Пример #1
0
		public BoxComposition(BoxCompositionViewModel viewModel)
		{
			this.DataContext = viewModel;
			//this.Background = Brushes.Aqua;
			Focusable = false;

			locations = new List<Point>();
			Width = double.NaN;

			boxes = new FacadeMapCollection<UIElement, Box>(this.Children, uielement => (Box)uielement);

			viewModel.Boxes.CollectionChanged += boxesCollectionChanged;
			Contract.Assert(viewModel.Boxes.Count != 0);

			//this.arrangement is initialized in InitializeComponents
		}
		/// <summary> Gets the only box in this composition construction that should receive initial focus. Returns null if no such box exists. </summary>
		/// <param name="result"> The box composition that was created using this composition construction specifier. </param>
		internal BoxViewModel GetCentralBox(BoxCompositionViewModel result, out int initialCaretPosition)
		{
			Contract.Requires(result != null);
			Contract.Requires(result.Count == this.Contents.Count);

			//this method works recursively: If the box that should receive initial focus is a direct child of the current box composition, the recursion terminates
			//otherwise the recursion is continued on the box composition containing the box (however deeply nested) that should receive initial focus

			int indexOfCentralChild = this.Contents.IndexOf(bcs => bcs.HasInitialFocus);
			if (indexOfCentralChild != -1)
			{
				initialCaretPosition = this.Contents[indexOfCentralChild].InitialCaretPosition;
				Contract.Assert(initialCaretPosition >= 0);
				return result[(InternalIndex)indexOfCentralChild];
			}


			//recursive part:
			for (int boxIndex = 0; boxIndex < this.Contents.Count; boxIndex++)
			{
				var boxSpecs = this.Contents[boxIndex];
				BoxViewModel box = result[(InternalIndex)boxIndex];

				ElementIndex compositionIndex = (ElementIndex)0;
				foreach (var boxContent in boxSpecs.Contents)
				{
					var content = boxContent as CompositionConstructionSpecifier;
					if (content != null)
					{
						var potential = content.GetCentralBox((BoxCompositionViewModel)box[compositionIndex], out initialCaretPosition);
						if (potential != null)
							return potential;
					}
					compositionIndex++;
				}
			}

			//no box that should receive the caret was found
			initialCaretPosition = -1;
			return null;
		}
Пример #3
0
		public IEnumerable<NameInstance> GetNameInstancesAlongRouteFromRootTo(BoxCompositionViewModel boxComposition)
		{
			var route = GetRoute(boxComposition);
			return GetNameInstancesAlongRoute(route);
		}
Пример #4
0
		private Stack<int> GetRoute(BoxCompositionViewModel boxComposition)
		{
			var result = GetRoute(boxComposition.Boxes[0]);
			int dummy = result.Pop();
			Contract.Assert(dummy == 0, "You probably meant to call the other GetRoute overload");
			return result;
		}
Пример #5
0
		private CompositeNameInstance ToNameInstance(BoxCompositionViewModel newComposition, LinearPosition position)
		{
			//Contract.Assert(newComposition.Boxes.Count == newComposition.Arranger.Positions.Count);
			Contract.AssertForAll(newComposition.Arranger.Positions, NotNull);

			return new CompositeNameInstance(Enumerable.Zip(newComposition.Boxes, newComposition.Arranger.Positions, GetMutation).ToList(), position);
		}
Пример #6
0
		private NameInstance GetMutation(BoxCompositionViewModel newComposition, int palpableIndex)
		{
			//register the box composition for subsequent changes to it
			newComposition.Boxes.CollectionChanged += onBoxCompositionCollectionChanged;

			//create the box composition in the name instance model
			var result = ToNameInstance(newComposition, new LinearPosition(palpableIndex));

			//associate the box composition with the name instance model
			newComposition.Model = result;

			return result;
		}
Пример #7
0
		/// <summary> Handles creating a new box composition. </summary>
		private void AddNewBoxCompositionMutation(BoxCompositionViewModel newComposition, int palpableIndex)
		{
			Func<IEnumerable<NameInstance>> mutation = () => GetMutation(newComposition, palpableIndex).ToSingleton();
			GetCollectionToAddTo(GetRoute(newComposition.Box)).Add(palpableIndex, mutation, true);
		}
Пример #8
0
			/// <summary> Gets the boxes in the specified box composition in the specified direction starting from a specific box. </summary>
			/// <param name="boxComposition"> The box composition whose boxes are to be yielded. </param>
			/// <param name="preferredBoxIndex"> The index of the first preferred box. The box _at_ this index is yielded. </param>
			/// <param name="boxesTraversalDirection"> The direction in which to get the boxes (true for right, false for left). </param>
			private static IEnumerable<BoxViewModel> GetPreferredBoxes(BoxCompositionViewModel boxComposition, int preferredBoxIndex, bool boxesTraversalDirection)
			{
				for (int i = preferredBoxIndex; 0 <= i && i < boxComposition.Boxes.Count; i += boxesTraversalDirection ? 1 : -1)
					yield return boxComposition.Boxes[i];
			}