home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / DU Folder / DU Selection FW / Sources / DUListFrame.cpp < prev    next >
Encoding:
Text File  |  1995-10-26  |  3.8 KB  |  140 lines  |  [TEXT/MPS ]

  1. //    Copyright © 1995 Apple Computer, Inc. All rights reserved.
  2. //    Release Version:    $ 1.0 d11 $
  3.  
  4. //=======================================================================
  5.  
  6. // --- DU Selection FW ---------------------
  7. #ifndef DULISTFRAME_H
  8. #include "DUListFrame.h"        // DU_CListFrame
  9. #endif
  10.  
  11. #ifndef DULISTPART_H
  12. #include "DUListPart.h"            // DU_CListPart
  13. #endif
  14.  
  15. #ifndef DULIST_H
  16. #include "DUList.h"                // DU_CList, DU_CListIterator
  17. #endif
  18.  
  19. #ifndef DULISTSELECTION_H
  20. #include "DUListSelection.h"    // DU_CListSelection
  21. #endif
  22.  
  23. // ----- Framework Layer -----
  24. #ifndef FWUTIL_H
  25. #include "FWUtil.h"                // FW_CFacetContext, FW_Beep()
  26. #endif
  27.  
  28. #ifndef FWVIEW_H
  29. #include "FWView.h"                // FW_CViewContext
  30. #endif
  31.  
  32. // ----- Graphic Includes -----
  33. #ifndef FWRECT_H
  34. #include <FWRect.h>                // FW_CRect
  35. #endif
  36.  
  37. #ifndef FWRECSHP_H
  38. #include "FWRecShp.h"            // FW_CRectShape
  39. #endif
  40.  
  41. //========================================================================================
  42. #ifdef FW_BUILD_MAC
  43. #pragma segment DUList
  44. #endif
  45.  
  46. //========================================================================================
  47. DU_CListFrame::DU_CListFrame(Environment* ev, ODFrame* odFrame, 
  48.                                     FW_CPresentation* presentation, DU_CListPart* part)
  49.   : FW_CFrame(ev, odFrame, presentation, part),
  50.       fListPart(part),
  51.       fSelection((DU_CListSelection*)GetPresentation(ev)->GetSelection(ev))
  52. {
  53. }
  54.  
  55. //----------------------------------------------------------------------------------------
  56. DU_CListFrame::~DU_CListFrame()
  57. {
  58. }
  59.  
  60. //----------------------------------------------------------------------------------------
  61. void 
  62. DU_CListFrame::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)    // Override
  63. {
  64.     FW_CViewContext vc(ev, this, odFacet, invalidShape);
  65. //    FW_CRect box;
  66. //    this->GetFrameShapeBounds(ev, box);    
  67.     FW_CRect box = this->GetBounds(ev);
  68.  
  69.     FW_CRectShape::RenderRect(vc, box, FW_kFill, FW_kRGBLightGray);
  70.     
  71.     // draw items
  72.     DU_CList* list = fListPart->GetItemList();
  73.     DU_CListIterator iter(list);
  74.     DU_MSelectable* item;
  75.     for (item = iter.First(); iter.IsNotComplete(); item = iter.Next()) {
  76.         item->Draw(vc);
  77.         item->DrawSelectionFeedback(vc);
  78.         }
  79. }
  80.  
  81. //--------------------------------------------------------------------------------
  82. FW_Boolean 
  83. DU_CListFrame::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, 
  84.                                      FW_Boolean hasMenuFocus,
  85.                                      FW_Boolean isRoot)    // Override
  86. {
  87.     if (hasMenuFocus) {    
  88.     }
  89.     return FALSE;
  90. }
  91.  
  92. //--------------------------------------------------------------------------------
  93. FW_Boolean 
  94. DU_CListFrame::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)    // Override
  95. {
  96.     FW_Boolean menuHandled = TRUE;
  97.     switch (theMenuEvent.GetCommandID(ev)) {
  98.  
  99.         default:
  100.             menuHandled = FALSE;
  101.     }
  102.     return menuHandled;
  103. }
  104.  
  105. //----------------------------------------------------------------------------------------
  106. FW_Boolean 
  107. DU_CListFrame::DoMouseDown(Environment* ev, const FW_CMouseEvent& theMouseEvent)
  108. {    
  109.     this->SelectItemWithMouse(ev, theMouseEvent);
  110.     return TRUE;                // we handled event
  111. }
  112.  
  113. //----------------------------------------------------------------------------------------
  114. void 
  115. DU_CListFrame::SelectItemWithMouse(Environment *ev, const FW_CMouseEvent& theMouseEvent)
  116. {    
  117.     FW_CPoint position = theMouseEvent.GetMousePosition(ev, FW_CMouseEvent::kFrame);
  118.     this->GetContentView(ev)->FrameToViewContent(ev, position);
  119.     DU_MSelectable* hitItem = fListPart->FrontItemHit(ev, position);
  120.     if (hitItem) {
  121.         if ( ! theMouseEvent.IsExtendModifier(ev) )    {    // normal click
  122.             if ( hitItem->IsSelected() )
  123.                 ;    // do nothing
  124.             else {
  125.                 fSelection->CloseSelection(ev);
  126.                 fSelection->AddItemToSelection(ev, hitItem);
  127.             }
  128.         }
  129.         else {                                            // shift-click
  130.             if ( hitItem->IsSelected() )
  131.                 fSelection->RemoveItemFromSelection(ev, hitItem);
  132.             else
  133.                 fSelection->AddItemToSelection(ev, hitItem);
  134.         }
  135.     }
  136.     else
  137.         if ( ! theMouseEvent.IsExtendModifier(ev) )
  138.             fSelection->CloseSelection(ev);
  139. }
  140.