home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / samples / ioc / hello6 / adialog6.cpp next >
Encoding:
C/C++ Source or Header  |  1996-02-22  |  10.1 KB  |  188 lines

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