The question of Implementation of custom item types is not covered in TRichView manual
("item" is an object that can be inserted in TRichView document, such as picture, equation, etc.)
This topic contains some information about custom items.
Normally, an item occupies a rectangular area in document, and can be placed inline in text. Such items must be inherited from TRVRectItemInfo class (RVItem.pas).
If you want to extend an existing item type with additional properties, inherit your class from the proper item type. For example, from TRVLabelItemInfo (RVLabelItem.pas)
Each item must have a unique identifier. It is a negative integer number.
A list of used numbers is here: https://www.trichview.com/help/idh_const_rvsxxx.html
This identifier must be assigned to StyleNo property in constructor.
You must override the constructor Create(ARVData: TPersistent).
If you want custom painting, override Paint method. If you want custom printing, override Print method (there is also an option of drawing to bitmap, and then printing this bitmap)
[Info] How to implement properties in custom TRichView items
-
- Site Admin
- Posts: 17554
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
-
- Site Admin
- Posts: 17554
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Custom item properties
The best method to add additional properties to items is implementation of "extra integer properties" and "extra string properties".
With the proper implementation, these properties can be stored in RVF files. In an editor, you will be able to assign values to these properties as an editing operations (undoable by the users).
You can use the following methods for integer properties:
If you need Boolean, TColor or enum properties, you can use integer properties (by converting value to Integer)
If you need TStringList property, you can use string properties (by accessing StringList.Text)
With the proper implementation, these properties can be stored in RVF files. In an editor, you will be able to assign values to these properties as an editing operations (undoable by the users).
You can use the following methods for integer properties:
- TRichView.GetExtraItemIntPropertyEx
- TRichView.SetExtraItemIntPropertyEx
- TRichViewEdit.SetItemExtraIntPropertyExEd
- TRichViewEdit.GetCurrentItemExtraIntPropertyEx
- TRichViewEdit.SetCurrentItemExtraIntPropertyEx
- TRichView.GetExtraItemStrPropertyEx
- TRichView.SetExtraItemStrPropertyEx
- TRichViewEdit.SetItemExtraStrPropertyExEd
- TRichViewEdit.GetCurrentItemExtraStrPropertyEx
- TRichViewEdit.SetCurrentItemExtraStrPropertyEx
If you need Boolean, TColor or enum properties, you can use integer properties (by converting value to Integer)
If you need TStringList property, you can use string properties (by accessing StringList.Text)
-
- Site Admin
- Posts: 17554
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Property identifiers
First, you need to choose integer identifiers for your properties.
Here is a list of used identifiers for integer properties:
https://www.trichview.com/help/idh_const_rveipcxxx.html
For string properties:
https://www.trichview.com/help/idh_const_rvespcxxx.html
These identifiers are not necessary globally unique. For example, value 200 is used for many identifiers.
But identifiers must be unique for the item type.
So, if you inherit your item from TRVLabelItemInfo, you cannot use value 200, because it is already used. You can start your property identifiers from 300.
I do not recommend starting your numbers immediately when numbers of the parent item type end. For example, TRVLabelItemInfo uses identifiers up to 206. It's a bad idea to use 207 for your item, because there is a chance that a new property will be added to TRVLabelItemInfo later, and it will use this identifier.
Next, you need to choose string identifiers for your properties. These identifiers will be used to store your properties in RVF file.
Here is a list of used identifiers for integer properties:
https://www.trichview.com/help/idh_const_rveipcxxx.html
For string properties:
https://www.trichview.com/help/idh_const_rvespcxxx.html
These identifiers are not necessary globally unique. For example, value 200 is used for many identifiers.
But identifiers must be unique for the item type.
So, if you inherit your item from TRVLabelItemInfo, you cannot use value 200, because it is already used. You can start your property identifiers from 300.
I do not recommend starting your numbers immediately when numbers of the parent item type end. For example, TRVLabelItemInfo uses identifiers up to 206. It's a bad idea to use 207 for your item, because there is a chance that a new property will be added to TRVLabelItemInfo later, and it will use this identifier.
Next, you need to choose string identifiers for your properties. These identifiers will be used to store your properties in RVF file.
-
- Site Admin
- Posts: 17554
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Methods to override
For integer properties, override the following methods:
SetExtraIntPropertyEx, GetExtraIntPropertyEx, and optionally GetExtraIntPropertyReformat
For string properties, override the following methods:
SetExtraStrPropertyEx, GetExtraStrPropertyEx, and optionally GetExtraStrPropertyReformat
For any type of properties, override
SetExtraCustomProperty, GetRVFExtraPropertyCount, SaveRVFExtraProperties
GetExtraStrPropertyReformat and GetExtraStrPropertyReformat informs the editor what should be done when assigning this property as an editing operation.
Possible result values:
rvrfNone - nothing (the property does not affect visual appearance) - default for string properties
rvrfNormal - normal reformatting (the property may affect size of the item) - default for integer properties
rvrfFull - assignment to this property requires the complete reformatting of the whole document
rvrfRepaint - repainting (the property affect visual appearance of the item but not its size)
rvrfSRVRepaint - (in ScaleRichView) repainting of the full component
rvrfSRVReformat - (in ScaleRichView) reformatting of the full component
SetExtraIntPropertyEx, GetExtraIntPropertyEx, and optionally GetExtraIntPropertyReformat
For string properties, override the following methods:
SetExtraStrPropertyEx, GetExtraStrPropertyEx, and optionally GetExtraStrPropertyReformat
For any type of properties, override
SetExtraCustomProperty, GetRVFExtraPropertyCount, SaveRVFExtraProperties
GetExtraStrPropertyReformat and GetExtraStrPropertyReformat informs the editor what should be done when assigning this property as an editing operation.
Possible result values:
rvrfNone - nothing (the property does not affect visual appearance) - default for string properties
rvrfNormal - normal reformatting (the property may affect size of the item) - default for integer properties
rvrfFull - assignment to this property requires the complete reformatting of the whole document
rvrfRepaint - repainting (the property affect visual appearance of the item but not its size)
rvrfSRVRepaint - (in ScaleRichView) repainting of the full component
rvrfSRVReformat - (in ScaleRichView) reformatting of the full component
-
- Site Admin
- Posts: 17554
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Example
As an example of implementation of custom properties, you can see the equation item (<TRichView Dir>\Math\Source\RVMathItem.pas)
It implements integer properties with identifiers:
String properties with identifiers:
For storing in RVF, it implements property names:
You can see implementation of the methods listed above your self in RVMathItem.pas
It implements integer properties with identifiers:
Code: Select all
rveipcFontSizeDouble = 200;
rveipcTextColor = 201;
rveipcDisplayInline = 202;
Code: Select all
rvespcText = 200;
rvespcFontName = 201;
Code: Select all
const
rveipcMath_First = rveipcFontSizeDouble;
rveipcMath_Last = rveipcDisplayInline;
rvespcMath_First = rvespcText;
rvespcMath_Last = rvespcFontName;
const
IntPropertyNames: array [rveipcMath_First .. rveipcMath_Last] of PRVAnsiChar =
('fontsize_double', 'text_color', 'display_inline');
StrPropertyNames: array [rvespcMath_First .. rvespcMath_Last] of PRVAnsiChar =
('text', 'fontname');