home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 October: Mac OS SDK / Dev.CD Oct 00 SDK1.toast / Development Kits / Mac OS / Appearance SDK 1.0.4 / Appearance Sample Code / Source / CDEFTesterUtils.cp < prev    next >
Encoding:
Text File  |  1999-07-16  |  46.4 KB  |  1,664 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        CDEFTesterUtils.cp
  3.  
  4.     Contains:    Code to demonstrate creating and using all types of controls.
  5.  
  6.     Version:    Appearance 1.0 SDK
  7.  
  8.     Copyright:    © 1997 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     File Ownership:
  11.  
  12.         DRI:                Edward Voas
  13.  
  14.         Other Contact:        7 of 9, Borg Collective
  15.  
  16.         Technology:            OS Technologies Group
  17.  
  18.     Writers:
  19.  
  20.         (MAA)    Matt Ackeret
  21.         (edv)    Ed Voas
  22.  
  23.     Change History (most recent first):
  24.  
  25.         <11>    12/18/97    edv        Fix compiler warnings.
  26.         <10>    11/21/97    MAA        Add UserPane
  27.          <9>     11/7/97    MAA        Remove tab count limitation
  28.          <8>     11/6/97    MAA        Make tab names variable length.
  29.          <7>     11/5/97    MAA        add Tabs
  30.          <6>    10/31/97    MAA        fix window title in CreateCheckBoxOrRadioButton
  31.          <5>    10/31/97    MAA        fix clock size in CreateClock
  32.          <4>    10/28/97    MAA        Remove temporary editText control bug checking code
  33.          <3>    10/28/97    MAA        Create many dialogs invisible then show after changes made
  34.          <2>    10/28/97    edv        Use RadioGroup control!
  35.          <1>     9/11/97    edv        First checked in.
  36. */
  37.  
  38. #include <TextUtils.h>
  39. #include <Appearance.h>
  40. #include <Resources.h>
  41. #include <String.h>
  42. #include <Controls.h>
  43. #include "CDEFTesterUtils.h"
  44. #include "BevelButtonItems.h"
  45. #include "RadioGroup.h"
  46. #include "AppearanceHelpers.h"
  47.  
  48. enum
  49. {
  50.     kLeftArrow        = 0x1C,
  51.     kRightArrow        = 0x1D,
  52.     kUpArrow        = 0x1E,
  53.     kDownArrow        = 0x1F,
  54.     kBackspace        = 0x08
  55. };
  56.  
  57. enum { kSmall = 1, kNormal, kLarge };
  58. enum { kMomentary = 1, kToggles, kSticky };
  59. enum { kTextOnly = 1, kIconSuite, kColorIcon, kPicture };
  60. enum { kPlaceNormal = 1, kPlaceLeft, kPlaceRight, kPlaceAbove, kPlaceBelow, kPlaceSys };
  61. enum { kTextSysDir = 1, kTextLeft, kTextRight, kTextCenter };
  62. enum { kGraphicSysDir = 1, kGraphicCenter, kGraphicLeft, kGraphicRight,
  63.         kGraphicTop, kGraphicBottom, kGraphicTopLeft, kGraphicBotLeft,
  64.         kGraphicTopRight, kGraphicBotRight };
  65.  
  66. static void                GetPictureSize( SInt16 resID, SInt32* height, SInt32* width );
  67. static void                GetIconSize( SInt16 resID, SInt32* height, SInt32* width );
  68. static ControlHandle    CreatePictureOrIconCDEF( WindowPtr window, SInt16 procID );
  69. static ControlHandle    CreateCheckBoxOrRadioButton( WindowPtr window, SInt16 procID );
  70. static pascal void        UserPaneDrawProc(ControlHandle theControl, SInt16 thePart);
  71.  
  72. ControlHandle
  73. CreateBevelButton( WindowPtr window )
  74. {
  75.     DialogPtr        dialog;
  76.     SInt16            itemHit = 0;
  77.     ControlHandle        control = nil;
  78.     SInt16            type;
  79.     Handle            handle;
  80.     Rect            rect;
  81.     SInt32            min, max, value, procID;
  82.     Str255            text, title;
  83.     Rect            bounds = { 0, 0, 48, 48 };
  84.     
  85.     ControlButtonGraphicAlignment    graphicAlign;
  86.     ControlButtonTextPlacement    placement;
  87.     ControlButtonTextAlignment    alignment;
  88.     SInt32                longOffset;
  89.     SInt16                offset;
  90.     SInt32                temp;
  91.     Point                graphicOffset;
  92.     ControlHandle        tempControl;
  93.     
  94.     dialog = GetNewDialog( 2000, nil, (WindowPtr)-1L );
  95.     if ( dialog == nil ) return nil;
  96.  
  97.     GetDialogItemAsControl( dialog, kBevelSizePopup, &tempControl );
  98.     SetControlValue( tempControl, kSmall );
  99.     
  100.     GetDialogItemAsControl( dialog, kBevelBehaviorPopup, &tempControl );
  101.     SetControlValue( tempControl, kMomentary );
  102.     
  103.     GetDialogItemAsControl( dialog, kBevelContentPopup, &tempControl );
  104.     SetControlValue( tempControl, kTextOnly );
  105.  
  106.     GetDialogItemAsControl( dialog, kBevelTextPlacePopup, &tempControl );
  107.     SetControlValue( tempControl, kPlaceNormal );
  108.  
  109.     GetDialogItemAsControl( dialog, kBevelTextAlignPopup, &tempControl );
  110.     SetControlValue( tempControl, kTextCenter );
  111.  
  112.     GetDialogItemAsControl( dialog, kBevelGraphicAlignPopup, &tempControl );
  113.     SetControlValue( tempControl, kGraphicCenter );
  114.  
  115.     SetDialogDefaultItem( dialog, kBevelOKButton );
  116.     SetDialogCancelItem( dialog, kBevelCancelButton );
  117.         
  118.     ShowWindow(dialog);
  119.     
  120.     while ( itemHit != kBevelCancelButton && itemHit != kBevelOKButton )
  121.     {
  122.         ModalDialog( nil, &itemHit );
  123.         
  124.         GetDialogItemAsControl( dialog, itemHit, &tempControl );
  125.         switch ( itemHit )
  126.         {
  127.             case kBevelOffsetCheck:
  128.             case kBevelMultiMenuCheck:
  129.             case kBevelMenuOnRightCheck:
  130.                 {
  131.                     SInt16    value = GetControlValue( tempControl );
  132.                     SetControlValue( tempControl, !value );
  133.                 }
  134.                 break;
  135.  
  136.         }
  137.     }
  138.     
  139.     if ( itemHit == kBevelCancelButton )
  140.     {
  141.         DisposeDialog( dialog );
  142.         return nil;
  143.     }
  144.     
  145.         // Get the content type from the popup into min.
  146.         
  147.     GetDialogItemAsControl( dialog, kBevelContentPopup, &tempControl );
  148.     switch ( GetControlValue( tempControl ) )
  149.     {
  150.         case kTextOnly:        min = kControlContentTextOnly;        break;
  151.         case kIconSuite:    min = kControlContentIconSuiteRes;    break;
  152.         case kColorIcon:    min = kControlContentCIconRes;        break;
  153.         case kPicture:        min = kControlContentPictRes;        break;
  154.     }
  155.     
  156.         // Now get the resource ID for the content, if we
  157.         // have chosen something other than text only.
  158.         // put the ID into max.
  159.         
  160.     if ( min != kControlContentTextOnly )
  161.     {
  162.         GetDialogItem( dialog, kBevelContentIDText, &type, &handle, &rect );
  163.         GetDialogItemText( handle, text );
  164.         StringToNum( text, &max );
  165.     }
  166.     else
  167.         max = 0;
  168.     
  169.         // Get the menu ID
  170.         
  171.     GetDialogItem( dialog, kBevelMenuIDText, &type, &handle, &rect );
  172.     GetDialogItemText( handle, text );
  173.     StringToNum( text, &value );
  174.     
  175.     GetDialogItemAsControl( dialog, kBevelSizePopup, &tempControl );
  176.     switch( GetControlValue( tempControl ) )
  177.     {
  178.         case kSmall:    procID = kControlBevelButtonSmallBevelProc;        break;
  179.         case kNormal:     procID = kControlBevelButtonNormalBevelProc;     break;
  180.         case kLarge:     procID = kControlBevelButtonLargeBevelProc;        break;
  181.     }
  182.  
  183.         // OR our behavior into min.
  184.  
  185.     GetDialogItemAsControl( dialog, kBevelBehaviorPopup, &tempControl );
  186.     switch( GetControlValue( (ControlHandle)handle ) )
  187.     {
  188.         case kToggles:         min |= kControlBehaviorToggles;     break;
  189.         case kSticky:         min |= kControlBehaviorSticky;        break;
  190.     }
  191.  
  192.         // See if we should offset the contents and OR the right bit
  193.         // into min.
  194.         
  195.     GetDialogItemAsControl( dialog, kBevelOffsetCheck, &tempControl );
  196.     if ( GetControlValue( tempControl ) == 1 )
  197.         min |= kControlBehaviorOffsetContents;
  198.     
  199.         // See if we have a multi-value menu and OR the right bit
  200.         // into min.
  201.         
  202.     GetDialogItemAsControl( dialog, kBevelMultiMenuCheck, &tempControl );
  203.     if ( GetControlValue( tempControl ) == 1 )
  204.         min |= kControlBehaviorMultiValueMenu;
  205.     
  206.         // See if the menu shoule be on the right and OR the right bit
  207.         // into min.
  208.         
  209.     GetDialogItemAsControl( dialog, kBevelMenuOnRightCheck, &tempControl );
  210.     if ( GetControlValue( tempControl ) == 1 )
  211.         procID |= kControlBevelButtonMenuOnRight;
  212.     
  213.         // Calculate the size of our button
  214.         
  215.     GetDialogItem( dialog, kBevelHeightText, &type, &handle, &rect );
  216.     GetDialogItemText( handle, text );
  217.     StringToNum( text, &temp );
  218.     bounds.bottom = temp;
  219.     GetDialogItem( dialog, kBevelWidthText, &type, &handle, &rect );
  220.     GetDialogItemText( handle, text );
  221.     StringToNum( text, &temp );
  222.     bounds.right = temp;
  223.     
  224.         // Get the text alignment, offset, and placement
  225.     
  226.     GetDialogItemAsControl( dialog, kBevelTextAlignPopup, &tempControl );
  227.     switch ( GetControlValue( tempControl ) )
  228.     {
  229.         case kTextSysDir:    alignment = kControlBevelButtonAlignTextSysDirection;    break;
  230.         case kTextLeft:        alignment = kControlBevelButtonAlignTextFlushLeft;        break;
  231.         case kTextRight:    alignment = kControlBevelButtonAlignTextFlushRight;        break;
  232.         case kTextCenter:    alignment = kControlBevelButtonAlignTextCenter;            break;
  233.     }
  234.     
  235.     GetDialogItem( dialog, kBevelTextOffsetText, &type, &handle, &rect );
  236.     GetDialogItemText( handle, text );
  237.     StringToNum( text, &longOffset );
  238.     offset = longOffset;
  239.  
  240.     GetDialogItemAsControl( dialog, kBevelTextPlacePopup, &tempControl );
  241.     switch ( GetControlValue( tempControl ) )
  242.     {
  243.         case kPlaceNormal:    placement = kControlBevelButtonPlaceNormally;            break;
  244.         case kPlaceLeft:    placement = kControlBevelButtonPlaceToLeftOfGraphic;    break;
  245.         case kPlaceRight:    placement = kControlBevelButtonPlaceToRightOfGraphic;    break;
  246.         case kPlaceAbove:    placement = kControlBevelButtonPlaceAboveGraphic;        break;
  247.         case kPlaceBelow:    placement = kControlBevelButtonPlaceBelowGraphic;        break;
  248.         case kPlaceSys:        placement = kControlBevelButtonPlaceSysDirection;        break;
  249.     }
  250.  
  251.         // Get the graphic alignment and offsets
  252.             
  253.     GetDialogItemAsControl( dialog, kBevelGraphicAlignPopup, &tempControl );
  254.     switch ( GetControlValue( tempControl ) )
  255.     {
  256.         case kGraphicSysDir:    graphicAlign = kControlBevelButtonAlignSysDirection;    break;
  257.         case kGraphicCenter:    graphicAlign = kControlBevelButtonAlignCenter;            break;
  258.         case kGraphicLeft:        graphicAlign = kControlBevelButtonAlignLeft;            break;
  259.         case kGraphicRight:        graphicAlign = kControlBevelButtonAlignRight;            break;
  260.         case kGraphicTop:        graphicAlign = kControlBevelButtonAlignTop;                break;
  261.         case kGraphicBottom:    graphicAlign = kControlBevelButtonAlignBottom;            break;
  262.         case kGraphicTopLeft:    graphicAlign = kControlBevelButtonAlignTopLeft;            break;
  263.         case kGraphicBotLeft:    graphicAlign = kControlBevelButtonAlignBottomLeft;        break;
  264.         case kGraphicTopRight:    graphicAlign = kControlBevelButtonAlignTopRight;        break;
  265.         case kGraphicBotRight:    graphicAlign = kControlBevelButtonAlignBottomRight;        break;
  266.     }
  267.  
  268.     GetDialogItem( dialog, kBevelGraphicHOffsetText, &type, &handle, &rect );
  269.     GetDialogItemText( handle, text );
  270.     StringToNum( text, &longOffset );
  271.     graphicOffset.h = longOffset;
  272.     GetDialogItem( dialog, kBevelGraphicVOffsetText, &type, &handle, &rect );
  273.     GetDialogItemText( handle, text );
  274.     StringToNum( text, &longOffset );
  275.     graphicOffset.v = longOffset;
  276.     
  277.         // Get the title.
  278.         
  279.     GetDialogItem( dialog, kBevelTitleText, &type, &handle, &rect );
  280.     GetDialogItemText( handle, title );
  281.     
  282.     DisposeDialog( dialog );
  283.     
  284.     control = NewControl( window, &bounds, title, false, value, min, max, procID, 0 );
  285.     if ( control == nil ) return nil;
  286.     
  287.     SetControlData( control, 0, kControlBevelButtonTextPlaceTag, sizeof( ControlButtonTextPlacement ),
  288.         (Ptr)&placement );
  289.         
  290.     SetControlData( control, 0, kControlBevelButtonTextAlignTag, sizeof( ControlButtonTextAlignment ),
  291.         (Ptr)&alignment );
  292.  
  293.     SetControlData( control, 0, kControlBevelButtonGraphicAlignTag, sizeof( ControlButtonGraphicAlignment ),
  294.         (Ptr)&graphicAlign );
  295.  
  296.     SetControlData( control, 0, kControlBevelButtonTextOffsetTag, sizeof( SInt16 ), (Ptr)&offset );
  297.     SetControlData( control, 0, kControlBevelButtonGraphicOffsetTag, sizeof( Point ), (Ptr)&graphicOffset );
  298.         
  299.     return control;
  300. }
  301.  
  302.  
  303. static pascal void
  304. UserPaneDrawProc (ControlHandle theControl, SInt16 thePart)
  305. {
  306.     #pragma unused( thePart )
  307.     Rect        bounds;
  308.     
  309.     bounds = (**theControl).contrlRect;
  310.     
  311.     FrameRect( &bounds );
  312. }
  313.  
  314.  
  315. /***
  316.     This is just a very simplistic User Pane that that draws a rectangle around its frame, and 
  317.     returns an incrementing number for the part codes.  It shows how to set up a few of the 
  318.     various procedures needed for User Panes.
  319. ***/
  320. ControlHandle
  321. CreateUserPane( WindowPtr window )
  322. {
  323.     Rect        bounds = { 0, 0, 100, 100 };
  324.     ControlHandle theControl;
  325.     
  326.     theControl =  NewControl( window, &bounds, "\p", false, 0, 0, 0, kControlUserPaneProc, 0 );
  327.     if (theControl)
  328.         {
  329.             ControlUserPaneDrawUPP myPaneDrawProc;
  330.             
  331.             myPaneDrawProc = NewControlUserPaneDrawProc(UserPaneDrawProc);
  332.             SetControlData(theControl, 0, kControlUserPaneDrawProcTag, sizeof(ControlUserPaneDrawUPP), (Ptr) &myPaneDrawProc);
  333.  
  334.             return(theControl);
  335.         }
  336.         
  337.     return(nil);
  338. }
  339.  
  340.  
  341. ControlHandle
  342. CreateChasingArrows( WindowPtr window )
  343. {
  344.     Rect        bounds = { 0, 0, 16, 16 };
  345.     
  346.     return NewControl( window, &bounds, "\p", false, 0, 0, 0, kControlChasingArrowsProc, 0 );
  347. }
  348.  
  349. ControlHandle
  350. CreateDivider( WindowPtr window )
  351. {
  352.     DialogPtr        dialog;
  353.     SInt16            itemHit = 0;
  354.     ControlHandle    control = nil;
  355.     SInt16            type;
  356.     Handle            handle;
  357.     Rect            rect;
  358.     SInt32            length;
  359.     Str255            text;
  360.     Rect            bounds = { 0, 0, 4, 4 };
  361.     ControlHandle    tempControl;
  362.     
  363.     dialog = GetNewDialog( 2001, nil, (WindowPtr)-1L );
  364.     if ( dialog == nil ) return nil;
  365.  
  366.     SetDialogDefaultItem( dialog, kDividerOKButton );
  367.     SetDialogCancelItem( dialog, kDividerCancelButton );
  368.         
  369.     while ( itemHit != kDividerCancelButton && itemHit != kDividerOKButton )
  370.     {
  371.         ModalDialog( nil, &itemHit );
  372.     }
  373.     
  374.     if ( itemHit == kDividerCancelButton )
  375.     {
  376.         DisposeDialog( dialog );
  377.         return nil;
  378.     }
  379.     
  380.     GetDialogItem( dialog, kLengthText, &type, &handle, &rect );
  381.     GetDialogItemText( handle, text );
  382.     StringToNum( text, &length );
  383.     
  384.     GetDialogItemAsControl( dialog, kDividerRadioGroup, &tempControl );
  385.     if ( GetControlValue( tempControl ) == 1 )
  386.         bounds.right = bounds.left + length;
  387.     else
  388.         bounds.bottom = bounds.top + length;
  389.     
  390.     DisposeDialog( dialog );
  391.     
  392.     control = NewControl( window, &bounds, "\p", false, 0, 0, 0, kControlSeparatorLineProc, 0 );
  393.     if ( control == nil ) return nil;
  394.     
  395.     return control;
  396. }
  397.  
  398. ControlHandle
  399. CreateTriangle( WindowPtr window )
  400. {
  401.     DialogPtr        dialog;
  402.     SInt16            itemHit = 0;
  403.     ControlHandle    control = nil;
  404.     Rect            bounds = { 0, 0, 12, 12 };
  405.     SInt16            procID;
  406.     ControlHandle    tempControl;
  407.     
  408.     dialog = GetNewDialog( 2002, nil, (WindowPtr)-1L );
  409.     if ( dialog == nil ) return nil;
  410.  
  411.     SetDialogDefaultItem( dialog, kTriangleOKButton );
  412.     SetDialogCancelItem( dialog, kTriangleCancelButton );
  413.         
  414.     while ( itemHit != kTriangleCancelButton && itemHit != kTriangleOKButton )
  415.     {
  416.         ModalDialog( nil, &itemHit );
  417.         
  418.         GetDialogItemAsControl( dialog, itemHit, &tempControl );
  419.         switch ( itemHit )
  420.         {
  421.             case kLeftFacingCheck:
  422.             case kAutoTrackCheck:
  423.                 SetControlValue( tempControl, !GetControlValue( tempControl ) );
  424.                 break;
  425.         }
  426.     }
  427.     
  428.     if ( itemHit == kTriangleCancelButton )
  429.     {
  430.         DisposeDialog( dialog );
  431.         return nil;
  432.     }
  433.     
  434.     procID = kControlTriangleProc;
  435.  
  436.     GetDialogItemAsControl( dialog, kLeftFacingCheck, &tempControl );
  437.     if ( GetControlValue( tempControl ) == 1 )
  438.         procID |= 1;
  439.         
  440.     GetDialogItemAsControl( dialog, kAutoTrackCheck, &tempControl );
  441.     if ( GetControlValue( tempControl ) == 1 )
  442.         procID |= 2;
  443.     
  444.     DisposeDialog( dialog );
  445.     
  446.     control = NewControl( window, &bounds, "\p", false, 0, 0, 1, procID, 0 );
  447.     if ( control == nil ) return nil;
  448.     
  449.     return control;
  450. }
  451.  
  452. ControlHandle
  453. CreateEditText( WindowPtr window )
  454. {
  455.     DialogPtr        dialog;
  456.     SInt16            itemHit = 0;
  457.     ControlHandle    control = nil;
  458.     Rect            bounds = { 20, 20, 36, 200 };
  459.     SInt16            procID;
  460.     ControlHandle    tempControl;
  461.     char            *string = "Sample Text";
  462.     
  463.     dialog = GetNewDialog( 2014, nil, (WindowPtr)-1L );
  464.     if ( dialog == nil ) return nil;
  465.  
  466.     SetDialogDefaultItem( dialog, kETOKButton );
  467.     SetDialogCancelItem( dialog, kETCancelButton );
  468.         
  469.     while ( itemHit != kETCancelButton && itemHit != kETOKButton )
  470.     {
  471.         ModalDialog( nil, &itemHit );
  472.         
  473.         GetDialogItemAsControl( dialog, itemHit, &tempControl );
  474.         if (itemHit == kETPasswordCheck)
  475.             SetControlValue(tempControl, !GetControlValue(tempControl));
  476.     }
  477.     
  478.     if ( itemHit == kETCancelButton )
  479.     {
  480.         DisposeDialog( dialog );
  481.         return nil;
  482.     }
  483.     
  484.     GetDialogItemAsControl( dialog, kETPasswordCheck, &tempControl );
  485.     if (GetControlValue( tempControl ))
  486.         procID = kControlEditTextPasswordProc;
  487.     else
  488.         procID = kControlEditTextProc;
  489.  
  490.     DisposeDialog( dialog );
  491.     
  492.     control = NewControl( window, &bounds, "\pEdit Text", false, 0, 0, 0, procID, 0 );
  493.     if (!control) return nil;
  494.     
  495.     SetKeyboardFocus(window, control, kControlFocusNextPart);
  496.     
  497.     if (procID != kControlEditTextPasswordProc)
  498.         SetControlData(control,kControlNoPart,kControlEditTextTextTag,strlen(string),(Ptr) string);
  499.     
  500.     return control;
  501. }
  502.  
  503. ControlHandle
  504. CreateSlider( WindowPtr window )
  505. {
  506.     DialogPtr        dialog;
  507.     SInt16            itemHit = 0;
  508.     ControlHandle    dialogControl,tempControl;
  509.     SInt16            procID = kControlSliderProc;
  510.     Rect            bounds = { 20, 20, 80, 200 };
  511.     Boolean         enableItems,alreadyEnabled;
  512.     
  513.     dialog = GetNewDialog( 2016, nil, (WindowPtr)-1L );
  514.     if ( dialog == nil ) return nil;
  515.  
  516.     SetDialogDefaultItem( dialog, kStdOkItemIndex );
  517.     SetDialogCancelItem( dialog, kStdCancelItemIndex );
  518.     GetDialogItemAsControl(dialog, kSliderDirectional, &tempControl);
  519.     SetControlValue(tempControl, 1);
  520.     ShowWindow(dialog);
  521.         
  522.     while ( itemHit != kStdOkItemIndex && itemHit != kStdCancelItemIndex )
  523.         {
  524.             ModalDialog( nil, &itemHit );
  525.             
  526.             GetDialogItemAsControl(dialog, itemHit, &dialogControl);
  527.             
  528.             if ((itemHit == kSliderTickMarks) || (itemHit == kSliderReverse))
  529.                 SetControlValue(dialogControl, !GetControlValue(dialogControl)); // toggle checkbox
  530.  
  531.             if ((itemHit == kSliderNonDirectional) || (itemHit == kSliderDirectional))
  532.                 {
  533.                     alreadyEnabled = GetControlValue(dialogControl);
  534.                     
  535.                     SetControlValue(dialogControl, 1);
  536.                     GetDialogItemAsControl(dialog, (itemHit == kSliderNonDirectional) ? kSliderDirectional : kSliderNonDirectional, &tempControl);
  537.                     SetControlValue(tempControl, 0);
  538.                     
  539.                     enableItems = (itemHit == kSliderDirectional);
  540.                     
  541.                     if (!alreadyEnabled) // don't enable/disable sub-items every time, it flickers
  542.                         {
  543.                             GetDialogItemAsControl(dialog, kSliderTickMarks, &tempControl);
  544.                             HiliteControl(tempControl, enableItems ? 0 : kControlDisabledPart);
  545.                             GetDialogItemAsControl(dialog, kSliderReverse, &tempControl);
  546.                             HiliteControl(tempControl, enableItems ? 0 : kControlDisabledPart);
  547.                         }
  548.                 }
  549.         }
  550.  
  551.     if ( itemHit == kStdCancelItemIndex )
  552.     {
  553.         DisposeDialog( dialog );
  554.         return nil;
  555.     }
  556.     
  557.     GetDialogItemAsControl(dialog, kSliderNonDirectional, &tempControl);
  558.  
  559.     if (GetControlValue(tempControl))
  560.         procID += kControlSliderNonDirectional;
  561.     else
  562.         {  // kSliderNonDirectional overrides all others..
  563.             GetDialogItemAsControl(dialog, kSliderTickMarks, &tempControl);
  564.         
  565.             if (GetControlValue(tempControl))
  566.                 procID += kControlSliderHasTickMarks;
  567.             
  568.             GetDialogItemAsControl(dialog, kSliderReverse, &tempControl);
  569.         
  570.             if (GetControlValue(tempControl))
  571.                 procID += kControlSliderReverseDirection;
  572.         }
  573.  
  574.     DisposeDialog( dialog );
  575.     
  576.     return(NewControl( window, &bounds, "\pSlider", false, 5, 0, 100, procID, 0));  // value is number of tickmarks
  577. }
  578.  
  579. ControlHandle
  580. CreateClock( WindowPtr window )
  581. {
  582.     DialogPtr        dialog;
  583.     SInt16            itemHit = 0;
  584.     ControlHandle    control = nil,dialogControl,tempControl;
  585.     Rect            bounds = { 0, 0, 23, 125 };
  586.     SInt16        procIDs[4] = {kControlClockTimeProc, kControlClockTimeSecondsProc, kControlClockDateProc, kControlClockMonthYearProc};
  587.     short itemIndex,kindIndex=0;
  588.     
  589.     dialog = GetNewDialog( 2017, nil, (WindowPtr)-1L );
  590.     if ( dialog == nil ) return nil;
  591.  
  592.     SetDialogDefaultItem( dialog, kStdOkItemIndex );
  593.     SetDialogCancelItem( dialog, kStdCancelItemIndex );
  594.     GetDialogItemAsControl(dialog, kClockTime, &tempControl);
  595.     SetControlValue(tempControl, 1);
  596.     ShowWindow(dialog);
  597.         
  598.     while ((itemHit != kStdOkItemIndex) && (itemHit != kStdCancelItemIndex))
  599.         {
  600.             ModalDialog( nil, &itemHit );
  601.             
  602.             GetDialogItemAsControl(dialog, itemHit, &dialogControl);
  603.             
  604.             if ((itemHit >= kClockTime) && (itemHit <= kClockMonthYear) && !GetControlValue(dialogControl)) 
  605.             // if it's radio buttons and the radio button isn't already selected
  606.                 {
  607.                     for(itemIndex=kClockTime;itemIndex<=kClockMonthYear;itemIndex++)
  608.                         {
  609.                             GetDialogItemAsControl(dialog, itemIndex, &tempControl);
  610.                         
  611.                             if (itemIndex == itemHit)
  612.                                 SetControlValue(tempControl, 1);
  613.                             else
  614.                                 SetControlValue(tempControl, 0);
  615.                         }
  616.                 }
  617.                         
  618.         }
  619.  
  620.     if ( itemHit == kStdCancelItemIndex )
  621.     {
  622.         DisposeDialog( dialog );
  623.         return nil;
  624.     }
  625.  
  626.     for(itemIndex=kClockTime;itemIndex<=kClockMonthYear;itemIndex++)
  627.     {    
  628.         GetDialogItemAsControl(dialog, itemIndex, &tempControl);
  629.         
  630.         if (GetControlValue(tempControl))
  631.             kindIndex = itemIndex - kClockTime;
  632.     }
  633.  
  634.     DisposeDialog( dialog );
  635.     
  636.     control = NewControl( window, &bounds, "\pClock", false, kControlClockNoFlags, 0, 0, procIDs[kindIndex], 0 );
  637.  
  638.     SetKeyboardFocus(window, control, kControlFocusNextPart);
  639.     
  640.     return(control);
  641. }
  642.  
  643. ControlHandle
  644. CreateStaticText( WindowPtr window )
  645. {
  646.     DialogPtr        dialog;
  647.     SInt16            itemHit = 0;
  648.     ControlHandle    control = nil;
  649.     Rect            bounds = { 20, 20, 52, 200 };
  650.     DialogItemType    dummyType;
  651.     Handle            textItem;
  652.     Rect            dummyRect;
  653.     Str255            text;
  654.     
  655.     dialog = GetNewDialog( 2015, nil, (WindowPtr)-1L );
  656.     if ( dialog == nil ) return nil;
  657.  
  658.     SetDialogDefaultItem( dialog, kSTOKButton );
  659.     SetDialogCancelItem( dialog, kSTCancelButton );
  660.         
  661.     while ( itemHit != kSTCancelButton && itemHit != kSTOKButton )
  662.         ModalDialog( nil, &itemHit );
  663.         
  664.  
  665.     if ( itemHit == kSTCancelButton )
  666.     {
  667.         DisposeDialog( dialog );
  668.         return nil;
  669.     }
  670.     
  671.     GetDialogItem(dialog, 3, &dummyType, &textItem, &dummyRect);
  672.     
  673.     GetDialogItemText(textItem, text);
  674.  
  675.     DisposeDialog( dialog );
  676.     
  677.     control = NewControl( window, &bounds, "\pStatic Text", false, 0, 0, 0, kControlStaticTextProc, 0 );
  678.     
  679.     if (!control)
  680.         return(nil);
  681.     
  682.     SetControlData(control, kControlNoPart, kControlStaticTextTextTag, *text, (Ptr) &(text[1]));
  683.  
  684.     return(control);
  685. }
  686.  
  687.  
  688.  
  689. ControlHandle
  690. CreateFinderHeader( WindowPtr window )
  691. {
  692.     DialogPtr        dialog;
  693.     SInt16            itemHit = 0;
  694.     ControlHandle    control = nil;
  695.     SInt16            type;
  696.     Handle            handle;
  697.     Rect            rect;
  698.     Rect            bounds = { 0, 0, 0, 0 };
  699.     SInt16            procID;
  700.     Str255            text;
  701.     SInt32            number;
  702.     ControlHandle    tempControl;
  703.     
  704.     dialog = GetNewDialog( 2003, nil, (WindowPtr)-1L );
  705.     if ( dialog == nil ) return nil;
  706.  
  707.     SetDialogDefaultItem( dialog, kFHOKButton );
  708.     SetDialogCancelItem( dialog, kFHCancelButton );
  709.         
  710.     while ( itemHit != kFHCancelButton && itemHit != kFHOKButton )
  711.     {
  712.         ModalDialog( nil, &itemHit );
  713.         
  714.         GetDialogItemAsControl( dialog, itemHit, &tempControl );
  715.         switch ( itemHit )
  716.         {
  717.             case kFHListViewCheck:
  718.                 SetControlValue( tempControl, !GetControlValue( tempControl ) );
  719.                 break;
  720.         }
  721.     }
  722.     
  723.     if ( itemHit == kFHCancelButton )
  724.     {
  725.         DisposeDialog( dialog );
  726.         return nil;
  727.     }
  728.     
  729.     procID = kControlWindowHeaderProc;
  730.  
  731.     GetDialogItemAsControl( dialog, kFHListViewCheck, &tempControl );
  732.     if ( GetControlValue( tempControl ) == 1 )
  733.         procID |= 1;
  734.  
  735.     GetDialogItem( dialog, kFHHeightText, &type, &handle, &rect );
  736.     GetDialogItemText( handle, text );
  737.     StringToNum( text, &number );
  738.     bounds.bottom = number;
  739.     
  740.     GetDialogItem( dialog, kFHWidthText, &type, &handle, &rect );
  741.     GetDialogItemText( handle, text );
  742.     StringToNum( text, &number );
  743.     bounds.right = number;
  744.     
  745.     DisposeDialog( dialog );
  746.     
  747.     control = NewControl( window, &bounds, "\p", false, 0, 0, 0, procID, 0 );
  748.     if ( control == nil ) return nil;
  749.     
  750.     return control;
  751. }
  752.  
  753. ControlHandle
  754. CreateIconCDEF( WindowPtr window )
  755. {
  756.     return CreatePictureOrIconCDEF( window, kControlIconProc );
  757. }
  758.  
  759. ControlHandle
  760. CreatePictureCDEF( WindowPtr window )
  761. {
  762.     return CreatePictureOrIconCDEF( window, kControlPictureProc );
  763. }
  764.  
  765. static ControlHandle
  766. CreatePictureOrIconCDEF( WindowPtr window, SInt16 procID )
  767. {
  768.     DialogPtr        dialog;
  769.     SInt16            itemNo;
  770.     SInt16            type;
  771.     Handle            handle;
  772.     Rect            rect;
  773.     Str255            text;
  774.     SInt32            resID, height, width;
  775.     Rect            bounds = { 0, 0, 0, 0 };
  776.     ControlKeyFilterUPP    filterProc;
  777.     ControlHandle        tempControl;
  778.     
  779.     dialog = GetNewDialog( 2005, nil, (WindowPtr)-1L );
  780.     if ( dialog == nil ) return nil;
  781.     
  782.     if ( procID == kControlIconProc )
  783.         SetWTitle( dialog, "\pIcon CDEF" );
  784.     else
  785.         SetWTitle( dialog, "\pPicture CDEF" );
  786.         
  787.     SetDialogDefaultItem( dialog, kIconOK );
  788.     SetDialogCancelItem( dialog, kIconCancel );
  789.     
  790.     filterProc = NewControlKeyFilterProc( NumericFilter );
  791.     GetDialogItemAsControl( dialog, kIconResIDText, &tempControl );
  792.     SetEditTextKeyFilter( tempControl, filterProc );
  793.     GetDialogItemAsControl( dialog, kIconHeightText, &tempControl );
  794.     SetEditTextKeyFilter( tempControl, filterProc );
  795.     GetDialogItemAsControl( dialog, kIconWidthText, &tempControl );
  796.     SetEditTextKeyFilter( tempControl, filterProc );
  797.                     
  798.     ShowWindow(dialog);
  799.                     
  800.     while( itemNo != kIconCancel && itemNo != kIconOK )
  801.     {
  802.         ModalDialog( nil, &itemNo );
  803.  
  804.         GetDialogItemAsControl( dialog, itemNo, &tempControl );
  805.         switch ( itemNo )
  806.         {
  807.             case kIconNoHitCheck:
  808.                 SetControlValue( tempControl, !GetControlValue( tempControl ) );
  809.                 break;
  810.  
  811.             case kIconUseRectCheck:
  812.                 SetControlValue( tempControl, !GetControlValue( tempControl ) );
  813.                 if ( GetControlValue( tempControl ) == 1 )
  814.                 {
  815.                     GetDialogItemAsControl( dialog, kIconHeightLabelText, &tempControl );
  816.                     DeactivateControl( tempControl );
  817.                     GetDialogItemAsControl( dialog, kIconWidthLabelText, &tempControl );
  818.                     DeactivateControl( tempControl );
  819.                     GetDialogItemAsControl( dialog, kIconHeightText, &tempControl );
  820.                     DeactivateControl( tempControl );
  821.                     GetDialogItemAsControl( dialog, kIconWidthText, &tempControl );
  822.                     DeactivateControl( tempControl );
  823.                 }
  824.                 else
  825.                 {
  826.                     GetDialogItemAsControl( dialog, kIconHeightLabelText, &tempControl );
  827.                     ActivateControl( tempControl );
  828.                     GetDialogItemAsControl( dialog, kIconWidthLabelText, &tempControl );
  829.                     ActivateControl( tempControl );
  830.                     GetDialogItemAsControl( dialog, kIconHeightText, &tempControl );
  831.                     ActivateControl( tempControl );
  832.                     GetDialogItemAsControl( dialog, kIconWidthText, &tempControl );
  833.                     ActivateControl( tempControl );
  834.                 }
  835.                 break;
  836.         }
  837.     }
  838.     DisposeRoutineDescriptor( filterProc );
  839.  
  840.     if ( itemNo == kIconCancel )
  841.     {
  842.         DisposeDialog( dialog );
  843.         return nil;
  844.     }
  845.  
  846.     GetDialogItem( dialog, kIconResIDText, &type, &handle, &rect );
  847.     GetDialogItemText( handle, text );
  848.     StringToNum( text, &resID );
  849.     
  850.     GetDialogItemAsControl( dialog, kIconUseRectCheck, &tempControl );
  851.     if ( GetControlValue( tempControl ) == 1 )
  852.     {
  853.         if ( procID == kControlPictureProc )
  854.             GetPictureSize( resID, &height, &width );
  855.         else
  856.             GetIconSize( resID, &height, &width );
  857.     }
  858.     else
  859.     {
  860.         GetDialogItem( dialog, kIconHeightText, &type, &handle, &rect );
  861.         GetDialogItemText( handle, text );
  862.         StringToNum( text, &height );
  863.         
  864.         GetDialogItem( dialog, kIconWidthText, &type, &handle, &rect );
  865.         GetDialogItemText( handle, text );
  866.         StringToNum( text, &width );
  867.     }    
  868.     GetDialogItemAsControl( dialog, kIconNoHitCheck, &tempControl );
  869.     if ( GetControlValue( tempControl ) == 1 )
  870.         procID |= 1;
  871.     
  872.     DisposeDialog( dialog );
  873.     
  874.     bounds.bottom = bounds.top + height;
  875.     bounds.right = bounds.left + width;
  876.     return(NewControl( window, &bounds, "\p", false, resID, 0, 0, procID, 0 ));
  877. }
  878.  
  879. ControlHandle
  880. CreateProgressBar( WindowPtr window )
  881. {
  882.     DialogPtr        dialog;
  883.     SInt16            itemHit = 0;
  884.     ControlHandle    control = nil;
  885.     SInt16            type;
  886.     Handle            handle;
  887.     Rect            rect;
  888.     Rect            bounds = { 0, 0, 16, 0 };
  889.     Str255            text;
  890.     SInt32            number;
  891.     Boolean            indeterminate;
  892.     ControlHandle    tempControl;
  893.     
  894.     dialog = GetNewDialog( 2006, nil, (WindowPtr)-1L );
  895.     if ( dialog == nil ) return nil;
  896.  
  897.     SetDialogDefaultItem( dialog, kProgOKButton );
  898.     SetDialogCancelItem( dialog, kProgCancelButton );
  899.         
  900.     while ( itemHit != kProgCancelButton && itemHit != kProgOKButton )
  901.     {
  902.         ModalDialog( nil, &itemHit );
  903.         
  904.         GetDialogItemAsControl( dialog, itemHit, &tempControl );
  905.         switch ( itemHit )
  906.         {
  907.             case kProgIndeterminateCheck:
  908.                 SetControlValue( tempControl, !GetControlValue( tempControl ) );
  909.                 break;
  910.         }
  911.     }
  912.     
  913.     if ( itemHit == kProgCancelButton )
  914.     {
  915.         DisposeDialog( dialog );
  916.         return nil;
  917.     }
  918.     
  919.     GetDialogItemAsControl( dialog, kProgIndeterminateCheck, &tempControl );
  920.     indeterminate = ( GetControlValue( tempControl ) == 1 );
  921.  
  922.     GetDialogItem( dialog, kProgLengthText, &type, &handle, &rect );
  923.     GetDialogItemText( handle, text );
  924.     StringToNum( text, &number );
  925.     bounds.right = number;
  926.     
  927.     DisposeDialog( dialog );
  928.     
  929.     control = NewControl( window, &bounds, "\p", false, 50, 0, 100, kControlProgressBarProc, 0 );
  930.     if ( control == nil ) return nil;
  931.     
  932.     if ( indeterminate )
  933.         SetProgressIndicatorState( control, false );
  934.         
  935.     return control;
  936. }
  937.  
  938. //——————————————————————————————————————————————————————————————————————————————————————
  939. //    • CreateLittleArrows                                                    PUBLIC
  940. //——————————————————————————————————————————————————————————————————————————————————————
  941. //    Creates the little arrows CDEF. We just use a standard size - no options.
  942. //
  943. ControlHandle
  944. CreateLittleArrows( WindowPtr window )
  945. {
  946.     Rect        bounds = { 0, 0, 24, 13 };
  947.     
  948.     return NewControl( window, &bounds, "\p", false, 0, 0, 100, kControlLittleArrowsProc, 0 );
  949. }
  950.  
  951. //——————————————————————————————————————————————————————————————————————————————————————
  952. //    • CreateGroupBox                                                            PUBLIC
  953. //——————————————————————————————————————————————————————————————————————————————————————
  954. //    Creates a group box.
  955. //
  956. ControlHandle
  957. CreateGroupBox( WindowPtr window )
  958. {
  959.     enum { kPrimary, kSecondary };
  960.     enum { kText = 1, kCheckBox, kPopup };
  961.     
  962.     DialogPtr        dialog;
  963.     SInt16            itemHit = 0;
  964.     ControlHandle        control = nil;
  965.     SInt16            type;
  966.     Handle            handle;
  967.     Rect            rect;
  968.     Rect            bounds = { 0, 0, 16, 0 };
  969.     ControlKeyFilterUPP    filterProc;
  970.     Str255            text, title;
  971.     SInt32            height, width, min, max, value;
  972.     SInt16            procID;
  973.     ControlHandle    tempControl;
  974.     
  975.     dialog = GetNewDialog( 2007, nil, (WindowPtr)-1L );
  976.     if ( dialog == nil ) return nil;
  977.  
  978.     filterProc = NewControlKeyFilterProc( NumericFilter );
  979.  
  980.     GetDialogItemAsControl( dialog, kGroupMenuIDLabelText, &tempControl );
  981.     DeactivateControl( tempControl );
  982.     GetDialogItemAsControl( dialog, kGroupMenuIDText, &tempControl );
  983.     DeactivateControl( tempControl );
  984.  
  985.     GetDialogItemAsControl( dialog, kGroupMenuIDText, &tempControl );
  986.     SetEditTextKeyFilter( tempControl, filterProc );
  987.     GetDialogItemAsControl( dialog, kGroupHeightText, &tempControl );
  988.     SetEditTextKeyFilter( tempControl, filterProc );
  989.     GetDialogItemAsControl( dialog, kGroupWidthText, &tempControl );
  990.     SetEditTextKeyFilter( tempControl, filterProc );
  991.  
  992.     SetDialogDefaultItem( dialog, kGroupOKButton );
  993.     SetDialogCancelItem( dialog, kGroupCancelButton );
  994.     
  995.     while ( itemHit != kGroupCancelButton && itemHit != kGroupOKButton )
  996.     {
  997.         ModalDialog( nil, &itemHit );
  998.         
  999.         GetDialogItemAsControl( dialog, itemHit, &tempControl );
  1000.         switch ( itemHit )
  1001.         {
  1002.             case kGroupVariantPopup:
  1003.                 if ( GetControlValue( tempControl ) == kPopup )
  1004.                 {
  1005.                     GetDialogItemAsControl( dialog, kGroupMenuIDLabelText, &tempControl );
  1006.                     ActivateControl( tempControl );
  1007.                     GetDialogItemAsControl( dialog, kGroupMenuIDText, &tempControl );
  1008.                     ActivateControl( tempControl );
  1009.                 }
  1010.                 else
  1011.                 {
  1012.                     GetDialogItemAsControl( dialog, kGroupMenuIDLabelText, &tempControl );
  1013.                     DeactivateControl( tempControl );
  1014.                     GetDialogItemAsControl( dialog, kGroupMenuIDText, &tempControl );
  1015.                     DeactivateControl( tempControl );
  1016.                 }
  1017.         }
  1018.     }
  1019.     DisposeRoutineDescriptor( filterProc );
  1020.     
  1021.     if ( itemHit == kGroupCancelButton )
  1022.     {
  1023.         DisposeDialog( dialog );
  1024.         return nil;
  1025.     }
  1026.     
  1027.         // Add the primary/secondary variant bit in
  1028.         
  1029.     procID = kControlGroupBoxTextTitleProc;
  1030.     
  1031.     GetDialogItemAsControl( dialog, kGroupRadioGroup, &tempControl );
  1032.     if ( GetControlValue( tempControl ) == 2 )
  1033.         procID |= 4;
  1034.     
  1035.         // Calculate the bounding rectangle based on width/height
  1036.         
  1037.     GetDialogItem( dialog, kGroupHeightText, &type, &handle, &rect );
  1038.     GetDialogItemText( handle, text );
  1039.     StringToNum( text, &height );
  1040.     GetDialogItem( dialog, kGroupWidthText, &type, &handle, &rect );
  1041.     GetDialogItemText( handle, text );
  1042.     StringToNum( text, &width );
  1043.  
  1044.     bounds.bottom = height;
  1045.     bounds.right = width;
  1046.     
  1047.         // Get the title of the control
  1048.         
  1049.     GetDialogItem( dialog, kGroupTitleText, &type, &handle, &rect );
  1050.     GetDialogItemText( handle, title );
  1051.     
  1052.     min = max = value = 0;
  1053.     
  1054.     GetDialogItemAsControl( dialog, kGroupVariantPopup, &tempControl );
  1055.     switch ( GetControlValue( tempControl ) )
  1056.     {
  1057.         case kCheckBox:
  1058.             procID |= 1;
  1059.             break;
  1060.         
  1061.         case kPopup:
  1062.             procID |= 2;
  1063.             GetDialogItem( dialog, kGroupMenuIDText, &type, &handle, &rect );
  1064.             GetDialogItemText( handle, text );
  1065.             StringToNum( text, &min );
  1066.             break;
  1067.     }            
  1068.     DisposeDialog( dialog );
  1069.  
  1070.     return NewControl( window, &bounds, title, false, value, min, max, procID, 0 );
  1071. }
  1072.  
  1073. //——————————————————————————————————————————————————————————————————————————————————————
  1074. //    • CreatePlacard                                                            PUBLIC
  1075. //——————————————————————————————————————————————————————————————————————————————————————
  1076. //    This routine creates a placard in any size the user wants.
  1077. //
  1078. ControlHandle
  1079. CreatePlacard( WindowPtr window )
  1080. {
  1081.     DialogPtr            dialog;
  1082.     SInt16                itemHit = 0;
  1083.     ControlHandle        control = nil;
  1084.     SInt16                type;
  1085.     Handle                handle;
  1086.     Rect                rect;
  1087.     Rect                bounds = { 0, 0, 0, 0 };
  1088.     Str255                text;
  1089.     SInt32                number;
  1090.     ControlKeyFilterUPP    filterProc;
  1091.     ControlHandle        tempControl;
  1092.     
  1093.     dialog = GetNewDialog( 2008, nil, (WindowPtr)-1L );
  1094.     if ( dialog == nil ) return nil;
  1095.  
  1096.     filterProc = NewControlKeyFilterProc( NumericFilter );
  1097.  
  1098.     GetDialogItemAsControl( dialog, kPlacardHeightText, &tempControl );
  1099.     SetEditTextKeyFilter( tempControl, filterProc );
  1100.     GetDialogItemAsControl( dialog, kPlacardWidthText, &tempControl );
  1101.     SetEditTextKeyFilter( tempControl, filterProc );
  1102.  
  1103.     SetDialogDefaultItem( dialog, kPlacardOKButton );
  1104.     SetDialogCancelItem( dialog, kPlacardCancelButton );
  1105.         
  1106.     while ( itemHit != kPlacardCancelButton && itemHit != kPlacardOKButton )
  1107.     {
  1108.         ModalDialog( nil, &itemHit );
  1109.     }
  1110.     DisposeRoutineDescriptor( filterProc );
  1111.     
  1112.     if ( itemHit == kPlacardCancelButton )
  1113.     {
  1114.         DisposeDialog( dialog );
  1115.         return nil;
  1116.     }
  1117.     
  1118.     GetDialogItem( dialog, kPlacardHeightText, &type, &handle, &rect );
  1119.     GetDialogItemText( handle, text );
  1120.     StringToNum( text, &number );
  1121.     bounds.bottom = number;
  1122.     
  1123.     GetDialogItem( dialog, kPlacardWidthText, &type, &handle, &rect );
  1124.     GetDialogItemText( handle, text );
  1125.     StringToNum( text, &number );
  1126.     bounds.right = number;
  1127.     
  1128.     DisposeDialog( dialog );
  1129.     
  1130.     control = NewControl( window, &bounds, "\p", false, 0, 0, 0, kControlPlacardProc, 0 );
  1131.     if ( control == nil ) return nil;
  1132.     
  1133.     return control;
  1134. }
  1135.  
  1136. //——————————————————————————————————————————————————————————————————————————————————————
  1137. //    • CreatePopupArrow                                                        PUBLIC
  1138. //——————————————————————————————————————————————————————————————————————————————————————
  1139. //    This routine creates a popup arrow in any direction and size the user wants.
  1140. //
  1141. ControlHandle
  1142. CreatePopupArrow( WindowPtr window )
  1143. {
  1144.     enum { kEast = 1, kWest, kNorth, kSouth };
  1145.     
  1146.     DialogPtr        dialog;
  1147.     SInt16            itemHit = 0;
  1148.     ControlHandle    control = nil;
  1149.     Rect            bounds = { 0, 0, 16, 16 };
  1150.     SInt16            procID;
  1151.     ControlHandle    tempControl;
  1152.     
  1153.     dialog = GetNewDialog( 2009, nil, (WindowPtr)-1L );
  1154.     if ( dialog == nil ) return nil;
  1155.  
  1156.     SetDialogDefaultItem( dialog, kPopArrowOKButton );
  1157.     SetDialogCancelItem( dialog, kPopArrowCancelButton );
  1158.         
  1159.     while ( itemHit != kPopArrowCancelButton && itemHit != kPopArrowOKButton )
  1160.     {
  1161.         ModalDialog( nil, &itemHit );
  1162.         
  1163.         GetDialogItemAsControl( dialog, itemHit, &tempControl );
  1164.         switch ( itemHit )
  1165.         {
  1166.             case kPopArrowSmallCheck:
  1167.                 SetControlValue( tempControl, !GetControlValue( tempControl ) );
  1168.                 break;
  1169.         }
  1170.     }
  1171.     
  1172.     if ( itemHit == kPopArrowCancelButton )
  1173.     {
  1174.         DisposeDialog( dialog );
  1175.         return nil;
  1176.     }
  1177.     
  1178.     procID = kControlPopupArrowEastProc;
  1179.  
  1180.     GetDialogItemAsControl( dialog, kPopArrowSmallCheck, &tempControl );
  1181.     if ( GetControlValue( tempControl ) == 1 )
  1182.         procID |= 4;
  1183.  
  1184.     GetDialogItemAsControl( dialog, kPopArrowDirPopup, &tempControl );
  1185.     switch ( GetControlValue( tempControl ) )
  1186.     {
  1187.         case kEast:
  1188.             break;
  1189.         
  1190.         case kWest:
  1191.             procID |= 1;
  1192.             break;
  1193.         
  1194.         case kNorth:
  1195.             procID |= 2;
  1196.             break;
  1197.         
  1198.         case kSouth:
  1199.             procID |= 3;
  1200.             break;
  1201.     }
  1202.     
  1203.     DisposeDialog( dialog );
  1204.     
  1205.     return(NewControl( window, &bounds, "\p", false, 0, 0, 0, procID, 0 ));
  1206. }
  1207.  
  1208. //——————————————————————————————————————————————————————————————————————————————————————
  1209. //    • CreateScrollBar                                                    PUBLIC
  1210. //——————————————————————————————————————————————————————————————————————————————————————
  1211. //    Creates a scroll bar.
  1212. //
  1213. ControlHandle
  1214. CreateScrollBar( WindowPtr window )
  1215. {
  1216.     DialogPtr        dialog;
  1217.     SInt16            itemHit = 0;
  1218.     ControlHandle        control = nil;
  1219.     SInt16            type;
  1220.     Handle            handle;
  1221.     Rect            rect;
  1222.     SInt32            length;
  1223.     Str255            text;
  1224.     Rect            bounds = { 0, 0, 16, 16 };
  1225.     ControlHandle    tempControl;
  1226.     
  1227.     dialog = GetNewDialog( 2010, nil, (WindowPtr)-1L );
  1228.     if ( dialog == nil ) return nil;
  1229.  
  1230.     SetDialogDefaultItem( dialog, kScrollOKButton );
  1231.     SetDialogCancelItem( dialog, kScrollCancelButton );
  1232.         
  1233.     while ( itemHit != kScrollCancelButton && itemHit != kScrollOKButton )
  1234.     {
  1235.         ModalDialog( nil, &itemHit );
  1236.     }
  1237.     
  1238.     if ( itemHit == kScrollCancelButton )
  1239.     {
  1240.         DisposeDialog( dialog );
  1241.         return nil;
  1242.     }
  1243.     
  1244.     GetDialogItem( dialog, kScrollLengthText, &type, &handle, &rect );
  1245.     GetDialogItemText( handle, text );
  1246.     StringToNum( text, &length );
  1247.     
  1248.     GetDialogItemAsControl( dialog, kScrollRadioGroup, &tempControl );
  1249.     if ( GetControlValue( tempControl ) == 1 )
  1250.         bounds.right = length;
  1251.     else
  1252.         bounds.bottom = length;
  1253.     
  1254.     DisposeDialog( dialog );
  1255.     
  1256.     return(NewControl( window, &bounds, "\p", false, 0, 0, 100, kControlScrollBarProc, 0 ));
  1257. }
  1258.  
  1259. //——————————————————————————————————————————————————————————————————————————————————————
  1260. //    • CreateTabs                                                        PUBLIC
  1261. //——————————————————————————————————————————————————————————————————————————————————————
  1262. //    Creates a standard push button.
  1263. //
  1264. ControlHandle
  1265. CreateTabs( WindowPtr window )
  1266. {
  1267.     DialogPtr        dialog;
  1268.     SInt16            itemHit = 0;
  1269.     ControlHandle    control = nil;
  1270.     ControlHandle        handle;
  1271.     Str255            text;
  1272.     Rect            bounds = { 0, 0, 100, 300 };
  1273.     Boolean            useIcons;
  1274.     ControlKeyFilterUPP    filterProc;
  1275.     SInt16            procID;
  1276.     short            i;
  1277.     ControlTabInfoRec infoRec;
  1278.     SInt32            numTabs;
  1279.     unsigned char            *titles[4] = {"\pA","\pBunch","\pOf","\pTitles."};
  1280.     
  1281.     dialog = GetNewDialog( 2018, nil, (WindowPtr)-1L );
  1282.     if ( dialog == nil ) return nil;
  1283.  
  1284.     SetDialogDefaultItem( dialog, kStdOkItemIndex );
  1285.     SetDialogCancelItem( dialog, kStdCancelItemIndex );
  1286.  
  1287.     filterProc = NewControlKeyFilterProc( NumericFilter );
  1288.  
  1289.     GetDialogItemAsControl( dialog, kTabNumberTabs, &control );
  1290.     SetEditTextKeyFilter( control, filterProc );
  1291.         
  1292.     while ( itemHit != kStdCancelItemIndex && itemHit != kStdOkItemIndex )
  1293.     {
  1294.         ModalDialog( nil, &itemHit );
  1295.         
  1296.         GetDialogItemAsControl( dialog, itemHit, &handle );
  1297.         if (itemHit == kTabUseIcon)
  1298.             SetControlValue( (ControlHandle)handle, !GetControlValue( (ControlHandle)handle ) );
  1299.     }
  1300.     
  1301.     if ( itemHit == kStdCancelItemIndex )
  1302.     {
  1303.         DisposeDialog( dialog );
  1304.         return nil;
  1305.     }
  1306.     
  1307.     GetDialogItemAsControl( dialog, kTabNumberTabs, &handle );
  1308.     GetDialogItemText( (Handle) handle, text );
  1309.     StringToNum( text, &numTabs );
  1310.     
  1311.     GetDialogItemAsControl( dialog, kTabSizeGroup, &handle);
  1312.     
  1313.     if (GetControlValue(handle) == 1)
  1314.         procID = kControlTabLargeProc;
  1315.     else
  1316.         procID = kControlTabSmallProc;
  1317.  
  1318.     GetDialogItemAsControl( dialog, kTabUseIcon, &handle);
  1319.     
  1320.     useIcons = GetControlValue(handle);
  1321.  
  1322.     DisposeDialog( dialog );
  1323.     
  1324.     control = NewControl( window, &bounds, text, false, 0, 0, numTabs, procID, 0 );
  1325.     if ( control == nil ) return nil;
  1326.  
  1327.     /**    now set the tab names manually (rather than via a tab# resource. The number of Tabs was set in the NewControl maximum parameter**/
  1328.         
  1329.     infoRec.version = kControlTabInfoVersionZero;
  1330.     infoRec.iconSuiteID = useIcons ? 128 : 0;
  1331.     
  1332.     for(i=1;i<=numTabs;i++)
  1333.         {
  1334.             // cycle through the sample titles
  1335.             memcpy(&infoRec.name,titles[(i-1) % 4], *titles[(i-1) % 4]+1);
  1336.             SetControlData(control, i, kControlTabInfoTag, sizeof(ControlTabInfoRec), (Ptr) &infoRec);
  1337.         }
  1338.     
  1339.     return control;
  1340. }
  1341.  
  1342.  
  1343.  
  1344.  
  1345. //——————————————————————————————————————————————————————————————————————————————————————
  1346. //    • CreatePushButton                                                        PUBLIC
  1347. //——————————————————————————————————————————————————————————————————————————————————————
  1348. //    Creates a standard push button.
  1349. //
  1350. ControlHandle
  1351. CreatePushButton( WindowPtr window )
  1352. {
  1353.     DialogPtr        dialog;
  1354.     SInt16            itemHit = 0;
  1355.     ControlHandle    control = nil;
  1356.     SInt16            type;
  1357.     Handle            handle;
  1358.     Rect            rect;
  1359.     Str255            text;
  1360.     Rect            bounds = { 0, 0, 22, 22 };
  1361.     Boolean            isDefault;
  1362.     SInt16            baseLine;
  1363.     ControlHandle    tempControl;
  1364.     
  1365.     dialog = GetNewDialog( 2012, nil, (WindowPtr)-1L );
  1366.     if ( dialog == nil ) return nil;
  1367.  
  1368.     SetDialogDefaultItem( dialog, kPushButtonOKButton );
  1369.     SetDialogCancelItem( dialog, kPushButtonCancelButton );
  1370.         
  1371.     while ( itemHit != kPushButtonCancelButton && itemHit != kPushButtonOKButton )
  1372.     {
  1373.         ModalDialog( nil, &itemHit );
  1374.         
  1375.         GetDialogItem( dialog, itemHit, &type, &handle, &rect );
  1376.         switch ( itemHit )
  1377.         {
  1378.             case kPushButtonDefaultCheck:
  1379.                 SetControlValue( (ControlHandle)handle, !GetControlValue( (ControlHandle)handle ) );
  1380.                 break;
  1381.         }
  1382.     }
  1383.     
  1384.     if ( itemHit == kPushButtonCancelButton )
  1385.     {
  1386.         DisposeDialog( dialog );
  1387.         return nil;
  1388.     }
  1389.     
  1390.     GetDialogItem( dialog, kPushButtonTitleText, &type, &handle, &rect );
  1391.     GetDialogItemText( handle, text );
  1392.     
  1393.     GetDialogItemAsControl( dialog, kPushButtonDefaultCheck, &tempControl );
  1394.     isDefault = (GetControlValue( tempControl ) == 1 );
  1395.         
  1396.     DisposeDialog( dialog );
  1397.     
  1398.     control = NewControl( window, &bounds, text, false, 0, 0, 1, kControlPushButtonProc, 0 );
  1399.     if ( control == nil ) return nil;
  1400.     
  1401.     if ( isDefault )
  1402.     {
  1403.         SetControlData( control, 0, kControlPushButtonDefaultTag, sizeof( isDefault ),
  1404.             (Ptr)&isDefault );
  1405.     }
  1406.     
  1407.     if ( GetBestControlRect( control, &bounds, &baseLine ) == noErr )
  1408.         (**control).contrlRect = bounds;
  1409.     
  1410.     return control;
  1411. }
  1412.  
  1413. //——————————————————————————————————————————————————————————————————————————————————————
  1414. //    • CreateCheckBox                                                            PUBLIC
  1415. //——————————————————————————————————————————————————————————————————————————————————————
  1416. //    Creates a standard check box.
  1417. //
  1418. ControlHandle
  1419. CreateCheckBox( WindowPtr window )
  1420. {
  1421.     return CreateCheckBoxOrRadioButton( window, kControlCheckBoxProc );
  1422. }
  1423.  
  1424. //——————————————————————————————————————————————————————————————————————————————————————
  1425. //    • CreateRadioButton                                                            PUBLIC
  1426. //——————————————————————————————————————————————————————————————————————————————————————
  1427. //    Creates a standard radio button.
  1428. //
  1429. ControlHandle
  1430. CreateRadioButton( WindowPtr window )
  1431. {
  1432.     return CreateCheckBoxOrRadioButton( window, kControlRadioButtonProc );
  1433. }
  1434.  
  1435. //——————————————————————————————————————————————————————————————————————————————————————
  1436. //    • CreateCheckBoxOrRadioButton                                                PRIVATE
  1437. //——————————————————————————————————————————————————————————————————————————————————————
  1438. //    Creates a standard check box or radio button.
  1439. //
  1440. static ControlHandle
  1441. CreateCheckBoxOrRadioButton( WindowPtr window, SInt16 procID )
  1442. {
  1443.     DialogPtr        dialog;
  1444.     SInt16            itemHit = 0;
  1445.     ControlHandle    control = nil;
  1446.     Handle            handle;
  1447.     Str255            text;
  1448.     Rect            bounds = { 0, 0, 22, 22 };
  1449.     SInt16            baseLine;
  1450.     
  1451.     dialog = GetNewDialog( 2013, nil, (WindowPtr)-1L );
  1452.     if ( dialog == nil ) return nil;
  1453.  
  1454.     GetDialogItemAsControl(dialog, kCheckBoxTitleText, (ControlHandle *) &handle);
  1455.     
  1456.     if ( procID == kControlCheckBoxProc )
  1457.         {
  1458.             SetWTitle( (WindowPtr) dialog, "\pCheck Box" );
  1459.             SetDialogItemText( handle, "\pCheck Box");
  1460.         }
  1461.     else
  1462.         {
  1463.             SetWTitle( (WindowPtr) dialog, "\pRadio Button" );
  1464.             SetDialogItemText( handle, "\pRadio Button");
  1465.         }
  1466.  
  1467.     SetDialogDefaultItem( dialog, kCheckBoxOKButton );
  1468.     SetDialogCancelItem( dialog, kCheckBoxCancelButton );
  1469.         
  1470.     ShowWindow(dialog);
  1471.     
  1472.     while ( itemHit != kCheckBoxCancelButton && itemHit != kCheckBoxOKButton )
  1473.     {
  1474.         ModalDialog( nil, &itemHit );
  1475.     }
  1476.     
  1477.     if ( itemHit == kCheckBoxCancelButton )
  1478.     {
  1479.         DisposeDialog( dialog );
  1480.         return nil;
  1481.     }
  1482.     
  1483.     GetDialogItemAsControl(dialog, kCheckBoxTitleText, (ControlHandle *) &handle);
  1484.     GetDialogItemText( handle, text );
  1485.     
  1486.     DisposeDialog( dialog );
  1487.     
  1488.     control = NewControl( window, &bounds, text, false, 0, 0, 2, procID, 0 );
  1489.     if ( control == nil ) return nil;
  1490.     
  1491.     if ( GetBestControlRect( control, &bounds, &baseLine ) == noErr )
  1492.         (**control).contrlRect = bounds;
  1493.     
  1494.     return control;
  1495. }
  1496.  
  1497.  
  1498. //——————————————————————————————————————————————————————————————————————————————————————
  1499. //    • CreateImageWell                                                        PUBLIC
  1500. //——————————————————————————————————————————————————————————————————————————————————————
  1501. //    This routine creates an image well.
  1502. //
  1503. ControlHandle
  1504. CreateImageWell( WindowPtr window )
  1505. {
  1506.     DialogPtr        dialog;
  1507.     SInt16            itemHit = 0;
  1508.     SInt16            type;
  1509.     Handle            handle;
  1510.     Rect            rect;
  1511.     Rect            bounds = { 0, 0, 0, 0 };
  1512.     Str255            text;
  1513.     SInt32            number;
  1514.     SInt32            resID, min;
  1515.     ControlKeyFilterUPP    filterProc;
  1516.     ControlHandle    tempControl;
  1517.     
  1518.     dialog = GetNewDialog( 2011, nil, (WindowPtr)-1L );
  1519.     if ( dialog == nil ) return nil;
  1520.  
  1521.     filterProc = NewControlKeyFilterProc( NumericFilter );
  1522.  
  1523.     GetDialogItemAsControl( dialog, kImageHeightText, &tempControl );
  1524.     SetEditTextKeyFilter( tempControl, filterProc );
  1525.  
  1526.     GetDialogItemAsControl( dialog, kImageWidthText, &tempControl );
  1527.     SetEditTextKeyFilter( tempControl, filterProc );
  1528.  
  1529.     GetDialogItemAsControl( dialog, kImageResIDText, &tempControl );
  1530.     SetEditTextKeyFilter( tempControl, filterProc );
  1531.  
  1532.     SetDialogDefaultItem( dialog, kImageOKButton );
  1533.     SetDialogCancelItem( dialog, kImageCancelButton );
  1534.         
  1535.     while ( itemHit != kImageCancelButton && itemHit != kImageOKButton )
  1536.     {
  1537.         ModalDialog( nil, &itemHit );
  1538.     }
  1539.     DisposeRoutineDescriptor( filterProc );
  1540.     
  1541.     if ( itemHit == kImageCancelButton )
  1542.     {
  1543.         DisposeDialog( dialog );
  1544.         return nil;
  1545.     }
  1546.     
  1547.     GetDialogItem( dialog, kImageHeightText, &type, &handle, &rect );
  1548.     GetDialogItemText( handle, text );
  1549.     StringToNum( text, &number );
  1550.     bounds.bottom = number;
  1551.     
  1552.     GetDialogItem( dialog, kImageWidthText, &type, &handle, &rect );
  1553.     GetDialogItemText( handle, text );
  1554.     StringToNum( text, &number );
  1555.     bounds.right = number;
  1556.     
  1557.     GetDialogItem( dialog, kImageResIDText, &type, &handle, &rect );
  1558.     GetDialogItemText( handle, text );
  1559.     StringToNum( text, &resID );
  1560.     
  1561.     GetDialogItemAsControl( dialog, kImageContentPopup, &tempControl );
  1562.     switch ( GetControlValue( tempControl ) )
  1563.     {
  1564.         case 1:
  1565.             min = kControlContentIconSuiteRes;
  1566.             break;
  1567.         
  1568.         case 2:
  1569.             min = kControlContentCIconRes;
  1570.             break;
  1571.         
  1572.         case 3:
  1573.             min = kControlContentPictRes;
  1574.             break;    
  1575.     }
  1576.     
  1577.     DisposeDialog( dialog );
  1578.     
  1579.     return NewControl( window, &bounds, "\p", false, resID, min, 0, kControlImageWellProc, 0 );
  1580. }
  1581.  
  1582. //——————————————————————————————————————————————————————————————————————————————————————
  1583. //    • GetIconSize                                                            UTILITY
  1584. //——————————————————————————————————————————————————————————————————————————————————————
  1585. //    This routine attempts to get the height and width of the icon specified by resID.
  1586. //    It assumes that ICONs are always 32x32. For cicns, we go into the resource and look
  1587. //    at the pixmap's bounding rectangle.
  1588. //
  1589. static void
  1590. GetPictureSize( SInt16 resID, SInt32* height, SInt32* width )
  1591. {
  1592.     PicHandle        picture;
  1593.     
  1594.     *height = 0;
  1595.     *width = 0;
  1596.     
  1597.     picture = GetPicture( resID );
  1598.     if ( picture == nil ) return;
  1599.     
  1600.     *height = (**picture).picFrame.bottom - (**picture).picFrame.top;
  1601.     *width = (**picture).picFrame.right - (**picture).picFrame.left;
  1602. }
  1603.  
  1604. //——————————————————————————————————————————————————————————————————————————————————————
  1605. //    • GetIconSize                                                            UTILITY
  1606. //——————————————————————————————————————————————————————————————————————————————————————
  1607. //    This routine attempts to get the height and width of the icon specified by resID.
  1608. //    It assumes that ICONs are always 32x32. For cicns, we go into the resource and look
  1609. //    at the pixmap's bounding rectangle.
  1610. //
  1611. static void
  1612. GetIconSize( SInt16 resID, SInt32* height, SInt32* width )
  1613. {
  1614.     Handle        icon;
  1615.     
  1616.     *height = 0;
  1617.     *width = 0;
  1618.     
  1619.     icon = GetResource( 'ICON', resID );
  1620.     if ( icon == nil )
  1621.     {
  1622.         icon = GetResource( 'cicn', resID );
  1623.         if ( icon == nil ) return;
  1624.     
  1625.         *height = (**(CIconHandle)icon).iconPMap.bounds.bottom - (**(CIconHandle)icon).iconPMap.bounds.top;
  1626.         *width = (**(CIconHandle)icon).iconPMap.bounds.right - (**(CIconHandle)icon).iconPMap.bounds.left;
  1627.     }
  1628.     else
  1629.     {    
  1630.         *height = *width = 32;
  1631.     }
  1632. }
  1633.  
  1634. //——————————————————————————————————————————————————————————————————————————————————————
  1635. //    • NumericFilter                                                            PUBLIC
  1636. //——————————————————————————————————————————————————————————————————————————————————————
  1637. //    This function is a key filter for edit text fields. It ensures that all input is
  1638. //    numeric. It also allows editing keys to pass thru so that the edit text actually
  1639. //    remains editable!
  1640. //
  1641. pascal ControlKeyFilterResult
  1642. NumericFilter( ControlHandle control, SInt16* keyCode, SInt16* charCode, SInt16* modifiers )
  1643. {
  1644. #pragma unused( control, keyCode, modifiers )
  1645.  
  1646.     if ( ((char)*charCode >= '0') && ((char)*charCode <= '9') )
  1647.         return kControlKeyFilterPassKey;
  1648.     
  1649.     switch ( *charCode )
  1650.     {
  1651.         case '-':
  1652.         case kLeftArrow:
  1653.         case kRightArrow:
  1654.         case kUpArrow:
  1655.         case kDownArrow:
  1656.         case kBackspace:
  1657.             return kControlKeyFilterPassKey;
  1658.  
  1659.         default:
  1660. //            SysBeep( 10 );
  1661.             return kControlKeyFilterBlockKey;
  1662.     }
  1663. }
  1664.