home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ontophan.zip / OnTopHandler.hpp < prev    next >
Text File  |  1998-09-07  |  4KB  |  127 lines

  1. #ifndef OnTopHandler_HPP
  2. #define OnTopHandler_HPP
  3.  
  4. #define INCL_WINMESSAGEMGR // required for WinSetVisibleRegionNotify
  5. #include <os2.h>           // OS/2
  6. #include <ihandler.hpp>    // IHandler
  7.  
  8. /* class OnTopHandler
  9.  *
  10.  * written by Stéphane Charette
  11.  * v1.0  17 August 1998 - initial version
  12.  * v1.0a 18 August 1998 - fixed recursion problem
  13.  * v1.0b 7 September 1998 - fixed redraw problem and
  14.  *             implemented ::frameWindowNeedsUpdate()
  15.  *
  16.  * based in part on code by William Law available at:
  17.  *    http://people.netscape.com/law/samples/index.html
  18.  *
  19.  * PURPOSE:       handle the necessary event to ensure that a window can
  20.  *                remain at the top of the Z-order; as a result, any window
  21.  *                whose messages are handled by this handler will always
  22.  *                remain "on top" of other windows, even when it isn't the
  23.  *                active window
  24.  *
  25.  * REQUIREMENTS:  IBM VisualAge C++ version 3.0+ for OS/2 Warp version 4.0+
  26.  *                (may also work with Warp 3 -- untested)
  27.  *
  28.  * USAGE:         (see the file OnTopHandler.cpp)
  29.  *                ...
  30.  *                IFrameWindow frame;
  31.  *                OnTopHandler handler;
  32.  *                handler.handleEventsFor( &frame );
  33.  *                ...
  34.  *                handler.stopHandlingEventsFor( &frame );
  35.  *                ...
  36.  *
  37.  * NOTE:          Derived classes that need to perform their own actions when
  38.  *                a frame window is about to be covered over can choose to
  39.  *                overload the method:
  40.  *
  41.  *                   virtual Boolean frameWindowNeedsUpdate( IEvent &event )
  42.  *
  43.  *                This method is called when a window needs to have its z-order
  44.  *                raised to remain "on top".  To get the frame window from the
  45.  *                event, use:
  46.  *
  47.  *                   event.dispatchingWindow()
  48.  *
  49.  *                Unless you also take care of screen redraw, you'll most
  50.  *                likely want to return "false" to ensure OS/2 correctly
  51.  *                redraws the screen.
  52.  */
  53. class OnTopHandler : public IHandler
  54. {
  55.    public:
  56.  
  57.       // start handling events for the specified frame window
  58.       virtual IHandler &handleEventsFor( IWindow *frame )
  59.       {
  60.          // make certain the window is a frame window
  61.          if( frame->isFrameWindow() )
  62.          {
  63.             // start the OCL event handling
  64.             IHandler::handleEventsFor( frame );
  65.  
  66.             // call the PM function to enable the WM_VRNENABLED message
  67.             WinSetVisibleRegionNotify( frame->handle(), true );
  68.          }
  69.          return *this;
  70.       }
  71.  
  72.       // stop handling events for the specified frame window
  73.       virtual IHandler &stopHandlingEventsFor( IWindow *frame )
  74.       {
  75.          // make certain the window is a frame window
  76.          if( frame->isFrameWindow() )
  77.          {
  78.             // call the PM function to disable the WM_VRNENABLED message
  79.             WinSetVisibleRegionNotify( frame->handle(), false );
  80.  
  81.             // stop the OCL event handling
  82.             IHandler::stopHandlingEventsFor( frame );
  83.          }
  84.          return *this;
  85.       }
  86.  
  87.    protected:
  88.  
  89.       // handle the event and put the frame window back on top
  90.       virtual Boolean frameWindowNeedsUpdate( IEvent &event )
  91.       {
  92.          // disable event processing (to prevent recursion)
  93.          disable();
  94.  
  95.          // put the window at the top of the z-order list
  96.          WinSetWindowPos( event.controlWindow()->handle(), HWND_TOP, 0, 0, 0, 0, SWP_ZORDER );
  97.  
  98.          // re-enable event processing
  99.          enable();
  100.  
  101.          // to ensure that the screen is properly redrawn, we need to
  102.          // return false, allowing the operating system to take care of
  103.          // redrawing the screen
  104.          return false;
  105.       }
  106.  
  107.       // handle event processing
  108.       virtual Boolean dispatchHandlerEvent( IEvent &event )
  109.       {
  110.          // assume the event wont be handled
  111.          Boolean result = false;
  112.  
  113.          // look for the WM_VRNENABLED message
  114.          if( event.eventId() == WM_VRNENABLED )
  115.          {
  116.             // call the method that takes care of the action
  117.             result = frameWindowNeedsUpdate( event );
  118.          }
  119.  
  120.          event.setResult(result);
  121.          return result;
  122.       }
  123. };
  124.  
  125. #endif
  126.  
  127.