コード例 #1
0
        private void GetLocales()
        {
            // REVIEW (EberhardB): Could we use InputLanguage instead of LgLanguageEnumerator?

            ILgLanguageEnumerator lenum = LgLanguageEnumeratorClass.Create();
            int id = 0;

            m_BadLocales = new List <IKeyboardErrorDescription>();
            try
            {
                lenum.Init();
                for (; ;)
                {
                    string name;
                    try
                    {
                        lenum.Next(out id, out name);
                    }
                    catch (OutOfMemoryException)
                    {
                        throw;
                    }
                    catch
                    {                     // if we fail to get a language, skip this one, but display once in error message.
                        m_BadLocales.Add(new KeyboardErrorDescription(KeyboardType.System, id));
                        // Under certain conditions it can happen that lenum.Next() returns
                        // E_UNEXPECTED right away. We're then stuck in an infinite loop.
                        if (m_BadLocales.Count > 1000 || id == 0)
                        {
                            break;
                        }
                        continue;
                    }
                    if (id == 0)
                    {
                        break;
                    }
                    KeyboardController.Manager.RegisterKeyboard(id, new KeyboardDescription(id, name, this));
                }
            }
            finally
            {
                // LT-8465 when Windows and Language Options changes are made lenum does not
                // always get updated correctly so we are ensuring the memory for this
                // ComObject gets released.
                Marshal.FinalReleaseComObject(lenum);
            }
        }
コード例 #2
0
 private string GetKeyboardName(int lcid)
 {
     try
     {
         ILgLanguageEnumerator lenum = LgLanguageEnumeratorClass.Create();
         lenum.Init();
         int    id = 0;
         string name;
         do
         {
             lenum.Next(out id, out name);
             if (id == lcid)
             {
                 return(name);
             }
         } while (id != 0);
     }
     catch
     {
     }
     return(null);
 }
コード例 #3
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Inits the language combo.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public void InitLanguageCombo()
        {
            CheckDisposed();

            ILgLanguageEnumerator lenum = LgLanguageEnumeratorClass.Create();

            m_cbLangId.Items.Clear();             // Clear out any old items.
            lenum.Init();
            int       id = 0;
            string    name;
            string    selectedName = null;
            int       selectedId   = m_langDef.WritingSystem.Locale;
            ArrayList badLocales   = new ArrayList();

            try
            {
                for (; ;)
                {
                    try
                    {
                        lenum.Next(out id, out name);
                    }
                    catch (OutOfMemoryException)
                    {
                        throw;
                    }
                    catch
                    {                     // if we fail to get a language, skip this one, but display once in error message.
                        badLocales.Add(id);
                        continue;
                    }
                    if (id == 0)
                    {
                        break;
                    }
                    try
                    {
                        m_cbLangId.Items.Add(new LangIdComboItem(id, name));
                        // The 'if' below should make a 'fr-CAN' language choose a french keyboard, if installed.
                        if (id == selectedId)
                        {
                            selectedName = name;
                        }
                    }
                    catch
                    {
                        // Problem adding a language to the combo box. Notify user and continue.
                        if (errorMessage1Out == false)
                        {
                            errorMessage1Out = true;
                            string message = FwCoreDlgControls.kstidBadLanguageName;
                            MessageBox.Show(this.ParentForm, FwCoreDlgControls.kstidBadLanguageName,
                                            FwCoreDlgControls.kstidError, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                        break;
                    }
                }
            }
            finally
            {
                // LT-8465 when Windows and Language Options changes are made lenum does not always get
                // updated correctly so we are ensuring the memory for this ComObject gets released.
                System.Runtime.InteropServices.Marshal.FinalReleaseComObject(lenum);
            }

            if (badLocales.Count > 0 && errorMessage2Out == false)
            {
                errorMessage2Out = true;
                string strBadLocales = "";
                foreach (int loc in badLocales)
                {
                    strBadLocales += loc + ", ";
                }
                strBadLocales = strBadLocales.Substring(0, strBadLocales.Length - 2);
                string caption = FwCoreDlgControls.kstidError;
                MessageBox.Show(this.ParentForm, String.Format(FwCoreDlgControls.kstidBadLocales,
                                                               strBadLocales), caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            if (selectedName == null)
            {
                try
                {
                    // Try selecting the default language
                    selectedName = InputLanguage.DefaultInputLanguage.Culture.DisplayName;
                }
                catch
                {
                    selectedName = FwCoreDlgControls.kstidInvalidKeyboard;
                }
                finally
                {
                    // The DefaultInputLanguage should already be in the control
                    if (selectedName == FwCoreDlgControls.kstidInvalidKeyboard)
                    {
                        m_cbLangId.Items.Add(new LangIdComboItem(selectedId, selectedName));
                    }
                }
            }
            int idx = m_cbLangId.FindStringExact(selectedName, -1);

            m_cbLangId.SelectedIndex = idx;
        }