home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-23 | 8.8 KB | 337 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: IntlTest.cpp
- // Release Version: $ ODF 1 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "IntlTest.hpp"
-
- #ifndef PART_H
- #include "Part.h"
- #endif
-
- #ifndef CONTENT_H
- #include "Content.h"
- #endif
-
- #ifndef BINDING_K
- #include "Binding.k"
- #endif
-
- #ifndef FRAME_H
- #include "Frame.h"
- #endif
-
- #ifndef SELECT_H
- #include "Select.h"
- #endif
-
- // ----- Framework Layer -----
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWITERS_H
- #include "FWIters.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- #ifndef FWEDVIEW_H
- #include "FWEdView.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 FWBARRAY_H
- #include "FWBArray.h"
- #endif
-
- #ifndef FWABOUT_H
- #include "FWAbout.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWSTREAM_H
- #include "FWStream.h"
- #endif
-
- #ifndef FWSTRS_H
- #include "FWStrs.h"
- #endif
-
- #ifndef FWSUSINK_H
- #include "FWSUSink.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef SOM_ODTranslation_xh
- #include <Translt.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- //========================================================================================
- // Constants and Globals
- //========================================================================================
-
- #define kMainPresentation "ODFExamples:Presentation:ODFIntlTest"
-
- // Function prototype to satisfy compiler
- FW_CString MyLoadRStringByID(Environment* ev,
- FW_PResourceFile& file,
- FW_ResourceId resourceId,
- FW_ResourceType resourceType);
-
- //========================================================================================
- // Runtime info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfIntlTest
- #endif
-
- //========================================================================================
- // CIntlTestPart class
- //========================================================================================
-
- FW_DEFINE_AUTO(CIntlTestPart)
-
- //----------------------------------------------------------------------------------------
- // CIntlTestPart constructor
- //----------------------------------------------------------------------------------------
-
- CIntlTestPart::CIntlTestPart(ODPart* odPart) :
- FW_CPart(odPart, FW_gInstance, kPartInfoID),
- fPartContent(NULL),
- fPresentation(NULL),
- fTestFrame(NULL)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CIntlTestPart destructor
- //----------------------------------------------------------------------------------------
-
- CIntlTestPart::~CIntlTestPart()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CIntlTestPart::Initialize
- //----------------------------------------------------------------------------------------
-
- void CIntlTestPart::Initialize(Environment* ev)
- {
- FW_CPart::Initialize(ev);
-
- // ----- Register our Presentation
- CIntlTestSelection* selection = FW_NEW(CIntlTestSelection, (ev, this));
- fPresentation = RegisterPresentation(ev, kMainPresentation, TRUE, selection);
- fTestSelection = selection;
-
- // ----- Initialize my menu -----
- FW_CSharedLibraryResourceFile resFile(ev);
- GetMenuBar(ev)->InitializeFromResource(ev, kMenuBar);
- }
-
- //----------------------------------------------------------------------------------------
- // CIntlTestPart::NewFrame
- //----------------------------------------------------------------------------------------
-
- FW_CFrame* CIntlTestPart::NewFrame(Environment* ev,
- ODFrame* odFrame,
- FW_CPresentation* presentation,
- FW_Boolean fromStorage) // Override
- {
- FW_UNUSED(fromStorage);
- fTestFrame = FW_NEW(CIntlTestFrame, (ev, odFrame, presentation, this));
- return fTestFrame;
- }
-
- //------------------------------------------------------------------------------
- // CIntlTestPart::NewPartContent
- //------------------------------------------------------------------------------
-
- FW_CContent* CIntlTestPart::NewPartContent(Environment* ev)
- {
- fPartContent = FW_NEW(CIntlTestContent, (ev, this));
- return fPartContent;
- }
-
- //----------------------------------------------------------------------------------------
- // CIntlTestPart::DoMenu
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CIntlTestPart::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent) // Override
- {
- FW_Boolean menuHandled = true;
- ODCommandID id = theMenuEvent.GetCommandID(ev);
-
- switch (id)
- {
- case cFirstCommand:
- case cSecondCommand:
- // TBD
- break;
-
- case kODCommandAbout:
- ::FW_About(ev, this, kAboutBox);
- break;
-
- default:
- menuHandled = false;
- }
-
- return menuHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // CIntlTestPart::DoAdjustMenus
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CIntlTestPart::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar,
- FW_Boolean hasMenuFocus,
- FW_Boolean isRoot)
- {
- if (hasMenuFocus)
- {
- // ----- Set up the IntlTest menu
- // menuBar->EnableCommand(ev, cFirstCommand, true);
- // menuBar->EnableCommand(ev, cSecondCommand, true);
- }
-
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // CIntlTestPart::PartChanged
- //----------------------------------------------------------------------------------------
-
- void CIntlTestPart::PartChanged(Environment* ev)
- {
- // Mark the document's draft as changed so it can be saved
- this->Changed(ev);
-
- // Mark the display frame as changed, so that containing parts can update links
- fPresentation->ContentUpdated(ev);
- }
-
- //----------------------------------------------------------------------------------------
- ODID CIntlTestPart::WhichEditViewIsActive(Environment* ev)
- {
- ODID target = fTestFrame->GetActiveEditViewId(ev);
- return target;
- }
-
- //----------------------------------------------------------------------------------------
- FW_CString MyLoadRStringByID(Environment* ev,
- FW_PResourceFile& file,
- FW_ResourceId resourceId,
- FW_ResourceType resourceType)
- {
- FW_ASSERT(resourceType == TESTSTRINGRES);
-
- // FW_RString resource header
- struct RStringHeader
- {
- FW_Locale fLocale;
- short fLengthWord;
- };
-
- FW_PResource resource(ev, file, resourceId, resourceType);
- FW_CAcquireResourceData data(ev, resource);
- RStringHeader* p = (RStringHeader*) data.GetData();
-
- FW_Locale* pLocale = (FW_Locale*) p;
- FW_CString string(((const FW_Char*)p)+sizeof(RStringHeader), p->fLengthWord, (const FW_Locale&)*pLocale);
- return string;
- }
-
- //----------------------------------------------------------------------------------------
- void CIntlTestPart::UpdateTextData(Environment* ev)
- {
- FW_CString s;
-
- if (fTestFrame) // fTestFrame is NULL when creating stationery
- {
- FW_CEditView* editView;
-
- editView = fTestFrame->FindEditView(ev, kTextEditView);
- s = editView->GetText(ev);
- fPartContent->SetTextData(ev, s, kTextEditView);
-
- editView = fTestFrame->FindEditView(ev, kEnglishEditView);
- s = editView->GetText(ev);
- fPartContent->SetTextData(ev, s, kEnglishEditView);
-
- editView = fTestFrame->FindEditView(ev, kJapaneseEditView);
- s = editView->GetText(ev);
- fPartContent->SetTextData(ev, s, kJapaneseEditView);
- }
- else // creating stationery - load default strings from resources
- {
- FW_CSharedLibraryResourceFile resFile(ev);
- s = MyLoadRStringByID(ev, resFile, kDefaultTextStringID, TESTSTRINGRES);
- fPartContent->SetTextData(ev, s, kTextEditView);
- s = MyLoadRStringByID(ev, resFile, kDefaultEngStringID, TESTSTRINGRES);
- fPartContent->SetTextData(ev, s, kEnglishEditView);
- s = MyLoadRStringByID(ev, resFile, kDefaultJapStringID, TESTSTRINGRES);
- fPartContent->SetTextData(ev, s, kJapaneseEditView);
- }
- }
-
- //----------------------------------------------------------------------------------------
- void CIntlTestPart::UpdateViewsFromTextData(Environment* ev)
- {
- FW_CEditView* editView;
- FW_CString s;
-
- s = fPartContent->GetTextData(kTextEditView);
- editView = fTestFrame->FindEditView(ev, kTextEditView);
- editView->SetText(ev, s);
-
- s = fPartContent->GetTextData(kEnglishEditView);
- editView = fTestFrame->FindEditView(ev, kEnglishEditView);
- editView->SetText(ev, s);
-
- s = fPartContent->GetTextData(kJapaneseEditView);
- editView = fTestFrame->FindEditView(ev, kJapaneseEditView);
- editView->SetText(ev, s);
- }
-
-