/// <summary>
        /// Create an overflow check button.
        /// </summary>
        /// <param name="page">Page to associate the check button with.</param>
        /// <param name="checkButtonOrient">Orientation of the check button.</param>
        /// <param name="dockFar">Docking position of the check button.</param>
        /// <returns></returns>
        protected override ViewDrawNavOutlookOverflow CreateOverflowItem(KryptonPage page, 
                                                                         VisualOrientation checkButtonOrient,
                                                                         ViewDockStyle dockFar)
        {
            // Let base class create the actual check button
            ViewDrawNavOutlookOverflow checkButton = base.CreateOverflowItem(page, checkButtonOrient, dockFar);

            // Add to the end of the overflow collection
            _viewOverflowLayout.Add(checkButton, dockFar);

            return checkButton;
        }
Beispiel #2
0
        /// <summary>
        /// Update the incoming dock style to reflect our orientation.
        /// </summary>
        /// <param name="style">Incoming dock style.</param>
        /// <returns>Orientation adjusted dock style.</returns>
        protected ViewDockStyle OrientateDock(ViewDockStyle style)
        {
            switch (Orientation)
            {
            case VisualOrientation.Top:
                // Nothing to do, as top is the standard setting
                break;

            case VisualOrientation.Left:
                switch (style)
                {
                case ViewDockStyle.Top:
                    return(ViewDockStyle.Left);

                case ViewDockStyle.Left:
                    return(ViewDockStyle.Bottom);

                case ViewDockStyle.Right:
                    return(ViewDockStyle.Top);

                case ViewDockStyle.Bottom:
                    return(ViewDockStyle.Right);
                }
                break;

            case VisualOrientation.Right:
                switch (style)
                {
                case ViewDockStyle.Top:
                    return(ViewDockStyle.Right);

                case ViewDockStyle.Left:
                    return(ViewDockStyle.Top);

                case ViewDockStyle.Right:
                    return(ViewDockStyle.Bottom);

                case ViewDockStyle.Bottom:
                    return(ViewDockStyle.Left);
                }
                break;

            case VisualOrientation.Bottom:
                switch (style)
                {
                case ViewDockStyle.Top:
                    return(ViewDockStyle.Bottom);

                case ViewDockStyle.Left:
                    return(ViewDockStyle.Right);

                case ViewDockStyle.Right:
                    return(ViewDockStyle.Left);

                case ViewDockStyle.Bottom:
                    return(ViewDockStyle.Top);
                }
                break;

            default:
                // Should never happen!
                Debug.Assert(false);
                break;
            }

            // No change required
            return(style);
        }
Beispiel #3
0
 /// <summary>
 /// Add a view element to a docker.
 /// </summary>
 /// <param name="i">Index of view docker.</param>
 /// <param name="dockStyle">Dock style for placement.</param>
 /// <param name="view">Actual view to add.</param>
 /// <param name="usingSpacers">Are view spacers being used.</param>
 protected abstract void AddViewToDocker(int i, ViewDockStyle dockStyle, ViewBase view, bool usingSpacers);
Beispiel #4
0
        /// <summary>
        /// Discover the preferred size of the element.
        /// </summary>
        /// <param name="context">Layout context.</param>
        public override Size GetPreferredSize(ViewLayoutContext context)
        {
            Debug.Assert(context != null);

            // Create new lookup that only contains entries for current child items
            ViewDockStyleLookup newChildDocking = new ViewDockStyleLookup();

            // Remember the original display rectangle provided
            Rectangle originalRect = context.DisplayRectangle;
            Rectangle displayRect  = context.DisplayRectangle;

            // Accumulate the size that must be provided by docking edges and then filler
            Size preferredSize = Size.Empty;

            // Track the minimize size needed to satisfy the docking edges only
            Size minimumSize = Size.Empty;

            PaletteDrawBorders leftEdges   = PaletteDrawBorders.All;
            PaletteDrawBorders rightEdges  = PaletteDrawBorders.All;
            PaletteDrawBorders topEdges    = PaletteDrawBorders.All;
            PaletteDrawBorders bottomEdges = PaletteDrawBorders.All;
            PaletteDrawBorders fillEdges   = PaletteDrawBorders.All;

            // Check for edge docking children
            foreach (ViewBase child in this.Reverse())
            {
                // Add into the valid child lookup
                ViewDockStyle dockStyle = GetDock(child);
                newChildDocking.Add(child, dockStyle);

                // Only position visible children that are not 'fill'
                if ((child.Visible || PreferredSizeAll) && (GetDock(child) != ViewDockStyle.Fill))
                {
                    // Prevent children from showing adjacent borders that are not needed
                    UpdateChildBorders(child, context, ref leftEdges, ref rightEdges,
                                       ref topEdges, ref bottomEdges, ref fillEdges);

                    // Update with latest calculated display rectangle
                    context.DisplayRectangle = displayRect;

                    // Get the preferred size of the child
                    Size childSize = child.GetPreferredSize(context);

                    // Apply size requests from edge docking children
                    switch (OrientateDock(dockStyle))
                    {
                    case ViewDockStyle.Top:
                        preferredSize.Height += childSize.Height;
                        displayRect.Y        += childSize.Height;
                        displayRect.Height   -= childSize.Height;

                        if (minimumSize.Width < childSize.Width)
                        {
                            minimumSize.Width = childSize.Width;
                        }
                        break;

                    case ViewDockStyle.Bottom:
                        preferredSize.Height += childSize.Height;
                        displayRect.Height   -= childSize.Height;

                        if (minimumSize.Width < childSize.Width)
                        {
                            minimumSize.Width = childSize.Width;
                        }
                        break;

                    case ViewDockStyle.Left:
                        preferredSize.Width += childSize.Width;
                        displayRect.X       += childSize.Width;
                        displayRect.Width   -= childSize.Width;

                        if (minimumSize.Height < childSize.Height)
                        {
                            minimumSize.Height = childSize.Height;
                        }
                        break;

                    case ViewDockStyle.Right:
                        preferredSize.Width += childSize.Width;
                        displayRect.Width   -= childSize.Width;

                        if (minimumSize.Height < childSize.Height)
                        {
                            minimumSize.Height = childSize.Height;
                        }
                        break;
                    }
                }
            }

            // Check for the fill child last
            foreach (ViewBase child in this.Reverse())
            {
                // Only interested in a visible 'fill' child
                if ((child.Visible || PreferredSizeAll) && (GetDock(child) == ViewDockStyle.Fill))
                {
                    // Prevent children from showing adjacent borders that are not needed
                    UpdateChildBorders(child, context, ref leftEdges, ref rightEdges,
                                       ref topEdges, ref bottomEdges, ref fillEdges);

                    // Update with latest calculated display rectangle
                    context.DisplayRectangle = displayRect;

                    // Get the preferred size of the child
                    Size childSize = child.GetPreferredSize(context);

                    preferredSize.Width  += childSize.Width;
                    preferredSize.Height += childSize.Height;

                    // There can only be one filler!
                    break;
                }
            }

            // Use updated lookup
            _childDocking = newChildDocking;

            // Put back the original display rect
            context.DisplayRectangle = originalRect;

            // Enforce the minimum values from the other docking edge sizes
            preferredSize.Width  = Math.Max(preferredSize.Width, minimumSize.Width);
            preferredSize.Height = Math.Max(preferredSize.Height, minimumSize.Height);

            // Apply the padding request
            switch (Orientation)
            {
            case VisualOrientation.Top:
            case VisualOrientation.Bottom:
                preferredSize.Width  += Padding.Horizontal;
                preferredSize.Height += Padding.Vertical;
                break;

            case VisualOrientation.Left:
            case VisualOrientation.Right:
                preferredSize.Width  += Padding.Vertical;
                preferredSize.Height += Padding.Horizontal;
                break;
            }

            // Allow the preferred size to be modified before being used
            return(UpdatePreferredSize(preferredSize));
        }
        private void CreateNavCheckButtons()
        {
            // Maintain lookup between page and check button/button edge that represent it
            _pageLookup       = new PageToNavCheckButton();
            _buttonEdgeLookup = new PageToButtonEdge();

            VisualOrientation     checkButtonOrient = ResolveButtonOrientation();
            RelativePositionAlign alignment         = Navigator.Stack.StackAlignment;
            Orientation           stackOrient       = Navigator.Stack.StackOrientation;
            Orientation           buttonEdgeOrient  = (stackOrient == Orientation.Vertical ? Orientation.Horizontal : Orientation.Vertical);
            ViewDockStyle         dockNear          = (stackOrient == Orientation.Vertical ? ViewDockStyle.Top : ViewDockStyle.Left);
            ViewDockStyle         dockFar           = (stackOrient == Orientation.Vertical ? ViewDockStyle.Bottom : ViewDockStyle.Right);

            // Cache the border edge palette to use
            PaletteBorderEdge buttonEdgePalette = (Navigator.Enabled ? Navigator.StateNormal.BorderEdge :
                                                   Navigator.StateDisabled.BorderEdge);

            // Start stacking from the top/left if not explicitly set to be far aligned
            bool dockTopLeft = (alignment != RelativePositionAlign.Far);

            // Create a check button to represent each krypton page
            foreach (KryptonPage page in Navigator.Pages)
            {
                // Create the draw view element for the check button and provide page it represents
                ViewDrawNavCheckButtonStack checkButton = new ViewDrawNavCheckButtonStack(Navigator, page, checkButtonOrient);

                // Provide the drag rectangle when requested for this button
                checkButton.ButtonDragRectangle += new EventHandler <ButtonDragRectangleEventArgs>(OnCheckButtonDragRect);
                checkButton.ButtonDragOffset    += new EventHandler <ButtonDragOffsetEventArgs>(OnCheckButtonDragOffset);

                // Need to know when check button needs repainting
                checkButton.NeedPaint = NeedPaintDelegate;

                // Set the initial state
                checkButton.Visible     = page.LastVisibleSet;
                checkButton.Enabled     = page.Enabled;
                checkButton.Checked     = (Navigator.SelectedPage == page);
                checkButton.Orientation = checkButtonOrient;

                // Create the border edge for use next to the check button
                ViewDrawBorderEdge buttonEdge = new ViewDrawBorderEdge(buttonEdgePalette, buttonEdgeOrient);
                buttonEdge.Visible = page.LastVisibleSet;

                // Add to lookup dictionary
                _pageLookup.Add(page, checkButton);
                _buttonEdgeLookup.Add(page, buttonEdge);

                // Add to the child collection with the correct docking style
                if (dockTopLeft)
                {
                    _viewLayout.Insert(1, checkButton);
                    _viewLayout.Insert(1, buttonEdge);
                    _viewLayout.SetDock(buttonEdge, dockNear);
                    _viewLayout.SetDock(checkButton, dockNear);
                }
                else
                {
                    _viewLayout.Add(buttonEdge, dockFar);
                    _viewLayout.Add(checkButton, dockFar);
                }

                // All entries after the selected page are docked at the bottom/right unless
                // we have been set to stack near or far, in which case we do not change.
                if (checkButton.Checked && (alignment == RelativePositionAlign.Center))
                {
                    dockTopLeft = false;
                }
            }

            // Need to monitor changes in the page collection to reflect in layout bar
            Navigator.Pages.Inserted += new TypedHandler <KryptonPage>(OnPageInserted);
            Navigator.Pages.Removed  += new TypedHandler <KryptonPage>(OnPageRemoved);
            Navigator.Pages.Cleared  += new EventHandler(OnPagesCleared);
            _events = true;
        }
        /// <summary>
        /// Update the incoming dock style to reflect our orientation.
        /// </summary>
        /// <param name="style">Incoming dock style.</param>
        /// <returns>Orientation adjusted dock style.</returns>
        protected ViewDockStyle OrientateDock(ViewDockStyle style)
        {
            switch (Orientation)
            {
                case VisualOrientation.Top:
                    // Nothing to do, as top is the standard setting
                    break;
                case VisualOrientation.Left:
                    switch (style)
                    {
                        case ViewDockStyle.Top:
                            return ViewDockStyle.Left;
                        case ViewDockStyle.Left:
                            return ViewDockStyle.Bottom;
                        case ViewDockStyle.Right:
                            return ViewDockStyle.Top;
                        case ViewDockStyle.Bottom:
                            return ViewDockStyle.Right;
                    }
                    break;
                case VisualOrientation.Right:
                    switch (style)
                    {
                        case ViewDockStyle.Top:
                            return ViewDockStyle.Right;
                        case ViewDockStyle.Left:
                            return ViewDockStyle.Top;
                        case ViewDockStyle.Right:
                            return ViewDockStyle.Bottom;
                        case ViewDockStyle.Bottom:
                            return ViewDockStyle.Left;
                    }
                    break;
                case VisualOrientation.Bottom:
                    switch (style)
                    {
                        case ViewDockStyle.Top:
                            return ViewDockStyle.Bottom;
                        case ViewDockStyle.Left:
                            return ViewDockStyle.Right;
                        case ViewDockStyle.Right:
                            return ViewDockStyle.Left;
                        case ViewDockStyle.Bottom:
                            return ViewDockStyle.Top;
                    }
                    break;
                default:
                    // Should never happen!
                    Debug.Assert(false);
                    break;
            }

            // No change required
            return style;
        }
        /// <summary>
        /// Find the actual docking to apply for the specified RightToLeft setting.
        /// </summary>
        /// <param name="ds">Docking style.</param>
        /// <param name="control">Control for which the setting is needed.</param>
        /// <returns>Calculated docking to actual use.</returns>
        protected ViewDockStyle CalculateDock(ViewDockStyle ds, Control control)
        {
            // Do we need to adjust to reflect right to left layout?
            if (CommonHelper.GetRightToLeftLayout(control) && (control.RightToLeft == RightToLeft.Yes))
            {
                // Only need to invert the left and right sides
                switch (ds)
                {
                    case ViewDockStyle.Left:
                        ds = ViewDockStyle.Right;
                        break;
                    case ViewDockStyle.Right:
                        ds = ViewDockStyle.Left;
                        break;
                }
            }

            return ds;
        }
        /// <summary>
        /// Sets the dock setting for the provided child instance.
        /// </summary>
        /// <param name="child">Child view element.</param>
        /// <param name="dock">DockStyle setting.</param>
        public void SetDock(ViewBase child, ViewDockStyle dock)
        {
            Debug.Assert(child != null);

            // If the lookup is not already defined
            if (!_childDocking.ContainsKey(child))
            {
                // Then just add the value
                _childDocking.Add(child, dock);
            }
            else
            {
                // Overwrite the existing value
                _childDocking[child] = dock;
            }
        }
        /// <summary>
        /// Append a view to the collection.
        /// </summary>
        /// <param name="item">ViewBase reference.</param>
        /// <param name="dock">DockStyle setting.</param>
        public void Add(ViewBase item, ViewDockStyle dock)
        {
            // Add the child to the view
            Add(item);

            // Set the initial docking for the new element
            SetDock(item, dock);
        }
        /// <summary>
        /// Add a view element to a docker.
        /// </summary>
        /// <param name="i">Index of view docker.</param>
        /// <param name="dockStyle">Dock style for placement.</param>
        /// <param name="view">Actual view to add.</param>
        /// <param name="usingSpacers">Are view spacers being used.</param>
        protected override void AddViewToDocker(int i,
                                                ViewDockStyle dockStyle,
                                                ViewBase view,
                                                bool usingSpacers)
        {
            // Get the indexed docker
            ViewDrawDocker viewDocker = _viewDockers[i];

            // By default add to the end of the children
            int insertIndex = viewDocker.Count;

            // If using spacers, then insert before the first spacer
            if (usingSpacers)
            {
                for(int j=0; j<insertIndex; j++)
                    if (viewDocker[j] is ViewLayoutMetricSpacer)
                    {
                        insertIndex = j;
                        break;
                    }
            }

            viewDocker.Insert(insertIndex, view);
            viewDocker.SetDock(view, dockStyle);
        }