sl@0
|
1 |
/*
|
sl@0
|
2 |
* tclMacPanic.c --
|
sl@0
|
3 |
*
|
sl@0
|
4 |
* Source code for the "Tcl_Panic" library procedure used in "Simple
|
sl@0
|
5 |
* Shell"; other Mac applications will probably call Tcl_SetPanicProc
|
sl@0
|
6 |
* to set a more robust application-specific panic procedure.
|
sl@0
|
7 |
*
|
sl@0
|
8 |
* Copyright (c) 1993-1994 Lockheed Missle & Space Company, AI Center
|
sl@0
|
9 |
* Copyright (c) 1995-1996 Sun Microsystems, Inc.
|
sl@0
|
10 |
*
|
sl@0
|
11 |
* See the file "license.terms" for information on usage and redistribution
|
sl@0
|
12 |
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* RCS: @(#) $Id: tclMacPanic.c,v 1.6 2001/11/23 01:28:08 das Exp $
|
sl@0
|
15 |
*/
|
sl@0
|
16 |
|
sl@0
|
17 |
|
sl@0
|
18 |
#include <Events.h>
|
sl@0
|
19 |
#include <Controls.h>
|
sl@0
|
20 |
#include <ControlDefinitions.h>
|
sl@0
|
21 |
#include <Windows.h>
|
sl@0
|
22 |
#include <TextEdit.h>
|
sl@0
|
23 |
#include <Fonts.h>
|
sl@0
|
24 |
#include <Dialogs.h>
|
sl@0
|
25 |
#include <Icons.h>
|
sl@0
|
26 |
#include <Sound.h>
|
sl@0
|
27 |
#include <stdarg.h>
|
sl@0
|
28 |
#include <stdio.h>
|
sl@0
|
29 |
#include <stdlib.h>
|
sl@0
|
30 |
|
sl@0
|
31 |
#include "tclInt.h"
|
sl@0
|
32 |
#include "tclMacInt.h"
|
sl@0
|
33 |
|
sl@0
|
34 |
/*
|
sl@0
|
35 |
* constants for panic dialog
|
sl@0
|
36 |
*/
|
sl@0
|
37 |
#define PANICHEIGHT 150 /* Height of dialog */
|
sl@0
|
38 |
#define PANICWIDTH 350 /* Width of dialog */
|
sl@0
|
39 |
#define PANIC_BUTTON_RECT {125, 260, 145, 335} /* Rect for button. */
|
sl@0
|
40 |
#define PANIC_ICON_RECT {10, 20, 42, 52} /* Rect for icon. */
|
sl@0
|
41 |
#define PANIC_TEXT_RECT {10, 65, 140, 330} /* Rect for text. */
|
sl@0
|
42 |
#define ENTERCODE (0x03)
|
sl@0
|
43 |
#define RETURNCODE (0x0D)
|
sl@0
|
44 |
|
sl@0
|
45 |
|
sl@0
|
46 |
/*
|
sl@0
|
47 |
*----------------------------------------------------------------------
|
sl@0
|
48 |
*
|
sl@0
|
49 |
* TclpPanic --
|
sl@0
|
50 |
*
|
sl@0
|
51 |
* Displays panic info, then aborts
|
sl@0
|
52 |
*
|
sl@0
|
53 |
* Results:
|
sl@0
|
54 |
* None.
|
sl@0
|
55 |
*
|
sl@0
|
56 |
* Side effects:
|
sl@0
|
57 |
* The process dies, entering the debugger if possible.
|
sl@0
|
58 |
*
|
sl@0
|
59 |
*----------------------------------------------------------------------
|
sl@0
|
60 |
*/
|
sl@0
|
61 |
|
sl@0
|
62 |
/* VARARGS ARGSUSED */
|
sl@0
|
63 |
void
|
sl@0
|
64 |
TclpPanic TCL_VARARGS_DEF(CONST char *, format)
|
sl@0
|
65 |
{
|
sl@0
|
66 |
va_list varg;
|
sl@0
|
67 |
char msg[256];
|
sl@0
|
68 |
WindowRef macWinPtr, foundWinPtr;
|
sl@0
|
69 |
Rect macRect;
|
sl@0
|
70 |
Rect buttonRect = PANIC_BUTTON_RECT;
|
sl@0
|
71 |
Rect iconRect = PANIC_ICON_RECT;
|
sl@0
|
72 |
Rect textRect = PANIC_TEXT_RECT;
|
sl@0
|
73 |
ControlHandle okButtonHandle;
|
sl@0
|
74 |
EventRecord event;
|
sl@0
|
75 |
Handle stopIconHandle;
|
sl@0
|
76 |
int part;
|
sl@0
|
77 |
Boolean done = false;
|
sl@0
|
78 |
|
sl@0
|
79 |
va_start(varg, format);
|
sl@0
|
80 |
vsprintf(msg, format, varg);
|
sl@0
|
81 |
va_end(varg);
|
sl@0
|
82 |
|
sl@0
|
83 |
/*
|
sl@0
|
84 |
* Put up an alert without using the Resource Manager (there may
|
sl@0
|
85 |
* be no resources to load). Use the Window and Control Managers instead.
|
sl@0
|
86 |
* We want the window centered on the main monitor. The following
|
sl@0
|
87 |
* should be tested with multiple monitors. Look and see if there is a way
|
sl@0
|
88 |
* not using qd.screenBits.
|
sl@0
|
89 |
*/
|
sl@0
|
90 |
|
sl@0
|
91 |
macRect.top = (qd.screenBits.bounds.top + qd.screenBits.bounds.bottom)
|
sl@0
|
92 |
/ 2 - (PANICHEIGHT / 2);
|
sl@0
|
93 |
macRect.bottom = (qd.screenBits.bounds.top + qd.screenBits.bounds.bottom)
|
sl@0
|
94 |
/ 2 + (PANICHEIGHT / 2);
|
sl@0
|
95 |
macRect.left = (qd.screenBits.bounds.left + qd.screenBits.bounds.right)
|
sl@0
|
96 |
/ 2 - (PANICWIDTH / 2);
|
sl@0
|
97 |
macRect.right = (qd.screenBits.bounds.left + qd.screenBits.bounds.right)
|
sl@0
|
98 |
/ 2 + (PANICWIDTH / 2);
|
sl@0
|
99 |
|
sl@0
|
100 |
macWinPtr = NewWindow(NULL, &macRect, "\p", true, dBoxProc, (WindowRef) -1,
|
sl@0
|
101 |
false, 0);
|
sl@0
|
102 |
if (macWinPtr == NULL) {
|
sl@0
|
103 |
goto exitNow;
|
sl@0
|
104 |
}
|
sl@0
|
105 |
|
sl@0
|
106 |
okButtonHandle = NewControl(macWinPtr, &buttonRect, "\pOK", true,
|
sl@0
|
107 |
0, 0, 1, pushButProc, 0);
|
sl@0
|
108 |
if (okButtonHandle == NULL) {
|
sl@0
|
109 |
CloseWindow(macWinPtr);
|
sl@0
|
110 |
goto exitNow;
|
sl@0
|
111 |
}
|
sl@0
|
112 |
|
sl@0
|
113 |
SelectWindow(macWinPtr);
|
sl@0
|
114 |
SetCursor(&qd.arrow);
|
sl@0
|
115 |
stopIconHandle = GetIcon(kStopIcon);
|
sl@0
|
116 |
|
sl@0
|
117 |
while (!done) {
|
sl@0
|
118 |
if (WaitNextEvent(mDownMask | keyDownMask | updateMask,
|
sl@0
|
119 |
&event, 0, NULL)) {
|
sl@0
|
120 |
switch(event.what) {
|
sl@0
|
121 |
case mouseDown:
|
sl@0
|
122 |
part = FindWindow(event.where, &foundWinPtr);
|
sl@0
|
123 |
|
sl@0
|
124 |
if ((foundWinPtr != macWinPtr) || (part != inContent)) {
|
sl@0
|
125 |
SysBeep(1);
|
sl@0
|
126 |
} else {
|
sl@0
|
127 |
SetPortWindowPort(macWinPtr);
|
sl@0
|
128 |
GlobalToLocal(&event.where);
|
sl@0
|
129 |
part = FindControl(event.where, macWinPtr,
|
sl@0
|
130 |
&okButtonHandle);
|
sl@0
|
131 |
|
sl@0
|
132 |
if ((kControlButtonPart == part) &&
|
sl@0
|
133 |
(TrackControl(okButtonHandle,
|
sl@0
|
134 |
event.where, NULL))) {
|
sl@0
|
135 |
done = true;
|
sl@0
|
136 |
}
|
sl@0
|
137 |
}
|
sl@0
|
138 |
break;
|
sl@0
|
139 |
case keyDown:
|
sl@0
|
140 |
switch (event.message & charCodeMask) {
|
sl@0
|
141 |
case ENTERCODE:
|
sl@0
|
142 |
case RETURNCODE:
|
sl@0
|
143 |
HiliteControl(okButtonHandle, 1);
|
sl@0
|
144 |
HiliteControl(okButtonHandle, 0);
|
sl@0
|
145 |
done = true;
|
sl@0
|
146 |
}
|
sl@0
|
147 |
break;
|
sl@0
|
148 |
case updateEvt:
|
sl@0
|
149 |
SetPortWindowPort(macWinPtr);
|
sl@0
|
150 |
TextFont(systemFont);
|
sl@0
|
151 |
|
sl@0
|
152 |
BeginUpdate(macWinPtr);
|
sl@0
|
153 |
if (stopIconHandle != NULL) {
|
sl@0
|
154 |
PlotIcon(&iconRect, stopIconHandle);
|
sl@0
|
155 |
}
|
sl@0
|
156 |
TETextBox(msg, strlen(msg), &textRect, teFlushDefault);
|
sl@0
|
157 |
DrawControls(macWinPtr);
|
sl@0
|
158 |
EndUpdate(macWinPtr);
|
sl@0
|
159 |
}
|
sl@0
|
160 |
}
|
sl@0
|
161 |
}
|
sl@0
|
162 |
|
sl@0
|
163 |
CloseWindow(macWinPtr);
|
sl@0
|
164 |
|
sl@0
|
165 |
exitNow:
|
sl@0
|
166 |
#ifdef TCL_DEBUG
|
sl@0
|
167 |
Debugger();
|
sl@0
|
168 |
#else
|
sl@0
|
169 |
abort();
|
sl@0
|
170 |
#endif
|
sl@0
|
171 |
}
|
sl@0
|
172 |
|