OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [tcl/] [mac/] [tclMacPanic.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
/*
2
 * tclMacPanic.c --
3
 *
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.
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: tclMacPanic.c,v 1.1.1.1 2002-01-16 10:25:30 markom Exp $
15
 */
16
 
17
 
18
#include <Events.h>
19
#include <Controls.h>
20
#include <Windows.h>
21
#include <TextEdit.h>
22
#include <Fonts.h>
23
#include <Dialogs.h>
24
#include <Icons.h>
25
#include <Sound.h>
26
#include <stdarg.h>
27
#include <stdio.h>
28
#include <stdlib.h>
29
 
30
#include "tclInt.h"
31
 
32
/*
33
 * constants for panic dialog
34
 */
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)
42
 
43
/*
44
 * The panicProc variable contains a pointer to an application
45
 * specific panic procedure.
46
 */
47
 
48
void (*panicProc) _ANSI_ARGS_(TCL_VARARGS(char *,format)) = NULL;
49
 
50
/*
51
 *----------------------------------------------------------------------
52
 *
53
 * Tcl_SetPanicProc --
54
 *
55
 *      Replace the default panic behavior with the specified functiion.
56
 *
57
 * Results:
58
 *      None.
59
 *
60
 * Side effects:
61
 *      Sets the panicProc variable.
62
 *
63
 *----------------------------------------------------------------------
64
 */
65
 
66
void
67
Tcl_SetPanicProc(proc)
68
    void (*proc) _ANSI_ARGS_(TCL_VARARGS(char *,format));
69
{
70
    panicProc = proc;
71
}
72
 
73
/*
74
 *----------------------------------------------------------------------
75
 *
76
 * MacPanic --
77
 *
78
 *      Displays panic info..
79
 *
80
 * Results:
81
 *      None.
82
 *
83
 * Side effects:
84
 *      Sets the panicProc variable.
85
 *
86
 *----------------------------------------------------------------------
87
 */
88
 
89
static void
90
MacPanic(
91
    char *msg)          /* Text to show in panic dialog. */
92
{
93
    WindowRef macWinPtr, foundWinPtr;
94
    Rect macRect;
95
    Rect buttonRect = PANIC_BUTTON_RECT;
96
    Rect iconRect = PANIC_ICON_RECT;
97
    Rect textRect = PANIC_TEXT_RECT;
98
    ControlHandle okButtonHandle;
99
    EventRecord event;
100
    Handle stopIconHandle;
101
    int part;
102
    Boolean done = false;
103
 
104
 
105
    /*
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.
111
     */
112
 
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);
121
 
122
    macWinPtr = NewWindow(NULL, &macRect, "\p", true, dBoxProc, (WindowRef) -1,
123
            false, 0);
124
    if (macWinPtr == NULL) {
125
        goto exitNow;
126
    }
127
 
128
    okButtonHandle = NewControl(macWinPtr, &buttonRect, "\pOK", true,
129
            0, 0, 1, pushButProc, 0);
130
    if (okButtonHandle == NULL) {
131
        CloseWindow(macWinPtr);
132
        goto exitNow;
133
    }
134
 
135
    SelectWindow(macWinPtr);
136
    SetCursor(&qd.arrow);
137
    stopIconHandle = GetIcon(kStopIcon);
138
 
139
    while (!done) {
140
        if (WaitNextEvent(mDownMask | keyDownMask | updateMask,
141
                &event, 0, NULL)) {
142
            switch(event.what) {
143
                case mouseDown:
144
                    part = FindWindow(event.where, &foundWinPtr);
145
 
146
                    if ((foundWinPtr != macWinPtr) || (part != inContent)) {
147
                        SysBeep(1);
148
                    } else {
149
                        SetPortWindowPort(macWinPtr);
150
                        GlobalToLocal(&event.where);
151
                        part = FindControl(event.where, macWinPtr,
152
                                &okButtonHandle);
153
 
154
                        if ((inButton == part) &&
155
                                (TrackControl(okButtonHandle,
156
                                        event.where, NULL))) {
157
                            done = true;
158
                        }
159
                    }
160
                    break;
161
                case keyDown:
162
                    switch (event.message & charCodeMask) {
163
                        case ENTERCODE:
164
                        case RETURNCODE:
165
                            HiliteControl(okButtonHandle, 1);
166
                            HiliteControl(okButtonHandle, 0);
167
                            done = true;
168
                    }
169
                    break;
170
                case updateEvt:
171
                    SetPortWindowPort(macWinPtr);
172
                    TextFont(systemFont);
173
 
174
                    BeginUpdate(macWinPtr);
175
                    if (stopIconHandle != NULL) {
176
                        PlotIcon(&iconRect, stopIconHandle);
177
                    }
178
                    TextBox(msg, strlen(msg), &textRect, teFlushDefault);
179
                    DrawControls(macWinPtr);
180
                    EndUpdate(macWinPtr);
181
            }
182
        }
183
    }
184
 
185
    CloseWindow(macWinPtr);
186
 
187
  exitNow:
188
#ifdef TCL_DEBUG
189
    Debugger();
190
#else
191
    abort();
192
#endif
193
}
194
 
195
/*
196
 *----------------------------------------------------------------------
197
 *
198
 * panic --
199
 *
200
 *      Print an error message and kill the process.
201
 *
202
 * Results:
203
 *      None.
204
 *
205
 * Side effects:
206
 *      The process dies, entering the debugger if possible.
207
 *
208
 *----------------------------------------------------------------------
209
 */
210
 
211
#pragma ignore_oldstyle on
212
void
213
panic(char * format, ...)
214
{
215
    va_list varg;
216
    char errorText[256];
217
 
218
    if (panicProc != NULL) {
219
        va_start(varg, format);
220
 
221
        (void) (*panicProc)(format, varg);
222
 
223
        va_end(varg);
224
    } else {
225
        va_start(varg, format);
226
 
227
        vsprintf(errorText, format, varg);
228
 
229
        va_end(varg);
230
 
231
        MacPanic(errorText);
232
    }
233
 
234
}
235
#pragma ignore_oldstyle reset

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.