gwenhywfar 5.14.1
gtk2/w_progressbar.c
Go to the documentation of this file.
1/***************************************************************************
2 begin : Sun May 16 2010
3 copyright : (C) 2010 by Martin Preuss
4 email : martin@libchipcard.de
5
6 ***************************************************************************
7 * Please see toplevel file COPYING for license details *
8 ***************************************************************************/
9
10
11
12typedef struct W_PROGRESSBAR W_PROGRESSBAR;
13struct W_PROGRESSBAR {
14 int minValue;
15 int maxValue;
16 int currentValue;
17};
18
19
21
22
23
24static GWENHYWFAR_CB
27 GWEN_UNUSED int index,
28 int value,
29 GWEN_UNUSED int doSignal)
30{
31 GtkProgressBar *g;
32 W_PROGRESSBAR *xw;
33
34 assert(w);
36 assert(xw);
37
39 assert(g);
40
41 switch (prop) {
43 gtk_widget_set_sensitive(GTK_WIDGET(g), (value==0)?FALSE:TRUE);
44 return 0;
45
47 gtk_widget_grab_focus(GTK_WIDGET(g));
48 return 0;
49
52 /* just ignore these for now */
53 return 0;
54
56
57 xw->currentValue=value;
58 if (xw->maxValue) {
59 gdouble d;
60 char numbuf[32];
61
62 d=(gdouble)(xw->currentValue-xw->minValue)/(gdouble)(xw->maxValue);
63 gtk_progress_bar_set_fraction(g, d);
64 snprintf(numbuf, sizeof(numbuf)-1, "%d %%", (int)(d*100.0));
65 numbuf[sizeof(numbuf)-1]=0;
66 gtk_progress_bar_set_text(g, numbuf);
67 }
68 else {
69 gtk_progress_bar_set_fraction(g, 0.0);
70 gtk_progress_bar_set_text(g, "");
71 }
72 return 0;
73 }
74
76 xw->minValue=value;
77 if (xw->maxValue) {
78 gdouble d;
79 char numbuf[32];
80
81 d=(gdouble)(xw->currentValue-xw->minValue)/(gdouble)(xw->maxValue);
82 gtk_progress_bar_set_fraction(g, d);
83 snprintf(numbuf, sizeof(numbuf)-1, "%d %%", (int)(d*100.0));
84 numbuf[sizeof(numbuf)-1]=0;
85 gtk_progress_bar_set_text(g, numbuf);
86 }
87 else {
88 gtk_progress_bar_set_fraction(g, 0.0);
89 gtk_progress_bar_set_text(g, "");
90 }
91 return 0;
92 }
93
95 xw->maxValue=value;
96 if (xw->maxValue) {
97 gdouble d;
98 char numbuf[32];
99
100 d=(gdouble)(xw->currentValue-xw->minValue)/(gdouble)(xw->maxValue);
101 gtk_progress_bar_set_fraction(g, d);
102 snprintf(numbuf, sizeof(numbuf)-1, "%d %%", (int)(d*100.0));
103 numbuf[sizeof(numbuf)-1]=0;
104 gtk_progress_bar_set_text(g, numbuf);
105 return 0;
106 }
107 else {
108 gtk_progress_bar_set_fraction(g, 0.0);
109 gtk_progress_bar_set_text(g, "");
110 }
111 }
112
113 default:
114 break;
115 }
116
118 "Function is not appropriate for this type of widget (%s)",
120 return GWEN_ERROR_INVALID;
121}
122
123
124
125
126static GWENHYWFAR_CB
129 GWEN_UNUSED int index,
130 int defaultValue)
131{
132 GtkProgressBar *g;
133 W_PROGRESSBAR *xw;
134
135 assert(w);
137 assert(xw);
138
139 g=GTK_PROGRESS_BAR(GWEN_Widget_GetImplData(w, GTK2_DIALOG_WIDGET_REAL));
140 assert(g);
141
142 switch (prop) {
144 return (gtk_widget_get_sensitive(GTK_WIDGET(g))==TRUE)?1:0;
145
147 return (gtk_widget_has_focus(GTK_WIDGET(g))==TRUE)?1:0;
148 return 0;
149
152 /* just ignore these for now */
153 return 0;
154
156 return xw->currentValue;
157
159 return xw->minValue;
160
162 return xw->maxValue;
163
164 default:
165 break;
166 }
167
169 "Function is not appropriate for this type of widget (%s)",
171 return defaultValue;
172}
173
174
175
176static GWENHYWFAR_CB
179 GWEN_UNUSED int index,
180 GWEN_UNUSED const char *value,
181 GWEN_UNUSED int doSignal)
182{
184 "Function is not appropriate for this type of widget (%s)",
186 return GWEN_ERROR_INVALID;
187}
188
189
190
191static GWENHYWFAR_CB
194 GWEN_UNUSED int index,
195 const char *defaultValue)
196{
198 "Function is not appropriate for this type of widget (%s)",
200 return defaultValue;
201}
202
203
204
206{
207 W_PROGRESSBAR *xw;
208
209 xw=(W_PROGRESSBAR *) p;
211}
212
213
214
216{
217 GtkWidget *g;
218 /*const char *s;*/
219 /*uint32_t flags;*/
220 GWEN_WIDGET *wParent;
221 W_PROGRESSBAR *xw;
222
225
226 /*flags=GWEN_Widget_GetFlags(w);*/
227 wParent=GWEN_Widget_Tree_GetParent(w);
228 /*s=GWEN_Widget_GetText(w, 0);*/
229
230 g=gtk_progress_bar_new();
233
238
239 if (wParent)
241
242 return 0;
243}
244
245
#define DBG_WARN(dbg_logger, format,...)
Definition debug.h:125
GWEN_DIALOG_PROPERTY
Definition dialog.h:260
@ GWEN_DialogProperty_MinValue
Definition dialog.h:265
@ GWEN_DialogProperty_MaxValue
Definition dialog.h:266
@ GWEN_DialogProperty_Height
Definition dialog.h:273
@ GWEN_DialogProperty_Enabled
Definition dialog.h:267
@ GWEN_DialogProperty_Value
Definition dialog.h:264
@ GWEN_DialogProperty_Focus
Definition dialog.h:276
@ GWEN_DialogProperty_Width
Definition dialog.h:272
#define GWEN_ERROR_INVALID
Definition error.h:67
static GWENHYWFAR_CB const char * Gtk2Gui_WProgressBar_GetCharProperty(GWEN_WIDGET *w, GWEN_UNUSED GWEN_DIALOG_PROPERTY prop, GWEN_UNUSED int index, const char *defaultValue)
static GWENHYWFAR_CB int Gtk2Gui_WProgressBar_GetIntProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, GWEN_UNUSED int index, int defaultValue)
static GWENHYWFAR_CB int Gtk2Gui_WProgressBar_SetIntProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, GWEN_UNUSED int index, int value, GWEN_UNUSED int doSignal)
static GWENHYWFAR_CB int Gtk2Gui_WProgressBar_SetCharProperty(GWEN_WIDGET *w, GWEN_UNUSED GWEN_DIALOG_PROPERTY prop, GWEN_UNUSED int index, GWEN_UNUSED const char *value, GWEN_UNUSED int doSignal)
static void GWENHYWFAR_CB Gtk2Gui_WProgressBar_FreeData(GWEN_UNUSED void *bp, void *p)
int Gtk2Gui_WProgressBar_Setup(GWEN_WIDGET *w)
#define GTK2_DIALOG_WIDGET_REAL
#define GTK2_DIALOG_WIDGET_CONTENT
#define GWEN_UNUSED
#define GWENHYWFAR_CB
#define GWEN_INHERIT_SETDATA(bt, t, element, data, fn)
Definition inherit.h:300
#define GWEN_INHERIT(bt, t)
Definition inherit.h:264
#define GWEN_INHERIT_GETDATA(bt, t, element)
Definition inherit.h:279
#define GWEN_LOGDOMAIN
Definition logger.h:32
#define GWEN_FREE_OBJECT(varname)
Definition memory.h:61
#define GWEN_NEW_OBJECT(typ, varname)
Definition memory.h:55
GWEN_WIDGET_GETCHARPROPERTY_FN GWEN_Widget_SetGetCharPropertyFn(GWEN_WIDGET *w, GWEN_WIDGET_GETCHARPROPERTY_FN fn)
Definition widget.c:740
GWEN_WIDGET_GETINTPROPERTY_FN GWEN_Widget_SetGetIntPropertyFn(GWEN_WIDGET *w, GWEN_WIDGET_GETINTPROPERTY_FN fn)
Definition widget.c:710
int GWEN_Widget_AddChildGuiWidget(GWEN_WIDGET *w, GWEN_WIDGET *wChild)
Definition widget.c:836
void GWEN_Widget_SetImplData(GWEN_WIDGET *w, int index, void *ptr)
Store a pointer with the widget.
Definition widget.c:136
void * GWEN_Widget_GetImplData(const GWEN_WIDGET *w, int index)
Definition widget.c:122
GWEN_WIDGET_SETINTPROPERTY_FN GWEN_Widget_SetSetIntPropertyFn(GWEN_WIDGET *w, GWEN_WIDGET_SETINTPROPERTY_FN fn)
Definition widget.c:695
const char * GWEN_Widget_Type_toString(GWEN_WIDGET_TYPE t)
Definition widget.c:456
GWEN_WIDGET_TYPE GWEN_Widget_GetType(const GWEN_WIDGET *w)
Definition widget.c:185
GWEN_WIDGET_SETCHARPROPERTY_FN GWEN_Widget_SetSetCharPropertyFn(GWEN_WIDGET *w, GWEN_WIDGET_SETCHARPROPERTY_FN fn)
Definition widget.c:725
struct GWEN_WIDGET GWEN_WIDGET
Definition widget_be.h:34