Toolbar and Action Classes

Top  Previous  Next

WPTools contains a complete set of component to quickly build a user interface.

You can use the ready-to-use TWPToolbar to create an editor within 5 seconds, or you can use the action classes and your own choice of tool buttons to let the user change the attributes of the text.

 

a) Toolbar Components

 

The tool-bar components (TWPToolBar and TWPToolPanel) can be attached to any TWPRichText component using its property WPToolBar. If you have more than one use the propety WPToolBar.NextToolBar to connect to the next toolbar in the chain.

 

 

       TWPToolBar

 

This components makes it easy to start a new program which uses a TWPRichText component.

You only have to activate some flags in the object inspector and the TWPToolBar will display action and status buttons and some combo boxes to select the font or color of the text in the TWPRichText control.

       TWPToolPanel

 

Contrary to the toolbar, which creates and positions the buttons automatically, with the tool-panel component you have to drop the buttons in place. This gives you more freedom in the design of the user interface.

       TWPComboBox

 

This components can be used together with a TWPToolPanel or TWPToolCtrl. It can control the font, font size or colors of the text - to select the mode use the property ComboBoxStyle.

       TWPToolButton

 

This components can be used together with a TWPToolPanel. It can control the fonts styles or execute certain actions like 'Print', 'Load' or 'Save'. If you use the TWPToolBar you don't need the TWPComboBox or TWPToolButton control since the buttons and combo boxes are created by the TWPToolBar object.

 

b) Work with Actions

 

       TActionList

 

Actions objects are uses to connect menu items and buttons to a certain procedure of the TWPRichText editor.

 

The TActionList which contains the action objects must be specified in the ActionList property of the TWPRichText component.

 

To add an action to a ActionList please open its editor (double click) and select 'new standard action'

 

Tip: In case you find out that certain hot keys do not work please check the short cuts defined in action lists or menus. It is possible that a shortcut is consumed somewhere else.

 

Assigning an action to a menu item always overrides the image index of this element. So please specify the image index values in the actions and not in the menu items. The image list must be assigned to both, the action list and the toolbar!

 

Please also see "Use WPTools5 with TBX" (TBX / DevExpressBars)

 

Work with TWPComboBox

 

The TWPToolCtrl component is not included in WPTools 5. If you want to use the TWPComboBox control which can display a list of fonts, colors or styles, You need to create a links using the TWPToolsCustomEditContolAction action class.

 

This action class is created in the ActionList and its property AttachedControl is set to the TWPComboBox instance you need to attach. The property AttachedControlStyle to select the functionality is not used for TWPComboBox - they have their own property ComboboxStyle for the same purpose.

 

Create shortcuts, such as Ctrl+I to activate/deactivate ITALIC:

 

To do this You can use the event OnKeyPress.

 

procedure TForm1.WPRichText1KeyPress(Sender: TObject;

var Key: Char);

procedure ToggleStyle(sty : TOneWrtStyle);

begin

    if sty in WPRichText1.CurrAttr.Style then

         WPRichText1.CurrAttr.DeleteStyle([sty])

    else WPRichText1.CurrAttr.AddStyle([sty]);

    WPRichText1.SetFocusValues(true);

end;

begin

if Key=Char(Integer('B')-64) then // Ctrl + B

begin

    ToggleStyle(afsBold);

    Key := #0;

end else

if Key=Char(Integer('I')-64) then // Ctrl + I

begin

    ToggleStyle(afsItalic);

    Key := #0;

end else

if Key=Char(Integer('U')-64) then // Ctrl + U

begin

    ToggleStyle(afsUnderline);

    Key := #0;

end;

end;

 

 

Note

 

Please do not use actions if you want to execute certain methods of the TWPRichText component from your own code. You can call the procedure directly (i.e. WPRichText1.Save) or change text attributes using CurrAttr (i.e. WPRichText1.CurrAttr.AddStyle[afsBold]).