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 / Developer University / DU Projects / Windoid / Sources / Part.cpp < prev    next >
Encoding:
Text File  |  1996-08-22  |  4.4 KB  |  164 lines  |  [TEXT/CWIE]

  1. //    Release Version:    $ ODF 2 $
  2. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  3.  
  4. //================================================================================
  5. #ifndef PART_H
  6. #include "Part.h"
  7. #endif
  8.  
  9. #ifndef DEFINES_K
  10. #include "Defines.k"
  11. #endif
  12.  
  13. #ifndef BINDING_K
  14. #include "Binding.k"
  15. #endif
  16.  
  17. #ifndef FRAME_H
  18. #include "Frame.h"
  19. #endif
  20.  
  21. // ----- Framework Layer -----
  22. #ifndef FWPRESEN_H
  23. #include "FWPresen.h"        // FW_CPresentation
  24. #endif
  25.  
  26. #ifndef FWABOUT_H
  27. #include "FWAbout.h"        //::FW_About()
  28. #endif
  29.  
  30. #ifndef FWFLOWIN_H
  31. #include "FWFloWin.h"        // FW_CFloatingWindow
  32. #endif
  33.  
  34. // ----- OS Layer -----
  35. #ifndef FWMENU_H
  36. #include "FWMenu.h"            // FW_CMenuBar, FW_CPullDownMenu
  37. #endif
  38.  
  39. #ifndef FWCFMRES_H
  40. #include "FWCFMRes.h"        // FW_PSharedLibraryResourceFile
  41. #endif
  42.  
  43. #ifndef FWPICTUR_H
  44. #include "FWPictur.h"        // FW_CPicture
  45. #endif
  46.  
  47. //==============================================================================
  48. #ifdef FW_BUILD_MAC
  49. #pragma segment Windoid
  50. #endif
  51.  
  52. FW_DEFINE_AUTO(CWindoidPart)
  53. //==============================================================================
  54. CWindoidPart::CWindoidPart(ODPart* odPart)
  55.   :    FW_CPart(odPart, FW_gInstance, kPartInfoID),
  56.     fMainPresentation(NULL),
  57.     fPalettePresentation(NULL),
  58.     fPaletteWindow(NULL)
  59. {
  60.     FW_END_CONSTRUCTOR
  61. }
  62.  
  63. //--------------------------------------------------------------------------------
  64. CWindoidPart::~CWindoidPart()
  65. {
  66.     FW_START_DESTRUCTOR
  67. }
  68.  
  69. //--------------------------------------------------------------------------------
  70. void 
  71. CWindoidPart::Initialize(Environment* ev, ODStorageUnit* storageUnit, FW_Boolean fromStorage)    // Override
  72. {
  73. FW_DO_NOT_DEAD_STRIP(FW_CToggleItem);
  74.  
  75.     FW_CPart::Initialize(ev, storageUnit, fromStorage);
  76.     const FW_Boolean kDefault = TRUE;
  77.     const ODType kMainPresentation = "Apple:Presentation:Main";
  78.     const ODType kPalettePresentation = "Apple:Presentation:Palette";
  79.     fMainPresentation = this->RegisterPresentation(ev, kMainPresentation, kDefault);
  80.     fPalettePresentation = this->RegisterPresentation(ev, kPalettePresentation, !kDefault);
  81. }
  82.  
  83. //--------------------------------------------------------------------------------
  84. FW_Handled 
  85. CWindoidPart::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, 
  86.                                      FW_Boolean hasMenuFocus,
  87.                                      FW_Boolean isRoot)    // Override
  88. {
  89.     FW_UNUSED(isRoot);
  90.     if (hasMenuFocus) {    
  91.         menuBar->EnableAndToggleCommand(ev, cShowHideCommand, true, 
  92.                     fPaletteWindow == NULL || !fPaletteWindow->IsShown(ev));
  93.     }
  94.     return false;
  95. }
  96.  
  97. //--------------------------------------------------------------------------------
  98. FW_Handled 
  99. CWindoidPart::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)    // Override
  100. {
  101.     FW_Handled menuHandled = true;    
  102.     switch (theMenuEvent.GetCommandID(ev))
  103.     {
  104.         case cShowHideCommand:
  105.             fPaletteWindow->ShowHide(ev, ! fPaletteWindow->IsShown(ev));
  106.             break;
  107.  
  108.         default:
  109.             menuHandled = false;
  110.     }
  111.     return menuHandled;
  112. }
  113.  
  114. //--------------------------------------------------------------------------------
  115. FW_CFrame* 
  116. CWindoidPart::NewFrame(Environment* ev, ODFrame* odFrame,
  117.                         FW_CPresentation* presentation, FW_Boolean fromStorage)    // Override
  118. {
  119.     FW_UNUSED(fromStorage);
  120.     if (presentation == fPalettePresentation) {
  121.         return FW_NEW( CPaletteFrame, (ev, odFrame, presentation, this) );
  122.     }
  123.     return FW_NEW( CMainFrame, (ev, odFrame, presentation, this) );
  124. }
  125.  
  126. //------------------------------------------------------------------------------
  127. FW_CContent* 
  128. CWindoidPart::NewPartContent(Environment* ev)
  129. {
  130.     FW_UNUSED(ev);
  131.     return NULL;
  132. }
  133.  
  134. //------------------------------------------------------------------------------
  135. FW_Handled 
  136. CWindoidPart::DoAbout(Environment* ev)
  137. {
  138.     ::FW_About(ev, this, kAbout);
  139.     
  140.     return FW_kHandled;
  141. }
  142.  
  143. //--------------------------------------------------------------------------------
  144. void 
  145. CWindoidPart::MyMakePalette(Environment* ev, FW_Boolean showWindow)
  146. {
  147.     if (fPaletteWindow == NULL)
  148.     {
  149.         FW_PSharedLibraryResourceFile resFile(ev);    // palette picture here
  150.         FW_CPicture picture(resFile, kPalettePictID);
  151.         FW_CRect bounds;
  152.         picture.GetPictBounds(bounds);
  153.         FW_CPoint windowSize = bounds.Size();
  154.         FW_CPoint windowPosition(FW_IntToFixed(100), FW_IntToFixed(100));
  155.         const FW_Boolean kWantCloseBox = true;
  156.         const FW_CString32 kWindowTitle("");
  157.         fPaletteWindow =  new FW_CFloatingWindow(ev, this, 
  158.                                 fPalettePresentation, kWindowTitle, 
  159.                                 windowSize, windowPosition, kWantCloseBox);
  160.         if (showWindow)
  161.             fPaletteWindow->Show(ev);
  162.     }
  163. }
  164.