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

  1. /******************************************************************************
  2. * .FILE:         ahellow3.cpp                                                 *
  3. *                                                                             *
  4. * .DESCRIPTION:  Hello World Sample Program Version 3:  Class Implementation  *
  5. *                                                                             *
  6. * .CLASSES:      ACommandHandler                                              *
  7. *                AHellowWindow                                                *
  8. *                                                                             *
  9. * .COPYRIGHT:                                                                 *
  10. *    Licensed Material - Program-Property of IBM                              *
  11. *    (C) Copyright IBM Corp. 1992, 1996 - All Rights Reserved                 *
  12. *                                                                             *
  13. * .DISCLAIMER:                                                                *
  14. *   The following [enclosed] code is sample code created by IBM               *
  15. *   Corporation.  This sample code is not part of any standard IBM product    *
  16. *   and is provided to you solely for the purpose of assisting you in the     *
  17. *   development of your applications.  The code is provided 'AS IS',          *
  18. *   without warranty of any kind.  IBM shall not be liable for any damages    *
  19. *   arising out of your use of the sample code, even if they have been        *
  20. *   advised of the possibility of such damages.                               *
  21. *                                                                             *
  22. * .NOTE: WE RECOMMEND USING A FIXED SPACE FONT TO LOOK AT THE SOURCE          *
  23. *                                                                             *
  24. ******************************************************************************/
  25. #include <ibase.hpp>
  26. #include <iapp.hpp>
  27. #include <ifont.hpp>
  28. #include <icoordsy.hpp>
  29. #include "ahellow3.hpp"
  30. #include "ahellow3.h"
  31.  
  32. /**************************************************************************
  33. * main  - Application entry point for Hello World Version 3.              *
  34. *                                                                         *
  35. * Creates a new object mainWindow of class AHelloWindow                   *
  36. * Sets Hello World window alignment                                       *
  37. * Sets the size of mainWindow                                             *
  38. * Sets the window focus to mainWindow                                     *
  39. * Displays the mainWindow                                                 *
  40. * Starts the events processing for the application                        *
  41. **************************************************************************/
  42. int main()
  43. {
  44.   ICoordinateSystem::setApplicationOrientation(
  45.           ICoordinateSystem::originLowerLeft );
  46.   AHelloWindow mainWindow (WND_MAIN);
  47.   mainWindow.setTextAlignment(AHelloWindow::left);
  48.   mainWindow.sizeTo(ISize(400,300));
  49.   mainWindow.setFocus();
  50.   mainWindow.show();
  51.   IApplication::current().run();
  52.   return 0;
  53. } /* end main() */
  54.  
  55. /**************************************************************************
  56. * Class AHelloWindow :: AHelloWindow - Constructor for the main window    *
  57. *                                                                         *
  58. * Define itself as an IFrameWindow                                        *
  59. * Create a menu bar                                                       *
  60. * Create status line                                                      *
  61. * Create static text in client window.                                    *
  62. * Create information area object                                          *
  63. * Create a command handler to process command events from                 *
  64. **************************************************************************/
  65.  
  66. AHelloWindow :: AHelloWindow(const unsigned long windowId)
  67.   :IFrameWindow(IFrameWindow::defaultStyle() |
  68.                 IFrameWindow::minimizedIcon,
  69.                 windowId)
  70.   ,menuBar(windowId, this)
  71.   ,statusLine(WND_STATUS,this,this)
  72.   ,hello(WND_HELLO, this, this)
  73.   ,infoArea(this)
  74.   ,commandHandler(this)
  75. {
  76.  
  77. /*------------------------------------------------------------------------|
  78. |  Set the hello world static text window as the client window.           |
  79. |------------------------------------------------------------------------*/
  80.   setClient(&hello);
  81.  
  82.  
  83. /*------------------------------------------------------------------------|
  84. |  Add the status line as an extension to the frame above the client      |
  85. |    window with the height calculated from the maximum height of a       |
  86. |    character in the current font.                                       |
  87. |------------------------------------------------------------------------*/
  88.   addExtension(&statusLine,
  89.                IFrameWindow::aboveClient,
  90.                IFont(&statusLine).maxCharHeight());
  91.  
  92.  
  93. /*------------------------------------------------------------------------|
  94. |  Set the values for the text controls from strings in the resource file.|
  95. |    The infoArea inactive text is displayed when no menu item is active. |
  96. |------------------------------------------------------------------------*/
  97.   hello.setText(STR_HELLO);
  98.   infoArea.setInactiveText(STR_INFO);
  99.  
  100.  
  101. /*------------------------------------------------------------------------|
  102. |  Have the command handler handle commands sent from the frame window.   |
  103. |    The command handler's command() function is called to process        |
  104. |    menu item selections.                                                |
  105. |------------------------------------------------------------------------*/
  106.   commandHandler.handleEventsFor(this);
  107.  
  108.  
  109. /*------------------------------------------------------------------------|
  110. | Align the static text, set the status line, and set the check mark in   |
  111. |   the menu bar.                                                         |
  112. |------------------------------------------------------------------------*/
  113.   setTextAlignment(center);
  114.  
  115. } /* end AHelloWindow :: AHelloWindow(...) */
  116.  
  117.  
  118.  
  119. /**************************************************************************
  120. * Class AHelloWindow :: ~AHelloWindow - Destructor for the main window    *
  121. **************************************************************************/
  122. AHelloWindow :: ~AHelloWindow()
  123. {
  124.   commandHandler.stopHandlingEventsFor(this);
  125. } /* end AHelloWindow :: ~AHelloWindow() */
  126.  
  127.  
  128.  
  129. /**************************************************************************
  130. * Class AHelloWindow :: setTextAlignment - Align static text in client    *
  131. *   window                                                                *
  132. **************************************************************************/
  133. AHelloWindow &
  134.   AHelloWindow :: setTextAlignment(const Alignment alignment)
  135. {
  136. /*------------------------------------------------------------------------|
  137. |  Depending on the value passed, update the window as follows:           |
  138. |    Set the alignment of the static text control in the client window.   |
  139. |    Set the text of the alignment status line static text control.       |
  140. |    Check the selected menu item; remove check marks from the other two. |
  141. |------------------------------------------------------------------------*/
  142.   switch(alignment)
  143.   {
  144.     case left:
  145.       hello.setAlignment(IStaticText::centerLeft);
  146.       statusLine.setText(STR_LEFT);
  147.       menuBar.uncheckItem(MI_CENTER);
  148.       menuBar.checkItem(MI_LEFT);
  149.       menuBar.uncheckItem(MI_RIGHT);
  150.       break;
  151.     case center:
  152.       hello.setAlignment(IStaticText::centerCenter);
  153.       statusLine.setText(STR_CENTER);
  154.       menuBar.checkItem(MI_CENTER);
  155.       menuBar.uncheckItem(MI_LEFT);
  156.       menuBar.uncheckItem(MI_RIGHT);
  157.       break;
  158.     case right:
  159.       hello.setAlignment(IStaticText::centerRight);
  160.       statusLine.setText(STR_RIGHT);
  161.       menuBar.uncheckItem(MI_CENTER);
  162.       menuBar.uncheckItem(MI_LEFT);
  163.       menuBar.checkItem(MI_RIGHT);
  164.       break;
  165.  }
  166.  return (*this);
  167. } /* end AHelloWindow :: setTextAlignment(...) */
  168.  
  169.  
  170.  
  171. /**************************************************************************
  172. * Class ACommandHandler :: ACommandHandler - Constructor for the Command  *
  173. *   Handler for the main window.                                          *
  174. *                                                                         *
  175. * Store the frame that events will be handled for                         *
  176. **************************************************************************/
  177. ACommandHandler :: ACommandHandler(AHelloWindow *helloFrame)
  178.   :frame(helloFrame)
  179. {
  180. } /* end ACommandHandler :: ACommandHandler(...) */
  181.  
  182.  
  183.  
  184. /**************************************************************************
  185. * Class ACommandHandler :: command -- Handles menu commands for the main  *
  186. *   window                                                                *
  187. **************************************************************************/
  188. IBase::Boolean  ACommandHandler :: command(ICommandEvent & cmdEvent)
  189. {
  190.   Boolean eventProcessed(true);         //Assume event will be processed
  191.  
  192. /*------------------------------------------------------------------------|
  193. |  Depending on the command event ID, call the AHelloWindow::setAlignment |
  194. |    function with the appropriate AHelloWorld::Alignment value.          |
  195. |------------------------------------------------------------------------*/
  196.   switch (cmdEvent.commandId())
  197.   {
  198.     case MI_CENTER:
  199.       frame->setTextAlignment(AHelloWindow::center);
  200.       break;
  201.     case MI_LEFT:
  202.       frame->setTextAlignment(AHelloWindow::left);
  203.       break;
  204.     case MI_RIGHT:
  205.       frame->setTextAlignment(AHelloWindow::right);
  206.       break;
  207.     default:
  208. /*------------------------------------------------------------------------|
  209. | The event was not processed                                             |
  210. |------------------------------------------------------------------------*/
  211.       eventProcessed=false;
  212.   } /* end switch */
  213.  
  214.   return(eventProcessed);
  215. } /* end ACommandHandler :: command(...) */
  216.