Page 1 of 1

rve.GetItemCoords identifies 1st line of multline Paragraph

Posted: Sat May 17, 2008 11:21 am
by j&b
Hello Sergey,

recently you helped me, to jump to a y- position in the memo ("procedure TForm1.Go2memoYpos").
The procedure works correctly.

In the meanwhile, I noticed that the identification of the y-position in a memo with "rve.GetItemCoords" is not correct.
"rve.GetItemCoords" identifies always the 1st line of a multi-paragraph. But I need the correct y-Position.
"OnMouseMoveUp" also doesn't work correct for what I want. If someone needs the y-position in rve, this procedure refers always to the y-position in memo-window (as soon as I scroll, y-Pos is wrong).

Is there a counterpart to "Go2memoYpos"?

Jürgen



procedure TForm1.Go2memoYpos; //---> OK <-----
var RVData:TCustomRVFormattedData;
ItemNo, OffsetInItem: Integer;
begin
rve.GetItemAt(0, rveYpos, RVData, ItemNo, OffsetInItem, False);
RVData := TCustomRVFormattedData(RVData.Edit);
RVData.SetSelectionBounds(ItemNo, OffsetInItem, ItemNo, OffsetInItem);
end;

Posted: Sat May 17, 2008 12:14 pm
by Sergey Tkachenko
uses CRVFData, DLines;

Code: Select all

procedure GetCaretY(rve: TCustomRichViewEdit): Integer;
var DItemNo, DItemOffs, X, Y: Integer;
begin
  rve := rve.TopLevelEditor;
  rve.RVData.Item2DrawItem(rve.CurItemNo, rve.OffsetInCurItem, DItemNo, DItemOffs);
  rve.RVData.GetOriginEx(X, Y);
  Result := rve.RVData.DrawItems[DItemNo].Top+Y;
end;

"rve.GetItemCoords identifies 1st line of multline Para

Posted: Sat May 17, 2008 1:37 pm
by j&b
Thanks, Sergey. It seems all oK.


I have deleted my changes because of Sergey answere (look next note).

Posted: Sat May 17, 2008 4:49 pm
by Sergey Tkachenko
Units DLines and CRVFData must still be added in "uses" of the unit where these functions are defined, otherwise the compiler will report error on lines with .Item2DrawItem and .Top.
There is nothing wrong with using these units, they are already used by trichview code.

Without the line rve := rve.TopLevelEditor, your code will not work when the caret is inside table cell (the table's Y coordinate will be returned instead of the caret's Y). Of course, rve must be local to this function (parameter), so assignment to it will not change a global rve.

Posted: Sat May 17, 2008 5:13 pm
by j&b
Thanks.

I will confine my changes and delete them in the above note.