public void RecreateCells()
        {
            LogicalChildren.Clear();
            VisualChildren.Clear();

            Cells = new CellsCollection(GridControl.Columns, AddCellAction, RemoveCellAction);

            LogicalChildren.Add(ScrollBar);
            VisualChildren.Add(ScrollBar);
            //TODO recalculate with viewport
            ScrollBar.Maximum = GridControl.Controller.Count;

            void AddCellAction(Cell cell)
            {
                //cell.PointerReleased += CellOnPointerReleased;
                LogicalChildren.Add(cell);
                VisualChildren.Add(cell);
            }

            void RemoveCellAction(Cell cell)
            {
                //cell.PointerReleased -= CellOnPointerReleased;
                LogicalChildren.Remove(cell);
                VisualChildren.Remove(cell);
            }
        }
Esempio n. 2
0
        //--------------------------------------------------------------
        #region Methods
        //--------------------------------------------------------------

        /// <inheritdoc/>
        protected override void OnLoad()
        {
            base.OnLoad();

            // Create scroll bar.
            var verticalScrollBarStyle = VerticalScrollBarStyle;

            if (!string.IsNullOrEmpty(verticalScrollBarStyle))
            {
                _verticalScrollBar = new ScrollBar
                {
                    Name        = "ConsoleScrollBar",
                    Style       = verticalScrollBarStyle,
                    SmallChange = 1, // 1 unit = 1 line.
                };
                VisualChildren.Add(_verticalScrollBar);

                var scrollBarValue = _verticalScrollBar.Properties.Get <float>(RangeBase.ValuePropertyId);
                scrollBarValue.Changed += (s, e) =>
                {
                    // The line offset is the "inverse" of the scroll bar value:
                    int maxLineOffset = _wrappedLines.Count - _numberOfLines;
                    LineOffset = maxLineOffset - (int)e.NewValue;
                };
            }
        }
Esempio n. 3
0
        /// <inheritdoc/>
        public sealed override void ApplyTemplate()
        {
            if (!_templateApplied)
            {
                VisualChildren.Clear();

                if (Template != null)
                {
                    _templateLog.Verbose("Creating control template");

                    var child     = Template.Build(this);
                    var nameScope = new NameScope();
                    NameScope.SetNameScope((Control)child, nameScope);

                    // We need to call SetupTemplateControls twice:
                    // - Once before the controls are added to the visual/logical trees so that the
                    //   TemplatedParent property is set and names are registered; if
                    //   TemplatedParent is not set when the control is added to the logical tree,
                    //   then styles with the /template/ selector won't match.
                    // - Once after the controls are added to the logical tree (and thus styled) to
                    //   call ApplyTemplate on nested templated controls and register any of our
                    //   templated children that appear as children of presenters in these nested
                    //   templated child controls.
                    SetupTemplateControls(child, nameScope);
                    VisualChildren.Add(child);
                    ((ISetLogicalParent)child).SetParent(this);
                    SetupTemplateControls(child, nameScope);

                    OnTemplateApplied(new TemplateAppliedEventArgs(nameScope));
                }

                _templateApplied = true;
            }
        }
Esempio n. 4
0
 public Viewbox()
 {
     _containerVisual = new Decorator();
     _containerVisual.RenderTransformOrigin = RelativePoint.TopLeft;
     LogicalChildren.Add(_containerVisual);
     VisualChildren.Add(_containerVisual);
 }
Esempio n. 5
0
        protected override void OnLoad()
        {
            base.OnLoad();

            if (_panel == null)
            {
                // Create the internal stack panel.
                // The padding of this tree view item is used as the margin of the panel.
                _panel = new StackPanel
                {
                    Margin = Padding,
                };

                // Whenever the padding is changed, the panel margin should be updated.
                var panelMargin = _panel.Properties.Get <Vector4F>(UIControl.MarginPropertyId);
                var padding     = this.Properties.Get <Vector4F>(UIControl.PaddingPropertyId);
                padding.Changed += panelMargin.Change;

                // Add Items to the panel.
                _panel.Children.Add(Header);
                foreach (var item in Items)
                {
                    _panel.Children.Add(item);
                }

                // The panel is the (only) visual child of the TreeView control.
                VisualChildren.Add(_panel);
            }
        }
Esempio n. 6
0
        /// <inheritdoc/>
        public sealed override void ApplyTemplate()
        {
            if (!_templateApplied)
            {
                if (VisualChildren.Count > 0)
                {
                    foreach (var child in this.GetTemplateChildren())
                    {
                        child.SetValue(TemplatedParentProperty, null);
                    }

                    VisualChildren.Clear();
                }

                if (Template != null)
                {
                    Logger.Verbose(LogArea.Control, this, "Creating control template");

                    var child     = Template.Build(this);
                    var nameScope = new NameScope();
                    NameScope.SetNameScope((Control)child, nameScope);
                    child.SetValue(TemplatedParentProperty, this);
                    RegisterNames(child, nameScope);
                    ((ISetLogicalParent)child).SetParent(this);
                    VisualChildren.Add(child);

                    OnTemplateApplied(new TemplateAppliedEventArgs(nameScope));
                }

                _templateApplied = true;
            }
        }
Esempio n. 7
0
    /// <inheritdoc/>
    protected override void OnLoad()
    {
      base.OnLoad();

      // If the control is writable, it uses an I beam cursor; otherwise, the default cursor.
      UpdateCursor();

      var verticalScrollBarStyle = VerticalScrollBarStyle;
      if (!string.IsNullOrEmpty(verticalScrollBarStyle))
      {
        _verticalScrollBar = new ScrollBar
        {
          Style = verticalScrollBarStyle,
        };
        VisualChildren.Add(_verticalScrollBar);

        if (Numeric.IsNaN(_verticalScrollBar.Width))
          _verticalScrollBar.Width = 16;

        // The scroll bar value changes the VisualOffset value.
        var scrollBarValue = _verticalScrollBar.Properties.Get<float>(RangeBase.ValuePropertyId);
        scrollBarValue.Changed += (s, e) => VisualOffset = _verticalScrollBar.Value;

        // The I beam cursor should not be visible over the scroll bar. Therefore, 
        // the scroll bar sets its desired cursor to the default cursor to override 
        // the I beam of the text box.
        _verticalScrollBar.Cursor = Screen.Renderer.GetCursor(null);
      }
    }
Esempio n. 8
0
        internal void SetVisualLines(ICollection <VisualLine> visualLines)
        {
            foreach (var v in _visuals)
            {
                if (v.VisualLine.IsDisposed)
                {
                    VisualChildren.Remove(v);
                }
            }

            _visuals.Clear();
            foreach (var newLine in visualLines)
            {
                var visual = newLine.Render();
                if (!visual.IsAdded)
                {
                    VisualChildren.Add(visual);
                    visual.IsAdded = true;
                }

                _visuals.Add(visual);
            }

            InvalidateArrange();
        }
Esempio n. 9
0
 public AdornerDecorator()
 {
     AdornerLayer = new AdornerLayer();
     ((ISetLogicalParent)AdornerLayer).SetParent(this);
     AdornerLayer.ZIndex = int.MaxValue;
     VisualChildren.Add(AdornerLayer);
 }
Esempio n. 10
0
        /// <summary>
        /// Updates the <see cref="Child"/> control based on the control's <see cref="Content"/>.
        /// </summary>
        /// <remarks>
        /// Usually the <see cref="Child"/> control is created automatically when
        /// <see cref="ApplyTemplate"/> is called; however for this to happen, the control needs to
        /// be attached to a logical tree (if the control is not attached to the logical tree, it
        /// is reasonable to expect that the DataTemplates needed for the child are not yet
        /// available). This method forces the <see cref="Child"/> control's creation at any point,
        /// and is particularly useful in unit tests.
        /// </remarks>
        public void UpdateChild()
        {
            var old     = Child;
            var content = Content;
            var result  = this.MaterializeDataTemplate(content);

            if (old != null)
            {
                VisualChildren.Remove(old);
            }

            if (result != null)
            {
                if (!(content is IControl))
                {
                    result.DataContext = content;
                }

                Child = result;

                if (result.Parent == null)
                {
                    ((ISetLogicalParent)result).SetParent((ILogical)this.TemplatedParent ?? this);
                }

                VisualChildren.Add(result);
            }
            else
            {
                Child = null;
            }

            _createdChild = true;
        }
Esempio n. 11
0
 public Viewbox()
 {
     // The Child control is hosted inside a ViewboxContainer control so that the transform
     // can be applied independently of the Viewbox and Child transforms.
     _containerVisual = new ViewboxContainer();
     _containerVisual.RenderTransformOrigin = RelativePoint.TopLeft;
     VisualChildren.Add(_containerVisual);
 }
Esempio n. 12
0
    /// <inheritdoc/>
    protected override void OnLoad()
    {
      base.OnLoad();

      // Create horizontal scroll bar.
      var horizontalScrollBarStyle = HorizontalScrollBarStyle;
      if (!string.IsNullOrEmpty(horizontalScrollBarStyle))
      {
        _horizontalScrollBar = new ScrollBar
        {
          Style = horizontalScrollBarStyle,
          Value = HorizontalOffset,
        };
        VisualChildren.Add(_horizontalScrollBar);

        // If not set, we set a fixed Height for the scroll bar. This simplifies our layout process.
        if (Numeric.IsNaN(_horizontalScrollBar.Height))
          _horizontalScrollBar.Height = 16;

        // Connect ScrollBar.Value with HorizontalOffset (two-way connection).
        var scrollBarValue = _horizontalScrollBar.Properties.Get<float>(RangeBase.ValuePropertyId);
        var horizontalOffset = Properties.Get<float>(HorizontalOffsetPropertyId);
        scrollBarValue.Changed += horizontalOffset.Change;
        horizontalOffset.Changed += scrollBarValue.Change;


        if (_isTouchDevice)
          _horizontalScrollBar.Opacity = 0;

      }

      // Create vertical scroll bar.
      var verticalScrollBarStyle = VerticalScrollBarStyle;
      if (!string.IsNullOrEmpty(verticalScrollBarStyle))
      {
        _verticalScrollBar = new ScrollBar
        {
          Style = verticalScrollBarStyle,
          Value = VerticalOffset,
        };
        VisualChildren.Add(_verticalScrollBar);

        // If not set, we set a fixed Width for the scroll bar. This simplifies our layout process.
        if (Numeric.IsNaN(_verticalScrollBar.Width))
          _verticalScrollBar.Width = 16;

        // Connect ScrollBar.Value with VerticalOffset (two-way connection).
        var scrollBarValue = _verticalScrollBar.Properties.Get<float>(RangeBase.ValuePropertyId);
        var verticalOffset = Properties.Get<float>(VerticalOffsetPropertyId);
        scrollBarValue.Changed += verticalOffset.Change;
        verticalOffset.Changed += scrollBarValue.Change;


        if (_isTouchDevice)
          _verticalScrollBar.Opacity = 0;

      }
    }
Esempio n. 13
0
 public ColumnHeader(Column column)
 {
     Column    = column;
     TextBlock = new TextBlock {
         Margin = new Thickness(1.0), Text = Column.FieldName
     };
     LogicalChildren.Add(TextBlock);
     VisualChildren.Add(TextBlock);
 }
Esempio n. 14
0
        /// <summary>
        /// Updates the <see cref="Child"/> control based on the control's <see cref="Content"/>.
        /// </summary>
        /// <remarks>
        /// Usually the <see cref="Child"/> control is created automatically when
        /// <see cref="ApplyTemplate"/> is called; however for this to happen, the control needs to
        /// be attached to a logical tree (if the control is not attached to the logical tree, it
        /// is reasonable to expect that the DataTemplates needed for the child are not yet
        /// available). This method forces the <see cref="Child"/> control's creation at any point,
        /// and is particularly useful in unit tests.
        /// </remarks>
        public void UpdateChild()
        {
            var content  = Content;
            var oldChild = Child;
            var newChild = CreateChild();

            // Remove the old child if we're not recycling it.
            if (oldChild != null && newChild != oldChild)
            {
                VisualChildren.Remove(oldChild);
            }

            // Set the DataContext if the data isn't a control.
            if (!(content is IControl))
            {
                DataContext = content;
            }
            else
            {
                ClearValue(DataContextProperty);
            }

            // Update the Child.
            if (newChild == null)
            {
                Child = null;
            }
            else if (newChild != oldChild)
            {
                ((ISetInheritanceParent)newChild).SetParent(this);

                Child = newChild;

                if (oldChild?.Parent == this)
                {
                    LogicalChildren.Remove(oldChild);
                }

                if (newChild.Parent == null)
                {
                    var templatedLogicalParent = TemplatedParent as ILogical;

                    if (templatedLogicalParent != null)
                    {
                        ((ISetLogicalParent)newChild).SetParent(templatedLogicalParent);
                    }
                    else
                    {
                        LogicalChildren.Add(newChild);
                    }
                }

                VisualChildren.Add(newChild);
            }

            _createdChild = true;
        }
Esempio n. 15
0
        private Ellipse CreateMarker()
        {
            var marker = new Ellipse();

            marker[~Shape.FillProperty]  = this[~MarkerBrushProperty];
            marker[~ToolTip.TipProperty] = this[~MessageProperty];
            VisualChildren.Add(marker);
            LogicalChildren.Add(marker);
            return(marker);
        }
Esempio n. 16
0
        private Thumb GetThumb()
        {
            var thumb = new Thumb {
                Width = 10, Height = 10, Background = Brushes.Black
            };

            thumb.DragStarted += (sender, e) => DragStarted = true;
            VisualChildren.Add(thumb);
            return(thumb);
        }
Esempio n. 17
0
        private Control CreateMarker()
        {
            var marker = new Image();

            marker.PointerPressed        += (o, e) => { e.Handled = true; MarkerPointerDown?.Invoke(o, e); };
            marker[~Image.SourceProperty] = this[~MarkerImageProperty];
            marker[~ToolTip.TipProperty]  = this[~MessageProperty];
            VisualChildren.Add(marker);
            LogicalChildren.Add(marker);
            return(marker);
        }
Esempio n. 18
0
        public void EnsureVisual()
        {
            VisualChildren.Add(Content as IVisual);

            if (!(Content is TestElement childElement))
            {
                return;
            }

            childElement.EnsureVisual();
        }
Esempio n. 19
0
 public void AddVisualControl(DesignerControl dc)
 {
     if (VisualChildren.Contains(dc))
     {
         return;
     }
     else
     {
         VisualChildren.Add(dc);
     }
 }
Esempio n. 20
0
        //--------------------------------------------------------------
        #region Methods
        //--------------------------------------------------------------

        /// <inheritdoc/>
        protected override void OnLoad()
        {
            base.OnLoad();

            // Create decrement button.
            var decrementButtonStyle = DecrementButtonStyle;

            if (!string.IsNullOrEmpty(decrementButtonStyle))
            {
                _decrementButton = new Button
                {
                    Name           = "DecrementButton",
                    Style          = decrementButtonStyle,
                    Focusable      = false, // Unlike normal buttons these arrow button can not be focused!
                    IsRepeatButton = true,
                };
                VisualChildren.Add(_decrementButton);

                var click = _decrementButton.Events.Get <EventArgs>(ButtonBase.ClickEventId);
                click.Event += OnDecrementButtonClick;
            }

            // Create increment button.
            var incrementButtonStyle = IncrementButtonStyle;

            if (!string.IsNullOrEmpty(incrementButtonStyle))
            {
                _incrementButton = new Button
                {
                    Name           = "RightDownButton",
                    Style          = incrementButtonStyle,
                    Focusable      = false, // Unlike normal buttons these arrow button can not be focused!
                    IsRepeatButton = true,
                };
                VisualChildren.Add(_incrementButton);

                var click = _incrementButton.Events.Get <EventArgs>(ButtonBase.ClickEventId);
                click.Event += OnIncrementButtonClick;
            }

            // Create thumb.
            var thumbStyle = ThumbStyle;

            if (!string.IsNullOrEmpty(thumbStyle))
            {
                _thumb = new Thumb
                {
                    Name  = "ScrollBarThumb",
                    Style = thumbStyle,
                };
                VisualChildren.Add(_thumb);
            }
        }
Esempio n. 21
0
 void AddLayer(Control layer, int zindex)
 {
     _layers.Add(layer);
     ((ISetLogicalParent)layer).SetParent(this);
     layer.ZIndex = zindex;
     VisualChildren.Add(layer);
     if (((ILogical)this).IsAttachedToLogicalTree)
     {
         ((ILogical)layer).NotifyAttachedToLogicalTree(new LogicalTreeAttachmentEventArgs(_logicalRoot, layer, this));
     }
     InvalidateArrange();
 }
Esempio n. 22
0
        private void InitializeComponent()
        {
            _viewer = new ScrollViewer()
            {
                Padding = new Thickness(5),
                HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled,
                VerticalScrollBarVisibility   = ScrollBarVisibility.Auto,
            };

            VisualChildren.Add(_viewer);
            LogicalChildren.Add(_viewer);
        }
Esempio n. 23
0
        /// <summary>
        /// Creates the <see cref="Panel"/>.
        /// </summary>
        private void CreatePanel()
        {
            Panel = ItemsPanel.Build();
            Panel.SetValue(TemplatedParentProperty, TemplatedParent);

            LogicalChildren.Clear();
            VisualChildren.Clear();
            LogicalChildren.Add(Panel);
            VisualChildren.Add(Panel);

            _createdPanel = true;
            var task = MoveToPage(-1, SelectedIndex);
        }
Esempio n. 24
0
        /// <inheritdoc/>
        public sealed override void ApplyTemplate()
        {
            var template = Template;
            var logical  = (ILogical)this;

            // Apply the template if it is not the same as the template already applied - except
            // for in the case that the template is null and we're not attached to the logical
            // tree. In that case, the template has probably been cleared because the style setting
            // the template has been detached, so we want to wait until it's re-attached to the
            // logical tree as if it's re-attached to the same tree the template will be the same
            // and we don't need to do anything.
            if (_appliedTemplate != template && (template != null || logical.IsAttachedToLogicalTree))
            {
                if (VisualChildren.Count > 0)
                {
                    foreach (var child in this.GetTemplateChildren())
                    {
                        child.SetValue(TemplatedParentProperty, null);
                        ((ISetLogicalParent)child).SetParent(null);
                    }

                    VisualChildren.Clear();
                }

                if (template != null)
                {
                    Logger.TryGet(LogEventLevel.Verbose, LogArea.Control)?.Log(this, "Creating control template");

                    var(child, nameScope) = template.Build(this);
                    ApplyTemplatedParent(child);
                    ((ISetLogicalParent)child).SetParent(this);
                    VisualChildren.Add(child);

                    // Existing code kinda expect to see a NameScope even if it's empty
                    if (nameScope == null)
                    {
                        nameScope = new NameScope();
                    }

                    var e = new TemplateAppliedEventArgs(nameScope);
                    OnApplyTemplate(e);
#pragma warning disable CS0618 // Type or member is obsolete
                    OnTemplateApplied(e);
#pragma warning restore CS0618 // Type or member is obsolete
                    RaiseEvent(e);
                }

                _appliedTemplate = template;
            }
        }
Esempio n. 25
0
        protected override void OnVisualChildrenChanged(DependencyObject visualAdded, DependencyObject visualRemoved)
        {
            if (visualAdded is Visual)
            {
                VisualChildren.Add(visualAdded as Visual);
            }

            if (visualRemoved is Visual)
            {
                VisualChildren.Remove(visualRemoved as Visual);
            }

            base.OnVisualChildrenChanged(visualAdded, visualRemoved);
        }
Esempio n. 26
0
        private Control CreateMarker()
        {
#pragma warning disable CS0618 // Type or member is obsolete
            var marker = new DrawingPresenter();
#pragma warning restore CS0618 // Type or member is obsolete
            marker.PointerPressed += (o, e) => { e.Handled = true; MarkerPointerDown?.Invoke(o, e); };
#pragma warning disable CS0618 // Type or member is obsolete
            marker[~DrawingPresenter.DrawingProperty] = this[~MarkerImageProperty];
#pragma warning restore CS0618 // Type or member is obsolete
            marker[~ToolTip.TipProperty] = this[~MessageProperty];
            VisualChildren.Add(marker);
            LogicalChildren.Add(marker);
            return(marker);
        }
Esempio n. 27
0
        /// <summary>
        /// Creates the big thumb that allows dragging a molecule around the canvas
        /// </summary>
        private void BuildBigDragArea()
        {
            BigThumb = new Thumb();
            VisualChildren.Add(BigThumb);
            BigThumb.IsHitTestVisible = true;

            BigThumb.Style                = (Style)FindResource(Globals.ThumbStyle);
            BigThumb.Cursor               = Cursors.Hand;
            BigThumb.DragStarted         += BigThumb_DragStarted;
            BigThumb.DragCompleted       += BigThumb_DragCompleted;
            BigThumb.DragDelta           += BigThumb_DragDelta;
            BigThumb.MouseLeftButtonDown += BigThumb_MouseLeftButtonDown;
            BigThumb.Focusable            = true;
            Keyboard.Focus(BigThumb);
        }
Esempio n. 28
0
        private void BuildAdornerCorner(ref Thumb cornerThumb, Cursor customizedCursor)
        {
            if (cornerThumb != null)
            {
                return;
            }

            cornerThumb = new Thumb();

            // Set some arbitrary visual characteristics.
            cornerThumb.Cursor = customizedCursor;
            SetThumbStyle(cornerThumb);
            cornerThumb.IsHitTestVisible = true;
            VisualChildren.Add(cornerThumb);
        }
Esempio n. 29
0
        /// <summary>
        /// Updates the <see cref="Child"/> control based on the control's <see cref="Content"/>.
        /// </summary>
        /// <remarks>
        /// Usually the <see cref="Child"/> control is created automatically when
        /// <see cref="ApplyTemplate"/> is called; however for this to happen, the control needs to
        /// be attached to a logical tree (if the control is not attached to the logical tree, it
        /// is reasonable to expect that the DataTemplates needed for the child are not yet
        /// available). This method forces the <see cref="Child"/> control's creation at any point,
        /// and is particularly useful in unit tests.
        /// </remarks>
        public void UpdateChild()
        {
            var content         = Content;
            var oldChild        = Child;
            var newChild        = CreateChild();
            var logicalChildren = Host?.LogicalChildren ?? LogicalChildren;

            // Remove the old child if we're not recycling it.
            if (newChild != oldChild)
            {
                if (oldChild != null)
                {
                    VisualChildren.Remove(oldChild);
                    logicalChildren.Remove(oldChild);
                    ((ISetInheritanceParent)oldChild).SetParent(oldChild.Parent);
                }
            }

            // Set the DataContext if the data isn't a control.
            if (!(content is IControl))
            {
                DataContext = content;
            }
            else
            {
                ClearValue(DataContextProperty);
            }

            // Update the Child.
            if (newChild == null)
            {
                Child = null;
            }
            else if (newChild != oldChild)
            {
                ((ISetInheritanceParent)newChild).SetParent(this);
                Child = newChild;

                if (!logicalChildren.Contains(newChild))
                {
                    logicalChildren.Add(newChild);
                }

                VisualChildren.Add(newChild);
            }

            _createdChild = true;
        }
Esempio n. 30
0
        private void BuildRotateThumb(ref Thumb rotateThumb, Cursor hand)
        {
            rotateThumb = new Thumb();

            rotateThumb.IsHitTestVisible = true;

            RotateHandle.Width         = _rotateThumbWidth;
            RotateHandle.Height        = _rotateThumbWidth;
            RotateHandle.Cursor        = Cursors.Hand;
            rotateThumb.Style          = (Style)FindResource(Globals.RotateThumbStyle);
            rotateThumb.DragStarted   += RotateStarted;
            rotateThumb.DragDelta     += RotateThumb_DragDelta;
            rotateThumb.DragCompleted += HandleResizeCompleted;

            VisualChildren.Add(rotateThumb);
        }