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

  1. /*****************************************************************************
  2. * HELLO WORLD SAMPLE PROGRAM - Version 5: Class Implementation (adialog5.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 "ahellow5.h"                   //Include symbolic definitions        V5
  26. #include "adialog5.hpp"                 //Include ATextDialog class header    V5
  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. *   Construct the dialog command handler passing a pointer to this frame. *   V4
  41. *   Save the text string reference passed into the constructor.           *   V4
  42. **************************************************************************/ //V4
  43. ATextDialog :: ATextDialog(IString & textString, IWindow * ownerWnd)        //V4
  44.              : IFrameWindow(IResourceId(WND_TEXTDIALOG)                     //V4
  45.                   ,IWindow::desktopWindow()                                 //V4
  46.                   ,ownerWnd                                                 //V4
  47.                   ,IRectangle(29,50,313,290)                                //V4
  48.                      .moveBy(ownerWnd->rect().bottomLeft())                 //V4
  49.                   ,IWindow::synchPaint                                      //V4
  50.                     |IWindow::clipSiblings                                  //V4
  51.                     |IWindow::saveBits                                      //V4
  52.                     |dialogBackground                                       //V4
  53.                     |dialogBorder                                           //V4
  54.                     |systemMenu                                             //V4
  55.                     |titleBar)                                              //V4
  56.                ,clientCanvas(WND_MCCANVAS,this,this)                        //V4
  57.                ,buttons(WND_STCANVAS, &clientCanvas, &clientCanvas)         //V4
  58.                ,statText(DID_STATIC,&clientCanvas,&clientCanvas)            //V4
  59.                ,textField( DID_ENTRY,&clientCanvas,&clientCanvas)           //V4
  60.                ,pushButton1( DID_OK,&buttons,&buttons)                      //V4
  61.                ,pushButton2(DID_CANCEL,&buttons,&buttons)                   //V4
  62.                ,dialogCommandHandler(this)                                  //V4
  63.                ,saveText(textString)                                        //V4
  64. {                                                                           //V4
  65. /*----------------------------- Set Up Frame -----------------------------|   V4
  66. |  Set the entry field text to the string passed in on the ATextDialog    |   V4
  67. |    constructor and set the style.                                       |   V4
  68. |  Set the entry field prompt and push button text strings from strings   |   V4
  69. |    in the resource file.                                                |   V4
  70. |  Set the push buttons and set canvas styles.  The buttons set canvas    |   V4
  71. |    pack type is set to expanded to size both push buttons to the same   |   V4
  72. |    size.                                                                |   V4
  73. |------------------------------------------------------------------------*/ //V4
  74.   textField.setText(saveText);                                              //V4
  75.   textField.disableAutoScroll().enableMargin().enableTabStop();             //V4
  76.  
  77.   statText.setText(DID_STATIC);                                             //V4
  78.  
  79.   pushButton1.enableDefault().setText(IResourceId(DID_OK)).enableTabStop(); //V4
  80.   pushButton2.setText(IResourceId(DID_CANCEL));                             //V4
  81.   buttons.setPackType(ISetCanvas::expanded).setMargin(ISize());             //V4
  82.  
  83. /*------------------------------- Fill Canvas ----------------------------|   V4
  84. |  Position the dialog controls in the multicell canvas.                  |   V4
  85. |------------------------------------------------------------------------*/ //V4
  86.   clientCanvas.addToCell(&statText , 2, 4);                                 //V4
  87.   clientCanvas.addToCell(&textField, 2, 7);                                 //V4
  88.   clientCanvas.addToCell(&buttons,   2,15);                                 //V4
  89.  
  90. /*-------------------------- Set Up Frame Window -------------------------|   V4
  91. |  Set the multicell canvas as the ATextDialog client window.             |   V4
  92. |  Have the command handler start handling events for the frame window.   |   V4
  93. |  Set the focus to the entry field.                                      |   V4
  94. |------------------------------------------------------------------------*/ //V4
  95.   setClient( &clientCanvas );                                               //V4
  96.   dialogCommandHandler.handleEventsFor(this);                               //V4
  97.   textField.setFocus();                                                     //V4
  98.  
  99. /*------------------------ Use Owner's Help Window -----------------------|   V5
  100. |  IHelpWindow::setAssociatedWindow is called to associate the dialog with|   V5
  101. |    its owner's help window so that the help window is positioned        |   V5
  102. |    relative to this window, and so that this window is correctly        |   V5
  103. |    activated when the user dismisses the help window.                   |   V5
  104. |------------------------------------------------------------------------*/ //V5
  105.   IHelpWindow::helpWindow(ownerWnd)->setAssociatedWindow(this);             //V5
  106.  
  107. } /* end ATextDialog :: ATextDialog(...) */                                 //V4
  108.  
  109. /**************************************************************************   V4
  110. * ATextDialog :: ~ATextDialog - Destructor for the dialog frame window    *   V4
  111. *   Stop handling command events for the frame.                           *   V4
  112. **************************************************************************/ //V4
  113. ATextDialog :: ~ATextDialog()                                               //V4
  114. {                                                                           //V4
  115.   dialogCommandHandler.stopHandlingEventsFor(this);                         //V4
  116. } /* end ATextDialog :: ~ATextDialog() */                                   //V4
  117.  
  118. /**************************************************************************   V4
  119. * ATextDialog :: setTextFromEntryField                                    *   V4
  120. *   Update the string reference passed into ATextDialog constructor using *   V4
  121. *   the text from the entry field.                                        *   V4
  122. **************************************************************************/ //V4
  123. ATextDialog &                                                               //V4
  124.   ATextDialog::setTextFromEntryField()                                      //V4
  125. {                                                                           //V4
  126.   saveText = textField.text();                                              //V4
  127.   return (*this);                       //Return a reference to the frame     V4
  128. } /* end AHelloWindow :: setTextFromEntryField */                           //V4
  129.  
  130. /**************************************************************************   V4
  131. * ADialogCommandHandler :: ADialogCommandHandler                          *   V4
  132. *       Construct the command handler from a pointer to the ATextDialog   *   V4
  133. *       that events are handled for.                                      *   V4
  134. **************************************************************************/ //V4
  135. ADialogCommandHandler :: ADialogCommandHandler(ATextDialog *dialogFrame)    //V4
  136. {                                                                           //V4
  137.    frame=dialogFrame;                   //Save frame to be handled            V4
  138. } /* end ADialogCommandHandler :: ADialogCommandHandler(...) */             //V4
  139.  
  140. /**************************************************************************   V4
  141. * ADialogCommandHandler :: command                                        *   V4
  142. *   Handle button commands                                                *   V4
  143. **************************************************************************/ //V4
  144. IBase::Boolean                                                              //V4
  145.   ADialogCommandHandler :: command(ICommandEvent & cmdEvent)                //V4
  146. {                                                                           //V4
  147.   Boolean eventProcessed(true);         //Assume event will be processed      V4
  148.  
  149. /*--------------------- Process command events ---------------------------|   V4
  150. |  Depending on the command event ID,                                     |   V4
  151. |    optionally update the Hello World text;                              |   V4
  152. |    then dismiss the text dialog passing the event ID as the result.     |   V4
  153. |------------------------------------------------------------------------*/ //V4
  154.   switch (cmdEvent.commandId()) {                                           //V4
  155.     case DID_OK:                                                            //V4
  156.       frame->setTextFromEntryField();                                       //V4
  157.       frame->dismiss(DID_OK);                                               //V4
  158.       break;                                                                //V4
  159.     case DID_CANCEL:                                                        //V4
  160.       frame->dismiss(DID_CANCEL);                                           //V4
  161.       break;                                                                //V4
  162.     default:                            //Otherwise,                          V4
  163.       eventProcessed=false;             //  the event wasn't processed        V4
  164.   } /* end switch */                                                        //V4
  165.  
  166.   return(eventProcessed);                                                   //V4
  167. } /* end ADialogCommandHandler :: command(...) */                           //V4
  168.  
  169.