gwenhywfar  4.3.1
w_radiobutton.c
Go to the documentation of this file.
00001 /***************************************************************************
00002     begin       : Mon Jul 12 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_WRadioButton_SetIntProperty(GWEN_WIDGET *w,
00016                                        GWEN_DIALOG_PROPERTY prop,
00017                                        int index,
00018                                        int value,
00019                                        int doSignal) {
00020   GtkButton *g;
00021 
00022   g=GTK_BUTTON(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   case GWEN_DialogProperty_Value:
00040     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g), (value==0)?FALSE:TRUE);
00041     return 0;
00042 
00043   default:
00044     break;
00045   }
00046 
00047   DBG_WARN(GWEN_LOGDOMAIN,
00048            "Function is not appropriate for this type of widget (%s)",
00049            GWEN_Widget_Type_toString(GWEN_Widget_GetType(w)));
00050   return GWEN_ERROR_INVALID;
00051 }
00052 
00053 
00054 
00055 
00056 static GWENHYWFAR_CB
00057 int Gtk2Gui_WRadioButton_GetIntProperty(GWEN_WIDGET *w,
00058                                        GWEN_DIALOG_PROPERTY prop,
00059                                        int index,
00060                                        int defaultValue) {
00061   GtkButton *g;
00062 
00063   g=GTK_BUTTON(GWEN_Widget_GetImplData(w, GTK2_DIALOG_WIDGET_REAL));
00064   assert(g);
00065 
00066   switch(prop) {
00067   case GWEN_DialogProperty_Enabled:
00068     return (gtk_widget_get_sensitive(GTK_WIDGET(g))==TRUE)?1:0;
00069 
00070   case GWEN_DialogProperty_Focus:
00071     return (gtk_widget_has_focus(GTK_WIDGET(g))==TRUE)?1:0;
00072 
00073   case GWEN_DialogProperty_Width:
00074   case GWEN_DialogProperty_Height:
00075     /* just ignore these for now */
00076     return 0;
00077 
00078   case GWEN_DialogProperty_Value:
00079     return (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(g))==TRUE)?1:0;
00080 
00081   default:
00082     break;
00083   }
00084 
00085   DBG_WARN(GWEN_LOGDOMAIN,
00086            "Function is not appropriate for this type of widget (%s)",
00087            GWEN_Widget_Type_toString(GWEN_Widget_GetType(w)));
00088   return defaultValue;
00089 }
00090 
00091 
00092 
00093 static GWENHYWFAR_CB
00094 int Gtk2Gui_WRadioButton_SetCharProperty(GWEN_WIDGET *w,
00095                                         GWEN_DIALOG_PROPERTY prop,
00096                                         int index,
00097                                         const char *value,
00098                                         int doSignal) {
00099   GtkButton *g;
00100 
00101   g=GTK_BUTTON(GWEN_Widget_GetImplData(w, GTK2_DIALOG_WIDGET_REAL));
00102   assert(g);
00103 
00104   switch(prop) {
00105   case GWEN_DialogProperty_Title:
00106     gtk_button_set_label(g, value);
00107     return 0;
00108   default:
00109     break;
00110   }
00111 
00112   DBG_WARN(GWEN_LOGDOMAIN,
00113            "Function is not appropriate for this type of widget (%s)",
00114            GWEN_Widget_Type_toString(GWEN_Widget_GetType(w)));
00115   return GWEN_ERROR_INVALID;
00116 }
00117 
00118 
00119 
00120 static GWENHYWFAR_CB
00121 const char* Gtk2Gui_WRadioButton_GetCharProperty(GWEN_WIDGET *w,
00122                                                 GWEN_DIALOG_PROPERTY prop,
00123                                                 int index,
00124                                                 const char *defaultValue) {
00125   GtkButton *g;
00126 
00127   g=GTK_BUTTON(GWEN_Widget_GetImplData(w, GTK2_DIALOG_WIDGET_REAL));
00128   assert(g);
00129 
00130   switch(prop) {
00131   case GWEN_DialogProperty_Title:
00132     return gtk_button_get_label(g);
00133   default:
00134     break;
00135   }
00136 
00137   DBG_WARN(GWEN_LOGDOMAIN,
00138            "Function is not appropriate for this type of widget (%s)",
00139            GWEN_Widget_Type_toString(GWEN_Widget_GetType(w)));
00140   return defaultValue;
00141 }
00142 
00143 
00144 
00145 static void Gtk2Gui_WRadioButton_Toggled_handler(GtkButton *button, gpointer data) {
00146   GWEN_WIDGET *w;
00147   int rv;
00148 
00149   w=data;
00150   assert(w);
00151   rv=GWEN_Dialog_EmitSignal(GWEN_Widget_GetDialog(w),
00152                             GWEN_DialogEvent_TypeActivated,
00153                             GWEN_Widget_GetName(w));
00154   if (rv==GWEN_DialogEvent_ResultAccept)
00155     Gtk2Gui_Dialog_Leave(GWEN_Widget_GetTopDialog(w), 1);
00156   else if (rv==GWEN_DialogEvent_ResultReject)
00157     Gtk2Gui_Dialog_Leave(GWEN_Widget_GetTopDialog(w), 0);
00158 }
00159 
00160 
00161 
00162 int Gtk2Gui_WRadioButton_Setup(GWEN_WIDGET *w) {
00163   GtkWidget *g;
00164   const char *s;
00165   uint32_t flags;
00166   GWEN_WIDGET *wParent;
00167   GWEN_WIDGET *wT;
00168   gulong toggled_handler_id;
00169   int groupId;
00170 
00171   flags=GWEN_Widget_GetFlags(w);
00172   wParent=GWEN_Widget_Tree_GetParent(w);
00173   groupId=GWEN_Widget_GetGroupId(w);
00174 
00175   s=GWEN_Widget_GetText(w, 0);
00176 
00177   /* create widget */
00178   if (s && *s)
00179     g=gtk_radio_button_new_with_mnemonic(NULL, s);
00180   else
00181     g=gtk_radio_button_new(NULL);
00182 
00183   /* get root widget */
00184   wT=wParent;
00185   while(GWEN_Widget_Tree_GetParent(wT))
00186     wT=GWEN_Widget_Tree_GetParent(wT);
00187 
00188   /* get first radio button of the same group */
00189   while(wT) {
00190     if ((GWEN_Widget_GetType(wT)==GWEN_Widget_TypeRadioButton) &&
00191         GWEN_Widget_GetGroupId(wT)==groupId)
00192       break;
00193     wT=GWEN_Widget_Tree_GetBelow(wT);
00194   }
00195   if (wT && wT!=w) {
00196     GSList *grp;
00197 
00198     grp=gtk_radio_button_get_group(GTK_RADIO_BUTTON(GWEN_Widget_GetImplData(wT, GTK2_DIALOG_WIDGET_REAL)));
00199     gtk_radio_button_set_group(GTK_RADIO_BUTTON(g), grp);
00200   }
00201 
00202   /* set pointers */
00203   GWEN_Widget_SetImplData(w, GTK2_DIALOG_WIDGET_REAL, (void*) g);
00204   GWEN_Widget_SetImplData(w, GTK2_DIALOG_WIDGET_CONTENT, (void*) g);
00205 
00206   GWEN_Widget_SetSetIntPropertyFn(w, Gtk2Gui_WRadioButton_SetIntProperty);
00207   GWEN_Widget_SetGetIntPropertyFn(w, Gtk2Gui_WRadioButton_GetIntProperty);
00208   GWEN_Widget_SetSetCharPropertyFn(w, Gtk2Gui_WRadioButton_SetCharProperty);
00209   GWEN_Widget_SetGetCharPropertyFn(w, Gtk2Gui_WRadioButton_GetCharProperty);
00210 
00211   toggled_handler_id=g_signal_connect(g,
00212                                       "toggled",
00213                                       G_CALLBACK (Gtk2Gui_WRadioButton_Toggled_handler),
00214                                       w);
00215 
00216   if (wParent)
00217     GWEN_Widget_AddChildGuiWidget(wParent, w);
00218 
00219   return 0;
00220 }
00221 
00222