[Previous] [Contents] [Index] [Next]


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 );


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.

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().

Note: 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.

The arguments to ApCreateWidget() are as follows:

points to a widget database opened with either ApOpenDBase() or ApOpenDBaseFile()
the instance name of one of the widgets inside the database
x and y
convenience arguments for specifying the position of the widget when it's created
Note: If y is -1, the widget's original position is used.

nargs and args
the standard resource argument counter and argument list used by PtCreateWidget()

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.


A pointer to the widget created for wgt_name, or NULL on failure.


ApDBase_t         *mydbase;
PtArg_t           args[2];

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 );
ApCreateWidget( mydbase, "my_label_widget", 10, 30, 2, 
                args );

ApCloseDBase( mydbase );



Interrupt handler No
Signal handler No
Thread No

See also:

ApCloseDBase(), ApCreateWidgetFamily(), ApOpenDBase(), ApOpenDBaseFile(), ApSaveDBaseFile(), PtCreateWidget(), PtSetParentWidget()

Accessing PhAB Modules from Code chapter of the Photon Programmer's Guide

[Previous] [Contents] [Index] [Next]