home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / samples / ioc / acdf6 / acdfvw6.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-22  |  6.9 KB  |  247 lines

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //                                              SAMPLE CODE
  3. //
  4. // FileName: ACDFVw6.cpp
  5. //
  6. // ClassName: ACompDocFwkView
  7. //
  8. // Description: Conversion of the Hello World 5 Sample
  9. //
  10. ///////////////////////////////////////////////////////////////////////////////
  11. #include "ACDFMdl6.hpp"
  12. #include "ACDFVw6.hpp"
  13. #include "acdfbd6.hpp"
  14. #include "acdfdlg6.hpp"
  15.  
  16. #include <igstring.hpp>
  17. #include <igrect.hpp>
  18. #include <igrafctx.hpp>
  19. #include <imsgbox.hpp>
  20. #include <ifont.hpp>
  21. #include <imenubar.hpp>
  22. #include <iframe.hpp>  // must be included to set the icon
  23. #include "acdfres6.h"
  24.  
  25. #include <iGUIBndl.hpp> // must be include after windows.h
  26.  
  27. ACompDocFwkView::ACompDocFwkView(IGUIBundle& bundle ) :
  28.     IView(bundle),
  29.     clientWindow(WND_CANVAS,
  30.                 this,
  31.                 this),
  32.     helloCanvas(WND_HCANVAS, 
  33.                 &clientWindow,
  34.                 &clientWindow,
  35.                 IRectangle(),
  36.                 IWindow::visible |
  37.                 ISplitCanvas::horizontal),
  38.     hello(WND_HELLO,
  39.                 &helloCanvas,
  40.                 &helloCanvas),
  41.     earthWindow(WND_EARTH,  
  42.                 &helloCanvas  ),
  43.     listBox(WND_LISTBOX,
  44.                 &clientWindow,
  45.                 &clientWindow,
  46.                 IRectangle(),
  47.                 IListBox::defaultStyle() |
  48.                 IControl::tabStop |
  49.                 IListBox::noAdjustPosition),
  50.     fCommandHandler(*this, handleCommand),
  51.     fSelectHandler(*this),
  52.     fHelpHandler(*this)
  53.     // Constructor
  54. {   IFUNCTRACE_DEVELOP();
  55.     bundle.frameWindow().setIcon(IC_ACDF6);
  56.     bundle.frameWindow().setId(WND_MAIN);
  57. }
  58.  
  59. ACompDocFwkView::~ACompDocFwkView()
  60. // Destructor
  61. {   IFUNCTRACE_DEVELOP(); 
  62.     fCommandHandler.stopHandlingEventsFor(this);
  63.     fSelectHandler.stopHandlingEventsFor(&listBox);
  64.     fHelpHandler.stopHandlingEventsFor(&bundle().frameWindow());
  65. }
  66.  
  67. void ACompDocFwkView::initialize()
  68. // Intialize code e.g build menus
  69. {   IFUNCTRACE_DEVELOP();
  70.     IView::initialize();
  71.     bundle().objectView().setBackgroundColor(IColor(64,128,128)); // Set the color to green
  72.  
  73.     this->sizeTo(ISize(400,300));
  74.     
  75.     //Get the frame window handle from the bundle
  76.  
  77.     setViewClient(&clientWindow);
  78.  
  79.     clientWindow.setSplitWindowPercentage(&helloCanvas, 60);
  80.     clientWindow.setSplitWindowPercentage(&listBox, 40);
  81.  
  82.     for (int i=0;i<=HI_COUNT;i++)
  83.     {
  84.         listBox.addAscending(HI_WORLD+i);
  85.     }
  86.  
  87.     hello.setText(STR_HELLO);
  88.     fSelectHandler.handleEventsFor(&listBox);
  89.  
  90.     fCommandHandler.handleEventsFor(this);
  91.     fHelpHandler.handleEventsFor(&bundle().frameWindow());
  92.     setTextAlignment(center);
  93. }
  94.  
  95.  
  96. void ACompDocFwkView::drawContents( IPresSpaceHandle& hdl,
  97.                   const IRectangle& invalidArea,
  98.                   Boolean metaFile )
  99. //  We can override "drawContents" if we want to optimize our drawing
  100. //  or do things differently when rendering to a meta-file (where controls
  101. //  won't be displayed).
  102. {   IFUNCTRACE_DEVELOP();
  103.     if (metaFile)
  104.     {
  105.     // Place the embedded image format here !!!
  106.        IGString myText(hello.text(),IPoint(20,10));
  107.        IGRectangle myRect(IRectangle(IPoint(10,10), IPoint(250,40)));
  108.        IGraphicContext ctxt ( hdl );
  109.        ctxt.setFillColor(IColor::white);
  110.        myRect.drawOn(ctxt);
  111.        myText.drawOn(ctxt);
  112.  
  113.     }
  114. }
  115.  
  116. Boolean ACompDocFwkView::handleCommand(ICommandEvent& cmdEvent)
  117. // Handle all the menu and push button commands
  118. {   IFUNCTRACE_DEVELOP();
  119.  
  120.     Boolean eventProcessed(true);
  121.     switch (cmdEvent.commandId())
  122.     {
  123.         case MI_CENTER:
  124.         {
  125.             setTextAlignment(ACompDocFwkView::center);
  126.             break;
  127.         }
  128.         case MI_LEFT:
  129.         {
  130.             setTextAlignment(ACompDocFwkView::left);
  131.             break;
  132.         }
  133.         case MI_RIGHT:
  134.         {
  135.             setTextAlignment(ACompDocFwkView::right);
  136.             break;
  137.         }
  138.         case MI_TEXT:
  139.         {
  140.             editText();
  141.             break;
  142.         }
  143.         default:
  144.         {
  145.             eventProcessed = false;
  146.             break;
  147.         }
  148.     }
  149.     return eventProcessed;
  150. }
  151.  
  152. Boolean ACompDocFwkView::handleSelected(IControlEvent& event)
  153. // Handle all the selections List Box
  154. {   IFUNCTRACE_DEVELOP();
  155.  
  156.     Boolean eventProcessed = false;
  157.  
  158.     if (event.controlId() == WND_LISTBOX)
  159.     {
  160.         setTextFromListBox();
  161.         eventProcessed = true;
  162.     }
  163.     return eventProcessed;
  164. }
  165. Boolean ACompDocFwkView::handleKeysHelpId(IEvent& event)
  166. // Handle the keys help request event
  167. {   IFUNCTRACE_DEVELOP();
  168.  
  169.     event.setResult(1000);  // 1000 = keys help ID
  170.  
  171.     return true;
  172.  
  173. ACompDocFwkView& ACompDocFwkView::setTextAlignment(const Alignment alignment)
  174. //align static text in client window
  175. {   IFUNCTRACE_DEVELOP();
  176.  
  177.     IMenuBar& myMenuBar = bundle().objectMenuBar();
  178.     ACompDocFwkMyBundle* myBundle = (ACompDocFwkMyBundle*) &bundle();
  179.     switch(alignment)
  180.     {
  181.         case left:
  182.         {       
  183.             hello.setAlignment(IStaticText::centerLeft);
  184.             myBundle->statusLine()->setText(STR_LEFT);
  185.             myMenuBar.uncheckItem(MI_CENTER);
  186.             myMenuBar.checkItem(MI_LEFT);
  187.             myMenuBar.uncheckItem(MI_RIGHT);
  188.             break;
  189.         }
  190.         case center:
  191.         {       
  192.             hello.setAlignment(IStaticText::centerCenter);
  193.             myBundle->statusLine()->setText(STR_CENTER);
  194.             myMenuBar.checkItem(MI_CENTER);
  195.             myMenuBar.uncheckItem(MI_LEFT);
  196.             myMenuBar.uncheckItem(MI_RIGHT);
  197.             break;
  198.         }
  199.         case right:
  200.         {       
  201.             hello.setAlignment(IStaticText::centerRight);
  202.             myBundle->statusLine()->setText(STR_RIGHT);
  203.             myMenuBar.uncheckItem(MI_CENTER);
  204.             myMenuBar.uncheckItem(MI_LEFT);
  205.             myMenuBar.checkItem(MI_RIGHT);
  206.             break;
  207.         }
  208.     }
  209.     return (*this);
  210. }
  211.  
  212. ACompDocFwkView& ACompDocFwkView::editText()
  213. // Creates and shows a dialog window for inputting text
  214. // that will be used to replace the text string
  215. {   IFUNCTRACE_DEVELOP();
  216.  
  217.     IString textValue(hello.text());
  218.     ACompDocFwkMyBundle* myBundle = (ACompDocFwkMyBundle*) &bundle();
  219.  
  220.     myBundle->infoArea()->setInactiveText(STR_INFODLG);
  221.     ATextDialog textDialog(textValue,this);
  222.     myBundle->helpWindow()->setAssociatedWindow(&textDialog);
  223.     textDialog.showModally();
  224.  
  225.     if (textDialog.result() == DID_OK)
  226.     {
  227.         hello.setText(textValue);
  228.     }
  229.  
  230.     myBundle->infoArea()->setInactiveText(STR_INFO);
  231.  
  232.     return (*this);
  233. }
  234.  
  235. ACompDocFwkView& ACompDocFwkView::setTextFromListBox()
  236. // Set the hello world text from the first selected item in the 
  237. // AHelloWindow listbox.
  238. {   IFUNCTRACE_DEVELOP();
  239.     IListBox::Cursor lbCursor(listBox);
  240.  
  241.     lbCursor.setToFirst();
  242.     hello.setText(listBox.elementAt(lbCursor));
  243.  
  244.     return (*this);
  245. }
  246.