]> git.saurik.com Git - wxWidgets.git/blobdiff - src/common/intl.cpp
Do not use Tooltips if they are disabled
[wxWidgets.git] / src / common / intl.cpp
index 5b9c02b7f41634da1d44145239d57fc4b05973b1..0960dfc57b9fbfb6007e3964d28522a1c7495455 100644 (file)
@@ -75,6 +75,7 @@
 #if defined(__WXOSX__)
     #include "wx/osx/core/cfref.h"
     #include <CoreFoundation/CFLocale.h>
+    #include <CoreFoundation/CFDateFormatter.h>
     #include "wx/osx/core/cfstring.h"
 #endif
 
@@ -2516,13 +2517,12 @@ bool wxLocale::IsAvailable(int lang)
 #elif defined(__UNIX__)
 
     // Test if setting the locale works, then set it back.
-    const char *oldLocale = wxSetlocale(LC_ALL, "");
-    const char *tmp = wxSetlocaleTryUTF8(LC_ALL, info->CanonicalName);
-    if ( !tmp )
+    const char *oldLocale = wxSetlocaleTryUTF8(LC_ALL, info->CanonicalName);
+    if ( !oldLocale )
     {
         // Some C libraries don't like xx_YY form and require xx only
-        tmp = wxSetlocaleTryUTF8(LC_ALL, ExtractLang(info->CanonicalName));
-        if ( !tmp )
+        oldLocale = wxSetlocaleTryUTF8(LC_ALL, ExtractLang(info->CanonicalName));
+        if ( !oldLocale )
             return false;
     }
     // restore the original locale
@@ -2612,6 +2612,15 @@ static wxString TranslateFromUnicodeFormat(const wxString& fmt)
 
     char chLast = '\0';
     size_t lastCount = 0;
+    
+    const char* formatchars = 
+        "dghHmMsSy"
+#ifdef __WXMSW__
+        "t"
+#else
+        "EawD"
+#endif
+        ;
     for ( wxString::const_iterator p = fmt.begin(); /* end handled inside */; ++p )
     {
         if ( p != fmt.end() )
@@ -2623,7 +2632,7 @@ static wxString TranslateFromUnicodeFormat(const wxString& fmt)
             }
 
             const wxUniChar ch = (*p).GetValue();
-            if ( ch.IsAscii() && strchr("dghHmMsSy", ch) )
+            if ( ch.IsAscii() && strchr(formatchars, ch) )
             {
                 // these characters come in groups, start counting them
                 chLast = ch;
@@ -2646,7 +2655,7 @@ static wxString TranslateFromUnicodeFormat(const wxString& fmt)
                             // between 1 and 2 digits for days
                             fmtWX += "%d";
                             break;
-
+#ifdef __WXMSW__
                         case 3: // ddd
                             fmtWX += "%a";
                             break;
@@ -2654,12 +2663,57 @@ static wxString TranslateFromUnicodeFormat(const wxString& fmt)
                         case 4: // dddd
                             fmtWX += "%A";
                             break;
-
+#endif
                         default:
                             wxFAIL_MSG( "too many 'd's" );
                     }
                     break;
+#ifndef __WXMSW__
+                case 'D':
+                    switch ( lastCount )
+                    {
+                        case 1: // D
+                        case 2: // DD
+                        case 3: // DDD
+                            fmtWX += "%j";
+                            break;
+
+                        default:
+                            wxFAIL_MSG( "wrong number of 'D's" );
+                    }
+                    break;
+               case 'w':
+                    switch ( lastCount )
+                    {
+                        case 1: // w
+                        case 2: // ww
+                            fmtWX += "%W";
+                            break;
+
+                        default:
+                            wxFAIL_MSG( "wrong number of 'w's" );
+                    }
+                    break;
+                case 'E':
+                   switch ( lastCount )
+                    {
+                        case 1: // E
+                        case 2: // EE
+                        case 3: // EEE
+                            fmtWX += "%a";
+                            break;
+                        case 4: // EEEE
+                            fmtWX += "%A";
+                            break;
+                        case 5: // EEEEE
+                            fmtWX += "%a";
+                            break;
 
+                        default:
+                            wxFAIL_MSG( "wrong number of 'E's" );
+                    }
+                    break;
+#endif
                 case 'M':
                     switch ( lastCount )
                     {
@@ -2717,7 +2771,7 @@ static wxString TranslateFromUnicodeFormat(const wxString& fmt)
                     {
                         case 1: // h
                         case 2: // hh
-                            fmtWX += "%h";
+                            fmtWX += "%I";
                             break;
 
                         default:
@@ -2755,8 +2809,27 @@ static wxString TranslateFromUnicodeFormat(const wxString& fmt)
                     // strftime() doesn't have era string,
                     // ignore this format
                     wxASSERT_MSG( lastCount <= 2, "too many 'g's" );
+         
+                    break;
+#ifndef __WXMSW__
+                case 'a':
+                    fmtWX += "%p";
                     break;
+#endif
+#ifdef __WXMSW__
+                case 't':
+                    switch ( lastCount )
+                    {
+                        case 1: // t
+                        case 2: // tt
+                            fmtWX += "%p";
+                            break;
 
+                        default:
+                            wxFAIL_MSG( "too many 't's" );
+                    }
+                    break;
+#endif
                 default:
                     wxFAIL_MSG( "unreachable" );
             }
@@ -2909,8 +2982,37 @@ wxString wxLocale::GetInfo(wxLocaleInfo index, wxLocaleCategory WXUNUSED(cat))
         case wxLOCALE_LONG_DATE_FMT:
         case wxLOCALE_DATE_TIME_FMT:
         case wxLOCALE_TIME_FMT:
-            // TODO
-            return wxString();
+            {
+                CFDateFormatterStyle dateStyle = kCFDateFormatterNoStyle;
+                CFDateFormatterStyle timeStyle = kCFDateFormatterNoStyle;
+                switch (index )
+                {
+                    case wxLOCALE_SHORT_DATE_FMT:
+                        dateStyle = kCFDateFormatterShortStyle;
+                        break;
+                    case wxLOCALE_LONG_DATE_FMT:
+                        dateStyle = kCFDateFormatterFullStyle;
+                        break;
+                    case wxLOCALE_DATE_TIME_FMT:
+                        dateStyle = kCFDateFormatterFullStyle;
+                        timeStyle = kCFDateFormatterMediumStyle;
+                        break;
+                    case wxLOCALE_TIME_FMT:
+                        timeStyle = kCFDateFormatterMediumStyle;
+                        break;
+                    default:
+                        wxFAIL_MSG( "unexpected time locale" );
+                        return wxString();
+                }
+                wxCFRef<CFDateFormatterRef> dateFormatter( CFDateFormatterCreate
+                    (NULL, userLocaleRef, dateStyle, timeStyle));
+                wxCFStringRef cfs = wxCFRetain( CFDateFormatterGetFormat(dateFormatter ));
+                wxString format = TranslateFromUnicodeFormat(cfs.AsString());
+                // we always want full years
+                format.Replace("%y","%Y");
+                return format;
+            }
+            break;
 
         default:
             wxFAIL_MSG( "Unknown locale info" );