replace List Markers with text
-
- Posts: 12
- Joined: Sat Nov 05, 2011 6:24 pm
replace List Markers with text
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
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
-
- Posts: 12
- Joined: Sat Nov 05, 2011 6:24 pm
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
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
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
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.
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.
-
- Posts: 12
- Joined: Sat Nov 05, 2011 6:24 pm
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
-
- Posts: 12
- Joined: Sat Nov 05, 2011 6:24 pm
Ok, thank you.
Here is an example of what should I replace and into what: http://www.mediafire.com/download.php?eyywy5dtd609mp8
Here is an example of what should I replace and into what: http://www.mediafire.com/download.php?eyywy5dtd609mp8
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
This is the simplest example:
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.
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 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.
-
- Posts: 12
- Joined: Sat Nov 05, 2011 6:24 pm
-
- Posts: 12
- Joined: Sat Nov 05, 2011 6:24 pm
A problem: I have found some list markers which are displayed well only in Word:
They look like '*' in RichViewEdit (and the code extract '*' in the widestring s):
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
They look like '*' in RichViewEdit (and the code extract '*' in the widestring s):
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
-
- Site Admin
- Posts: 17559
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
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.
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.