]> git.saurik.com Git - wxWidgets.git/blob - src/mac/font.cpp
Misc. Dialog Editor/resource bugs fixed
[wxWidgets.git] / src / mac / font.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: 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 #ifdef __GNUG__
13 #pragma implementation "font.h"
14 #endif
15
16 #include "wx/defs.h"
17 #include "wx/string.h"
18 #include "wx/font.h"
19 #include "wx/gdicmn.h"
20
21 IMPLEMENT_DYNAMIC_CLASS(wxFont, wxGDIObject)
22
23
24
25
26 // ============================================================================
27 // implementation
28 // ============================================================================
29
30 // ----------------------------------------------------------------------------
31 // wxFontRefData
32 // ----------------------------------------------------------------------------
33
34 void wxFontRefData::Init(int pointSize,
35 int family,
36 int style,
37 int weight,
38 bool underlined,
39 const wxString& faceName,
40 wxFontEncoding encoding)
41 {
42 m_style = style;
43 m_pointSize = pointSize;
44 m_family = family;
45 m_style = style;
46 m_weight = weight;
47 m_underlined = underlined;
48 m_faceName = faceName;
49 m_encoding = encoding;
50
51 m_macFontNum = 0 ;
52 m_macFontSize = 0;
53 m_macFontStyle = 0;
54 m_fontId = 0;
55 }
56
57 wxFontRefData::~wxFontRefData()
58 {
59 }
60
61 void wxFontRefData::MacFindFont()
62 {
63 if( m_faceName == "" )
64 {
65 switch( m_family )
66 {
67 case wxDEFAULT :
68 m_macFontNum = ::GetAppFont() ;
69 break ;
70 case wxDECORATIVE :
71 ::GetFNum( "\pTimes" , &m_macFontNum) ;
72 break ;
73 case wxROMAN :
74 ::GetFNum( "\pTimes" , &m_macFontNum) ;
75 break ;
76 case wxSCRIPT :
77 ::GetFNum( "\pTimes" , &m_macFontNum) ;
78 break ;
79 case wxSWISS :
80 ::GetFNum( "\pHelvetica" , &m_macFontNum) ;
81 break ;
82 case wxMODERN :
83 ::GetFNum( "\pMonaco" , &m_macFontNum) ;
84 break ;
85 }
86 }
87 else
88 {
89 if ( m_faceName == "systemfont" )
90 m_macFontNum = ::GetSysFont() ;
91 else if ( m_faceName == "applicationfont" )
92 m_macFontNum = ::GetAppFont() ;
93 else
94 {
95 strcpy(wxBuffer, m_faceName);
96 C2PStr(wxBuffer);
97 ::GetFNum( (unsigned char*) wxBuffer, &m_macFontNum);
98 }
99 }
100
101 m_macFontStyle = 0;
102 if (m_weight == wxBOLD)
103 m_macFontStyle |= bold;
104 if (m_style == wxITALIC || m_style == wxSLANT)
105 m_macFontStyle |= italic;
106 if (m_underlined)
107 m_macFontStyle |= underline;
108 m_macFontSize = m_pointSize ;
109 }
110
111 // ----------------------------------------------------------------------------
112 // wxFont
113 // ----------------------------------------------------------------------------
114
115 void wxFont::Init()
116 {
117 if ( wxTheFontList )
118 wxTheFontList->Append(this);
119 }
120
121 bool wxFont::Create(int pointSize,
122 int family,
123 int style,
124 int weight,
125 bool underlined,
126 const wxString& faceName,
127 wxFontEncoding encoding)
128 {
129 UnRef();
130 m_refData = new wxFontRefData(pointSize, family, style, weight,
131 underlined, faceName, encoding);
132
133 RealizeResource();
134
135 return TRUE;
136 }
137
138 wxFont::~wxFont()
139 {
140 if (wxTheFontList)
141 wxTheFontList->DeleteObject(this);
142 }
143
144 bool wxFont::RealizeResource()
145 {
146 M_FONTDATA->MacFindFont() ;
147 return TRUE;
148 }
149
150 void wxFont::SetEncoding(wxFontEncoding encoding)
151 {
152 Unshare();
153
154 M_FONTDATA->m_encoding = encoding;
155
156 RealizeResource();
157 }
158
159 void wxFont::Unshare()
160 {
161 // Don't change shared data
162 if (!m_refData)
163 {
164 m_refData = new wxFontRefData();
165 }
166 else
167 {
168 wxFontRefData* ref = new wxFontRefData(*(wxFontRefData*)m_refData);
169 UnRef();
170 m_refData = ref;
171 }
172 }
173
174 void wxFont::SetPointSize(int pointSize)
175 {
176 Unshare();
177
178 M_FONTDATA->m_pointSize = pointSize;
179
180 RealizeResource();
181 }
182
183 void wxFont::SetFamily(int family)
184 {
185 Unshare();
186
187 M_FONTDATA->m_family = family;
188
189 RealizeResource();
190 }
191
192 void wxFont::SetStyle(int style)
193 {
194 Unshare();
195
196 M_FONTDATA->m_style = style;
197
198 RealizeResource();
199 }
200
201 void wxFont::SetWeight(int weight)
202 {
203 Unshare();
204
205 M_FONTDATA->m_weight = weight;
206
207 RealizeResource();
208 }
209
210 void wxFont::SetFaceName(const wxString& faceName)
211 {
212 Unshare();
213
214 M_FONTDATA->m_faceName = faceName;
215
216 RealizeResource();
217 }
218
219 void wxFont::SetUnderlined(bool underlined)
220 {
221 Unshare();
222
223 M_FONTDATA->m_underlined = underlined;
224
225 RealizeResource();
226 }
227
228 // ----------------------------------------------------------------------------
229 // accessors
230 // ----------------------------------------------------------------------------
231
232 int wxFont::GetPointSize() const
233 {
234 return M_FONTDATA->m_pointSize;
235 }
236
237 int wxFont::GetFamily() const
238 {
239 return M_FONTDATA->m_family;
240 }
241
242 int wxFont::GetStyle() const
243 {
244 return M_FONTDATA->m_style;
245 }
246
247 int wxFont::GetWeight() const
248 {
249 return M_FONTDATA->m_weight;
250 }
251
252 bool wxFont::GetUnderlined() const
253 {
254 return M_FONTDATA->m_underlined;
255 }
256
257 wxString wxFont::GetFaceName() const
258 {
259 wxString str;
260 if ( M_FONTDATA )
261 str = M_FONTDATA->m_faceName ;
262 return str;
263 }
264
265 wxFontEncoding wxFont::GetEncoding() const
266 {
267 return M_FONTDATA->m_encoding;
268 }
269