From ff6332a66f71cdc4379e2233243848cc521a876c Mon Sep 17 00:00:00 2001 From: Anatoly Mihalchenko Date: Wed, 5 Sep 2012 12:34:04 +0300 Subject: [PATCH] Virtual Keyboard under Mac OS 10.7: switching locales --- src/frameworks/UBPlatformUtils.h | 5 +++++ src/frameworks/UBPlatformUtils_mac.mm | 25 +++++++++++++++++++++++++ src/gui/UBKeyboardPalette_mac.cpp | 19 +------------------ 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/frameworks/UBPlatformUtils.h b/src/frameworks/UBPlatformUtils.h index ebac3995..46acb6f6 100644 --- a/src/frameworks/UBPlatformUtils.h +++ b/src/frameworks/UBPlatformUtils.h @@ -171,6 +171,7 @@ class UBPlatformUtils static int nKeyboardLayouts; static UBKeyboardLocale** keyboardLayouts; + public: static void init(); static void destroy(); @@ -192,6 +193,10 @@ public: static UBKeyboardLocale** getKeyboardLayouts(int& nCount); static QString urlFromClipboard(); static QStringList availableTranslations(); + +#ifdef Q_WS_MAC + static void SetMacLocaleByIdentifier(const QString& id); +#endif }; diff --git a/src/frameworks/UBPlatformUtils_mac.mm b/src/frameworks/UBPlatformUtils_mac.mm index d62e9f2e..72dcb75c 100644 --- a/src/frameworks/UBPlatformUtils_mac.mm +++ b/src/frameworks/UBPlatformUtils_mac.mm @@ -570,3 +570,28 @@ QString UBPlatformUtils::urlFromClipboard() */ return qsRet; } + + +void UBPlatformUtils::SetMacLocaleByIdentifier(const QString& id) +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + + const char * strName = id.toAscii().data(); + + CFStringRef iName = CFStringCreateWithCString(NULL, strName, kCFStringEncodingMacRoman ); + + CFStringRef keys[] = { kTISPropertyInputSourceCategory, kTISPropertyInputSourceID }; + CFStringRef values[] = { kTISCategoryKeyboardInputSource, iName }; + CFDictionaryRef dict = CFDictionaryCreate(NULL, (const void **)keys, (const void **)values, 2, NULL, NULL); + CFArrayRef kbds = TISCreateInputSourceList(dict, true); + if (kbds!=NULL) + { + if (CFArrayGetCount(kbds)!=0) + { + TISInputSourceRef klRef = (TISInputSourceRef)CFArrayGetValueAtIndex(kbds, 0); + if (klRef!=NULL) + TISSelectInputSource(klRef); + } + } + [pool drain]; +} diff --git a/src/gui/UBKeyboardPalette_mac.cpp b/src/gui/UBKeyboardPalette_mac.cpp index a8ca7c72..79e48e36 100644 --- a/src/gui/UBKeyboardPalette_mac.cpp +++ b/src/gui/UBKeyboardPalette_mac.cpp @@ -57,23 +57,6 @@ void UBKeyboardPalette::createCtrlButtons() ctrlButtons[8] = new UBLocaleButton(this); } -void SetMacLocaleByIdentifier(const QString& id) -{ - const char * strName = id.toAscii().data(); - - CFStringRef iName = CFStringCreateWithCString(NULL, strName, kCFStringEncodingMacRoman ); - - CFStringRef keys[] = { kTISPropertyInputSourceCategory, kTISPropertyInputSourceID }; - CFStringRef values[] = { kTISCategoryKeyboardInputSource, iName }; - CFDictionaryRef dict = CFDictionaryCreate(NULL, (const void **)keys, (const void **)values, 2, NULL, NULL); - CFArrayRef kbds = TISCreateInputSourceList(dict, true); - if (CFArrayGetCount(kbds)!=0) - { - TISInputSourceRef klRef = (TISInputSourceRef)CFArrayGetValueAtIndex(kbds, 0); - if (klRef!=NULL) - TISSelectInputSource(klRef); - } -} void UBKeyboardPalette::checkLayout() @@ -108,6 +91,6 @@ void UBKeyboardPalette::onActivated(bool) void UBKeyboardPalette::onLocaleChanged(UBKeyboardLocale* locale) { - SetMacLocaleByIdentifier(locale->id); + UBPlatformUtils::SetMacLocaleByIdentifier(locale->id); }