home *** CD-ROM | disk | FTP | other *** search
- /*************************************************************************************************
- *
- *
- * ObjectMacZapp -- a standard Mac OOP application template
- *
- *
- *
- * ZShowOffApplication.cpp -- the demo application
- *
- *
- *
- *
- *
- * © 1996, Graham Cox
- *
- *
- *
- *
- *************************************************************************************************/
-
- #include "ZShowOffApplication.h"
- #include "MacZoop.h"
- #include "ZGWorldWindow.h"
- #include "ZDialog.h"
- #include "ZProgress.h"
- #include "ZFolderScanner.h"
- #include "ZSortTestWindow.h"
- #include "ZTextWindow.h"
- #include "ZHexEditor.h"
- #include "ZStdPrefsDialog.h"
- #include "ZPrefsFile.h"
- #include "ZTestInspector.h"
-
- #if APPEARANCE_MGR_AWARE
- #include "ZAMDialog.h"
- #endif
-
-
- ZInspectorWindow* gInspector = NULL;
-
-
- /*--------------------------------*** CONSTRUCTOR ***---------------------------------*/
-
-
- ZShowOffApplication::ZShowOffApplication()
- : ZApplication()
- {
- }
-
-
-
- void ZShowOffApplication::StartUp()
- {
- gPrefsFile = new ZPrefsFile();
-
- if ( gPrefsFile )
- gPrefsFile->OpenResFork();
-
- anFType = 'TEXT';
- gMenuBar->NominateWindowsMenu( 132 );
- gMenuBar->AppendStdItems( 133, appendFontNames );
- }
-
-
- void ZShowOffApplication::ShutDown()
- {
- if ( gPrefsFile )
- ForgetObject( gPrefsFile );
- }
-
-
- /*------------------------------*** MAKENEWWINDOW ***---------------------------------*/
- /*
-
- makes a document window of type ZGWorldWindow or ZSortTestWindow according to the filetype
- picked.
- ----------------------------------------------------------------------------------------*/
-
- void ZShowOffApplication::MakeNewWindow()
- {
- FailNIL( mostRecent = new ZHexEditor( this, kUntitledWindowID ));
-
- try
- {
- mostRecent->InitZWindow();
- }
- catch(OSErr err)
- {
- ForgetObject(mostRecent);
-
- throw err;
- }
- }
-
-
- /*----------------------------*** MAKENEWWINDOWTYPE ***-------------------------------*/
- /*
- makes one of several kinds of windows. Here, the class ID of the desired type is used as
- an way to identify them. This is one way to do it, but there is nothing sacred about this-
- you could equally well just enumerate the various types.
- ----------------------------------------------------------------------------------------*/
-
- ZWindow* ZShowOffApplication::MakeNewWindowType( OSType aType )
- {
- ZWindow* zw = NULL;
-
- switch( aType )
- {
- case CLASS_ZHexEditor:
- FailNIL( zw = new ZHexEditor( this, kUntitledWindowID ));
- break;
-
- default:
- case CLASS_ZWindow:
- FailNIL( zw = new ZWindow( this, kUntitledWindowID ));
- break;
-
- case 'TEXT':
- FailNIL( zw = new ZSortTestWindow( this, kUntitledWindowID ));
- break;
-
- case 'PICT':
- FailNIL( zw = new ZGWorldWindow( this, kUntitledWindowID ));
- break;
-
- case CLASS_ZTextWindow:
- FailNIL( zw = new ZTextWindow( this, kUntitledWindowID ));
- break;
-
- case CLASS_ZScroller:
- FailNIL( zw = new ZScroller( this, kUntitledWindowID ));
- break;
- }
-
- if ( zw )
- {
- try
- {
- zw->InitZWindow();
-
- // postprocessing for specific types:
-
- switch ( aType )
- {
- case CLASS_ZScroller:
- Rect bounds = { 0, 0, 600, 600 };
-
- (( ZScroller* ) zw )->SetBounds( bounds );
- break;
-
- case 'PICT':
- (( ZGWorldWindow* ) zw )->SetPictureFromResource( 128 );
- break;
-
- default:
- break;
- }
- }
- catch( OSErr err )
- {
- ForgetObject( zw );
- throw err;
- }
- }
-
- return zw;
- }
-
-
- /*--------------------------------*** NEWFLOATER ***----------------------------------*/
- /*
- makes a new floating window, to demonstrate this cool new feature!
- ----------------------------------------------------------------------------------------*/
-
- void ZShowOffApplication::NewFloater()
- {
- FailNIL( mostRecent = new ZWindow( this, kFloaterID ));
-
- try
- {
- mostRecent->InitZWindow();
-
- }
- catch( OSErr err )
- {
- ForgetObject( mostRecent );
-
- throw err;
- }
-
- mostRecent->Select();
- }
-
-
- /*-------------------------------*** UPDATEMENUS ***---------------------------------*/
- /*
-
- Enable the dialog demo menu items
-
- ----------------------------------------------------------------------------------------*/
-
- void ZShowOffApplication::UpdateMenus()
- {
- // enable the menus
-
- gMenuBar->EnableCommand( kCmdOpenMoveableModal );
- gMenuBar->EnableCommand( kCmdOpenModal );
- gMenuBar->EnableCommand( kCmdOpenModeless );
- gMenuBar->EnableCommand( kCmdTestProgress );
- gMenuBar->EnableCommand( kCmdScanFolder );
- gMenuBar->EnableCommand( kCmdNewFloater );
-
- gMenuBar->EnableCommand( kCmdOpenTextWindow );
- gMenuBar->EnableCommand( kCmdOpenGWorldWindow );
- gMenuBar->EnableCommand( kCmdOpenPlainWindow );
- gMenuBar->EnableCommand( kCmdOpenScrollerWindow );
- gMenuBar->EnableCommand( kCmdOpenHexEditorWindow );
- gMenuBar->EnableCommand( kCmdOpenSortTestWindow );
- gMenuBar->EnableCommand( kCmdOpenListWindow );
- gMenuBar->EnableCommand( kCmdTestNotification );
- gMenuBar->EnableCommand( kCmdShowInspector );
-
-
- ZApplication::UpdateMenus();
- }
-
-
-
- /*-------------------------------*** HANDLECOMMAND ***--------------------------------*/
- /*
-
- handle the menu items for dialog demo
-
- ----------------------------------------------------------------------------------------*/
-
-
- void ZShowOffApplication::HandleCommand( const long aCmd )
- {
- switch ( aCmd )
- {
- case kCmdOpenMoveableModal:
- OpenDialog( kDialog1 );
- break;
-
- case kCmdOpenModal:
- OpenDialog( kDialog2 );
- break;
-
- case kCmdOpenModeless:
- OpenDialog( kDialog3 );
- break;
-
- case kCmdTestProgress:
- TestProgress();
- break;
-
- case kCmdScanFolder:
- TestScan();
- break;
-
- case kCmdNewFloater:
- NewFloater();
- break;
-
- case kCmdOpenHexEditorWindow:
- OpenNewWindowType( CLASS_ZHexEditor );
- break;
-
- case kCmdOpenPlainWindow:
- OpenNewWindowType( CLASS_ZWindow );
- break;
-
- case kCmdOpenTextWindow:
- OpenNewWindowType( CLASS_ZTextWindow );
- break;
-
- case kCmdOpenSortTestWindow:
- OpenNewWindowType( 'TEXT' );
- break;
-
- case kCmdOpenGWorldWindow:
- OpenNewWindowType( 'PICT' );
- break;
-
- case kCmdOpenScrollerWindow:
- OpenNewWindowType( CLASS_ZScroller );
- break;
-
- case kCmdTestNotification:
- TestNotification();
- break;
-
- case kCmdShowInspector:
- OpenInspector();
- break;
-
- }
-
- // ask base class to handle any other menu commnds
-
- ZApplication::HandleCommand( aCmd );
- }
-
-
-
- /*-------------------------------*** RECEIVEMESSAGE ***-------------------------------*/
- /*
- listem for dialog item clicks and respond to them
- ----------------------------------------------------------------------------------------*/
-
- void ZShowOffApplication::ReceiveMessage( ZComrade* aSender, long aMsg, void* msgData )
- {
- // this code illustrates the fact that your dialog can be set up and responded to
- // by the owning commander, avoiding a subclass of the dialog for standard cases. For the
- // case of subclassing a dialog, look at the prefs dialog.
-
- ZDialog* zd = (ZDialog*) aSender;
-
- if ( aMsg == kMsgDialogItemClicked && HiWord( *(long*) msgData ) == kDialog1 )
- {
- short iState, item = LoWord( *(long*) msgData );
-
- switch( item )
- {
- case kEnableOKButtonCheckBox:
- iState = zd->GetValue( kEnableOKButtonCheckBox );
- if ( iState )
- zd->EnableItem( ok );
- else
- zd->DisableItem( ok );
- break;
-
- case kEnableGroupCheckBox:
- iState = zd->GetValue( kEnableGroupCheckBox );
- if ( iState )
- zd->EnableItem( -1 );
- else
- zd->DisableItem( -1 );
- break;
-
- case kEnableFieldCheckBox:
- zd->EnableItem( kEditField );
- break;
-
- case kDisableFieldCheckBox:
- zd->DisableItem( kEditField );
- break;
- }
- }
-
- if ( aMsg == kMsgDialogSetUp && HiWord( *(long*) msgData ) == kDialog1 )
- {
- zd->SetValue( kEnableOKButtonCheckBox, 1 );
- zd->SetValue( kEnableGroupCheckBox, 1 );
- }
- }
-
-
- /*----------------------------------*** OPENFILE ***----------------------------------*/
- /*
- make sure we create the right sort of window for the file type chosen
- ----------------------------------------------------------------------------------------*/
-
- void ZShowOffApplication::OpenFile( const FSSpec& aFile, const OSType fType, Boolean isStationery )
- {
- anFType = fType;
-
- ZApplication::OpenFile( aFile, fType, isStationery );
- }
-
-
- /*--------------------------------*** TESTPROGRESS ***--------------------------------*/
- /*
-
- this shows how to use the progress dialog class (ZProgress)
- ----------------------------------------------------------------------------------------*/
-
- #define kLoops 10000
-
-
- void ZShowOffApplication::TestProgress()
- {
- // make the progress dialog object on the heap
-
- ZProgress aPD (this, kStdProgressResID, kLoops, kProportionalProgress, kCancelType);
-
- long loop;
-
- // wait two seconds before showing the dialog
-
- aPD.SetDelay( kTwoSeconds );
- aPD.SetMessage("\pLooping 10,000 times...");
-
- // loop <kLoops> times, updating the progress and
- // aborting if the user cancelled
-
- for (loop = 0; loop < kLoops; loop++)
- {
- if (! aPD.InformProgress(loop))
- break;
- }
-
- // when the dialog goes out of scope now, it will be automatically deleted
- // and the chain of command maintained accordingly. Neat, huh?
- }
-
-
-
-
- /*---------------------------------*** OPENDIALOG ***---------------------------------*/
- /*
-
- construct dialog windows with the ID passed- used to demonstrate dialogs
-
- ----------------------------------------------------------------------------------------*/
-
- void ZShowOffApplication::OpenDialog(short id)
- {
- ZDialog* aDialog;
-
- #if APPEARANCE_MGR_AWARE
-
- if ( gMacInfo.hasAppearanceMgr )
- FailNIL( aDialog = new ZAMDialog( this, id ));
- else
- FailNIL(aDialog = new ZDialog( this, id ));
-
- #else
- FailNIL(aDialog = new ZDialog( this, id ));
- #endif
-
- try
- {
- aDialog->InitZWindow();
- }
- catch(OSErr err)
- {
- ForgetObject(aDialog);
-
- throw err;
- }
-
- // show the window and make it active
-
- aDialog->Select();
- }
-
-
-
- void ZShowOffApplication::OpenInspector()
- {
- ZInspectorWindow* zi;
-
- if ( gInspector == NULL )
- {
- FailNIL( zi = new ZTestInspector( this, 180 ));
-
- try
- {
- zi->InitZWindow();
- gInspector = zi;
-
- }
- catch( OSErr err )
- {
- ForgetObject( zi );
- throw err;
- }
- }
-
- gInspector->Select();
- }
-
-
- /*-----------------------------------*** TESTSCAN ***---------------------------------*/
- /*
- demonstrate the folder scanner- this scans every file in the selected folder.
-
- ----------------------------------------------------------------------------------------*/
-
- void ZShowOffApplication::TestScan()
- {
- ZFolderScanner aScanner; // make object on the stack
-
- if ( aScanner.PickFolder())
- {
- aScanner.SetSearchDepth( kScanEveryFolderInHierarchy );
- aScanner.ScanFolder(); // do the scan
- }
- }
-
-
- void ZShowOffApplication::DoPreferences()
- {
- ZStdPrefsDialog* zPD;
-
- FailNIL( zPD = new ZStdPrefsDialog( this, kStdPrefsDialogResID ));
-
- try
- {
- zPD->InitZWindow();
- zPD->Select();
- }
- catch( OSErr err )
- {
- ForgetObject( zPD );
- throw err;
- }
- }
-
-
- void ZShowOffApplication::TestNotification()
- {
- // wait 5 seconds, then post an alert. If in the background, this should use the
- // notification manager.
-
- (void) Alert( 201, NULL );
-
- long timer = TickCount();
-
- SetWatchCursor();
-
- while( TickCount() < ( timer + 300 ))
- gApplication->Process1Event();
-
- FailOSErr( 123 );
- }
-
-
-