home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / Libraries / VideoToolbox 95.04.18 / VideoToolboxSources / MaximizeConsoleHeight.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-26  |  5.1 KB  |  124 lines  |  [TEXT/MMCC]

  1. /*
  2. MaximizeConsoleHeight.c
  3. Both THINK C and Metrowerks CodeWarrior C provide a built-in console for stdin
  4. and stdout. That console is less useful than it might be because it opens to
  5. only a small size, presumably designed to fit on the tiny screen of a Mac Plus,
  6. i.e. the lowest common denominator, for portability. MaximizeConsoleHeight
  7. requests that the console open to the full height of your main screen. This
  8. makes good use of your screen, while maintaining the portability of your
  9. application. Call MaximizeConsoleHeight() BEFORE opening the console, i.e.
  10. before your first printf().
  11.  
  12. To set the WIDTH of the THINK C console, before opening it, do this:
  13.     #include <console.h>
  14.     ...
  15.     console_options.ncols=100;
  16.  
  17. To set the width of the CodeWarrior console, before opening it, do this:
  18.     #include <SIOUX.h>
  19.     ...
  20.     tSIOUXSettings.columns=100;
  21.  
  22. LIMITATION:
  23. In June 1994 Mike Garver reported that on a Mac Plus running System 6.07 with an
  24. attached big screen the console window appears on the Mac Plus screen, as it
  25. should, but extends well past the bottom, "so I could see none of the text
  26. unless I moved the window onto the large screen." This happens because, when
  27. Color QuickDraw is not available, MaximizeConsoleHeight() resorts to using the
  28. CrsrPin rect to estimate the height of the main screen. (CrsrPin is the
  29. rectangle to which the cursor is confined. When the desktop isn't rectangular
  30. CrsrPin is the smallest rectangle that contains the desktop.) I don't know how
  31. to fix this. If Color QuickDraw were running then the program would have
  32. correctly gotten the bounds of the main device, but the computer lacks Color
  33. QuickDraw, so there are no video device records, nor a GrayRgn structure to
  34. consult. Since MaximizeConsoleHeight() is typically called before QuickDraw is
  35. initialized we can't use qd.screenBits.bounds (which is probably the same as
  36. CrsrPin rect anyway). I can't think of any way for this program to find out the
  37. correct height of the main screen under these circumstances. So I blame this on
  38. the necessary cludge implicit in having two screens in a computer lacking Color
  39. QuickDraw, since 1-bit QuickDraw doesn't really support multiple screens. I
  40. believe, but didn't confirm, that System 7 provides 32-bit QuickDraw (which
  41. includes Color QuickDraw) on all computers.
  42.  
  43. HISTORY:
  44. 1/92    dgp wrote it.
  45. 8/27/92    dgp    check for 8-bit quickdraw before using GDevices.
  46. 10/10/92 dgp Reduced maximum console height by one pixel, so as not to clip 
  47.             displayed text.
  48. 2/22/93    dgp replaced GetMBarHeight() by MBarHeight.
  49. 4/16/93    dgp    enhanced to actively support 1-bit QD, rather than doing nothing.
  50. 6/3/94    dgp    replaced low-memory global MBarHeight by GetMBarHeight().
  51. 6/21/94 dgp documented limitation above.
  52. 6/28/94 dgp use gdRect instead of pixmap bounds, which is correct for any device,
  53. not just the main device.
  54. 10/10/94 dgp added support for Metrowerks CodeWarrior C.
  55. 11/17/94 dgp Eliminated need for THINK C's LoMem.h by defining LMGetCrsrPin().
  56. 1/7/95 dgp updated to CW5, so that it now works similarly for both THINK & CW C.
  57. */
  58.  
  59. #include "VideoToolbox.h"
  60. #if UNIVERSAL_HEADERS
  61.     #include <LowMem.h>
  62. #else
  63.     #define LMGetMBarHeight() (* (short *) 0x0BAA)
  64.     #define LMSetMBarHeight(MBarHeightValue) ((* (short *) 0x0BAA) = (MBarHeightValue))
  65. #endif
  66. // NOTE: Apple's Universal Headers fail to provide any access to CrsrPin, so I rolled my own.
  67. #define LMGetCrsrPin() (* (Rect *) 0x834)
  68. #if (THINK_C || THINK_CPLUS) || __MWERKS__
  69.     #include <console.h>
  70. #endif
  71. #if __MWERKS__
  72.     #include <SIOUX.h>
  73. #endif
  74.  
  75. void MaximizeConsoleHeight(void)
  76. {
  77.     long qD;
  78.     Rect r;
  79.     
  80.     Gestalt(gestaltQuickdrawVersion,&qD);
  81.     if(qD>=gestalt8BitQD) r=(*GetMainDevice())->gdRect;
  82.     else r=LMGetCrsrPin();    // Can't use qd.screenBits.bounds 'cause qd may not yet be inited.
  83.     #if (THINK_C || THINK_CPLUS)
  84.         console_options.top=LMGetMBarHeight()+19;    // allow for menu bar and title bar
  85.         console_options.left=1;
  86.         console_options.nrows=r.bottom-4-console_options.top;
  87.         console_options.nrows/=console_options.txSize*4/3-1; /* estimate line spacing */
  88.     #endif
  89.     #if __MWERKS__
  90.         SIOUXSettings.toppixel=LMGetMBarHeight()+19;    // allow for menu bar and title bar
  91.         SIOUXSettings.leftpixel=1;
  92.         SIOUXSettings.rows=r.bottom-4-SIOUXSettings.toppixel;
  93.         SIOUXSettings.rows/=SIOUXSettings.fontsize*4/3-1; /* estimate line spacing */
  94.  
  95.         // These settings approximate the behavior of the THINK C console.
  96.         SIOUXSettings.autocloseonquit=0;
  97.         SIOUXSettings.showstatusline=0;
  98.         SIOUXSettings.asktosaveonclose=0;
  99.     #endif
  100.     #if 0 && __MWERKS__
  101.         /*
  102.             This code probably fails under CW 5.5. The GetPort returns a window pointer
  103.             presumably corresponding to the console, 
  104.             but subsequent attempts to use that window pointer crash, e.g. in SetWTitle.
  105.             I reported the bug to Metrowerks.
  106.         */
  107.         Rect r;
  108.         GDHandle device;
  109.         WindowPtr window;
  110.     
  111.         printf("\n");
  112.         GetPort(&window);
  113.         device=GetWindowDevice(window);
  114.         if(device==NULL)return;
  115.         r=(**device).gdRect;
  116.         if(GetMainDevice()==device)r.top+=LMGetMBarHeight();
  117.         r.top+=19;        // allow for title bar
  118.         r.bottom-=1;    // allow for 1-pixel frame
  119.         r.left+=1;        // allow for 1-pixel frame
  120.         if(r.right-r.left>500)r.right=r.left+500;
  121.     //    SizeWindow(window,r.right-r.left,r.bottom-r.top,1);
  122.         MoveWindow(window,r.left,r.top,1);
  123.     #endif
  124. }