<< Click to Display Table of Contents >> Navigation: Programming > User Interface > Toolbar > Ribbon Applications > TMS Office 2010 > Populate Style toolbar with Font and Color Selector |
Now we use the special TMS comboboxes to work with TWPRichText.
Create a new toolbar and click right on it. Now you can select the AdvOfficeFontSelector:
Assigning the selected font to the editor is very simple. You only need an event handler like this.
procedure TWPEditor.AdvOfficeFontSelector1SelectFontName(Sender: TObject;
AName: string);
begin
WPRichText1.CurrAttr.FontName := AName;
WPRichText1.SetFocus;
end;
Now we add a and a TAdvOfficeFontSizeSelector and 3 TAdvOfficeColorSelector for text color, highlight color and paragraph color.
This code is used to update the text:
procedure TWPEditor.AdvOfficeFontSizeSelector1SelectFontSize(Sender: TObject;
ASize: Integer);
begin
WPRichText1.CurrAttr.Size := ASize;
WPRichText1.SetFocus;
end;
procedure TWPEditor.TextColorSelectorSelectColor(Sender: TObject;
AColor: TColor);
begin
WPRichText1.CurrAttr.Color := WPRichText1.CurrAttr.ColorToNr(AColor);
WPRichText1.SetFocus;
end;
procedure TWPEditor.HighlightColorSelectorSelectColor(Sender: TObject;
AColor: TColor);
begin
WPRichText1.CurrAttr.BKColor := WPRichText1.CurrAttr.ColorToNr(AColor);
WPRichText1.SetFocus;
end;
procedure TWPEditor.ParagraphColorSelectorSelectColor(Sender: TObject;
AColor: TColor);
begin
WPRichText1.CurrAttr.ParColor := WPRichText1.CurrAttr.ColorToNr(AColor);
WPRichText1.SetFocus;
end;
To update the controls according to the text attributes you need an event handler for the event TWPRichText.OnCharacterAttrChange.
procedure TWPEditor.WPRichText1CharacterAttrChange(Sender: TObject;
Attribute: TWPSetModeControl);
begin
// Font Color
AdvOfficeFontSelector1.ItemIndex :=
AdvOfficeFontSelector1.Items.IndexOf(Attribute.FontName);
// Font Size
if Attribute.Size<=0 then
AdvOfficeFontSizeSelector1.ItemIndex := -1
else AdvOfficeFontSizeSelector1.SelectedFontSize := Trunc(Attribute.Size);
// TextColor
if Attribute.Color<=0 then
TextColorSelector.SelectedColor := clNone
else TextColorSelector.SelectedColor :=
Attribute.NrToColor(Attribute.Color);
// HighlightColor
if Attribute.BKColor<=0 then
HighlightColorSelector.SelectedColor := clNone
else HighlightColorSelector.SelectedColor :=
Attribute.NrToColor(Attribute.BKColor);
// ParagraphColor
if Attribute.ParColor<=0 then
ParagraphColorSelector.SelectedColor := clNone
else ParagraphColorSelector.SelectedColor :=
Attribute.NrToColor(Attribute.ParColor);
end;
Now we can add additional buttons to change the writing mode and properties of the text.
They all use actions from the WPToolDefaultAction datamodule.
For the buttons we set the property Rounded to true and the property Position to bpLeft, bpMiddle ... and bpRight to create the grouped look.
All buttons which can also display a state (active/inactive) the property Style must be to to bsCheck.
Now we create a popup menu (TAdvPopupMenu) and add actions to show important dialogs:
The menu is assigned to the property OptionsMenu of our style toolbar. Don't forget to assign WPDefAct.StdIcons to property Images of the popup menu.