HBasic packages |
There are some packages that will already be delivered with HBasic. This
document should give an overview of this packages and the components in it.
Creating components / packages |
Directories for packages in HBasic |
When a package has been compiled there are two files that belong to a package. The first is the library file itself which must be a dynamic link library that HBasic may load at runtime and the second is a description that helps HBasic to find the components and their structure within the package. The names for this two files are <package_name>.hbso for the shared library and <package_name>.desc for the description file. See "source files in a package" to lear how to set up the package source to create these files.
Basic requirements to set up a package |
The second important part is the description of the package which is stored
in a separate file. The format for this description is a readable text in
a XML like format. You can find a short description of the syntax for this
file in "Description of methods, properties and events".
Source files in a package |
Parts of a component |
As for other function calls used by HBasic the starting address of these two functions must be listed in the function_call table that is set up by the init_package function. In the following example the address of the set function must be at position 25 in the function table and the address of the get function is at address 26.
<namespace>
[package description header]
<class>
[description of first component]
</class>
<class>
[description of second component]
</class>
...
<class>
[description of last component]
</class>
</namespace>
Starting with a namespace tag it should be possible to declare more than one namespace (logical structure for components) within one package. Currently this is not used but the namespace tag is needed to support the correct syntax. In the following we show some examples from the description of the hbasic_stdgui package.
<namespace>
<name>QT_STDGUI</name>
<version>100</version>
<shortdesc>Standard GUI-QT components for HBasic</shortdesc>
<desc>
<line> "This package defines the
standard " </line>
<line> "GUI Components for the QT
library " </line>
<line> "like Button, Lineedit ..."
</line>
</desc>
[component definitions]
</namespace>
The tags that may be used in the package header are
Each component description starts with the <class> tag and ends with
</class>. The following tags may be used within this class description:
<name> | Name of the component |
<flaglist> | Set different options / flags for the component |
<shortdesc> | Short description text for component |
<method> | Describe a method of the component |
<property> | Describe a property of the component |
<event> | Describe an event the component may raise |
<icon> | Set the icon picture for the component |
Name of the component
<name>LABEL</name>
Flags for the component
Flags may set special properties of a component that only accept the values
TRUE or FALSE. Currently HBasic only knows the following flags:
NOWIDGET | Used if the component doesn't have a widget that may be displayed to show the component in a gui window. These components are not visible at runtime but may export the same parts as other components. They are used for example in the file_package or net_package because their components don't need a visible gui. |
NOPICTURE | This component will not be displayed in the list of components the user may select (component selection window) and can therefore not be instantiated by the hbasic developer. Used for FORM component in hbasic_stdgui. |
<flaglist>
<set>NOWIDGET</set>
</flaglist>
Short description of the component
<shortdesc>General form widget</shortdesc>
Method definition in component description
<method>
<name>TAN</name>
<callfunction>6</callfunction>
<return>double</return>
<parameter>double</parameter>
</method>
To set up a function definition you can use the following tags:
<name> | Name of the method |
<callfunction> | Position of the function in the function table which should be called when HBasic wants to call the method. |
<return> | Type of return value of the method. If there is no return value the default is a method without a return value. |
<parameter> | Type of the parameters of the method. You may set up one, more than one or no parameter. HBasic uses this description to check the method call in the parser for the correct syntax. |
This describes the method TAN which when used in a habsic program calls the function number 6 of the package through the function table of the package. The method call has only one parameter of type double.
Property description in component description
<property>
<name>prop1</name>
<set>25</set>
<get>26</get>
<type>long</type>
</property>
This describes a property prop1 which when used in a HBasic propgram calls a set function to write the property value or get function to read the property value. The type of the property value is long and the name of the property is prop1. If you declared a variable comp1 from this component type you may read or write the property with statements like
comp1.prop1 = <newvalue>
Print comp1.prop1
Event definition in component description
The event desciption uses the following tags:
<name> | Name of the event |
<id> | Unique id of the event |
<parameter> | Type for each parameter that will be transferred when raising the event. |
When Hbasic wants to connect a component with an event handling function it must store a reference in the memory of the component. When designing the memory structure of a component the developer has to reserve this memory. Each event address starting with id 0 needs a long value. Since the first address in each component is a pointer to the function table of the package the address table for the events start behing this address. A structure definition for a component with event id's 0, 1, and 2 should look like the following:
struct COMP_MEMORY
{
void *function table;
long event_address_0;
long event_address_1;
long event_address_2;
[definition of other event memory parts]
}
The contents of this fields will be initialized and used by HBasic.
<event>
<name>CLICKED</name>
<id>0</id>
<parameter>
<TYPE>short</TYPE>
<TYPE>short</TYPE>
</parameter>
</event>
When you want to raise an event from the C++ code of the package you start the global function startEvent( event_id, component_memory). This function needs the unique id number of the event and the starting address of the component as parameters to the call. HBasic will search the connected HBasic function if the user has defined one in it's source code and start it.
To select a component within the GUI editor of HBasic each component of a package will be displayed as a small icon in the component selection window. You can set the image for this icon with the <icon> tag in the component definition. The format of the picture is similar to a XPM format. To create a new icon start a program like gimp and create a new image with a pixelwith and height between 16 and 24 pixel. Save this image in XPM format (name.xpm) and copy the created text file with an editor like vi to yout component description.
A picture in XPM format normally looks similar to the following lines:
/* XPM */
static char * label_xpm[] = {
"17 17 3 1",
" c Black",
"X c Gray74",
"O c None",
"OOOOOOOOOOOOOOOOO",
"OOOOOOOO OOOOOOO",
"OOOOOOO OOOOOOO",
"OOOOOOO OOOOOOO",
"OOOOOO OOOOOO",
"OOOOOO OOOOOO",
"OOOOO O OOOOO",
"OOOOO O OOOO",
"OOOO OO OOOO",
"OOOO OOO",
"OOO OOO",
"OOO OOOOO OOO",
"OO OOOOO OO",
"O OOOOO O",
"O OOO O",
"OOOOOOOOOOOOOOOOO"};
Since I didn't find a better way to separate between the lines of the picture than putting each line in new tags you have to correct this for each line of your XPM file. Surround each picture line with this tags as you can see in the following example. Afterwards delete some the leading and finishing lines that define comments or the C++ character array for the picture. You may now use the resulting lines as an icon definition within your HBasic package description.
<icon>
<line>17 17 3 1</line>
<line> c Black</line>
<line>X c Gray74</line>
<line>O c None</line>
<line>OOOOOOOOOOOOOOOOO</line>
<line>OOOOOOOO OOOOOOO</line>
<line>OOOOOOO OOOOOOO</line>
<line>OOOOOOO OOOOOOO</line>
<line>OOOOOO OOOOOO</line>
<line>OOOOOO OOOOOO</line>
<line>OOOOOO OOOOO</line>
<line>OOOOO O OOOOO</line>
<line>OOOOO O OOOO</line>
<line>OOOO OO OOOO</line>
<line>OOOO
OOO</line>
<line>OOO
OOO</line>
<line>OOO OOOOO OOO</line>
<line>OO OOOOO OO</line>
<line>O OOOOO
O</line>
<line>O OOO
O</line>
<line>OOOOOOOOOOOOOOOOO</line>
</icon>
Creating components / packages |