]> git.saurik.com Git - wxWidgets.git/blob - src/cocoa/font.mm
Replace most of the fields in wxFontRefData with one wxNativeFontInfo.
[wxWidgets.git] / src / cocoa / font.mm
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/cocoa/font.cpp
3 // Purpose: wxFont class
4 // Author: AUTHOR
5 // Modified by:
6 // Created: ??/??/98
7 // RCS-ID: $Id$
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #include "wx/font.h"
15
16 #ifndef WX_PRECOMP
17 #include "wx/string.h"
18 #include "wx/gdicmn.h"
19 #endif
20
21 #include "wx/fontutil.h"
22 #include "wx/encinfo.h"
23
24 class WXDLLEXPORT wxFontRefData: public wxGDIRefData
25 {
26 friend class WXDLLIMPEXP_FWD_CORE wxFont;
27 public:
28 wxFontRefData()
29 : m_fontId(0)
30 {
31 Init(10, wxDEFAULT, wxNORMAL, wxNORMAL, FALSE,
32 wxT("Geneva"), wxFONTENCODING_DEFAULT);
33 }
34
35 wxFontRefData(const wxFontRefData& data)
36 : wxGDIRefData()
37 , m_fontId(data.m_fontId)
38 , m_info(data.m_info)
39 {
40 }
41
42 wxFontRefData(int size,
43 int family,
44 int style,
45 int weight,
46 bool underlined,
47 const wxString& faceName,
48 wxFontEncoding encoding)
49 : m_fontId(0)
50 {
51 Init(size, family, style, weight, underlined, faceName, encoding);
52 }
53
54 virtual ~wxFontRefData();
55 protected:
56 // common part of all ctors
57 void Init(int size,
58 int family,
59 int style,
60 int weight,
61 bool underlined,
62 const wxString& faceName,
63 wxFontEncoding encoding);
64
65 // font characterstics
66 int m_fontId;
67 wxNativeFontInfo m_info;
68
69 public:
70 };
71
72 IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject)
73
74 void wxFontRefData::Init(int size, int family, int style, int weight, bool underlined, const wxString& faceName, wxFontEncoding encoding)
75 {
76 m_info.pointSize = size;
77 m_info.family = static_cast<wxFontFamily>(family);
78 m_info.style = static_cast<wxFontStyle>(style);
79 m_info.weight = static_cast<wxFontWeight>(weight);
80 m_info.underlined = underlined;
81 m_info.faceName = faceName;
82 m_info.encoding = encoding;
83 }
84
85 wxFontRefData::~wxFontRefData()
86 {
87 // TODO: delete font data
88 }
89
90 #define M_FONTDATA ((wxFontRefData*)m_refData)
91
92 bool wxFont::Create(const wxNativeFontInfo&)
93 {
94 return false;
95 }
96
97 void wxFont::SetEncoding(wxFontEncoding)
98 {
99 }
100
101 wxFontEncoding wxFont::GetEncoding() const
102 {
103 return wxFontEncoding();
104 }
105
106 int wxFont::GetPointSize() const
107 {
108 return 0;
109 }
110
111 bool wxFont::GetUnderlined() const
112 {
113 if(M_FONTDATA)
114 return M_FONTDATA->m_info.underlined;
115 else
116 return false;
117 }
118
119 int wxFont::GetStyle() const
120 {
121 return 0;
122 }
123
124 int wxFont::GetFamily() const
125 {
126 return 0;
127 }
128
129 int wxFont::GetWeight() const
130 {
131 return 0;
132 }
133
134 const wxNativeFontInfo *wxFont::GetNativeFontInfo() const
135 {
136 wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
137 return &M_FONTDATA->m_info;
138 }
139
140 bool wxFont::Create(int pointSize, int family, int style, int weight, bool underlined, const wxString& faceName, wxFontEncoding encoding)
141 {
142 UnRef();
143 m_refData = new wxFontRefData(pointSize, family, style, weight, underlined, faceName, encoding);
144
145 RealizeResource();
146
147 return true;
148 }
149
150 wxFont::~wxFont()
151 {
152 }
153
154 bool wxFont::RealizeResource()
155 {
156 // TODO: create the font (if there is a native font object)
157 return false;
158 }
159
160 void wxFont::Unshare()
161 {
162 // Don't change shared data
163 if (!m_refData)
164 {
165 m_refData = new wxFontRefData();
166 }
167 else
168 {
169 wxFontRefData* ref = new wxFontRefData(*(wxFontRefData*)m_refData);
170 UnRef();
171 m_refData = ref;
172 }
173 }
174
175 void wxFont::SetPointSize(int pointSize)
176 {
177 Unshare();
178
179 M_FONTDATA->m_info.pointSize = pointSize;
180
181 RealizeResource();
182 }
183
184 void wxFont::SetFamily(int family)
185 {
186 Unshare();
187
188 M_FONTDATA->m_info.family = static_cast<wxFontFamily>(family);
189
190 RealizeResource();
191 }
192
193 void wxFont::SetStyle(int style)
194 {
195 Unshare();
196
197 M_FONTDATA->m_info.style = static_cast<wxFontStyle>(style);
198
199 RealizeResource();
200 }
201
202 void wxFont::SetWeight(int weight)
203 {
204 Unshare();
205
206 M_FONTDATA->m_info.weight = static_cast<wxFontWeight>(weight);
207
208 RealizeResource();
209 }
210
211 bool wxFont::SetFaceName(const wxString& faceName)
212 {
213 Unshare();
214
215 M_FONTDATA->m_info.faceName = faceName;
216
217 RealizeResource();
218
219 return wxFontBase::SetFaceName(faceName);
220 }
221
222 void wxFont::SetUnderlined(bool underlined)
223 {
224 Unshare();
225
226 M_FONTDATA->m_info.underlined = underlined;
227
228 RealizeResource();
229 }
230
231 /* New font system */
232 wxString wxFont::GetFaceName() const
233 {
234 wxString str;
235 if (M_FONTDATA)
236 str = M_FONTDATA->m_info.faceName;
237 return str;
238 }
239
240 // vim:sts=4:sw=4:et