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 / Form / Sources / Part.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  10.7 KB  |  387 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Part.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "Form.hpp"
  11.  
  12. #ifndef PART_H
  13. #include "Part.h"
  14. #endif
  15.  
  16. #ifndef CONTENT_H
  17. #include "Content.h"
  18. #endif
  19.  
  20. #ifndef FRAME_H
  21. #include "Frame.h"
  22. #endif
  23.  
  24. #ifndef DIALOG_H
  25. #include "Dialog.h"
  26. #endif
  27.  
  28. #ifndef VIEW_H
  29. #include "View.h"
  30. #endif
  31.  
  32. #ifndef SCROLLED_H
  33. #include "ScrollEd.h"
  34. #endif
  35.  
  36. #ifndef BINDING_K
  37. #include "Binding.k"
  38. #endif
  39.  
  40. // ----- Framework Layer -----
  41.  
  42. #ifndef FWABOUT_H
  43. #include "FWAbout.h"
  44. #endif
  45.  
  46. #ifndef FWUTIL_H
  47. #include "FWUtil.h"
  48. #endif
  49.  
  50. #ifndef FWITERS_H
  51. #include "FWIters.h"
  52. #endif
  53.  
  54. #ifndef FWPRESEN_H
  55. #include "FWPresen.h"
  56. #endif
  57.  
  58. #ifndef FWSCLBAR_H
  59. #include "FWSclBar.h"
  60. #endif
  61.  
  62. #ifndef FWKIND_H
  63. #include "FWKind.h"
  64. #endif
  65.  
  66. // ----- OS Layer -----
  67.  
  68. #ifndef FWMENU_H
  69. #include "FWMenu.h"
  70. #endif
  71.  
  72. #ifndef FWCFMRES_H
  73. #include "FWCFMRes.h"
  74. #endif
  75.  
  76. #ifndef FWRESTYP_H
  77. #include "FWResTyp.h"
  78. #endif
  79.  
  80. #ifndef FWSUSINK_H
  81. #include "FWSUSink.h"
  82. #endif
  83.  
  84. #ifndef FWEVENT_H
  85. #include "FWEvent.h"
  86. #endif
  87.  
  88. #ifndef FWPICSHP_H
  89. #include "FWPicShp.h"
  90. #endif
  91.  
  92. #ifndef SLMixOS_H
  93. #include "SLMixOS.h"
  94. #endif
  95.  
  96. // ----- Foundation Layer -----
  97.  
  98. #ifndef FWSTREAM_H
  99. #include "FWStream.h"
  100. #endif
  101.  
  102. #ifndef FWSTRS_H
  103. #include "FWStrs.h"
  104. #endif
  105.  
  106. // ----- OpenDoc Includes -----
  107.  
  108. #ifndef SOM_Module_OpenDoc_StdProps_defined
  109. #include <StdProps.xh>
  110. #endif
  111.  
  112. // ----- PPob View Support -----
  113.  
  114. #if FW_PPOB_VIEWS
  115. #include "FWPPobRd.h"
  116. #endif
  117.  
  118. // ----- MacApp View Support -----
  119.  
  120. #if FW_MACAPP_VIEWS
  121. #include "FWMARead.h"
  122. #endif
  123.  
  124. //========================================================================================
  125. //    Runtime info
  126. //========================================================================================
  127.  
  128. #ifdef FW_BUILD_MAC
  129. #pragma segment odfform
  130. #endif
  131.  
  132. FW_DEFINE_AUTO(CFormPart)
  133.  
  134. //========================================================================================
  135. //    CFormPart class
  136. //========================================================================================
  137.  
  138. //----------------------------------------------------------------------------------------
  139. // CFormPart constructor
  140. //----------------------------------------------------------------------------------------
  141.  
  142. CFormPart::CFormPart(ODPart* odPart) :
  143.     FW_CPart(odPart, FW_gInstance, kPartInfoID),
  144.     fTextData(""),
  145.     fIsForm(TRUE),
  146.     fMainPresentation(NULL),
  147.     fPwdDialogPresentation(NULL)
  148. {
  149.     FW_END_CONSTRUCTOR
  150. }
  151.  
  152. //----------------------------------------------------------------------------------------
  153. // CFormPart destructor
  154. //----------------------------------------------------------------------------------------
  155.  
  156. CFormPart::~CFormPart()
  157. {
  158.     FW_START_DESTRUCTOR
  159. }
  160.  
  161. //----------------------------------------------------------------------------------------
  162. // CFormPart::Initialize
  163. //----------------------------------------------------------------------------------------
  164.  
  165. void CFormPart::Initialize(Environment* ev, ODStorageUnit* storageUnit, FW_Boolean fromStorage)    // Override
  166. {
  167.     FW_CPart::Initialize(ev, storageUnit, fromStorage);
  168.  
  169.     // ----- Register our Presentations
  170.     //    By not passing a view id for fMainPresentation we force ODF to call our frame's
  171.     //  CreateSubView method.
  172.     fMainPresentation = RegisterPresentation(ev, kMainPresentation, TRUE, NULL);    
  173. #if FW_ODFRC_VIEWS
  174.     fPwdDialogPresentation = RegisterPresentation(ev, kPasswordDialogPresentation, FALSE,
  175.                                                 kPasswordDialog, kPasswordDialog, NULL);
  176. #else
  177.     fPwdDialogPresentation = RegisterPresentation(ev, kPasswordDialogPresentation, FALSE,
  178.                                                 FW_kNoViewID, FW_kNoViewID, NULL);
  179. #endif
  180.  
  181.     // ----- Register one extra kind -----
  182.  
  183. #if FW_ODFRC_VIEWS
  184.     // nothing to do
  185.  
  186. #elif FW_PPOB_VIEWS
  187.     // Register the standard PP classes
  188.     FW_CPPobReader::RegisterAllPPClasses();
  189.  
  190.     // Register the PP view classes for this part
  191.     FW_CPPobReader::RegisterClass('Form', CPPobFormView::Create);
  192.     FW_CPPobReader::RegisterClass('PwEd', CPPobPwdEditView::Create);
  193.     FW_CPPobReader::RegisterClass('ScEd', CPPobScrollEdit::Create);
  194.     
  195. #elif FW_MACAPP_VIEWS
  196.     // Register the standard MacApp classes
  197.     FW_CMacAppReader::RegisterAllMacAppClasses();
  198.  
  199.     // Register our custom MacApp view classes for this part
  200.     // Note: We register kStdTEView again (after RegisterAllMacAppClasses) in order 
  201.     // to map it to our CScrollEdit class instead of the simpler FW_CEditView.
  202.     // (We could also have defined a custom TScrollEdit class in Ad Lib)
  203.     FW_CMacAppReader::RegisterClassName(FW_CString("TForm"), CMAFormView::Create);
  204.     FW_CMacAppReader::RegisterClassName(FW_CString("TPwdEdit"), CMAPwdEditView::Create);
  205.     FW_CMacAppReader::RegisterSignature(kStdTEView, CMAScrollEdit::Create);
  206. #endif
  207.     
  208.     // WARNING: Make sure that classes created from resources won't be dead-stripped!
  209.     FW_DO_NOT_DEAD_STRIP(FW_CGrowBox);
  210.     FW_DO_NOT_DEAD_STRIP(FW_CScrollBarScroller);
  211.     FW_DO_NOT_DEAD_STRIP(FW_CGroupBox);
  212.     FW_DO_NOT_DEAD_STRIP(FW_CScrollBar);
  213.     FW_DO_NOT_DEAD_STRIP(FW_CEditView);
  214.     FW_DO_NOT_DEAD_STRIP(FW_CListBox);
  215.     FW_DO_NOT_DEAD_STRIP(FW_CButton);
  216.     FW_DO_NOT_DEAD_STRIP(FW_CRadioCluster);
  217.     FW_DO_NOT_DEAD_STRIP(FW_CPopupMenu);
  218. }
  219.  
  220. //----------------------------------------------------------------------------------------
  221. //    CFormPart::NewPartContent
  222. //----------------------------------------------------------------------------------------
  223. //    ODF Method
  224.  
  225. FW_CContent* CFormPart::NewPartContent(Environment* ev)
  226. {
  227.     return (FW_NEW(CFormContent, (ev, this)));
  228. }
  229.  
  230. //----------------------------------------------------------------------------------------
  231. // CFormPart::NewFrame
  232. //----------------------------------------------------------------------------------------
  233.  
  234. FW_CFrame* CFormPart::NewFrame(Environment* ev,
  235.                                 ODFrame* odFrame,
  236.                                 FW_CPresentation* presentation,
  237.                                 FW_Boolean fromStorage)    // Override
  238. {
  239.     FW_UNUSED(fromStorage);
  240.     FW_CFrame* newFrame = NULL;
  241.  
  242.     if (presentation == fMainPresentation) {
  243.         // Create the frame for the main presentation
  244.         newFrame = FW_NEW(CFormFrame, (ev, odFrame, presentation, this));
  245.     }
  246.     else if (presentation == fPwdDialogPresentation) {
  247.         // Create the frame for the dialog presentation, using an ODFRC resource id
  248.         newFrame = FW_NEW(CPwdDialogFrame, (ev, odFrame, presentation, this));
  249.     }
  250.     
  251.     return newFrame;
  252. }
  253.  
  254. //----------------------------------------------------------------------------------------
  255. // CFormPart::DoMenu
  256. //----------------------------------------------------------------------------------------
  257.  
  258. FW_Handled CFormPart::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent) // Override
  259. {
  260.     FW_Handled menuHandled = FW_kHandled;
  261.     ODCommandID id = theMenuEvent.GetCommandID(ev);
  262.     
  263.     switch (id)
  264.     {
  265.         case cResetFormCommand:
  266.             DoFormCommand(ev);
  267.             break;
  268.         
  269. #if FW_MACAPP_VIEWS && defined(FW_DEBUG)
  270.         case cReloadMacAppViews:
  271.             // Reload the views from an external resource file. 
  272.             // NOTE: we were lazy here... this command should be handled by CFormFrame!
  273.             //       Also, instead of reloading views for all frames of fMainPresentation
  274.             //         we do it only for the active frame, so you could end up having 2
  275.             //       different Form frame! (try it with View In Window)
  276.             FW_CFrame* frame = GetLastActiveFrame(ev);
  277.             CFormFrame* formFrame = FW_DYNAMIC_CAST(CFormFrame, frame);
  278.             if (formFrame)
  279.                 FW_PlatformError error = FW_CMacAppReader::ReloadViews(ev, 
  280.                                                         kFormView, 
  281.                                                         formFrame, 
  282.                                                         formFrame, 
  283.                                                         FW_CMacAppReader::kCurrentResFile);
  284.             break;
  285. #endif
  286. #if FW_PPOB_VIEWS  && defined(FW_DEBUG)
  287.         case cReloadPPobViews:
  288.             // Reload the views from an external resource file. 
  289.             // (Same as for MacApp, see note above)
  290.             FW_CFrame* frame = GetLastActiveFrame(ev);
  291.             CFormFrame* formFrame = FW_DYNAMIC_CAST(CFormFrame, frame);
  292.             if (formFrame)
  293.                 FW_PlatformError error = FW_CPPobReader::ReloadViews(ev, 
  294.                                                         kFormView, 
  295.                                                         formFrame, 
  296.                                                         formFrame, 
  297.                                                         FW_CPPobReader::kCurrentResFile);
  298.             break;
  299. #endif
  300.         default:
  301.             menuHandled = FW_kNotHandled;
  302.     }
  303.  
  304.     return menuHandled;
  305. }
  306.  
  307. //----------------------------------------------------------------------------------------
  308. //    CFormPart::DoAbout
  309. //----------------------------------------------------------------------------------------
  310.  
  311. FW_Handled CFormPart::DoAbout(Environment* ev)
  312. {
  313.     ::FW_About(ev, this, kAbout);
  314.     
  315.     return FW_kHandled;
  316. }
  317.  
  318. //----------------------------------------------------------------------------------------
  319. // CFormPart::DoAdjustMenus
  320. //----------------------------------------------------------------------------------------
  321.  
  322. FW_Handled CFormPart::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, 
  323.                                      FW_Boolean hasMenuFocus,
  324.                                      FW_Boolean isRoot)    // Override
  325. {
  326. FW_UNUSED(isRoot);
  327.     if (hasMenuFocus)
  328.     {    
  329.         // ToDo: should enable command only if the form has changed
  330.         menuBar->EnableCommand(ev, cResetFormCommand, true);
  331. #if FW_PPOB_VIEWS  && defined(FW_DEBUG)
  332.         menuBar->EnableCommand(ev, cReloadPPobViews, true);
  333. #endif
  334. #if FW_MACAPP_VIEWS  && defined(FW_DEBUG)
  335.         menuBar->EnableCommand(ev, cReloadMacAppViews, true);
  336. #endif
  337.     }
  338.     return FW_kNotHandled;
  339. }
  340.  
  341. //----------------------------------------------------------------------------------------
  342. // CFormPart::DoFormCommand
  343. //----------------------------------------------------------------------------------------
  344.  
  345. void CFormPart::DoFormCommand(Environment* ev)
  346. {
  347.     // This sample doesn't use a Content model yet. For now the "reset" command will 
  348.     // simply erase the text in the edit-fields of each frame
  349.     
  350.     FW_CPresentationFrameIterator iter(ev, fMainPresentation);
  351.     for (CFormFrame* frame = (CFormFrame*)iter.First(ev); iter.IsNotComplete(ev); frame = (CFormFrame*)iter.Next(ev))
  352.     {
  353.         CFormView* formView = (CFormView*) frame->GetContentView(ev);
  354.         formView->ResetData(ev);                
  355.     }
  356.  
  357. #if 0
  358.     // [LSD] PartMaker-generated code, not used yet because we don't have a content model
  359.         
  360.     // Mark the document as changed so it can be saved
  361.     Changed(ev);
  362.  
  363.     // Mark the display frame as changed, so that containing parts can update links
  364.     fMainPresentation->ContentUpdated(ev);
  365.  
  366.     // Force all frames to be redrawn
  367.     fMainPresentation->Invalidate(ev);
  368. #endif
  369. }
  370.  
  371. //----------------------------------------------------------------------------------------
  372. // CFormPart::GetResourceString
  373. //----------------------------------------------------------------------------------------
  374.  
  375. void CFormPart::GetResourceString(Environment* ev,
  376.                                   FW_ResourceID multiStringID,
  377.                                   FW_ResourceID stringID,
  378.                                   FW_CString& string)
  379. {
  380.     // ----- Open the resource file for this shared library -----
  381.     FW_PSharedLibraryResourceFile resFile(ev);
  382.  
  383.     // ----- Read the string from the resource file -----
  384.     ::FW_LoadStringByID(ev, resFile, multiStringID, FW_kMultiStringRes, stringID, string);
  385. }
  386.  
  387.