4 * Source code for the "panic" library procedure used in "Simple Shell";
5 * other Mac applications will probably override this with a more robust
6 * application-specific panic procedure.
8 * Copyright (c) 1993-1994 Lockheed Missle & Space Company, AI Center
9 * Copyright (c) 1995-1996 Sun Microsystems, Inc.
11 * See the file "license.terms" for information on usage and redistribution
12 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
33 * constants for panic dialog
35 #define PANICHEIGHT 150 /* Height of dialog */
36 #define PANICWIDTH 350 /* Width of dialog */
37 #define PANIC_BUTTON_RECT {125, 260, 145, 335} /* Rect for button. */
38 #define PANIC_ICON_RECT {10, 20, 42, 52} /* Rect for icon. */
39 #define PANIC_TEXT_RECT {10, 65, 140, 330} /* Rect for text. */
40 #define ENTERCODE (0x03)
41 #define RETURNCODE (0x0D)
44 * The panicProc variable contains a pointer to an application
45 * specific panic procedure.
48 void (*panicProc) _ANSI_ARGS_(TCL_VARARGS(char *,format)) = NULL;
51 *----------------------------------------------------------------------
55 * Replace the default panic behavior with the specified functiion.
61 * Sets the panicProc variable.
63 *----------------------------------------------------------------------
67 Tcl_SetPanicProc(proc)
68 void (*proc) _ANSI_ARGS_(TCL_VARARGS(char *,format));
74 *----------------------------------------------------------------------
78 * Displays panic info..
84 * Sets the panicProc variable.
86 *----------------------------------------------------------------------
91 char *msg) /* Text to show in panic dialog. */
93 WindowRef macWinPtr, foundWinPtr;
95 Rect buttonRect = PANIC_BUTTON_RECT;
96 Rect iconRect = PANIC_ICON_RECT;
97 Rect textRect = PANIC_TEXT_RECT;
98 ControlHandle okButtonHandle;
100 Handle stopIconHandle;
102 Boolean done = false;
106 * Put up an alert without using the Resource Manager (there may
107 * be no resources to load). Use the Window and Control Managers instead.
108 * We want the window centered on the main monitor. The following
109 * should be tested with multiple monitors. Look and see if there is a way
110 * not using qd.screenBits.
113 macRect.top = (qd.screenBits.bounds.top + qd.screenBits.bounds.bottom)
114 / 2 - (PANICHEIGHT / 2);
115 macRect.bottom = (qd.screenBits.bounds.top + qd.screenBits.bounds.bottom)
116 / 2 + (PANICHEIGHT / 2);
117 macRect.left = (qd.screenBits.bounds.left + qd.screenBits.bounds.right)
118 / 2 - (PANICWIDTH / 2);
119 macRect.right = (qd.screenBits.bounds.left + qd.screenBits.bounds.right)
120 / 2 + (PANICWIDTH / 2);
122 macWinPtr = NewWindow(NULL, &macRect, "\p", true, dBoxProc, (WindowRef) -1,
124 if (macWinPtr == NULL) {
128 okButtonHandle = NewControl(macWinPtr, &buttonRect, "\pOK", true,
129 0, 0, 1, pushButProc, 0);
130 if (okButtonHandle == NULL) {
131 CloseWindow(macWinPtr);
135 SelectWindow(macWinPtr);
136 SetCursor(&qd.arrow);
137 stopIconHandle = GetIcon(kStopIcon);
140 if (WaitNextEvent(mDownMask | keyDownMask | updateMask,
144 part = FindWindow(event.where, &foundWinPtr);
146 if ((foundWinPtr != macWinPtr) || (part != inContent)) {
149 SetPortWindowPort(macWinPtr);
150 GlobalToLocal(&event.where);
151 part = FindControl(event.where, macWinPtr,
154 if ((inButton == part) &&
155 (TrackControl(okButtonHandle,
156 event.where, NULL))) {
162 switch (event.message & charCodeMask) {
165 HiliteControl(okButtonHandle, 1);
166 HiliteControl(okButtonHandle, 0);
171 SetPortWindowPort(macWinPtr);
172 TextFont(systemFont);
174 BeginUpdate(macWinPtr);
175 if (stopIconHandle != NULL) {
176 PlotIcon(&iconRect, stopIconHandle);
178 TextBox(msg, strlen(msg), &textRect, teFlushDefault);
179 DrawControls(macWinPtr);
180 EndUpdate(macWinPtr);
185 CloseWindow(macWinPtr);
196 *----------------------------------------------------------------------
200 * Print an error message and kill the process.
206 * The process dies, entering the debugger if possible.
208 *----------------------------------------------------------------------
211 #pragma ignore_oldstyle on
213 panic(char * format, ...)
218 if (panicProc != NULL) {
219 va_start(varg, format);
221 (void) (*panicProc)(format, varg);
225 va_start(varg, format);
227 vsprintf(errorText, format, varg);
235 #pragma ignore_oldstyle reset