Virtual Keyboard under Mac OS 10.7: switching locales

preferencesAboutTextFull
Anatoly Mihalchenko 12 years ago
parent 34c6aa28a9
commit ff6332a66f
  1. 5
      src/frameworks/UBPlatformUtils.h
  2. 25
      src/frameworks/UBPlatformUtils_mac.mm
  3. 19
      src/gui/UBKeyboardPalette_mac.cpp

@ -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
};

@ -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];
}

@ -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);
}

Loading…
Cancel
Save