home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 10.7 KB | 387 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: Part.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "Form.hpp"
-
- #ifndef PART_H
- #include "Part.h"
- #endif
-
- #ifndef CONTENT_H
- #include "Content.h"
- #endif
-
- #ifndef FRAME_H
- #include "Frame.h"
- #endif
-
- #ifndef DIALOG_H
- #include "Dialog.h"
- #endif
-
- #ifndef VIEW_H
- #include "View.h"
- #endif
-
- #ifndef SCROLLED_H
- #include "ScrollEd.h"
- #endif
-
- #ifndef BINDING_K
- #include "Binding.k"
- #endif
-
- // ----- Framework Layer -----
-
- #ifndef FWABOUT_H
- #include "FWAbout.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWITERS_H
- #include "FWIters.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- #ifndef FWSCLBAR_H
- #include "FWSclBar.h"
- #endif
-
- #ifndef FWKIND_H
- #include "FWKind.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWMENU_H
- #include "FWMenu.h"
- #endif
-
- #ifndef FWCFMRES_H
- #include "FWCFMRes.h"
- #endif
-
- #ifndef FWRESTYP_H
- #include "FWResTyp.h"
- #endif
-
- #ifndef FWSUSINK_H
- #include "FWSUSink.h"
- #endif
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef FWPICSHP_H
- #include "FWPicShp.h"
- #endif
-
- #ifndef SLMixOS_H
- #include "SLMixOS.h"
- #endif
-
- // ----- Foundation Layer -----
-
- #ifndef FWSTREAM_H
- #include "FWStream.h"
- #endif
-
- #ifndef FWSTRS_H
- #include "FWStrs.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- // ----- PPob View Support -----
-
- #if FW_PPOB_VIEWS
- #include "FWPPobRd.h"
- #endif
-
- // ----- MacApp View Support -----
-
- #if FW_MACAPP_VIEWS
- #include "FWMARead.h"
- #endif
-
- //========================================================================================
- // Runtime info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfform
- #endif
-
- FW_DEFINE_AUTO(CFormPart)
-
- //========================================================================================
- // CFormPart class
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CFormPart constructor
- //----------------------------------------------------------------------------------------
-
- CFormPart::CFormPart(ODPart* odPart) :
- FW_CPart(odPart, FW_gInstance, kPartInfoID),
- fTextData(""),
- fIsForm(TRUE),
- fMainPresentation(NULL),
- fPwdDialogPresentation(NULL)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CFormPart destructor
- //----------------------------------------------------------------------------------------
-
- CFormPart::~CFormPart()
- {
- FW_START_DESTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CFormPart::Initialize
- //----------------------------------------------------------------------------------------
-
- void CFormPart::Initialize(Environment* ev, ODStorageUnit* storageUnit, FW_Boolean fromStorage) // Override
- {
- FW_CPart::Initialize(ev, storageUnit, fromStorage);
-
- // ----- Register our Presentations
- // By not passing a view id for fMainPresentation we force ODF to call our frame's
- // CreateSubView method.
- fMainPresentation = RegisterPresentation(ev, kMainPresentation, TRUE, NULL);
- #if FW_ODFRC_VIEWS
- fPwdDialogPresentation = RegisterPresentation(ev, kPasswordDialogPresentation, FALSE,
- kPasswordDialog, kPasswordDialog, NULL);
- #else
- fPwdDialogPresentation = RegisterPresentation(ev, kPasswordDialogPresentation, FALSE,
- FW_kNoViewID, FW_kNoViewID, NULL);
- #endif
-
- // ----- Register one extra kind -----
-
- #if FW_ODFRC_VIEWS
- // nothing to do
-
- #elif FW_PPOB_VIEWS
- // Register the standard PP classes
- FW_CPPobReader::RegisterAllPPClasses();
-
- // Register the PP view classes for this part
- FW_CPPobReader::RegisterClass('Form', CPPobFormView::Create);
- FW_CPPobReader::RegisterClass('PwEd', CPPobPwdEditView::Create);
- FW_CPPobReader::RegisterClass('ScEd', CPPobScrollEdit::Create);
-
- #elif FW_MACAPP_VIEWS
- // Register the standard MacApp classes
- FW_CMacAppReader::RegisterAllMacAppClasses();
-
- // Register our custom MacApp view classes for this part
- // Note: We register kStdTEView again (after RegisterAllMacAppClasses) in order
- // to map it to our CScrollEdit class instead of the simpler FW_CEditView.
- // (We could also have defined a custom TScrollEdit class in Ad Lib)
- FW_CMacAppReader::RegisterClassName(FW_CString("TForm"), CMAFormView::Create);
- FW_CMacAppReader::RegisterClassName(FW_CString("TPwdEdit"), CMAPwdEditView::Create);
- FW_CMacAppReader::RegisterSignature(kStdTEView, CMAScrollEdit::Create);
- #endif
-
- // WARNING: Make sure that classes created from resources won't be dead-stripped!
- FW_DO_NOT_DEAD_STRIP(FW_CGrowBox);
- FW_DO_NOT_DEAD_STRIP(FW_CScrollBarScroller);
- FW_DO_NOT_DEAD_STRIP(FW_CGroupBox);
- FW_DO_NOT_DEAD_STRIP(FW_CScrollBar);
- FW_DO_NOT_DEAD_STRIP(FW_CEditView);
- FW_DO_NOT_DEAD_STRIP(FW_CListBox);
- FW_DO_NOT_DEAD_STRIP(FW_CButton);
- FW_DO_NOT_DEAD_STRIP(FW_CRadioCluster);
- FW_DO_NOT_DEAD_STRIP(FW_CPopupMenu);
- }
-
- //----------------------------------------------------------------------------------------
- // CFormPart::NewPartContent
- //----------------------------------------------------------------------------------------
- // ODF Method
-
- FW_CContent* CFormPart::NewPartContent(Environment* ev)
- {
- return (FW_NEW(CFormContent, (ev, this)));
- }
-
- //----------------------------------------------------------------------------------------
- // CFormPart::NewFrame
- //----------------------------------------------------------------------------------------
-
- FW_CFrame* CFormPart::NewFrame(Environment* ev,
- ODFrame* odFrame,
- FW_CPresentation* presentation,
- FW_Boolean fromStorage) // Override
- {
- FW_UNUSED(fromStorage);
- FW_CFrame* newFrame = NULL;
-
- if (presentation == fMainPresentation) {
- // Create the frame for the main presentation
- newFrame = FW_NEW(CFormFrame, (ev, odFrame, presentation, this));
- }
- else if (presentation == fPwdDialogPresentation) {
- // Create the frame for the dialog presentation, using an ODFRC resource id
- newFrame = FW_NEW(CPwdDialogFrame, (ev, odFrame, presentation, this));
- }
-
- return newFrame;
- }
-
- //----------------------------------------------------------------------------------------
- // CFormPart::DoMenu
- //----------------------------------------------------------------------------------------
-
- FW_Handled CFormPart::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent) // Override
- {
- FW_Handled menuHandled = FW_kHandled;
- ODCommandID id = theMenuEvent.GetCommandID(ev);
-
- switch (id)
- {
- case cResetFormCommand:
- DoFormCommand(ev);
- break;
-
- #if FW_MACAPP_VIEWS && defined(FW_DEBUG)
- case cReloadMacAppViews:
- // Reload the views from an external resource file.
- // NOTE: we were lazy here... this command should be handled by CFormFrame!
- // Also, instead of reloading views for all frames of fMainPresentation
- // we do it only for the active frame, so you could end up having 2
- // different Form frame! (try it with View In Window)
- FW_CFrame* frame = GetLastActiveFrame(ev);
- CFormFrame* formFrame = FW_DYNAMIC_CAST(CFormFrame, frame);
- if (formFrame)
- FW_PlatformError error = FW_CMacAppReader::ReloadViews(ev,
- kFormView,
- formFrame,
- formFrame,
- FW_CMacAppReader::kCurrentResFile);
- break;
- #endif
- #if FW_PPOB_VIEWS && defined(FW_DEBUG)
- case cReloadPPobViews:
- // Reload the views from an external resource file.
- // (Same as for MacApp, see note above)
- FW_CFrame* frame = GetLastActiveFrame(ev);
- CFormFrame* formFrame = FW_DYNAMIC_CAST(CFormFrame, frame);
- if (formFrame)
- FW_PlatformError error = FW_CPPobReader::ReloadViews(ev,
- kFormView,
- formFrame,
- formFrame,
- FW_CPPobReader::kCurrentResFile);
- break;
- #endif
- default:
- menuHandled = FW_kNotHandled;
- }
-
- return menuHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // CFormPart::DoAbout
- //----------------------------------------------------------------------------------------
-
- FW_Handled CFormPart::DoAbout(Environment* ev)
- {
- ::FW_About(ev, this, kAbout);
-
- return FW_kHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // CFormPart::DoAdjustMenus
- //----------------------------------------------------------------------------------------
-
- FW_Handled CFormPart::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar,
- FW_Boolean hasMenuFocus,
- FW_Boolean isRoot) // Override
- {
- FW_UNUSED(isRoot);
- if (hasMenuFocus)
- {
- // ToDo: should enable command only if the form has changed
- menuBar->EnableCommand(ev, cResetFormCommand, true);
- #if FW_PPOB_VIEWS && defined(FW_DEBUG)
- menuBar->EnableCommand(ev, cReloadPPobViews, true);
- #endif
- #if FW_MACAPP_VIEWS && defined(FW_DEBUG)
- menuBar->EnableCommand(ev, cReloadMacAppViews, true);
- #endif
- }
- return FW_kNotHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // CFormPart::DoFormCommand
- //----------------------------------------------------------------------------------------
-
- void CFormPart::DoFormCommand(Environment* ev)
- {
- // This sample doesn't use a Content model yet. For now the "reset" command will
- // simply erase the text in the edit-fields of each frame
-
- FW_CPresentationFrameIterator iter(ev, fMainPresentation);
- for (CFormFrame* frame = (CFormFrame*)iter.First(ev); iter.IsNotComplete(ev); frame = (CFormFrame*)iter.Next(ev))
- {
- CFormView* formView = (CFormView*) frame->GetContentView(ev);
- formView->ResetData(ev);
- }
-
- #if 0
- // [LSD] PartMaker-generated code, not used yet because we don't have a content model
-
- // Mark the document as changed so it can be saved
- Changed(ev);
-
- // Mark the display frame as changed, so that containing parts can update links
- fMainPresentation->ContentUpdated(ev);
-
- // Force all frames to be redrawn
- fMainPresentation->Invalidate(ev);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // CFormPart::GetResourceString
- //----------------------------------------------------------------------------------------
-
- void CFormPart::GetResourceString(Environment* ev,
- FW_ResourceID multiStringID,
- FW_ResourceID stringID,
- FW_CString& string)
- {
- // ----- Open the resource file for this shared library -----
- FW_PSharedLibraryResourceFile resFile(ev);
-
- // ----- Read the string from the resource file -----
- ::FW_LoadStringByID(ev, resFile, multiStringID, FW_kMultiStringRes, stringID, string);
- }
-
-