|
Use WPTools5 with TBX (Toolbar2000 Extension) |
Top Previous Next |
|
Toolbar2000 is a component by Jordan Russel to build a modern GUI. It can be extended with TBX, written by Alex A. Denisov. You can download and order ToolBar2000 and TBX 2.1 from www.g32.org and www.jrsoftware.org. For additional TBX themes check out www.rmklever.com.
It is easy to create an impressive word processing application using this 2 products and of course, WPTools 5.
INFO: Using the WPTools 5 Demo VCL You cannot activate the support for TBX combos using the define USETBX. Therefore the demo does not install the TBX demo project.
Note, there is also experimental support for DevExpressBars - use compiler define: USEEXPRESSBARS
1) Please activate the define USETBX in file WPINC.INC or, better, in your project options.
This modifies the compilation of the units wpruler and wpaction. Please make sure you do a 'compile all' after the change.
2) Create a toolbar (see Toolbar2000 and TBX manual)
Example:
3) Now you can bring life to the tool items
a) For the buttons, such as 'bold'
Create a TActionlist on the form. Assign it to the property 'Actionlist' of the editor component, TWPRichText. In this action list you can create WPTools standard actions, such as TWPABold
This new actions can be assigned to the 'Action' property of menu items and button elements. Now they will automatically work with the attached TWPRichText.
b) To activate the color drop downs more code is requires.
If you use 3 drop downs for text color, highlight color and paragraph background color use the tags 1, 2 and 3. Depending on the tags the drawing and OnChange code can be behave differently.
This code is used in the OnDrawImage event of the button itself.
procedure TForm1.bColorButtonDrawImage(Item: TTBCustomItem; Viewer: TTBItemViewer; Canvas: TCanvas; ImageRect: TRect; ImageOffset: TPoint; StateFlags: Integer); var DC: HDC; Color: TColor; ColorInd: Integer; begin DC := Canvas.Handle; ColorInd := -1; if not Boolean(StateFlags and ISF_DISABLED) then begin case Item.Tag of 1: ColorInd := WPRichText1.CurrAttr.GetColorEx(WPAT_CharColor); 2: ColorInd := WPRichText1.CurrAttr.GetColorEx(WPAT_CharBGColor); 3: ColorInd := WPRichText1.CurrAttr.GetColorEx(WPAT_FGColor); else ColorInd := -1; end; OffsetRect(ImageRect, ImageOffset.X, ImageOffset.Y); ImageRect.Top := ImageRect.Bottom - 4; if ColorInd >= 0 then begin Color := WPRichText1.CurrAttr.NrToColor(ColorInd); Canvas.Brush.Color := Color; Canvas.FillRect(ImageRect); end else begin FrameRectEx(DC, ImageRect, clBtnShadow, True); DitherRect(DC, ImageRect, clBtnFace, clBtnShadow); end; end; end;
Each of the buttons has as subitems (which are used for the dropdown) and ColorPalette. We assigned the tags 1,2 and 3 to this 3 color palettes as well and use the same OnChange code.
procedure TForm1.TBXColorPalette1Change(Sender: TObject); var aColor: Integer; begin aColor := (Sender as TTBXColorPalette).Color; case (Sender as TTBXColorPalette).Tag of 1: WPRichText1.CurrAttr.Color := WPRichText1.CurrAttr.ColorToNr(aColor, true); 2: WPRichText1.CurrAttr.BKColor := WPRichText1.CurrAttr.ColorToNr(aColor, true); 3: WPRichText1.CurrAttr.ParColor := WPRichText1.CurrAttr.ColorToNr(aColor, true); end; end;
This was already sufficient to make all three color buttons work.
c) to bring life to the drop down combos, such as the font selection, you only need to use the special WPTools' pseudo actions (TWPToolsCustomEditContolAction) which have to be added to the action list as well.
After such an action has been created in category 'WPT_COMBOS', you can select the style in property 'AttachedControlStyle' and the list box in property 'AttachedControl'. The first time the drop down will be used it will be initialized and the events to modify the attached editor will be set. Please note that the combo box styles cbsColor, cbsBKColor, cbsParColor are not supported by TWPToolsCustomEditContolAction. The style cbsStandard is the neutral value.
Note: The TWPToolsCustomEditContolAction can be also used to attach TWPComboBox elements. In this case 'AttachedControlStyle' has to be set to cbsStandard.
Now you can create the horizontal and if required, also the vertical ruler:
You only need to attach the ruler controls to the the property WPRuler and VertRuler of the TWPRichText Control. If you are using a vertical ruler disable the flag wpNoVertRulerAttached in WPRuler.Options.
How to use the predefined dialogs?
Please drop one of the dialog components on the form:
Then set the property 'EditBox' to point to the editor which should be used.
Using a call to the method 'Execute' the dialog can be opend:
(Screenshot of the Border dialog. When this dialog is opend all properties are set to 'undefined': the user can change any of the elements and leave the other unchanged)
|