]> git.saurik.com Git - wxWidgets.git/blobdiff - src/motif/font.cpp
Applied #9011: Native wxListCtrl::HitTest on OS X
[wxWidgets.git] / src / motif / font.cpp
index 07db51f0ab8e4d8cc8468a2f0febc2c856aa3c67..2969f829be42b054572d565893c89a221ed1a7a8 100644 (file)
@@ -61,7 +61,7 @@ public:
 #endif
 #if !wxMOTIF_USE_RENDER_TABLE
     WXFontList          m_fontList;     // Motif XmFontList
 #endif
 #if !wxMOTIF_USE_RENDER_TABLE
     WXFontList          m_fontList;     // Motif XmFontList
-#else // if wxUSE_RENDER_TABLE
+#else // if wxMOTIF_USE_RENDER_TABLE
     WXRenderTable       m_renderTable;  // Motif XmRenderTable
     WXRendition         m_rendition;    // Motif XmRendition
 #endif
     WXRenderTable       m_renderTable;  // Motif XmRenderTable
     WXRendition         m_rendition;    // Motif XmRendition
 #endif
@@ -75,9 +75,9 @@ class wxFontRefData: public wxGDIRefData
 
 public:
     wxFontRefData(int size = wxDEFAULT,
 
 public:
     wxFontRefData(int size = wxDEFAULT,
-                  int family = wxDEFAULT,
-                  int style = wxDEFAULT,
-                  int weight = wxDEFAULT,
+                  wxFontFamily family = wxFONTFAMILY_DEFAULT,
+                  wxFontStyle style = wxFONTSTYLE_NORMAL,
+                  wxFontWeight weight = wxFONTWEIGHT_NORMAL,
                   bool underlined = false,
                   const wxString& faceName = wxEmptyString,
                   wxFontEncoding encoding = wxFONTENCODING_DEFAULT)
                   bool underlined = false,
                   const wxString& faceName = wxEmptyString,
                   wxFontEncoding encoding = wxFONTENCODING_DEFAULT)
@@ -96,18 +96,18 @@ public:
 protected:
     // common part of all ctors
     void Init(int size,
 protected:
     // common part of all ctors
     void Init(int size,
-              int family,
-              int style,
-              int weight,
+              wxFontFamily family,
+              wxFontStyle style,
+              wxFontWeight weight,
               bool underlined,
               const wxString& faceName,
               wxFontEncoding encoding);
 
     // font attributes
     int           m_pointSize;
               bool underlined,
               const wxString& faceName,
               wxFontEncoding encoding);
 
     // font attributes
     int           m_pointSize;
-    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;
     bool          m_underlined;
     wxString      m_faceName;
     wxFontEncoding m_encoding;
@@ -147,7 +147,7 @@ wxXFont::~wxXFont()
     if (m_fontList)
         XmFontListFree ((XmFontList) m_fontList);
     m_fontList = NULL;
     if (m_fontList)
         XmFontListFree ((XmFontList) m_fontList);
     m_fontList = NULL;
-#else // if wxUSE_RENDER_TABLE
+#else // if wxMOTIF_USE_RENDER_TABLE
     if (m_renderTable)
         XmRenderTableFree ((XmRenderTable) m_renderTable);
     m_renderTable = NULL;
     if (m_renderTable)
         XmRenderTableFree ((XmRenderTable) m_renderTable);
     m_renderTable = NULL;
@@ -166,27 +166,27 @@ wxXFont::~wxXFont()
 // ----------------------------------------------------------------------------
 
 void wxFontRefData::Init(int pointSize,
 // ----------------------------------------------------------------------------
 
 void wxFontRefData::Init(int pointSize,
-                         int family,
-                         int style,
-                         int weight,
+                         wxFontFamily family,
+                         wxFontStyle style,
+                         wxFontWeight weight,
                          bool underlined,
                          const wxString& faceName,
                          wxFontEncoding encoding)
 {
     if (family == wxDEFAULT)
                          bool underlined,
                          const wxString& faceName,
                          wxFontEncoding encoding)
 {
     if (family == wxDEFAULT)
-        m_family = wxSWISS;
+        m_family = wxFONTFAMILY_SWISS;
     else
         m_family = family;
 
     m_faceName = faceName;
 
     if (style == wxDEFAULT)
     else
         m_family = family;
 
     m_faceName = faceName;
 
     if (style == wxDEFAULT)
-        m_style = wxNORMAL;
+        m_style = wxFONTSTYLE_NORMAL;
     else
         m_style = style;
 
     if (weight == wxDEFAULT)
     else
         m_style = style;
 
     if (weight == wxDEFAULT)
-        m_weight = wxNORMAL;
+        m_weight = wxFONTWEIGHT_NORMAL;
     else
         m_weight = weight;
 
     else
         m_weight = weight;
 
@@ -223,9 +223,9 @@ wxFont::wxFont(const wxNativeFontInfo& info)
 }
 
 bool wxFont::Create(int pointSize,
 }
 
 bool wxFont::Create(int pointSize,
-                    int family,
-                    int style,
-                    int weight,
+                    wxFontFamily family,
+                    wxFontStyle style,
+                    wxFontWeight weight,
                     bool underlined,
                     const wxString& faceName,
                     wxFontEncoding encoding)
                     bool underlined,
                     const wxString& faceName,
                     wxFontEncoding encoding)
@@ -260,18 +260,18 @@ bool wxFont::Create(const wxString& fontname, wxFontEncoding enc)
     M_FONTDATA->m_faceName = tn.GetNextToken();  // family
 
     tmp = tn.GetNextToken().MakeUpper();         // weight
     M_FONTDATA->m_faceName = tn.GetNextToken();  // family
 
     tmp = tn.GetNextToken().MakeUpper();         // weight
-    if (tmp == wxT("BOLD")) M_FONTDATA->m_weight = wxBOLD;
-    if (tmp == wxT("BLACK")) M_FONTDATA->m_weight = wxBOLD;
-    if (tmp == wxT("EXTRABOLD")) M_FONTDATA->m_weight = wxBOLD;
-    if (tmp == wxT("DEMIBOLD")) M_FONTDATA->m_weight = wxBOLD;
-    if (tmp == wxT("ULTRABOLD")) M_FONTDATA->m_weight = wxBOLD;
+    if (tmp == wxT("BOLD")) M_FONTDATA->m_weight = wxFONTWEIGHT_BOLD;
+    if (tmp == wxT("BLACK")) M_FONTDATA->m_weight = wxFONTWEIGHT_BOLD;
+    if (tmp == wxT("EXTRABOLD")) M_FONTDATA->m_weight = wxFONTWEIGHT_BOLD;
+    if (tmp == wxT("DEMIBOLD")) M_FONTDATA->m_weight = wxFONTWEIGHT_BOLD;
+    if (tmp == wxT("ULTRABOLD")) M_FONTDATA->m_weight = wxFONTWEIGHT_BOLD;
 
 
-    if (tmp == wxT("LIGHT")) M_FONTDATA->m_weight = wxLIGHT;
-    if (tmp == wxT("THIN")) M_FONTDATA->m_weight = wxLIGHT;
+    if (tmp == wxT("LIGHT")) M_FONTDATA->m_weight = wxFONTWEIGHT_LIGHT;
+    if (tmp == wxT("THIN")) M_FONTDATA->m_weight = wxFONTWEIGHT_LIGHT;
 
     tmp = tn.GetNextToken().MakeUpper();        // slant
 
     tmp = tn.GetNextToken().MakeUpper();        // slant
-    if (tmp == wxT("I")) M_FONTDATA->m_style = wxITALIC;
-    if (tmp == wxT("O")) M_FONTDATA->m_style = wxITALIC;
+    if (tmp == wxT("I")) M_FONTDATA->m_style = wxFONTSTYLE_ITALIC;
+    if (tmp == wxT("O")) M_FONTDATA->m_style = wxFONTSTYLE_ITALIC;
 
     tn.GetNextToken();                           // set width
     tn.GetNextToken();                           // add. style
 
     tn.GetNextToken();                           // set width
     tn.GetNextToken();                           // add. style
@@ -290,17 +290,17 @@ bool wxFont::Create(const wxString& fontname, wxFontEncoding enc)
     tmp = tn.GetNextToken().MakeUpper();         // spacing
 
     if (tmp == wxT("M"))
     tmp = tn.GetNextToken().MakeUpper();         // spacing
 
     if (tmp == wxT("M"))
-        M_FONTDATA->m_family = wxMODERN;
+        M_FONTDATA->m_family = wxFONTFAMILY_MODERN;
     else if (M_FONTDATA->m_faceName == wxT("TIMES"))
     else if (M_FONTDATA->m_faceName == wxT("TIMES"))
-        M_FONTDATA->m_family = wxROMAN;
+        M_FONTDATA->m_family = wxFONTFAMILY_ROMAN;
     else if (M_FONTDATA->m_faceName == wxT("HELVETICA"))
     else if (M_FONTDATA->m_faceName == wxT("HELVETICA"))
-        M_FONTDATA->m_family = wxSWISS;
+        M_FONTDATA->m_family = wxFONTFAMILY_SWISS;
     else if (M_FONTDATA->m_faceName == wxT("LUCIDATYPEWRITER"))
     else if (M_FONTDATA->m_faceName == wxT("LUCIDATYPEWRITER"))
-        M_FONTDATA->m_family = wxTELETYPE;
+        M_FONTDATA->m_family = wxFONTFAMILY_TELETYPE;
     else if (M_FONTDATA->m_faceName == wxT("LUCIDA"))
     else if (M_FONTDATA->m_faceName == wxT("LUCIDA"))
-        M_FONTDATA->m_family = wxDECORATIVE;
+        M_FONTDATA->m_family = wxFONTFAMILY_DECORATIVE;
     else if (M_FONTDATA->m_faceName == wxT("UTOPIA"))
     else if (M_FONTDATA->m_faceName == wxT("UTOPIA"))
-        M_FONTDATA->m_family = wxSCRIPT;
+        M_FONTDATA->m_family = wxFONTFAMILY_SCRIPT;
 
     tn.GetNextToken();                           // avg width
 
 
     tn.GetNextToken();                           // avg width
 
@@ -311,7 +311,7 @@ bool wxFont::Create(const wxString& fontname, wxFontEncoding enc)
         wxString registry = tn.GetNextToken().MakeUpper(),
                  encoding = tn.GetNextToken().MakeUpper();
 
         wxString registry = tn.GetNextToken().MakeUpper(),
                  encoding = tn.GetNextToken().MakeUpper();
 
-        if ( registry == _T("ISO8859") )
+        if ( registry == wxT("ISO8859") )
         {
             int cp;
             if ( wxSscanf(encoding, wxT("%d"), &cp) == 1 )
         {
             int cp;
             if ( wxSscanf(encoding, wxT("%d"), &cp) == 1 )
@@ -320,7 +320,7 @@ bool wxFont::Create(const wxString& fontname, wxFontEncoding enc)
                     (wxFontEncoding)(wxFONTENCODING_ISO8859_1 + cp - 1);
             }
         }
                     (wxFontEncoding)(wxFONTENCODING_ISO8859_1 + cp - 1);
             }
         }
-        else if ( registry == _T("MICROSOFT") )
+        else if ( registry == wxT("MICROSOFT") )
         {
             int cp;
             if ( wxSscanf(encoding, wxT("cp125%d"), &cp) == 1 )
         {
             int cp;
             if ( wxSscanf(encoding, wxT("cp125%d"), &cp) == 1 )
@@ -329,7 +329,7 @@ bool wxFont::Create(const wxString& fontname, wxFontEncoding enc)
                     (wxFontEncoding)(wxFONTENCODING_CP1250 + cp);
             }
         }
                     (wxFontEncoding)(wxFONTENCODING_CP1250 + cp);
             }
         }
-        else if ( registry == _T("KOI8") )
+        else if ( registry == wxT("KOI8") )
         {
             M_FONTDATA->m_encoding = wxFONTENCODING_KOI8;
         }
         {
             M_FONTDATA->m_encoding = wxFONTENCODING_KOI8;
         }
@@ -344,6 +344,16 @@ wxFont::~wxFont()
 {
 }
 
 {
 }
 
+wxGDIRefData *wxFont::CreateGDIRefData() const
+{
+    return new wxFontRefData;
+}
+
+wxGDIRefData *wxFont::CloneGDIRefData(const wxGDIRefData *data) const
+{
+    return new wxFontRefData(*static_cast<const wxFontRefData *>(data));
+}
+
 // ----------------------------------------------------------------------------
 // change the font attributes
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // change the font attributes
 // ----------------------------------------------------------------------------
@@ -371,7 +381,7 @@ void wxFont::SetPointSize(int pointSize)
     M_FONTDATA->m_nativeFontInfo.GetXFontName().Clear(); // invalid now
 }
 
     M_FONTDATA->m_nativeFontInfo.GetXFontName().Clear(); // invalid now
 }
 
-void wxFont::SetFamily(int family)
+void wxFont::SetFamily(wxFontFamily family)
 {
     Unshare();
 
 {
     Unshare();
 
@@ -379,7 +389,7 @@ void wxFont::SetFamily(int family)
     M_FONTDATA->m_nativeFontInfo.GetXFontName().Clear(); // invalid now
 }
 
     M_FONTDATA->m_nativeFontInfo.GetXFontName().Clear(); // invalid now
 }
 
-void wxFont::SetStyle(int style)
+void wxFont::SetStyle(wxFontStyle style)
 {
     Unshare();
 
 {
     Unshare();
 
@@ -387,7 +397,7 @@ void wxFont::SetStyle(int style)
     M_FONTDATA->m_nativeFontInfo.GetXFontName().Clear(); // invalid now
 }
 
     M_FONTDATA->m_nativeFontInfo.GetXFontName().Clear(); // invalid now
 }
 
-void wxFont::SetWeight(int weight)
+void wxFont::SetWeight(wxFontWeight weight)
 {
     Unshare();
 
 {
     Unshare();
 
@@ -445,23 +455,23 @@ wxString wxFont::GetFaceName() const
     return M_FONTDATA->m_faceName ;
 }
 
     return M_FONTDATA->m_faceName ;
 }
 
-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->m_family;
 }
 
 
     return M_FONTDATA->m_family;
 }
 
-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->m_style;
 }
 
 
     return M_FONTDATA->m_style;
 }
 
-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->m_weight;
 }
 
     return M_FONTDATA->m_weight;
 }
@@ -482,7 +492,7 @@ wxFontEncoding wxFont::GetEncoding() const
 
 const wxNativeFontInfo *wxFont::GetNativeFontInfo() const
 {
 
 const wxNativeFontInfo *wxFont::GetNativeFontInfo() const
 {
-    wxCHECK_MSG( Ok(), (wxNativeFontInfo *)NULL, wxT("invalid font") );
+    wxCHECK_MSG( Ok(), NULL, wxT("invalid font") );
 
     if(M_FONTDATA->m_nativeFontInfo.GetXFontName().empty())
         GetInternalFont();
 
     if(M_FONTDATA->m_nativeFontInfo.GetXFontName().empty())
         GetInternalFont();
@@ -500,7 +510,7 @@ const wxNativeFontInfo *wxFont::GetNativeFontInfo() const
 wxXFont* wxFont::GetInternalFont(double scale, WXDisplay* display) const
 {
     if ( !Ok() )
 wxXFont* wxFont::GetInternalFont(double scale, WXDisplay* display) const
 {
     if ( !Ok() )
-        return (wxXFont *)NULL;
+        return NULL;
 
     long intScale = long(scale * 100.0 + 0.5); // key for wxXFont
     int pointSize = (M_FONTDATA->m_pointSize * 10 * intScale) / 100;
 
     long intScale = long(scale * 100.0 + 0.5); // key for wxXFont
     int pointSize = (M_FONTDATA->m_pointSize * 10 * intScale) / 100;
@@ -531,7 +541,7 @@ wxXFont* wxFont::GetInternalFont(double scale, WXDisplay* display) const
     {
         wxFAIL_MSG( wxT("Could not allocate even a default font -- something is wrong.") );
 
     {
         wxFAIL_MSG( wxT("Could not allocate even a default font -- something is wrong.") );
 
-        return (wxXFont*) NULL;
+        return NULL;
     }
 
     wxXFont* f = new wxXFont;
     }
 
     wxXFont* f = new wxXFont;
@@ -679,7 +689,8 @@ void wxGetTextExtent(WXDisplay* display, const wxFont& font,
     XCharStruct overall;
     int slen = str.length();
 
     XCharStruct overall;
     int slen = str.length();
 
-    XTextExtents((XFontStruct*) pFontStruct, (char*) str.mb_str(), slen,
+    XTextExtents((XFontStruct*) pFontStruct,
+                 const_cast<char*>((const char *)str.mb_str()), slen,
                  &direction, &ascent2, &descent2, &overall);
 
     if ( width )
                  &direction, &ascent2, &descent2, &overall);
 
     if ( width )