Exemplo n.º 1
0
        /// <summary>
        /// Initialize a new instance of the ButtonSpecCalendar class.
        /// </summary>
        /// <param name="month">Reference to owning view.</param>
        /// <param name="fixedStyle">Fixed style to use.</param>
        /// <param name="edge">Alignment edge.</param>
        public ButtonSpecCalendar(ViewDrawMonth month,
                                  PaletteButtonSpecStyle fixedStyle,
                                  RelativeEdgeAlign edge)
        {
            Debug.Assert(month != null);

            // Remember back reference to owning navigator.
            _month   = month;
            _edge    = edge;
            _enabled = true;
            _visible = true;

            // Fix the type
            ProtectedType = fixedStyle;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the button for the day that is nearest (date wise) to the point provided.
        /// </summary>
        /// <param name="pt">Point to lookup.</param>
        /// <returns>DateTime for nearest matching day.</returns>
        public DateTime DayNearPoint(Point pt)
        {
            // Search for an exact matching month view
            foreach (ViewBase view in this)
            {
                ViewDrawMonth month = view as ViewDrawMonth;
                if ((month != null) && month.ClientRectangle.Contains(pt))
                {
                    return(month.ViewDrawMonthDays.DayNearPoint(pt));
                }
            }

            int cols  = _calendar.CalendarDimensions.Width;
            int rows  = _calendar.CalendarDimensions.Height;
            int ptCol = cols - 1;
            int ptRow = rows - 1;

            // Find the column to be used in lookup
            for (int col = 0; col < cols; col++)
            {
                if (pt.X < this[col + 1].ClientRectangle.Right)
                {
                    ptCol = col;
                    break;
                }
            }

            // Find the row to be used in lookup
            for (int row = 0; row < rows; row++)
            {
                if (pt.Y < this[(row * cols) + 1].ClientRectangle.Bottom)
                {
                    ptRow = row;
                    break;
                }
            }

            ViewDrawMonth target = ((ViewDrawMonth)this[(ptCol + (ptRow * cols)) + 1]);

            return(target.ViewDrawMonthDays.DayNearPoint(pt));
        }
Exemplo n.º 3
0
 /// <summary>
 /// Initialize a new instance of the CalendarButtonSpecCollection class.
 /// </summary>
 /// <param name="owner">Reference to owning object.</param>
 public CalendarButtonSpecCollection(ViewDrawMonth owner)
     : base(owner)
 {
 }
Exemplo n.º 4
0
        private void SyncMonths()
        {
            // We need the today header if we show the today button or a button spec
            this[0].Visible    = _showToday || (_buttonSpecs.Count > 0);
            this[0].Enabled    = Enabled;
            _drawToday.Visible = _showToday;

            // How many month children instances do we need?
            int months = Months;

            // Do we need to create more month view?
            if (Count < (months + 1))
            {
                for (int i = Count - 1; i < months; i++)
                {
                    Add(new ViewDrawMonth(_calendar, this, _redirector, _needPaintDelegate));
                }
            }
            else if (Count > (months + 1))
            {
                // Remove excess month view instances
                for (int i = Count - 1; i > months; i--)
                {
                    this[i].Dispose();
                    this.RemoveAt(i);
                }
            }

            // Is there a change in the selection range?
            if ((_oldSelectionStart != _calendar.SelectionStart) ||
                (_oldSelectionEnd != _calendar.SelectionEnd) ||
                (_oldFocusDay != FocusDay) ||
                _firstTimeSync)
            {
                _firstTimeSync     = false;
                _oldSelectionStart = _calendar.SelectionStart;
                _oldSelectionEnd   = _calendar.SelectionEnd;
                _oldFocusDay       = FocusDay;

                // If we have a day with the focus
                if (FocusDay != null)
                {
                    // If focus day is before the first month
                    if (FocusDay.Value < _displayMonth)
                    {
                        _displayMonth = new DateTime(FocusDay.Value.Year, FocusDay.Value.Month, 1);
                    }
                    else
                    {
                        // If focus day is after the last month
                        DateTime endDate = _displayMonth.AddMonths(months);
                        if (FocusDay.Value >= endDate)
                        {
                            _displayMonth = new DateTime(FocusDay.Value.Year, FocusDay.Value.Month, 1).AddMonths(-(months - 1));
                        }
                    }
                }
                else
                {
                    // Bring the selection into the display range
                    DateTime endMonth       = _displayMonth.AddMonths(months - 1);
                    DateTime oldSelEndDate  = _oldSelectionEnd.Date;
                    DateTime oldSelEndMonth = new DateTime(oldSelEndDate.Year, oldSelEndDate.Month, 1);
                    if (oldSelEndMonth >= endMonth)
                    {
                        _displayMonth = oldSelEndMonth.AddMonths(-(months - 1));
                    }

                    if (_oldSelectionStart < _displayMonth)
                    {
                        _displayMonth = new DateTime(_calendar.SelectionStart.Year, _calendar.SelectionStart.Month, 1);
                    }
                }
            }

            DateTime currentMonth = _displayMonth;

            // Inform each view which month it should be drawing
            for (int i = 1; i < Count; i++)
            {
                ViewDrawMonth viewMonth = (ViewDrawMonth)this[i];
                viewMonth.Enabled    = Enabled;
                viewMonth.Month      = currentMonth;
                viewMonth.FirstMonth = (i == 1);
                viewMonth.LastMonth  = (i == (Count - 1));
                viewMonth.UpdateButtons((i == 1), ((i - 1) == (_calendar.CalendarDimensions.Width - 1)));

                // Move forward to next month
                currentMonth = currentMonth.AddMonths(1);
            }
        }