home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ctlcpp.zip / IMMOVEVT.CPP < prev    next >
C/C++ Source or Header  |  1994-06-06  |  7KB  |  172 lines

  1. /***************************************************************/
  2. /* Filename: immovevt.cpp                                      */
  3. /*                                                             */
  4. /* Purpose: Definition of the IMouseMoveEvent class. These     */
  5. /*          classes encapsulates several different types of    */
  6. /*          mouse movement events, including WM_MOUSEMOVE,     */
  7. /*          WM_CONTROLPOINTER, WM_BEGIN/ENDDRAG, and           */
  8. /*          WM_BEGIN/ENDSELECT. An associated class is         */
  9. /*          IMouseMoveHandler.                                 */
  10. /*                                                             */
  11. /* Program name: cppctl.exe     Title: C++ PM Control Test App */
  12. /* OS/2 Developer Magazine, Issue: Sept. '94, page             */
  13. /* Article title: Writing OS/2 PM Controls in C++              */
  14. /* Authors: Eric Snell and Lori Ruffing                        */
  15. /*                                                             */
  16. /* Description: This example shows how to implement an OS/2 PM */
  17. /*              control window in C++.                         */
  18. /*                                                             */
  19. /* Program Requirements: This example requires the IBM C Set++ */
  20. /*                       compiler and libraries.               */
  21. /***************************************************************/
  22. extern "C"
  23.    {
  24.    #define INCL_WININPUT
  25.    #define INCL_WINMESSAGEMGR
  26.    #define INCL_WINPOINTERS
  27.    #include <os2.h>
  28.    }
  29.  
  30. #include "immovevt.hpp"
  31.  
  32. IMouseMoveEvent::IMouseMoveEvent(IEvent &evt)
  33.    : IEvent(evt)
  34.    {
  35.    }
  36.  
  37. IMouseMoveEvent::~IMouseMoveEvent()
  38.    {
  39.    }
  40.  
  41. //----------------------------------------------------------------------------
  42. // Method: IMouseMoveEvent::pointerPosition
  43. //
  44. // Description: 'pointerPosition' returns the x/y coordinate of the pointer
  45. //               at the time the mouse move event occurred.
  46. //----------------------------------------------------------------------------
  47. IPoint IMouseMoveEvent::pointerPosition() const
  48.    {
  49.    return IPoint(parameter1().lowNumber(), parameter1().highNumber());
  50.    }
  51.  
  52. //----------------------------------------------------------------------------
  53. // Method: IMouseMoveEvent::hitTest
  54. //
  55. // Description: 'hitTest' returns 0 if a pointing device capture is
  56. //              currently in progress, otherewise returns the result
  57. //              of the WM_HITTEST message.
  58. //----------------------------------------------------------------------------
  59. IMouseMoveEvent::HitTest IMouseMoveEvent::hitTest() const
  60.    {
  61.    return IMouseMoveEvent::HitTest(parameter2().lowNumber());
  62.    }
  63.  
  64. //----------------------------------------------------------------------------
  65. // Method: IMouseMoveEvent::keyCodes
  66. //
  67. // Description: 'keyCodes' returns the keyboard control code, which reflects
  68. //              the keyboard state at the time the mouse move was initiated.
  69. //----------------------------------------------------------------------------
  70. unsigned short IMouseMoveEvent::keyCodes() const
  71.    {
  72.    return parameter2().highNumber();
  73.    }
  74.  
  75. //----------------------------------------------------------------------------
  76. // Method: IMouseMoveEvent::currentPointerPosition
  77. //
  78. // Description: 'currentPointerPosition' returns the x/y coordinate of the
  79. //               pointer at the time the method is invoked.
  80. //
  81. // Notes: The value returned by this method can be different (more current)
  82. //        than the value returned by the pointerPosition method.
  83. //        This method is static so can be called anytime.
  84. //----------------------------------------------------------------------------
  85. IPoint IMouseMoveEvent::currentPointerPosition()
  86.    {
  87.    POINTL ptl = {0, 0};
  88.    WinQueryPointerPos(HWND_DESKTOP, &ptl);
  89.    return IPoint(ptl);
  90.    }
  91.  
  92. IControlPointerEvent::IControlPointerEvent(IEvent &evt)
  93.    : IEvent(evt)
  94.    {
  95.    }
  96.  
  97. IControlPointerEvent::~IControlPointerEvent()
  98.    {
  99.    }
  100.  
  101. //----------------------------------------------------------------------------
  102. // Method: IControlPointerEvent::pointerOverId
  103. //
  104. // Description: 'pointerOverId' returns the id of the control the pointer
  105. //              is over.
  106. //----------------------------------------------------------------------------
  107. unsigned long IControlPointerEvent::pointerOverId() const
  108.    {
  109.    return parameter1();
  110.    }
  111.  
  112. //----------------------------------------------------------------------------
  113. // Method: IControlPointerEvent::currentPointer
  114. //
  115. // Description: 'currentPointer' returns the current pointer handle.
  116. //----------------------------------------------------------------------------
  117. IPointerHandle IControlPointerEvent::currentPointer() const
  118.    {
  119.    return IPointerHandle(parameter2());
  120.    }
  121.  
  122. //----------------------------------------------------------------------------
  123. // Method: IControlPointerEvent::setNewPointer
  124. //
  125. // Description: 'setNewPointer' sets the pointer to 'ptrHandle'.
  126. //----------------------------------------------------------------------------
  127. Boolean IControlPointerEvent::setNewPointer(const IPointerHandle &ptrHandle)
  128.    {
  129.    setResult(IEventResult((unsigned long)ptrHandle));
  130.    return true;
  131.    }
  132.  
  133. IMouseDragSelectEvent::IMouseDragSelectEvent(IEvent &evt)
  134.    : IEvent(evt)
  135.    {
  136.    }
  137.  
  138. IMouseDragSelectEvent::~IMouseDragSelectEvent()
  139.    {
  140.    }
  141.  
  142. //----------------------------------------------------------------------------
  143. // Method: IMouseDragSelectEvent::pointerInitiated
  144. //
  145. // Description: 'pointerInitiated' returns true if the pointer is being
  146. //              dragged into the window, false otherwise.
  147. //----------------------------------------------------------------------------
  148. Boolean IMouseDragSelectEvent::pointerInitiated() const
  149.    {
  150.    return !parameter2().asUnsignedLong();
  151.    }
  152.  
  153. //----------------------------------------------------------------------------
  154. // Method: IMouseDragSelectEvent::pointerPosition
  155. //
  156. // Description: 'pointerPosition' returns the x/y coordinate of the pointer
  157. //               at the time the mouse drag event occurred.
  158. //----------------------------------------------------------------------------
  159. IPoint IMouseDragSelectEvent::pointerPosition() const
  160.    {
  161.    // If pointer is being dragged into the window, return those
  162.    // coordinates, otherwise return (0,0).
  163.    if (pointerInitiated())
  164.       {
  165.       return IPoint(parameter1().lowNumber(), parameter1().highNumber());
  166.       }
  167.    else
  168.       return IPoint();
  169.    }
  170.  
  171.  
  172.