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 >
Wrap
Text File
|
1995-05-01
|
7KB
|
224 lines
#ifndef _IBASE_ //Make sure ibase.hpp is included
#include <ibase.hpp> // since that is where IC_<environ>
#endif // is defined.
#include <iapp.hpp>
#include <iframe.hpp>
#include <ifont.hpp>
#include <itbar.hpp>
#include <itbarbut.hpp>
#include <imle.hpp>
#include <icmdhdr.hpp>
#include <imenubar.hpp>
#include <iflytext.hpp>
#include <istattxt.hpp>
#include <iflyhhdr.hpp>
#include <icombobx.hpp>
#include <iselhdr.hpp>
#include "tbar1.hpp"
#include "tbar1.h"
//-------------------------------------------------------------------
// Main routine
//
// This routine creates and shows the editor window
//-------------------------------------------------------------------
int main()
{
Editor editor;
editor.show();
editor.setFocus();
IApplication::current().run();
return 0;
}
//-------------------------------------------------------------------
// Editor::Editor
//
// This constructor initializes all of the windows (including the
// tool bar and tool bar buttons).
//
// Note: The tool bar buttons are created with standard identifiers
// that are provided by the class library (defined in icconst.h) for
// standard operations.
//-------------------------------------------------------------------
Editor::Editor ()
:IFrameWindow("Tool Bar Sample 1", ID_MAIN_WINDOW),
toolBar(ID_TOOLBAR, this),
flyText(ID_FLYTEXT, &toolBar),
infoText(ID_INFOTEXT, this, this),
flyHelpHandler(&flyText, &infoText, 0, 0),
editWindow(ID_EDITOR, this, this),
fontSelectHandler(*this),
cutButton (IC_ID_CUT, &toolBar, &toolBar),
copyButton (IC_ID_COPY, &toolBar, &toolBar),
pasteButton (IC_ID_PASTE, &toolBar, &toolBar),
boldButton (IC_ID_BOLD, &toolBar, &toolBar),
italicButton (IC_ID_ITALIC, &toolBar, &toolBar),
underscoreButton(IC_ID_UNDERSCORE, &toolBar, &toolBar),
fontCombo(ID_FONTCOMBO, &toolBar, &toolBar, IRectangle(),
IComboBox::classDefaultStyle &~IComboBox::simpleType |
IComboBox::dropDownListType),
menu(ID_MAIN_WINDOW,this),
editFont("Times New Roman",8)
{
// Set the icon
setIcon( id() );
// Add the buttons to the toolbar
toolBar.addAsLast(&cutButton,true);
toolBar.addAsLast(©Button);
toolBar.addAsLast(&pasteButton);
toolBar.addAsLast(&boldButton,true);
toolBar.addAsLast(&italicButton);
toolBar.addAsLast(&underscoreButton);
toolBar.addAsLast(&fontCombo,true);
// Set up latchable style for font property buttons
boldButton.enableLatching();
italicButton.enableLatching();
underscoreButton.enableLatching();
// Load up font combo box with face names
fontCombo.setLimit(10);
IFont::FaceNameCursor fontCursor;
for ( fontCursor.setToFirst(); fontCursor.isValid(); fontCursor.setToNext())
{
IString faceName = IFont::faceNameAt(fontCursor);
fontCombo.addAsLast(faceName);
if (faceName.length() > fontCombo.limit())
fontCombo.setLimit(faceName.length());
}
// Set up title for toolbar when floating
toolBar.setFloatingTitle("Toolbar");
// Setup the editor
setClient(&editWindow);
editWindow.setFont(editFont);
editWindow.importFromFile("toolbar.not");
editWindow.setTop(1);
// Add the Info frame extension
addExtension(&infoText, IFrameWindow::belowClient);
// Set up and add the help handler
flyHelpHandler.setLongStringTableOffset(OFFSET_INFOTEXT);
flyHelpHandler.setDefaultText("\0");
flyHelpHandler.handleEventsFor(&toolBar);
// Attach the Command Handler to frame and toolbar
handleEventsFor(this);
handleEventsFor(&toolBar);
// Add the handler to change the font
fontSelectHandler.handleEventsFor(&fontCombo);
moveSizeToClient(IRectangle(IPoint(100,100),
ISize(editFont.avgCharWidth()*80,
editFont.maxCharHeight()*15)));
}
//-------------------------------------------------------------------
// Handle user menu bar selections
//-------------------------------------------------------------------
Boolean Editor::command(ICommandEvent &event)
{
switch (event.commandId())
{
case IC_ID_CUT:
{
if(editWindow.hasSelectedText())
editWindow.cut();
break;
}
case IC_ID_COPY:
{
if(editWindow.hasSelectedText())
editWindow.copy();
break;
}
case IC_ID_PASTE:
{
if(editWindow.clipboardHasTextFormat())
editWindow.paste();
break;
}
case IC_ID_BOLD:
{
editFont.setBold(boldButton.isLatched());
editWindow.setFont(editFont);
break;
}
case IC_ID_ITALIC:
{
editFont.setItalic(italicButton.isLatched());
editWindow.setFont(editFont);
break;
}
case IC_ID_UNDERSCORE:
{
editFont.setUnderscore(underscoreButton.isLatched());
editWindow.setFont(editFont);
break;
}
case ID_SHOWTEXT:
{
toolBar.setButtonView(IToolBarButton::textView);
break;
}
case ID_SHOWBITMAPS:
{
toolBar.setButtonView(IToolBarButton::bitmapView);
break;
}
case ID_SHOWTEXTANDBITMAPS:
{
toolBar.setButtonView(IToolBarButton::bitmapAndTextView);
break;
}
case ID_TOOLBAR_TOP:
{
toolBar.setLocation(IToolBar::aboveClient);
break;
}
case ID_TOOLBAR_BOTTOM:
{
toolBar.setLocation(IToolBar::belowClient);
break;
}
case ID_TOOLBAR_LEFT:
{
toolBar.setLocation(IToolBar::leftOfClient);
break;
}
case ID_TOOLBAR_RIGHT:
{
toolBar.setLocation(IToolBar::rightOfClient);
break;
}
case ID_TOOLBAR_FLOATING:
{
toolBar.setLocation(IToolBar::floating);
break;
}
}
return true;
}
//-------------------------------------------------------------------
// Handle combo box selections
//-------------------------------------------------------------------
Boolean FontSelectHandler::enter( IControlEvent& event)
{
IString fontChoice = ((IComboBox*)event.controlWindow())->text();
if(fontChoice.length())
{
// Set the new font
editorFrame.editorFont().setName(fontChoice);
editorFrame.editorWindow().setFont(editorFrame.editorFont());
}
return true;
}