< prev index next >

src/java.desktop/windows/native/libawt/windows/awt_Component.cpp

Print this page
rev 60071 : 8211999: Window positioning bugs due to overlapping GraphicsDevice bounds (Windows/HiDPI)
Reviewed-by: XXX


 586 
 587     ::ImmAssociateContext(m_hwnd, NULL);
 588 
 589     SetDrawState((jint)JAWT_LOCK_SURFACE_CHANGED |
 590         (jint)JAWT_LOCK_BOUNDS_CHANGED |
 591         (jint)JAWT_LOCK_CLIP_CHANGED);
 592 
 593     LinkObjects(env, peer);
 594 
 595     /* Subclass the window now so that we can snoop on its messages */
 596     SubclassHWND();
 597 
 598     AwtToolkit& tk = AwtToolkit::GetInstance();
 599     if (tk.IsWin8OrLater() && tk.IsTouchKeyboardAutoShowEnabled()) {
 600         tk.TIRegisterTouchWindow(GetHWnd(), TWF_WANTPALM);
 601     }
 602 
 603     /*
 604       * Fix for 4046446.
 605       */
 606     SetWindowPos(GetHWnd(), 0, x, y, w, h, SWP_NOZORDER | SWP_NOCOPYBITS | SWP_NOACTIVATE);
 607 
 608     /* Set default colors. */
 609     m_colorForeground = colorForeground;
 610     m_colorBackground = colorBackground;
 611 
 612     /*
 613      * Only set background color if the color is actually set on the
 614      * target -- this avoids inheriting a parent's color unnecessarily,
 615      * and has to be done here because there isn't an API to get the
 616      * real background color from outside the AWT package.
 617      */
 618     jobject bkgrd = env->GetObjectField(target, AwtComponent::backgroundID) ;
 619     if (bkgrd != NULL) {
 620         JNU_CallMethodByName(env, NULL, peer, "setBackground",
 621                              "(Ljava/awt/Color;)V", bkgrd);
 622         DASSERT(!safe_ExceptionOccurred(env));
 623     }
 624     env->DeleteLocalRef(target);
 625     env->DeleteLocalRef(bkgrd);
 626 }


1070 static UINT lastMessage = WM_NULL;
1071 
1072 #ifndef SPY_MESSAGES
1073 #define SpyWinMessage(hwin,msg,str)
1074 #else
1075 
1076 #define FMT_MSG(x,y) case x: _stprintf(szBuf, \
1077     "0x%8.8x(%s):%s\n", hwnd, szComment, y); break;
1078 #define WIN_MSG(x) FMT_MSG(x,#x)
1079 
1080 void SpyWinMessage(HWND hwnd, UINT message, LPCTSTR szComment) {
1081 
1082     TCHAR szBuf[256];
1083 
1084     switch (message) {
1085         WIN_MSG(WM_NULL)
1086         WIN_MSG(WM_CREATE)
1087         WIN_MSG(WM_DESTROY)
1088         WIN_MSG(WM_MOVE)
1089         WIN_MSG(WM_SIZE)

1090         WIN_MSG(WM_ACTIVATE)
1091         WIN_MSG(WM_SETFOCUS)
1092         WIN_MSG(WM_KILLFOCUS)
1093         WIN_MSG(WM_ENABLE)
1094         WIN_MSG(WM_SETREDRAW)
1095         WIN_MSG(WM_SETTEXT)
1096         WIN_MSG(WM_GETTEXT)
1097         WIN_MSG(WM_GETTEXTLENGTH)
1098         WIN_MSG(WM_PAINT)
1099         WIN_MSG(WM_CLOSE)
1100         WIN_MSG(WM_QUERYENDSESSION)
1101         WIN_MSG(WM_QUIT)
1102         WIN_MSG(WM_QUERYOPEN)
1103         WIN_MSG(WM_ERASEBKGND)
1104         WIN_MSG(WM_SYSCOLORCHANGE)
1105         WIN_MSG(WM_ENDSESSION)
1106         WIN_MSG(WM_SHOWWINDOW)
1107         FMT_MSG(WM_WININICHANGE,"WM_WININICHANGE/WM_SETTINGCHANGE")
1108         WIN_MSG(WM_DEVMODECHANGE)
1109         WIN_MSG(WM_ACTIVATEAPP)


1488       }
1489       case WM_WINDOWPOSCHANGED:
1490       {
1491           // Release lock grabbed in the POSCHANGING message
1492           if (windowMoveLockHeld) {
1493               windowMoveLockHeld = FALSE;
1494               windowMoveLock.Leave();
1495           }
1496           mr = WmWindowPosChanged(lParam);
1497           break;
1498       }
1499       case WM_MOVE: {
1500           RECT r;
1501           ::GetWindowRect(GetHWnd(), &r);
1502           mr = WmMove(r.left, r.top);
1503           break;
1504       }
1505       case WM_SIZE:
1506       {
1507           RECT r;
1508           // fix 4128317 : use GetClientRect for full 32-bit int precision and
1509           // to avoid negative client area dimensions overflowing 16-bit params - robi
1510           ::GetClientRect( GetHWnd(), &r );
1511           mr = WmSize(static_cast<UINT>(wParam), r.right - r.left, r.bottom - r.top);
1512           //mr = WmSize(wParam, LOWORD(lParam), HIWORD(lParam));
1513           SetCompositionWindow(r);
1514           break;
1515       }
1516       case WM_SIZING:
1517           mr = WmSizing();
1518           break;
1519       case WM_SHOWWINDOW:
1520           mr = WmShowWindow(static_cast<BOOL>(wParam),
1521                             static_cast<UINT>(lParam)); break;
1522       case WM_SYSCOMMAND:
1523           mr = WmSysCommand(static_cast<UINT>(wParam & 0xFFF0),
1524                             GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
1525           break;
1526       case WM_ENTERSIZEMOVE:
1527           mr = WmEnterSizeMove();
1528           break;
1529       case WM_EXITSIZEMOVE:
1530           mr = WmExitSizeMove();


3871     COMPOSITIONFORM cf = {CFS_DEFAULT, {0, 0}, {0, 0, 0, 0}};
3872     LOGFONT lf;
3873     HFONT hFont = (HFONT) GetStockObject(DEFAULT_GUI_FONT);
3874     if (GetObject(hFont, sizeof(lf), (LPVOID)&lf) == sizeof(lf)) {
3875         ImmSetCompositionFont(hIMC, &lf);
3876     }
3877     ImmSetCompositionWindow(hIMC, &cf);
3878     ImmReleaseContext(hwnd, hIMC);
3879 }
3880 
3881 void AwtComponent::OpenCandidateWindow(int x, int y)
3882 {
3883     UINT bits = 1;
3884     POINT p = {0, 0}; // upper left corner of the client area
3885     HWND hWnd = ImmGetHWnd();
3886     if (!::IsWindowVisible(hWnd)) {
3887         return;
3888     }
3889     HWND hTop = GetTopLevelParentForWindow(hWnd);
3890     ::ClientToScreen(hTop, &p);
3891     int sx = ScaleUpX(x) - p.x;
3892     int sy = ScaleUpY(y) - p.y;
3893     if (!m_bitsCandType) {
3894         SetCandidateWindow(m_bitsCandType, sx, sy);
3895         return;
3896     }
3897     for (int iCandType=0; iCandType<32; iCandType++, bits<<=1) {
3898         if ( m_bitsCandType & bits )
3899             SetCandidateWindow(iCandType, sx, sy);
3900     }
3901 }
3902 
3903 void AwtComponent::SetCandidateWindow(int iCandType, int x, int y)
3904 {
3905     HWND hwnd = ImmGetHWnd();
3906     HIMC hIMC = ImmGetContext(hwnd);
3907     if (hIMC) {
3908         CANDIDATEFORM cf;
3909         cf.dwStyle = CFS_POINT;
3910         ImmGetCandidateWindow(hIMC, 0, &cf);
3911         if (x != cf.ptCurrentPos.x || y != cf.ptCurrentPos.y) {
3912             cf.dwIndex = iCandType;


4750 {
4751     RECT eraseR = { 0, 0, size.cx, size.cy };
4752     VERIFY(::FillRect(hMemoryDC, &eraseR, GetBackgroundBrush()));
4753 }
4754 
4755 void AwtComponent::FillAlpha(void *bitmapBits, SIZE &size, BYTE alpha)
4756 {
4757     if (!bitmapBits) {
4758         return;
4759     }
4760 
4761     DWORD* dest = (DWORD*)bitmapBits;
4762     //XXX: might be optimized to use one loop (cy*cx -> 0)
4763     for (int i = 0; i < size.cy; i++ ) {
4764         for (int j = 0; j < size.cx; j++ ) {
4765             ((BYTE*)(dest++))[3] = alpha;
4766         }
4767     }
4768 }
4769 









4770 int AwtComponent::ScaleUpX(int x) {
4771     int screen = AwtWin32GraphicsDevice::DeviceIndexForWindow(GetHWnd());
4772     Devices::InstanceAccess devices;
4773     AwtWin32GraphicsDevice* device = devices->GetDevice(screen);
4774     return device == NULL ? x : device->ScaleUpX(x);
4775 }
4776 







4777 int AwtComponent::ScaleUpY(int y) {
4778     int screen = AwtWin32GraphicsDevice::DeviceIndexForWindow(GetHWnd());
4779     Devices::InstanceAccess devices;
4780     AwtWin32GraphicsDevice* device = devices->GetDevice(screen);
4781     return device == NULL ? y : device->ScaleUpY(y);
4782 }
4783 







4784 int AwtComponent::ScaleDownX(int x) {
4785     int screen = AwtWin32GraphicsDevice::DeviceIndexForWindow(GetHWnd());
4786     Devices::InstanceAccess devices;
4787     AwtWin32GraphicsDevice* device = devices->GetDevice(screen);
4788     return device == NULL ? x : device->ScaleDownX(x);
4789 }
4790 







4791 int AwtComponent::ScaleDownY(int y) {
4792     int screen = AwtWin32GraphicsDevice::DeviceIndexForWindow(GetHWnd());
4793     Devices::InstanceAccess devices;
4794     AwtWin32GraphicsDevice* device = devices->GetDevice(screen);
4795     return device == NULL ? y : device->ScaleDownY(y);
4796 }
4797 







4798 jintArray AwtComponent::CreatePrintedPixels(SIZE &loc, SIZE &size, int alpha) {
4799     JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
4800 
4801     if (!::IsWindowVisible(GetHWnd())) {
4802         return NULL;
4803     }
4804 
4805     HDC hdc = GetDCFromComponent();
4806     if (!hdc) {
4807         return NULL;
4808     }
4809     HDC hMemoryDC = ::CreateCompatibleDC(hdc);
4810     void *bitmapBits = NULL;
4811     HBITMAP hBitmap = BitmapUtil::CreateARGBBitmap(size.cx, size.cy, &bitmapBits);
4812     HBITMAP hOldBitmap = (HBITMAP)::SelectObject(hMemoryDC, hBitmap);
4813     SendMessage(WM_AWT_RELEASEDC, (WPARAM)hdc);
4814 
4815     FillBackground(hMemoryDC, size);
4816 
4817     VERIFY(::SetWindowOrgEx(hMemoryDC, loc.cx, loc.cy, NULL));


5073     static jmethodID mouseEventConst;
5074     if (mouseEventConst == NULL) {
5075         mouseEventConst =
5076             env->GetMethodID(mouseEventCls, "<init>",
5077                  "(Ljava/awt/Component;IJIIIIIIZI)V");
5078         DASSERT(mouseEventConst);
5079         CHECK_NULL(mouseEventConst);
5080     }
5081     if (env->EnsureLocalCapacity(2) < 0) {
5082         return;
5083     }
5084     jobject target = GetTarget(env);
5085     DWORD curMousePos = ::GetMessagePos();
5086     int xAbs = GET_X_LPARAM(curMousePos);
5087     int yAbs = GET_Y_LPARAM(curMousePos);
5088     jobject mouseEvent = env->NewObject(mouseEventCls, mouseEventConst,
5089                                         target,
5090                                         id, when, modifiers,
5091                                         ScaleDownX(x + insets.left),
5092                                         ScaleDownY(y + insets.top),
5093                                         ScaleDownX(xAbs), ScaleDownY(yAbs),
5094                                         clickCount, popupTrigger, button);
5095 
5096     if (safe_ExceptionOccurred(env)) {
5097         env->ExceptionDescribe();
5098         env->ExceptionClear();
5099     }
5100 
5101     DASSERT(mouseEvent != NULL);
5102     CHECK_NULL(mouseEvent);
5103     if (causedByTouchEvent) {
5104         env->SetBooleanField(mouseEvent, AwtMouseEvent::causedByTouchEventID,
5105             JNI_TRUE);
5106     }
5107     if (pMsg != 0) {
5108         AwtAWTEvent::saveMSG(env, pMsg, mouseEvent);
5109     }
5110     SendEvent(mouseEvent);
5111 
5112     env->DeleteLocalRef(mouseEvent);
5113     env->DeleteLocalRef(target);


5146                            "(Ljava/awt/Component;IJIIIIIIZIIID)V");
5147         DASSERT(mouseWheelEventConst);
5148         CHECK_NULL(mouseWheelEventConst);
5149     }
5150     if (env->EnsureLocalCapacity(2) < 0) {
5151         return;
5152     }
5153     jobject target = GetTarget(env);
5154     DWORD curMousePos = ::GetMessagePos();
5155     int xAbs = GET_X_LPARAM(curMousePos);
5156     int yAbs = GET_Y_LPARAM(curMousePos);
5157 
5158     DTRACE_PRINTLN("creating MWE in JNI");
5159 
5160     jobject mouseWheelEvent = env->NewObject(mouseWheelEventCls,
5161                                              mouseWheelEventConst,
5162                                              target,
5163                                              id, when, modifiers,
5164                                              ScaleDownX(x + insets.left),
5165                                              ScaleDownY(y + insets.top),
5166                                              ScaleDownX(xAbs),
5167                                              ScaleDownY(yAbs),
5168                                              clickCount, popupTrigger,
5169                                              scrollType, scrollAmount,
5170                                              roundedWheelRotation, preciseWheelRotation);
5171 
5172     DASSERT(mouseWheelEvent != NULL);
5173     if (mouseWheelEvent == NULL || safe_ExceptionOccurred(env)) {
5174         env->ExceptionDescribe();
5175         env->ExceptionClear();
5176         env->DeleteLocalRef(target);
5177         return;
5178     }
5179     if (pMsg != NULL) {
5180         AwtAWTEvent::saveMSG(env, pMsg, mouseWheelEvent);
5181     }
5182     SendEvent(mouseWheelEvent);
5183 
5184     env->DeleteLocalRef(mouseWheelEvent);
5185     env->DeleteLocalRef(target);
5186 }
5187 


5657     env->DeleteGlobalRef(self);
5658 }
5659 
5660 jobject AwtComponent::_GetLocationOnScreen(void *param)
5661 {
5662     JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
5663 
5664     jobject self = (jobject)param;
5665 
5666     jobject result = NULL;
5667     AwtComponent *p;
5668 
5669     PDATA pData;
5670     JNI_CHECK_PEER_GOTO(self, ret);
5671     p = (AwtComponent *)pData;
5672     if (::IsWindow(p->GetHWnd()))
5673     {
5674         RECT rect;
5675         VERIFY(::GetWindowRect(p->GetHWnd(),&rect));
5676         result = JNU_NewObjectByName(env, "java/awt/Point", "(II)V",
5677                                      p->ScaleDownX(rect.left),
5678                                      p->ScaleDownY(rect.top));
5679     }
5680 ret:
5681     env->DeleteGlobalRef(self);
5682 
5683     if (result != NULL)
5684     {
5685         jobject resultGlobalRef = env->NewGlobalRef(result);
5686         env->DeleteLocalRef(result);
5687         return resultGlobalRef;
5688     }
5689     else
5690     {
5691         return NULL;
5692     }
5693 }
5694 
5695 void AwtComponent::_Reshape(void *param)
5696 {
5697     JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
5698 




 586 
 587     ::ImmAssociateContext(m_hwnd, NULL);
 588 
 589     SetDrawState((jint)JAWT_LOCK_SURFACE_CHANGED |
 590         (jint)JAWT_LOCK_BOUNDS_CHANGED |
 591         (jint)JAWT_LOCK_CLIP_CHANGED);
 592 
 593     LinkObjects(env, peer);
 594 
 595     /* Subclass the window now so that we can snoop on its messages */
 596     SubclassHWND();
 597 
 598     AwtToolkit& tk = AwtToolkit::GetInstance();
 599     if (tk.IsWin8OrLater() && tk.IsTouchKeyboardAutoShowEnabled()) {
 600         tk.TIRegisterTouchWindow(GetHWnd(), TWF_WANTPALM);
 601     }
 602 
 603     /*
 604       * Fix for 4046446.
 605       */
 606     Reshape(x, y, w, h);
 607 
 608     /* Set default colors. */
 609     m_colorForeground = colorForeground;
 610     m_colorBackground = colorBackground;
 611 
 612     /*
 613      * Only set background color if the color is actually set on the
 614      * target -- this avoids inheriting a parent's color unnecessarily,
 615      * and has to be done here because there isn't an API to get the
 616      * real background color from outside the AWT package.
 617      */
 618     jobject bkgrd = env->GetObjectField(target, AwtComponent::backgroundID) ;
 619     if (bkgrd != NULL) {
 620         JNU_CallMethodByName(env, NULL, peer, "setBackground",
 621                              "(Ljava/awt/Color;)V", bkgrd);
 622         DASSERT(!safe_ExceptionOccurred(env));
 623     }
 624     env->DeleteLocalRef(target);
 625     env->DeleteLocalRef(bkgrd);
 626 }


1070 static UINT lastMessage = WM_NULL;
1071 
1072 #ifndef SPY_MESSAGES
1073 #define SpyWinMessage(hwin,msg,str)
1074 #else
1075 
1076 #define FMT_MSG(x,y) case x: _stprintf(szBuf, \
1077     "0x%8.8x(%s):%s\n", hwnd, szComment, y); break;
1078 #define WIN_MSG(x) FMT_MSG(x,#x)
1079 
1080 void SpyWinMessage(HWND hwnd, UINT message, LPCTSTR szComment) {
1081 
1082     TCHAR szBuf[256];
1083 
1084     switch (message) {
1085         WIN_MSG(WM_NULL)
1086         WIN_MSG(WM_CREATE)
1087         WIN_MSG(WM_DESTROY)
1088         WIN_MSG(WM_MOVE)
1089         WIN_MSG(WM_SIZE)
1090         WIN_MSG(WM_DPICHANGED)
1091         WIN_MSG(WM_ACTIVATE)
1092         WIN_MSG(WM_SETFOCUS)
1093         WIN_MSG(WM_KILLFOCUS)
1094         WIN_MSG(WM_ENABLE)
1095         WIN_MSG(WM_SETREDRAW)
1096         WIN_MSG(WM_SETTEXT)
1097         WIN_MSG(WM_GETTEXT)
1098         WIN_MSG(WM_GETTEXTLENGTH)
1099         WIN_MSG(WM_PAINT)
1100         WIN_MSG(WM_CLOSE)
1101         WIN_MSG(WM_QUERYENDSESSION)
1102         WIN_MSG(WM_QUIT)
1103         WIN_MSG(WM_QUERYOPEN)
1104         WIN_MSG(WM_ERASEBKGND)
1105         WIN_MSG(WM_SYSCOLORCHANGE)
1106         WIN_MSG(WM_ENDSESSION)
1107         WIN_MSG(WM_SHOWWINDOW)
1108         FMT_MSG(WM_WININICHANGE,"WM_WININICHANGE/WM_SETTINGCHANGE")
1109         WIN_MSG(WM_DEVMODECHANGE)
1110         WIN_MSG(WM_ACTIVATEAPP)


1489       }
1490       case WM_WINDOWPOSCHANGED:
1491       {
1492           // Release lock grabbed in the POSCHANGING message
1493           if (windowMoveLockHeld) {
1494               windowMoveLockHeld = FALSE;
1495               windowMoveLock.Leave();
1496           }
1497           mr = WmWindowPosChanged(lParam);
1498           break;
1499       }
1500       case WM_MOVE: {
1501           RECT r;
1502           ::GetWindowRect(GetHWnd(), &r);
1503           mr = WmMove(r.left, r.top);
1504           break;
1505       }
1506       case WM_SIZE:
1507       {
1508           RECT r;
1509           // fix 4128317 : use GetWindowRect for full 32-bit int precision and
1510           // to avoid negative client area dimensions overflowing 16-bit params - robi
1511           ::GetWindowRect(GetHWnd(), &r);
1512           mr = WmSize(static_cast<UINT>(wParam), r.right - r.left, r.bottom - r.top);
1513           //mr = WmSize(wParam, LOWORD(lParam), HIWORD(lParam));
1514           SetCompositionWindow(r);
1515           break;
1516       }
1517       case WM_SIZING:
1518           mr = WmSizing();
1519           break;
1520       case WM_SHOWWINDOW:
1521           mr = WmShowWindow(static_cast<BOOL>(wParam),
1522                             static_cast<UINT>(lParam)); break;
1523       case WM_SYSCOMMAND:
1524           mr = WmSysCommand(static_cast<UINT>(wParam & 0xFFF0),
1525                             GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
1526           break;
1527       case WM_ENTERSIZEMOVE:
1528           mr = WmEnterSizeMove();
1529           break;
1530       case WM_EXITSIZEMOVE:
1531           mr = WmExitSizeMove();


3872     COMPOSITIONFORM cf = {CFS_DEFAULT, {0, 0}, {0, 0, 0, 0}};
3873     LOGFONT lf;
3874     HFONT hFont = (HFONT) GetStockObject(DEFAULT_GUI_FONT);
3875     if (GetObject(hFont, sizeof(lf), (LPVOID)&lf) == sizeof(lf)) {
3876         ImmSetCompositionFont(hIMC, &lf);
3877     }
3878     ImmSetCompositionWindow(hIMC, &cf);
3879     ImmReleaseContext(hwnd, hIMC);
3880 }
3881 
3882 void AwtComponent::OpenCandidateWindow(int x, int y)
3883 {
3884     UINT bits = 1;
3885     POINT p = {0, 0}; // upper left corner of the client area
3886     HWND hWnd = ImmGetHWnd();
3887     if (!::IsWindowVisible(hWnd)) {
3888         return;
3889     }
3890     HWND hTop = GetTopLevelParentForWindow(hWnd);
3891     ::ClientToScreen(hTop, &p);
3892     int sx = ScaleUpAbsX(x) - p.x;
3893     int sy = ScaleUpAbsY(y) - p.y;
3894     if (!m_bitsCandType) {
3895         SetCandidateWindow(m_bitsCandType, sx, sy);
3896         return;
3897     }
3898     for (int iCandType=0; iCandType<32; iCandType++, bits<<=1) {
3899         if ( m_bitsCandType & bits )
3900             SetCandidateWindow(iCandType, sx, sy);
3901     }
3902 }
3903 
3904 void AwtComponent::SetCandidateWindow(int iCandType, int x, int y)
3905 {
3906     HWND hwnd = ImmGetHWnd();
3907     HIMC hIMC = ImmGetContext(hwnd);
3908     if (hIMC) {
3909         CANDIDATEFORM cf;
3910         cf.dwStyle = CFS_POINT;
3911         ImmGetCandidateWindow(hIMC, 0, &cf);
3912         if (x != cf.ptCurrentPos.x || y != cf.ptCurrentPos.y) {
3913             cf.dwIndex = iCandType;


4751 {
4752     RECT eraseR = { 0, 0, size.cx, size.cy };
4753     VERIFY(::FillRect(hMemoryDC, &eraseR, GetBackgroundBrush()));
4754 }
4755 
4756 void AwtComponent::FillAlpha(void *bitmapBits, SIZE &size, BYTE alpha)
4757 {
4758     if (!bitmapBits) {
4759         return;
4760     }
4761 
4762     DWORD* dest = (DWORD*)bitmapBits;
4763     //XXX: might be optimized to use one loop (cy*cx -> 0)
4764     for (int i = 0; i < size.cy; i++ ) {
4765         for (int j = 0; j < size.cx; j++ ) {
4766             ((BYTE*)(dest++))[3] = alpha;
4767         }
4768     }
4769 }
4770 
4771 int AwtComponent::GetScreenImOn() {
4772     HWND hWindow = GetAncestor(GetHWnd(), GA_ROOT);
4773     AwtComponent *comp = AwtComponent::GetComponent(hWindow);
4774     if (comp && comp->IsTopLevel()) {
4775         return comp->GetScreenImOn();
4776     }
4777     return AwtWin32GraphicsDevice::DeviceIndexForWindow(hWindow);
4778 }
4779 
4780 int AwtComponent::ScaleUpX(int x) {
4781     int screen = GetScreenImOn();
4782     Devices::InstanceAccess devices;
4783     AwtWin32GraphicsDevice* device = devices->GetDevice(screen);
4784     return device == NULL ? x : device->ScaleUpX(x);
4785 }
4786 
4787 int AwtComponent::ScaleUpAbsX(int x) {
4788     int screen = GetScreenImOn();
4789     Devices::InstanceAccess devices;
4790     AwtWin32GraphicsDevice* device = devices->GetDevice(screen);
4791     return device == NULL ? x : device->ScaleUpAbsX(x);
4792 }
4793 
4794 int AwtComponent::ScaleUpY(int y) {
4795     int screen = GetScreenImOn();
4796     Devices::InstanceAccess devices;
4797     AwtWin32GraphicsDevice* device = devices->GetDevice(screen);
4798     return device == NULL ? y : device->ScaleUpY(y);
4799 }
4800 
4801 int AwtComponent::ScaleUpAbsY(int y) {
4802     int screen = GetScreenImOn();
4803     Devices::InstanceAccess devices;
4804     AwtWin32GraphicsDevice* device = devices->GetDevice(screen);
4805     return device == NULL ? y : device->ScaleUpAbsY(y);
4806 }
4807 
4808 int AwtComponent::ScaleDownX(int x) {
4809     int screen = GetScreenImOn();
4810     Devices::InstanceAccess devices;
4811     AwtWin32GraphicsDevice* device = devices->GetDevice(screen);
4812     return device == NULL ? x : device->ScaleDownX(x);
4813 }
4814 
4815 int AwtComponent::ScaleDownAbsX(int x) {
4816     int screen = GetScreenImOn();
4817     Devices::InstanceAccess devices;
4818     AwtWin32GraphicsDevice* device = devices->GetDevice(screen);
4819     return device == NULL ? x : device->ScaleDownAbsX(x);
4820 }
4821 
4822 int AwtComponent::ScaleDownY(int y) {
4823     int screen = GetScreenImOn();
4824     Devices::InstanceAccess devices;
4825     AwtWin32GraphicsDevice* device = devices->GetDevice(screen);
4826     return device == NULL ? y : device->ScaleDownY(y);
4827 }
4828 
4829 int AwtComponent::ScaleDownAbsY(int y) {
4830     int screen = GetScreenImOn();
4831     Devices::InstanceAccess devices;
4832     AwtWin32GraphicsDevice* device = devices->GetDevice(screen);
4833     return device == NULL ? y : device->ScaleDownAbsY(y);
4834 }
4835 
4836 jintArray AwtComponent::CreatePrintedPixels(SIZE &loc, SIZE &size, int alpha) {
4837     JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
4838 
4839     if (!::IsWindowVisible(GetHWnd())) {
4840         return NULL;
4841     }
4842 
4843     HDC hdc = GetDCFromComponent();
4844     if (!hdc) {
4845         return NULL;
4846     }
4847     HDC hMemoryDC = ::CreateCompatibleDC(hdc);
4848     void *bitmapBits = NULL;
4849     HBITMAP hBitmap = BitmapUtil::CreateARGBBitmap(size.cx, size.cy, &bitmapBits);
4850     HBITMAP hOldBitmap = (HBITMAP)::SelectObject(hMemoryDC, hBitmap);
4851     SendMessage(WM_AWT_RELEASEDC, (WPARAM)hdc);
4852 
4853     FillBackground(hMemoryDC, size);
4854 
4855     VERIFY(::SetWindowOrgEx(hMemoryDC, loc.cx, loc.cy, NULL));


5111     static jmethodID mouseEventConst;
5112     if (mouseEventConst == NULL) {
5113         mouseEventConst =
5114             env->GetMethodID(mouseEventCls, "<init>",
5115                  "(Ljava/awt/Component;IJIIIIIIZI)V");
5116         DASSERT(mouseEventConst);
5117         CHECK_NULL(mouseEventConst);
5118     }
5119     if (env->EnsureLocalCapacity(2) < 0) {
5120         return;
5121     }
5122     jobject target = GetTarget(env);
5123     DWORD curMousePos = ::GetMessagePos();
5124     int xAbs = GET_X_LPARAM(curMousePos);
5125     int yAbs = GET_Y_LPARAM(curMousePos);
5126     jobject mouseEvent = env->NewObject(mouseEventCls, mouseEventConst,
5127                                         target,
5128                                         id, when, modifiers,
5129                                         ScaleDownX(x + insets.left),
5130                                         ScaleDownY(y + insets.top),
5131                                         ScaleDownAbsX(xAbs), ScaleDownAbsY(yAbs),
5132                                         clickCount, popupTrigger, button);
5133 
5134     if (safe_ExceptionOccurred(env)) {
5135         env->ExceptionDescribe();
5136         env->ExceptionClear();
5137     }
5138 
5139     DASSERT(mouseEvent != NULL);
5140     CHECK_NULL(mouseEvent);
5141     if (causedByTouchEvent) {
5142         env->SetBooleanField(mouseEvent, AwtMouseEvent::causedByTouchEventID,
5143             JNI_TRUE);
5144     }
5145     if (pMsg != 0) {
5146         AwtAWTEvent::saveMSG(env, pMsg, mouseEvent);
5147     }
5148     SendEvent(mouseEvent);
5149 
5150     env->DeleteLocalRef(mouseEvent);
5151     env->DeleteLocalRef(target);


5184                            "(Ljava/awt/Component;IJIIIIIIZIIID)V");
5185         DASSERT(mouseWheelEventConst);
5186         CHECK_NULL(mouseWheelEventConst);
5187     }
5188     if (env->EnsureLocalCapacity(2) < 0) {
5189         return;
5190     }
5191     jobject target = GetTarget(env);
5192     DWORD curMousePos = ::GetMessagePos();
5193     int xAbs = GET_X_LPARAM(curMousePos);
5194     int yAbs = GET_Y_LPARAM(curMousePos);
5195 
5196     DTRACE_PRINTLN("creating MWE in JNI");
5197 
5198     jobject mouseWheelEvent = env->NewObject(mouseWheelEventCls,
5199                                              mouseWheelEventConst,
5200                                              target,
5201                                              id, when, modifiers,
5202                                              ScaleDownX(x + insets.left),
5203                                              ScaleDownY(y + insets.top),
5204                                              ScaleDownAbsX(xAbs),
5205                                              ScaleDownAbsY(yAbs),
5206                                              clickCount, popupTrigger,
5207                                              scrollType, scrollAmount,
5208                                              roundedWheelRotation, preciseWheelRotation);
5209 
5210     DASSERT(mouseWheelEvent != NULL);
5211     if (mouseWheelEvent == NULL || safe_ExceptionOccurred(env)) {
5212         env->ExceptionDescribe();
5213         env->ExceptionClear();
5214         env->DeleteLocalRef(target);
5215         return;
5216     }
5217     if (pMsg != NULL) {
5218         AwtAWTEvent::saveMSG(env, pMsg, mouseWheelEvent);
5219     }
5220     SendEvent(mouseWheelEvent);
5221 
5222     env->DeleteLocalRef(mouseWheelEvent);
5223     env->DeleteLocalRef(target);
5224 }
5225 


5695     env->DeleteGlobalRef(self);
5696 }
5697 
5698 jobject AwtComponent::_GetLocationOnScreen(void *param)
5699 {
5700     JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
5701 
5702     jobject self = (jobject)param;
5703 
5704     jobject result = NULL;
5705     AwtComponent *p;
5706 
5707     PDATA pData;
5708     JNI_CHECK_PEER_GOTO(self, ret);
5709     p = (AwtComponent *)pData;
5710     if (::IsWindow(p->GetHWnd()))
5711     {
5712         RECT rect;
5713         VERIFY(::GetWindowRect(p->GetHWnd(),&rect));
5714         result = JNU_NewObjectByName(env, "java/awt/Point", "(II)V",
5715                                      p->ScaleDownAbsX(rect.left),
5716                                      p->ScaleDownAbsY(rect.top));
5717     }
5718 ret:
5719     env->DeleteGlobalRef(self);
5720 
5721     if (result != NULL)
5722     {
5723         jobject resultGlobalRef = env->NewGlobalRef(result);
5724         env->DeleteLocalRef(result);
5725         return resultGlobalRef;
5726     }
5727     else
5728     {
5729         return NULL;
5730     }
5731 }
5732 
5733 void AwtComponent::_Reshape(void *param)
5734 {
5735     JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
5736 


< prev index next >