LabeledMultiStringControl (used in InsertEntryDlg) has an FdoCache, but it is used only to figure out the writing systems to use; the control works with a dummy cache, object, and flid, and the resulting text must be read back.
Inheritance: System.Windows.Forms.UserControl, IVwNotifyChange, IFWDisposable
		/// <summary>
		/// Convert the text box for the caption to a multilingual string control.
		/// </summary>
		public void UseMultiStringCaption(FdoCache cache, int wsMagic, IVwStylesheet stylesheet)
		{
			m_lmscCaption = new LabeledMultiStringControl(cache, wsMagic, stylesheet);
			m_txtCaption.Hide();
			m_lmscCaption.Location = m_txtCaption.Location;
			m_lmscCaption.Width = m_txtCaption.Width;
			m_lmscCaption.Anchor = m_txtCaption.Anchor;
			m_lmscCaption.AccessibleName = m_txtCaption.AccessibleName;
			m_lmscCaption.Dock = DockStyle.Fill;

			// Grow the dialog and move all lower controls down to make room.
			pnlCaption.Controls.Remove(m_txtCaption);
			m_lmscCaption.TabIndex = m_txtCaption.TabIndex;	// assume the same tab order as the 'designed' control
			pnlCaption.Controls.Add(m_lmscCaption);
		}
Beispiel #2
0
		protected void SetDlgInfo(FdoCache cache, IMoMorphType morphType, int wsVern, MorphTypeFilterType filter)
		{
			try
			{
				IVwStylesheet stylesheet = FontHeightAdjuster.StyleSheetFromMediator(m_mediator);
				var xnWindow = (XmlNode) m_mediator.PropertyTable.GetValue("WindowConfiguration");
				XmlNode configNode = xnWindow.SelectSingleNode("controls/parameters/guicontrol[@id=\"matchingEntries\"]/parameters");

				SearchEngine searchEngine = SearchEngine.Get(m_mediator, "InsertEntrySearchEngine", () => new InsertEntrySearchEngine(cache));

				m_matchingObjectsBrowser.Initialize(cache, stylesheet, m_mediator, configNode,
					searchEngine);

				m_cache = cache;

				m_fNewlyCreated = false;
				m_oldForm = "";

				// Set fonts for the two edit boxes.
				if (stylesheet != null)
				{
					m_tbLexicalForm.StyleSheet = stylesheet;
					m_tbGloss.StyleSheet = stylesheet;
				}

				// Set writing system factory and code for the two edit boxes.
				IWritingSystemContainer wsContainer = cache.ServiceLocator.WritingSystems;
				IWritingSystem defAnalWs = wsContainer.DefaultAnalysisWritingSystem;
				IWritingSystem defVernWs = wsContainer.DefaultVernacularWritingSystem;
				m_tbLexicalForm.WritingSystemFactory = cache.WritingSystemFactory;
				m_tbGloss.WritingSystemFactory = cache.WritingSystemFactory;

				m_tbLexicalForm.AdjustStringHeight = false;
				m_tbGloss.AdjustStringHeight = false;

				if (wsVern <= 0)
					wsVern = defVernWs.Handle;
				// initialize to empty TsStrings
				ITsStrFactory tsf = cache.TsStrFactory;
				//we need to use the wsVern so that tbLexicalForm is sized correctly for the font size.
				//In Interlinear text the baseline can be in any of the vernacular writing systems, not just
				//the defaultVernacularWritingSystem.
				ITsString tssForm = tsf.MakeString("", wsVern);
				ITsString tssGloss = tsf.MakeString("", defAnalWs.Handle);

				using (m_updateTextMonitor.Enter())
				{
					m_tbLexicalForm.WritingSystemCode = wsVern;
					m_tbGloss.WritingSystemCode = defAnalWs.Handle;

					TssForm = tssForm;
					TssGloss = tssGloss;
				}

				// start building index
				m_matchingObjectsBrowser.SearchAsync(BuildSearchFieldArray(tssForm, tssGloss));

				((ISupportInitialize)(m_tbLexicalForm)).EndInit();
				((ISupportInitialize)(m_tbGloss)).EndInit();

				if (WritingSystemServices.GetWritingSystemList(m_cache, WritingSystemServices.kwsVerns, false).Count > 1)
				{
					msLexicalForm = ReplaceTextBoxWithMultiStringBox(m_tbLexicalForm, WritingSystemServices.kwsVerns, stylesheet);
					msLexicalForm.TextChanged += tbLexicalForm_TextChanged;
				}
				else
				{
					// See if we need to adjust the height of the lexical form
					AdjustTextBoxAndDialogHeight(m_tbLexicalForm);
				}

				// JohnT addition: if multiple analysis writing systems, replace tbGloss with msGloss
				if (WritingSystemServices.GetWritingSystemList(m_cache, WritingSystemServices.kwsAnals, false).Count > 1)
				{
					msGloss = ReplaceTextBoxWithMultiStringBox(m_tbGloss, WritingSystemServices.kwsAnals, stylesheet);
					m_lnkAssistant.Top = msGloss.Bottom - m_lnkAssistant.Height;
					msGloss.TextChanged += tbGloss_TextChanged;
				}
				else
				{
					// See if we need to adjust the height of the gloss
					AdjustTextBoxAndDialogHeight(m_tbGloss);
				}

				m_msaGroupBox.Initialize(cache, m_mediator, m_lnkAssistant, this);
				// See if we need to adjust the height of the MSA group box.
				int oldHeight = m_msaGroupBox.Height;
				int newHeight = Math.Max(m_msaGroupBox.PreferredHeight, oldHeight);
				GrowDialogAndAdjustControls(newHeight - oldHeight, m_msaGroupBox);
				m_msaGroupBox.AdjustInternalControlsAndGrow();

				Text = GetTitle();
				m_lnkAssistant.Enabled = false;

				// Set font for the combobox.
				m_cbMorphType.Font = new Font(defAnalWs.DefaultFontName, 10);

				// Populate morph type combo.
				// first Fill ComplexFormType combo, since cbMorphType controls
				// whether it gets enabled and which index is selected.
				m_cbComplexFormType.Font = new Font(defAnalWs.DefaultFontName, 10);
				var rgComplexTypes = new List<ICmPossibility>(m_cache.LangProject.LexDbOA.ComplexEntryTypesOA.ReallyReallyAllPossibilities.ToArray());
				rgComplexTypes.Sort();
				m_idxNotComplex = m_cbComplexFormType.Items.Count;
				m_cbComplexFormType.Items.Add(new DummyEntryType(LexTextControls.ksNotApplicable, false));
				m_idxUnknownComplex = m_cbComplexFormType.Items.Count;
				m_cbComplexFormType.Items.Add(new DummyEntryType(LexTextControls.ksUnknownComplexForm, true));
				for (int i = 0; i < rgComplexTypes.Count; ++i)
				{
					var type = (ILexEntryType)rgComplexTypes[i];
					m_cbComplexFormType.Items.Add(type);
				}
				m_cbComplexFormType.SelectedIndex = 0;
				m_cbComplexFormType.Visible = true;
				m_cbComplexFormType.Enabled = true;
				// Convert from Set to List, since the Set can't sort.

				var al = new List<IMoMorphType>();
				foreach (IMoMorphType mType in m_cache.LanguageProject.LexDbOA.MorphTypesOA.ReallyReallyAllPossibilities.Cast<IMoMorphType>())
				{
					switch (filter)
					{
						case MorphTypeFilterType.Prefix:
							if (mType.IsPrefixishType)
								al.Add(mType);
							break;

						case MorphTypeFilterType.Suffix:
							if (mType.IsSuffixishType)
								al.Add(mType);
							break;

						case MorphTypeFilterType.Any:
							al.Add(mType);
							break;
					}
				}
				al.Sort();
				for (int i = 0; i < al.Count; ++i)
				{
					m_cbMorphType.Items.Add(al[i]);
					if (al[i] == morphType)
						m_cbMorphType.SelectedIndex = i;
				}

				m_morphType = morphType; // Is this still needed?
				m_msaGroupBox.MorphTypePreference = m_morphType;
				// Now position the searching animation
				/*
					* This position put the animation over the Glossing Assistant button. LT-9146
				m_searchAnimation.Top = groupBox2.Top - m_searchAnimation.Height - 5;
				m_searchAnimation.Left = groupBox2.Right - m_searchAnimation.Width - 10;
					*/
				/* This position puts the animation over the top left corner, but will that
					* look okay with right-to-left?
				m_searchAnimation.Top = groupBox2.Top + 40;
				m_searchAnimation.Left = groupBox2.Left + 10;
					*/
				// This position puts the animation close to the middle of the list.
				m_searchAnimation.Top = m_matchingEntriesGroupBox.Top + (m_matchingEntriesGroupBox.Height / 2) - (m_searchAnimation.Height / 2);
				m_searchAnimation.Left = m_matchingEntriesGroupBox.Left + (m_matchingEntriesGroupBox.Width / 2) - (m_searchAnimation.Width / 2);
			}
			catch(Exception e)
			{
				MessageBox.Show(e.ToString());
				MessageBox.Show(e.StackTrace);
			}
		}
Beispiel #3
0
		private LabeledMultiStringControl ReplaceTextBoxWithMultiStringBox(FwTextBox tb, int wsType,
			IVwStylesheet stylesheet)
		{
			tb.Hide();
			var ms = new LabeledMultiStringControl(m_cache, wsType, stylesheet)
			{
				Location = tb.Location,
				Width = tb.Width,
				Anchor = tb.Anchor
			};

			int oldHeight = tb.Parent.Height;
			FontHeightAdjuster.GrowDialogAndAdjustControls(tb.Parent, ms.Height - tb.Height, ms);
			tb.Parent.Controls.Add(ms);

			// Grow the dialog and move all lower controls down to make room.
			GrowDialogAndAdjustControls(tb.Parent.Height - oldHeight, tb.Parent);
			ms.TabIndex = tb.TabIndex;	// assume the same tab order as the single ws control
			return ms;
		}
Beispiel #4
0
		protected void SetDlgInfo(FdoCache cache, IMoMorphType morphType, int wsVern, MorphTypeFilterType filter)
		{
			ReplaceMatchingEntriesControl();
			IVwStylesheet stylesheet = null;
			if (m_mediator != null)
			{
				stylesheet = FontHeightAdjuster.StyleSheetFromMediator(m_mediator);
				if (matchingEntries != null)
					matchingEntries.Initialize(cache, stylesheet, m_mediator);
			}
			m_cache = cache;

			m_fNewlyCreated = false;
			m_oldForm = "";

			if (m_types == null)
				m_types = new MoMorphTypeCollection(cache);

			// Set fonts for the two edit boxes.
			if (stylesheet != null)
			{
				tbLexicalForm.StyleSheet = stylesheet;
				tbGloss.StyleSheet = stylesheet;
			}

			// Set writing system factory and code for the two edit boxes.
			tbLexicalForm.WritingSystemFactory = cache.LanguageWritingSystemFactoryAccessor;
			if (wsVern <= 0)
				wsVern = cache.LangProject.DefaultVernacularWritingSystem;
			tbLexicalForm.WritingSystemCode = wsVern;
			tbLexicalForm.AdjustStringHeight = false;

			tbGloss.WritingSystemFactory = cache.LanguageWritingSystemFactoryAccessor;
			tbGloss.WritingSystemCode = cache.LangProject.DefaultAnalysisWritingSystem;
			tbGloss.AdjustStringHeight = false;

			// initialize to empty TsStrings
			ITsStrFactory tsf = TsStrFactoryClass.Create();
			//we need to use the weVern so that tbLexicalForm is sized correctly for the font size.
			//In Interlinear text the baseline can be in any of the vernacular writing systems, not just
			//the defaultVernacularWritingSystem.
			TssForm = tsf.MakeString("", wsVern);
			TssGloss = tsf.MakeString("", cache.LangProject.DefaultAnalysisWritingSystem);
			((System.ComponentModel.ISupportInitialize)(this.tbLexicalForm)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.tbGloss)).EndInit();


			int cVern = LabeledMultiStringView.GetWritingSystemList(m_cache, LangProject.kwsVerns, false).Length;
			if (cVern > 1)
			{
				msLexicalForm = ReplaceTextBoxWithMultiStringBox(tbLexicalForm, LangProject.kwsVerns, stylesheet);
				msLexicalForm.TextChanged += new EventHandler(tbLexicalForm_TextChanged);
			}
			else
			{
				// See if we need to adjust the height of the lexical form
				AdjustTextBoxAndDialogHeight(tbLexicalForm);
			}

			// JohnT addition: if multiple analysis writing systems, replace tbGloss with msGloss
			int cWritingSystem = LabeledMultiStringView.GetWritingSystemList(m_cache, LangProject.kwsAnals, false).Length;
			if (cWritingSystem > 1)
			{
				msGloss = ReplaceTextBoxWithMultiStringBox(tbGloss, LangProject.kwsAnals, stylesheet);
				m_lnkAssistant.Top = msGloss.Bottom - m_lnkAssistant.Height;
				msGloss.TextChanged += new System.EventHandler(this.tbGloss_TextChanged);
			}
			else
			{
				// See if we need to adjust the height of the gloss
				AdjustTextBoxAndDialogHeight(tbGloss);
			}

			m_msaGroupBox.Initialize(cache, m_mediator, m_lnkAssistant, this);
			// See if we need to adjust the height of the MSA group box.
			int oldHeight = m_msaGroupBox.Height;
			int newHeight = Math.Max(m_msaGroupBox.PreferredHeight, oldHeight);
			GrowDialogAndAdjustControls(newHeight - oldHeight, m_msaGroupBox);
			m_msaGroupBox.AdjustInternalControlsAndGrow();

			Text = GetTitle();
			m_lnkAssistant.Enabled = false;

			// Set font for the combobox.
			cbMorphType.Font =
				new Font(cache.LangProject.DefaultAnalysisWritingSystemFont, 10);

			// Populate morph type combo.
			// first Fill ComplexFormType combo, since cbMorphType controls
			// whether it gets enabled and which index is selected.
			cbComplexFormType.Font =
				new Font(cache.LangProject.DefaultAnalysisWritingSystemFont, 10);
			List<ICmPossibility> rgComplexTypes = new List<ICmPossibility>(m_cache.LangProject.LexDbOA.ComplexEntryTypesOA.ReallyReallyAllPossibilities.ToArray());
			rgComplexTypes.Sort();
			m_idxNotComplex = cbComplexFormType.Items.Count;
			cbComplexFormType.Items.Add(new DummyEntryType(LexTextControls.ksNotApplicable, false));
			m_idxUnknownComplex = cbComplexFormType.Items.Count;
			cbComplexFormType.Items.Add(new DummyEntryType(LexTextControls.ksUnknownComplexForm, true));
			for (int i = 0; i < rgComplexTypes.Count; ++i)
			{
				ILexEntryType type = (ILexEntryType)rgComplexTypes[i];
				cbComplexFormType.Items.Add(type);
			}
			cbComplexFormType.SelectedIndex = 0;
			cbComplexFormType.Visible = true;
			cbComplexFormType.Enabled = true;
			// Convert from Set to List, since the Set can't sort.

			List<ICmPossibility> al = new List<ICmPossibility>();
			foreach (ICmPossibility mType in m_cache.LangProject.LexDbOA.MorphTypesOA.ReallyReallyAllPossibilities)
			{
				switch (filter)
				{
					case MorphTypeFilterType.prefix:
						if (MoMorphType.IsPrefixishType(m_cache, mType.Hvo))
							al.Add(mType);
						break;

					case MorphTypeFilterType.suffix:
						if (MoMorphType.IsSuffixishType(m_cache, mType.Hvo))
							al.Add(mType);
						break;

					case MorphTypeFilterType.any:
						al.Add(mType);
						break;
				}
			}
			al.Sort();
			for (int i = 0; i < al.Count; ++i)
			{
				IMoMorphType type = (IMoMorphType)al[i];

				cbMorphType.Items.Add(type);
				//previously had "if (type == morphType)" which was always false
				if (type.Equals(morphType))
					cbMorphType.SelectedIndex = i;
			}

			m_morphType = morphType; // Is this still needed?
			m_msaGroupBox.MorphTypePreference = m_morphType;
			// Now position the searching animation
			/*
			 * This position put the animation over the Glossing Assistant button. LT-9146
			m_searchAnimtation.Top = groupBox2.Top - m_searchAnimtation.Height - 5;
			m_searchAnimtation.Left = groupBox2.Right - m_searchAnimtation.Width - 10;
			 */
			/* This position puts the animation over the top left corner, but will that
			 * look okay with right-to-left?
			m_searchAnimtation.Top = groupBox2.Top + 40;
			m_searchAnimtation.Left = groupBox2.Left + 10;
			 */
			// This position puts the animation close to the middle of the list.
			m_searchAnimtation.Top = groupBox2.Top + (groupBox2.Top / 2);
			m_searchAnimtation.Left = groupBox2.Left + (groupBox2.Right / 2);
		}
Beispiel #5
0
		private void CollectValuesFromMultiStringControl(LabeledMultiStringControl lmsControl,
			IList<ITsString> alternativesCollector, ITsString defaultIfNoMultiString)
		{
			var bldr = m_cache.TsStrFactory;
			if (lmsControl == null)
			{
				alternativesCollector.Add(defaultIfNoMultiString);
			}
			else
			{
				// Save all the writing systems.
				for (var i = 0; i < lmsControl.NumberOfWritingSystems; i++)
				{
					int ws;
					ITsString tss = lmsControl.ValueAndWs(i, out ws);
					if (tss != null && tss.Text != null)
					{
						// In the case of copied text, sometimes the string had the wrong ws attached to it. (LT-11950)
						alternativesCollector.Add(bldr.MakeString(tss.Text, ws));
					}
				}
			}
		}
Beispiel #6
0
		protected void InitializeMultiStringControls()
		{
			// protected for testing. N.B. if testing, set test cache first!
			m_uiWss = GetUiWritingSystemAndEnglish();
			//m_delta = 0;
			m_lmscListName = ReplaceTextBoxWithMultiStringBox(m_tboxListName,
				m_stylesheet);
			m_lmscDescription = ReplaceTextBoxWithMultiStringBox(m_tboxDescription,
				m_stylesheet);
		}
Beispiel #7
0
		private static bool HasMsContentChanged(IMultiAccessorBase oldStrings, LabeledMultiStringControl msControl)
		{
			var cws = msControl.NumberOfWritingSystems;
			for (var i = 0; i < cws; i++)
			{
				var curWs = msControl.Ws(i);
				//if (oldStrings.get_String(curWs).Text != Cache.TsStrFactory.EmptyString(curWs).Text
				//    && oldStrings.get_String(curWs).Text != msControl.Value(curWs).Text)
				//    return true;
				if (oldStrings.get_String(curWs).Text != msControl.Value(curWs).Text)
					return true;
			}
			return false;
		}
Beispiel #8
0
		protected static void SetAllMultiAlternatives(IMultiAccessorBase multiField,
			LabeledMultiStringControl source)
		{
			var cws = source.NumberOfWritingSystems;
			for (var i = 0; i < cws; i++)
			{
				var curWs = source.Ws(i);
				multiField.set_String(curWs, source.Value(curWs));
			}
		}
Beispiel #9
0
		protected static void LoadAllMultiAlternatives(IMultiAccessorBase multiField,
			LabeledMultiStringControl destination)
		{
			var cws = destination.NumberOfWritingSystems;
			for (var i = 0; i < cws; i++)
			{
				var curWs = destination.Ws(i);
				if (curWs <= 0)
					continue;
				int actualWs;
				ITsString tssStr;
				if (!multiField.TryWs(curWs, out actualWs, out tssStr))
					continue;
				destination.SetValue(curWs, tssStr);
			}
		}
Beispiel #10
0
		private LabeledMultiStringControl ReplaceTextBoxWithMultiStringBox(TextBox tb,
			IVwStylesheet stylesheet)
		{
			Debug.Assert(Cache != null, "Need a cache to setup a MultiStringBox.");
			tb.Hide();
			if (m_uiWss.Count == 0)
				return null;
			var ms = new LabeledMultiStringControl(Cache, m_uiWss, stylesheet);
			ms.Location = tb.Location;
			ms.Width = tb.Width;
			ms.Anchor = tb.Anchor;
			ms.AccessibleName = tb.AccessibleName;

			// Grow the dialog and move all lower controls down to make room.
			Controls.Remove(tb);
			ms.TabIndex = tb.TabIndex;	// assume the same tab order as the 'designed' control
			Controls.Add(ms);
			FontHeightAdjuster.GrowDialogAndAdjustControls(this, ms.Height - tb.Height, ms);
			return ms;
		}