コード例 #1
0
        /// <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);
        }