Beispiel #1
0
        /// <summary>
        /// Initialize a new instance of the ViewLayoutControl class.
        /// </summary>
        /// <param name="viewControl">View control to use as child.</param>
        /// <param name="rootControl">Top level visual control.</param>
        /// <param name="viewChild">View used to size and position the child control.</param>
        public ViewLayoutControl(ViewControl viewControl,
                                 VisualControl rootControl,
                                 ViewBase viewChild)
        {
            Debug.Assert(viewControl != null);
            Debug.Assert(rootControl != null);
            Debug.Assert(viewChild != null);

            // Default values
            LayoutOffset = Point.Empty;

            // Remember the view
            ChildView = viewChild;

            // Ensure the child is hooked into the hierarchy of elements
            ChildView.Parent = this;

            // Create the view control instance
            ChildControl = viewControl;

            // Back reference hookup
            ChildControl.ViewLayoutControl = this;

            // Start off invisible until first layed out
            ChildControl.Visible = false;

            // Ensure that all view elements inside here use our control
            OwningControl = ChildControl;

            // Add our new control to the provided parent collection
            CommonHelper.AddControlToParent(rootControl, ChildControl);
        }
Beispiel #2
0
        /// <summary>
        /// Gets and sets the root control for point translation and message dispatch.
        /// </summary>
        /// <param name="parent">Parent control.</param>
        public void UpdateParent(Control parent)
        {
            // Keep looking till we run out of parents
            while (parent != null)
            {
                // We can hook into a visual control derived class
                if (parent is VisualControl control)
                {
                    _rootControl = control;
                    _rootPopup   = null;
                    break;
                }

                // We can hook into a visual popup derived class
                if (parent is VisualPopup popup)
                {
                    _rootControl = null;
                    _rootPopup   = popup;
                    break;
                }

                // Move up another level
                parent = parent.Parent;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Initialize a new instance of the ViewControl class.
        /// </summary>
        /// <param name="rootControl">Top level visual control.</param>
        public ViewControl(VisualControl rootControl)
        {
            Debug.Assert(rootControl != null);

            // We use double buffering to reduce drawing flicker
            SetStyle(ControlStyles.OptimizedDoubleBuffer |
                     ControlStyles.AllPaintingInWmPaint |
                     ControlStyles.UserPaint, true);

            // We need to repaint entire control whenever resized
            SetStyle(ControlStyles.ResizeRedraw, true);

            // We are not selectable
            SetStyle(ControlStyles.Selectable, false);

            // Default
            TransparentBackground = false;
            InDesignMode          = false;

            // Remember incoming references
            _rootControl = rootControl;

            // Create delegate so child elements can request a repaint
            NeedPaintDelegate = OnNeedPaint;
        }
        /// <summary>
        /// Initialize a new instance of the ViewLayoutScrollViewport class.
        /// </summary>
        /// <param name="rootControl">Top level visual control.</param>
        /// <param name="viewportFiller">View element to place inside viewport.</param>
        /// <param name="paletteBorderEdge">Palette for use with the border edge.</param>
        /// <param name="paletteMetrics">Palette source for metrics.</param>
        /// <param name="metricPadding">Metric used to get view padding.</param>
        /// <param name="metricOvers">Metric used to get overposition.</param>
        /// <param name="orientation">Orientation for the viewport children.</param>
        /// <param name="alignment">Alignment of the children within the viewport.</param>
        /// <param name="animateChange">Animate changes in the viewport.</param>
        /// <param name="vertical">Is the viewport vertical.</param>
        /// <param name="needPaintDelegate">Delegate for notifying paint requests.</param>
        public ViewLayoutScrollViewport(VisualControl rootControl,
                                        ViewBase viewportFiller,
                                        PaletteBorderEdge paletteBorderEdge,
                                        IPaletteMetric paletteMetrics,
                                        PaletteMetricPadding metricPadding,
                                        PaletteMetricInt metricOvers,
                                        VisualOrientation orientation,
                                        RelativePositionAlign alignment,
                                        bool animateChange,
                                        bool vertical,
                                        NeedPaintHandler needPaintDelegate)
        {
            Debug.Assert(rootControl != null);
            Debug.Assert(viewportFiller != null);
            Debug.Assert(needPaintDelegate != null);

            // We need a way to notify changes in layout
            _needPaintDelegate = needPaintDelegate;

            // By default we are showing the contained viewport in vertical scrolling
            _viewportVertical = vertical;

            // Our initial visual orientation should match the parameter
            Orientation = orientation;

            // Create the child viewport
            Viewport = new ViewLayoutViewport(paletteMetrics, metricPadding,
                                              metricOvers, ViewportOrientation(_viewportVertical),
                                              alignment, animateChange)
            {
                // Default to same alignment for both directions
                CounterAlignment = alignment,

                // We always want the viewport to fill any remainder space
                FillSpace = true
            };

            // Put the provided element inside the viewport
            Viewport.Add(viewportFiller);

            // Hook into animation step events
            Viewport.AnimateStep += OnAnimateStep;

            // To prevent the contents of the viewport from being able to draw outside
            // the viewport (such as having child controls) we use a ViewLayoutControl
            // that uses a child control to restrict the drawing region.
            ViewControl = new ViewLayoutControl(rootControl, Viewport)
            {
                InDesignMode = rootControl.InDesignMode
            };

            // Create the scrollbar and matching border edge
            ScrollbarV  = new ViewDrawScrollBar(true);
            ScrollbarH  = new ViewDrawScrollBar(false);
            BorderEdgeV = new ViewDrawBorderEdge(paletteBorderEdge, System.Windows.Forms.Orientation.Vertical);
            BorderEdgeH = new ViewDrawBorderEdge(paletteBorderEdge, System.Windows.Forms.Orientation.Horizontal);

            // Hook into scroll position changes
            ScrollbarV.ScrollChanged += OnScrollVChanged;
            ScrollbarH.ScrollChanged += OnScrollHChanged;

            // Add with appropriate docking style
            Add(ViewControl, ViewDockStyle.Fill);
            Add(BorderEdgeV, ViewDockStyle.Right);
            Add(BorderEdgeH, ViewDockStyle.Bottom);
            Add(ScrollbarV, ViewDockStyle.Right);
            Add(ScrollbarH, ViewDockStyle.Bottom);
        }
Beispiel #5
0
 /// <summary>
 /// Initialize a new instance of the ViewLayoutControl class.
 /// </summary>
 /// <param name="rootControl">Top level visual control.</param>
 /// <param name="viewChild">View used to size and position the child control.</param>
 public ViewLayoutControl(VisualControl rootControl,
                          ViewBase viewChild)
     : this(new ViewControl(rootControl), rootControl, viewChild)
 {
 }