gwenhywfar 4.0.3

w_groupbox.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_WGroupBox_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   case GWEN_DialogProperty_Width:
00035   case GWEN_DialogProperty_Height:
00036     /* just ignore these for now */
00037     return 0;
00038 
00039   default:
00040     break;
00041   }
00042 
00043   DBG_WARN(GWEN_LOGDOMAIN,
00044            "Function is not appropriate for this type of widget (%s)",
00045            GWEN_Widget_Type_toString(GWEN_Widget_GetType(w)));
00046   return GWEN_ERROR_INVALID;
00047 }
00048 
00049 
00050 
00051 
00052 static GWENHYWFAR_CB
00053 int Gtk2Gui_WGroupBox_GetIntProperty(GWEN_WIDGET *w,
00054                                  GWEN_DIALOG_PROPERTY prop,
00055                                  int index,
00056                                  int defaultValue) {
00057   GtkWidget *g;
00058 
00059   g=GTK_WIDGET(GWEN_Widget_GetImplData(w, GTK2_DIALOG_WIDGET_REAL));
00060   assert(g);
00061 
00062   switch(prop) {
00063   case GWEN_DialogProperty_Enabled:
00064     return (gtk_widget_get_sensitive(GTK_WIDGET(g))==TRUE)?1:0;
00065 
00066   case GWEN_DialogProperty_Focus:
00067     return (gtk_widget_has_focus(GTK_WIDGET(g))==TRUE)?1:0;
00068     return 0;
00069 
00070   case GWEN_DialogProperty_Width:
00071   case GWEN_DialogProperty_Height:
00072     /* just ignore these for now */
00073     return 0;
00074 
00075   default:
00076     break;
00077   }
00078 
00079   DBG_WARN(GWEN_LOGDOMAIN,
00080            "Function is not appropriate for this type of widget (%s)",
00081            GWEN_Widget_Type_toString(GWEN_Widget_GetType(w)));
00082   return defaultValue;
00083 }
00084 
00085 
00086 
00087 static GWENHYWFAR_CB
00088 int Gtk2Gui_WGroupBox_SetCharProperty(GWEN_WIDGET *w,
00089                                   GWEN_DIALOG_PROPERTY prop,
00090                                   int index,
00091                                   const char *value,
00092                                   int doSignal) {
00093   GtkWidget *g;
00094 
00095   g=GTK_WIDGET(GWEN_Widget_GetImplData(w, GTK2_DIALOG_WIDGET_REAL));
00096   assert(g);
00097 
00098   switch(prop) {
00099   case GWEN_DialogProperty_Title:
00100     gtk_frame_set_label(GTK_FRAME(g), value);
00101     return 0;
00102   default:
00103     break;
00104   }
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 GWEN_ERROR_INVALID;
00110 }
00111 
00112 
00113 
00114 static GWENHYWFAR_CB
00115 const char* Gtk2Gui_WGroupBox_GetCharProperty(GWEN_WIDGET *w,
00116                                            GWEN_DIALOG_PROPERTY prop,
00117                                            int index,
00118                                            const char *defaultValue) {
00119   GtkWidget *g;
00120 
00121   g=GTK_WIDGET(GWEN_Widget_GetImplData(w, GTK2_DIALOG_WIDGET_REAL));
00122   assert(g);
00123 
00124   switch(prop) {
00125   case GWEN_DialogProperty_Title:
00126     return gtk_frame_get_label(GTK_FRAME(g));
00127   default:
00128     break;
00129   }
00130 
00131   DBG_WARN(GWEN_LOGDOMAIN,
00132            "Function is not appropriate for this type of widget (%s)",
00133            GWEN_Widget_Type_toString(GWEN_Widget_GetType(w)));
00134   return defaultValue;
00135 }
00136 
00137 
00138 
00139 static GWENHYWFAR_CB
00140 int Gtk2Gui_WGroupBox_AddChildGuiWidget(GWEN_WIDGET *w, GWEN_WIDGET *wChild) {
00141   GtkWidget *g;
00142   GtkWidget *gChild;
00143   uint32_t cflags;
00144 
00145   g=GTK_WIDGET(GWEN_Widget_GetImplData(w, GTK2_DIALOG_WIDGET_CONTENT));
00146   assert(g);
00147 
00148   gChild=GTK_WIDGET(GWEN_Widget_GetImplData(wChild, GTK2_DIALOG_WIDGET_REAL));
00149   assert(gChild);
00150 
00151   cflags=GWEN_Widget_GetFlags(wChild);
00152 
00153   gtk_box_pack_start(GTK_BOX(g), gChild,
00154                      (cflags & GWEN_WIDGET_FLAGS_FILLY)?TRUE:FALSE,
00155                      (cflags & GWEN_WIDGET_FLAGS_FILLY)?TRUE:FALSE,
00156                      0);
00157 
00158   return 0;
00159 }
00160 
00161 
00162 
00163 int Gtk2Gui_WGroupBox_Setup(GWEN_WIDGET *w) {
00164   GtkWidget *g;
00165   GtkWidget *gContent;
00166   const char *s;
00167   uint32_t flags;
00168   GWEN_WIDGET *wParent;
00169 
00170   flags=GWEN_Widget_GetFlags(w);
00171   wParent=GWEN_Widget_Tree_GetParent(w);
00172   s=GWEN_Widget_GetText(w, 0);
00173 
00174   g=gtk_frame_new(s);
00175 
00176   gContent=gtk_vbox_new(TRUE, GTK2_GUI_DIALOG_DEFAULT_BOX_SPACING);
00177   gtk_container_add(GTK_CONTAINER(g), gContent);
00178 
00179   GWEN_Widget_SetImplData(w, GTK2_DIALOG_WIDGET_REAL, (void*) g);
00180   GWEN_Widget_SetImplData(w, GTK2_DIALOG_WIDGET_CONTENT, (void*) gContent);
00181 
00182   GWEN_Widget_SetSetIntPropertyFn(w, Gtk2Gui_WGroupBox_SetIntProperty);
00183   GWEN_Widget_SetGetIntPropertyFn(w, Gtk2Gui_WGroupBox_GetIntProperty);
00184   GWEN_Widget_SetSetCharPropertyFn(w, Gtk2Gui_WGroupBox_SetCharProperty);
00185   GWEN_Widget_SetGetCharPropertyFn(w, Gtk2Gui_WGroupBox_GetCharProperty);
00186   GWEN_Widget_SetAddChildGuiWidgetFn(w, Gtk2Gui_WGroupBox_AddChildGuiWidget);
00187 
00188   if (wParent)
00189     GWEN_Widget_AddChildGuiWidget(wParent, w);
00190 
00191   return 0;
00192 }
00193 
00194