home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / Button / Sources / Behavior.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  3.6 KB  |  119 lines  |  [TEXT/CWIE]

  1. //========================================================================================
  2. //
  3. //    File:                Behavior.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //
  8. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #ifndef BEHAVIOR_H
  13. #include "Behavior.h"
  14. #endif
  15.  
  16. #ifndef FWSESION_H
  17. #include "FWSesion.h"
  18. #endif
  19.  
  20. #ifndef FWPART_H
  21. #include "FWPart.h"
  22. #endif
  23.  
  24. #ifndef FWEVENT_H
  25. #include "FWEvent.h"
  26. #endif
  27.  
  28. // ----- OpenDoc -----
  29.  
  30. #ifndef SOM_ODFocusSet_xh
  31. #include <FocusSet.xh>
  32. #endif
  33.  
  34. #ifndef SOM_ODArbitrator_xh
  35. #include <Arbitrat.xh>
  36. #endif
  37.  
  38. //========================================================================================
  39. //    Runtime information
  40. //========================================================================================
  41.  
  42. #ifdef FW_BUILD_MAC
  43. #pragma segment odfbutton
  44. #endif
  45.  
  46. //========================================================================================
  47. //    class COptionBehavior
  48. //========================================================================================
  49.  
  50. FW_DEFINE_AUTO(COptionBehavior)
  51.  
  52. //----------------------------------------------------------------------------------------
  53. //    COptionBehavior::COptionBehavior
  54. //----------------------------------------------------------------------------------------
  55.  
  56. COptionBehavior::COptionBehavior(Environment* ev) :
  57.     FW_MEventHandler(ev, NULL, FW_kNoPriority),
  58.     fEmptyFocusSet(NULL),
  59.     fFullFocusSet(NULL),
  60.     fCurrentFocusSet(NULL)
  61. {
  62.     // - fEmptyFocusSet will be used to handle simple clicks
  63.     // - fFullFocusSet will be used to select the button as an embedded frame
  64.     ODArbitrator* arbitrator = FW_CSession::GetArbitrator(ev);
  65.     fEmptyFocusSet = arbitrator->CreateFocusSet(ev);    
  66.     
  67.     fFullFocusSet = arbitrator->CreateFocusSet(ev);
  68.     fFullFocusSet->Add(ev, FW_CPart::fgKeyFocusToken);
  69.     fFullFocusSet->Add(ev, FW_CPart::fgMenuFocusToken);
  70.     fFullFocusSet->Add(ev, FW_CPart::fgSelectionFocusToken);
  71.     fFullFocusSet->Add(ev, FW_CPart::fgClipboardFocusToken);    
  72.     
  73.     fDesiredFocusSet = fEmptyFocusSet;
  74.  
  75.     FW_END_CONSTRUCTOR
  76. }
  77.  
  78. //----------------------------------------------------------------------------------------
  79. //    COptionBehavior::~COptionBehavior
  80. //----------------------------------------------------------------------------------------
  81.  
  82. COptionBehavior::~COptionBehavior() 
  83. {
  84.     FW_START_DESTRUCTOR
  85.     
  86.     // Do not delete the fCurrentFocusSet, it is owned by the frame
  87.     if (fCurrentFocusSet != fFullFocusSet)
  88.         delete fFullFocusSet;
  89.     
  90.     if (fCurrentFocusSet != fEmptyFocusSet)
  91.         delete fEmptyFocusSet;
  92. }
  93.  
  94. //----------------------------------------------------------------------------------------
  95. //    COptionBehavior::DoMouseDown
  96. //----------------------------------------------------------------------------------------
  97.  
  98. FW_Handled COptionBehavior::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent) 
  99. {
  100.     FW_Boolean optionPressed = theMouseEvent.IsCopyModifier(ev);
  101.     
  102.     // Switches focus set on the fly to allow selection of the button when it's an
  103.     // embedded frame.
  104.     fDesiredFocusSet = optionPressed ? fFullFocusSet : fEmptyFocusSet;
  105.  
  106.     return optionPressed ? FW_kHandled : FW_kNotHandled;
  107. }
  108.  
  109. //----------------------------------------------------------------------------------------
  110. //    COptionBehavior::GetDesiredFocusSet
  111. //----------------------------------------------------------------------------------------
  112.  
  113. ODFocusSet* COptionBehavior::GetDesiredFocusSet()
  114. {        
  115.     fCurrentFocusSet = fDesiredFocusSet;
  116.     fDesiredFocusSet = fEmptyFocusSet;        // So next time it will be empty unless user uses Option key
  117.     return fCurrentFocusSet;
  118. }
  119.