private void m_btnInsert_Click(object sender, System.EventArgs e) { IVwSelection sel = m_view.RootBox.Selection; if (sel == null) { return; } string undo; string redo; ResourceHelper.MakeUndoRedoLabels("kstidUndoRedoInsertRelatedWord", out undo, out redo); using (UndoTaskHelper undoTaskHelper = new UndoTaskHelper(m_cache.ActionHandlerAccessor, m_view.RootBox.Site, undo, redo)) { ITsString tss; sel.GetSelectionString(out tss, ""); m_sel.ReplaceWithTsString(tss); undoTaskHelper.RollBack = false; } }
public void FootnoteTranslationTest() { // get an existing footnote IScrBook book = m_scr.ScriptureBooksOS[1]; // book of Exodus IScrFootnote footnote = AddFootnote(book, (IStTxtPara)book.TitleOA.ParagraphsOS[0], 0, "This is a footnote"); IStTxtPara para = (IStTxtPara)footnote.ParagraphsOS[0]; // add a translation to the footnote ICmTranslation translation = para.GetOrCreateBT(); int analWs = Cache.DefaultAnalWs; translation.Translation.set_String(analWs, TsStringHelper.MakeTSS("abcde", analWs)); FwStyleSheet styleSheet = new FwStyleSheet(); styleSheet.Init(Cache, m_scr.Hvo, ScriptureTags.kflidStyles); // Prepare the test by creating a footnote view using (DummyFootnoteView footnoteView = new DummyFootnoteView(Cache, true)) { footnoteView.StyleSheet = styleSheet; footnoteView.Visible = false; // We don't actually want to show it, but we need to force the view to create the root // box and lay it out so that various test stuff can happen properly. footnoteView.MakeRoot(); footnoteView.CallLayout(); // Select the footnote marker and some characters of the footnote paragraph footnoteView.RootBox.MakeSimpleSel(true, true, false, true); // Now the real test: IVwSelection sel = footnoteView.RootBox.Selection.GrowToWord(); ITsString tss; sel.GetSelectionString(out tss, string.Empty); Assert.AreEqual("abcde", tss.Text); } }
/// <summary> /// If we are in ReadOnlySelect mode, intercept the click, and select the appropriate row /// without installing a normal selection. /// </summary> /// <param name="e"></param> protected override void OnMouseUp(MouseEventArgs e) { //If XmlBrouseView did not receive a mouse down event then we do not want to //do anything on the mouseUp because the mouseUp would have come from clicking //somewhere else. LT-8939 if (!m_fMouseUpEnabled) { return; } try { if (m_selectedIndex == -1) { return; // Can't do much in an empty list, so quit. } m_fHandlingMouseUp = true; #pragma warning disable 219 int oldSelectedIndex = m_selectedIndex; #pragma warning restore 219 // Note all the stuff we might want to know about what was clicked that we will // use later. We want to get this now before anything changes, because there can // be scrolling effects from converting dummy objects to real. IVwSelection vwsel = MakeSelectionAt(e); int newSelectedIndex = GetRowIndexFromSelection(vwsel, true); // If we're changing records, we need to do some tricks to keep the selection in the place // clicked and the focus here. Save the information we will need. SelectionHelper clickSel = null; if (newSelectedIndex != SelectedIndex && vwsel != null && SelectionHelper.IsEditable(vwsel)) { clickSel = SelectionHelper.Create(vwsel, this); } ITsString tssWord = null; // word clicked for click copy ITsString tssSource = null; // whole source string of clicked cell for click copy int hvoNewSelRow = 0; // hvo of new selected row (only for click copy) int ichStart = 0; // of tssWord in tssSource if (ClickCopy != null && e.Button == MouseButtons.Left && newSelectedIndex >= 0) { if (vwsel != null && vwsel.SelType == VwSelType.kstText) { int icol = vwsel.get_BoxIndex(false, 3); if (icol != Vc.OverrideAllowEditColumn + 1) { IVwSelection vwSelWord = vwsel.GrowToWord(); // GrowToWord() can return a null -- see LT-9163 and LT-9349. if (vwSelWord != null) { vwSelWord.GetSelectionString(out tssWord, " "); tssWord = StripTrailingNewLine(tssWord); hvoNewSelRow = m_sda.get_VecItem(m_hvoRoot, m_fakeFlid, newSelectedIndex); int hvoObj, tag, ws; bool fAssocPrev; vwSelWord.TextSelInfo(false, out tssSource, out ichStart, out fAssocPrev, out hvoObj, out tag, out ws); } } } } // We need to manually change the index for ReadOnly views. // SimpleRootSite delegates RightMouseClickEvent to our RecordBrowseView parent, // which also makes the selection for us.. if (ReadOnlySelect && e.Button != MouseButtons.Right) { if (this.m_xbvvc.HasSelectColumn && e.X < m_xbvvc.SelectColumnWidth) { base.OnMouseUp(e); // allows check box to operate. } } else { // If we leave this set, the base method call's side effects like updating the WS combo // don't happen. m_fHandlingMouseUp = false; base.OnMouseUp(e); // normal behavior. m_fHandlingMouseUp = true; } SetSelectedIndex(newSelectedIndex); if (tssWord != null) { // We're doing click copies; generate an event. // Do this AFTER other actions which may change the current line. ClickCopy(this, new ClickCopyEventArgs(tssWord, hvoNewSelRow, tssSource, ichStart)); } if (clickSel != null) { IVwSelection finalSel = null; // There seem to be some cases where the selection helper can't restore the selection. // One that came up in FWR-3666 was clicking on a check box. // If we can't re-establish an editiable selection just let the default behavior continue. try { finalSel = clickSel.MakeRangeSelection(RootBox, false); } catch (Exception) { } if (finalSel != null && SelectionHelper.IsEditable(finalSel)) { finalSel.Install(); FocusMe(); } } } finally { m_fHandlingMouseUp = false; m_fMouseUpEnabled = false; } }
public void ClearStyle_CharStyleRemovedFromAdjacentWhiteSpace() { m_draftView.RefreshDisplay(); // *** Test setup *** // Select a word in the book intro with white space around it: " text. " m_draftView.SetInsertionPoint(0, 0, 0, 5, false); IVwSelection sel0 = m_draftView.RootBox.Selection; Assert.IsNotNull(sel0); m_draftView.SetInsertionPoint(0, 0, 0, 12, true); IVwSelection sel1 = m_draftView.RootBox.Selection; Assert.IsNotNull(sel1); IVwSelection rangeSel = m_draftView.RootBox.MakeRangeSelection(sel0, sel1, true); ITsString tssSelected; rangeSel.GetSelectionString(out tssSelected, "*"); Assert.AreEqual(" text. ", tssSelected.Text); // Build an array of string props with the style name of the only run. ITsTextProps[] props = new ITsTextProps[1]; ITsPropsBldr bldr = TsPropsBldrClass.Create(); // The named style is the default, so not property values are added. props[0] = bldr.GetTextProps(); // Apply a character style to the selected text (including the surrounding white space) m_draftView.EditingHelper.RemoveCharFormatting(rangeSel, ref props, "Emphasis"); // so that we have three runs. IScrSection introSection = m_exodus.SectionsOS[0]; ITsString paraContents = introSection.ContentOA[0].Contents; Assert.AreEqual(3, paraContents.RunCount); // *** Test *** // Select just the word "text." without the surrounding white space. m_draftView.SetInsertionPoint(0, 0, 0, 6, false); sel0 = m_draftView.RootBox.Selection; Assert.IsNotNull(sel0); m_draftView.SetInsertionPoint(0, 0, 0, 11, true); sel1 = m_draftView.RootBox.Selection; Assert.IsNotNull(sel1); rangeSel = m_draftView.RootBox.MakeRangeSelection(sel0, sel1, true); rangeSel.GetSelectionString(out tssSelected, "*"); Assert.AreEqual("text.", tssSelected.Text); // Remove character style formatting from the selected text. m_draftView.EditingHelper.RemoveCharFormatting(rangeSel, ref props, string.Empty); // We expect that there should now only be one run in this paragraph with the style // "Default Paragraph Characters". paraContents = introSection.ContentOA[0].Contents; Assert.AreEqual(1, paraContents.RunCount, "Style for boundary white space characters not properly removed"); ITsTextProps ttp = paraContents.get_Properties(0); Assert.IsNull(ttp.GetStrPropValue((int)FwTextStringProp.kstpNamedStyle), "Character style of run should be 'Default Paragraph Characters'"); }
internal InterlinClipboardHelper(IVwSelection vwsel, InterlinDocChild site, FdoCache cache) { // Get the string and split it into its individual lines. vwsel.GetSelectionString(out m_tss, "\t"); m_rgtssPieces = StringUtils.Split(m_tss, new string[] { Environment.NewLine }, StringSplitOptions.None); m_choices = site.LineChoices; m_fHaveMorphemeLevel = m_choices.HaveMorphemeLevel; if (m_fHaveMorphemeLevel) m_cMorphLines = m_idxChoiceLastMorpheme - m_idxChoiceFirstMorpheme + 1; m_idxChoiceFirstMorpheme = m_choices.FirstMorphemeIndex; m_idxChoiceLastMorpheme = m_choices.LastMorphemeIndex; m_idxChoiceFirstFreeform = m_choices.FirstFreeformIndex; m_cChoices = m_choices.Count; m_cInterlinearLines = m_choices.FirstFreeformIndex; // Get the labels for the lines in m_choices. m_rgsLabel = new string[m_cInterlinearLines]; for (int i = 0; i < m_rgsLabel.Length; ++i) m_rgsLabel[i] = m_choices.LabelFor(m_choices[i].Flid); bool fTaggingView = site is InterlinTaggingChild; if (site is InterlinTaggingChild) { m_fHaveTagging = true; m_idxChoiceTaggingLine = m_idxChoiceFirstFreeform; ++m_idxChoiceFirstFreeform; ++m_cChoices; } else { m_fHaveTagging = false; m_idxChoiceTaggingLine = -1; } m_cache = cache; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Handle TE specific requirements on selection change. /// </summary> /// <param name="rootb">The rootbox whose selection changed</param> /// <param name="vwselNew">The new selection</param> /// ------------------------------------------------------------------------------------ public override void HandleSelectionChange(IVwRootBox rootb, IVwSelection vwselNew) { CheckDisposed(); // selection change is being done by this routine, don't need to do processing // second time. if (m_selectionUpdateInProcess) return; SelectionHelper helper = CurrentSelection; UpdateGotoPassageControl(); // update the verse reference to the new selection SetInformationBarForSelection(); // update title bar with section reference range if (VernacularDraftVc != null) ProcessBTSelChange(helper); int hvoSelObj = 0; if (helper != null && helper.LevelInfo.Length > 0) hvoSelObj = helper.LevelInfo[0].hvo; ITeDraftView getVc = rootb.Site as ITeDraftView; TeStVc vc = (getVc != null) ? getVc.Vc : null; if (vc != null && vc.HvoOfSegmentWhoseBtPromptIsToBeSupressed != hvoSelObj) { vc.HvoOfSegmentWhoseBtPromptIsToBeSupressed = 0; // Enhance JohnT: do a Propchanged (possibly delayed until idle) on hvo.Comment to make the prompt reappear. } // If the selection is in a user prompt then extend the selection to cover the // entire prompt. if (IsSelectionInPrompt(helper)) { if (vc != null) vc.HvoOfSegmentWhoseBtPromptIsToBeSupressed = hvoSelObj; // If we're not really showing the prompt, but just an incomplete composition that was typed // over it, we do NOT want to select all of it all the time! (TE-8267). if (!rootb.IsCompositionInProgress) vwselNew.ExtendToStringBoundaries(); SetKeyboardForSelection(vwselNew); } // This isn't ideal but it's one of the better of several bad options for dealing // with simplifying the selection changes in footnote views. if ((m_viewType & TeViewType.FootnoteView) != 0 || helper == null) { // This makes sure the writing system and styles combos get updated. base.HandleSelectionChange(rootb, vwselNew); return; } // If selection is IP, don't allow it to be associated with a verse number run. bool fRangeSelection = vwselNew.IsRange; if (!fRangeSelection) PreventIPAssociationWithVerseRun(rootb); // Need to do this at end since selection may be changed by this method. // Doing this at top can also cause value of style in StylesComboBox to flash base.HandleSelectionChange(rootb, vwselNew); // Make sure the selection is in a valid Scripture element. int tagSelection; int hvoSelection; if (!vwselNew.IsValid || !GetSelectedScrElement(out tagSelection, out hvoSelection)) { m_sPrevSelectedText = null; return; } // Determine whether or not the selection changed but is in a different reference. bool fInSameRef = (m_oldReference == CurrentStartRef); if (fInSameRef && !fRangeSelection) { m_sPrevSelectedText = null; SyncToScrLocation(true); return; } ScrReference curStartRef = CurrentStartRef; if (curStartRef.Chapter == 0) curStartRef.Chapter = 1; m_oldReference = CurrentStartRef; string selectedText = null; if (fRangeSelection) { try { ITsString tssSelectedText; vwselNew.GetSelectionString(out tssSelectedText, string.Empty); selectedText = (tssSelectedText != null ? tssSelectedText.Text : null); } catch { selectedText = null; } } bool fSameSelectedText = (m_sPrevSelectedText == selectedText); m_sPrevSelectedText = selectedText; if (!fInSameRef || !fSameSelectedText || InBookTitle || InSectionHead || InIntroSection) SyncToScrLocation(fInSameRef); }
/// <summary> /// Given the GUI control or view ah, find and highlight the text indicated /// via the location (level) path. /// </summary> /// <param name="lpath">Level path array.</param> /// <param name="ah">Accessibility helper from the GUI control or view</param> /// <returns>true if the selected string was retrieved.</returns> private bool selectText(GuiPath lpath, AccessibilityHelper ah) { IVwRootBox rbox = ah.RootBox(); isNotNull(rbox, "view rootbox not found"); IVwSelection sel = null; // returned selection // create a SelLevInfo[] array to the content using the model view levels. int clevels = 0; SelLevInfo[] rgvsli; if (DrillToContent(lpath, out rgvsli, out clevels)) { int ihvoRoot = 0; // first rootbox int tagTextProp = 16002; // kflidStTxtPara_Contents int cpropPrevious = 0; int ichAnchor = m_at; // starting character number int ichEnd = m_at + m_run; // ending character number in rgvsli[0].ihvo or ihvoEnd if it is not -1 int ws = 0; bool fAssocPrev = false; int ihvoEnd = -1; // paragraph # to end at, if it doesn't exist, get unspecified interop error ITsTextProps ttpIns = null; bool fInstall = true; // make it the view's default selection //int iHeight = rbox.get_Height(); int iHeight = rbox.Height; sel = rbox.MakeTextSelection (ihvoRoot, clevels, rgvsli, tagTextProp, cpropPrevious, ichAnchor, ichEnd, ws, fAssocPrev, ihvoEnd, ttpIns, fInstall); isNotNull(sel, "failed to select text"); //areEqual(true, sel.get_IsValid(), "selection is not valid"); areEqual(true, sel.IsValid, "selection is not valid"); ITsTextProps ttp = spyOnSelection(sel); if (ttp != null) { spyOnTextProps(ttp); } } string strSeparator = "|"; ITsString tssFromApp; sel.GetSelectionString(out tssFromApp, strSeparator); ITsStreamWrapper tsw = TsStreamWrapperClass.Create(); //UCOMIStream strm = tsw.get_Stream(); System.Runtime.InteropServices.ComTypes.IStream strm = tsw.Stream; // Copy the string to our address space. ITsStrBldr bldr = TsStrBldrClass.Create(); bldr.ReplaceTsString(0, 0, tssFromApp); ITsString tss = bldr.GetString(); int icchIndent = 2; int iws = 0; bool fWriteObjData = true; //tsw.WriteTssAsXml(tss2, icchIndent, iws, fWriteObjData); //ISilDataAccess da = rbox.get_DataAccess(); ISilDataAccess da = rbox.DataAccess; //ILgWritingSystemFactory wsf = da.get_WritingSystemFactory(); ILgWritingSystemFactory wsf = da.WritingSystemFactory; tss.WriteAsXml(strm, wsf, icchIndent, iws, fWriteObjData); //m_text = tsw.get_Contents(); // XML formatted string m_text = tsw.Contents; // XML formatted string return(m_text != null); }