Example #1
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;
            }
        }
Example #2
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");
                    }
                }
            }
        }
Example #3
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Level 0 returns the same object as Hvo(fEndPoint).
        /// Level 1 returns the object which contains the display of ContainingObject(0, fEndPoint).
        /// Level n returns the object which contains the display of ContainingObject(n-1, fEndPoint).
        /// Returns 0 if there was no selection or level is too large.
        /// </summary>
        /// <param name="level"></param>
        /// <param name="fEndPoint"></param>
        /// <returns></returns>
        /// ------------------------------------------------------------------------------------
        public int ContainingObject(int level, bool fEndPoint)
        {
            if (m_sel == null)
            {
                return(0);
            }
            if (level >= m_sel.CLevels(fEndPoint))
            {
                return(0);
            }
            int hvoObj, tag, ihvo, cpropPrevious;
            IVwPropertyStore vps;

            m_sel.PropInfo(fEndPoint, level, out hvoObj, out tag, out ihvo, out cpropPrevious, out vps);
            return(hvoObj);
        }
Example #4
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>
        /// -----------------------------------------------------------------------------------
        public override void SelectionChanged(IVwRootBox prootb, IVwSelection vwselNew)
        {
            CheckDisposed();

            base.SelectionChanged(prootb, vwselNew);
            if (vwselNew == null)
            {
                return;
            }
            int clev = vwselNew.CLevels(false);                         // anchor
            int hvoRoot, tag, ihvo, cpropPrevious;
            IVwPropertyStore vps;

            vwselNew.PropInfo(false, clev - 1, out hvoRoot, out tag, out ihvo,
                              out cpropPrevious, out vps);
            Debug.Assert(hvoRoot == m_hvoRoot);
            int hvoObjNewSel = m_fdoCache.MainCacheAccessor.get_VecItem(hvoRoot, tag, ihvo);

            if (hvoObjNewSel != 0)
            {
                // Notify any delegates that the selection of the main object in the vector
                // may have changed.
                if (SelectionChangedEvent != null)
                {
                    SelectionChangedEvent(this, new FwObjectSelectionEventArgs(hvoObjNewSel, ihvo));
                }
            }
        }
Example #5
0
        public void OnFwRightMouseClick(SimpleRootSite sender, FwRightMouseClickEventArgs e)
        {
            CheckDisposed();

            XmlBrowseView 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);
                CmObjectUi ui  = CmObjectUi.MakeUi(Cache, hvo);
                if (ui != null)
                {
                    e.EventHandled = ui.HandleRightClick(m_mediator, sender, true, "mnuBrowseView");
                }
            }
        }
Example #6
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)
        {
            CheckDisposed();

            base.HandleSelectionChange(prootb, vwselNew);
            if (vwselNew == null)
            {
                return;
            }
            int clev    = vwselNew.CLevels(false);                      // anchor
            int clevEnd = vwselNew.CLevels(true);

            if (clev < 2 || clevEnd < 2)
            {
                return;                 // paranoia
            }
            int hvoRoot, tag, ihvo, ihvoEnd, cpropPrevious;
            IVwPropertyStore vps;

            vwselNew.PropInfo(true, clevEnd - 1, out hvoRoot, out tag, out ihvoEnd,
                              out cpropPrevious, out vps);
            vwselNew.PropInfo(false, clev - 1, out hvoRoot, out tag, out ihvo,
                              out cpropPrevious, out vps);
            // Give up if the selection doesn't indicate any top-level object; I think this can happen with pictures.
            // selection larger than a top-level object, maybe select all, side effects are confusing.
            if (ihvo != ihvoEnd || ihvo < 0)
            {
                return;
            }
            if (hvoRoot == 0)
            {
                return;
            }
            Debug.Assert(hvoRoot == m_hvoRoot);
            int hvoObjNewSel = m_sdaSource.get_VecItem(hvoRoot, tag, ihvo);

            if (hvoObjNewSel != 0)
            {
                // Notify any delegates that the selection of the main object in the vector
                // may have changed.
                if (SelectionChangedEvent != null)
                {
                    SelectionChangedEvent(this, new FwObjectSelectionEventArgs(hvoObjNewSel, ihvo));
                }
            }
        }
Example #7
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Print method
        /// </summary>
        /// ------------------------------------------------------------------------------------
        public override void Print(PrintDocument pd)
        {
            CheckDisposed();

            bool fPrintSelection = (pd.PrinterSettings.PrintRange == PrintRange.Selection);

            int[] originalObjects = null;
            if (fPrintSelection)
            {
                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);
                ISilDataAccess sda      = m_fdoCache.MainCacheAccessor;
                int            chvoReal = sda.get_VecSize(m_hvoRoot, m_mainFlid);
                using (ArrayPtr arrayPtr = MarshalEx.ArrayToNative(chvoReal, typeof(int)))
                {
                    sda.VecProp(m_hvoRoot, m_mainFlid, chvoReal, out chvoReal, arrayPtr);
                    originalObjects = (int[])MarshalEx.NativeToArray(arrayPtr, chvoReal, typeof(int));
                }
                int   ihvoMin         = Math.Min(ihvoEnd, ihvoAnchor);
                int   ihvoLim         = Math.Max(ihvoEnd, ihvoAnchor) + 1;
                int[] selectedObjects = new int[ihvoLim - ihvoMin];
                for (int i = 0; i < selectedObjects.Length; i++)
                {
                    selectedObjects[i] = originalObjects[i + ihvoMin];
                }
                m_fdoCache.VwCacheDaAccessor.CacheVecProp(m_hvoRoot, m_mainFlid, selectedObjects, selectedObjects.Length);
            }
            try
            {
                base.Print(pd);
            }
            finally
            {
                if (fPrintSelection)
                {
                    m_fdoCache.VwCacheDaAccessor.CacheVecProp(m_hvoRoot, m_mainFlid, originalObjects, originalObjects.Length);
                }
            }
        }
Example #8
0
        protected override bool DoContextMenu(IVwSelection sel, Point pt, Rectangle rcSrcRoot, Rectangle rcDstRoot)
        {
            int hvo, tag, ihvo, cpropPrevious;
            IVwPropertyStore propStore;

            sel.PropInfo(false, 0, out hvo, out tag, out ihvo, out cpropPrevious, out propStore);
            string nodePath = null;

            if (propStore != null)
            {
                nodePath = propStore.get_StringProperty((int)FwTextPropType.ktptBulNumTxtBef);
            }
            if (string.IsNullOrEmpty(nodePath))
            {
                if (sel.SelType == VwSelType.kstPicture)
                {
                    return(true);
                }
                // may be a literal string, where we can get it from the string itself.
                ITsString tss;
                int       ich, ws;
                bool      fAssocPrev;
                sel.TextSelInfo(false, out tss, out ich, out fAssocPrev, out hvo, out tag, out ws);
                nodePath = tss.get_Properties(0).GetStrPropValue((int)FwTextPropType.ktptBulNumTxtBef);
            }
            if (m_configObjectName == null)
            {
                m_configObjectName = XmlUtils.GetLocalizedAttributeValue(
                    Mediator.StringTbl, m_xnSpec, "configureObjectName", null);
            }
            string label;

            if (string.IsNullOrEmpty(nodePath))
            {
                label = String.Format(xWorksStrings.ksConfigure, m_configObjectName);
            }
            else
            {
                label = String.Format(xWorksStrings.ksConfigureIn, nodePath.Split(':')[3], m_configObjectName);
            }
            m_contextMenu = new ContextMenuStrip();
            var item = new ToolStripMenuItem(label);

            m_contextMenu.Items.Add(item);
            item.Click += RunConfigureDialogAt;
            item.Tag    = nodePath;
            m_contextMenu.Show(this, pt);
            m_contextMenu.Closed += m_contextMenu_Closed;
            return(true);
        }
Example #9
0
        /// <summary>
        /// Determine whether the current selection is at a place suitable for type-ahead. If not, answer 0.
        /// (In this case the values of hvoParent and ihvo should not be relied on.)
        /// If so, indicate the object whose property may be set by type-ahead (hvoParent), the object
        /// in the relevant property that is selected (return result), and its index within the property
        /// (0 if atomic).
        /// </summary>
        /// <param name="rootb"></param>
        /// <param name="sel"></param>
        /// <param name="hvoParent"></param>
        /// <param name="ihvo"></param>
        /// <returns></returns>
        private int SelectedObject(IVwRootBox rootb, IVwSelection sel, out int hvoParent, out int ihvo)
        {
            hvoParent = 0;
            ihvo      = 0;
            if (rootb == null)             // If we don't have a root box, can't do anything interesting.
            {
                return(0);
            }
            if (sel == null)             // nothing interesting to do without a selection, either.
            {
                return(0);
            }
            ITsString tssA, tssE;
            int       ichA, ichE, hvoObjA, hvoObjE, tagA, tagE, ws;
            bool      fAssocPrev;

            // Enhance JohnT: what we're really trying to do here is confirm that the selection is
            // all in one string property. We could readily have a method in the selection interface to tell us that.
            sel.TextSelInfo(false, out tssA, out ichA, out fAssocPrev, out hvoObjA, out tagA, out ws);
            if (tagA != m_taTagName && tagA != m_snTagName)
            {
                return(0);                // selection not anchored in any sort of type-ahead name property.
            }
            sel.TextSelInfo(true, out tssE, out ichE, out fAssocPrev, out hvoObjE, out tagE, out ws);
            int cch = tssA.Length;

            // To do our type-ahead trick, both ends of the seleciton must be in the same string property.
            // Also, we want the selection to extend to the end of the name.
            // Enhance JohnT: if we do a popup window, it may not matter whether the selection extends
            // to the end; just show items that match.
            if (tagE != tagA || hvoObjE != hvoObjA || cch != tssE.Length || Math.Max(ichA, ichE) != cch)
            {
                return(0);                // not going to attempt type-ahead behavior
            }
            int clev = sel.CLevels(false);

            if (clev < 2)
            {
                return(0);                // can't be our property.
            }
            int tagParent, cpropPrevious;
            IVwPropertyStore vps;

            sel.PropInfo(false, 1, out hvoParent, out tagParent, out ihvo, out cpropPrevious, out vps);
            if (tagParent != m_virtualTagObj)
            {
                return(0);                // not our virtual property!
            }
            return(hvoObjA);
        }
Example #10
0
        protected override bool OnRightMouseDown(Point pt, Rectangle rcSrcRoot, Rectangle rcDstRoot)
        {
            IVwSelection vwsel = m_rootb.MakeSelAt(pt.X, pt.Y, rcSrcRoot, rcDstRoot, false);

            if (vwsel != null)
            {
                int clevels = vwsel.CLevels(false);
                // Figure which paragraph we clicked. The last level (clevels-1) is our top-level
                // list: hvoObj would be khvoBook. (clevels-2) is next: hvoObj is a section.
                // (clevels-3) gives us a paragraph object.
                int hvoObj, tag, ihvo, cpropPrevious;
                IVwPropertyStore vps;
                vwsel.PropInfo(false, clevels - 3, out hvoObj, out tag, out ihvo, out cpropPrevious, out vps);

                Parse(hvoObj);
            }

            return(true);
        }
Example #11
0
        /// -----------------------------------------------------------------------------------
        /// <summary>
        /// Retrieves the flid and hvo corresponding to the current Scripture element (e.g., section
        /// heading, section contents, or title) selected.
        /// </summary>
        /// <param name="vwsel">The current selection</param>
        /// <param name="tag">The flid of the selected footnote</param>
        /// <param name="hvoSel">The hvo of the selected footnote</param>
        /// <returns>True, if a footnote is found at the current selection</returns>
        /// -----------------------------------------------------------------------------------
        protected bool GetSelectedFootnote(IVwSelection vwsel, out int tag, out int hvoSel)
        {
            hvoSel = 0;
            tag    = 0;
            int hvoPrevLevel = 0;
            int tagPrev      = 0;

            try
            {
                if (vwsel != null)
                {
                    // If we look more than 10 levels then something is wrong.
                    for (int ilev = 0; ilev < 10; ilev++)
                    {
                        int ihvo, cpropPrev;
                        IVwPropertyStore qvps;
                        hvoPrevLevel = hvoSel;
                        tagPrev      = tag;
                        vwsel.PropInfo(false, ilev, out hvoSel, out tag, out ihvo,
                                       out cpropPrev, out qvps);
                        switch (tag)
                        {
                        case ScrBookTags.kflidFootnotes:
                        {
                            hvoSel = hvoPrevLevel;
                            tag    = tagPrev;
                            return(true);
                        }

                        default:
                            break;
                        }
                    }
                }
            }
            catch
            {
                // REVIEW (TimS): Why are we catching all exceptions here?
            }
            return(false);
        }
			public override void SelectionChanged(IVwRootBox rootb, IVwSelection vwselNew)
			{
				CheckDisposed();

				if (vwselNew == null)
					return;

				base.SelectionChanged(rootb, vwselNew);

				ITsString tss;
				int ichAnchor;
				bool fAssocPrev;
				int hvoObj;
				int tag;
				int ws;
				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)
				{
					// Can't do much with a multi-object selection.
					CheckHeight();
					return;
				}

				// The next level out in the view should be the entry in the index.
				int hvoIndex, ihvoEntry, cpropPrevious, tagEntry;
				IVwPropertyStore vps;
				vwselNew.PropInfo(false, 1, out hvoIndex, out tagEntry, out ihvoEntry, out cpropPrevious, out vps);
				// And the next one is the relevant index.
				int hvoSense, tagIndex, ihvoIndex;
				vwselNew.PropInfo(false, 2, out hvoSense, out tagIndex, out ihvoIndex, out cpropPrevious, out vps);

				int count = m_silCache.get_VecSize(hvoIndex, kFlidEntries);
				int lastEntryHvo = m_silCache.get_VecItem(hvoIndex, kFlidEntries, count - 1);

				//string oldForm = m_silCache.get_UnicodeProp(m_hvoOldSelection, (int)ReversalIndexEntry.ReversalIndexEntryTags.kflidForm);
				string oldForm = null;
				int wsIndex = m_silCache.get_IntProp(hvoIndex, (int)ReversalIndex.ReversalIndexTags.kflidWritingSystem);
				ITsString tssEntry = m_silCache.get_MultiStringAlt(m_hvoOldSelection,
					(int)ReversalIndexEntry.ReversalIndexEntryTags.kflidReversalForm, wsIndex);
				if (tssEntry != null)
					oldForm = tssEntry.Text;
				if (m_hvoOldSelection != 0
					&& hvoObj != m_hvoOldSelection
					&& (oldForm == null || oldForm.Length  == 0))
				{
					// Remove the old string from the dummy cache, since its length is 0.
					for (int i = 0; i < count; ++i)
					{
						if (m_hvoOldSelection == m_silCache.get_VecItem(hvoIndex, kFlidEntries, i))
						{
							RemoveFromDummyCache(hvoIndex, i);
							break;
						}
					}
				}
				// If it's not the last index in the list, we can just go on editing it.
				if (hvoObj != lastEntryHvo)
				{
					m_hvoOldSelection = hvoObj;
					CheckHeight();
					return;
				}
				// Even if it's the last object, if it's empty we don't need to do anything.
				if (tss.Length == 0)
				{
					CheckHeight();
					return;
				}
				// Create a new object, and recreate a new empty object.
				count = m_silCache.get_VecSize(hvoIndex, kFlidEntries);
				// Assign a new dummy ID.
				m_dummyId--;
				// Insert it at the end of the list.
				m_vwCache.CacheReplace(hvoIndex, kFlidEntries, count, count, new int[] {m_dummyId}, 1);
				Cache.EnableUndo = false;	// Things have changed in a way we can't Undo.
				// Set its 'form' to be an empty string in the appropriate writing system.
				ITsTextProps props = tss.get_PropertiesAt(0);
				int nVar;
				ws = props.GetIntPropValues((int)FwTextPropType.ktptWs, out nVar);
				//m_vwCache.CacheUnicodeProp(m_dummyId, (int)ReversalIndexEntry.ReversalIndexEntryTags.kflidForm, String.Empty, 0);
				//m_vwCache.CacheIntProp(m_dummyId, (int)ReversalIndexEntry.ReversalIndexEntryTags.kflidWritingSystem, ws);
				ITsString tssEmpty = m_tsf.MakeString("", ws);
				m_vwCache.CacheStringAlt(m_dummyId, (int)ReversalIndexEntry.ReversalIndexEntryTags.kflidReversalForm,
					ws, tssEmpty);
				// Refresh
				m_silCache.PropChanged(null, (int)PropChangeType.kpctNotifyAll,
					hvoIndex, kFlidEntries, count, 1, 0);

				// Reset selection.
				SelLevInfo[] rgvsli = new SelLevInfo[2];
				rgvsli[0].cpropPrevious = 0;
				rgvsli[0].tag = kFlidEntries;
				rgvsli[0].ihvo = count - 1;
				rgvsli[1].cpropPrevious = 0;
				rgvsli[1].tag = kFlidIndices;
				rgvsli[1].ihvo = ihvoIndex;
				try
				{
					m_rootb.MakeTextSelection(0, rgvsli.Length, rgvsli, tag, 0, ichAnchor, ichEnd, ws, fAssocPrev, -1, null, true);
				}
				catch (Exception e)
				{
					Debug.WriteLine(e.ToString());
					throw;
				}

				m_hvoOldSelection = hvoObj;
				CheckHeight();
			}
Example #13
0
		/// <summary>
		/// Determine whether the current selection is at a place suitable for type-ahead. If not, answer 0.
		/// (In this case the values of hvoParent and ihvo should not be relied on.)
		/// If so, indicate the object whose property may be set by type-ahead (hvoParent), the object
		/// in the relevant property that is selected (return result), and its index within the property
		/// (0 if atomic).
		/// </summary>
		/// <param name="rootb"></param>
		/// <param name="sel"></param>
		/// <param name="hvoParent"></param>
		/// <param name="ihvo"></param>
		/// <returns></returns>
		private int SelectedObject(IVwRootBox rootb, IVwSelection sel, out int hvoParent, out int ihvo)
		{
			hvoParent = 0;
			ihvo = 0;
			if (rootb == null) // If we don't have a root box, can't do anything interesting.
				return 0;
			if (sel == null) // nothing interesting to do without a selection, either.
				return 0;
			ITsString tssA, tssE;
			int ichA, ichE, hvoObjA, hvoObjE, tagA, tagE, ws;
			bool fAssocPrev;
			// Enhance JohnT: what we're really trying to do here is confirm that the selection is
			// all in one string property. We could readily have a method in the selection interface to tell us that.
			sel.TextSelInfo(false, out tssA, out ichA, out fAssocPrev, out hvoObjA, out tagA, out ws);
			if (tagA != m_taTagName && tagA != m_snTagName)
				return 0; // selection not anchored in any sort of type-ahead name property.
			sel.TextSelInfo(true, out tssE, out ichE, out fAssocPrev, out hvoObjE, out tagE, out ws);
			int cch = tssA.Length;
			// To do our type-ahead trick, both ends of the seleciton must be in the same string property.
			// Also, we want the selection to extend to the end of the name.
			// Enhance JohnT: if we do a popup window, it may not matter whether the selection extends
			// to the end; just show items that match.
			if (tagE != tagA || hvoObjE != hvoObjA || cch != tssE.Length || Math.Max(ichA, ichE) != cch)
				return 0; // not going to attempt type-ahead behavior
			int clev = sel.CLevels(false);
			if (clev < 2)
				return 0; // can't be our property.
			int tagParent, cpropPrevious;
			IVwPropertyStore vps;
			sel.PropInfo(false, 1, out hvoParent, out tagParent, out ihvo, out cpropPrevious, out vps);
			if (tagParent != m_virtualTagObj)
				return 0; // not our virtual property!
			return hvoObjA;
		}
Example #14
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>
		/// -----------------------------------------------------------------------------------
		public override void SelectionChanged(IVwRootBox prootb, IVwSelection vwselNew)
		{
			CheckDisposed();

			base.SelectionChanged(prootb, vwselNew);
			if (vwselNew == null)
				return;
			int clev = vwselNew.CLevels(false);		// anchor
			int hvoRoot, tag, ihvo, cpropPrevious;
			IVwPropertyStore vps;
			vwselNew.PropInfo(false, clev - 1, out hvoRoot, out tag, out ihvo,
				out cpropPrevious, out vps);
			Debug.Assert(hvoRoot == m_hvoRoot);
			int hvoObjNewSel = m_fdoCache.MainCacheAccessor.get_VecItem(hvoRoot, tag, ihvo);
			if (hvoObjNewSel != 0)
			{
				// Notify any delegates that the selection of the main object in the vector
				// may have changed.
				if (SelectionChangedEvent != null)
					SelectionChangedEvent(this, new FwObjectSelectionEventArgs(hvoObjNewSel, ihvo));
			}
		}
Example #15
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)
		{
			CheckDisposed();

			base.HandleSelectionChange(prootb, vwselNew);
			if (vwselNew == null)
				return;
			int clev = vwselNew.CLevels(false);		// anchor
			int clevEnd = vwselNew.CLevels(true);
			if (clev < 2 || clevEnd < 2)
				return; // paranoia
			int hvoRoot, tag, ihvo, ihvoEnd, cpropPrevious;
			IVwPropertyStore vps;
			vwselNew.PropInfo(true, clevEnd - 1, out hvoRoot, out tag, out ihvoEnd,
				out cpropPrevious, out vps);
			vwselNew.PropInfo(false, clev - 1, out hvoRoot, out tag, out ihvo,
				out cpropPrevious, out vps);
			// Give up if the selection doesn't indicate any top-level object; I think this can happen with pictures.
			// selection larger than a top-level object, maybe select all, side effects are confusing.
			if (ihvo != ihvoEnd || ihvo < 0)
				return;
			if (hvoRoot == 0)
				return;
			Debug.Assert(hvoRoot == m_hvoRoot);
			int hvoObjNewSel = m_sdaSource.get_VecItem(hvoRoot, tag, ihvo);
			if (hvoObjNewSel != 0)
			{
				// Notify any delegates that the selection of the main object in the vector
				// may have changed.
				if (SelectionChangedEvent != null)
					SelectionChangedEvent(this, new FwObjectSelectionEventArgs(hvoObjNewSel, ihvo));
			}
		}
Example #16
0
 protected override bool DoContextMenu(IVwSelection sel, Point pt, Rectangle rcSrcRoot, Rectangle rcDstRoot)
 {
     int hvo, tag, ihvo, cpropPrevious;
     IVwPropertyStore propStore;
     sel.PropInfo(false, 0, out hvo, out tag, out ihvo, out cpropPrevious, out propStore);
     string nodePath = null;
     if (propStore != null)
     {
         nodePath = propStore.get_StringProperty((int) FwTextPropType.ktptBulNumTxtBef);
     }
     if (string.IsNullOrEmpty(nodePath))
     {
         if (sel.SelType == VwSelType.kstPicture)
             return true;
         // may be a literal string, where we can get it from the string itself.
         ITsString tss;
         int ich, ws;
         bool fAssocPrev;
         sel.TextSelInfo(false, out tss, out ich, out fAssocPrev, out hvo, out tag, out ws);
         nodePath = tss.get_Properties(0).GetStrPropValue((int) FwTextPropType.ktptBulNumTxtBef);
     }
     if (m_configObjectName == null)
         m_configObjectName = XmlUtils.GetLocalizedAttributeValue(
             Mediator.StringTbl, m_xnSpec, "configureObjectName", null);
     string label;
     if (string.IsNullOrEmpty(nodePath))
         label = String.Format(xWorksStrings.ksConfigure, m_configObjectName);
     else
         label = String.Format(xWorksStrings.ksConfigureIn, nodePath.Split(':')[3], m_configObjectName);
     m_contextMenu = new ContextMenuStrip();
     var item = new ToolStripMenuItem(label);
     m_contextMenu.Items.Add(item);
     item.Click += RunConfigureDialogAt;
     item.Tag = nodePath;
     m_contextMenu.Show(this, pt);
     m_contextMenu.Closed += m_contextMenu_Closed;
     return true;
 }
Example #17
0
		/// -----------------------------------------------------------------------------------
		/// <summary>
		/// Retrieves the flid and hvo corresponding to the current Scripture element (e.g., section
		/// heading, section contents, or title) selected.
		/// </summary>
		/// <param name="vwsel">The current selection</param>
		/// <param name="tag">The flid of the selected footnote</param>
		/// <param name="hvoSel">The hvo of the selected footnote</param>
		/// <returns>True, if a footnote is found at the current selection</returns>
		/// -----------------------------------------------------------------------------------
		protected bool GetSelectedFootnote(IVwSelection vwsel, out int tag, out int hvoSel)
		{
			hvoSel = 0;
			tag = 0;
			int hvoPrevLevel = 0;
			int tagPrev = 0;
			try
			{
				if (vwsel != null)
				{
					// If we look more than 10 levels then something is wrong.
					for (int ilev = 0; ilev < 10; ilev++)
					{
						int ihvo, cpropPrev;
						IVwPropertyStore qvps;
						hvoPrevLevel = hvoSel;
						tagPrev = tag;
						vwsel.PropInfo(false, ilev, out hvoSel, out tag, out ihvo,
							out cpropPrev, out qvps);
						switch (tag)
						{
							case (int)ScrBook.ScrBookTags.kflidFootnotes:
							{
								hvoSel = hvoPrevLevel;
								tag = tagPrev;
								return true;
							}
							default:
								break;
						}
					}
				}
			}
			catch
			{
			}
			return false;
		}
Example #18
0
		/// <summary>
		/// Given a selection in the view, return the row index. Rarely may return -1 if unable to
		/// identify a row.
		/// </summary>
		/// <param name="sel"></param>
		/// <param name="fEndPoint">true to get index based on end of selection, false based on anchor.
		/// deafault is true, so in a long drag we get the mouse-up row.</param>
		/// <returns></returns>
		internal int GetRowIndexFromSelection(IVwSelection sel, bool fEndPoint)
		{
			if (sel == null)
				return -1;
			try
			{
				int clev = sel.CLevels(fEndPoint);
				int hvoRoot, tag, ihvo, cpropPrevious;
				IVwPropertyStore vps;
				sel.PropInfo(fEndPoint, clev - 1, out hvoRoot, out tag, out ihvo, out cpropPrevious, out vps);
				if (tag != m_fakeFlid) // not sure how this could happen, but the precaution was in an earlier version.
					return -1;
				return ihvo;
			}
			catch (System.Runtime.InteropServices.COMException)
			{
				// This shouldn't happen, but don't let it be catastrophic if it does.
			}
			return -1;
		}
Example #19
0
        /// <summary>
        /// This is the real guts of type-ahead. It is called by the client whenever a key is pressed.
        /// It returns true if it handled the key press, which it does if the current selection
        /// is in a type-ahead name property.
        /// </summary>
        /// <param name="ehelp"></param>
        /// <param name="e"></param>
        /// <param name="modifiers"></param>
        /// <param name="vwGraphics"></param>
        /// <returns></returns>
        public virtual bool OnKeyPress(EditingHelper ehelp, KeyPressEventArgs e, Keys modifiers, IVwGraphics vwGraphics)
        {
            IVwRootBox rootb = ehelp.Callbacks.EditedRootBox;

            if (rootb == null)             // If we don't have a root box, can't do anything interesting.
            {
                return(false);
            }
            IVwSelection sel = rootb.Selection;

            if (sel == null)             // nothing interesting to do without a selection, either.
            {
                return(false);
            }
            ITsString tssA, tssE;
            int       ichA, ichE, hvoObjA, hvoObjE, tagA, tagE, ws;
            bool      fAssocPrev;

            // Enhance JohnT: what we're really trying to do here is confirm that the selection is
            // all in one string property. We could readily have a method in the selection interface to tell us that.
            sel.TextSelInfo(false, out tssA, out ichA, out fAssocPrev, out hvoObjA, out tagA, out ws);
            if (tagA != m_taTagName)
            {
                return(false);                // selection not anchored in a type-ahead name property.
            }
            sel.TextSelInfo(true, out tssE, out ichE, out fAssocPrev, out hvoObjE, out tagE, out ws);
            int cch = tssA.Length;

            // To do our type-ahead trick, both ends of the seleciton must be in the same string property.
            // Also, we want the selection to extend to the end of the name.
            // Enhance JohnT: poupu list may not depend on selection extending to end.
            if (tagE != m_taTagName || hvoObjE != hvoObjA || cch != tssE.Length || Math.Max(ichA, ichE) != cch)
            {
                return(false);                // not going to attempt type-ahead behavior
            }
            // if the key pressed is a backspace or del, prevent smart completion,
            // otherwise we are likely to put back what the user deleted.
            // Review JohnT: do arrow keys come through here? What do we do if so?
            int charT = Convert.ToInt32(e.KeyChar);

            if (charT == (int)Keys.Back || charT == (int)Keys.Delete)
            {
                return(false);                // normal key handling will just delete selection. // Review: should backspace delete one more?
            }
            // OK, we're in a type-ahead situation. First step is to let normal editing take place.
            ehelp.OnKeyPress(e, modifiers);
            e.Handled = true;
            // Now see what we have. Note that our old selection is no longer valid.
            sel = rootb.Selection;
            if (sel == null)
            {
                return(true);                // can't be smart, but we already did the keypress.
            }
            int cvsli = sel.CLevels(false);

            // CLevels includes the string prop itself, but AllTextSelInfo does not need it.
            cvsli--;
            // Get selection information to determine where the user is typing.
            int          ihvoObj;
            int          tagTextProp;
            int          cpropPrevious, ichAnchor, ichEnd, ihvoEnd;
            ITsTextProps ttp;

            SelLevInfo[] rgvsli = SelLevInfo.AllTextSelInfo(sel, cvsli,
                                                            out ihvoObj, out tagTextProp, out cpropPrevious, out ichAnchor, out ichEnd,
                                                            out ws, out fAssocPrev, out ihvoEnd, out ttp);
            if (tagTextProp != m_taTagName || ichAnchor != ichEnd || ihvoEnd != -1 || cvsli < 1)
            {
                return(true);                // something bizarre happened, but keypress is done.
            }
            int hvoLeaf = rgvsli[0].hvo;

            // Get the parent object we will modify.
            // (This would usually work, but not if the parent object is the root of the whole display,
            // as in a simple atomic ref type ahead slice.
            //int hvoParent = rgvsli[1].hvo; // object whose reference property we are setting.)
            int tagParent, cpropPreviousDummy, ihvo;
            IVwPropertyStore vps;
            int hvoParent;

            sel.PropInfo(false, 1, out hvoParent, out tagParent, out ihvo, out cpropPreviousDummy, out vps);

            if (hvoParent != m_hvoParent)
            {
                return(true);                // another bizarre unexpected event.
            }
            // This is what the name looks like after the keypress.
            ITsString tssTyped = m_sda.get_StringProp(hvoLeaf, m_taTagName);
            // Get the substitute. This is where the actual type-ahead behavior happens. Sets hvoNewRef to 0 if no match.
            ICmObject  objNewRef;
            ITsString  tssLookup = Lookup(tssTyped, out objNewRef);
            int        hvoNewRef = (objNewRef != null) ? objNewRef.Hvo : 0;
            IVwCacheDa cda       = m_sda as IVwCacheDa;

            if (hvoNewRef == 0 && tssTyped.Length > 0)
            {
                // No match...underline string in red squiggle.
                ITsStrBldr bldr = tssLookup.GetBldr();
                bldr.SetIntPropValues(0, tssLookup.Length, (int)FwTextPropType.ktptUnderline,
                                      (int)FwTextPropVar.ktpvEnum, (int)FwUnderlineType.kuntSquiggle);
                bldr.SetIntPropValues(0, tssLookup.Length, (int)FwTextPropType.ktptUnderColor,
                                      (int)FwTextPropVar.ktpvDefault, (int)ColorUtil.ConvertColorToBGR(Color.Red));
                tssLookup = bldr.GetString();
            }

            // Don't rely on sel from here on.
            if (hvoNewRef != hvoLeaf)
            {
                m_hvoTa = hvoNewRef;                 // Before we replace in the prop, so it gets displayed using special ta prop.
                switch (m_type)
                {
                case CellarPropertyType.ReferenceAtomic:
                    if (m_hvoParent != 0)                     // I think it always is, except when loss of focus during debugging causes problems.
                    {
                        // If nothing matched, set the real property to null and the fake one to kbaseFakeObj.
                        // Otherwise set both to the indicated object.
                        m_sda.SetObjProp(m_hvoParent, m_tag, hvoNewRef);                         // Review: do we want to set the real thing yet?
                        m_sda.PropChanged(null, (int)PropChangeType.kpctNotifyAll, m_hvoParent, m_tag, 0, 1, 1);
                        if (hvoNewRef == 0)
                        {
                            hvoNewRef = m_hvoTa = kBaseFakeObj;                             // use in fake so we can display something.
                        }
                        cda.CacheObjProp(m_hvoParent, m_virtualTagObj, hvoNewRef);          // Change the fake property
                        m_sda.PropChanged(null, (int)PropChangeType.kpctNotifyAll, m_hvoParent, m_virtualTagObj, 0, 1, 1);
                    }
                    break;

                case CellarPropertyType.ReferenceSequence:
                case CellarPropertyType.ReferenceCollection:
                    // Several cases, depending on whether we got a match and whether hvoLeaf is the dummy object
                    // 1. match on dummy: insert appropriate real object, change dummy name to empty.
                    // 2. match on non-dummy: replace old object with new
                    // 3: non-match: do nothing. (Even if not looking at the fake object, we'll go on using the
                    // actual object as a base for the fake name, since it's displayed only for the active position.)
                    if (hvoNewRef == 0)
                    {
                        break;                         // case 3
                    }
                    if (hvoLeaf == kBaseFakeObj)
                    {                     // case 1
                        // The fake object goes back to being an empty name at the end of the list.
                        ITsStrBldr bldr = tssLookup.GetBldr();
                        bldr.ReplaceTsString(0, bldr.Length, null);                         // makes an empty string in correct ws.
                        cda.CacheStringProp(kBaseFakeObj, m_taTagName, bldr.GetString());
                        // Insert the new object before the fake one in fake prop and at end of real seq.
                        // Include the fake object in the replace to get it redisplayed also.
                        cda.CacheReplace(m_hvoParent, m_virtualTagObj, m_ihvoTa, m_ihvoTa + 1, new int[] { hvoNewRef, kBaseFakeObj }, 2);
                        m_sda.PropChanged(null, (int)PropChangeType.kpctNotifyAll, m_hvoParent, m_virtualTagObj, m_ihvoTa, 2, 1);
                        m_sda.Replace(m_hvoParent, m_tag, m_ihvoTa, m_ihvoTa, new int[] { hvoNewRef }, 1);
                        m_sda.PropChanged(null, (int)PropChangeType.kpctNotifyAll, m_hvoParent, m_tag, m_ihvoTa, 1, 0);
                    }
                    else
                    {                     // case 2
                        // Replace the object being edited with the indicated one in both props.
                        cda.CacheReplace(m_hvoParent, m_virtualTagObj, m_ihvoTa, m_ihvoTa + 1, new int[] { hvoNewRef }, 1);
                        m_sda.PropChanged(null, (int)PropChangeType.kpctNotifyAll, m_hvoParent, m_virtualTagObj, m_ihvoTa, 1, 1);
                        m_sda.Replace(m_hvoParent, m_tag, m_ihvoTa, m_ihvoTa + 1, new int[] { hvoNewRef }, 1);
                        m_sda.PropChanged(null, (int)PropChangeType.kpctNotifyAll, m_hvoParent, m_tag, m_ihvoTa, 1, 1);
                    }
                    break;

                default:
                    throw new Exception("unsupported property type for type-ahead chooser");
                }
            }
            cda.CacheStringProp(hvoNewRef, m_taTagName, tssLookup);
            m_sda.PropChanged(null, (int)PropChangeType.kpctNotifyAll, hvoNewRef, m_taTagName, 0, tssLookup.Length, tssTyped.Length);
            // Make a new selection, typically the range that is the bit added to the typed string.
            // no change is needed to rgvsli because it's the same object index in the same property of the same parent.
            sel = rootb.MakeTextSelection(ihvoObj, cvsli, rgvsli, m_taTagName, cpropPrevious, ichAnchor,
                                          tssLookup.Length, ws, true, -1, null, true);
            return(true);
        }
Example #20
0
		/// <summary>
		/// Given a selection (typically from a click), determine the object that should be the target for jumping to,
		/// and return the property that was clicked (which in the case of a right-click may generate a spelling menu instead).
		/// </summary>
		/// <param name="sel"></param>
		/// <param name="hvoReal"></param>
		/// <returns></returns>
		private int GetInfoForJumpToTool(IVwSelection sel, out int hvoReal)
		{
			int ws;
			int tagRightClickTextProp;
			bool fAssocPrev;
			ITsString tss;
			int ichAnchorDum;
			int hvoRightClickObject = 0;
			sel.TextSelInfo(false, out tss, out ichAnchorDum, out fAssocPrev,
				out hvoRightClickObject, out tagRightClickTextProp, out ws);
			switch (tagRightClickTextProp)
			{
				case ktagSbMorphPrefix:
				case ktagSbMorphPostfix:
					m_hvoRightClickMorph = hvoRightClickObject;
					// Pretend we clicked on the morph form.  (See LT-7590.)
					hvoRightClickObject = Caches.DataAccess.get_ObjectProp(hvoRightClickObject, ktagSbMorphForm);
					break;
				case ktagSbNamedObjName:
					if (sel.CLevels(false) < 2)
						break;
					int hvoOuterObj, tagOuter, ihvoOuter, cpropPreviousOuter;
					IVwPropertyStore vpsDummy;
					sel.PropInfo(false, 1, out hvoOuterObj, out tagOuter, out ihvoOuter, out cpropPreviousOuter, out vpsDummy);
					if (tagOuter == ktagSbMorphGloss || tagOuter == ktagSbMorphPos || tagOuter == ktagSbMorphForm
						|| tagOuter == ktagSbMorphEntry)
					{
						m_hvoRightClickMorph = hvoOuterObj;
					}
					break;
				default:
					m_hvoRightClickMorph = 0;
					break;
			}

			hvoReal = m_caches.RealHvo(hvoRightClickObject);
			return tagRightClickTextProp;
		}
Example #21
0
		private bool DeleteFreeform(IVwSelection sel)
		{
			int hvoAnnotation;
			if (!CanDeleteFF(sel, out hvoAnnotation))
				return false;
			int hvoSeg, tagFF, ihvoFF, cpropPrevious;
			IVwPropertyStore vps;
			// NOTE: Do not use ihvoFF for updating the cache directly, because the display vector indices
			// does not necessarily correspond to the cache vector indices.
			sel.PropInfo(false, 1, out hvoSeg, out tagFF, out ihvoFF, out cpropPrevious, out vps);
			CmBaseAnnotation seg = new CmBaseAnnotation(Cache, hvoSeg);
			CmIndirectAnnotation ft = new CmIndirectAnnotation(Cache, hvoAnnotation);
			bool wasFt = ft.AnnotationTypeRAHvo == Cache.GetIdFromGuid(LangProject.kguidAnnFreeTranslation);
			StTxtPara para = seg.BeginObjectRA as StTxtPara;
			m_fdoCache.DeleteObject(hvoAnnotation);
			m_fdoCache.PropChanged(null, PropChangeType.kpctNotifyAll, hvoSeg, tagFF, ihvoFF, 0, 1);
			if (wasFt && para != null)
				FreeTransEditMonitor.UpdateMainTransFromSegmented(para, Cache.LangProject.CurAnalysisWssRS.HvoArray);
			return true; // handled
		}