public bool TryGetKeyboard(IInputLanguage language, out IKeyboardDefinition keyboard) { // NOTE: on Windows InputLanguage.LayoutName returns a wrong name in some cases. // Therefore we need this overload so that we can identify the keyboard correctly. keyboard = _keyboards.FirstOrDefault(kd => kd.InputLanguage != null && kd.InputLanguage.Equals(language)); return(keyboard != null); }
/// <summary> /// Gets the InputLanguage that has the same layout as <paramref name="keyboardDescription"/>. /// </summary> internal static InputLanguage GetInputLanguage(IKeyboardDefinition keyboardDescription) { InputLanguage sameLayout = null; InputLanguage sameCulture = null; foreach (InputLanguage lang in InputLanguage.InstalledInputLanguages) { // TODO: write some tests try { if (GetLayoutNameEx(lang.Handle).Name == keyboardDescription.Name) { if (keyboardDescription.Locale == lang.Culture.Name) { return(lang); } if (sameLayout == null) { sameLayout = lang; } } else if (keyboardDescription.Locale == lang.Culture.Name && sameCulture == null) { sameCulture = lang; } } catch (CultureNotFoundException) { // we get an exception for non-supported cultures, probably because of a // badly applied .NET patch. // http://www.ironspeed.com/Designer/3.2.4/WebHelp/Part_VI/Culture_ID__XXX__is_not_a_supported_culture.htm and others } } return(sameLayout ?? sameCulture); }
public void OnInputLanguageChanged(IKeyboardDefinition previousKeyboard, IKeyboardDefinition newKeyboard) { Console.WriteLine("TestAppKeyboard.OnLanguageChanged: previous {0}, new {1}", previousKeyboard != null ? previousKeyboard.Layout : "<null>", newKeyboard != null ? newKeyboard.Layout : "<null>"); lblCurrentKeyboard.Text = newKeyboard != null ? newKeyboard.Layout : "<null>"; }
public void OnInputLanguageChanged(IKeyboardDefinition previousKeyboard, IKeyboardDefinition newKeyboard) { Console.WriteLine("TestAppKeyboard.OnLanguageChanged: previous {0}, new {1}", previousKeyboard != null ? previousKeyboard.Layout : "<null>", newKeyboard != null ? newKeyboard.Layout : "<null>"); _form.lblCurrentKeyboard.Text = newKeyboard != null ? newKeyboard.Layout : "<null>"; }
public override WritingSystemDefinition ShowDialogIfNeededAndGetDefinition() { WaitCursor.Show(); try { var variants = new List <VariantSubtag> { WellKnownSubtags.IpaVariant }; variants.AddRange(_templateWritingSystemDefinition.Variants); WritingSystemDefinition ws; WritingSystemFactory.Create(IetfLanguageTag.Create(_templateWritingSystemDefinition.Language, null, _templateWritingSystemDefinition.Region, variants), out ws); string ipaFontName = _fontsForIpa.FirstOrDefault(FontExists); if (!string.IsNullOrEmpty(ipaFontName)) { ws.DefaultFont = new FontDefinition(ipaFontName); } ws.Abbreviation = "ipa"; ws.DefaultFontSize = _templateWritingSystemDefinition.DefaultFontSize; IKeyboardDefinition ipaKeyboard = Keyboard.Controller.AvailableKeyboards.FirstOrDefault(k => k.Id.ToLower().Contains("ipa")); if (ipaKeyboard != null) { ws.Keyboard = ipaKeyboard.Id; } return(ws); } finally { WaitCursor.Hide(); } }
public override void DeactivateKeyboard(IKeyboardDefinition keyboard) { //Console.WriteLine ("DEBUG deactivating {0}", keyboard); if (keyboard is IbusKeyboardDescription) { var ibusAdaptor = GetAdaptor <IbusKeyboardAdaptor>(); if (ibusAdaptor.CanSetIbusKeyboard()) { var context = GlobalCachedInputContext.InputContext; try { context.SetEngine(""); context.Reset(); context.Disable(); } catch (Exception ex) { // We don't want a random DBus exception to kill the program. // If the keyboarding doesn't work quite right, that's still // better than dying spontaneously. (And keyboarding seems // to keep working okay according to my limited testing even // after exceptions have been caught and ignored here.) Console.WriteLine("DBUS EXCEPTION CAUGHT: {0}", ex.Message); } } } GlobalCachedInputContext.Keyboard = null; }
public void WindowsIME_ActivateKeyboardUsingKeyboard_ReportsItWasActivated() { IKeyboardDefinition d = FirstInactiveKeyboard; d.Activate(); Assert.AreEqual(d, Keyboard.Controller.ActiveKeyboard); }
/// <summary> /// Restore the conversion and sentence mode to the states they had last time /// we activated this keyboard (unless we never activated this keyboard since the app /// got started, in which case we use sensible default values). /// </summary> private void RestoreImeConversionStatus(IKeyboardDefinition keyboard) { var winKeyboard = keyboard as WinKeyboardDescription; if (winKeyboard == null) { return; } // Restore the state of the new keyboard to the previous value. If we don't do // that e.g. in Chinese IME the input mode will toggle between English and // Chinese (LT-7487 et al). var windowPtr = winKeyboard.WindowHandle != IntPtr.Zero ? winKeyboard.WindowHandle : Win32.GetFocus(); var windowHandle = new HandleRef(this, windowPtr); // NOTE: Windows uses the same context for all windows of the current thread, so it // doesn't really matter which window handle we pass. var contextPtr = Win32.ImmGetContext(windowHandle); if (contextPtr == IntPtr.Zero) { return; } // NOTE: Chinese Pinyin IME allows to switch between Chinese and Western punctuation. // This can be selected in both Native and Alphanumeric conversion mode. However, // when setting the value the punctuation setting doesn't get restored in Alphanumeric // conversion mode, not matter what I try. I guess that is because Chinese punctuation // doesn't really make sense with Latin characters. var contextHandle = new HandleRef(this, contextPtr); Win32.ImmSetConversionStatus(contextHandle, winKeyboard.ConversionMode, winKeyboard.SentenceMode); Win32.ImmReleaseContext(windowHandle, contextHandle); winKeyboard.WindowHandle = windowPtr; }
public override bool ActivateKeyboard(IKeyboardDefinition keyboard) { Debug.Assert(keyboard is KeyboardDescription); Debug.Assert(((KeyboardDescription)keyboard).Engine == this); if (keyboard is XkbKeyboardDescription) { var xkbKeyboard = keyboard as XkbKeyboardDescription; if (xkbKeyboard.GroupIndex >= 0) SelectKeyboard(xkbKeyboard.GroupIndex); } else if (keyboard is IbusKeyboardDescription) { var ibusKeyboard = keyboard as IbusKeyboardDescription; try { var ibusAdaptor = GetAdaptor<IbusKeyboardAdaptor>(); if (!ibusAdaptor.CanSetIbusKeyboard()) return false; if (ibusAdaptor.IBusKeyboardAlreadySet(ibusKeyboard)) return true; SelectKeyboard(ibusKeyboard.SystemIndex); GlobalCachedInputContext.Keyboard = ibusKeyboard; } catch (Exception e) { Debug.WriteLine(string.Format("Changing keyboard failed, is kfml/ibus running? {0}", e)); return false; } } else { throw new ArgumentException(); } return true; }
public void DeactivateKeyboard(IKeyboardDefinition keyboard) { var winKeyboard = keyboard as WinKeyboardDescription; Debug.Assert(winKeyboard != null); SaveImeConversionStatus(winKeyboard); }
public void GetKeyboard_FromInputLanguage_ExistingKeyboardReturnsKeyboard() { IKeyboardDefinition keyboard = Keyboard.Controller.CreateKeyboard("en-US_foo", KeyboardFormat.Unknown, null); var inputLanguage = new InputLanguageWrapper(new CultureInfo("en-US"), IntPtr.Zero, "foo"); Assert.That(Keyboard.Controller.GetKeyboard(inputLanguage), Is.EqualTo(keyboard)); }
public void CreateKeyboardDefinition_NewKeyboard_ReturnsNewObject() { // REVIEW: adjust this test IKeyboardDefinition keyboard = Keyboard.Controller.CreateKeyboard("en-US_foo", KeyboardFormat.Unknown, Enumerable.Empty <string>()); Assert.That(keyboard, Is.Not.Null); Assert.That(keyboard, Is.TypeOf <XkbKeyboardDescription>()); }
public void GetKeyboard_FromOldParatextId_ExistingKeyboardReturnsKeyboard() { // This is the case of a keyboard that the old Palaso system was incapable of supporting. IKeyboardDefinition keyboardFooBoo = Keyboard.Controller.CreateKeyboard("az-Latn-AZ_foo", KeyboardFormat.Unknown, null); IKeyboardDefinition keyboard = Keyboard.Controller.CreateKeyboard("en-US_foo", KeyboardFormat.Unknown, null); Assert.That(Keyboard.Controller.GetKeyboard("foo|en-US"), Is.EqualTo(keyboard)); Assert.That(Keyboard.Controller.GetKeyboard("foo|az-Latn-AZ"), Is.EqualTo(keyboardFooBoo)); }
private void TextControl_Enter(object sender, EventArgs e) { if (_model == null) { return; } _defaultKeyboard = Keyboard.Controller.ActiveKeyboard; _model.ActivateCurrentKeyboard(); }
protected override void SelectKeyboard(IKeyboardDefinition keyboard) { var xkbKeyboard = keyboard as XkbKeyboardDescription; if (xkbKeyboard != null) { if (xkbKeyboard.GroupIndex >= 0) UnityIbusKeyboardSwitchingAdaptor.SelectKeyboard((uint)xkbKeyboard.GroupIndex); } }
public void WindowsIME_DeActivateKeyboard_RevertsToDefault() { IKeyboardDefinition[] keyboards = Keyboard.Controller.AvailableKeyboards.Where(kd => kd is WinKeyboardDescription).ToArray(); Assert.Greater(keyboards.Length, 1, "This test requires that the Windows IME has at least two languages installed."); IKeyboardDefinition d = GetNonDefaultKeyboard(keyboards); d.Activate(); Assert.AreEqual(d, Keyboard.Controller.ActiveKeyboard); Keyboard.Controller.ActivateDefaultKeyboard(); Assert.AreNotEqual(d, Keyboard.Controller.ActiveKeyboard); }
public bool TryGetKeyboard(string id, out IKeyboardDefinition keyboard) { DefaultKeyboardDefinition kd; if (_keyboards.TryGetValue(id, out kd)) { keyboard = kd; return true; } keyboard = null; return false; }
public bool TryGetKeyboard(string layoutName, string locale, out IKeyboardDefinition keyboard) { if (string.IsNullOrEmpty(layoutName) && string.IsNullOrEmpty(locale)) { keyboard = null; return(false); } keyboard = _keyboards.FirstOrDefault(kd => kd.Layout == layoutName && kd.Locale == locale); return(keyboard != null); }
public void OnLanguageChanged() { IKeyboardDefinition winKeyboard = _keyboardAdaptor.ActiveKeyboard; Debug.WriteLine("Language changed from {0} to {1}", Keyboard.Controller.ActiveKeyboard != null ? Keyboard.Controller.ActiveKeyboard.Layout : "<null>", winKeyboard != null ? winKeyboard.Layout : "<null>"); _keyboardAdaptor._windowsLanguageProfileSinks.ForEach( sink => sink.OnInputLanguageChanged(Keyboard.Controller.ActiveKeyboard, winKeyboard)); }
public override void DeactivateKeyboard(IKeyboardDefinition keyboard) { if (keyboard is IbusKeyboardDescription) { var ibusAdaptor = GetAdaptor <IbusKeyboardAdaptor>(); if (ibusAdaptor.CanSetIbusKeyboard()) { GlobalCachedInputContext.InputContext.Reset(); } } GlobalCachedInputContext.Keyboard = null; }
public void CreateKeyboardDefinition_ExistingKeyboard_ReturnsReference() { var expectedKeyboard = new KeyboardDescription("en-US_foo", "foo - English (US)", "foo", "en-US", true, KeyboardController.Instance.Adaptors[KeyboardAdaptorType.System].SwitchingAdaptor); KeyboardController.Instance.Keyboards.Add(expectedKeyboard); IKeyboardDefinition keyboard = Keyboard.Controller.CreateKeyboard("en-US_foo", KeyboardFormat.Unknown, null); Assert.That(keyboard, Is.SameAs(expectedKeyboard)); Assert.That(keyboard, Is.TypeOf <KeyboardDescription>()); Assert.That(keyboard.Name, Is.EqualTo("foo - English (US)")); }
public void GetKeyboard_FromOldPalasoId_ExistingKeyboardReturnsKeyboard() { // This demonstrates the case of a keyboard that the old Palaso system was incapable of supporting. // There's no way to reference this keyboard, or is there??? IKeyboardDefinition keyboardFooBoo = Keyboard.Controller.CreateKeyboard("az-Latn-AZ_foo", KeyboardFormat.Unknown, null); IKeyboardDefinition keyboardFooF = Keyboard.Controller.CreateKeyboard("en-US_foo-az", KeyboardFormat.Unknown, null); IKeyboardDefinition keyboardFoo = Keyboard.Controller.CreateKeyboard("en-US_foo", KeyboardFormat.Unknown, null); Assert.That(Keyboard.Controller.GetKeyboard("foo-az-en-US"), Is.EqualTo(keyboardFooF)); Assert.That(Keyboard.Controller.GetKeyboard("foo-en-US"), Is.EqualTo(keyboardFoo)); Assert.That(Keyboard.Controller.GetKeyboard("foo-az-Latn-AZ"), Is.EqualTo(keyboardFooBoo)); }
public bool TryGetKeyboard(string id, out IKeyboardDefinition keyboard) { DefaultKeyboardDefinition kd; if (_keyboards.TryGetValue(id, out kd)) { keyboard = kd; return(true); } keyboard = null; return(false); }
public bool TryGetKeyboard(int windowsLcid, out IKeyboardDefinition keyboard) { try { CultureInfo ci = CultureInfo.GetCultureInfo(windowsLcid); keyboard = _keyboards.Values.FirstOrDefault(k => k.Locale == ci.Name); } catch (CultureNotFoundException) { keyboard = null; } return keyboard != null; }
public bool TryGetKeyboard(int windowsLcid, out IKeyboardDefinition keyboard) { try { CultureInfo ci = CultureInfo.GetCultureInfo(windowsLcid); keyboard = _keyboards.Values.FirstOrDefault(k => k.Locale == ci.Name); } catch (CultureNotFoundException) { keyboard = null; } return(keyboard != null); }
public bool TryGetKeyboard(int windowsLcid, out IKeyboardDefinition keyboard) { keyboard = _keyboards.FirstOrDefault( kbd => { if (kbd.InputLanguage == null || kbd.InputLanguage.Culture == null) { return(false); } return(kbd.InputLanguage.Culture.LCID == windowsLcid); }); return(keyboard != null); }
protected virtual void SelectKeyboard(IKeyboardDefinition keyboard) { Debug.Assert(keyboard is KeyboardDescription); Debug.Assert(((KeyboardDescription)keyboard).Engine == this); Debug.Assert(keyboard is XkbKeyboardDescription); var xkbKeyboard = keyboard as XkbKeyboardDescription; if (xkbKeyboard == null) throw new ArgumentException(); if (xkbKeyboard.GroupIndex >= 0) { m_engine.SetGroup(xkbKeyboard.GroupIndex); } }
public bool TryGetKeyboard(string id, out IKeyboardDefinition keyboard) { if (string.IsNullOrEmpty(id)) { keyboard = null; return(false); } KeyboardDescription kd; if (_keyboards.TryGet(id, out kd)) { keyboard = kd; return(true); } string[] parts = id.Split('|'); if (parts.Length == 2) { // This is the way Paratext stored IDs in 7.4-7.5 while there was a temporary bug-fix in place) keyboard = GetKeyboard(parts[0], parts[1]); if (keyboard != NullKeyboard) { return(true); } keyboard = null; return(false); } // Handle old Palaso IDs parts = id.Split('-'); if (parts.Length > 1) { for (int i = 1; i < parts.Length; i++) { keyboard = GetKeyboard(string.Join("-", parts.Take(i)), string.Join("-", parts.Skip(i))); if (keyboard != NullKeyboard) { return(true); } } } keyboard = null; return(false); }
public override bool ActivateKeyboard(IKeyboardDefinition keyboard) { Debug.Assert(keyboard is KeyboardDescription); Debug.Assert(((KeyboardDescription)keyboard).Engine == this); //Console.WriteLine("DEBUG CinnamonIbusAdaptor.ActivateKeyboard({0})", keyboard); if (keyboard is IbusKeyboardDescription) { var ibusKeyboard = keyboard as IbusKeyboardDescription; try { if (m_ibuscom == null) { m_ibuscom = new IbusCommunicator(); } m_ibuscom.FocusIn(); var ibusAdaptor = GetAdaptor <IbusKeyboardAdaptor>(); if (!ibusAdaptor.CanSetIbusKeyboard()) { return(false); } if (ibusAdaptor.IBusKeyboardAlreadySet(ibusKeyboard)) { return(true); } // Set the associated XKB layout SetLayout(ibusKeyboard); // Then set the IBus keyboard (may be an XKB keyboard in actuality) var context = GlobalCachedInputContext.InputContext; //Console.WriteLine ("DEBUG calling context.SetEngine({0})", ibusKeyboard.IBusKeyboardEngine.LongName); context.SetEngine(ibusKeyboard.IBusKeyboardEngine.LongName); GlobalCachedInputContext.Keyboard = ibusKeyboard; } catch (Exception e) { Debug.WriteLine(string.Format("Changing keyboard failed, is kfml/ibus running? {0}", e)); return(false); } } else { throw new ArgumentException(); } return(true); }
public bool ActivateKeyboard(IKeyboardDefinition keyboard) { var keymanKbdDesc = (KeymanKeyboardDescription)keyboard; if (keymanKbdDesc.IsKeyman6) { try { KeymanLink.KeymanLink keymanLink = new KeymanLink.KeymanLink(); if (!keymanLink.Initialize()) { Palaso.Reporting.ErrorReport.NotifyUserOfProblem("Keyman6 could not be activated."); return(false); } keymanLink.SelectKeymanKeyboard(keyboard.Layout); } catch (Exception) { return(false); } } else { try { TavultesoftKeymanClass keyman = new TavultesoftKeymanClass(); int oneBasedIndex = keyman.Keyboards.IndexOf(keyboard.Layout); if (oneBasedIndex < 1) { Palaso.Reporting.ErrorReport.NotifyUserOfProblem("The keyboard '{0}' could not be activated using Keyman 7.", keyboard.Layout); return(false); } keyman.Control.ActiveKeyboard = keyman.Keyboards[oneBasedIndex]; } catch (Exception) { // Keyman 7 not installed? return(false); } } ((IKeyboardControllerImpl)Keyboard.Controller).ActiveKeyboard = keyboard; return(true); }
public bool ActivateKeyboard(IKeyboardDefinition keyboard) { var keymanKbdDesc = (KeymanKeyboardDescription)keyboard; if (keymanKbdDesc.IsKeyman6) { try { KeymanLink.KeymanLink keymanLink = new KeymanLink.KeymanLink(); if (!keymanLink.Initialize()) { Palaso.Reporting.ErrorReport.NotifyUserOfProblem("Keyman6 could not be activated."); return false; } keymanLink.SelectKeymanKeyboard(keyboard.Layout); } catch (Exception) { return false; } } else { try { TavultesoftKeymanClass keyman = new TavultesoftKeymanClass(); int oneBasedIndex = keyman.Keyboards.IndexOf(keyboard.Layout); if (oneBasedIndex < 1) { Palaso.Reporting.ErrorReport.NotifyUserOfProblem("The keyboard '{0}' could not be activated using Keyman 7.", keyboard.Layout); return false; } keyman.Control.ActiveKeyboard = keyman.Keyboards[oneBasedIndex]; } catch (Exception) { // Keyman 7 not installed? return false; } } ((IKeyboardControllerImpl)Keyboard.Controller).ActiveKeyboard = keyboard; return true; }
public bool ActivateKeyboard(IKeyboardDefinition keyboard) { Debug.Assert(keyboard is KeyboardDescription); Debug.Assert(((KeyboardDescription)keyboard).Engine == this); Debug.Assert(keyboard is XkbKeyboardDescription); var xkbKeyboard = keyboard as XkbKeyboardDescription; if (xkbKeyboard == null) { throw new ArgumentException(); } if (xkbKeyboard.GroupIndex >= 0) { m_engine.SetGroup(xkbKeyboard.GroupIndex); } return(true); }
public void KeyboardEqualityDependsOnExpectedProperties() { var keyboard1 = new DefaultKeyboardDefinition() { Layout = "layout1", Locale = "en-US", OperatingSystem = PlatformID.MacOSX }; var keyboard2 = new DefaultKeyboardDefinition() { Layout = "layout1", Locale = "en-US", OperatingSystem = PlatformID.MacOSX }; Assert.That(keyboard1 == keyboard2, Is.True); Assert.That(keyboard1.GetHashCode() == keyboard2.GetHashCode()); Assert.That(keyboard1 != keyboard2, Is.False); IKeyboardDefinition kbd1 = keyboard1; IKeyboardDefinition kbd2 = keyboard2; Assert.That(kbd1.Equals(kbd2), Is.True); keyboard2.Layout = "layout2"; Assert.That(keyboard1 == keyboard2, Is.False); Assert.That(keyboard1.GetHashCode() != keyboard2.GetHashCode()); Assert.That(keyboard1 != keyboard2, Is.True); Assert.That(kbd1.Equals(kbd2), Is.False); keyboard2.Layout = "layout1"; Assert.That(keyboard1 == keyboard2, Is.True); keyboard2.Locale = "en-GB"; Assert.That(keyboard1 == keyboard2, Is.False); Assert.That(keyboard1.GetHashCode() != keyboard2.GetHashCode()); Assert.That(keyboard1 != keyboard2, Is.True); Assert.That(kbd1.Equals(kbd2), Is.False); keyboard2.Locale = "en-US"; Assert.That(keyboard1 == keyboard2, Is.True); keyboard2.OperatingSystem = PlatformID.Unix; Assert.That(keyboard1 == keyboard2, Is.True, "Equality should NOT depend on OS"); Assert.That(keyboard1.GetHashCode() == keyboard2.GetHashCode(), "Hash should NOT depend on OS"); Assert.That(keyboard1 != keyboard2, Is.False); Assert.That(kbd1.Equals(kbd2), Is.True); }
public override bool ActivateKeyboard(IKeyboardDefinition keyboard) { Debug.Assert(keyboard is KeyboardDescription); Debug.Assert(((KeyboardDescription)keyboard).Engine == this); if (keyboard is XkbKeyboardDescription) { var xkbKeyboard = keyboard as XkbKeyboardDescription; if (xkbKeyboard.GroupIndex >= 0) { SelectKeyboard(xkbKeyboard.GroupIndex); } } else if (keyboard is IbusKeyboardDescription) { var ibusKeyboard = keyboard as IbusKeyboardDescription; try { var ibusAdaptor = GetAdaptor <IbusKeyboardAdaptor>(); if (!ibusAdaptor.CanSetIbusKeyboard()) { return(false); } if (ibusAdaptor.IBusKeyboardAlreadySet(ibusKeyboard)) { return(true); } SelectKeyboard(ibusKeyboard.SystemIndex); GlobalCachedInputContext.Keyboard = ibusKeyboard; } catch (Exception e) { Debug.WriteLine(string.Format("Changing keyboard failed, is kfml/ibus running? {0}", e)); return(false); } } else { throw new ArgumentException(); } return(true); }
/// <summary> /// Activate the ibus keyboard /// </summary> /// <remarks>This method will have a different implementation depending on how ibus /// keyboards are implemented.</remarks> protected virtual void SelectKeyboard(KeyboardDescription keyboard) { var ibusKeyboard = (IbusKeyboardDescription)keyboard; // Set the associated XKB keyboard string parentLayout = ibusKeyboard.ParentLayout; if (parentLayout == "en") { parentLayout = "us"; } IKeyboardDefinition xkbKeyboard = KeyboardController.Instance.AvailableKeyboards.FirstOrDefault(kbd => kbd.Layout == parentLayout); if (xkbKeyboard != null) { xkbKeyboard.Activate(); } // Then set the IBus keyboard var context = GlobalCachedInputContext.InputContext; context.SetEngine(ibusKeyboard.IBusKeyboardEngine.LongName); }
private static IKeyboardDefinition GetNonDefaultKeyboard(IList <IKeyboardDefinition> keyboards) { // The default language is not necessarily the first one, so we have to make sure // that we don't select the default one. IKeyboardDefinition defaultKeyboard = Keyboard.Controller.GetKeyboard(new InputLanguageWrapper(InputLanguage.DefaultInputLanguage)); int index = keyboards.Count - 1; while (index >= 0) { if (!keyboards[index].Equals(defaultKeyboard)) { break; } index--; } if (index < 0) { Assert.Fail("Could not find a non-default keyboard !?"); } return(keyboards[index]); }
/// <summary> /// Get the writing system that is most probably intended by the user, when the input /// method changes to the specified <paramref name="inputMethod"/>, given the indicated /// candidates, and that <paramref name="wsCurrent"/> is the preferred result if it is /// a possible WS for the specified input method. wsCurrent is also returned if none /// of the <paramref name="candidates"/> is found to match the specified inputs. /// </summary> /// <param name="inputMethod">The input method or keyboard</param> /// <param name="wsCurrent">The writing system that is currently active in the form. /// This serves as a default that will be returned if no writing system can be /// determined from the first argument. It may be null. Also, if there is more than /// one equally promising match in candidates, and wsCurrent is one of them, it will /// be preferred. This ensures that we don't change WS on the user unless the keyboard /// they have selected definitely indicates a different WS.</param> /// <param name="candidates">The writing systems that should be considered as possible /// return values.</param> /// <returns>The best writing system for <paramref name="inputMethod"/>.</returns> /// <remarks>This method replaces IWritingSystemRepository.GetWsForInputLanguage and /// should preferably be used.</remarks> public IWritingSystemDefinition GetWsForInputMethod(IKeyboardDefinition inputMethod, IWritingSystemDefinition wsCurrent, IWritingSystemDefinition[] candidates) { if (inputMethod == null) { throw new ArgumentNullException("inputMethod"); } // See if the default is suitable. if (wsCurrent != null && inputMethod.Equals(wsCurrent.LocalKeyboard)) { return(wsCurrent); } foreach (var ws in candidates) { if (inputMethod.Equals(ws.LocalKeyboard)) { return(ws); } } return(wsCurrent); }
public void SetKeyboard(IKeyboardDefinition keyboard) { if (keyboard != null) // This should prevent the crash from LT-15498 keyboard.Activate(); }
/// <summary> /// If the new keyboard is the default windows keyboard then we need to deactivate the Keyman /// keyboard without resetting the windows keyboard. However, if the default keyboard is a Keyman /// keyboard associated with the system default keyboard, then don't reset the Keyman keyboard as /// that causes the association to appear as if it's not there due to a Keyman timing issue. /// </summary> protected override bool DeactivatePreviousKeyboard(IKeyboardDefinition keyboardToActivate) { return (!s_keymanKeyboardSwitchingSettingEnabled || keyboardToActivate.Equals(((IKeyboardControllerImpl)Keyboard.Controller).DefaultKeyboard)); }
/// <summary> /// Get the writing system that is most probably intended by the user, when the input /// method changes to the specified <paramref name="inputMethod"/>, given the indicated /// candidates, and that <paramref name="wsCurrent"/> is the preferred result if it is /// a possible WS for the specified input method. wsCurrent is also returned if none /// of the <paramref name="candidates"/> is found to match the specified inputs. /// </summary> /// <param name="inputMethod">The input method or keyboard</param> /// <param name="wsCurrent">The writing system that is currently active in the form. /// This serves as a default that will be returned if no writing system can be /// determined from the first argument. It may be null. Also, if there is more than /// one equally promising match in candidates, and wsCurrent is one of them, it will /// be preferred. This ensures that we don't change WS on the user unless the keyboard /// they have selected definitely indicates a different WS.</param> /// <param name="candidates">The writing systems that should be considered as possible /// return values.</param> /// <returns>The best writing system for <paramref name="inputMethod"/>.</returns> /// <remarks>This method replaces IWritingSystemRepository.GetWsForInputLanguage and /// should preferably be used.</remarks> public IWritingSystemDefinition GetWsForInputMethod(IKeyboardDefinition inputMethod, IWritingSystemDefinition wsCurrent, IWritingSystemDefinition[] candidates) { if (inputMethod == null) throw new ArgumentNullException("inputMethod"); // See if the default is suitable. if (wsCurrent != null && inputMethod.Equals(wsCurrent.LocalKeyboard)) return wsCurrent; foreach (var ws in candidates) { if (inputMethod.Equals(ws.LocalKeyboard)) return ws; } return wsCurrent; }
public void SetKeyboard(IKeyboardDefinition keyboard) { }
public bool TryGetKeyboard(string layoutName, string locale, out IKeyboardDefinition keyboard) { if (string.IsNullOrEmpty(layoutName) && string.IsNullOrEmpty(locale)) { keyboard = null; return false; } keyboard = _keyboards.FirstOrDefault(kd => kd.Layout == layoutName && kd.Locale == locale); return keyboard != null; }
protected virtual bool DeactivatePreviousKeyboard(IKeyboardDefinition keyboardToActivate) { return true; }
public bool TryGetKeyboard(IInputLanguage language, out IKeyboardDefinition keyboard) { // NOTE: on Windows InputLanguage.LayoutName returns a wrong name in some cases. // Therefore we need this overload so that we can identify the keyboard correctly. keyboard = _keyboards.FirstOrDefault(kd => kd.InputLanguage != null && kd.InputLanguage.Equals(language)); return keyboard != null; }
public bool TryGetKeyboard(int windowsLcid, out IKeyboardDefinition keyboard) { keyboard = _keyboards.FirstOrDefault( kbd => { if (kbd.InputLanguage == null || kbd.InputLanguage.Culture == null) return false; return kbd.InputLanguage.Culture.LCID == windowsLcid; }); return keyboard != null; }
public bool ActivateKeyboard(IKeyboardDefinition keyboard) { Debug.Assert(keyboard is KeyboardDescription); Debug.Assert(((KeyboardDescription)keyboard).Engine == this); Debug.Assert(keyboard is XkbKeyboardDescription); var xkbKeyboard = keyboard as XkbKeyboardDescription; if (xkbKeyboard == null) throw new ArgumentException(); if (xkbKeyboard.GroupIndex >= 0) { m_engine.SetGroup(xkbKeyboard.GroupIndex); } return true; }
public void DeactivateKeyboard(IKeyboardDefinition keyboard) { }
public override void DeactivateKeyboard(IKeyboardDefinition keyboard) { if (keyboard is IbusKeyboardDescription) { var ibusAdaptor = GetAdaptor<IbusKeyboardAdaptor>(); if (ibusAdaptor.CanSetIbusKeyboard()) GlobalCachedInputContext.InputContext.Reset(); } GlobalCachedInputContext.Keyboard = null; }
public void DeactivateKeyboard(IKeyboardDefinition keyboard) { try { if (((KeymanKeyboardDescription) keyboard).IsKeyman6) { KeymanLink.KeymanLink keymanLink = new KeymanLink.KeymanLink(); if (keymanLink.Initialize()) keymanLink.SelectKeymanKeyboard(null, false); } else { TavultesoftKeymanClass keyman = new TavultesoftKeymanClass(); keyman.Control.ActiveKeyboard = null; } } catch (Exception) { // Keyman not installed? } }
protected virtual bool DeactivatePreviousKeyboard(IKeyboardDefinition keyboardToActivate) { return (keyboardToActivate as KeyboardDescription) != this; }
public bool TryGetKeyboard(string id, out IKeyboardDefinition keyboard) { if (string.IsNullOrEmpty(id)) { keyboard = null; return false; } KeyboardDescription kd; if (_keyboards.TryGet(id, out kd)) { keyboard = kd; return true; } string[] parts = id.Split('|'); if (parts.Length == 2) { // This is the way Paratext stored IDs in 7.4-7.5 while there was a temporary bug-fix in place) keyboard = GetKeyboard(parts[0], parts[1]); if (keyboard != NullKeyboard) return true; keyboard = null; return false; } // Handle old Palaso IDs parts = id.Split('-'); if (parts.Length > 1) { for (int i = 1; i < parts.Length; i++) { keyboard = GetKeyboard(string.Join("-", parts.Take(i)), string.Join("-", parts.Skip(i))); if (keyboard != NullKeyboard) return true; } } keyboard = null; return false; }
protected override void SelectKeyboard(IKeyboardDefinition keyboard) { var ibusKeyboard = keyboard as IbusKeyboardDescription; var systemIndex = ibusKeyboard.SystemIndex; SelectKeyboard(systemIndex); }
/// <summary> /// Restore the conversion and sentence mode to the states they had last time /// we activated this keyboard (unless we never activated this keyboard since the app /// got started, in which case we use sensible default values). /// </summary> private void RestoreImeConversionStatus(IKeyboardDefinition keyboard) { var winKeyboard = keyboard as WinKeyboardDescription; if (winKeyboard == null) return; // Restore the state of the new keyboard to the previous value. If we don't do // that e.g. in Chinese IME the input mode will toggle between English and // Chinese (LT-7487 et al). var windowPtr = winKeyboard.WindowHandle != IntPtr.Zero ? winKeyboard.WindowHandle : Win32.GetFocus(); var windowHandle = new HandleRef(this, windowPtr); // NOTE: Windows uses the same context for all windows of the current thread, so it // doesn't really matter which window handle we pass. var contextPtr = Win32.ImmGetContext(windowHandle); if (contextPtr == IntPtr.Zero) return; // NOTE: Chinese Pinyin IME allows to switch between Chinese and Western punctuation. // This can be selected in both Native and Alphanumeric conversion mode. However, // when setting the value the punctuation setting doesn't get restored in Alphanumeric // conversion mode, not matter what I try. I guess that is because Chinese punctuation // doesn't really make sense with Latin characters. var contextHandle = new HandleRef(this, contextPtr); Win32.ImmSetConversionStatus(contextHandle, winKeyboard.ConversionMode, winKeyboard.SentenceMode); Win32.ImmReleaseContext(windowHandle, contextHandle); winKeyboard.WindowHandle = windowPtr; }
/// <summary> /// If the new keyboard is the default windows keyboard then we need to deactivate the Keyman /// keyboard without resetting the windows keyboard. However, if the default keyboard is a Keyman /// keyboard associated with the system default keyboard, then don't reset the Keyman keyboard as /// that causes the association to appear as if it's not there due to a Keyman timing issue. /// </summary> protected override bool DeactivatePreviousKeyboard(IKeyboardDefinition keyboardToActivate) { return !KeymanKeyboardSwitchingSettingEnabled || keyboardToActivate == KeyboardController.Instance.DefaultKeyboard; }
public bool ActivateKeyboard(IKeyboardDefinition keyboard) { SwitchKeyboard(keyboard as WinKeyboardDescription); return true; }
/// <summary> /// Adds a keyboard to the list of installed keyboards /// </summary> /// <param name='description'>Keyboard description object</param> public static void RegisterKeyboard(IKeyboardDefinition description) { if (!Instance.Keyboards.Contains(description)) Instance.Keyboards.Add(description); }
/// <summary> /// Gets the InputLanguage that has the same layout as <paramref name="keyboardDescription"/>. /// </summary> internal static InputLanguage GetInputLanguage(IKeyboardDefinition keyboardDescription) { InputLanguage sameLayout = null; InputLanguage sameCulture = null; foreach (InputLanguage lang in InputLanguage.InstalledInputLanguages) { // TODO: write some tests try { if (GetLayoutNameEx(lang.Handle).Name == keyboardDescription.Name) { if (keyboardDescription.Locale == lang.Culture.Name) return lang; if (sameLayout == null) sameLayout = lang; } else if (keyboardDescription.Locale == lang.Culture.Name && sameCulture == null) sameCulture = lang; } catch (CultureNotFoundException) { // we get an exception for non-supported cultures, probably because of a // badly applied .NET patch. // http://www.ironspeed.com/Designer/3.2.4/WebHelp/Part_VI/Culture_ID__XXX__is_not_a_supported_culture.htm and others } } return sameLayout ?? sameCulture; }
public void SetKeyboard(IKeyboardDefinition keyboard) { keyboard.Activate(); }