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