home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 November: Tool Chest / Dev.CD Nov 98 TC.toast / Sample Code / Text / SimpleText Sample / SimpleText.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-10-17  |  17.5 KB  |  486 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        SimpleText.h
  3.  
  4.     Contains:    defines input for both .c and .r files.
  5.                 structured so as to compile corrected in both.
  6.  
  7.     Version:    SimpleText 1.4 or later
  8.  
  9. ** Copyright 1993-1996 Apple Computer. All rights reserved.
  10. **
  11. **    You may incorporate this sample code into your applications without
  12. **    restriction, though the sample code has been provided "AS IS" and the
  13. **    responsibility for its operation is 100% yours.  However, what you are
  14. **    not permitted to do is to redistribute the source as "DSC Sample Code"
  15. **    after having made changes. If you're going to re-distribute the source,
  16. **    we require that you make it clear in the source that the code was
  17. **    descended from Apple Sample Code, but that you've made changes.
  18.  
  19. */
  20.  
  21. #ifndef __SIMPLETEXT__
  22. #define __SIMPLETEXT__
  23.  
  24. #define kScrollBarSize                15        // size of a scroll bar, in pixels
  25.  
  26. // Internal errors -- WARNING: some also appear in SimpleText.r
  27. #define eActionAlreadyHandled        100        // the action was handled by the object, don't report an error
  28. #define eUserCanceled                101        // user canceled an operation
  29.  
  30. #define eDocumentTooLarge            200        // document too large to be opened
  31. #define eDocumentWrongKind            201        // document cannot be opened by this application
  32. #define eErrorWhileDrawing            202        // error while drawing the document
  33. #define eDocumentContainsPS            203        // document contains PostScript, it may not display properly
  34. #define eMachineToOld                204
  35. #define eDocumentNotModifiable        205        // document can't be modified
  36. #define eDocumentAlreadyOpen        206
  37. #define eDocumentContainsNoPages    207
  38.  
  39. #define eDocumentHasNoContentsEntries 208    
  40.  
  41. // icon IDs -- WARNING: Also appear in SimpleText.r
  42. #define kTextIcon                    129
  43. #define kReadOnlyIcon                130
  44. #define kPICTIcon                    131
  45. #define kStationeryIcon                132
  46.  
  47. // menu and item defines -- define 'MENU' 'MCMD' 'hmnu' and 'STR#' IDs for menus!
  48. #define rMenuBar            128
  49.  
  50. #define    mApple                128
  51. #define    mFile                129
  52. #define    mEdit                130
  53. #define mFont                131
  54. #define mSize                132
  55. #define mStyle                133
  56. #define    mSound                134
  57. #define mVoices                135
  58. #define mContents            136        
  59.  
  60. #define mLastMenu            mContents
  61. #define mNumberMenus        9
  62.  
  63. #define mFontSubMenusStart    200
  64.  
  65. // Command numbers
  66. #define cNull                0
  67. #define cAbout                1
  68. #define cDeskAccessory        2
  69. #define cTypingCommand        3
  70.  
  71. #define cNew                10
  72. #define cOpen                11
  73. #define cClose                12
  74. #define cSave                13
  75. #define cSaveAs                14
  76. #define cPageSetup            15
  77. #define cPrint                16
  78. #define cPrintOneCopy        17
  79. #define cQuit                18
  80.  
  81. #define cUndo                20
  82. #define cCut                21
  83. #define cCopy                22
  84. #define cPaste                23
  85. #define cClear                24
  86. #define cSelectAll            25
  87. #define cFind                26
  88. #define cFindAgain            27
  89. #define cFindSelection        28
  90. #define cReplace            29
  91. #define cReplaceAgain        30
  92. #define cNextPage            31
  93. #define cPreviousPage        32
  94. #define cGotoPage            33
  95.     #define cGotoLast            32767
  96.     #define cGotoFirst            -32767
  97. #define cShowClipboard        34
  98.  
  99. #define cSelectFont            35
  100. #define cSelectFontStyle    36
  101.  
  102. #define cSize9                40
  103. #define cSize10                41
  104. #define cSize12                42
  105. #define cSize14                43
  106. #define cSize18                44
  107. #define cSize24                45
  108. #define cSize36                46
  109.  
  110. #define cPlain                50
  111. #define cBold                51
  112. #define cItalic                52
  113. #define cUnderline            53
  114. #define cOutline            54
  115. #define cShadow                55
  116. #define cCondensed            56
  117. #define cExtended            57
  118.  
  119. #define cRecord                60
  120. #define cPlay                61
  121. #define cErase                62
  122. #define cSpeak                63
  123. #define cStopSpeaking        64
  124. #define cSelectVoice        65
  125. #define cSelectVoiceSubMenu    66
  126.  
  127. #define cSelectContents        75        
  128.  
  129. // windows, dialogs, alerts, and other items of that sort
  130. #define kDefaultWindowID        128
  131. #define kSaveChangesWindowID    129
  132. #define kFindWindowID            130
  133. #define kReplaceWindowID        131
  134.     #define iFindEdit                4
  135.     #define iCaseSensitive            5
  136.     #define iWrapAround                6
  137.     #define iReplaceEdit            8
  138.     #define iReplaceAll                9
  139.     
  140. // Error STR# base
  141. #define kErrorBaseID            1000
  142.  
  143. // Help for window STR#
  144. #define kWindowHelpID            2000
  145.     #define iDidTheBalloon                -1
  146.     #define iNoBalloon                    0
  147.     
  148.     #define iHelpActiveScroll            1
  149.     #define iHelpDimHorizScroll            2
  150.     #define iHelpDimVertScroll            3
  151.     #define iHelpGrowBox                4
  152.     #define iHelpGenericContent            5
  153.  
  154.     #define iHelpPictContent            6
  155.     #define iHelpPictSelection            7
  156.     #define iHelpTextContent            8
  157.  
  158. // Miscellaneous strings (STR#)
  159. #define kMiscStrings            3000
  160. #define iFirstNewDocumentTitle    1
  161. #define iHelpMenuCommand        2
  162. #define iSelectAllCommand        3
  163. #define iSelectNoneCommand        4
  164.  
  165. // Patterns used for selections
  166. #define kPatternListID        128
  167.  
  168. // for disabling menu items
  169. #define AllItems    0b1111111111111111111111111111111    /* 31 flags */
  170. #define NoItems        0b0000000000000000000000000000000
  171. #define MenuItem1    0b0000000000000000000000000000001
  172. #define MenuItem2    0b0000000000000000000000000000010
  173. #define MenuItem3    0b0000000000000000000000000000100
  174. #define MenuItem4    0b0000000000000000000000000001000
  175. #define MenuItem5    0b0000000000000000000000000010000
  176. #define MenuItem6    0b0000000000000000000000000100000
  177. #define MenuItem7    0b0000000000000000000000001000000
  178. #define MenuItem8    0b0000000000000000000000010000000
  179. #define MenuItem9    0b0000000000000000000000100000000
  180. #define MenuItem10    0b0000000000000000000001000000000
  181. #define MenuItem11    0b0000000000000000000010000000000
  182. #define MenuItem12    0b0000000000000000000100000000000
  183. #define MenuItem13    0b0000000000000000001000000000000
  184. #define MenuItem14    0b0000000000000000010000000000000
  185. #define MenuItem15    0b0000000000000000100000000000000
  186. #define MenuItem16    0b0000000000000001000000000000000
  187. #define MenuItem17    0b0000000000000010000000000000000
  188. #define MenuItem18    0b0000000000000100000000000000000
  189. #define MenuItem19    0b0000000000001000000000000000000
  190.  
  191. // Size resource information
  192. #define kPreferredSize        512*1024
  193. #define kMinimumSize        192*1024
  194.  
  195. #ifndef REZ
  196.  
  197.     enum {
  198.         // Keyboard virtual keycode constants
  199.         kHome        = 0x73,
  200.         kEnd        = 0x77,
  201.         kPageUp        = 0x74,
  202.         kPageDown    = 0x79,
  203.         kUpArrow    = 0x7E,
  204.         kDownArrow    = 0x7D,
  205.         kLeftArrow    = 0x7B,
  206.         kRightArrow    = 0x7C,
  207.         kF1            = 0x7A,
  208.         kF2            = 0x78,
  209.         kF3            = 0x63,
  210.         kF4            = 0x76,
  211.     
  212.         kFromTopTipOffset = 20,                        // offset from top/left of balloons
  213.         kFromBottomTipOffset = 7,                    // offset from bottom/right of balloons
  214.         
  215.         kRAMNeededForNew = 64*1024,                    // amount of RAM free before we allow New documents
  216.         kGrowScrollAdjust = 13,                        // amount to cull scroll bar to make room for growbox
  217.         
  218.         kMinDocSize        =     128                        // min window size in pixels
  219.         };
  220.  
  221.     enum
  222.         {
  223.         kMaxWaitTime    =    5*60*60                // maximum time to pass to WaitNextEvent()
  224.         };
  225.         
  226.     struct MachineInfoRec
  227.         {
  228.         SysEnvRec        theEnvirons;            // SysEnvirons for this machine
  229.         Boolean            amInBackground;            // are we running in the background or foreground
  230.         long            documentCount;            // # of new docs we have made
  231.         short            lastBalloonIndex;        // identifier of last balloon we displayed
  232.  
  233.         Boolean            haveQuickTime;            // do we have QuickTime installed?
  234.         Boolean            haveRecording;            // do we have sound input?
  235.         Boolean            haveTTS;                // do we have text to speech?
  236.         Boolean            haveGX;                    // do we have GX?
  237.         Boolean            haveTSM;                // do we have text services?
  238.         Boolean            haveTSMTE;                // have inline support for TE?
  239.         Boolean            haveDragMgr;            // do we have the Drag Manager?
  240.         Boolean            haveThreeD;                // do we have 3D on this machine?
  241.         Boolean            haveAppleGuide;            // do we have AppleGuide?
  242.         Boolean            haveThreads;            // do we have threads?
  243.         
  244.         Boolean            haveStartedGX;            // have initialized GX
  245.         };
  246.     typedef struct MachineInfoRec MachineInfoRec, *MachineInfoPtr;
  247.  
  248.     #ifndef CompilingMain
  249.     extern MachineInfoRec     gMachineInfo;
  250.     extern EventRecord        gEvent;
  251.     extern Str255            gFindString, gReplaceString;
  252.     extern Boolean            gWrapAround, gCaseSensitive;
  253.     #endif
  254.     
  255.     
  256.     struct PreflightRecord
  257.         {
  258.         Boolean        continueWithOpen;    // continue with the opening of the window
  259.         Boolean        needResFork;        // create resfork if none exists
  260.         SignedByte    openKind;            // kind of opening of this file
  261.         short        resourceID;            // resource ID of the 'WIND' resource
  262.         Boolean        wantHScroll;        // want a horizontal scroll bar
  263.         Boolean        wantVScroll;        // want a vertical scroll bar
  264.         Boolean        doZoom;                // want window opened large
  265.         long        storageSize;        // data for the window's refCon
  266.         void *        makeProcPtr;        // pointer to the make proc
  267.         OSType        fileType;            // file type of document
  268.         };
  269.     typedef struct PreflightRecord PreflightRecord, *PreflightPtr;
  270.     
  271.     struct LongRect
  272.         {
  273.         long    top;
  274.         long    left;
  275.         long    bottom;
  276.         long    right;
  277.         };
  278.     typedef struct LongRect LongRect;
  279.     
  280.     typedef OSErr     (*PreflightWindowProc) (PreflightPtr pPreflightData);
  281.     typedef OSErr     (*MakeWindowProc) (WindowRef pWindow, void* refCon);
  282.     typedef OSErr     (*UpdateWindowProc) (WindowRef pWindow, void* refCon);
  283.     typedef OSErr     (*AdjustMenusProc) (WindowRef pWindow, void* refCon);
  284.     typedef OSErr     (*CloseWindowProc) (WindowRef pWindow, void* refCon);
  285.     typedef OSErr     (*GetDocumentRectProc) (WindowRef pWindow, void* refCon, LongRect * documentRectangle, Boolean forGrow);
  286.     typedef OSErr     (*ContentClickProc) (WindowRef pWindow, void* refCon, EventRecord * event);
  287.     typedef OSErr     (*ScrollContentProc) (WindowRef pWindow, void* refCon, short deltaH, short deltaV);
  288.     typedef Boolean    (*FilterEventProc) (WindowRef pWindow, void* refCon, EventRecord * event);
  289.     typedef OSErr    (*ActivateEventProc) (WindowRef pWindow, void* refCon, Boolean activating);
  290.     typedef OSErr    (*KeyEventProc) (WindowRef pWindow, void* refCon, EventRecord * event, Boolean isMotionKey);
  291.     typedef OSErr    (*AdjustSizeProc) (WindowRef pWindow, void* refCon, Boolean *didResize);
  292.     typedef OSErr    (*CommandProc) (WindowRef pWindow, void* refCon, short commandID, long menuResult);
  293.     typedef OSErr    (*AdjustCursorProc) (WindowRef pWindow, void* refCon, Point * localMouse, Rect *globalRect);
  294.     typedef OSErr    (*PrintPageProc) (WindowRef pWindow, void* refCon, Rect* pageRect, long* pageNum);
  295.     typedef OSErr    (*GetBalloonProc) (WindowRef pWindow, void* refCon, Point *localMouse, short * returnedBalloonIndex, Rect *returnedRectangle);
  296.     typedef OSErr    (*DragTrackingProc) (WindowRef pWindow, void *refCon, DragReference theDragRef, short message);
  297.     typedef OSErr    (*DragReceiveProc) (WindowRef pWindow, void *refCon, DragReference theDragRef);
  298.     typedef OSErr    (*DragAddFlavorsProc) (WindowRef pWindow, void *refCon, DragReference theDragRef);
  299.     typedef long    (*CalculateIdleTimeProc) (WindowRef pWindow, void* refCon);
  300.     typedef OSErr    (*GetCoachRectangleProc) (WindowRef pWindow, void* refCon, Rect *pRect, Ptr name);
  301.  
  302.     struct WindowDataRecord
  303.         {
  304.         WindowRecord            theWindow;                // toolbox storage
  305.         ResType                    windowKind;                // and kind to identify window type
  306.         OSType                    originalFileType;        // original source of file
  307.         FSSpec                    fileSpec;                // file spec of the file
  308.         short                    dataRefNum;                // data fork refNum
  309.         short                    resRefNum;                // res fork refNum
  310.         Boolean                    isWritable;                // can you write to this file?
  311.         Boolean                    bumpUntitledCount;        // does this kind of document use up an "untitled" number?
  312.         Boolean                    openAsNew;                // open as an untitled document?
  313.         Boolean                    changed;                // has content changed?
  314.         Boolean                    documentOutputsGX;        // document provides GX printing
  315.         Boolean                    documentAcceptsText;    // document allows typing
  316.         Boolean                    dragWindowAligned;        // drag using DragAlignedWindow
  317.         
  318.         // Standard procedure entry points, may be NIL to get default behavior
  319.         PreflightWindowProc        pPreflightWindow;
  320.         MakeWindowProc            pMakeWindow;
  321.         CloseWindowProc            pCloseWindow;
  322.         
  323.         GetDocumentRectProc        pGetDocumentRect;
  324.         ScrollContentProc        pScrollContent;
  325.         AdjustSizeProc            pAdjustSize;
  326.         AdjustCursorProc        pAdjustCursor;
  327.         GetBalloonProc            pGetBalloon;
  328.         DragTrackingProc        pDragTracking;
  329.         DragReceiveProc            pDragReceive;
  330.         DragAddFlavorsProc        pDragAddFlavors;
  331.         
  332.         FilterEventProc            pFilterEvent;
  333.         ActivateEventProc        pActivateEvent;
  334.         UpdateWindowProc        pUpdateWindow;
  335.         AdjustMenusProc            pAdjustMenus;
  336.         KeyEventProc            pKeyEvent;
  337.         ContentClickProc        pContentClick;
  338.         CommandProc                pCommand;
  339.         PrintPageProc            pPrintPage;
  340.         CalculateIdleTimeProc    pCalculateIdleTime;
  341.         GetCoachRectangleProc    pGetCoachRectangle;
  342.         
  343.         // controls that the default implementations use
  344.         void*                    hPrint;            // print record, gxJob, or NIL for none
  345.         Boolean                    hasGrow;        // has a grow box?
  346.         Rect                    contentRect;    // content area, minus the scroll bars
  347.         short                    minHSize;        // minimum window X size, 0 default
  348.         short                    minVSize;        // minimum window Y size, 0 default
  349.         ControlRef                hScroll;        // horizontal scroll bar
  350.         ControlRef                vScroll;        // vertical scroll bar
  351.         short                    hScrollAmount;    // amount to scroll in left/right arrow
  352.         short                    vScrollAmount;    // amount to scroll in up/down arrow
  353.         short                    hScrollOffset;    // offset of scrollbar from left side of window
  354.         short                    vScrollOffset;    // offset of scrollbar from top of window
  355.         
  356.         // variables having to do with input support
  357.         TSMTERecHandle            docTSMRecHandle;    // TSM info stored here
  358.         TSMDocumentID            docTSMDoc;            // TSM document id
  359.         
  360.         // Custom data follows here
  361.         };
  362.     typedef struct WindowDataRecord WindowDataRecord, *WindowDataPtr;    
  363.  
  364.     // Window adjustment routines
  365.     OSErr AdjustScrollBars(WindowRef pWindow, Boolean moveControls, Boolean didGrow, Boolean *needInvalidate);
  366.     void SetControlAndClipAmount(ControlRef control, short * amount);
  367.     OSErr DoScrollContent(WindowRef pWindow, WindowDataPtr pData, short deltaH, short deltaV);
  368.  
  369.     // document rectangle utilities
  370.     void LongRectToRect(LongRect* longRect, Rect *rect);
  371.     void RectToLongRect(Rect *rect, LongRect *longRect);
  372.     void MovableModalDialog(ModalFilterProcPtr filterProc, short * pItem);
  373.     void BeginMovableModal(void);
  374.     void EndMovableModal(void);
  375.     void GetPICTRectangleAt72dpi(PicHandle hPicture, Rect *pictureRect);
  376.     
  377.     // menu command utilities
  378.     void EnableCommand(short commandID);
  379.     void EnableCommandCheck(short commandID, Boolean check);
  380.     void EnableCommandCheckStyle(short commandID, Boolean check, short style);
  381.     void ChangeCommandName(short commandID, short resourceID, short resourceIndex);
  382.     Boolean IsCommandEnabled(short commandID);
  383.  
  384.     // printing utility routines
  385.     Boolean IsSomewhereInRectangle(gxRectangle *pContainer, gxRectangle *pShape);
  386.     OSErr    DoDefault(WindowDataPtr     pData);
  387.     OSErr    DoPageSetup(WindowRef pWindow);
  388.  
  389.     // event handling routines
  390.     void HandleEvent(EventRecord *);
  391.     void DragAndDropArea(WindowRef pWindow, WindowDataPtr pData, EventRecord* event, Rect *pFrameRect);
  392.     short ConductFindOrReplaceDialog(short dialogID);
  393.     Boolean PerformSearch(
  394.             Handle    h,                    // handle to search
  395.             long start,                    // offset to begin with
  396.             Str255 searchString,        // string to search for
  397.             Boolean isCaseSensitive,    // case sensitive search
  398.             Boolean isBackwards,        // search backwards from starting point
  399.             Boolean isWraparound,        // wrap search around from end->begining
  400.             long * pNewStart,            // returned new selection start
  401.             long * pNewEnd);            // returned new selection end
  402.  
  403.     // Drag utils
  404.     Boolean IsOnlyThisFlavor(DragReference theDragRef, FlavorType theType);
  405.     Boolean IsDropInFinderTrash(AEDesc *dropLocation);
  406.     Boolean DragText(WindowRef pWindow, void *pData, EventRecord *pEvent, RgnHandle hilightRgn);
  407.     OSErr TextDragTracking(WindowRef pWindow, void *pData, DragReference theDragRef, short message);
  408.     OSErr TextDragReceive(WindowRef pWindow, void *pData, DragReference theDragRef);
  409.     
  410.     // TEClick utilities
  411.     pascal void TextClickLoop(void);
  412.     pascal TEClickLoopUPP GetOldClickLoop(void);
  413.     void AdjustTE(WindowDataPtr pData, Boolean doScroll);
  414.  
  415.     // error utilities
  416.     void ConductErrorDialog(OSErr error, short commandID, short alertType);
  417.  
  418.     // generic utilities
  419.     void SetWatchCursor(void);
  420.     OSErr SaveCurrentUndoState(WindowDataPtr pData, short newCommandID);
  421.     #if GENERATINGPOWERPC
  422.         pascal void MyDrawHook ( unsigned short offset, unsigned short textLen,
  423.             Ptr textPtr, TEPtr tePtr, TEHandle teHdl );
  424.     #else
  425.         pascal void MyDrawHook ( TEHandle teHdl, TEPtr tePtr, Ptr textPtr, short textLen, short offset );
  426.     #endif
  427.     
  428.     // Preflight routines for the windows we support
  429.     OSErr AboutPreflightWindow(PreflightPtr pPreflightData);
  430.     OSErr PICTPreflightWindow(PreflightPtr pPreflightData);
  431.     OSErr MoviePreflightWindow(PreflightPtr pPreflightData);
  432.     OSErr ClipboardPreflightWindow(PreflightPtr pPreflightData);
  433.     OSErr TextPreflightWindow(PreflightPtr pPreflightData);
  434.     OSErr GXPreflightWindow(PreflightPtr pPreflightData);
  435.     OSErr ThreeDPreflightWindow(PreflightPtr pPreflightData);
  436.     
  437.     // File type routines for the document kinds we support
  438.     void AboutGetFileTypes(OSType * pFileTypes, OSType * pDocumentTypes, short * numTypes);
  439.     void PICTGetFileTypes(OSType * pFileTypes, OSType * pDocumentTypes, short * numTypes);
  440.     void MovieGetFileTypes(OSType * pFileTypes, OSType * pDocumentTypes, short * numTypes);
  441.     void ClipboardGetFileTypes(OSType * pFileTypes, OSType * pDocumentTypes, short * numTypes);
  442.     void TextGetFileTypes(OSType * pFileTypes, OSType * pDocumentTypes, short * numTypes);
  443.     void GXGetFileTypes(OSType * pFileTypes, OSType * pDocumentTypes, short * numTypes);
  444.     void ThreeDGetFileTypes(OSType * pFileTypes, OSType * pDocumentTypes, short * numTypes);
  445.     
  446.     // selection rectangle utilities
  447.     #define MOVESELECTION(X) (((X) & 0x7) == 0x4)
  448.     void DrawSelection(WindowDataPtr pData, Rect *pSelection, short * pPhase, Boolean bumpPhase);
  449.     OSErr SelectContents(WindowRef pWindow, WindowDataPtr pData, EventRecord *pEvent, Rect *pSelection, Rect *pContent, short *pPhase);
  450.     
  451.     // Exported globals
  452.     struct FontMappingRecord
  453.         {
  454.         gxFont    fontID;
  455.         short    qdFont;
  456.         Style    qdStyle;
  457.         };
  458.     typedef struct FontMappingRecord FontMappingRecord, *FontMappingPtr, **FontMappingHandle;
  459.  
  460.     extern FontMappingHandle gFontMappingList;
  461.     
  462. #endif
  463.  
  464. // defined window kinds and resource ranges for windows we support
  465. #define kAboutWindow        'ABOT'
  466. #define kAboutBaseID        200
  467.  
  468. #define kPICTWindow            'PICT'
  469. #define kPICTBaseID            300
  470.  
  471. #define kMovieWindow        'MooV'
  472. #define kMovieBaseID        400
  473.  
  474. #define kClipboardWindow    'Clip'
  475. #define kClipboardBaseID    500
  476.  
  477. #define kTextWindow            'TEXT'
  478. #define kTextBaseID            600
  479.  
  480. #define kGXWindow            'qdgx'
  481. #define kGXBaseID            700
  482.  
  483. #define kThreeDWindow        '3DMF'
  484. #define kThreeDBaseID        800
  485.  
  486. #endif