< prev index next >

src/windows/native/sun/windows/awt_Component.cpp

Print this page




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




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


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





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


1683                                RIGHT_BUTTON);
1684               break;
1685           case WM_RBUTTONUP:
1686               mr = WmMouseUp(static_cast<UINT>(wParam), myPos.x, myPos.y,
1687                              RIGHT_BUTTON);
1688               break;
1689           case WM_MBUTTONUP:
1690               mr = WmMouseUp(static_cast<UINT>(wParam), myPos.x, myPos.y,
1691                              MIDDLE_BUTTON);
1692               break;
1693           case WM_AWT_MOUSEEXIT:
1694               mr = WmMouseExit(static_cast<UINT>(wParam), myPos.x, myPos.y);
1695               break;
1696           case  WM_MOUSEWHEEL:
1697               mr = WmMouseWheel(GET_KEYSTATE_WPARAM(wParam),
1698                                 GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam),
1699                                 GET_WHEEL_DELTA_WPARAM(wParam));
1700               break;
1701           }
1702           break;



1703       case WM_SETCURSOR:
1704           mr = mrDoDefault;
1705           if (LOWORD(lParam) == HTCLIENT) {
1706               if (AwtComponent* comp =
1707                                     AwtComponent::GetComponent((HWND)wParam)) {
1708                   AwtCursor::UpdateCursor(comp);
1709                   mr = mrConsume;
1710               }
1711           }
1712           break;
1713 
1714       case WM_KEYDOWN:
1715           mr = WmKeyDown(static_cast<UINT>(wParam),
1716                          LOWORD(lParam), HIWORD(lParam), FALSE);
1717           break;
1718       case WM_KEYUP:
1719           mr = WmKeyUp(static_cast<UINT>(wParam),
1720                        LOWORD(lParam), HIWORD(lParam), FALSE);
1721           break;
1722       case WM_SYSKEYDOWN:


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
































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


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








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








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


4877 
4878 void AwtComponent::SetDragCapture(UINT flags)
4879 {
4880     // don't want to interfere with other controls
4881     if (::GetCapture() == NULL) {
4882         ::SetCapture(GetHWnd());
4883     }
4884 }
4885 
4886 void AwtComponent::ReleaseDragCapture(UINT flags)
4887 {
4888     if ((::GetCapture() == GetHWnd()) && ((flags & ALL_MK_BUTTONS) == 0)) {
4889         // user has released all buttons, so release the capture
4890         ::ReleaseCapture();
4891     }
4892 }
4893 
4894 void AwtComponent::SendMouseEvent(jint id, jlong when, jint x, jint y,
4895                                   jint modifiers, jint clickCount,
4896                                   jboolean popupTrigger, jint button,
4897                                   MSG *pMsg)
4898 {
4899     JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
4900     CriticalSection::Lock l(GetLock());
4901     if (GetPeer(env) == NULL) {
4902         /* event received during termination. */
4903         return;
4904     }
4905 
4906     static jclass mouseEventCls;
4907     if (mouseEventCls == NULL) {
4908         jclass mouseEventClsLocal =
4909             env->FindClass("java/awt/event/MouseEvent");
4910         CHECK_NULL(mouseEventClsLocal);
4911         mouseEventCls = (jclass)env->NewGlobalRef(mouseEventClsLocal);
4912         env->DeleteLocalRef(mouseEventClsLocal);
4913     }
4914     RECT insets;
4915     GetInsets(&insets);
4916 
4917     static jmethodID mouseEventConst;


4926         return;
4927     }
4928     jobject target = GetTarget(env);
4929     DWORD curMousePos = ::GetMessagePos();
4930     int xAbs = GET_X_LPARAM(curMousePos);
4931     int yAbs = GET_Y_LPARAM(curMousePos);
4932     jobject mouseEvent = env->NewObject(mouseEventCls, mouseEventConst,
4933                                         target,
4934                                         id, when, modifiers,
4935                                         x+insets.left, y+insets.top,
4936                                         xAbs, yAbs,
4937                                         clickCount, popupTrigger, button);
4938 
4939     if (safe_ExceptionOccurred(env)) {
4940         env->ExceptionDescribe();
4941         env->ExceptionClear();
4942     }
4943 
4944     DASSERT(mouseEvent != NULL);
4945     CHECK_NULL(mouseEvent);




4946     if (pMsg != 0) {
4947         AwtAWTEvent::saveMSG(env, pMsg, mouseEvent);
4948     }
4949     SendEvent(mouseEvent);
4950 
4951     env->DeleteLocalRef(mouseEvent);
4952     env->DeleteLocalRef(target);
4953 }
4954 
4955 void
4956 AwtComponent::SendMouseWheelEvent(jint id, jlong when, jint x, jint y,
4957                                   jint modifiers, jint clickCount,
4958                                   jboolean popupTrigger, jint scrollType,
4959                                   jint scrollAmount, jint roundedWheelRotation,
4960                                   jdouble preciseWheelRotation, MSG *pMsg)
4961 {
4962     /* Code based not so loosely on AwtComponent::SendMouseEvent */
4963     JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
4964     CriticalSection::Lock l(GetLock());
4965     if (GetPeer(env) == NULL) {




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


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


1692                                RIGHT_BUTTON);
1693               break;
1694           case WM_RBUTTONUP:
1695               mr = WmMouseUp(static_cast<UINT>(wParam), myPos.x, myPos.y,
1696                              RIGHT_BUTTON);
1697               break;
1698           case WM_MBUTTONUP:
1699               mr = WmMouseUp(static_cast<UINT>(wParam), myPos.x, myPos.y,
1700                              MIDDLE_BUTTON);
1701               break;
1702           case WM_AWT_MOUSEEXIT:
1703               mr = WmMouseExit(static_cast<UINT>(wParam), myPos.x, myPos.y);
1704               break;
1705           case  WM_MOUSEWHEEL:
1706               mr = WmMouseWheel(GET_KEYSTATE_WPARAM(wParam),
1707                                 GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam),
1708                                 GET_WHEEL_DELTA_WPARAM(wParam));
1709               break;
1710           }
1711           break;
1712       case WM_TOUCH:
1713           WmTouch(wParam, lParam);
1714           break;
1715       case WM_SETCURSOR:
1716           mr = mrDoDefault;
1717           if (LOWORD(lParam) == HTCLIENT) {
1718               if (AwtComponent* comp =
1719                                     AwtComponent::GetComponent((HWND)wParam)) {
1720                   AwtCursor::UpdateCursor(comp);
1721                   mr = mrConsume;
1722               }
1723           }
1724           break;
1725 
1726       case WM_KEYDOWN:
1727           mr = WmKeyDown(static_cast<UINT>(wParam),
1728                          LOWORD(lParam), HIWORD(lParam), FALSE);
1729           break;
1730       case WM_KEYUP:
1731           mr = WmKeyUp(static_cast<UINT>(wParam),
1732                        LOWORD(lParam), HIWORD(lParam), FALSE);
1733           break;
1734       case WM_SYSKEYDOWN:


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


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


4937 
4938 void AwtComponent::SetDragCapture(UINT flags)
4939 {
4940     // don't want to interfere with other controls
4941     if (::GetCapture() == NULL) {
4942         ::SetCapture(GetHWnd());
4943     }
4944 }
4945 
4946 void AwtComponent::ReleaseDragCapture(UINT flags)
4947 {
4948     if ((::GetCapture() == GetHWnd()) && ((flags & ALL_MK_BUTTONS) == 0)) {
4949         // user has released all buttons, so release the capture
4950         ::ReleaseCapture();
4951     }
4952 }
4953 
4954 void AwtComponent::SendMouseEvent(jint id, jlong when, jint x, jint y,
4955                                   jint modifiers, jint clickCount,
4956                                   jboolean popupTrigger, jint button,
4957                                   MSG *pMsg, BOOL causedByTouchEvent)
4958 {
4959     JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
4960     CriticalSection::Lock l(GetLock());
4961     if (GetPeer(env) == NULL) {
4962         /* event received during termination. */
4963         return;
4964     }
4965 
4966     static jclass mouseEventCls;
4967     if (mouseEventCls == NULL) {
4968         jclass mouseEventClsLocal =
4969             env->FindClass("java/awt/event/MouseEvent");
4970         CHECK_NULL(mouseEventClsLocal);
4971         mouseEventCls = (jclass)env->NewGlobalRef(mouseEventClsLocal);
4972         env->DeleteLocalRef(mouseEventClsLocal);
4973     }
4974     RECT insets;
4975     GetInsets(&insets);
4976 
4977     static jmethodID mouseEventConst;


4986         return;
4987     }
4988     jobject target = GetTarget(env);
4989     DWORD curMousePos = ::GetMessagePos();
4990     int xAbs = GET_X_LPARAM(curMousePos);
4991     int yAbs = GET_Y_LPARAM(curMousePos);
4992     jobject mouseEvent = env->NewObject(mouseEventCls, mouseEventConst,
4993                                         target,
4994                                         id, when, modifiers,
4995                                         x+insets.left, y+insets.top,
4996                                         xAbs, yAbs,
4997                                         clickCount, popupTrigger, button);
4998 
4999     if (safe_ExceptionOccurred(env)) {
5000         env->ExceptionDescribe();
5001         env->ExceptionClear();
5002     }
5003 
5004     DASSERT(mouseEvent != NULL);
5005     CHECK_NULL(mouseEvent);
5006     if (causedByTouchEvent) {
5007         env->SetBooleanField(mouseEvent, AwtMouseEvent::causedByTouchEventID,
5008             JNI_TRUE);
5009     }
5010     if (pMsg != 0) {
5011         AwtAWTEvent::saveMSG(env, pMsg, mouseEvent);
5012     }
5013     SendEvent(mouseEvent);
5014 
5015     env->DeleteLocalRef(mouseEvent);
5016     env->DeleteLocalRef(target);
5017 }
5018 
5019 void
5020 AwtComponent::SendMouseWheelEvent(jint id, jlong when, jint x, jint y,
5021                                   jint modifiers, jint clickCount,
5022                                   jboolean popupTrigger, jint scrollType,
5023                                   jint scrollAmount, jint roundedWheelRotation,
5024                                   jdouble preciseWheelRotation, MSG *pMsg)
5025 {
5026     /* Code based not so loosely on AwtComponent::SendMouseEvent */
5027     JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
5028     CriticalSection::Lock l(GetLock());
5029     if (GetPeer(env) == NULL) {


< prev index next >