How to set paragraph style for bullet & numbering list?

General TRichView support forum. Please post your questions here
Post Reply
Jim Knopf
Posts: 241
Joined: Mon Dec 30, 2013 10:07 pm
Location: Austria
Contact:

How to set paragraph style for bullet & numbering list?

Post by Jim Knopf »

How can I assign a paragraph style to a bullet list or numbered list?
Or: how can I change the space before, space after, line spacing for such a list?
Sergey Tkachenko
Site Admin
Posts: 17565
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Paragraph properties for bulleted/numbered paragraphs are assigned like for normal paragraphs (ApplyParaStyleConversion or ApplyParaStyle).
The only paragraph properties overridden by a list style are LeftIndent and FirstIndent.
Jim Knopf
Posts: 241
Joined: Mon Dec 30, 2013 10:07 pm
Location: Austria
Contact:

Post by Jim Knopf »

So sorry, I assume a node in my thinking ...

I have an editor with a predefindes set of styles - normal, bold, italic, underline, strikeout. That's it.
For the one an only ParaStyle I defined 'SpaceBefor' 10px.
But I need another predefined style for the bullets without SpaceBefore, a second one that I can connect to the ListStyles. In other words: how does the editor know which style to take for the bullet list? If I define a second one then he makes a third but the bullets have 10px SpaceBefore ... I am really desperate, don't understand relations.

Would be happy for solution!

Thanks
Martin
Sergey Tkachenko
Site Admin
Posts: 17565
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Paragraph styles and list styles are applied separately.

Do you need to create list in code?
SetListMarkerInfo has AListNo parameter where you can specify the index in ListStyles, and AParaNo parameter where you can specify the index in ParaStyles.
This code adds a paragraph using ParaStyles[1] and ListStyles[0] to the end of RV:

Code: Select all

RV.SetListMarkerInfo(-1, 0{ListNo}, 0, 1, 1{ParaNo}, False);
RV.AddNL(List item', 0);
Jim Knopf
Posts: 241
Joined: Mon Dec 30, 2013 10:07 pm
Location: Austria
Contact:

Post by Jim Knopf »

ohkayy ... I start understanding ;-)

thanks!
Jim Knopf
Posts: 241
Joined: Mon Dec 30, 2013 10:07 pm
Location: Austria
Contact:

Post by Jim Knopf »

not completely ... :-(

In the attached ListStyles-Demo you create a bulleted list style with this method:

Code: Select all

function TForm1.CreateBullets: Integer;
var ListStyle: TRVListInfo;
begin
  // 1. Creating desired list style
  ListStyle := TRVListInfo.Create(nil);
  with ListStyle.Levels.Add do begin
    ListType  := rvlstBullet;
    Font.Name := 'Symbol';
    {$IFDEF RICHVIEWCBDEF3}
    Font.Charset := SYMBOL_CHARSET;
    {$ENDIF}
    Font.Size := 12;
    FirstIndent := 0;
    LeftIndent  := 24;
  end;
  // 2. Searching for existing style with these properties. Creating it, if not found
  Result := RVStyle1.ListStyles.FindSuchStyle(ListStyle, True);
  ListStyle.Free;
end;
Afterwards this ListStyle exists and can be used by the RVEdit. In the demo it works fine because the text is not saved an loaded later. My problem is that I cannot allow rvrsAddIfNeeded in RTFReadOptions because I disallow in those RVEdits formatting from outside by dropping text. I need the usage of only predefined styles. So I set the RVEdit to rvrsUseSpecified. But in this case I can save the text but after reloading there are no bullets anymore. I checked out exactly the ListStyles and the according ListLevels and predefined them in the IDE. It doesn't work. What's wrong?

Code for setting / clearing bullets:

Code: Select all

var Item: TCustomRVItemInfo;
begin
  if ActiveControl is TRichViewEdit then
  begin
    if not siHasBullet.Down then
    begin
      TRichViewEdit(ActiveControl).RemoveLists(False);
      Item := TRichViewEdit(ActiveControl).RVData.GetItem(TRichViewEdit(ActiveControl).CurItemNo);
      Item.ParaNo := 0;
      TRichViewEdit(ActiveControl).Format;
    end
    else
      TRichViewEdit(ActiveControl).ApplyListStyle(CreateBullets, 0, 0, False, False);
  end;
end;
This works but in this way I cant protect the edit from formatting

Code: Select all

if RVEdit.RTFReadProperties.ParaStyleMode = rvrsAddIfNeeded
Doesn't work although styles and ListLevels are exactly the same as RVEdit is creating:

Code: Select all

if RVEdit.RTFReadProperties.ParaStyleMode = rvrsUseSpecified
Sergey Tkachenko
Site Admin
Posts: 17565
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Unfortunately, bullets and numbering can be read from RTF only if ParaStyleMode = rvrsAddIfNeeded.
In other modes they are ignored.
All modes are supported for bullets and numbering only for RVF.

I do not plan implement mapping to the most similar list for RTF, however, I can implement mapping RTF lists to two predefined list styles (one for numbering, one for bullets)
Jim Knopf
Posts: 241
Joined: Mon Dec 30, 2013 10:07 pm
Location: Austria
Contact:

Post by Jim Knopf »

Would be very helpful! Thanks!
Jim Knopf
Posts: 241
Joined: Mon Dec 30, 2013 10:07 pm
Location: Austria
Contact:

Post by Jim Knopf »

Found a workaround for the meantime:

Code: Select all

    rvFDesc.RTFReadProperties.ParaStyleMode := rvrsAddIfNeeded;
    try
      rvFDesc.LoadRTFFromStream(Stream);
      rvFDesc.Format;
    finally
      rvFDesc.RTFReadProperties.ParaStyleMode := rvrsUseSpecified;
    end;
Not very smart but seems to work:
1. If I press the bullet button during editing the editor creates its new style and saves it to the rtf file
2. For loading a window for self creating of the style that is stored in the file is opened and closes after loading
Post Reply