home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / lib / mac / UserInterface / CMouseDispatcher.cp < prev    next >
Encoding:
Text File  |  1998-04-08  |  5.6 KB  |  195 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. #ifdef PowerPlant_PCH
  20. #include PowerPlant_PCH
  21. #endif
  22.  
  23. #include "CMouseDispatcher.h"
  24. #include "macutil.h"
  25.  
  26.  
  27. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  28. //    Ñ    
  29. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  30.  
  31. CMouseDispatcher::CMouseDispatcher()
  32.     :    LAttachment(msg_Event, true)
  33. {
  34. }
  35.  
  36. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  37. //    Ñ    
  38. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  39.  
  40. void CMouseDispatcher::ExecuteSelf(
  41.     MessageT            inMessage,
  42.     void*                ioParam)
  43. {
  44.     Assert_(inMessage == msg_Event);
  45.     const EventRecord* theEvent = (const EventRecord*)ioParam;
  46.     
  47.     // High level events dont have the mouse position in the where field
  48.     // of the event record.
  49.     if (theEvent->what == kHighLevelEvent)
  50.         return;
  51.  
  52.     LPane* theCurrentPane = nil;
  53.     LPane* theLastPane = LPane::GetLastPaneMoused();
  54.  
  55.     Point thePortMouse;    
  56.     WindowPtr theMacWindow;
  57.     Int16 thePart = ::FindWindow(theEvent->where, &theMacWindow);
  58.     LWindow    *theWindow = LWindow::FetchWindowObject(theMacWindow);
  59.  
  60.     if (theWindow != nil)
  61.     {
  62.         thePortMouse = theEvent->where;
  63.         theWindow->GlobalToPortPoint(thePortMouse);
  64.  
  65.         // Note: it is the responsibility of the pane
  66.         // to guard with IsEnabled(), IsActive(), etc.
  67.         // Some panes need to execute MouseEnter, etc
  68.         // even in inactive windows
  69.         
  70.         theCurrentPane = FindPaneHitBy(theEvent->where);
  71.     }
  72.  
  73.  
  74.     // It is okay to assume that the mouse point was converted to port coordinates
  75.     // in the conditional above.  If it was not, it's because the current pane will
  76.     // be nil, and the only thing that will be called later is MouseLeave() which
  77.     // dosen't need it.
  78.     SMouseTrackParms theMouseParms;
  79.     theMouseParms.portMouse = thePortMouse;
  80.     theMouseParms.macEvent = *theEvent;
  81.  
  82.     if (theCurrentPane != theLastPane)
  83.         {
  84.         if (theLastPane != nil)
  85.             {
  86.             if (theLastPane->ExecuteAttachments(msg_MouseLeft, &theMouseParms))
  87.                 {
  88.                 theLastPane->MouseLeave();
  89.                 // If theLastPane is a CPatternButton with a tooltip attachment,
  90.                 // the ExecuteAttachments() method above deletes the tooltip pane.
  91.                 // This is normal behaviour. However, if we are unlucky enough,
  92.                 // theCurrentPane can point to the tooltip pane which has just
  93.                 // been deleted. So it is important to re-initialize theCurrentPane
  94.                 // at this point:
  95.                 if (theCurrentPane != nil)
  96.                     theCurrentPane = FindPaneHitBy(theEvent->where);
  97.                 }
  98.  
  99.             }
  100.         
  101.         if (theCurrentPane != nil)
  102.             {
  103.             if (theCurrentPane->ExecuteAttachments(msg_MouseEntered, &theMouseParms))
  104.                 theCurrentPane->MouseEnter(thePortMouse, *theEvent);
  105.             }
  106.         
  107.         LPane::SetLastPaneMoused(theCurrentPane);
  108.         }
  109.     else if (theCurrentPane != nil)
  110.         {
  111.         if (theCurrentPane->ExecuteAttachments(msg_MouseWithin, &theMouseParms))
  112.             theCurrentPane->MouseWithin(thePortMouse, *theEvent);
  113.         }
  114. }
  115.  
  116. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  117. //    Ñ    
  118. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  119.  
  120. CMouseTrackAttachment::CMouseTrackAttachment()
  121.     :    LAttachment(msg_AnyMessage)
  122.     ,    mOwningPane(nil)
  123.     ,    mMustBeActive(true)
  124.     ,    mMustBeEnabled(true)
  125. {
  126.     SetExecuteHost(true);
  127. }
  128.  
  129. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  130. //    Ñ    
  131. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  132.  
  133. CMouseTrackAttachment::CMouseTrackAttachment(LStream* inStream)
  134.     :    LAttachment(inStream)
  135.     ,    mOwningPane(nil)
  136.     ,    mMustBeActive(true)
  137.     ,    mMustBeEnabled(true)
  138. {
  139. }
  140.  
  141. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  142. //    Ñ    
  143. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  144.  
  145. Boolean CMouseTrackAttachment::EnsureOwningPane()
  146. {
  147.     if (!mOwningPane)
  148.     {
  149.         mOwningPane = dynamic_cast<LPane*>(GetOwnerHost());
  150.         Assert_(mOwningPane);     // you didn't attach to an LPane* derivative
  151.         if (!mOwningPane)
  152.             return false;
  153.     }
  154.     return true;
  155. }
  156.  
  157. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  158. //    Ñ    
  159. // ╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤╤
  160.  
  161. void CMouseTrackAttachment::ExecuteSelf(
  162.     MessageT            inMessage,
  163.     void*                ioParam)
  164. {
  165.     SMouseTrackParms* theTrackParms = (SMouseTrackParms*)ioParam;
  166.  
  167.     if (!EnsureOwningPane())
  168.         return;
  169.  
  170.     if (mMustBeEnabled && !mOwningPane->IsEnabled())
  171.         return;
  172.         
  173.     if (mMustBeActive && !mOwningPane->IsActive())
  174.         return;
  175.         
  176.     switch (inMessage)
  177.         {
  178.         case msg_MouseEntered:
  179.             Assert_(theTrackParms != nil);
  180.             MouseEnter(theTrackParms->portMouse, theTrackParms->macEvent);
  181.             break;
  182.             
  183.         case msg_MouseWithin:
  184.             Assert_(theTrackParms != nil);
  185.             MouseWithin(theTrackParms->portMouse, theTrackParms->macEvent);
  186.             break;
  187.             
  188.         case msg_MouseLeft:
  189.             MouseLeave();
  190.             break;    
  191.         }
  192. };
  193.  
  194.  
  195.