gwenhywfar 4.0.3
|
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 typedef struct GTK2_GRIDLAYOUT_WIDGET GTK2_GRIDLAYOUT_WIDGET; 00013 struct GTK2_GRIDLAYOUT_WIDGET { 00014 int sortByRow; 00015 int allocatedColumns; 00016 int allocatedRows; 00017 00018 int currentColumn; 00019 int currentRow; 00020 }; 00021 00022 00023 GWEN_INHERIT(GWEN_WIDGET, GTK2_GRIDLAYOUT_WIDGET) 00024 00025 00026 00027 static GWENHYWFAR_CB 00028 int Gtk2Gui_WGridLayout_SetIntProperty(GWEN_WIDGET *w, 00029 GWEN_DIALOG_PROPERTY prop, 00030 int index, 00031 int value, 00032 int doSignal) { 00033 GtkWidget *g; 00034 00035 g=GTK_WIDGET(GWEN_Widget_GetImplData(w, GTK2_DIALOG_WIDGET_REAL)); 00036 assert(g); 00037 00038 switch(prop) { 00039 case GWEN_DialogProperty_Enabled: 00040 gtk_widget_set_sensitive(GTK_WIDGET(g), (value==0)?FALSE:TRUE); 00041 return 0; 00042 00043 case GWEN_DialogProperty_Focus: 00044 gtk_widget_grab_focus(GTK_WIDGET(g)); 00045 return 0; 00046 00047 default: 00048 break; 00049 } 00050 00051 DBG_WARN(GWEN_LOGDOMAIN, 00052 "Function is not appropriate for this type of widget (%s)", 00053 GWEN_Widget_Type_toString(GWEN_Widget_GetType(w))); 00054 return GWEN_ERROR_INVALID; 00055 } 00056 00057 00058 00059 00060 static GWENHYWFAR_CB 00061 int Gtk2Gui_WGridLayout_GetIntProperty(GWEN_WIDGET *w, 00062 GWEN_DIALOG_PROPERTY prop, 00063 int index, 00064 int defaultValue) { 00065 GtkWidget *g; 00066 00067 g=GTK_WIDGET(GWEN_Widget_GetImplData(w, GTK2_DIALOG_WIDGET_REAL)); 00068 assert(g); 00069 00070 switch(prop) { 00071 case GWEN_DialogProperty_Enabled: 00072 return (gtk_widget_get_sensitive(GTK_WIDGET(g))==TRUE)?1:0; 00073 00074 case GWEN_DialogProperty_Focus: 00075 return (gtk_widget_has_focus(GTK_WIDGET(g))==TRUE)?1:0; 00076 return 0; 00077 00078 default: 00079 break; 00080 } 00081 00082 DBG_WARN(GWEN_LOGDOMAIN, 00083 "Function is not appropriate for this type of widget (%s)", 00084 GWEN_Widget_Type_toString(GWEN_Widget_GetType(w))); 00085 return defaultValue; 00086 } 00087 00088 00089 00090 static GWENHYWFAR_CB 00091 int Gtk2Gui_WGridLayout_SetCharProperty(GWEN_WIDGET *w, 00092 GWEN_DIALOG_PROPERTY prop, 00093 int index, 00094 const char *value, 00095 int doSignal) { 00096 GtkWidget *g; 00097 00098 g=GTK_WIDGET(GWEN_Widget_GetImplData(w, GTK2_DIALOG_WIDGET_REAL)); 00099 assert(g); 00100 00101 DBG_WARN(GWEN_LOGDOMAIN, 00102 "Function is not appropriate for this type of widget (%s)", 00103 GWEN_Widget_Type_toString(GWEN_Widget_GetType(w))); 00104 return GWEN_ERROR_INVALID; 00105 } 00106 00107 00108 00109 static GWENHYWFAR_CB 00110 const char* Gtk2Gui_WGridLayout_GetCharProperty(GWEN_WIDGET *w, 00111 GWEN_DIALOG_PROPERTY prop, 00112 int index, 00113 const char *defaultValue) { 00114 GtkWidget *g; 00115 00116 g=GTK_WIDGET(GWEN_Widget_GetImplData(w, GTK2_DIALOG_WIDGET_REAL)); 00117 assert(g); 00118 00119 DBG_WARN(GWEN_LOGDOMAIN, 00120 "Function is not appropriate for this type of widget (%s)", 00121 GWEN_Widget_Type_toString(GWEN_Widget_GetType(w))); 00122 return defaultValue; 00123 } 00124 00125 00126 00127 static GWENHYWFAR_CB 00128 int Gtk2Gui_WGridLayout_AddChildGuiWidget(GWEN_WIDGET *w, GWEN_WIDGET *wChild) { 00129 GTK2_GRIDLAYOUT_WIDGET *xw; 00130 GtkWidget *g; 00131 GtkWidget *gChild; 00132 uint32_t cflags; 00133 int x; 00134 int y; 00135 00136 assert(w); 00137 xw=GWEN_INHERIT_GETDATA(GWEN_WIDGET, GTK2_GRIDLAYOUT_WIDGET, w); 00138 assert(xw); 00139 00140 cflags=GWEN_Widget_GetFlags(wChild); 00141 00142 g=GTK_WIDGET(GWEN_Widget_GetImplData(w, GTK2_DIALOG_WIDGET_REAL)); 00143 assert(g); 00144 00145 gChild=GTK_WIDGET(GWEN_Widget_GetImplData(wChild, GTK2_DIALOG_WIDGET_REAL)); 00146 assert(gChild); 00147 00148 if (xw->sortByRow) { 00149 /* fill rows, enter next column if column full */ 00150 y=(xw->currentRow)++; 00151 if (y>=xw->allocatedRows) { 00152 xw->currentRow=0; 00153 y=(xw->currentRow)++; 00154 xw->currentColumn++; 00155 } 00156 00157 x=xw->currentColumn; 00158 if (x>=xw->allocatedColumns) { 00159 xw->allocatedColumns=x+1; 00160 gtk_table_resize(GTK_TABLE(g), xw->allocatedRows, xw->allocatedColumns); 00161 } 00162 } 00163 else { 00164 /* fill columns, enter next row if row full */ 00165 x=(xw->currentColumn)++; 00166 if (x>=xw->allocatedColumns) { 00167 xw->currentColumn=0; 00168 x=(xw->currentColumn)++; 00169 xw->currentRow++; 00170 } 00171 00172 y=xw->currentRow; 00173 if (y>=xw->allocatedRows) { 00174 xw->allocatedRows=y+1; 00175 gtk_table_resize(GTK_TABLE(g), xw->allocatedRows, xw->allocatedColumns); 00176 } 00177 } 00178 00179 gtk_table_attach(GTK_TABLE(g), gChild, 00180 x, x+1, y, y+1, 00181 (cflags & GWEN_WIDGET_FLAGS_FILLX)?(GTK_FILL|GTK_EXPAND):0, 00182 (cflags & GWEN_WIDGET_FLAGS_FILLY)?(GTK_FILL|GTK_EXPAND):0, 00183 GTK2_GUI_DIALOG_DEFAULT_BOX_SPACING, 00184 GTK2_GUI_DIALOG_DEFAULT_BOX_SPACING); 00185 00186 return 0; 00187 } 00188 00189 00190 00191 00192 static GWENHYWFAR_CB 00193 void Gtk2Gui_WGridLayout_FreeData(void *bp, void *p) { 00194 GTK2_GRIDLAYOUT_WIDGET *xw; 00195 00196 xw=(GTK2_GRIDLAYOUT_WIDGET*) p; 00197 00198 GWEN_FREE_OBJECT(xw); 00199 } 00200 00201 00202 00203 int Gtk2Gui_WGridLayout_Setup(GWEN_WIDGET *w) { 00204 GtkWidget *g; 00205 uint32_t flags; 00206 GWEN_WIDGET *wParent; 00207 GTK2_GRIDLAYOUT_WIDGET *xw; 00208 int rows; 00209 int cols; 00210 00211 GWEN_NEW_OBJECT(GTK2_GRIDLAYOUT_WIDGET, xw); 00212 GWEN_INHERIT_SETDATA(GWEN_WIDGET, GTK2_GRIDLAYOUT_WIDGET, w, xw, Gtk2Gui_WGridLayout_FreeData); 00213 00214 flags=GWEN_Widget_GetFlags(w); 00215 wParent=GWEN_Widget_Tree_GetParent(w); 00216 cols=GWEN_Widget_GetColumns(w); 00217 rows=GWEN_Widget_GetRows(w); 00218 00219 if (rows>0) { 00220 xw->sortByRow=1; 00221 xw->allocatedRows=rows; 00222 xw->allocatedColumns=1; 00223 } 00224 else { 00225 xw->sortByRow=0; 00226 xw->allocatedColumns=cols; 00227 xw->allocatedRows=1; 00228 } 00229 00230 g=gtk_table_new(xw->allocatedRows, xw->allocatedColumns, FALSE); 00231 00232 GWEN_Widget_SetImplData(w, GTK2_DIALOG_WIDGET_REAL, (void*) g); 00233 GWEN_Widget_SetImplData(w, GTK2_DIALOG_WIDGET_CONTENT, (void*) g); 00234 00235 GWEN_Widget_SetSetIntPropertyFn(w, Gtk2Gui_WGridLayout_SetIntProperty); 00236 GWEN_Widget_SetGetIntPropertyFn(w, Gtk2Gui_WGridLayout_GetIntProperty); 00237 GWEN_Widget_SetSetCharPropertyFn(w, Gtk2Gui_WGridLayout_SetCharProperty); 00238 GWEN_Widget_SetGetCharPropertyFn(w, Gtk2Gui_WGridLayout_GetCharProperty); 00239 GWEN_Widget_SetAddChildGuiWidgetFn(w, Gtk2Gui_WGridLayout_AddChildGuiWidget); 00240 00241 if (wParent) 00242 GWEN_Widget_AddChildGuiWidget(wParent, w); 00243 00244 return 0; 00245 } 00246 00247