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