REALbasic plugins are code resources that extend the features available to a REALbasic user.
The things that can be written with plugins are:
* functions
* controls
Plugin file details
===================
A plugin file has the Creator type of: 'SfTg' and a file type of 'RBPl' - there is an icon associated with this by REALbasic - if you upgraded from a previous version, you may need to rebuild your desktop.
As for the resources themselves, a 68k plugin has the resource type of 'PL68', and a PPC plugin has the resource type of 'PLPC'. Unless the plugin has strict computational requirements, it's better to just write a 68k plugin - a PPC program will still be able to access it.
The first plugin resource in a file must have id 128, the second plugin 129, etc.
Plugin file requirements
========================
All plugins must have a routine called 'PluginEntry' - this routine should notify REALbasic about all of the features that the plugin provides.
A simple PluginEntry routine might be something like:
void PluginEntry(void)
{
REALRegisterMethod(&add5defn);
}
This plugin has defined a single method, and it calls the REALRegisterMethod function to define it.
The currently supported registration routines are:
REALRegisterControl - for registering new controls
REALRegisterMethod - for registering new methods
A plugin also needs to declare the pluginExports table, which lists all of the routines that are exported from the plugin - this includes both methods, as well as callbacks defined for controls.
An example pluginExports table is:
REALexport pluginExports[] = {
{ nil, add5func},
};
short pluginExportCode = sizeof(pluginExports) / sizeof(REALexport);
An entry in the pluginExports table consists of:
* the entry name - just leave this field nil
* the reference to the function that implements the export
eg
static int add5func(int v)
{
return v + 5;
}
Declaring new methods
=====================
The REALRegisterMethod function passes a reference to a REALmethodDefinition structure.
eg
REALmethodDefinition add5defn = {
0,
"add5(v as integer) as integer"
};
The number (in this case 0) is the index in the pluginExports table for the implementation, and the string gives the interface of the method that is used by REALbasic.
Declaring controls
==================
The REALRegisterControl function passes a reference to a REALcontrol structure.
The fields of the REALcontrol structure are as follows:
* version - the version of the plugin architecture that the control was built under - just pass the constant kCurrentREALControlVersion
* name - the name of the control as used in REALbasic
* dataSize - the size of the auxiliary data structure allocated for the control
* flags - any special control flags. In the given example, the control indicates that it accepts focus, and it wants REALbasic to automatically draw a focus ring when it has the focus.
* toolbarPICT - the resource id of a PICT resource of the toolbar icon for the control
* toolbarDownPICT - the resource id of a PICT resource of the depressed version of the toolbar icon
* properties - a reference to the array of property declarations for the control
* propertyCount - the number of properties for the control
* methods - a reference to the array of method declarations for the control
* methodCount - the number of method declarations for the control
* events - a reference to the array of event declarations for the control
* eventCount - the number of event declarations for the control
* behaviour - a reference to the control behaviour table
group - the name of the property group that the property should be displayed in
name - the name of the property
type - the name of the type of the property
flags - any special property flags
propertyOffset - the offset of the property in the auxiliary structure for the form
(Please note that properties are only data-driven in the current version - code-driven properties should be available in the next version)
Declaring methods
-----------------
REALmethodDefinition boxMethods[] = {
{ 6, "makered" },
{ 7, "colorComponent(v as integer) as integer" },
};
Control methods are declared exactly the same as declaring new global methods.
Declaring events
----------------
REALevent boxEvents[] = {
{ "Action" }
};
A REALevent structure merely has the declaration for the event, which is in the same form as a method declaration.
Control behaviour
-----------------
REALcontrolBehaviour boxBehaviour = {
nil,
nil,
&pluginExports[2],
&pluginExports[3],
&pluginExports[4],
&pluginExports[5],
nil,
nil,
nil
};
The REALcontrolBehaviour structure references the REALexport entry points that define the behaviour for the control.
The entry points are:
initFunction - called when the control is initialized:
void initFunction(REALcontrolInstance)
disposeFunction - called when the control is disposed:
void disposeFunction(REALcontrolInstance)
redrawFunction - called when the control needs to be redrawn:
void redrawFunction(REALcontrolInstance)
clickFunction - called when the control is clicked on:
Boolean clickFunction(REALcontrolInstance, int x, int y, int modifiers)
mouseDragFunction - called while the mouse is held down after clickFunction returned true:
void mouseDragFunction(REALcontrolInstance, int x, int y)
mouseUpFunction - called when mouse is released after clickFunction returned true:
void mouseUpFunction(REALcontrolInstance, int x, int y)
gainedFocusFunction - called when the control gains the focus
void gainedFocusFunction(REALcontrolInstance)
lostFocusFunction - called when the control loses the focus
void lostFocusFunction(REALcontrolInstance)
keyDownFunction - called when the user presses a key while the control has the focus:
Boolean keyDownFunction(REALcontrolInstance, int charCode, int keyCode, int modifiers)
Incorporating resources
-----------------------
A plugin file can specify additional resources to be incorporated into the built application via a PLRm resource.
A PLRm resource is just a list of resource type and id pairs - these resources will be incorporated into any built applications that utilise the plugin.
The PLRm resource must have the same id as the associated plugin (usually 128), and a ResEdit TMPL resource for the PLRm resource can be found in the GetFolder.rsrc file (also the REALbasic application itself).
Version History
r35a
- added faceless control flag REALinvisibleControl
- add more examples
- added REALSelectGraphics
- added REALFolderItemFromFSSpec
- improved performance
- removed requirement to use Mixed Mode Manager to handle events
- added ability in incorporate additional resources