gwenhywfar  5.10.1
dlg_message.c
Go to the documentation of this file.
1 /***************************************************************************
2  begin : Wed Feb 17 2010
3  copyright : (C) 2019 by Martin Preuss
4  email : martin@libchipcard.de
5 
6  ***************************************************************************
7  * Please see toplevel file COPYING for license details *
8  ***************************************************************************/
9 
10 
11 #ifdef HAVE_CONFIG_H
12 # include <config.h>
13 #endif
14 
15 #define DISABLE_DEBUGLOG
16 
17 
18 #include "dlg_message_p.h"
19 
20 #include <gwenhywfar/gwenhywfar.h>
21 #include <gwenhywfar/pathmanager.h>
22 #include <gwenhywfar/gui.h>
23 #include <gwenhywfar/debug.h>
24 
25 
26 
27 
28 GWEN_INHERIT(GWEN_DIALOG, GWEN_DLGMSG)
29 
30 
31 
32 
33 
35  const char *title,
36  const char *text,
37  const char *b1,
38  const char *b2,
39  const char *b3)
40 {
41  GWEN_DIALOG *dlg;
42  GWEN_DLGMSG *xdlg;
43  int confirmButton;
44 
45  dlg=GWEN_Dialog_CreateAndLoadWithPath("dlg_gwen_message",
48  "gwenhywfar/dialogs/dlg_message.dlg");
49  if (dlg==NULL) {
50  DBG_INFO(GWEN_LOGDOMAIN, "here");
51  return NULL;
52  }
53  GWEN_NEW_OBJECT(GWEN_DLGMSG, xdlg);
54  GWEN_INHERIT_SETDATA(GWEN_DIALOG, GWEN_DLGMSG, dlg, xdlg,
57 
58 
59  confirmButton=GWEN_GUI_MSG_FLAGS_CONFIRM_BUTTON(flags);
60 
61 
62  xdlg->flags=flags;
63  if (title)
64  xdlg->title=strdup(title);
65  if (text)
66  xdlg->text=strdup(text);
67 
68  if (b1 && *b1) {
69  GWEN_Dialog_SetWidgetText(dlg, "button1", b1);
70  if (confirmButton==1)
72  }
73  else
74  GWEN_Dialog_RemoveWidget(dlg, "button1");
75 
76 
77  if (b2 && *b2) {
78  GWEN_Dialog_SetWidgetText(dlg, "button2", b2);
79  if (confirmButton==2)
81  }
82  else
83  GWEN_Dialog_RemoveWidget(dlg, "button2");
84 
85  if (b3 && *b3) {
86  GWEN_Dialog_SetWidgetText(dlg, "button3", b3);
87  if (confirmButton==3)
89  }
90  else
91  GWEN_Dialog_RemoveWidget(dlg, "button3");
92 
93  return dlg;
94 }
95 
96 
97 
99 {
100  GWEN_DLGMSG *xdlg;
101 
102  xdlg=(GWEN_DLGMSG *) p;
103 
104  free(xdlg->title);
105  free(xdlg->text);
106 
107  GWEN_FREE_OBJECT(xdlg);
108 }
109 
110 
111 
113 {
114  GWEN_DLGMSG *xdlg;
115 
116  assert(dlg);
117  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGMSG, dlg);
118  assert(xdlg);
119 
120  return xdlg->response;
121 }
122 
123 
124 
126 {
127  GWEN_DLGMSG *xdlg;
128  GWEN_DB_NODE *dbParams;
129 
130  assert(dlg);
131  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGMSG, dlg);
132  assert(xdlg);
133 
134  dbParams=GWEN_Dialog_GetPreferences(dlg);
135  assert(dbParams);
136 
137 #if 0
138  /* read width */
139  i=GWEN_DB_GetIntValue(dbParams, "dialog_width", 0, -1);
140  if (i>=DIALOG_MINWIDTH)
142 
143  /* read height */
144  i=GWEN_DB_GetIntValue(dbParams, "dialog_height", 0, -1);
145  if (i>=DIALOG_MINHEIGHT)
147 #endif
148 
149  /* special stuff */
150  if (xdlg->title)
151  GWEN_Dialog_SetCharProperty(dlg, "", GWEN_DialogProperty_Title, 0, xdlg->title, 0);
152 
153  if (xdlg->text)
154  GWEN_Dialog_SetCharProperty(dlg, "descrLabel", GWEN_DialogProperty_Title, 0, xdlg->text, 0);
155 
156 
157  xdlg->wasInit=1;
158 }
159 
160 
161 
163 {
164  GWEN_DLGMSG *xdlg;
165  GWEN_DB_NODE *dbParams;
166 
167  assert(dlg);
168  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGMSG, dlg);
169  assert(xdlg);
170 
171  dbParams=GWEN_Dialog_GetPreferences(dlg);
172  assert(dbParams);
173 
174 #if 0
175  /* store dialog width */
177  if (i<DIALOG_MINWIDTH)
178  i=DIALOG_MINWIDTH;
179  GWEN_DB_SetIntValue(dbParams,
181  "dialog_width",
182  i);
183 
184  /* store dialog height */
186  if (i<DIALOG_MINHEIGHT)
188  GWEN_DB_SetIntValue(dbParams,
190  "dialog_height",
191  i);
192 #endif
193 }
194 
195 
196 
197 
198 int GWEN_DlgMessage_HandleActivated(GWEN_DIALOG *dlg, const char *sender)
199 {
200  GWEN_DLGMSG *xdlg;
201 
202  assert(dlg);
203  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGMSG, dlg);
204  assert(xdlg);
205 
206  if (strcasecmp(sender, "button1")==0) {
207  xdlg->response=1;
209  }
210  else if (strcasecmp(sender, "button2")==0) {
211  xdlg->response=2;
213  }
214  else if (strcasecmp(sender, "button3")==0) {
215  xdlg->response=3;
217  }
218 
220 }
221 
222 
223 
224 
227  const char *sender)
228 {
229  GWEN_DLGMSG *xdlg;
230 
231  assert(dlg);
232  xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGMSG, dlg);
233  assert(xdlg);
234 
235  switch (t) {
239 
243 
245  return GWEN_DlgMessage_HandleActivated(dlg, sender);
246 
250 
253 
258  }
259 
261 
262 }
263 
264 
265 
266 
void GWEN_DlgMessage_Init(GWEN_DIALOG *dlg)
Definition: dlg_message.c:125
#define GWEN_DB_FLAGS_OVERWRITE_VARS
Definition: db.h:121
struct GWEN_DB_NODE GWEN_DB_NODE
Definition: db.h:228
#define GWEN_PM_SYSDATADIR
Definition: gwenhywfar.h:66
#define GWEN_FREE_OBJECT(varname)
Definition: memory.h:61
#define NULL
Definition: binreloc.c:300
int GWEN_Dialog_RemoveWidget(GWEN_DIALOG *dlg, const char *name)
Definition: dialog.c:821
void GWEN_Dialog_AddWidgetFlags(GWEN_DIALOG *dlg, const char *name, uint32_t fl)
Definition: dialog.c:862
GWEN_DIALOG_EVENTTYPE
Definition: dialog.h:98
int GWENHYWFAR_CB GWEN_DlgMessage_SignalHandler(GWEN_DIALOG *dlg, GWEN_DIALOG_EVENTTYPE t, const char *sender)
Definition: dlg_message.c:225
GWEN_DIALOG_SIGNALHANDLER GWEN_Dialog_SetSignalHandler(GWEN_DIALOG *dlg, GWEN_DIALOG_SIGNALHANDLER fn)
Definition: dialog.c:305
#define GWEN_LOGDOMAIN
Definition: logger.h:35
GWEN_DB_NODE * GWEN_Dialog_GetPreferences(const GWEN_DIALOG *dlg)
Definition: dialog.c:1002
struct GWEN_DIALOG GWEN_DIALOG
Definition: dialog.h:54
void GWEN_Dialog_SetWidgetText(GWEN_DIALOG *dlg, const char *name, const char *t)
Definition: dialog.c:938
#define GWEN_WIDGET_FLAGS_DEFAULT_WIDGET
Definition: dialog.h:65
#define GWEN_NEW_OBJECT(typ, varname)
Definition: memory.h:55
#define DIALOG_MINWIDTH
Definition: dlg_progress.c:27
#define GWEN_GUI_MSG_FLAGS_CONFIRM_BUTTON(fl)
Definition: gui.h:305
int GWEN_Dialog_GetIntProperty(GWEN_DIALOG *dlg, const char *name, GWEN_DIALOG_PROPERTY prop, int index, int defaultProperty)
Definition: dialog.c:733
#define GWENHYWFAR_CB
Definition: gwenhywfarapi.h:89
void GWENHYWFAR_CB GWEN_DlgMessage_FreeData(GWEN_UNUSED void *bp, void *p)
Definition: dlg_message.c:98
void GWEN_DlgMessage_Fini(GWEN_DIALOG *dlg)
Definition: dlg_message.c:162
int GWEN_DlgMessage_GetResponse(const GWEN_DIALOG *dlg)
Definition: dlg_message.c:112
GWEN_DIALOG * GWEN_DlgMessage_new(uint32_t flags, const char *title, const char *text, const char *b1, const char *b2, const char *b3)
Definition: dlg_message.c:34
int GWEN_DlgMessage_HandleActivated(GWEN_DIALOG *dlg, const char *sender)
Definition: dlg_message.c:198
int GWEN_Dialog_SetIntProperty(GWEN_DIALOG *dlg, const char *name, GWEN_DIALOG_PROPERTY prop, int index, int value, int doSignal)
Definition: dialog.c:703
int GWEN_Dialog_SetCharProperty(GWEN_DIALOG *dlg, const char *name, GWEN_DIALOG_PROPERTY prop, int index, const char *value, int doSignal)
Definition: dialog.c:762
#define DBG_INFO(dbg_logger, format, args...)
Definition: debug.h:181
#define GWEN_PM_LIBNAME
Definition: gwenhywfar.h:42
int GWEN_DB_GetIntValue(GWEN_DB_NODE *n, const char *path, int idx, int defVal)
Definition: db.c:1163
#define GWEN_INHERIT(bt, t)
Definition: inherit.h:264
int GWEN_DB_SetIntValue(GWEN_DB_NODE *n, uint32_t flags, const char *path, int val)
Definition: db.c:1202
#define GWEN_INHERIT_SETDATA(bt, t, element, data, fn)
Definition: inherit.h:292
GWEN_DIALOG * GWEN_Dialog_CreateAndLoadWithPath(const char *dialogId, const char *pmLibName, const char *pmDataDir, const char *fileName)
Definition: dialog.c:90
#define GWEN_UNUSED
#define GWEN_INHERIT_GETDATA(bt, t, element)
Definition: inherit.h:271
#define DIALOG_MINHEIGHT
Definition: dlg_progress.c:28