home *** CD-ROM | disk | FTP | other *** search
- /*
- WASTE Demo Project:
- Demo Header
-
- Copyright ゥ 1993-1996 Marco Piovanelli
- All Rights Reserved
-
- C port by John C. Daub
- */
-
- /*
- Due to differences between Pascal and C, this file (nothing like it originally existed
- in the original Pascal code) was neccessary to create. In it contains various macros,
- constants, type and class declarations, function prototypes, etc.. From the original
- code, some of this material would be spread amongst the source files, but a good
- majority of this file comes from the WEDemoIntf.p file (the declarations, constants, etc).
- There still is a WEDemoIntf.c file in the project tho since the .p file had a few
- utility functions declared and defined in it.
- */
-
- #ifndef __WEDEMOAPP__
- #define __WEDEMOAPP__
-
- #ifndef __TYPES__
- #include <Types.h>
- #endif
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
- #ifndef __QUICKDRAW__
- #include <QuickDraw.h>
- #endif
- #ifndef __MENUS__
- #include <Menus.h>
- #endif
- #ifndef __WINDOWS__
- #include <Windows.h>
- #endif
- #ifndef __CONTROLS__
- #include <Controls.h>
- #endif
- #ifndef __STANDARDFILE__
- #include <StandardFile.h>
- #endif
- #ifndef _WASTE_
- #include "WASTE.h"
- #endif
- #ifndef _LIMITS
- #include "limits.h"
- #endif
-
-
- /*
- * Some utility macros.
- */
-
-
-
- // "Originally," these are things built into the Pascal language
- // but since C doesn't have anything like them, and in an attempt to keep the code readable
- // and similar to the original Pascal source, these #define macros work nice.
-
-
- #define BTST( FLAGS, BIT ) (((FLAGS) & (1L << (BIT))) ? 1 : 0)
- #define BSET( FLAGS, BIT ) ((FLAGS) |= (1L << (BIT)))
- #define BCLR( FLAGS, BIT ) ((FLAGS) &= (~(1L << (BIT))))
-
- #define ABS(A) ((A) > 0 ? (A) : -(A))
-
- #define BSL(A, B) (((long) (A)) << (B))
- #define BSR(A, B) (((long) (A)) >> (B))
- #define BOR(A, B) ((A) | (B))
- #define BAND(A, B) ((A) & (B))
-
- #ifndef HiWrd
- #define HiWrd(aLong) (((aLong) >> 16) & 0xFFFF )
- #endif
- #ifndef LoWrd
- #define LoWrd(aLong) ((aLong) & 0xFFFF )
- #endif
-
- enum {
-
- // WASTE Demo signature
-
- sigWASTEDemo = 'OEDE',
-
- // resource types, clipboard types, and file types
-
- kTypeDeskAccessory = 'DRVR',
- kTypeFont = 'FONT',
- kTypeFontTable = 'FISH',
- kTypePicture = 'PICT',
- kTypeSound = 'snd ',
- kTypeSoup = 'SOUP',
- kTypeStyles = 'styl',
- kTypeText = 'TEXT'
- };
-
- enum {
-
- // virtual key codes for navigation keys found on extended keyboards
-
- keyPgUp = 0x74,
- keyPgDn = 0x79,
- keyHome = 0x73,
- keyEnd = 0x77,
-
- // virtual key codes generated by some function keys
-
- keyF1 = 0x7A,
- keyF2 = 0x78,
- keyF3 = 0x63,
- keyF4 = 0x76
- };
-
- // possible values for HandleOpenDocument refCon parameter
-
- enum {
- kDoOpen = 0,
- kDoPrint = 1
- };
-
- // other commonly used constants
-
- #define kBarWidth 16 // width of a scroll bar
- #define kTitleHeight 20 // usual height of a window title bar
- #define kTextMargin 3 // indent of text rect from a window port rect
- #define kScrollDelta 11 // pixels to scroll when the scroll bar arrow is clicked
- #define kStandardTranslucencyThreshold 16384 // 16K sq pixels
-
- #define kMinSystemVersion 0x0700 // MacOS 7.0
- #define kMinWASTEVersion 0x00134001 // WASTE 1.3a1
- #define kScrapThreshold 4 * 1024 // 4 KB
-
- // enumeration types used for closing a window and/or quitting the application
-
- typedef enum {closingWindow, closingApplication} ClosingOption;
- typedef enum {savingYes, savingNo, savingAsk} SavingOption;
-
-
- /*
- * Resource ID numbers
- */
-
- // menu IDs
-
- enum {
- kMenuApple = 1,
- kMenuFile,
- kMenuEdit,
- kMenuFont,
- kMenuSize,
- kMenuStyle,
- kMenuColor,
- kMenuFeatures,
- kMenuAlignment,
- kMenuDirection
- };
-
- // Apple Menu items
-
- enum {
- kItemAbout = 1
- };
-
- // File menu items
-
- enum {
- kItemNew = 1,
- kItemOpen = 2,
- kItemClose = 4,
- kItemSave = 5,
- kItemSaveAs = 6,
- kItemQuit = 8
- };
-
- // Edit menu items
-
- enum {
- kItemUndo = 1,
- kItemCut = 3,
- kItemCopy = 4,
- kItemPaste = 5,
- kItemClear = 6,
- kItemSelectAll = 7
- };
-
- // Size menu items
-
- enum {
- kItemLastSize = 6,
- kItemSmaller = 8,
- kItemLarger = 9,
- kItemOtherSize = 11
- };
-
- // Style menu items
-
- enum {
- kItemPlainText = 1,
- kItemBold,
- kItemItalic,
- kItemUnderline,
- kItemOutline,
- kItemShadow,
- kItemCondensed,
- kItemExtended
- };
-
- // Color menu items
-
- enum {
- kItemLastColor = 7,
- kItemOtherColor = 9
- };
-
- // Alignment menu items
-
- enum {
- kItemAlignDefault = 1,
- kItemAlignLeft = 3,
- kItemCenter,
- kItemAlignRight,
- kItemJustify
- };
-
- // Direction menu items
-
- enum
- {
- kItemDirectionDefault = 1 ,
- kItemDirectionLR = 3 ,
- kItemDirectionRL
- } ;
-
- // Features menu items
-
- enum {
- kItemAlignment = 1,
- kItemDirection = 2,
- kItemTabHooks = 3,
- kItemAutoScroll = 5,
- kItemOutlineHilite = 6,
- kItemReadOnly = 7,
- kItemIntCutAndPaste = 8,
- kItemDragAndDrop = 9,
- kItemTranslucentDrags = 10,
- kItemOffscreenDrawing = 11
- };
-
-
- // Alert & dialog template resource IDs
-
- enum {
- kAlertNeedSys7 = 128,
- kAlertNeedNewerWASTE = 129,
- kAlertGenError = 130,
- kAlertSaveChanges = 131,
- kDialogAboutBox = 256
- };
-
- // String list resource IDs
-
- enum {
- kUndoStringsID = 128,
- kClosingQuittingStringsID = 129,
- kMiscStringsID = 130
- };
-
- // miscellaneous resource IDs
-
- enum {
- kMenuBarID = 128,
- kWindowTemplateID = 128,
- kScrollBarTemplateID = 128,
- kPromptStringID = 128
- };
-
- // a DocumentRecord is a structure associated with each window
- // a handle to this structure is kept in the window refCon
-
- struct DocumentRecord
- {
- WindowRef owner; // the window
- ControlRef scrollBars [ 2 ]; // its scroll bars
- WEReference we; // its WASTE instance
- Handle fileAlias; // alias to associated file
- }; // DocumentRec
-
- typedef struct DocumentRecord DocumentRecord, *DocumentPtr, **DocumentHandle;
-
-
- /*
- * The external declaration of some global variables.
- */
-
- // These are defined in WEDemoIntf.c
-
- extern Boolean gHasColorQD; // true if Color QuickDraw is available
- extern Boolean gHasDragAndDrop; // true if Drag Manager is available
- extern Boolean gHasTextServices; // true is the Text Services Manager is available
- extern Boolean gExiting; // set this variable to drop out of the event loop and quit
-
- /*
- * Function Prototypes
- */
-
- // From DialogUtils.c
-
- ModalFilterUPP GetMyStandardDialogFilter( void );
- short GetDialogItemType( DialogRef, short );
- Handle GetDialogItemHandle( DialogRef, short );
- void GetDialogItemRect( DialogRef, short, Rect * );
- void SetDialogItemProc( DialogRef, short, UserItemUPP );
- void FlashButton( DialogRef, short );
-
- // From LongControls.c
-
- OSErr LCAttach( ControlRef );
- void LCDetach( ControlRef );
- void LCSetValue( ControlRef, long );
- void LCSetMin( ControlRef, long );
- void LCSetMax( ControlRef, long );
- long LCGetValue( ControlRef );
- long LCGetMin( ControlRef );
- long LCGetMax( ControlRef );
- void LCSynch( ControlRef );
-
-
- // From WEDemoIntf.c
-
- DocumentHandle GetWindowDocument(WindowRef);
- #if __cplusplus
- inline WEReference GetWindowWE(WindowRef window) { return (* GetWindowDocument(window))->we; }
- #else
- #define GetWindowWE(window) (* GetWindowDocument(window))->we
- #endif
- void ErrorAlert( OSErr );
- void ForgetHandle( Handle * );
- void ForgetResource( Handle * );
- void BlockClr ( void *, Size ) ;
- OSErr NewHandleTemp( Size, Handle * );
- void PStringCopy( ConstStr255Param, Str255 );
-
- // From WEDemoAbout.c
-
- OSErr WETextBox( short, const Rect *, WEAlignment );
- void DoAboutBox( short );
-
- // From WEDemoDrags.c
-
- OSErr InstallDragHandlers( void );
- OSErr RemoveDragHandlers( void );
-
- // From WEDemoEvents.c
-
- void AdjustCursor( Point, RgnHandle );
- void DoMouseDown( const EventRecord * );
- void DoKeyDown( const EventRecord * );
- void DoDiskEvent( const EventRecord * );
- void DoOSEvent( const EventRecord * );
- void DoHighLevelEvent( const EventRecord * );
- void DoNullEvent( const EventRecord * );
- void DoWindowEvent( const EventRecord *);
- void ProcessEvent( void );
- OSErr GotRequiredParams( const AppleEvent * );
- OSErr InitializeEvents( void );
-
- // from WEDemoFiles.c
-
- OSErr ReadTextFile( const FSSpec *, WEReference );
- OSErr WriteTextFile( const FSSpec *, WEReference );
- pascal OSErr TranslateDrag( DragReference, ItemReference, FlavorType, Handle );
- pascal OSErr CheckObjectLock( short, long, StringPtr );
- pascal OSErr FSpCheckObjectLock( const FSSpec * );
-
- // from WEDemoInit.c
-
- OSErr Initialize( void );
- void Finalize( void );
-
- // from WEDemoMenus.c
-
- void SetDefaultDirectory( const FSSpec * );
- short FindMenuItemText( MenuRef, ConstStr255Param );
- Boolean EqualColor( const RGBColor *, const RGBColor * );
- void PrepareMenus( void );
- void DoDeskAcc( short );
- OSErr DoNew( void );
- OSErr DoOpen( void );
- OSErr SaveWindow( const FSSpec *, WindowRef );
- OSErr DoSaveAs( const FSSpec *, WindowRef );
- OSErr DoSave( WindowRef );
- OSErr DoClose( ClosingOption, SavingOption, WindowRef );
- OSErr DoQuit( SavingOption );
- void DoAppleChoice( short );
- void DoFileChoice( short );
- void DoEditChoice( short );
- void DoFontChoice( short, EventModifiers );
- void DoSizeChoice( short );
- void DoStyleChoice( short );
- void DoColorChoice( short );
- void DoAlignmentChoice( short );
- void DoDirectionChoice ( short ) ;
- void DoFeatureChoice( short );
- void DoMenuChoice( long, EventModifiers );
- OSErr InitializeMenus( void );
-
- // from WEDemoScripting.c
-
- OSErr WEGetContentsDesc( long, long, Boolean, AEDesc *, WEReference );
- OSErr WESetContentsDesc( long, long, const AEDesc *, WEReference );
- OSErr InstallCoreHandlers( void );
-
- // from WEDemoWindows.c
-
- void DoDrag( Point, WindowRef );
- void DoGrow( Point, WindowRef );
- void DoZoom( short, WindowRef );
- Boolean DoContent( Point, const EventRecord *, WindowRef );
- void DoKey( short, const EventRecord * );
- void DoUpdate( WindowRef );
- void DoActivate( Boolean, WindowRef );
- OSErr CreateWindow( const FSSpec * );
- void DestroyWindow( WindowRef );
- void Resize( Point, WindowRef );
-
-
- #endif /* __WEDEMOAPP__ */