gwenhywfar  5.10.1
gtk3/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  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 
38  g=GTK_PROGRESS_BAR(GWEN_Widget_GetImplData(w, GTK3_DIALOG_WIDGET_REAL));
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 
126 static 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, GTK3_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 
176 static 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 
191 static 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;
210  GWEN_FREE_OBJECT(xw);
211 }
212 
213 
214 
216 {
217  GtkWidget *g;
218  GWEN_WIDGET *wParent;
219  W_PROGRESSBAR *xw;
220 
223 
224  wParent=GWEN_Widget_Tree_GetParent(w);
225 
226  g=gtk_progress_bar_new();
229 
234 
235  if (wParent)
236  GWEN_Widget_AddChildGuiWidget(wParent, w);
237 
238  return 0;
239 }
240 
241 
GWEN_WIDGET_TYPE GWEN_Widget_GetType(const GWEN_WIDGET *w)
Definition: widget.c:185
#define GWEN_ERROR_INVALID
Definition: error.h:67
#define GTK3_DIALOG_WIDGET_REAL
int Gtk3Gui_WProgressBar_Setup(GWEN_WIDGET *w)
#define GTK3_DIALOG_WIDGET_CONTENT
GWEN_WIDGET_SETCHARPROPERTY_FN GWEN_Widget_SetSetCharPropertyFn(GWEN_WIDGET *w, GWEN_WIDGET_SETCHARPROPERTY_FN fn)
Definition: widget.c:717
GWEN_WIDGET_GETCHARPROPERTY_FN GWEN_Widget_SetGetCharPropertyFn(GWEN_WIDGET *w, GWEN_WIDGET_GETCHARPROPERTY_FN fn)
Definition: widget.c:732
GWEN_DIALOG_PROPERTY
Definition: dialog.h:260
#define GWEN_FREE_OBJECT(varname)
Definition: memory.h:61
#define DBG_WARN(dbg_logger, format, args...)
Definition: debug.h:125
#define GWEN_LOGDOMAIN
Definition: logger.h:35
void GWEN_Widget_SetImplData(GWEN_WIDGET *w, int index, void *ptr)
Store a pointer with the widget.
Definition: widget.c:136
GWEN_WIDGET_GETINTPROPERTY_FN GWEN_Widget_SetGetIntPropertyFn(GWEN_WIDGET *w, GWEN_WIDGET_GETINTPROPERTY_FN fn)
Definition: widget.c:702
#define GWEN_NEW_OBJECT(typ, varname)
Definition: memory.h:55
void * GWEN_Widget_GetImplData(const GWEN_WIDGET *w, int index)
Definition: widget.c:122
#define GWENHYWFAR_CB
Definition: gwenhywfarapi.h:89
static void GWENHYWFAR_CB Gtk3Gui_WProgressBar_FreeData(GWEN_UNUSED void *bp, void *p)
GWEN_WIDGET_SETINTPROPERTY_FN GWEN_Widget_SetSetIntPropertyFn(GWEN_WIDGET *w, GWEN_WIDGET_SETINTPROPERTY_FN fn)
Definition: widget.c:687
static GWENHYWFAR_CB const char * Gtk3Gui_WProgressBar_GetCharProperty(GWEN_WIDGET *w, GWEN_UNUSED GWEN_DIALOG_PROPERTY prop, GWEN_UNUSED int index, const char *defaultValue)
static GWENHYWFAR_CB int Gtk3Gui_WProgressBar_SetCharProperty(GWEN_WIDGET *w, GWEN_UNUSED GWEN_DIALOG_PROPERTY prop, GWEN_UNUSED int index, GWEN_UNUSED const char *value, GWEN_UNUSED int doSignal)
struct GWEN_WIDGET GWEN_WIDGET
Definition: widget_be.h:34
int GWEN_Widget_AddChildGuiWidget(GWEN_WIDGET *w, GWEN_WIDGET *wChild)
Definition: widget.c:828
static GWENHYWFAR_CB int Gtk3Gui_WProgressBar_SetIntProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, GWEN_UNUSED int index, int value, GWEN_UNUSED int doSignal)
static GWENHYWFAR_CB int Gtk3Gui_WProgressBar_GetIntProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, GWEN_UNUSED int index, int defaultValue)
#define GWEN_INHERIT(bt, t)
Definition: inherit.h:264
const char * GWEN_Widget_Type_toString(GWEN_WIDGET_TYPE t)
Definition: widget.c:452
#define GWEN_INHERIT_SETDATA(bt, t, element, data, fn)
Definition: inherit.h:292
#define GWEN_UNUSED
#define GWEN_INHERIT_GETDATA(bt, t, element)
Definition: inherit.h:271