home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cpptba.zip / TOOLBAR.CPP < prev    next >
C/C++ Source or Header  |  1993-11-30  |  6KB  |  180 lines

  1. //
  2. // Project: Toolbars under IBM User Interface Class Libraries
  3. // File:    Toolbar.cpp
  4. // Author:  Stewart Hyde
  5. // Created: Nov   29, 1993
  6. // Updated: Nov   30, 1993
  7. //
  8. // Description:
  9. //
  10.  
  11. #include <iapp.hpp>                     //IApplication Class
  12. #include "toolbar.hpp"
  13. #include "toolbar.h"
  14.  
  15.  
  16. ToolBar::ToolBar(unsigned long windowId)        //Define Toolbar Constructor
  17.     : IFrameWindow (                            //Call IFrameWindow constructor
  18.       IFrameWindow::menuBar,                  //  Get Menu Bar from Resource File
  19.       windowId)                                 //  Main Window ID
  20. {
  21.     handleEventsFor(this);              //Set self as command event handler
  22.     setFocus();                         //Set focus to main window
  23.     show();                             //Set to show main window
  24. } /* end ToolBar :: ToolBar(...) */
  25.  
  26. Boolean ToolBar::command(ICommandEvent& cEvent)    //Define command member function
  27. {
  28.     if (cEvent.commandId() == MI_CLOSE) //Is Command Event Id = Close Id
  29.     {                                   //  Yes, the command is close
  30.       close();                          //  Let's close the main window
  31.       return true;                      //  Normally, you would return true
  32.     };                                  //  to indicate command processed
  33.     return false;                       //Return Command not Processed
  34. } /* end Bar :: command(...) */
  35.  
  36.  
  37. MainWin::MainWin(unsigned long windowId)        //Define Toolbar Constructor
  38.     : IFrameWindow (                            //Call IFrameWindow constructor
  39.       IFrameWindow::defaultStyle()              //  Use default styles plus
  40.       | IFrameWindow::menuBar,                  //  Get Menu Bar from Resource File
  41.       windowId)                                 //  Main Window ID
  42. {
  43.    IString aString("Simple Toolbar Example");  //Create text string for static text
  44.    IStaticText * staticText=new        //Create Static Text Control
  45.       IStaticText(5002, this, this);    //  Pass in myself as parent & owner
  46.    staticText->setText(aString);       //Set text in Static Text Control
  47.  
  48.    setupMenuBar(windowId);
  49.  
  50.    createTopToolBar();
  51.    createSideBar();
  52.  
  53.  
  54.    handleEventsFor(this);              //Set self as command event handler
  55.    setClient(staticText);              //Set button control in Client Area
  56.    setFocus();                         //Set focus to main window
  57.    show();                             //Set to show main window
  58. } /* end ToolBar :: ToolBar(...) */
  59.  
  60. MainWin::~MainWin()
  61. {
  62.    destroyTopToolBar();
  63.    destroySideBar();
  64. }
  65.  
  66.  
  67. void MainWin :: setupMenuBar(unsigned long windowId)  //Setup Menu Bar                       
  68. {                                       //                                     
  69.   menuBar=new IMenuBar(windowId,        //Create Menu Bar for main window     
  70.     this);                              //  Set self as parent                 .
  71.     fToolBarActive = false; 
  72.     fSideBarActive = false; 
  73.     ICommandHandler::handleEventsFor(this);//Set self as command event handler  
  74. } /* end MainWin :: setupMenuBar() */                       
  75.  
  76.  
  77.  
  78. void MainWin::createTopToolBar()
  79. {
  80.    if (!fToolBarActive)
  81.    {
  82.       //
  83.       // Not create the toolbar by setting up a frame extension for a frame
  84.       // window that a collect of bitmaps for items...
  85.       //
  86.        menuBar->disableItem(MI_ENABLE_TOP);     
  87.        menuBar->enableItem(MI_DISABLE_TOP);     
  88.  
  89.  
  90.       myToolBar = new ToolBar(WND_BAR);
  91.       addExtension(myToolBar,IFrameWindow::aboveClient, 40);         
  92.       fToolBarActive = true;
  93.    }
  94. }
  95.  
  96.  
  97. void MainWin::destroyTopToolBar()
  98. {
  99.    if (fToolBarActive)
  100.    {
  101.  
  102.        menuBar->enableItem(MI_ENABLE_TOP);     
  103.        menuBar->disableItem(MI_DISABLE_TOP);     
  104.  
  105.  
  106.       removeExtension(myToolBar);
  107.       delete myToolBar;
  108.       fToolBarActive = false;
  109.    }
  110. }
  111.  
  112.  
  113. void MainWin::createSideBar()
  114. {
  115.    if (!fSideBarActive)
  116.    {
  117.       //
  118.       // Not create the sidebar by setting up a frame extension for a frame
  119.       // window that a collect of bitmaps for items...
  120.       //
  121.        menuBar->disableItem(MI_ENABLE_SIDE);     
  122.        menuBar->enableItem(MI_DISABLE_SIDE);     
  123.  
  124.  
  125.       mySideBar = new ToolBar(WND_SIDE);
  126.       addExtension(mySideBar,IFrameWindow::rightOfClient, 40);         
  127.       fSideBarActive = true;
  128.    }
  129. }
  130.  
  131.  
  132. void MainWin::destroySideBar()
  133. {
  134.    if (fSideBarActive)
  135.    {
  136.  
  137.        menuBar->enableItem(MI_ENABLE_SIDE);     
  138.        menuBar->disableItem(MI_DISABLE_SIDE);     
  139.  
  140.  
  141.       removeExtension(mySideBar);
  142.       delete mySideBar;
  143.       fSideBarActive = false;
  144.    }
  145. }
  146.  
  147.  
  148. Boolean MainWin::command(ICommandEvent& cEvent)    //Define command member function
  149. {
  150.     switch (cEvent.commandId())
  151.     {
  152.       case MI_CLOSE:
  153.          close();
  154.          break;
  155.       case MI_ENABLE_TOP:
  156.          createTopToolBar();
  157.          break;
  158.       case MI_DISABLE_TOP:
  159.          destroyTopToolBar();
  160.          break;
  161.       case MI_ENABLE_SIDE:
  162.          createSideBar();
  163.          break;
  164.       case MI_DISABLE_SIDE:
  165.          destroySideBar();
  166.          break;
  167.       default:
  168.          return false;
  169.     }                        
  170.     return true;                       //Return Command not Processed
  171. } /* end Toolbar :: command(...) */
  172.  
  173.  
  174. void main()                             //Main Procedure with no parameters
  175. {
  176.   MainWin mainWindow(WND_MAIN);         //Create main window on the desktop
  177.   IApplication::current().run();        //Get current application & start runnig
  178. } /* end main */
  179.  
  180.