Create function
- Define a function
void sun_awt_motif_MComboBox(
struct Hsun_awt_motif_MComponentPeer *this,
struct Hsun_awt_motif_MComponentPeer *parent)
to create the Motif widget
- The thread should be locked during this function
- The function must extract information from the parent
struct ComponentData *wdata =
(struct ComponentData *)
unhand(parent)->pData;
- wdata->widget contains the parent widget
- it must build a data structure for the new object
struct ComponentData *cdata =
(struct ComponentData *)
sysMalloc(sizeof(struct ComponentData));
SET_PDATA(this, cdata)
- cdata->widget will be set to the new widget
- If funny extra info is required, such as an extra widget in List
(the ScrolledWidget plus the List), define a new structure with first
field a ComponentData, and the rest the extra info, and do the above
anyway. The cdata->widget should be set to the topmost widget.
- Create the widget
- Set MappedWhenManaged to False
- Manage the widget
- Add callback functions for callbacks of interest
void
sun_awt_motif_MComboBoxPeer_create(
struct Hsun_awt_motif_MComboBoxPeer *this,
struct Hsun_awt_motif_MComponentPeer *parent)
{
int argc = 0;
Arg args[40];
struct ComponentData *wdata;
struct ComponentData *cdata;
AWT_LOCK();
if (parent == 0 || unhand(parent)->pData == 0) {
SignalError(0, JAVAPKG "NullPointerException", 0);
AWT_UNLOCK();
return;
}
wdata = (struct ComponentData *)unhand(parent)->pData;
cdata = (struct ComponentData *)sysMalloc(sizeof(struct ComponentData));
SET_PDATA(this, sdata);
if (sdata == 0) {
SignalError(0, JAVAPKG "OutOfMemoryError", 0);
AWT_UNLOCK();
return;
}
cdata->widget = XmCreateComboBox(wdata->widget,
"combo_box",
args,
argc);
XtSetMappedWhenManaged(cdata->widget, False);
XtAddCallback(cdata->widget,
XmNactivateCallback,
activateCB,
(XtPointer)this);
XtManageChild(cdata->widget);
AWT_UNLOCK();
}
Slide 64