home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / Form / Sources / Part.cpp < prev    next >
Encoding:
Text File  |  1996-04-25  |  9.0 KB  |  337 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FormPrt.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Author:                Laurent Delamare
  7. //
  8. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "Form.hpp"
  13.  
  14. #ifndef PART_H
  15. #include "Part.h"
  16. #endif
  17.  
  18. #ifndef FRAME_H
  19. #include "Frame.h"
  20. #endif
  21.  
  22. #ifndef DIALOG_H
  23. #include "Dialog.h"
  24. #endif
  25.  
  26. #ifndef FORMVIEW_H
  27. #include "FormView.h"
  28. #endif
  29.  
  30. #ifndef BINDING_K
  31. #include "Binding.k"
  32. #endif
  33.  
  34. // ----- Framework Layer -----
  35.  
  36. #ifndef FWABOUT_H
  37. #include "FWAbout.h"
  38. #endif
  39.  
  40. #ifndef FWUTIL_H
  41. #include "FWUtil.h"
  42. #endif
  43.  
  44. #ifndef FWITERS_H
  45. #include "FWIters.h"
  46. #endif
  47.  
  48. #ifndef FWPRESEN_H
  49. #include "FWPresen.h"
  50. #endif
  51.  
  52. #ifndef FWSCLBAR_H
  53. #include "FWSclBar.h"
  54. #endif
  55.  
  56. // ----- OS Layer -----
  57.  
  58. #ifndef FWMENU_H
  59. #include "FWMenu.h"
  60. #endif
  61.  
  62. #ifndef FWCFMRES_H
  63. #include "FWCFMRes.h"
  64. #endif
  65.  
  66. #ifndef FWRESTYP_H
  67. #include "FWResTyp.h"
  68. #endif
  69.  
  70. #ifndef FWSUSINK_H
  71. #include "FWSUSink.h"
  72. #endif
  73.  
  74. #ifndef FWEVENT_H
  75. #include "FWEvent.h"
  76. #endif
  77.  
  78. #ifndef FWPICSHP_H
  79. #include "FWPicShp.h"
  80. #endif
  81.  
  82. #ifndef SLMixOS_H
  83. #include "SLMixOS.h"
  84. #endif
  85.  
  86. // ----- Foundation Layer -----
  87.  
  88. #ifndef FWSTREAM_H
  89. #include "FWStream.h"
  90. #endif
  91.  
  92. #ifndef FWSTRS_H
  93. #include "FWStrs.h"
  94. #endif
  95.  
  96. // ----- OpenDoc Includes -----
  97.  
  98. #ifndef SOM_Module_OpenDoc_StdProps_defined
  99. #include <StdProps.xh>
  100. #endif
  101.  
  102. //========================================================================================
  103. // Constants
  104. //========================================================================================
  105.  
  106. #define kMainPresentation                "ODF:Presentation:Form"
  107. #define kPasswordDialogPresentation        "ODF:Presentation:Form:PasswordDialog"
  108. #define kInvalidDialogPresentation        "ODF:Presentation:Form:InvalidDialog"
  109.  
  110. //========================================================================================
  111. //    Runtime info
  112. //========================================================================================
  113.  
  114. #ifdef FW_BUILD_MAC
  115. #pragma segment odfform
  116. #endif
  117.  
  118. FW_DEFINE_AUTO(CFormPart)
  119.  
  120. //========================================================================================
  121. //    CFormPart class
  122. //========================================================================================
  123.  
  124. //----------------------------------------------------------------------------------------
  125. // CFormPart constructor
  126. //----------------------------------------------------------------------------------------
  127.  
  128. CFormPart::CFormPart(ODPart* odPart) :
  129.     FW_CPart(odPart, FW_gInstance, kPartInfoID),
  130.     fTextData(""),
  131.     fIsForm(TRUE),
  132.     fMainPresentation(NULL),
  133.     fPwdDialogPresentation(NULL),
  134.     fPictShape1(NULL),
  135.     fPictShape2(NULL)
  136. {
  137. }
  138.  
  139. //----------------------------------------------------------------------------------------
  140. // CFormPart destructor
  141. //----------------------------------------------------------------------------------------
  142.  
  143. CFormPart::~CFormPart()
  144. {
  145.     delete fPictShape1; 
  146.     delete fPictShape2; 
  147. }
  148.  
  149. //----------------------------------------------------------------------------------------
  150. // CFormPart::Initialize
  151. //----------------------------------------------------------------------------------------
  152.  
  153. void CFormPart::Initialize(Environment* ev)    // Override
  154. {
  155.     FW_CPart::Initialize(ev);
  156.  
  157.     // ----- Register our Presentations
  158.     fMainPresentation = RegisterPresentation(ev, kMainPresentation, TRUE, NULL);    
  159.     fPwdDialogPresentation = RegisterPresentation(ev, kPasswordDialogPresentation, FALSE);
  160.  
  161.     // ----- Init MenuBar -----
  162.     GetMenuBar(ev)->InitializeFromResource(ev, kMenuBar);
  163.     
  164.     // ----- Initialize pictures
  165.     InitPicture(ev);
  166. }
  167.  
  168. //----------------------------------------------------------------------------------------
  169. // CFormPart::InitPicture
  170. //----------------------------------------------------------------------------------------
  171. // Keep picture shape with the part to share it among multiple frames
  172.  
  173. void CFormPart::InitPicture(Environment* ev)
  174. {
  175.     // Open the resource file for this shared library 
  176.     FW_CSharedLibraryResourceFile resFile(ev);    
  177.     
  178. #ifdef FW_BUILD_MAC
  179.     FW_CPicture formPict1(resFile, kFormPict1);
  180.     FW_CRect bounds;
  181.     formPict1.GetPictBounds(bounds);
  182.     fPictShape1 = FW_NEW(FW_CPictureShape, (formPict1, bounds));
  183.  
  184.     FW_CPicture formPict2(resFile, kFormPict2);
  185.     formPict2.GetPictBounds(bounds);
  186.     fPictShape2 = FW_NEW(FW_CPictureShape, (formPict2, bounds));
  187. #endif
  188. }
  189.  
  190. //----------------------------------------------------------------------------------------
  191. //    CFormPart::NewPartContent
  192. //----------------------------------------------------------------------------------------
  193. //    ODF Method
  194.  
  195. FW_CContent* CFormPart::NewPartContent(Environment* ev)
  196. {
  197.     return NULL;
  198. }
  199.  
  200. //----------------------------------------------------------------------------------------
  201. //    CFormPart::NewDocumentWindow
  202. //----------------------------------------------------------------------------------------
  203.  
  204. FW_CWindow* CFormPart::NewDocumentWindow(Environment* ev)
  205. {
  206.     FW_CPoint sbSize = FW_CScrollBar::GetDefaultScrollBarSize();
  207.  
  208.     FW_CRect    pictRect;
  209.     GetPictShape1()->GetRectangle(pictRect);
  210.         
  211.     FW_CRect screenBounds;
  212.     ::FW_GetMainScreenBounds(screenBounds);
  213.     screenBounds.Inset(FW_IntToFixed(3), FW_IntToFixed(3));
  214.     
  215.     return new FW_CWindow(ev,
  216.                         this,
  217.                          FW_CPart::gViewAsFrameToken,
  218.                         fMainPresentation,                // presentation
  219.                         pictRect.Size() + sbSize,        // interior size
  220.                         screenBounds.TopLeft(),            // position
  221.                         FW_kDocumentWindow);            // window style
  222. }
  223.  
  224. //----------------------------------------------------------------------------------------
  225. // CFormPart::NewFrame
  226. //----------------------------------------------------------------------------------------
  227.  
  228. FW_CFrame* CFormPart::NewFrame(Environment* ev,
  229.                                 ODFrame* odFrame,
  230.                                 FW_CPresentation* presentation,
  231.                                 FW_Boolean fromStorage)    // Override
  232. {
  233.     FW_UNUSED(fromStorage);
  234.     FW_CFrame* newFrame = NULL;
  235.  
  236.     if (presentation == fMainPresentation) {
  237.         // Create the frame for the main presentation
  238.         newFrame = FW_NEW(CFormFrame, (ev, odFrame, presentation, this));
  239.     }
  240.     else if (presentation == fPwdDialogPresentation) {
  241.         // Create the frame for the dialog presentation, using a resource id
  242.         newFrame = FW_NEW(CPwdDialogFrame, 
  243.                                     (ev, odFrame, presentation, this, kPasswordDialog));
  244.     }
  245.     
  246.     return newFrame;
  247. }
  248.  
  249. //----------------------------------------------------------------------------------------
  250. // CFormPart::DoMenu
  251. //----------------------------------------------------------------------------------------
  252.  
  253. FW_Boolean CFormPart::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent) // Override
  254. {
  255.     FW_Boolean menuHandled = TRUE;
  256.     ODCommandID id = theMenuEvent.GetCommandID(ev);
  257.     
  258.     switch (id)
  259.     {
  260.         case cResetFormCommand:
  261.             DoFormCommand(ev, id);
  262.             break;
  263.         
  264.         case kODCommandAbout:
  265.             ::FW_About(ev, this, kAbout);
  266.             break;
  267.  
  268.         default:
  269.             menuHandled = FALSE;
  270.     }
  271.     
  272.     return menuHandled;
  273. }
  274.  
  275. //----------------------------------------------------------------------------------------
  276. // CFormPart::DoAdjustMenus
  277. //----------------------------------------------------------------------------------------
  278.  
  279. FW_Boolean CFormPart::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, 
  280.                                      FW_Boolean hasMenuFocus,
  281.                                      FW_Boolean isRoot)    // Override
  282. {
  283.     if (hasMenuFocus)
  284.     {    
  285.         // ToDo: should enable command only if the form has changed
  286.         menuBar->EnableCommand(ev, cResetFormCommand, true);
  287.     }
  288.     return FALSE;
  289. }
  290.  
  291. //----------------------------------------------------------------------------------------
  292. // CFormPart::DoFormCommand
  293. //----------------------------------------------------------------------------------------
  294.  
  295. void CFormPart::DoFormCommand(Environment* ev, ODCommandID id)
  296. {
  297.     // This sample doesn't use a Content model yet. For now the "reset" command will 
  298.     // simply erase the text in the edit-fields of each frame
  299.     
  300.     FW_CPresentationFrameIterator iter(ev, fMainPresentation);
  301.     for (CFormFrame* frame = (CFormFrame*)iter.First(ev); iter.IsNotComplete(ev); frame = (CFormFrame*)iter.Next(ev))
  302.     {
  303.         CFormView* formView = (CFormView*) frame->GetContentView(ev);
  304.         formView->ResetData(ev);                
  305.     }
  306.  
  307. #if 0
  308.     // [LSD] PartMaker-generated code, not used yet because we don't have a content model
  309.         
  310.     // Mark the document as changed so it can be saved
  311.     Changed(ev);
  312.  
  313.     // Mark the display frame as changed, so that containing parts can update links
  314.     fMainPresentation->ContentUpdated(ev);
  315.  
  316.     // Force all frames to be redrawn
  317.     fMainPresentation->Invalidate(ev);
  318. #endif
  319. }
  320.  
  321. //----------------------------------------------------------------------------------------
  322. // CFormPart::GetResourceString
  323. //----------------------------------------------------------------------------------------
  324.  
  325. void CFormPart::GetResourceString(Environment* ev,
  326.                                   FW_ResourceId multiStringId,
  327.                                   FW_ResourceId stringId,
  328.                                   FW_CString& string)
  329. {
  330.     // ----- Open the resource file for this shared library -----
  331.     FW_CSharedLibraryResourceFile resFile(ev);
  332.  
  333.     // ----- Read the string from the resource file -----
  334.     ::FW_LoadStringByID(ev, resFile, multiStringId, MULTISTRINGRES, stringId, string);
  335. }
  336.  
  337.