Exemplo n.º 1
0
        private void InitSandbox()
        {
            SetSandboxSize();

            m_vc.LeftPadding = 0;
            m_rootb.Reconstruct();
            using (new HoldGraphics(this))
            {
                Rectangle rcSrcRoot;
                Rectangle rcDstRoot;
                GetCoordRects(out rcSrcRoot, out rcDstRoot);
                SelLevInfo[] rgvsli = new SelLevInfo[1];
                //rgvsli[1].ihvo = 0; // first morpheme bundle
                //rgvsli[1].tag = (int)WfiAnalysis.WfiAnalysisTags.kflidMorphBundles;
                rgvsli[0].ihvo = 0;
                rgvsli[0].tag  = m_tag;
                IVwSelection sel = null;
                sel = RootBox.MakeTextSelInObj(0, rgvsli.Length, rgvsli, 0, null, true, false, false, false, false);
                if (sel == null)
                {
                    Debug.WriteLine("Could not make selection in InitSandbox");
                    return;                     // can't position it accurately.
                }
                Rect rcSec;
                bool fSplit, fEndBeforeAnchor;
                sel.Location(m_graphicsManager.VwGraphics, rcSrcRoot, rcDstRoot, out m_rcPrimary, out rcSec,
                             out fSplit, out fEndBeforeAnchor);
            }
            SetPadding();
            SetSandboxLocation();
        }
Exemplo n.º 2
0
        protected bool CheckForValidDelete(IVwSelection sel, out int cvsli, out int hvoObj)
        {
            hvoObj = 0;
            if (sel == null)
            {
                cvsli = 0;                 // satisfy compiler.
                return(false);             // nothing selected, give up.
            }

            cvsli = sel.CLevels(false);
            // CLevels includes the string property itself, but AllTextSelInfo doesn't need it.
            cvsli--;
            if (cvsli == 0)
            {
                // No object in selection, so quit.
                return(false);
            }
            ITsString tss;
            int       ichAnchor;
            bool      fAssocPrev;
            int       tag;
            int       ws;
            int       ichEnd;
            int       hvoObjEnd;

            sel.TextSelInfo(false, out tss, out ichAnchor, out fAssocPrev, out hvoObj,
                            out tag, out ws);
            sel.TextSelInfo(true, out tss, out ichEnd, out fAssocPrev, out hvoObjEnd,
                            out tag, out ws);
            return(hvoObj == hvoObjEnd);
        }
Exemplo n.º 3
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting
        /// unmanaged resources. In this case, attempt to restore the selection we originally
        /// saved.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected virtual void Dispose(bool fDisposing)
        {
            System.Diagnostics.Debug.WriteLineIf(!fDisposing, "****** Missing Dispose() call for " + GetType().Name + ". ****** ");
            if (!fDisposing || IsDisposed || m_savedSelection == null || m_rootSite.RootBox.Height <= 0)
            {
                return;
            }

            if (m_rootSite.ReadOnlyView)
            {
                // if we are a read-only view, then we can't make a writable selection
                RestoreSelectionWhenReadOnly();
                return;
            }

            IVwSelection newSel = RestoreSelection();

            if (newSel == null)
            {
                try
                {
                    // Any selection is betther than no selection...
                    m_rootSite.RootBox.MakeSimpleSel(true, true, false, true);
                }
                catch (COMException)
                {
                    // Just ignore any errors - don't get an selection but who cares.
                }
            }


            IsDisposed = true;
        }
Exemplo n.º 4
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Handle a selection change by growing it to a word (unless the new selection IS
        /// the one we're growing to a word).
        /// </summary>
        /// ------------------------------------------------------------------------------------
        private void HandleSelectionChange(object sender, VwSelectionArgs args)
        {
            CheckDisposed();

            IVwRootBox   rootb    = args.RootBox;
            IVwSelection vwselNew = args.Selection;

            Debug.Assert(vwselNew != null);

            if (!m_fInSelChange)
            {
                m_fInSelChange = true;
                try
                {
                    if (!vwselNew.IsRange)
                    {
                        vwselNew.GrowToWord().Install();
                    }
                }
                finally
                {
                    m_fInSelChange = false;
                }
            }
            if (SelChanged != null)
            {
                SelChanged(this, new EventArgs());
            }
        }
Exemplo n.º 5
0
        /// -----------------------------------------------------------------------------------
        /// <summary>
        /// Not implemented.
        /// </summary>
        /// <param name="vwsel"></param>
        /// <param name="hvo"></param>
        /// <param name="tag"></param>
        /// <param name="frag"></param>
        /// <param name="tssVal"></param>
        /// <returns></returns>
        /// -----------------------------------------------------------------------------------
        public virtual ITsString UpdateProp(IVwSelection vwsel, int hvo, int tag, int frag,
                                            ITsString tssVal)
        {
            CheckDisposed();

            throw new NotImplementedException();
        }
Exemplo n.º 6
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Remember if a picture is selected so that it can be deselected on mouse up,
        /// if necessary.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected override void CallMouseDown(Point pt, Rectangle rcSrcRoot, Rectangle rcDstRoot)
        {
            IVwSelection sel = m_rootb.MakeSelAt(pt.X, pt.Y, rcSrcRoot, rcDstRoot, false);

            m_pictureSelected = (sel != null && sel.SelType == VwSelType.kstPicture);
            base.CallMouseDown(pt, rcSrcRoot, rcDstRoot);
        }
        /// <summary>
        /// Make one.
        /// </summary>
        public PromptSelectionRestorer(IVwRootBox rootbox)
        {
            m_rootbox = rootbox;
            if (rootbox == null)
            {
                return;
            }
            // Save information about the old selection.
            IVwSelection oldsel = rootbox.Selection;
            // Dummy variables
            int  tagTextProp;
            int  ichAnchor;
            int  ichEnd;
            int  ihvoEnd;
            bool fAssocPrev;

            if (oldsel != null && oldsel.CLevels(false) > 0)
            {
                cvsli = oldsel.CLevels(false);
                cvsli--;                 // CLevels includes the string property itself, but AllTextSelInfo doesn't need it.
                rgvsli = SelLevInfo.AllTextSelInfo(oldsel, cvsli,
                                                   out ihvoRoot, out tagTextProp, out cpropPrevious, out ichAnchor, out ichEnd,
                                                   out ws, out fAssocPrev, out ihvoEnd, out ttp);
            }
        }
Exemplo n.º 8
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Create a range selection (adapted from TePrintLayout.cs).
        /// </summary>
        /// <param name="rootbox">The rootbox.</param>
        /// <param name="iPara">The 0-based index of the paragraph in which to put the insertion
        /// point</param>
        /// <param name="startCharacter">The 0-based index of the character at which the
        /// selection begins (or before which the insertion point is to be placed if
        /// startCharacter == endCharacter)</param>
        /// <param name="endCharacter">The character location to end the selection</param>
        /// <returns>The selection helper</returns>
        /// ------------------------------------------------------------------------------------
        private SelectionHelper SelectRangeOfChars(IVwRootBox rootbox, int iPara,
                                                   int startCharacter, int endCharacter)
        {
            if (rootbox == null)
            {
                return(null);                 // can't make a selection
            }
            SelectionHelper selHelper = new SelectionHelper();

            selHelper.NumberOfLevels = 1;

            selHelper.LevelInfo[0].ihvo = iPara;
            selHelper.LevelInfo[0].tag  = (int)StText.StTextTags.kflidParagraphs;
            selHelper.AssocPrev         = true;

            selHelper.SetLevelInfo(SelectionHelper.SelLimitType.End, selHelper.LevelInfo);

            // Prepare to move the IP to the specified character in the paragraph.
            selHelper.IchAnchor = startCharacter;
            selHelper.IchEnd    = endCharacter;

            // Now that all the preparation to set the IP is done, set it.
            IVwSelection vwsel = selHelper.SetSelection(rootbox.Site, true, false,
                                                        VwScrollSelOpts.kssoDefault);

            Assert.IsNotNull(vwsel);
            Application.DoEvents();

            return(selHelper);
        }
Exemplo n.º 9
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Handle Mouse up
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected override void OnMouseUp(MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Right)
            {
                base.OnMouseUp(e);
                return;
            }

            NotesMainWnd notesMainWnd = TheMainWnd as NotesMainWnd;

            if (notesMainWnd == null || notesMainWnd.TMAdapter == null)
            {
                return;
            }

            Rectangle rcSrcRoot;
            Rectangle rcDstRoot;

            GetCoordRects(out rcSrcRoot, out rcDstRoot);
            Point        pt      = new Point(e.X, e.Y);
            IVwSelection sel     = m_rootb.MakeSelAt(pt.X, pt.Y, rcSrcRoot, rcDstRoot, false);
            int          noteHvo = 0;

            if (sel != null)
            {
                SelectionHelper selHelper = SelectionHelper.Create(sel, this);
                SelLevInfo      annInfo   = selHelper.GetLevelInfoForTag(m_currentNotesTag);
                noteHvo = annInfo.hvo;
            }

            pt = PointToScreen(new Point(e.X, e.Y));
            notesMainWnd.TMAdapter.PopupMenu("cmnuNotesDataEntryView", pt.X, pt.Y);
        }
Exemplo n.º 10
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// If a data update is actually in progress, we want to only complete edits and not
        /// notify the world of the prop changes yet (we'll store the info in a queue for
        /// broadcast later, in Dispose()).
        /// </summary>
        /// <param name="vwsel"></param>
        /// <param name="sda">Data access object (corresponds to a DB connection)</param>
        /// <returns>Return value from IVwSelection.Commit() or IVwSelection.CompleteEdits()
        /// </returns>
        /// ------------------------------------------------------------------------------------
        public static bool Commit(IVwSelection vwsel, ISilDataAccess sda)
        {
            if (vwsel == null)
            {
                return(false);
            }

            UpdateSemaphore semaphore = null;

            if (s_UpdateSemaphores.ContainsKey(sda))
            {
                semaphore = s_UpdateSemaphores[sda];
            }
            if (semaphore == null || !semaphore.fDataUpdateInProgress)
            {
                return(vwsel.Commit());
            }

            VwChangeInfo changeInfo;
            bool         fRet = vwsel.CompleteEdits(out changeInfo);

            if (changeInfo.hvo != 0)
            {
                semaphore.changeInfoQueue.Enqueue(changeInfo);
            }
            return(fRet);
        }
Exemplo n.º 11
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Print method
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public override void Print(PrintDocument pd)
        {
            CheckDisposed();

            ISilDataAccess oldSda          = null;
            bool           fPrintSelection = (pd.PrinterSettings.PrintRange == PrintRange.Selection);

            if (fPrintSelection)
            {
                oldSda = RootBox.DataAccess;
                IVwSelection     sel = RootBox.Selection;
                int              clev = sel.CLevels(true);
                int              hvoObj, tag, ihvoEnd, ihvoAnchor, cpropPrevious;
                IVwPropertyStore vps;
                sel.PropInfo(true, clev - 1, out hvoObj, out tag, out ihvoEnd, out cpropPrevious, out vps);
                clev = sel.CLevels(false);
                sel.PropInfo(false, clev - 1, out hvoObj, out tag, out ihvoAnchor, out cpropPrevious, out vps);
                int[] originalObjects = m_sdaSource.VecProp(m_hvoRoot, m_mainFlid);
                int   ihvoMin         = Math.Min(ihvoEnd, ihvoAnchor);
                int   ihvoLim         = Math.Max(ihvoEnd, ihvoAnchor) + 1;
                var   selectedObjects = new int[ihvoLim - ihvoMin];
                for (int i = 0; i < selectedObjects.Length; i++)
                {
                    selectedObjects[i] = originalObjects[i + ihvoMin];
                }
                RootBox.DataAccess = CachePrintDecorator(m_sdaSource, m_hvoRoot, m_mainFlid, selectedObjects);
            }
            base.Print(pd);
            if (fPrintSelection)
            {
                RootBox.DataAccess = oldSda;
            }
        }
        /// <summary>
        /// Return the sound control rectangle.
        /// </summary>
        internal void GetSoundControlRectangle(IVwSelection sel, out Rectangle selRect)
        {
            bool fEndBeforeAnchor;

            using (new HoldGraphics(this))
                SelectionRectangle(sel, out selRect, out fEndBeforeAnchor);
        }
Exemplo n.º 13
0
 public void FindInDictionary(IOleDbEncap ode, IFwMetaDataCache mdc, IVwOleDbDa oleDbAccess, IVwSelection sel)
 {
     using (FdoCache cache = new FdoCache(ode, mdc, oleDbAccess))
     {
         if (sel == null)
         {
             return;
         }
         IVwSelection sel2 = sel.EndPoint(false);
         if (sel2 == null)
         {
             return;
         }
         IVwSelection sel3 = sel2.GrowToWord();
         if (sel3 == null)
         {
             return;
         }
         ITsString tss;
         int       ichMin, ichLim, hvo, tag, ws;
         bool      fAssocPrev;
         sel3.TextSelInfo(false, out tss, out ichMin, out fAssocPrev, out hvo, out tag, out ws);
         sel3.TextSelInfo(true, out tss, out ichLim, out fAssocPrev, out hvo, out tag, out ws);
         // TODO (TimS): need to supply help information (last 2 params)
         LexEntryUi.DisplayOrCreateEntry(cache, hvo, tag, ws, ichMin, ichLim, null, null, null, string.Empty);
         return;
     }
 }
Exemplo n.º 14
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Scroll the selection in view and set the IP at the given client position.
 /// </summary>
 /// <param name="sel">The selection</param>
 /// <param name="dyPos">Position from top of client window where IP should be set</param>
 /// ------------------------------------------------------------------------------------
 void IRootSite.ScrollSelectionToLocation(IVwSelection sel, int dyPos)
 {
     if (m_draftView != null)
     {
         m_draftView.ScrollSelectionToLocation(sel, dyPos);
     }
 }
Exemplo n.º 15
0
        void VerifySelection(SandboxBase sandbox, bool fPicture, int tagText, int tagObj, int morphIndex)
        {
            Assert.That(sandbox.RootBox.Selection, Is.Not.Null);
            Assert.That(sandbox.MorphIndex, Is.EqualTo(morphIndex));
            int          ihvoRoot;
            int          tagTextProp;
            int          cpropPrevious;
            int          ichAnchor;
            int          ichEnd;
            int          ws;
            bool         fAssocPrev;
            int          ihvoEnd;
            ITsTextProps ttpBogus;

            // Main array of information retrived from sel that made combo.
            SelLevInfo[] rgvsli;
            bool         fIsPictureSel;     // icon selected.

            IVwSelection sel = sandbox.RootBox.Selection;

            fIsPictureSel = sel.SelType == VwSelType.kstPicture;
            int cvsli = sel.CLevels(false) - 1;

            rgvsli = SelLevInfo.AllTextSelInfo(sel, cvsli,
                                               out ihvoRoot, out tagTextProp, out cpropPrevious, out ichAnchor, out ichEnd,
                                               out ws, out fAssocPrev, out ihvoEnd, out ttpBogus);
            Assert.That(fIsPictureSel, Is.EqualTo(fPicture));
            Assert.That(tagTextProp, Is.EqualTo(tagText));
            if (tagTextProp == SandboxBase.ktagSbNamedObjName)
            {
                int tagObjProp = rgvsli[0].tag;
                Assert.That(tagObjProp, Is.EqualTo(tagObj));
            }
            //sandbox.InterlinLineChoices.
        }
Exemplo n.º 16
0
        protected override void HandleSelectionChange(IVwRootBox rootb, IVwSelection vwselNew)
        {
            CheckDisposed();

            base.HandleSelectionChange(rootb, vwselNew);

            // JohnT: it's remotely possible that the base, in calling commit, made this
            // selection no longer useable.
            if (!vwselNew.IsValid)
            {
                return;
            }

            IWfiWordform wordform;

            if (!GetSelectedWordform(vwselNew, out wordform))
            {
                wordform = null;
            }
            m_mediator.PropertyTable.SetProperty("TextSelectedWord", wordform);
            m_mediator.PropertyTable.SetPropertyPersistence("TextSelectedWord", false);

            SelectionHelper helper = SelectionHelper.Create(vwselNew, this);

            if (helper != null && helper.GetTextPropId(SelectionHelper.SelLimitType.Anchor) == RawTextVc.kTagUserPrompt)
            {
                vwselNew.ExtendToStringBoundaries();
                EditingHelper.SetKeyboardForSelection(vwselNew);
            }
        }
 private static void ValidateTextRange(IVwSelection value)
 {
     if (value == null || !value.IsRange || value.SelType == VwSelType.kstPicture)
     {
         throw new ArgumentException("TextRange must be set to valid range of a text.");
     }
 }
Exemplo n.º 18
0
        public void OnFwRightMouseClick(SimpleRootSite sender, FwRightMouseClickEventArgs e)
        {
            CheckDisposed();

            var browseView = sender as XmlBrowseView;

            if (browseView != null)
            {
                IVwSelection     sel = e.Selection;
                int              clev = sel.CLevels(false);    // anchor
                int              hvoRoot, tag, ihvo, cpropPrevious;
                IVwPropertyStore vps;
                sel.PropInfo(false, clev - 1, out hvoRoot, out tag, out ihvo, out cpropPrevious, out vps);
                // First make the selection so it will be highlighted before the context menu popup.
                if (browseView.SelectedIndex != ihvo)                 // No sense in waking up the beast for no reason.
                {
                    browseView.SelectedIndex = ihvo;
                }
                int hvo = browseView.HvoAt(ihvo);
                if (Cache.ServiceLocator.IsValidObjectId(hvo))                 // may be fake one from decorator.
                {
                    CmObjectUi ui = CmObjectUi.MakeUi(Cache, hvo);             // Disposes of itself when menu closes since true passed in lext line.
                    if (ui != null)
                    {
                        ui.Mediator    = m_mediator;
                        ui.PropTable   = m_propertyTable;
                        e.EventHandled = ui.HandleRightClick(m_mediator, m_propertyTable, sender, true, "mnuBrowseView");
                    }
                }
            }
        }
Exemplo n.º 19
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Navigate to the beginning of any Scripture element: Title, Section Head, or Section
        /// Content.
        /// </summary>
        /// <param name="tag">Indicates whether selection should be made in the title, section
        /// Heading or section Content</param>
        /// <param name="book">The 0-based index of the Scripture book in which to put the
        /// insertion point</param>
        /// <param name="section">The 0-based index of the Scripture section in which to put the
        /// insertion point. Ignored if tag is <see cref="ScrBook.ScrBookTags.kflidTitle"/>
        /// </param>
        /// ------------------------------------------------------------------------------------
        public void SetInsertionPoint(int tag, int book, int section)
        {
            CheckDisposed();

            SelectionHelper selHelper = new SelectionHelper();
            int             cLev;

            if (tag == (int)ScrBook.ScrBookTags.kflidTitle)
            {
                cLev = 3;
                selHelper.NumberOfLevels          = cLev;
                selHelper.LevelInfo[cLev - 2].tag = tag;
            }
            else
            {
                cLev = 4;
                selHelper.NumberOfLevels           = cLev;
                selHelper.LevelInfo[cLev - 2].tag  = (int)ScrBook.ScrBookTags.kflidSections;
                selHelper.LevelInfo[cLev - 2].ihvo = section;
                selHelper.LevelInfo[cLev - 3].tag  = tag;
            }
            selHelper.LevelInfo[cLev - 1].tag  = (int)Scripture.ScriptureTags.kflidScriptureBooks;
            selHelper.LevelInfo[cLev - 1].ihvo = book;

            // Now that all the preparation to set the IP is done, set it.
            IVwSelection vwsel = selHelper.SetSelection(this, true, true);

            Application.DoEvents();
        }
Exemplo n.º 20
0
        public void GoToNextPara_NextFlid()
        {
            // Add a title to the root object
            int hvoTitle     = m_cache.MakeNewObject(SimpleRootsiteTestsConstants.kclsidStText, m_hvoRoot, SimpleRootsiteTestsConstants.kflidDocTitle, -2);
            int hvoTitlePara = m_cache.MakeNewObject(SimpleRootsiteTestsConstants.kclsidStTxtPara, hvoTitle, SimpleRootsiteTestsConstants.kflidTextParas, 0);

            m_cache.CacheStringProp(hvoTitlePara, SimpleRootsiteTestsConstants.kflidParaContents,
                                    TsStringUtils.MakeString("The First Book of the Law given by Moses", m_wsFrn));

            ShowForm(Lng.English, SimpleViewVc.DisplayType.kNormal |
                     SimpleViewVc.DisplayType.kTitle);
            m_basicView.Show();
            m_basicView.RefreshDisplay();

            // Set the IP at the beginning of the only (0th) instance of the only (0th) paragraph
            // of the only (0th) instance of the second (1th) footnote of the book we're displaying.
            m_SelectionHelper = new DummySelectionHelper(null, m_basicView);
            SetSelection(0, 1, 0, 0, 2, 0, 0, true);
            IVwSelection vwsel = m_SelectionHelper.SetSelection(true);

            Assert.IsNotNull(vwsel, "No selection made");
            Assert.IsTrue(m_basicView.IsSelectionVisible(null), "Selection is not visible");
            m_basicView.EditingHelper.GoToNextPara();

            // We expect that the selection will be at the start of the book title.
            SelectionHelper selectionHelper = SelectionHelper.GetSelectionInfo(null, m_basicView);

            Assert.IsFalse(selectionHelper.IsRange);
            CheckSelectionHelperValues(SelectionHelper.SelLimitType.Anchor, selectionHelper, 0,
                                       0, 0, 0, false, 2, SimpleRootsiteTestsConstants.kflidDocTitle, 0, 0,
                                       SimpleRootsiteTestsConstants.kflidTextParas, 0, 0);
        }
Exemplo n.º 21
0
        public void GoToNextPara_LastParaInView()
        {
            ShowForm(Lng.English, SimpleViewVc.DisplayType.kNormal |
                     SimpleViewVc.DisplayType.kDuplicateParagraphs);
            m_basicView.Show();
            m_basicView.RefreshDisplay();

            m_SelectionHelper = new DummySelectionHelper(null, m_basicView);
            SetSelection(0, 1, 1, 0, 2, 6, 0, true);
            IVwSelection vwsel = m_SelectionHelper.SetSelection(true);

            Assert.IsNotNull(vwsel, "No selection made");
            Assert.IsTrue(m_basicView.IsSelectionVisible(null), "Selection is not visible");
            m_basicView.EditingHelper.GoToNextPara();

            // We expect that the selection will be unchanged.
            SelectionHelper selectionHelper = SelectionHelper.GetSelectionInfo(null, m_basicView);

            Assert.IsTrue(selectionHelper.IsRange);
            CheckSelectionHelperValues(SelectionHelper.SelLimitType.Anchor, selectionHelper, 0,
                                       2, 6, 0, true, 2, SimpleRootsiteTestsConstants.kflidDocFootnotes, 0, 1,
                                       SimpleRootsiteTestsConstants.kflidTextParas, 1, 0);
            CheckSelectionHelperValues(SelectionHelper.SelLimitType.End, selectionHelper, 0,
                                       2, 0, 0, false, 2, SimpleRootsiteTestsConstants.kflidDocFootnotes, 0, 1,
                                       SimpleRootsiteTestsConstants.kflidTextParas, 1, 0);
        }
Exemplo n.º 22
0
        /// <summary>
        /// Any selection that involves an IAnalysis should be expanded to complete IAnalysis objects.
        /// This method also updates a list of selected AnalysisOccurrences.
        /// </summary>
        /// <param name="prootb"></param>
        /// <param name="vwselNew"></param>
        protected override void HandleSelectionChange(IVwRootBox prootb, IVwSelection vwselNew)
        {
            if (m_fInSelChanged)
            {
                return;
            }
            m_fInSelChanged = true;
            try
            {
                m_selectedWordforms = null;
                base.HandleSelectionChange(prootb, vwselNew);
                if (vwselNew == null)
                {
                    return;
                }

                SelLevInfo[] analysisLevels;
                SelLevInfo[] endLevels;
                if (TryGetAnalysisLevelsAndEndLevels(vwselNew, out analysisLevels, out endLevels))
                {
                    m_selectedWordforms = GetSelectedOccurrences(analysisLevels, endLevels[0].ihvo);
                    RootBox.MakeTextSelInObj(0, analysisLevels.Length, analysisLevels, endLevels.Length, endLevels, false, false,
                                             false, true, true);
                }
                else
                {
                    RootBox.DestroySelection();
                }
            }
            finally
            {
                m_fInSelChanged = false;
            }
        }
Exemplo n.º 23
0
        public void GoToNextPara_MultiParaRangeSelection()
        {
            ShowForm(Lng.English, SimpleViewVc.DisplayType.kNormal |
                     SimpleViewVc.DisplayType.kDuplicateParagraphs);
            m_basicView.Show();
            m_basicView.RefreshDisplay();

            m_SelectionHelper = new DummySelectionHelper(null, m_basicView);

            // Make a bottom-up selection, just to be sure we're not using the anchor instead of
            // the top.
            SetSelection(0, 0, 0, 0, 2, 1, 1, false);             // Set end
            SetSelection(0, 1, 0, 0, 1, 12, 12, true);            // Set anchor
            IVwSelection vwsel = m_SelectionHelper.SetSelection(true);

            Assert.IsNotNull(vwsel, "No selection made");
            m_basicView.EditingHelper.GoToNextPara();

            // We expect that the selection will be at the start of the second paragraph in
            // the selected range.
            SelectionHelper selectionHelper = SelectionHelper.GetSelectionInfo(null, m_basicView);

            Assert.IsFalse(selectionHelper.IsRange);
            CheckSelectionHelperValues(SelectionHelper.SelLimitType.Anchor, selectionHelper, 0,
                                       0, 0, 0, false, 2, SimpleRootsiteTestsConstants.kflidDocFootnotes, 0, 0,
                                       SimpleRootsiteTestsConstants.kflidTextParas, 1, 0);
        }
Exemplo n.º 24
0
        /// <summary>
        /// Return annotation Hvo that contains the selection.
        /// </summary>
        /// <returns></returns>
        public int AnnotationContainingSelection()
        {
            Debug.Assert(m_rootb != null);
            if (m_rootb == null)
            {
                return(0);
            }
            IVwSelection sel = m_rootb.Selection;

            if (sel == null)
            {
                return(0);
            }

            // See if our selection contains a base annotation.
            int cvsli = sel.CLevels(false);

            cvsli--;             // CLevels includes the string property itself, but AllTextSelInfo doesn't need it.
            // Out variables for AllTextSelInfo.
            int          ihvoRoot, tagTextProp, cpropPrevious, ichAnchor, ichEnd, ws, ihvoEnd;
            bool         fAssocPrev;
            ITsTextProps ttpBogus;

            // Main array of information retrived from sel that made combo.
            SelLevInfo[] rgvsli = SelLevInfo.AllTextSelInfo(sel, cvsli,
                                                            out ihvoRoot, out tagTextProp, out cpropPrevious, out ichAnchor, out ichEnd,
                                                            out ws, out fAssocPrev, out ihvoEnd, out ttpBogus);

            return(FindBaseAnnInSelLevInfo(rgvsli));            // returns 0 if unsuccessful
        }
Exemplo n.º 25
0
        private bool TryGetAnalysisLevelsAndEndLevels(IVwSelection vwselNew, out SelLevInfo[] analysisLevels, out SelLevInfo[] endLevels)
        {
            endLevels      = null;
            analysisLevels = GetAnalysisLevelsFromSelection(vwselNew);
            if (analysisLevels == null)
            {
                return(false);
            }

            var rgvsliEnd = GetOneEndPointOfSelection(vwselNew, true);

            // analysisLevels[0] contains info about the sequence of Analyses property. We want the corresponding
            // level in rgvsliEnd to have the same tag but not necessarily the same ihvo.
            // All the higher levels should be exactly the same. The loop checks this, and if successful
            // sets iend to the index of the property corresponding to analysisLevels[0].
            int iend;

            if (AreHigherLevelsSameObject(analysisLevels, rgvsliEnd, out iend))
            {
                endLevels = analysisLevels.Clone() as SelLevInfo[];
                if (endLevels != null)
                {
                    endLevels[0]      = new SelLevInfo();                // clone is SHALLOW; don't modify element of analysisLevels.
                    endLevels[0].ihvo = rgvsliEnd[iend].ihvo;
                    endLevels[0].tag  = analysisLevels[0].tag;
                }
            }
            return(endLevels != null);
        }
Exemplo n.º 26
0
        public void InsertVerseNumber_AtTitle()
        {
            CheckDisposed();
            IVwRootBox rootBox = m_draftView.RootBox;

            rootBox.MakeSimpleSel(true, true, false, true);
            IVwSelection sel = m_draftView.TeEditingHelper.CurrentSelection.Selection;
            int          tag;
            int          hvoSel;

            m_draftView.TeEditingHelper.GetSelectedScrElement(out tag, out hvoSel);
            Assert.AreEqual((int)ScrBook.ScrBookTags.kflidTitle, tag,
                            "First para in view was not a Title");
            ITsString tss;
            int       ich;
            bool      fAssocPrev;
            int       hvoObj;
            int       enc;

            sel.TextSelInfo(true, out tss, out ich, out fAssocPrev, out hvoObj, out tag, out enc);
            string str = tss.Text;

            m_draftView.InsertVerseNumber();
            // may destroy or move selection? Make another one to be sure.
            rootBox.MakeSimpleSel(true, true, false, true);
            sel = m_draftView.TeEditingHelper.CurrentSelection.Selection;
            sel.TextSelInfo(true, out tss, out ich, out fAssocPrev, out hvoObj, out tag, out enc);
            string str2 = tss.Text;

            Assert.AreEqual(str, str2, "Should not have inserted verse num into title para");
        }
Exemplo n.º 27
0
        /// <summary>
        /// Select the word indicated by the text-wordform-in-context (twfic) annotation.
        /// This ignores the Sandbox! This is 'public' because it overrides a public method.
        /// </summary>
        /// <param name="hvoAnn"></param>
        public override void SelectAnnotation(int hvoAnn)
        {
            ISilDataAccess sda = Cache.MainCacheAccessor;
            // We should assert that ann is Twfic
            int twficType = CmAnnotationDefn.Twfic(Cache).Hvo;
            int annoType  = sda.get_ObjectProp(hvoAnn, (int)CmAnnotation.CmAnnotationTags.kflidAnnotationType);

            Debug.Assert(annoType == twficType, "Given annotation type should be twfic("
                         + twficType + ") but was " + annoType + ".");

            // The following will select the Twfic, ... I hope!
            // Scroll to selection into view
            IVwSelection sel = SelectWficInIText(hvoAnn);

            if (sel == null)
            {
                return;
            }
            if (!this.Focused)
            {
                this.Focus();
            }
            this.ScrollSelectionIntoView(sel, VwScrollSelOpts.kssoTop);
            Update();
        }
Exemplo n.º 28
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Selects the paragraph in the DraftView or FootnoteView associated with the style.
        /// </summary>
        /// <param name="origSelection">selection user originally made</param>
        /// <param name="view">The DraftView or FootnoteView</param>
        /// ------------------------------------------------------------------------------------
        private void SelectAssociatedPara(SelectionHelper origSelection, IVwRootSite view)
        {
            SelLevInfo paraInfoAnchor = origSelection.GetLevelInfoForTag(
                StTextTags.kflidParagraphs, SelectionHelper.SelLimitType.Top);
            SelLevInfo paraInfoEnd = origSelection.GetLevelInfoForTag(
                StTextTags.kflidParagraphs, SelectionHelper.SelLimitType.Bottom);

            if (paraInfoAnchor.hvo != m_prevPara1Hvo || paraInfoEnd.hvo != m_prevPara2Hvo)
            {
                // The selection changed paragraphs, so update the selection in the
                // DraftView or FootnoteView
                IStTxtPara      para1  = m_fdoCache.ServiceLocator.GetInstance <IStTxtParaRepository>().GetObject(paraInfoAnchor.hvo);
                IStTxtPara      para2  = m_fdoCache.ServiceLocator.GetInstance <IStTxtParaRepository>().GetObject(paraInfoEnd.hvo);
                SelectionHelper helper = MakeSelection(para1, para2, view);
                IVwSelection    sel    = helper.SetSelection(view, true, false);
                // If the selection fails then try selecting the user prompt.
                if (sel == null)
                {
                    AdjustSelectionForPrompt(helper, para1, para2);
                    sel = helper.SetSelection(view, true, false);
                }

                Debug.Assert(sel != null || ((SimpleRootSite)view).ReadOnlyView);
                m_prevPara1Hvo = paraInfoAnchor.hvo;
                m_prevPara2Hvo = paraInfoEnd.hvo;
            }
        }
Exemplo n.º 29
0
        internal bool SafeToDoMacro(IVwSelection sel, out ICmObject obj, out int flid, out int ws, out int start, out int length)
        {
            start = flid = ws = length = 0;             // defaults so we can return early.
            obj   = null;
            if (sel == null || !(sel.SelType == VwSelType.kstText))
            {
                return(false);
            }
            ITsString dummy;
            int       hvoA, hvoE, flidE, ichA, ichE, wsE;
            bool      fAssocPrev;

            sel.TextSelInfo(false, out dummy, out ichA, out fAssocPrev, out hvoA, out flid, out ws);
            sel.TextSelInfo(true, out dummy, out ichE, out fAssocPrev, out hvoE, out flidE, out wsE);
            // for safety require selection to be in a single property.
            if (hvoA != hvoE || flid != flidE || ws != wsE)
            {
                return(false);
            }
            var cache = (FdoCache)m_mediator.PropertyTable.GetValue("cache");

            obj    = cache.ServiceLocator.ObjectRepository.GetObject(hvoA);
            start  = Math.Min(ichA, ichE);
            length = Math.Max(ichA, ichE) - start;
            return(true);
        }
Exemplo n.º 30
0
        // The body of OnMacro is isolated so we don't have to fake all the objects needed to get the (typically mock) selection in testing.
        internal bool DoMacro(object commandObject, IVwSelection sel)
        {
            var macro = GetMacro(commandObject);

            if (macro == null)
            {
                return(true);                // Paranoia, it should be disabled.
            }
            int       ichA, hvoA, flid, ws, ichE, start, length;
            ICmObject obj;

            if (!SafeToDoMacro(sel, out obj, out flid, out ws, out start, out length) || !macro.Enabled(obj, flid, ws, start, length))
            {
                return(true);
            }
            string commandName = macro.CommandName;
            // We normally let undo and redo be localized independently, but we compromise in the interests of making macros
            // easier to create.
            string undo = string.Format(xWorksStrings.ksUndoMacro, commandName);
            string redo = string.Format(xWorksStrings.ksRedoMacro, commandName);

            UndoableUnitOfWorkHelper.Do(undo, redo, obj.Cache.ActionHandlerAccessor,
                                        () => macro.RunMacro(obj, flid, ws, start, length));
            return(true);
        }
Exemplo n.º 31
0
			/// ------------------------------------------------------------------------------------
			/// <summary>
			/// Gets an array of property stores, one for each paragraph in the given selection.
			/// </summary>
			/// <param name="vwsel">The selection.</param>
			/// <param name="vqvps">The property stores.</param>
			/// ------------------------------------------------------------------------------------
			protected override void GetParaPropStores(IVwSelection vwsel,
				out IVwPropertyStore[] vqvps)
			{
				if (m_fOverrideGetParaPropStores)
					vqvps = new IVwPropertyStore[1];
				else
					base.GetParaPropStores(vwsel, out vqvps);
			}
Exemplo n.º 32
0
		/// <summary>
		/// Return a word selection based on the beginning of the current selection.
		/// Here the "beginning" of the selection is the offset corresponding to word order,
		/// not the selection anchor.
		/// </summary>
		/// <returns>null if we couldn't handle the selection</returns>
		private static IVwSelection SelectionBeginningGrowToWord(IVwSelection sel)
		{
			if (sel == null)
				return null;
			var sel2 = sel.EndBeforeAnchor ? sel.EndPoint(true) : sel.EndPoint(false);
			if (sel2 == null)
				return null;
			var sel3 = sel2.GrowToWord();
			return sel3;
		}
Exemplo n.º 33
0
		/// <summary>
		/// Get an array of SelLevInfo structs from the given selection.
		/// </summary>
		/// <param name="vwsel"></param>
		/// <param name="cvsli"></param>
		/// <param name="ihvoRoot"></param>
		/// <param name="tagTextProp"></param>
		/// <param name="cpropPrevious"></param>
		/// <param name="ichAnchor"></param>
		/// <param name="ichEnd"></param>
		/// <param name="ws"></param>
		/// <param name="fAssocPrev"></param>
		/// <param name="ihvoEnd"></param>
		/// <param name="ttp"></param>
		/// <returns></returns>
		public static SelLevInfo[] AllTextSelInfo(IVwSelection vwsel, int cvsli,
			out int ihvoRoot, out int tagTextProp, out int cpropPrevious, out int ichAnchor,
			out int ichEnd, out int ws, out bool fAssocPrev, out int ihvoEnd, out ITsTextProps ttp)
		{
			Debug.Assert(vwsel != null);

			using (ArrayPtr rgvsliPtr = MarshalEx.ArrayToNative<SelLevInfo>(cvsli))
			{
				vwsel.AllTextSelInfo(out ihvoRoot, cvsli, rgvsliPtr,
					out tagTextProp, out cpropPrevious, out ichAnchor, out ichEnd,
					out ws, out fAssocPrev, out ihvoEnd, out ttp);
				return MarshalEx.NativeToArray<SelLevInfo>(rgvsliPtr, cvsli);
			}
		}
		protected override void HandleSelectionChange(IVwRootBox rootb, IVwSelection vwselNew)
		{
			CheckDisposed();

			if (m_handlingSelectionChanged)
				return;

			m_handlingSelectionChanged = true;
			try
			{
				m_selectedSenseHvo = 0;
				if (vwselNew == null)
					return;
				base.HandleSelectionChange(rootb, vwselNew);

				// Get the Id of the selected snes, and store it.
				int cvsli = vwselNew.CLevels(false);
				// CLevels includes the string property itself, but AllTextSelInfo doesn't need it.
				cvsli--;
				if (cvsli == 0)
				{
					// No objects in selection: don't allow a selection.
					m_rootb.DestroySelection();
					// Enhance: invoke launcher's selection dialog.
					return;
				}
				ITsString tss;
				int ichAnchor;
				int ichEnd;
				bool fAssocPrev;
				int hvoObj;
				int hvoObjEnd;
				int tag;
				int ws;
				vwselNew.TextSelInfo(false, out tss, out ichAnchor, out fAssocPrev, out hvoObj,
					out tag, out ws);
				vwselNew.TextSelInfo(true, out tss, out ichEnd, out fAssocPrev, out hvoObjEnd,
					out tag, out ws);
				if (hvoObj != hvoObjEnd)
					return;
				m_selectedSenseHvo = hvoObj;
			}
			finally
			{
				m_handlingSelectionChanged = false;
			}
		}
Exemplo n.º 35
0
		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);
			}
		}
Exemplo n.º 36
0
		public void FindInDictionary(IOleDbEncap ode, IFwMetaDataCache mdc, IVwOleDbDa oleDbAccess, IVwSelection sel)
		{
			using (FdoCache cache = new FdoCache(ode, mdc, oleDbAccess))
			{
				if (sel == null)
					return;
				IVwSelection sel2 = sel.EndPoint(false);
				if (sel2 == null)
					return;
				IVwSelection sel3 = sel2.GrowToWord();
				if (sel3 == null)
					return;
				ITsString tss;
				int ichMin, ichLim, hvo, tag, ws;
				bool fAssocPrev;
				sel3.TextSelInfo(false, out tss, out ichMin, out fAssocPrev, out hvo, out tag, out ws);
				sel3.TextSelInfo(true, out tss, out ichLim, out fAssocPrev, out hvo, out tag, out ws);
				// TODO (TimS): need to supply help information (last 2 params)
				LexEntryUi.DisplayOrCreateEntry(cache, hvo, tag, ws, ichMin, ichLim, null, null, null, string.Empty);
				return;
			}
		}
Exemplo n.º 37
0
		/// <summary>
		/// This handles deleting the "owning" sense or entry from a calendar type lex
		/// reference by posting a message instead of simply removing the sense or entry from
		/// the reference vector.  This keeps things nice and tidy on the screen, and behaving
		/// like users would (or ought to) expect.  See LT-4114.
		/// </summary>
		/// <param name="sel"></param>
		/// <param name="dpt"></param>
		/// <returns></returns>
		public override VwDelProbResponse OnProblemDeletion(IVwSelection sel,
			VwDelProbType dpt)
		{
			CheckDisposed();

			int cvsli;
			int hvoObj;
			if (!CheckForValidDelete(sel, out cvsli, out hvoObj))
			{
				return VwDelProbResponse.kdprAbort;
			}
			else if (hvoObj == m_hvoDisplayParent)
			{
				// We need to handle this the same way as the delete command in the slice menu,
				// but can't do it directly because we've stacked up an undo handler.
				m_mediator.PostMessage("DataTreeDelete", null);
				return VwDelProbResponse.kdprDone;
			}
			else
			{
				return DeleteObjectFromVector(sel, cvsli, hvoObj);
			}
		}
Exemplo n.º 38
0
		/// <summary>
		/// The only property we update is a user prompt. We need to switch things back to normal if
		/// anything was typed there, otherwise, the string has the wrong properties, and with all of it
		/// selected, we keep typing over things.
		/// </summary>
		public override ITsString UpdateProp(IVwSelection vwsel, int hvo, int tag, int frag, ITsString tssVal)
		{
			if (tag != SimpleRootSite.kTagUserPrompt)
				return tssVal;

			// wait until an IME composition is completed before switching the user prompt to a comment
			// field, otherwise setting the comment will terminate the composition (LT-9929)
			if (RootSite.RootBox.IsCompositionInProgress)
				return tssVal;

			if (tssVal.Length == 0)
			{
				// User typed something (return?) which didn't actually put any text over the prompt.
				// No good replacing it because we'll just get the prompt string back and won't be
				// able to make our new selection.
				return tssVal;
			}

			// Get information about current selection
			SelectionHelper helper = SelectionHelper.Create(vwsel, RootSite);

			var seg = (ISegment)m_coRepository.GetObject(hvo);

			ITsStrBldr bldr = tssVal.GetBldr();
			// Clear special prompt properties
			bldr.SetIntPropValues(0, bldr.Length, SimpleRootSite.ktptUserPrompt, -1, -1);
			bldr.SetIntPropValues(0, bldr.Length, (int)FwTextPropType.ktptSpellCheck, -1, -1);

			// Add the text the user just typed to the translatin - this destroys the selection
			// because we replace the user prompt. We use the frag to note the WS of interest.
			RootSite.RootBox.DataAccess.SetMultiStringAlt(seg.Hvo, ActiveFreeformFlid, frag, bldr.GetString());

			// arrange to restore the selection (in the new property) at the end of the UOW (when the
			// required property will have been re-established by various PropChanged calls).
			RootSite.RequestSelectionAtEndOfUow(RootSite.RootBox, 0, helper.LevelInfo.Length, helper.LevelInfo, ActiveFreeformFlid,
				m_cpropActiveFreeform, helper.IchAnchor, helper.Ws, helper.AssocPrev,
				helper.GetSelProps(SelectionHelper.SelLimitType.Anchor));
			SetActiveFreeform(0, 0, 0, 0); // AFTER request selection, since it clears ActiveFreeformFlid.
			return tssVal;
		}
Exemplo n.º 39
0
		/// summary>
		/// Get the location of the given selection, presumably that of a Sandbox.
		/// /summary>
		Point GetSandboxSelLocation(IVwSelection sel)
		{
			Debug.Assert(sel != null);
			Rect rcPrimary = GetPrimarySelRect(sel);
			// The location includes margins, so for RTL we need to adjust the
			// Sandbox so it isn't hard up against the next word.
			// Enhance JohnT: ideally we would probably figure this margin
			// to exactly match the margin between words set by the VC.
			int left = rcPrimary.left;
			if (m_vc.RightToLeft)
				left += 8;
			return new Point(left, rcPrimary.top);
		}
Exemplo n.º 40
0
		/// -----------------------------------------------------------------------------------
		/// <summary>
		/// Notifies the site that something about the selection has changed.
		/// </summary>
		/// <param name="prootb"></param>
		/// <param name="vwselNew">Selection</param>
		/// <remarks>When overriding you should call the base class first.</remarks>
		/// -----------------------------------------------------------------------------------
		protected override void HandleSelectionChange(IVwRootBox prootb, IVwSelection vwselNew)
		{
			if (m_fInSelectionChanged)
				return; // don't need to reprocess our own changes.
			m_fInSelectionChanged = true;
			try
			{
				base.HandleSelectionChange(prootb, vwselNew);
				IVwSelection sel = vwselNew;
				if (!sel.IsValid)
					sel = prootb.Selection;
				if (sel == null)
					return;
				SelectionHelper helper = SelectionHelper.Create(sel, prootb.Site);
				// Check whether the selection is on the proper line of a multilingual
				// annotation and, if not, fix it.  See LT-9421.
				if (m_cpropPrevForInsert > 0 && !sel.IsRange &&
					(helper.GetNumberOfPreviousProps(SelectionHelper.SelLimitType.Anchor) == 0 ||
					 helper.GetNumberOfPreviousProps(SelectionHelper.SelLimitType.End) == 0))
				{
					try
					{
						helper.SetNumberOfPreviousProps(SelectionHelper.SelLimitType.Anchor, m_cpropPrevForInsert);
						helper.SetNumberOfPreviousProps(SelectionHelper.SelLimitType.End, m_cpropPrevForInsert);
						helper.MakeBest(true);
						m_cpropPrevForInsert = -1;	// we've used this the one time it was needed.
					}
					catch (Exception exc)
					{
						if (exc != null)
							Debug.WriteLine(String.Format(
								"InterlinDocChild.SelectionChanged() trying to display prompt in proper line of annotation: {0}", exc.Message));
					}
				}
				int flid = helper.GetTextPropId(SelectionHelper.SelLimitType.Anchor);
				//If the flid is -2 and it is an insertion point then we may have encountered a case where the selection has landed at the boundary between our (possibly empty)
				//translation field and a literal string containing our magic Bidi marker character that helps keep things in the right order.
				//Sometimes AssocPrev gets set so that we read the (non-existent) flid of the literal string and miss the fact that on the other side
				//of the insertion point is the field we're looking for. The following code will attempt to make a selection that associates in
				//the other direction to see if the flid we want is on the other side. [LT-10568]
				if (flid == -2 && !sel.IsRange && sel.SelType == VwSelType.kstText)
				{
					helper.AssocPrev = !helper.AssocPrev;
					try
					{
						var newSel = helper.MakeRangeSelection(this.RootBox, false);
						helper = SelectionHelper.Create(newSel, this);
						flid = helper.GetTextPropId(SelectionHelper.SelLimitType.Anchor);
					}
					catch (COMException)
					{
						// Ignore HResult E_Fail caused by Extended Keys (PgUp/PgDown) in non-editable text (LT-13500)
					}
				}
				//Fixes LT-9884 Crash when clicking on the blank space in Text & Words--->Print view area!
				if (helper.LevelInfo.Length == 0)
					return;
				int hvo = helper.LevelInfo[0].hvo;

				// If the selection is in a freeform or literal translation that is empty, display the prompt.
				if (SelIsInEmptyTranslation(helper, flid, hvo) && !m_rootb.IsCompositionInProgress)
				{
					var handlerExtensions = Cache.ActionHandlerAccessor as IActionHandlerExtensions;
					if (handlerExtensions != null && handlerExtensions.IsUndoTaskActive)
					{
						// Wait to make the changes until the task (typically typing backspace) completes.
						m_setupPromptHelper = helper;
						m_setupPromptFlid = flid;
						handlerExtensions.DoAtEndOfPropChanged(handlerExtensions_PropChangedCompleted);
					}
					else
					{
						// No undo task to tag on the end of, so do it now.
						SetupTranslationPrompt(helper, flid);
					}
				}
				else if (flid != kTagUserPrompt)
				{
					m_vc.SetActiveFreeform(0, 0, 0, 0); // clear any current prompt.
				}
				// do not extend the selection for a user prompt if the user is currently entering an IME composition,
				// since we are about to switch the prompt to a real comment field
				else if (helper.GetTextPropId(SelectionHelper.SelLimitType.End) == SimpleRootSite.kTagUserPrompt
					&& !m_rootb.IsCompositionInProgress)
				{
					// If the selection is entirely in a user prompt then extend the selection to cover the
					// entire prompt. This covers changes within the prompt, like clicking within it or continuing
					// a drag while making it.
					sel.ExtendToStringBoundaries();
					EditingHelper.SetKeyboardForSelection(sel);
				}
			}
			finally
			{
				m_fInSelectionChanged = false;
			}
		}
Exemplo n.º 41
0
		/// <summary>
		/// Handles a view selection produced by a click. Return true to suppress normal
		/// mouse down handling, indicating that an interlinear bundle has been clicked and the Sandbox
		/// moved.
		/// </summary>
		/// <param name="vwselNew"></param>
		/// <param name="fBundleOnly"></param>
		/// <param name="fSaveGuess">if true, saves guesses; if false, skips guesses but still saves edits.</param>
		/// <returns></returns>
		protected virtual bool HandleClickSelection(IVwSelection vwselNew, bool fBundleOnly, bool fSaveGuess)
		{
			if (vwselNew == null)
				return false; // couldn't select a bundle!
			// The basic idea is to find the level at which we are displaying the TagAnalysis property.
			int cvsli = vwselNew.CLevels(false);
			cvsli--; // CLevels includes the string property itself, but AllTextSelInfo doesn't need it.

			// Out variables for AllTextSelInfo.
			int ihvoRoot;
			int tagTextProp;
			int cpropPrevious;
			int ichAnchor;
			int ichEnd;
			int ws;
			bool fAssocPrev;
			int ihvoEnd;
			ITsTextProps ttpBogus;
			// Main array of information retrived from sel that made combo.
			SelLevInfo[] rgvsli = SelLevInfo.AllTextSelInfo(vwselNew, cvsli,
				out ihvoRoot, out tagTextProp, out cpropPrevious, out ichAnchor, out ichEnd,
				out ws, out fAssocPrev, out ihvoEnd, out ttpBogus);

			if (tagTextProp == SegmentTags.kflidFreeTranslation || tagTextProp == SegmentTags.kflidLiteralTranslation
				|| tagTextProp == NoteTags.kflidContent)
			{
				bool fWasFocusBoxInstalled = IsFocusBoxInstalled;
				Rect oldSelLoc = GetPrimarySelRect(vwselNew);
				if (!fBundleOnly)
				{
					if (IsFocusBoxInstalled)
						FocusBox.UpdateRealFromSandbox(null, fSaveGuess, null);
					TryHideFocusBoxAndUninstall();
				}

				// If the selection resulting from the click is still valid, and we just closed the focus box, go ahead and install it;
				// continuing to process the click may not produce the intended result, because
				// removing the focus box can re-arrange things substantially (LT-9220).
				// (However, if we didn't change anything it is necesary to process it normally, otherwise, dragging
				// and shift-clicking in the free translation don't work.)
				if (!vwselNew.IsValid || !fWasFocusBoxInstalled)
					return false;
				// We have destroyed a focus box...but we may not have moved the free translation we clicked enough
				// to cause problems. If not, we'd rather do a normal click, because installing a selection that
				// the root box doesn't think is from mouse down does not allow dragging.
				Rect selLoc = GetPrimarySelRect(vwselNew);
				if (selLoc.top == oldSelLoc.top)
					return false;
				//The following line could quite possibly invalidate the selection as in the case where it creates
				//a translation prompt.
				vwselNew.Install();
				//scroll the current selection into view (don't use vwselNew, it might be invalid now)
				ScrollSelectionIntoView(this.RootBox.Selection, VwScrollSelOpts.kssoDefault);
				return true;
			}

			// Identify the analysis, and the position in m_rgvsli of the property holding it.
			// It is also possible that the analysis is the root object.
			// This is important because although we are currently displaying just an StTxtPara,
			// eventually it might be part of a higher level structure. We want to be able to
			// reproduce everything that gets us down to the analysis.
			int itagAnalysis = -1;
			for (int i = rgvsli.Length; --i >= 0; )
			{
				if (rgvsli[i].tag == SegmentTags.kflidAnalyses)
				{
					itagAnalysis = i;
					break;
				}
			}
			if (itagAnalysis < 0)
			{
				if (!fBundleOnly)
				{
					if (IsFocusBoxInstalled)
						FocusBox.UpdateRealFromSandbox(null, fSaveGuess, null);
					TryHideFocusBoxAndUninstall();
				}

				return false; // Selection is somewhere we can't handle.
			}
			int ianalysis = rgvsli[itagAnalysis].ihvo;
			Debug.Assert(itagAnalysis < rgvsli.Length - 1); // Need different approach if the analysis is the root.
			int hvoSeg = rgvsli[itagAnalysis + 1].hvo;
			var seg = Cache.ServiceLocator.GetObject(hvoSeg) as ISegment;
			Debug.Assert(seg != null);
			// If the mouse click lands on a punctuation form, move to the preceding
			// wordform (if any).  See FWR-815.
			while (seg.AnalysesRS[ianalysis] is IPunctuationForm && ianalysis > 0)
				--ianalysis;
			if (ianalysis == 0 && seg.AnalysesRS[0] is IPunctuationForm)
			{
				if (!fBundleOnly)
					TryHideFocusBoxAndUninstall();
				return false;
			}
			TriggerAnnotationSelected(new AnalysisOccurrence(seg, ianalysis), fSaveGuess);
			return true;
		}
Exemplo n.º 42
0
		/// -----------------------------------------------------------------------------------
		/// <summary>
		/// Handle a selection changed event.
		/// </summary>
		/// <param name="rootb">root box that has the selection change</param>
		/// <param name="vwselNew">Selection</param>
		/// -----------------------------------------------------------------------------------
		protected override void HandleSelectionChange(IVwRootBox rootb, IVwSelection vwselNew)
		{
			CheckDisposed();

			base.HandleSelectionChange(rootb, vwselNew);

			// It's possible that the base either changed the selection or invalidated it in
			// calling commit and made this selection no longer useable.
			SelectionHelper helper = EditingHelper.CurrentSelection;
			if (helper == null || !helper.Selection.IsValid)
				return;

			// scroll the footnote pane to be in synch with the draft view
			// (TimS): Focused was taken out because it was causing selection changes that
			// happended from a menu item wouldn't scroll to the footnote.
			if (TheDraftViewWrapper != null && TheDraftViewWrapper.FootnoteViewShowing &&
				Options.FootnoteSynchronousScrollingSetting)
			{
				// For performance on typing, don't try to scroll footnote pane on every update
				SelLevInfo paraInfo;
				if (helper.GetLevelInfoForTag(StTextTags.kflidParagraphs, out paraInfo))
				{
					IStTxtPara para = m_fdoCache.ServiceLocator.GetInstance<IStTxtParaRepository>().GetObject(paraInfo.hvo);
					ITsString tss = para.Contents;
					if (helper.IchAnchor <= tss.Length)
					{
						int iRun = (helper.IchAnchor >= 0) ? tss.get_RunAt(helper.IchAnchor) : -1;
						if (iRun != -1 && (m_prevSelectedParagraph != paraInfo.hvo ||
						iRun != m_prevAnchorPosition))
						{
							SynchFootnoteView(helper);
							// Save selection information
							m_prevSelectedParagraph = paraInfo.hvo;
							m_prevAnchorPosition = iRun;
						}
					}
				}
			}

			// Debug code was taken out. It was put in to help with testing using TestLangProj.
			// Most of our tests are using the InMemoryCache so this information is almost useless.
			// If you need it, just change the "DEBUG_not_exist" to "DEBUG" and then compile.
			#region Debug code
#if DEBUG_not_exist
			// This section of code will display selection information in the status bar when the
			// program is compiled in Debug mode. The information shown in the status bar is useful
			// when you want to make selections in tests.
			try
			{
				string text;
				SelLevInfo paraInfo = helper.GetLevelInfoForTag(StTextTags.kflidParagraphs);
				SelLevInfo secInfo = helper.GetLevelInfoForTag(ScrBookTags.kflidSections);
				SelLevInfo bookInfo = helper.GetLevelInfoForTag(BookFilter.Tag);

				bool inBookTitle = TeEditingHelper.InBookTitle;
				bool inSectionHead = TeEditingHelper.InSectionHead;

				text = "Book: " + bookInfo.ihvo +
					"  Section: " + (inBookTitle ? "Book Title" : secInfo.ihvo.ToString()) +
					"  Paragraph: " + paraInfo.ihvo +
					"  Anchor: " + helper.IchAnchor + "  End: " + helper.IchEnd +
					" AssocPrev: " + helper.AssocPrev;

				if (!inBookTitle && bookInfo.ihvo >= 0)
				{
					IStTxtPara para = m_fdoCache.ServiceLocator.GetInstance<IStTxtParaRepository>().GetObject(paraInfo.hvo);
					ITsString tss = para.Contents;
					if (helper.IchAnchor <= tss.Length)
						text += "  Run No.: " + tss.get_RunAt(helper.IchAnchor);
				}

				if (TheMainWnd != null)
					TheMainWnd.StatusStrip.Items[0].Text = text;
			}
			catch
			{
			}
#endif
			#endregion
		}
Exemplo n.º 43
0
		/// -----------------------------------------------------------------------------------
		/// <summary>
		/// Notifies the site that something about the selection has changed.
		/// </summary>
		/// <param name="prootb"></param>
		/// <param name="vwselNew"></param>
		/// -----------------------------------------------------------------------------------
		void IVwRootSite.SelectionChanged(IVwRootBox prootb, IVwSelection vwselNew)
		{
			// Do nothing for printing
		}
		public IVwSelection MakeSelInBox(IVwSelection _selInit, bool fEndPoint, int iLevel, int iBox,
			bool fInitial, bool fRange, bool fInstall)
		{
			throw new NotImplementedException();
		}
Exemplo n.º 45
0
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		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 )
			{
				if(components != null)
				{
					components.Dispose();
				}
				if (m_view != null && !Controls.Contains(m_view))
					m_view.Dispose();
				if (m_detailView != null && !Controls.Contains(m_detailView))
					m_detailView.Dispose();
			}
			m_sel = null;
			m_cache = null;
			m_view = null;
			m_detailView = null;
			if (m_cdaTemp != null)
			{
				m_cdaTemp.ClearAllData();
				Marshal.ReleaseComObject(m_cdaTemp);
				m_cdaTemp = null;
			}

			base.Dispose( disposing );
		}
Exemplo n.º 46
0
		public override void SelectionChanged(IVwRootBox rootb, IVwSelection vwselNew)
		{
			CheckDisposed();
			if (vwselNew == null)
				return;
			bool hasFoc = Focused;

			base.SelectionChanged(rootb, vwselNew);

			ITsString tss;
			int ichAnchor;
			bool fAssocPrev;
			int hvoObj;
			int tag;
			int ws; // NB: This will be 0 after each call, since the string does
			// not have alternatives. Ws would be the WS of an alternative,
			// if there were any.
			vwselNew.TextSelInfo(false, out tss, out ichAnchor, out fAssocPrev, out hvoObj,
				out tag, out ws);

			int ichEnd;
			int hvoObjEnd;
			vwselNew.TextSelInfo(true, out tss, out ichEnd, out fAssocPrev, out hvoObjEnd,
				out tag, out ws);

			if (hvoObjEnd != hvoObj)
			{
				CheckHeight();
				return;
			}
			if (m_hvoOldSelection > 0 && hvoObj != m_hvoOldSelection)
			{
				// Try to validate previously selected string rep.
				if (m_silCache.get_StringProp(m_hvoOldSelection, kEnvStringRep).Length==0)
				{
					// Remove it from the dummy cache, since its length is 0.
					int limit = m_silCache.get_VecSize(m_rootObj.Hvo, kMainObjEnvironments);
					for (int i = 0; i < limit; ++i)
					{
						if (m_hvoOldSelection ==
							m_silCache.get_VecItem(m_rootObj.Hvo, kMainObjEnvironments, i))
						{
							RemoveFromDummyCache(i);
							break;
						}
					}
				}
				else // Validate previously selected string rep.
				{
					ValidateStringRep(m_hvoOldSelection);
				}
			}
			if (hvoObj != kDummyPhoneEnvID)
			{
				m_hvoOldSelection = hvoObj;
				CheckHeight();
				return;
			}
			if (tss.Length == 0)
			{
				CheckHeight();
				return;
			}
			// Create a new object, and recreate a new empty object. Make this part of the Undo
			// Task with the character we typed.
			m_silCache.GetActionHandler().ContinueUndoTask();
			int count = m_silCache.get_VecSize(m_rootObj.Hvo, kMainObjEnvironments);
			int hvoNew = InsertNewEnv(count - 1);
			m_silCache.SetString(hvoNew, kEnvStringRep, tss);
			m_silCache.SetString(kDummyPhoneEnvID, kEnvStringRep, DummyString);
			m_silCache.EndUndoTask();
			// Refresh
			m_silCache.PropChanged(null, (int)PropChangeType.kpctNotifyAll,
				m_rootObj.Hvo, kMainObjEnvironments, count - 1, 2, 1);

			// Reset selection.
			SelLevInfo[] rgvsli = new SelLevInfo[1];
			rgvsli[0].cpropPrevious = 0;
			rgvsli[0].tag = kMainObjEnvironments;
			rgvsli[0].ihvo = count - 1;
			m_rootb.MakeTextSelection(0, rgvsli.Length, rgvsli, tag, 0, ichAnchor, ichEnd, ws,
				fAssocPrev, -1, null, true);

			m_hvoOldSelection = hvoNew;
			CheckHeight();
		}
Exemplo n.º 47
0
		/// <summary>
		/// Get the string representation of the current selection in the environment list,
		/// plus the selection object and some of its internal information.
		/// </summary>
		/// <param name="tss"></param>
		/// <param name="vwsel"></param>
		/// <param name="hvoDummyObj"></param>
		/// <param name="ichAnchor"></param>
		/// <param name="ichEnd"></param>
		/// <returns>false if selection spans two or more objects, true otherwise</returns>
		internal bool GetSelectedStringRep(out ITsString tss, out IVwSelection vwsel,
			out int hvoDummyObj, out int ichAnchor, out int ichEnd)
		{
			CheckDisposed();
			tss = null;
			vwsel = null;
			hvoDummyObj = 0;
			ichAnchor = 0;
			ichEnd = 0;
			try
			{
				ITsString tss2;
				bool fAssocPrev;
				int hvoObjEnd;
				int tag1;
				int tag2;
				int ws1;
				int ws2;
				vwsel = m_rootb.Selection;
				vwsel.TextSelInfo(false, out tss, out ichAnchor, out fAssocPrev, out hvoDummyObj,
					out tag1, out ws1);
				vwsel.TextSelInfo(true, out tss2, out ichEnd, out fAssocPrev, out hvoObjEnd,
					out tag2, out ws2);
				if (hvoDummyObj != hvoObjEnd)
					return false;
			}
			catch
			{
				vwsel = null;
				tss = null;
				return true;
			}
			return true;
		}
Exemplo n.º 48
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Scrolls the selection into view, positioning it as requested
		/// </summary>
		/// <param name="sel">The selection, or <c>null</c> to use the current selection</param>
		/// <param name="scrollOption">The VwScrollSelOpts specification.</param>
		/// ------------------------------------------------------------------------------------
		bool IVwRootSite.ScrollSelectionIntoView(IVwSelection sel,
			VwScrollSelOpts scrollOption)
		{
			// Do nothing for printing
			return false;
		}
Exemplo n.º 49
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// User trying to paste text with object ref - not implemented for print.
		/// </summary>
		/// <param name="text"></param>
		/// <param name="selDst"></param>
		/// <param name="podt"></param>
		/// ------------------------------------------------------------------------------------
		Guid IVwRootSite.get_MakeObjFromText(string text, IVwSelection selDst, out int podt)
		{
			throw new NotImplementedException();
		}
Exemplo n.º 50
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// The user has attempted to delete something which the system does not inherently
		/// know how to delete. The dpt argument indicates the type of problem.
		/// </summary>
		/// <param name="sel">The selection</param>
		/// <param name="dpt">Problem type</param>
		/// <returns><c>true</c> to abort</returns>
		/// ------------------------------------------------------------------------------------
		VwDelProbResponse IVwRootSite.OnProblemDeletion(IVwSelection sel, VwDelProbType dpt)
		{
			throw new NotImplementedException();
		}
		public IVwSelection MakeRangeSelection(IVwSelection _selAnchor, IVwSelection _selEnd,
			bool fInstall)
		{
			m_dummySelection = new DummyVwSelection(this,
				(_selAnchor as DummyVwSelection).Anchor, (_selEnd as DummyVwSelection).End);
			return m_dummySelection;
		}
Exemplo n.º 52
0
		private void DeleteNote(IVwSelection sel)
		{
			int hvoNote;
			if (!CanDeleteNote(sel, out hvoNote))
				return;
			var note = Cache.ServiceLocator.GetInstance<INoteRepository>().GetObject(hvoNote);
			var segment = (ISegment)note.Owner;
			segment.NotesOS.Remove(note);
		}
Exemplo n.º 53
0
		/// <summary>
		/// Suppress the special behavior that produces a Sandbox when a click happens.
		/// </summary>
		/// <param name="vwselNew"></param>
		/// <param name="fBundleOnly"></param>
		/// <param name="fConfirm"></param>
		protected override bool HandleClickSelection(IVwSelection vwselNew, bool fBundleOnly, bool fConfirm)
		{
			return false;
		}
Exemplo n.º 54
0
		/// <summary>
		///  Answer true if the indicated selection is within a single note we can delete.
		/// </summary>
		/// <param name="sel"></param>
		/// <returns></returns>
		private bool CanDeleteNote(IVwSelection sel, out int hvoNote)
		{
			hvoNote = 0;
			int tagAnchor, hvoObj;
			if (!GetTagAndObjForOnePropSelection(sel, out hvoObj, out tagAnchor))
				return false;
			if (tagAnchor != NoteTags.kflidContent)
				return false; // must be a selection in a note to be deletable.
			hvoNote = hvoObj;
			return true;
		}
Exemplo n.º 55
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Handle a problem deletion - a complex selection crossing sections or other
		/// difficult cases such as BS/DEL at boundaries.
		/// </summary>
		/// <param name="sel"></param>
		/// <param name="dpt"></param>
		/// <returns></returns>
		/// ------------------------------------------------------------------------------------
		public override VwDelProbResponse OnProblemDeletion(IVwSelection sel,
			VwDelProbType dpt)
		{
			CheckDisposed();

			return TeEditingHelper.OnProblemDeletion(sel, dpt);
		}
Exemplo n.º 56
0
		/// <summary>
		///  Answer true if the indicated selection is within a single note we can delete. Also obtain
		/// the object and property.
		/// </summary>
		private bool GetTagAndObjForOnePropSelection(IVwSelection sel, out int hvoObj, out int tagAnchor)
		{
			hvoObj = tagAnchor = 0;
			if (sel == null)
				return false;
			ITsString tss;
			int ichEnd, hvoEnd, tagEnd, wsEnd;
			bool fAssocPrev;
			sel.TextSelInfo(true, out tss, out ichEnd, out fAssocPrev, out hvoEnd, out tagEnd, out wsEnd);
			int ichAnchor, hvoAnchor, wsAnchor;
			sel.TextSelInfo(false, out tss, out ichAnchor, out fAssocPrev, out hvoAnchor, out tagAnchor, out wsAnchor);
			if (hvoEnd != hvoAnchor || tagEnd != tagAnchor || wsEnd != wsAnchor)
				return false; // must be a one-property selection
			hvoObj = hvoAnchor;
			return true;
		}
Exemplo n.º 57
0
		public RelatedWords(FdoCache cache, IVwSelection sel, int hvoEntry, int[] domains, int[] lexrels,
			IVwCacheDa cdaTemp, IVwStylesheet styleSheet)
		{
			m_cache = cache;
			m_sel = sel;
			m_hvoEntry = hvoEntry;
			m_styleSheet = styleSheet;
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			m_cdaTemp = cdaTemp;
			ISilDataAccess sda = m_cdaTemp as ISilDataAccess;
			sda.WritingSystemFactory = cache.MainCacheAccessor.WritingSystemFactory;

			SetupForEntry(domains, lexrels);

			m_view = new RelatedWordsView(m_hvoEntry, m_cdaTemp as ISilDataAccess, cache.DefaultUserWs);
			m_view.Width = this.Width - 20;
			m_view.Height = m_btnClose.Top - 20;
			m_view.Top = 10;
			m_view.Left = 10;
			m_view.Anchor = AnchorStyles.Bottom | AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
			m_view.BackColor = Color.FromKnownColor(KnownColor.Window);
			m_view.EditingHelper.DefaultCursor = Cursors.Arrow;

			m_view.SelChanged += new EventHandler(m_view_SelChanged);
			this.Controls.Add(m_view);
		}
		public bool get_Follows(IVwSelection _sel)
		{
			throw new NotImplementedException();
		}
Exemplo n.º 59
0
		/// <summary>
		/// Handle a selection change by growing it to a word (unless the new selection IS
		/// the one we're growing to a word).
		/// </summary>
		/// <param name="prootb"></param>
		/// <param name="vwselNew"></param>
		public override void SelectionChanged(IVwRootBox prootb, IVwSelection vwselNew)
		{
			CheckDisposed();

			base.SelectionChanged (prootb, vwselNew);
			if (!m_fInSelChange)
			{
				m_fInSelChange = true;
				try
				{
					if (!vwselNew.IsRange)
					{
						vwselNew.GrowToWord().Install();
					}
				}
				finally
				{
					m_fInSelChange = false;
				}
			}
			if (SelChanged != null)
				SelChanged(this, new EventArgs());
		}
Exemplo n.º 60
0
		/// <summary>
		/// Gets the sel lev info from selection.
		/// </summary>
		/// <param name="vwsel">The vwsel.</param>
		/// <returns></returns>
		private SelLevInfo[] GetSelLevInfoFromSelection(IVwSelection vwsel)
		{
			SelectionHelper helper = SelectionHelper.Create(vwsel, this);
			if (helper == null)
				return null;
			return helper.LevelInfo;
		}