Esempio n. 1
0
		//private double GetElementHorizontalLocation(ElementIndex index, BoxViewModel owner)
		//{
		//	Contract.Requires(index.Value < owner.Elements.Count);
		//
		//	GlyphRunViewModel placeholder = (GlyphRunViewModel)owner.Elements[index];
		//	//Contract.Requires(placeholder.IsPlaceholder);
		//
		//	return placeholder[0].AdvanceWidth * placeholder.FontSize;
		//}
		private double GetPositionHorizontalLocation(int position)
		{
			ExplicitIndex index = new ExplicitIndex(position, viewModel.ShallowEnd.Elements, IndexRoundingBehavior.ToText);

			var boxViewModelTEST = Box.viewModel;
			MathGlyphRun container = (MathGlyphRun)Box.Children[index.ElementIndex.Value];
			return Box.ColumnDefinitions[index.ElementIndex.Value].Offset + container.GetGlyphLocation(index.IndexInElement.Value).X;


			//double cumulativeWidthOfElementsBefore = this.ShallowEnd.Elements.Take(index.ElementIndex.Value - 1).Select(element => element.Width GetElementHorizontalLocation(index.ElementIndex, owner);
			//if (index.IndexInElement != 0)
			//{
			//	//this[index.ElementIndex] is a math glyph run, since we round to extra above, and if that were a box composition, then IndexInElement would be 0. 
			//	//Assumption: A box composition has exactly 2 caret positions
			//	//Whether it is round to extra unless empty of extra only makes the difference that empty elements aren't included with "ExtraUnlessEmpty", which is slightly faster since they have negligible width anyway (so why count that...)
			//	var glyphRun = (GlyphRunViewModel)owner.Elements[index.ElementIndex];
			//	Point glyphLocation = glyphRun.GetGlyphLocation(index.IndexInElement);
			//	cumulativeWidthOfElementsBefore += glyphLocation.X;
			//
			//	//the glyphlocation.Y here could be used for not selection extraneous white space above or below text
			//	//intermediate elements (between selection.leftposition and selection.rightPosition) should also be taken into account in that case.
			//	//this may not even be desirable, ultimately
			//}
			//return cumulativeWidthOfElementsBefore;
		}
Esempio n. 2
0
		internal void Set(BoxViewModel box, ExplicitIndex position)
		{
			if (box != null) Contract.Requires(box.Modifiable, "Boxes that may not be modified may not contain the caret");
			if (box == this.Box && position == this.position)
				return;

			//remove caret from previous box if necessary:
			if (this.Box != null)
			{
				this.Box.PropertyChanged -= OnBoxIsPlaceholderChanged;
				//this.Box.Caret = null;
			}

			this.Box = box;


			if (box != null)
			{
				position = ToPosition(position); //makes last explicit and rounds to text. Otherwise the result equality comparison later on might not be identical to the equality test performed when triggering the caret changed event

				//set the caret at the correct position in the box and resets the animation
				//box.Caret = this;
				box.PropertyChanged += OnBoxIsPlaceholderChanged;

				if (this.position == position)
					CaretChanged?.Invoke(this, new EventArgs());
				else
					this.position = position; //triggers caret changed event
											  //OnBoxIsPlaceholderChanged(box, new PropertyChangedEventArgs(nameof(BoxViewModel.IsPlaceholder)));
				IsVisible = !this.Box.IsPlaceholder;
			}
			else
			{
				throw new NotImplementedException("what to do with the position argument?");
				IsVisible = false;
			}
		}
Esempio n. 3
0
		/// <summary> Formats the specified index to the form acceptable as _position. That is, rounded to text and the special value of last index is made explicit. </summary>
		private ExplicitIndex ToPosition(ExplicitIndex index)
		{
			return index.MakeLastExplicit(this.Box.Elements).Round(IndexRoundingBehavior.ToText, this.Box.Elements);
		}
Esempio n. 4
0
		public bool Equals(ExplicitIndex explictIndex)
		{
			return explictIndex.ElementIndex == this.ElementIndex && explictIndex.IndexInElement == this.IndexInElement;
		}
Esempio n. 5
0
			/// <summary> Focuses on the box parent in the specified direction. </summary>
			/// <param name="caretState"> The box parent of the box composition this glyphrun is in, will be focused on. </param>
			/// <param name="traversalDirection"> The direction in which the caret moves out of the box (true for right, false for left). </param>
			private static void boxOut(InputCommandParameter caretState, bool traversalDirection)
			{
				Contract.Requires(!caretState.CaretBox.IsRoot);
				Contract.Requires(caretState.CaretBox.BoxParent != null);

				BoxCompositionViewModel parentBoxComposition = caretState.CaretBox.BoxParent;
				BoxViewModel parentBox = parentBoxComposition.Box;

				ExplicitIndex newCaretIndex = new ExplicitIndex(parentBoxComposition, traversalDirection ? InternalIndex.Last : InternalIndex.First);
				parentBox.Focus(newCaretIndex);
			}