More Motif stuff
[wxWidgets.git] / include / wx / motif / font.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: font.h
3 // Purpose: wxFont class
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 17/09/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_FONT_H_
13 #define _WX_FONT_H_
14
15 #ifdef __GNUG__
16 #pragma interface "font.h"
17 #endif
18
19 #include "wx/gdiobj.h"
20 #include "wx/list.h"
21
22 class WXDLLEXPORT wxFont;
23
24 class WXDLLEXPORT wxFontRefData: public wxGDIRefData
25 {
26 friend class WXDLLEXPORT wxFont;
27 public:
28 wxFontRefData();
29 wxFontRefData(const wxFontRefData& data);
30 ~wxFontRefData();
31 protected:
32 int m_pointSize;
33 int m_family;
34 int m_style;
35 int m_weight;
36 bool m_underlined;
37 wxString m_faceName;
38
39 // A list of XFontStructs indexed by scale (*100)
40 wxList m_fontsByScale;
41 };
42
43 #define M_FONTDATA ((wxFontRefData *)m_refData)
44
45 WXDLLEXPORT_DATA(extern const char*) wxEmptyString;
46
47 // Font
48 class WXDLLEXPORT wxFont: public wxGDIObject
49 {
50 DECLARE_DYNAMIC_CLASS(wxFont)
51 public:
52 wxFont();
53 wxFont(int pointSize, int family, int style, int weight, bool underlined = FALSE, const wxString& faceName = wxEmptyString);
54 inline wxFont(const wxFont& font) { Ref(font); }
55 inline wxFont(const wxFont* font) { if (font) Ref(*font); }
56
57 ~wxFont();
58
59 bool Create(int pointSize, int family, int style, int weight, bool underlined = FALSE, const wxString& faceName = wxEmptyString);
60
61 virtual bool Ok() const { return (m_refData != NULL) ; }
62
63 inline int GetPointSize() const { return M_FONTDATA->m_pointSize; }
64 inline int GetFamily() const { return M_FONTDATA->m_family; }
65 inline int GetStyle() const { return M_FONTDATA->m_style; }
66 inline int GetWeight() const { return M_FONTDATA->m_weight; }
67 wxString GetFamilyString() const ;
68 wxString GetFaceName() const ;
69 wxString GetStyleString() const ;
70 wxString GetWeightString() const ;
71 inline bool GetUnderlined() const { return M_FONTDATA->m_underlined; }
72
73 void SetPointSize(int pointSize);
74 void SetFamily(int family);
75 void SetStyle(int style);
76 void SetWeight(int weight);
77 void SetFaceName(const wxString& faceName);
78 void SetUnderlined(bool underlined);
79
80 inline wxFont& operator = (const wxFont& font) { if (*this == font) return (*this); Ref(font); return *this; }
81 inline bool operator == (const wxFont& font) { return m_refData == font.m_refData; }
82 inline bool operator != (const wxFont& font) { return m_refData != font.m_refData; }
83
84 // Implementation
85
86 // Find an existing, or create a new, XFontStruct
87 // based on this wxFont and the given scale. Append the
88 // font to list in the private data for future reference.
89
90 // TODO This is a very basic implementation, that doesn't
91 // allow for different facenames, and also doesn't do a mapping
92 // between 'standard' facenames (e.g. Arial, Helvetica, Times Roman etc.)
93 // and the fonts that are available on a particular system.
94 // Maybe we need to scan the user's machine to build up a profile
95 // of the fonts and a mapping file.
96
97 WXFontStructPtr FindOrCreateFontStruct(double scale = 1.0);
98 WXFontStructPtr LoadQueryFont(int pointSize, int family, int style,
99 int weight, bool underlined);
100 protected:
101 bool RealizeResource();
102 void Unshare();
103 };
104
105 #endif
106 // _WX_FONT_H_