table of contents
Prima::VB::Classes(3) | User Contributed Perl Documentation | Prima::VB::Classes(3) |
NAME¶
Prima::VB::Classes - Visual Builder widgets and types
DESCRIPTION¶
Visual Builder is designed without prior knowledge of the widget classes that would be contained in its widget palette. Instead, it provides the registration interface for new widgets and their specific properties.
This document describes the API provided by the builder and its widget interface. Through the document, widget or widget class mean not the original widget or class, but their representative proxies in the Visual Builder.
USAGE¶
The widget must provide specific methods to cooperate with the builder. It is not required, however, to define these methods in its base module or package; it can delegate its representation to another, usually very light class, which is used by the builder.
Such a class must be derived from "Prima::VB::Object" which provides the minimal base functionality. One of the basic features here is the overloading of the property change method. Since the user can change any property interactively, the class can catch the properties of interest by declaring a "prf_XXX" method where "XXX" is the property name. "Prima::VB::Widget" declares a set of these methods, assuming that a widget would repaint when, for example, its "color" or "font" properties change.
The hierarchy of VB classes mimics the one of the core toolkit classes, but this is a mere resemblance, there are no other dependencies except the names themselves. The hierarchy is as follows:
Prima::VB::Object Prima::Widget Prima::VB::Component Prima::VB::Drawable Prima::VB::Widget Prima::VB::Control Prima::VB::Window
Note: "Prima::VB::CoreClasses" extends the hierarchy to the full set of default widget palette in the builder.
The proxy widgets provide access to the profile properties with the "prf" and "prf_set" methods. The profile is stored as a hash in each proxy widget and is used when generating a VB form file. The proxy widgets usually don't change their own properties when the user changes for example a font or a color on a proxy widget; the proxy widgets draw themselves using the profile properties.
A type object is a class used to represent a particular type of property in the object inspector window in the builder. The type objects, like the widget classes, also are not hard-coded. The builder presents a basic set of the type objects, which can be easily expanded. The hierarchy ( incomplete ) of the type objects classes is as follows:
Prima::VB::Types::generic Prima::VB::Types::bool Prima::VB::Types::color Prima::VB::Types::point Prima::VB::Types::icon Prima::VB::Types::Handle Prima::VB::Types::textee Prima::VB::Types::text Prima::VB::Types::string Prima::VB::Types::char Prima::VB::Types::name Prima::VB::Types::iv Prima::VB::Types::uiv
The document does not describe all the types, since their function can be observed at runtime in the object inspector. Only the "Prima::VB::Types::generic" API is documented.
Prima::VB::Object¶
Properties¶
- class STRING
- Selects the original widget class. A create-only property.
- creationOrder INTEGER
- Sets the creation order of the widget.
- module STRING
- Selects the module that contains the original widget class. A create-only property.
- profile HASH
- Sets the original widget profile. A create-only property. Changes to the profile at run-time are performed by the "prf_set" method.
Methods¶
- act_profile
- Returns a hash of callbacks to be stored in the form file and executed by
"Prima::VB::VBLoader" when the form file
is loaded. The hash keys are names of the VBLoader events, and the values
are strings with code to be eval'ed. See "Events" in
Prima::VB::VBLoader for the description and the format of the callbacks.
Called when the builder writes a form file.
- add_hooks @PROPERTIES
- Registers the object as a watcher of PROPERTIES. When any object changes a
property listed in the hook record, the
"on_hook" callback is triggered.
The special name 'DESTROY' can be used to set a hook on the object destruction event.
- ext_profile
- Returns a class-specific hash, written in a form file. Can be used as a set of extra parameters passed from the builder to the "act_profile" events.
- prf_set %PROIFLE
- The main method for setting a property of an object. PROFILE keys are property names, and values are property values.
- prf_adjust_default PROFILE, DEFAULT_PROFILE
- DEFAULT_PROFILE is a result of the "profile_default" call on the real object class. However, not all properties usually are exported to the object inspector. "prf_adjust_default" deletes the unnecessary or rarely used property keys from the PROFILE hash.
- prf_delete @PROPERTIES
- Removes PROPERTIES from the internal properties hash. This action results in the PROPERTIES in the object inspector being grayed and reassigned to their default values.
- prf_events
- Returns a hash of class-specific events. These appear in the object
inspector on the "Events" page. The hash
keys are event names; the hash values are default code pieces, that
describe the format of the event parameters. For example:
sub prf_events { return ( $_[0]-> SUPER::prf_events, onSelectItem => 'my ( $self, $index, $selectState) = @_;', )}
- prf @PROPERTIES
- Maps an array of PROPERTIES names to their values. If called in the scalar context, returns the first value only; in the array context returns an array of property values.
- prf_types
- Returns an anonymous hash, where keys are names of the type class without
the "Prima::VB::Types::" prefix and
values are arrays of property names.
This callback returns an inverse mapping of properties by their types.
- prf_types_add PROFILE1, PROFILE2
- Adds PROFILE2 content to PROFILE1. PROFILE1 and PROFILE2 are hashes in the format of the "prf_types" method.
- prf_types_delete PROFILE, @NAMES
- Removes @NAMES from PROFILE. Need to be called if the property type is redefined through the inheritance.
- remove_hooks @PROPERTIES
- Stops watching PROPERTIES.
Events¶
- on_hook NAME, PROPERTY, OLD_VALUE, NEW_VALUE, WIDGET
- Called for all objects registered as watchers through the "add_hooks" method, when PROPERTY on object NAME is changed from OLD_VALUE to NEW_VALUE. A special PROPERTY 'DESTROY' hook is called when object NAME is destroyed.
Prima::VB::Component¶
Properties¶
- marked MARKED, EXCLUSIVE
- Selects the marked state of a widget. If the MARKED flag is 1, the widget is selected as marked. If 0, it is selected as unmarked. If the EXCLUSIVE flag is set to 1, then all marked widgets are unmarked before the object mark flag is set.
- sizeable BOOLEAN
- If 1, the widget can be resized by the user. If 0, it can only be moved.
- mainEvent STRING
- Selects the event name, that will be opened in the object inspector when the user double-clicks on the widget.
Methods¶
- common_paint CANVAS
- Draws the selection and resize marks on the widget if it is in the selected state. To be called from all "on_paint" callbacks.
- get_o_delta
- Returns the offset in pixels to the owner widget. Since the builder does not insert widgets in widgets to reflect the user-designed object hierarchy, this method is to be used to calculate the relative positions of the children widgets.
- xy2part X, Y
- Maps an X,Y point to a part of the widget. If the result is not equal to the 'client' string, the mouse event in this coordinate must be ignored.
- iterate_children SUB::(WIDGET, SELF, @ARGS), @ARGS
- Traverses all children widgets in the hierarchy, calling the SUB routine with widget, self, and @ARGS parameters on each.
- altpopup
- Invokes an alternative, class-specific popup menu, if present. The popup object must be named 'AltPopup'.
Events¶
- Load
- Called when the widget is loaded from a file or the clipboard.
Prima::VB::Types::generic¶
The root of all type classes.
A type class can be used with and without an object instance. The instantiated class contains a reference to an ID string, which is a property name that the object presents in the object inspector, and a WIDGET, which is the property applied to. When the object inspector switches widgets, the type object is commanded to update the references.
A class must also be usable without an object instance, in particular, in the "write" method. It is called to export the property value in a storable format as a perl-evaluable string.
Methods¶
- new CONTAINER, ID, WIDGET
- A constructor method. CONTAINER is a panel widget in the object inspector, where the type object can insert its own controls to manage the properties of this type.
- renew ID, WIDGET
- Resets the property name and the widget.
- quotable STRING
- Returns a quotable STRING.
- printable STRING
- Returns a string that can be stored in a file.
Callbacks¶
- change
- Called when the widget property value is changed.
- change_id
- Called when the property name ( ID ) is changed. The type object may consider updating its look or eventual internal variables on this event.
- get
- Returns the property value based on the selector widgets value.
- open
- Called when the type object is to be visualized for the first time. The object must populate the "{container}" panel widget with its specific type controls.
- preload_modules
- Returns an array of strings of modules needed to be preloaded before a form file with type class-specific information can be loaded. Usually, it is used when the "write" method exports constant values which are defined in another module.
- set DATA
- Called when a new value is set to the widget property by means other than the selector widgets, so the latter can be updated. DATA is the property's new value.
- valid
- Checks the internal state of data and returns a boolean flag if the type object data can be safely exported and applied to the widget profile.
- write CLASS, ID, DATA
- Called when DATA is to be written in the form file. "write" must return a string that can be later loaded by "Prima::VB::VBLoader" .
AUTHOR¶
Dmitry Karasik, <dmitry@karasik.eu.org>.
SEE ALSO¶
VB, Prima::VB::VBLoader, Prima::VB::CfgMaint.
2024-08-20 | perl v5.40.0 |