Beispiel #1
0
        private void LexImportWizardLanguage_Load(object sender, EventArgs e)
        {
            // (Bev) modify a few labels
            if (m_LinguaLinksImport)
            {
                Text             = LexTextControls.ksSpecifyFwWs;
                lblComment.Text  = LexTextControls.ksSpecifyFwWsDescription;
                lblLangDesc.Text = LexTextControls.ksLanguageDefinition;
            }
            else
            {
                if (m_AddUsage)
                {
                    Text = LexTextControls.ksAddLangMapping;
                }
                else
                {
                    Text = LexTextControls.ksModifyLangMapping;
                }
            }

            tbLangDesc.Text = m_LangDesc;

            // initialize the 'ws' combo box and the AddWs button with the data from the DB
            ReloadWsCombo();
            btnAddWS.Initialize(m_cache, m_helpTopicProvider, m_app, m_cache.ServiceLocator.WritingSystemManager.WritingSystems);

            // select the proper index if there is a valid writing system
            int index = 0;

            if (!string.IsNullOrEmpty(m_wsName))
            {
                index = cbWS.FindStringExact(m_wsName);
                if (index < 0)
                {
                    index = 0;
                }
            }
            cbWS.SelectedIndex = index;

            LoadEncodingConverters();

            index = 0;
            if (!string.IsNullOrEmpty(m_encConverter))
            {
                index = cbEC.FindStringExact(m_encConverter);
                if (index < 0)
                {
                    index = 0;
                }
            }
            cbEC.SelectedIndex = index;
        }
Beispiel #2
0
        /// <summary>
        /// This is also called when the selection changes. If the user types the exact name
        /// of an existing item, we may get both notifications, and the order we get them
        /// is not certain. However, we expect that whatever the order, the last notification
        /// will have a correct SelectedIndex and so should produce the right effects.
        /// We do this continuously, not just when the user leaves the control, because
        /// the natural place to go when leaving is the abbreviation, but that might be
        /// disabled when the user starts editing this box.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void m_variantName_TextChanged(object sender, EventArgs e)
        {
            m_enableLangTagSideEffects = false;
            string variantName = m_variantName.Text.Trim();
            // We don't want to store a trimmed version here because it causes very strange
            // behavior when backspace over a space.
            int selIndex = m_variantName.FindStringExact(variantName);

            if (selIndex >= 0)
            {
                m_variantName.SelectedIndex = selIndex;
                m_variantAbbrev.Enabled     = true;
                m_variantAbbrev.Text        = ((VariantSubtag)m_variantName.Items[selIndex]).Code;
                m_variantAbbrev.Enabled     = ((VariantSubtag)m_variantName.Items[selIndex]).IsPrivateUse;
            }
            else if (string.IsNullOrEmpty(variantName))
            {
                m_variantAbbrev.Enabled = false;
                m_variantAbbrev.Text    = "";
            }
            else
            {
                m_variantAbbrev.Enabled = true;
                m_variantAbbrev.Text    = GetValidAbbr(variantName, 8).ToLowerInvariant();
            }
            VariantName = variantName;

            HandleAudioVariant();
            m_enableLangTagSideEffects = true;
            OnScriptRegionVariantChanged(EventArgs.Empty);
        }
Beispiel #3
0
        /// <summary>
        /// This is also called when the selection changes. If the user types the exact name
        /// of an existing item, we may get both notifications, and the order we get them
        /// is not certain (In fact, it appears that it is somewhat unpredictable(!) whether
        /// the index changed happens at all!).
        /// However, whatever the order, we make the behavior depend only on whether what's
        /// in the text matches one of the items.
        /// We do this continuously, not just when the user leaves the control, because
        /// the natural place to go when leaving is the abbreviation, but that might be
        /// disabled when the user starts editing this box.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void m_regionName_TextChanged(object sender, EventArgs e)
        {
            string regionName = m_regionName.Text.Trim();

            // We don't want to store a trimmed version here because it causes very strange
            // behavior when backspace over a space.
            int selIndex = m_regionName.FindStringExact(regionName);

            if (selIndex >= 0)
            {
                RegionName             = regionName;
                m_regionAbbrev.Text    = ((RegionSubtag)m_regionName.Items[selIndex]).Code;
                m_regionAbbrev.Enabled = ((RegionSubtag)m_regionName.Items[selIndex]).IsPrivateUse;
                return;
            }

            if (string.IsNullOrEmpty(regionName))
            {
                m_regionAbbrev.Text    = "";
                m_regionAbbrev.Enabled = false;
            }
            else
            {
                m_regionAbbrev.Enabled = true;
                m_regionAbbrev.Text    = GetValidAbbr(regionName, 2).ToUpperInvariant();
            }

            RegionName        = regionName;
            m_ws.RegionSubtag = RegionSubtag;

            if (m_enableLangTagSideEffects)
            {
                DoSideEffectsOfChangingScriptTag();
            }
        }
Beispiel #4
0
        /// <summary>
        /// This is also called when the selection changes. If the user types the exact name
        /// of an existing item, we may get both notifications, and the order we get them
        /// is not certain (In fact, it appears that it is somewhat unpredictable(!) whether
        /// the index changed happens at all!).
        /// However, whatever the order, we make the behavior depend only on whether what's
        /// in the text matches one of the items.
        /// We do this continuously, not just when the user leaves the control, because
        /// the natural place to go when leaving is the abbreviation, but that might be
        /// disabled when the user starts editing this box.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void m_scriptName_TextChanged(object sender, EventArgs e)
        {
            string scriptName = m_scriptName.Text.Trim();
            // We don't want to store a trimmed version here because it causes very strange
            // behavior when backspace over a space.
            int selIndex = m_scriptName.FindStringExact(scriptName);

            if (selIndex >= 0)
            {
                ScriptName             = scriptName;
                m_scriptAbbrev.Text    = ((ScriptSubtag)m_scriptName.Items[selIndex]).Code;
                m_scriptAbbrev.Enabled = ((ScriptSubtag)m_scriptName.Items[selIndex]).IsPrivateUse;
                return;
            }

            if (string.IsNullOrEmpty(scriptName))
            {
                ScriptName             = "";
                m_scriptAbbrev.Text    = "";
                m_scriptAbbrev.Enabled = false;
            }
            else
            {
                m_scriptAbbrev.Text    = CultureInfo.InvariantCulture.TextInfo.ToTitleCase(GetValidAbbr(scriptName, 4));
                m_scriptAbbrev.Enabled = m_scriptName.Enabled;                 // true except for Zxxx for audio
            }

            // We need to prevent setting this if we already set it as a side effect of choosing audio.
            // Otherwise the WS changes it to x-Zxxx.
            if (!IsVoiceWritingSystem)
            {
                m_ws.ScriptSubtag = ScriptSubtag;
            }

            if (m_enableLangTagSideEffects)
            {
                DoSideEffectsOfChangingScriptTag();
            }
        }
Beispiel #5
0
        /// <summary>
        /// This is also called when the selection changes. If the user types the exact name
        /// of an existing item, we may get both notifications, and the order we get them
        /// is not certain. However, we expect that whatever the order, the last notification
        /// will have a correct SelectedIndex and so should produce the right effects.
        /// We do this continuously, not just when the user leaves the control, because
        /// the natural place to go when leaving is the abbreviation, but that might be
        /// disabled when the user starts editing this box.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void m_variantName_TextChanged(object sender, EventArgs e)
        {
            m_enableLangTagSideEffects = false;
            string variantName = m_variantName.Text.Trim();
            // We don't want to store a trimmed version here because it causes very strange
            // behavior when backspace over a space.
            int selIndex = m_variantName.FindStringExact(variantName);

            if (selIndex >= 0)
            {
                m_variantName.SelectedIndex = selIndex;
                m_variantAbbrev.Enabled     = true;
                var variantSubtag = (VariantSubtag)m_variantName.Items[selIndex];
                if (variantSubtag == WellKnownSubtags.IpaPhonemicPrivateUse || variantSubtag == WellKnownSubtags.IpaPhoneticPrivateUse)
                {
                    m_variantAbbrev.Text = WellKnownSubtags.IpaVariant + "-x-" + variantSubtag.Code;
                }
                else
                {
                    m_variantAbbrev.Text = variantSubtag.IsPrivateUse ? "x-" + variantSubtag.Code : variantSubtag.Code;
                }
                m_variantAbbrev.Enabled = variantSubtag.IsPrivateUse && !StandardSubtags.CommonPrivateUseVariants.Contains(variantSubtag);
            }
            else if (string.IsNullOrEmpty(variantName))
            {
                m_variantAbbrev.Enabled = false;
                m_variantAbbrev.Text    = "";
            }
            else
            {
                m_variantAbbrev.Enabled = true;
                m_variantAbbrev.Text    = GetValidAbbr(variantName, 8).ToLowerInvariant();
            }
            VariantName = variantName;

            HandleAudioVariant();
            m_enableLangTagSideEffects = true;
            OnScriptRegionVariantChanged(EventArgs.Empty);
        }
        private void LexImportWizardLanguage_Load(object sender, EventArgs e)
        {
            // (Bev) modify a few labels
            if (m_LinguaLinksImport)
            {
                Text             = LexTextControls.ksSpecifyFwWs;
                lblComment.Text  = LexTextControls.ksSpecifyFwWsDescription;
                lblLangDesc.Text = LexTextControls.ksLanguageDefinition;
            }
            else
            {
                if (m_AddUsage)
                {
                    Text = LexTextControls.ksAddLangMapping;
                }
                else
                {
                    Text = LexTextControls.ksModifyLangMapping;
                }
            }

            tbLangDesc.Text = m_LangDesc;

            // initialize the 'ws' combo box and the AddWs button with the data from the DB
            foreach (IWritingSystem ws in m_cache.ServiceLocator.WritingSystemManager.LocalWritingSystems)
            {
                var wsi = new WsInfo(ws.DisplayLabel, ws.Id, ws.LegacyMapping);
                m_wsInfo.Add(wsi.KEY, wsi);
                cbWS.Items.Add(wsi);
            }

            cbWS.Sorted = false;
            var wsiIgnore = new WsInfo();

            cbWS.Items.Add(wsiIgnore);
            btnAddWS.Initialize(m_cache, m_helpTopicProvider, m_app, m_stylesheet, m_cache.ServiceLocator.WritingSystemManager.LocalWritingSystems);

            // select the proper index if there is a valid writing system
            int index = 0;

            if (!string.IsNullOrEmpty(m_wsName))
            {
                index = cbWS.FindStringExact(m_wsName);
                if (index < 0)
                {
                    index = 0;
                }
            }
            cbWS.SelectedIndex = index;

            LoadEncodingConverters();

            index = 0;
            if (!string.IsNullOrEmpty(m_encConverter))
            {
                index = cbEC.FindStringExact(m_encConverter);
                if (index < 0)
                {
                    index = 0;
                }
            }
            cbEC.SelectedIndex = index;
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Inits the language combo.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void InitLanguageCombo()
        {
            CheckDisposed();

            m_langIdComboBox.Items.Clear();             // Clear out any old items.
            string selectedName = null;
            int    selectedId   = m_ws.LCID;

            foreach (var item in KeyboardController.InstalledKeyboards.Where(
                         keyboard => keyboard.Type == KeyboardType.System))
            {
                try
                {
                    m_langIdComboBox.Items.Add(item);
                    // The 'if' below should make a 'fr-CAN' language choose a french keyboard, if installed.
                    if (item.Id == selectedId)
                    {
                        selectedName = item.Name;
                    }
                }
                catch
                {
                    // Problem adding a language to the combo box. Notify user and continue.
                    if (errorMessage1Out == false)
                    {
                        errorMessage1Out = true;
                        MessageBoxUtils.Show(ParentForm, FwCoreDlgControls.kstidBadLanguageName,
                                             FwCoreDlgControls.kstidError, MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    break;
                }
            }

            var badLocales = KeyboardController.ErrorKeyboards.Where(
                keyboard => keyboard.Type == KeyboardType.System).ToList();

            if (badLocales.Count > 0 && errorMessage2Out == false)
            {
                errorMessage2Out = true;
                string strBadLocales = badLocales.Aggregate("", (current, loc) => current + (loc.Details + ", "));
                strBadLocales = strBadLocales.Substring(0, strBadLocales.Length - 2);
                string caption = FwCoreDlgControls.kstidError;
                MessageBoxUtils.Show(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_langIdComboBox.Items.Add(new KeyboardDescription(selectedId, selectedName, null));
                    }
                }
            }
            int idx = m_langIdComboBox.FindStringExact(selectedName, -1);

            m_langIdComboBox.SelectedIndex = idx;
        }
Beispiel #8
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;
        }
Beispiel #9
0
        private void LexImportWizardLanguage_Load(object sender, System.EventArgs e)
        {
            // (Bev) modify a few labels
            if (m_LinguaLinksImport)
            {
                this.Text        = LexTextControls.ksSpecifyFwWs;
                lblComment.Text  = LexTextControls.ksSpecifyFwWsDescription;
                lblLangDesc.Text = LexTextControls.ksLanguageDefinition;
            }
            else
            {
                if (m_AddUsage)
                {
                    this.Text = LexTextControls.ksAddLangMapping;
                }
                else
                {
                    this.Text = LexTextControls.ksModifyLangMapping;
                }
            }

            tbLangDesc.Text = m_LangDesc;

            //getting name for a writing system given the ICU code.
            ILgWritingSystemFactory wsf = m_cache.LanguageWritingSystemFactoryAccessor;
            int            wsUser       = wsf.UserWs;
            int            wsVern       = m_cache.DefaultVernWs;
            IWritingSystem ws           = wsf.get_EngineOrNull(wsVern);

            m_wsiDefault = new WsInfo(wsVern, ws.get_UiName(wsVern), ws.IcuLocale, ws.LegacyMapping);

            // getting list of writing systems to populate a combo.
            int cws = wsf.NumberOfWs;

            using (ArrayPtr ptr = MarshalEx.ArrayToNative(cws, typeof(int)))
            {
                wsf.GetWritingSystems(ptr, cws);
                int[] vws = (int[])MarshalEx.NativeToArray(ptr, cws, typeof(int));
                for (int iws = 0; iws < cws; iws++)
                {
                    if (vws[iws] == 0)
                    {
                        continue;
                    }
                    ws = wsf.get_EngineOrNull(vws[iws]);
                    if (ws == null)
                    {
                        continue;
                    }
                    string name     = ws.get_UiName(wsUser);
                    string icuLocal = ws.IcuLocale;
                    string mapName  = ws.LegacyMapping;
                    WsInfo wsi      = new WsInfo(vws[iws], name, icuLocal, mapName);
                    m_wsInfo.Add(wsi.KEY, wsi);
                }
            }

            // initialize the 'ws' combo box with the data from the DB
            foreach (DictionaryEntry entry in m_wsInfo)
            {
                WsInfo wsi = entry.Value as WsInfo;
                cbWS.Items.Add(wsi);
            }
            cbWS.Sorted = false;
            WsInfo wsiIgnore = new WsInfo();

            cbWS.Items.Add(wsiIgnore);

            // select the proper index if there is a valid writhing system
            int index = 0;

            if (m_wsName != null && m_wsName != "")
            {
                index = cbWS.FindStringExact(m_wsName);
                if (index < 0)
                {
                    index = 0;
                }
            }
            cbWS.SelectedIndex = index;

            LoadEncodingConverters();

            index = 0;
            if (m_encConverter != null && m_encConverter != "")
            {
                index = cbEC.FindStringExact(m_encConverter);
                if (index < 0)
                {
                    index = 0;
                }
            }
            cbEC.SelectedIndex = index;
        }