void CGUIDialogKeyboardGeneric::UpdateButtons() { SET_CONTROL_SELECTED(GetID(), CTL_BUTTON_SHIFT, m_bShift); SET_CONTROL_SELECTED(GetID(), CTL_BUTTON_CAPS, m_keyType == CAPS); SET_CONTROL_SELECTED(GetID(), CTL_BUTTON_SYMBOLS, m_keyType == SYMBOLS); if (m_currentLayout >= m_layouts.size()) m_currentLayout = 0; CKeyboardLayout layout = m_layouts.empty() ? CKeyboardLayout() : m_layouts[m_currentLayout]; SET_CONTROL_LABEL(CTL_BUTTON_LAYOUT, layout.GetName()); unsigned int modifiers = CKeyboardLayout::ModifierKeyNone; if ((m_keyType == CAPS && !m_bShift) || (m_keyType == LOWER && m_bShift)) modifiers |= CKeyboardLayout::ModifierKeyShift; if (m_keyType == SYMBOLS) { modifiers |= CKeyboardLayout::ModifierKeySymbol; if (m_bShift) modifiers |= CKeyboardLayout::ModifierKeyShift; } for (unsigned int row = 0; row < BUTTONS_MAX_ROWS; row++) { for (unsigned int column = 0; column < BUTTONS_PER_ROW; column++) { int buttonID = (row * BUTTONS_PER_ROW) + column + BUTTON_ID_OFFSET; std::string label = layout.GetCharAt(row, column, modifiers); SetControlLabel(buttonID, label); if (!label.empty()) SET_CONTROL_VISIBLE(buttonID); else SET_CONTROL_HIDDEN(buttonID); } } }
void CGUIDialogKeyboardGeneric::OnLayout() { m_currentLayout++; if (m_currentLayout >= m_layouts.size()) m_currentLayout = 0; CKeyboardLayout layout = m_layouts.empty() ? CKeyboardLayout() : m_layouts[m_currentLayout]; CServiceBroker::GetSettings().SetString(CSettings::SETTING_LOCALE_ACTIVEKEYBOARDLAYOUT, layout.GetName()); UpdateButtons(); }
void CKey::OnMouseMove(const UINT nFlags, CPoint point) { if (nFlags & MK_LBUTTON) { ClientToScreen(&point); CKeyboardLayout *parent = (CKeyboardLayout *)GetParent(); if (m_nKeyType == PUSHED_KEY) { int nPointedKey = parent->GetPointedKey(point); if (nPointedKey) { if (nPointedKey != m_nDroppableKey) { if (m_nDroppableKey) { reinterpret_cast<CKey*>(parent->GetDlgItem(m_nDroppableKey))->SetKeyType(m_nDroppableKeyType); SetNoCursor(); } if (IsDroppableKey(nPointedKey)) { m_nDroppableKey = nPointedKey; m_nDroppableKeyType = ((CKey*)parent->GetDlgItem(m_nDroppableKey))->GetKeyType(); reinterpret_cast<CKey*>(parent->GetDlgItem(m_nDroppableKey))->SetKeyType(DROPPABLE_KEY); SetDraggingCursor(); } } } else { if (m_nDroppableKey) { reinterpret_cast<CKey*>(parent->GetDlgItem(m_nDroppableKey))->SetKeyType(m_nDroppableKeyType); m_nDroppableKey = 0; m_nDroppableKeyType = NORMAL_KEY; SetNoCursor(); } } } if (m_nKeyType == REMAPPED_PUSHED_KEY) { if (m_nKey != parent->GetPointedKey(point)) { SetKeyType(REMAPPED_KEY); } } if (m_nKeyType == REMAPPED_KEY) { if (m_nKey == parent->GetPointedKey(point)) { SetKeyType(REMAPPED_PUSHED_KEY); } } } CButton::OnMouseMove(nFlags, point); }
void CGUIDialogKeyboardGeneric::UpdateButtons() { SET_CONTROL_SELECTED(GetID(), CTL_BUTTON_SHIFT, m_bShift); SET_CONTROL_SELECTED(GetID(), CTL_BUTTON_CAPS, m_keyType == CAPS); SET_CONTROL_SELECTED(GetID(), CTL_BUTTON_SYMBOLS, m_keyType == SYMBOLS); if (m_currentLayout >= m_layouts.size()) m_currentLayout = 0; CKeyboardLayout layout = m_layouts.empty() ? CKeyboardLayout() : m_layouts[m_currentLayout]; m_codingtable = layout.GetCodingTable(); if (m_codingtable && !m_codingtable->IsInitialized()) m_codingtable->Initialize(); bool bShowWordList = false; if (m_codingtable) { switch (m_codingtable->GetType()) { case IInputCodingTable::TYPE_WORD_LIST: bShowWordList = true; break; case IInputCodingTable::TYPE_CONVERT_STRING: m_codingtable->SetTextPrev(GetText()); m_hzcode.clear(); break; } } if (bShowWordList) { SET_CONTROL_VISIBLE(CTL_LABEL_HZCODE); SET_CONTROL_VISIBLE(CTL_LABEL_HZLIST); } else { SET_CONTROL_HIDDEN(CTL_LABEL_HZCODE); SET_CONTROL_HIDDEN(CTL_LABEL_HZLIST); } SET_CONTROL_LABEL(CTL_BUTTON_LAYOUT, layout.GetName()); unsigned int modifiers = CKeyboardLayout::ModifierKeyNone; if ((m_keyType == CAPS && !m_bShift) || (m_keyType == LOWER && m_bShift)) modifiers |= CKeyboardLayout::ModifierKeyShift; if (m_keyType == SYMBOLS) { modifiers |= CKeyboardLayout::ModifierKeySymbol; if (m_bShift) modifiers |= CKeyboardLayout::ModifierKeyShift; } for (unsigned int row = 0; row < BUTTONS_MAX_ROWS; row++) { for (unsigned int column = 0; column < BUTTONS_PER_ROW; column++) { int buttonID = (row * BUTTONS_PER_ROW) + column + BUTTON_ID_OFFSET; std::string label = layout.GetCharAt(row, column, modifiers); SetControlLabel(buttonID, label); if (!label.empty()) SET_CONTROL_VISIBLE(buttonID); else SET_CONTROL_HIDDEN(buttonID); } } }
void CKey::OnLButtonUp(const UINT nFlags, CPoint point) { if (m_nKeyType == PUSHED_KEY) { SetKeyType(NORMAL_KEY); } CKeyboardLayout *parent = reinterpret_cast<CKeyboardLayout *>(GetParent()); ClientToScreen(&point); if (m_nKeyType == REMAPPED_PUSHED_KEY) { if (m_nKey == parent->GetPointedKey(point)) { KeyboardLayout *pKeyboardLayout = parent->GetKeyboardLayout(m_nKey); if (pKeyboardLayout) { CString szWindowText; parent->GetDlgItem(pKeyboardLayout->nBaseControlID)->GetWindowText(szWindowText); SetWindowText(szWindowText); parent->ToolTip()->UpdateTipText(parent->GetToolTipID(pKeyboardLayout->nToolTipID), this); ScanCodeMapping mapping = {{0, 0}, {pKeyboardLayout->scancode.nScanCode, pKeyboardLayout->scancode.nPrefix}}; parent->SetScanCodeMap(m_HkeyType, mapping); } SetKeyType(ORIGINAL_KEY); } else { SetKeyType(REMAPPED_KEY); } } int nPointedKey = parent->GetPointedKey(point); if (m_nDroppableKey && nPointedKey) { if (m_nDroppableKey != nPointedKey) { reinterpret_cast<CKey*>(parent->GetDlgItem(m_nDroppableKey))->SetKeyType(m_nDroppableKeyType); if (IsDroppableKey(nPointedKey)) { m_nDroppableKey = nPointedKey; } else { m_nDroppableKey = 0; } } if (m_nDroppableKey) { KeyboardLayout *pKeyboardLayout = parent->GetKeyboardLayout(m_nDroppableKey); KeyboardLayout *pBaseKeyboardLayout = parent->GetKeyboardLayout(m_nKey); if (pKeyboardLayout && pBaseKeyboardLayout) { CString szWindowText; GetWindowText(szWindowText); parent->GetDlgItem(pKeyboardLayout->nCurrentControlID)->SetWindowText(szWindowText); parent->ToolTip()->UpdateTipText(parent->GetToolTipID(pBaseKeyboardLayout->nToolTipID), parent->GetDlgItem(pKeyboardLayout->nCurrentControlID)); reinterpret_cast<CKey *>(parent->GetDlgItem(pKeyboardLayout->nBaseControlID))->SetKeyType(NORMAL_KEY); reinterpret_cast<CKey*>(parent->GetDlgItem(pKeyboardLayout->nCurrentControlID))->SetKeyType(REMAPPED_KEY); ScanCodeMapping mapping = {{pBaseKeyboardLayout->scancode.nScanCode, pBaseKeyboardLayout->scancode.nPrefix}, {pKeyboardLayout->scancode.nScanCode, pKeyboardLayout->scancode.nPrefix}}; parent->SetScanCodeMap(m_HkeyType, mapping); } } } m_nDroppableKey = 0; m_nDroppableKeyType = NORMAL_KEY; SetNormalCursor(); CButton::OnLButtonUp(nFlags, point); }
bool CKeyboardLayoutManager::Load(const std::string& path /* = "" */) { std::string layoutDirectory = path; if (layoutDirectory.empty()) layoutDirectory = KEYBOARD_LAYOUTS_PATH; if (!XFILE::CDirectory::Exists(layoutDirectory)) { CLog::Log(LOGWARNING, "CKeyboardLayoutManager: unable to load keyboard layouts from non-existing directory \"%s\"", layoutDirectory.c_str()); return false; } CFileItemList layouts; if (!XFILE::CDirectory::GetDirectory(CURL(layoutDirectory), layouts, ".xml") || layouts.IsEmpty()) { CLog::Log(LOGWARNING, "CKeyboardLayoutManager: no keyboard layouts found in %s", layoutDirectory.c_str()); return false; } CLog::Log(LOGINFO, "CKeyboardLayoutManager: loading keyboard layouts from %s...", layoutDirectory.c_str()); size_t oldLayoutCount = m_layouts.size(); for (int i = 0; i < layouts.Size(); i++) { std::string layoutPath = layouts[i]->GetPath(); if (layoutPath.empty()) continue; CXBMCTinyXML xmlDoc; if (!xmlDoc.LoadFile(layoutPath)) { CLog::Log(LOGWARNING, "CKeyboardLayoutManager: unable to open %s", layoutPath.c_str()); continue; } const TiXmlElement* rootElement = xmlDoc.RootElement(); if (rootElement == NULL) { CLog::Log(LOGWARNING, "CKeyboardLayoutManager: missing or invalid XML root element in %s", layoutPath.c_str()); continue; } if (rootElement->ValueStr() != "keyboardlayouts") { CLog::Log(LOGWARNING, "CKeyboardLayoutManager: unexpected XML root element \"%s\" in %s", rootElement->Value(), layoutPath.c_str()); continue; } const TiXmlElement* layoutElement = rootElement->FirstChildElement("layout"); while (layoutElement != NULL) { CKeyboardLayout layout; if (!layout.Load(layoutElement)) CLog::Log(LOGWARNING, "CKeyboardLayoutManager: failed to load %s", layoutPath.c_str()); else if (m_layouts.find(layout.GetIdentifier()) != m_layouts.end()) CLog::Log(LOGWARNING, "CKeyboardLayoutManager: duplicate layout with identifier \"%s\" in %s", layout.GetIdentifier().c_str(), layoutPath.c_str()); else { CLog::Log(LOGDEBUG, "CKeyboardLayoutManager: keyboard layout \"%s\" successfully loaded", layout.GetIdentifier().c_str()); m_layouts.insert(std::make_pair(layout.GetIdentifier(), layout)); } layoutElement = layoutElement->NextSiblingElement(); } } return m_layouts.size() > oldLayoutCount; }
TInt CLayoutLibrary::SetLayout(TInt aId) { TInt err = KErrNone; TBool foundLayout = EFalse; // Implementation info array RImplInfoPtrArray implInfoArray; TRACE_INFO( (_L("[HID]\tCLayoutLibrary::SetLayout: id=%d"), aId)); if( aId == iId ) { TRACE_INFO( (_L("[HID]\tCLayoutLibrary::SetLayout: Same layout id=%d, don't load twice"), aId)); return KErrNone; } // Plain ignore is enough. If listing leaves, the array is just empty. TRAP_IGNORE( REComSession::ListImplementationsL( KHidLayoutPluginInterfaceUid, implInfoArray ) ); TRACE_INFO( (_L("[HID]\tCLayoutLibrary::SetLayout: %d plugins listed"),implInfoArray.Count() )); if ( 0 == implInfoArray.Count()) { TRACE_INFO( (_L("[HID]\tCLayoutLibrary::SetLayout: No Drivers found"))); err = KErrNotFound; } else { for (TInt i=0; i<implInfoArray.Count() && !foundLayout; i++) { // parse implementation UID CImplementationInformation* info = implInfoArray[ i ]; TUid implUid = info->ImplementationUid(); TRACE_INFO( (_L("[HID]\tCLayoutLibrary::SetLayout: load plugin 0x%08x"),implUid )); // load driver // Trap so other drivers will be enumerated even if // this fails: CHidLayoutPluginInterface* plugin = NULL; TRAPD( err, plugin = CHidLayoutPluginInterface::NewL( implUid ); TRACE_INFO( (_L("[HID]\tCLayoutLibrary::SetLayout: plugin loaded"))); ); if( err == KErrNone) { CKeyboardLayout* layout = reinterpret_cast<CKeyboardLayout*>(plugin); if (aId == layout->LayoutId()) { TRACE_INFO( (_L("[HID]\tCLayoutLibrary::SetLayout: Found layout %d!"), aId)); foundLayout = ETrue; // Swap the current layout object: CKeyboardLayout* tmpLayout = iLayout; iLayout = layout; iId = aId; iLoaded = ETrue; TRACE_INFO( (_L("[HID]\tCLayoutLibrary::SetLayout: delete old layout"))); delete tmpLayout; } else { TRACE_INFO( (_L("[HID]\tCLayoutLibrary::SetLayout: wrong layout, delete plugin"))); delete plugin; } } else { TRACE_INFO( (_L("[HID]\tCLayoutLibrary::SetLayout: plugin creation failed"))); } }// end of for loop }