]> git.saurik.com Git - wxWidgets.git/blob - include/wx/motif/font.h
Accelerators implemented for wxMotif; some wxComboBox stupidities cured
[wxWidgets.git] / include / wx / motif / font.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: font.h
3 // Purpose: wxFont class
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 17/09/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_FONT_H_
13 #define _WX_FONT_H_
14
15 #ifdef __GNUG__
16 #pragma interface "font.h"
17 #endif
18
19 #include "wx/gdiobj.h"
20 #include "wx/list.h"
21
22 class WXDLLEXPORT wxFont;
23
24 // For every wxFont, there must be a font for each display and scale requested.
25 // So these objects are stored in wxFontRefData::m_fonts
26 class WXDLLEXPORT wxXFont: public wxObject
27 {
28 public:
29 wxXFont();
30 ~wxXFont();
31
32 WXFontStructPtr m_fontStruct; // XFontStruct
33 WXFontList m_fontList; // Motif XmFontList
34 WXDisplay* m_display; // XDisplay
35 int m_scale; // Scale * 100
36 };
37
38 class WXDLLEXPORT wxFontRefData: public wxGDIRefData
39 {
40 friend class WXDLLEXPORT wxFont;
41 public:
42 wxFontRefData();
43 wxFontRefData(const wxFontRefData& data);
44 ~wxFontRefData();
45 protected:
46 int m_pointSize;
47 int m_family;
48 int m_style;
49 int m_weight;
50 bool m_underlined;
51 wxString m_faceName;
52
53 // A list of wxXFonts
54 wxList m_fonts;
55 };
56
57 #define M_FONTDATA ((wxFontRefData *)m_refData)
58
59 WXDLLEXPORT_DATA(extern const char*) wxEmptyString;
60
61 // Font
62 class WXDLLEXPORT wxFont: public wxGDIObject
63 {
64 DECLARE_DYNAMIC_CLASS(wxFont)
65 public:
66 wxFont();
67 wxFont(int pointSize, int family, int style, int weight, bool underlined = FALSE, const wxString& faceName = wxEmptyString);
68 inline wxFont(const wxFont& font) { Ref(font); }
69 inline wxFont(const wxFont* font) { if (font) Ref(*font); }
70
71 ~wxFont();
72
73 bool Create(int pointSize, int family, int style, int weight, bool underlined = FALSE, const wxString& faceName = wxEmptyString);
74
75 virtual bool Ok() const { return (m_refData != NULL) ; }
76
77 inline int GetPointSize() const { return M_FONTDATA->m_pointSize; }
78 inline int GetFamily() const { return M_FONTDATA->m_family; }
79 inline int GetStyle() const { return M_FONTDATA->m_style; }
80 inline int GetWeight() const { return M_FONTDATA->m_weight; }
81 wxString GetFamilyString() const ;
82 wxString GetFaceName() const ;
83 wxString GetStyleString() const ;
84 wxString GetWeightString() const ;
85 inline bool GetUnderlined() const { return M_FONTDATA->m_underlined; }
86
87 void SetPointSize(int pointSize);
88 void SetFamily(int family);
89 void SetStyle(int style);
90 void SetWeight(int weight);
91 void SetFaceName(const wxString& faceName);
92 void SetUnderlined(bool underlined);
93
94 inline wxFont& operator = (const wxFont& font) { if (*this == font) return (*this); Ref(font); return *this; }
95 inline bool operator == (const wxFont& font) { return m_refData == font.m_refData; }
96 inline bool operator != (const wxFont& font) { return m_refData != font.m_refData; }
97
98 // Implementation
99
100 // Find an existing, or create a new, XFontStruct
101 // based on this wxFont and the given scale. Append the
102 // font to list in the private data for future reference.
103
104 // TODO This is a fairly basic implementation, that doesn't
105 // allow for different facenames, and also doesn't do a mapping
106 // between 'standard' facenames (e.g. Arial, Helvetica, Times Roman etc.)
107 // and the fonts that are available on a particular system.
108 // Maybe we need to scan the user's machine to build up a profile
109 // of the fonts and a mapping file.
110
111 // Return font struct, and optionally the Motif font list
112 wxXFont* GetInternalFont(double scale = 1.0, WXDisplay* display = NULL) const;
113
114 // These two are helper functions for convenient access of the above.
115 inline WXFontStructPtr GetFontStruct(double scale = 1.0, WXDisplay* display = NULL) const
116 {
117 wxXFont* f = GetInternalFont(scale, display);
118 return (f ? f->m_fontStruct : (WXFontStructPtr) 0);
119 }
120 WXFontList GetFontList(double scale = 1.0, WXDisplay* display = NULL) const
121 {
122 wxXFont* f = GetInternalFont(scale, display);
123 return (f ? f->m_fontList : (WXFontList) 0);
124 }
125
126 WXFontStructPtr LoadQueryFont(int pointSize, int family, int style,
127 int weight, bool underlined) const;
128 protected:
129 bool RealizeResource();
130 void Unshare();
131 };
132
133 #endif
134 // _WX_FONT_H_