home *** CD-ROM | disk | FTP | other *** search
- /*
- *
- * XTRN.h: external interface definitions and structures
- * © 1994 Jersey Scientific, All Rights Reserved
- *
- * History:
- * 01/01/94: Version 1 of xtern structure
- * 03/01/94: OK to have globals in the code
- * 06/01/94: Added Zoom, WindowCloseIntercept
- * 06/10/94: Added AEOpen callback
- * 06/12/94: keyEquivalent and keyFunction have #include files
- */
-
- #ifndef __XTRN__
- #define __XTRN__
-
- /*
- Each external has a 'mres' resource of ID == 128 consisting of an array of
- 'mres' structures which describe the resources which the external needs to function.
- The PROC resource MUST be described as the the first 'mres' structure.
-
- All resources will be loaded and HLock'ed before the external is called, and are
- HUnlocked and HPurged after the call, except the PROC resource, which gets restored
- to its previous state (the state you set it when it was created).
-
- The external's ID can change during an editing session if an external is deleted,
- so never cache this number! DLOGs and ALRTs will be pre-centered so no need to call
- your own position dialog routine unless you want something different.
-
- You can use Globals in your code resource.
- */
-
- #define CAPSLOCK ((*(short*)0x17A & 0x2) != 0)
- /* Handy, as you can use it for debugging as
- * if(CAPSLOCK) {
- * (xt->debugPrintf("Got a problem %d", i);
- * }
- */
-
- typedef struct {
- short flags; // what type is this item
- # define NX_FUNCTION 0x0001 // type
- # define NX_PRAGMA_MARK 0x0002 // type
- # define NX_MPSR 0x0004 // type
- # define NX_IFDEF_MARK 0x0008 // type
- # define NX_ELSEIF_MARK 0x0010 // type
- # define NX_ENDIF_MARK 0x0020 // type
- # define NX_CPLUS 0x0040 // C++ function
- # define NX_NOCOUNT 0x0080 // no count this function (used with exclusion feature)
- # define NX_NEVERCOUNT 0x0100 // never count this resource
- # define NX_INCLUDE 0x0200 // #include file (not normally passed to Externals)
- # define NX_CLASS 0x0400 // class ... lines
- # define NX_ENUM 0x0800 // enum ... lines
- # define NX_STRUCT 0x1000 // struct... lines
- # define NX_TYPEDEF 0x2000 // typdef struct ... lines
- short protoLen; // includes the '{' at the end
- long commentStart; // best guess where the comment starts
- long protoStart; // information needed for developing prototypes
- long nameStart; // points to function name
- long startBrace; // offset to the starting brace
- long endBrace; // offset to the final brace
- Byte nameLen; // function name len
- Byte classLen; // length of the class in "class :: method"
- Byte methodLen; // length of the method in "class :: method"
- Byte _unused; // spare
- } NameNode, *NameNodePtr, **NameNodeHdl;
-
- typedef struct {
- short version; // version number to get all fields below - now 1
- Handle text; // actual handle of the windows text (usually unlocked!)
- long textLngth; // don't GetHandleSize of above - use this number
- long topOfScreen; // offset to the char at top left of window
- long startSelect; // offset to the cursor or the current selection start
- long endSelect; // offset to the cursor or the current selection end
- unsigned long upDateTime; // System time of last update
- FSSpec fileFSSpec; // FSSpec of the current text file
- StringPtr fileName; // file name of current window
- short vRefNum; // file volume reference number
- long dirID; // file directory reference number
- short tabCount; // chars-per-tab
- NameNodeHdl nnH; // parsed data (see above struct)
- short nnCount; // size of above
- short windDirty; // true if window is "dirty"
- short windType; // 0 == no write, 1 write OK, 2 write/modified
- Handle ckidHdl; // the 'ckid' handle attached to this window
- long _growth[3]; // we might add more stuff during the beta
- } TextData, *TextDataPtr, **TextDataHdl;
-
- typedef struct {
- char function[32]; // name for menus (C style)
- short keyEquivalent; // used to temporarily store equivalents
- } PxItem, *PxItemPtr, **PxItemHdl;
-
- typedef struct {
- char fileName[32]; // USED BY CMASTER - DO NOT CHANGE
- short _cmReserved0; // USED BY CMASTER - DO NOT CHANGE
- short inited; // USED BY CMASTER - DO NOT CHANGE
- short wantRawEvents; // want to see events before CMaster
- // - events passes in the parameter block,
- // - CMaster passes your return code as
- // - GetNextEvent return
- short wantProcessedEvents; // want to see events after CMaster has perhaps
- // - changed it,
- // - events passes in the parameter block.
- // - CMaster passes your return code as the
- // - GetNextEvent return.
- short wantOpenWindow; // want to do something just as a window opens.
- // - CMaster responds with two calls.
- // - One, when the window size can be changed.
- // - Two, when you can look at the data, and
- // - possibly change it (we haven't tested this.)
- // - WindowPeek, fileRefNum, passed in the parameter block
- short wantCloseWindow; // want to intercept the user closing a window. Return TRUE
- // - in response to the XTRN_WIND_CLOSE event to prevent the window
- // - actually closing. To actually close the window, you must
- // - later post a CMD-W event (while getting RAW or COOKED events,
- // - change a nullEvent into a CMD-W). See NOTE below on this event.
- // - WindowPeek, fileRefNum, passed in the parameter block
- short wantZoom; // want to do something when user presses Zoom box
- // - or they type Cmd-/
- // - You can change either of the userState or stdState
- // - rectangles, so you could move the window to another
- // - monitor if you wanted to. You would return FALSE
- // - to let the Zoom proceed as normal, or you can
- // - return inZoomIn (Windows.h) to have the window zoom
- // - to the userState, or inZoomOut to the WDEF's out state.
- // - WindowPeek, fileRefNum, passed in the parameter block
- short _unused[2]; // future something...
-
- long reserved0; // use for semi-permanent storage (during one project cycle)
- long reserved1; // use for semi-permanent storage (during one project cycle)
- long reserved2; // use for semi-permanent storage (during one project cycle)
- long reserved3; // use for semi-permanent storage (during one project cycle)
- short _cmReserved1; // USED BY CMASTER - DO NOT CHANGE
-
- PxItem normalFunc;
- PxItem optionFunc;
- PxItem cmdFunc;
- PxItem controlFunc;
- PxItem shiftFunc;
- PxItem shiftOptionFunc;
- PxItem shiftCmdFunc;
- PxItem optionCmdFunc;
- PxItem optionControlFunc;
- PxItem optionShiftCmdFunc;
- } XtItem, *XtItemPtr, **XtItemHdl; // resource 'xitm'
-
- typedef struct {
- short version; // version of this structure
- short resID; // the current XTRN's resource ID (20000 -> ...)
- EventRecord *evp; // NULL or event record (XTRN_RAW, XTRN_COOKED, XTRN_KEY)
- WindowPeek window; // NULL, foremost text window, or window for XTRN_WIND_OPEN & XTRN_WIND_CLOSE
- short projResFile; // refNum of resource fork of the Project file
- short xtrnResFile; // refNum of resource fork of the CMaster Pref file
- short xtrnVRefNum; // vRefNum of the CMaster XTRN folder
- long xtrnDirID; // dirID of the CMaster XTRN folder
- long private[4]; // needed by future callbacks
-
- void (*deActivate)(void);
- // call this before showing a dialog (or another) window - it unhilites the
- // foremost window as needed
- void (*debugPrintf)(char *fmt, ...);
- // Printf-style DebugStr- just makes debugging nices and CMaster eats the extra
- // space instead of you
- void (*doneBeep)(void);
- // DoneBeep sound used by CMaster to signal the end of an activity otherwise not
- // obvious
- Handle (*fullFileName)(FSSpec *fssP);
- // Given a FSSpec pointer, CMaster builds the complete path name and stores
- // it into a handle, which you then must DisposeHandle(). A handle is used as
- // a Str255 may not be large enought to store the string. The handle contains
- // text only, that is, it is neither a Pascal nor a C string.
- Handle (*getScrapHandle)(void); // get current scrap
- // Returns a handle containing a copy of the current scrap.
- // DisposeHandle() after using.
- void (*hardBeep)(void);
- // HardBeep sound used to signal serious problems that will likely lead to a crash
- Boolean (*putScrapHandle)(Handle textH);
- // loading THINK's scrap with this handle, but don't paste it. The user can then
- // paste this text by typing Cmd-V. Before pasting your own text, you can use
- // the getScrapHandle call to get the current scrap, paste your stuff, then use this
- // command to reload THINK's scrap with the original contents.
- Boolean (*pasteText)(Handle textH);
- // paste the supplied text handle into the window at the current cursor or selection
- // range, perhaps overwriting text.
- void (*positionDialog)(OSType type, short resID);
- // put a 'DLOG' or 'ALRT' onto the main screen either 1/3 or 1/5 from the top, respectively
- void (*positionSubDialog)(OSType type, short resID);
- // put a DLOG or ALRT positioned over another window. the Apple HIM recommends this
- // type of action when the dialog refers to the foremost window. This call could
- // place the dialog offscreen if the window is poorly located or small relative to
- // the dialog.
- void (*softBeep)(void);
- // SoftBeep sound - used to signal incorrect input, a user error, etc
- void (*reFreshWindows)(WindowPeek wp);
- // callback for Moveable Modal dialogs to UpDate THINK C windows as the window
- // moves. In a Modal Dialog filter function, call the code located at the bottom
- // of this file to get a "cheap" Moveable-Modal-Dialog.
-
- TextDataPtr (*getTextData)(WindowPeek wp);// returns nil or a struct ptr
- // function to get data for the foremost window's text handle,
- // length of the text (which may be smaller than GetHandleSize!!).
- // This is the actual text handle - may or may not be locked,
- // so return to its original state when you return.
- // Also, don't change text directly - use pasteText below.
- // Remember that you have to call DisposePtr on this data.
- void (*setSelection)(WindowPeek wp, long beginChar, long beginSelChar, long endSelChar, Boolean forceChange);
- // Set window to start showing text at offset "beginChar", hiliting
- // the text between offsets beginSelChar and endSelChar. The forceChange option,
- // if TRUE, says ignore "beginChar" and center the selection, This may happen in
- // any case, if the text does not all fit on the screen.
- Boolean (*getFiles)(WindowPeek wp, short type, FSSpec **fsspP, short *fsspNum);
- // CMaster returns a Ptr in fsspP containing an array of FSSpec records,
- // each containing a file which is either a header file (type == FILES_HEADER) or
- // a .c file (type == FILES_PROJ_SRC). Note that these values reference the STR#
- // 1030x strings that CMaster lets you override. They are the negative of the string
- // you want to get, so you could also get other files from that string too.
- // When calling this function, you define a variable "FSSpec *fsPtr", and use it
- // in the call as (..., &fsPtr, ...). When done, you must DisposePtr((Ptr)fsPtr).
- #define FILES_HEADERS -2 // Get header files in the current source file
- #define FILES_PROJ_HEADERS -5 // Get all header files in the project
- #define FILES_PROJ_SRC -6 // Get all source files in the project
- Boolean (*keyFunction)(WindowPeek wp, short type, EventRecord *evp);
- // Actuate a CMaster Key Function. The type is the 0-based offset in the pnmk 10000
- // resource. #include "CallKeyFunctions.h" to get #defines for them...
- Boolean (*keyEquivalent)(WindowPeek wp, short type, EventRecord *evp);
- // Actuate a CMaster Key Equivalent. The type is the 0-based offset in the pnme
- // 10000 resource. #include "CallKeyEquivalents.h" to get #defines for them...
- Boolean (*drawWindow)(WindowPeek wp, Boolean showIt);
- // If you muck with the size of the window as it opens (XTRN_WIND_OPEN), then
- // call this with "showIt" either false or true, depending on what works best for you...
- Boolean (*getResFile)(FSSpec *fssP);
- // Return a FSSpec containing a reference to the Project.π.rsrc file, or a
- // Aliased Project Resource File if one exists.
- short (*sprintf)(char *s, char *fmt, ...);
- // Standard File package Routine
- // Aliased Project Resource File if one exists.
- Boolean (*AEOpen)(FSSpec *fssP);
- // Open a file FSSpec, open that file. If THINK 5, this call queues a call
- // which is not processed until later (next NULL Event). Otherwise, CMaster
- // uses AppleEvents with THINK to open the file during the call. Note that
- // the current file will most likely NOT be the foremost file after this
- // call, so you probably should not do further text editing (however, we didn't
- // test this hypothesis, so all might work just fine.)
- // The file must be of type 'TEXT' or this call fails.
- } Xtrn, *XtrnPtr, **XtrnHdl;
-
- // NOTE: to change the text of a window as it closes, you intercept the WIND_CLOSE action
- // - first must set wantCloseWindow to TRUE. When you get a WIND_CLOSE_WIND call, you
- // - can change the file text, then set the wantProcessedEvents to TRUE (to look for nullEvents).
- // - Change the nullevent into a CMD-S to save the file, then at the next null event
- // - change it into a CMD-W event (and keep a flag around so that you will remember to
- // - return FALSE which lets THINK finally close the file. Sorry we can't give you a
- // - callback to do this, but CMaster has no way or doing this the "right" way.
-
- // NOTE: to remove a selection, get an empty handle (NewHandle(0L), then use it to
- // - in a call to PasteText(), and don't forget the DisposeHandle.
-
- // this is how your main function will be called
- typedef Boolean (*xProc)(
- short type, // type of call (XTRN_xxxx, see above)
- XtrnPtr xP, // xtern structure
- XtItemPtr iP, // some fields are for your private use - see above
- short keys // modifier keys associated with this event (KEY, MENU, and ZOOM only)
- // - XTRN_WIND_OPEN: TRUE if a Untitled window, FALSE otherwise
- );
- // type values
- #define XTRN_INIT 0 // init message: allocate temp memory, etc
- #define XTRN_QUIT 1 // quit message: deallocate temp memory, etc
- #define XTRN_RAW 2 // raw event in
- #define XTRN_COOKED 3 // event after CMaster could have changed it
- #define XTRN_WIND_OPEN1_SIZE 4 // window opening - you could resize it if you wanted to
- // - however, GetTextData fails at this point
- #define XTRN_WIND_OPEN2_DATA 8 // window opening - can now call GetTextData()
- #define XTRN_WIND_CLOSE 5 // selected by a menu selection (evp invalid) - see NOTE below
- #define XTRN_KEY 6 // selected by a key stroke (evp valid)
- #define XTRN_MENU 7 // selected by a menu selection (evp invalid)
- #define XTRN_ZOOM 9 // selected by a menu selection (evp invalid)
-
-
- // Externsion defines
- #define XTRN_START 20000 // CMaster starts numbering resources from here
- #define XTRN_GAP 32 // each XTRN gets a range of 32
- #define XTRN_DEFAULT 128 // default number
-
- /*
- * THIS IS A HANDY switch to use if you want to support many modifier options
- *
- switch(keys) {
- case 0:
- break;
- case (optionKey):
- break;
- case (cmdKey):
- break;
- case (controlKey):
- break;
- case (shiftKey):
- break;
- case (shiftKey|optionKey):
- break;
- case (shiftKey|cmdKey):
- break;
- case (optionKey|cmdKey):
- break;
- case (optionKey|controlKey):
- break;
- case (optionKey|shiftKey|cmdKey):
- break;
- }
- */
-
- /* code to add to a filter function for a cheap Moveable Modal Dialog Window (Thanks Max!)
- case mouseDown:
- case mouseUp:
- gWhere = evt->where; // Make info available to DoDialog()
- GlobalToLocal(&gWhere);
- theWindow = dlog;
- mouseLoc = FindWindow(evt->where, &theWindow);
- switch (mouseLoc) {
- case inDrag:
- bounds = (**GetGrayRgn()).rgnBBox;
- #define DRAG_MARGIN 4
- InsetRect(&bounds, DRAG_MARGIN, DRAG_MARGIN);
- DragWindow(theWindow, evt->where, &bounds);
- ans = TRUE; // Make sure Modal dialog doesn't handle event
- break;
- default:
- break;
- }
- break;
- case updateEvt:
- GetPort(&oldPort);
- SetPort(w);
- BeginUpdate(w);
- if (w == dlog) { // Update our dialog contents
- UpdtDialog(w, w->visRgn);
- {
- # define kButtonFrameInset (-4) // inset rectangle adjustment around button
- # define kButtonFrameSize 3 // button frame’s pen size
- short type; Handle hndl; Rect box;
- PenState oldPen;
- short buttonOval;
-
- GetPenState(&oldPen);
- PenNormal();
-
- GetDItem(dlog, 1, &type, &hndl, &box);
- InsetRect(&box, kButtonFrameInset, kButtonFrameInset);
- buttonOval = (box.bottom - box.top) / 2 + 2;
-
- PenMode(patCopy); // Paint or delete frame
- PenSize(kButtonFrameSize, kButtonFrameSize);
- FrameRoundRect(&box, buttonOval, buttonOval);
-
- SetPenState(&oldPen);
- }
- } else {
- (*xP->reFreshWindows)((WindowPeek)w); // the call back
- }
- EndUpdate((WindowPtr)w);
- SetPort(oldPort);
- */
- #endif /* __XTRN__ */