home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / VSCPPv8.zip / VACPP / IBMCPP / samples / IOC / TBAR1 / TBAR1.CPP < prev    next >
Text File  |  1995-05-01  |  7KB  |  224 lines

  1. #ifndef _IBASE_                         //Make sure ibase.hpp is included
  2.   #include <ibase.hpp>                  //  since that is where IC_<environ>
  3. #endif                                  //  is defined.
  4. #include <iapp.hpp>
  5. #include <iframe.hpp>
  6. #include <ifont.hpp>
  7. #include <itbar.hpp>
  8. #include <itbarbut.hpp>
  9. #include <imle.hpp>
  10. #include <icmdhdr.hpp>
  11. #include <imenubar.hpp>
  12. #include <iflytext.hpp>
  13. #include <istattxt.hpp>
  14. #include <iflyhhdr.hpp>
  15. #include <icombobx.hpp>
  16. #include <iselhdr.hpp>
  17.  
  18. #include "tbar1.hpp"
  19. #include "tbar1.h"
  20.  
  21. //-------------------------------------------------------------------
  22. // Main routine
  23. //
  24. // This routine creates and shows the editor window
  25. //-------------------------------------------------------------------
  26. int main()
  27. {
  28.    Editor editor;
  29.    editor.show();
  30.    editor.setFocus();
  31.    IApplication::current().run();
  32.    return 0;
  33. }
  34.  
  35. //-------------------------------------------------------------------
  36. // Editor::Editor
  37. //
  38. // This constructor initializes all of the windows (including the
  39. // tool bar and tool bar buttons).
  40. //
  41. // Note: The tool bar buttons are created with standard identifiers
  42. // that are provided by the class library (defined in icconst.h) for
  43. // standard operations.
  44. //-------------------------------------------------------------------
  45. Editor::Editor ()
  46.        :IFrameWindow("Tool Bar Sample 1", ID_MAIN_WINDOW),
  47.         toolBar(ID_TOOLBAR, this),
  48.         flyText(ID_FLYTEXT, &toolBar),
  49.         infoText(ID_INFOTEXT, this, this),
  50.         flyHelpHandler(&flyText, &infoText, 0, 0),
  51.         editWindow(ID_EDITOR, this, this),
  52.         fontSelectHandler(*this),
  53.         cutButton       (IC_ID_CUT,        &toolBar, &toolBar),
  54.         copyButton      (IC_ID_COPY,       &toolBar, &toolBar),
  55.         pasteButton     (IC_ID_PASTE,      &toolBar, &toolBar),
  56.         boldButton      (IC_ID_BOLD,       &toolBar, &toolBar),
  57.         italicButton    (IC_ID_ITALIC,     &toolBar, &toolBar),
  58.         underscoreButton(IC_ID_UNDERSCORE, &toolBar, &toolBar),
  59.         fontCombo(ID_FONTCOMBO, &toolBar, &toolBar, IRectangle(),
  60.                   IComboBox::classDefaultStyle &~IComboBox::simpleType |
  61.                   IComboBox::dropDownListType),
  62.         menu(ID_MAIN_WINDOW,this),
  63.         editFont("Times New Roman",8)
  64. {
  65.    // Set the icon
  66.    setIcon( id() );
  67.  
  68.    // Add the buttons to the toolbar
  69.    toolBar.addAsLast(&cutButton,true);
  70.    toolBar.addAsLast(©Button);
  71.    toolBar.addAsLast(&pasteButton);
  72.    toolBar.addAsLast(&boldButton,true);
  73.    toolBar.addAsLast(&italicButton);
  74.    toolBar.addAsLast(&underscoreButton);
  75.    toolBar.addAsLast(&fontCombo,true);
  76.  
  77.    // Set up latchable style for font property buttons
  78.    boldButton.enableLatching();
  79.    italicButton.enableLatching();
  80.    underscoreButton.enableLatching();
  81.  
  82.    // Load up font combo box with face names
  83.    fontCombo.setLimit(10);
  84.    IFont::FaceNameCursor fontCursor;
  85.    for ( fontCursor.setToFirst(); fontCursor.isValid(); fontCursor.setToNext())
  86.    {
  87.      IString faceName = IFont::faceNameAt(fontCursor);
  88.      fontCombo.addAsLast(faceName);
  89.      if (faceName.length() > fontCombo.limit())
  90.        fontCombo.setLimit(faceName.length());
  91.    }
  92.  
  93.    // Set up title for toolbar when floating
  94.    toolBar.setFloatingTitle("Toolbar");
  95.  
  96.    // Setup the editor
  97.    setClient(&editWindow);
  98.    editWindow.setFont(editFont);
  99.    editWindow.importFromFile("toolbar.not");
  100.    editWindow.setTop(1);
  101.  
  102.    // Add the Info frame extension
  103.    addExtension(&infoText, IFrameWindow::belowClient);
  104.  
  105.    // Set up and add the help handler
  106.    flyHelpHandler.setLongStringTableOffset(OFFSET_INFOTEXT);
  107.    flyHelpHandler.setDefaultText("\0");
  108.    flyHelpHandler.handleEventsFor(&toolBar);
  109.  
  110.    // Attach the Command Handler to frame and toolbar
  111.    handleEventsFor(this);
  112.    handleEventsFor(&toolBar);
  113.  
  114.    // Add the handler to change the font
  115.    fontSelectHandler.handleEventsFor(&fontCombo);
  116.  
  117.    moveSizeToClient(IRectangle(IPoint(100,100),
  118.                                ISize(editFont.avgCharWidth()*80,
  119.                                      editFont.maxCharHeight()*15)));
  120. }
  121.  
  122. //-------------------------------------------------------------------
  123. // Handle user menu bar selections
  124. //-------------------------------------------------------------------
  125. Boolean Editor::command(ICommandEvent &event)
  126. {
  127.    switch (event.commandId())
  128.    {
  129.      case IC_ID_CUT:
  130.      {
  131.          if(editWindow.hasSelectedText())
  132.             editWindow.cut();
  133.          break;
  134.      }
  135.      case IC_ID_COPY:
  136.      {
  137.          if(editWindow.hasSelectedText())
  138.             editWindow.copy();
  139.          break;
  140.      }
  141.      case IC_ID_PASTE:
  142.      {
  143.          if(editWindow.clipboardHasTextFormat())
  144.             editWindow.paste();
  145.          break;
  146.      }
  147.      case IC_ID_BOLD:
  148.      {
  149.          editFont.setBold(boldButton.isLatched());
  150.          editWindow.setFont(editFont);
  151.          break;
  152.      }
  153.      case IC_ID_ITALIC:
  154.      {
  155.          editFont.setItalic(italicButton.isLatched());
  156.          editWindow.setFont(editFont);
  157.          break;
  158.      }
  159.      case IC_ID_UNDERSCORE:
  160.      {
  161.          editFont.setUnderscore(underscoreButton.isLatched());
  162.          editWindow.setFont(editFont);
  163.          break;
  164.      }
  165.      case ID_SHOWTEXT:
  166.      {
  167.          toolBar.setButtonView(IToolBarButton::textView);
  168.          break;
  169.      }
  170.      case ID_SHOWBITMAPS:
  171.      {
  172.          toolBar.setButtonView(IToolBarButton::bitmapView);
  173.          break;
  174.      }
  175.      case ID_SHOWTEXTANDBITMAPS:
  176.      {
  177.          toolBar.setButtonView(IToolBarButton::bitmapAndTextView);
  178.          break;
  179.      }
  180.      case ID_TOOLBAR_TOP:
  181.      {
  182.          toolBar.setLocation(IToolBar::aboveClient);
  183.          break;
  184.      }
  185.      case ID_TOOLBAR_BOTTOM:
  186.      {
  187.          toolBar.setLocation(IToolBar::belowClient);
  188.          break;
  189.      }
  190.      case ID_TOOLBAR_LEFT:
  191.      {
  192.          toolBar.setLocation(IToolBar::leftOfClient);
  193.          break;
  194.      }
  195.      case ID_TOOLBAR_RIGHT:
  196.      {
  197.          toolBar.setLocation(IToolBar::rightOfClient);
  198.          break;
  199.      }
  200.      case ID_TOOLBAR_FLOATING:
  201.      {
  202.          toolBar.setLocation(IToolBar::floating);
  203.          break;
  204.      }
  205.    }
  206.    return true;
  207. }
  208.  
  209. //-------------------------------------------------------------------
  210. // Handle combo box selections
  211. //-------------------------------------------------------------------
  212. Boolean FontSelectHandler::enter( IControlEvent& event)
  213. {
  214.   IString fontChoice =  ((IComboBox*)event.controlWindow())->text();
  215.   if(fontChoice.length())
  216.   {
  217.      // Set the new font
  218.      editorFrame.editorFont().setName(fontChoice);
  219.      editorFrame.editorWindow().setFont(editorFrame.editorFont());
  220.   }
  221.   return true;
  222. }
  223.  
  224.