/// <summary> /// Executes in two distinct scenarios. /// /// 1. If disposing is true, the method has been called directly /// or indirectly by a user's code via the Dispose method. /// Both managed and unmanaged resources can be disposed. /// /// 2. If disposing is false, the method has been called by the /// runtime from inside the finalizer and you should not reference (access) /// other managed objects, as they already have been garbage collected. /// Only unmanaged resources can be disposed. /// </summary> /// <param name="disposing"></param> /// <remarks> /// If any exceptions are thrown, that is fine. /// If the method is being done in a finalizer, it will be ignored. /// If it is thrown by client code calling Dispose, /// it needs to be handled by fixing the bug. /// /// If subclasses override this method, they should call the base implementation. /// </remarks> protected override void Dispose(bool disposing) { //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************"); // Must not be run more than once. if (IsDisposed) { return; } if (disposing) { // Dispose managed resources here. if (m_sda != null) { m_sda.RemoveNotification(this); m_sda = null; } AtomicReferenceLauncher arl = Control as AtomicReferenceLauncher; if (arl != null) { arl.ChoicesMade -= new EventHandler(this.RefreshTree); arl.ViewSizeChanged -= new FwViewSizeChangedEventHandler(this.OnViewSizeChanged); AtomicReferenceView view = (AtomicReferenceView)arl.MainControl; view.ViewSizeChanged -= new FwViewSizeChangedEventHandler(this.OnViewSizeChanged); } } // Dispose unmanaged resources here, whether disposing is true or false. base.Dispose(disposing); }
/// <summary> /// /// </summary> /// <param name="persistenceProvider"></param> /// <param name="stringTbl"></param> protected override void SetupControls(IPersistenceProvider persistenceProvider, Mediator mediator, StringTable stringTbl) { AtomicReferenceLauncher arl = new AtomicReferenceLauncher(); arl.Initialize(m_cache, m_obj, m_flid, m_fieldName, persistenceProvider, mediator, DisplayNameProperty, BestWsName); // TODO: Get better default 'best ws'. arl.ConfigurationNode = ConfigurationNode; XmlNode deParams = ConfigurationNode.SelectSingleNode("deParams"); if (XmlUtils.GetOptionalBooleanAttributeValue( deParams, "changeRequiresRefresh", false)) { arl.ChoicesMade += new EventHandler(this.RefreshTree); } // We don't want to be visible until later, since otherwise we get a temporary // display in the wrong place with the wrong size that serves only to annoy the // user. See LT-1518 "The drawing of the DataTree for Lexicon/Advanced Edit draws // some initial invalid controls." Becoming visible when we set the width and // height seems to delay things enough to avoid this visual clutter. arl.Visible = false; this.Control = arl; arl.ViewSizeChanged += new FwViewSizeChangedEventHandler(this.OnViewSizeChanged); AtomicReferenceView view = (AtomicReferenceView)arl.MainControl; view.ViewSizeChanged += new FwViewSizeChangedEventHandler(this.OnViewSizeChanged); }
private int GetOtherHvo(AtomicReferenceSlice otherSlice, int otherFlid, bool myIsFromPOS, out AtomicReferenceLauncher otherOne) { otherOne = null; int otherHvo = 0; if (otherSlice != null) { AtomicReferenceLauncher otherControl = otherSlice.Control as AtomicReferenceLauncher; int of = otherSlice.Flid; if (otherSlice.Object == Object && (otherSlice.Flid == otherFlid)) { otherOne = otherControl; if (myIsFromPOS) { otherHvo = (Object as MoDerivAffMsa).ToPartOfSpeechRAHvo; } else { otherHvo = (Object as MoDerivAffMsa).FromPartOfSpeechRAHvo; } } } return(otherHvo); }
/// <summary> /// /// </summary> /// <param name="persistenceProvider"></param> /// <param name="stringTbl"></param> protected override void SetupControls(IPersistenceProvider persistenceProvider, Mediator mediator, StringTable stringTbl) { base.SetupControls(persistenceProvider, mediator, stringTbl); AtomicReferenceLauncher arl = Control as AtomicReferenceLauncher; arl.ReferenceChanged += new FwSelectionChangedEventHandler(OnReferenceChanged); }
/// <summary> /// This PropChanged detects a needed UI update. See LT-9002. /// </summary> public void PropChanged(int hvo, int tag, int ivMin, int cvIns, int cvDel) { if (m_flid == (int)PartOfSpeech.PartOfSpeechTags.kflidDefaultInflectionClass && cvIns == 0 && cvDel > 0 && (tag == (int)PartOfSpeech.PartOfSpeechTags.kflidInflectionClasses || tag == (int)MoInflClass.MoInflClassTags.kflidSubclasses) && (m_obj as PartOfSpeech).DefaultInflectionClassRAHvo == 0) { AtomicReferenceLauncher arl = (AtomicReferenceLauncher)this.Control; arl.UpdateDisplayFromDatabase(); } }
protected override void OnSizeChanged(EventArgs e) { base.OnSizeChanged(e); if (this.Width == m_dxLastWidth) { return; } m_dxLastWidth = Width; // BEFORE doing anything, actions below may trigger recursive call. AtomicReferenceLauncher arl = (AtomicReferenceLauncher)this.Control; AtomicReferenceView view = (AtomicReferenceView)arl.MainControl; view.PerformLayout(); int h1 = view.RootBox.Height; int hNew = Math.Max(h1, ContainingDataTree.GetMinFieldHeight()) + 3; if (hNew != this.Height) { this.Height = hNew; } }
/// <summary> /// Handle changes in the size of the underlying view. /// </summary> protected void OnViewSizeChanged(object sender, FwViewSizeEventArgs e) { // For now, just handle changes in the height. AtomicReferenceLauncher arl = (AtomicReferenceLauncher)this.Control; AtomicReferenceView view = (AtomicReferenceView)arl.MainControl; int hMin = ContainingDataTree.GetMinFieldHeight(); int h1 = view.RootBox.Height; Debug.Assert(e.Height == h1); int hOld = TreeNode.Height; int hNew = Math.Max(h1, hMin) + 3; if (hNew > hOld) { TreeNode.Height = hNew; arl.Height = hNew - 1; view.Height = hNew - 1; this.Height = hNew; } }
/// <summary> /// Executes in two distinct scenarios. /// /// 1. If disposing is true, the method has been called directly /// or indirectly by a user's code via the Dispose method. /// Both managed and unmanaged resources can be disposed. /// /// 2. If disposing is false, the method has been called by the /// runtime from inside the finalizer and you should not reference (access) /// other managed objects, as they already have been garbage collected. /// Only unmanaged resources can be disposed. /// </summary> /// <param name="disposing"></param> /// <remarks> /// If any exceptions are thrown, that is fine. /// If the method is being done in a finalizer, it will be ignored. /// If it is thrown by client code calling Dispose, /// it needs to be handled by fixing the bug. /// /// If subclasses override this method, they should call the base implementation. /// </remarks> protected override void Dispose(bool disposing) { //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************"); // Must not be run more than once. if (IsDisposed) { return; } if (disposing) { // Dispose managed resources here. AtomicReferenceLauncher arl = Control as AtomicReferenceLauncher; arl.ReferenceChanged -= new FwSelectionChangedEventHandler(OnReferenceChanged); } // Dispose unmanaged resources here, whether disposing is true or false. base.Dispose(disposing); }
public override void RegisterWithContextHelper() { CheckDisposed(); if (this.Control != null) { Mediator mediator = this.Mediator; StringTable tbl = null; if (mediator.HasStringTable) { tbl = mediator.StringTbl; } string caption = XmlUtils.GetLocalizedAttributeValue(tbl, ConfigurationNode, "label", ""); AtomicReferenceLauncher launcher = (AtomicReferenceLauncher)this.Control; //NB: which is 0 and which is 1 is sensitive to the front-back order of these widgets in the launcher mediator.SendMessage("RegisterHelpTargetWithId", new object[] { launcher.Controls[1], caption, HelpId }, false); mediator.SendMessage("RegisterHelpTargetWithId", new object[] { launcher.Controls[0], caption, HelpId, "Button" }, false); } }
/// <summary> /// Handle interaction between to and from POS for a derivational affix MSA. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <remarks> /// If the new value is zero, then set the other one's value to zero, as well. /// If the other one's value is zero, then set it to the new value. /// In all cases, set this one's value to the new value. /// </remarks> protected void OnReferenceChanged(object sender, SIL.FieldWorks.Common.Utils.FwObjectSelectionEventArgs e) { Debug.Assert(sender is AtomicReferenceLauncher); AtomicReferenceLauncher source = (AtomicReferenceLauncher)sender; Debug.Assert(Control == source); Debug.Assert(Object is MoDerivAffMsa); AtomicReferenceLauncher otherControl = null; int idxSender = Parent.Controls.IndexOf(this); int otherFlid; bool myIsFromPOS = true; if (m_flid == (int)MoDerivAffMsa.MoDerivAffMsaTags.kflidFromPartOfSpeech) { otherFlid = (int)MoDerivAffMsa.MoDerivAffMsaTags.kflidToPartOfSpeech; } else { otherFlid = (int)MoDerivAffMsa.MoDerivAffMsaTags.kflidFromPartOfSpeech; myIsFromPOS = false; } int otherHvo = 0; Slice otherSlice = null; int idxOther; if (idxSender > 0) { idxOther = idxSender - 1; while (otherSlice == null || (otherSlice.Indent == Indent && idxOther > 0 && otherSlice.Object == Object)) { otherSlice = (Slice)Parent.Controls[idxOther--]; if (otherSlice is AtomicReferenceSlice && (otherSlice as AtomicReferenceSlice).Flid == otherFlid) { break; } } if (otherSlice != null && otherSlice is AtomicReferenceSlice) { otherHvo = GetOtherHvo(otherSlice as AtomicReferenceSlice, otherFlid, myIsFromPOS, out otherControl); } else { otherSlice = null; } } if (otherControl == null && idxSender < Parent.Controls.Count) { idxOther = idxSender + 1; while (otherSlice == null || (otherSlice.Indent == Indent && idxOther > 0 && otherSlice.Object == Object)) { otherSlice = (Slice)Parent.Controls[idxOther++]; if (otherSlice is AtomicReferenceSlice && (otherSlice as AtomicReferenceSlice).Flid == otherFlid) { break; } } if (otherSlice != null && otherSlice is AtomicReferenceSlice) { otherHvo = GetOtherHvo(otherSlice as AtomicReferenceSlice, otherFlid, myIsFromPOS, out otherControl); } else { otherSlice = null; } } MoDerivAffMsa msa = Object as MoDerivAffMsa; if (e.Hvo == 0 && otherHvo != 0) { if (otherControl == null) { otherControl.AddItem(0); // Clear the other one, as well. } else { if (m_flid == (int)MoDerivAffMsa.MoDerivAffMsaTags.kflidFromPartOfSpeech) { msa.ToPartOfSpeechRAHvo = 0; } else { msa.FromPartOfSpeechRAHvo = 0; } } } else if (otherHvo == 0 && e.Hvo > 0) { if (otherControl == null) { // The other one is not available (filtered out?), // so set it directly using the msa. if (m_flid == (int)MoDerivAffMsa.MoDerivAffMsaTags.kflidFromPartOfSpeech) { msa.ToPartOfSpeechRAHvo = e.Hvo; } else { msa.FromPartOfSpeechRAHvo = e.Hvo; } } else { otherControl.AddItem(e.Hvo); // Set the other guy to this value. } } }
private int GetOtherHvo(AtomicReferenceSlice otherSlice, int otherFlid, bool myIsFromPOS, out AtomicReferenceLauncher otherOne) { otherOne = null; int otherHvo = 0; if (otherSlice != null) { AtomicReferenceLauncher otherControl = otherSlice.Control as AtomicReferenceLauncher; int of = otherSlice.Flid; if (otherSlice.Object == Object && (otherSlice.Flid == otherFlid)) { otherOne = otherControl; if (myIsFromPOS) otherHvo = (Object as MoDerivAffMsa).ToPartOfSpeechRAHvo; else otherHvo = (Object as MoDerivAffMsa).FromPartOfSpeechRAHvo; } } return otherHvo; }
/// <summary> /// Handle interaction between POS and Slot ptoeprties for a inflectional affix MSA. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <remarks> /// If the new value is zero, then set the Slot prop to zero. /// If the new value is not zero, then make sure the Slot prop is valid. /// If the current slot is not legal for the new POS value, then set it to zero. /// Otherwise leave the slot value alone. /// </remarks> protected void OnReferenceChanged(object sender, SIL.FieldWorks.Common.Utils.FwObjectSelectionEventArgs e) { Debug.Assert(sender is AtomicReferenceLauncher); AtomicReferenceLauncher source = (AtomicReferenceLauncher)sender; Debug.Assert(Control == source); Debug.Assert(Object is MoInflAffMsa); int idxSender = Parent.Controls.IndexOf(this); int otherFlid = (int)MoInflAffMsa.MoInflAffMsaTags.kflidSlots; Slice otherSlice = null; int idxOther; // Try to get the Slots slice. // Check for slices before this one. if (idxSender > 0) { idxOther = idxSender - 1; while (idxOther >= 0 && (otherSlice == null || (otherSlice.Indent == Indent && idxOther > 0 && otherSlice.Object == Object))) { otherSlice = (Slice)Parent.Controls[idxOther--]; if (otherSlice is ReferenceVectorSlice && (otherSlice as ReferenceVectorSlice).Flid == otherFlid) { break; } otherSlice = null; } } // Check for following slices, if we didn't get one earlier. if (otherSlice == null && idxSender < Parent.Controls.Count) { idxOther = idxSender + 1; while (idxOther < Parent.Controls.Count && (otherSlice == null || (otherSlice.Indent == Indent && idxOther > 0 && otherSlice.Object == Object))) { otherSlice = (Slice)Parent.Controls[idxOther++]; if (otherSlice is ReferenceVectorSlice && (otherSlice as ReferenceVectorSlice).Flid == otherFlid) { break; } otherSlice = null; } } VectorReferenceLauncher otherControl = null; if (otherSlice != null) { Debug.Assert((otherSlice as ReferenceVectorSlice).Flid == otherFlid); Debug.Assert(otherSlice.Object == Object); otherControl = otherSlice.Control as VectorReferenceLauncher; Debug.Assert(otherControl != null); } MoInflAffMsa msa = Object as MoInflAffMsa; int slotHvo = 0; if (msa.SlotsRC.Count > 0) { int[] hvos = msa.SlotsRC.HvoArray; slotHvo = hvos[0]; } if (e.Hvo == 0 || slotHvo > 0) { IPartOfSpeech pos = msa.PartOfSpeechRA; List <int> slotIDs = new List <int>(); if (pos != null) { slotIDs = pos.AllAffixSlotIDs; } bool clearSlot = ((e.Hvo == 0) || (!slotIDs.Contains(slotHvo))); if (clearSlot) { if (otherControl == null) { msa.ClearAllSlots(); // The slot slice is not showing, so directly set the object's Slot property. } else { otherControl.AddItem(0); // Reset it using the other slice, so it gets refreshed. } } } }
/// <summary> /// Handle interaction between to and from POS for a derivational affix MSA. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <remarks> /// If the new value is zero, then set the other one's value to zero, as well. /// If the other one's value is zero, then set it to the new value. /// In all cases, set this one's value to the new value. /// </remarks> protected void OnReferenceChanged(object sender, FwObjectSelectionEventArgs e) { Debug.Assert(sender is AtomicReferenceLauncher); var source = (AtomicReferenceLauncher)sender; Debug.Assert(Control == source); Debug.Assert(Object is IMoDerivAffMsa); AtomicReferenceLauncher otherControl = null; int idxSender = ContainingDataTree.Slices.IndexOf(this); int otherFlid; bool myIsFromPOS = true; if (m_flid == MoDerivAffMsaTags.kflidFromPartOfSpeech) { otherFlid = MoDerivAffMsaTags.kflidToPartOfSpeech; } else { otherFlid = MoDerivAffMsaTags.kflidFromPartOfSpeech; myIsFromPOS = false; } int otherHvo = 0; Slice otherSlice = null; int idxOther; if (idxSender > 0) { idxOther = idxSender - 1; while (otherSlice == null || (otherSlice.Indent == Indent && idxOther > 0 && otherSlice.Object == Object)) { otherSlice = ContainingDataTree.Slices[idxOther--]; if (otherSlice is AtomicReferenceSlice && (otherSlice as AtomicReferenceSlice).Flid == otherFlid) { break; } } if (otherSlice != null && otherSlice is AtomicReferenceSlice) { otherHvo = GetOtherHvo(otherSlice as AtomicReferenceSlice, otherFlid, myIsFromPOS, out otherControl); } else { otherSlice = null; } } if (otherControl == null && idxSender < ContainingDataTree.Slices.Count) { idxOther = idxSender + 1; while (otherSlice == null || (otherSlice.Indent == Indent && idxOther > 0 && otherSlice.Object == Object)) { otherSlice = ContainingDataTree.Slices[idxOther++]; if (otherSlice is AtomicReferenceSlice && (otherSlice as AtomicReferenceSlice).Flid == otherFlid) { break; } } if (otherSlice != null && otherSlice is AtomicReferenceSlice) { otherHvo = GetOtherHvo(otherSlice as AtomicReferenceSlice, otherFlid, myIsFromPOS, out otherControl); } else { otherSlice = null; } } var msa = Object as IMoDerivAffMsa; if (e.Hvo == 0 && otherHvo != 0) { if (otherControl != null) { if (m_flid == MoDerivAffMsaTags.kflidFromPartOfSpeech) { msa.ToPartOfSpeechRA = null; } else { msa.FromPartOfSpeechRA = null; } } } else if (otherHvo == 0 && e.Hvo > 0) { if (otherControl == null) { // The other one is not available (filtered out?), // so set it directly using the msa. if (m_flid == MoDerivAffMsaTags.kflidFromPartOfSpeech) { msa.ToPartOfSpeechRA = m_cache.ServiceLocator.GetInstance <IPartOfSpeechRepository>().GetObject(e.Hvo); } else { msa.FromPartOfSpeechRA = m_cache.ServiceLocator.GetInstance <IPartOfSpeechRepository>().GetObject(e.Hvo); } } else { otherControl.AddItem(m_cache.ServiceLocator.GetObject(e.Hvo)); // Set the other guy to this value. } } }
private int GetOtherHvo(AtomicReferenceSlice otherSlice, int otherFlid, bool myIsFromPOS, out AtomicReferenceLauncher otherOne) { otherOne = null; int otherHvo = 0; if (otherSlice != null) { var otherControl = otherSlice.Control as AtomicReferenceLauncher; if (otherSlice.Object == Object && (otherSlice.Flid == otherFlid)) { otherOne = otherControl; otherHvo = myIsFromPOS ? ((IMoDerivAffMsa)Object).ToPartOfSpeechRA.Hvo : ((IMoDerivAffMsa)Object).FromPartOfSpeechRA.Hvo; } } return(otherHvo); }
protected override void UpdateDisplayFromDatabase() { AtomicReferenceLauncher arl = (AtomicReferenceLauncher)this.Control; arl.UpdateDisplayFromDatabase(); }
private int GetOtherHvo(AtomicReferenceSlice otherSlice, int otherFlid, bool myIsFromPOS, out AtomicReferenceLauncher otherOne) { otherOne = null; int otherHvo = 0; if (otherSlice != null) { var otherControl = otherSlice.Control as AtomicReferenceLauncher; if (otherSlice.Object == Object && (otherSlice.Flid == otherFlid)) { otherOne = otherControl; otherHvo = myIsFromPOS ? ((IMoDerivAffMsa)Object).ToPartOfSpeechRA.Hvo : ((IMoDerivAffMsa)Object).FromPartOfSpeechRA.Hvo; } } return otherHvo; }