Update the ORCA/C desktop template to have more error checking.
This commit is contained in:
parent
222afbf9d6
commit
3c5a978718
|
@ -16,28 +16,39 @@
|
||||||
#include <Window.h>
|
#include <Window.h>
|
||||||
#include <Desk.h>
|
#include <Desk.h>
|
||||||
#include <Resources.h>
|
#include <Resources.h>
|
||||||
|
#include <MiscTool.h>
|
||||||
|
|
||||||
#include "___FILEBASENAME___.h"
|
#include "___FILEBASENAME___.h"
|
||||||
|
|
||||||
|
|
||||||
|
// Defines and macros
|
||||||
|
|
||||||
|
#define TOOLFAIL(string) \
|
||||||
|
if (toolerror()) SysFailMgr(toolerror(), "\p" string "\n\r Error Code -> $");
|
||||||
|
|
||||||
|
|
||||||
|
// Globals
|
||||||
|
|
||||||
BOOLEAN done;
|
BOOLEAN done;
|
||||||
EventRecord myEvent;
|
EventRecord myEvent;
|
||||||
unsigned int userid;
|
unsigned int userid;
|
||||||
|
|
||||||
|
|
||||||
void DoAbout(void)
|
// Implementation
|
||||||
|
|
||||||
|
void doAbout(void)
|
||||||
{
|
{
|
||||||
AlertWindow(awCString + awResource, NULL, aboutAlertString);
|
AlertWindow(awCString + awResource, NULL, ABOUT_ALERT_STRING);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
GrafPortPtr NewDocument(void)
|
GrafPortPtr newDocument(void)
|
||||||
{
|
{
|
||||||
return(NewWindow2("\pMyWindow", 0, NULL, NULL, 0x02, windowRes, rWindParam1));
|
return(NewWindow2("\p MyWindow ", 0, NULL, NULL, 0x02, WINDOW_RESID, rWindParam1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void CloseDocument(GrafPortPtr wPtr)
|
void closeDocument(GrafPortPtr wPtr)
|
||||||
{
|
{
|
||||||
if (wPtr != NULL) {
|
if (wPtr != NULL) {
|
||||||
CloseWindow(wPtr);
|
CloseWindow(wPtr);
|
||||||
|
@ -45,7 +56,7 @@ void CloseDocument(GrafPortPtr wPtr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void HandleMenu(void)
|
void handleMenu(void)
|
||||||
{
|
{
|
||||||
int menuNum;
|
int menuNum;
|
||||||
int menuItemNum;
|
int menuItemNum;
|
||||||
|
@ -54,47 +65,58 @@ void HandleMenu(void)
|
||||||
menuItemNum = myEvent.wmTaskData;
|
menuItemNum = myEvent.wmTaskData;
|
||||||
|
|
||||||
switch (menuItemNum) {
|
switch (menuItemNum) {
|
||||||
case appleAbout:
|
case APPLE_ABOUT:
|
||||||
DoAbout();
|
doAbout();
|
||||||
break;
|
break;
|
||||||
case fileNew:
|
case FILE_NEW:
|
||||||
NewDocument();
|
newDocument();
|
||||||
break;
|
break;
|
||||||
case fileOpen:
|
case FILE_OPEN:
|
||||||
NewDocument();
|
newDocument();
|
||||||
break;
|
break;
|
||||||
case fileClose:
|
case FILE_CLOSE:
|
||||||
CloseDocument(FrontWindow());
|
closeDocument(FrontWindow());
|
||||||
break;
|
break;
|
||||||
case fileQuit:
|
case FILE_QUIT:
|
||||||
done = TRUE;
|
done = TRUE;
|
||||||
break;
|
break;
|
||||||
case editUndo:
|
case EDIT_UNDO:
|
||||||
break;
|
break;
|
||||||
case editCut:
|
case EDIT_CUT:
|
||||||
break;
|
break;
|
||||||
case editCopy:
|
case EDIT_COPY:
|
||||||
break;
|
break;
|
||||||
case editPaste:
|
case EDIT_PASTE:
|
||||||
break;
|
break;
|
||||||
case editClear:
|
case EDIT_CLEAR:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
HiliteMenu(FALSE, menuNum);
|
HiliteMenu(FALSE, menuNum);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void InitMenus(void)
|
void initMenus(void)
|
||||||
{
|
{
|
||||||
int height;
|
int height;
|
||||||
MenuBarRecHndl menuBarHand;
|
MenuBarRecHndl menuBarHand;
|
||||||
|
|
||||||
menuBarHand = NewMenuBar2(refIsResource, menuBar, NULL);
|
menuBarHand = NewMenuBar2(refIsResource, MENU_BAR, NULL);
|
||||||
|
TOOLFAIL("Unable to create menu bar");
|
||||||
|
|
||||||
SetSysBar(menuBarHand);
|
SetSysBar(menuBarHand);
|
||||||
|
TOOLFAIL("Unable to set system menu bar");
|
||||||
|
|
||||||
SetMenuBar(NULL);
|
SetMenuBar(NULL);
|
||||||
FixAppleMenu(appleMenu);
|
TOOLFAIL("Unable to set menu bar");
|
||||||
|
|
||||||
|
FixAppleMenu(APPLE_MENU);
|
||||||
|
TOOLFAIL("Unable to fix Apple menu");
|
||||||
|
|
||||||
height = FixMenuBar();
|
height = FixMenuBar();
|
||||||
|
TOOLFAIL("Unable to fix menu bar");
|
||||||
|
|
||||||
DrawMenuBar();
|
DrawMenuBar();
|
||||||
|
TOOLFAIL("Unable to draw menu bar");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -104,29 +126,40 @@ int main(void)
|
||||||
Ref toolStartupRef;
|
Ref toolStartupRef;
|
||||||
|
|
||||||
userid = MMStartUp();
|
userid = MMStartUp();
|
||||||
TLStartUp();
|
TOOLFAIL("Unable to start memory manager");
|
||||||
toolStartupRef = StartUpTools(userid, refIsResource, toolStartup);
|
|
||||||
|
|
||||||
InitMenus();
|
TLStartUp();
|
||||||
|
TOOLFAIL("Unable to start tool locator");
|
||||||
|
|
||||||
|
toolStartupRef = StartUpTools(userid, refIsResource, TOOL_STARTUP);
|
||||||
|
TOOLFAIL("Unable to start tools");
|
||||||
|
|
||||||
|
initMenus();
|
||||||
InitCursor();
|
InitCursor();
|
||||||
|
|
||||||
done = FALSE;
|
done = FALSE;
|
||||||
myEvent.wmTaskMask = 0x001F7FFF;
|
myEvent.wmTaskMask = 0x001F7FFF;
|
||||||
while (!done) {
|
while (!done) {
|
||||||
event = TaskMaster(everyEvent, &myEvent);
|
event = TaskMaster(everyEvent, &myEvent);
|
||||||
|
TOOLFAIL("Unable to handle next event");
|
||||||
|
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case wInSpecial:
|
case wInSpecial:
|
||||||
case wInMenuBar:
|
case wInMenuBar:
|
||||||
HandleMenu();
|
handleMenu();
|
||||||
break;
|
break;
|
||||||
case wInGoAway:
|
case wInGoAway:
|
||||||
CloseDocument((GrafPortPtr)myEvent.wmTaskData);
|
closeDocument((GrafPortPtr)myEvent.wmTaskData);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ShutDownTools(refIsHandle, toolStartupRef);
|
ShutDownTools(refIsHandle, toolStartupRef);
|
||||||
|
TOOLFAIL("Unable to shutdown tools");
|
||||||
|
|
||||||
TLShutDown();
|
TLShutDown();
|
||||||
|
TOOLFAIL("Unable to shutdown tool locator");
|
||||||
|
|
||||||
MMShutDown(userid);
|
MMShutDown(userid);
|
||||||
|
TOOLFAIL("Unable to shutdown memory manager");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,30 +11,30 @@
|
||||||
#define _GUARD_PROJECT___PROJECTNAMEASIDENTIFIER____FILE___FILEBASENAMEASIDENTIFIER____
|
#define _GUARD_PROJECT___PROJECTNAMEASIDENTIFIER____FILE___FILEBASENAMEASIDENTIFIER____
|
||||||
|
|
||||||
|
|
||||||
#define menuBar 1
|
#define MENU_BAR 1
|
||||||
|
|
||||||
#define appleMenu 3
|
#define APPLE_MENU 3
|
||||||
#define fileMenu 4
|
#define FILE_MENU 4
|
||||||
#define editMenu 5
|
#define EDIT_MENU 5
|
||||||
|
|
||||||
#define editUndo 250
|
#define EDIT_UNDO 250
|
||||||
#define editCut 251
|
#define EDIT_CUT 251
|
||||||
#define editCopy 252
|
#define EDIT_COPY 252
|
||||||
#define editPaste 253
|
#define EDIT_PASTE 253
|
||||||
#define editClear 254
|
#define EDIT_CLEAR 254
|
||||||
|
|
||||||
#define fileNew 401
|
#define FILE_NEW 401
|
||||||
#define fileOpen 402
|
#define FILE_OPEN 402
|
||||||
#define fileClose 255
|
#define FILE_CLOSE 255
|
||||||
#define fileQuit 256
|
#define FILE_QUIT 256
|
||||||
|
|
||||||
#define appleAbout 301
|
#define APPLE_ABOUT 301
|
||||||
|
|
||||||
#define aboutAlertString 1
|
#define ABOUT_ALERT_STRING 1
|
||||||
|
|
||||||
#define windowRes 1001
|
#define WINDOW_RESID 1001
|
||||||
|
|
||||||
#define toolStartup 1
|
#define TOOL_STARTUP 1
|
||||||
|
|
||||||
|
|
||||||
#endif /* defined(_GUARD_PROJECT___PROJECTNAMEASIDENTIFIER____FILE___FILEBASENAMEASIDENTIFIER____) */
|
#endif /* defined(_GUARD_PROJECT___PROJECTNAMEASIDENTIFIER____FILE___FILEBASENAMEASIDENTIFIER____) */
|
||||||
|
|
|
@ -25,171 +25,171 @@ resource rVersion (1) {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
resource rMenuBar (menuBar) {
|
resource rMenuBar (MENU_BAR) {
|
||||||
{
|
{
|
||||||
appleMenu,
|
APPLE_MENU,
|
||||||
fileMenu,
|
FILE_MENU,
|
||||||
editMenu
|
EDIT_MENU
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
resource rMenu (appleMenu) {
|
resource rMenu (APPLE_MENU) {
|
||||||
appleMenu,
|
APPLE_MENU,
|
||||||
refIsResource * menuTitleRefShift
|
refIsResource * menuTitleRefShift
|
||||||
+ refIsResource * itemRefShift
|
+ refIsResource * itemRefShift
|
||||||
+ fAllowCache,
|
+ fAllowCache,
|
||||||
appleMenu,
|
APPLE_MENU,
|
||||||
{
|
{
|
||||||
appleAbout
|
APPLE_ABOUT
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
resource rMenu (fileMenu) {
|
resource rMenu (FILE_MENU) {
|
||||||
fileMenu,
|
FILE_MENU,
|
||||||
refIsResource * menuTitleRefShift
|
refIsResource * menuTitleRefShift
|
||||||
+ refIsResource * itemRefShift
|
+ refIsResource * itemRefShift
|
||||||
+ fAllowCache,
|
+ fAllowCache,
|
||||||
fileMenu,
|
FILE_MENU,
|
||||||
{
|
{
|
||||||
fileNew,
|
FILE_NEW,
|
||||||
fileOpen,
|
FILE_OPEN,
|
||||||
fileClose,
|
FILE_CLOSE,
|
||||||
fileQuit
|
FILE_QUIT
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
resource rMenu (editMenu) {
|
resource rMenu (EDIT_MENU) {
|
||||||
editMenu,
|
EDIT_MENU,
|
||||||
refIsResource * menuTitleRefShift
|
refIsResource * menuTitleRefShift
|
||||||
+ refIsResource * itemRefShift
|
+ refIsResource * itemRefShift
|
||||||
+ fAllowCache,
|
+ fAllowCache,
|
||||||
editMenu,
|
EDIT_MENU,
|
||||||
{
|
{
|
||||||
editUndo,
|
EDIT_UNDO,
|
||||||
editCut,
|
EDIT_CUT,
|
||||||
editCopy,
|
EDIT_COPY,
|
||||||
editPaste,
|
EDIT_PASTE,
|
||||||
editClear
|
EDIT_CLEAR
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
resource rMenuItem (editUndo) {
|
resource rMenuItem (EDIT_UNDO) {
|
||||||
editUndo,
|
EDIT_UNDO,
|
||||||
"Z", "z",
|
"Z", "z",
|
||||||
0,
|
0,
|
||||||
refIsResource * itemTitleRefShift
|
refIsResource * itemTitleRefShift
|
||||||
+ fDivider,
|
+ fDivider,
|
||||||
editUndo
|
EDIT_UNDO
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
resource rMenuItem (editCut) {
|
resource rMenuItem (EDIT_CUT) {
|
||||||
editCut,
|
EDIT_CUT,
|
||||||
"X", "x",
|
"X", "x",
|
||||||
0,
|
0,
|
||||||
refIsResource * itemTitleRefShift,
|
refIsResource * itemTitleRefShift,
|
||||||
editCut
|
EDIT_CUT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
resource rMenuItem (editCopy) {
|
resource rMenuItem (EDIT_COPY) {
|
||||||
editCopy,
|
EDIT_COPY,
|
||||||
"C", "c",
|
"C", "c",
|
||||||
0,
|
0,
|
||||||
refIsResource * itemTitleRefShift,
|
refIsResource * itemTitleRefShift,
|
||||||
editCopy
|
EDIT_COPY
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
resource rMenuItem (editPaste) {
|
resource rMenuItem (EDIT_PASTE) {
|
||||||
editPaste,
|
EDIT_PASTE,
|
||||||
"V", "v",
|
"V", "v",
|
||||||
0,
|
0,
|
||||||
refIsResource * itemTitleRefShift,
|
refIsResource * itemTitleRefShift,
|
||||||
editPaste
|
EDIT_PASTE
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
resource rMenuItem (editClear) {
|
resource rMenuItem (EDIT_CLEAR) {
|
||||||
editClear,
|
EDIT_CLEAR,
|
||||||
"", "",
|
"", "",
|
||||||
0,
|
0,
|
||||||
refIsResource * itemTitleRefShift,
|
refIsResource * itemTitleRefShift,
|
||||||
editClear
|
EDIT_CLEAR
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
resource rMenuItem (fileNew) {
|
resource rMenuItem (FILE_NEW) {
|
||||||
fileNew,
|
FILE_NEW,
|
||||||
"N", "n",
|
"N", "n",
|
||||||
0,
|
0,
|
||||||
refIsResource * itemTitleRefShift,
|
refIsResource * itemTitleRefShift,
|
||||||
fileNew
|
FILE_NEW
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
resource rMenuItem (fileOpen) {
|
resource rMenuItem (FILE_OPEN) {
|
||||||
fileOpen,
|
FILE_OPEN,
|
||||||
"O", "o",
|
"O", "o",
|
||||||
0,
|
0,
|
||||||
refIsResource * itemTitleRefShift
|
refIsResource * itemTitleRefShift
|
||||||
+ fDivider,
|
+ fDivider,
|
||||||
fileOpen
|
FILE_OPEN
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
resource rMenuItem (fileClose) {
|
resource rMenuItem (FILE_CLOSE) {
|
||||||
fileClose,
|
FILE_CLOSE,
|
||||||
"W", "w",
|
"W", "w",
|
||||||
0,
|
0,
|
||||||
refIsResource * itemTitleRefShift
|
refIsResource * itemTitleRefShift
|
||||||
+ fDivider,
|
+ fDivider,
|
||||||
fileClose
|
FILE_CLOSE
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
resource rMenuItem (fileQuit) {
|
resource rMenuItem (FILE_QUIT) {
|
||||||
fileQuit,
|
FILE_QUIT,
|
||||||
"Q", "q",
|
"Q", "q",
|
||||||
0,
|
0,
|
||||||
refIsResource * itemTitleRefShift,
|
refIsResource * itemTitleRefShift,
|
||||||
fileQuit
|
FILE_QUIT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
resource rMenuItem (appleAbout) {
|
resource rMenuItem (APPLE_ABOUT) {
|
||||||
appleAbout,
|
APPLE_ABOUT,
|
||||||
"", "",
|
"", "",
|
||||||
0,
|
0,
|
||||||
refIsResource * itemTitleRefShift
|
refIsResource * itemTitleRefShift
|
||||||
+ fDivider,
|
+ fDivider,
|
||||||
appleAbout
|
APPLE_ABOUT
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
resource rPString (appleMenu, noCrossBank) {"@"};
|
resource rPString (APPLE_MENU, noCrossBank) {"@"};
|
||||||
resource rPString (fileMenu, noCrossBank) {" File "};
|
resource rPString (FILE_MENU, noCrossBank) {" File "};
|
||||||
resource rPString (editMenu, noCrossBank) {" Edit "};
|
resource rPString (EDIT_MENU, noCrossBank) {" Edit "};
|
||||||
|
|
||||||
resource rPString (editUndo, noCrossBank) {"Undo"};
|
resource rPString (EDIT_UNDO, noCrossBank) {"Undo"};
|
||||||
resource rPString (editCut, noCrossBank) {"Cut"};
|
resource rPString (EDIT_CUT, noCrossBank) {"Cut"};
|
||||||
resource rPString (editCopy, noCrossBank) {"Copy"};
|
resource rPString (EDIT_COPY, noCrossBank) {"Copy"};
|
||||||
resource rPString (editPaste, noCrossBank) {"Paste"};
|
resource rPString (EDIT_PASTE, noCrossBank) {"Paste"};
|
||||||
resource rPString (editClear, noCrossBank) {"Clear"};
|
resource rPString (EDIT_CLEAR, noCrossBank) {"Clear"};
|
||||||
|
|
||||||
resource rPString (fileNew, noCrossBank) {"New"};
|
resource rPString (FILE_NEW, noCrossBank) {"New"};
|
||||||
resource rPString (fileOpen, noCrossBank) {"Open"};
|
resource rPString (FILE_OPEN, noCrossBank) {"Open"};
|
||||||
resource rPString (fileClose, noCrossBank) {"Close"};
|
resource rPString (FILE_CLOSE, noCrossBank) {"Close"};
|
||||||
resource rPString (fileQuit, noCrossBank) {"Quit"};
|
resource rPString (FILE_QUIT, noCrossBank) {"Quit"};
|
||||||
|
|
||||||
resource rPString (appleAbout, noCrossBank) {"About ___PROJECTNAME___..."};
|
resource rPString (APPLE_ABOUT, noCrossBank) {"About ___PROJECTNAME___..."};
|
||||||
|
|
||||||
|
|
||||||
resource rAlertString (aboutAlertString) {
|
resource rAlertString (ABOUT_ALERT_STRING) {
|
||||||
"0" /* Custom size */
|
"0" /* Custom size */
|
||||||
"\$38\$00" /* Upper Y coordinate at 56 */
|
"\$38\$00" /* Upper Y coordinate at 56 */
|
||||||
"\$90\$00" /* Left X coordinate at 144 */
|
"\$90\$00" /* Left X coordinate at 144 */
|
||||||
|
@ -207,7 +207,7 @@ resource rAlertString (aboutAlertString) {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
resource rWindParam1 (windowRes) {
|
resource rWindParam1 (WINDOW_RESID) {
|
||||||
$DDA5, /* wFrameBits */
|
$DDA5, /* wFrameBits */
|
||||||
nil, /* wTitle */
|
nil, /* wTitle */
|
||||||
0, /* wRefCon */
|
0, /* wRefCon */
|
||||||
|
@ -227,7 +227,7 @@ resource rWindParam1 (windowRes) {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
resource rToolStartup (toolStartup) {
|
resource rToolStartup (TOOL_STARTUP) {
|
||||||
mode640,
|
mode640,
|
||||||
{
|
{
|
||||||
3,$0100, /* Misc Tool */
|
3,$0100, /* Misc Tool */
|
||||||
|
|
Loading…
Reference in New Issue