Page 1 of 1

replace List Markers with text

Posted: Sat Nov 05, 2011 6:26 pm
by David.Brenner
Hi.
I want to replace in RichViewEdit some List Markers (that have a certain Unicode character in them) with a Unicode text character (so with a text item).
I tried getting the Unicode character from them with GetListMarkerInfo but no luck.
Oh, and I don't wanna use DeleteItem function (I want Undo).
How can I do this?

Thank you very much for your help.

Best regards, David Brenner

Posted: Mon Nov 14, 2011 5:35 pm
by David.Brenner
Also I tried with RemoveListMarker but my application shows "list index out of bounds" errors even when scrolling the document.
In another topic I found "TRVMarkerItemInfo(RVData.GetItem(i)).DisplayString" but it does not have any string in it.
I'm starting to think that maybe there is no solution for this :(

Posted: Mon Nov 14, 2011 5:50 pm
by Sergey Tkachenko
What version of Delphi?

DisplayString is the correct solution, but there is a difference in Unicode and non-Unicode versions of Delphi.

Delphi 4-2007.
This is ANSI string. It contains empty string only for picture list types (rvlstPicture, rvlstImageList, rvlstImageListCounter) and for rvlstUnicodeBullet.

Delphi 2009-XE2
This is Unicode string. It contains empty string only for picture list types. rvlstUnicodeBullet is redundant, it works like rvlstBullet.

Posted: Mon Nov 14, 2011 6:01 pm
by David.Brenner
Delphi 7.
Like I said DisplayString for rvsListMarker's from my documents are always empty.

Posted: Mon Nov 14, 2011 6:13 pm
by Sergey Tkachenko
I'll make an example tomorrow.

Posted: Mon Nov 14, 2011 9:00 pm
by David.Brenner
Ok, thank you.
Here is an example of what should I replace and into what: http://www.mediafire.com/download.php?eyywy5dtd609mp8

Posted: Tue Nov 15, 2011 7:27 pm
by Sergey Tkachenko
This is the simplest example:

Code: Select all

procedure MarkersToText(rve: TCustomRichViewEdit);
var i, ListNo, Level, StartFrom: Integer;
    UseStartFrom: Boolean;
    s: WideString;
    ListStyle: TRVListInfo;
begin
  rve.BeginUndoGroup(rvutList);
  rve.SetUndoGroupMode(True);
  rve.BeginUpdate;
  try
    for i := rve.ItemCount-1 downto 0 do
      if rve.GetItemStyle(i)=rvsListMarker then begin
        s := '';
        rve.GetListMarkerInfo(i, ListNo, Level, StartFrom, UseStartFrom);
        if ListNo>=rve.Style.ListStyles.Count then
          ListNo := rve.Style.ListStyles.Count-1;
        if ListNo>=0 then begin
          ListStyle := rve.Style.ListStyles[ListNo];
          if Level>=ListStyle.Levels.Count then
            Level := ListStyle.Levels.Count-1;
          if Level>=0 then
            if ListStyle.Levels[Level].ListType=rvlstUnicodeBullet then
              s := ListStyle.Levels[Level].FormatStringW
            else
              s := WideString(TRVMarkerItemInfo(rve.GetItem(i)).DisplayString);
        end;
        rve.SetSelectionBounds(i, 1, i, 1);
        if s<>'' then
          rve.InsertTextW(s+#9);
        rve.RemoveLists(False);
      end;
  finally
    rve.EndUpdate;
    rve.SetUndoGroupMode(False);
  end;
end;
It just removes all markers and calls InsertTextW(marker_text+tab).
It does not retain indents and fonts.
If the current text is not Unicode, marker text will be converted to ANSI.
It replaces markers only in the main document, not in table cells.

If you need to improve this code, let me know.

Posted: Wed Nov 16, 2011 10:48 am
by David.Brenner
Yes, it works fine with this code.
Thank you very much.

Best regards, David Brenner

Posted: Thu Nov 17, 2011 9:57 am
by David.Brenner
A problem: I have found some list markers which are displayed well only in Word:
Image
They look like '*' in RichViewEdit (and the code extract '*' in the widestring s):
Image

You can download a sample from here: http://www.mediafire.com/?qqncp4crmxjuusb
It would help to find a way to display correctly too but at least could you please help me find if that character is a '-' list marker or not?
I could modify my code to replace if it finds a '*' in s but this could be a problem if the list marker has other character in it (but "seen" by RichViewEdit as '*' too).

Thank you for your help.

Best regards, David Brenner

Posted: Thu Nov 17, 2011 1:48 pm
by Sergey Tkachenko
The problem is not in these characters themselves.

This RTF file uses a feature that I never seen before: the list-override-table overriding the list marker text. Normally, a list-override-table override only a starting value for a numbering (or nothing at all).

TRichView does not have an analog of a list-override-table (it is an intermediate layer between a list-table and a document) - in TRichView, items refer directly to a list-table (ListStyles). So there is no place where it can store this text override, and it displays a marker text read from the RTF list table.
Since list text overriding is very rarely used, I do not plan to fix the problem with this RTF, sorry.

Posted: Thu Nov 17, 2011 3:28 pm
by David.Brenner
I understand :(
Thanks anyway.