gwenhywfar
4.3.3
|
00001 /*************************************************************************** 00002 begin : Sun May 16 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 #ifdef HAVE_CONFIG_H 00011 # include <config.h> 00012 #endif 00013 00014 #include <gwenhywfar/gwenhywfar.h> 00015 #include <gwenhywfar/gui.h> 00016 #include <gwenhywfar/dialog.h> 00017 #include <gwenhywfar/debug.h> 00018 #include <gwenhywfar/pathmanager.h> 00019 00020 00021 #ifdef OS_WIN32 00022 # include <windows.h> 00023 # define sleep(x) Sleep(x) 00024 #endif 00025 00026 #include <unistd.h> 00027 00028 00029 00030 00031 00032 static int GWENHYWFAR_CB _gwenGuiSignalHandler(GWEN_DIALOG *dlg, 00033 GWEN_DIALOG_EVENTTYPE t, 00034 const char *sender) { 00035 fprintf(stderr, 00036 "Received event %d from widget [%s]\n", t, sender); 00037 00038 switch(t) { 00039 case GWEN_DialogEvent_TypeInit: 00040 fprintf(stderr, "Init\n"); 00041 GWEN_Dialog_SetCharProperty(dlg, "combo1", 00042 GWEN_DialogProperty_AddValue, 00043 0, 00044 "Erster Text in Combo1", 00045 0); 00046 GWEN_Dialog_SetCharProperty(dlg, "combo1", 00047 GWEN_DialogProperty_AddValue, 00048 0, 00049 "Zweiter Text in Combo1", 00050 0); 00051 GWEN_Dialog_SetIntProperty(dlg, "combo1", 00052 GWEN_DialogProperty_Value, 00053 0, 00054 0, 00055 0); 00056 00057 00058 GWEN_Dialog_SetCharProperty(dlg, "combo2", 00059 GWEN_DialogProperty_AddValue, 00060 0, 00061 "Erster Text in Combo2", 00062 0); 00063 GWEN_Dialog_SetCharProperty(dlg, "combo2", 00064 GWEN_DialogProperty_AddValue, 00065 0, 00066 "Zweiter Text in Combo2", 00067 0); 00068 GWEN_Dialog_SetIntProperty(dlg, "combo2", 00069 GWEN_DialogProperty_Value, 00070 0, 00071 0, 00072 0); 00073 00074 GWEN_Dialog_SetCharProperty(dlg, "listbox1", 00075 GWEN_DialogProperty_Title, 00076 0, 00077 "Column1\tColumn2\tColumn3", 00078 0); 00079 00080 GWEN_Dialog_SetCharProperty(dlg, "listbox1", 00081 GWEN_DialogProperty_AddValue, 00082 0, 00083 "Zeile 1 Spalte 1\tZeile 1 Spalte 2\tZeile 1 Spalte 3", 00084 0); 00085 GWEN_Dialog_SetCharProperty(dlg, "listbox1", 00086 GWEN_DialogProperty_AddValue, 00087 0, 00088 "Zeile 2 Spalte 1\tZeile 2 Spalte 2\tZeile 2 Spalte 3", 00089 0); 00090 GWEN_Dialog_SetIntProperty(dlg, "listbox1", 00091 GWEN_DialogProperty_ColumnWidth, 00092 0, 00093 100, 00094 0); 00095 GWEN_Dialog_SetIntProperty(dlg, "listbox1", 00096 GWEN_DialogProperty_ColumnWidth, 00097 1, 00098 200, 00099 0); 00100 00101 GWEN_Dialog_SetCharProperty(dlg, "labelWithHtmlImage", 00102 GWEN_DialogProperty_Title, 00103 0, 00104 "<html>This label contains text which should also contain an image:" 00105 "<img src=\"chipcard.png\">" 00106 "<p>And here the text should continue, followed by another image:" 00107 "<img src=\"disk.png\"></p>" 00108 "And again, this should be on the following line.</html>" 00109 "This label would contain an image if it were able to use " 00110 "HTML.", 00111 0); 00112 00113 GWEN_Dialog_SetCharProperty(dlg, "textBrowser1", 00114 GWEN_DialogProperty_Value, 00115 0, 00116 "<html>" 00117 "<p>This is <b>bold</b> text, while this one is <i>italic</i>.</p>" 00118 "This is a list:" 00119 "<ul>" 00120 "<li>first item</li>" 00121 "<li>second item</li>" 00122 "<li>third item</li>" 00123 "<li>fourth item</li>" 00124 "</ul>" 00125 "<p>This paragraph should follow the list.</p>" 00126 "</html>" 00127 "This is BOLD text, while this one is would be i t a l i c.\n" 00128 "This is a list:\n" 00129 "- first item\n" 00130 "- second item\n" 00131 "- third item\n" 00132 "- fourth item\n" 00133 "This paragraph should follow the list.", 00134 0); 00135 00136 GWEN_Dialog_SetIntProperty(dlg, "progressBar1", 00137 GWEN_DialogProperty_MinValue, 00138 0, 00139 0, 00140 0); 00141 GWEN_Dialog_SetIntProperty(dlg, "progressBar1", 00142 GWEN_DialogProperty_MaxValue, 00143 0, 00144 10, 00145 0); 00146 00147 00148 GWEN_Dialog_SetIntProperty(dlg, "", 00149 GWEN_DialogProperty_Width, 00150 0, 00151 640, 00152 0); 00153 GWEN_Dialog_SetIntProperty(dlg, "", 00154 GWEN_DialogProperty_Height, 00155 0, 00156 480, 00157 0); 00158 00159 break; 00160 00161 case GWEN_DialogEvent_TypeFini: 00162 fprintf(stderr, "Fini\n"); 00163 break; 00164 case GWEN_DialogEvent_TypeValueChanged: 00165 fprintf(stderr, "ValueChanged\n"); 00166 if (strcasecmp(sender, "listbox1")==0) { 00167 fprintf(stderr, "Selected list entry %d\n", 00168 GWEN_Dialog_GetIntProperty(dlg, "listbox1", GWEN_DialogProperty_Value, 0, -1)); 00169 } 00170 else if (strcasecmp(sender, "editPass1")==0) { 00171 const char *s; 00172 00173 s=GWEN_Dialog_GetCharProperty(dlg, "editPass1", GWEN_DialogProperty_Value, 0, NULL); 00174 if (!(s && *s)) 00175 s="<empty>"; 00176 GWEN_Dialog_SetCharProperty(dlg, "editPass2", GWEN_DialogProperty_Value, 0, s, 0); 00177 } 00178 break; 00179 00180 case GWEN_DialogEvent_TypeActivated: 00181 fprintf(stderr, "Activated\n"); 00182 if (strcasecmp(sender, "listbox1")==0) { 00183 int idx; 00184 00185 idx=GWEN_Dialog_GetIntProperty(dlg, "listbox1", GWEN_DialogProperty_Value, 0, -1); 00186 fprintf(stderr, "Selected list entry %d\n", idx); 00187 if (idx>=0) { 00188 const char *s; 00189 00190 s=GWEN_Dialog_GetCharProperty(dlg, "listbox1", GWEN_DialogProperty_Value, idx, NULL); 00191 if (s && *s) { 00192 fprintf(stderr, "Text of selected list entry %d: [%s]\n", idx, s); 00193 } 00194 } 00195 } 00196 else if (strcasecmp(sender, "combo1")==0) { 00197 int idx; 00198 00199 idx=GWEN_Dialog_GetIntProperty(dlg, "combo1", GWEN_DialogProperty_Value, 0, -1); 00200 fprintf(stderr, "Selected list entry %d\n", idx); 00201 if (idx>=0) { 00202 const char *s; 00203 00204 s=GWEN_Dialog_GetCharProperty(dlg, "combo1", GWEN_DialogProperty_Value, idx, NULL); 00205 if (s && *s) { 00206 fprintf(stderr, "Text of selected list entry %d: [%s]\n", idx, s); 00207 } 00208 } 00209 00210 } 00211 else if (strcasecmp(sender, "okButton")==0) 00212 return GWEN_DialogEvent_ResultAccept; 00213 else if (strcasecmp(sender, "abortButton")==0) 00214 return GWEN_DialogEvent_ResultReject; 00215 else if (strcasecmp(sender, "progressMinus")==0) { 00216 int v; 00217 00218 v=GWEN_Dialog_GetIntProperty(dlg, "progressBar1", GWEN_DialogProperty_Value, 0, -1); 00219 if (v>0) 00220 GWEN_Dialog_SetIntProperty(dlg, "progressBar1", GWEN_DialogProperty_Value, 0, v-1, 0); 00221 return GWEN_DialogEvent_ResultHandled; 00222 } 00223 else if (strcasecmp(sender, "progressPlus")==0) { 00224 int v; 00225 00226 v=GWEN_Dialog_GetIntProperty(dlg, "progressBar1", GWEN_DialogProperty_Value, 0, -1); 00227 if (v<10) 00228 GWEN_Dialog_SetIntProperty(dlg, "progressBar1", GWEN_DialogProperty_Value, 0, v+1, 0); 00229 return GWEN_DialogEvent_ResultHandled; 00230 } 00231 else if (strcasecmp(sender, "prevPageButton")==0) { 00232 int v; 00233 00234 v=GWEN_Dialog_GetIntProperty(dlg, "stack1", GWEN_DialogProperty_Value, 0, -1); 00235 if (v>0) 00236 GWEN_Dialog_SetIntProperty(dlg, "stack1", GWEN_DialogProperty_Value, 0, v-1, 0); 00237 return GWEN_DialogEvent_ResultHandled; 00238 } 00239 else if (strcasecmp(sender, "nextPageButton")==0) { 00240 int v; 00241 00242 v=GWEN_Dialog_GetIntProperty(dlg, "stack1", GWEN_DialogProperty_Value, 0, -1); 00243 if (v<3) 00244 GWEN_Dialog_SetIntProperty(dlg, "stack1", GWEN_DialogProperty_Value, 0, v+1, 0); 00245 return GWEN_DialogEvent_ResultHandled; 00246 } 00247 break; 00248 00249 case GWEN_DialogEvent_TypeEnabled: 00250 fprintf(stderr, "Enabled\n"); 00251 break; 00252 case GWEN_DialogEvent_TypeDisabled: 00253 fprintf(stderr, "Disabled\n"); 00254 break; 00255 case GWEN_DialogEvent_TypeClose: 00256 fprintf(stderr, "Close\n"); 00257 return GWEN_DialogEvent_ResultNotHandled; 00258 case GWEN_DialogEvent_TypeLast: 00259 fprintf(stderr, "Last, ignored\n"); 00260 return GWEN_DialogEvent_ResultNotHandled; 00261 } 00262 return GWEN_DialogEvent_ResultHandled; 00263 } 00264 00265 00266 00267 GWEN_DIALOG *Dlg_Test1_new() { 00268 GWEN_DIALOG *dlg; 00269 int rv; 00270 const char *s; 00271 GWEN_BUFFER *tbuf; 00272 00273 tbuf=GWEN_Buffer_new(0, 256, 0, 1); 00274 s=getenv("DIALOG_DIR"); 00275 if (s && *s) 00276 GWEN_Buffer_AppendString(tbuf, s); 00277 else 00278 GWEN_Buffer_AppendString(tbuf, MEDIAPATH); 00279 dlg=GWEN_Dialog_new("dlg_test"); 00280 GWEN_Dialog_SetSignalHandler(dlg, _gwenGuiSignalHandler); 00281 GWEN_Dialog_AddMediaPath(dlg, GWEN_Buffer_GetStart(tbuf)); 00282 00283 /* read dialog from dialog description file */ 00284 GWEN_Buffer_AppendString(tbuf, GWEN_DIR_SEPARATOR_S "dlg_test.dlg"); 00285 rv=GWEN_Dialog_ReadXmlFile(dlg, GWEN_Buffer_GetStart(tbuf)); 00286 GWEN_Buffer_free(tbuf); 00287 if (rv<0) { 00288 DBG_INFO(GWEN_LOGDOMAIN, "here (%d).", rv); 00289 GWEN_Dialog_free(dlg); 00290 return NULL; 00291 } 00292 00293 /* done */ 00294 return dlg; 00295 } 00296 00297 00298 00299 00300