copy bullet style

General TRichView support forum. Please post your questions here
Post Reply
maddwood
Posts: 7
Joined: Mon Oct 30, 2006 3:49 pm

copy bullet style

Post by maddwood »

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.
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

As an editing operation?
Select (SetSelectionBounds) and call ApplyListStyle
maddwood
Posts: 7
Joined: Mon Oct 30, 2006 3:49 pm

Post by maddwood »

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.
maddwood
Posts: 7
Joined: Mon Oct 30, 2006 3:49 pm

Post by maddwood »

Sergey,

Are you able to help me with this?

Colin.
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Do you need to create document with bullets or to add bullets to existing paragraphs?

I do not understand the second question ("how do I get the ListStyle from the TRichViewEdit")
mamouri
Posts: 63
Joined: Sat Aug 19, 2006 5:06 am

Post by mamouri »

Maybe this could help:

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;
It require to add at least one list style. it convert selected items to list style.
Thank you
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

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:

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.
mamouri
Posts: 63
Joined: Sat Aug 19, 2006 5:06 am

Post by mamouri »

- list markers are items, so inserting list marker adds an item, item range is changed;
I'm such stupid person :(

Thank you for very detailed information
maddwood
Posts: 7
Joined: Mon Oct 30, 2006 3:49 pm

Post by maddwood »

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.
maddwood
Posts: 7
Joined: Mon Oct 30, 2006 3:49 pm

Post by maddwood »

Sergey,

Can you help me with this, please?

Kind regards,

Colin.
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

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:

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; 
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.

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;
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.
Post Reply