]> git.saurik.com Git - wxWidgets.git/blame - src/motif/font.cpp
Only give capture to wxPopupTransientWindow child if it's the only one.
[wxWidgets.git] / src / motif / font.cpp
CommitLineData
4bb6408c 1/////////////////////////////////////////////////////////////////////////////
7ecb8b06 2// Name: src/motif/font.cpp
4bb6408c
JS
3// Purpose: wxFont class
4// Author: Julian Smart
5// Modified by:
6// Created: 17/09/98
4bb6408c 7// Copyright: (c) Julian Smart
65571936 8// Licence: wxWindows licence
4bb6408c
JS
9/////////////////////////////////////////////////////////////////////////////
10
93ccaed8
VZ
11// ============================================================================
12// declarations
13// ============================================================================
14
15// ----------------------------------------------------------------------------
16// headers
17// ----------------------------------------------------------------------------
18
1248b41f
MB
19// For compilers that support precompilation, includes "wx.h".
20#include "wx/wxprec.h"
21
338dd992
JJ
22#ifdef __VMS
23#pragma message disable nosimpint
4dff3400 24#include "wx/vms_x_fix.h"
338dd992 25#endif
79e4b627 26#include <Xm/Xm.h>
338dd992
JJ
27#ifdef __VMS
28#pragma message enable nosimpint
29#endif
79e4b627 30
4bb6408c 31#include "wx/font.h"
df91131c
WS
32
33#ifndef WX_PRECOMP
34 #include "wx/string.h"
de6185e2 35 #include "wx/utils.h" // for wxGetDisplay()
9eddec69 36 #include "wx/settings.h"
dd05139a 37 #include "wx/gdicmn.h"
df91131c
WS
38#endif
39
98c9fc2d 40#include "wx/fontutil.h" // for wxNativeFontInfo
563f868d 41#include "wx/tokenzr.h"
da494b40 42#include "wx/motif/private.h"
4bb6408c 43
93ccaed8
VZ
44// ----------------------------------------------------------------------------
45// private classes
46// ----------------------------------------------------------------------------
47
48// For every wxFont, there must be a font for each display and scale requested.
49// So these objects are stored in wxFontRefData::m_fonts
79e4b627 50class wxXFont : public wxObject
93ccaed8
VZ
51{
52public:
53 wxXFont();
d3c7fc99 54 virtual ~wxXFont();
93ccaed8 55
996994c7 56#if !wxMOTIF_NEW_FONT_HANDLING
93ccaed8 57 WXFontStructPtr m_fontStruct; // XFontStruct
996994c7 58#endif
105fbe1f 59#if !wxMOTIF_USE_RENDER_TABLE
93ccaed8 60 WXFontList m_fontList; // Motif XmFontList
b0f76951 61#else // if wxMOTIF_USE_RENDER_TABLE
da494b40 62 WXRenderTable m_renderTable; // Motif XmRenderTable
996994c7 63 WXRendition m_rendition; // Motif XmRendition
da494b40 64#endif
93ccaed8
VZ
65 WXDisplay* m_display; // XDisplay
66 int m_scale; // Scale * 100
67};
68
69class wxFontRefData: public wxGDIRefData
70{
73608949 71 friend class wxFont;
93ccaed8
VZ
72
73public:
74 wxFontRefData(int size = wxDEFAULT,
0c14b6c3
FM
75 wxFontFamily family = wxFONTFAMILY_DEFAULT,
76 wxFontStyle style = wxFONTSTYLE_NORMAL,
77 wxFontWeight weight = wxFONTWEIGHT_NORMAL,
96be256b 78 bool underlined = false,
93ccaed8
VZ
79 const wxString& faceName = wxEmptyString,
80 wxFontEncoding encoding = wxFONTENCODING_DEFAULT)
81 {
82 Init(size, family, style, weight, underlined, faceName, encoding);
83 }
84
85 wxFontRefData(const wxFontRefData& data)
86 {
87 Init(data.m_pointSize, data.m_family, data.m_style, data.m_weight,
88 data.m_underlined, data.m_faceName, data.m_encoding);
89 }
90
d3c7fc99 91 virtual ~wxFontRefData();
93ccaed8
VZ
92
93protected:
94 // common part of all ctors
95 void Init(int size,
0c14b6c3
FM
96 wxFontFamily family,
97 wxFontStyle style,
98 wxFontWeight weight,
93ccaed8
VZ
99 bool underlined,
100 const wxString& faceName,
101 wxFontEncoding encoding);
102
103 // font attributes
104 int m_pointSize;
0c14b6c3
FM
105 wxFontFamily m_family;
106 wxFontStyle m_style;
107 wxFontWeight m_weight;
93ccaed8
VZ
108 bool m_underlined;
109 wxString m_faceName;
110 wxFontEncoding m_encoding;
111
563f868d 112 wxNativeFontInfo m_nativeFontInfo;
9045ad9d 113
93ccaed8
VZ
114 // A list of wxXFonts
115 wxList m_fonts;
116};
117
118// ============================================================================
119// implementation
120// ============================================================================
121
122// ----------------------------------------------------------------------------
123// wxXFont
124// ----------------------------------------------------------------------------
125
f97c9854
JS
126wxXFont::wxXFont()
127{
996994c7 128#if !wxMOTIF_NEW_FONT_HANDLING
f97c9854 129 m_fontStruct = (WXFontStructPtr) 0;
996994c7 130#endif
105fbe1f 131#if !wxMOTIF_USE_RENDER_TABLE
f97c9854 132 m_fontList = (WXFontList) 0;
eb9d223a 133#else // if wxMOTIF_USE_RENDER_TABLE
da494b40 134 m_renderTable = (WXRenderTable) 0;
996994c7 135 m_rendition = (WXRendition) 0;
da494b40 136#endif
f97c9854
JS
137 m_display = (WXDisplay*) 0;
138 m_scale = 100;
139}
140
141wxXFont::~wxXFont()
142{
eb9d223a 143#if !wxMOTIF_USE_RENDER_TABLE
73608949
MB
144 if (m_fontList)
145 XmFontListFree ((XmFontList) m_fontList);
146 m_fontList = NULL;
b0f76951 147#else // if wxMOTIF_USE_RENDER_TABLE
73608949
MB
148 if (m_renderTable)
149 XmRenderTableFree ((XmRenderTable) m_renderTable);
150 m_renderTable = NULL;
da494b40
MB
151#endif
152
2d120f83 153 // TODO: why does freeing the font produce a segv???
f97c9854 154 // Note that XFreeFont wasn't called in wxWin 1.68 either.
73608949
MB
155 // MBN: probably some interaction with fonts being still
156 // in use in some widgets...
dfe1eee3 157 // XFontStruct* fontStruct = (XFontStruct*) m_fontStruct;
2d120f83 158 // XFreeFont((Display*) m_display, fontStruct);
f97c9854
JS
159}
160
93ccaed8
VZ
161// ----------------------------------------------------------------------------
162// wxFontRefData
163// ----------------------------------------------------------------------------
164
165void wxFontRefData::Init(int pointSize,
0c14b6c3
FM
166 wxFontFamily family,
167 wxFontStyle style,
168 wxFontWeight weight,
93ccaed8
VZ
169 bool underlined,
170 const wxString& faceName,
171 wxFontEncoding encoding)
4bb6408c 172{
93ccaed8 173 if (family == wxDEFAULT)
0c14b6c3 174 m_family = wxFONTFAMILY_SWISS;
93ccaed8
VZ
175 else
176 m_family = family;
4bb6408c 177
93ccaed8
VZ
178 m_faceName = faceName;
179
180 if (style == wxDEFAULT)
0c14b6c3 181 m_style = wxFONTSTYLE_NORMAL;
93ccaed8
VZ
182 else
183 m_style = style;
184
185 if (weight == wxDEFAULT)
0c14b6c3 186 m_weight = wxFONTWEIGHT_NORMAL;
93ccaed8
VZ
187 else
188 m_weight = weight;
189
190 if (pointSize == wxDEFAULT)
191 m_pointSize = 12;
192 else
193 m_pointSize = pointSize;
194
195 m_underlined = underlined;
196 m_encoding = encoding;
4bb6408c
JS
197}
198
199wxFontRefData::~wxFontRefData()
200{
ac32ba44 201 wxList::compatibility_iterator node = m_fonts.GetFirst();
dfc54541
JS
202 while (node)
203 {
fd304d98 204 wxXFont* f = (wxXFont*) node->GetData();
f97c9854 205 delete f;
fd304d98 206 node = node->GetNext();
dfc54541 207 }
f97c9854 208 m_fonts.Clear();
4bb6408c
JS
209}
210
68c95704 211#define M_FONTDATA ((wxFontRefData*)m_refData)
873fd4af 212
93ccaed8
VZ
213// ----------------------------------------------------------------------------
214// wxFont
215// ----------------------------------------------------------------------------
4bb6408c 216
ef4e8ebd 217wxFont::wxFont(const wxNativeFontInfo& info)
98c9fc2d 218{
42f30fa2 219 (void)Create(info.GetXFontName());
98c9fc2d
VZ
220}
221
93ccaed8 222bool wxFont::Create(int pointSize,
0c14b6c3
FM
223 wxFontFamily family,
224 wxFontStyle style,
225 wxFontWeight weight,
93ccaed8
VZ
226 bool underlined,
227 const wxString& faceName,
228 wxFontEncoding encoding)
4bb6408c
JS
229{
230 UnRef();
93ccaed8
VZ
231 m_refData = new wxFontRefData(pointSize, family, style, weight,
232 underlined, faceName, encoding);
dfe1eee3 233
96be256b 234 return true;
4bb6408c
JS
235}
236
563f868d
GD
237bool wxFont::Create(const wxString& fontname, wxFontEncoding enc)
238{
239 if( !fontname )
240 {
a756f210 241 *this = wxSystemSettings::GetFont( wxSYS_DEFAULT_GUI_FONT);
96be256b 242 return true;
563f868d
GD
243 }
244
245 m_refData = new wxFontRefData();
246
42f30fa2 247 M_FONTDATA->m_nativeFontInfo.SetXFontName(fontname); // X font name
563f868d
GD
248
249 wxString tmp;
250
251 wxStringTokenizer tn( fontname, wxT("-") );
252
253 tn.GetNextToken(); // skip initial empty token
254 tn.GetNextToken(); // foundry
255
256
257 M_FONTDATA->m_faceName = tn.GetNextToken(); // family
258
259 tmp = tn.GetNextToken().MakeUpper(); // weight
0c14b6c3
FM
260 if (tmp == wxT("BOLD")) M_FONTDATA->m_weight = wxFONTWEIGHT_BOLD;
261 if (tmp == wxT("BLACK")) M_FONTDATA->m_weight = wxFONTWEIGHT_BOLD;
262 if (tmp == wxT("EXTRABOLD")) M_FONTDATA->m_weight = wxFONTWEIGHT_BOLD;
263 if (tmp == wxT("DEMIBOLD")) M_FONTDATA->m_weight = wxFONTWEIGHT_BOLD;
264 if (tmp == wxT("ULTRABOLD")) M_FONTDATA->m_weight = wxFONTWEIGHT_BOLD;
563f868d 265
0c14b6c3
FM
266 if (tmp == wxT("LIGHT")) M_FONTDATA->m_weight = wxFONTWEIGHT_LIGHT;
267 if (tmp == wxT("THIN")) M_FONTDATA->m_weight = wxFONTWEIGHT_LIGHT;
563f868d
GD
268
269 tmp = tn.GetNextToken().MakeUpper(); // slant
0c14b6c3
FM
270 if (tmp == wxT("I")) M_FONTDATA->m_style = wxFONTSTYLE_ITALIC;
271 if (tmp == wxT("O")) M_FONTDATA->m_style = wxFONTSTYLE_ITALIC;
563f868d
GD
272
273 tn.GetNextToken(); // set width
274 tn.GetNextToken(); // add. style
275 tn.GetNextToken(); // pixel size
276
277 tmp = tn.GetNextToken(); // pointsize
278 if (tmp != wxT("*"))
279 {
9b135950 280 long num = wxStrtol (tmp.mb_str(), (wxChar **) NULL, 10);
563f868d
GD
281 M_FONTDATA->m_pointSize = (int)(num / 10);
282 }
283
284 tn.GetNextToken(); // x-res
285 tn.GetNextToken(); // y-res
286
287 tmp = tn.GetNextToken().MakeUpper(); // spacing
288
289 if (tmp == wxT("M"))
0c14b6c3 290 M_FONTDATA->m_family = wxFONTFAMILY_MODERN;
563f868d 291 else if (M_FONTDATA->m_faceName == wxT("TIMES"))
0c14b6c3 292 M_FONTDATA->m_family = wxFONTFAMILY_ROMAN;
563f868d 293 else if (M_FONTDATA->m_faceName == wxT("HELVETICA"))
0c14b6c3 294 M_FONTDATA->m_family = wxFONTFAMILY_SWISS;
563f868d 295 else if (M_FONTDATA->m_faceName == wxT("LUCIDATYPEWRITER"))
0c14b6c3 296 M_FONTDATA->m_family = wxFONTFAMILY_TELETYPE;
563f868d 297 else if (M_FONTDATA->m_faceName == wxT("LUCIDA"))
0c14b6c3 298 M_FONTDATA->m_family = wxFONTFAMILY_DECORATIVE;
563f868d 299 else if (M_FONTDATA->m_faceName == wxT("UTOPIA"))
0c14b6c3 300 M_FONTDATA->m_family = wxFONTFAMILY_SCRIPT;
563f868d
GD
301
302 tn.GetNextToken(); // avg width
303
304 // deal with font encoding
305 M_FONTDATA->m_encoding = enc;
306 if ( M_FONTDATA->m_encoding == wxFONTENCODING_SYSTEM )
307 {
308 wxString registry = tn.GetNextToken().MakeUpper(),
309 encoding = tn.GetNextToken().MakeUpper();
310
9a83f860 311 if ( registry == wxT("ISO8859") )
563f868d
GD
312 {
313 int cp;
314 if ( wxSscanf(encoding, wxT("%d"), &cp) == 1 )
315 {
316 M_FONTDATA->m_encoding =
317 (wxFontEncoding)(wxFONTENCODING_ISO8859_1 + cp - 1);
318 }
319 }
9a83f860 320 else if ( registry == wxT("MICROSOFT") )
563f868d
GD
321 {
322 int cp;
323 if ( wxSscanf(encoding, wxT("cp125%d"), &cp) == 1 )
324 {
325 M_FONTDATA->m_encoding =
326 (wxFontEncoding)(wxFONTENCODING_CP1250 + cp);
327 }
328 }
9a83f860 329 else if ( registry == wxT("KOI8") )
563f868d
GD
330 {
331 M_FONTDATA->m_encoding = wxFONTENCODING_KOI8;
332 }
333 //else: unknown encoding - may be give a warning here?
334 else
96be256b 335 return false;
563f868d 336 }
96be256b 337 return true;
563f868d
GD
338}
339
4bb6408c
JS
340wxFont::~wxFont()
341{
4bb6408c
JS
342}
343
8f884a0d
VZ
344wxGDIRefData *wxFont::CreateGDIRefData() const
345{
346 return new wxFontRefData;
347}
348
349wxGDIRefData *wxFont::CloneGDIRefData(const wxGDIRefData *data) const
350{
5c33522f 351 return new wxFontRefData(*static_cast<const wxFontRefData *>(data));
8f884a0d
VZ
352}
353
93ccaed8
VZ
354// ----------------------------------------------------------------------------
355// change the font attributes
356// ----------------------------------------------------------------------------
4bb6408c
JS
357
358void wxFont::Unshare()
359{
2d120f83
JS
360 // Don't change shared data
361 if (!m_refData)
4bb6408c 362 {
2d120f83
JS
363 m_refData = new wxFontRefData();
364 }
4bb6408c
JS
365 else
366 {
2d120f83
JS
367 wxFontRefData* ref = new wxFontRefData(*(wxFontRefData*)m_refData);
368 UnRef();
369 m_refData = ref;
370 }
4bb6408c
JS
371}
372
373void wxFont::SetPointSize(int pointSize)
374{
375 Unshare();
dfe1eee3 376
4bb6408c 377 M_FONTDATA->m_pointSize = pointSize;
42f30fa2 378 M_FONTDATA->m_nativeFontInfo.GetXFontName().Clear(); // invalid now
4bb6408c
JS
379}
380
0c14b6c3 381void wxFont::SetFamily(wxFontFamily family)
4bb6408c
JS
382{
383 Unshare();
dfe1eee3 384
4bb6408c 385 M_FONTDATA->m_family = family;
42f30fa2 386 M_FONTDATA->m_nativeFontInfo.GetXFontName().Clear(); // invalid now
4bb6408c
JS
387}
388
0c14b6c3 389void wxFont::SetStyle(wxFontStyle style)
4bb6408c
JS
390{
391 Unshare();
dfe1eee3 392
4bb6408c 393 M_FONTDATA->m_style = style;
42f30fa2 394 M_FONTDATA->m_nativeFontInfo.GetXFontName().Clear(); // invalid now
4bb6408c
JS
395}
396
0c14b6c3 397void wxFont::SetWeight(wxFontWeight weight)
4bb6408c
JS
398{
399 Unshare();
dfe1eee3 400
4bb6408c 401 M_FONTDATA->m_weight = weight;
42f30fa2 402 M_FONTDATA->m_nativeFontInfo.GetXFontName().Clear(); // invalid now
4bb6408c
JS
403}
404
85ab460e 405bool wxFont::SetFaceName(const wxString& faceName)
4bb6408c
JS
406{
407 Unshare();
dfe1eee3 408
4bb6408c 409 M_FONTDATA->m_faceName = faceName;
42f30fa2 410 M_FONTDATA->m_nativeFontInfo.GetXFontName().Clear(); // invalid now
85ab460e
VZ
411
412 return wxFontBase::SetFaceName(faceName);
4bb6408c
JS
413}
414
415void wxFont::SetUnderlined(bool underlined)
416{
417 Unshare();
dfe1eee3 418
4bb6408c 419 M_FONTDATA->m_underlined = underlined;
4bb6408c
JS
420}
421
93ccaed8 422void wxFont::SetEncoding(wxFontEncoding encoding)
4bb6408c 423{
93ccaed8
VZ
424 Unshare();
425
426 M_FONTDATA->m_encoding = encoding;
42f30fa2 427 M_FONTDATA->m_nativeFontInfo.GetXFontName().Clear(); // invalid now
93ccaed8
VZ
428}
429
9045ad9d 430void wxFont::DoSetNativeFontInfo(const wxNativeFontInfo& info)
563f868d
GD
431{
432 Unshare();
433
434 M_FONTDATA->m_nativeFontInfo = info;
435}
436
93ccaed8
VZ
437// ----------------------------------------------------------------------------
438// query font attributes
439// ----------------------------------------------------------------------------
440
441int wxFont::GetPointSize() const
442{
a1b806b9 443 wxCHECK_MSG( IsOk(), 0, wxT("invalid font") );
9045ad9d 444
93ccaed8
VZ
445 return M_FONTDATA->m_pointSize;
446}
447
563f868d
GD
448wxString wxFont::GetFaceName() const
449{
a1b806b9 450 wxCHECK_MSG( IsOk(), wxEmptyString, wxT("invalid font") );
563f868d
GD
451
452 return M_FONTDATA->m_faceName ;
453}
454
59b7da02 455wxFontFamily wxFont::DoGetFamily() const
93ccaed8
VZ
456{
457 return M_FONTDATA->m_family;
458}
459
0c14b6c3 460wxFontStyle wxFont::GetStyle() const
93ccaed8 461{
a1b806b9 462 wxCHECK_MSG( IsOk(), wxFONTSTYLE_MAX, wxT("invalid font") );
563f868d 463
93ccaed8
VZ
464 return M_FONTDATA->m_style;
465}
466
0c14b6c3 467wxFontWeight wxFont::GetWeight() const
93ccaed8 468{
a1b806b9 469 wxCHECK_MSG( IsOk(), wxFONTWEIGHT_MAX, wxT("invalid font") );
563f868d 470
93ccaed8
VZ
471 return M_FONTDATA->m_weight;
472}
473
474bool wxFont::GetUnderlined() const
475{
a1b806b9 476 wxCHECK_MSG( IsOk(), false, wxT("invalid font") );
563f868d 477
93ccaed8 478 return M_FONTDATA->m_underlined;
4bb6408c
JS
479}
480
563f868d 481wxFontEncoding wxFont::GetEncoding() const
4bb6408c 482{
a1b806b9 483 wxCHECK_MSG( IsOk(), wxFONTENCODING_DEFAULT, wxT("invalid font") );
563f868d
GD
484
485 return M_FONTDATA->m_encoding;
4bb6408c
JS
486}
487
3bf5a59b 488const wxNativeFontInfo *wxFont::GetNativeFontInfo() const
4bb6408c 489{
a1b806b9 490 wxCHECK_MSG( IsOk(), NULL, wxT("invalid font") );
563f868d 491
7520f3da 492 if(M_FONTDATA->m_nativeFontInfo.GetXFontName().empty())
563f868d
GD
493 GetInternalFont();
494
3bf5a59b 495 return &(M_FONTDATA->m_nativeFontInfo);
4bb6408c
JS
496}
497
93ccaed8
VZ
498// ----------------------------------------------------------------------------
499// real implementation
500// ----------------------------------------------------------------------------
4bb6408c 501
dfc54541
JS
502// Find an existing, or create a new, XFontStruct
503// based on this wxFont and the given scale. Append the
504// font to list in the private data for future reference.
f97c9854 505wxXFont* wxFont::GetInternalFont(double scale, WXDisplay* display) const
dfc54541 506{
a1b806b9 507 if ( !IsOk() )
d3b9f782 508 return NULL;
dfe1eee3 509
2d120f83
JS
510 long intScale = long(scale * 100.0 + 0.5); // key for wxXFont
511 int pointSize = (M_FONTDATA->m_pointSize * 10 * intScale) / 100;
dfe1eee3 512
93ccaed8 513 // search existing fonts first
ac32ba44 514 wxList::compatibility_iterator node = M_FONTDATA->m_fonts.GetFirst();
2d120f83
JS
515 while (node)
516 {
fd304d98 517 wxXFont* f = (wxXFont*) node->GetData();
2d120f83
JS
518 if ((!display || (f->m_display == display)) && (f->m_scale == intScale))
519 return f;
fd304d98 520 node = node->GetNext();
2d120f83 521 }
dfe1eee3 522
93ccaed8 523 // not found, create a new one
996994c7 524 wxString xFontSpec;
0d083705
VZ
525 XFontStruct *font = (XFontStruct *)
526 wxLoadQueryNearestFont(pointSize,
93ccaed8
VZ
527 M_FONTDATA->m_family,
528 M_FONTDATA->m_style,
529 M_FONTDATA->m_weight,
530 M_FONTDATA->m_underlined,
223d09f6 531 wxT(""),
996994c7
MB
532 M_FONTDATA->m_encoding,
533 &xFontSpec);
dfe1eee3 534
93ccaed8 535 if ( !font )
2d120f83 536 {
223d09f6 537 wxFAIL_MSG( wxT("Could not allocate even a default font -- something is wrong.") );
93ccaed8 538
d3b9f782 539 return NULL;
2d120f83 540 }
93ccaed8
VZ
541
542 wxXFont* f = new wxXFont;
996994c7
MB
543#if wxMOTIF_NEW_FONT_HANDLING
544 XFreeFont( (Display*) display, font );
545#else
93ccaed8 546 f->m_fontStruct = (WXFontStructPtr)font;
996994c7 547#endif
93ccaed8
VZ
548 f->m_display = ( display ? display : wxGetDisplay() );
549 f->m_scale = intScale;
7520f3da 550
eb9d223a 551#if wxMOTIF_USE_RENDER_TABLE
da494b40
MB
552 XmRendition rendition;
553 XmRenderTable renderTable;
554 Arg args[5];
555 int count = 0;
556
996994c7 557#if wxMOTIF_NEW_FONT_HANDLING
6991087b 558 char* fontSpec = wxStrdup(xFontSpec.mb_str());
996994c7
MB
559 XtSetArg( args[count], XmNfontName, fontSpec ); ++count;
560 XtSetArg( args[count], XmNfontType, XmFONT_IS_FONTSET ); ++count;
561#else
da494b40 562 XtSetArg( args[count], XmNfont, font ); ++count;
996994c7 563#endif
da494b40
MB
564 XtSetArg( args[count], XmNunderlineType,
565 GetUnderlined() ? XmSINGLE_LINE : XmNO_LINE ); ++count;
566 rendition = XmRenditionCreate( XmGetXmDisplay( (Display*)f->m_display ),
567 (XmStringTag)"",
568 args, count );
569 renderTable = XmRenderTableAddRenditions( NULL, &rendition, 1,
570 XmMERGE_REPLACE );
571
572 f->m_renderTable = (WXRenderTable)renderTable;
996994c7
MB
573 f->m_rendition = (WXRendition)rendition;
574 wxASSERT( f->m_renderTable != NULL );
eb9d223a 575#else // if !wxMOTIF_USE_RENDER_TABLE
996994c7
MB
576 f->m_fontList = XmFontListCreate ((XFontStruct*) font, XmSTRING_DEFAULT_CHARSET);
577 wxASSERT( f->m_fontList != NULL );
da494b40
MB
578#endif
579
996994c7
MB
580 M_FONTDATA->m_fonts.Append(f);
581
93ccaed8 582 return f;
dfc54541
JS
583}
584
996994c7
MB
585#if !wxMOTIF_NEW_FONT_HANDLING
586
93ccaed8 587WXFontStructPtr wxFont::GetFontStruct(double scale, WXDisplay* display) const
dfc54541 588{
93ccaed8 589 wxXFont* f = GetInternalFont(scale, display);
dfe1eee3 590
93ccaed8
VZ
591 return (f ? f->m_fontStruct : (WXFontStructPtr) 0);
592}
dfe1eee3 593
eb9d223a
MB
594#endif
595
596#if !wxMOTIF_USE_RENDER_TABLE
597
93ccaed8
VZ
598WXFontList wxFont::GetFontList(double scale, WXDisplay* display) const
599{
600 wxXFont* f = GetInternalFont(scale, display);
dfe1eee3 601
93ccaed8 602 return (f ? f->m_fontList : (WXFontList) 0);
dfc54541 603}
7ecb8b06 604
eb9d223a 605#else // if wxMOTIF_USE_RENDER_TABLE
da494b40
MB
606
607WXRenderTable wxFont::GetRenderTable(WXDisplay* display) const
608{
609 wxXFont* f = GetInternalFont(1.0, display);
610
eb9d223a 611 return (f ? f->m_renderTable : (WXRenderTable) 0);
da494b40
MB
612}
613
eb9d223a 614#endif // wxMOTIF_USE_RENDER_TABLE
da494b40
MB
615
616WXFontType wxFont::GetFontType(WXDisplay* display) const
617{
eb9d223a 618#if wxMOTIF_USE_RENDER_TABLE
a1b806b9 619 return IsOk() ? GetRenderTable(display) : NULL;
da494b40 620#else
a1b806b9 621 return IsOk() ? GetFontList(1.0, display) : NULL;
da494b40
MB
622#endif
623}
624
73608949
MB
625WXFontType wxFont::GetFontTypeC(WXDisplay* display) const
626{
eb9d223a 627#if wxMOTIF_USE_RENDER_TABLE
a1b806b9 628 return IsOk() ? GetRenderTable(display) : NULL;
73608949 629#else
a1b806b9 630 return IsOk() ? XmFontListCopy( (XmFontList)GetFontList(1.0, display) ) : NULL;
73608949
MB
631#endif
632}
633
da494b40
MB
634/*static*/ WXString wxFont::GetFontTag()
635{
eb9d223a 636#if wxMOTIF_USE_RENDER_TABLE
da494b40
MB
637 return (WXString)XmNrenderTable;
638#else
639 return (WXString)XmNfontList;
640#endif
641}
996994c7 642
105fbe1f 643#if wxMOTIF_USE_RENDER_TABLE
996994c7
MB
644
645WXFontSet wxFont::GetFontSet(double scale, WXDisplay* display) const
646{
647 wxXFont* f = GetInternalFont(scale, display);
648
649 if( !f ) return (WXFontSet) 0;
650
651 Arg args[2];
652 int count = 0;
653
654 XtSetArg( args[count], XmNfont, 0 ); ++count;
655 XmRenditionRetrieve( (XmRendition) f->m_rendition, args, count );
656
657 return (WXFontSet) args[0].value;
658}
659
660void wxGetTextExtent(WXDisplay* display, const wxFont& font, double scale,
661 const wxString& str,
662 int* width, int* height, int* ascent, int* descent)
663{
664 XRectangle ink, logical;
665 WXFontSet fset = font.GetFontSet(scale, display);
7520f3da 666
9b135950 667 XmbTextExtents( (XFontSet)fset, str.mb_str(), str.length(), &ink, &logical);
996994c7
MB
668
669 if( width ) *width = logical.width;
670 if( height ) *height = logical.height;
7520f3da
WS
671 if( ascent ) *ascent = -logical.y;
672 if( descent ) *descent = logical.height + logical.y;
996994c7
MB
673}
674
105fbe1f 675#else // if !wxMOTIF_USE_RENDER_TABLE
996994c7
MB
676
677void wxGetTextExtent(WXDisplay* display, const wxFont& font,
678 double scale, const wxString& str,
679 int* width, int* height, int* ascent, int* descent)
680{
681 WXFontStructPtr pFontStruct = font.GetFontStruct(scale, display);
682
683 int direction, ascent2, descent2;
684 XCharStruct overall;
dd05139a 685 int slen = str.length();
996994c7 686
efb35beb 687 XTextExtents((XFontStruct*) pFontStruct,
5c33522f 688 const_cast<char*>((const char *)str.mb_str()), slen,
996994c7
MB
689 &direction, &ascent2, &descent2, &overall);
690
691 if ( width )
692 *width = (overall.width);
693 if ( height )
694 *height = (ascent2 + descent2);
695 if ( descent )
696 *descent = descent2;
697 if ( ascent )
698 *ascent = ascent2;
699}
700
105fbe1f 701#endif // !wxMOTIF_USE_RENDER_TABLE