gwenhywfar  4.6.0beta
fox16_htmllabel.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  begin : Tue Feb 23 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 #include "fox16_htmllabel.hpp"
15 #include "fox16_htmlctx.hpp"
16 
17 #include <gwenhywfar/debug.h>
18 #include <gwenhywfar/i18n.h>
19 #include <gwenhywfar/stringlist.h>
20 
21 #include <assert.h>
22 
23 
24 #define MAX_DEFAULT_WIDTH 400
25 #define ICON_SPACE 4
26 
27 
28 
29 FXDEFMAP(FOX16_HtmlLabel) FOX16_HtmlLabelMap[]={
30  FXMAPFUNC(SEL_PAINT,0,FOX16_HtmlLabel::onPaint),
31 };
32 
33 
34 
35 // Object implementation
36 FXIMPLEMENT(FOX16_HtmlLabel, FXFrame, FOX16_HtmlLabelMap, ARRAYNUMBER(FOX16_HtmlLabelMap))
37 
38 
39 
40 
41 FOX16_HtmlLabel::FOX16_HtmlLabel(FXComposite* p, const FXString& text,
42  FXuint opts,
43  FXint x, FXint y, FXint w, FXint h,
44  FXint pl, FXint pr,
45  FXint pt, FXint pb)
46 :FXFrame(p, opts, x, y, w, h, pl, pr, pt, pb)
47 ,m_htmlCtx(NULL)
48 ,m_minWidth(0)
49 ,m_maxDefaultWidth(MAX_DEFAULT_WIDTH)
50 ,m_haveDefaultDims(false)
51 ,m_mediaPaths(NULL)
52 ,m_icon(NULL)
53 {
54  m_mediaPaths=GWEN_StringList_new();
55  setText(text);
56  flags|=FLAG_ENABLED|FLAG_DIRTY|FLAG_RECALC;
57 
58 }
59 
60 
61 
63 :FXFrame()
64 ,m_htmlCtx(NULL)
65 ,m_minWidth(0)
66 ,m_mediaPaths(NULL)
67 ,m_icon(NULL)
68 {
69  flags|=FLAG_ENABLED;
70 }
71 
72 
73 
75  if (m_htmlCtx)
76  delete m_htmlCtx;
78 }
79 
80 
81 
82 void FOX16_HtmlLabel::setText(const FXString& text) {
83  m_haveDefaultDims=false;
84  m_text=text;
85  updateHtml();
86  flags|=FLAG_DIRTY;
87  layout();
88  recalc();
89  update();
90 }
91 
92 
93 
94 void FOX16_HtmlLabel::addMediaPath(const char *s) {
95  assert(s);
97 }
98 
99 
100 
101 void FOX16_HtmlLabel::setIcon(FXIcon *ic) {
102  m_icon=ic;
103  flags|=FLAG_DIRTY;
104  layout();
105  recalc();
106  update();
107 }
108 
109 
110 
112 #if 0
113  int w;
114  int wNeeded;
115 
116  m_htmlCtx->layout(-1, -1);
117  wNeeded=m_htmlCtx->getWidth();
118  w=wNeeded;
119  if (w>m_maxDefaultWidth)
121  if (w<width)
122  w=width;
123  if (w<wNeeded) {
124  m_htmlCtx->layout(w-border*2, -1);
125  }
128  m_haveDefaultDims=true;
129 #else
130  int w;
131 
132  if (options & FLAGS_NO_WORDWRAP)
133  w=-1;
134  else if (options & FLAGS_USE_FULL_WIDTH)
135  w=width;
136  else
138  m_htmlCtx->layout(w-border*2, -1);
141  m_haveDefaultDims=true;
142 #endif
143 }
144 
145 
146 
148  int w;
149 
150  if (m_htmlCtx==NULL)
151  updateHtml();
152  if (!m_haveDefaultDims)
153  calcDefaultDims();
154 
155  w=m_defaultWidth;
156  if (m_icon)
157  w+=m_icon->getWidth()+ICON_SPACE;
158  return w;
159 }
160 
161 
162 
164  int h;
165 
166  if (m_htmlCtx==NULL)
167  updateHtml();
168  if (!m_haveDefaultDims)
169  calcDefaultDims();
170  h=m_defaultHeight;
171  if (m_icon) {
172  int ih;
173 
174  ih=m_icon->getHeight();
175  if (ih>h)
176  h=ih;
177  }
178 
179  return h;
180 }
181 
182 
183 
184 long FOX16_HtmlLabel::onPaint(FXObject*, FXSelector, void *ptr) {
185  FXEvent *ev=(FXEvent*)ptr;
186  FXDCWindow dc(this, ev);
187 
188  dc.setForeground(backColor);
189  dc.fillRectangle(border, border, width-(border*2), height-(border*2));
190 
191  if (m_htmlCtx) {
192  if (m_icon) {
193  int th;
194  int ih;
195  int ty=border;
196 
197  if(isEnabled())
198  dc.drawIcon(m_icon, border, border);
199  else
200  dc.drawIconSunken(m_icon, border, border);
201 
202  ih=m_icon->getHeight();
203  th=m_htmlCtx->getHeight();
204  if (ih>th)
205  ty+=(ih-th)/2;
206  m_htmlCtx->paint(&dc, border+ICON_SPACE+m_icon->getWidth(), ty);
207  }
208  else {
209  m_htmlCtx->paint(&dc, border, border);
210  }
211  }
212  else {
213  DBG_ERROR(GWEN_LOGDOMAIN, "No HtmlContext");
214  }
215 
216  drawFrame(dc, 0, 0, width, height);
217  return 1;
218 }
219 
220 
221 
223  FXFrame::create();
224  if (m_icon)
225  m_icon->create();
226  updateHtml();
227  recalc();
228 }
229 
230 
231 
233 #if 0
234  int w;
235 
236  m_haveDefaultDims=false;
237  if (options & FLAGS_NO_WORDWRAP)
238  w=-1;
239  else
240  w=width;
241 
242  if (m_htmlCtx==NULL)
243  updateHtml();
244  m_htmlCtx->layout(w-border*2, height-border*2);
245  update();
246  flags&=~FLAG_DIRTY;
247 #else
248  int w;
249 
250  m_haveDefaultDims=false;
251  if (options & FLAGS_NO_WORDWRAP)
252  w=-1;
253  else if (options & FLAGS_USE_FULL_WIDTH) {
254  w=width;
255  if (m_icon)
256  w-=(m_icon->getWidth()+ICON_SPACE);
257  }
258  else
260 
261  if (m_htmlCtx==NULL)
262  updateHtml();
263  m_htmlCtx->layout(w-border*2, height-border*2);
264  update();
265  flags&=~FLAG_DIRTY;
266 #endif
267 }
268 
269 
270 
273 
274  if (m_htmlCtx)
275  delete m_htmlCtx;
276  m_haveDefaultDims=false;
277  m_htmlCtx=new FOX16_HtmlCtx(0);
278  /* copy media paths to context */
280  while(se) {
281  const char *s;
282 
284  assert(s);
287  }
288 
289  m_htmlCtx->setBackgroundColor(backColor);
290  m_htmlCtx->setForegroundColor(fxcolorfromname("black"));
291  m_htmlCtx->setText(m_text.text());
292  flags|=FLAG_DIRTY;
293 }
294 
295 
296 
297 
298 
299 
300