]> git.saurik.com Git - wxWidgets.git/blob - src/stubs/font.cpp
SN: Added #pragma implementation needed by GCC - expect more to come
[wxWidgets.git] / src / stubs / 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 wxFontRefData::wxFontRefData()
24 {
25 m_style = 0;
26 m_pointSize = 0;
27 m_family = 0;
28 m_style = 0;
29 m_weight = 0;
30 m_underlined = 0;
31 m_faceName = "";
32 /* TODO
33 m_hFont = 0;
34 */
35 }
36
37 wxFontRefData::wxFontRefData(const wxFontRefData& data)
38 {
39 m_style = data.m_style;
40 m_pointSize = data.m_pointSize;
41 m_family = data.m_family;
42 m_style = data.m_style;
43 m_weight = data.m_weight;
44 m_underlined = data.m_underlined;
45 m_faceName = data.m_faceName;
46 /* TODO
47 m_hFont = 0;
48 */
49 }
50
51 wxFontRefData::~wxFontRefData()
52 {
53 // TODO: delete font data
54 }
55
56 wxFont::wxFont()
57 {
58 if ( wxTheFontList )
59 wxTheFontList->Append(this);
60 }
61
62 wxFont::wxFont(int pointSize, int family, int style, int weight, bool underlined, const wxString& faceName)
63 {
64 Create(pointSize, family, style, weight, underlined, faceName);
65
66 if ( wxTheFontList )
67 wxTheFontList->Append(this);
68 }
69
70 bool wxFont::Create(int pointSize, int family, int style, int weight, bool underlined, const wxString& faceName)
71 {
72 UnRef();
73 m_refData = new wxFontRefData;
74
75 M_FONTDATA->m_family = family;
76 M_FONTDATA->m_style = style;
77 M_FONTDATA->m_weight = weight;
78 M_FONTDATA->m_pointSize = pointSize;
79 M_FONTDATA->m_underlined = underlined;
80 M_FONTDATA->m_faceName = faceName;
81
82 RealizeResource();
83
84 return TRUE;
85 }
86
87 wxFont::~wxFont()
88 {
89 if (wxTheFontList)
90 wxTheFontList->DeleteObject(this);
91 }
92
93 bool wxFont::RealizeResource()
94 {
95 // TODO: create the font (if there is a native font object)
96 return FALSE;
97 }
98
99 void wxFont::Unshare()
100 {
101 // Don't change shared data
102 if (!m_refData)
103 {
104 m_refData = new wxFontRefData();
105 }
106 else
107 {
108 wxFontRefData* ref = new wxFontRefData(*(wxFontRefData*)m_refData);
109 UnRef();
110 m_refData = ref;
111 }
112 }
113
114 void wxFont::SetPointSize(int pointSize)
115 {
116 Unshare();
117
118 M_FONTDATA->m_pointSize = pointSize;
119
120 RealizeResource();
121 }
122
123 void wxFont::SetFamily(int family)
124 {
125 Unshare();
126
127 M_FONTDATA->m_family = family;
128
129 RealizeResource();
130 }
131
132 void wxFont::SetStyle(int style)
133 {
134 Unshare();
135
136 M_FONTDATA->m_style = style;
137
138 RealizeResource();
139 }
140
141 void wxFont::SetWeight(int weight)
142 {
143 Unshare();
144
145 M_FONTDATA->m_weight = weight;
146
147 RealizeResource();
148 }
149
150 void wxFont::SetFaceName(const wxString& faceName)
151 {
152 Unshare();
153
154 M_FONTDATA->m_faceName = faceName;
155
156 RealizeResource();
157 }
158
159 void wxFont::SetUnderlined(bool underlined)
160 {
161 Unshare();
162
163 M_FONTDATA->m_underlined = underlined;
164
165 RealizeResource();
166 }
167
168 wxString wxFont::GetFamilyString() const
169 {
170 wxString fam("");
171 switch (GetFamily())
172 {
173 case wxDECORATIVE:
174 fam = "wxDECORATIVE";
175 break;
176 case wxROMAN:
177 fam = "wxROMAN";
178 break;
179 case wxSCRIPT:
180 fam = "wxSCRIPT";
181 break;
182 case wxSWISS:
183 fam = "wxSWISS";
184 break;
185 case wxMODERN:
186 fam = "wxMODERN";
187 break;
188 case wxTELETYPE:
189 fam = "wxTELETYPE";
190 break;
191 default:
192 fam = "wxDEFAULT";
193 break;
194 }
195 return fam;
196 }
197
198 /* New font system */
199 wxString wxFont::GetFaceName() const
200 {
201 wxString str("");
202 if (M_FONTDATA)
203 str = M_FONTDATA->m_faceName ;
204 return str;
205 }
206
207 wxString wxFont::GetStyleString() const
208 {
209 wxString styl("");
210 switch (GetStyle())
211 {
212 case wxITALIC:
213 styl = "wxITALIC";
214 break;
215 case wxSLANT:
216 styl = "wxSLANT";
217 break;
218 default:
219 styl = "wxNORMAL";
220 break;
221 }
222 return styl;
223 }
224
225 wxString wxFont::GetWeightString() const
226 {
227 wxString w("");
228 switch (GetWeight())
229 {
230 case wxBOLD:
231 w = "wxBOLD";
232 break;
233 case wxLIGHT:
234 w = "wxLIGHT";
235 break;
236 default:
237 w = "wxNORMAL";
238 break;
239 }
240 return w;
241 }
242