home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / sml_nj / 93src.lha / src / runtime / mac / os_mac_eStyle.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-02-09  |  21.7 KB  |  776 lines

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