[3595] | 1 | #region License Information
|
---|
[3565] | 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
[3595] | 24 | using System.ComponentModel;
|
---|
[3565] | 25 | using System.Drawing;
|
---|
[3595] | 26 | using System.Data;
|
---|
| 27 | using System.Linq;
|
---|
| 28 | using System.Text;
|
---|
[3565] | 29 | using System.Windows.Forms;
|
---|
| 30 | using HeuristicLab.Collections;
|
---|
| 31 | using HeuristicLab.MainForm;
|
---|
| 32 |
|
---|
| 33 | namespace HeuristicLab.Core.Views {
|
---|
| 34 | /// <summary>
|
---|
| 35 | /// The visual representation of a list of checked items.
|
---|
| 36 | /// </summary>
|
---|
| 37 | [View("CheckedItemList View")]
|
---|
| 38 | [Content(typeof(CheckedItemList<>), true)]
|
---|
[3628] | 39 | [Content(typeof(ICheckedItemList<>), true)]
|
---|
[3595] | 40 | public partial class CheckedItemListView<T> : ItemListView<T> where T : class, IItem {
|
---|
[3565] | 41 | public new ICheckedItemList<T> Content {
|
---|
| 42 | get { return (ICheckedItemList<T>)base.Content; }
|
---|
| 43 | set { base.Content = value; }
|
---|
| 44 | }
|
---|
| 45 |
|
---|
[3595] | 46 | public CheckedItemListView()
|
---|
| 47 | : base() {
|
---|
| 48 | InitializeComponent();
|
---|
[3565] | 49 | }
|
---|
| 50 |
|
---|
[3595] | 51 | protected override void RegisterContentEvents() {
|
---|
| 52 | Content.CheckedItemsChanged += new CollectionItemsChangedEventHandler<IndexedItem<T>>(Content_CheckedItemsChanged);
|
---|
| 53 | base.RegisterContentEvents();
|
---|
[3565] | 54 | }
|
---|
| 55 | protected override void DeregisterContentEvents() {
|
---|
| 56 | Content.CheckedItemsChanged -= new CollectionItemsChangedEventHandler<IndexedItem<T>>(Content_CheckedItemsChanged);
|
---|
| 57 | base.DeregisterContentEvents();
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | protected override void OnContentChanged() {
|
---|
| 61 | base.OnContentChanged();
|
---|
[3788] | 62 | base.itemsListView.Enabled = !this.Locked;
|
---|
[3565] | 63 | }
|
---|
| 64 |
|
---|
[3595] | 65 | protected override ListViewItem CreateListViewItem(T item) {
|
---|
| 66 | ListViewItem listViewItem = base.CreateListViewItem(item);
|
---|
[3565] | 67 | listViewItem.Checked = Content.ItemChecked(item);
|
---|
| 68 | return listViewItem;
|
---|
| 69 | }
|
---|
| 70 |
|
---|
[3788] | 71 | protected override void OnLockedChanged() {
|
---|
| 72 | base.OnLockedChanged();
|
---|
| 73 | base.itemsListView.Enabled = !this.Locked;
|
---|
| 74 | }
|
---|
| 75 |
|
---|
[3565] | 76 | #region ListView Events
|
---|
[3788] | 77 | private bool doubleClick;
|
---|
[3738] | 78 | protected virtual void itemsListView_ItemCheck(object sender, ItemCheckEventArgs e) {
|
---|
[3788] | 79 | if (doubleClick) {
|
---|
| 80 | e.NewValue = e.CurrentValue;
|
---|
| 81 | doubleClick = false;
|
---|
| 82 | } else {
|
---|
| 83 | var checkedItem = (T)itemsListView.Items[e.Index].Tag;
|
---|
| 84 | bool check = e.NewValue == CheckState.Checked;
|
---|
| 85 | if (Content.ItemChecked(checkedItem) != check) {
|
---|
| 86 | Content.SetItemCheckedState(checkedItem, check);
|
---|
| 87 | }
|
---|
[3565] | 88 | }
|
---|
| 89 | }
|
---|
[3788] | 90 |
|
---|
| 91 | protected void itemsListView_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) {
|
---|
| 92 | if (e.Clicks > 1)
|
---|
| 93 | doubleClick = true;
|
---|
| 94 | }
|
---|
[3565] | 95 | #endregion
|
---|
| 96 |
|
---|
| 97 | #region Content Events
|
---|
| 98 | protected virtual void Content_CheckedItemsChanged(object sender, CollectionItemsChangedEventArgs<IndexedItem<T>> e) {
|
---|
| 99 | if (InvokeRequired)
|
---|
| 100 | Invoke(new CollectionItemsChangedEventHandler<IndexedItem<T>>(Content_CheckedItemsChanged), sender, e);
|
---|
| 101 | else {
|
---|
| 102 | foreach (var item in e.Items) {
|
---|
| 103 | if (itemsListView.Items[item.Index].Checked != Content.ItemChecked(item.Value))
|
---|
| 104 | itemsListView.Items[item.Index].Checked = Content.ItemChecked(item.Value);
|
---|
| 105 | }
|
---|
| 106 | }
|
---|
| 107 | }
|
---|
| 108 | #endregion
|
---|
| 109 | }
|
---|
| 110 | }
|
---|