gwenhywfar 4.0.3
|
00001 /*************************************************************************** 00002 begin : Fri Jan 22 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 00015 #include "fox16_gui.hpp" 00016 #include "fox16_gui_dialog_l.hpp" 00017 #include "fox16_gui_updater_l.hpp" 00018 00019 #include <gwenhywfar/debug.h> 00020 00021 00022 00023 FOX16_Gui::WinScope::WinScope(uint32_t parentId, FXWindow *w) 00024 : m_parentId(parentId) 00025 , m_id(0) 00026 , m_window(w) 00027 , m_type(WIN_SCOPE_TYPE_WINDOW) { 00028 FOX16_Gui *gui=FOX16_Gui::getFgGui(); 00029 assert(gui); 00030 00031 if (m_parentId==0) 00032 m_parentId=gui->getIdOfLastScope(); 00033 m_id=gui->getNextId(); 00034 gui->addWinScope(this); 00035 } 00036 00037 00038 00039 FOX16_Gui::WinScope::WinScope(FXWindow *w) 00040 : m_parentId() 00041 , m_id(ID_MAINWINDOW) 00042 , m_window(w) 00043 , m_type(WIN_SCOPE_TYPE_WINDOW) { 00044 FOX16_Gui *gui=FOX16_Gui::getFgGui(); 00045 assert(gui); 00046 00047 gui->addWinScope(this); 00048 } 00049 00050 00051 00052 FOX16_Gui::WinScope::WinScope(FOX16_Gui::WinScope::WIN_SCOPE_TYPE t, uint32_t parentId, FXWindow *w) 00053 : m_parentId(parentId) 00054 , m_id(0) 00055 , m_window(w) 00056 , m_type(t) { 00057 FOX16_Gui *gui=FOX16_Gui::getFgGui(); 00058 assert(gui); 00059 00060 if (m_parentId==0) 00061 m_parentId=gui->getIdOfLastScope(); 00062 m_id=gui->getNextId(); 00063 gui->addWinScope(this); 00064 } 00065 00066 00067 00068 FOX16_Gui::WinScope::~WinScope() { 00069 FOX16_Gui *gui=FOX16_Gui::getFgGui(); 00070 assert(gui); 00071 gui->delWinScope(this); 00072 } 00073 00074 00075 00076 00077 00078 00079 FOX16_Gui::FOX16_Gui(FXApp *a) 00080 :CppGui() 00081 ,m_app(a) 00082 ,m_lastId(0) 00083 ,m_updater() 00084 ,m_fontList(NULL) 00085 { 00086 m_updater=new FOX16_GuiUpdater(); 00087 GWEN_Gui_AddFlags(_gui, GWEN_GUI_FLAGS_DIALOGSUPPORTED); 00088 GWEN_Gui_UseDialogs(_gui); 00089 GWEN_Gui_SetName(_gui, "fox16-gui"); 00090 m_fontList=HtmlFont_List_new(); 00091 } 00092 00093 00094 00095 FOX16_Gui::~FOX16_Gui() { 00096 if (!m_scopeList.empty()) { 00097 DBG_ERROR(GWEN_LOGDOMAIN, "ScopeList is not empty!"); 00098 } 00099 00100 if (m_updater) 00101 delete m_updater; 00102 HtmlFont_List_free(m_fontList); 00103 } 00104 00105 00106 00107 uint32_t FOX16_Gui::getNextId() { 00108 return ++m_lastId; 00109 } 00110 00111 00112 00113 uint32_t FOX16_Gui::getIdOfLastScope() { 00114 if (!m_scopeList.empty()) 00115 return m_scopeList.back()->getId(); 00116 00117 return 0; 00118 } 00119 00120 00121 00122 void FOX16_Gui::addWinScope(WinScope *ws) { 00123 m_scopeList.push_back(ws); 00124 } 00125 00126 00127 00128 void FOX16_Gui::delWinScope(WinScope *ws) { 00129 m_scopeList.remove(ws); 00130 } 00131 00132 00133 00134 FOX16_Gui::WinScope *FOX16_Gui::findWinScope(uint32_t id) { 00135 WinScopePtrList::iterator it; 00136 00137 for (it=m_scopeList.begin(); 00138 it!=m_scopeList.end(); 00139 it++) { 00140 if ((*it)->getId()==id) 00141 return (*it); 00142 } 00143 00144 return NULL; 00145 } 00146 00147 00148 00149 FXWindow *FOX16_Gui::getGuiWindow(uint32_t id) { 00150 return m_app->getActiveWindow(); 00151 } 00152 00153 00154 00155 00156 FOX16_Gui *FOX16_Gui::getFgGui() { 00157 CppGui *cppgui; 00158 00159 cppgui=CppGui::getCppGui(); 00160 if (cppgui) 00161 return dynamic_cast<FOX16_Gui*>(cppgui); 00162 else 00163 return NULL; 00164 } 00165 00166 00167 00168 void FOX16_Gui::dumpScopeList() { 00169 WinScopePtrList::iterator it; 00170 00171 for (it=m_scopeList.begin(); 00172 it!=m_scopeList.end(); 00173 it++) { 00174 const char *s; 00175 00176 switch((*it)->getType()) { 00177 case WinScope::WIN_SCOPE_TYPE_WINDOW: 00178 s="window"; 00179 break; 00180 default: 00181 s="unknown"; 00182 break; 00183 } 00184 fprintf(stderr, "WinScope: id %08x, parent %08x, type %s\n", 00185 (*it)->getId(), 00186 (*it)->getParentId(), 00187 s); 00188 } 00189 } 00190 00191 00192 00193 00194 int FOX16_Gui::print(const char *docTitle, 00195 const char *docType, 00196 const char *descr, 00197 const char *text, 00198 uint32_t guiid) { 00199 return GWEN_ERROR_NOT_IMPLEMENTED; 00200 } 00201 00202 00203 00204 FXString FOX16_Gui::getRawText(const char *text) { 00205 const char *p=0; 00206 const char *p2=0; 00207 00208 if (text==NULL) 00209 return FXString(""); 00210 00211 /* find begin of HTML area */ 00212 p=text; 00213 while ((p=strchr(p, '<'))) { 00214 const char *t; 00215 00216 t=p; 00217 t++; 00218 if (toupper(*t)=='H') { 00219 t++; 00220 if (toupper(*t)=='T') { 00221 t++; 00222 if (toupper(*t)=='M') { 00223 t++; 00224 if (toupper(*t)=='L') { 00225 t++; 00226 if (toupper(*t)=='>') { 00227 break; 00228 } 00229 } 00230 } 00231 } 00232 } 00233 p++; 00234 } /* while */ 00235 00236 /* find end of HTML area */ 00237 if (p) { 00238 p2=p; 00239 p2+=6; /* skip "<html>" */ 00240 while ((p2=strchr(p2, '<'))) { 00241 const char *t; 00242 00243 t=p2; 00244 t++; 00245 if (toupper(*t)=='/') { 00246 t++; 00247 if (toupper(*t)=='H') { 00248 t++; 00249 if (toupper(*t)=='T') { 00250 t++; 00251 if (toupper(*t)=='M') { 00252 t++; 00253 if (toupper(*t)=='L') { 00254 t++; 00255 if (toupper(*t)=='>') { 00256 break; 00257 } 00258 } 00259 } 00260 } 00261 } 00262 } 00263 p2++; 00264 } /* while */ 00265 } 00266 00267 if (p && p2) { 00268 p2+=7; /* skip "</html>" */ 00269 00270 int startPos=(p-text); 00271 int endPos=(p2-text); 00272 FXString result; 00273 00274 result=FXString(text); 00275 result.erase(startPos, endPos); 00276 return result; 00277 } 00278 else 00279 return FXString(text); 00280 } 00281 00282 00283 00284 FXString FOX16_Gui::getHtmlText(const char *text) { 00285 const char *p=0; 00286 const char *p2=0; 00287 00288 if (text==NULL) 00289 return FXString(""); 00290 00291 /* find begin of HTML area */ 00292 p=text; 00293 while ((p=strchr(p, '<'))) { 00294 const char *t; 00295 00296 t=p; 00297 t++; 00298 if (toupper(*t)=='H') { 00299 t++; 00300 if (toupper(*t)=='T') { 00301 t++; 00302 if (toupper(*t)=='M') { 00303 t++; 00304 if (toupper(*t)=='L') { 00305 t++; 00306 if (toupper(*t)=='>') { 00307 break; 00308 } 00309 } 00310 } 00311 } 00312 } 00313 p++; 00314 } /* while */ 00315 00316 /* find end of HTML area */ 00317 if (p) { 00318 p+=6; /* skip "<html>" */ 00319 p2=p; 00320 while ((p2=strchr(p2, '<'))) { 00321 const char *t; 00322 00323 t=p2; 00324 t++; 00325 if (toupper(*t)=='/') { 00326 t++; 00327 if (toupper(*t)=='H') { 00328 t++; 00329 if (toupper(*t)=='T') { 00330 t++; 00331 if (toupper(*t)=='M') { 00332 t++; 00333 if (toupper(*t)=='L') { 00334 t++; 00335 if (toupper(*t)=='>') { 00336 break; 00337 } 00338 } 00339 } 00340 } 00341 } 00342 } 00343 p2++; 00344 } /* while */ 00345 } 00346 00347 if (p && p2) 00348 return FXString(p, p2-p); 00349 else 00350 return FXString(text); 00351 } 00352 00353 00354 00355 int FOX16_Gui::execDialog(GWEN_DIALOG *dlg, uint32_t guiid) { 00356 FOX16_GuiDialog foxDlg(this, dlg); 00357 FXWindow *owner; 00358 00359 /* get main window of parent dialog (if any) */ 00360 owner=m_app->getActiveWindow(); 00361 00362 /* setup widget tree for the dialog */ 00363 if (!(foxDlg.setup(owner))) { 00364 return GWEN_ERROR_GENERIC; 00365 } 00366 00367 return foxDlg.execute(); 00368 } 00369 00370 00371 00372 int FOX16_Gui::openDialog(GWEN_DIALOG *dlg, uint32_t guiid) { 00373 FOX16_GuiDialog *foxDlg; 00374 FXWindow *owner; 00375 00376 /* get main window of parent dialog (if any) */ 00377 owner=m_app->getActiveWindow(); 00378 00379 foxDlg=new FOX16_GuiDialog(this, dlg); 00380 00381 /* setup widget tree for the dialog */ 00382 if (!(foxDlg->setup(owner))) { 00383 delete foxDlg; 00384 return GWEN_ERROR_GENERIC; 00385 } 00386 00387 foxDlg->openDialog(); 00388 m_updater->guiUpdate(); 00389 00390 return 0; 00391 } 00392 00393 00394 00395 int FOX16_Gui::closeDialog(GWEN_DIALOG *dlg) { 00396 FOX16_GuiDialog *foxDlg; 00397 00398 foxDlg=FOX16_GuiDialog::getDialog(dlg); 00399 assert(foxDlg); 00400 00401 foxDlg->closeDialog(); 00402 delete foxDlg; 00403 m_updater->guiUpdate(); 00404 00405 return 0; 00406 } 00407 00408 00409 00410 int FOX16_Gui::runDialog(GWEN_DIALOG *dlg, int untilEnd) { 00411 FOX16_GuiDialog *foxDlg; 00412 00413 foxDlg=FOX16_GuiDialog::getDialog(dlg); 00414 assert(foxDlg); 00415 00416 if (untilEnd) 00417 return foxDlg->cont(); 00418 else { 00419 m_updater->guiUpdate(); 00420 return 0; 00421 } 00422 } 00423 00424 00425 00426 int FOX16_Gui::getFileName(const char *caption, 00427 GWEN_GUI_FILENAME_TYPE fnt, 00428 uint32_t flags, 00429 const char *patterns, 00430 GWEN_BUFFER *pathBuffer, 00431 uint32_t guiid) { 00432 FXString sCaption; 00433 FXString sPatterns; 00434 FXString sPath; 00435 FXString str; 00436 FXWindow *owner; 00437 00438 if (caption) 00439 sCaption=FXString(caption); 00440 00441 if (patterns) { 00442 const char *s1; 00443 const char *s2; 00444 00445 s1=patterns; 00446 while(s1 && *s1) { 00447 s2=strchr(s1, '\t'); 00448 if (s2) { 00449 str=FXString(s1, s2-s1); 00450 /* skip tab */ 00451 s2++; 00452 } 00453 else { 00454 str=FXString(s1); 00455 s2=NULL; 00456 } 00457 00458 if (str.contains('(')) { 00459 if (!sPatterns.empty()) 00460 sPatterns+='\n'; 00461 sPatterns+=str.before('('); 00462 str=str.after('('); 00463 sPatterns+='('; 00464 sPatterns+=str.substitute(';', ','); 00465 } 00466 else { 00467 if (!sPatterns.empty()) 00468 sPatterns+='\n'; 00469 sPatterns+=str.substitute(';', ','); 00470 } 00471 00472 s1=s2; 00473 } 00474 } 00475 00476 if (GWEN_Buffer_GetUsedBytes(pathBuffer)) 00477 sPath=FXString(GWEN_Buffer_GetStart(pathBuffer)); 00478 00479 owner=m_app->getModalWindow(); 00480 if (owner==NULL) { 00481 owner=m_app->getActiveWindow(); 00482 } 00483 if (owner==NULL) { 00484 owner=m_app->getRootWindow(); 00485 } 00486 if (owner==NULL) { 00487 DBG_ERROR(GWEN_LOGDOMAIN, "Could not determine owner window"); 00488 return GWEN_ERROR_INTERNAL; 00489 } 00490 00491 switch(fnt) { 00492 case GWEN_Gui_FileNameType_OpenFileName: 00493 str=FXFileDialog::getOpenFilename(owner, sCaption, sPath, sPatterns, 0); 00494 break; 00495 00496 case GWEN_Gui_FileNameType_SaveFileName: 00497 str=FXFileDialog::getSaveFilename(owner, sCaption, sPath, sPatterns, 0); 00498 break; 00499 00500 case GWEN_Gui_FileNameType_OpenDirectory: 00501 str=FXFileDialog::getOpenDirectory(owner, sCaption, sPath); 00502 break; 00503 } 00504 00505 if (str.empty()) { 00506 DBG_ERROR(GWEN_LOGDOMAIN, "Empty filename returned."); 00507 return GWEN_ERROR_ABORTED; 00508 } 00509 else { 00510 GWEN_Buffer_Reset(pathBuffer); 00511 GWEN_Buffer_AppendString(pathBuffer, str.text()); 00512 return 0; 00513 } 00514 } 00515 00516 00517 00518 HTML_FONT *FOX16_Gui::findFont(const char *fontName, 00519 int fontSize, 00520 uint32_t fontFlags) { 00521 HTML_FONT *fnt; 00522 00523 assert(m_fontList); 00524 fnt=HtmlFont_List_First(m_fontList); 00525 while(fnt) { 00526 const char *s; 00527 00528 s=HtmlFont_GetFontName(fnt); 00529 if (s && *s && 00530 HtmlFont_GetFontSize(fnt)==fontSize && 00531 HtmlFont_GetFontFlags(fnt)==fontFlags && 00532 strcasecmp(s, fontName)==0) 00533 break; 00534 fnt=HtmlFont_List_Next(fnt); 00535 } 00536 00537 return fnt; 00538 } 00539 00540 00541 00542 HTML_FONT *FOX16_Gui::getFont(const char *fontName, 00543 int fontSize, 00544 uint32_t fontFlags) { 00545 HTML_FONT *fnt; 00546 00547 fnt=findFont(fontName, fontSize, fontFlags); 00548 if (fnt) 00549 return fnt; 00550 else { 00551 fnt=HtmlFont_new(); 00552 HtmlFont_SetFontName(fnt, fontName); 00553 HtmlFont_SetFontSize(fnt, fontSize); 00554 HtmlFont_SetFontFlags(fnt, fontFlags); 00555 HtmlFont_List_Add(fnt, m_fontList); 00556 return fnt; 00557 } 00558 } 00559 00560 00561 00562 00563