public void DeepCopy(IDeepCopyable source, ICopyManager copyManager) { ListViewItemGenerator icg = (ListViewItemGenerator) source; _itemTemplate = copyManager.GetCopy(icg._itemTemplate); _itemContainerStyle = copyManager.GetCopy(icg._itemContainerStyle); _parent = copyManager.GetCopy(icg._parent); if (icg._items == null) _items = null; else { _items = new List<object>(icg._items.Count); foreach (object item in icg._items) _items.Add(copyManager.GetCopy(item)); } _populatedStartIndex = icg._populatedStartIndex; _populatedEndIndex = icg._populatedEndIndex; if (icg._materializedItems == null) _materializedItems = null; else { _materializedItems = new List<FrameworkElement>(icg._materializedItems.Count); foreach (FrameworkElement item in icg._materializedItems) _materializedItems.Add(copyManager.GetCopy(item)); } }
public void Initialize(FrameworkElement parent, IEnumerable<object> itemsSource, Style itemContainerStyle, DataTemplate itemTemplate) { _parent = parent; if (_materializedItems != null) DisposeItems(); _items = new List<object>(itemsSource); _materializedItems = new List<FrameworkElement>(_items.Count); for (int i = 0; i < _items.Count; i++) _materializedItems.Add(null); MPF.TryCleanupAndDispose(_itemContainerStyle); MPF.TryCleanupAndDispose(_itemTemplate); // No need to set the LogicalParent at styles or data templates because they don't bind bindings _itemContainerStyle = MpfCopyManager.DeepCopyCutLVPs(itemContainerStyle); _itemTemplate = MpfCopyManager.DeepCopyCutLVPs(itemTemplate); }
protected float GetLeft(FrameworkElement child, bool registerPositionProperty) { AbstractProperty leftAttachedProperty = GetLeftAttachedProperty_NoCreate(child); AbstractProperty rightAttachedProperty = GetRightAttachedProperty_NoCreate(child); if (leftAttachedProperty != null) RegisterChildCanvasPosition(leftAttachedProperty); if (rightAttachedProperty != null) RegisterChildCanvasPosition(rightAttachedProperty); float result; if (leftAttachedProperty != null) result = (float) (double) leftAttachedProperty.GetValue(); else if (rightAttachedProperty != null) result = (float) (double) rightAttachedProperty.GetValue() - child.DesiredSize.Width; else result = 0; return result; }
public void SetKeyboardLayoutControl(VirtualKeyboardControl parent, FrameworkElement keyboardLayoutControl) { FrameworkElement oldKeyboardControl = _keyboardLayoutControl; _keyboardLayoutControl = null; if (oldKeyboardControl != null) oldKeyboardControl.CleanupAndDispose(); if (keyboardLayoutControl == null) return; keyboardLayoutControl.Context = parent; keyboardLayoutControl.LogicalParent = this; keyboardLayoutControl.VisualParent = this; keyboardLayoutControl.SetScreen(Screen); keyboardLayoutControl.SetElementState(_elementState); if (IsAllocated) keyboardLayoutControl.Allocate(); _keyboardLayoutControl = keyboardLayoutControl; InvalidateLayout(true, true); }
public override void SetupBrush(FrameworkElement parent, ref PositionColoredTextured[] verts, float zOrder, bool adaptVertsToBrushTexture) { base.SetupBrush(parent, ref verts, zOrder, adaptVertsToBrushTexture); if (ServiceRegistration.Get<IPlayerManager>(false) == null) ServiceRegistration.Get<ILogger>().Debug("VideoBrush.SetupBrush: Player manager not found"); }
/// <summary> /// Arranges the child vertical in a given area. If the area is bigger than the child's desired /// size, the child will be arranged according to the given <paramref name="alignment"/>. /// </summary> /// <param name="child">The child to arrange. The child will not be changed by this method.</param> /// <param name="alignment">Alignment in vertical direction.</param> /// <param name="location">Input: The starting position of the available area. Output: The position /// the child should be located.</param> /// <param name="childSize">Input: The available area for the <paramref name="child"/>. Output: /// The area the child should take.</param> public void ArrangeChildVertical(FrameworkElement child, VerticalAlignmentEnum alignment, ref PointF location, ref SizeF childSize) { // See comment in ArrangeChild SizeF desiredSize = child.DesiredSize; if (!double.IsNaN(desiredSize.Height) && desiredSize.Height <= childSize.Height) { // Height takes precedence over Stretch - Use Center as fallback if (alignment == VerticalAlignmentEnum.Center || (alignment == VerticalAlignmentEnum.Stretch && !double.IsNaN(child.Height))) { location.Y += (childSize.Height - desiredSize.Height) / 2; childSize.Height = desiredSize.Height; } else if (alignment == VerticalAlignmentEnum.Bottom) { location.Y += childSize.Height - desiredSize.Height; childSize.Height = desiredSize.Height; } else if (alignment == VerticalAlignmentEnum.Top) { // Leave location unchanged childSize.Height = desiredSize.Height; } //else if (child.VerticalAlignment == VerticalAlignmentEnum.Stretch) // - Use all the space, nothing to do here } }
/// <summary> /// Arranges the child horizontal in a given area. If the area is bigger than the child's desired /// size, the child will be arranged according to the given <paramref name="alignment"/>. /// </summary> /// <param name="child">The child to arrange. The child will not be changed by this method.</param> /// <param name="alignment">Alignment in horizontal direction.</param> /// <param name="location">Input: The starting position of the available area. Output: The position /// the child should be located.</param> /// <param name="childSize">Input: The available area for the <paramref name="child"/>. Output: /// The area the child should take.</param> public void ArrangeChildHorizontal(FrameworkElement child, HorizontalAlignmentEnum alignment, ref PointF location, ref SizeF childSize) { // See comment in ArrangeChild SizeF desiredSize = child.DesiredSize; if (!double.IsNaN(desiredSize.Width) && desiredSize.Width <= childSize.Width) { // Width takes precedence over Stretch - Use Center as fallback if (alignment == HorizontalAlignmentEnum.Center || (alignment == HorizontalAlignmentEnum.Stretch && !double.IsNaN(child.Width))) { location.X += (childSize.Width - desiredSize.Width) / 2; childSize.Width = desiredSize.Width; } if (alignment == HorizontalAlignmentEnum.Right) { location.X += childSize.Width - desiredSize.Width; childSize.Width = desiredSize.Width; } else if (alignment == HorizontalAlignmentEnum.Left) { // Leave location unchanged childSize.Width = desiredSize.Width; } //else if (child.HorizontalAlignment == HorizontalAlignmentEnum.Stretch) // - Use all the space, nothing to do here } }
/// <summary> /// Arranges the child horizontal and vertical in a given area. If the area is bigger than /// the child's desired size, the child will be arranged according to the given <paramref name="horizontalAlignment"/> /// and <paramref name="verticalAlignment"/>. /// </summary> /// <param name="child">The child to arrange. The child will not be changed by this method.</param> /// <param name="horizontalAlignment">Alignment in horizontal direction.</param> /// <param name="verticalAlignment">Alignment in vertical direction.</param> /// <param name="location">Input: The starting position of the available area. Output: The position /// the child should be located.</param> /// <param name="childSize">Input: The available area for the <paramref name="child"/>. Output: /// The area the child should take.</param> public void ArrangeChild(FrameworkElement child, HorizontalAlignmentEnum horizontalAlignment, VerticalAlignmentEnum verticalAlignment, ref PointF location, ref SizeF childSize) { // Be careful when changing the implementation of those arrangement methods. // MPF behaves a bit different from WPF: We don't clip elements at the boundaries of containers, // instead, we arrange them with a maximum size calculated by the container. If we would not avoid // that controls can become bigger than their arrange size, we would have to accomplish a means to clip // their render size. ArrangeChildHorizontal(child, horizontalAlignment, ref location, ref childSize); ArrangeChildVertical(child, verticalAlignment, ref location, ref childSize); }
public override void SetupBrush(FrameworkElement parent, ref PositionColoredTextured[] verts, float zOrder, bool adaptVertsToBrushTexture) { base.SetupBrush(parent, ref verts, zOrder, adaptVertsToBrushTexture); _visualTexture = ContentManager.Instance.GetRenderTexture(_renderTextureKey); _visualSurface = ContentManager.Instance.GetRenderTarget(_renderSurfaceKey); _screen = parent.Screen; PrepareVisual(); }
/// <summary> /// Finds the nearest program relative to given <paramref name="startTime"/>. The "nearest" one is checked by comparing program start times. /// If the start time is before the current view port, the SlimTvMultiChannelGuideModel.GuideStartTime will be used. /// </summary> /// <param name="startTime">Start time of currently focused program</param> /// <param name="row">New row to focus</param> /// <param name="programControl">Returns the next program's control to focus</param> /// <returns><c>true</c> if matching program could be found</returns> private bool FindNearestProgram(DateTime startTime, int row, out FrameworkElement programControl) { var rowItems = Children.Where(c => GetRow(c) == row && c.DataContext != null).ToList(); double minDiff = Double.MaxValue; FrameworkElement nearestStartItem = null; foreach (var program in rowItems) { var pi = program.DataContext.Source as ProgramListItem; if (pi == null) continue; var programStartTime = pi.Program.StartTime; if (programStartTime < SlimTvMultiChannelGuideModel.GuideStartTime) programStartTime = SlimTvMultiChannelGuideModel.GuideStartTime; var diff = Math.Abs((startTime - programStartTime).TotalMinutes); if (nearestStartItem == null || diff < minDiff) { minDiff = diff; nearestStartItem = program; } } programControl = nearestStartItem; return programControl != null; }
public override void SetupBrush(FrameworkElement parent, ref PositionColoredTextured[] verts, float zOrder, bool adaptVertsToBrushTexture) { Allocate(); base.SetupBrush(parent, ref verts, zOrder, adaptVertsToBrushTexture); }
public FocusCandidate(FrameworkElement candidate, float zIndex) { Candidate = candidate; ZIndex = zIndex; }
/// <summary> /// Checks if the currently focused element is contained in this items control. /// </summary> /// <param name="focusedElement">Currelty focused element.</param> bool CheckFocusInScope(FrameworkElement focusedElement) { Visual focusPath = focusedElement; while (focusPath != null) { if (focusPath == this) // Focused control is located in our focus scope return true; if (focusPath is ItemsControl) // Focused control is located in another itemscontrol's focus scope return false; focusPath = focusPath.VisualParent; } return false; }
void OnTemplateControlChanged(AbstractProperty property, object oldValue) { FrameworkElement oldTemplateControl = oldValue as FrameworkElement; MPF.TryCleanupAndDispose(oldTemplateControl); FrameworkElement element = TemplateControl; if (element != null) { element.VisualParent = this; element.SetScreen(Screen); element.SetElementState(_elementState); if (element.TemplateNameScope == null) // This might be the case if the TemplateControl is directly assigned, without the use of a FrameworkTemplate, // which normally sets the TemplateNameScope. element.TemplateNameScope = new NameScope(); if (IsAllocated) element.Allocate(); } _initializedTemplateControl = element; InvalidateLayout(true, true); }
void UpdateRenderTarget(FrameworkElement fe) { // We need to consider a special case for rendering Opacity masks: in this case the alpha blending is enabled on device already. If we render now without changes, // the Visual will not be visible in target texture. In this case we switch back to normal rendering mode and restore blending mode after the Visual is rendered. var wasBlendingEnabled = GraphicsDevice.IsAlphaChannelBlendingEnabled; if (wasBlendingEnabled) { // Opposite steps as done inside FrameworkElement.RenderOpacityBrush GraphicsDevice.DisableAlphaChannelBlending(); GraphicsDevice.EnableAlphaTest(); } RectangleF bounds = new RectangleF(0, 0, _vertsBounds.Size.Width, _vertsBounds.Size.Height); fe.RenderToTexture(_visualTexture, new RenderContext(Matrix.Identity, Opacity, bounds, 1.0f)); if (wasBlendingEnabled) { // Redo steps as done inside FrameworkElement.RenderOpacityBrush GraphicsDevice.EnableAlphaChannelBlending(); GraphicsDevice.DisableAlphaTest(); } }
public FrameworkElement GetOrCreateItem(int index, FrameworkElement lvParent, out bool newCreated) { if (index < 0 || index >= _materializedItems.Count) { newCreated = false; return null; } FrameworkElement result = _materializedItems[index]; if (result != null) { newCreated = false; return result; } newCreated = true; result = _materializedItems[index] = PrepareItem(_items[index], lvParent); if (_populatedStartIndex == -1 || _populatedEndIndex == -1) { _populatedStartIndex = index; _populatedEndIndex = index; } else { if (index < _populatedStartIndex) _populatedStartIndex = index; else if (index > _populatedEndIndex) _populatedEndIndex = index; } return result; }
protected FrameworkElement PrepareItem(object dataItem, FrameworkElement lvParent) { // ReSharper disable UseObjectOrCollectionInitializer ListViewItem result = new ListViewItem // ReSharper restore UseObjectOrCollectionInitializer { Context = dataItem, Content = dataItem, Screen = _parent.Screen, VisualParent = lvParent, LogicalParent = lvParent }; // Set this after the other properties have been initialized to avoid duplicate work // No need to set the LogicalParent because styles and content templates don't bind bindings result.Style = MpfCopyManager.DeepCopyCutLVPs(ItemContainerStyle); result.ContentTemplate = MpfCopyManager.DeepCopyCutLVPs(ItemTemplate); return result; }
public override void DeepCopy(IDeepCopyable source, ICopyManager copyManager) { Detach(); base.DeepCopy(source, copyManager); ContentPresenter p = (ContentPresenter) source; Content = copyManager.GetCopy(p.Content); ContentTemplate = copyManager.GetCopy(p.ContentTemplate); HorizontalContentAlignment = p.HorizontalContentAlignment; VerticalContentAlignment = p.VerticalContentAlignment; _templateControl = copyManager.GetCopy(p._templateControl); _convertedContent = copyManager.GetCopy(p._convertedContent); Attach(); }
protected void SetTemplateControl(FrameworkElement templateControl) { FrameworkElement oldTemplateControl = _templateControl; if (ReferenceEquals(oldTemplateControl, templateControl)) return; _templateControl = null; if (oldTemplateControl != null) oldTemplateControl.CleanupAndDispose(); if (templateControl == null) return; object content = _convertedContent; if (!(content is FrameworkElement)) // If our content is a FrameworkElement itself, it should only be used as template control but not as context templateControl.Context = content; templateControl.LogicalParent = this; templateControl.VisualParent = this; templateControl.SetScreen(Screen); templateControl.SetElementState(_elementState); if (IsAllocated) templateControl.Allocate(); _templateControl = templateControl; InvalidateLayout(true, true); }
public override void DeepCopy(IDeepCopyable source, ICopyManager copyManager) { Detach(); base.DeepCopy(source, copyManager); Control c = (Control) source; BorderBrush = copyManager.GetCopy(c.BorderBrush); Background = copyManager.GetCopy(c.Background); BorderThickness = c.BorderThickness; Template = copyManager.GetCopy(c.Template); FrameworkElement oldTemplateControl = TemplateControl; if (oldTemplateControl != null) oldTemplateControl.VisualParent = null; TemplateControl = copyManager.GetCopy(c.TemplateControl); HorizontalContentAlignment = c.HorizontalContentAlignment; VerticalContentAlignment = c.VerticalContentAlignment; _initializedTemplateControl = copyManager.GetCopy(c._initializedTemplateControl); Attach(); }
protected float GetTop(FrameworkElement child, bool registerPositionProperty) { AbstractProperty topAttachedProperty = GetTopAttachedProperty_NoCreate(child); AbstractProperty bottomAttachedProperty = GetBottomAttachedProperty_NoCreate(child); if (topAttachedProperty != null) RegisterChildCanvasPosition(topAttachedProperty); if (bottomAttachedProperty != null) RegisterChildCanvasPosition(bottomAttachedProperty); float result; if (topAttachedProperty != null) result = (float) (double) topAttachedProperty.GetValue(); else if (bottomAttachedProperty != null) result = (float) (double) bottomAttachedProperty.GetValue() - child.DesiredSize.Height; else result = 0; return result; }
/// <summary> /// Will update the <see cref="CurrentItem"/> property. This method will be called when the /// current item might have changed. /// </summary> protected void UpdateCurrentItem() { Screen screen = Screen; FrameworkElement focusedElement = screen == null ? null : screen.FocusedElement; if (_lastFocusedElement == focusedElement) return; _lastFocusedElement = focusedElement; object lastCurrentItem = CurrentItem; object newCurrentItem = null; if (_itemsHostPanel != null && CheckFocusInScope(focusedElement)) { Visual element = focusedElement; while (element != null && element.VisualParent != _itemsHostPanel) element = element.VisualParent; newCurrentItem = element == null ? null : element.Context; ISelectableItemContainer container = element as ISelectableItemContainer; if (container != null) container.Selected = true; // Triggers an update of our _lastSelectedItem } if (newCurrentItem != lastCurrentItem) { CurrentItem = newCurrentItem; FireSelectionChanged(newCurrentItem); } }
void UpdateRenderTarget(FrameworkElement fe) { RectangleF bounds = new RectangleF(0, 0, _vertsBounds.Size.Width, _vertsBounds.Size.Height); fe.RenderToSurface(_visualSurface, new RenderContext(Matrix.Identity, Opacity, bounds, 1.0f)); // Unfortunately, brushes/brush effects are based on textures and cannot work with surfaces, so we need this additional copy step GraphicsDevice.Device.StretchRectangle( _visualSurface.Surface, new Rectangle(0, 0, _visualSurface.Size.Width, _visualSurface.Size.Height), _visualTexture.Surface0, new Rectangle(0, 0, _visualTexture.Size.Width, _visualTexture.Size.Height), TextureFilter.None); }
public virtual void SetupBrush(FrameworkElement parent, ref PositionColoredTextured[] verts, float zOrder, bool adaptVertsToBrushTexture) { if (!UpdateBounds(ref verts)) return; float w = _vertsBounds.Width; float h = _vertsBounds.Height; float xoff = _vertsBounds.X; float yoff = _vertsBounds.Y; if (adaptVertsToBrushTexture) for (int i = 0; i < verts.Length; i++) { PositionColoredTextured vert = verts[i]; float x = vert.X; float u = x - xoff; u /= w; float y = vert.Y; float v = y - yoff; v /= h; if (u < 0) u = 0; if (u > 1) u = 1; if (v < 0) v = 0; if (v > 1) v = 1; unchecked { Color4 color = Color.White; color.Alpha *= (float) Opacity; vert.Color = color.ToBgra(); } vert.Tu1 = u; vert.Tv1 = v; vert.Z = zOrder; verts[i] = vert; } }
protected void PrepareVisual() { FrameworkElement visual = Visual; if (_preparedVisual != null && _preparedVisual != visual) { _preparedVisual.SetElementState(ElementState.Available); _preparedVisual.Deallocate(); _preparedVisual = null; } if (_screen == null) return; if (visual == null) return; if (AutoLayoutContent) { // We must bypass normal layout or the visual will be layed out to screen/skin size visual.SetScreen(_screen); if (visual.ElementState == ElementState.Available) visual.SetElementState(ElementState.Running); // Here is _screen != null, which means we are allocated visual.Allocate(); SizeF size = _vertsBounds.Size; visual.Measure(ref size); visual.Arrange(new RectangleF(0, 0, _vertsBounds.Size.Width, _vertsBounds.Size.Height)); } _preparedVisual = visual; }
protected override SizeF CalculateInnerDesiredSize(SizeF totalSize) { // Return the biggest available child extents SizeF childSize; SizeF maxChildSize = new SizeF(float.NaN, float.NaN); foreach (FrameworkElement child in GetVisibleChildren()) { childSize = new SizeF(totalSize.Width, totalSize.Height); child.Measure(ref childSize); if (float.IsNaN(maxChildSize.Width) || childSize.Width > maxChildSize.Width) maxChildSize.Width = childSize.Width; if (float.IsNaN(maxChildSize.Height) || childSize.Height > maxChildSize.Height) maxChildSize.Height = childSize.Height; } if (_ellipsisControl == null) _ellipsisControl = CreateEllipsisControl(); childSize = new SizeF(totalSize.Width, totalSize.Height); _ellipsisControl.Measure(ref childSize); if (float.IsNaN(maxChildSize.Width) || childSize.Width > maxChildSize.Width) maxChildSize.Width = childSize.Width; if (float.IsNaN(maxChildSize.Height) || childSize.Height > maxChildSize.Height) maxChildSize.Height = childSize.Height; return maxChildSize; }
/// <summary> /// Gets the currently focused program or header control and its Grid.Row. /// </summary> /// <param name="program">Focused program</param> /// <param name="headerControl">Focused header</param> /// <param name="row">The focused row</param> /// <returns><c>true</c> if matching program could be found</returns> private bool GetFocusedRowAndStartTime(out ProgramListItem program, out FrameworkElement headerControl, out int row) { program = null; headerControl = null; row = 0; FrameworkElement currentElement = GetFocusedElementOrChild(); while (currentElement != null) { if (currentElement.DataContext != null) { // Check for program var item = currentElement.DataContext.Source as ProgramListItem; if (item != null) { program = item; row = GetRow(currentElement); return true; } // Check for channel header var channel = currentElement.DataContext.Source as ChannelProgramListItem; if (channel != null) { headerControl = currentElement; row = GetRow(currentElement); return true; } } currentElement = currentElement.LogicalParent as Control; } return false; }