home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C++ / Frameworks / Argus Frameworks 2.1 / Argus Starter 2.1 / Dialogs / SampleDialog.cp next >
Encoding:
Text File  |  1996-01-02  |  7.8 KB  |  254 lines  |  [TEXT/KAHL]

  1. /**********************************************************************
  2.  
  3.     SampleDialog.cp
  4.  
  5. ***********************************************************************/
  6.  
  7. /*
  8.     A sample case demonstrating a movable model dialog box.  Need 
  9.     System 7 for pop-up menu functionality.
  10. */
  11.  
  12. /********** Includes */
  13. #include <Dialogs.h>
  14. #include "Fn_Prototypes.h"
  15. #include "MainWindow.h"
  16.  
  17.  
  18. /********** Defines */
  19. #define SAMPLE_DLOG    500
  20. #define NIL_PTR        0L
  21. #define ALLOCATE_MEM   0
  22. #define IN_FRONT       (WindowPtr)-1L
  23. #define RETURN_KEY     13
  24. #define ENTER_KEY      3
  25. #define ESCAPE_KEY     27
  26. #define PERIOD_KEY     46
  27. #define VISUAL_DELAY   8  // standard is 8 ticks
  28.  
  29. #define OK_BUTTON      1
  30. #define CANCEL_BUTTON  2
  31. #define NAME           5
  32. #define PHONE          6
  33. #define MALE_RADIO     7
  34. #define FEMALE_RADIO   8
  35. #define MARRIED_BOX    10
  36. #define DB             11
  37.  
  38.  
  39. /********** Prototypes */
  40. Boolean        MySampleDialog( void );
  41. pascal Boolean MyDialogEventFilter( DialogPtr    theDialog,
  42.                                     EventRecord  *theEvent,
  43.                                     short        *itemHit );
  44.  
  45. /********** SampleDialog */
  46.  
  47. Boolean MySampleDialog( void )
  48. {
  49.     WindowPtr   docWindow;
  50.     DialogPtr   dialog;
  51.     Boolean     done;
  52.     Boolean     result;
  53.     short       itemHit;
  54.     short       itemType;
  55.     Handle      itemHandle;
  56.     Rect        itemRect;
  57.     EventRecord theEvent;
  58.     
  59.     Boolean     isMale;
  60.     Boolean     isFemale;
  61.     Boolean     isMarried;
  62.     int         phoneDB;
  63.     Str255      name;
  64.     Str255      phone;
  65.  
  66.     result = FALSE;
  67.  
  68.     docWindow = FrontWindow();
  69.     if( docWindow != NIL_PTR )
  70.         MyDoDeactivateWindow( docWindow );
  71.  
  72.     dialog = GetNewDialog( SAMPLE_DLOG, ALLOCATE_MEM, IN_FRONT );
  73.  
  74.     if( dialog == NIL_PTR )
  75.         return( result );
  76.  
  77.     /* AdjustMenus_(); */
  78.     ShowWindow( dialog );
  79.     FnMisc_FrameButton( dialog, OK_BUTTON );
  80.  
  81.     done = FALSE;
  82.     while( done == FALSE )
  83.     {
  84.         ModalDialog( &MyDialogEventFilter, &itemHit );
  85.  
  86.         switch( itemHit )
  87.         {
  88.             case OK_BUTTON:
  89.                 result = TRUE;
  90.                 done = TRUE;
  91.                 break;
  92.             case CANCEL_BUTTON:
  93.                 done = TRUE;
  94.                 break;
  95.             case MALE_RADIO:
  96.                 GetDItem( dialog,
  97.                           MALE_RADIO,
  98.                           &itemType,
  99.                           &itemHandle,
  100.                           &itemRect );
  101.                 SetCtlValue( (ControlHandle)itemHandle, TRUE );
  102.                 GetDItem( dialog,
  103.                           FEMALE_RADIO,
  104.                           &itemType,
  105.                           &itemHandle,
  106.                           &itemRect );
  107.                 SetCtlValue( (ControlHandle)itemHandle, FALSE );
  108.                 break;
  109.             case FEMALE_RADIO:
  110.                 GetDItem( dialog,
  111.                           FEMALE_RADIO,
  112.                           &itemType,
  113.                           &itemHandle,
  114.                           &itemRect );
  115.                 SetCtlValue( (ControlHandle)itemHandle, TRUE );
  116.                 GetDItem( dialog,
  117.                           MALE_RADIO,
  118.                           &itemType,
  119.                           &itemHandle,
  120.                           &itemRect );
  121.                 SetCtlValue( (ControlHandle)itemHandle, FALSE );
  122.                 break;
  123.             case MARRIED_BOX:
  124.                 GetDItem( dialog,
  125.                           MARRIED_BOX,
  126.                           &itemType,
  127.                           &itemHandle,
  128.                           &itemRect );
  129.                 if( GetCtlValue( (ControlHandle)itemHandle ) )
  130.                     SetCtlValue( (ControlHandle)itemHandle, FALSE );
  131.                 else
  132.                     SetCtlValue( (ControlHandle)itemHandle, TRUE );
  133.                 break;
  134.         }
  135.      }
  136.  
  137.     GetDItem(dialog,MALE_RADIO,&itemType,&itemHandle,&itemRect);
  138.     isMale = GetCtlValue((ControlHandle)itemHandle);
  139.     GetDItem(dialog,FEMALE_RADIO,&itemType,&itemHandle,&itemRect);
  140.     isFemale = GetCtlValue((ControlHandle)itemHandle);
  141.     GetDItem(dialog,MARRIED_BOX,&itemType,&itemHandle,&itemRect);
  142.     isMarried = GetCtlValue((ControlHandle)itemHandle);
  143.  
  144.     GetDItem(dialog,NAME,&itemType,&itemHandle,&itemRect);
  145.     GetIText(itemHandle,name);
  146.     GetDItem(dialog,PHONE,&itemType,&itemHandle,&itemRect);
  147.     GetIText(itemHandle,phone);
  148.  
  149.     GetDItem(dialog,DB,&itemType,&itemHandle,&itemRect);
  150.     phoneDB = GetCtlValue((ControlHandle)itemHandle);
  151.  
  152.     DisposDialog( dialog );
  153.  
  154.     return( result );
  155. }
  156.  
  157.  
  158. /********** PASCAL MyDialogEventFilter */
  159.  
  160. pascal Boolean MyDialogEventFilter( DialogPtr    theDialog,
  161.                                     EventRecord  *theEvent,
  162.                                     short        *itemHit )
  163. {
  164.     short          thePart;
  165.     char           key;
  166.     short          itemType;
  167.     Handle         itemHandle;
  168.     Rect           itemRect;
  169.     long           finalTicks;
  170.     Rect           dragRect;
  171.     Boolean        result;
  172.     WindowPtr      theWindow;
  173.     
  174.     result = FALSE;
  175.     dragRect = qd.screenBits.bounds;
  176.  
  177.         switch( (*theEvent).what )
  178.         {
  179.             case mouseDown:
  180.                 thePart = FindWindow( (*theEvent).where, &theWindow );
  181.                 if( theWindow == theDialog )
  182.                 {
  183.                 switch( thePart )
  184.                     {
  185.                         case inDrag:
  186.                             DragWindow( theDialog,
  187.                                         (*theEvent).where,
  188.                                         &dragRect );
  189.                             result = TRUE;
  190.                             break;
  191.                     }
  192.                 }
  193.                 break;
  194.             case keyDown:
  195.             case autoKey:
  196.                 key = (*theEvent).message & charCodeMask;
  197.                 if( (key == RETURN_KEY) || (key == ENTER_KEY) )
  198.                 {
  199.                     *itemHit = OK_BUTTON;
  200.                     GetDItem( theDialog,
  201.                               OK_BUTTON,
  202.                               &itemType,
  203.                               &itemHandle,
  204.                               &itemRect );
  205.                     HiliteControl( (ControlHandle)itemHandle,
  206.                                    inButton );
  207.                     Delay( VISUAL_DELAY, &finalTicks );
  208.                     HiliteControl( (ControlHandle)itemHandle, 0 );
  209.                     result = TRUE;
  210.                 }
  211.                 if( (key == ESCAPE_KEY) ||
  212.                     (((*theEvent).modifiers & cmdKey) &&
  213.                     (key == PERIOD_KEY)) )
  214.                 {
  215.                     *itemHit = CANCEL_BUTTON;
  216.                     GetDItem( theDialog,
  217.                               CANCEL_BUTTON,
  218.                               &itemType,
  219.                               &itemHandle,
  220.                               &itemRect );
  221.                     HiliteControl( (ControlHandle)itemHandle,
  222.                                    inButton );
  223.                     Delay( VISUAL_DELAY, &finalTicks );
  224.                     HiliteControl( (ControlHandle)itemHandle, 0 );
  225.                     result = TRUE;
  226.                 }
  227.                 /* Handle other keyboard equivalents here */
  228.                 break;
  229.             case updateEvt:
  230.                 if( (WindowPtr)(*theEvent).message != theDialog )
  231.                 {
  232.                     MyDoUpdateWindow( (WindowPtr)(*theEvent).message );
  233.                 }
  234.                 else
  235.                 {
  236.                     FnMisc_FrameButton( theDialog, OK_BUTTON );
  237.                 }
  238.                 break;
  239.             case activateEvt:
  240.                 if( (WindowPtr)(*theEvent).message != theDialog )
  241.                 {
  242.                     /*
  243.                     DoActivate_( (WindowPtr)(*theEvent).message,
  244.                                  ((*theEvent).modifiers & activeFlag),
  245.                                  *theEvent );
  246.                     */
  247.                  }
  248.                  break;
  249.         }
  250.         
  251.     return( result );
  252. }
  253.  
  254. // End of File