+public:
+ // constructors
+ wxFontRefData()
+ {
+ Init(-1, wxSize(0,0), false, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL,
+ wxFONTWEIGHT_NORMAL, false, wxEmptyString,
+ wxFONTENCODING_DEFAULT);
+ }
+
+ wxFontRefData(int size,
+ const wxSize& pixelSize,
+ bool sizeUsingPixels,
+ wxFontFamily family,
+ wxFontStyle style,
+ wxFontWeight weight,
+ bool underlined,
+ const wxString& faceName,
+ wxFontEncoding encoding)
+ {
+ Init(size, pixelSize, sizeUsingPixels, family, style, weight,
+ underlined, faceName, encoding);
+ }
+
+ wxFontRefData(const wxNativeFontInfo& info, WXHFONT hFont = 0)
+ {
+ Init(info, hFont);
+ }
+
+ wxFontRefData(const wxFontRefData& data) : wxGDIRefData()
+ {
+ Init(data.m_nativeFontInfo);
+ }
+
+ virtual ~wxFontRefData();
+
+ // operations
+ bool Alloc();
+
+ void Free();
+
+ // all wxFont accessors
+ int GetPointSize() const
+ {
+ return m_nativeFontInfo.GetPointSize();
+ }
+
+ wxSize GetPixelSize() const
+ {
+ return m_nativeFontInfo.GetPixelSize();
+ }
+
+ bool IsUsingSizeInPixels() const
+ {
+ return m_sizeUsingPixels;
+ }
+
+ wxFontFamily GetFamily() const
+ {
+ return m_nativeFontInfo.GetFamily();
+ }
+
+ wxFontStyle GetStyle() const
+ {
+ return m_nativeFontInfo.GetStyle();
+ }
+
+ wxFontWeight GetWeight() const
+ {
+ return m_nativeFontInfo.GetWeight();
+ }
+
+ bool GetUnderlined() const
+ {
+ return m_nativeFontInfo.GetUnderlined();
+ }
+
+ wxString GetFaceName() const
+ {
+ return m_nativeFontInfo.GetFaceName();
+ }
+
+ wxFontEncoding GetEncoding() const
+ {
+ return m_nativeFontInfo.GetEncoding();
+ }
+
+ WXHFONT GetHFONT() const
+ {
+ if ( !m_hFont )
+ const_cast<wxFontRefData *>(this)->Alloc();
+
+ return (WXHFONT)m_hFont;
+ }
+
+ bool HasHFONT() const
+ {
+ return m_hFont != 0;
+ }
+
+ // ... and setters: notice that all of them invalidate the currently
+ // allocated HFONT, if any, so that the next call to GetHFONT() recreates a
+ // new one
+ void SetPointSize(int pointSize)
+ {
+ Free();
+
+ m_nativeFontInfo.SetPointSize(pointSize);
+ m_sizeUsingPixels = false;
+ }
+
+ void SetPixelSize(const wxSize& pixelSize)
+ {
+ Free();
+
+ m_nativeFontInfo.SetPixelSize(pixelSize);
+ m_sizeUsingPixels = true;
+ }
+
+ void SetFamily(wxFontFamily family)
+ {
+ Free();
+
+ m_nativeFontInfo.SetFamily(family);
+ }
+
+ void SetStyle(wxFontStyle style)
+ {
+ Free();
+
+ m_nativeFontInfo.SetStyle(style);
+ }
+
+ void SetWeight(wxFontWeight weight)
+ {
+ Free();
+
+ m_nativeFontInfo.SetWeight(weight);
+ }
+
+ bool SetFaceName(const wxString& faceName)
+ {
+ Free();
+
+ return m_nativeFontInfo.SetFaceName(faceName);
+ }
+
+ void SetUnderlined(bool underlined)
+ {
+ Free();
+
+ m_nativeFontInfo.SetUnderlined(underlined);
+ }
+
+ void SetEncoding(wxFontEncoding encoding)
+ {
+ Free();
+
+ m_nativeFontInfo.SetEncoding(encoding);
+ }
+
+ const wxNativeFontInfo& GetNativeFontInfo() const
+ { return m_nativeFontInfo; }
+
+ void SetNativeFontInfo(const wxNativeFontInfo& nativeFontInfo)
+ {
+ Free();
+
+ m_nativeFontInfo = nativeFontInfo;
+ }
+
+protected:
+ // common part of all ctors
+ void Init(int size,
+ const wxSize& pixelSize,
+ bool sizeUsingPixels,
+ wxFontFamily family,
+ wxFontStyle style,
+ wxFontWeight weight,
+ bool underlined,
+ const wxString& faceName,
+ wxFontEncoding encoding);
+
+ void Init(const wxNativeFontInfo& info, WXHFONT hFont = 0);
+
+ // are we using m_nativeFontInfo.lf.lfHeight for point size or pixel size?
+ bool m_sizeUsingPixels;
+
+ // Windows font handle, created on demand in GetHFONT()
+ HFONT m_hFont;
+
+ // Native font info
+ wxNativeFontInfo m_nativeFontInfo;
+};
+
+#define M_FONTDATA ((wxFontRefData*)m_refData)
+
+// ============================================================================
+// implementation
+// ============================================================================
+
+// ----------------------------------------------------------------------------
+// wxFontRefData
+// ----------------------------------------------------------------------------
+
+void wxFontRefData::Init(int pointSize,
+ const wxSize& pixelSize,
+ bool sizeUsingPixels,
+ wxFontFamily family,
+ wxFontStyle style,
+ wxFontWeight weight,
+ bool underlined,
+ const wxString& faceName,
+ wxFontEncoding encoding)
+{
+ m_hFont = NULL;
+
+ m_sizeUsingPixels = sizeUsingPixels;
+ if ( m_sizeUsingPixels )
+ SetPixelSize(pixelSize);
+ else
+ SetPointSize(pointSize);
+
+ SetStyle(style);
+ SetWeight(weight);
+ SetUnderlined(underlined);
+
+ // set the family/facename
+ SetFamily(family);
+ if ( !faceName.empty() )
+ SetFaceName(faceName);
+
+ // deal with encoding now (it may override the font family and facename
+ // so do it after setting them)
+ SetEncoding(encoding);
+}
+
+void wxFontRefData::Init(const wxNativeFontInfo& info, WXHFONT hFont)
+{
+ // hFont may be zero, or it be passed in case we really want to
+ // use the exact font created in the underlying system
+ // (for example where we can't guarantee conversion from HFONT
+ // to LOGFONT back to HFONT)
+ m_hFont = (HFONT)hFont;
+ m_nativeFontInfo = info;
+
+ // TODO: m_sizeUsingPixels?
+}
+
+wxFontRefData::~wxFontRefData()
+{
+ Free();