<< Click to Display Table of Contents >> Navigation: Programming > Change text attributes in code > Numbering > Numbering |
In WPTools Version 9 you can create paragraphs with bullets, simple numbering our outline numbering.
The numbering is always controlled by the collection NumberStyles which is accessible by TWPRichText.NumberStyles.
Each entry in this collection has a unique ID which is selected in each numbered paragraph using the WPAT_NumberStyle property. In case of outline numbering this style id only needs to select one style from the correct group. The engine will then use the outline level (WPAT_NumberLevel) to select the style within the same group.
If a paragraph uses a paragraph style the NumberStyle defined in this style (if any) has priority. The number level of a paragraph has priority over the number level defined by a paragraph style!
Please note: The properties WPAT_NumberMode, NumberTEXTB, NumberTEXTA etc should NOT be used for paragraphs or paragraph styles. They are only handled by the styles which are part of NumberStyles collection.
Example: Initialize the NumberStyles to use legal numbering 1, 1.1, 1.2 ...
var
i: Integer;
begin
if WPRichText1 <> nil then
for i := 1 to 9 do
with WPRichText1.NumberStyles.AddOutlineStyle(1, i) do
begin
Style := wp_1;
TextB := '';
TextA := '.';
Font := '';
Indent := 360 * i;
UsePrev := TRUE;
end;
WPRichText1.Refresh;
end;
Example using 'SelectedTextAttr': Assign simple 1,2,3 numbering to the selected text:
var ind : Integer;
begin
ind := 360;
WPRichText1.SelectAll;
WPRichText1.SelectedTextAttr.ASet(
WPAT_NumberStyle,
WPRichText1.NumberStyles.AddNumberStyle(
wp_1, // possible values: wp_bullet, wp_circle,
// wp_1, wp_lg_i, wp_i, wp_lg_a, wp_a,
Before1.Text,
After1.Text,
'', // Font, important for bullets
ind, // default indent
0, // Fontsize or default
false, // = legal numbering
0, // group, 1 for outline numbering
0 // level in group 1..10
));
end;
If the selected numbering style is an outline style, you can use ASet(WPAT_NumberLevel, level) to select the style within this level.
This example will apply the level one of the default outline group to either the current paragraph or the selected text if any selection has been made.
var sty : TWPRTFNumberingStyle;
begin
// Locate level 1 in default outline group
sty := WPRichText1.NumberStyles.FindNumberStyle(-1,1);
// and assign the ID to the current paragraph or the selected
// paragraphs
WPRichText1.ASet(WPAT_NumberSTYLE, sty.ID);
WPRichText1.ASet(WPAT_NumberLEVEL, 1);
WPRichText1.Refresh;
end;
Like the paragraph styles the elements in "NumberStyles" have a property 'TextStyle'. This is a standard TWPTextStyle instance which holds the attributes for the numbering level. You can use it to set additional properties, such as the font color for the numbers.
Example using 'CurrAttr': Assign simple 1,2,3 numbering to the selected text:
var ind : Integer;
begin
ind := 360;
WPRichText1.SelectAll;
WPRichText1.CurrAttr.BeginUpdate;
WPRichText1.CurrAttr.IndentLeft := ind;
WPRichText1.CurrAttr.IndentFirst:= -ind;
WPRichText1.CurrAttr.SetNumberStyle(
Before1.Text, After1.Text, '', wp_1, ind );
WPRichText1.CurrAttr.EndUpdate;
WPRichText1.HideSelection;
end;
Example using 'CurrAttr': Create several outline levels in the text
var cp : Integer; i,l,m : Integer;
begin
cp := WPRichText1.TextCursor.DropMarker;
// Remove numbers and indent
WPRichText1.SelectAll;
WPRichText1.CurrAttr.BeginUpdate;
WPRichText1.CurrAttr.NumberStyle := 0;
WPRichText1.CurrAttr.IndentLeft := 0;
WPRichText1.CurrAttr.EndUpdate;
WPRichText1.HideSelection;
i := 0;
l := 1;
m := 1;
// Move down and apply Outline Mode
WPRichText1.CPPosition := 0;
repeat
WPRichText1.CurrAttr.BeginUpdate;
WPRichText1.CurrAttr.OutlineLevel := l;
WPRichText1.CurrAttr.IndentLeft := l * 360;
WPRichText1.CurrAttr.IndentFirst := -360;
WPRichText1.CurrAttr.EndUpdate;
inc(i);
if i=3 then
begin
l := l+m;
if (l=4) or (l=1) then m := -m;
i := 0;
end;
until not WPRichText1.CPMoveDownPar;
end;
Note about CurrAttr: This is an interface which was introduced in WPTools 3. It is still supported and implemented in unit WPCTRRich. If you do not want to link unit WPCTRRich you cannot use CurrAttr. For new code we suggest to use ActiveParagraph, ASet or SelectTextAttr methods.