gwenhywfar  4.6.0beta
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()
85 {
89  GWEN_Gui_SetName(_gui, "fox16-gui");
90  m_fontList=HtmlFont_List_new();
91 }
92 
93 
94 
96  if (!m_scopeList.empty()) {
97  DBG_ERROR(GWEN_LOGDOMAIN, "ScopeList is not empty!");
98  }
99 
100  if (m_updater)
101  delete m_updater;
102  HtmlFont_List_free(m_fontList);
103 }
104 
105 
106 
108  return ++m_lastId;
109 }
110 
111 
112 
114  if (!m_scopeList.empty())
115  return m_scopeList.back()->getId();
116 
117  return 0;
118 }
119 
120 
121 
123  m_scopeList.push_back(ws);
124 }
125 
126 
127 
129  m_scopeList.remove(ws);
130 }
131 
132 
133 
135  WinScopePtrList::iterator it;
136 
137  for (it=m_scopeList.begin();
138  it!=m_scopeList.end();
139  it++) {
140  if ((*it)->getId()==id)
141  return (*it);
142  }
143 
144  return NULL;
145 }
146 
147 
148 
149 FXWindow *FOX16_Gui::getGuiWindow(uint32_t id) {
150  return m_app->getActiveWindow();
151 }
152 
153 
154 
155 
157  CppGui *cppgui;
158 
159  cppgui=CppGui::getCppGui();
160  if (cppgui)
161  return dynamic_cast<FOX16_Gui*>(cppgui);
162  else
163  return NULL;
164 }
165 
166 
167 
169  WinScopePtrList::iterator it;
170 
171  for (it=m_scopeList.begin();
172  it!=m_scopeList.end();
173  it++) {
174  const char *s;
175 
176  switch((*it)->getType()) {
178  s="window";
179  break;
180  default:
181  s="unknown";
182  break;
183  }
184  fprintf(stderr, "WinScope: id %08x, parent %08x, type %s\n",
185  (*it)->getId(),
186  (*it)->getParentId(),
187  s);
188  }
189 }
190 
191 
192 
193 
194 int FOX16_Gui::print(const char *docTitle,
195  const char *docType,
196  const char *descr,
197  const char *text,
198  uint32_t guiid) {
199  DBG_ERROR(GWEN_LOGDOMAIN, "Not implemented");
201 }
202 
203 
204 
205 FXString FOX16_Gui::getRawText(const char *text) {
206  const char *p=0;
207  const char *p2=0;
208 
209  if (text==NULL)
210  return FXString("");
211 
212  /* find begin of HTML area */
213  p=text;
214  while ((p=strchr(p, '<'))) {
215  const char *t;
216 
217  t=p;
218  t++;
219  if (toupper(*t)=='H') {
220  t++;
221  if (toupper(*t)=='T') {
222  t++;
223  if (toupper(*t)=='M') {
224  t++;
225  if (toupper(*t)=='L') {
226  t++;
227  if (toupper(*t)=='>') {
228  break;
229  }
230  }
231  }
232  }
233  }
234  p++;
235  } /* while */
236 
237  /* find end of HTML area */
238  if (p) {
239  p2=p;
240  p2+=6; /* skip "<html>" */
241  while ((p2=strchr(p2, '<'))) {
242  const char *t;
243 
244  t=p2;
245  t++;
246  if (toupper(*t)=='/') {
247  t++;
248  if (toupper(*t)=='H') {
249  t++;
250  if (toupper(*t)=='T') {
251  t++;
252  if (toupper(*t)=='M') {
253  t++;
254  if (toupper(*t)=='L') {
255  t++;
256  if (toupper(*t)=='>') {
257  break;
258  }
259  }
260  }
261  }
262  }
263  }
264  p2++;
265  } /* while */
266  }
267 
268  if (p && p2) {
269  p2+=7; /* skip "</html>" */
270 
271  int startPos=(p-text);
272  int endPos=(p2-text);
273  FXString result;
274 
275  result=FXString(text);
276  result.erase(startPos, endPos);
277  return result;
278  }
279  else
280  return FXString(text);
281 }
282 
283 
284 
285 FXString FOX16_Gui::getHtmlText(const char *text) {
286  const char *p=0;
287  const char *p2=0;
288 
289  if (text==NULL)
290  return FXString("");
291 
292  /* find begin of HTML area */
293  p=text;
294  while ((p=strchr(p, '<'))) {
295  const char *t;
296 
297  t=p;
298  t++;
299  if (toupper(*t)=='H') {
300  t++;
301  if (toupper(*t)=='T') {
302  t++;
303  if (toupper(*t)=='M') {
304  t++;
305  if (toupper(*t)=='L') {
306  t++;
307  if (toupper(*t)=='>') {
308  break;
309  }
310  }
311  }
312  }
313  }
314  p++;
315  } /* while */
316 
317  /* find end of HTML area */
318  if (p) {
319  p+=6; /* skip "<html>" */
320  p2=p;
321  while ((p2=strchr(p2, '<'))) {
322  const char *t;
323 
324  t=p2;
325  t++;
326  if (toupper(*t)=='/') {
327  t++;
328  if (toupper(*t)=='H') {
329  t++;
330  if (toupper(*t)=='T') {
331  t++;
332  if (toupper(*t)=='M') {
333  t++;
334  if (toupper(*t)=='L') {
335  t++;
336  if (toupper(*t)=='>') {
337  break;
338  }
339  }
340  }
341  }
342  }
343  }
344  p2++;
345  } /* while */
346  }
347 
348  if (p && p2)
349  return FXString(p, p2-p);
350  else
351  return FXString(text);
352 }
353 
354 
355 
356 int FOX16_Gui::execDialog(GWEN_DIALOG *dlg, uint32_t guiid) {
357  FOX16_GuiDialog foxDlg(this, dlg);
358  FXWindow *owner;
359 
360  /* get main window of parent dialog (if any) */
361  owner=m_app->getActiveWindow();
362 
363  /* setup widget tree for the dialog */
364  if (!(foxDlg.setup(owner))) {
365  return GWEN_ERROR_GENERIC;
366  }
367 
368  return foxDlg.execute();
369 }
370 
371 
372 
373 int FOX16_Gui::openDialog(GWEN_DIALOG *dlg, uint32_t guiid) {
374  FOX16_GuiDialog *foxDlg;
375  FXWindow *owner;
376 
377  /* get main window of parent dialog (if any) */
378  owner=m_app->getActiveWindow();
379 
380  foxDlg=new FOX16_GuiDialog(this, dlg);
381 
382  /* setup widget tree for the dialog */
383  if (!(foxDlg->setup(owner))) {
384  delete foxDlg;
385  return GWEN_ERROR_GENERIC;
386  }
387 
388  foxDlg->openDialog();
389  m_updater->guiUpdate();
390 
391  return 0;
392 }
393 
394 
395 
397  FOX16_GuiDialog *foxDlg;
398 
399  foxDlg=FOX16_GuiDialog::getDialog(dlg);
400  assert(foxDlg);
401 
402  foxDlg->closeDialog();
403  delete foxDlg;
404  m_updater->guiUpdate();
405 
406  return 0;
407 }
408 
409 
410 
411 int FOX16_Gui::runDialog(GWEN_DIALOG *dlg, int untilEnd) {
412  FOX16_GuiDialog *foxDlg;
413 
414  foxDlg=FOX16_GuiDialog::getDialog(dlg);
415  assert(foxDlg);
416 
417  if (untilEnd)
418  return foxDlg->cont();
419  else {
420  m_updater->guiUpdate();
421  return 0;
422  }
423 }
424 
425 
426 
427 int FOX16_Gui::getFileName(const char *caption,
429  uint32_t flags,
430  const char *patterns,
431  GWEN_BUFFER *pathBuffer,
432  uint32_t guiid) {
433  FXString sCaption;
434  FXString sPatterns;
435  FXString sPath;
436  FXString str;
437  FXWindow *owner;
438 
439  if (caption)
440  sCaption=FXString(caption);
441 
442  if (patterns) {
443  const char *s1;
444  const char *s2;
445 
446  s1=patterns;
447  while(s1 && *s1) {
448  s2=strchr(s1, '\t');
449  if (s2) {
450  str=FXString(s1, s2-s1);
451  /* skip tab */
452  s2++;
453  }
454  else {
455  str=FXString(s1);
456  s2=NULL;
457  }
458 
459  if (str.contains('(')) {
460  if (!sPatterns.empty())
461  sPatterns+='\n';
462  sPatterns+=str.before('(');
463  str=str.after('(');
464  sPatterns+='(';
465  sPatterns+=str.substitute(';', ',');
466  }
467  else {
468  if (!sPatterns.empty())
469  sPatterns+='\n';
470  sPatterns+=str.substitute(';', ',');
471  }
472 
473  s1=s2;
474  }
475  }
476 
477  if (GWEN_Buffer_GetUsedBytes(pathBuffer))
478  sPath=FXString(GWEN_Buffer_GetStart(pathBuffer));
479 
480  owner=m_app->getModalWindow();
481  if (owner==NULL) {
482  owner=m_app->getActiveWindow();
483  }
484  if (owner==NULL) {
485  owner=m_app->getRootWindow();
486  }
487  if (owner==NULL) {
488  DBG_ERROR(GWEN_LOGDOMAIN, "Could not determine owner window");
489  return GWEN_ERROR_INTERNAL;
490  }
491 
492  switch(fnt) {
494  str=FXFileDialog::getOpenFilename(owner, sCaption, sPath, sPatterns, 0);
495  break;
496 
498  str=FXFileDialog::getSaveFilename(owner, sCaption, sPath, sPatterns, 0);
499  break;
500 
502  str=FXFileDialog::getOpenDirectory(owner, sCaption, sPath);
503  break;
504  }
505 
506  if (str.empty()) {
507  DBG_ERROR(GWEN_LOGDOMAIN, "Empty filename returned.");
508  return GWEN_ERROR_ABORTED;
509  }
510  else {
511  GWEN_Buffer_Reset(pathBuffer);
512  GWEN_Buffer_AppendString(pathBuffer, str.text());
513  return 0;
514  }
515 }
516 
517 
518 
519 HTML_FONT *FOX16_Gui::findFont(const char *fontName,
520  int fontSize,
521  uint32_t fontFlags) {
522  HTML_FONT *fnt;
523 
524  assert(m_fontList);
525  fnt=HtmlFont_List_First(m_fontList);
526  while(fnt) {
527  const char *s;
528 
529  s=HtmlFont_GetFontName(fnt);
530  if (s && *s &&
531  HtmlFont_GetFontSize(fnt)==fontSize &&
532  HtmlFont_GetFontFlags(fnt)==fontFlags &&
533  strcasecmp(s, fontName)==0)
534  break;
535  fnt=HtmlFont_List_Next(fnt);
536  }
537 
538  return fnt;
539 }
540 
541 
542 
543 HTML_FONT *FOX16_Gui::getFont(const char *fontName,
544  int fontSize,
545  uint32_t fontFlags) {
546  HTML_FONT *fnt;
547 
548  fnt=findFont(fontName, fontSize, fontFlags);
549  if (fnt)
550  return fnt;
551  else {
552  fnt=HtmlFont_new();
553  HtmlFont_SetFontName(fnt, fontName);
554  HtmlFont_SetFontSize(fnt, fontSize);
555  HtmlFont_SetFontFlags(fnt, fontFlags);
556  HtmlFont_List_Add(fnt, m_fontList);
557  return fnt;
558  }
559 }
560 
561 
562 
563 
564