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