]> git.saurik.com Git - wxWidgets.git/blob - src/palmos/font.cpp
Derive wxWebViewEvent from wxNotifyEvent.
[wxWidgets.git] / src / palmos / font.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/palmos/font.cpp
3 // Purpose: wxFont class
4 // Author: William Osborne - minimal working wxPalmOS port
5 // Modified by:
6 // Created: 10/14/04
7 // RCS-ID: $Id$
8 // Copyright: (c) wxWidgets team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ============================================================================
13 // declarations
14 // ============================================================================
15
16 // ----------------------------------------------------------------------------
17 // headers
18 // ----------------------------------------------------------------------------
19
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #include "wx/font.h"
28
29 #ifndef WX_PRECOMP
30 #include "wx/list.h"
31 #include "wx/utils.h"
32 #include "wx/app.h"
33 #include "wx/log.h"
34 #include "wx/encinfo.h"
35 #endif // WX_PRECOMP
36
37 #include "wx/fontutil.h"
38 #include "wx/fontmap.h"
39
40 #include "wx/tokenzr.h"
41
42 // ----------------------------------------------------------------------------
43 // constants
44 // ----------------------------------------------------------------------------
45
46 // ----------------------------------------------------------------------------
47 // wxFontRefData - the internal description of the font
48 // ----------------------------------------------------------------------------
49
50 class WXDLLEXPORT wxFontRefData: public wxGDIRefData
51 {
52 public:
53 // constructors
54 wxFontRefData()
55 {
56 Init(-1, wxSize(0, 0), false, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL,
57 wxFONTWEIGHT_NORMAL, false, wxEmptyString,
58 wxFONTENCODING_DEFAULT);
59 }
60
61 wxFontRefData(int size,
62 const wxSize& pixelSize,
63 bool sizeUsingPixels,
64 wxFontFamily family,
65 wxFontStyle style,
66 wxFontWeight weight,
67 bool underlined,
68 const wxString& faceName,
69 wxFontEncoding encoding)
70 {
71 Init(size, pixelSize, sizeUsingPixels, family, style, weight,
72 underlined, faceName, encoding);
73 }
74
75 wxFontRefData(const wxNativeFontInfo& info, WXHFONT hFont = 0)
76 {
77 Init(info, hFont);
78 }
79
80 wxFontRefData(const wxFontRefData& data)
81 {
82 if ( data.m_nativeFontInfoOk )
83 {
84 Init(data.m_nativeFontInfo);
85 }
86 else
87 {
88 Init(data.m_pointSize, data.m_pixelSize, data.m_sizeUsingPixels,
89 data.m_family, data.m_style, data.m_weight,
90 data.m_underlined, data.m_faceName, data.m_encoding);
91 }
92 }
93
94 virtual ~wxFontRefData();
95
96 // operations
97 bool Alloc(wxFont *font);
98
99 void Free();
100
101 // all wxFont accessors
102 int GetPointSize() const
103 {
104 return m_nativeFontInfoOk ? m_nativeFontInfo.GetPointSize()
105 : m_pointSize;
106 }
107
108 wxSize GetPixelSize() const
109 {
110 return m_nativeFontInfoOk ? m_nativeFontInfo.GetPixelSize()
111 : m_pixelSize;
112 }
113
114 bool IsUsingSizeInPixels() const
115 {
116 return m_nativeFontInfoOk ? true : m_sizeUsingPixels;
117 }
118
119 int GetFamily() const
120 {
121 return m_family;
122 }
123
124 int GetStyle() const
125 {
126 return m_nativeFontInfoOk ? m_nativeFontInfo.GetStyle()
127 : m_style;
128 }
129
130 int GetWeight() const
131 {
132 return m_nativeFontInfoOk ? m_nativeFontInfo.GetWeight()
133 : m_weight;
134 }
135
136 bool GetUnderlined() const
137 {
138 return m_nativeFontInfoOk ? m_nativeFontInfo.GetUnderlined()
139 : m_underlined;
140 }
141
142 wxString GetFaceName() const
143 {
144 wxString s;
145 if ( m_nativeFontInfoOk )
146 s = m_nativeFontInfo.GetFaceName();
147 else
148 s = m_faceName;
149
150 return s;
151 }
152
153 wxFontEncoding GetEncoding() const
154 {
155 return m_nativeFontInfoOk ? m_nativeFontInfo.GetEncoding()
156 : m_encoding;
157 }
158
159 WXHFONT GetHFONT() const { return m_hFont; }
160
161 // ... and setters
162 void SetPointSize(int pointSize)
163 {
164 if ( m_nativeFontInfoOk )
165 {
166 m_nativeFontInfo.SetPointSize(pointSize);
167 }
168 else
169 {
170 m_pointSize = pointSize;
171 m_sizeUsingPixels = false;
172 }
173 }
174
175 void SetPixelSize(const wxSize& pixelSize)
176 {
177 if ( m_nativeFontInfoOk )
178 {
179 m_nativeFontInfo.SetPixelSize(pixelSize);
180 }
181 else
182 {
183 m_pixelSize = pixelSize;
184 m_sizeUsingPixels = true;
185 }
186 }
187
188 void SetFamily(wxFontFamily family)
189 {
190 m_family = family;
191 }
192
193 void SetStyle(wxFontStyle style)
194 {
195 if ( m_nativeFontInfoOk )
196 m_nativeFontInfo.SetStyle((wxFontStyle)style);
197 else
198 m_style = style;
199 }
200
201 void SetWeight(wxFontWeight weight)
202 {
203 if ( m_nativeFontInfoOk )
204 m_nativeFontInfo.SetWeight((wxFontWeight)weight);
205 else
206 m_weight = weight;
207 }
208
209 bool SetFaceName(const wxString& faceName)
210 {
211 if ( m_nativeFontInfoOk )
212 m_nativeFontInfo.SetFaceName(faceName);
213 else
214 m_faceName = faceName;
215 }
216
217 void SetUnderlined(bool underlined)
218 {
219 if ( m_nativeFontInfoOk )
220 m_nativeFontInfo.SetUnderlined(underlined);
221 else
222 m_underlined = underlined;
223 }
224
225 void SetEncoding(wxFontEncoding encoding)
226 {
227 if ( m_nativeFontInfoOk )
228 m_nativeFontInfo.SetEncoding(encoding);
229 else
230 m_encoding = encoding;
231 }
232
233 // native font info tests
234 bool HasNativeFontInfo() const { return m_nativeFontInfoOk; }
235
236 const wxNativeFontInfo& GetNativeFontInfo() const
237 { return m_nativeFontInfo; }
238
239 protected:
240 // common part of all ctors
241 void Init(int size,
242 const wxSize& pixelSize,
243 bool sizeUsingPixels,
244 wxFontFamily family,
245 wxFontStyle style,
246 wxFontWeight weight,
247 bool underlined,
248 const wxString& faceName,
249 wxFontEncoding encoding);
250
251 void Init(const wxNativeFontInfo& info, WXHFONT hFont = 0);
252
253 // font characterstics
254 int m_pointSize;
255 wxSize m_pixelSize;
256 bool m_sizeUsingPixels;
257 wxFontFamily m_family;
258 wxFontStyle m_style;
259 wxFontWeight m_weight;
260 bool m_underlined;
261 wxString m_faceName;
262 wxFontEncoding m_encoding;
263
264 // Windows font handle
265 WXHFONT m_hFont;
266
267 // Native font info
268 wxNativeFontInfo m_nativeFontInfo;
269 bool m_nativeFontInfoOk;
270 };
271
272 #define M_FONTDATA ((wxFontRefData*)m_refData)
273
274 // ============================================================================
275 // implementation
276 // ============================================================================
277
278 // ----------------------------------------------------------------------------
279 // wxFontRefData
280 // ----------------------------------------------------------------------------
281
282 void wxFontRefData::Init(int pointSize,
283 const wxSize& pixelSize,
284 bool sizeUsingPixels,
285 wxFontFamily family,
286 wxFontStyle style,
287 wxFontWeight weight,
288 bool underlined,
289 const wxString& faceName,
290 wxFontEncoding encoding)
291 {
292 }
293
294 void wxFontRefData::Init(const wxNativeFontInfo& info, WXHFONT hFont)
295 {
296 }
297
298 wxFontRefData::~wxFontRefData()
299 {
300 }
301
302 bool wxFontRefData::Alloc(wxFont *font)
303 {
304 return false;
305 }
306
307 void wxFontRefData::Free()
308 {
309 }
310
311 // ----------------------------------------------------------------------------
312 // wxNativeFontInfo
313 // ----------------------------------------------------------------------------
314
315 void wxNativeFontInfo::SetPixelSize(const wxSize& pixelSize)
316 {
317 }
318
319 // ----------------------------------------------------------------------------
320 // wxFont
321 // ----------------------------------------------------------------------------
322
323 bool wxFont::Create(const wxNativeFontInfo& info, WXHFONT hFont)
324 {
325 return false;
326 }
327
328 wxFont::wxFont(const wxString& fontdesc)
329 {
330 }
331
332 /* Constructor for a font. Note that the real construction is done
333 * in wxDC::SetFont, when information is available about scaling etc.
334 */
335 bool wxFont::DoCreate(int pointSize,
336 const wxSize& pixelSize,
337 bool sizeUsingPixels,
338 wxFontFamily family,
339 wxFontStyle style,
340 wxFontWeight weight,
341 bool underlined,
342 const wxString& faceName,
343 wxFontEncoding encoding)
344 {
345 return false;
346 }
347
348 wxFont::~wxFont()
349 {
350 }
351
352 // ----------------------------------------------------------------------------
353 // real implementation
354 // ----------------------------------------------------------------------------
355 wxGDIRefData *wxFont::CreateGDIRefData() const
356 {
357 return new wxFontRefData();
358 }
359
360 wxGDIRefData *wxFont::CloneGDIRefData(const wxGDIRefData *data) const
361 {
362 return new wxFontRefData(*static_cast<const wxFontRefData *>(data));
363 }
364
365 bool wxFont::RealizeResource()
366 {
367 return false;
368 }
369
370 bool wxFont::FreeResource(bool WXUNUSED(force))
371 {
372 return false;
373 }
374
375 WXHANDLE wxFont::GetResourceHandle() const
376 {
377 return (WXHANDLE)0;
378 }
379
380 bool wxFont::IsFree() const
381 {
382 return false;
383 }
384
385 // ----------------------------------------------------------------------------
386 // change font attribute: we recreate font when doing it
387 // ----------------------------------------------------------------------------
388
389 void wxFont::SetPointSize(int pointSize)
390 {
391 }
392
393 void wxFont::SetPixelSize(const wxSize& pixelSize)
394 {
395 }
396
397 void wxFont::SetFamily(wxFontFamily family)
398 {
399 }
400
401 void wxFont::SetStyle(wxFontStyle style)
402 {
403 }
404
405 void wxFont::SetWeight(wxFontWeight weight)
406 {
407 }
408
409 bool wxFont::SetFaceName(const wxString& faceName)
410 {
411 return true;
412 }
413
414 void wxFont::SetUnderlined(bool underlined)
415 {
416 }
417
418 void wxFont::SetEncoding(wxFontEncoding encoding)
419 {
420 }
421
422 void wxFont::DoSetNativeFontInfo(const wxNativeFontInfo& info)
423 {
424 }
425
426 // ----------------------------------------------------------------------------
427 // accessors
428 // ----------------------------------------------------------------------------
429
430 int wxFont::GetPointSize() const
431 {
432 return 0;
433 }
434
435 wxSize wxFont::GetPixelSize() const
436 {
437 return wxSize(0,0);
438 }
439
440 bool wxFont::IsUsingSizeInPixels() const
441 {
442 return false;
443 }
444
445 wxFontFamily wxFont::DoGetFamily() const
446 {
447 return wxFONTFAMILY_ROMAN;
448 }
449
450 wxFontStyle wxFont::GetStyle() const
451 {
452 return wxFONTSTYLE_NORMAL;
453 }
454
455 wxFontWeight wxFont::GetWeight() const
456 {
457 return wxFONTWEIGHT_NORMAL;
458 }
459
460 bool wxFont::GetUnderlined() const
461 {
462 return false;
463 }
464
465 wxString wxFont::GetFaceName() const
466 {
467 return wxEmptyString;
468 }
469
470 wxFontEncoding wxFont::GetEncoding() const
471 {
472 return wxFONTENCODING_SYSTEM;
473 }
474
475 const wxNativeFontInfo *wxFont::GetNativeFontInfo() const
476 {
477 return NULL;
478 }
479
480 wxString wxFont::GetNativeFontInfoDesc() const
481 {
482 wxCHECK_MSG( IsOk(), wxEmptyString, wxT("invalid font") );
483
484 // be sure we have an HFONT associated...
485 wxConstCast(this, wxFont)->RealizeResource();
486 return wxFontBase::GetNativeFontInfoDesc();
487 }
488
489 wxString wxFont::GetNativeFontInfoUserDesc() const
490 {
491 wxCHECK_MSG( IsOk(), wxEmptyString, wxT("invalid font") );
492
493 // be sure we have an HFONT associated...
494 wxConstCast(this, wxFont)->RealizeResource();
495 return wxFontBase::GetNativeFontInfoUserDesc();
496 }
497
498 bool wxFont::IsFixedWidth() const
499 {
500 return false;
501 }