home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ctdemo.zip / classes / @CLSLIB1.ZIP / cls / iclui / ahlwndw5.cpp < prev    next >
C/C++ Source or Header  |  1995-04-07  |  10KB  |  452 lines

  1. #ifndef INC_AHELLOWINDOW5
  2. #define INC_AHELLOWINDOW5
  3.  
  4. #ifndef __FIRST__
  5. #define __FIRST__
  6. #define __IMPL__AHELLOWINDOW5
  7. #endif
  8.  
  9. /////V AHelloWindow5 PCM f:\cls_ibm\cls\iclui 7  PM 07.04.95 11:54:31
  10. /*
  11. /////H
  12. 20.10.94 19:37 PM 0 copied from: AHelloWindow5 TOS f:\cls_ibm\cls\iclui 0 PM 19.10.94 00:26:00
  13. 30.03.95 10:34 PM 0 archived: AHelloWindow5 PCM f:\cls_ibm\cls\iclui 0 PM 20.10.94 19:37:13
  14. /////
  15. */
  16.  
  17. /////1
  18. #undef inline
  19.  
  20. #include <bsa.h>
  21.  
  22. /////I iframe.hpp @ @ @ @ pre 
  23. #include <iframe.hpp>
  24.  
  25. /////I icmdhdr.hpp @ @ @ @ pre 
  26. #include <icmdhdr.hpp>
  27.  
  28. /////I iselhdr.hpp @ @ @ @ pre 
  29. #include <iselhdr.hpp>
  30.  
  31. /////I ihelphdr.hpp @ @ @ @ pre 
  32. #include <ihelphdr.hpp>
  33.  
  34. /////T Forward pre 
  35. class IPushButton;
  36. class ISplitCanvas;
  37. class IStaticText;
  38. class IHelpWindow;
  39. class IInfoArea;
  40. class IListBox;
  41. class IMenuBar;
  42.  
  43. class ATextDialog;              //Define the ATextDialog Class
  44. class AEarthWindow;             //Define the AEarthWindow Class
  45. /////
  46.  
  47. /////T Aux pre 
  48. /*
  49.  *    Since this is a VERY small class that is used just for
  50.  *    AHelloWindow5,  we don't convert it separately.
  51.  *    However, there are other ways to organize this stuff
  52.  */
  53.  
  54. class AHelpHandler: public IHelpHandler
  55. {
  56.   protected:
  57.    virtual Boolean keysHelpId ( IEvent& evt )
  58.     {
  59.       evt.setResult(1000);  // 1000=keys help id in ahellow5.ipf file
  60.       return true;          //Return command processed
  61.     }
  62. };
  63. /////
  64.  
  65.  
  66. #ifndef __INLINE__
  67. #define inline
  68. #endif
  69.  
  70. /////C AHelloWindow5 @ @ app define:_PM_ 
  71. class AHelloWindow5 :
  72.  
  73. /////B IFrameWindow @ @ multiple extern visible 
  74. public  IFrameWindow,
  75.  
  76. /////B ICommandHandler @ @ multiple extern visible 
  77. public  ICommandHandler,
  78.  
  79. /////B ISelectHandler @ @ multiple extern visible 
  80. public  ISelectHandler
  81.  
  82. {
  83.  
  84. private:
  85. /////D centerButton @  @ instance private 
  86.     IPushButton *  centerButton;
  87.  
  88. /////D clientWindow @  @ instance private 
  89.     ISplitCanvas *  clientWindow;
  90.  
  91. /////D earthWindow @  @ instance private 
  92.     AEarthWindow *  earthWindow;
  93.  
  94. /////D hello @  @ instance private 
  95.     IStaticText *  hello;
  96.  
  97. /////D helloCanvas @  @ instance private 
  98.     ISplitCanvas *  helloCanvas;
  99.  
  100. /////D help @  @ instance private 
  101.     IHelpWindow *  help;
  102.  
  103. /////D infoArea @  @ instance private 
  104.     IInfoArea *  infoArea;
  105.  
  106. /////D leftButton @  @ instance private 
  107.     IPushButton *  leftButton;
  108.  
  109. /////D listBox @  @ instance private 
  110.     IListBox *  listBox;
  111.  
  112. /////D menuBar @  @ instance private 
  113.     IMenuBar *  menuBar;
  114.  
  115. /////D rightButton @  @ instance private 
  116.     IPushButton *  rightButton;
  117.  
  118. /////D statusLine @  @ instance private 
  119.     IStaticText *  statusLine;
  120.  
  121. /////D textDialog @  @ instance private 
  122.     ATextDialog *  textDialog;
  123.  
  124.  
  125. protected:
  126.     Boolean  command (ICommandEvent&);
  127.     virtual Boolean  selected (IControlEvent&);
  128.     virtual Boolean  setText (const char*);
  129.     virtual Boolean  setupButtons ();
  130.     virtual Boolean  setupClient ();
  131.     virtual Boolean  setupHelp ();
  132.     virtual Boolean  setupInfoArea ();
  133.     virtual Boolean  setupMenuBar ();
  134.     virtual Boolean  setupStatusArea ();
  135. public:
  136.     AHelloWindow5 (unsigned long);
  137. };
  138.  
  139.  
  140. /////2
  141. #undef inline
  142.  
  143.  
  144. #if (defined __INLINE__) || (defined __IMPL__AHELLOWINDOW5)
  145.  
  146. #ifndef __INLINE__
  147. #define inline
  148. #endif
  149.  
  150. /////
  151. #endif
  152.  
  153. /////3
  154. #undef inline
  155.  
  156. #ifdef __IMPL__AHELLOWINDOW5
  157. /////I iapp.hpp @ @ @ @ impl 
  158. #include <iapp.hpp>
  159.  
  160. /////I istattxt.hpp @ @ @ @ impl 
  161. #include <istattxt.hpp>
  162.  
  163. /////I iinfoa.hpp @ @ @ @ impl 
  164. #include <iinfoa.hpp>
  165.  
  166. /////I imenubar.hpp @ @ @ @ impl 
  167. #include <imenubar.hpp>
  168.  
  169. /////I ifont.hpp @ @ @ @ impl 
  170. #include <ifont.hpp>
  171.  
  172. /////I istring.hpp @ @ @ @ impl 
  173. #include <istring.hpp>
  174.  
  175. /////I isetcv.hpp @ @ @ @ impl 
  176. #include <isetcv.hpp>
  177.  
  178. /////I ipushbut.hpp @ @ @ @ impl 
  179. #include <ipushbut.hpp>
  180.  
  181. /////I ihelp.hpp @ @ @ @ impl 
  182. #include <ihelp.hpp>
  183.  
  184. /////I isplitcv.hpp @ @ @ @ impl 
  185. #include <isplitcv.hpp>
  186.  
  187. /////I ilistbox.hpp @ @ @ @ impl 
  188. #include <ilistbox.hpp>
  189.  
  190. /////I ahellow5.h @ @ @ @ impl 
  191. #include <ahellow5.h>
  192.  
  193. /////I ATextDialog @ @ @ @ class impl 
  194. #include <atxtdlog.cpp>
  195.  
  196. /////I AEarthWindow @ @ @ @ class impl 
  197. #include <aertwndw.cpp>
  198.  
  199. /////F AHelloWindow5 @ @ instance public 
  200. AHelloWindow5 :: AHelloWindow5(unsigned long windowId)
  201.   : IFrameWindow (
  202.     IFrameWindow::defaultStyle()
  203.     | IFrameWindow::minimizedIcon
  204.     | IFrameWindow::menuBar
  205.     | IFrameWindow::accelerator,
  206.     windowId)
  207. {
  208.   setupClient();
  209.   setupStatusArea();
  210.   setupInfoArea();
  211.   setupButtons();
  212.   setupMenuBar();
  213.   setupHelp();
  214.  
  215.   sizeTo(ISize(400,300));
  216.   setFocus();
  217.   show();
  218.  
  219. }
  220.  
  221. /////F command @ @ instance protected 
  222. Boolean AHelloWindow5 :: command(ICommandEvent & cmdEvent)
  223. {
  224.   IString temp;
  225.   unsigned short value;
  226.  
  227.   switch (cmdEvent.commandId()) {
  228.  
  229.     case MI_CENTER:
  230.       hello->setAlignment(
  231.         IStaticText::centerCenter);
  232.       statusLine->setText(STR_CENTER);
  233.       menuBar->checkItem(MI_CENTER);
  234.       menuBar->uncheckItem(MI_LEFT);
  235.       menuBar->uncheckItem(MI_RIGHT);
  236.       return(true);
  237.       break;
  238.  
  239.     case MI_LEFT:
  240.       hello->setAlignment(
  241.         IStaticText::centerLeft);
  242.       statusLine->setText(STR_LEFT);
  243.       menuBar->uncheckItem(MI_CENTER);
  244.       menuBar->checkItem(MI_LEFT);
  245.       menuBar->uncheckItem(MI_RIGHT);
  246.       return(true);
  247.       break;
  248.  
  249.     case MI_RIGHT:
  250.       hello->setAlignment(
  251.         IStaticText::centerRight);
  252.       statusLine->setText(STR_RIGHT);
  253.       menuBar->uncheckItem(MI_CENTER);
  254.       menuBar->uncheckItem(MI_LEFT);
  255.       menuBar->checkItem(MI_RIGHT);
  256.       return(true);
  257.       break;
  258.  
  259.     case MI_TEXT:
  260.       {
  261.       temp=hello->text();
  262.       infoArea->setInactiveText(
  263.         STR_INFODLG);
  264.       ATextDialog * textDialog=new
  265.         ATextDialog(temp, this);
  266.       textDialog->showModally();
  267.       value=textDialog->result();
  268.       if (value != DID_CANCEL)
  269.         hello->setText(temp);
  270.       infoArea->setInactiveText(STR_INFO);
  271.       delete textDialog;
  272.       return(true);
  273.       break;
  274.       }
  275.  
  276.     case MI_GENERAL_HELP:
  277.       help->show(IHelpWindow::general);
  278.       return(true);
  279.       break;
  280.  
  281.   } 
  282.  
  283.   return(false);
  284. }
  285.  
  286. /////
  287. #ifdef __APPCLASS__
  288. /////F main @ @ global 
  289. void main()
  290. {
  291.   AHelloWindow5 mainWindow (WND_MAIN);
  292.  
  293.   IApplication::current().run();
  294.  
  295. }
  296. /////
  297. #endif
  298.  
  299. /////F selected @ @ terminal protected instance 
  300. Boolean AHelloWindow5 :: selected(IControlEvent & evt)
  301. {
  302.   IListBox::Cursor lbCursor(*listBox);
  303.   lbCursor.setToFirst();
  304.   setText(listBox->elementAt(lbCursor));
  305.   return true;
  306. }
  307.  
  308. /////F setText @ @ terminal protected instance 
  309. Boolean AHelloWindow5 :: setText(const char* text)
  310. {
  311.   hello->setText(text);
  312.   return true;
  313. }
  314.  
  315. /////F setupButtons @ @ terminal protected instance 
  316. Boolean AHelloWindow5 :: setupButtons()
  317. {
  318.   ISetCanvas    * buttons;
  319.   IPushButton   * helpButton;
  320.  
  321.   buttons=new ISetCanvas(WND_BUTTONS,
  322.     this, this) ;
  323.   buttons->setMargin(ISize());
  324.   buttons->setPad(ISize());
  325.   leftButton=new IPushButton(MI_LEFT,
  326.     buttons, buttons, IRectangle(),
  327.     IPushButton::defaultStyle() |
  328.     IControl::tabStop);
  329.   leftButton->setText(STR_LEFTB);
  330.   centerButton=new IPushButton(MI_CENTER,
  331.     buttons, buttons, IRectangle(),
  332.     IPushButton::defaultStyle() |
  333.     IControl::tabStop);
  334.   centerButton->setText(STR_CENTERB);
  335.   rightButton=new IPushButton(MI_RIGHT,
  336.     buttons, buttons, IRectangle(),
  337.     IPushButton::defaultStyle() |
  338.     IControl::tabStop);
  339.   rightButton->setText(STR_RIGHTB);
  340.   helpButton=new IPushButton(MI_HELP,
  341.     buttons, buttons, IRectangle(),
  342.     IPushButton::defaultStyle() |
  343.     IPushButton::help |
  344.     IButton::noPointerFocus |
  345.     IControl::tabStop);
  346.   helpButton->setText(STR_HELPB);
  347.   addExtension(buttons,
  348.     IFrameWindow::belowClient,
  349.     30UL);
  350.   return true;
  351. }
  352.  
  353. /////F setupClient @ @ terminal protected instance 
  354. Boolean AHelloWindow5 :: setupClient()
  355. {
  356.   clientWindow=new ISplitCanvas(
  357.     WND_CANVAS, this, this);
  358.   setClient(clientWindow);
  359.  
  360.   helloCanvas=new ISplitCanvas(
  361.     WND_HCANVAS, clientWindow,
  362.     clientWindow);
  363.   helloCanvas->setOrientation(
  364.     ISplitCanvas::horizontalSplit);
  365.  
  366.   hello=new IStaticText(WND_HELLO,
  367.     helloCanvas, helloCanvas);
  368.   hello->setText(STR_HELLO);
  369.  
  370.   earthWindow  = new AEarthWindow
  371.     (WND_EARTH, helloCanvas);
  372.  
  373.   hello->setAlignment(
  374.     IStaticText::centerCenter);
  375.  
  376.   listBox=new IListBox(WND_LISTBOX,
  377.     clientWindow, clientWindow,
  378.     IRectangle(),
  379.     IListBox::defaultStyle() |
  380.     IControl::tabStop |
  381.     IListBox::noAdjustPosition);
  382.   listBox->addAscending("Hello, World!");
  383.   listBox->addAscending("Hi, World!");
  384.   listBox->addAscending("Howdy, World!");
  385.   listBox->addAscending("Alo, Mundo!");
  386.   listBox->addAscending("Ola, Mondo!");
  387.   listBox->addAscending("Hallo wereld!");
  388.   listBox->addAscending("Hallo Welt!");
  389.   listBox->addAscending("Bonjour le monde!");
  390.   ISelectHandler::handleEventsFor(listBox);
  391.  
  392.   clientWindow->setSplitWindowPercentage(
  393.     helloCanvas, 60);
  394.   clientWindow->setSplitWindowPercentage(
  395.     listBox, 40);
  396.  
  397.   return true;
  398. }
  399.  
  400. /////F setupHelp @ @ terminal protected instance 
  401. Boolean AHelloWindow5 :: setupHelp()
  402. {
  403.   help=new IHelpWindow(HELP_TABLE,
  404.     this);
  405.   help->addLibraries("AHELLOW5.HLP");
  406.   help->setTitle(STR_HTITLE);
  407.  
  408.   AHelpHandler* phelpHandler=
  409.     new AHelpHandler();
  410.   phelpHandler->handleEventsFor(this);
  411.   return true;
  412. }
  413.  
  414. /////F setupInfoArea @ @ terminal protected instance 
  415. Boolean AHelloWindow5 :: setupInfoArea()
  416. {
  417.   infoArea=new IInfoArea(this);
  418.   infoArea->setInactiveText(STR_INFO);
  419.   setExtensionSize(infoArea,
  420.     (int)IFont(infoArea).maxCharHeight());
  421. //  IFont(infoArea).maxCharHeight());        // changed headers in CPPBETA !!
  422.  
  423.   return true;
  424. }
  425.  
  426. /////F setupMenuBar @ @ terminal protected instance 
  427. Boolean AHelloWindow5 :: setupMenuBar()
  428. {
  429.   ICommandHandler::handleEventsFor(this);
  430.   menuBar=new IMenuBar(WND_MAIN,
  431.     this);
  432.   menuBar->checkItem(MI_CENTER);
  433.   return true;
  434. }
  435.  
  436. /////F setupStatusArea @ @ terminal protected instance 
  437. Boolean AHelloWindow5 :: setupStatusArea()
  438. {
  439.   statusLine=new IStaticText
  440.     (WND_STATUS, this, this);
  441.   statusLine->setText(STR_CENTER);
  442.   addExtension(statusLine,
  443.     IFrameWindow::aboveClient,
  444.     IFont(statusLine).maxCharHeight());
  445.   return true;
  446. }
  447.  
  448. /////
  449. #endif
  450.  
  451. #endif
  452.