]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/font.cpp
rename wxDECLARE_LOCAL_EVENT to just wxDECLARE_EVENT
[wxWidgets.git] / src / msw / font.cpp
index 4d373edc8b1dfe6537e72708d3815da7b8349c5a..ed8728be509a700253436f4bbfbfd800f3a05f7d 100644 (file)
 #include "wx/fontutil.h"
 #include "wx/fontmap.h"
 
+#ifndef __WXWINCE__
+    #include "wx/sysopt.h"
+#endif
+
 #include "wx/tokenzr.h"
 
 #if wxUSE_EXTENDED_RTTI
@@ -112,9 +116,9 @@ public:
     wxFontRefData(int size,
                   const wxSize& pixelSize,
                   bool sizeUsingPixels,
-                  int family,
-                  int style,
-                  int weight,
+                  wxFontFamily family,
+                  wxFontStyle style,
+                  wxFontWeight weight,
                   bool underlined,
                   const wxString& faceName,
                   wxFontEncoding encoding)
@@ -167,18 +171,18 @@ public:
         return m_nativeFontInfoOk ? true : m_sizeUsingPixels;
     }
 
-    int GetFamily() const
+    wxFontFamily GetFamily() const
     {
         return m_family;
     }
 
-    int GetStyle() const
+    wxFontStyle GetStyle() const
     {
         return m_nativeFontInfoOk ? m_nativeFontInfo.GetStyle()
                                   : m_style;
     }
 
-    int GetWeight() const
+    wxFontWeight GetWeight() const
     {
         return m_nativeFontInfoOk ? m_nativeFontInfo.GetWeight()
                                   : m_weight;
@@ -210,7 +214,7 @@ public:
     WXHFONT GetHFONT(const wxFont *font) const
     {
         if ( !m_hFont )
-            wx_const_cast(wxFontRefData *, this)->Alloc(font);
+            const_cast<wxFontRefData *>(this)->Alloc(font);
 
         return (WXHFONT)m_hFont;
     }
@@ -253,14 +257,14 @@ public:
         }
     }
 
-    void SetFamily(int family)
+    void SetFamily(wxFontFamily family)
     {
         Free();
 
         m_family = family;
     }
 
-    void SetStyle(int style)
+    void SetStyle(wxFontStyle style)
     {
         Free();
 
@@ -270,7 +274,7 @@ public:
             m_style = style;
     }
 
-    void SetWeight(int weight)
+    void SetWeight(wxFontWeight weight)
     {
         Free();
 
@@ -318,16 +322,21 @@ public:
         { return m_nativeFontInfo; }
 
     void SetNativeFontInfo(const wxNativeFontInfo& nativeFontInfo)
-        { Free(); m_nativeFontInfo = nativeFontInfo; }
+    {
+        Free();
+
+        m_nativeFontInfo = nativeFontInfo;
+        m_nativeFontInfoOk = true;
+    }
 
 protected:
     // common part of all ctors
     void Init(int size,
               const wxSize& pixelSize,
               bool sizeUsingPixels,
-              int family,
-              int style,
-              int weight,
+              wxFontFamily family,
+              wxFontStyle style,
+              wxFontWeight weight,
               bool underlined,
               const wxString& faceName,
               wxFontEncoding encoding);
@@ -338,9 +347,9 @@ protected:
     int           m_pointSize;
     wxSize        m_pixelSize;
     bool          m_sizeUsingPixels;
-    int           m_family;
-    int           m_style;
-    int           m_weight;
+    wxFontFamily  m_family;
+    wxFontStyle   m_style;
+    wxFontWeight  m_weight;
     bool          m_underlined;
     wxString      m_faceName;
     wxFontEncoding m_encoding;
@@ -366,9 +375,9 @@ protected:
 void wxFontRefData::Init(int pointSize,
                          const wxSize& pixelSize,
                          bool sizeUsingPixels,
-                         int family,
-                         int style,
-                         int weight,
+                         wxFontFamily family,
+                         wxFontStyle style,
+                         wxFontWeight weight,
                          bool underlined,
                          const wxString& faceName,
                          wxFontEncoding encoding)
@@ -401,7 +410,7 @@ void wxFontRefData::Init(const wxNativeFontInfo& info, WXHFONT hFont)
     m_nativeFontInfo = info;
     // This is the best we can do since we don't have the
     // correct information at this point.
-    m_family = wxSWISS;
+    m_family = wxFONTFAMILY_SWISS;
 }
 
 wxFontRefData::~wxFontRefData()
@@ -448,12 +457,16 @@ void wxNativeFontInfo::Init()
 {
     wxZeroMemory(lf);
 
-    // we get better font quality if we use this instead of DEFAULT_QUALITY
-    // apparently without any drawbacks
+    // we get better font quality if we use PROOF_QUALITY instead of
+    // DEFAULT_QUALITY but some fonts (e.g. "Terminal 6pt") are not available
+    // then so we allow to set a global option to choose between quality and
+    // wider font selection
 #ifdef __WXWINCE__
     lf.lfQuality = CLEARTYPE_QUALITY;
 #else
-    lf.lfQuality = PROOF_QUALITY;
+    lf.lfQuality = wxSystemOptions::GetOptionInt(_T("msw.font.no-proof-quality"))
+                    ? DEFAULT_QUALITY
+                    : PROOF_QUALITY;
 #endif
 }
 
@@ -463,13 +476,14 @@ int wxNativeFontInfo::GetPointSize() const
     //        for printing!
     const int ppInch = ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY);
 
-    return (int) (((72.0*(double)abs(lf.lfHeight)) / (double) ppInch) + 0.5);
+    // BC++ 2007 doesn't provide abs(long) overload, hence the cast
+    return (int) (((72.0*abs((int)lf.lfHeight)) / (double) ppInch) + 0.5);
 }
 
 wxSize wxNativeFontInfo::GetPixelSize() const
 {
     wxSize ret;
-    ret.SetHeight(lf.lfHeight);
+    ret.SetHeight(abs((int)lf.lfHeight));
     ret.SetWidth(lf.lfWidth);
     return ret;
 }
@@ -604,9 +618,7 @@ void wxNativeFontInfo::SetUnderlined(bool underlined)
 
 bool wxNativeFontInfo::SetFaceName(const wxString& facename)
 {
-    size_t len = WXSIZEOF(lf.lfFaceName);
-    wxStrncpy(lf.lfFaceName, facename, len);
-    lf.lfFaceName[len - 1] = '\0';    // truncate the face name
+    wxStrlcpy(lf.lfFaceName, facename.c_str(), WXSIZEOF(lf.lfFaceName));
     return true;
 }
 
@@ -822,7 +834,7 @@ wxString wxNativeFontInfo::ToString() const
              lf.lfClipPrecision,
              lf.lfQuality,
              lf.lfPitchAndFamily,
-             lf.lfFaceName);
+             (const wxChar*)lf.lfFaceName);
 
     return s;
 }
@@ -850,9 +862,9 @@ wxFont::wxFont(const wxString& fontdesc)
 bool wxFont::DoCreate(int pointSize,
                       const wxSize& pixelSize,
                       bool sizeUsingPixels,
-                      int family,
-                      int style,
-                      int weight,
+                      wxFontFamily family,
+                      wxFontStyle style,
+                      wxFontWeight weight,
                       bool underlined,
                       const wxString& faceName,
                       wxFontEncoding encoding)
@@ -881,14 +893,14 @@ wxFont::~wxFont()
 // real implementation
 // ----------------------------------------------------------------------------
 
-wxObjectRefData *wxFont::CreateRefData() const
+wxGDIRefData *wxFont::CreateGDIRefData() const
 {
     return new wxFontRefData();
 }
 
-wxObjectRefData *wxFont::CloneRefData(const wxObjectRefData *data) const
+wxGDIRefData *wxFont::CloneGDIRefData(const wxGDIRefData *data) const
 {
-    return new wxFontRefData(*wx_static_cast(const wxFontRefData *, data));
+    return new wxFontRefData(*static_cast<const wxFontRefData *>(data));
 }
 
 bool wxFont::RealizeResource()
@@ -944,21 +956,21 @@ void wxFont::SetPixelSize(const wxSize& pixelSize)
     M_FONTDATA->SetPixelSize(pixelSize);
 }
 
-void wxFont::SetFamily(int family)
+void wxFont::SetFamily(wxFontFamily family)
 {
     AllocExclusive();
 
     M_FONTDATA->SetFamily(family);
 }
 
-void wxFont::SetStyle(int style)
+void wxFont::SetStyle(wxFontStyle style)
 {
     AllocExclusive();
 
     M_FONTDATA->SetStyle(style);
 }
 
-void wxFont::SetWeight(int weight)
+void wxFont::SetWeight(wxFontWeight weight)
 {
     AllocExclusive();
 
@@ -1028,23 +1040,23 @@ bool wxFont::IsUsingSizeInPixels() const
     return M_FONTDATA->IsUsingSizeInPixels();
 }
 
-int wxFont::GetFamily() const
+wxFontFamily wxFont::GetFamily() const
 {
-    wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
+    wxCHECK_MSG( Ok(), wxFONTFAMILY_MAX, wxT("invalid font") );
 
     return M_FONTDATA->GetFamily();
 }
 
-int wxFont::GetStyle() const
+wxFontStyle wxFont::GetStyle() const
 {
-    wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
+    wxCHECK_MSG( Ok(), wxFONTSTYLE_MAX, wxT("invalid font") );
 
     return M_FONTDATA->GetStyle();
 }
 
-int wxFont::GetWeight() const
+wxFontWeight wxFont::GetWeight() const
 {
-    wxCHECK_MSG( Ok(), 0, wxT("invalid font") );
+    wxCHECK_MSG( Ok(), wxFONTWEIGHT_MAX, wxT("invalid font") );
 
     return M_FONTDATA->GetWeight();
 }