When working with a regular rve I've noticed if I have empty lines selected there is no visual feedback to tell you that. So, here are 2 examples of how it works normally:
What I'm used to is this with the same 2 examples showing all the selection areas:
I put some code in my rve's paint method (see below) and have it working. Maybe it will help others wanting to do the same thing.
However...
My questions are:
- Is there already a built-in way of doing this that I've missed? Some option or property?
If not, then
- Does the code I wrote (below) seem reasonable?
- Note that I draw the "pilcrow" symbol (¶) "manually" since my paint code "overwrites" the built-in ¶ in empty lines.
- Can you tell me where in the source you are drawing that ¶ symbol when rvscParagraph is in RVVisibleSpecialCharacters and they are being shown? I'm not sure what I've done will work in all circumstances and I think I'd be better off replicating whatever it is you're doing.
Thanks Sergey
Code: Select all
procedure TForm1.rvePaint(Sender: TCustomRichView; ACanvas: TCanvas;
Prepaint: Boolean);
var
i, YOffSet: integer;
FStart, FSOff, FEnd, FEoff: integer;
DItemStart, DOffStart, DItemEnd, DOffEnd: integer;
DItem: TRVDrawLineInfo;
r: TRect;
begin
if Sender.ItemCount = 0 then exit;
try
//Selection Area Marker (vertical line in rve left margin at empty lines)
if ShowSelMarker1.Checked and Sender.SelectionExists then
begin
//Get current selection:
Sender.GetSelectionBounds(FStart, FSOff, FEnd, FEoff, true);
//Convert start/end items to DrawItems:
Sender.RVData.Item2DrawItem(FStart,FSOff,DItemStart,DOffStart);
Sender.RVData.Item2DrawItem(Fend,FEoff,DItemEnd,DOffEnd);
//Draw selection color on any empty DrawItem lines
for i := DItemStart to DItemEnd do
begin
DItem := Sender.RVData.DrawItems[i];
r.Left := Sender.LeftMargin - 1;
r.Right := r.Left + 6;
YOffSet := ( Sender.VScrollPos * Sender.VSmallStep );
r.Top := DItem.Top - YOffSet;
r.Bottom := DITem.Top + DItem.Height - YOffSet;
ACanvas.Brush.Color := Sender.Style.SelColor;
//DrawItem is empty:
if (DItem.TextLength = 0) and //not an image:
(Sender.GetItemStyle(DItem.ItemNo) = rvsNormal ) then
begin
ACanvas.FillRect(r);
if (rvoShowSpecialCharacters in Sender.Options) and
(rvscParagraph in RVVisibleSpecialCharacters) then
begin
ACanvas.Font.Size :=
Sender.Style.TextStyles[Sender.GetItemStyle(DItem.ItemNo)].Size;
ACanvas.Font.Name :=
Sender.Style.TextStyles[Sender.GetItemStyle(DItem.ItemNo)].FontName;
ACanvas.Font.Charset := DEFAULT_CHARSET;
ACanvas.Font.Color := Sender.Style.SpecialCharactersColor;
r.Right := r.Left + ACanvas.TextWidth(chr(182)); //chr(182) = '¶'
ACanvas.FillRect(r);
ACanvas.Brush.Style := bsClear;
ACanvas.TextOut(r.Left,r.Top,chr(182));
end;
end;
end;
end;
...