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 += OnCheckButtonDragRect;
                checkButton.ButtonDragOffset    += 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)
                {
                    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 += OnPageInserted;
            Navigator.Pages.Removed  += OnPageRemoved;
            Navigator.Pages.Cleared  += OnPagesCleared;
            _events = true;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initialize a new instance of the ViewDrawMonth class.
        /// </summary>
        /// <param name="calendar">Reference to calendar provider.</param>
        /// <param name="months">Reference to months instance.</param>
        /// <param name="redirector">Redirector for getting values.</param>
        /// <param name="needPaintDelegate">Delegate for requesting paint changes.</param>
        public ViewDrawMonth(IKryptonMonthCalendar calendar,
                             ViewLayoutMonths months,
                             PaletteRedirect redirector,
                             NeedPaintHandler needPaintDelegate)
            : base(false)
        {
            _calendar = calendar;
            _months   = months;

            // Add a header for showing the month/year value
            _drawContent  = new ViewDrawContent(_calendar.StateNormal.Header.Content, this, VisualOrientation.Top);
            _borderForced = new PaletteBorderInheritForced(_calendar.StateNormal.Header.Border);
            _borderForced.ForceBorderEdges(PaletteDrawBorders.None);
            _drawHeader = new ViewDrawDocker(_calendar.StateNormal.Header.Back, _borderForced, null)
            {
                { _drawContent, ViewDockStyle.Fill }
            };
            Add(_drawHeader);

            // Create the left/right arrows for moving the months
            _arrowPrev        = new ButtonSpecCalendar(this, PaletteButtonSpecStyle.Previous, RelativeEdgeAlign.Near);
            _arrowNext        = new ButtonSpecCalendar(this, PaletteButtonSpecStyle.Next, RelativeEdgeAlign.Far);
            _arrowPrev.Click += OnPrevMonth;
            _arrowNext.Click += OnNextMonth;
            _buttonSpecs      = new CalendarButtonSpecCollection(this)
            {
                _arrowPrev,
                _arrowNext
            };

            // Using a button spec manager to add the buttons to the header
            _buttonManager = new ButtonSpecManagerDraw(_calendar.CalendarControl, redirector, null, _buttonSpecs,
                                                       new[] { _drawHeader },
                                                       new IPaletteMetric[] { _calendar.StateCommon },
                                                       new[] { PaletteMetricInt.HeaderButtonEdgeInsetCalendar },
                                                       new[] { PaletteMetricPadding.None },
                                                       _calendar.GetToolStripDelegate, needPaintDelegate);

            // Create stacks for holding display items
            ViewLayoutStack namesStack = new(true);
            ViewLayoutStack weeksStack = new(true);
            ViewLayoutStack daysStack  = new(false);

            _numberStack = new ViewLayoutStack(false);
            weeksStack.Add(_numberStack);
            weeksStack.Add(daysStack);

            // Add day names
            _drawMonthDayNames = new ViewDrawMonthDayNames(_calendar, _months);
            _drawWeekCorner    = new ViewLayoutWeekCorner(_calendar, _months, _calendar.StateNormal.Header.Border);
            namesStack.Add(_drawWeekCorner);
            namesStack.Add(_drawMonthDayNames);
            Add(namesStack);
            Add(weeksStack);

            // Add border between week numbers and days area
            _borderEdgeRedirect = new PaletteBorderEdgeRedirect(_calendar.StateNormal.Header.Border, null);
            _borderEdge         = new PaletteBorderEdge(_borderEdgeRedirect, null);
            _drawBorderEdge     = new ViewDrawBorderEdge(_borderEdge, Orientation.Vertical);
            _drawWeekNumbers    = new ViewDrawWeekNumbers(_calendar, _months);
            ViewLayoutDocker borderLeftDock = new()
            {
                { _drawWeekNumbers, ViewDockStyle.Left },
                { new ViewLayoutSeparator(0, 4), ViewDockStyle.Top },