home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / VSCPPv8.zip / VACPP / IBMCPP / samples / IOC / HELLO6 / ADIALOG6.CPP next >
C/C++ Source or Header  |  1995-04-07  |  13KB  |  176 lines

  1. /*****************************************************************************
  2. * HELLO WORLD SAMPLE PROGRAM - Version 6: Class Implementation (adialog6.cpp)*
  3. *                                                                            *
  4. * COPYRIGHT: Copyright (C) International Business Machines Corp., 1992,1995. *
  5. *                                                                            *
  6. * DISCLAIMER OF WARRANTIES:                                                  *
  7. *   The following [enclosed] code is sample code created by IBM              *
  8. *   Corporation.  This sample code is not part of any standard IBM product   *
  9. *   and is provided to you solely for the purpose of assisting you in the    *
  10. *   development of your applications.  The code is provided "AS IS",         *
  11. *   without warranty of any kind.  IBM shall not be liable for any damages   *
  12. *   arising out of your use of the sample code, even if they have been       *
  13. *   advised of the possibility of such damages.                              *
  14. *****************************************************************************/
  15. //NOTE: WE RECOMMEND USING A FIXED-SPACE FONT TO LOOK AT THE SOURCE.
  16.  
  17. //Include User Interface Class Library class headers:                         V4
  18. #ifndef _IBASE_                         //Make sure ibase.hpp is included
  19.   #include <ibase.hpp>                  //  since that is where IC_<environ>
  20. #endif                                  //  is defined.
  21. #include <istring.hpp>                  //Include IString class header        V4
  22. #include <ireslib.hpp>                  //Include IResourceId class header    V4
  23. #include <ihelp.hpp>                    //Include IHelpWindow class header    V5
  24.  
  25. #include "ahellow6.h"                   //Include symbolic definitions        v6
  26. #include "adialog6.hpp"                 //Include ATextDialog class header    v6
  27. /**************************************************************************   V4
  28. * ATextDialog :: ATextDialog - Constructor for the text dialog window     *   V4
  29. *   Construct the dialog as a frame window owned by the window passed.    *   V4
  30. *     The size and position of the window are calculated as an offset     *   V4
  31. *       from the left bottom position of the owner window.                *   V4
  32. *     The style is set to match that of an OS/2 PM dialog template plus   *   V4
  33. *       settings for system menu and title bar.                           *   V4
  34. *       NOTE: IWindow::visible should not be used with dialogBackground.  *   V4
  35. *   Create the multicell canvas with this dialog frame as owner.          *   V4
  36. *   Place the dialog's push buttons on a set canvas so that they are      *   V4
  37. *     evenly spaced.                                                      *   V4
  38. *   Place the dialog controls for the static text and the entry field     *   V4
  39. *       along with the set canvas into a multicell canvas.                *   V4
  40. *       (Version 6 replaces the entry field with a drop-down combo box)   *   V6
  41. *   Construct the dialog command handler passing a pointer to this frame. *   V4
  42. *   Save the text string reference passed into the constructor.           *   V4
  43. **************************************************************************/ //V4
  44. ATextDialog :: ATextDialog(IString & textString, IWindow * ownerWnd)        //V4
  45.              : IFrameWindow(IResourceId(WND_TEXTDIALOG)                     //V4
  46.                   ,IWindow::desktopWindow()                                 //V4
  47.                   ,ownerWnd                                                 //V4
  48.                   ,IRectangle(29,50,375,350)                                //v6
  49.                      .moveBy(ownerWnd->rect().bottomLeft())                 //V4
  50.                   ,IWindow::synchPaint                                      //V4
  51.                     |IWindow::clipSiblings                                  //V4
  52.                     |IWindow::saveBits                                      //V4
  53.                     |dialogBackground                                       //V4
  54.                     |dialogBorder                                           //V4
  55.                     |systemMenu                                             //V4
  56.                     |titleBar)                                              //V4
  57.                ,clientCanvas(WND_MCCANVAS,this,this)                        //V4
  58.                ,buttons(WND_STCANVAS, &clientCanvas, &clientCanvas)         //V4
  59.                ,statText(DID_STATIC,&clientCanvas,&clientCanvas)            //V4
  60.                ,textField( DID_ENTRY,&clientCanvas,&clientCanvas            //v6
  61.                   ,IRectangle(), IWindow::visible|IComboBox::dropDownType)  //V6
  62.                ,pushButton1( DID_OK,&buttons,&buttons)                      //V4
  63.                ,pushButton2(DID_CANCEL,&buttons,&buttons)                   //V4
  64.                ,dialogCommandHandler(this)                                  //V4
  65.                ,saveText(textString)                                        //V4
  66. {                                                                           //V4
  67. /*----------------------------- Set Up Frame -----------------------------|   V4
  68. |  Since the entry field is now a combox box, load the box with items     |   V6
  69. |    from the resource file.                                              |   V6
  70. |  Set the entry field text to the string passed in on the ATextDialog    |   V4
  71. |    constructor and set the style.                                       |   V4
  72. |  Set the entry field prompt and push button text strings from strings   |   V4
  73. |    in the resource file.                                                |   V4
  74. |  Set the push buttons and set canvas styles.  The buttons set canvas    |   V4
  75. |    pack type is set to expanded to size both push buttons to the same   |   V4
  76. |    size.                                                                |   V4
  77. |------------------------------------------------------------------------*/ //V4
  78.   for (int i=0;i<HI_COUNT;i++ )                                             //V6
  79.      textField.addAscending(HI_WORLD+i);                                    //V6
  80.   textField.setText(saveText);                                              //V4
  81.   textField.disableAutoScroll().enableMargin().enableTabStop();             //V4
  82.  
  83.   statText.setText(DID_STATIC);                                             //V4
  84.  
  85.   pushButton1.enableDefault().setText(IResourceId(DID_OK)).enableTabStop(); //V4
  86.   pushButton2.setText(IResourceId(DID_CANCEL));                             //V4
  87.   buttons.setPackType(ISetCanvas::expanded).setMargin(ISize());             //V4
  88.  
  89. /*------------------------------- Fill Canvas ----------------------------|   V4
  90. |  Position the dialog controls in the multicell canvas.                  |   V4
  91. |------------------------------------------------------------------------*/ //V4
  92.   clientCanvas.addToCell(&statText , 2, 4);                                 //V4
  93.   clientCanvas.addToCell(&textField, 2, 7);                                 //V4
  94.   clientCanvas.addToCell(&buttons,   2, 9);                                 //V4
  95.   clientCanvas.setRowHeight(7ul, 10ul, true);                               //V6
  96.  
  97. /*-------------------------- Set Up Frame Window -------------------------|   V4
  98. |  Set the multicell canvas as the ATextDialog client window.             |   V4
  99. |  Have the command handler start handling events for the frame window.   |   V4
  100. |  Set the focus to the entry field.                                      |   V4
  101. |------------------------------------------------------------------------*/ //V4
  102.   setClient( &clientCanvas );                                               //V4
  103.   dialogCommandHandler.handleEventsFor(this);                               //V4
  104.   textField.setFocus();                                                     //V4
  105.  
  106. /*------------------------ Use Owner's Help Window -----------------------|   V5
  107. |  IHelpWindow::setAssociatedWindow is called to associate the dialog with|   V5
  108. |    its owner's help window so that the help window is positioned        |   V5
  109. |    relative to this window, and so that this window is correctly        |   V5
  110. |    activated when the user dismisses the help window.                   |   V5
  111. |------------------------------------------------------------------------*/ //V5
  112.   IHelpWindow::helpWindow(ownerWnd)->setAssociatedWindow(this);             //V5
  113.  
  114. } /* end ATextDialog :: ATextDialog(...) */                                 //V4
  115.  
  116. /**************************************************************************   V4
  117. * ATextDialog :: ~ATextDialog - Destructor for the dialog frame window    *   V4
  118. *   Stop handling command events for the frame.                           *   V4
  119. **************************************************************************/ //V4
  120. ATextDialog :: ~ATextDialog()                                               //V4
  121. {                                                                           //V4
  122.   dialogCommandHandler.stopHandlingEventsFor(this);                         //V4
  123. } /* end ATextDialog :: ~ATextDialog() */                                   //V4
  124.  
  125. /**************************************************************************   V4
  126. * ATextDialog :: setTextFromEntryField                                    *   V4
  127. *   Update the string reference passed into ATextDialog constructor using *   V4
  128. *   the text from the entry field.                                        *   V4
  129. **************************************************************************/ //V4
  130. ATextDialog &                                                               //V4
  131.   ATextDialog::setTextFromEntryField()                                      //V4
  132. {                                                                           //V4
  133.   saveText = textField.text();                                              //V4
  134.   return (*this);                       //Return a reference to the frame     V4
  135. } /* end AHelloWindow :: setTextFromEntryField */                           //V4
  136.  
  137. /**************************************************************************   V4
  138. * ADialogCommandHandler :: ADialogCommandHandler                          *   V4
  139. *       Construct the command handler from a pointer to the ATextDialog   *   V4
  140. *       that events are handled for.                                      *   V4
  141. **************************************************************************/ //V4
  142. ADialogCommandHandler :: ADialogCommandHandler(ATextDialog *dialogFrame)    //V4
  143. {                                                                           //V4
  144.    frame=dialogFrame;                   //Save frame to be handled            V4
  145. } /* end ADialogCommandHandler :: ADialogCommandHandler(...) */             //V4
  146.  
  147. /**************************************************************************   V4
  148. * ADialogCommandHandler :: command                                        *   V4
  149. *   Handle button commands                                                *   V4
  150. **************************************************************************/ //V4
  151. IBase::Boolean                                                              //V4
  152.   ADialogCommandHandler :: command(ICommandEvent & cmdEvent)                //V4
  153. {                                                                           //V4
  154.   Boolean eventProcessed(true);         //Assume event will be processed      V4
  155.  
  156. /*--------------------- Process command events ---------------------------|   V4
  157. |  Depending on the command event ID,                                     |   V4
  158. |    optionally update the Hello World text;                              |   V4
  159. |    then dismiss the text dialog passing the event ID as the result.     |   V4
  160. |------------------------------------------------------------------------*/ //V4
  161.   switch (cmdEvent.commandId()) {                                           //V4
  162.     case DID_OK:                                                            //V4
  163.       frame->setTextFromEntryField();                                       //V4
  164.       frame->dismiss(DID_OK);                                               //V4
  165.       break;                                                                //V4
  166.     case DID_CANCEL:                                                        //V4
  167.       frame->dismiss(DID_CANCEL);                                           //V4
  168.       break;                                                                //V4
  169.     default:                            //Otherwise,                          V4
  170.       eventProcessed=false;             //  the event wasn't processed        V4
  171.   } /* end switch */                                                        //V4
  172.  
  173.   return(eventProcessed);                                                   //V4
  174. } /* end ADialogCommandHandler :: command(...) */                           //V4
  175.  
  176.