home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 November / macformat-018.iso / Utility Spectacular / Developer / macgambit-20-compiler-src-p1 / Runtime (.c & .h) / os_mac_eStyle.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-26  |  21.7 KB  |  772 lines  |  [TEXT/KAHL]

  1. /* os_mac_eStyle.c
  2.  * 2Jun92  e
  3.  */
  4.  
  5. #include <Dialogs.h>
  6. #include <Controls.h>
  7. #include <QuickDraw.h>
  8. #include <Windows.h>
  9. #include <ToolUtils.h>
  10. #include <OSUtils.h>
  11. #include <Menus.h>
  12. #include <Fonts.h>
  13. #include <resources.h>
  14.  
  15. #include "os_mac.h"
  16.  
  17. /* extensions to an editor for text files by e
  18.    questions/comments via Internet <e@Flavors.COM>
  19. */
  20. /* Copyright © e 1992. All rights reserved.
  21.     Developed using THINK C 5.0.1 for use with Gambit Scheme.
  22.     This code may be freely distributed as long as this notice remains.
  23. */
  24.  
  25. /* to do:
  26. 06Jun92  e
  27. consider checkbox to modify OK to:
  28. - Set Style for All Windows
  29. consider showing text in style
  30. - (let ((the 3) (quick 5) (brown 7)) (fox jumps over the lazy dog))
  31. - ((lambda (the quick brown) (fox jumps over (the lazy) dog)) 3 5 7)
  32. consider a way to save Window's style in the file
  33. consider a way to save Creation style (preferences)
  34. add a Use Outline Fonts checkbox
  35. */
  36.  
  37. #define MAXFONTSIZE 1023
  38.  
  39. /* resources */
  40.  
  41. #define esdID        357
  42.  
  43. /* dialog items */
  44.  
  45. #define esdOK         1
  46. #define esdCancel     2
  47. #define esdTabsEt     3
  48. #define esdTabsSt     4
  49. #define esdFont1St     5
  50. #define esdFont1Pu     6
  51. #define esdSize1St     7
  52. #define esdSize1Et     8
  53. #define esdBold1Cb     9
  54. #define esdItal1Cb    10
  55. #define esdCond1Cb    11
  56. #define esdUndr1Cb    12
  57. #define esdInvr1Cb    13
  58. #define esdExpd1Cb    14
  59. #define esdFont2St    15
  60. #define esdFont2Pu    16
  61. #define esdSize2St    17
  62. #define esdSize2Et    18
  63. #define esdBold2Cb    19
  64. #define esdItal2Cb    20
  65. #define esdCond2Cb    21
  66. #define esdUndr2Cb    22
  67. #define esdInvr2Cb    23
  68. #define esdExpd2Cb    24
  69. #define esdPS1St    25
  70. #define esdPS2St    26
  71. #define esdSize1Pu    27
  72. #define esdSize2Pu    28
  73. #define esdOutline1    29
  74. #define esdOutline2    30
  75. #define esdOKring    31
  76. #define esdThisBt    32
  77. #define esdPrefBt    33
  78. #define esdDfltBt    34
  79. #define esdGetSt    35
  80. #define esdOutline3    36
  81. #define esdApplSt    37
  82. #define esdThisCb    38
  83. #define esdPrefCb    39
  84. #define esdWrapEt    40
  85. #define esdAutoInd    42
  86.  
  87. /* the pop-up font item */
  88.  
  89. /* See: Apple Macintosh Developer Technical Support
  90.         Pop-up Menu Example Application
  91.         PopMenus.p
  92. */
  93.  
  94. static TextStyle tsNewPri, tsNewAlt;
  95. static short tabsNew;
  96. static short wrapNew;
  97. static short autoIndNew;
  98.  
  99. #define popMenuID1 128
  100. static MenuHandle popMenu1;
  101. static Rect  popUpBox1;        /* boundsrect of font popUp1 */
  102. static Rect  promptBox1;    /* boundsrect of its title */
  103. static short fontChoice1;    /* its last chosen item */
  104.  
  105. #define popMenuID2 129
  106. static MenuHandle popMenu2;
  107. static Rect  popUpBox2;        /* boundsrect of font popUp2 */
  108. static Rect  promptBox2;    /* boundsrect of its title */
  109. static short fontChoice2;    /* its last chosen item */
  110.  
  111. #define popMenuID3 130
  112. static MenuHandle popMenu3;
  113. static Rect  popUpBox3;        /* boundsrect of font popUp2 */
  114. static short sizeChoice3;    /* its last chosen item */
  115.  
  116. #define popMenuID4 131
  117. static MenuHandle popMenu4;
  118. static Rect  popUpBox4;        /* boundsrect of font popUp2 */
  119. static short sizeChoice4;    /* its last chosen item */
  120.  
  121. /* some user item action procs -- used in update events mostly */
  122.  
  123. #define leftSlop 15
  124. #define rightSlop 17
  125. #define botSlop 5
  126.  
  127. static void drawPopArrow( Rect r )
  128.   FrameRect( &r );
  129.   MoveTo( r.right, r.top+2 );
  130.   LineTo( r.right, r.bottom );
  131.   LineTo( r.left+2, r.bottom );
  132.   MoveTo( r.right-17, r.top+6 );
  133.   Line( 11, 0 );
  134.   Move( -10, 1 );
  135.   Line( 9, 0 );
  136.   Move( -8, 1);
  137.   Line( 7, 0 );
  138.   Move( -6, 1);
  139.   Line( 5, 0 );
  140.   Move( -4, 1 );
  141.   Line( 3, 0 );
  142.   Move( -2, 1 );
  143.   Line( 1, 0 );
  144. }
  145.  
  146. static pascal void DrawPopUpSz( DialogPtr dwind, short dinum )
  147. { short itemtype;
  148.   Handle itemhandle;
  149.   Rect r;
  150.   GetDItem( dwind, dinum, &itemtype, &itemhandle, &r );
  151.   InsetRect( &r, -1, -1 );
  152.   drawPopArrow( r );
  153. }
  154.  
  155. static void DrawPopUpX( MenuHandle popMenu, Rect* popUpBox, short lastChoice )
  156. { Rect r;
  157.   Str255 curFont;
  158.   short newWid, newLen, wid;
  159.  
  160.   GetItem( popMenu, lastChoice, curFont ); /* get currently-selected item */
  161.   r = *popUpBox;
  162.   EraseRect( &r );
  163.   InsetRect( &r, -1, -1 );
  164.   /* Make sure the title fits. Truncate it and add an ellipses (“…”) otherwise */
  165.   wid = (r.right - r.left) - (leftSlop + rightSlop);
  166.   newWid = StringWidth( curFont );
  167.   if( newWid > wid )
  168.   { newLen = curFont[0]; /* current length in characters */
  169.     wid = wid - CharWidth('…');
  170.     do
  171.     { newWid = newWid - CharWidth( curFont[newLen--] );
  172.     } while( ( newWid > wid ) && ( newLen > 0 ) );
  173.     curFont[++newLen] = '…';
  174.     curFont[0] = newLen;
  175.   }
  176.   drawPopArrow( r );
  177.   MoveTo( r.left+leftSlop, r.bottom-botSlop);
  178.   DrawString( curFont );
  179. }
  180.  
  181. static pascal void DrawPopUp1( DialogPtr theDialog, short theItem )
  182. { DrawPopUpX( popMenu1, &popUpBox1, fontChoice1 );
  183. }
  184.  
  185. static pascal void DrawPopUp2( DialogPtr theDialog, short theItem )
  186. { DrawPopUpX( popMenu2, &popUpBox2, fontChoice2 );
  187. }
  188.  
  189. /* BorderDefault draws a heavy border around the default ( OK ) button */
  190. static pascal void BorderDefault( WindowPtr dwind, short dinum )
  191. { short itemtype;
  192.   Handle itemhandle;
  193.   Rect borderRect;
  194.   GetDItem( dwind, esdOK, &itemtype, &itemhandle, &borderRect );
  195.   InsetRect( &borderRect, -4, -4 );
  196.   PenSize( 3, 3 );
  197.   FrameRoundRect( &borderRect, 16, 16 );
  198.   PenSize( 1, 1 );
  199. }
  200.  
  201. /* Outliner draws a light border around the the user item */
  202. static pascal void Outliner( WindowPtr dwind, short dinum )
  203. { short itemtype;
  204.   Handle itemhandle;
  205.   Rect borderRect;
  206.   GetDItem( dwind, dinum, &itemtype, &itemhandle, &borderRect );
  207.   /* InsetRect( &borderRect, -4, -4 ); */
  208.   PenSize( 1, 1 );
  209.   FrameRoundRect( &borderRect, 16, 16 );
  210. }
  211.  
  212. /* util fcns. */
  213.  
  214. /* cursor to IBeam if it's over an active edit line, arrow if it's not */
  215. void IBeamIt( WindowPtr dwind )
  216. { Point mouseAt;
  217.   short itemtype;
  218.   Handle itemhandle;
  219.   Rect borderRect;
  220.   short itemNum;
  221.   /* first get the current edit line out of the dialog record */
  222.   itemNum = ((DialogPeek )dwind)->editField + 1; /* always stored 1 less */
  223.   GetDItem( dwind, itemNum, &itemtype, &itemhandle, &borderRect );
  224.   GetMouse( &mouseAt );
  225.   if( PtInRect( mouseAt, &borderRect ) )
  226.     SetCursor(&ibeam_cursor);
  227.   else
  228.     SetCursor(&arrow);
  229. }
  230.  
  231. static void pseudoClick( DialogPtr dbox, short item )
  232. { short itemtype;
  233.   Rect itemrect;
  234.   Handle hC;
  235.   long tilticks;
  236.   GetDItem( dbox, item, &itemtype, &hC, &itemrect );
  237.   HiliteControl( (ControlHandle)hC, inButton );
  238.   Delay( 8, &tilticks );
  239.   HiliteControl( (ControlHandle)hC, false );
  240. }
  241.  
  242. static short apndMenu( MenuHandle hM, Str255 title, short itemno, Boolean check, Boolean realfont )
  243. {
  244.   AppendMenu( hM, title );
  245.   if( realfont ) SetItemStyle( hM, itemno, outline );
  246.   if( check )
  247.   { SetItemMark( hM, itemno, checkMark );
  248.     return itemno;
  249.   }
  250.   return 0;
  251. }
  252.  
  253. static MenuHandle sizeMenu( short id, short *ckitem, short fNum, short curSize )
  254. { MenuHandle hM;
  255.   Str255 oddSize;
  256.   short match = 0;
  257.   hM = NewMenu( id, "" );
  258.   match |= apndMenu( hM,  "\p9", 1, (curSize ==  9), RealFont( fNum,  9 ) );
  259.   match |= apndMenu( hM, "\p10", 2, (curSize == 10), RealFont( fNum, 10 ) );
  260.   match |= apndMenu( hM, "\p12", 3, (curSize == 12), RealFont( fNum, 12 ) );
  261.   match |= apndMenu( hM, "\p14", 4, (curSize == 14), RealFont( fNum, 14 ) );
  262.   match |= apndMenu( hM, "\p18", 5, (curSize == 18), RealFont( fNum, 18 ) );
  263.   match |= apndMenu( hM, "\p24", 6, (curSize == 24), RealFont( fNum, 24 ) );
  264.   if( match == 0 )
  265.   { NumToString( (long )curSize, oddSize );
  266.     InsMenuItem( hM, oddSize, 0 );
  267.     InsMenuItem( hM, "\p(-", 1 );
  268.     SetItemMark( hM, 1, checkMark );
  269.     if( RealFont( fNum, curSize ) ) SetItemStyle( hM, 1, outline );
  270.     *ckitem = 1;
  271.   }
  272.   else *ckitem = match;
  273.   return( hM );
  274. }
  275.  
  276. static short doPop( DialogPtr esd, MenuHandle popMenu, Rect popUpBox, short id, short oldChoice )
  277. { long chosen;
  278.   Point popLoc;
  279.   short newChoice;
  280.   InsertMenu( popMenu, -1 );
  281.   popLoc = topLeft(popUpBox);
  282.   LocalToGlobal( &popLoc );
  283.   CalcMenuSize( popMenu ); /* Work around Menu Mgr bug */
  284.   chosen = PopUpMenuSelect( popMenu, popLoc.v, popLoc.h, oldChoice );
  285.   DeleteMenu( id );
  286.   if( chosen != 0 )
  287.   { newChoice = LoWord(chosen);
  288.     if( newChoice != oldChoice )
  289.     { SetItemMark( popMenu, oldChoice, ' ' );
  290.       SetItemMark( popMenu, newChoice, checkMark );
  291.       EraseRect( &popUpBox );
  292.       return( newChoice );
  293.     }
  294.   }
  295.   return 0;
  296. }
  297.  
  298. /* filter proc */
  299.  
  300. #define kReturnKey 0x0D
  301. #define kEnterKey 0x03
  302. #define kEscKey 0x1B
  303. #define kTabKey 9
  304. enum  {
  305.     kBackSpace = 8,
  306.     kLeftArrow = 0x1C, kRightArrow, kUpArrow, kDownArrow,
  307.     kDeleteKey = 0x7F
  308. };
  309.  
  310. /* size menu selection => edit text box */
  311. static void doSize1( DialogPtr esd )
  312. { Rect tempRect;
  313.   short tempItem;
  314.   Handle tempHandle;
  315.   long tmp;
  316.   Str255 tStr;
  317.   GetDItem( esd, esdSize1Et, &tempItem, &tempHandle, &tempRect );
  318.   GetItem( popMenu3, sizeChoice3, tStr );
  319.   SetIText( tempHandle, tStr );
  320.   SelIText( esd, esdSize1Et, 0, 32767 );
  321.   StringToNum( tStr, &tmp);
  322.   tsNewPri.tsSize = tmp;
  323. }
  324.  
  325. /* size menu selection => edit text box */
  326. static void doSize2( DialogPtr esd )
  327. { Rect tempRect;
  328.   short tempItem;
  329.   Handle tempHandle;
  330.   long tmp;
  331.   Str255 tStr;
  332.   GetDItem( esd, esdSize2Et, &tempItem, &tempHandle, &tempRect );
  333.   GetItem( popMenu4, sizeChoice4, tStr );
  334.   SetIText( tempHandle, tStr );
  335.   SelIText( esd, esdSize2Et, 0, 32767 );
  336.   StringToNum( tStr, &tmp);
  337.   tsNewAlt.tsSize = tmp;
  338. }
  339.  
  340. /* font menu selection triggers update of size menu */
  341. static void doFont1( void )
  342. { Str255 tStr;
  343.   GetItem( popMenu1, fontChoice1, tStr );
  344.   GetFNum( tStr, &tsNewPri.tsFont );
  345.   if( popMenu3 ) DisposHandle( popMenu3 );
  346.   popMenu3 = sizeMenu( popMenuID3, &sizeChoice3, tsNewPri.tsFont, tsNewPri.tsSize );
  347. }
  348.  
  349. /* font menu selection triggers update of size menu */
  350. static void doFont2( void )
  351. { Str255 tStr;
  352.   GetItem( popMenu2, fontChoice2, tStr );
  353.   GetFNum( tStr, &tsNewAlt.tsFont );
  354.   if( popMenu4 ) DisposHandle( popMenu4 );
  355.   popMenu4 = sizeMenu( popMenuID4, &sizeChoice4, tsNewAlt.tsFont, tsNewAlt.tsSize );
  356. }
  357.  
  358. /* this function always returns a value between 1 and MAXFONTSIZE inclusive */
  359. /* an out of range number returns 8;
  360.    this is so font sizes and tab stops are reasonable */
  361. static long etToNum( DialogPtr dbox, short item )
  362. { short tempItem;
  363.   Rect tempRect;
  364.   Handle tempHandle;
  365.   long tmp;
  366.   Str255 tStr;
  367.   GetDItem( dbox, item, &tempItem, &tempHandle, &tempRect );
  368.   GetIText( tempHandle, tStr );
  369.   StringToNum( tStr, &tmp);
  370.   if( tmp > MAXFONTSIZE || tmp < 1 ) tmp = 8;
  371.   return tmp;
  372. }
  373.  
  374. /* update size menu if size edit text box changed */
  375. static void preSize1( DialogPtr esd )
  376. { long tmp;
  377.   tmp = etToNum( esd, esdSize1Et );
  378.   if( tsNewPri.tsSize != tmp )
  379.   { tsNewPri.tsSize = tmp;
  380.     if( popMenu3 ) DisposHandle( popMenu3 );
  381.     popMenu3 = sizeMenu( popMenuID3, &sizeChoice3, tsNewPri.tsFont, tsNewPri.tsSize );
  382.   }
  383. }
  384.  
  385. /* update size menu if size edit text box changed */
  386. static void preSize2( DialogPtr esd )
  387. { long tmp;
  388.   tmp = etToNum( esd, esdSize2Et );
  389.   if( tsNewAlt.tsSize != tmp )
  390.   { tsNewAlt.tsSize = tmp;
  391.     if( popMenu4 ) DisposHandle( popMenu4 );
  392.     popMenu4 = sizeMenu( popMenuID4, &sizeChoice4, tsNewAlt.tsFont, tsNewAlt.tsSize );
  393.   }
  394. }
  395.  
  396. pascal Boolean filterIt( DialogPtr esd, EventRecord *myDialogEvent, short *theDialogItem)
  397. { WindowPtr temp;
  398.   char theKey;
  399.   Rect tempRect;
  400.   short tempItem;
  401.   Handle tempHandle;
  402.   Boolean result = false;
  403.  
  404.   GetPort( &temp );
  405.   SetPort( esd );
  406.     
  407.   IBeamIt( esd ); /* make IBeam cursor when over the active edit line */
  408.     
  409.   /* do standard filtering for escape and return as OK and Cancel aliases */
  410.   /* invert the button in the dialog, so the user get's visual feedback */
  411.  
  412.   if ((myDialogEvent->what == keyDown) || (myDialogEvent->what == autoKey))
  413.   { theKey = myDialogEvent->message & charCodeMask;
  414.     if( (myDialogEvent->modifiers & (cmdKey|controlKey|optionKey)) == 0 )
  415.     { switch( theKey )
  416.       { case kReturnKey:
  417.         case kEnterKey:
  418.             *theDialogItem = esdOK;
  419.             pseudoClick( esd, esdOK );
  420.           SetPort(temp);
  421.           result = true;
  422.           break;
  423.         case kEscKey:
  424.           *theDialogItem = esdCancel;
  425.           pseudoClick( esd, esdCancel );
  426.           SetPort(temp);
  427.           result = true;
  428.           break;
  429.         case kTabKey:
  430.         case kBackSpace:
  431.         case kLeftArrow:
  432.         case kRightArrow:
  433.         case kUpArrow:
  434.         case kDownArrow:
  435.         case kDeleteKey:
  436.             break;
  437.         default:
  438.           /* filter out non-numeric keys */
  439.           if( theKey < 0x30 || theKey > 0x39 )
  440.           { SysBeep( 1 );
  441.             SetPort( temp );
  442.             result = true;
  443.           }
  444.           break;
  445.       }
  446.     }
  447.   }
  448.   else if( myDialogEvent->what == mouseDown )
  449.   { Point mouseLoc;
  450.     short newChoice;
  451.     mouseLoc = ( myDialogEvent->where );
  452.     GlobalToLocal( &mouseLoc );
  453.     switch( newChoice = FindDItem( esd, mouseLoc ) + 1 )
  454.     { case esdFont1St:
  455.       case esdFont1Pu:
  456.         InvertRect( &promptBox1 );
  457.         newChoice = doPop( esd, popMenu1, popUpBox1, popMenuID1, fontChoice1 );
  458.         InvertRect( &promptBox1 );
  459.         if( newChoice != 0 )
  460.         { fontChoice1 = newChoice;
  461.           DrawPopUp1( esd, esdFont1Pu );
  462.           *theDialogItem = esdFont1Pu;
  463.           SetPort( temp );
  464.           result = true;
  465.         }
  466.         break;
  467.       case esdFont2St:
  468.       case esdFont2Pu:
  469.         InvertRect( &promptBox2 );
  470.         newChoice = doPop( esd, popMenu2, popUpBox2, popMenuID2, fontChoice2 );
  471.         InvertRect( &promptBox2 );
  472.         if( newChoice != 0 )
  473.         { fontChoice2 = newChoice;
  474.           DrawPopUp2( esd, esdFont2Pu );
  475.           *theDialogItem = esdFont2Pu;
  476.           SetPort( temp );
  477.           result = true;
  478.         }
  479.         break;
  480.       /* case esdSize2St:  not for size menu!? */
  481.       case esdSize1Pu:
  482.           SelIText( esd, esdSize1Et, 0, 32767 );
  483.           preSize1( esd );
  484.         newChoice = doPop( esd, popMenu3, popUpBox3, popMenuID3, sizeChoice3 );
  485.         if( newChoice != 0 )
  486.         { sizeChoice3 = newChoice;
  487.           DrawPopUpSz( esd, esdSize1Pu );
  488.           *theDialogItem = esdSize1Pu;
  489.           SetPort( temp );
  490.           result = true;
  491.         }
  492.         break;
  493.       /* case esdSize2St:  not for size menu!? */
  494.       case esdSize2Pu:
  495.           SelIText( esd, esdSize2Et, 0, 32767 );
  496.           preSize2( esd );
  497.         newChoice = doPop( esd, popMenu4, popUpBox4, popMenuID4, sizeChoice4 );
  498.         if( newChoice != 0 )
  499.         { sizeChoice4 = newChoice;
  500.           DrawPopUpSz( esd, esdSize2Pu );
  501.           *theDialogItem = esdSize2Pu;
  502.           SetPort( temp );
  503.           result = true;
  504.         }
  505.         break;
  506.     }
  507.   }
  508.   return( result );
  509. }
  510.  
  511. static void check( DialogPtr dbox, short item, Boolean mark )
  512. { ControlHandle hC;
  513.   short itemtype;
  514.   Rect itemrect;    
  515.   GetDItem( dbox, item, &itemtype, (Handle)&hC, &itemrect);
  516.   SetCtlValue( hC, mark );
  517. }
  518.  
  519. static void checks( DialogPtr dbox, short style, short offs )
  520. {
  521.   check( dbox, esdBold1Cb + offs, ( style & bold ) ? 1 : 0 );
  522.   check( dbox, esdItal1Cb + offs, ( style & italic ) ? 1 : 0 );
  523.   check( dbox, esdUndr1Cb + offs, ( style & underline ) ? 1 : 0 );
  524.   check( dbox, esdCond1Cb + offs, ( style & condense ) ? 1 : 0 );
  525.   check( dbox, esdExpd1Cb + offs, ( style & extend ) ? 1 : 0 );
  526.   /*
  527.   check( dbox, esdInvr1Cb + offs, ( style & bold ) ? 1 : 0 );
  528.   */
  529. }
  530.  
  531. short checklist[] = { bold, italic, condense, underline, 0x80, extend };
  532.  
  533. static short findFontItem( MenuHandle hM, short fontNum )
  534. { short result = 1;
  535.   short i, fn;
  536.   Str255 tStr;
  537.   for( i = CountMItems( hM ); i > 0; i-- )
  538.   { GetItem( hM, i, tStr );
  539.     GetFNum( tStr, &fn );
  540.     if( fn == fontNum ) return i;
  541.     if( fn == 0 ) result = i;
  542.   }
  543.   return result;
  544. }
  545.  
  546. /* get the item's rect & set the procPtr */
  547. static void initUserItem( DialogPtr esd, short item, Rect *pRect, ProcPtr pProc )
  548. { short tempItem;
  549.   Handle tempHandle;
  550.   GetDItem( esd, item, &tempItem, &tempHandle, pRect );
  551.   SetDItem( esd, item, tempItem, (Handle)pProc, pRect );
  552. }
  553.  
  554. static void hosePops( void )
  555. {
  556.   if( popMenu1 ) DisposHandle( popMenu1 );
  557.   popMenu1 = 0;
  558.   if( popMenu2 ) DisposHandle( popMenu2 );
  559.   popMenu2 = 0;
  560.   if( popMenu3 ) DisposHandle( popMenu3 );
  561.   popMenu3 = 0;
  562.   if( popMenu4 ) DisposHandle( popMenu4 );
  563.   popMenu4 = 0;
  564. }
  565.  
  566. static void initPops( DialogPtr esd )
  567. { Str255 tStr;
  568.   short tempItem;
  569.   Rect tempRect;
  570.   Handle tempHandle;
  571.  
  572.   hosePops();
  573.   
  574.   SetPort( esd );
  575.   
  576.   popMenu1 = NewMenu( popMenuID1, "" );
  577.   AddResMenu( popMenu1, 'FONT' );
  578.   fontChoice1 = findFontItem( popMenu1, tsNewPri.tsFont );
  579.   SetItemMark( popMenu1, fontChoice1, checkMark );
  580.   InvalRect( &popUpBox1 );
  581.     
  582.   popMenu2 = NewMenu( popMenuID2, "" );
  583.   AddResMenu( popMenu2, 'FONT' );
  584.   fontChoice2 = findFontItem( popMenu2, tsNewAlt.tsFont );
  585.   SetItemMark( popMenu2, fontChoice2, checkMark );
  586.   InvalRect( &popUpBox2 );
  587.   
  588.   popMenu3 = sizeMenu( popMenuID3, &sizeChoice3, tsNewPri.tsFont, tsNewPri.tsSize );
  589.   doSize1( esd );
  590.  
  591.   popMenu4 = sizeMenu( popMenuID4, &sizeChoice4, tsNewAlt.tsFont, tsNewAlt.tsSize );
  592.   doSize2( esd );
  593.   
  594.   checks( esd, tsNewPri.tsFace,  0 );
  595.   checks( esd, tsNewAlt.tsFace, 10 );
  596.   
  597.   NumToString( (long )tabsNew, tStr );
  598.   GetDItem( esd, esdTabsEt, &tempItem, &tempHandle, &tempRect );
  599.   SetIText( tempHandle, tStr );
  600.   SelIText( esd, esdTabsEt, 0, 32767 );
  601.   
  602.   NumToString( (long )wrapNew, tStr );
  603.   GetDItem( esd, esdWrapEt, &tempItem, &tempHandle, &tempRect );
  604.   SetIText( tempHandle, tStr );
  605.   SelIText( esd, esdWrapEt, 0, 32767 );
  606.  
  607.   check( esd, esdAutoInd, autoIndNew );
  608. }  
  609.  
  610. void eStyleDlg( eRec **hE /* , TextStyle *pri, TextStyle *alt */ )
  611. { DialogPtr esd = NULL;
  612.   short hitItem = 0;
  613.   short tempItem;
  614.   Rect tempRect;
  615.   Handle tempHandle;
  616.   Boolean tBool;
  617.   long tmp1, tmp2, tmp3;
  618.   
  619.   tsNewPri = (**hE).style[0];
  620.   tsNewAlt = (**hE).style[1];
  621.   tabsNew = (**hE).tabStops;
  622.   wrapNew = (**hE).wrap;
  623.   autoIndNew = (**hE).autoInd;
  624.  
  625.   /* Get a dialog box, and set up our useritems */
  626.   esd = GetNewDialog( esdID, NULL, (WindowPtr)(-1) );
  627.         
  628.   /* Find out where our useritems are, and set their item handles to be
  629.      a pointer to our popup-drawing or other special procedure */
  630.   GetDItem( esd, esdFont1St, &tempItem, &tempHandle, &promptBox1 ); /* get the title rect */
  631.   initUserItem( esd, esdFont1Pu, &popUpBox1, DrawPopUp1 );
  632.   GetDItem( esd, esdFont2St, &tempItem, &tempHandle, &promptBox2 ); /* get the title rect */
  633.   initUserItem( esd, esdFont2Pu, &popUpBox2, DrawPopUp2 );
  634.   initUserItem( esd, esdSize1Pu, &popUpBox3, DrawPopUpSz );
  635.   initUserItem( esd, esdSize2Pu, &popUpBox4, DrawPopUpSz );
  636.   initUserItem( esd, esdOutline1, &tempRect, Outliner );
  637.   initUserItem( esd, esdOutline2, &tempRect, Outliner );
  638.   initUserItem( esd, esdOutline3, &tempRect, Outliner );
  639.  
  640.   GetDItem( esd, esdOK,&tempItem, &tempHandle, &tempRect ); /* get the OK button's rect */
  641.   InsetRect( &tempRect, -4, -4);
  642.   SetDItem( esd, esdOKring, userItem+itemDisable, (Handle)BorderDefault, &tempRect);
  643.  
  644.   /* Get two menus containing the current set of fonts */
  645.   /* and two menus containing their corresponding sizes */
  646.   initPops( esd );
  647.   
  648.   check( esd, esdThisCb, 1 );
  649.   check( esd, esdPrefCb, 0 );    /* defaulted to off  --  16Jul92  e  */
  650.     
  651.   ShowWindow( (WindowPtr)esd );
  652.   DrawDialog( esd );
  653.   do
  654.   { ModalDialog( (ModalFilterProcPtr)filterIt, &hitItem );
  655.     switch ( hitItem )
  656.     { case esdFont1Pu:
  657.         doFont1( );
  658.         break;
  659.       case esdFont2Pu:
  660.         doFont2( );
  661.         break;
  662.       case esdSize1Pu:
  663.           doSize1( esd );
  664.         break;
  665.       case esdSize2Pu:
  666.           doSize2( esd );
  667.         break;
  668.       case esdBold1Cb:
  669.       case esdItal1Cb:
  670.       case esdCond1Cb:
  671.       case esdUndr1Cb:
  672.       case esdInvr1Cb:
  673.       case esdExpd1Cb:
  674.         GetDItem( esd, hitItem, &tempItem, &tempHandle, &tempRect);
  675.         tempItem = GetCtlValue( (ControlHandle )tempHandle ) ^ 1;
  676.         if( tempItem == 0 )
  677.           tsNewPri.tsFace &= ~checklist[hitItem-esdBold1Cb];
  678.         else
  679.           tsNewPri.tsFace |=  checklist[hitItem-esdBold1Cb];
  680.         SetCtlValue( (ControlHandle )tempHandle, tempItem);
  681.         break;
  682.       case esdBold2Cb:
  683.       case esdItal2Cb:
  684.       case esdCond2Cb:
  685.       case esdUndr2Cb:
  686.       case esdInvr2Cb:
  687.       case esdExpd2Cb:
  688.         GetDItem( esd, hitItem, &tempItem, &tempHandle, &tempRect);
  689.         tempItem = GetCtlValue( (ControlHandle )tempHandle ) ^ 1;
  690.         if( tempItem == 0 )
  691.           tsNewAlt.tsFace &= ~checklist[hitItem-esdBold2Cb];
  692.         else
  693.           tsNewAlt.tsFace |=  checklist[hitItem-esdBold2Cb];
  694.         SetCtlValue( (ControlHandle )tempHandle, tempItem);
  695.         break;
  696.       case esdThisCb:
  697.       case esdPrefCb:
  698.       case esdAutoInd:
  699.         GetDItem( esd, hitItem, &tempItem, &tempHandle, &tempRect);
  700.         tempItem = GetCtlValue( (ControlHandle )tempHandle ) ^ 1;
  701.         SetCtlValue( (ControlHandle )tempHandle, tempItem);
  702.         break;
  703.       case esdThisBt:
  704.         tsNewPri   = (**hE).style[0];
  705.         tsNewAlt   = (**hE).style[1];
  706.         tabsNew    = (**hE).tabStops;
  707.         wrapNew    = (**hE).wrap;
  708.         autoIndNew = (**hE).autoInd;
  709.         initPops( esd );
  710.         break;
  711.       case esdPrefBt:
  712.         tsNewPri   = prefStylNormal;
  713.         tsNewAlt   = prefStylHilite;
  714.         tabsNew    = prefTabs;
  715.         wrapNew    = prefWrap;
  716.         autoIndNew = prefAutoInd;
  717.         initPops( esd );
  718.         break;
  719.       case esdDfltBt:
  720.         tsNewPri   = dfltStylNormal;
  721.         tsNewAlt   = dfltStylHilite;
  722.         tabsNew    = dfltTabs;
  723.         wrapNew    = dfltWrap;
  724.         autoIndNew = dfltAutoInd;
  725.         initPops( esd );
  726.         break;
  727.     }
  728.   } while ( hitItem != esdOK && hitItem != esdCancel );
  729.   
  730.   if( hitItem == esdOK )
  731.   { tsNewPri.tsSize = etToNum( esd, esdSize1Et );
  732.     tsNewAlt.tsSize = etToNum( esd, esdSize2Et );
  733.     tmp1 = etToNum( esd, esdTabsEt );
  734.     tmp2 = etToNum( esd, esdWrapEt );
  735.     GetDItem( esd, esdAutoInd, &tempItem, &tempHandle, &tempRect);
  736.     tmp3 = GetCtlValue( (ControlHandle )tempHandle );
  737.     GetDItem( esd, esdThisCb, &tempItem, &tempHandle, &tempRect);
  738.     if( GetCtlValue( (ControlHandle )tempHandle ) )
  739.     { if( (**hE).tabStops != tmp1 )
  740.       { eTeSetTabStop( hE, (short )tmp1 );
  741.       }
  742.       if( (**hE).wrap != tmp2 )
  743.       { eTeSetWrap( hE, (short )tmp2 );
  744.       }
  745.       (**hE).autoInd = tmp3;
  746.       if(    tsNewPri.tsFont != (**hE).style[0].tsFont
  747.           || tsNewPri.tsSize != (**hE).style[0].tsSize
  748.           || tsNewPri.tsFace != (**hE).style[0].tsFace
  749.           || tsNewAlt.tsFont != (**hE).style[1].tsFont
  750.           || tsNewAlt.tsSize != (**hE).style[1].tsSize
  751.           || tsNewAlt.tsFace != (**hE).style[1].tsFace
  752.         )
  753.       { eTeSetStyles( hE, &tsNewPri, &tsNewAlt );
  754.       }
  755.     }
  756.     GetDItem( esd, esdPrefCb, &tempItem, &tempHandle, &tempRect);
  757.     if( GetCtlValue( (ControlHandle )tempHandle ) )
  758.     { prefStylNormal = tsNewPri;
  759.       prefStylHilite = tsNewAlt;
  760.       prefTabs    = (short )tmp1;
  761.       prefWrap    = (short )tmp2;
  762.       prefAutoInd = (short )tmp3;
  763.       savePrefs( PREFS_FILENAME );  /*  16Jul92  e  */
  764.     }
  765.   }
  766.   hosePops();
  767.   if( esd ) DisposDialog( esd );
  768. }
  769.  
  770. /* end of os_mac_eStyle.c */
  771.