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(); }
protected bool GetTaskEnabled(AbstractProcessingTask task) { if (!m_SourceTaskEnableStatus.ContainsKey(task)) { m_SourceTaskEnableStatus.Add(task, true); } return(m_SourceTaskEnableStatus[task]); }
protected AbstractProcessingTask Change(AbstractProcessingTask oldTask, AbstractProcessingTask newTask) { bool enabled = GetTaskEnabled(oldTask); m_SourceTaskEnableStatus.Remove(oldTask); SetTaskEnabled(newTask, enabled); return(newTask); }
private void DragDropTaskList_Load(object sender, EventArgs e) { if (this.IsDesignMode()) { return; } MessageLabel.ForeColor = SkinInfo.ForeColor.GetStepColor(SkinInfo.BackColor, 0.5); FileDialog.Filter = "Process File (*.process.xml)|*.process.xml"; FileDialog.InitialDirectory = Program.ProcessPath; if (!Directory.Exists(Program.ProcessPath)) { Directory.CreateDirectory(Program.ProcessPath); } try { /* * var availabelTaskType = AppDomain.CurrentDomain.GetAssemblies() * .SelectMany(assembly => assembly.GetTypes()) * .Where(type => type.IsSubclassOf(typeof(AbstractProcessingTask))); * foreach (Type type in availabelTaskType) * { * if (!type.IsAbstract) * { * BrowsableAttribute attribute = Attribute.GetCustomAttribute(type, typeof(BrowsableAttribute)) as BrowsableAttribute; * if (attribute == null || (attribute != null && attribute.Browsable)) * { * AbstractProcessingTask task = (AbstractProcessingTask)Activator.CreateInstance(type); * AbstractProcessingTask settingsTask = task.LoadFromFile(Program.TaskConfigPath); * if (settingsTask != null) * task = settingsTask; * tasks.Add(task); * } * } * } * * tasks.Sort(); */ List <AbstractProcessingTask> tasks = new List <AbstractProcessingTask>(); var availabelTaskType = Reflector.GetSubClassOf(typeof(AbstractProcessingTask)); foreach (Type type in availabelTaskType) { AbstractProcessingTask task = (AbstractProcessingTask)Activator.CreateInstance(type); AbstractProcessingTask settingsTask = task.LoadFromFile(Program.TaskPath); if (settingsTask != null) { task = settingsTask; } tasks.Add(task); } this.ListDragSource.SetStartupTask(tasks); AlignTaskEnable(); } catch { } }
protected void SetTaskEnabled(AbstractProcessingTask task, bool enable) { if (m_SourceTaskEnableStatus.ContainsKey(task)) { m_SourceTaskEnableStatus[task] = enable; } else { m_SourceTaskEnableStatus.Add(task, enable); } }
public void Invalidate(AbstractProcessingTask task) { if (task != null) { Invalidate(Items.IndexOf(task)); } else { Invalidate(); } this.Update(); }
public void Insert(int index, AbstractProcessingTask task) { SuspendLayout(); if (index < 0 || index >= this.Items.Count) { Items.Add(task); } else { Items.Insert(index, task); } ResumeLayout(); }
public void Remove(AbstractProcessingTask task) { SuspendLayout(); if (task == null) { return; } m_SourceTaskEnableStatus.Remove(task); int index = Items.IndexOf(task); Items.RemoveAt(index); ResumeLayout(); }
public bool Add(AbstractProcessingTask task) { if (task != null) { if (IsValidInsertionIndex(Count, task, eTaskItem.None)) { SuspendLayout(); Items.Add(task); ResumeLayout(); return(true); } } return(false); }
public bool RemovableForTaskFlow(int index) { AbstractProcessingTask prev = Get(index - 1); AbstractProcessingTask next = Get(index + 1); if (next == null) { return(true); } if (prev == null) { return(next.In == eTaskItem.None); } return(next.CanFolow(prev)); }
public static Rectangle DrawStatus(this AbstractProcessingTask task, Graphics g, Rectangle bound, Color backColor, Color frontColor) { eTaskStatus status = task.Status; int percent = task.Percent; if (status == eTaskStatus.Working) { return(DrawProgress(g, bound, percent, backColor, frontColor)); } else if (status == eTaskStatus.Error) { return(DrawScaleImage(g, global::Sardauscan.Properties.Resources.Bug, bound)); } else if (status == eTaskStatus.Finished) { return(DrawScaleImage(g, global::Sardauscan.Properties.Resources.Check, bound)); } return(bound); }
private void List_Click(object sender, MouseEventArgs e) { bool isDefaultTask = sender == this.ListDragSource; int index = ((ListBox)sender).IndexFromPoint(e.Location); if (index != System.Windows.Forms.ListBox.NoMatches && !((TaskListBox)sender).Lock) { AbstractProcessingTask task = (AbstractProcessingTask)((ListBox)sender).Items[index]; Rectangle bounds = ((ListBox)sender).GetItemRectangle(index); int settingsSize = Math.Min(bounds.Width, bounds.Height); Rectangle settingsRect = new Rectangle(bounds.Right - settingsSize, bounds.Top, settingsSize, settingsSize); if (settingsRect.Contains(e.Location)) { if (task != null && task.HasSettings) { AbstractProcessingTask ret = PropertyForm.EditSettings(this, task, sender == ListDragSource); ((ListBox)sender).Items[index] = ret; } } } }
public AbstractProcessingTask EditSettings(IWin32Window owner, AbstractProcessingTask task, bool defaultsettings) { AbstractProcessingTask ret = task.Clone(); if (ret != null) { if (!ret.RunSettings()) { this.Grid.SelectedObject = task; if (this.ShowDialog(owner) == System.Windows.Forms.DialogResult.OK) { ret = (AbstractProcessingTask)this.Grid.SelectedObject; if (defaultsettings && task.HasBrowsableSettings) { task.SaveToFile(Program.TaskPath); } } } } return(ret); }
public bool IsValidInsertionIndex(int index, AbstractProcessingTask newTask, eTaskItem emptyTaskItem) { if (newTask == null || index == -1) { return(false); } AbstractProcessingTask prev = Get(index - 1); AbstractProcessingTask next = Get(index); if (prev == null && next == null) { return(newTask.In == emptyTaskItem); } if (prev == null) { return(newTask.In == emptyTaskItem && newTask.Out == next.In); } else if (next == null) { return(newTask.In == prev.Out); } return(newTask.In == prev.Out && newTask.Out == next.In); }
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; } } } } } }
public void RemoveAt(int index) { AbstractProcessingTask task = Get(index); Remove(task); }
public void DrawTask(Graphics g, int itemIndex, Rectangle r, bool forceDisabled, bool showsettings = false) { if (itemIndex > -1 && itemIndex < Items.Count) { AbstractProcessingTask task = Items[itemIndex] as AbstractProcessingTask; if (task == null) { return; } bool disabled = !GetTaskEnabled(task) || forceDisabled; using (SolidBrush backgroundBrush = new SolidBrush(SkinInfo.BackColor)) { // Draw the background g.FillRectangle(backgroundBrush, r); int bitmapSize = Math.Min(r.Width, r.Height); int imageOffset = 0; using (Image inImage = GetImage(task.In)) { using (Image outImage = GetImage(task.Out)) { DrawScaleImage(g, r.Location, inImage, bitmapSize, !disabled, SkinInfo.FadedColorMatrix); r.X += bitmapSize * 3 / 4; r.Width -= bitmapSize * 3 / 4; DrawScaleImage(g, r.Location, outImage, bitmapSize, !disabled, SkinInfo.FadedColorMatrix); r.X += bitmapSize; r.Width -= bitmapSize; using (Image taskImage = GetImage(task.TaskType)) { Point p = new Point((int)(r.X - bitmapSize * 1.35), r.Y); DrawScaleImage(g, p, taskImage, bitmapSize, !disabled, SkinInfo.HoverColorMatrix); } } if (r.Width <= 0) { return; } if (showsettings && task.HasSettings) { DrawScaleImage(g, new Point(r.Right - bitmapSize, r.Top), global::Sardauscan.Properties.Resources.Gears, bitmapSize, true); } r.Width -= bitmapSize; if (r.Width <= 0) { return; } r = task.DrawStatus(g, r, SkinInfo.BackColor, SkinInfo.ForeColor); if (r.Width <= 0) { return; } Color textColor = SkinInfo.ForeColor.GetStepColor(SkinInfo.BackColor, this.Lock ? 0.5 : 0); if (!task.Ready) { textColor = Color.Red; } using (SolidBrush TextBrush = new SolidBrush(textColor)) { StringFormat sf = new StringFormat(StringFormatFlags.NoWrap | StringFormatFlags.NoClip); sf.Alignment = StringAlignment.Near; sf.LineAlignment = StringAlignment.Center; Rectangle textRect = new Rectangle(r.X + imageOffset, r.Y + 0, r.Width - imageOffset, r.Height); string text = task.DisplayName; if (this.Enabled) { g.DrawString(text, this.Font, TextBrush, textRect, sf); } else { ControlPaint.DrawStringDisabled(g, text, this.Font, backgroundBrush.Color, textRect, sf); } } } } } }
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(); } }