< prev index next >

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

Print this page




 200 BOOL AwtComponent::sm_rtl = PRIMARYLANGID(GetInputLanguage()) == LANG_ARABIC ||
 201                             PRIMARYLANGID(GetInputLanguage()) == LANG_HEBREW;
 202 BOOL AwtComponent::sm_rtlReadingOrder =
 203     PRIMARYLANGID(GetInputLanguage()) == LANG_ARABIC;
 204 
 205 BOOL AwtComponent::sm_PrimaryDynamicTableBuilt = FALSE;
 206 
 207 HWND AwtComponent::sm_cursorOn;
 208 BOOL AwtComponent::m_QueryNewPaletteCalled = FALSE;
 209 
 210 CriticalSection windowMoveLock;
 211 BOOL windowMoveLockHeld = FALSE;
 212 
 213 /************************************************************************
 214  * AwtComponent methods
 215  */
 216 
 217 AwtComponent::AwtComponent()
 218 {
 219     m_mouseButtonClickAllowed = 0;




 220     m_callbacksEnabled = FALSE;
 221     m_hwnd = NULL;
 222 
 223     m_colorForeground = 0;
 224     m_colorBackground = 0;
 225     m_backgroundColorSet = FALSE;
 226     m_penForeground = NULL;
 227     m_brushBackground = NULL;
 228     m_DefWindowProc = NULL;
 229     m_nextControlID = 1;
 230     m_childList = NULL;
 231     m_myControlID = 0;
 232     m_hdwp = NULL;
 233     m_validationNestCount = 0;
 234 
 235     m_dropTarget = NULL;
 236 
 237     m_InputMethod = NULL;
 238     m_useNativeCompWindow = TRUE;
 239     m_PendingLeadByte = 0;


 565             env->SetObjectField(peer, AwtObject::createErrorID, createError);
 566             env->DeleteLocalRef(createError);
 567         }
 568         env->DeleteLocalRef(target);
 569         return;
 570     }
 571 
 572     m_hwnd = hwnd;
 573 
 574     ::ImmAssociateContext(m_hwnd, NULL);
 575 
 576     SetDrawState((jint)JAWT_LOCK_SURFACE_CHANGED |
 577         (jint)JAWT_LOCK_BOUNDS_CHANGED |
 578         (jint)JAWT_LOCK_CLIP_CHANGED);
 579 
 580     LinkObjects(env, peer);
 581 
 582     /* Subclass the window now so that we can snoop on its messages */
 583     SubclassHWND();
 584 





 585     /*
 586       * Fix for 4046446.
 587       */
 588     SetWindowPos(GetHWnd(), 0, x, y, w, h, SWP_NOZORDER | SWP_NOCOPYBITS | SWP_NOACTIVATE);
 589 
 590     /* Set default colors. */
 591     m_colorForeground = colorForeground;
 592     m_colorBackground = colorBackground;
 593 
 594     /*
 595      * Only set background color if the color is actually set on the
 596      * target -- this avoids inheriting a parent's color unnecessarily,
 597      * and has to be done here because there isn't an API to get the
 598      * real background color from outside the AWT package.
 599      */
 600     jobject bkgrd = env->GetObjectField(target, AwtComponent::backgroundID) ;
 601     if (bkgrd != NULL) {
 602         JNU_CallMethodByName(env, NULL, peer, "setBackground",
 603                              "(Ljava/awt/Color;)V", bkgrd);
 604         DASSERT(!safe_ExceptionOccurred(env));


1696           case WM_RBUTTONUP:
1697               mr = WmMouseUp(static_cast<UINT>(wParam), myPos.x, myPos.y,
1698                              RIGHT_BUTTON);
1699               break;
1700           case WM_MBUTTONUP:
1701               mr = WmMouseUp(static_cast<UINT>(wParam), myPos.x, myPos.y,
1702                              MIDDLE_BUTTON);
1703               break;
1704           case WM_AWT_MOUSEEXIT:
1705               mr = WmMouseExit(static_cast<UINT>(wParam), myPos.x, myPos.y);
1706               break;
1707           case WM_MOUSEWHEEL:
1708           case WM_MOUSEHWHEEL:
1709               mr = WmMouseWheel(GET_KEYSTATE_WPARAM(wParam),
1710                                 GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam),
1711                                 GET_WHEEL_DELTA_WPARAM(wParam),
1712                                 switchMessage == WM_MOUSEHWHEEL);
1713               break;
1714           }
1715           break;



1716       case WM_SETCURSOR:
1717           mr = mrDoDefault;
1718           if (LOWORD(lParam) == HTCLIENT) {
1719               if (AwtComponent* comp =
1720                                     AwtComponent::GetComponent((HWND)wParam)) {
1721                   AwtCursor::UpdateCursor(comp);
1722                   mr = mrConsume;
1723               }
1724           }
1725           break;
1726 
1727       case WM_KEYDOWN:
1728           mr = WmKeyDown(static_cast<UINT>(wParam),
1729                          LOWORD(lParam), HIWORD(lParam), FALSE);
1730           break;
1731       case WM_KEYUP:
1732           mr = WmKeyUp(static_cast<UINT>(wParam),
1733                        LOWORD(lParam), HIWORD(lParam), FALSE);
1734           break;
1735       case WM_SYSKEYDOWN:


2278     msg->lParam = lParam;
2279     msg->time = ::GetMessageTime();
2280     msg->pt.x = x;
2281     msg->pt.y = y;
2282 }
2283 
2284 MsgRouting AwtComponent::WmNcMouseDown(WPARAM hitTest, int x, int y, int button) {
2285     return mrDoDefault;
2286 }
2287 MsgRouting AwtComponent::WmNcMouseUp(WPARAM hitTest, int x, int y, int button) {
2288     return mrDoDefault;
2289 }
2290 
2291 MsgRouting AwtComponent::WmWindowPosChanging(LPARAM windowPos) {
2292     return mrDoDefault;
2293 }
2294 MsgRouting AwtComponent::WmWindowPosChanged(LPARAM windowPos) {
2295     return mrDoDefault;
2296 }
2297 
































2298 /* Double-click variables. */
2299 static jlong multiClickTime = ::GetDoubleClickTime();
2300 static int multiClickMaxX = ::GetSystemMetrics(SM_CXDOUBLECLK);
2301 static int multiClickMaxY = ::GetSystemMetrics(SM_CYDOUBLECLK);
2302 static AwtComponent* lastClickWnd = NULL;
2303 static jlong lastTime = 0;
2304 static int lastClickX = 0;
2305 static int lastClickY = 0;
2306 static int lastButton = 0;
2307 static int clickCount = 0;
2308 
2309 // A static method that makes the clickCount available in the derived classes
2310 // overriding WmMouseDown().
2311 int AwtComponent::GetClickCount()
2312 {
2313     return clickCount;
2314 }
2315 
2316 MsgRouting AwtComponent::WmMouseDown(UINT flags, int x, int y, int button)
2317 {


2320     if (lastClickWnd == this &&
2321         lastButton == button &&
2322         (now - lastTime) <= multiClickTime &&
2323         abs(x - lastClickX) <= multiClickMaxX &&
2324         abs(y - lastClickY) <= multiClickMaxY)
2325     {
2326         clickCount++;
2327     } else {
2328         clickCount = 1;
2329         lastClickWnd = this;
2330         lastButton = button;
2331         lastClickX = x;
2332         lastClickY = y;
2333     }
2334     /*
2335      *Set appropriate bit of the mask on WM_MOUSE_DOWN message.
2336      */
2337     m_mouseButtonClickAllowed |= GetButtonMK(button);
2338     lastTime = now;
2339 








2340     MSG msg;
2341     InitMessage(&msg, lastMessage, flags, MAKELPARAM(x, y), x, y);
2342 
2343     AwtWindow *toplevel = GetContainer();
2344     if (toplevel && !toplevel->IsSimpleWindow()) {
2345         /*
2346          * The frame should be focused by click in case it is
2347          * the active window but not the focused window. See 6886678.
2348          */
2349         if (toplevel->GetHWnd() == ::GetActiveWindow() &&
2350             toplevel->GetHWnd() != AwtComponent::GetFocusedWindow())
2351         {
2352             toplevel->AwtSetActiveWindow();
2353         }
2354     }
2355 
2356     SendMouseEvent(java_awt_event_MouseEvent_MOUSE_PRESSED, now, x, y,
2357                    GetJavaModifiers(), clickCount, JNI_FALSE,
2358                    GetButton(button), &msg);
2359     /*
2360      * NOTE: this call is intentionally placed after all other code,
2361      * since AwtComponent::WmMouseDown() assumes that the cached id of the
2362      * latest retrieved message (see lastMessage in awt_Component.cpp)
2363      * matches the mouse message being processed.
2364      * SetCapture() sends WM_CAPTURECHANGED and breaks that
2365      * assumption.
2366      */
2367     SetDragCapture(flags);
2368 
2369     AwtWindow * owner = (AwtWindow*)GetComponent(GetTopLevelParentForWindow(GetHWnd()));
2370     if (AwtWindow::GetGrabbedWindow() != NULL && owner != NULL) {
2371         if (!AwtWindow::GetGrabbedWindow()->IsOneOfOwnersOf(owner)) {
2372             AwtWindow::GetGrabbedWindow()->Ungrab();
2373         }
2374     }
2375     return mrConsume;
2376 }
2377 
2378 MsgRouting AwtComponent::WmMouseUp(UINT flags, int x, int y, int button)
2379 {








2380     MSG msg;
2381     InitMessage(&msg, lastMessage, flags, MAKELPARAM(x, y), x, y);
2382 
2383     SendMouseEvent(java_awt_event_MouseEvent_MOUSE_RELEASED, ::JVM_CurrentTimeMillis(NULL, 0),
2384                    x, y, GetJavaModifiers(), clickCount,
2385                    (GetButton(button) == java_awt_event_MouseEvent_BUTTON3 ?
2386                     TRUE : FALSE), GetButton(button), &msg);
2387     /*
2388      * If no movement, then report a click following the button release.
2389      * When WM_MOUSEUP comes to a window without previous WM_MOUSEDOWN,
2390      * spurous MOUSE_CLICK is about to happen. See 6430553.
2391      */
2392     if ((m_mouseButtonClickAllowed & GetButtonMK(button)) != 0) { //CLICK allowed
2393         SendMouseEvent(java_awt_event_MouseEvent_MOUSE_CLICKED,
2394                        ::JVM_CurrentTimeMillis(NULL, 0), x, y, GetJavaModifiers(),
2395                        clickCount, JNI_FALSE, GetButton(button));
2396     }
2397     // Exclude button from allowed to generate CLICK messages
2398     m_mouseButtonClickAllowed &= ~GetButtonMK(button);
2399 
2400     if ((flags & ALL_MK_BUTTONS) == 0) {
2401         // only update if all buttons have been released
2402         AwtCursor::UpdateCursor(this);
2403     }
2404     /*
2405      * NOTE: this call is intentionally placed after all other code,
2406      * since AwtComponent::WmMouseUp() assumes that the cached id of the


4953 
4954 void AwtComponent::SetDragCapture(UINT flags)
4955 {
4956     // don't want to interfere with other controls
4957     if (::GetCapture() == NULL) {
4958         ::SetCapture(GetHWnd());
4959     }
4960 }
4961 
4962 void AwtComponent::ReleaseDragCapture(UINT flags)
4963 {
4964     if ((::GetCapture() == GetHWnd()) && ((flags & ALL_MK_BUTTONS) == 0)) {
4965         // user has released all buttons, so release the capture
4966         ::ReleaseCapture();
4967     }
4968 }
4969 
4970 void AwtComponent::SendMouseEvent(jint id, jlong when, jint x, jint y,
4971                                   jint modifiers, jint clickCount,
4972                                   jboolean popupTrigger, jint button,
4973                                   MSG *pMsg)
4974 {
4975     JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
4976     CriticalSection::Lock l(GetLock());
4977     if (GetPeer(env) == NULL) {
4978         /* event received during termination. */
4979         return;
4980     }
4981 
4982     static jclass mouseEventCls;
4983     if (mouseEventCls == NULL) {
4984         jclass mouseEventClsLocal =
4985             env->FindClass("java/awt/event/MouseEvent");
4986         CHECK_NULL(mouseEventClsLocal);
4987         mouseEventCls = (jclass)env->NewGlobalRef(mouseEventClsLocal);
4988         env->DeleteLocalRef(mouseEventClsLocal);
4989     }
4990     RECT insets;
4991     GetInsets(&insets);
4992 
4993     static jmethodID mouseEventConst;


5003     }
5004     jobject target = GetTarget(env);
5005     DWORD curMousePos = ::GetMessagePos();
5006     int xAbs = GET_X_LPARAM(curMousePos);
5007     int yAbs = GET_Y_LPARAM(curMousePos);
5008     jobject mouseEvent = env->NewObject(mouseEventCls, mouseEventConst,
5009                                         target,
5010                                         id, when, modifiers,
5011                                         ScaleDownX(x + insets.left),
5012                                         ScaleDownY(y + insets.top),
5013                                         ScaleDownX(xAbs), ScaleDownY(yAbs),
5014                                         clickCount, popupTrigger, button);
5015 
5016     if (safe_ExceptionOccurred(env)) {
5017         env->ExceptionDescribe();
5018         env->ExceptionClear();
5019     }
5020 
5021     DASSERT(mouseEvent != NULL);
5022     CHECK_NULL(mouseEvent);




5023     if (pMsg != 0) {
5024         AwtAWTEvent::saveMSG(env, pMsg, mouseEvent);
5025     }
5026     SendEvent(mouseEvent);
5027 
5028     env->DeleteLocalRef(mouseEvent);
5029     env->DeleteLocalRef(target);
5030 }
5031 
5032 void
5033 AwtComponent::SendMouseWheelEvent(jint id, jlong when, jint x, jint y,
5034                                   jint modifiers, jint clickCount,
5035                                   jboolean popupTrigger, jint scrollType,
5036                                   jint scrollAmount, jint roundedWheelRotation,
5037                                   jdouble preciseWheelRotation, MSG *pMsg)
5038 {
5039     /* Code based not so loosely on AwtComponent::SendMouseEvent */
5040     JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
5041     CriticalSection::Lock l(GetLock());
5042     if (GetPeer(env) == NULL) {




 200 BOOL AwtComponent::sm_rtl = PRIMARYLANGID(GetInputLanguage()) == LANG_ARABIC ||
 201                             PRIMARYLANGID(GetInputLanguage()) == LANG_HEBREW;
 202 BOOL AwtComponent::sm_rtlReadingOrder =
 203     PRIMARYLANGID(GetInputLanguage()) == LANG_ARABIC;
 204 
 205 BOOL AwtComponent::sm_PrimaryDynamicTableBuilt = FALSE;
 206 
 207 HWND AwtComponent::sm_cursorOn;
 208 BOOL AwtComponent::m_QueryNewPaletteCalled = FALSE;
 209 
 210 CriticalSection windowMoveLock;
 211 BOOL windowMoveLockHeld = FALSE;
 212 
 213 /************************************************************************
 214  * AwtComponent methods
 215  */
 216 
 217 AwtComponent::AwtComponent()
 218 {
 219     m_mouseButtonClickAllowed = 0;
 220     m_touchDownOccurred = FALSE;
 221     m_touchUpOccurred = FALSE;
 222     m_touchDownPoint.x = m_touchDownPoint.y = 0;
 223     m_touchUpPoint.x = m_touchUpPoint.y = 0;
 224     m_callbacksEnabled = FALSE;
 225     m_hwnd = NULL;
 226 
 227     m_colorForeground = 0;
 228     m_colorBackground = 0;
 229     m_backgroundColorSet = FALSE;
 230     m_penForeground = NULL;
 231     m_brushBackground = NULL;
 232     m_DefWindowProc = NULL;
 233     m_nextControlID = 1;
 234     m_childList = NULL;
 235     m_myControlID = 0;
 236     m_hdwp = NULL;
 237     m_validationNestCount = 0;
 238 
 239     m_dropTarget = NULL;
 240 
 241     m_InputMethod = NULL;
 242     m_useNativeCompWindow = TRUE;
 243     m_PendingLeadByte = 0;


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


1705           case WM_RBUTTONUP:
1706               mr = WmMouseUp(static_cast<UINT>(wParam), myPos.x, myPos.y,
1707                              RIGHT_BUTTON);
1708               break;
1709           case WM_MBUTTONUP:
1710               mr = WmMouseUp(static_cast<UINT>(wParam), myPos.x, myPos.y,
1711                              MIDDLE_BUTTON);
1712               break;
1713           case WM_AWT_MOUSEEXIT:
1714               mr = WmMouseExit(static_cast<UINT>(wParam), myPos.x, myPos.y);
1715               break;
1716           case WM_MOUSEWHEEL:
1717           case WM_MOUSEHWHEEL:
1718               mr = WmMouseWheel(GET_KEYSTATE_WPARAM(wParam),
1719                                 GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam),
1720                                 GET_WHEEL_DELTA_WPARAM(wParam),
1721                                 switchMessage == WM_MOUSEHWHEEL);
1722               break;
1723           }
1724           break;
1725       case WM_TOUCH:
1726           WmTouch(wParam, lParam);
1727           break;
1728       case WM_SETCURSOR:
1729           mr = mrDoDefault;
1730           if (LOWORD(lParam) == HTCLIENT) {
1731               if (AwtComponent* comp =
1732                                     AwtComponent::GetComponent((HWND)wParam)) {
1733                   AwtCursor::UpdateCursor(comp);
1734                   mr = mrConsume;
1735               }
1736           }
1737           break;
1738 
1739       case WM_KEYDOWN:
1740           mr = WmKeyDown(static_cast<UINT>(wParam),
1741                          LOWORD(lParam), HIWORD(lParam), FALSE);
1742           break;
1743       case WM_KEYUP:
1744           mr = WmKeyUp(static_cast<UINT>(wParam),
1745                        LOWORD(lParam), HIWORD(lParam), FALSE);
1746           break;
1747       case WM_SYSKEYDOWN:


2290     msg->lParam = lParam;
2291     msg->time = ::GetMessageTime();
2292     msg->pt.x = x;
2293     msg->pt.y = y;
2294 }
2295 
2296 MsgRouting AwtComponent::WmNcMouseDown(WPARAM hitTest, int x, int y, int button) {
2297     return mrDoDefault;
2298 }
2299 MsgRouting AwtComponent::WmNcMouseUp(WPARAM hitTest, int x, int y, int button) {
2300     return mrDoDefault;
2301 }
2302 
2303 MsgRouting AwtComponent::WmWindowPosChanging(LPARAM windowPos) {
2304     return mrDoDefault;
2305 }
2306 MsgRouting AwtComponent::WmWindowPosChanged(LPARAM windowPos) {
2307     return mrDoDefault;
2308 }
2309 
2310 void AwtComponent::WmTouch(WPARAM wParam, LPARAM lParam) {
2311     AwtToolkit& tk = AwtToolkit::GetInstance();
2312     if (!tk.IsWin8OrLater() || !tk.IsTouchKeyboardAutoShowEnabled()) {
2313         return;
2314     }
2315 
2316     UINT inputsCount = LOWORD(wParam);
2317     TOUCHINPUT* pInputs = new TOUCHINPUT[inputsCount];
2318     if (pInputs != NULL) {
2319         if (tk.TIGetTouchInputInfo((HTOUCHINPUT)lParam, inputsCount, pInputs,
2320                 sizeof(TOUCHINPUT)) != 0) {
2321             for (UINT i = 0; i < inputsCount; i++) {
2322                 TOUCHINPUT ti = pInputs[i];
2323                 if (ti.dwFlags & TOUCHEVENTF_PRIMARY) {
2324                     if (ti.dwFlags & TOUCHEVENTF_DOWN) {
2325                         m_touchDownPoint.x = ti.x / 100;
2326                         m_touchDownPoint.y = ti.y / 100;
2327                         ::ScreenToClient(GetHWnd(), &m_touchDownPoint);
2328                         m_touchDownOccurred = TRUE;
2329                     } else if (ti.dwFlags & TOUCHEVENTF_UP) {
2330                         m_touchUpPoint.x = ti.x / 100;
2331                         m_touchUpPoint.y = ti.y / 100;
2332                         ::ScreenToClient(GetHWnd(), &m_touchUpPoint);
2333                         m_touchUpOccurred = TRUE;
2334                     }
2335                 }
2336             }
2337         }
2338         delete[] pInputs;
2339     }
2340 }
2341 
2342 /* Double-click variables. */
2343 static jlong multiClickTime = ::GetDoubleClickTime();
2344 static int multiClickMaxX = ::GetSystemMetrics(SM_CXDOUBLECLK);
2345 static int multiClickMaxY = ::GetSystemMetrics(SM_CYDOUBLECLK);
2346 static AwtComponent* lastClickWnd = NULL;
2347 static jlong lastTime = 0;
2348 static int lastClickX = 0;
2349 static int lastClickY = 0;
2350 static int lastButton = 0;
2351 static int clickCount = 0;
2352 
2353 // A static method that makes the clickCount available in the derived classes
2354 // overriding WmMouseDown().
2355 int AwtComponent::GetClickCount()
2356 {
2357     return clickCount;
2358 }
2359 
2360 MsgRouting AwtComponent::WmMouseDown(UINT flags, int x, int y, int button)
2361 {


2364     if (lastClickWnd == this &&
2365         lastButton == button &&
2366         (now - lastTime) <= multiClickTime &&
2367         abs(x - lastClickX) <= multiClickMaxX &&
2368         abs(y - lastClickY) <= multiClickMaxY)
2369     {
2370         clickCount++;
2371     } else {
2372         clickCount = 1;
2373         lastClickWnd = this;
2374         lastButton = button;
2375         lastClickX = x;
2376         lastClickY = y;
2377     }
2378     /*
2379      *Set appropriate bit of the mask on WM_MOUSE_DOWN message.
2380      */
2381     m_mouseButtonClickAllowed |= GetButtonMK(button);
2382     lastTime = now;
2383 
2384     BOOL causedByTouchEvent = FALSE;
2385     if (m_touchDownOccurred &&
2386         (abs(m_touchDownPoint.x - x) <= TOUCH_MOUSE_COORDS_DELTA) &&
2387         (abs(m_touchDownPoint.y - y) <= TOUCH_MOUSE_COORDS_DELTA)) {
2388         causedByTouchEvent = TRUE;
2389         m_touchDownOccurred = FALSE;
2390     }
2391 
2392     MSG msg;
2393     InitMessage(&msg, lastMessage, flags, MAKELPARAM(x, y), x, y);
2394 
2395     AwtWindow *toplevel = GetContainer();
2396     if (toplevel && !toplevel->IsSimpleWindow()) {
2397         /*
2398          * The frame should be focused by click in case it is
2399          * the active window but not the focused window. See 6886678.
2400          */
2401         if (toplevel->GetHWnd() == ::GetActiveWindow() &&
2402             toplevel->GetHWnd() != AwtComponent::GetFocusedWindow())
2403         {
2404             toplevel->AwtSetActiveWindow();
2405         }
2406     }
2407 
2408     SendMouseEvent(java_awt_event_MouseEvent_MOUSE_PRESSED, now, x, y,
2409                    GetJavaModifiers(), clickCount, JNI_FALSE,
2410                    GetButton(button), &msg, causedByTouchEvent);
2411     /*
2412      * NOTE: this call is intentionally placed after all other code,
2413      * since AwtComponent::WmMouseDown() assumes that the cached id of the
2414      * latest retrieved message (see lastMessage in awt_Component.cpp)
2415      * matches the mouse message being processed.
2416      * SetCapture() sends WM_CAPTURECHANGED and breaks that
2417      * assumption.
2418      */
2419     SetDragCapture(flags);
2420 
2421     AwtWindow * owner = (AwtWindow*)GetComponent(GetTopLevelParentForWindow(GetHWnd()));
2422     if (AwtWindow::GetGrabbedWindow() != NULL && owner != NULL) {
2423         if (!AwtWindow::GetGrabbedWindow()->IsOneOfOwnersOf(owner)) {
2424             AwtWindow::GetGrabbedWindow()->Ungrab();
2425         }
2426     }
2427     return mrConsume;
2428 }
2429 
2430 MsgRouting AwtComponent::WmMouseUp(UINT flags, int x, int y, int button)
2431 {
2432     BOOL causedByTouchEvent = FALSE;
2433     if (m_touchUpOccurred &&
2434         (abs(m_touchUpPoint.x - x) <= TOUCH_MOUSE_COORDS_DELTA) &&
2435         (abs(m_touchUpPoint.y - y) <= TOUCH_MOUSE_COORDS_DELTA)) {
2436         causedByTouchEvent = TRUE;
2437         m_touchUpOccurred = FALSE;
2438     }
2439 
2440     MSG msg;
2441     InitMessage(&msg, lastMessage, flags, MAKELPARAM(x, y), x, y);
2442 
2443     SendMouseEvent(java_awt_event_MouseEvent_MOUSE_RELEASED, ::JVM_CurrentTimeMillis(NULL, 0),
2444                    x, y, GetJavaModifiers(), clickCount,
2445                    (GetButton(button) == java_awt_event_MouseEvent_BUTTON3 ?
2446                     TRUE : FALSE), GetButton(button), &msg, causedByTouchEvent);
2447     /*
2448      * If no movement, then report a click following the button release.
2449      * When WM_MOUSEUP comes to a window without previous WM_MOUSEDOWN,
2450      * spurous MOUSE_CLICK is about to happen. See 6430553.
2451      */
2452     if ((m_mouseButtonClickAllowed & GetButtonMK(button)) != 0) { //CLICK allowed
2453         SendMouseEvent(java_awt_event_MouseEvent_MOUSE_CLICKED,
2454                        ::JVM_CurrentTimeMillis(NULL, 0), x, y, GetJavaModifiers(),
2455                        clickCount, JNI_FALSE, GetButton(button));
2456     }
2457     // Exclude button from allowed to generate CLICK messages
2458     m_mouseButtonClickAllowed &= ~GetButtonMK(button);
2459 
2460     if ((flags & ALL_MK_BUTTONS) == 0) {
2461         // only update if all buttons have been released
2462         AwtCursor::UpdateCursor(this);
2463     }
2464     /*
2465      * NOTE: this call is intentionally placed after all other code,
2466      * since AwtComponent::WmMouseUp() assumes that the cached id of the


5013 
5014 void AwtComponent::SetDragCapture(UINT flags)
5015 {
5016     // don't want to interfere with other controls
5017     if (::GetCapture() == NULL) {
5018         ::SetCapture(GetHWnd());
5019     }
5020 }
5021 
5022 void AwtComponent::ReleaseDragCapture(UINT flags)
5023 {
5024     if ((::GetCapture() == GetHWnd()) && ((flags & ALL_MK_BUTTONS) == 0)) {
5025         // user has released all buttons, so release the capture
5026         ::ReleaseCapture();
5027     }
5028 }
5029 
5030 void AwtComponent::SendMouseEvent(jint id, jlong when, jint x, jint y,
5031                                   jint modifiers, jint clickCount,
5032                                   jboolean popupTrigger, jint button,
5033                                   MSG *pMsg, BOOL causedByTouchEvent)
5034 {
5035     JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
5036     CriticalSection::Lock l(GetLock());
5037     if (GetPeer(env) == NULL) {
5038         /* event received during termination. */
5039         return;
5040     }
5041 
5042     static jclass mouseEventCls;
5043     if (mouseEventCls == NULL) {
5044         jclass mouseEventClsLocal =
5045             env->FindClass("java/awt/event/MouseEvent");
5046         CHECK_NULL(mouseEventClsLocal);
5047         mouseEventCls = (jclass)env->NewGlobalRef(mouseEventClsLocal);
5048         env->DeleteLocalRef(mouseEventClsLocal);
5049     }
5050     RECT insets;
5051     GetInsets(&insets);
5052 
5053     static jmethodID mouseEventConst;


5063     }
5064     jobject target = GetTarget(env);
5065     DWORD curMousePos = ::GetMessagePos();
5066     int xAbs = GET_X_LPARAM(curMousePos);
5067     int yAbs = GET_Y_LPARAM(curMousePos);
5068     jobject mouseEvent = env->NewObject(mouseEventCls, mouseEventConst,
5069                                         target,
5070                                         id, when, modifiers,
5071                                         ScaleDownX(x + insets.left),
5072                                         ScaleDownY(y + insets.top),
5073                                         ScaleDownX(xAbs), ScaleDownY(yAbs),
5074                                         clickCount, popupTrigger, button);
5075 
5076     if (safe_ExceptionOccurred(env)) {
5077         env->ExceptionDescribe();
5078         env->ExceptionClear();
5079     }
5080 
5081     DASSERT(mouseEvent != NULL);
5082     CHECK_NULL(mouseEvent);
5083     if (causedByTouchEvent) {
5084         env->SetBooleanField(mouseEvent, AwtMouseEvent::causedByTouchEventID,
5085             JNI_TRUE);
5086     }
5087     if (pMsg != 0) {
5088         AwtAWTEvent::saveMSG(env, pMsg, mouseEvent);
5089     }
5090     SendEvent(mouseEvent);
5091 
5092     env->DeleteLocalRef(mouseEvent);
5093     env->DeleteLocalRef(target);
5094 }
5095 
5096 void
5097 AwtComponent::SendMouseWheelEvent(jint id, jlong when, jint x, jint y,
5098                                   jint modifiers, jint clickCount,
5099                                   jboolean popupTrigger, jint scrollType,
5100                                   jint scrollAmount, jint roundedWheelRotation,
5101                                   jdouble preciseWheelRotation, MSG *pMsg)
5102 {
5103     /* Code based not so loosely on AwtComponent::SendMouseEvent */
5104     JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
5105     CriticalSection::Lock l(GetLock());
5106     if (GetPeer(env) == NULL) {


< prev index next >