|
RichView Items' Checkpoints Overview |
Top Previous Next |
|
Checkpoints are... Each item can have associated checkpoint – an invisible label that you can use for jumping to the specified part of document. Other word-processing tools call similar objects as "bookmarks" or "anchors". Checkpoint has:
Limitations: checkpoint names and tags must not contain line breaking characters (#10, #13) and #0. Failing to follow these rules will cause problems in saving documents in RichView Format. Drawing checkpoints You can set the option to make checkpoints visible: include rvoShowCheckpoints in RichView.Options. By default, checkpoints are shown as dotted vertical lines with a small circle in the top left corner of the associated item. Displaying checkpoints is useful in editing mode. Checkpoints colors:
You can create your own procedure for drawing checkpoints, see TRVStyle.OnDrawCheckpoint. Using checkpoints The usual using of checkpoint is obtaining its vertical coordinate (relative to the top of document area) and scrolling document so that the item associated with the checkpoint becomes visible. There are some more interesting applications for checkpoints. Adding checkpoints in the document You can add checkpoint at the end of the document using AddNamedCheckpointEx, AddNamedCheckpointExTag, AddNamedCheckpoint, AddCheckpoint, AddCheckpointTag. All these methods have a subset of functionality of the AddNamedCheckpointExTag method.
function TRichView.AddNamedCheckpointExTag(const CpName: String; RaiseEvent: Boolean; Tag: Integer): Integer;
The parameters of this function were described above. This function (and all these functions) returns the index of the added checkpoint in RichView (the first checkpoint has index=0).
These calls are equivalent: AddNamedCheckpointEx(Name, RaiseEvent) and AddNamedCheckpointExTag(Name, RaiseEvent,0);
AddNamedCheckpoint(Name) and AddNamedCheckpointExTag(Name, False, 0);
AddCheckpointTag(Tag) and AddNamedCheckpointExTag('', False, Tag);
AddCheckpoint and AddNamedCheckpointExTag('', False, 0);
Recommended for using: AddCheckpoint, AddNamedCheckpointEx, AddNamedCheckpointExTag. As it was told, the above described methods add a new checkpoint to the end of the document. When you add a new item to the end of the document, the last added checkpoint becomes associated with this item. (So, TRichView can contain any number of checkpoints associated with items and one checkpoint at the end of the document). You can modify the checkpoint by SetCheckpointInfomethod, and remove it by RemoveCheckpoint. The rest of methods can be separated into two groups:
Methods and events of the first group (obtaining TCheckpointData): TCheckpointData is a pointer. If these methods return nil, it means that there is no such checkpoint, item has no associated checkpoint, etc.
Methods of the second group (extracting information from TCheckpointData):
Methods belonging to the both groups:
Methods of editor The first group of methods contains editing-style analogs of SetCheckpointInfo and RemoveCheckpoint:
The second group contains methods working with the item at the position of caret (if the caret is between items, they work with the item to the left):
The third group contains methods working with the checkpoint at the position of caret:
RTF and HTML In HTML, checkpoints are saved as anchors (<a name> tag). Either checkpoint name or checkpoint index can be used, see rvsoUseCheckpointsNames option for SaveHTML and SaveHTMLEx. Links to checkpoints must start with '#' character. In RTF, checkpoints are saved as bookmarks (checkpoints names are used). When importing RTF, bookmark start is read as checkpoint (bookmark name is written in checkpoint name). When reading RTF, links to bookmarks are converted to links started from '#'. When writing RTF, links started from '#' are written as links to bookmarks. Example 1 Enumerating all checkpoints in the document (not including checkpoints in table cells). This method is very fast even for large documents, because all checkpoints are organized in a special list. var Tag: Integer; Name: String; RaiseEvent: Boolean; CheckpointData: TCheckpointData; begin CheckpointData := MyRichView.GetFirstCheckPoint; while CheckpointData<>nil do begin MyRichView.GetCheckpointInfo(CheckpointData,Tag,Name,RaiseEvent); // processing this checkpoint ... CheckpointData := MyRichView.GetNextCheckpoint(CheckpointData); end; end;
Example 2 Enumerating all checkpoints in the document, including checkpoints in table cells procedure EnumCheckpoints(RVData: TCustomRVData); var i,r,c: Integer; table: TRVTableItemInfo; Tag: Integer; Name: String; RaiseEvent: Boolean; CheckpointData: TCheckpointData; begin for i := 0 to RVData.ItemsCount-1 do begin CheckpointData := RVData.GetItemCheckpoint(i); if CheckpointData<>nil then begin RVData.GetCheckpointInfo(CheckpointData,Tag,Name,RaiseEvent); // processing this checkpoint ... end; if RVData.GetItemStyle(i)=rvsTable then begin table := TRVTableItemInfo(RVData.GetItem(i)); for r := 0 to table.RowCount-1 do for c := 0 to table.ColCount-1 do if table.Cells[r,c]<>nil then EnumCheckpoints(table.Cells[r,c].GetRVData); end; end; end; Call: EnumCheckpoints(MyRichView.RVData);
In the second example, RVData.GetCheckpointXY returns checkpoint coordinates relative to the top left corner of this RVData (it may be left top corner of the cell). In order to get absolute coordinates of this checkpoint in the document (for MyRichView.ScrollTo), obtain the coordinates of top left corner of this RVData (TCustomRVFormattedData(RVData).GetOriginEx(X,Y)), relative coordinates of checkpoint (TCustomRVFormattedData(RVData).GetCheckpointXY(X,Y)), and sum them up Compatibility Issues Incompatibility with old (freeware) versions of RichView: in older versions checkpoints were items. Now it's not true – they are an additional information associated with items (text, pictures or controls). Therefore, you now can't add two or more checkpoints one by one without an item "between" them. You can choose one of two options when compiling RichView source:
See also... See also properties and events of TRVStyle: CheckpointColor ,.CheckpointEvColor, OnDrawCheckpoint See also properties of TRichView: See also events of TRichView: See also methods of TRichView: AddNamedCheckpointEx, AddNamedCheckpointExTag, AddNamedCheckpoint, AddCheckpoint, AddCheckpointTag, SetCheckpointInfo, RemoveCheckpoint,·GetFirstCheckpoint, GetNextCheckpoint, GetItemCheckpoint, GetCheckpointByNo, FindCheckpointByName, FindCheckpointByTag, GetCheckpointInfo, GetCheckpointXY, GetCheckpointYEx, GetCheckpointItemNo, GetCheckpointNo, GetCheckpointY See also methods of TRichViewEdit: GetCurrentCheckpoint, SetCheckpointInfoEd, RemoveCheckpointEd |