Changeset 177 for trunk/src/plugins


Ignore:
Timestamp:
Aug 18, 2009, 3:19:00 PM (16 years ago)
Author:
lpino
Message:
  • Basic mouse event implementation
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/plugins/org.eclipse.swt/Eclipse SWT/pm/org/eclipse/swt/widgets/Control.java

    r176 r177  
    472472
    473473//@@TODO (dmik): debug code, remove when no more necessary
    474 //System.out.println (
    475 //    "Control.createHandle(): Window has been created:\n" +
    476 //    "    hwnd = " + Integer.toHexString (handle) + "\n" +
    477 //    "    hwnd.parent = hwnd.owner = " + Integer.toHexString (parent.handle) + "\n" +
    478 //    "    class = " + windowClass() + "\n" +
    479 //    "    style = " + Integer.toHexString (widgetStyle())
    480 //);
     474System.out.println (
     475    "Control.createHandle(): Window has been created:\n" +
     476    "    hwnd = " + Integer.toHexString (handle) + "\n" +
     477    "    hwnd.parent = hwnd.owner = " + Integer.toHexString (parent.handle) + "\n" +
     478    "    class = " + windowClass() + "\n" +
     479    "    style = " + Integer.toHexString (widgetStyle())
     480);
    481481
    482482//@@TODO(dmik): DBCS handling?
     
    17751775}
    17761776
    1777 //@@TODO(dmik): later
    1778 //boolean sendMouseEvent (int type, int button, int msg, int wParam, int lParam) {
    1779 //    Event event = new Event ();
    1780 //    event.button = button;
    1781 //    event.x = (short) (lParam & 0xFFFF);
    1782 //    event.y = (short) (lParam >> 16);
     1777boolean sendMouseEvent (int type, int button, int msg, int mp1, int mp2) {
     1778    Event event = new Event ();
     1779    event.button = button;
     1780    event.x = (short) (mp1 & 0xFFFF);
     1781    event.y = (short) (mp1 >> 16);
     1782    int keyState = mp2 >> 16;
     1783    //@@TODO(lpino): Remove debug
     1784    System.out.println("Control::sendMouseEvent -> X= " + event.x + " Y= " + event.y);
     1785    System.out.println("Control::sendMouseEvent -> MP2= " + Integer.toHexString(keyState));
    17831786//    if (OS.GetKeyState (OS.VK_MENU) < 0) event.stateMask |= SWT.ALT;
    1784 //    if ((wParam & OS.MK_SHIFT) != 0) event.stateMask |= SWT.SHIFT;
    1785 //    if ((wParam & OS.MK_CONTROL) != 0) event.stateMask |= SWT.CONTROL;
    1786 //    if ((wParam & OS.MK_LBUTTON) != 0) event.stateMask |= SWT.BUTTON1;
     1787    if ((keyState & OS.KC_SHIFT) != 0) event.stateMask |= SWT.SHIFT;
     1788    if ((keyState & OS.KC_CTRL) != 0) event.stateMask |= SWT.CONTROL;
     1789    if (button == 1) event.stateMask |= SWT.BUTTON1;
    17871790//    if ((wParam & OS.MK_MBUTTON) != 0) event.stateMask |= SWT.BUTTON2;
    17881791//    if ((wParam & OS.MK_RBUTTON) != 0) event.stateMask |= SWT.BUTTON3;
    1789 //    switch (type) {
    1790 //        case SWT.MouseDown:
    1791 //        case SWT.MouseDoubleClick:
    1792 //            if (button == 1) event.stateMask &= ~SWT.BUTTON1;
    1793 //            if (button == 2) event.stateMask &= ~SWT.BUTTON2;
    1794 //            if (button == 3) event.stateMask &= ~SWT.BUTTON3;
    1795 //            break;
    1796 //        case SWT.MouseUp:
    1797 //            if (button == 1) event.stateMask |= SWT.BUTTON1;
    1798 //            if (button == 2) event.stateMask |= SWT.BUTTON2;
    1799 //            if (button == 3) event.stateMask |= SWT.BUTTON3;
    1800 //            break;
    1801 //    }
    1802 //    return sendMouseEvent (type, msg, wParam, lParam, event);
    1803 //}
    1804 
    1805 //@@TODO(dmik)
    1806 //boolean sendMouseEvent (int type, int msg, int wParam, int lParam, Event event) {
    1807 //    postEvent (type, event);
    1808 //    return true;
    1809 //}
     1792    switch (type) {
     1793        case SWT.MouseDown:
     1794        case SWT.MouseDoubleClick:
     1795            if (button == 1) event.stateMask &= ~SWT.BUTTON1;
     1796            if (button == 2) event.stateMask &= ~SWT.BUTTON2;
     1797            if (button == 3) event.stateMask &= ~SWT.BUTTON3;
     1798            break;
     1799        case SWT.MouseUp:
     1800            if (button == 1) event.stateMask |= SWT.BUTTON1;
     1801            if (button == 2) event.stateMask |= SWT.BUTTON2;
     1802            if (button == 3) event.stateMask |= SWT.BUTTON3;
     1803            break;
     1804    }
     1805    return sendMouseEvent (type, msg, mp1, mp2, event);
     1806}
     1807
     1808
     1809boolean sendMouseEvent (int type, int msg, int wParam, int lParam, Event event) {
     1810    postEvent (type, event);
     1811    return true;
     1812}
    18101813
    18111814/**
     
    29452948//        case OS.WM_ADJUSTWINDOWPOS: result = WM_ADJUSTWINDOWPOS (mp1, mp2); break;
    29462949//        case OS.WM_BUTTON2DBLCLK: result = WM_BUTTON2DBLCLK (mp1, mp2); break;
     2950        case OS.WM_BUTTON1DOWN: result = WM_BUTTON1DOWN (mp1, mp2); break;
     2951//        case OS.WM_BUTTON1UP: result = WM_BUTTON1UP (mp1, mp2); break;
     2952//        case OS.WM_BUTTON1CLICK: result = WM_BUTTON1CLICK (mp1, mp2); break;
    29472953        case OS.WM_CALCVALIDRECTS: result = WM_CALCVALIDRECTS (mp1, mp2); break;
    29482954        case OS.WM_CHAR: result = WM_CHAR (mp1, mp2); break;
     
    29782984//        case OS.WM_KEYDOWN: result = WM_KEYDOWN (wParam, lParam); break;
    29792985//        case OS.WM_KEYUP: result = WM_KEYUP (wParam, lParam); break;
    2980 //        case OS.WM_LBUTTONDBLCLK: result = WM_LBUTTONDBLCLK (wParam, lParam); break;
     2986        case OS.WM_BUTTON1DBLCLK: result = WM_BUTTON1DBLCLK (mp1, mp2); break;
    29812987//        case OS.WM_LBUTTONDOWN: result = WM_LBUTTONDOWN (wParam, lParam); break;
    29822988//        case OS.WM_LBUTTONUP: result = WM_LBUTTONUP (wParam, lParam); break;
     
    33213327
    33223328//@@TODO (dmik): later
    3323 //LRESULT WM_LBUTTONDBLCLK (int wParam, int lParam) {
    3324 //      /*
    3325 //      * Feature in Windows. Windows sends the following
    3326 //      * messages when the user double clicks the mouse:
    3327 //      *
    3328 //      *       WM_LBUTTONDOWN          - mouse down
    3329 //      *       WM_LBUTTONUP            - mouse up
    3330 //      *       WM_LBUTTONDBLCLK        - double click
    3331 //      *       WM_LBUTTONUP            - mouse up
    3332 //      *
    3333 //      * Applications that expect matching mouse down/up
    3334 //      * pairs will not see the second mouse down.  The
    3335 //      * fix is to send a mouse down event.
    3336 //      */
     3329MRESULT WM_BUTTON1DBLCLK (int mp1, int mp2) {
     3330      /*
     3331      * Feature in Windows. Windows sends the following
     3332      * messages when the user double clicks the mouse:
     3333      *
     3334      *       WM_LBUTTONDOWN          - mouse down
     3335      *       WM_LBUTTONUP            - mouse up
     3336      *       WM_LBUTTONDBLCLK        - double click
     3337      *       WM_LBUTTONUP            - mouse up
     3338      *
     3339      * Applications that expect matching mouse down/up
     3340      * pairs will not see the second mouse down.  The
     3341      * fix is to send a mouse down event.
     3342      */
    33373343//      sendMouseEvent (SWT.MouseDown, 1, OS.WM_LBUTTONDOWN, wParam, lParam);
    3338 //      sendMouseEvent (SWT.MouseDoubleClick, 1, OS.WM_LBUTTONDBLCLK, wParam, lParam);
    3339 //      int result = callWindowProc (OS.WM_LBUTTONDBLCLK, wParam, lParam);
    3340 //      if (OS.GetCapture () != handle) OS.SetCapture (handle);
    3341 //      return new LRESULT (result);
    3342 //}
    3343 //
    3344 //LRESULT WM_LBUTTONDOWN (int wParam, int lParam) {
    3345 //      boolean dragging = false, mouseDown = true;
     3344      sendMouseEvent (SWT.MouseDoubleClick, 1, OS.WM_BUTTON1DBLCLK, mp1, mp2);
     3345      int result = callWindowProc (OS.WM_BUTTON1DBLCLK, mp1, mp2);
     3346      if (OS.WinQueryCapture (OS.HWND_DESKTOP) != handle) OS.WinSetCapture (OS.HWND_DESKTOP, handle);
     3347      return new MRESULT (result);
     3348}
     3349
     3350MRESULT WM_BUTTON1DOWN (int mp1, int mp2) {
     3351      boolean dragging = false, mouseDown = true;
    33463352//      if (hooks (SWT.DragDetect)) {
    33473353//              POINT pt = new POINT ();
     
    33613367//              }
    33623368//      }
    3363 //      sendMouseEvent (SWT.MouseDown, 1, OS.WM_LBUTTONDOWN, wParam, lParam);
    3364 //      int result = callWindowProc (OS.WM_LBUTTONDOWN, wParam, lParam);
    3365 //      if (mouseDown) {
    3366 //              if (OS.GetCapture () != handle) OS.SetCapture (handle);
    3367 //      }
     3369      sendMouseEvent (SWT.MouseDown, 1, OS.WM_BUTTON1DOWN, mp1, mp2);
     3370//      int result = callWindowProc (OS.WM_BUTTON1DOWN, mp1, mp2);
     3371      int result = 0;
     3372      if (mouseDown) {
     3373          int hwnd = OS.WinQueryCapture (OS.HWND_DESKTOP);
     3374          int hwnd2 = OS.WinQueryWindow(handle, OS.QW_PARENT);
     3375          int hwnd3 = OS.WinQueryActiveWindow(OS.HWND_DESKTOP);
     3376          System.out.println("Control::WM_BUTTON1DOWN -> Window = " + Integer.toHexString(handle) + " Window Activa = " + Integer.toHexString(hwnd) + " Padre = " + Integer.toHexString(hwnd2));
     3377              if (OS.WinQueryCapture (OS.HWND_DESKTOP) != handle){
     3378                  OS.WinSetCapture (OS.HWND_DESKTOP, handle);
     3379              }
     3380              if(OS.WinQueryWindow(handle, OS.QW_PARENT) == OS.WinQueryActiveWindow(OS.HWND_DESKTOP)){
     3381                  System.out.println("Control::WM_BUTTON1DOWN");
     3382              }
     3383//              OS.WinSetActiveWindow (OS.HWND_DESKTOP, handle);
     3384      }
    33683385//      if (dragging) {
    33693386//              postEvent (SWT.DragDetect);
     
    33953412//              }
    33963413//      }
    3397 //      return new LRESULT (result);
    3398 //}
    3399 //
     3414      return new MRESULT (result);
     3415}
     3416
    34003417//LRESULT WM_LBUTTONUP (int wParam, int lParam) {
    34013418//      sendMouseEvent (SWT.MouseUp, 1, OS.WM_LBUTTONUP, wParam, lParam);
    34023419//      int result = callWindowProc (OS.WM_LBUTTONUP, wParam, lParam);
    34033420//      if ((wParam & (OS.MK_LBUTTON | OS.MK_MBUTTON | OS.MK_RBUTTON)) == 0) {
    3404 //              if (OS.GetCapture () == handle) OS.ReleaseCapture ();
     3421//              if (OS.WinQueryCapture () == handle) OS.ReleaseCapture ();
    34053422//      }
    34063423//      return new LRESULT (result);
Note: See TracChangeset for help on using the changeset viewer.