Implementation Notes
Toolkit Independent Dialog Framework

Implementation hints.

Implementation hints.

The dialog framework is part of the GWEN_GUI framework (Graphical User Interface). To make your implementation available to the application you will have to set the following callbacks in GWEN_GUI:

- GWEN_Gui_ExecDialog (use GWEN_Gui_SetExecDialogFn)
- GWEN_Gui_OpenDialog (use GWEN_Gui_SetOpenDialogFn)
- GWEN_Gui_CloseDialog (use GWEN_Gui_SetCloseDialogFn)
- GWEN_Gui_RunDialog (use GWEN_Gui_SetRunDialogFn)

The function GWEN_Gui_ExecDialog can be implemented by just calling the other functions (first GWEN_Gui_OpenDialog followed by GWEN_Gui_RunDialog and GWEN_Gui_CloseDialog).

Your implementation of GWEN_Gui_OpenDialog must set the follwing callbacks in the object pointed to by the first argument (GWEN_DIALOG):

- GWEN_Dialog_SetIntProperty (use GWEN_Dialog_SetSetIntPropertyFn)
- GWEN_Dialog_GetIntProperty (use GWEN_Dialog_SetGetIntPropertyFn)
- GWEN_Dialog_SetCharProperty (use GWEN_Dialog_SetSetCharPropertyFn)
- GWEN_Dialog_GetCharProperty (use GWEN_Dialog_SetGetCharPropertyFn)

The GKT2 implementation does it like this:

GWEN_INHERIT(GWEN_DIALOG, GTK2_GUI_DIALOG)
void Gtk2Gui_Dialog_Extend(GWEN_DIALOG *dlg) {
GTK2_GUI_DIALOG *xdlg;
GWEN_NEW_OBJECT(GTK2_GUI_DIALOG, xdlg);
GWEN_INHERIT_SETDATA(GWEN_DIALOG, GTK2_GUI_DIALOG, dlg, xdlg, Gtk2Gui_Dialog_FreeData);
GWEN_Dialog_SetSetIntPropertyFn(dlg, Gtk2Gui_Dialog_SetIntProperty);
GWEN_Dialog_SetGetIntPropertyFn(dlg, Gtk2Gui_Dialog_GetIntProperty);
GWEN_Dialog_SetSetCharPropertyFn(dlg, Gtk2Gui_Dialog_SetCharProperty);
GWEN_Dialog_SetGetCharPropertyFn(dlg, Gtk2Gui_Dialog_GetCharProperty);
}
GWEN_DIALOG
struct GWEN_DIALOG GWEN_DIALOG
Definition dialog.h:54
GWEN_Dialog_SetGetCharPropertyFn
GWENHYWFAR_API GWEN_DIALOG_GETCHARPROPERTY_FN GWEN_Dialog_SetGetCharPropertyFn(GWEN_DIALOG *dlg, GWEN_DIALOG_GETCHARPROPERTY_FN fn)
GWEN_Dialog_SetSetCharPropertyFn
GWENHYWFAR_API GWEN_DIALOG_SETCHARPROPERTY_FN GWEN_Dialog_SetSetCharPropertyFn(GWEN_DIALOG *dlg, GWEN_DIALOG_SETCHARPROPERTY_FN fn)
GWEN_Dialog_SetGetIntPropertyFn
GWENHYWFAR_API GWEN_DIALOG_GETINTPROPERTY_FN GWEN_Dialog_SetGetIntPropertyFn(GWEN_DIALOG *dlg, GWEN_DIALOG_GETINTPROPERTY_FN fn)
GWEN_Dialog_SetSetIntPropertyFn
GWENHYWFAR_API GWEN_DIALOG_SETINTPROPERTY_FN GWEN_Dialog_SetSetIntPropertyFn(GWEN_DIALOG *dlg, GWEN_DIALOG_SETINTPROPERTY_FN fn)
GWEN_INHERIT_SETDATA
#define GWEN_INHERIT_SETDATA(bt, t, element, data, fn)
Definition inherit.h:300
GWEN_INHERIT
#define GWEN_INHERIT(bt, t)
Definition inherit.h:264
GWEN_NEW_OBJECT
#define GWEN_NEW_OBJECT(typ, varname)
Definition memory.h:55

It must also create the actual widgets used by your GUI toolkit (e.g. QLabel for label widgets with QT). To do that you should call GWEN_Dialog_GetWidgets to get the tree of widget descriptions. The most important information about a widget is its type (GWEN_Widget_GetType). The implementation of GWEN_Gui_OpenDialog can use that information to decide what GUI widget should be created to represent that widget description.

For example the QT implementation creates a QLabel object for the widget type GWEN_Widget_TypeLabel.

You can call the function GWEN_Widget_SetImplData to store a pointer to the GUI widget created (e.g. the QT implementation stores a pointer to the created QLabel object for widgets of type GWEN_Widget_TypeLabel). To retrieve that pointer later call GWEN_Widget_GetImplData. Currently up to 4 pointers can be stored per GWEN_WIDGET object (in the case that there are multiple GUI objects required to represent a given GWEN_WIDGET).

Another important hint comes from the widget flags (get them with GWEN_Widget_GetFlags). Those flag tell the implementation about some layout options and other things.

For widgets using media like icons or images the implementation can call GWEN_Dialog_GetMediaPaths to get a list of paths where those icons can be found. This information is provided by the dialog itself. You can use functions like GWEN_Directory_FindFileInPaths to actually find the icon or image file using the media paths.

This example shows how the GTK2 implementation creates a GUI representation of type GWEN_Widget_TypeLabel:

#define GTK2_DIALOG_WIDGET_REAL 0
#define GTK2_DIALOG_WIDGET_CONTENT 1
int Gtk2Gui_WLabel_Setup(GWEN_WIDGET *w) {
GtkWidget *g;
const char *s;
uint32_t flags;
GWEN_WIDGET *wParent;
flags=GWEN_Widget_GetFlags(w);
wParent=GWEN_Widget_Tree_GetParent(w);
s=GWEN_Widget_GetText(w, 0);
g=gtk_label_new(s);
GWEN_Widget_SetImplData(w, GTK2_DIALOG_WIDGET_REAL, (void*) g);
GWEN_Widget_SetImplData(w, GTK2_DIALOG_WIDGET_CONTENT, (void*) g);
GWEN_Widget_SetSetIntPropertyFn(w, Gtk2Gui_WLabel_SetIntProperty);
GWEN_Widget_SetGetIntPropertyFn(w, Gtk2Gui_WLabel_GetIntProperty);
GWEN_Widget_SetSetCharPropertyFn(w, Gtk2Gui_WLabel_SetCharProperty);
GWEN_Widget_SetGetCharPropertyFn(w, Gtk2Gui_WLabel_GetCharProperty);
if (wParent)
GWEN_Widget_AddChildGuiWidget(wParent, w);
return 0;
}
GWEN_Widget_SetSetCharPropertyFn
GWENHYWFAR_API GWEN_WIDGET_SETCHARPROPERTY_FN GWEN_Widget_SetSetCharPropertyFn(GWEN_WIDGET *w, GWEN_WIDGET_SETCHARPROPERTY_FN fn)
GWEN_WIDGET
struct GWEN_WIDGET GWEN_WIDGET
Definition widget_be.h:34
GWEN_Widget_GetFlags
GWENHYWFAR_API uint32_t GWEN_Widget_GetFlags(const GWEN_WIDGET *w)
GWEN_Widget_SetImplData
GWENHYWFAR_API void GWEN_Widget_SetImplData(GWEN_WIDGET *w, int index, void *ptr)
Store a pointer with the widget.
GWEN_Widget_AddChildGuiWidget
GWENHYWFAR_API int GWEN_Widget_AddChildGuiWidget(GWEN_WIDGET *w, GWEN_WIDGET *wChild)
GWEN_Widget_SetGetCharPropertyFn
GWENHYWFAR_API GWEN_WIDGET_GETCHARPROPERTY_FN GWEN_Widget_SetGetCharPropertyFn(GWEN_WIDGET *w, GWEN_WIDGET_GETCHARPROPERTY_FN fn)
GWEN_Widget_SetSetIntPropertyFn
GWENHYWFAR_API GWEN_WIDGET_SETINTPROPERTY_FN GWEN_Widget_SetSetIntPropertyFn(GWEN_WIDGET *w, GWEN_WIDGET_SETINTPROPERTY_FN fn)
GWEN_Widget_GetText
GWENHYWFAR_API const char * GWEN_Widget_GetText(const GWEN_WIDGET *w, int idx)
GWEN_Widget_SetGetIntPropertyFn
GWENHYWFAR_API GWEN_WIDGET_GETINTPROPERTY_FN GWEN_Widget_SetGetIntPropertyFn(GWEN_WIDGET *w, GWEN_WIDGET_GETINTPROPERTY_FN fn)