private bool IsItemWithinRange(CalendarItem item, DateTime startDate, DateTime endDate) { // Always show a task if it is currently being dragged if (IsResizingAppointment() && (item == SelectedAppointment)) { return(true); } if (HideParentTasks && item.IsParent) { return(false); } if (!item.HasValidDates()) { return(false); } // Task must at least intersect the range if ((item.StartDate >= endDate) || (item.EndDate <= startDate)) { return(false); } if (!DisplayTasksContinuous) { if ((item.StartDate < startDate) && (item.EndDate > endDate)) { return(false); } } if (HideTasksSpanningWeekends) { if (DateUtil.WeekOfYear(item.StartDate) != DateUtil.WeekOfYear(item.EndDate)) { return(false); } } if (HideTasksSpanningDays) { if (item.IsLongAppt()) { return(false); } } if (HideTasksWithoutTimes) { if (CalendarItem.IsStartOfDay(item.StartDate) && CalendarItem.IsEndOfDay(item.EndDate)) { return(false); } } return(true); }
protected override void DrawAppointment(Graphics g, Rectangle rect, Calendar.Appointment appointment, bool isSelected, Rectangle gripRect) { // Allow selection to be drawn even when a // selection rect is active isSelected = (appointment.Id == m_SelectedTaskID); // Our custom gripper bar gripRect = rect; gripRect.Inflate(-2, -2); gripRect.Width = 5; // If the start date precedes the start of the week then extend the // draw rect to the left so the edge is clipped and likewise for the right. CalendarItem taskItem = (appointment as CalendarItem); bool longAppt = taskItem.IsLongAppt(); if (longAppt) { if (appointment.StartDate < StartDate) { rect.X -= 4; rect.Width += 4; gripRect.X = rect.X; gripRect.Width = 0; } else if (appointment.StartDate > StartDate) { rect.X++; rect.Width--; gripRect.X++; } if (appointment.EndDate >= EndDate) { rect.Width += 5; } } else // day appointment { if (taskItem.StartDate.TimeOfDay.TotalHours == 0.0) { rect.Y++; rect.Height--; } rect.Width -= 1; } m_Renderer.DrawAppointment(g, rect, appointment, isSelected, gripRect); }
public override void DrawAppointment(System.Drawing.Graphics g, System.Drawing.Rectangle rect, Calendar.Appointment appointment, bool isSelected, System.Drawing.Rectangle gripRect) { if (appointment == null) { throw new ArgumentNullException("appointment"); } if (g == null) { throw new ArgumentNullException("g"); } if (rect.Width != 0 && rect.Height != 0) { CalendarItem taskItem = (appointment as CalendarItem); bool isLongAppt = taskItem.IsLongAppt(); // Recalculate colours Color textColor = taskItem.TaskTextColor; Color fillColor = DrawingColor.SetLuminance(textColor, 0.95f); Color borderColor = textColor; Color barColor = textColor; if (taskItem.HasTaskTextColor) { if (isSelected) { textColor = DrawingColor.SetLuminance(textColor, 0.3f); } else if (TaskColorIsBackground && !taskItem.IsDoneOrGoodAsDone) { barColor = textColor; fillColor = textColor; borderColor = DrawingColor.AdjustLighting(textColor, -0.5f, true); textColor = DrawingColor.GetBestTextColor(textColor); } } // Draw the background of the appointment g.SmoothingMode = SmoothingMode.None; if (isSelected) { if (isLongAppt) { rect.Height++; } UIExtension.SelectionRect.Draw(m_hWnd, g, rect.Left, rect.Top, rect.Width, rect.Height, false); // opaque } else { using (SolidBrush brush = new SolidBrush(fillColor)) g.FillRectangle(brush, rect); if (taskItem.DrawBorder) { if (!isLongAppt) { rect.Height--; // drawing with pen adds 1 to height rect.Width--; } using (Pen pen = new Pen(borderColor, 1)) g.DrawRectangle(pen, rect); } } // Draw appointment icon bool hasIcon = false; taskItem.IconRect = Rectangle.Empty; if (TaskHasIcon(taskItem)) { Rectangle rectIcon; int imageSize = DPIScaling.Scale(16); if (isLongAppt) { int yCentre = ((rect.Top + rect.Bottom + 1) / 2); rectIcon = new Rectangle((rect.Left + TextPadding), (yCentre - (imageSize / 2)), imageSize, imageSize); } else { rectIcon = new Rectangle(rect.Left + TextPadding, rect.Top + TextPadding, imageSize, imageSize); } if (g.IsVisible(rectIcon) && m_TaskIcons.Get(taskItem.Id)) { if (isLongAppt) { rectIcon.X = (gripRect.Right + TextPadding); } else { gripRect.Y += (imageSize + TextPadding); gripRect.Height -= (imageSize + TextPadding); } var clipRgn = g.Clip; if (rect.Bottom < (rectIcon.Y + imageSize)) { g.Clip = new Region(RectangleF.Intersect(rect, g.ClipBounds)); } m_TaskIcons.Draw(g, rectIcon.X, rectIcon.Y); g.Clip = clipRgn; hasIcon = true; taskItem.IconRect = rectIcon; rect.Width -= (rectIcon.Right - rect.Left); rect.X = rectIcon.Right; } } // Draw gripper bar if (gripRect.Width > 0) { using (SolidBrush brush = new SolidBrush(barColor)) g.FillRectangle(brush, gripRect); if (!isLongAppt) { gripRect.Height--; // drawing with pen adds 1 to height } // Draw gripper border using (Pen pen = new Pen(DrawingColor.AdjustLighting(barColor, -0.5f, true), 1)) g.DrawRectangle(pen, gripRect); if (!hasIcon) { rect.X = gripRect.Right; rect.Width -= (gripRect.Width + (TextPadding * 2)); } } // draw appointment text using (StringFormat format = new StringFormat()) { format.Alignment = StringAlignment.Near; format.LineAlignment = (isLongAppt ? StringAlignment.Center : StringAlignment.Near); rect.Y += 3; if (isLongAppt) { rect.Height = m_BaseFont.Height; } else { rect.Height -= 3; } taskItem.TextRect = rect; g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; using (SolidBrush brush = new SolidBrush(textColor)) { if (taskItem.IsDone && StrikeThruDoneTasks) { using (Font font = new Font(this.BaseFont, FontStyle.Strikeout)) { g.DrawString(appointment.Title, font, brush, rect, format); } } else { g.DrawString(appointment.Title, this.BaseFont, brush, rect, format); } } g.TextRenderingHint = TextRenderingHint.SystemDefault; } } }
public override void DrawAppointment(System.Drawing.Graphics g, System.Drawing.Rectangle rect, Calendar.Appointment appointment, bool isSelected, System.Drawing.Rectangle gripRect) { if (appointment == null) { throw new ArgumentNullException("appointment"); } if (g == null) { throw new ArgumentNullException("g"); } if (rect.Width != 0 && rect.Height != 0) { CalendarItem taskItem = (appointment as CalendarItem); bool longAppt = taskItem.IsLongAppt(); if (!longAppt && (taskItem.StartDate.TimeOfDay.TotalHours == 0.0)) { rect.Y++; rect.Height--; } rect.Width--; // Recalculate colours Color textColor = taskItem.TaskTextColor; Color borderColor = taskItem.TaskTextColor; Color fillColor = DrawingColor.SetLuminance(taskItem.TaskTextColor, 0.95f); Color barColor = taskItem.TaskTextColor; if (taskItem.HasTaskTextColor) { if (isSelected) { textColor = DrawingColor.SetLuminance(taskItem.TaskTextColor, 0.3f); } else if (m_TaskColorIsBkgnd && !taskItem.IsDone) { textColor = DrawingColor.GetBestTextColor(taskItem.TaskTextColor); borderColor = DrawingColor.AdjustLighting(taskItem.TaskTextColor, -0.5f, true); barColor = taskItem.TaskTextColor; fillColor = taskItem.TaskTextColor; } } using (StringFormat format = new StringFormat()) { format.Alignment = StringAlignment.Near; format.LineAlignment = (longAppt ? StringAlignment.Center : StringAlignment.Near); // Draw the background of the appointment if (isSelected) { m_SelectionRect.Draw(m_hWnd, g, rect.Left, rect.Top, rect.Width, rect.Height); } else { using (SolidBrush brush = new SolidBrush(fillColor)) g.FillRectangle(brush, rect); } // Draw appointment border if needed if (!isSelected && taskItem.DrawBorder) { using (Pen pen = new Pen(borderColor, 1)) g.DrawRectangle(pen, rect); } // Draw appointment icon bool hasIcon = false; taskItem.IconRect = Rectangle.Empty; if (TaskHasIcon(taskItem)) { Rectangle rectIcon; int imageSize = DPIScaling.Scale(16); if (taskItem.IsLongAppt()) { int yCentre = ((rect.Top + rect.Bottom + 1) / 2); rectIcon = new Rectangle((rect.Left + 2), (yCentre - (imageSize / 2)), imageSize, imageSize); } else { rectIcon = new Rectangle(rect.Left + 2, rect.Top + 2, imageSize, imageSize); } if (Rectangle.Round(g.VisibleClipBounds).Contains(rectIcon) && m_TaskIcons.Get(taskItem.Id)) { if (longAppt) { rectIcon.X = (gripRect.Right + 2); } else { gripRect.Y += (imageSize + 2); gripRect.Height -= (imageSize + 2); } m_TaskIcons.Draw(g, rectIcon.X, rectIcon.Y); hasIcon = true; taskItem.IconRect = rectIcon; rect.Width -= (rectIcon.Right - rect.Left); rect.X = rectIcon.Right; } } // Draw gripper bar if (gripRect.Width > 0) { using (SolidBrush brush = new SolidBrush(barColor)) g.FillRectangle(brush, gripRect); // Draw gripper border using (Pen pen = new Pen(DrawingColor.AdjustLighting(barColor, -0.5f, true), 1)) g.DrawRectangle(pen, gripRect); if (!hasIcon) { rect.X = gripRect.Right; rect.Width -= (gripRect.Width + 4); } } // draw appointment text rect.Y += 3; if (longAppt) { rect.Height = m_BaseFont.Height; } else { rect.Height -= 3; } g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; using (SolidBrush brush = new SolidBrush(textColor)) g.DrawString(appointment.Title, this.BaseFont, brush, rect, format); g.TextRenderingHint = TextRenderingHint.SystemDefault; } } }
override protected bool MoveAppointment(System.Windows.Forms.MouseEventArgs e) { // Default implementation handles move WITHIN the respective // 'long/short appointments' regions if (base.MoveAppointment(e)) { return(true); } // whilst we handle transitions BETWEEN the regions // Note: we need to duplicate some of the base checks // because we don't know what failed if (EditMode != Mode.Move) { return(false); } Rectangle shortApptsRect = DayView.GetTrueRectangle(); Rectangle longApptsRect = DayView.GetFullDayApptsRectangle(); // Make sure the long appointments rect has a reasonable height if (longApptsRect.Height < DayView.LongAppointmentHeight) { int adjustment = (DayView.LongAppointmentHeight - longApptsRect.Height); longApptsRect.Y -= adjustment; longApptsRect.Height += adjustment; } if (!shortApptsRect.Contains(e.Location) && !longApptsRect.Contains(e.Location)) { return(false); } // _ _________________________________________ // | ____________ | // | | | | // longApptsRect | | long | ^ | // | |____________| | | // _ |---------|---------------------|---------| // | | | | // | V __|__ | // | | | | // | | | | // | | | | // shortApptsRect | |short| | // | | | | // | | | | // | | | | // | |_____| | // | | // _ |_________________________________________| CalendarItem selection = (DayView.SelectedAppointment as CalendarItem); bool longAppt = selection.IsLongAppt(); bool shortAppt = !longAppt; bool curPtInLongApptsRect = longApptsRect.Contains(e.Location); bool prevPtInLongApptsRect = longApptsRect.Contains(m_lastMouseMove); bool curPtInShortApptsRect = shortApptsRect.Contains(e.Location); bool prevPtInShortApptsRect = shortApptsRect.Contains(m_lastMouseMove); TimeSpan length = TimeSpan.Zero; DateTime dateAtCursor = DayView.GetDateTimeAt(e.X, e.Y, curPtInLongApptsRect); if (shortAppt && prevPtInShortApptsRect && curPtInLongApptsRect) { // Short appointment dragged into long appointment rect m_Transitioned = !base.IsEditingLongAppt; // If the appointment was originally a long appointment we // restore the original length else create a day-long task length = (m_Transitioned ? new TimeSpan(24, 0, 0) : selection.OriginalLength); } else if (longAppt && prevPtInLongApptsRect && curPtInShortApptsRect) { // Long appointment dragged into short appointment rect m_Transitioned = base.IsEditingLongAppt; // If the appointment was originally a long appointment we // restore the original length else create a 3-hour task length = (m_Transitioned ? new TimeSpan(3, 0, 0) : selection.OriginalLength); } if (length != TimeSpan.Zero) { selection.StartDate = dateAtCursor.AddHours(-length.TotalHours / 2); selection.EndDate = selection.StartDate.Add(length); m_delta = (selection.StartDate - dateAtCursor); m_length = TimeSpan.Zero; return(true); } // all else return(false); }