Page 1 of 1

How to set paragraph style for bullet & numbering list?

Posted: Mon Jan 27, 2014 2:08 pm
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?

Posted: Mon Jan 27, 2014 7:05 pm
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.

Posted: Tue Jan 28, 2014 5:48 pm
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

Posted: Wed Jan 29, 2014 1:48 pm
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);

Posted: Wed Jan 29, 2014 9:25 pm
by Jim Knopf
ohkayy ... I start understanding ;-)

thanks!

Posted: Thu Jan 30, 2014 10:46 pm
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

Posted: Fri Jan 31, 2014 9:48 am
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)

Posted: Fri Jan 31, 2014 4:05 pm
by Jim Knopf
Would be very helpful! Thanks!

Posted: Sat Feb 01, 2014 1:18 pm
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