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 / ODF / Framewrk / FWEvents / FWTabber.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  3.9 KB  |  138 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWTabber.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFrameW.hpp"
  11.  
  12. #ifndef FWTABBER_H
  13. #include "FWTabber.h"
  14. #endif
  15.  
  16. #ifndef FWEVENTH_H
  17. #include "FWEventH.h"
  18. #endif
  19.  
  20. #ifndef FWEVENT_H
  21. #include "FWEvent.h"
  22. #endif
  23.  
  24. #ifndef FWEVEDEF_H
  25. #include "FWEveDef.h"
  26. #endif
  27.  
  28. #ifndef FWVIEW_H
  29. #include "FWSView.h"
  30. #endif
  31.  
  32. //========================================================================================
  33. // Runtime Informations
  34. //========================================================================================
  35.  
  36. #ifdef FW_BUILD_MAC
  37. #pragma segment fwevents
  38. #endif
  39.  
  40. //========================================================================================
  41. // CLASS FW_CViewTabber
  42. //========================================================================================
  43.  
  44. FW_DEFINE_CLASS_M1(FW_CViewTabber, FW_MEventHandler)
  45.  
  46. //----------------------------------------------------------------------------------------
  47. // FW_CViewTabber::FW_CViewTabber
  48. //----------------------------------------------------------------------------------------
  49.  
  50. FW_CViewTabber::FW_CViewTabber(Environment* ev, FW_CSuperView* parent, short tabbingKey) 
  51.     : FW_MEventHandler(),
  52.     fParentView(parent),
  53.     fFirstView(NULL),
  54.     fNextView(NULL),
  55.     fFoundCurrent(FALSE),
  56.     fTabbingKey(tabbingKey)
  57. {
  58.     parent->AdoptEventHandler(ev, this);
  59. }
  60.  
  61. //----------------------------------------------------------------------------------------
  62. // FW_CViewTabber::~FW_CViewTabber
  63. //----------------------------------------------------------------------------------------
  64.  
  65. FW_CViewTabber::~FW_CViewTabber() 
  66. {
  67. }
  68.  
  69. //----------------------------------------------------------------------------------------
  70. // FW_CViewTabber::DispatchVirtualKey
  71. //----------------------------------------------------------------------------------------
  72.  
  73. FW_Handled FW_CViewTabber::DoVirtualKey(Environment* ev, 
  74.         const FW_CVirtualKeyEvent& keyEvent)
  75. {
  76.     if (keyEvent.GetKeyCode(ev) == fTabbingKey) {
  77.         Tab(ev, fParentView, keyEvent.IsExtendModifier(ev));
  78.         return FW_kHandled;
  79.     }
  80.     else
  81.         return FW_kNotHandled;
  82. }
  83.  
  84. //----------------------------------------------------------------------------------------
  85. // FW_CViewTabber::Tab
  86. //----------------------------------------------------------------------------------------
  87.  
  88. void FW_CViewTabber::Tab(Environment* ev, FW_CSuperView* parentView, FW_Boolean tabBackward)
  89. {
  90.     Reset();
  91.     
  92.     FindTargets(ev, parentView, tabBackward);
  93.     
  94.     if (fNextView == NULL) {
  95.         // Wrap-around to first target
  96.         fNextView = fFirstView;
  97.     }
  98.     
  99.     if (fNextView)
  100.     {        
  101.         fNextView->BecomeTarget(ev, TRUE);
  102.     }
  103.  
  104. //----------------------------------------------------------------------------------------
  105. // FW_CViewTabber::FindTargets
  106. //----------------------------------------------------------------------------------------
  107.  
  108. void FW_CViewTabber::FindTargets(Environment* ev, FW_CSuperView* parent, FW_Boolean tabBackward)
  109. {
  110.     FW_CViewIterator ite(parent);
  111.     FW_CView* subview = tabBackward ? ite.Last() : ite.First();
  112.  
  113.     for (; ite.IsNotComplete(); subview = tabBackward ? ite.Previous() : ite.Next())
  114.     {
  115.         FW_Boolean canBeTarget = subview->IsEnabled(ev) && subview->IsVisible(ev) 
  116.                                 && subview->WantsToBeTarget(ev);
  117.  
  118.         if ((fFirstView == NULL) && canBeTarget)
  119.             fFirstView = subview;    // found the first potential target
  120.             
  121.         if (subview->IsTarget(ev)) {
  122.             fFoundCurrent = TRUE;    // found the current target        
  123.         } 
  124.         else if (fFoundCurrent && (fNextView == NULL) && canBeTarget)
  125.         {
  126.             fNextView = subview;
  127.             break;                    // found the next target
  128.         }
  129.  
  130.         if (subview->HasSubViews(ev))
  131.             FindTargets(ev, (FW_CSuperView*)subview, tabBackward);    // try deeper
  132.         
  133.         if (fNextView)    break;        // found the next target
  134.     }
  135. }
  136.  
  137.