copy bullet style
copy bullet style
I have a TRichView that has a list in it:
First Item
Second Item
Third Item
I have a bullet style in a TRichViewEdit.
Please can someone tell me how to apply the bullet style in the TRichViewEdit to the list in the TRichView?
Many thanks in advance,
Colin.
First Item
Second Item
Third Item
I have a bullet style in a TRichViewEdit.
Please can someone tell me how to apply the bullet style in the TRichViewEdit to the list in the TRichView?
Many thanks in advance,
Colin.
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Sergey - thanks for your quick response.
I need to apply the style to the list that is in the TRichView, not the TRichViewEdit. From what I can see ApplyListStyle is introduced in the TRichViewEdit, and therefore wont work for me.
Can I do this - apply a ListStyle to the contents of a TRichView? And, if so, how do I get the ListStyle from the TRichViewEdit?
Thanks again,
Colin.
I need to apply the style to the list that is in the TRichView, not the TRichViewEdit. From what I can see ApplyListStyle is introduced in the TRichViewEdit, and therefore wont work for me.
Can I do this - apply a ListStyle to the contents of a TRichView? And, if so, how do I get the ListStyle from the TRichViewEdit?
Thanks again,
Colin.
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Maybe this could help:
It require to add at least one list style. it convert selected items to list style.
Thank you
Code: Select all
var
StartItemNo, StartItemOffs, EndItemNo, EndItemOffs: Integer;
I: Integer;
begin
R.GetSelectionBounds(StartItemNo, StartItemOffs, EndItemNo, EndItemOffs, False);
for I := StartItemNo to StartItemNo do
R.SetListMarkerInfo(I, 0, 0, 0, 0, True);
R.Format;
Thank you
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Generally, your code is right, but it has several problems:
- the last parameter of GetSelectionBounds should be True;
- case of empty selection should be checked;
- cycle to EndItemNo;
- list markers are items, so inserting list marker adds an item, item range is changed;
- does not make sense to use StartFrom value;
- not necessary to call SetListMarkerInfo for all items, it's enough (and faster) to call once per paragraph.
Fixed code:
- the last parameter of GetSelectionBounds should be True;
- case of empty selection should be checked;
- cycle to EndItemNo;
- list markers are items, so inserting list marker adds an item, item range is changed;
- does not make sense to use StartFrom value;
- not necessary to call SetListMarkerInfo for all items, it's enough (and faster) to call once per paragraph.
Fixed code:
Code: Select all
var
StartItemNo, StartItemOffs, EndItemNo, EndItemOffs: Integer;
I: Integer;
...
R.GetSelectionBounds(StartItemNo, StartItemOffs, EndItemNo, EndItemOffs, True);
if StartItemNo>=0 then begin
for I := EndItemNo downto StartItemNo do
if R.IsParaStart(I) or (I=StartItemNo) then
R.SetListMarkerInfo(I, 0, 0, 0, 0, False);
R.Format;
end;
Last edited by Sergey Tkachenko on Sat Nov 25, 2006 2:17 pm, edited 1 time in total.
Thanks for your help mamouri, and Sergey for the correction.
In answer to your questions Sergey:
I need to add bullets to existing paragraphs in a TRichView (I am figuring that mamouri's suggestion will do this?)
Sorry, I was not clear with "how do I get the ListStyle from the TRichVewEdit". What I mean is:
I have a TRichViewEdit that may have a bullet style in it - I need a way to find out if bullets are used in the TRichVewEdit (if there is one, there will ONLY be one bullet style used), and having determined this I need to apply the bullet style that is in that TRichViewEdit to the paragraphs in the TRichView.
I hope this is clearer.
Colin.
In answer to your questions Sergey:
I need to add bullets to existing paragraphs in a TRichView (I am figuring that mamouri's suggestion will do this?)
Sorry, I was not clear with "how do I get the ListStyle from the TRichVewEdit". What I mean is:
I have a TRichViewEdit that may have a bullet style in it - I need a way to find out if bullets are used in the TRichVewEdit (if there is one, there will ONLY be one bullet style used), and having determined this I need to apply the bullet style that is in that TRichViewEdit to the paragraphs in the TRichView.
I hope this is clearer.
Colin.
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
mamouri, everybody makes mistakes. I really appreciate your help. Actually, my code was incorrect too (checking empty selection), I fixed it.
maddwood, yes, the code posted by mamouri (and then corrected by me) adds bullets to the selected paragraphs in TRichView.
If you want to apply list style to all paragaraphs, the code is:
The list style index is the second parameter of SetListMarkerInfo. In this code sample, it is zero, but, of course, you can use your list style index.
As for returning list style used by TRichViewEdit.
This procedure returns style index of the first used list marker.
Call: GetTheFirstListStyleNo(RichViewEdit1.RVData).
This procedure searches also in tables (without tables, the code would be much simpler).
Are both your TRichView and TRichViewEdit components linked to the same TRVStyle? If not, you need to copy this list style from TRichViewEdit's RVStyle to TRichView's RVStyle.
maddwood, yes, the code posted by mamouri (and then corrected by me) adds bullets to the selected paragraphs in TRichView.
If you want to apply list style to all paragaraphs, the code is:
Code: Select all
for I := R.ItemCount-1 downto 0 do
if R.IsParaStart(I) or (I=0) then
R.SetListMarkerInfo(I, 0, 0, 0, 0, False);
R.Format;
As for returning list style used by TRichViewEdit.
This procedure returns style index of the first used list marker.
Code: Select all
function GetTheFirstListStyleNo(RVData: TCustomRVData): Integer;
var i,r,c: Integer;
Table: TRVTableItemInfo;
ListLevel, StartFrom: Integer;
UseStartFrom: Boolean;
begin
Result := -1;
for i := 0 to RVData.ItemCount-1 do
case RVData.GetItemStyle(i) of
rvsTable:
begin
Table := TRVTableItemInfo(RVData.GetItem(i));
for r := 0 to Table.RowCount-1 do
for c := 0 to Table.ColCount-1 do
if Table.Cells[r,c]<>nil then begin
Result := GetTheFirstListStyleNo(Table.Cells[r,c].GetRVData);
if Result>=0 then
exit;
end;
end;
rvsListMarker:
begin
RVData.GetListMarkerInfo(i, Result, ListLevel, StartFrom, UseStartFrom);
if Result>=0 then
exit;
end;
end;
end;
This procedure searches also in tables (without tables, the code would be much simpler).
Are both your TRichView and TRichViewEdit components linked to the same TRVStyle? If not, you need to copy this list style from TRichViewEdit's RVStyle to TRichView's RVStyle.