gwenhywfar 5.12.0
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
29FXDEFMAP(FOX16_HtmlLabel) FOX16_HtmlLabelMap[]= {
30 FXMAPFUNC(SEL_PAINT,0,FOX16_HtmlLabel::onPaint),
31};
32
33
34
35// Object implementation
36FXIMPLEMENT(FOX16_HtmlLabel, FXFrame, FOX16_HtmlLabelMap, ARRAYNUMBER(FOX16_HtmlLabelMap))
37
38
39
40
41FOX16_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)
48 ,m_minWidth(0)
50 ,m_haveDefaultDims(false)
52 ,m_icon(NULL) {
54 setText(text);
55 flags|=FLAG_ENABLED|FLAG_DIRTY|FLAG_RECALC;
56
57}
58
59
60
62 :FXFrame()
64 ,m_minWidth(0)
66 ,m_icon(NULL) {
67 flags|=FLAG_ENABLED;
68}
69
70
71
77
78
79
80void FOX16_HtmlLabel::setText(const FXString& text) {
82 m_text=text;
83 updateHtml();
84 flags|=FLAG_DIRTY;
85 layout();
86 recalc();
87 update();
88}
89
90
91
92void FOX16_HtmlLabel::addMediaPath(const char *s) {
93 assert(s);
95}
96
97
98
99void FOX16_HtmlLabel::setIcon(FXIcon *ic) {
100 m_icon=ic;
101 flags|=FLAG_DIRTY;
102 layout();
103 recalc();
104 update();
105}
106
107
108
110#if 0
111 int w;
112
113 if (options & FLAGS_NO_WORDWRAP)
114 w=-1;
115 else if (options & FLAGS_USE_FULL_WIDTH)
116 w=width;
117 else
119 m_htmlCtx->layout(w-border*2, -1);
120 m_defaultWidth=m_htmlCtx->getWidth();
121 m_defaultHeight=m_htmlCtx->getHeight();
123#else
124 int w;
125
126 if (options & FLAGS_NO_WORDWRAP)
127 w=-1;
128 else if (options & FLAGS_USE_FULL_WIDTH)
129 w=width;
130 else if (m_maxDefaultWidth!=-1)
132 else {
133 int wTmp=1024;
134 int mask=1024;
135 int i;
136
137 for (i=0; i<10; i++) {
138 double ar, nw, nh;
139
140 m_htmlCtx->layout(wTmp-border*2, -1);
141 nw=(double) (m_htmlCtx->getWidth());
142 nh=(double)(m_htmlCtx->getHeight());
143 ar=nw/nh;
144
145 if (ar>=3.5 && ar<4.0)
146 break;
147
148 if (ar>4.0)
149 /* w/h too high, so we need to reduce the width */
150 wTmp&=~mask;
151
152 mask>>=1;
153 wTmp|=mask;
154 }
155 w=wTmp;
156 }
157
158 /* TODO: handle icon size correctly */
159
160 m_htmlCtx->layout(w-border*2, -1);
161 m_defaultWidth=m_htmlCtx->getWidth();
162 m_defaultHeight=m_htmlCtx->getHeight();
164 //DBG_ERROR(0, "Labelsize: %d / %d", m_defaultWidth, m_defaultHeight);
165#endif
166}
167
168
169
171 int w;
172
173 if (m_htmlCtx==NULL)
174 updateHtml();
177
179 if (m_icon)
180 w+=m_icon->getWidth()+ICON_SPACE;
181
182 //DBG_ERROR(0, "GetDefaultWidth[%s]: Width= %d", m_text.text(), w);
183
184 return w;
185}
186
187
188
190 int h;
191
192 if (m_htmlCtx==NULL)
193 updateHtml();
197 if (m_icon) {
198 int ih;
199
200 ih=m_icon->getHeight();
201 if (ih>h)
202 h=ih;
203 }
204
205 //DBG_ERROR(0, "GetDefaultHeight[%s]: Height= %d", m_text.text(), h);
206
207 return h;
208}
209
210
211
212long FOX16_HtmlLabel::onPaint(FXObject*, FXSelector, void *ptr) {
213 FXEvent *ev=(FXEvent*)ptr;
214 FXDCWindow dc(this, ev);
215
216 dc.setForeground(backColor);
217 dc.fillRectangle(border, border, width-(border*2), height-(border*2));
218
219 if (m_htmlCtx) {
220 //DBG_ERROR(0, "Paint: Labelsize= %d / %d", m_htmlCtx->getWidth(), m_htmlCtx->getHeight());
221 if (m_icon) {
222 int th;
223 int ih;
224 int ty=border;
225
226 if(isEnabled())
227 dc.drawIcon(m_icon, border, border);
228 else
229 dc.drawIconSunken(m_icon, border, border);
230
231 ih=m_icon->getHeight();
232 th=m_htmlCtx->getHeight();
233 if (ih>th)
234 ty+=(ih-th)/2;
235 m_htmlCtx->paint(&dc, border+ICON_SPACE+m_icon->getWidth(), ty);
236 }
237 else {
238 m_htmlCtx->paint(&dc, border, border);
239 }
240 }
241 else {
242 DBG_ERROR(GWEN_LOGDOMAIN, "No HtmlContext");
243 }
244
245 drawFrame(dc, 0, 0, width, height);
246 return 1;
247}
248
249
250
252 FXFrame::create();
253 if (m_icon)
254 m_icon->create();
255 updateHtml();
256 recalc();
257}
258
259
260
262#if 0
263 int w;
264
265 m_haveDefaultDims=false;
266 if (options & FLAGS_NO_WORDWRAP)
267 w=-1;
268 else if (options & FLAGS_USE_FULL_WIDTH) {
269 w=width;
270 if (m_icon)
271 w-=(m_icon->getWidth()+ICON_SPACE);
272 }
273 else
275
276 if (m_htmlCtx==NULL)
277 updateHtml();
278 m_htmlCtx->layout(w-border*2, height-border*2);
279 update();
280 flags&=~FLAG_DIRTY;
281#else
282 int w;
283
284 //DBG_ERROR(0, "Layout[%s]: Width=%d, height=%d", m_text.text(), width, height);
285
286 if (m_htmlCtx==NULL)
287 updateHtml();
288
291
292 if (options & FLAGS_NO_WORDWRAP)
293 w=-1;
294 else if (options & FLAGS_USE_FULL_WIDTH) {
295 w=width;
296 if (m_icon)
297 w-=(m_icon->getWidth()+ICON_SPACE);
298 }
299 else
301
302 m_htmlCtx->layout(w-border*2, height-border*2);
303 update();
304 flags&=~FLAG_DIRTY;
305
306#endif
307}
308
309
310
313
314 if (m_htmlCtx)
315 delete m_htmlCtx;
316 m_haveDefaultDims=false;
318 /* copy media paths to context */
320 while(se) {
321 const char *s;
322
324 assert(s);
325 m_htmlCtx->addMediaPath(s);
327 }
328
329 m_htmlCtx->setBackgroundColor(backColor);
330 m_htmlCtx->setForegroundColor(fxcolorfromname("black"));
331 m_htmlCtx->setText(m_text.text());
332 flags|=FLAG_DIRTY;
333}
334
335
336
337
338
339
340
#define NULL
Definition binreloc.c:300
long onPaint(FXObject *, FXSelector, void *)
void addMediaPath(const char *s)
void setIcon(FXIcon *ic)
FOX16_HtmlCtx * m_htmlCtx
FOX16_HtmlLabel(FXComposite *p, const FXString &text, FXuint opts=0, FXint x=0, FXint y=0, FXint w=0, FXint h=0, FXint pl=DEFAULT_PAD, FXint pr=DEFAULT_PAD, FXint pt=DEFAULT_PAD, FXint pb=DEFAULT_PAD)
void setText(const FXString &text)
Set the text for this label.
GWEN_STRINGLIST * m_mediaPaths
virtual FXint getDefaultWidth()
Return default width.
virtual FXint getDefaultHeight()
Return default height.
#define DBG_ERROR(dbg_logger, format,...)
Definition debug.h:97
FXIMPLEMENT(FOX16_GuiSortingList, FXFoldingList, FOX16_GuiSortingListMap, ARRAYNUMBER(FOX16_GuiSortingListMap)) FOX16_GuiSortingList
FXDEFMAP(FOX16_HtmlLabel) FOX16_HtmlLabelMap[]
#define ICON_SPACE
#define GWEN_LOGDOMAIN
Definition logger.h:35
void GWEN_StringList_free(GWEN_STRINGLIST *sl)
Definition stringlist.c:62
const char * GWEN_StringListEntry_Data(const GWEN_STRINGLISTENTRY *se)
Definition stringlist.c:406
GWEN_STRINGLISTENTRY * GWEN_StringListEntry_Next(const GWEN_STRINGLISTENTRY *se)
Definition stringlist.c:398
int GWEN_StringList_AppendString(GWEN_STRINGLIST *sl, const char *s, int take, int checkDouble)
Definition stringlist.c:245
GWEN_STRINGLISTENTRY * GWEN_StringList_FirstEntry(const GWEN_STRINGLIST *sl)
Definition stringlist.c:390
GWEN_STRINGLIST * GWEN_StringList_new(void)
Definition stringlist.c:50
struct GWEN_STRINGLISTENTRYSTRUCT GWEN_STRINGLISTENTRY
Definition stringlist.h:53
static void drawFrame(FXDCWindow &dc, FXint x, FXint y, FXint w, FXint h)
Definition theme.cpp:228