Create a widget by copying it from a PhAB widget database
#include <Ap.h> PtWidget_t *ApCreateWidget( ApDBase_t const *db, char const *wgt_name, int x, int y, int nargs, PtArg_t const *args );
If y is -1, the widget's original position is used. |
Ap
This function is used to create widgets by copying a widget from a PhAB widget database. This is very useful when you need to create many instances of the same widget. For example, a file manager may want to draw a file folder for each directory it displays.
You can use ApCreateDBWidget() instead of this function. ApCreateDBWidget() lets you specify the position without having to worry about the case when y happens to be -1.
The widget is created as a child of the default parent, which is usually the most recently created container. To change the default parent, call PtSetParentWidget().
Before loading widgets from an external database, you should call ApAddClass() for each widget class that you'll likely encounter in it. This will add the widget classes to the internal widget class table. |
ApCreateWidget() creates only the widget named by wgt_name regardless of its class. ApCreateWidgetFamily() creates the named widget and, for container class widgets, any children of the widget.
If the widget returned by this function contains images, the images reference data in the widget database. Therefore, don't close the widget database while you're using the widget. If you need to close the database, you must remove all references to image data. You can do this by destroying the widgets, unsetting images in the widgets, or changing them into images that don't reference the database by using PiDuplicateImage() to copy the images from the database. |
A pointer to the widget created for wgt_name, or NULL on failure.
ApDBase_t *mydbase; PtArg_t args[2]; PtWidget_t *my_label; mydbase = ApOpenDBase( ABM_mypicture ); PtSetArg( &args[0], Pt_ARG_TEXT_STRING, "This Widget", 0 ); ApCreateWidget( mydbase, "my_label_widget", 10, 10, 1, args ); PtSetArg( &args[0], Pt_ARG_TEXT_STRING, "That Widget", 0 ); PtSetArg( &args[1], Pt_ARG_FILL_COLOR, Pg_WHITE, 0 ); my_label = ApCreateWidget( mydbase, "my_label_widget", 10, 30, 2, args ); if (my_label != NULL) { PtRealizeWidget( my_label ); } ApCloseDBase( mydbase );
Photon
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | No |
Thread | No |
ApCloseDBase(), ApCreateDBWidget(), ApCreateDBWidgetFamily(), ApCreateWidgetFamily(), ApGetDBWidgetInfo(), ApOpenDBase(), ApOpenDBaseFile(), ApSaveDBaseFile(), PtArg_t, PtCreateWidget(), PtSetParentWidget()
Accessing PhAB Modules from Code chapter of the Photon Programmer's Guide