home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1999 / MacHack 1999.toast / The Hacks / DesktopDoubler / NubApp / Window.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1999-06-23  |  15.2 KB  |  1,088 lines  |  [TEXT/CWIE]

  1. #define DISABLE_LOCAL_CALLTRACE        1        // Set to 1 to disable Call Traces for this file.
  2. #define DISABLE_LOCAL_DEBUG            0        // Set to 1 to disable all debugging for this file.
  3. #include "DebugUtils.h"
  4.  
  5. #include <Dialogs.h>
  6. #include <stdarg.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include "Menu.h"
  11. #include "QDUtils.h"
  12. #include "Window.h"
  13.  
  14.  
  15.  
  16.  
  17.  
  18. enum
  19. {
  20.     kOKButtonID                = 1,
  21.     kCancelButtonID            = 2
  22. };
  23.  
  24.  
  25.  
  26.  
  27.  
  28. extern MenuManager                    *gMenuManager;
  29. extern WindowManager                *gWindowManager;
  30.  
  31.  
  32.  
  33.  
  34.  
  35. BaseWindowManager::BaseWindowManager(void)
  36. {
  37.     fSuspended = false;
  38. }
  39.  
  40.  
  41.  
  42.  
  43.  
  44. BaseWindowObject *BaseWindowManager::GetWindowObject(WindowPtr window)
  45. {
  46.     BaseWindowObject    *obj;
  47.     
  48.     
  49.     obj = fWindowList.GetFirst();
  50.     while(obj && (obj->fWindowID != window))
  51.         obj = obj->next;
  52.     
  53.     return obj;
  54. }
  55.  
  56.  
  57.  
  58.  
  59.  
  60. void BaseWindowManager::DoAddWindow(Window *window)
  61. {
  62.     BaseWindowObject    *obj;
  63.     
  64.     
  65.     obj = new BaseWindowObject;
  66.     if (obj != NULL)
  67.     {
  68.         obj->fWindowID = window->fWindow;
  69.         obj->fWindowObject = window;
  70.         fWindowList.Append(obj);
  71.         gMenuManager->DoWindowNotice(window,true);
  72.     }
  73. }
  74.  
  75.  
  76.  
  77.  
  78.  
  79. void BaseWindowManager::DoDeleteWindow(Window *window)
  80. {
  81.     BaseWindowObject    *obj;
  82.     
  83.     
  84.     obj = GetWindowObject(window->fWindow);
  85.     if (obj != NULL)
  86.     {
  87.         gMenuManager->DoWindowNotice(window,false);
  88.         fWindowList.Delete(obj);
  89.         delete obj;    
  90.     }
  91. }
  92.  
  93.  
  94.  
  95.  
  96.  
  97. void BaseWindowManager::DoClick(Point where,UInt32 modifiers,WindowPtr window,SInt32 part)
  98. {
  99.     Window    *win = DoGetWindow(window);
  100.     Window    *top;
  101.     
  102.     
  103.     // Don't let any other window have input or be able
  104.     // to layer switch if a modal dialog is the topmost
  105.     top = DoGetFrontWindow();
  106.     if ((win != top) && ((top->fFlags & (kDialog | kModal)) == (kDialog | kModal)))
  107.         return;
  108.     
  109.     if (win != NULL)
  110.         win->DoClick(where,modifiers,part);
  111. }
  112.  
  113.  
  114.  
  115.  
  116.  
  117. void BaseWindowManager::DoIdleTime(EventRecord *event,Point mouse,UInt32 modifiers)
  118. {
  119.     BaseWindowObject    *obj;
  120.     WindowPtr            window;
  121.     Window                *win;
  122.     SInt32                part;
  123.     
  124.     
  125.     if (!fSuspended)
  126.     {
  127.         win = NULL;
  128.         part = FindWindow(mouse,&window);
  129.         if (part == inContent)
  130.         {
  131.             win = DoGetWindow(window);
  132.             if ((win != NULL) && (win->fFlags & kActive))
  133.                 win->DoUpdateCursor(mouse,modifiers);
  134.             else
  135.                 win = NULL;
  136.         }
  137.         
  138.         if (win == NULL)
  139.             SetCursor(&qd.arrow);
  140.     }
  141.     
  142.     obj = fWindowList.GetFirst();
  143.     while(obj != NULL)
  144.     {
  145.         obj->fWindowObject->DoIdleTime(event,mouse,modifiers);
  146.         obj = obj->next;
  147.     }
  148. }
  149.  
  150.  
  151.  
  152.  
  153.  
  154. void BaseWindowManager::DoActivation(WindowPtr window,Boolean isActivating)
  155. {
  156.     Window    *win;
  157.     
  158.     
  159.     win = DoGetWindow(window);
  160.     if (win != NULL)
  161.     {
  162.         win->DoSetActivationState(isActivating);
  163.         gMenuManager->DoWindowActivation(win,isActivating);
  164.     }
  165. }
  166.  
  167.  
  168.  
  169.  
  170.  
  171. void BaseWindowManager::DoSuspendResume(EventRecord *event,Boolean isSuspend)
  172. {
  173.     BaseWindowObject    *obj;
  174.     
  175.     
  176.     obj = fWindowList.GetFirst();
  177.     while(obj != NULL)
  178.     {
  179.         obj->fWindowObject->DoSetSuspensionState(event,isSuspend);
  180.         obj = obj->next;
  181.     }
  182.     
  183.     fSuspended = isSuspend;
  184. }
  185.  
  186.  
  187.  
  188.  
  189.  
  190. Window *BaseWindowManager::DoGetFrontWindow(void)
  191. {
  192.     WindowPtr    window;
  193.     Window        *win;
  194.     
  195.     
  196.     // Floating windows are system windows
  197.     // do this actually is correct
  198.     window = FrontWindow();
  199.     while(window != NULL)
  200.     {
  201.         if (((WindowPeek)window)->visible)
  202.         {
  203.             win = DoGetWindow(window);
  204.             if (win != NULL)
  205.                 return win;
  206.         }
  207.         
  208.         window = (WindowPtr)((WindowPeek)window)->nextWindow;
  209.     }
  210.     
  211.     return NULL;
  212. }
  213.  
  214.  
  215.  
  216.  
  217.  
  218. Window *BaseWindowManager::DoGetNextWindow(Window *window)
  219. {
  220.     WindowPtr    next;
  221.     
  222.     
  223.     next = (WindowPtr)((WindowPeek)window->fWindow)->nextWindow;
  224.     while(next != NULL)
  225.     {
  226.         window = DoGetWindow(next);
  227.         if ((window != NULL) && ((WindowPeek)window)->visible)
  228.             return window;
  229.         
  230.         next = (WindowPtr)((WindowPeek)next)->nextWindow;
  231.     }
  232.     
  233.     return NULL;
  234. }
  235.  
  236.  
  237.  
  238.  
  239.  
  240. Window *BaseWindowManager::DoGetWindow(WindowPtr window)
  241. {
  242.     BaseWindowObject    *obj;
  243.     
  244.     
  245.     obj = GetWindowObject(window);
  246.     return obj ? obj->fWindowObject : NULL;
  247. }
  248.  
  249.  
  250.  
  251.  
  252.  
  253. // Do nothing constructor varient
  254. BaseWindow::BaseWindow(void)
  255. {
  256.     
  257. }
  258.  
  259.  
  260.  
  261.  
  262.  
  263. // Resource based window constructor varient
  264. BaseWindow::BaseWindow(UInt32 windowID)
  265. {
  266.     fWindow = ::GetNewCWindow(windowID,NULL,(WindowPtr)-1L);
  267.     if (fWindow != NULL)
  268.     {
  269.         fFlags = 0L;
  270.         gWindowManager->DoAddWindow(this);
  271.     }
  272. }
  273.  
  274.  
  275.  
  276.  
  277.  
  278. // Runtime based window constructor varient
  279. BaseWindow::BaseWindow(Boolean isFloatingWindow,short procID,Boolean goAwayFlag)
  280. {
  281.     Rect    bounds;
  282.     
  283.     
  284.     SetRect(&bounds,32,48,160,144);
  285.     if (isFloatingWindow)
  286.     {
  287.         dprintf(kDConPrefix "What, you think we do everything?\n");
  288.     }
  289.     else
  290.     {
  291.         fWindow = NewCWindow(    NULL,
  292.                                 &bounds,
  293.                                 "\p",
  294.                                 false,
  295.                                 procID,
  296.                                 (WindowPtr)(-1L),
  297.                                 goAwayFlag,
  298.                                 0L);
  299.         
  300.         if (fWindow != NULL)
  301.         {
  302.             fFlags = 0L;
  303.             gWindowManager->DoAddWindow(this);
  304.         }
  305.     }
  306. }
  307.  
  308.  
  309.  
  310.  
  311.  
  312. BaseWindow::~BaseWindow(void)
  313. {
  314.     if (fWindow != NULL)
  315.     {
  316.         gWindowManager->DoDeleteWindow(this);
  317.         if (fFlags & kFloater)
  318.         {
  319.             
  320.         }
  321.         else
  322.             DisposeWindow(fWindow);
  323.         fWindow = NULL;
  324.     }
  325. }
  326.  
  327.  
  328.  
  329.  
  330.  
  331. Boolean BaseWindow::DoGetParam(OSType param,SInt32 *value)
  332. {
  333.     return HandleGetParam(param,value);
  334. }
  335.  
  336.  
  337.  
  338.  
  339.  
  340. Boolean BaseWindow::DoSetParam(OSType param,SInt32 value)
  341. {
  342.     QDContext    context(fWindow);
  343.     
  344.     
  345.     return HandleSetParam(param,value);
  346. }
  347.  
  348.  
  349.  
  350.  
  351.  
  352. void BaseWindow::DoDialogEvent(EventRecord *event)
  353. {
  354.     DialogPtr    dialog;
  355.     short        item;
  356.     
  357.     
  358.     // Were really not a dialog...but
  359.     // lets do the right thing anyway
  360.     DialogSelect(event,&dialog,&item);
  361. }
  362.  
  363.  
  364.  
  365.  
  366.  
  367. void BaseWindow::DoClose(void)
  368. {
  369.     QDContext    context(fWindow);
  370.     
  371.     
  372.     HandleClose();
  373. }
  374.  
  375.  
  376.  
  377.  
  378.  
  379. void BaseWindow::DoKey(UInt32 key,UInt32 modifiers)
  380. {
  381.     QDContext    context(fWindow);
  382.     
  383.     
  384.     HandleKey(key,modifiers);
  385. }
  386.  
  387.  
  388.  
  389.  
  390.  
  391. void BaseWindow::DoClick(Point where,UInt32 modifiers,SInt32 part)
  392. {
  393.     QDContext    context(fWindow);
  394.     
  395.     
  396.     switch(part)
  397.     {
  398.         case inContent:
  399.             if (!(fFlags & (kActive | kFloater)))
  400.                 SelectWindow(fWindow);
  401.             else
  402.             {
  403.                 GlobalToLocal(&where);
  404.                 HandleClick(where,modifiers);
  405.             }
  406.             break;
  407.         
  408.         case inDrag:
  409.             HandleDrag(where);
  410.             break;
  411.         
  412.         case inGrow:
  413.             HandleGrow(where);
  414.             break;
  415.         
  416.         case inGoAway:
  417.             if (TrackGoAway(fWindow,where))
  418.                 HandleClose();
  419.             break;
  420.         
  421.         case inZoomIn:
  422.             if (TrackBox(fWindow,where,part))
  423.                 HandleZoomIn();
  424.             break;
  425.         
  426.         case inZoomOut:
  427.             if (TrackBox(fWindow,where,part))
  428.                 HandleZoomOut();
  429.             break;
  430.     }
  431. }
  432.  
  433.  
  434.  
  435.  
  436.  
  437. void BaseWindow::DoUpdate(void)
  438. {
  439.     QDContext    context(fWindow);
  440.     
  441.     
  442.     BeginUpdate((GrafPtr)fWindow);
  443.     HandleDraw();
  444.     EndUpdate((GrafPtr)fWindow);
  445. }
  446.  
  447.  
  448.  
  449.  
  450.  
  451. void BaseWindow::DoUpdateCursor(Point mouse,UInt32 modifiers)
  452. {
  453.     QDContext    context(fWindow);
  454.     
  455.     
  456.     GlobalToLocal(&mouse);
  457.     HandleCursorUpdate(mouse,modifiers);
  458. }
  459.  
  460.  
  461.  
  462.  
  463.  
  464. void BaseWindow::DoIdleTime(EventRecord *event,Point mouse,UInt32 modifiers)
  465. {
  466.     QDContext    context(fWindow);
  467.     
  468.     
  469.     GlobalToLocal(&mouse);
  470.     HandleIdleTime(mouse,modifiers);
  471.     
  472.     if ((fFlags & kDialog) && IsDialogEvent(event))
  473.         DoDialogEvent(event);
  474. }
  475.  
  476.  
  477.  
  478.  
  479.  
  480. void BaseWindow::DoSetActivationState(Boolean isActive)
  481. {
  482.     QDContext    context(fWindow);
  483.     
  484.     
  485.     if (isActive)
  486.     {
  487.         fFlags |= kActive;
  488.         HandleActivate();
  489.     }
  490.     else
  491.     {
  492.         fFlags &= ~kActive;
  493.         HandleDeactivate();
  494.     }
  495. }
  496.  
  497.  
  498.  
  499.  
  500.  
  501. void BaseWindow::DoSetSuspensionState(EventRecord *event,Boolean isSuspended)
  502. {
  503.     if (fFlags & kFloater)
  504.     {
  505.         if (isSuspended)
  506.         {
  507.             if (((WindowPeek)fWindow)->visible)
  508.             {
  509.                 fFlags |= kSuspended;
  510.                 ::HideWindow(fWindow);
  511.             }
  512.         }
  513.         else
  514.         {
  515.             if (fFlags & kSuspended)
  516.             {
  517.                 fFlags &= ~kSuspended;
  518.                 ::ShowWindow(fWindow);
  519.             }
  520.         }
  521.     }
  522.     else
  523.     {
  524.         if (isSuspended)
  525.         {
  526.             if (fFlags & kActive)
  527.             {
  528.                 fFlags |= kSuspended;
  529.                 DoSetActivationState(false);
  530.             }
  531.         }
  532.         else
  533.         {
  534.             if (fFlags & kSuspended)
  535.             {
  536.                 fFlags &= ~kSuspended;
  537.                 DoSetActivationState(true);
  538.             }
  539.         }
  540.     }
  541. }
  542.  
  543.  
  544.  
  545.  
  546.  
  547. Boolean BaseWindow::HandleGetParam(OSType param,SInt32 *value)
  548. {
  549.     switch(param)
  550.     {
  551.         case 'type':
  552.             *value = 'base';
  553.             return true;
  554.             break;
  555.         
  556.         default:
  557.             return false;
  558.             break;
  559.     }
  560. }
  561.  
  562.  
  563.  
  564.  
  565.  
  566. Boolean BaseWindow::HandleSetParam(OSType param,SInt32 value)
  567. {
  568.     switch(param)
  569.     {
  570.         default:
  571.             return false;
  572.             break;
  573.     }
  574. }
  575.  
  576.  
  577.  
  578.  
  579.  
  580. void BaseWindow::HandleClose(void)
  581. {
  582.     
  583. }
  584.  
  585.  
  586.  
  587.  
  588.  
  589. void BaseWindow::HandleZoomIn(void)
  590. {
  591.     
  592. }
  593.  
  594.  
  595.  
  596.  
  597.  
  598. void BaseWindow::HandleZoomOut(void)
  599. {
  600.     
  601. }
  602.  
  603.  
  604.  
  605.  
  606.  
  607. void BaseWindow::HandleDrag(Point start)
  608. {
  609.     Point    oldPos,newPos;
  610.     
  611.     
  612.     oldPos.h = fWindow->portRect.left;
  613.     oldPos.v = fWindow->portRect.top;
  614.     LocalToGlobal(&oldPos);
  615.     
  616.     DragWindow(fWindow,start,&qd.screenBits.bounds);
  617.     
  618.     newPos.h = fWindow->portRect.left;
  619.     newPos.v = fWindow->portRect.top;
  620.     LocalToGlobal(&newPos);
  621.     
  622.     if ((oldPos.h != newPos.h) || (oldPos.v != newPos.v))
  623.         HandleMove(newPos);
  624. }
  625.  
  626.  
  627.  
  628.  
  629.  
  630. void BaseWindow::HandleMove(Point where)
  631. {
  632.     
  633. }
  634.  
  635.  
  636.  
  637.  
  638.  
  639. void BaseWindow::HandleGrow(Point start)
  640. {
  641.     Rect    limits;
  642.     UInt32    dimensions;
  643.     
  644.     
  645.     limits.top = 64;
  646.     limits.left = 64;
  647.     limits.right = qd.screenBits.bounds.right;
  648.     limits.bottom = qd.screenBits.bounds.bottom;
  649.     
  650.     if (0 != (dimensions = GrowWindow(fWindow,start,&limits)))
  651.         HandleResize((dimensions >> 16),(dimensions & 0xFFFF));
  652. }
  653.  
  654.  
  655.  
  656.  
  657.  
  658. void BaseWindow::HandleResize(UInt32 height,UInt32 width)
  659. {
  660.     SizeWindow(fWindow,width,height,false);
  661.     InvalRect(&fWindow->portRect);
  662. }
  663.  
  664.  
  665.  
  666.  
  667.  
  668. void BaseWindow::HandleKey(UInt32 key,UInt32 modifiers)
  669. {
  670.     
  671. }
  672.  
  673.  
  674.  
  675.  
  676.  
  677. void BaseWindow::HandleClick(Point where,UInt32 modifiers)
  678. {
  679.     
  680. }
  681.  
  682.  
  683.  
  684.  
  685.  
  686. void BaseWindow::HandleActivate(void)
  687. {
  688.     
  689. }
  690.  
  691.  
  692.  
  693.  
  694.  
  695. void BaseWindow::HandleDeactivate(void)
  696. {
  697.     
  698. }
  699.  
  700.  
  701.  
  702.  
  703.  
  704. void BaseWindow::HandleCursorUpdate(Point mouse,UInt32 modifiers)
  705. {
  706.     
  707. }
  708.  
  709.  
  710.  
  711.  
  712.  
  713. void BaseWindow::HandleIdleTime(Point mouse,UInt32 modifiers)
  714. {
  715.     
  716. }
  717.  
  718.  
  719.  
  720.  
  721.  
  722. void BaseWindow::HandleDraw(void)
  723. {
  724.     
  725. }
  726.  
  727.  
  728.  
  729.  
  730.  
  731. BaseDialog::BaseDialog(UInt32 dialogID,Boolean isModal)
  732. {
  733.     fDialog = ::GetNewDialog(dialogID,NULL,(WindowPtr)-1L);
  734.     if (fDialog != NULL)
  735.     {
  736.         fFlags = isModal ? (kDialog | kModal) : kDialog;
  737.         fWindow = (WindowPtr)fDialog;
  738.         gWindowManager->DoAddWindow(this);
  739.         SelectWindow(fWindow);
  740.     }
  741. }
  742.  
  743.  
  744.  
  745.  
  746.  
  747. BaseDialog::~BaseDialog(void)
  748. {
  749.     if (fDialog != NULL)
  750.     {
  751.         gWindowManager->DoDeleteWindow(this);
  752.         DisposeDialog(fDialog);
  753.         fDialog = NULL;
  754.         fWindow = NULL;
  755.     }
  756. }
  757.  
  758.  
  759.  
  760.  
  761.  
  762. void BaseDialog::DoDialogEvent(EventRecord *event)
  763. {
  764.     QDContext    context(fWindow);
  765.     
  766.     
  767.     // We don't do any special preprocessing of
  768.     // events (yet) so just pass it straight thru
  769.     HandleDialogEvent(event);
  770. }
  771.  
  772.  
  773.  
  774.  
  775.  
  776. void BaseDialog::HandleDialogEvent(EventRecord *event)
  777. {
  778.     DialogPtr    dialog;
  779.     short        item;
  780.     
  781.     
  782.     if (HandleDialogEventFilter(event))
  783.     {
  784.         if (DialogSelect(event,&dialog,&item))
  785.             HandleDialogItemhit(item);
  786.         
  787.         // We have to check here to see if we've been deleted
  788.         // because HandleDialogItemhit might have been a hit to
  789.         // the OK or Cancel button.
  790.         if (fDialog != NULL)
  791.         {
  792.             // Automagically handle the hiliting
  793.             // and updating of the OK button
  794.             switch(event->what)
  795.             {
  796.                 case keyDown:
  797.                 case keyUp:
  798.                 case mouseDown:
  799.                 case mouseUp:
  800.                     // Only query the OK button state if something
  801.                     // happened that could have possibly changed it
  802.                     SetOKState(HandleOKButtonHiliteQuery());
  803.                     break;
  804.                 
  805.                 case updateEvt:
  806.                     DrawThickOutline(kOKButtonID);
  807.                     break;
  808.             }
  809.         }
  810.     }
  811. }
  812.  
  813.  
  814.  
  815.  
  816.  
  817. Boolean BaseDialog::HandleDialogEventFilter(EventRecord *event)
  818. {
  819.     ControlHandle    control;
  820.     short            type;
  821.     Rect            box;
  822.     
  823.     
  824.     // Filter out command/option/control keys
  825.     if (event->what == keyDown && (event->modifiers & (cmdKey | optionKey | controlKey)))
  826.         return false;
  827.     
  828.     switch(event->what)
  829.     {
  830.         case keyDown:
  831.         case autoKey:
  832.             switch(charCodeMask & event->message)
  833.             {
  834.                 case 0x0D:    // RETURN
  835.                     GetDialogItem(fDialog,kOKButtonID,&type,(Handle*)&control,&box);
  836.                     if ((type == 4) && (control[0]->contrlHilite == 0))
  837.                     {
  838.                         AnimateButtonPress(kOKButtonID);
  839.                         HandleDialogItemhit(kOKButtonID);
  840.                         return false;
  841.                     }
  842.                     break;
  843.                 
  844.                 case 0x1B:    // ESC
  845.                     GetDialogItem(fDialog,kCancelButtonID,&type,(Handle*)&control,&box);
  846.                     if ((type == 4) && (control[0]->contrlHilite == 0))
  847.                     {
  848.                         AnimateButtonPress(kCancelButtonID);
  849.                         HandleDialogItemhit(kCancelButtonID);
  850.                         return false;
  851.                     }
  852.                     break;
  853.             }
  854.             break;
  855.     }
  856.     
  857.     // Continue processing event
  858.     return true;
  859. }
  860.  
  861.  
  862.  
  863.  
  864.  
  865. void BaseDialog::HandleDialogItemhit(short item)
  866. {
  867.     // Default behavior for OK and Cancel
  868.     // button hits are to dismiss the dialog
  869.     switch(item)
  870.     {
  871.         case kOKButtonID:
  872.         case kCancelButtonID:
  873.             delete this;
  874.             break;
  875.     }
  876. }
  877.  
  878.  
  879.  
  880.  
  881.  
  882. Boolean BaseDialog::HandleOKButtonHiliteQuery(void)
  883. {
  884.     // Default behavior is to have a
  885.     // hilited and active OK button
  886.     return true;
  887. }
  888.  
  889.  
  890.  
  891.  
  892.  
  893. void BaseDialog::DrawThickOutline(short item)
  894. {
  895.     QDContext        context(fWindow);
  896.     ControlHandle    control;
  897.     short            type;
  898.     Rect            box;
  899.     
  900.     
  901.     // Draw a thick border around an item (default button outline)
  902.     GetDialogItem(fDialog,item,&type,(Handle*)&control,&box);
  903.     if (type == 4)
  904.     {
  905.         InsetRect(&box,-4,-4);
  906.         
  907.         if (control[0]->contrlHilite == 255)
  908.             PenPat(&qd.gray);
  909.         
  910.         PenSize(3,3);
  911.         FrameRoundRect(&box,16,16);
  912.     }
  913. }
  914.  
  915.  
  916.  
  917.  
  918.  
  919. void BaseDialog::SetOKState(Boolean isActive)
  920. {
  921.     ControlHandle    control;
  922.     short            type;
  923.     Rect            box;
  924.     
  925.     
  926.     // (De)Hilite the OK button to show its (in)active state
  927.     GetDialogItem(fDialog,kOKButtonID,&type,(Handle*)&control,&box);
  928.     if (type == 4)
  929.     {
  930.         if (isActive)
  931.         {
  932.             if (control[0]->contrlHilite == 255)
  933.             {
  934.                 HiliteControl(control,0);
  935.                 DrawThickOutline(kOKButtonID);
  936.             }
  937.         }
  938.         else
  939.         {
  940.             if (control[0]->contrlHilite != 255)
  941.             {
  942.                 HiliteControl(control,255);
  943.                 DrawThickOutline(kOKButtonID);
  944.             }
  945.         }
  946.     }
  947. }
  948.  
  949.  
  950.  
  951.  
  952.  
  953. void BaseDialog::AnimateButtonPress(short item)
  954. {
  955.     ControlHandle    control;
  956.     UInt32            ticks;
  957.     short            type;
  958.     Rect            box;
  959.     
  960.     
  961.     // Make it appear to the user that a button was pressed
  962.     GetDialogItem(fDialog,item,&type,(Handle*)&control,&box);
  963.     if ((type == 4) && (control[0]->contrlHilite == 0))
  964.     {
  965.         HiliteControl(control,kControlButtonPart);
  966.         Delay(10,&ticks);
  967.         HiliteControl(control,0);
  968.     }
  969. }
  970.  
  971.  
  972.  
  973.  
  974.  
  975. void BaseDialog::GetItemText(short item,char *text)
  976. {
  977.     Handle    data;
  978.     short    type;
  979.     Rect    rect;
  980.     Str255    pstr;
  981.     
  982.     
  983.     // Get the text of a static text item or an
  984.     // edit text item and return it as a c string
  985.     GetDialogItem(fDialog,item,&type,&data,&rect);
  986.     if ((type == statText) || (type == editText))
  987.         GetDialogItemText(data,pstr);
  988.     else
  989.         pstr[0] = '\0';
  990.     
  991.     pstr[1 + pstr[0]] = '\0';
  992.     strcpy(text,(char*)&pstr[1]);
  993. }
  994.  
  995.  
  996.  
  997.  
  998.  
  999. int BaseDialog::GetItemTextAsDecimal(short item)
  1000. {
  1001.     char    text[256];
  1002.     
  1003.     
  1004.     // Get the text of a static text item or an edit
  1005.     // text item and return it as a decimal value
  1006.     GetItemText(item,text);
  1007.     return atoi(text);
  1008. }
  1009.  
  1010.  
  1011.  
  1012.  
  1013.  
  1014. void BaseDialog::SetItemText(short item,char *text)
  1015. {
  1016.     Handle    data;
  1017.     short    type;
  1018.     Rect    rect;
  1019.     Str255    pstr;
  1020.     
  1021.     
  1022.     // Set the text of a static text item
  1023.     // or an edit text item from a c string
  1024.     GetDialogItem(fDialog,item,&type,&data,&rect);
  1025.     if ((type == statText) || (type == editText))
  1026.     {
  1027.         pstr[0] = strlen(text);
  1028.         strcpy((char*)&pstr[1],text);
  1029.         SetDialogItemText(data,pstr);
  1030.     }
  1031. }
  1032.  
  1033.  
  1034.  
  1035.  
  1036.  
  1037. void BaseDialog::SetItemTextf(short item,char *format,...)
  1038. {
  1039.     va_list    args;
  1040.     char    text[256];
  1041.     
  1042.     
  1043.     // Set the text of a static text item or an edit
  1044.     // text item from a printf formatted specification
  1045.     va_start(args,format);
  1046.     vsprintf(text,format,args);
  1047.     va_end(args);
  1048.     
  1049.     SetItemText(item,text);
  1050. }
  1051.  
  1052.  
  1053.  
  1054.  
  1055.  
  1056. void BaseDialog::AppendItemText(short item,char *text)
  1057. {
  1058.     char    cur[256];
  1059.     
  1060.     
  1061.     // Append text to the end of a static text
  1062.     // item or an edit text item from a c string
  1063.     GetItemText(item,cur);
  1064.     strcat(cur,text);
  1065.     SetItemText(item,cur);
  1066. }
  1067.  
  1068.  
  1069.  
  1070.  
  1071.  
  1072. void BaseDialog::AppendItemTextf(short item,char *format,...)
  1073. {
  1074.     va_list    args;
  1075.     char    cur[256],text[256];
  1076.     
  1077.     
  1078.     // Append text to the end of a static text item or an
  1079.     // edit text item from a printf formatted specification
  1080.     va_start(args,format);
  1081.     vsprintf(text,format,args);
  1082.     va_end(args);
  1083.     
  1084.     GetItemText(item,cur);
  1085.     strcat(cur,text);
  1086.     SetItemText(item,cur);
  1087. }
  1088.