]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/fmapbase.cpp
implemented wxSS::GetMetric on wxGTK2 (patch 950618)
[wxWidgets.git] / src / common / fmapbase.cpp
index fa6dcd0d65eb693774c2c590cea1f6861060ee82..8aba4bafc8b43ec6482fd7605ec389ffadb167df 100644 (file)
@@ -43,7 +43,8 @@
 #include "wx/apptrait.h"
 #include "wx/module.h"
 
 #include "wx/apptrait.h"
 #include "wx/module.h"
 
-#if wxUSE_CONFIG
+// wxMemoryConfig uses wxFileConfig
+#if wxUSE_CONFIG && wxUSE_FILECONFIG
     #include "wx/config.h"
     #include "wx/memconf.h"
 #endif
     #include "wx/config.h"
     #include "wx/memconf.h"
 #endif
@@ -71,6 +72,7 @@ static wxFontEncoding gs_encodings[] =
     wxFONTENCODING_ISO8859_14,
     wxFONTENCODING_ISO8859_15,
     wxFONTENCODING_KOI8,
     wxFONTENCODING_ISO8859_14,
     wxFONTENCODING_ISO8859_15,
     wxFONTENCODING_KOI8,
+    wxFONTENCODING_KOI8_U,
     wxFONTENCODING_CP932,
     wxFONTENCODING_CP936,
     wxFONTENCODING_CP949,
     wxFONTENCODING_CP932,
     wxFONTENCODING_CP936,
     wxFONTENCODING_CP949,
@@ -86,6 +88,12 @@ static wxFontEncoding gs_encodings[] =
     wxFONTENCODING_CP437,
     wxFONTENCODING_UTF7,
     wxFONTENCODING_UTF8,
     wxFONTENCODING_CP437,
     wxFONTENCODING_UTF7,
     wxFONTENCODING_UTF8,
+    wxFONTENCODING_UTF16,
+    wxFONTENCODING_UTF16BE,
+    wxFONTENCODING_UTF16LE,
+    wxFONTENCODING_UTF32,
+    wxFONTENCODING_UTF32BE,
+    wxFONTENCODING_UTF32LE,
     wxFONTENCODING_EUC_JP,
 };
 
     wxFONTENCODING_EUC_JP,
 };
 
@@ -108,6 +116,7 @@ static const wxChar* gs_encodingDescs[] =
     wxTRANSLATE( "Celtic (ISO-8859-14)" ),
     wxTRANSLATE( "Western European with Euro (ISO-8859-15)" ),
     wxTRANSLATE( "KOI8-R" ),
     wxTRANSLATE( "Celtic (ISO-8859-14)" ),
     wxTRANSLATE( "Western European with Euro (ISO-8859-15)" ),
     wxTRANSLATE( "KOI8-R" ),
+    wxTRANSLATE( "KOI8-U" ),
     wxTRANSLATE( "Windows Japanese (CP 932)" ),
     wxTRANSLATE( "Windows Chinese Simplified (CP 936)" ),
     wxTRANSLATE( "Windows Korean (CP 949)" ),
     wxTRANSLATE( "Windows Japanese (CP 932)" ),
     wxTRANSLATE( "Windows Chinese Simplified (CP 936)" ),
     wxTRANSLATE( "Windows Korean (CP 949)" ),
@@ -123,6 +132,12 @@ static const wxChar* gs_encodingDescs[] =
     wxTRANSLATE( "Windows/DOS OEM (CP 437)" ),
     wxTRANSLATE( "Unicode 7 bit (UTF-7)" ),
     wxTRANSLATE( "Unicode 8 bit (UTF-8)" ),
     wxTRANSLATE( "Windows/DOS OEM (CP 437)" ),
     wxTRANSLATE( "Unicode 7 bit (UTF-7)" ),
     wxTRANSLATE( "Unicode 8 bit (UTF-8)" ),
+    wxTRANSLATE( "Unicode 16 bit (UTF-16)" ),
+    wxTRANSLATE( "Unicode 16 bit Big Endian (UTF-16BE)" ),
+    wxTRANSLATE( "Unicode 16 bit Little Endian (UTF-16LE)" ),
+    wxTRANSLATE( "Unicode 32 bit (UTF-32)" ),
+    wxTRANSLATE( "Unicode 32 bit Big Endian (UTF-32BE)" ),
+    wxTRANSLATE( "Unicode 32 bit Little Endian (UTF-32LE)" ),
     wxTRANSLATE( "Extended Unix Codepage for Japanese (EUC-JP)" ),
 };
 
     wxTRANSLATE( "Extended Unix Codepage for Japanese (EUC-JP)" ),
 };
 
@@ -145,6 +160,7 @@ static const wxChar* gs_encodingNames[] =
     wxT( "iso-8859-14" ),
     wxT( "iso-8859-15" ),
     wxT( "koi8-r" ),
     wxT( "iso-8859-14" ),
     wxT( "iso-8859-15" ),
     wxT( "koi8-r" ),
+    wxT( "koi8-u" ),
     wxT( "windows-932" ),
     wxT( "windows-936" ),
     wxT( "windows-949" ),
     wxT( "windows-932" ),
     wxT( "windows-936" ),
     wxT( "windows-949" ),
@@ -160,6 +176,12 @@ static const wxChar* gs_encodingNames[] =
     wxT( "windows-437" ),
     wxT( "utf-7" ),
     wxT( "utf-8" ),
     wxT( "windows-437" ),
     wxT( "utf-7" ),
     wxT( "utf-8" ),
+    wxT( "utf-16" ),
+    wxT( "utf-16be" ),
+    wxT( "utf-16le" ),
+    wxT( "utf-32" ),
+    wxT( "utf-32be" ),
+    wxT( "utf-32le" ),
     wxT( "euc-jp" ),
 };
 
     wxT( "euc-jp" ),
 };
 
@@ -197,7 +219,7 @@ wxFontMapper *wxFontMapperBase::sm_instance = NULL;
 
 wxFontMapperBase::wxFontMapperBase()
 {
 
 wxFontMapperBase::wxFontMapperBase()
 {
-#if wxUSE_CONFIG
+#if wxUSE_CONFIG && wxUSE_FILECONFIG
     m_config = NULL;
     m_configIsDummy = FALSE;
 #endif // wxUSE_CONFIG
     m_config = NULL;
     m_configIsDummy = FALSE;
 #endif // wxUSE_CONFIG
@@ -205,7 +227,7 @@ wxFontMapperBase::wxFontMapperBase()
 
 wxFontMapperBase::~wxFontMapperBase()
 {
 
 wxFontMapperBase::~wxFontMapperBase()
 {
-#if wxUSE_CONFIG
+#if wxUSE_CONFIG && wxUSE_FILECONFIG
     if ( m_configIsDummy )
         delete m_config;
 #endif // wxUSE_CONFIG
     if ( m_configIsDummy )
         delete m_config;
 #endif // wxUSE_CONFIG
@@ -244,7 +266,7 @@ wxFontMapper *wxFontMapperBase::Set(wxFontMapper *mapper)
     return old;
 }
 
     return old;
 }
 
-#if wxUSE_CONFIG
+#if wxUSE_CONFIG && wxUSE_FILECONFIG
 
 // ----------------------------------------------------------------------------
 // config usage customisation
 
 // ----------------------------------------------------------------------------
 // config usage customisation
@@ -352,6 +374,8 @@ void wxFontMapperBase::RestorePath(const wxString& pathOld)
     GetConfig()->SetPath(pathOld);
 }
 
     GetConfig()->SetPath(pathOld);
 }
 
+#endif
+
 // ----------------------------------------------------------------------------
 // charset/encoding correspondence
 // ----------------------------------------------------------------------------
 // ----------------------------------------------------------------------------
 // charset/encoding correspondence
 // ----------------------------------------------------------------------------
@@ -359,13 +383,27 @@ void wxFontMapperBase::RestorePath(const wxString& pathOld)
 wxFontEncoding
 wxFontMapperBase::CharsetToEncoding(const wxString& charset,
                                     bool WXUNUSED(interactive))
 wxFontEncoding
 wxFontMapperBase::CharsetToEncoding(const wxString& charset,
                                     bool WXUNUSED(interactive))
+{
+    int enc = NonInteractiveCharsetToEncoding(charset);
+    if ( enc == wxFONTENCODING_UNKNOWN )
+    {
+        // we should return wxFONTENCODING_SYSTEM from here for unknown
+        // encodings
+        enc = wxFONTENCODING_SYSTEM;
+    }
+
+    return (wxFontEncoding)enc;
+}
+
+int
+wxFontMapperBase::NonInteractiveCharsetToEncoding(const wxString& charset)
 {
     wxFontEncoding encoding = wxFONTENCODING_SYSTEM;
 
     // we're going to modify it, make a copy
     wxString cs = charset;
 
 {
     wxFontEncoding encoding = wxFONTENCODING_SYSTEM;
 
     // we're going to modify it, make a copy
     wxString cs = charset;
 
-#if wxUSE_CONFIG
+#if wxUSE_CONFIG && wxUSE_FILECONFIG
     // first try the user-defined settings
     wxFontMapperPathChanger path(this, FONTMAPPER_CHARSET_PATH);
     if ( path.IsOk() )
     // first try the user-defined settings
     wxFontMapperPathChanger path(this, FONTMAPPER_CHARSET_PATH);
     if ( path.IsOk() )
@@ -379,7 +417,7 @@ wxFontMapperBase::CharsetToEncoding(const wxString& charset,
             if ( value == wxFONTENCODING_UNKNOWN )
             {
                 // don't try to find it, in particular don't ask the user
             if ( value == wxFONTENCODING_UNKNOWN )
             {
                 // don't try to find it, in particular don't ask the user
-                return wxFONTENCODING_SYSTEM;
+                return value;
             }
 
             if ( value >= 0 && value <= wxFONTENCODING_MAX )
             }
 
             if ( value >= 0 && value <= wxFONTENCODING_MAX )
@@ -438,6 +476,30 @@ wxFontMapperBase::CharsetToEncoding(const wxString& charset,
         {
             encoding = wxFONTENCODING_UTF8;
         }
         {
             encoding = wxFONTENCODING_UTF8;
         }
+        else if ( cs == wxT("UTF-16") )
+        {
+            encoding = wxFONTENCODING_UTF16;
+        }
+        else if ( cs == wxT("UTF-16BE") )
+        {
+            encoding = wxFONTENCODING_UTF16BE;
+        }
+        else if ( cs == wxT("UTF-16LE") )
+        {
+            encoding = wxFONTENCODING_UTF16LE;
+        }
+        else if ( cs == wxT("UTF-32") || cs == wxT("UCS-4") )
+        {
+            encoding = wxFONTENCODING_UTF32;
+        }
+        else if ( cs == wxT("UTF-32BE") || cs == wxT("UCS-4BE") )
+        {
+            encoding = wxFONTENCODING_UTF32BE;
+        }
+        else if ( cs == wxT("UTF-32LE") || cs == wxT("UCS-4LE") )
+        {
+            encoding = wxFONTENCODING_UTF32LE;
+        }
         else if ( cs == wxT("GB2312") )
         {
             encoding = wxFONTENCODING_GB2312;
         else if ( cs == wxT("GB2312") )
         {
             encoding = wxFONTENCODING_GB2312;
@@ -458,14 +520,17 @@ wxFontMapperBase::CharsetToEncoding(const wxString& charset,
             encoding = wxFONTENCODING_EUC_JP;
         }
         else if ( cs == wxT("KOI8-R") ||
             encoding = wxFONTENCODING_EUC_JP;
         }
         else if ( cs == wxT("KOI8-R") ||
-                  cs == wxT("KOI8-U") ||
                   cs == wxT("KOI8-RU") )
         {
             // although koi8-ru is not strictly speaking the same as koi8-r,
             // they are similar enough to make mapping it to koi8 better than
                   cs == wxT("KOI8-RU") )
         {
             // although koi8-ru is not strictly speaking the same as koi8-r,
             // they are similar enough to make mapping it to koi8 better than
-            // not reckognizing it at all
+            // not recognizing it at all
             encoding = wxFONTENCODING_KOI8;
         }
             encoding = wxFONTENCODING_KOI8;
         }
+        else if ( cs == wxT("KOI8-U") )
+        {
+            encoding = wxFONTENCODING_KOI8_U;
+        }
         else if ( cs.Left(3) == wxT("ISO") )
         {
             // the dash is optional (or, to be exact, it is not, but
         else if ( cs.Left(3) == wxT("ISO") )
         {
             // the dash is optional (or, to be exact, it is not, but
@@ -641,7 +706,26 @@ wxString wxFontMapperBase::GetEncodingName(wxFontEncoding encoding)
     return str;
 }
 
     return str;
 }
 
-#endif // wxUSE_CONFIG
+/* static */
+wxFontEncoding wxFontMapperBase::GetEncodingFromName(const wxString& name)
+{
+    const size_t count = WXSIZEOF(gs_encodingNames);
+
+    for ( size_t i = 0; i < count; i++ )
+    {
+        if ( gs_encodingNames[i] == name )
+        {
+            return gs_encodings[i];
+        }
+    }
+
+    if ( name == _("default") )
+    {
+        return wxFONTENCODING_DEFAULT;
+    }
+
+    return wxFONTENCODING_MAX;
+}
 
 #endif // wxUSE_FONTMAP
 
 
 #endif // wxUSE_FONTMAP