home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Think Class Libraries / CPasswordText 1.0 / CPasswordText / CPasswordTextDemoDir.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-30  |  3.0 KB  |  126 lines  |  [TEXT/KAHL]

  1. /******************************************************************************
  2.  CPasswordTextDemoDir.c
  3.     
  4.     To install this Showcase demo, follow these two easy steps:
  5.     
  6.         1)  Add both source files to the CSApplication project.
  7.         
  8.              *    CPasswordText
  9.                 CPasswordTextDemoDir
  10.                 
  11.             a whole bunch of dialog support
  12.     
  13.                 CButton
  14.                 CCheckBox
  15.                 CDialog
  16.                 CDialogDirector
  17.                 CDLOGDialog
  18.                 CDLOGDirector
  19.                 CIconPane
  20.                 CIntegerText
  21.                 CRadioControl
  22.                 CRadioGroupPane
  23.                 SANE (library)
  24.             
  25.             [ Those marked with an * are the files necessary when using
  26.               the CPasswordText class.  The others are only for this demo. ]
  27.     
  28.         2)    Add all resources in "CPasswordTextDemo.rsrc" to the
  29.             Showcase resource file "CSApplication π.rsrc".
  30.  
  31.         3) Recompile and run.
  32.  
  33.     NOTE: This example uses the CDialog classes. Please see its documentation
  34.     on how to use an overloaded static text dialog item. The password dialog 
  35.     uses such an item to present the CPasswordText instance.
  36.     
  37.     SUPERCLASS: CShowcaseDemoDir    
  38.     REQUIRES:   CPasswordText    
  39.     AUTHOR:     Andrew_Gilmartin@Brown.Edu
  40.     MODIFIED:   93-05-21
  41.  
  42. ******************************************************************************/
  43.  
  44. #include <TCLHeaders>
  45. #include "CPasswordTextDemoDir.h"
  46. #include "CPasswordText.h"
  47.  
  48.  
  49.  
  50. /*============================================================================
  51.  GetUserNameAndPassword
  52.  
  53.     Ask the user for a name and password.
  54. ============================================================================*/
  55.  
  56. #define GET_ITEM_STRING( _dialog, _item, _string )\
  57.     ((CDialogText*)_dialog->itsWindow->FindViewByID(_item))->GetTextString(_string)
  58.  
  59. #define SET_ITEM_STRING( _dialog, _item, _string )\
  60.     ((CDialogText*)_dialog->itsWindow->FindViewByID(_item))->SetTextString(_string)
  61.  
  62. #define kPasswordDialogID 1024
  63.  
  64. #define kNameItem 4
  65. #define kPasswordItem 3
  66.  
  67. static Boolean GetUserNameAndPassword( StringPtr aName, StringPtr aPassword )
  68. {
  69.     CDLOGDirector* theDialog = NULL;
  70.     long theResult = cmdNull;
  71.  
  72.     TRY
  73.     {    
  74.         theDialog = new CDLOGDirector;
  75.         theDialog->IDLOGDirector( kPasswordDialogID, gApplication );
  76.         
  77.         SET_ITEM_STRING( theDialog, kNameItem, aName );
  78.         SET_ITEM_STRING( theDialog, kPasswordItem, aPassword );
  79.         
  80.         theDialog->BeginDialog();
  81.     
  82.         if ( ( theResult = theDialog->DoModalDialog( cmdOK ) ) == cmdOK )
  83.         {
  84.             GET_ITEM_STRING( theDialog, kNameItem, aName );
  85.             GET_ITEM_STRING( theDialog, kPasswordItem, aPassword );
  86.         }
  87.     
  88.         ForgetObject( theDialog );
  89.     }
  90.     CATCH
  91.     {
  92.         ForgetObject( theDialog );
  93.     }
  94.     ENDTRY
  95.  
  96.     return theResult == cmdOK;
  97.  
  98. } /* GetUserNameAndPassword */
  99.  
  100.  
  101. /******************************************************************************
  102.  INewDemo
  103.  
  104. ******************************************************************************/
  105.  
  106. void CPasswordTextDemoDir::INewDemo( CDirectorOwner *aSupervisor )
  107. {
  108.     Str255 theName;
  109.     Str255 thePassword;
  110.  
  111.     inherited::INewDemo( aSupervisor);
  112.  
  113.     CopyPString( "\pAndrew Gilmartin", theName );
  114.     CopyPString( "\p", thePassword );
  115.  
  116.     if ( GetUserNameAndPassword( theName, thePassword ) )
  117.     {
  118.         /* The user pressed OK */
  119.     }
  120.  
  121.         /* Finished with the demo */
  122.  
  123.     Close( FALSE );
  124.         
  125. } /* INewDemo */
  126.