Esempio n. 1
0
bool
OSXKeyState::getGroups(GroupList& groups) const
{
	CFIndex n;
	bool gotLayouts = false;

	// get number of layouts
	CFStringRef keys[] = { kTISPropertyInputSourceCategory };
	CFStringRef values[] = { kTISCategoryKeyboardInputSource };
	CFDictionaryRef dict = CFDictionaryCreate(NULL, (const void **)keys, (const void **)values, 1, NULL, NULL);
	CFArrayRef kbds = TISCreateInputSourceList(dict, false);
	n = CFArrayGetCount(kbds);
	gotLayouts = (n != 0);

	if (!gotLayouts) {
		LOG((CLOG_DEBUG1 "can't get keyboard layouts"));
		return false;
	}

	// get each layout
	groups.clear();
	for (CFIndex i = 0; i < n; ++i) {
		bool addToGroups = true;
		TISInputSourceRef keyboardLayout = 
			(TISInputSourceRef)CFArrayGetValueAtIndex(kbds, i);

		if (addToGroups)
    		groups.push_back(keyboardLayout);
	}
	return true;
}
Esempio n. 2
0
bool
COSXKeyState::getGroups(GroupList& groups) const
{
	CFIndex n;
	bool gotLayouts = false;

#if defined(MAC_OS_X_VERSION_10_5)
	// get number of layouts
	CFStringRef keys[] = { kTISPropertyInputSourceCategory };
	CFStringRef values[] = { kTISCategoryKeyboardInputSource };
	CFDictionaryRef dict = CFDictionaryCreate(NULL, (const void **)keys, (const void **)values, 1, NULL, NULL);
	CFArrayRef kbds = TISCreateInputSourceList(dict, false);
	n = CFArrayGetCount(kbds);
	gotLayouts = (n != 0);
#else
	OSStatus status = KLGetKeyboardLayoutCount(&n);
	gotLayouts = (status == noErr);
#endif

	if (!gotLayouts) {
		LOG((CLOG_DEBUG1 "can't get keyboard layouts"));
		return false;
	}

	// get each layout
	groups.clear();
	for (CFIndex i = 0; i < n; ++i) {
		bool addToGroups = true;
#if defined(MAC_OS_X_VERSION_10_5)
		TISInputSourceRef keyboardLayout = 
			(TISInputSourceRef)CFArrayGetValueAtIndex(kbds, i);
#else
		KeyboardLayoutRef keyboardLayout;
		status = KLGetKeyboardLayoutAtIndex(i, &keyboardLayout);
		addToGroups == (status == noErr);
#endif
		if (addToGroups)
    		groups.push_back(keyboardLayout);
	}
	return true;
}
bool
CMSWindowsKeyState::getGroups(GroupList& groups) const
{
	// get keyboard layouts
	UInt32 newNumLayouts = GetKeyboardLayoutList(0, NULL);
	if (newNumLayouts == 0) {
		LOG((CLOG_DEBUG1 "can't get keyboard layouts"));
		return false;
	}
	HKL* newLayouts = new HKL[newNumLayouts];
	newNumLayouts = GetKeyboardLayoutList(newNumLayouts, newLayouts);
	if (newNumLayouts == 0) {
		LOG((CLOG_DEBUG1 "can't get keyboard layouts"));
		delete[] newLayouts;
		return false;
	}

	groups.clear();
	groups.insert(groups.end(), newLayouts, newLayouts + newNumLayouts);
	delete[] newLayouts;
	return true;
}