sl@0: /* sl@0: * tclMacPanic.c -- sl@0: * sl@0: * Source code for the "Tcl_Panic" library procedure used in "Simple sl@0: * Shell"; other Mac applications will probably call Tcl_SetPanicProc sl@0: * to set a more robust application-specific panic procedure. sl@0: * sl@0: * Copyright (c) 1993-1994 Lockheed Missle & Space Company, AI Center sl@0: * Copyright (c) 1995-1996 Sun Microsystems, Inc. sl@0: * sl@0: * See the file "license.terms" for information on usage and redistribution sl@0: * of this file, and for a DISCLAIMER OF ALL WARRANTIES. sl@0: * sl@0: * RCS: @(#) $Id: tclMacPanic.c,v 1.6 2001/11/23 01:28:08 das Exp $ sl@0: */ sl@0: sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: #include "tclInt.h" sl@0: #include "tclMacInt.h" sl@0: sl@0: /* sl@0: * constants for panic dialog sl@0: */ sl@0: #define PANICHEIGHT 150 /* Height of dialog */ sl@0: #define PANICWIDTH 350 /* Width of dialog */ sl@0: #define PANIC_BUTTON_RECT {125, 260, 145, 335} /* Rect for button. */ sl@0: #define PANIC_ICON_RECT {10, 20, 42, 52} /* Rect for icon. */ sl@0: #define PANIC_TEXT_RECT {10, 65, 140, 330} /* Rect for text. */ sl@0: #define ENTERCODE (0x03) sl@0: #define RETURNCODE (0x0D) sl@0: sl@0: sl@0: /* sl@0: *---------------------------------------------------------------------- sl@0: * sl@0: * TclpPanic -- sl@0: * sl@0: * Displays panic info, then aborts sl@0: * sl@0: * Results: sl@0: * None. sl@0: * sl@0: * Side effects: sl@0: * The process dies, entering the debugger if possible. sl@0: * sl@0: *---------------------------------------------------------------------- sl@0: */ sl@0: sl@0: /* VARARGS ARGSUSED */ sl@0: void sl@0: TclpPanic TCL_VARARGS_DEF(CONST char *, format) sl@0: { sl@0: va_list varg; sl@0: char msg[256]; sl@0: WindowRef macWinPtr, foundWinPtr; sl@0: Rect macRect; sl@0: Rect buttonRect = PANIC_BUTTON_RECT; sl@0: Rect iconRect = PANIC_ICON_RECT; sl@0: Rect textRect = PANIC_TEXT_RECT; sl@0: ControlHandle okButtonHandle; sl@0: EventRecord event; sl@0: Handle stopIconHandle; sl@0: int part; sl@0: Boolean done = false; sl@0: sl@0: va_start(varg, format); sl@0: vsprintf(msg, format, varg); sl@0: va_end(varg); sl@0: sl@0: /* sl@0: * Put up an alert without using the Resource Manager (there may sl@0: * be no resources to load). Use the Window and Control Managers instead. sl@0: * We want the window centered on the main monitor. The following sl@0: * should be tested with multiple monitors. Look and see if there is a way sl@0: * not using qd.screenBits. sl@0: */ sl@0: sl@0: macRect.top = (qd.screenBits.bounds.top + qd.screenBits.bounds.bottom) sl@0: / 2 - (PANICHEIGHT / 2); sl@0: macRect.bottom = (qd.screenBits.bounds.top + qd.screenBits.bounds.bottom) sl@0: / 2 + (PANICHEIGHT / 2); sl@0: macRect.left = (qd.screenBits.bounds.left + qd.screenBits.bounds.right) sl@0: / 2 - (PANICWIDTH / 2); sl@0: macRect.right = (qd.screenBits.bounds.left + qd.screenBits.bounds.right) sl@0: / 2 + (PANICWIDTH / 2); sl@0: sl@0: macWinPtr = NewWindow(NULL, &macRect, "\p", true, dBoxProc, (WindowRef) -1, sl@0: false, 0); sl@0: if (macWinPtr == NULL) { sl@0: goto exitNow; sl@0: } sl@0: sl@0: okButtonHandle = NewControl(macWinPtr, &buttonRect, "\pOK", true, sl@0: 0, 0, 1, pushButProc, 0); sl@0: if (okButtonHandle == NULL) { sl@0: CloseWindow(macWinPtr); sl@0: goto exitNow; sl@0: } sl@0: sl@0: SelectWindow(macWinPtr); sl@0: SetCursor(&qd.arrow); sl@0: stopIconHandle = GetIcon(kStopIcon); sl@0: sl@0: while (!done) { sl@0: if (WaitNextEvent(mDownMask | keyDownMask | updateMask, sl@0: &event, 0, NULL)) { sl@0: switch(event.what) { sl@0: case mouseDown: sl@0: part = FindWindow(event.where, &foundWinPtr); sl@0: sl@0: if ((foundWinPtr != macWinPtr) || (part != inContent)) { sl@0: SysBeep(1); sl@0: } else { sl@0: SetPortWindowPort(macWinPtr); sl@0: GlobalToLocal(&event.where); sl@0: part = FindControl(event.where, macWinPtr, sl@0: &okButtonHandle); sl@0: sl@0: if ((kControlButtonPart == part) && sl@0: (TrackControl(okButtonHandle, sl@0: event.where, NULL))) { sl@0: done = true; sl@0: } sl@0: } sl@0: break; sl@0: case keyDown: sl@0: switch (event.message & charCodeMask) { sl@0: case ENTERCODE: sl@0: case RETURNCODE: sl@0: HiliteControl(okButtonHandle, 1); sl@0: HiliteControl(okButtonHandle, 0); sl@0: done = true; sl@0: } sl@0: break; sl@0: case updateEvt: sl@0: SetPortWindowPort(macWinPtr); sl@0: TextFont(systemFont); sl@0: sl@0: BeginUpdate(macWinPtr); sl@0: if (stopIconHandle != NULL) { sl@0: PlotIcon(&iconRect, stopIconHandle); sl@0: } sl@0: TETextBox(msg, strlen(msg), &textRect, teFlushDefault); sl@0: DrawControls(macWinPtr); sl@0: EndUpdate(macWinPtr); sl@0: } sl@0: } sl@0: } sl@0: sl@0: CloseWindow(macWinPtr); sl@0: sl@0: exitNow: sl@0: #ifdef TCL_DEBUG sl@0: Debugger(); sl@0: #else sl@0: abort(); sl@0: #endif sl@0: } sl@0: