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