home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / powergui / thread / userevt / userevt.cpp < prev    next >
Text File  |  1996-10-29  |  5KB  |  127 lines

  1. /***************************************************************
  2. * FILE NAME: userevt.cpp                                       *
  3. *                                                              *
  4. * DESCRIPTION:                                                 *
  5. *   This file contains the implementation of                   *
  6. *   classes/functions declared in userevt.hpp.                 *
  7. *                                                              *
  8. * COPYRIGHT:                                                   *
  9. *   Licensed Materials - Property of Solution Frameworks       *
  10. *   Copyright (C) 1996, Solution Frameworks                    *
  11. *   All Rights Reserved                                        *
  12. ***************************************************************/
  13. #ifdef __OS2__
  14. #define INCL_PM
  15. #include <os2.h>
  16. #else
  17. #include <windows.h>
  18. #endif
  19.  
  20. #include <iwindow.hpp>
  21.  
  22. #include "userevt.hpp"
  23.  
  24. /*------------------- UserEvent::UserEvent ---------------------
  25. | The constructors just pass the arguments to the base         |
  26. | class's constructor.                                         |
  27. --------------------------------------------------------------*/
  28. UserEvent :: UserEvent ( unsigned int            id,
  29.                          const IEventParameter1 &mp1,
  30.                          const IEventParameter2 &mp2 ) 
  31.   : IEvent( IWindowHandle( 0 ), baseId() + id, mp1, mp2 ) {
  32. }
  33.  
  34. UserEvent :: UserEvent ( const IEvent &genericEvent )
  35.   : IEvent( genericEvent ) {
  36. }
  37.  
  38. UserEvent :: ~UserEvent ( ) {
  39. }
  40.  
  41. /*------------------ UserEvent::userEventId --------------------
  42. | Map the event identifier to the system-independent portion   |
  43. | by subtracting the system-dependent base value.              |
  44. --------------------------------------------------------------*/
  45. unsigned long UserEvent :: userEventId ( ) const {
  46.   return this->eventId() - baseId();
  47. }
  48.  
  49. /*-------------------- UserEvent::postTo -----------------------
  50. | Post the event to the argument window handle.                |
  51. --------------------------------------------------------------*/
  52. void UserEvent :: postTo ( const IWindow &window ) const {
  53.   postTo( window.handle() );
  54. }
  55. void UserEvent :: postTo ( const IWindowHandle &window ) const {
  56.   window.postEvent( eventId(), parameter1(), parameter2() );
  57. }
  58.  
  59. /*-------------------- UserEvent::sendTo -----------------------
  60. | Send the event to the argument window handle.                |
  61. --------------------------------------------------------------*/
  62. unsigned long 
  63.   UserEvent :: sendTo ( const IWindow &window ) const {
  64.   return sendTo( window.handle() );
  65. }
  66. unsigned long 
  67.   UserEvent :: sendTo ( const IWindowHandle &window ) const {
  68.   return window.sendEvent( eventId(), 
  69.                            parameter1(), 
  70.                            parameter2() );
  71. }
  72.  
  73. /*-------------------- UserEvent::baseId -----------------------
  74. | On OS/2, use WM_USER.                                        |
  75. | On Windows, use WM_USER + 500 (Windows itself uses some in   |
  76. | the range WM_USER to WM_USER+500).                           |
  77. --------------------------------------------------------------*/
  78. unsigned long UserEvent :: baseId ( ) {
  79.   #ifdef __OS2__
  80.     return WM_USER;
  81.   #else
  82.     return WM_USER + 500;
  83.   #endif
  84. }
  85.  
  86. /*----------------- UserHandler::UserHandler -------------------
  87. | Set the handler's low/high event identifiers.                |
  88. --------------------------------------------------------------*/
  89. UserHandler :: UserHandler ( unsigned long id )
  90.   : low( UserEvent::baseId() + id ),
  91.     high( UserEvent::baseId() + id ) {
  92. }
  93.  
  94. UserHandler :: UserHandler ( unsigned long low, unsigned long high )
  95.   : low( UserEvent::baseId() + low ),
  96.     high( UserEvent::baseId() + high ) {
  97. }
  98.  
  99. UserHandler :: ~UserHandler ( ) {
  100. }
  101.  
  102. /*--------------- UserHandler::handleUserEvent -----------------
  103. | Default implementation simply returns false.  Derived        |
  104. | class must override this function.                           |
  105. --------------------------------------------------------------*/
  106. Boolean UserHandler :: handleUserEvent( UserEvent &event ) {
  107.   return false;
  108. }
  109.  
  110. /*------------ UserHandler::dispatchHandlerEvent ---------------
  111. | If the event identifier is in the range of interest to this  |
  112. | handler, call the handleUserEvent member function.           |
  113. --------------------------------------------------------------*/
  114. Boolean UserHandler :: dispatchHandlerEvent ( IEvent &event ) {
  115.   Boolean
  116.     result = false;
  117.   if ( event.eventId() >= low
  118.        &&
  119.        event.eventId() <= high ) {
  120.     UserEvent
  121.       userEvent( event );
  122.     result = handleUserEvent( userEvent );
  123.     event.setResult( userEvent.result() );
  124.   }
  125.   return result;
  126. }
  127.