home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1997 January / macpower199701.bin / AMUG / Programming_10 / WASTE 1.3a1.sit / WASTE 1.3a1 Distribution / Demo / WEDemoIntf.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-23  |  9.7 KB  |  430 lines  |  [TEXT/CWIE]

  1. /*
  2.     WASTE Demo Project:
  3.     Demo Header
  4.  
  5.     Copyright ゥ 1993-1996 Marco Piovanelli
  6.     All Rights Reserved
  7.  
  8.     C port by John C. Daub
  9. */
  10.  
  11. /*
  12.     Due to differences between Pascal and C, this file (nothing like it originally existed
  13.     in the original Pascal code) was neccessary to create.  In it contains various macros,
  14.     constants, type and class declarations, function prototypes, etc..  From the original
  15.     code, some of this material would be spread amongst the source files, but a good
  16.     majority of this file comes from the WEDemoIntf.p file (the declarations, constants, etc).
  17.     There still is a WEDemoIntf.c file in the project tho since the .p file had a few
  18.     utility functions declared and defined in it.
  19. */
  20.  
  21. #ifndef __WEDEMOAPP__
  22. #define __WEDEMOAPP__
  23.  
  24. #ifndef __TYPES__
  25. #include <Types.h>
  26. #endif
  27. #ifndef __RESOURCES__
  28. #include <Resources.h>
  29. #endif
  30. #ifndef __QUICKDRAW__
  31. #include <QuickDraw.h>
  32. #endif
  33. #ifndef __MENUS__
  34. #include <Menus.h>
  35. #endif
  36. #ifndef __WINDOWS__
  37. #include <Windows.h>
  38. #endif
  39. #ifndef __CONTROLS__
  40. #include <Controls.h>
  41. #endif
  42. #ifndef __STANDARDFILE__
  43. #include <StandardFile.h>
  44. #endif
  45. #ifndef _WASTE_
  46. #include "WASTE.h"
  47. #endif
  48. #ifndef _LIMITS
  49. #include "limits.h"
  50. #endif
  51.  
  52.  
  53. /*
  54.  *    Some utility macros.
  55.  */
  56.  
  57.  
  58.  
  59. //     "Originally," these are things built into the Pascal language
  60. //     but since C doesn't have anything like them, and in an attempt to keep the code readable
  61. //     and similar to the original Pascal source, these #define macros work nice.
  62.  
  63.  
  64. #define BTST( FLAGS, BIT )    (((FLAGS) & (1L << (BIT))) ? 1 : 0)
  65. #define BSET( FLAGS, BIT )  ((FLAGS) |= (1L << (BIT)))
  66. #define BCLR( FLAGS, BIT )  ((FLAGS) &= (~(1L << (BIT))))
  67.  
  68. #define ABS(A) ((A) > 0 ? (A) : -(A))
  69.  
  70. #define BSL(A, B)    (((long) (A)) << (B))
  71. #define BSR(A, B)    (((long) (A)) >> (B))
  72. #define BOR(A, B)    ((A) | (B))
  73. #define BAND(A, B)    ((A) & (B))
  74.  
  75. #ifndef HiWrd
  76. #define HiWrd(aLong)        (((aLong) >> 16) & 0xFFFF )
  77. #endif
  78. #ifndef LoWrd
  79. #define LoWrd(aLong)        ((aLong) & 0xFFFF )
  80. #endif
  81.  
  82. enum {
  83.  
  84. //    WASTE Demo signature
  85.  
  86.     sigWASTEDemo        =        'OEDE',
  87.  
  88. //    resource types, clipboard types, and file types
  89.  
  90.     kTypeDeskAccessory    =        'DRVR',
  91.     kTypeFont            =        'FONT',
  92.     kTypeFontTable        =        'FISH',
  93.     kTypePicture        =        'PICT',
  94.     kTypeSound            =        'snd ',
  95.     kTypeSoup            =        'SOUP',
  96.     kTypeStyles            =        'styl',
  97.     kTypeText            =        'TEXT'
  98. };
  99.  
  100. enum {
  101.  
  102. //    virtual key codes for navigation keys found on extended keyboards
  103.  
  104.     keyPgUp                =        0x74,
  105.     keyPgDn                =        0x79,
  106.     keyHome                =        0x73,
  107.     keyEnd                =        0x77,
  108.  
  109. //    virtual key codes generated by some function keys
  110.  
  111.     keyF1                =        0x7A,
  112.     keyF2                =        0x78,
  113.     keyF3                =        0x63,
  114.     keyF4                =        0x76
  115. };
  116.  
  117. //    possible values for HandleOpenDocument refCon parameter
  118.  
  119. enum {
  120.     kDoOpen        = 0,
  121.     kDoPrint    = 1
  122. };
  123.  
  124. //     other commonly used constants
  125.  
  126. #define    kBarWidth                        16            // width of a scroll bar
  127. #define kTitleHeight                    20            // usual height of a window title bar
  128. #define kTextMargin                        3            // indent of text rect from a window port rect
  129. #define kScrollDelta                    11            // pixels to scroll when the scroll bar arrow is clicked
  130. #define kStandardTranslucencyThreshold    16384        // 16K sq pixels
  131.  
  132. #define kMinSystemVersion                0x0700        //    MacOS 7.0
  133. #define kMinWASTEVersion                0x00134001    //    WASTE 1.3a1
  134. #define kScrapThreshold                    4 * 1024    //    4 KB
  135.  
  136. // enumeration types used for closing a window and/or quitting the application
  137.  
  138. typedef enum {closingWindow, closingApplication} ClosingOption;
  139. typedef enum {savingYes, savingNo, savingAsk} SavingOption;
  140.  
  141.  
  142. /*
  143.  *    Resource ID numbers
  144.  */
  145.  
  146. // menu IDs
  147.  
  148. enum {
  149.     kMenuApple        = 1,
  150.     kMenuFile,
  151.     kMenuEdit,
  152.     kMenuFont,
  153.     kMenuSize,
  154.     kMenuStyle,
  155.     kMenuColor,
  156.     kMenuFeatures,
  157.     kMenuAlignment,
  158.     kMenuDirection
  159. };
  160.  
  161. //    Apple Menu items
  162.  
  163. enum {
  164.     kItemAbout        = 1
  165. };
  166.  
  167. //    File menu items
  168.  
  169. enum {
  170.     kItemNew        = 1,
  171.     kItemOpen        = 2,
  172.     kItemClose        = 4,
  173.     kItemSave        = 5,
  174.     kItemSaveAs        = 6,
  175.     kItemQuit        = 8
  176. };
  177.  
  178. //    Edit menu items
  179.  
  180. enum {
  181.     kItemUndo        = 1,
  182.     kItemCut        = 3,
  183.     kItemCopy        = 4,
  184.     kItemPaste        = 5,
  185.     kItemClear        = 6,
  186.     kItemSelectAll    = 7
  187. };
  188.  
  189. //    Size menu items
  190.  
  191. enum {
  192.     kItemLastSize    = 6,
  193.     kItemSmaller    = 8,
  194.     kItemLarger        = 9,
  195.     kItemOtherSize    = 11
  196. };
  197.  
  198. //    Style menu items
  199.  
  200. enum {
  201.     kItemPlainText    = 1,
  202.     kItemBold,
  203.     kItemItalic,
  204.     kItemUnderline,
  205.     kItemOutline,
  206.     kItemShadow,
  207.     kItemCondensed,
  208.     kItemExtended
  209. };
  210.  
  211. //    Color menu items
  212.  
  213. enum {
  214.     kItemLastColor    = 7,
  215.     kItemOtherColor = 9
  216. };
  217.  
  218. //    Alignment menu items
  219.  
  220. enum {
  221.     kItemAlignDefault    = 1,
  222.     kItemAlignLeft        = 3,
  223.     kItemCenter,
  224.     kItemAlignRight,
  225.     kItemJustify
  226. };
  227.  
  228. //    Direction menu items
  229.  
  230. enum
  231. {
  232.     kItemDirectionDefault = 1 ,
  233.     kItemDirectionLR = 3 ,
  234.     kItemDirectionRL
  235. } ;
  236.  
  237. //    Features menu items
  238.  
  239. enum {
  240.     kItemAlignment            = 1,
  241.     kItemDirection            = 2,
  242.     kItemTabHooks            = 3,
  243.     kItemAutoScroll            = 5,
  244.     kItemOutlineHilite        = 6,
  245.     kItemReadOnly            = 7,
  246.     kItemIntCutAndPaste     = 8,
  247.     kItemDragAndDrop        = 9,
  248.     kItemTranslucentDrags    = 10,
  249.     kItemOffscreenDrawing    = 11
  250. };
  251.  
  252.  
  253. //    Alert & dialog template resource IDs
  254.  
  255. enum {
  256.     kAlertNeedSys7            = 128,
  257.     kAlertNeedNewerWASTE    = 129,
  258.     kAlertGenError            = 130,
  259.     kAlertSaveChanges        = 131,
  260.     kDialogAboutBox            = 256
  261. };
  262.  
  263. //    String list resource IDs
  264.  
  265. enum {
  266.     kUndoStringsID                = 128,
  267.     kClosingQuittingStringsID    = 129,
  268.     kMiscStringsID                = 130
  269. };
  270.  
  271. // miscellaneous resource IDs
  272.  
  273. enum {
  274.     kMenuBarID                = 128,
  275.     kWindowTemplateID        = 128,
  276.     kScrollBarTemplateID    = 128,
  277.     kPromptStringID            = 128
  278. };
  279.  
  280. // a DocumentRecord is a structure associated with each window
  281. // a handle to this structure is kept in the window refCon
  282.  
  283. struct DocumentRecord
  284. {
  285.     WindowRef            owner;                // the window
  286.     ControlRef            scrollBars [ 2 ];    // its scroll bars
  287.     WEReference         we;                    // its WASTE instance
  288.     Handle                 fileAlias;            // alias to associated file
  289. };  // DocumentRec
  290.  
  291. typedef struct DocumentRecord DocumentRecord, *DocumentPtr, **DocumentHandle;
  292.  
  293.  
  294. /*
  295.  *    The external declaration of some global variables.
  296.  */
  297.  
  298. //  These are defined in WEDemoIntf.c
  299.  
  300. extern    Boolean        gHasColorQD;        // true if Color QuickDraw is available
  301. extern    Boolean        gHasDragAndDrop;    // true if Drag Manager is available
  302. extern    Boolean        gHasTextServices;    // true is the Text Services Manager is available
  303. extern    Boolean        gExiting;            // set this variable to drop out of the event loop and quit
  304.  
  305. /*
  306.  *    Function Prototypes
  307.  */
  308.  
  309. //    From DialogUtils.c
  310.  
  311. ModalFilterUPP    GetMyStandardDialogFilter( void );
  312. short            GetDialogItemType( DialogRef, short );
  313. Handle            GetDialogItemHandle( DialogRef, short );
  314. void            GetDialogItemRect( DialogRef, short, Rect * );
  315. void            SetDialogItemProc( DialogRef, short, UserItemUPP );
  316. void            FlashButton( DialogRef, short );
  317.  
  318. //    From LongControls.c
  319.  
  320. OSErr            LCAttach( ControlRef );
  321. void            LCDetach( ControlRef );
  322. void            LCSetValue( ControlRef, long );
  323. void            LCSetMin( ControlRef, long );
  324. void            LCSetMax( ControlRef, long );
  325. long            LCGetValue( ControlRef );
  326. long            LCGetMin( ControlRef );
  327. long            LCGetMax( ControlRef );
  328. void            LCSynch( ControlRef );
  329.  
  330.  
  331. //    From WEDemoIntf.c
  332.  
  333. DocumentHandle    GetWindowDocument(WindowRef);
  334. #if __cplusplus
  335. inline WEReference GetWindowWE(WindowRef window) { return (* GetWindowDocument(window))->we; }
  336. #else
  337. #define GetWindowWE(window) (* GetWindowDocument(window))->we
  338. #endif
  339. void            ErrorAlert( OSErr );
  340. void            ForgetHandle( Handle * );
  341. void            ForgetResource( Handle * );
  342. void            BlockClr ( void *, Size ) ;
  343. OSErr            NewHandleTemp( Size, Handle * );
  344. void            PStringCopy( ConstStr255Param, Str255 );
  345.  
  346. //    From WEDemoAbout.c
  347.  
  348. OSErr            WETextBox( short, const Rect *, WEAlignment );
  349. void            DoAboutBox( short );
  350.  
  351. //    From WEDemoDrags.c
  352.  
  353. OSErr            InstallDragHandlers( void );
  354. OSErr            RemoveDragHandlers( void );
  355.  
  356. //    From WEDemoEvents.c
  357.  
  358. void            AdjustCursor( Point, RgnHandle );
  359. void            DoMouseDown( const EventRecord * );
  360. void            DoKeyDown( const EventRecord * );
  361. void            DoDiskEvent( const EventRecord * );
  362. void            DoOSEvent( const EventRecord * );
  363. void            DoHighLevelEvent( const EventRecord * );
  364. void            DoNullEvent( const EventRecord * );
  365. void            DoWindowEvent( const EventRecord *);
  366. void            ProcessEvent( void );
  367. OSErr            GotRequiredParams( const AppleEvent * );
  368. OSErr            InitializeEvents( void );
  369.  
  370. // from WEDemoFiles.c
  371.  
  372. OSErr            ReadTextFile( const FSSpec *, WEReference );
  373. OSErr            WriteTextFile( const FSSpec *, WEReference );
  374. pascal OSErr    TranslateDrag( DragReference, ItemReference, FlavorType, Handle );
  375. pascal OSErr    CheckObjectLock( short, long, StringPtr );
  376. pascal OSErr    FSpCheckObjectLock( const FSSpec * );
  377.  
  378. // from WEDemoInit.c
  379.  
  380. OSErr            Initialize( void );
  381. void            Finalize( void );
  382.  
  383. // from WEDemoMenus.c
  384.  
  385. void            SetDefaultDirectory( const FSSpec * );
  386. short            FindMenuItemText( MenuRef, ConstStr255Param );
  387. Boolean            EqualColor( const RGBColor *, const RGBColor * );
  388. void            PrepareMenus( void );
  389. void            DoDeskAcc( short );
  390. OSErr            DoNew( void );
  391. OSErr            DoOpen( void );
  392. OSErr            SaveWindow( const FSSpec *, WindowRef );
  393. OSErr            DoSaveAs( const FSSpec *, WindowRef );
  394. OSErr            DoSave( WindowRef );
  395. OSErr            DoClose( ClosingOption, SavingOption, WindowRef );
  396. OSErr            DoQuit( SavingOption );
  397. void            DoAppleChoice( short );
  398. void            DoFileChoice( short );
  399. void            DoEditChoice( short );
  400. void            DoFontChoice( short, EventModifiers );
  401. void            DoSizeChoice( short );
  402. void            DoStyleChoice( short );
  403. void            DoColorChoice( short );
  404. void            DoAlignmentChoice( short );
  405. void            DoDirectionChoice ( short ) ;
  406. void            DoFeatureChoice( short );
  407. void            DoMenuChoice( long, EventModifiers );
  408. OSErr            InitializeMenus( void );
  409.  
  410. // from WEDemoScripting.c
  411.  
  412. OSErr            WEGetContentsDesc( long, long, Boolean, AEDesc *, WEReference );
  413. OSErr            WESetContentsDesc( long, long, const AEDesc *, WEReference );
  414. OSErr            InstallCoreHandlers( void );
  415.  
  416. // from WEDemoWindows.c
  417.  
  418. void            DoDrag( Point, WindowRef );
  419. void            DoGrow( Point, WindowRef );
  420. void            DoZoom( short, WindowRef );
  421. Boolean            DoContent( Point, const EventRecord *, WindowRef );
  422. void            DoKey( short, const EventRecord * );
  423. void            DoUpdate( WindowRef );
  424. void            DoActivate( Boolean, WindowRef );
  425. OSErr            CreateWindow( const FSSpec * );
  426. void            DestroyWindow( WindowRef );
  427. void            Resize( Point, WindowRef );
  428.  
  429.  
  430. #endif /* __WEDEMOAPP__ */