gwenhywfar
4.3.1
|
00001 /*************************************************************************** 00002 begin : Wed Feb 17 2010 00003 copyright : (C) 2010 by Martin Preuss 00004 email : martin@libchipcard.de 00005 00006 *************************************************************************** 00007 * Please see toplevel file COPYING for license details * 00008 ***************************************************************************/ 00009 00010 00011 #ifdef HAVE_CONFIG_H 00012 # include <config.h> 00013 #endif 00014 00015 #define DISABLE_DEBUGLOG 00016 00017 00018 #include "dlg_message_p.h" 00019 00020 #include <gwenhywfar/gwenhywfar.h> 00021 #include <gwenhywfar/pathmanager.h> 00022 #include <gwenhywfar/gui.h> 00023 #include <gwenhywfar/debug.h> 00024 00025 00026 00027 00028 GWEN_INHERIT(GWEN_DIALOG, GWEN_DLGMSG) 00029 00030 00031 00032 00033 00034 GWEN_DIALOG *GWEN_DlgMessage_new(uint32_t flags, 00035 const char *title, 00036 const char *text, 00037 const char *b1, 00038 const char *b2, 00039 const char *b3) { 00040 GWEN_DIALOG *dlg; 00041 GWEN_DLGMSG *xdlg; 00042 GWEN_BUFFER *fbuf; 00043 int rv; 00044 int confirmButton; 00045 00046 dlg=GWEN_Dialog_new("dlg_gwen_message"); 00047 GWEN_NEW_OBJECT(GWEN_DLGMSG, xdlg); 00048 00049 GWEN_INHERIT_SETDATA(GWEN_DIALOG, GWEN_DLGMSG, dlg, xdlg, 00050 GWEN_DlgMessage_FreeData); 00051 00052 GWEN_Dialog_SetSignalHandler(dlg, GWEN_DlgMessage_SignalHandler); 00053 00054 /* get path of dialog description file */ 00055 fbuf=GWEN_Buffer_new(0, 256, 0, 1); 00056 rv=GWEN_PathManager_FindFile(GWEN_PM_LIBNAME, GWEN_PM_SYSDATADIR, 00057 "gwenhywfar/dialogs/dlg_message.dlg", 00058 fbuf); 00059 if (rv<0) { 00060 DBG_INFO(GWEN_LOGDOMAIN, "Dialog description file not found (%d).", rv); 00061 GWEN_Buffer_free(fbuf); 00062 GWEN_Dialog_free(dlg); 00063 return NULL; 00064 } 00065 00066 /* read dialog from dialog description file */ 00067 rv=GWEN_Dialog_ReadXmlFile(dlg, GWEN_Buffer_GetStart(fbuf)); 00068 if (rv<0) { 00069 DBG_INFO(GWEN_LOGDOMAIN, "here (%d).", rv); 00070 GWEN_Buffer_free(fbuf); 00071 GWEN_Dialog_free(dlg); 00072 return NULL; 00073 } 00074 GWEN_Buffer_free(fbuf); 00075 00076 confirmButton=GWEN_GUI_MSG_FLAGS_CONFIRM_BUTTON(flags); 00077 00078 00079 xdlg->flags=flags; 00080 if (title) 00081 xdlg->title=strdup(title); 00082 if (text) 00083 xdlg->text=strdup(text); 00084 00085 if (b1 && *b1) { 00086 GWEN_Dialog_SetWidgetText(dlg, "button1", b1); 00087 if (confirmButton==1) 00088 GWEN_Dialog_AddWidgetFlags(dlg, "button1", GWEN_WIDGET_FLAGS_DEFAULT_WIDGET); 00089 } 00090 else 00091 GWEN_Dialog_RemoveWidget(dlg, "button1"); 00092 00093 00094 if (b2 && *b2) { 00095 GWEN_Dialog_SetWidgetText(dlg, "button2", b2); 00096 if (confirmButton==2) 00097 GWEN_Dialog_AddWidgetFlags(dlg, "button2", GWEN_WIDGET_FLAGS_DEFAULT_WIDGET); 00098 } 00099 else 00100 GWEN_Dialog_RemoveWidget(dlg, "button2"); 00101 00102 if (b3 && *b3) { 00103 GWEN_Dialog_SetWidgetText(dlg, "button3", b3); 00104 if (confirmButton==3) 00105 GWEN_Dialog_AddWidgetFlags(dlg, "button3", GWEN_WIDGET_FLAGS_DEFAULT_WIDGET); 00106 } 00107 else 00108 GWEN_Dialog_RemoveWidget(dlg, "button3"); 00109 00110 return dlg; 00111 } 00112 00113 00114 00115 void GWENHYWFAR_CB GWEN_DlgMessage_FreeData(void *bp, void *p) { 00116 GWEN_DLGMSG *xdlg; 00117 00118 xdlg=(GWEN_DLGMSG*) p; 00119 00120 free(xdlg->title); 00121 free(xdlg->text); 00122 00123 GWEN_FREE_OBJECT(xdlg); 00124 } 00125 00126 00127 00128 int GWEN_DlgMessage_GetResponse(const GWEN_DIALOG *dlg) { 00129 GWEN_DLGMSG *xdlg; 00130 00131 assert(dlg); 00132 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGMSG, dlg); 00133 assert(xdlg); 00134 00135 return xdlg->response; 00136 } 00137 00138 00139 00140 void GWEN_DlgMessage_Init(GWEN_DIALOG *dlg) { 00141 GWEN_DLGMSG *xdlg; 00142 GWEN_DB_NODE *dbParams; 00143 00144 assert(dlg); 00145 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGMSG, dlg); 00146 assert(xdlg); 00147 00148 dbParams=GWEN_Dialog_GetPreferences(dlg); 00149 assert(dbParams); 00150 00151 #if 0 00152 /* read width */ 00153 i=GWEN_DB_GetIntValue(dbParams, "dialog_width", 0, -1); 00154 if (i>=DIALOG_MINWIDTH) 00155 GWEN_Dialog_SetIntProperty(dlg, "", GWEN_DialogProperty_Width, 0, i, 0); 00156 00157 /* read height */ 00158 i=GWEN_DB_GetIntValue(dbParams, "dialog_height", 0, -1); 00159 if (i>=DIALOG_MINHEIGHT) 00160 GWEN_Dialog_SetIntProperty(dlg, "", GWEN_DialogProperty_Height, 0, i, 0); 00161 #endif 00162 00163 /* special stuff */ 00164 if (xdlg->title) 00165 GWEN_Dialog_SetCharProperty(dlg, "", GWEN_DialogProperty_Title, 0, xdlg->title, 0); 00166 00167 if (xdlg->text) 00168 GWEN_Dialog_SetCharProperty(dlg, "descrLabel", GWEN_DialogProperty_Title, 0, xdlg->text, 0); 00169 00170 00171 xdlg->wasInit=1; 00172 } 00173 00174 00175 00176 void GWEN_DlgMessage_Fini(GWEN_DIALOG *dlg) { 00177 GWEN_DLGMSG *xdlg; 00178 GWEN_DB_NODE *dbParams; 00179 00180 assert(dlg); 00181 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGMSG, dlg); 00182 assert(xdlg); 00183 00184 dbParams=GWEN_Dialog_GetPreferences(dlg); 00185 assert(dbParams); 00186 00187 #if 0 00188 /* store dialog width */ 00189 i=GWEN_Dialog_GetIntProperty(dlg, "", GWEN_DialogProperty_Width, 0, -1); 00190 if (i<DIALOG_MINWIDTH) 00191 i=DIALOG_MINWIDTH; 00192 GWEN_DB_SetIntValue(dbParams, 00193 GWEN_DB_FLAGS_OVERWRITE_VARS, 00194 "dialog_width", 00195 i); 00196 00197 /* store dialog height */ 00198 i=GWEN_Dialog_GetIntProperty(dlg, "", GWEN_DialogProperty_Height, 0, -1); 00199 if (i<DIALOG_MINHEIGHT) 00200 i=DIALOG_MINHEIGHT; 00201 GWEN_DB_SetIntValue(dbParams, 00202 GWEN_DB_FLAGS_OVERWRITE_VARS, 00203 "dialog_height", 00204 i); 00205 #endif 00206 } 00207 00208 00209 00210 00211 int GWEN_DlgMessage_HandleActivated(GWEN_DIALOG *dlg, const char *sender) { 00212 GWEN_DLGMSG *xdlg; 00213 00214 assert(dlg); 00215 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGMSG, dlg); 00216 assert(xdlg); 00217 00218 if (strcasecmp(sender, "button1")==0) { 00219 xdlg->response=1; 00220 return GWEN_DialogEvent_ResultAccept; 00221 } 00222 else if (strcasecmp(sender, "button2")==0) { 00223 xdlg->response=2; 00224 return GWEN_DialogEvent_ResultAccept; 00225 } 00226 else if (strcasecmp(sender, "button3")==0) { 00227 xdlg->response=3; 00228 return GWEN_DialogEvent_ResultAccept; 00229 } 00230 00231 return GWEN_DialogEvent_ResultNotHandled; 00232 } 00233 00234 00235 00236 00237 int GWENHYWFAR_CB GWEN_DlgMessage_SignalHandler(GWEN_DIALOG *dlg, 00238 GWEN_DIALOG_EVENTTYPE t, 00239 const char *sender) { 00240 GWEN_DLGMSG *xdlg; 00241 00242 assert(dlg); 00243 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, GWEN_DLGMSG, dlg); 00244 assert(xdlg); 00245 00246 switch(t) { 00247 case GWEN_DialogEvent_TypeInit: 00248 GWEN_DlgMessage_Init(dlg); 00249 return GWEN_DialogEvent_ResultHandled;; 00250 00251 case GWEN_DialogEvent_TypeFini: 00252 GWEN_DlgMessage_Fini(dlg); 00253 return GWEN_DialogEvent_ResultHandled;; 00254 00255 case GWEN_DialogEvent_TypeActivated: 00256 return GWEN_DlgMessage_HandleActivated(dlg, sender); 00257 00258 case GWEN_DialogEvent_TypeValueChanged: 00259 case GWEN_DialogEvent_TypeEnabled: 00260 case GWEN_DialogEvent_TypeDisabled: 00261 00262 case GWEN_DialogEvent_TypeClose: 00263 return GWEN_DialogEvent_ResultAccept; 00264 00265 case GWEN_DialogEvent_TypeLast: 00266 return GWEN_DialogEvent_ResultNotHandled; 00267 } 00268 00269 return GWEN_DialogEvent_ResultNotHandled; 00270 00271 } 00272 00273 00274 00275