tclMacPanic.c
上传用户:rrhhcc
上传日期:2015-12-11
资源大小:54129k
文件大小:4k
源码类别:

通讯编程

开发平台:

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