Example #1
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Process right mouse button down
		/// </summary>
		/// <param name="pt">The point where the mouse was pressed.</param>
		/// <param name="rootb">The root box.</param>
		/// <param name="rcSrcRoot">The rc SRC root.</param>
		/// <param name="rcDstRoot">The rc DST root.</param>
		/// <returns>true if handled, false otherwise</returns>
		/// ------------------------------------------------------------------------------------
		protected virtual bool OnRightMouseDown(Point pt, IVwRootBox rootb, Rectangle rcSrcRoot,
			Rectangle rcDstRoot)
		{
			InitScreenGraphics();
			try
			{
				IVwSelection sel = (IVwSelection)rootb.Selection;
				if (sel != null && sel.IsRange)
				{
					// TODO KenZ: We need a better way to determine if the cursor is in a selection
					// when the selection spans partial lines.

					// We don't want to destroy a range selection if we are within the range, since it
					// is quite likely the user will want to do a right+click cut or paste.
					Rect rcPrimary;
					Rect rcSecondary;
					bool fSplit;
					bool fEndBeforeAnchor;

					Debug.Assert(m_screenGraphics.VwGraphics != null);

					sel.Location(m_screenGraphics.VwGraphics, rcSrcRoot, rcDstRoot,
						out rcPrimary, out rcSecondary, out fSplit,
						out fEndBeforeAnchor);

					if (pt.X >= rcPrimary.left && pt.X < rcPrimary.right
						&& pt.Y >= rcPrimary.top && pt.Y < rcPrimary.bottom)
					{
						return true;
					}
				}

				try
				{
					// Make an invisible selection to see if we are in editable text.
					sel = rootb.MakeSelAt(pt.X, pt.Y, rcSrcRoot, rcDstRoot, false);
					if (sel != null && SelectionHelper.IsEditable(sel))
					{
						// Make a simple text selection without executing a mouse click. This is
						// needed in order to not launch a hot link when we right+click.
						rootb.MakeSelAt(pt.X, pt.Y, rcSrcRoot, rcDstRoot, true);
						return true;
					}
				}
				catch
				{
				}
			}
			finally
			{
				UninitScreenGraphics();
			}
			return false;
		}