home *** CD-ROM | disk | FTP | other *** search
Wrap
Text File | 1996-09-17 | 14.2 KB | 522 lines | [ TEXT/MPS ]
//======================================================================================== // // File: Part.cpp // Release Version: $ ODF 2 $ // // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved. // //======================================================================================== #ifndef PART_H #include "Part.h" #endif #ifndef FRAME_H #include "Frame.h" #endif #ifndef DIALOG_H #include "Dialog.h" #endif #ifndef DEFINES_K #include "Defines.k" #endif #ifndef BINDING_K #include "Binding.k" #endif // ----- Framework Includes ----- #ifndef FWUTIL_H #include "FWUtil.h" #endif #ifndef FWITERS_H #include "FWIters.h" #endif #ifndef FWCFMRES_H #include "FWCFMRes.h" #endif #ifndef FWABOUT_H #include "FWAbout.h" #endif #ifndef FWMENUS_K #include "FWMenus.k" #endif #ifndef FWMNUBAR_H #include "FWMnubar.h" #endif #ifndef SLMIXOS_H #include "SLMixOS.h" #endif // ----- PPob View Support ----- #if FW_PPOB_VIEWS #include "FWPPobRd.h" #endif // ----- MacApp View Support ----- #if FW_MACAPP_VIEWS #include "FWMARead.h" #endif //======================================================================================== // Runtime informations //======================================================================================== #ifdef FW_BUILD_MAC #pragma segment viewtester #endif //======================================================================================== // CLASS CViewTesterPart //======================================================================================== FW_DEFINE_AUTO(CViewTesterPart) //---------------------------------------------------------------------------------------- // CViewTesterPart::CViewTesterPart //---------------------------------------------------------------------------------------- CViewTesterPart::CViewTesterPart(ODPart* odPart): FW_CPart(odPart, FW_gInstance, kPartInfoID), fViewTestFrame(0), fViewID(-1), fUsingMacApp(true) { } //---------------------------------------------------------------------------------------- // CViewTesterPart::~CViewTesterPart //---------------------------------------------------------------------------------------- CViewTesterPart::~CViewTesterPart() { } //---------------------------------------------------------------------------------------- // CViewTesterPart::Initialize //---------------------------------------------------------------------------------------- void CViewTesterPart::Initialize(Environment* ev, ODStorageUnit* storageUnit, FW_Boolean fromStorage) { FW_CPart::Initialize(ev, storageUnit, fromStorage); fMainPresentation = RegisterPresentation(ev, kMainPresentation, TRUE, kMainViewID, kMainViewID); fDialogPresentation = RegisterPresentation(ev, kDialogPresentation, FALSE, kDialogID, kDialogID); fTestPresentation = RegisterPresentation(ev, kTestPresentation, FALSE); #if FW_MACAPP_VIEWS // Register the standard MacApp classes FW_CMacAppReader::RegisterAllMacAppClasses(); #endif #if FW_PPOB_VIEWS // Register the standard PP classes FW_CPPobReader::RegisterAllPPClasses(); #endif // Make sure that classes created from ODFRC 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); FW_DO_NOT_DEAD_STRIP(FW_CStaticText); FW_DO_NOT_DEAD_STRIP(FW_CPictSView); } //---------------------------------------------------------------------------------------- // CViewTesterPart::NewFrame //---------------------------------------------------------------------------------------- FW_CFrame* CViewTesterPart::NewFrame(Environment* ev, ODFrame* odFrame, FW_CPresentation* presentation, FW_Boolean fromStorage) { FW_UNUSED(fromStorage); FW_CFrame* newFrame = NULL; if (presentation == fMainPresentation) newFrame = FW_NEW(FW_CFrame, (ev, odFrame, presentation, this)); else if (presentation == fDialogPresentation) newFrame = FW_NEW(CDialogFrame, (ev, odFrame, presentation, this)); else if (presentation == fTestPresentation) { if(fViewTestFrame == 0) { newFrame = FW_NEW(CViewTesterFrame, (ev, odFrame, presentation, this)); fViewTestFrame = FW_DYNAMIC_CAST(CViewTesterFrame, newFrame); } else FW_DEBUG_MESSAGE("This parts allows only 1 test frame"); } return newFrame; } //---------------------------------------------------------------------------------------- // CViewTesterPart::NewPartContent //---------------------------------------------------------------------------------------- FW_CContent* CViewTesterPart::NewPartContent(Environment* ev) { return NULL; } //---------------------------------------------------------------------------------------- // CViewTesterPart::DoMenu //---------------------------------------------------------------------------------------- FW_Handled CViewTesterPart::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent) { FW_Handled handled = FW_kHandled; FW_PlatformError error; ODCommandID commandID = theMenuEvent.GetCommandID(ev); switch (commandID) { case cReloadMAViews: FW_ASSERT(fViewTestFrame); fUsingMacApp = true; error = FW_CMacAppReader::ReloadViews(ev, fViewID, fViewTestFrame, 0, FW_CMacAppReader::kCurrentResFile, HasWarningsOn(ev)); CheckForError(ev, error); break; case cReloadPPobViews: FW_ASSERT(fViewTestFrame); fUsingMacApp = false; if (theMenuEvent.IsExtendModifier(ev)) FW_CPPobReader::UseClassAlias(true); error = FW_CPPobReader::ReloadViews(ev, fViewID, fViewTestFrame, 0, FW_CPPobReader::kCurrentResFile, HasWarningsOn(ev)); FW_CPPobReader::UseClassAlias(false); CheckForError(ev, error); break; case cLoadNewMAViews: fUsingMacApp = true; OpenDialog(ev); break; case cLoadNewPPobViews: fUsingMacApp = false; OpenDialog(ev); break; case cLoadNewMAResFile: { // Pick a new resource file first. FW_PResourceFile* resFile = FW_CMacAppReader::GetResFile(ev, FW_CMacAppReader::kNewResFile); if (resFile) { delete resFile; fUsingMacApp = true; OpenDialog(ev); // Pick a resource id in the dialog } } break; case cLoadNewPPobResFile: { // Pick a new resource file first. FW_PResourceFile* resFile = FW_CPPobReader::GetResFile(ev, FW_CPPobReader::kNewResFile); if (resFile) { delete resFile; fUsingMacApp = false; OpenDialog(ev); // Pick a resource id in the dialog } } break; default: handled = FW_kNotHandled; } return handled; } //---------------------------------------------------------------------------------------- // CViewTesterPart::DoAbout //---------------------------------------------------------------------------------------- FW_Handled CViewTesterPart::DoAbout(Environment* ev) { ::FW_About(ev, this, kAbout); return FW_kHandled; } //---------------------------------------------------------------------------------------- // CViewTesterPart::DoAdjustMenus //---------------------------------------------------------------------------------------- FW_Handled CViewTesterPart::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, FW_Boolean hasMenuFocus, FW_Boolean isRoot) { // ----- Edit Menu ----- if (hasMenuFocus) { #if FW_MACAPP_VIEWS { FW_Boolean hasResFile = FW_CMacAppReader::HasResFile(); FW_Boolean canReload = hasResFile && (fViewTestFrame != 0); menuBar->EnableCommand(ev, cReloadMAViews, canReload); menuBar->EnableCommand(ev, cLoadNewMAViews, hasResFile); menuBar->EnableCommand(ev, cLoadNewMAResFile, true); } #endif #if FW_PPOB_VIEWS { FW_Boolean hasResFile = FW_CPPobReader::HasResFile(); FW_Boolean canReload = hasResFile && (fViewTestFrame != 0); menuBar->EnableCommand(ev, cReloadPPobViews, canReload); menuBar->EnableCommand(ev, cLoadNewPPobViews, hasResFile); menuBar->EnableCommand(ev, cLoadNewPPobResFile, true); } #endif } return FW_kNotHandled; } //---------------------------------------------------------------------------------------- // CViewTesterPart::OpenDialog //---------------------------------------------------------------------------------------- void CViewTesterPart::OpenDialog(Environment* ev) { // Prepare dialog attributes FW_CPoint position(FW_kZeroPoint); FW_CPoint size(FW_IntToFixed(330), FW_IntToFixed(160)); FW_WindowStyle style = FW_kStandardDialogPosition | FW_kHasCaption; FW_CString fileName; if (fUsingMacApp) FW_CMacAppReader::GetResFileName(ev, fileName); else FW_CPPobReader::GetResFileName(ev, fileName); FW_CString title = "Resources of "; title += fileName; // HACK: in order to create the popup menus containing the list of MacApp or PPob // resources we need to open the proper resource file before creating the dialog FW_PResourceFile* resFile = 0; if (fUsingMacApp) resFile = FW_CMacAppReader::GetResFile(ev, FW_CMacAppReader::kCurrentResFile); else resFile = FW_CPPobReader::GetResFile(ev, FW_CPPobReader::kCurrentResFile); // ----- Create new dialog window ----- CDialogFrame* dialog = (CDialogFrame*) FW_CDialogFrame::NewModalDialog(ev, this, fDialogPresentation, size, position, style, title); delete resFile; if (dialog != NULL) { dialog->Initialize(ev); dialog->GetWindow(ev)->Show(ev); } } //---------------------------------------------------------------------------------------- // CViewTesterPart::CheckForError //---------------------------------------------------------------------------------------- void CViewTesterPart::CheckForError(Environment* ev, FW_PlatformError error) { FW_CString fileName; if (fUsingMacApp) FW_CMacAppReader::GetResFileName(ev, fileName); else FW_CPPobReader::GetResFileName(ev, fileName); FW_CString idstr; idstr.ReplaceAllAsUnsignedDecimalInteger(fViewID); // Bring the test frame's window to the front and update its title FW_CString winTitle; winTitle = fileName; winTitle += " (view id "; winTitle += idstr; winTitle += ")"; FW_CWindow* testWindow = fViewTestFrame->GetWindow(ev); testWindow->SetWindowTitle(ev, winTitle); testWindow->Select(ev); // Update the error log FW_CString errorStr = ""; if (error != FW_xNoError) { FW_Beep(); errorStr += "Error reading "; if (fUsingMacApp) errorStr += "MacApp 'View' resource ID "; else errorStr += "PowerPlant 'PPob' resource ID "; errorStr += idstr; // errorStr += " in "; // errorStr += fileName; switch(error) { case FW_xResourceNotFound: case FW_xResourceNotLoaded: errorStr += ": resource not found!"; break; case FW_xReadableStream: errorStr += ": found invalid data or couldn't skip unknown view!"; break; case FW_xWrongViewResourceVersion: errorStr += ": wrong view resource version!"; break; case FW_xUnknownError: errorStr += ": unknown error! (Please report to the ODF-Interest list)"; break; default: FW_CString errorStr; errorStr.ReplaceAllAsSignedDecimalInteger(error); errorStr += ": ODF error "; errorStr += errorStr; errorStr += " (see definitions in FWErrors.h)"; break; } } else if (fUsingMacApp == false && FW_CPPobReader::FoundViewWithAlias() == true) { FW_Beep(); errorStr += "Some pink (unregistered) views are simple subclasses of registered views. Hold the Shift key down and do 'Reload Views' to use the known views"; } FW_CPresentationFrameIterator ite(ev, fMainPresentation); for (FW_CFrame* frame = ite.First(ev); ite.IsNotComplete(ev); frame = ite.Next(ev)) { FW_CView* view = frame->FindViewByID(ev, 1); FW_CEditView* viewTEd = FW_DYNAMIC_CAST(FW_CEditView, view); FW_ASSERT(viewTEd); viewTEd->SetText(ev, errorStr); } } //---------------------------------------------------------------------------------------- // CViewTesterPart::ChangeViews //---------------------------------------------------------------------------------------- void CViewTesterPart::ChangeViews(Environment* ev, ODID viewID) { fViewID = viewID; if (fViewTestFrame == 0) { // Create the test frame in a new window. FW_CPoint size(FW_IntToFixed(200), FW_IntToFixed(100)); FW_CPoint position(FW_IntToFixed(3), FW_IntToFixed(3)); FW_CWindow* testWindow = new FW_CWindow(ev, this, NULL, // no parent frame FALSE, // not persistent FW_CPart::fgViewAsFrameToken, fTestPresentation, "TestFrame", // updated after loading views size, // updated after loading views position, // updated after loading views FW_kDocumentWindow); FW_ASSERT(fViewTestFrame); // Showing the window will call FacetAdded and CViewTesterFrame::CreateSubView testWindow->Show(ev); } else { FW_PlatformError error; if (fUsingMacApp) error = FW_CMacAppReader::ReloadViews(ev, viewID, fViewTestFrame, 0, FW_CMacAppReader::kCurrentResFile, HasWarningsOn(ev)); else error = FW_CPPobReader::ReloadViews(ev, viewID, fViewTestFrame, 0, FW_CPPobReader::kCurrentResFile, HasWarningsOn(ev)); CheckForError(ev, error); } } //---------------------------------------------------------------------------------------- // CViewTesterPart::HasWarningsOn //---------------------------------------------------------------------------------------- FW_Boolean CViewTesterPart::HasWarningsOn(Environment* ev) { // This is not very clean.. we read the warnings check-box state from the 1st frame. // (I was lazy and didn't want to create a FW_CFrame class for fMainPresentation!) FW_CPresentationFrameIterator ite(ev, fMainPresentation); FW_CFrame* frame = ite.First(ev); if (frame) { FW_CView* view = frame->FindViewByID(ev, 2); FW_CButton* button = FW_DYNAMIC_CAST(FW_CButton, view); return (button->GetState(ev) == false); } else return true; }