OSDN Git Service

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