gwenhywfar  4.99.8beta
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  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, GTK3_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, GTK3_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 Gtk3Gui_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  GWEN_WIDGET *wParent;
213  W_PROGRESSBAR *xw;
214 
217 
218  wParent=GWEN_Widget_Tree_GetParent(w);
219 
220  g=gtk_progress_bar_new();
223 
228 
229  if (wParent)
230  GWEN_Widget_AddChildGuiWidget(wParent, w);
231 
232  return 0;
233 }
234 
235 
GWEN_WIDGET_TYPE GWEN_Widget_GetType(const GWEN_WIDGET *w)
Definition: widget.c:175
static GWENHYWFAR_CB const char * Gtk3Gui_WProgressBar_GetCharProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, const char *defaultValue)
static GWENHYWFAR_CB int Gtk3Gui_WProgressBar_SetIntProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, int value, int doSignal)
#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:663
GWEN_WIDGET_GETCHARPROPERTY_FN GWEN_Widget_SetGetCharPropertyFn(GWEN_WIDGET *w, GWEN_WIDGET_GETCHARPROPERTY_FN fn)
Definition: widget.c:677
static GWENHYWFAR_CB int Gtk3Gui_WProgressBar_GetIntProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, int defaultValue)
GWEN_DIALOG_PROPERTY
Definition: dialog.h:215
#define GWEN_FREE_OBJECT(varname)
Definition: memory.h:92
#define DBG_WARN(dbg_logger, format, args...)
Definition: debug.h:118
#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:131
GWEN_WIDGET_GETINTPROPERTY_FN GWEN_Widget_SetGetIntPropertyFn(GWEN_WIDGET *w, GWEN_WIDGET_GETINTPROPERTY_FN fn)
Definition: widget.c:649
#define GWEN_NEW_OBJECT(typ, varname)
Definition: memory.h:86
void * GWEN_Widget_GetImplData(const GWEN_WIDGET *w, int index)
Definition: widget.c:118
#define GWENHYWFAR_CB
Definition: gwenhywfarapi.h:89
GWEN_WIDGET_SETINTPROPERTY_FN GWEN_Widget_SetSetIntPropertyFn(GWEN_WIDGET *w, GWEN_WIDGET_SETINTPROPERTY_FN fn)
Definition: widget.c:635
struct GWEN_WIDGET GWEN_WIDGET
Definition: widget_be.h:34
int GWEN_Widget_AddChildGuiWidget(GWEN_WIDGET *w, GWEN_WIDGET *wChild)
Definition: widget.c:767
static void GWENHYWFAR_CB Gtk3Gui_WProgressBar_FreeData(void *bp, void *p)
static GWENHYWFAR_CB int Gtk3Gui_WProgressBar_SetCharProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, const char *value, int doSignal)
#define GWEN_INHERIT(bt, t)
Definition: inherit.h:264
const char * GWEN_Widget_Type_toString(GWEN_WIDGET_TYPE t)
Definition: widget.c:413
#define GWEN_INHERIT_SETDATA(bt, t, element, data, fn)
Definition: inherit.h:292
#define GWEN_INHERIT_GETDATA(bt, t, element)
Definition: inherit.h:271