home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Think Class Libraries / Item Class / Item sources / CItemApp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-30  |  9.5 KB  |  360 lines  |  [TEXT/KAHL]

  1. /*
  2.  * File:        CItemApp.c
  3.  * Created:        8/1/93
  4.  * Desc:        A mousetask that handles dragging and dropping
  5.  *                in CItemTable.
  6.  *
  7.  * Superclass:    CApplication.
  8.  * Original Author:    W. Wesley Monroe
  9.  * Modifications:    Atul Barve
  10.  *
  11.  * Copyright © 1993 Animas Software Production. All rights reserved.
  12.  */
  13.  
  14. #include "CItemApp.h"
  15. #include "Commands.h"
  16. #include "ItemCommands.h"
  17. #include "CBartender.h"
  18. #include "CPane.h"
  19. #include "CPaneBorder.h"
  20. #include "CItemTableDemo.h"
  21. #include "CAppleEvent.h"
  22.  
  23.     // to suppress class stripping only
  24. #include "CButton.h"
  25. #include "CRadioControl.h"
  26. #include "CRadioGroupPane.h"
  27. #include "CStdPopupPane.h"
  28. #include "CArrowPopupPane.h"
  29. #include "CCheckBox.h"
  30. #include "CIconPane.h"
  31. #include "CIntegerText.h"
  32.  
  33. #define        kExtraMasters        10        // #times to call MoreMasters
  34. #define        kRainyDayFund        45000    // total size of rainyDay memory reserve
  35. #define        kCriticalBalance    40000    // portion of rainyDay saved for critical operations
  36. #define        kToolboxBalance        20000    // portion of rainyDay saved for toolbox calls
  37.                                         // and other operations that must not fail
  38.  
  39. #define     MENUdialogs            1000    // dialog menu ID
  40.  
  41. #define        kItemDialog1        1026    // resource IDs of demo dialogs
  42. #define        kItemDialog2        1027
  43. #define        kItemDialog3        1028
  44. #define        kItemDialog4        1029
  45.  
  46.     // global variables used in this file
  47.     
  48. extern CClipboard    *gClipboard;
  49. extern CDesktop        *gDesktop;
  50. extern CBartender    *gBartender;
  51. extern OSType        gSignature;
  52.  
  53. /******************************************************************************
  54.  CItemApp
  55.  
  56.      Initialize the global application object.
  57. ******************************************************************************/
  58.  
  59. CItemApp::CItemApp( void)
  60. {
  61.         // call CApplication's initialization method, indicating the
  62.         // number of times to call MoreMasters, the size of the rainy day
  63.         // fund memory reserve, and the critical operation and toolbox
  64.         // balances
  65.         
  66.     CApplication::IApplication( kExtraMasters, kRainyDayFund,
  67.                         kCriticalBalance, kToolboxBalance);
  68.                         
  69.         // The task names used in the undo menu item are stored
  70.         // in STR# 130, in whatever order you define. If you want
  71.         // text editing to display the correct name, e.g. "Undo Typing"
  72.         // then you must tell CAbstractText where its strings are in
  73.         // the STR# 130 resource.
  74.         
  75.     CAbstractText::cFirstTaskIndex = 1;    // first in the resource
  76.  
  77. }
  78.  
  79. /******************************************************************************
  80.  MakeClipboard {OVERRIDE}
  81.  
  82.      We override MakeClipboard in order to create a subclass of 
  83.      CClipboard, CStyleTEClipboard, that can display styled text.
  84. ******************************************************************************/
  85.  
  86. void    CItemApp::MakeClipboard( void)
  87. {
  88.     CClipboard    *clip = new( CClipboard);
  89.     
  90.     clip->IClipboard( this, TRUE);
  91.     gClipboard = clip;
  92. }
  93.  
  94. /******************************************************************************
  95.  SetUpFileParameters {OVERRIDE}
  96.  
  97.      You need to override SetUpFileParameters to specify your applications
  98.      file creator signature, and the types of files your application can open.
  99. ******************************************************************************/
  100.  
  101. void CItemApp::SetUpFileParameters(void)
  102. {
  103.     inherited::SetUpFileParameters();
  104.  
  105.     sfNumTypes = 2;                // we open two types of files:
  106.     sfFileTypes[0] = 'TEXT';    //    any text file,
  107.     sfFileTypes[1] = 'rsrc';    //  and resource files. ResEdit uses
  108.                                 // 'rsrc' as the file type for files it creates
  109.                                 
  110.     gSignature = 'tclD';        // The file creator for files your application
  111.                                 // creates
  112. }
  113.  
  114. /******************************************************************************
  115.  SetupMenus {OVERRIDE}
  116.  
  117.      We override SetupMenus in order to do some extra menu initialization.
  118. ******************************************************************************/
  119.  
  120. void    CItemApp::SetUpMenus( void)
  121. {
  122.         // Creates the bartender, loads our MBAR, and installs the Apple menu
  123.         
  124.     inherited::SetUpMenus();
  125.     
  126.         // Turn off dimming and unchecking for the Font, size, and style menus
  127.     
  128.         
  129.     gBartender->SetDimOption( MENUdialogs, dimNONE);
  130. }
  131.  
  132. /******************************************************************************
  133.  DoCommand {OVERRIDE}
  134.  
  135.      We override DoCommand to receive special commands handled by CItemApp
  136. ******************************************************************************/
  137.  
  138. void    CItemApp::DoCommand( long theCommand)
  139. {
  140.     CDirector     *director;
  141.     CWindow        *window;
  142.     
  143.     switch( theCommand)
  144.     {            
  145.         case cmdNew :
  146.             CreateDocument();
  147.             break;    
  148.         default:
  149.             inherited::DoCommand( theCommand);
  150.             break;
  151.     }
  152. }
  153.  
  154. /******************************************************************************
  155.  CreateDocument
  156.  
  157.      Here we display a dialog for the user to choose the type of document
  158.      to create, and then send ourselves a DoCommand message with the command
  159.      number corresponding to the selected document type.
  160.  ******************************************************************************/
  161.  
  162. void    CItemApp::CreateDocument( void)
  163. {
  164.     DoItemTable();
  165. }
  166.  
  167. /******************************************************************************
  168.  NewTextDoc
  169.  
  170.      Creates a new text document. If theCommand is cmdNewStyleText, the
  171.      document will support styled text, else it supports only plain text.
  172. ******************************************************************************/
  173.  
  174. void    CItemApp::NewTextDoc( long theCommand)
  175. {
  176. }
  177.  
  178.  
  179. /******************************************************************************
  180.  NewTableDoc
  181.  
  182.      Create a new ItemTable document.
  183. ******************************************************************************/
  184.  
  185. void    CItemApp::NewTableDoc( void)
  186. {
  187. }
  188.  
  189. /******************************************************************************
  190.  OpenDocument  {OVERRIDE}
  191.  
  192.     Open an existing document. The type of document we open is depends upon 
  193.     the file type, as given in macReply.
  194.  ******************************************************************************/
  195.  
  196. void CItemApp::OpenDocument( SFReply *macReply)
  197. {
  198. }
  199.  
  200. /******************************************************************************
  201.  DoItemDialog
  202.  
  203.      Creates a dialog from the DLOG resource with the given ID. This method
  204.      is used for several of the dialogs opened from the Dialogs menu.
  205. ******************************************************************************/
  206.  
  207. CDirector *CItemApp::DoItemDialog( short resID, Boolean modal)
  208. {
  209.     CDLOGDirector    *dialog = NULL;
  210.     long            cmd;
  211.     
  212.     TRY
  213.     {
  214.         dialog = new CDLOGDirector;    
  215.         dialog->IDLOGDirector( resID, this);
  216.         dialog->BeginDialog();
  217.             
  218.         if (modal)
  219.         {
  220.             cmd = dialog->DoModalDialog( cmdOK);    
  221.             ForgetObject( dialog);
  222.         }
  223.     }
  224.     CATCH
  225.     {
  226.         ForgetObject( dialog);
  227.     }
  228.     ENDTRY;
  229.     
  230.     return dialog; // not null if dialog is non-modal
  231.  
  232. }
  233.  
  234. /******************************************************************************
  235.  DoBorderDialog
  236.  
  237.      Creates the Borders demo dialog.
  238. ******************************************************************************/
  239.  
  240. void CItemApp::DoBorderDialog( void)
  241. {
  242.     CDocument    *doc = NULL;
  243.     CDLOGDialog    *dlog;
  244.     CPane        *pane;
  245.     short        paneID;
  246.         
  247.     TRY
  248.     {
  249.         doc = new CDocument;
  250.         doc->IDocument( this, kPrintable);
  251.         dlog = new CDLOGDialog;
  252.         doc->itsWindow = dlog;
  253.         dlog->IDLOGDialog( kItemDialog4, gDesktop, doc);
  254.         
  255.             // there are 12 panes, with IDs 1-12, and 12 PBrd resources 128-139
  256.         for (paneID = 1; paneID <= 12; paneID++)
  257.         {
  258.             pane = (CPane*) dlog->FindViewByID( paneID);
  259.             if (pane)
  260.                 pane->SetResBorder( paneID + 127);
  261.         }
  262.         
  263.             // set the main pane to the dialog panorama
  264.         doc->itsMainPane = (CPane*) dlog->FindViewByID( kDialogPanoramaID);
  265.         
  266.             // size window so it fits on any screen
  267.         dlog->ChangeSize( 480, 320);
  268.         
  269.             // show the window
  270.         dlog->Select();
  271.     }
  272.     CATCH
  273.     {
  274.         ForgetObject( doc);
  275.     }
  276.     ENDTRY;
  277. }
  278.  
  279. /******************************************************************************
  280.  DoItemTable
  281.  
  282.      Creates the string table demo dialog
  283. ******************************************************************************/
  284.  
  285. void CItemApp::DoItemTable( void)
  286. {
  287.     CItemTableDemo *stringDlg = NULL;
  288.         
  289.     TRY
  290.     {
  291.         stringDlg = new CItemTableDemo;
  292.         stringDlg->IItemTableDemo();
  293.         stringDlg->BeginDialog();
  294.     }
  295.     CATCH
  296.     {
  297.         ForgetObject( stringDlg);
  298.     }
  299.     ENDTRY;
  300.  
  301. }
  302.  
  303. /******************************************************************************
  304.  ForceClassReferences
  305.  
  306.      This method creates dummy references to classes that we don't want
  307.      stripped out by the linker when the application is built. This could
  308.      happen if the class is only created via new_by_name and is never directly
  309.      referenced. CApplication automatically calls this method.
  310.      
  311. ******************************************************************************/
  312.  
  313.  
  314. void    CItemApp::ForceClassReferences( void)
  315. {
  316.     Boolean alwaysFalse = FALSE;
  317.     CObject *dummy = NULL;
  318.     
  319.     if (alwaysFalse == TRUE)
  320.     {
  321.         member( dummy, CButton);
  322.         member( dummy, CCheckBox);
  323.         member( dummy, CRadioControl);
  324.         member( dummy, CRadioGroupPane);
  325.         member( dummy, CIconPane);
  326.         member( dummy, CIntegerText);
  327.         member( dummy, CStdPopupPane);
  328.         member( dummy, CArrowPopupPane);    
  329.     }
  330. }
  331.  
  332.  
  333. /******************************************************************************
  334.  DoAppleEvent  {OVERRIDE}
  335.  
  336.     When the user chooses File/New, CItemApp display a dialog for the
  337.     user to choose the new doc type. Because of this interaction, we
  338.     have to request user interation before handling the kAEOpenApplication
  339.     AppleEvent.
  340.     
  341. ******************************************************************************/
  342.  
  343. void CItemApp::DoAppleEvent( CAppleEvent *anAppleEvent)
  344. {
  345.     OSErr        err;
  346.     Boolean        passIt = TRUE;
  347.         
  348.     if ((anAppleEvent->GetEventClass() == kCoreEventClass) &&
  349.         (anAppleEvent->GetEventID() == kAEOpenApplication))
  350.     {
  351.         err = anAppleEvent->RequestInteraction( MAXLONG);
  352.         if (err != noErr)
  353.             passIt = FALSE;
  354.     }
  355.     
  356.     if (passIt)
  357.         inherited::DoAppleEvent( anAppleEvent);
  358.  
  359. }
  360.