Checkpoint navigation

General TRichView support forum. Please post your questions here
Post Reply
Denis

Checkpoint navigation

Post by Denis »

Can you send example of code:
How to move cursor to checkpoint, if this checkpoint inside table cell?
.............
I run recurce scanner for cells bookmarks (your example Demos/Autoscan URL). And scan all bookmarks.

But I can not put cursor on cells bookmarks :(

Denis

Bookmarks

Post by Denis »

Anybody? How to move cursor in table cell[j] ? (or Scroll TRichView)

Sergey Tkachenko
Site Admin
Posts: 15235
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

I have examples for Delphi:

Example 1:

Code: Select all

function ScrollToCheckpoint(rv: TCustomRichView; const CPName: String): Boolean;

function _ScrollToCheckpoint(RVData: TCustomRVFormattedData;
  rv: TCustomRichView; const CPName: String): Boolean;
var i,r,c,x,y: Integer;
    Tag: TRVTag;
    CPD: TCheckpointData;
    Name: String;
    RI: Boolean;
    table: TRVTableItemInfo;
begin
  for i := 0 to RVData.ItemCount-1 do begin
    CPD := RVData.GetItemCheckpoint(i);
    if Assigned(CPD) then begin
      RVData.GetCheckpointInfo(CPD, Tag, Name, RI);
      if Name=CPName then begin
        RVData.GetOriginEx(x,y);
        rv.ScrollTo(y+RVData.GetCheckpointYEx(CPD));
        Result := True;
        exit;
      end;
    end;
    if RVData.GetItemStyle(i)=rvsTable then begin
      table := TRVTableItemInfo(RVData.GetItem(i));
      for r := 0 to table.Rows.Count-1 do
        for c := 0 to table.Rows[r].Count-1 do
          if table.Cells[r,c]<>nil then begin
            Result := _ScrollToCheckpoint(
              TCustomRVFormattedData(table.Cells[r,c].GetRVData),
              rv, CPName);
            if Result then
              exit;
          end;
    end;
  end;
  Result := False;
end;

begin
  Result := _ScrollToCheckpoint(rv.RVData, rv, CPName);
end;
Example 2:

Code: Select all

function GoToCheckpoint(rv: TCustomRichViewEdit; const CPName: String): Boolean;

function _GoToCheckpoint(RVData: TCustomRVFormattedData;
  rv: TCustomRichViewEdit; const CPName: String): Boolean;
var i,r,c,x,y: Integer;
    Tag: TRVTag;
    CPD: TCheckpointData;
    Name: String;
    RI: Boolean;
    table: TRVTableItemInfo;
begin
  for i := 0 to RVData.ItemCount-1 do begin
    CPD := RVData.GetItemCheckpoint(i);
    if Assigned(CPD) then begin
      RVData.GetCheckpointInfo(CPD, Tag, Name, RI);
      if Name=CPName then begin
        RVData := TCustomRVFormattedData(RVData.Edit);
        RVData.SetSelectionBounds(i, RVData.GetOffsBeforeItem(i), i, RVData.GetOffsBeforeItem(i));
        Result := True;
        exit;
      end;
    end;
    if RVData.GetItemStyle(i)=rvsTable then begin
      table := TRVTableItemInfo(RVData.GetItem(i));
      for r := 0 to table.Rows.Count-1 do
        for c := 0 to table.Rows[r].Count-1 do
          if table.Cells[r,c]<>nil then begin
            Result := _GoToCheckpoint(
              TCustomRVFormattedData(table.Cells[r,c].GetRVData),
              rv, CPName);
            if Result then
              exit;
          end;
    end;
  end;
  Result := False;
end;

begin
  Result := _GoToCheckpoint(rv.RVData, rv, CPName);
end;
Update 2012-02-28: modified for compatibility with TRichView 13.4+
Last edited by Sergey Tkachenko on Tue Feb 28, 2012 12:28 pm, edited 2 times in total.

Sergey Tkachenko
Site Admin
Posts: 15235
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

As you can see, for moving caret to the cell, you need to call Cell.Edit(). This method returns RVData of the cell inplace editor (also available as Cell.GetRVData()). Using this RVData, you can move caret to the specifying item with the method SetSelectionBounds.

Denoson
Posts: 71
Joined: Tue Jan 24, 2006 9:25 pm
Contact:

Scroll

Post by Denoson »

Sergey, thank you for this example. This code works fine for TRichViewEdit :lol: , but TRichView can't scroll on Cell.Edit() :(

Can you help for Viewer (scroll to table cell / bookmark)?

Sergey Tkachenko
Site Admin
Posts: 15235
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

The Example 1 is for TRichView and TRichViewEdit (scrolling to the checkpoint), The Example 2 is for TRichViewEdit only (I fixed the rv parameter type)

Denoson
Posts: 71
Joined: Tue Jan 24, 2006 9:25 pm
Contact:

Thanks

Post by Denoson »

I try to test this code, thanks.

Denoson
Posts: 71
Joined: Tue Jan 24, 2006 9:25 pm
Contact:

Samples

Post by Denoson »

Ok, this code works Fine!

Rael Bauer
Posts: 36
Joined: Tue Aug 21, 2007 4:47 am

Re: Checkpoint navigation

Post by Rael Bauer »

Hi,

The above ScrollToCheckpoint routine will bring the checkpoint into view, sometimes at the bottom of the visible area. How can I make ScrollToCheckpoint bring the checkpoint to the middle of the visible area?

Thanks
Rael

Sergey Tkachenko
Site Admin
Posts: 15235
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Checkpoint navigation

Post by Sergey Tkachenko »

In the today's update, GoToCheckpoint procedure from RichViewActions.pas has a new parameter ScrollToCenter: Boolean.

Post Reply