gwenhywfar  5.10.1
fox16_gui.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  begin : Fri Jan 22 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 #ifdef HAVE_CONFIG_H
11 # include <config.h>
12 #endif
13 
14 
15 #include "fox16_gui.hpp"
16 #include "fox16_gui_dialog_l.hpp"
17 #include "fox16_gui_updater_l.hpp"
18 
19 #include <gwenhywfar/debug.h>
20 
21 
22 
23 FOX16_Gui::WinScope::WinScope(uint32_t parentId, FXWindow *w)
24  : m_parentId(parentId)
25  , m_id(0)
26  , m_window(w)
27  , m_type(WIN_SCOPE_TYPE_WINDOW) {
29  assert(gui);
30 
31  if (m_parentId==0)
33  m_id=gui->getNextId();
34  gui->addWinScope(this);
35 }
36 
37 
38 
40  : m_parentId()
41  , m_id(ID_MAINWINDOW)
42  , m_window(w)
43  , m_type(WIN_SCOPE_TYPE_WINDOW) {
45  assert(gui);
46 
47  gui->addWinScope(this);
48 }
49 
50 
51 
53  : m_parentId(parentId)
54  , m_id(0)
55  , m_window(w)
56  , m_type(t) {
58  assert(gui);
59 
60  if (m_parentId==0)
62  m_id=gui->getNextId();
63  gui->addWinScope(this);
64 }
65 
66 
67 
70  assert(gui);
71  gui->delWinScope(this);
72 }
73 
74 
75 
76 
77 
78 
80  :CppGui()
81  ,m_app(a)
82  ,m_lastId(0)
83  ,m_updater()
84  ,m_fontList(NULL) {
88  GWEN_Gui_SetName(_gui, "fox16-gui");
90 }
91 
92 
93 
95  if (!m_scopeList.empty()) {
96  DBG_ERROR(GWEN_LOGDOMAIN, "ScopeList is not empty!");
97  }
98 
99  if (m_updater)
100  delete m_updater;
102 }
103 
104 
105 
107  return ++m_lastId;
108 }
109 
110 
111 
113  if (!m_scopeList.empty())
114  return m_scopeList.back()->getId();
115 
116  return 0;
117 }
118 
119 
120 
122  m_scopeList.push_back(ws);
123 }
124 
125 
126 
128  m_scopeList.remove(ws);
129 }
130 
131 
132 
134  WinScopePtrList::iterator it;
135 
136  for (it=m_scopeList.begin();
137  it!=m_scopeList.end();
138  it++) {
139  if ((*it)->getId()==id)
140  return (*it);
141  }
142 
143  return NULL;
144 }
145 
146 
147 
148 FXWindow *FOX16_Gui::getGuiWindow(uint32_t id) {
149  return m_app->getActiveWindow();
150 }
151 
152 
153 
154 
156  CppGui *cppgui;
157 
158  cppgui=CppGui::getCppGui();
159  if (cppgui)
160  return dynamic_cast<FOX16_Gui*>(cppgui);
161  else
162  return NULL;
163 }
164 
165 
166 
168  WinScopePtrList::iterator it;
169 
170  for (it=m_scopeList.begin();
171  it!=m_scopeList.end();
172  it++) {
173  const char *s;
174 
175  switch((*it)->getType()) {
177  s="window";
178  break;
179  default:
180  s="unknown";
181  break;
182  }
183  fprintf(stderr, "WinScope: id %08x, parent %08x, type %s\n",
184  (*it)->getId(),
185  (*it)->getParentId(),
186  s);
187  }
188 }
189 
190 
191 
192 
193 int FOX16_Gui::print(const char *docTitle,
194  const char *docType,
195  const char *descr,
196  const char *text,
197  uint32_t guiid) {
198  DBG_ERROR(GWEN_LOGDOMAIN, "Not implemented");
200 }
201 
202 
203 
204 FXString FOX16_Gui::getRawText(const char *text) {
205  const char *p=0;
206  const char *p2=0;
207 
208  if (text==NULL)
209  return FXString("");
210 
211  /* find begin of HTML area */
212  p=text;
213  while ((p=strchr(p, '<'))) {
214  const char *t;
215 
216  t=p;
217  t++;
218  if (toupper(*t)=='H') {
219  t++;
220  if (toupper(*t)=='T') {
221  t++;
222  if (toupper(*t)=='M') {
223  t++;
224  if (toupper(*t)=='L') {
225  t++;
226  if (toupper(*t)=='>') {
227  break;
228  }
229  }
230  }
231  }
232  }
233  p++;
234  } /* while */
235 
236  /* find end of HTML area */
237  if (p) {
238  p2=p;
239  p2+=6; /* skip "<html>" */
240  while ((p2=strchr(p2, '<'))) {
241  const char *t;
242 
243  t=p2;
244  t++;
245  if (toupper(*t)=='/') {
246  t++;
247  if (toupper(*t)=='H') {
248  t++;
249  if (toupper(*t)=='T') {
250  t++;
251  if (toupper(*t)=='M') {
252  t++;
253  if (toupper(*t)=='L') {
254  t++;
255  if (toupper(*t)=='>') {
256  break;
257  }
258  }
259  }
260  }
261  }
262  }
263  p2++;
264  } /* while */
265  }
266 
267  if (p && p2) {
268  p2+=7; /* skip "</html>" */
269 
270  int startPos=(p-text);
271  int endPos=(p2-text);
272  FXString result;
273 
274  result=FXString(text);
275  result.erase(startPos, endPos);
276  return result;
277  }
278  else
279  return FXString(text);
280 }
281 
282 
283 
284 FXString FOX16_Gui::getHtmlText(const char *text) {
285  const char *p=0;
286  const char *p2=0;
287 
288  if (text==NULL)
289  return FXString("");
290 
291  /* find begin of HTML area */
292  p=text;
293  while ((p=strchr(p, '<'))) {
294  const char *t;
295 
296  t=p;
297  t++;
298  if (toupper(*t)=='H') {
299  t++;
300  if (toupper(*t)=='T') {
301  t++;
302  if (toupper(*t)=='M') {
303  t++;
304  if (toupper(*t)=='L') {
305  t++;
306  if (toupper(*t)=='>') {
307  break;
308  }
309  }
310  }
311  }
312  }
313  p++;
314  } /* while */
315 
316  /* find end of HTML area */
317  if (p) {
318  p+=6; /* skip "<html>" */
319  p2=p;
320  while ((p2=strchr(p2, '<'))) {
321  const char *t;
322 
323  t=p2;
324  t++;
325  if (toupper(*t)=='/') {
326  t++;
327  if (toupper(*t)=='H') {
328  t++;
329  if (toupper(*t)=='T') {
330  t++;
331  if (toupper(*t)=='M') {
332  t++;
333  if (toupper(*t)=='L') {
334  t++;
335  if (toupper(*t)=='>') {
336  break;
337  }
338  }
339  }
340  }
341  }
342  }
343  p2++;
344  } /* while */
345  }
346 
347  if (p && p2)
348  return FXString(p, p2-p);
349  else
350  return FXString(text);
351 }
352 
353 
354 
355 int FOX16_Gui::execDialog(GWEN_DIALOG *dlg, uint32_t guiid) {
356  FOX16_GuiDialog foxDlg(this, dlg);
357  FXWindow *owner;
358 
359  /* get main window of parent dialog (if any) */
360  owner=m_app->getActiveWindow();
361 
362  /* setup widget tree for the dialog */
363  if (!(foxDlg.setup(owner))) {
364  return GWEN_ERROR_GENERIC;
365  }
366 
367  return foxDlg.execute();
368 }
369 
370 
371 
372 int FOX16_Gui::openDialog(GWEN_DIALOG *dlg, uint32_t guiid) {
373  FOX16_GuiDialog *foxDlg;
374  FXWindow *owner;
375 
376  /* get main window of parent dialog (if any) */
377  owner=m_app->getActiveWindow();
378 
379  foxDlg=new FOX16_GuiDialog(this, dlg);
380 
381  /* setup widget tree for the dialog */
382  if (!(foxDlg->setup(owner))) {
383  delete foxDlg;
384  return GWEN_ERROR_GENERIC;
385  }
386 
387  foxDlg->openDialog();
388  m_updater->guiUpdate();
389 
390  return 0;
391 }
392 
393 
394 
396  FOX16_GuiDialog *foxDlg;
397 
398  foxDlg=FOX16_GuiDialog::getDialog(dlg);
399  assert(foxDlg);
400 
401  foxDlg->closeDialog();
402  delete foxDlg;
403  m_updater->guiUpdate();
404 
405  return 0;
406 }
407 
408 
409 
410 int FOX16_Gui::runDialog(GWEN_DIALOG *dlg, int untilEnd) {
411  FOX16_GuiDialog *foxDlg;
412 
413  foxDlg=FOX16_GuiDialog::getDialog(dlg);
414  assert(foxDlg);
415 
416  if (untilEnd)
417  return foxDlg->cont();
418  else {
419  m_updater->guiUpdate();
420  return 0;
421  }
422 }
423 
424 
425 
426 int FOX16_Gui::getFileName(const char *caption,
428  uint32_t flags,
429  const char *patterns,
430  GWEN_BUFFER *pathBuffer,
431  uint32_t guiid) {
432  FXString sCaption;
433  FXString sPatterns;
434  FXString sPath;
435  FXString str;
436  FXWindow *owner;
437 
438  if (caption)
439  sCaption=FXString(caption);
440 
441  if (patterns) {
442  const char *s1;
443  const char *s2;
444 
445  s1=patterns;
446  while(s1 && *s1) {
447  s2=strchr(s1, '\t');
448  if (s2) {
449  str=FXString(s1, s2-s1);
450  /* skip tab */
451  s2++;
452  }
453  else {
454  str=FXString(s1);
455  s2=NULL;
456  }
457 
458  if (str.contains('(')) {
459  if (!sPatterns.empty())
460  sPatterns+='\n';
461  sPatterns+=str.before('(');
462  str=str.after('(');
463  sPatterns+='(';
464  sPatterns+=str.substitute(';', ',');
465  }
466  else {
467  if (!sPatterns.empty())
468  sPatterns+='\n';
469  sPatterns+=str.substitute(';', ',');
470  }
471 
472  s1=s2;
473  }
474  }
475 
476  if (GWEN_Buffer_GetUsedBytes(pathBuffer))
477  sPath=FXString(GWEN_Buffer_GetStart(pathBuffer));
478 
479  owner=m_app->getModalWindow();
480  if (owner==NULL) {
481  owner=m_app->getActiveWindow();
482  }
483  if (owner==NULL) {
484  owner=m_app->getRootWindow();
485  }
486  if (owner==NULL) {
487  DBG_ERROR(GWEN_LOGDOMAIN, "Could not determine owner window");
488  return GWEN_ERROR_INTERNAL;
489  }
490 
491  switch(fnt) {
493  str=FXFileDialog::getOpenFilename(owner, sCaption, sPath, sPatterns, 0);
494  break;
495 
497  str=FXFileDialog::getSaveFilename(owner, sCaption, sPath, sPatterns, 0);
498  break;
499 
501  str=FXFileDialog::getOpenDirectory(owner, sCaption, sPath);
502  break;
503  }
504 
505  if (str.empty()) {
506  DBG_ERROR(GWEN_LOGDOMAIN, "Empty filename returned.");
507  return GWEN_ERROR_ABORTED;
508  }
509  else {
510  GWEN_Buffer_Reset(pathBuffer);
511  GWEN_Buffer_AppendString(pathBuffer, str.text());
512  return 0;
513  }
514 }
515 
516 
517 
518 HTML_FONT *FOX16_Gui::findFont(const char *fontName,
519  int fontSize,
520  uint32_t fontFlags) {
521  HTML_FONT *fnt;
522 
523  assert(m_fontList);
525  while(fnt) {
526  const char *s;
527 
528  s=HtmlFont_GetFontName(fnt);
529  if (s && *s &&
530  HtmlFont_GetFontSize(fnt)==fontSize &&
531  HtmlFont_GetFontFlags(fnt)==fontFlags &&
532  strcasecmp(s, fontName)==0)
533  break;
534  fnt=HtmlFont_List_Next(fnt);
535  }
536 
537  return fnt;
538 }
539 
540 
541 
542 HTML_FONT *FOX16_Gui::getFont(const char *fontName,
543  int fontSize,
544  uint32_t fontFlags) {
545  HTML_FONT *fnt;
546 
547  fnt=findFont(fontName, fontSize, fontFlags);
548  if (fnt)
549  return fnt;
550  else {
551  fnt=HtmlFont_new();
552  HtmlFont_SetFontName(fnt, fontName);
553  HtmlFont_SetFontSize(fnt, fontSize);
554  HtmlFont_SetFontFlags(fnt, fontFlags);
556  return fnt;
557  }
558 }
559 
560 
561 
562 
563 
const char * HtmlFont_GetFontName(const HTML_FONT *fnt)
Definition: htmlfont.c:67
int HtmlFont_GetFontSize(const HTML_FONT *fnt)
Definition: htmlfont.c:89
char * GWEN_Buffer_GetStart(const GWEN_BUFFER *bf)
Definition: buffer.c:235
void HtmlFont_SetFontSize(HTML_FONT *fnt, int i)
Definition: htmlfont.c:98
uint32_t GWEN_Buffer_GetUsedBytes(const GWEN_BUFFER *bf)
Definition: buffer.c:277
static FOX16_GuiDialog * getDialog(GWEN_DIALOG *dlg)
void HtmlFont_List_free(HTML_FONT_LIST *l)
WinScope * findWinScope(uint32_t id)
Definition: fox16_gui.cpp:133
#define NULL
Definition: binreloc.c:300
void GWEN_Gui_AddFlags(GWEN_GUI *gui, uint32_t fl)
Definition: gui.c:211
FXWindow * getGuiWindow(uint32_t id)
Definition: fox16_gui.cpp:148
#define GWEN_LOGDOMAIN
Definition: logger.h:35
HTML_FONT * HtmlFont_new(void)
Definition: htmlfont.c:25
int execDialog(GWEN_DIALOG *dlg, uint32_t guiid)
Definition: fox16_gui.cpp:355
struct GWEN_DIALOG GWEN_DIALOG
Definition: dialog.h:54
void GWEN_Buffer_Reset(GWEN_BUFFER *bf)
Definition: buffer.c:650
void HtmlFont_List_Add(HTML_FONT *element, HTML_FONT_LIST *list)
WinScopePtrList m_scopeList
Definition: fox16_gui.hpp:124
GWENHYWFAR_API void GWEN_Gui_UseDialogs(GWEN_GUI *gui)
Definition: gui_dialogs.c:29
void addWinScope(WinScope *ws)
Definition: fox16_gui.cpp:121
virtual int openDialog(GWEN_DIALOG *dlg, uint32_t guiid)
Definition: fox16_gui.cpp:372
void dumpScopeList()
Definition: fox16_gui.cpp:167
GWEN_GUI_FILENAME_TYPE
Definition: gui.h:949
static FOX16GUI_API FOX16_Gui * getFgGui()
Definition: fox16_gui.cpp:155
static CPPGUI_API CppGui * getCppGui()
Definition: cppgui.cpp:379
uint32_t getIdOfLastScope()
Definition: fox16_gui.cpp:112
#define GWEN_ERROR_ABORTED
Definition: error.h:63
A C++ binding for the C module GWEN_GUI.
Definition: cppgui.hpp:39
struct HTML_FONT HTML_FONT
Definition: htmlfont_be.h:23
FOX16_GuiUpdater * m_updater
Definition: fox16_gui.hpp:127
HTML_FONT_LIST * HtmlFont_List_new()
#define GWEN_ERROR_GENERIC
Definition: error.h:62
#define GWEN_GUI_FLAGS_DIALOGSUPPORTED
Definition: gui.h:1001
bool setup(FXWindow *parentWindow)
HTML_FONT * findFont(const char *fontName, int fontSize, uint32_t fontFlags)
Definition: fox16_gui.cpp:518
int print(const char *docTitle, const char *docType, const char *descr, const char *text, uint32_t guiid)
Definition: fox16_gui.cpp:193
struct GWEN_BUFFER GWEN_BUFFER
A dynamically resizeable text buffer.
Definition: buffer.h:38
void delWinScope(WinScope *ws)
Definition: fox16_gui.cpp:127
WinScope(uint32_t parentId, FXWindow *w)
Definition: fox16_gui.cpp:23
static FOX16GUI_API FXString getRawText(const char *text)
Definition: fox16_gui.cpp:204
int getFileName(const char *caption, GWEN_GUI_FILENAME_TYPE fnt, uint32_t flags, const char *patterns, GWEN_BUFFER *pathBuffer, uint32_t guiid)
Definition: fox16_gui.cpp:426
uint32_t m_lastId
Definition: fox16_gui.hpp:125
#define DBG_ERROR(dbg_logger, format, args...)
Definition: debug.h:97
HTML_FONT * HtmlFont_List_First(const HTML_FONT_LIST *l)
virtual int runDialog(GWEN_DIALOG *dlg, int untilEnd)
Definition: fox16_gui.cpp:410
HTML_FONT * getFont(const char *fontName, int fontSize, uint32_t fontFlags)
Definition: fox16_gui.cpp:542
FOX16_Gui(FXApp *a)
Definition: fox16_gui.cpp:79
HTML_FONT * HtmlFont_List_Next(const HTML_FONT *element)
#define GWEN_ERROR_INTERNAL
Definition: error.h:125
void GWEN_Gui_SetName(GWEN_GUI *gui, const char *name)
Definition: gui.c:227
void HtmlFont_SetFontFlags(HTML_FONT *fnt, uint32_t i)
Definition: htmlfont.c:116
uint32_t getNextId()
Definition: fox16_gui.cpp:106
void HtmlFont_SetFontName(HTML_FONT *fnt, const char *s)
Definition: htmlfont.c:76
virtual int closeDialog(GWEN_DIALOG *dlg)
Definition: fox16_gui.cpp:395
static FOX16GUI_API FXString getHtmlText(const char *text)
Definition: fox16_gui.cpp:284
uint32_t HtmlFont_GetFontFlags(const HTML_FONT *fnt)
Definition: htmlfont.c:107
FXApp * m_app
Definition: fox16_gui.hpp:123
GWEN_GUI * _gui
Definition: cppgui.hpp:67
int GWEN_Buffer_AppendString(GWEN_BUFFER *bf, const char *buffer)
Definition: buffer.c:989
HTML_FONT_LIST * m_fontList
Definition: fox16_gui.hpp:129
#define GWEN_ERROR_NOT_IMPLEMENTED
Definition: error.h:108