void InterlinDocForAnalysis_RightMouseClickedEvent(SimpleRootSite sender, FwRightMouseClickEventArgs e) { e.EventHandled = true; // for the moment we always claim to have handled it. ContextMenuStrip menu = new ContextMenuStrip(); // Add spelling items if any (i.e., if we clicked a squiggle word). int hvoObj, tagAnchor; if (GetTagAndObjForOnePropSelection(e.Selection, out hvoObj, out tagAnchor) && (tagAnchor == SegmentTags.kflidFreeTranslation || tagAnchor == SegmentTags.kflidLiteralTranslation || tagAnchor == NoteTags.kflidContent)) { var helper = new SpellCheckHelper(Cache); helper.MakeSpellCheckMenuOptions(e.MouseLocation, this, menu); } int hvoNote; if (CanDeleteNote(e.Selection, out hvoNote)) { if (menu.Items.Count > 0) { menu.Items.Add(new ToolStripSeparator()); } // Add the delete item. string sMenuText = ITextStrings.ksDeleteNote; ToolStripMenuItem item = new ToolStripMenuItem(sMenuText); item.Click += OnDeleteNote; menu.Items.Add(item); } if (menu.Items.Count > 0) { e.Selection.Install(); menu.Show(this, e.MouseLocation); } }
/// -------------------------------------------------------------------------------- /// <summary> /// Initializes the graphics object /// </summary> /// <param name="parent">Containing rootsite</param> /// -------------------------------------------------------------------------------- public HoldGraphics(SimpleRootSite parent) { if (parent.Disposing || parent.IsDisposed) return; // don't do anything if the parent is disposing or already disposed m_Parent = parent; m_Parent.InitGraphics(); }
/// ----------------------------------------------------------------------------------- /// <summary> /// Creates and shows a context menu with spelling suggestions. /// </summary> /// <param name="pt">The location on the screen of the word for which we want spelling /// suggestions (usually the mouse position)</param> /// <param name="rootsite">The focused rootsite</param> /// <returns><c>true</c> if a menu was created and shown (with at least one item); /// <c>false</c> otherwise</returns> /// ----------------------------------------------------------------------------------- public bool ShowContextMenu(Point pt, SimpleRootSite rootsite) { ContextMenuStrip menu = new ContextMenuStrip(); MakeSpellCheckMenuOptions(pt, rootsite, menu); if (menu.Items.Count == 0) return false; menu.Show(rootsite, pt); return true; }
void HandleRightMouseClickedEvent(SimpleRootSite sender, FwRightMouseClickEventArgs e) { string sMenu = XmlUtils.GetOptionalAttributeValue(this.ConfigurationNode, "contextMenu"); if (String.IsNullOrEmpty(sMenu)) return; e.EventHandled = true; e.Selection.Install(); XWindow xwind = (XWindow)this.Mediator.PropertyTable.GetValue("window"); xwind.ShowContextMenu(sMenu, new Point(Cursor.Position.X, Cursor.Position.Y), null, null); }
public SelectionWrapper(SimpleRootSite rootSite) { SelectionHelper = new SelectionHelper(rootSite.EditingHelper.CurrentSelection); ITsTextProps[] textProps; IVwPropertyStore[] propertyStores; int numberOfProps; SelectionHelper.GetSelectionProps(SelectionHelper.Selection, out textProps, out propertyStores, out numberOfProps); if (numberOfProps > 0) m_TextProps = textProps; }
private IVwSelection m_sel; // the selection. #endregion /// ------------------------------------------------------------------------------------ /// <summary> /// Construct and save info about selection at top left of rootSite. /// </summary> /// <param name="rootSite">rootSite</param> /// ------------------------------------------------------------------------------------ public SelPositionInfo(SimpleRootSite rootSite) { m_rootSite = rootSite; if (rootSite == null) return; int xdLeft = m_rootSite.ClientRectangle.X; int ydTop = m_rootSite.ClientRectangle.Y; Rectangle rcSrcRoot, rcDstRoot; m_rootSite.GetCoordRects(out rcSrcRoot, out rcDstRoot); m_sel = m_rootSite.RootBox.MakeSelAt(xdLeft + 1,ydTop + 1, rcSrcRoot, rcDstRoot, false); if (m_sel != null) { bool fEndBeforeAnchor; m_rootSite.SelectionRectangle(m_sel, out m_rcPrimaryOld, out fEndBeforeAnchor); } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="SelectionRestorer"/> class. /// </summary> /// ------------------------------------------------------------------------------------ public SelectionRestorer(SimpleRootSite rootSite) { // we can't use EditingHelper.CurrentSelection here because the scroll position // of the selection may have changed. m_savedSelection = SelectionHelper.Create(rootSite); m_rootSite = rootSite; Rectangle rcSrc, rcDst; rootSite.GetCoordRects(out rcSrc, out rcDst); try { IVwSelection sel = rootSite.RootBox.MakeSelAt(5, 5, rcSrc, rcDst, false); m_topOfViewSelection = SelectionHelper.Create(sel, rootSite); } catch (COMException) { // Just ignore any errors } }
/// <summary> /// Initializes a new instance of the <see cref="SimpleRootSiteTextRangeProvider"/> class. /// </summary> /// <param name="textRange">The selection from which to extract the text</param> /// <param name="site">The site in which the textRange selection has been made.</param> public SimpleRootSiteTextRangeProvider(SimpleRootSite site, IVwSelection textRange) { m_site = site; m_rootb = site.RootBox; m_vwTextRange = textRange; }
/// <summary> /// Initializes a new instance of the <see cref="SimpleRootSiteTextRangeProvider"/> class. /// </summary> /// <param name="site">the root site.(by default provide entire text).</param> public SimpleRootSiteTextRangeProvider(SimpleRootSite site) : this(site, null) { }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="T:DummyFootnoteEditingHelper"/> class. /// </summary> /// <param name="cache">The cache.</param> /// <param name="rootsite">The rootsite.</param> /// ------------------------------------------------------------------------------------ public DummyFootnoteEditingHelper(FdoCache cache, SimpleRootSite rootsite) : base(rootsite, cache, 0, null, false) { InTestMode = true; }
/// <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_editingHelper != null) m_editingHelper.Dispose(); if (m_RootSite != null) m_RootSite.Dispose(); } // Dispose unmanaged resources here, whether disposing is true or false. m_editingHelper = null; m_RootSite = null; base.Dispose(disposing); }
/// <summary> /// /// </summary> public override void TestTearDown() { m_editingHelper.Dispose(); m_editingHelper = null; m_RootSite.Dispose(); m_RootSite = null; base.TestTearDown(); }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// <param name="ctrlT"></param> /// ------------------------------------------------------------------------------------ public ViewSlice(SimpleRootSite ctrlT): base(ctrlT) { InternalInitialize(); }
private void ReversalIndexEntrySliceView_RightMouseClickedEvent(SimpleRootSite sender, FwRightMouseClickEventArgs e) { e.EventHandled = true; e.Selection.Install(); ContextMenuStrip menu = new ContextMenuStrip(); string sMenuText = LexEdStrings.ksShowInReversalIndex; ToolStripMenuItem item = new ToolStripMenuItem(sMenuText); item.Click += new EventHandler(OnShowInReversalIndex); menu.Items.Add(item); menu.Show(this, e.MouseLocation); }
public override void Initialize() { CheckDisposed(); base.Initialize(); Debug.Assert(m_RootSite == null, "m_RootSite is not null."); Debug.Assert(m_editingHelper == null, "m_editingHelper is not null."); m_RootSite = new DummySimpleRootSite(Cache); m_editingHelper = new DummyTeEditingHelper(Cache, m_RootSite); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="T:DummyTeEditingHelper"/> class. /// </summary> /// <param name="cache">The cache.</param> /// <param name="rootsite">The rootsite.</param> /// ------------------------------------------------------------------------------------ public DummyTeEditingHelper(FdoCache cache, SimpleRootSite rootsite) : base(rootsite, cache, 0, TeViewType.DraftView | TeViewType.Scripture) { InTestMode = true; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Derived classes may override this in case they contain SimpleRootSites that cannot /// be zoomed. /// </summary> /// ------------------------------------------------------------------------------------ protected virtual bool ZoomEnabledForView(SimpleRootSite view) { return true; }
/// <summary> /// Return an item of the specified class that is indicated by a click at the specified position, /// but only if it is part of a different object also of that class. /// </summary> internal static ICmObject SubitemClicked(Point where, int clsid, SimpleRootSite view, FdoCache cache, ISortItemProvider sortItemProvider, IPreferedTargetAdjuster adjuster) { var sel = view.GetSelectionAtPoint(where, false); if (sel == null) return null; Rect rcPrimary = view.GetPrimarySelRect(sel); Rectangle selRect = new Rectangle(rcPrimary.left, rcPrimary.top, rcPrimary.right - rcPrimary.left, rcPrimary.bottom - rcPrimary.top); selRect.Inflate(8,2); if (!selRect.Contains(where)) return null; // off somewhere in white space, tooltip is confusing var helper = SelectionHelper.Create(sel, view); var levels = helper.GetLevelInfo(SelectionHelper.SelLimitType.Anchor); ICmObject firstMatch = null; ICmObject lastMatch = null; foreach (var info in levels) { int hvo = info.hvo; if (!cache.ServiceLocator.IsValidObjectId(hvo)) continue; // may be some invalid numbers in there var obj = cache.ServiceLocator.GetObject(hvo); var target = GetTarget(obj, clsid); if (target == null) continue; // nothing interesting at this level. lastMatch = target; // last one we've seen. if (firstMatch == null) firstMatch = target; // first one we've seen } firstMatch = adjuster.AdjustTarget(firstMatch); if (firstMatch == lastMatch) return null; // the only object we can find to jump to is the top-level one we clicked inside. A jump would go nowhere. if (sortItemProvider.IndexOf(firstMatch.Hvo) != -1) return firstMatch; // it's a link to a top-level item in the list, we can jump // Enhance JohnT: we'd like to be able to jump to the parent entry, if target is a subentry. // That's tricky, because this is generic code, and finding the right object requires domain knowledge. // For now I'm putting a special case in. At some point we could move this into a helper that could be configured by XML. if(firstMatch is ILexSense) { firstMatch = ((ILexSense) firstMatch).Entry; if (sortItemProvider.IndexOf(firstMatch.Hvo) != -1) return firstMatch; // it's a link to a top-level item in the list, we can jump } return null; }
public WindowsLanguageProfileSink(SimpleRootSite parent) { Parent = parent; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="T:DummyFootnoteEditingHelper"/> class. /// </summary> /// <param name="cache">The cache.</param> /// <param name="rootsite">The rootsite.</param> /// ------------------------------------------------------------------------------------ public DummyFootnoteEditingHelper(FdoCache cache, SimpleRootSite rootsite) : base(rootsite, cache, 0, null, TeViewType.FootnoteView | TeViewType.Horizontal, null) { }
/// <summary> /// make one. /// </summary> /// <param name="site"></param> public VerticalOrientationManager(SimpleRootSite site) : base(site) { }
public InflAffixTemplateSlice(SimpleRootSite ctrlT): base(ctrlT) { CheckDisposed(); }
/// <summary> /// Make one. /// </summary> /// <param name="site"></param> public OrientationManager(SimpleRootSite site) { m_site = site; }
/// <summary> /// We got a right click event. Bring up the appropriate menu if any. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void InterlinDocChild_RightMouseClickedEvent(SimpleRootSite sender, FwRightMouseClickEventArgs e) { e.EventHandled = true; // for the moment we always claim to have handled it. int hvoAnnotation; if (!CanDeleteFF(e.Selection, out hvoAnnotation)) return; e.Selection.Install(); ContextMenuStrip menu = new ContextMenuStrip(); // Add spelling items if any (i.e., if we clicked a squiggle word). Rectangle rcSrcRoot, rcDstRoot; GetCoordRects(out rcSrcRoot, out rcDstRoot); EditingHelper.MakeSpellCheckMenuOptions(e.MouseLocation, m_rootb, rcSrcRoot, rcDstRoot, menu); if (menu.Items.Count > 0) { menu.Items.Add(new ToolStripSeparator()); } // Add the delete item. // We need to choose the proper menu id for the selected annotation. string sMenuText = GetTextForDeleteFreeform(hvoAnnotation); ToolStripMenuItem item = new ToolStripMenuItem(sMenuText); item.Click += new EventHandler(OnDeleteFreeform); menu.Items.Add(item); menu.Show(this, e.MouseLocation); //// We need to choose the proper menu id for the selected annotation. //string sMenuId = "mnuIText-Note"; //ISilDataAccess sda = Cache.MainCacheAccessor; //int hvo = sda.get_ObjectProp(hvoAnnotation, // (int)CmAnnotation.CmAnnotationTags.kflidAnnotationType); //// Only one Free Translation annotation and one Literal Translation annotation //// is allowed for each segment! //if (hvo == m_vc.FtSegmentDefn) // sMenuId = "mnuIText-FreeTrans"; //if (hvo == m_vc.LtSegmentDefn) // sMenuId = "mnuIText-LitTrans"; //XCore.XWindow window = (XCore.XWindow)m_mediator.PropertyTable.GetValue("window"); //Point pt = new Point(e.MouseLocation.X, e.MouseLocation.Y); //ClientToScreen(m_rootb, ref pt); //window.ShowContextMenu(sMenuId, // pt, // null, // No temporary XCore colleague. // null); // // Using the sequencer here now causes problems. // // If a safe blocking mechanism can be found for the context menu, we can restore the original behavior // // which will have this code do the setup and teardown work. // //(this as IReceiveSequentialMessages).Sequencer); }
public ICollection<SpellCorrectMenuItem> GetSuggestions(Point mousePos, SimpleRootSite rootsite, out int hvoObj, out int tag, out int wsAlt, out int wsText, out string word, out ISpellEngine dict, out bool nonSpellingError) { hvoObj = tag = wsAlt = wsText = 0; // make compiler happy for early returns word = null; dict = null; nonSpellingError = true; IVwRootBox rootb = rootsite != null ? rootsite.RootBox : null; if (rootb == null) return null; // Get a selection at the indicated point. IVwSelection sel = rootsite.GetSelectionAtPoint(mousePos, false); // Get the selected word and verify that it is a single run within a single // editable string. if (sel != null) sel = sel.GrowToWord(); if (sel == null || !sel.IsRange || sel.SelType != VwSelType.kstText || !SelectionHelper.IsEditable(sel)) return null; ITsString tss; bool fAssocPrev; int ichAnchor; sel.TextSelInfo(false, out tss, out ichAnchor, out fAssocPrev, out hvoObj, out tag, out wsAlt); int ichEnd, hvoObjE, tagE, wsE; sel.TextSelInfo(true, out tss, out ichEnd, out fAssocPrev, out hvoObjE, out tagE, out wsE); if (hvoObj != hvoObjE || tag != tagE || wsAlt != wsE) return null; int ichMin = Math.Min(ichEnd, ichAnchor); int ichLim = Math.Max(ichEnd, ichAnchor); ILgWritingSystemFactory wsf = rootsite.RootBox.DataAccess.WritingSystemFactory; // May need to enlarge the word beyond what GrowToWord does, if there is adjacent wordforming material. int ichMinAdjust = AdjustWordBoundary(wsf, tss, ichMin, -1, 0) + 1; // further expanded start of word. int ichLimAdjust = AdjustWordBoundary(wsf, tss, ichLim - 1, 1, tss.Length); // further expanded lim of word. // From the ends we can strip stuff with different spell-checking properties. IVwStylesheet styles = rootsite.RootBox.Stylesheet; int spellProps = SpellCheckProps(tss, ichMin, styles); while (ichMinAdjust < ichMin && SpellCheckProps(tss, ichMinAdjust, styles) != spellProps) ichMinAdjust++; while (ichLimAdjust > ichLim && SpellCheckProps(tss, ichLimAdjust - 1, styles) != spellProps) ichLimAdjust--; ichMin = ichMinAdjust; ichLim = ichLimAdjust; ITsStrFactory tsf = TsStrFactoryClass.Create(); // Now we have the specific range we will check. Get the actual string. ITsStrBldr bldr = tss.GetBldr(); if (ichLim < bldr.Length) bldr.ReplaceTsString(ichLim, bldr.Length, null); if (ichMin > 0) bldr.ReplaceTsString(0, ichMin, null); ITsString tssWord = bldr.GetString(); // See whether we need the special blue underline, which is used mainly for adjacent words in different writing systems. List<int> wss = TsStringUtils.GetWritingSystems(tssWord); if (wss.Count > 1) return MakeWssSuggestions(tssWord, wss, rootb, hvoObj, tag, wsAlt, ichMin, ichLim); ITsString keepOrcs; // holds any ORCs we found in the original word that we need to keep rather than reporting. IList<SpellCorrectMenuItem> result = MakeEmbeddedNscSuggestion(ref tssWord, styles, rootb, hvoObj, tag, wsAlt, ichMin, ichLim, out keepOrcs); if (result.Count > 0) return result; // Determine whether it is a spelling problem. wsText = TsStringUtils.GetWsOfRun(tssWord, 0); dict = SpellingHelper.GetSpellChecker(wsText, wsf); if (dict == null) return null; word = tssWord.get_NormalizedForm(FwNormalizationMode.knmNFC).Text; if (word == null) return null; // don't think this can happen, but... if (dict.Check(word)) return null; // not mis-spelled. // Get suggestions. Make sure to return an empty collection rather than null, even if no suggestions, // to indicate an error. ICollection<string> suggestions = dict.Suggest(word); foreach (string suggest in suggestions) { ITsString replacement = tsf.MakeStringRgch(suggest, suggest.Length, wsText); if (keepOrcs != null) { ITsStrBldr bldrRep = keepOrcs.GetBldr(); bldrRep.ReplaceTsString(0, 0, replacement); replacement = bldrRep.GetString(); } result.Add(new SpellCorrectMenuItem(rootb, hvoObj, tag, wsAlt, ichMin, ichLim, suggest, replacement)); } nonSpellingError = false; // it IS a spelling problem. return result; }
public override void Exit() { CheckDisposed(); m_editingHelper.Dispose(); m_editingHelper = null; m_RootSite.Dispose(); m_RootSite = null; base.Exit(); }
/// ----------------------------------------------------------------------------------- /// <summary> /// If the mousePos is part of a word that is not properly spelled, add to the menu /// options for correcting it. /// </summary> /// <param name="pt">The location on the screen of the word for which we want spelling /// suggestions (usually the mouse position)</param> /// <param name="rootsite">The focused rootsite</param> /// <param name="menu">to add items to.</param> /// <returns>the number of menu items added (not counting a possible separator line)</returns> /// ----------------------------------------------------------------------------------- public virtual int MakeSpellCheckMenuOptions(Point pt, SimpleRootSite rootsite, ContextMenuStrip menu) { int hvoObj, tag, wsAlt, wsText; string word; ISpellEngine dict; bool nonSpellingError; ICollection<SpellCorrectMenuItem> suggestions = GetSuggestions(pt, rootsite, out hvoObj, out tag, out wsAlt, out wsText, out word, out dict, out nonSpellingError); if (suggestions == null) return 0; // no detectable spelling problem. // Note that items are inserted in order starting at the beginning, rather than // added to the end. This is to support TE-6901. // If the menu isn't empty, add a separator. if (menu.Items.Count > 0) menu.Items.Insert(0, new ToolStripSeparator()); // Make the menu option. ToolStripMenuItem itemExtras = null; int cSuggestions = 0; int iMenuItem = 0; IVwRootBox rootb = rootsite.RootBox; foreach (SpellCorrectMenuItem subItem in suggestions) { subItem.Click += spellingMenuItemClick; if (cSuggestions++ < RootSiteEditingHelper.kMaxSpellingSuggestionsInRootMenu) { Font createdFont = null; try { Font font = subItem.Font; if (wsText != 0) { font = createdFont = EditingHelper.GetFontForNormalStyle(wsText, rootb.Stylesheet, rootb.DataAccess.WritingSystemFactory); //string familyName = rootb.DataAccess.WritingSystemFactory.get_EngineOrNull(wsText).DefaultBodyFont; //font = new Font(familyName, font.Size, FontStyle.Bold); } subItem.Font = new Font(font, FontStyle.Bold); menu.Items.Insert(iMenuItem++, subItem); } finally { if (createdFont != null) createdFont.Dispose(); } } else { if (itemExtras == null) { itemExtras = new ToolStripMenuItem(RootSiteStrings.ksAdditionalSuggestions); menu.Items.Insert(iMenuItem++, itemExtras); } itemExtras.DropDownItems.Add(subItem); } } if (suggestions.Count == 0) { ToolStripMenuItem noSuggestItems = new ToolStripMenuItem(RootSiteStrings.ksNoSuggestions); menu.Items.Insert(iMenuItem++, noSuggestItems); noSuggestItems.Enabled = false; } ToolStripMenuItem itemAdd = new AddToDictMenuItem(dict, word, rootb, hvoObj, tag, wsAlt, wsText, RootSiteStrings.ksAddToDictionary, m_cache); if (nonSpellingError) itemAdd.Enabled = false; menu.Items.Insert(iMenuItem++, itemAdd); itemAdd.Image = SIL.FieldWorks.Resources.ResourceHelper.SpellingIcon; itemAdd.Click += spellingMenuItemClick; return iMenuItem; }
/// <summary> /// /// </summary> public override void TestSetup() { base.TestSetup(); m_RootSite = new DummySimpleRootSite(Cache); m_editingHelper = new DummyFootnoteEditingHelper(Cache, m_RootSite); }
/// ------------------------------------------------------------------------------------ /// <summary> /// /// </summary> /// <param name="cache"></param> /// ------------------------------------------------------------------------------------ public DummyNotesEditingHelper(FdoCache cache, SimpleRootSite rootsite) : base(cache, rootsite, null) { }
public override void Initialize() { CheckDisposed(); base.Initialize(); m_RootSite = new DummySimpleRootSite(Cache); m_editingHelper = new DummyFootnoteEditingHelper(Cache, m_RootSite); }