Inheritance: Calendar.Appointment
Beispiel #1
0
        public void FixupSelection(bool scrollToTask, bool allowNotify)
        {
            // Our base class clears the selected appointment whenever
            // the week changes so we can't rely on 'SelectedAppointmentId'
            UInt32 prevSelTaskID = m_VisibleSelectedTaskID;
            UInt32 selTaskID     = GetSelectedTaskID();

            m_VisibleSelectedTaskID = selTaskID;

            if (selTaskID > 0)
            {
                CalendarItem item;

                if (m_Items.TryGetValue(selTaskID, out item))
                {
                    if (scrollToTask)
                    {
                        if (item.StartDate != DateTime.MinValue)
                        {
                            if (!IsItemWithinRange(item, StartDate, EndDate))
                            {
                                StartDate = item.StartDate;
                            }

                            SelectedAppointment = item;
                        }
                    }
                    else if (IsItemWithinRange(item, StartDate, EndDate))
                    {
                        SelectedAppointment = item;
                    }
                }
                else
                {
                    SelectedAppointment = null;
                }
            }
            else
            {
                SelectedAppointment = null;
            }

            // Notify parent of changes
            if (allowNotify && (GetSelectedTaskID() != prevSelTaskID))
            {
                CalendarItem item = null;
                m_Items.TryGetValue(m_VisibleSelectedTaskID, out item);

                RaiseSelectionChanged(item);
            }
        }
Beispiel #2
0
        protected override void DrawAppointment(Graphics g, Rectangle rect, Calendar.Appointment appointment, bool isSelected, Rectangle gripRect)
        {
            isSelected = WantDrawAppointmentSelected(appointment);

            // 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);
        }
        // --------------------

        protected CalendarItem(CalendarItem item) : base(item)
        {
            AllocTo         = item.AllocTo;
            HasIcon         = item.HasIcon;
            IsParent        = item.IsParent;
            TaskTextColor   = item.TaskTextColor;
            HasDependencies = item.HasDependencies;
            IsDone          = item.IsDone;
            IsGoodAsDone    = item.IsGoodAsDone;
            StartDate       = item.StartDate;
            EndDate         = item.EndDate;
            TimeEstimate    = item.TimeEstimate;
            TimeEstUnits    = item.TimeEstUnits;
            IsRecurring     = item.IsRecurring;
        }
Beispiel #4
0
        public bool GetSelectedItemLabelRect(ref Rectangle rect)
        {
            if (GetAppointmentRect(SelectedAppointment, ref rect))
            {
                CalendarItem selItem = (SelectedAppointment as CalendarItem);

                bool hasIcon = m_Renderer.TaskHasIcon(selItem);

                if (SelectedAppointment.IsLongAppt())
                {
                    // Gripper
                    if (SelectedAppointment.StartDate >= StartDate)
                    {
                        rect.X += 8;
                    }

                    if (hasIcon)
                    {
                        rect.X += 16;
                    }

                    rect.X      += 1;
                    rect.Height += 1;
                }
                else
                {
                    if (hasIcon)
                    {
                        rect.X += 18;
                    }
                    else
                    {
                        // Gripper
                        rect.X += 8;
                    }

                    rect.X += 1;
                    rect.Y += 1;

                    rect.Height = (GetFontHeight() + 4);                     // 4 = border
                }

                return(true);
            }

            // else
            return(false);
        }
Beispiel #5
0
        private bool IsItemWithinRange(CalendarItem item, DateTime startDate, DateTime endDate)
        {
            if (HideParentTasks && item.IsParent)
            {
                return(false);
            }

            if (!item.HasValidDates())
            {
                return(false);
            }

            bool startDateInRange = IsDateWithinRange(item.StartDate, startDate, endDate);
            bool endDateInRange   = IsDateWithinRange(item.EndDate, startDate, endDate);

            // As a bare minimum, at least one of the task's dates must fall in the week
            if (!startDateInRange && !endDateInRange)
            {
                return(false);
            }

            if (HideTasksSpanningWeekends)
            {
                if (!startDateInRange || !endDateInRange)
                {
                    return(false);
                }
            }

            if (HideTasksSpanningDays)
            {
                if (item.StartDate.Date != item.EndDate.Date)
                {
                    return(false);
                }
            }

            if (HideTasksWithoutTimes)
            {
                if (CalendarItem.IsStartOfDay(item.StartDate) && CalendarItem.IsEndOfDay(item.EndDate))
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #6
0
        private void OnDayViewAppointmentChanged(object sender, Calendar.AppointmentEventArgs args)
        {
            Calendar.MoveAppointmentEventArgs move = args as Calendar.MoveAppointmentEventArgs;

            // Ignore moves whilst they are occurring
            if ((move == null) || !move.Finished)
            {
                return;
            }

            CalendarItem item = args.Appointment as CalendarItem;

            if (item == null)
            {
                return;
            }

            UIExtension.ParentNotify notify = new UIExtension.ParentNotify(m_hwndParent);

            switch (move.Mode)
            {
            case Calendar.SelectionTool.Mode.Move:
                if ((item.StartDate - item.OrgStartDate).TotalSeconds != 0.0)
                {
                    item.OrgStartDate = item.StartDate;
                    notify.NotifyMod(UIExtension.TaskAttribute.OffsetTask, args.Appointment.StartDate);
                }
                break;

            case Calendar.SelectionTool.Mode.ResizeTop:
                if ((item.StartDate - item.OrgStartDate).TotalSeconds != 0.0)
                {
                    item.OrgStartDate = item.StartDate;
                    notify.NotifyMod(UIExtension.TaskAttribute.StartDate, args.Appointment.StartDate);
                }
                break;

            case Calendar.SelectionTool.Mode.ResizeBottom:
                if ((item.EndDate - item.OrgEndDate).TotalSeconds != 0.0)
                {
                    item.OrgEndDate = item.EndDate;
                    notify.NotifyMod(UIExtension.TaskAttribute.DueDate, args.Appointment.EndDate);
                }
                break;
            }
        }
        private List <Calendar.Appointment> GetMatchingAppointments(DateTime start, DateTime end, bool sorted = false)
        {
            // Future items are always populated on demand
            m_FutureItems = new Dictionary <uint, CalendarFutureItem>();

            var    appts        = new List <Calendar.Appointment>();
            UInt32 nextFutureId = (((m_MaxTaskID / 1000) + 1) * 1000);

            foreach (System.Collections.Generic.KeyValuePair <UInt32, CalendarItem> pair in m_Items)
            {
                CalendarItem item = pair.Value;

                if (IsItemWithinRange(item, start, end))
                {
                    appts.Add(item);
                }

                if (m_ShowFutureOcurrences && item.IsRecurring)
                {
                    // Add this task's future items for the current date range
                    // Note: we deliberately double the range else we lose
                    // future items which overlap the the current item
                    var futureItems = m_TaskRecurrences.Get(item.Id, StartDate, EndDate.AddDays(DaysShowing));

                    if (futureItems != null)
                    {
                        foreach (var futureItem in futureItems)
                        {
                            var futureAppt = new CalendarFutureItem(item, nextFutureId, futureItem);

                            m_FutureItems[nextFutureId] = futureAppt;
                            appts.Add(futureAppt);

                            nextFutureId++;
                        }
                    }
                }
            }

            if (sorted)
            {
                appts.Sort((a, b) => (int)(b.StartDate.Ticks - a.StartDate.Ticks));
            }

            return(appts);
        }
Beispiel #8
0
        private bool CanResizeTask(CalendarItem taskItem, Calendar.SelectionTool.Mode mode)
        {
            switch (mode)
            {
            // Disable start date editing for tasks with dependencies that are auto-calculated
            case Calendar.SelectionTool.Mode.ResizeTop:
            case Calendar.SelectionTool.Mode.ResizeLeft:
            case Calendar.SelectionTool.Mode.Move:
                return(!taskItem.HasDependencies || !AutoCalculateDependencyDates);

            case Calendar.SelectionTool.Mode.ResizeBottom:
            case Calendar.SelectionTool.Mode.ResizeRight:
                return(true);
            }

            // catch all
            return(false);
        }
Beispiel #9
0
        public bool IsItemDisplayable(CalendarItem item)
        {
            // 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);
            }

            if (HideTasksSpanningWeekends)
            {
                if (DateUtil.WeekOfYear(item.StartDate) != DateUtil.WeekOfYear(item.EndDate))
                {
                    return(false);
                }
            }

            if (HideTasksSpanningDays)
            {
                if (item.StartDate.Date != item.EndDate.Date)
                {
                    return(false);
                }
            }

            if (HideTasksWithoutTimes)
            {
                if (CalendarItem.IsStartOfDay(item.StartDate) && CalendarItem.IsEndOfDay(item.EndDate))
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #10
0
        public bool PrepareNewTask(ref Task task)
        {
            // Set the start/due dates to match the current selection
            if (m_DayView.SelectionStart < m_DayView.SelectionEnd)
            {
                task.SetStartDate(m_DayView.SelectionStart);

                DateTime endDate = m_DayView.SelectionEnd;

                if (CalendarItem.IsStartOfDay(endDate))
                {
                    endDate = endDate.AddSeconds(-1);
                }

                task.SetDueDate(endDate);
            }

            return(true);
        }
        // --------------------

        protected CalendarItem(CalendarItem item) : base(item)
        {
            if (item == null)
            {
                return;
            }

            AllocTo         = item.AllocTo;
            HasIcon         = item.HasIcon;
            IsParent        = item.IsParent;
            TaskTextColor   = item.TaskTextColor;
            HasDependencies = item.HasDependencies;
            IsDone          = item.IsDone;
            IsGoodAsDone    = item.IsGoodAsDone;
            TimeEstimate    = item.TimeEstimate;
            TimeEstUnits    = item.TimeEstUnits;

            UpdateOriginalDates();
        }
Beispiel #12
0
        public bool IsItemDisplayable(CalendarItem item)
        {
            if (item == null)
            {
                return(false);
            }

            if (HideParentTasks && item.IsParent)
            {
                return(false);
            }

            if (!item.HasValidDates())
            {
                return(false);
            }

            if (HideTasksSpanningWeekends)
            {
                if (DateUtil.WeekOfYear(item.StartDate) != DateUtil.WeekOfYear(item.EndDate))
                {
                    return(false);
                }
            }

            if (HideTasksSpanningDays)
            {
                if (item.StartDate.Date != item.EndDate.Date)
                {
                    return(false);
                }
            }

            if (HideTasksWithoutTimes)
            {
                if (CalendarItem.IsStartOfDay(item.StartDate) && CalendarItem.IsEndOfDay(item.EndDate))
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #13
0
        private void ProcessTaskAppointmentChange(CalendarItem item, Calendar.SelectionTool.Mode mode)
        {
            var notify = new UIExtension.ParentNotify(m_HwndParent);

            if (PrepareTaskNotify(item, mode, notify))
            {
                bool modifyTimeEst = WantModifyTimeEstimate(item);

                if (notify.NotifyMod())
                {
                    item.UpdateOriginalDates();

                    if (modifyTimeEst)
                    {
                        item.TimeEstimate = item.LengthAsTimeEstimate(m_WorkWeek, false);
                    }

                    return;
                }
            }

            item.RestoreOriginalDates();
            m_DayView.Invalidate();
        }
Beispiel #14
0
        private bool PrepareTaskNotify(CalendarItem item, Calendar.SelectionTool.Mode mode, UIExtension.ParentNotify notify, bool includeTimeEstimate = true)
        {
            switch (mode)
            {
            case Calendar.SelectionTool.Mode.Move:
                if (item.LengthDiffersFromOriginal())
                {
                    // Start date WITHOUT TIME ESTIMATE
                    PrepareTaskNotify(item, Calendar.SelectionTool.Mode.ResizeLeft, notify, false);

                    // End date WITHOUT TIME ESTIMATE
                    PrepareTaskNotify(item, Calendar.SelectionTool.Mode.ResizeRight, notify, false);

                    if (includeTimeEstimate && WantModifyTimeEstimate(item))
                    {
                        notify.AddMod(Task.Attribute.TimeEstimate, item.LengthAsTimeEstimate(m_WorkWeek, false), item.TimeEstUnits);
                    }

                    return(true);
                }
                else if (item.StartDateDiffersFromOriginal())
                {
                    notify.AddMod(Task.Attribute.OffsetTask, item.StartDate);

                    return(true);
                }
                break;

            case Calendar.SelectionTool.Mode.ResizeLeft:
            case Calendar.SelectionTool.Mode.ResizeTop:
                if (item.StartDateDiffersFromOriginal())
                {
                    notify.AddMod(Task.Attribute.StartDate, item.StartDate);

                    if (includeTimeEstimate && WantModifyTimeEstimate(item))
                    {
                        notify.AddMod(Task.Attribute.TimeEstimate, item.LengthAsTimeEstimate(m_WorkWeek, false), item.TimeEstUnits);
                    }

                    return(true);
                }
                break;

            case Calendar.SelectionTool.Mode.ResizeRight:
            case Calendar.SelectionTool.Mode.ResizeBottom:
                if (item.EndDateDiffersFromOriginal())
                {
                    // Allow for end of day
                    var endDate = item.EndDate;

                    if (endDate == endDate.Date)
                    {
                        endDate = endDate.AddDays(-1);
                    }

                    if (item.IsDone)
                    {
                        notify.AddMod(Task.Attribute.DoneDate, endDate);
                    }
                    else
                    {
                        notify.AddMod(Task.Attribute.DueDate, endDate);
                    }

                    if (includeTimeEstimate && WantModifyTimeEstimate(item))
                    {
                        notify.AddMod(Task.Attribute.TimeEstimate, item.LengthAsTimeEstimate(m_WorkWeek, false), item.TimeEstUnits);
                    }

                    return(true);
                }
                break;
            }

            return(false);
        }
        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;
                }
            }
        }
Beispiel #16
0
        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);
        }
        private bool ProcessTaskUpdate(TDLTask task, 
                                       TDLUIExtension.UpdateType type,
                                       TDLUIExtension.TaskAttribute attrib)
        {
            if (!task.IsValid())
                return false;

            CalendarItem item;

            if (m_Items.TryGetValue(task.GetID(), out item))
            {
                switch (attrib)
                {
                    case TDLUIExtension.TaskAttribute.Title:
                        item.Title = task.GetTitle();
                        break;

                    case TDLUIExtension.TaskAttribute.DoneDate:
                        item.End = ToDateTime(task.GetDoneDate());
                        break;

                    case TDLUIExtension.TaskAttribute.DueDate:
                        item.End = ToDateTime(task.GetDueDate());
                        break;

                    case TDLUIExtension.TaskAttribute.StartDate:
                        item.Start = ToDateTime(task.GetStartDate());
                        break;
                }
            }
            else
            {
                item = new CalendarItem();

                item.Title = task.GetTitle();
                item.End = ToDateTime(task.GetDueDate());
                item.Start = ToDateTime(task.GetStartDate());
                item.TaskID = task.GetID();
                item.IsParent = task.GetFirstSubtask().IsValid();
            }

            m_Items[task.GetID()] = item;

            // Process children
            TDLTask subtask = task.GetFirstSubtask();

            while (subtask.IsValid() && ProcessTaskUpdate(subtask, type, attrib))
                subtask = subtask.GetNextTask();

            return true;
        }
Beispiel #18
0
 public bool TaskHasIcon(CalendarItem taskItem)
 {
     return((m_TaskIcons != null) &&
            (taskItem != null) &&
            (taskItem.HasIcon || (ShowParentsAsFolder && taskItem.IsParent)));
 }
Beispiel #19
0
        private bool ProcessTaskUpdate(Task task,
                                       UIExtension.UpdateType type,
                                       System.Collections.Generic.HashSet <UIExtension.TaskAttribute> attribs)
        {
            if (!task.IsValid())
            {
                return(false);
            }

            CalendarItem item;

            if (m_Items.TryGetValue(task.GetID(), out item))
            {
                if (attribs.Contains(UIExtension.TaskAttribute.Title))
                {
                    item.Title = task.GetTitle();
                }

                if (attribs.Contains(UIExtension.TaskAttribute.DoneDate))
                {
                    item.EndDate = item.OrgEndDate = task.GetDoneDate();
                }

                if (attribs.Contains(UIExtension.TaskAttribute.DueDate))
                {
                    item.EndDate = item.OrgEndDate = task.GetDueDate();
                }

                if (attribs.Contains(UIExtension.TaskAttribute.StartDate))
                {
                    item.StartDate = item.OrgStartDate = task.GetStartDate();
                }

                if (attribs.Contains(UIExtension.TaskAttribute.AllocTo))
                {
                    item.AllocTo = String.Join(", ", task.GetAllocatedTo());
                }

                item.TaskTextColor = task.GetTextDrawingColor();
            }
            else
            {
                item = new CalendarItem();

                item.Title         = task.GetTitle();
                item.EndDate       = item.OrgEndDate = task.GetDueDate();
                item.StartDate     = item.OrgStartDate = task.GetStartDate();
                item.AllocTo       = String.Join(", ", task.GetAllocatedTo());
                item.Id            = task.GetID();
                item.IsParent      = task.IsParent();
                item.TaskTextColor = task.GetTextDrawingColor();
                item.DrawBorder    = true;
            }

            if (item.EndDate > item.StartDate)
            {
                m_Items[task.GetID()] = item;
            }

            // Process children
            Task subtask = task.GetFirstSubtask();

            while (subtask.IsValid() && ProcessTaskUpdate(subtask, type, attribs))
            {
                subtask = subtask.GetNextTask();
            }

            return(true);
        }
Beispiel #20
0
        private void OnDayViewAppointmentChanged(object sender, Calendar.AppointmentEventArgs args)
        {
            Calendar.MoveAppointmentEventArgs move = args as Calendar.MoveAppointmentEventArgs;

            // Ignore moves whilst they are occurring
            if ((move == null) || !move.Finished)
            {
                return;
            }

            CalendarItem item = args.Appointment as CalendarItem;

            if (item == null)
            {
                return;
            }

            UIExtension.ParentNotify notify = new UIExtension.ParentNotify(m_HwndParent);

            switch (move.Mode)
            {
            case Calendar.SelectionTool.Mode.Move:
                if (item.StartDateDiffersFromOriginal())
                {
                    if (notify.NotifyMod(UIExtension.TaskAttribute.OffsetTask, item.StartDate))
                    {
                        item.UpdateOriginalDates();
                    }
                    else
                    {
                        item.RestoreOriginalDates();
                        m_DayView.Invalidate();
                    }
                }
                break;

            case Calendar.SelectionTool.Mode.ResizeLeft:
            case Calendar.SelectionTool.Mode.ResizeTop:
                if (item.StartDateDiffersFromOriginal())
                {
                    notify.AddMod(UIExtension.TaskAttribute.StartDate, item.StartDate);

                    // Update the Time estimate if it is zero or
                    // it used to match the previous date range
                    bool modifyTimeEst = WantModifyTimeEstimate(item);

                    if (modifyTimeEst)
                    {
                        notify.AddMod(UIExtension.TaskAttribute.TimeEstimate, item.LengthAsTimeEstimate(false), item.TimeEstUnits);
                    }

                    if (notify.NotifyMod())
                    {
                        item.UpdateOriginalDates();

                        if (modifyTimeEst)
                        {
                            item.TimeEstimate = item.LengthAsTimeEstimate(false);
                        }
                    }
                    else
                    {
                        item.RestoreOriginalDates();
                        m_DayView.Invalidate();
                    }
                }
                break;

            case Calendar.SelectionTool.Mode.ResizeRight:
            case Calendar.SelectionTool.Mode.ResizeBottom:
                if (item.EndDateDiffersFromOriginal())
                {
                    // Allow for end of day
                    var endDate = item.EndDate;

                    if (endDate == endDate.Date)
                    {
                        endDate = endDate.AddDays(-1);
                    }

                    if (item.IsDone)
                    {
                        notify.AddMod(UIExtension.TaskAttribute.DoneDate, endDate);
                    }
                    else
                    {
                        notify.AddMod(UIExtension.TaskAttribute.DueDate, endDate);
                    }

                    // Update the Time estimate if used to match the previous date range
                    bool modifyTimeEst = WantModifyTimeEstimate(item);

                    if (modifyTimeEst)
                    {
                        notify.AddMod(UIExtension.TaskAttribute.TimeEstimate, item.LengthAsTimeEstimate(false), item.TimeEstUnits);
                    }

                    if (notify.NotifyMod())
                    {
                        item.UpdateOriginalDates();

                        if (modifyTimeEst)
                        {
                            item.TimeEstimate = item.LengthAsTimeEstimate(false);
                        }
                    }
                    else
                    {
                        item.RestoreOriginalDates();
                        m_DayView.Invalidate();
                    }
                }
                break;
            }
        }
        private bool ProcessTaskUpdate(TDLTask task, 
									   TDLUIExtension.UpdateType type,
                                       System.Collections.Generic.HashSet<TDLUIExtension.TaskAttribute> attribs)
        {
            if (!task.IsValid())
                return false;

            CalendarItem item;

            if (m_Items.TryGetValue(task.GetID(), out item))
            {
                if (attribs.Contains(TDLUIExtension.TaskAttribute.Title))
                    item.Title = task.GetTitle();

                if (attribs.Contains(TDLUIExtension.TaskAttribute.DoneDate))
                    item.EndDate = item.OrgEndDate = task.GetDoneDate();

                if (attribs.Contains(TDLUIExtension.TaskAttribute.DueDate))
                    item.EndDate = item.OrgEndDate = task.GetDueDate();

                if (attribs.Contains(TDLUIExtension.TaskAttribute.StartDate))
                    item.StartDate = item.OrgStartDate = task.GetStartDate();

                if (attribs.Contains(TDLUIExtension.TaskAttribute.AllocTo))
                    item.AllocTo = String.Join(", ", task.GetAllocatedTo());

                item.TaskTextColor = task.GetTextDrawingColor();
            }
            else
            {
                item = new CalendarItem();

                item.Title = task.GetTitle();
                item.EndDate = item.OrgEndDate = task.GetDueDate();
                item.StartDate = item.OrgStartDate = task.GetStartDate();
                item.AllocTo = String.Join(", ", task.GetAllocatedTo());
                item.Id = task.GetID();
                item.IsParent = task.IsParent();
                item.TaskTextColor = task.GetTextDrawingColor();
                item.DrawBorder = true;
            }

            if (item.EndDate > item.StartDate)
                m_Items[task.GetID()] = item;

            // Process children
            TDLTask subtask = task.GetFirstSubtask();

            while (subtask.IsValid() && ProcessTaskUpdate(subtask, type, attribs))
                subtask = subtask.GetNextTask();

            return true;
        }
 private bool IsItemWithinRange(CalendarItem item, DateTime startDate, DateTime endDate)
 {
     return ((item.StartDate >= startDate) && (item.EndDate <= endDate));
 }
Beispiel #23
0
        public override void DrawAppointment(Graphics g, Rectangle rect, Calendar.Appointment appointment, bool isLong, bool isSelected, 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);

                UInt32 taskId     = taskItem.Id;
                UInt32 realTaskId = GetRealTaskId(taskItem);

                bool isFutureItem = (taskId != realTaskId);

                // Recalculate colours
                Color textColor = taskItem.TaskTextColor;
                Color fillColor = DrawingColor.SetLuminance(textColor, 0.95f);

                if (isFutureItem)
                {
                    fillColor = SystemColors.Window;

                    float textLum = DrawingColor.GetLuminance(textColor);
                    textColor = DrawingColor.SetLuminance(textColor, Math.Min(textLum + 0.2f, 0.7f));
                }

                Color borderColor = textColor;
                Color barColor    = textColor;

                if (taskItem.HasTaskTextColor)
                {
                    if (isSelected)
                    {
                        textColor = DrawingColor.SetLuminance(textColor, 0.3f);
                    }
                    else if (TaskColorIsBackground && !taskItem.IsDoneOrGoodAsDone && !isFutureItem)
                    {
                        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 (isLong)
                    {
                        rect.Height++;
                    }

                    if (isFutureItem)
                    {
                        UIExtension.SelectionRect.Draw(m_hWnd,
                                                       g,
                                                       rect.Left,
                                                       rect.Top,
                                                       rect.Width,
                                                       rect.Height,
                                                       UIExtension.SelectionRect.Style.DropHighlighted,
                                                       false);                                                          // opaque
                    }
                    else
                    {
                        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 (!isLong)
                        {
                            rect.Height--;                             // drawing with pen adds 1 to height
                            rect.Width--;
                        }


                        using (Pen pen = new Pen(borderColor, 1))
                        {
                            if (isFutureItem)
                            {
                                pen.DashStyle = DashStyle.Dash;
                            }

                            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 (isLong)
                    {
                        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(realTaskId))
                    {
                        if (isLong)
                        {
                            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 (!isLong)
                    {
                        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 = (isLong ? StringAlignment.Center : StringAlignment.Near);

                    rect.Y += 3;

                    if (isLong)
                    {
                        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;
                }
            }
        }
Beispiel #24
0
 private bool IsItemWithinRange(CalendarItem item, DateTime startDate, DateTime endDate)
 {
     return((item.StartDate >= startDate) && (item.EndDate <= endDate));
 }