home *** CD-ROM | disk | FTP | other *** search
- /****
- * CDictTestDoc.c
- *
- * Document methods for a typical application.
- *
- ****/
-
- #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 "CDictTestDoc.h"
- #include "CStaticInteger.h"
- #include "CSmartWindow.h"
- #include "CSmartButton.h"
- #include "CSmartEditText.h"
- #include "DictTest.h"
- #include "CPascalString.h"
- #include "CTestDict.h"
- #include "CPattern.h"
- #include "CFilledBorder.h"
- #include "TBUtilities.h"
-
- #define WINDDictTest 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 CDictTestDoc::IDictTestDoc(CBureaucrat *aSupervisor, Boolean printable)
-
- {
- CSmartDocument::ISmartDocument(aSupervisor, printable, TRUE);
-
- utilString = new( CPascalString);
- }
- /*****************************************************************************/
- void CDictTestDoc::NewFile(void)
- {
- itsDictionary = new( CTestDict);
- CheckAllocation( itsDictionary);
- itsDictionary->ITestDict();
- BuildWindow();
- itsWindow->Select();
-
- }
- /*****************************************************************************/
- void CDictTestDoc::Dispose()
- {
- if (utilString) utilString->Dispose();
- if (itsDictionary) itsDictionary->DisposeAll();
- inherited::Dispose();
- }
- /*****************************************************************************/
- void CDictTestDoc::DoCommand(long theCommand)
-
- {
- switch (theCommand)
- {
- case cmdAddAssoc:
- AddAssociation();
- break;
-
- case cmdRemoveAssoc:
- RemoveAssociation();
- break;
-
- case cmdLookupAssoc:
- LookupAssociation();
- break;
-
- case cmdAddLots:
- AddLots();
- break;
-
- default:
- inherited::DoCommand(theCommand);
- break;
- }
- }
- /*****************************************************************************/
- void CDictTestDoc::BuildWindow ( void)
- {
- CScrollPane *theScrollPane;
- CPanorama *theMainPane;
- CFilledBorder *border;
- Rect r;
- CStaticString *string;
- CSmartWindow *window;
- CSmartButton *btn;
- CPattern *pat;
-
- window = new(CSmartWindow);
- CheckAllocation( window);
- window->ISmartWindow( WINDDictTest, FALSE, gDesktop, this, TRUE);
- itsWindow = window;
-
- theScrollPane = new(CScrollPane);
- CheckAllocation( theScrollPane);
- theScrollPane->IViewRes('ScPn', 1, itsWindow, this);
- theScrollPane->FitToEnclFrame(TRUE, TRUE);
-
- theMainPane = new( CPanorama);
- CheckAllocation( theMainPane);
- itsMainPane = theMainPane;
-
- theMainPane->IPanorama( theScrollPane, this, 0, 0, 0, 0, sizELASTIC, sizELASTIC);
- theMainPane->FitToEnclosure( TRUE, TRUE);
- theMainPane->SetWantsClicks( TRUE);
- theMainPane->GetFrame( &r);
- theMainPane->SetBounds( &r);
- theScrollPane->InstallPanorama( theMainPane);
-
- pat = new(CPattern);
- CheckAllocation( pat);
- pat->IPattern( theMainPane, this, 0, 0, 0, 0,
- sizELASTIC, sizELASTIC, 300, TRUE);
- pat->FitToEnclosure( TRUE, TRUE);
-
- string = new( CStaticString);
- CheckAllocation( string);
- string->IViewRes( 'StSt', 1, theMainPane, itsSupervisor);
- string = new( CStaticString);
- CheckAllocation( string);
- string->IViewRes( 'StSt', 2, theMainPane, itsSupervisor);
- string = new( CStaticString);
- CheckAllocation( string);
- string->IViewRes( 'StSt', 3, theMainPane, itsSupervisor);
- itsItemCount = new( CStaticInteger);
- CheckAllocation( itsItemCount);
- itsItemCount->IViewRes( 'StSt', 4, theMainPane, itsSupervisor);
- itsItemCount->SetIntValue( itsDictionary->GetNumItems());
-
- border = new(CFilledBorder);
- CheckAllocation( border);
- border->IFilledBorder( theMainPane, this, 100, 30, 50, 10, sizFIXEDSTICKY,
- sizFIXEDSTICKY);
- border->SetWantsClicks( TRUE);
-
- itsKeyText = new( CSmartEditText);
- CheckAllocation( itsKeyText);
- itsKeyText->ISmartEditText( border, this, 0, 0, 0, 0, sizELASTIC,
- sizELASTIC, -1, 1);
- itsKeyText->FitToEnclosure( TRUE, TRUE);
- SetRect( &r, 2, 2, -2, -2);
- itsKeyText->ChangeSize( &r, TRUE);
-
- border = new(CFilledBorder);
- CheckAllocation( border);
- border->IFilledBorder( theMainPane, this, 200, 100, 50, 50, sizFIXEDSTICKY,
- sizFIXEDSTICKY);
- border->SetWantsClicks( TRUE);
-
- itsValueText = new( CSmartEditText);
- CheckAllocation( itsValueText);
- itsValueText->ISmartEditText( border, this, 0, 0, 0, 0, sizELASTIC,
- sizELASTIC, -1, 1);
- itsValueText->FitToEnclosure( TRUE, TRUE);
- SetRect( &r, 2, 2, -2, -2);
- itsValueText->ChangeSize( &r, TRUE);
-
- ActivateEditItem( itsKeyText);
-
- btn = new( CSmartButton);
- CheckAllocation( btn);
- btn->ISmartButton( 1, theMainPane, this); /* Add */
- btn = new( CSmartButton);
- CheckAllocation( btn);
- btn->ISmartButton( 2, theMainPane, this); /* Remove */
- btn = new( CSmartButton);
- CheckAllocation( btn);
- btn->ISmartButton( 3, theMainPane, this); /* Lookup */
-
- gDecorator->PlaceNewWindow( itsWindow);
- }
- /*****************************************************************************/
- void CDictTestDoc::AddAssociation( void)
- {
- Str255 key;
- Str255 valueStr;
- CPascalString *value;
-
- itsKeyText->GetString( key);
- key[0] = MIN( key[0], 20);
-
- itsValueText->GetString( valueStr);
- value = new( CPascalString);
- CheckAllocation( CPascalString);
-
- value->SetString( valueStr);
-
- itsDictionary->Add( key, value);
- itsItemCount->SetIntValue( itsDictionary->GetNumItems());
- dirty = TRUE;
-
- } /* CDictTestDoc::AddAssociation */
- /*****************************************************************************/
- void CDictTestDoc::RemoveAssociation( void)
- {
- Str255 key;
-
- itsKeyText->GetString( key);
- key[0] = MIN( key[0], 20);
-
- itsDictionary->Remove( key);
- itsValueText->ClearText();
- itsItemCount->SetIntValue( itsDictionary->GetNumItems());
- dirty = TRUE;
-
- } /* CDictTestDoc::RemoveAssociation */
- /*****************************************************************************/
- void CDictTestDoc::LookupAssociation( void)
- {
- Str255 key;
- Str255 valueStr;
- CPascalString *value;
-
- itsKeyText->GetString( key);
- key[0] = MIN( key[0], 20);
-
- value = (CPascalString*) itsDictionary->Lookup( key);
- if (value)
- value->GetString(valueStr);
- else
- {
- valueStr[0] = 0;
- SysBeep(3);
- }
- itsValueText->SetTextString( valueStr);
-
- } /* CDictTestDoc::LookupAssociation */
- /*****************************************************************************/
- void CDictTestDoc::AddLots( void)
- {
- Str255 s, s2;
- Int32 i;
- #define kNumTestEntries 250
-
- for( i = 1; i <= kNumTestEntries; i++)
- {
- NumToString( i+1000, s);
- itsKeyText->SetTextString(s);
- pStrCopy( "\pentry ", s2);
- pConcat( s2, s);
- itsValueText->SetTextString(s2);
- AddAssociation();
- if ((i % 50) == 0)
- itsWindow->Update();
-
- if (MaxBlock() < 32767L) return;
- }
-
- } /* CDictTestDoc::AddLots */
- /*****************************************************************************/
- void CDictTestDoc::UpdateMenus( void)
- {
- inherited::UpdateMenus();
-
- gBartender->EnableCmd( cmdAddAssoc);
- gBartender->EnableCmd( cmdLookupAssoc);
- gBartender->EnableCmd( cmdRemoveAssoc);
- gBartender->EnableCmd( cmdAddLots);
-
- gBartender->DisableCmd( cmdSave);
- gBartender->DisableCmd( cmdSaveAs);
- gBartender->DisableCmd( cmdRevert);
-
-
- } /* CDictTestDoc::UpdateMenus */
- /*****************************************************************************/
- Boolean CDictTestDoc::ConfirmClose(Boolean quitting)
- {
- return TRUE; /* never save the document */
-
- } /* CDictTestDoc::UpdateMenus */
- /*****************************************************************************/
-
-