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

  1. /******************************************************************************
  2. * .FILE:         adialog4.cpp                                                 *
  3. *                                                                             *
  4. * .DESCRIPTION:  Hello World Sample Program  Version 4: 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.  
  30. #include "ahellow4.h"
  31. #include "adialog4.hpp"
  32. /**************************************************************************
  33. * Class ATextDialog :: ATextDialog - Constructor for the text dialog      *
  34. *   window                                                                *
  35. *                                                                         *
  36. * Construct the dialog as a frame window owned by the window passed.      *
  37. *   Size and position of the window are calculated as an offset           *
  38. *   from the left bottom position of the owner window.                    *
  39. *   The style is set to match that of an OS/2 PM dialog template plus     *
  40. *   settings for system menu and title bar.                               *
  41. * Create the multicell canvas with this dialog frame as owner.            *
  42. * Place the dialog's push buttons on a set canvas so that they are        *
  43. *   evenly spaced.                                                        *
  44. * Place the dialog controls for the static text and the entry field       *
  45. *   along with the set canvas into a multicell canvas.                    *
  46. * Construct the dialog command handler passing a pointer to this frame.   *
  47. * Save the text string reference passed into the constructor.             *
  48. **************************************************************************/
  49. ATextDialog :: ATextDialog(IString & textString, IWindow * ownerWnd)
  50.              : IFrameWindow(IResourceId(WND_TEXTDIALOG)
  51.                   ,IWindow::desktopWindow()
  52.                   ,ownerWnd
  53.                   ,IRectangle(29,50,313,290)
  54.                      .moveBy(ownerWnd->rect().bottomLeft())
  55.                   ,IWindow::synchPaint
  56.                     |IWindow::clipSiblings
  57.                     |IWindow::saveBits
  58.                     |dialogBackground
  59.                     |dialogBorder
  60.                     |systemMenu
  61.                     |titleBar)
  62.                ,clientCanvas(WND_MCCANVAS,this,this)
  63.                ,buttons(WND_STCANVAS, &clientCanvas, &clientCanvas)
  64.                ,statText(DID_STATIC,&clientCanvas,&clientCanvas)
  65.                ,textField( DID_ENTRY,&clientCanvas,&clientCanvas)
  66.                ,pushButton1( DID_OK,&buttons,&buttons)
  67.                ,pushButton2(DID_CANCEL,&buttons,&buttons)
  68.                ,dialogCommandHandler(this)
  69.                ,saveText(textString)
  70. {
  71. /*------------------------------------------------------------------------|
  72. |Set the entry field text to the string passed in on the ATextDialog      |
  73. |  constructor and set the style.                                         |
  74. |Set the entry field prompt and push button text strings from strings     |
  75. |  in the resource file.                                                  |
  76. |Set the push buttons and set canvas styles.  The buttons set canvas      |
  77. |  pack type is set to expanded to size both push buttons to the same     |
  78. |  size.                                                                  |
  79. -------------------------------------------------------------------------*/
  80.   textField.setText(saveText);
  81.   textField.disableAutoScroll().enableMargin().enableTabStop();
  82.  
  83.   statText.setText(DID_STATIC);
  84.  
  85.   pushButton1.enableDefault().setText(IResourceId(DID_OK)).enableTabStop();
  86.   pushButton2.setText(IResourceId(DID_CANCEL));
  87.   buttons.setPackType(ISetCanvas::expanded).setMargin(ISize());
  88.  
  89. /*------------------------------------------------------------------------|
  90. |  Position the dialog controls in the multicell canvas.                  |
  91. -------------------------------------------------------------------------*/
  92.   clientCanvas.addToCell(&statText , 2, 4);
  93.   clientCanvas.addToCell(&textField, 2, 7);
  94.   clientCanvas.addToCell(&buttons,   2,15);
  95.  
  96. /*------------------------------------------------------------------------|
  97. |  Set the multicell canvas as the ATextDialog client window.             |
  98. |  Have the command handler start handling events for the frame window.   |
  99. |  Set the focus to the entry field.                                      |
  100. |------------------------------------------------------------------------*/
  101.   setClient( &clientCanvas );
  102.   dialogCommandHandler.handleEventsFor(this);
  103.   textField.setFocus();
  104.  
  105. } /* end ATextDialog :: ATextDialog(...) */
  106.  
  107. /**************************************************************************
  108. * Class ATextDialog :: ~ATextDialog - Destructor for the dialog frame     *
  109. *   window                                                                *
  110. **************************************************************************/
  111. ATextDialog :: ~ATextDialog()
  112. {
  113.   dialogCommandHandler.stopHandlingEventsFor(this);
  114. } /* end ATextDialog :: ~ATextDialog() */
  115.  
  116. /**************************************************************************
  117. * Class ATextDialog :: setTextFromEntryField - Update the reference       *
  118. *   string with the text from the entry field.                            *
  119. **************************************************************************/
  120. ATextDialog &
  121.   ATextDialog::setTextFromEntryField()
  122. {
  123.   saveText = textField.text();
  124.   return (*this);
  125. } /* end AHelloWindow :: setTextFromEntryField */
  126.  
  127. /**************************************************************************
  128. * Class ADialogCommandHandler :: ADialogCommandHandler--Constructs the    *
  129. *   command handler for the dialog box.                                   *
  130. *                                                                         *
  131. *  Store the pointer to the ATextDialog that events are handled for.      *
  132. **************************************************************************/
  133. ADialogCommandHandler :: ADialogCommandHandler(ATextDialog *dialogFrame)
  134.   :frame(dialogFrame)
  135. {
  136. } /* end ADialogCommandHandler :: ADialogCommandHandler(...) */
  137.  
  138. /**************************************************************************
  139. * Class ADialogCommandHandler :: command -- Handle menu commands for      *
  140. *   dialog window                                                         *
  141. **************************************************************************/
  142. IBase::Boolean ADialogCommandHandler :: command(ICommandEvent & cmdEvent)
  143. {
  144.   Boolean eventProcessed(true);         //Assume event will be processed
  145.  
  146. /*------------------------------------------------------------------------|
  147. |  Depending on the command event ID,                                     |
  148. |    optionally update the Hello World text;                              |
  149. |    then dismiss the text dialog passing the event ID as the result.     |
  150. |------------------------------------------------------------------------*/
  151.   switch (cmdEvent.commandId()) {
  152.     case DID_OK:
  153.       frame->setTextFromEntryField();
  154.       frame->dismiss(DID_OK);
  155.       break;
  156.     case DID_CANCEL:
  157.       frame->dismiss(DID_CANCEL);
  158.       break;
  159.     default:
  160. /*------------------------------------------------------------------------|
  161. | The event was not processed                                             |
  162. -------------------------------------------------------------------------*/
  163.       eventProcessed=false;
  164.   } /* end switch */
  165.  
  166.   return(eventProcessed);
  167. } /* end ADialogCommandHandler :: command(...) */
  168.  
  169.