gwenhywfar  4.6.0beta
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 
13 struct W_PROGRESSBAR {
14  int minValue;
15  int maxValue;
16  int currentValue;
17 };
18 
19 
21 
22 
23 
24 static GWENHYWFAR_CB
27  int index,
28  int value,
29  int doSignal) {
30  GtkProgressBar *g;
31  W_PROGRESSBAR *xw;
32 
33  assert(w);
35  assert(xw);
36 
37  g=GTK_PROGRESS_BAR(GWEN_Widget_GetImplData(w, GTK2_DIALOG_WIDGET_REAL));
38  assert(g);
39 
40  switch(prop) {
42  gtk_widget_set_sensitive(GTK_WIDGET(g), (value==0)?FALSE:TRUE);
43  return 0;
44 
46  gtk_widget_grab_focus(GTK_WIDGET(g));
47  return 0;
48 
51  /* just ignore these for now */
52  return 0;
53 
55 
56  xw->currentValue=value;
57  if (xw->maxValue) {
58  gdouble d;
59  char numbuf[32];
60 
61  d=(gdouble)(xw->currentValue-xw->minValue)/(gdouble)(xw->maxValue);
62  gtk_progress_bar_set_fraction(g, d);
63  snprintf(numbuf, sizeof(numbuf)-1, "%d %%", (int)(d*100.0));
64  numbuf[sizeof(numbuf)-1]=0;
65  gtk_progress_bar_set_text(g, numbuf);
66  }
67  else {
68  gtk_progress_bar_set_fraction(g, 0.0);
69  gtk_progress_bar_set_text(g, "");
70  }
71  return 0;
72  }
73 
75  xw->minValue=value;
76  if (xw->maxValue) {
77  gdouble d;
78  char numbuf[32];
79 
80  d=(gdouble)(xw->currentValue-xw->minValue)/(gdouble)(xw->maxValue);
81  gtk_progress_bar_set_fraction(g, d);
82  snprintf(numbuf, sizeof(numbuf)-1, "%d %%", (int)(d*100.0));
83  numbuf[sizeof(numbuf)-1]=0;
84  gtk_progress_bar_set_text(g, numbuf);
85  }
86  else {
87  gtk_progress_bar_set_fraction(g, 0.0);
88  gtk_progress_bar_set_text(g, "");
89  }
90  return 0;
91  }
92 
94  xw->maxValue=value;
95  if (xw->maxValue) {
96  gdouble d;
97  char numbuf[32];
98 
99  d=(gdouble)(xw->currentValue-xw->minValue)/(gdouble)(xw->maxValue);
100  gtk_progress_bar_set_fraction(g, d);
101  snprintf(numbuf, sizeof(numbuf)-1, "%d %%", (int)(d*100.0));
102  numbuf[sizeof(numbuf)-1]=0;
103  gtk_progress_bar_set_text(g, numbuf);
104  return 0;
105  }
106  else {
107  gtk_progress_bar_set_fraction(g, 0.0);
108  gtk_progress_bar_set_text(g, "");
109  }
110  }
111 
112  default:
113  break;
114  }
115 
117  "Function is not appropriate for this type of widget (%s)",
119  return GWEN_ERROR_INVALID;
120 }
121 
122 
123 
124 
125 static GWENHYWFAR_CB
128  int index,
129  int defaultValue) {
130  GtkProgressBar *g;
131  W_PROGRESSBAR *xw;
132 
133  assert(w);
135  assert(xw);
136 
137  g=GTK_PROGRESS_BAR(GWEN_Widget_GetImplData(w, GTK2_DIALOG_WIDGET_REAL));
138  assert(g);
139 
140  switch(prop) {
142  return (gtk_widget_get_sensitive(GTK_WIDGET(g))==TRUE)?1:0;
143 
145  return (gtk_widget_has_focus(GTK_WIDGET(g))==TRUE)?1:0;
146  return 0;
147 
150  /* just ignore these for now */
151  return 0;
152 
154  return xw->currentValue;
155 
157  return xw->minValue;
158 
160  return xw->maxValue;
161 
162  default:
163  break;
164  }
165 
167  "Function is not appropriate for this type of widget (%s)",
169  return defaultValue;
170 }
171 
172 
173 
174 static GWENHYWFAR_CB
177  int index,
178  const char *value,
179  int doSignal) {
181  "Function is not appropriate for this type of widget (%s)",
183  return GWEN_ERROR_INVALID;
184 }
185 
186 
187 
188 static GWENHYWFAR_CB
191  int index,
192  const char *defaultValue) {
194  "Function is not appropriate for this type of widget (%s)",
196  return defaultValue;
197 }
198 
199 
200 
201 static void GWENHYWFAR_CB Gtk2Gui_WProgressBar_FreeData(void *bp, void *p) {
202  W_PROGRESSBAR *xw;
203 
204  xw=(W_PROGRESSBAR*) p;
205  GWEN_FREE_OBJECT(xw);
206 }
207 
208 
209 
211  GtkWidget *g;
212  const char *s;
213  uint32_t flags;
214  GWEN_WIDGET *wParent;
215  W_PROGRESSBAR *xw;
216 
219 
220  flags=GWEN_Widget_GetFlags(w);
221  wParent=GWEN_Widget_Tree_GetParent(w);
222  s=GWEN_Widget_GetText(w, 0);
223 
224  g=gtk_progress_bar_new();
227 
232 
233  if (wParent)
234  GWEN_Widget_AddChildGuiWidget(wParent, w);
235 
236  return 0;
237 }
238 
239