/// <summary> /// Calculates normal appointment bounds /// </summary> /// <param name="colList">Accumulated ColumnList</param> /// <param name="dy"></param> /// <param name="collate"></param> private int CalcAppointmentBounds(ColumnList colList, int dy, bool collate) { if (colList.SList.Count > 0) { int rowSpread = 0; int rowHeight = AppointmentHeight; // If we are stretching the rows height, then calculate // the default row height and the row spread, to evenly // distribute the fill remainder if (collate == false && CalendarView.TimeLineStretchRowHeight == true) { int height = GetColRect(0).Height; rowHeight = height / colList.SList.Count; if (rowHeight < AppointmentHeight) rowHeight = AppointmentHeight; else rowSpread = height - (colList.SList.Count * rowHeight); } for (int i = 0; i < colList.SList.Count; i++) { int maxRowHeight = 0; for (int j = 0; j < colList.SList[i].Count; j++) { CalendarItem item = colList.SList[i][j].CItem; Rectangle r = new Rectangle(); r.Y = ClientRect.Y + dy; r.Height = rowHeight; if (collate == false && CalendarView.TimeLineStretchRowHeight == true) { if (i < rowSpread) r.Height++; } else { r.Height = GetRowHeight(item, rowHeight); } TimeSpan ts1 = item.StartTime - StartDate; TimeSpan ts2 = item.EndTime - item.StartTime; int pos = (int) ((ts1.TotalMinutes * ColumnWidth) / BaseInterval); int width = (int) ((ts2.TotalMinutes * ColumnWidth) / BaseInterval); if (CalendarView.TimeLinePeriod == eTimeLinePeriod.Years) { int years = item.StartTime.Year - StartDate.Year; pos = (years * ColumnWidth) / CalendarView.TimeLineInterval; } if (width < 20) width = 20; r.X = ClientRect.X + pos + _HScrollPos; r.Width = width; Rectangle p = ClientRect; int hpad = CalendarView.TimeLineHorizontalPadding; if (r.Left >= p.Left) { r.X += hpad; r.Width -= hpad; } if (r.Right <= p.Right) r.Width -= hpad; // Now that we have calculated the items height and // width, invoke a Recalc on the item item.WidthInternal = r.Width; item.HeightInternal = r.Height - 1; item.RecalcSize(); // Set our bounds for the item r.Width = item.WidthInternal; r.Height = item.HeightInternal; item.Bounds = r; if (item.StartTime != item.EndTime) { if (r.Height + 1 > maxRowHeight) maxRowHeight = r.Height + 1; } // Set it's display state item.Displayed = r.IntersectsWith(ClientRect); } dy += maxRowHeight; } } return (dy); }
/// <summary> /// Updates our CalendarItems list /// </summary> private void UpdateCalendarItems() { if (NeedRecalcLayout == true) { _CollateLines.Clear(); if (_CalendarItems.Count > 0) { List<CalendarItem> items = SortCalendarItems(_CalendarItems); if (CalendarView.HasTimeLineGetRowCollateIdCallout) { SortedDictionary<int, List<CalendarItem>> ditems = CollateCalendarItems(items); int dy = 0; foreach (KeyValuePair<int, List<CalendarItem>> kvp in ditems) { ColumnList colList = new ColumnList(); for (int i = 0; i < kvp.Value.Count; i++) colList.AddColumnSlot(kvp.Value[i], 0); colList.CountColumns(); dy = CalcAppointmentBounds(colList, dy, true); _CollateLines.Add(dy); } } else { ColumnList colList = new ColumnList(); for (int i = 0; i < items.Count; i++) colList.AddColumnSlot(items[i], 0); colList.CountColumns(); CalcAppointmentBounds(colList, 0, false); } } NeedRecalcLayout = false; InvalidateRect(); } }
/// <summary> /// Calculates normal appointment bounds /// </summary> /// <param name="col">DayColumn column</param> /// <param name="colList">Accumulated ColumnList</param> private void CalcAppointmentBounds(int col, ColumnList colList) { Rectangle r = _DayColumns[col].Bounds; r.X += 1; r.Width -= 8; for (int i = 0; i < colList.SList.Count; i++) { for (int j = 0; j < colList.SList[i].Count; j++) { Rectangle r2 = r; SlotItem si = colList.SList[i][j]; CalendarItem item = si.CItem; float dx = (float)r2.Width / si.Count; r2.X += (int)(dx * i); if (si.SList != null && si.SList.Count == 1) r2.Width = (int)(dx * (si.SList[0].Column - si.Column)); else if (si.SList == null) r2.Width = r.Width - (r2.X - r.X); else r2.Width = (int)dx; DateTime date = item.StartTime.Date; TimeSpan ts1 = item.StartTime.AddMinutes(-StartSlice * TimeSlotDuration) - date; TimeSpan ts2 = item.EndTime - item.StartTime; int pos = (int)(ts1.TotalMinutes / TimeSlotDuration * TimeSliceHeight); int height = (int)Math.Round(ts2.TotalMinutes / TimeSlotDuration * TimeSliceHeight); AppointmentView view = item as AppointmentView; if (view != null) { Font font = view.Font ?? CalendarView.Font; if (font != null) height = Math.Max(font.Height + 6, height); } r2.Y = r.Y + pos; r2.Height = height; // Now that we have calculated the items height and // width, invoke a Recalc on the item item.WidthInternal = r2.Width; item.HeightInternal = r2.Height - 1; item.RecalcSize(); // Set our bounds for the item r2.Width = item.WidthInternal; r2.Height = item.HeightInternal; if (item.Bounds != r2) { InvalidateRect(item.Bounds); InvalidateRect(r2); } item.Bounds = r2; // Set it's display state item.Displayed = r2.IntersectsWith(ClientRect); } } }
/// <summary> /// Updates the condensed view column list /// </summary> internal void UpdateCondensedColumnList() { if (_ModelReloaded == true && Connector != null) { _CondensedColList = new List<ColumnList>(); List<CalendarItem> items = new List<CalendarItem>(); // Get our appointment collection GetCondensedAppts(items); GetCondensedCustomItems(items); // If we have any items, sort them and // create a corresponding ColumnList if (items.Count > 0) { items = SortCalendarItems(items); if (CalendarView.HasTimeLineGetRowCollateIdCallout) { SortedDictionary<int, List<CalendarItem>> ditems = CollateCalendarItems(items); foreach (KeyValuePair<int, List<CalendarItem>> kvp in ditems) { ColumnList colList = new ColumnList(); for (int i = 0; i < kvp.Value.Count; i++) colList.AddColumnSlot(kvp.Value[i], 0); colList.CountColumns(); _CondensedColList.Add(colList); } } else { _CondensedColList.Add(new ColumnList()); for (int i = 0; i < items.Count; i++) _CondensedColList[0].AddColumnSlot(items[i], 0); _CondensedColList[0].CountColumns(); } } _ModelReloaded = false; } }
/// <summary> /// Updates our CalendarItems list /// </summary> private void UpdateCalendarItems() { ColumnList colList = new ColumnList(); for (int i = 0; i < _NumberOfColumns; i++) { if (IsLayoutNeeded(i) == true) { if (_DayColumns[i].CalendarItems.Count > 0) { List<CalendarItem> items = SortCalendarItems(i); colList.Clear(); for (int j = 0; j < items.Count; j++) colList.AddColumnSlot(items[j], 0); colList.CountColumns(); CalcAppointmentBounds(i, colList); } _DayColumns[i].NeedRecalcLayout = false; } } }