home *** CD-ROM | disk | FTP | other *** search
Text File | 1993-11-10 | 6.4 KB | 256 lines | [TEXT/KAHL] |
- /****
- * CObjectDoc.c
- *
- * Document methods for a typical application.
- *
- * Copyright © 1990 Symantec Corporation. All rights reserved.
- *
- ****/
-
- #include <Global.h>
- #include <Commands.h>
- #include <CApplication.h>
- #include <CBartender.h>
- #include <CDataFile.h>
- #include <CDecorator.h>
- #include <CDesktop.h>
- #include <CError.h>
- #include <CPanorama.h>
- #include <CScrollPane.h>
- #include <TBUtilities.h>
- #include <CWindow.h>
- #include <Packages.h>
- #include <CTextEnvirons.h>
- #include "CObjectDoc.h"
- #include "CARTable.h"
- #include "CARArray.h"
-
- #define WINDObject 500 /* Resource ID for WIND template */
-
- extern CApplication *gApplication; /* The application */
- extern CBartender *gBartender; /* The menu handling object */
- extern CDecorator *gDecorator; /* Window dressing object */
- extern CDesktop *gDesktop; /* The enclosure for all windows */
- extern CBureaucrat *gGopher; /* The current boss in the chain of command */
- extern OSType gSignature; /* The application's signature */
- extern CError *gError; /* The global error handler */
-
- void CObjectDoc::IObjectDoc(CApplication *aSupervisor, Boolean printable)
-
- {
- CDocument::IDocument(aSupervisor, printable);
- }
-
- void CObjectDoc::Dispose()
-
- {
- if (itsData) DisposHandle( itsData);
- inherited::Dispose();
- }
-
- void CObjectDoc::DoCommand(long theCommand)
-
- {
- switch (theCommand) {
- default: inherited::DoCommand(theCommand);
- break;
- }
- }
-
- void CObjectDoc::UpdateMenus()
- {
- inherited::UpdateMenus();
- gBartender->DisableCmd(cmdSave);
- gBartender->DisableCmd(cmdSaveAs);
- }
-
- void CObjectDoc::OpenFile(SFReply *macSFReply)
- {
- CDataFile *theFile;
- Str63 theName;
- OSErr theError;
-
- TRY
- {
- itsData = NULL;
- itsFile = NULL;
- theFile = new(CDataFile);
- theFile->IDataFile();
- theFile->SFSpecify(macSFReply);
-
- theFile->Open(fsRdPerm);
- itsData = theFile->ReadAll();
- BuildWindow(itsData);
- theFile->GetName(theName);
- theFile->Close();
- theFile->Dispose();
-
- itsWindow->SetTitle(theName);
- itsWindow->Select();
- }
-
- CATCH
- {
- /*
- * This exception handler will be executed if an exception occurs
- * anywhere within the scope of the TRY block above.
- * You should perform any cleanup of things that won't be needed
- * since the document could not be opened. By convention,
- * the creator of an object is responsible for sending it
- * the Dispose message. This means that we should only dispose
- * of things that would not be taken care of in Dispose.
- * In this case, we just make sure that the Handle theData
- * has been disposed of. The exception will propagate up to
- * CApplications's exception handler, which handles displaying
- * an error alert.
- */
-
- if (itsData) DisposHandle( itsData);
-
- }
- ENDTRY;
- }
-
-
-
- /***
- * BuildWindow
- *
- * This is the auxiliary window-building method that the
- * NewFile() and OpenFile() methods use to create a window.
- *
- * In this implementation, the argument is the data to display.
- *
- ***/
-
- void CObjectDoc::BuildWindow (Handle theData)
-
- {
- CScrollPane *theScrollPane;
- CARTable *theMainPane;
- CARArray *theArray;
-
- /**
- ** First create the window and initialize
- ** it. The first argument is the resource ID
- ** of the window. The second argument specifies
- ** whether the window is a floating window.
- ** The third argument is the window's enclosure; it
- ** should always be gDesktop. The last argument is
- ** the window's supervisor in the Chain of Command;
- ** it should always be the Document object.
- **
- **/
-
- itsWindow = new(CWindow);
- itsWindow->IWindow(WINDObject, FALSE, gDesktop, this);
-
- /**
- ** After you create the window, you can use the
- ** SetSizeRect() message to set the window’s maximum
- ** and minimum size. Be sure to set the max & min
- ** BEFORE you send a PlaceNewWindow() message to the
- ** decorator.
- **
- ** The default minimum is 100 by 100 pixels. The
- ** default maximum is the bounds of GrayRgn() (The
- ** entire display area on all screens.)
- **
- ** We'll use the defaults.
- **
- **/
-
- /**
- ** Our window will contain a ScrollPane,
- ** which in turn will contain a Panorama.
- ** Now, let's create the ScrollPane.
- **/
-
- theScrollPane = new(CScrollPane);
-
- /**
- ** You can initialize a scroll pane two ways:
- ** 1. You can specify all the values
- ** right in your code, like this.
- ** 2. You can create a ScPn resource and
- ** initialize the pane from the information
- ** in the resource.
- **
- **/
-
- theScrollPane->IScrollPane(itsWindow, this, 10, 10, 0, 0,
- sizELASTIC, sizELASTIC,
- TRUE, TRUE, TRUE);
-
- /**
- ** The FitToEnclFrame() method makes the
- ** scroll pane be as large as its enclosure.
- ** In this case, the enclosure is the window,
- ** so the scroll pane will take up the entire
- ** window.
- **
- **/
-
- theScrollPane->FitToEnclFrame(TRUE, TRUE);
-
-
- /**
- ** itsMainPane is the document's focus
- ** of attention. Some of the standard
- ** classes (particularly CPrinter) rely
- ** on itsMainPane pointing to the main
- ** pane of your window.
- **
- ** itsGopher specifies which object
- ** should become the gopher when the document
- ** becomes active. By default
- ** the document becomes the gopher. It’s
- ** likely that your main pane handles commands
- ** so you’ll almost always want to set itsGopher
- ** to point to the same object as itsMainPane.
- **
- ** Note that the main pane is the
- ** panorama in the scroll pane and not
- ** the scroll pane itself.
- **
- **/
-
- {
- TextInfoRec textInfo;
- textInfo.fontNumber = monaco;
- textInfo.theSize = 12;
- textInfo.theStyle = 0;
- textInfo.theMode = srcOr;
-
- theMainPane = new(CARTable);
- theMainPane->IARTable(theScrollPane, this, 0, 0, 0, 0, sizELASTIC, sizELASTIC);
- theMainPane->FitToEnclosure(TRUE, TRUE);
- ((CTextEnvirons *)(theMainPane->itsEnvironment))->SetTextInfo( &textInfo);
- itsMainPane = theMainPane;
- itsGopher = theMainPane;
- }
-
- theArray = new(CARArray);
- theArray->IARArray(theData);
- theMainPane->SetArray(theArray, true);
-
-
- /**
- ** Send the scroll pane an InstallPanorama()
- ** message to associate the panorama with
- ** the scroll pane.
- **
- **/
-
- theScrollPane->InstallPanorama(theMainPane);
-
- /**
- ** The Decorator is a global object that takes care
- ** of placing and sizing windows on the screen.
- ** You don't have to use it.
- **
- **/
-
- gDecorator->StaggerWindow(itsWindow);
- }
-