Exemple #1
0
        private void ListDragTarget_DragDrop(object sender, System.Windows.Forms.DragEventArgs e)
        {
            // Ensure that the list item index is contained in the data.
            if (TaskListBox.IsValidDragData(e.Data))
            {
                // Perform drag-and-drop, depending upon the effect.
                if (e.Effect == DragDropEffects.Copy ||
                    e.Effect == DragDropEffects.Move)
                {
                    AbstractProcessingTask task = null;
                    if (TaskListBox.DragDataSource(e.Data) == ListDragTarget)
                    {
                        task = (AbstractProcessingTask)(TaskListBox.DragDataTask(e.Data));
                    }
                    else                     // if we are comming from source list => Create a new instance
                    if (task == null)
                    {
                        task = TaskListBox.DragDataTask(e.Data).Clone();
                    }

                    if (ListDragTarget.IsValidInsertionIndex(IndexOfItemUnderMouseToDrop, task, In))                     // if place is ok
                    {
                        ((TaskListBox)sender).Insert(IndexOfItemUnderMouseToDrop, task);
                    }
                    else if (TaskListBox.DragDataSource(e.Data) == ListDragTarget)                     // if place is not ok, but we came from the destination listbox, we reinsert the task when she come from
                    {
                        ((TaskListBox)sender).Insert(TaskListBox.DragDataIndex(e.Data), task);
                    }
                    ListDragTarget.Invalidate();
                    IndexOfItemUnderMouseToDrop = ListBox.NoMatches;
                }
            }
            AlignTaskEnable();
            AlignHelpMessage();
        }
Exemple #2
0
        private void ListDragTarget_DragOver(object sender, System.Windows.Forms.DragEventArgs e)
        {
            // Determine whether string data exists in the drop data. If not, then
            // the drop effect reflects that the drop cannot occur.
            bool valid = TaskListBox.IsValidDragData(e.Data);

            if (!valid)
            {
                e.Effect = DragDropEffects.None;
                return;
            }

            int lastIndex = IndexOfItemUnderMouseToDrop;

            IndexOfItemUnderMouseToDrop = ListDragTarget.IndexFromPoint(ListDragTarget.PointToClient(new Point(e.X, e.Y)));

            if (sender == ListDragTarget)
            {
                if (IndexOfItemUnderMouseToDrop == -1)
                {
                    IndexOfItemUnderMouseToDrop = ListDragTarget.Count;
                }

                ListDragTarget.Invalidate(lastIndex);
                ListDragTarget.Invalidate(IndexOfItemUnderMouseToDrop);

                if (ListDragTarget.IsValidInsertionIndex(IndexOfItemUnderMouseToDrop, TaskListBox.DragDataTask(e.Data), In))
                {
                    e.Effect = DragDropEffects.Copy;
                    return;
                }
                else
                {
                    IndexOfItemUnderMouseToDrop = -1;
                    e.Effect = DragDropEffects.Move;
                    return;
                }
            }
            e.Effect = DragDropEffects.Move;
        }
Exemple #3
0
        private void ListDragSource_DrawItem(object sender, DrawItemEventArgs e)
        {
            TaskListBox listbox = (TaskListBox)sender;

            listbox.DrawTask(e.Graphics, e.Index, e.Bounds, !this.Enabled, true);
            if (sender == ListDragTarget)
            {
                e.Graphics.Clip = new Region();
                using (Pen p = new Pen(ForeColor, 3))
                {
                    if (IndexOfItemUnderMouseToDrop == e.Index)
                    {
                        e.Graphics.DrawLine(p, e.Bounds.X, e.Bounds.Top + 2, e.Bounds.Right, e.Bounds.Top + 2);
                    }
                    else if (IndexOfItemUnderMouseToDrop == listbox.Count && e.Index == listbox.Count - 1)
                    {
                        e.Graphics.DrawLine(p, e.Bounds.X, e.Bounds.Bottom - 2, e.Bounds.Right, e.Bounds.Bottom - 2);
                    }
                }
            }
            e.DrawFocusRectangle();
        }
Exemple #4
0
 public DragData(TaskListBox source, int index)
 {
     Source = source;
     Index  = index;
     Task   = source.Get(index);
 }
Exemple #5
0
        public void AlignTaskEnable(TaskListBox destListBox)
        {
            List <AbstractProcessingTask> alreadySelectedTask = new List <AbstractProcessingTask>();

            foreach (AbstractProcessingTask task in destListBox.Items)
            {
                alreadySelectedTask.Add(task);
            }

            bool somethingchange = false;
            bool oneNotReady     = false;
            List <AbstractProcessingTask> candidateTask = new List <AbstractProcessingTask>();

            if (this != destListBox)
            {
                candidateTask = new List <AbstractProcessingTask>(this.AllTask);
            }
            else
            {
                candidateTask = new List <AbstractProcessingTask>(Items.OfType <AbstractProcessingTask>());
            }


            for (int s = 0; s < candidateTask.Count; s++)
            {
                AbstractProcessingTask task = (AbstractProcessingTask)candidateTask[s];
                int  count = alreadySelectedTask.Count;
                bool insertionPointFound = false;
                for (int d = 0; d <= count && !insertionPointFound; d++)
                {
                    AbstractProcessingTask prev = d == 0 ? null : alreadySelectedTask[d - 1];
                    AbstractProcessingTask next = d == count ? null : alreadySelectedTask[d];
                    insertionPointFound = task.CanInsert(prev, next);
                }
                somethingchange |= this.GetTaskEnabled(task) != insertionPointFound;
                this.SetTaskEnabled(task, insertionPointFound);
                oneNotReady |= !task.Ready;
            }
            bool notreadyChange = lastOnNotReady != oneNotReady;

            lastOnNotReady = oneNotReady;
            if (somethingchange || notreadyChange)
            {
                SuspendLayout();
                bool sort = this != destListBox;
                if (sort)
                {
                    List <AbstractProcessingTask> enabled  = new List <AbstractProcessingTask>();
                    List <AbstractProcessingTask> disabled = new List <AbstractProcessingTask>();
                    for (int i = 0; i < candidateTask.Count; i++)
                    {
                        AbstractProcessingTask task = candidateTask[i];
                        if (GetTaskEnabled(task))
                        {
                            enabled.Add(task);
                        }
                        else
                        {
                            disabled.Add(task);
                        }
                    }
                    enabled.Sort();
                    disabled.Sort();
                    Items.Clear();
                    Items.AddRange(enabled.ToArray());
                    //Items.AddRange(disabled.ToArray());
                }
                Invalidate();
                ResumeLayout();
            }
            if (oneNotReady)
            {
                InvalidateNotReady();
            }
        }
Exemple #6
0
        private void ListDragSource_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            if ((e.Button & MouseButtons.Left) == MouseButtons.Left)
            {
                if (!ListDragTarget.Lock)
                {
                    bool draggable = true;
                    if (sender == ListDragTarget)
                    {
                        draggable = ListDragTarget.RemovableForTaskFlow(IndexOfItemUnderMouseToDrag);
                    }
                    if (!draggable)
                    {
                        Cursor.Current = Cursors.No;
                    }
                    // If the mouse moves outside the rectangle, start the drag.
                    if (draggable && dragBoxFromMouseDown != Rectangle.Empty &&
                        !dragBoxFromMouseDown.Contains(e.X, e.Y))
                    {
                        // Create custom cursors for the drag-and-drop operation.
                        try
                        {
                            TaskListBox ctrl = (TaskListBox)sender;

                            MyNormalCursor = ctrl.CreateCursor(IndexOfItemUnderMouseToDrag, true);
                            MyNodropCursor = ctrl.CreateCursor(IndexOfItemUnderMouseToDrag, false);
                        }
                        catch
                        {
                        }
                        finally
                        {
                            // The screenOffset is used to account for any desktop bands
                            // that may be at the top or left side of the screen when
                            // determining when to cancel the drag drop operation.
                            screenOffset = SystemInformation.WorkingArea.Location;
                            object data = ((TaskListBox)sender).GetDragData(IndexOfItemUnderMouseToDrag);
                            if (sender == ListDragTarget)
                            {
                                ((TaskListBox)sender).RemoveAt(IndexOfItemUnderMouseToDrag);
                                AlignHelpMessage();
                            }
                            // Proceed with the drag-and-drop, passing in the list item.
                            DragDropEffects dropEffect = ((TaskListBox)sender).DoDragDrop(data, DragDropEffects.All | DragDropEffects.Copy);

                            // Dispose of the cursors since they are no longer needed.
                            if (MyNormalCursor != null)
                            {
                                MyNormalCursor.Dispose();
                            }
                            if (MyNodropCursor != null)
                            {
                                MyNodropCursor.Dispose();
                            }
                        }
                    }
                }
            }
            else
            {
                if (sender is TaskListBox)
                {
                    TaskListBox listbox         = (TaskListBox)sender;
                    int         newHoveredIndex = listbox.IndexFromPoint(e.Location);
                    if (newHoveredIndex == -1)
                    {
                        this.ToolTip.ShowAlways = false;
                    }
                    if (hoveredIndex != newHoveredIndex)
                    {
                        hoveredIndex = newHoveredIndex;
                        if (hoveredIndex > -1)
                        {
                            AbstractProcessingTask task = listbox.Get(hoveredIndex);
                            if (task != null)
                            {
                                this.ToolTip.Active = false;
                                this.ToolTip.SetToolTip(listbox, task.ToolTip);
                                this.ToolTip.Active     = true;
                                this.ToolTip.ShowAlways = true;
                            }
                        }
                    }
                }
            }
        }
Exemple #7
0
			public DragData(TaskListBox source, int index)
			{
				Source = source;
				Index = index;
				Task = source.Get(index);
			}
Exemple #8
0
		public void AlignTaskEnable(TaskListBox destListBox)
		{
			List<AbstractProcessingTask> alreadySelectedTask = new List<AbstractProcessingTask>();
			foreach (AbstractProcessingTask task in destListBox.Items)
				alreadySelectedTask.Add(task);

			bool somethingchange = false;
			bool oneNotReady=false;
			List<AbstractProcessingTask> candidateTask = new List<AbstractProcessingTask>();
			if (this != destListBox)
				candidateTask = new List<AbstractProcessingTask>(this.AllTask);
			else
				candidateTask = new List<AbstractProcessingTask>(Items.OfType<AbstractProcessingTask>());


			for (int s = 0; s < candidateTask.Count; s++)
			{
				AbstractProcessingTask task = (AbstractProcessingTask)candidateTask[s];
				int count = alreadySelectedTask.Count;
				bool insertionPointFound = false;
				for (int d = 0; d <= count && !insertionPointFound; d++)
				{
					AbstractProcessingTask prev = d == 0 ? null : alreadySelectedTask[d - 1];
					AbstractProcessingTask next = d == count ? null : alreadySelectedTask[d];
					insertionPointFound = task.CanInsert(prev, next);

				}
				somethingchange |= this.GetTaskEnabled(task) != insertionPointFound;
				this.SetTaskEnabled(task, insertionPointFound);
				oneNotReady |= !task.Ready;
			}
			bool notreadyChange = lastOnNotReady != oneNotReady;
			lastOnNotReady = oneNotReady;
			if (somethingchange || notreadyChange)
			{
				SuspendLayout();
				bool sort = this != destListBox;
				if (sort)
				{
					List<AbstractProcessingTask> enabled = new List<AbstractProcessingTask>();
					List<AbstractProcessingTask> disabled = new List<AbstractProcessingTask>();
					for (int i = 0; i < candidateTask.Count; i++)
					{
						AbstractProcessingTask task = candidateTask[i];
						if (GetTaskEnabled(task))
							enabled.Add(task);
						else
							disabled.Add(task);
					}
					enabled.Sort();
					disabled.Sort();
					Items.Clear();
					Items.AddRange(enabled.ToArray());
					//Items.AddRange(disabled.ToArray());
				}
				Invalidate();
				ResumeLayout();
			}
			if (oneNotReady)
				InvalidateNotReady();
		}