gwenhywfar  4.3.3
w_hlayout.c
Go to the documentation of this file.
00001 /***************************************************************************
00002     begin       : Sun May 16 2010
00003     copyright   : (C) 2010 by Martin Preuss
00004     email       : martin@libchipcard.de
00005 
00006  ***************************************************************************
00007  *          Please see toplevel file COPYING for license details           *
00008  ***************************************************************************/
00009 
00010 
00011 
00012 
00013 
00014 static GWENHYWFAR_CB
00015 int Gtk2Gui_WHLayout_SetIntProperty(GWEN_WIDGET *w,
00016                                  GWEN_DIALOG_PROPERTY prop,
00017                                  int index,
00018                                  int value,
00019                                  int doSignal) {
00020   GtkWidget *g;
00021 
00022   g=GTK_WIDGET(GWEN_Widget_GetImplData(w, GTK2_DIALOG_WIDGET_REAL));
00023   assert(g);
00024 
00025   switch(prop) {
00026   case GWEN_DialogProperty_Enabled:
00027     gtk_widget_set_sensitive(GTK_WIDGET(g), (value==0)?FALSE:TRUE);
00028     return 0;
00029   
00030   case GWEN_DialogProperty_Focus:
00031     gtk_widget_grab_focus(GTK_WIDGET(g));
00032     return 0;
00033 
00034   default:
00035     break;
00036   }
00037 
00038   DBG_WARN(GWEN_LOGDOMAIN,
00039            "Function is not appropriate for this type of widget (%s)",
00040            GWEN_Widget_Type_toString(GWEN_Widget_GetType(w)));
00041   return GWEN_ERROR_INVALID;
00042 }
00043 
00044 
00045 
00046 
00047 static GWENHYWFAR_CB
00048 int Gtk2Gui_WHLayout_GetIntProperty(GWEN_WIDGET *w,
00049                                  GWEN_DIALOG_PROPERTY prop,
00050                                  int index,
00051                                  int defaultValue) {
00052   GtkWidget *g;
00053 
00054   g=GTK_WIDGET(GWEN_Widget_GetImplData(w, GTK2_DIALOG_WIDGET_REAL));
00055   assert(g);
00056 
00057   switch(prop) {
00058   case GWEN_DialogProperty_Enabled:
00059     return (gtk_widget_get_sensitive(GTK_WIDGET(g))==TRUE)?1:0;
00060 
00061   case GWEN_DialogProperty_Focus:
00062     return (gtk_widget_has_focus(GTK_WIDGET(g))==TRUE)?1:0;
00063     return 0;
00064 
00065   default:
00066     break;
00067   }
00068 
00069   DBG_WARN(GWEN_LOGDOMAIN,
00070            "Function is not appropriate for this type of widget (%s)",
00071            GWEN_Widget_Type_toString(GWEN_Widget_GetType(w)));
00072   return defaultValue;
00073 }
00074 
00075 
00076 
00077 static GWENHYWFAR_CB
00078 int Gtk2Gui_WHLayout_SetCharProperty(GWEN_WIDGET *w,
00079                                      GWEN_DIALOG_PROPERTY prop,
00080                                      int index,
00081                                      const char *value,
00082                                      int doSignal) {
00083   GtkWidget *g;
00084 
00085   g=GTK_WIDGET(GWEN_Widget_GetImplData(w, GTK2_DIALOG_WIDGET_REAL));
00086   assert(g);
00087 
00088   DBG_WARN(GWEN_LOGDOMAIN,
00089            "Function is not appropriate for this type of widget (%s)",
00090            GWEN_Widget_Type_toString(GWEN_Widget_GetType(w)));
00091   return GWEN_ERROR_INVALID;
00092 }
00093 
00094 
00095 
00096 static GWENHYWFAR_CB
00097 const char* Gtk2Gui_WHLayout_GetCharProperty(GWEN_WIDGET *w,
00098                                              GWEN_DIALOG_PROPERTY prop,
00099                                              int index,
00100                                              const char *defaultValue) {
00101   GtkWidget *g;
00102 
00103   g=GTK_WIDGET(GWEN_Widget_GetImplData(w, GTK2_DIALOG_WIDGET_REAL));
00104   assert(g);
00105 
00106   DBG_WARN(GWEN_LOGDOMAIN,
00107            "Function is not appropriate for this type of widget (%s)",
00108            GWEN_Widget_Type_toString(GWEN_Widget_GetType(w)));
00109   return defaultValue;
00110 }
00111 
00112 
00113 
00114 static GWENHYWFAR_CB
00115 int Gtk2Gui_WHLayout_AddChildGuiWidget(GWEN_WIDGET *w, GWEN_WIDGET *wChild) {
00116   GtkWidget *g;
00117   GtkWidget *gChild;
00118   uint32_t cflags;
00119 
00120   g=GTK_WIDGET(GWEN_Widget_GetImplData(w, GTK2_DIALOG_WIDGET_REAL));
00121   assert(g);
00122 
00123   gChild=GTK_WIDGET(GWEN_Widget_GetImplData(wChild, GTK2_DIALOG_WIDGET_REAL));
00124   assert(gChild);
00125 
00126   cflags=GWEN_Widget_GetFlags(wChild);
00127 
00128   gtk_box_pack_start(GTK_BOX(g), gChild,
00129                      (cflags & GWEN_WIDGET_FLAGS_FILLX)?TRUE:FALSE,
00130                      (cflags & GWEN_WIDGET_FLAGS_FILLX)?TRUE:FALSE,
00131                      0);
00132 
00133   return 0;
00134 }
00135 
00136 
00137 
00138 int Gtk2Gui_WHLayout_Setup(GWEN_WIDGET *w) {
00139   GtkWidget *g;
00140   uint32_t flags;
00141   GWEN_WIDGET *wParent;
00142 
00143   flags=GWEN_Widget_GetFlags(w);
00144   wParent=GWEN_Widget_Tree_GetParent(w);
00145 
00146 #if 0
00147   /* using equal width here doesn't seem to be working as expected:
00148    * I would expect al children be of equal width, but instead all children are
00149    * equally distant to each other while still being of different width...
00150    */
00151   g=gtk_hbox_new((flags & GWEN_WIDGET_FLAGS_EQUAL_WIDTH)?TRUE:FALSE,
00152                  GTK2_GUI_DIALOG_DEFAULT_BOX_SPACING);
00153 #else
00154   g=gtk_hbox_new(FALSE, GTK2_GUI_DIALOG_DEFAULT_BOX_SPACING);
00155 #endif
00156   GWEN_Widget_SetImplData(w, GTK2_DIALOG_WIDGET_REAL, (void*) g);
00157   GWEN_Widget_SetImplData(w, GTK2_DIALOG_WIDGET_CONTENT, (void*) g);
00158 
00159   GWEN_Widget_SetSetIntPropertyFn(w, Gtk2Gui_WHLayout_SetIntProperty);
00160   GWEN_Widget_SetGetIntPropertyFn(w, Gtk2Gui_WHLayout_GetIntProperty);
00161   GWEN_Widget_SetSetCharPropertyFn(w, Gtk2Gui_WHLayout_SetCharProperty);
00162   GWEN_Widget_SetGetCharPropertyFn(w, Gtk2Gui_WHLayout_GetCharProperty);
00163   GWEN_Widget_SetAddChildGuiWidgetFn(w, Gtk2Gui_WHLayout_AddChildGuiWidget);
00164 
00165   if (wParent)
00166     GWEN_Widget_AddChildGuiWidget(wParent, w);
00167 
00168   return 0;
00169 }
00170 
00171