[2989] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[5445] | 3 | * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[2989] | 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.Windows.Forms;
|
---|
| 24 | using HeuristicLab.MainForm;
|
---|
| 25 |
|
---|
| 26 | namespace HeuristicLab.Core.Views {
|
---|
| 27 | /// <summary>
|
---|
| 28 | /// The visual representation of a <see cref="Variable"/>.
|
---|
| 29 | /// </summary>
|
---|
| 30 | [View("Variable Value View")]
|
---|
| 31 | [Content(typeof(Variable), false)]
|
---|
| 32 | [Content(typeof(IVariable), false)]
|
---|
| 33 | public partial class VariableValueView : ItemView {
|
---|
| 34 | /// <summary>
|
---|
| 35 | /// Gets or sets the variable to represent visually.
|
---|
| 36 | /// </summary>
|
---|
| 37 | /// <remarks>Uses property <see cref="ViewBase.Item"/> of base class <see cref="ViewBase"/>.
|
---|
| 38 | /// No own data storage present.</remarks>
|
---|
| 39 | public new IVariable Content {
|
---|
| 40 | get { return (IVariable)base.Content; }
|
---|
| 41 | set { base.Content = value; }
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | /// <summary>
|
---|
| 45 | /// Initializes a new instance of <see cref="VariableView"/> with caption "Variable".
|
---|
| 46 | /// </summary>
|
---|
| 47 | public VariableValueView() {
|
---|
| 48 | InitializeComponent();
|
---|
| 49 | }
|
---|
| 50 |
|
---|
| 51 | /// <summary>
|
---|
| 52 | /// Removes the eventhandlers from the underlying <see cref="Variable"/>.
|
---|
| 53 | /// </summary>
|
---|
| 54 | /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
|
---|
| 55 | protected override void DeregisterContentEvents() {
|
---|
| 56 | Content.ValueChanged -= new EventHandler(Content_ValueChanged);
|
---|
| 57 | base.DeregisterContentEvents();
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | /// <summary>
|
---|
| 61 | /// Adds eventhandlers to the underlying <see cref="Variable"/>.
|
---|
| 62 | /// </summary>
|
---|
| 63 | /// <remarks>Calls <see cref="ViewBase.AddItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
|
---|
| 64 | protected override void RegisterContentEvents() {
|
---|
| 65 | base.RegisterContentEvents();
|
---|
| 66 | Content.ValueChanged += new EventHandler(Content_ValueChanged);
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | protected override void OnContentChanged() {
|
---|
| 70 | base.OnContentChanged();
|
---|
| 71 | if (Content == null) {
|
---|
| 72 | viewHost.Content = null;
|
---|
| 73 | } else {
|
---|
| 74 | viewHost.ViewType = null;
|
---|
| 75 | viewHost.Content = Content.Value;
|
---|
| 76 | }
|
---|
| 77 | }
|
---|
| 78 |
|
---|
| 79 | protected virtual void Content_ValueChanged(object sender, EventArgs e) {
|
---|
| 80 | if (InvokeRequired)
|
---|
| 81 | Invoke(new EventHandler(Content_ValueChanged), sender, e);
|
---|
| 82 | else {
|
---|
| 83 | viewHost.ViewType = null;
|
---|
| 84 | viewHost.Content = Content.Value;
|
---|
| 85 | }
|
---|
| 86 | }
|
---|
| 87 |
|
---|
[4445] | 88 | protected virtual void VariableValueView_DragEnterOver(object sender, DragEventArgs e) {
|
---|
[2989] | 89 | e.Effect = DragDropEffects.None;
|
---|
| 90 | Type type = e.Data.GetData("Type") as Type;
|
---|
[3362] | 91 | if (!ReadOnly && (type != null) && (typeof(IItem).IsAssignableFrom(type))) {
|
---|
[3694] | 92 | if ((e.KeyState & 32) == 32) e.Effect = DragDropEffects.Link; // ALT key
|
---|
[2989] | 93 | else if ((e.KeyState & 4) == 4) e.Effect = DragDropEffects.Move; // SHIFT key
|
---|
| 94 | else if ((e.AllowedEffect & DragDropEffects.Copy) == DragDropEffects.Copy) e.Effect = DragDropEffects.Copy;
|
---|
| 95 | else if ((e.AllowedEffect & DragDropEffects.Move) == DragDropEffects.Move) e.Effect = DragDropEffects.Move;
|
---|
[3526] | 96 | else if ((e.AllowedEffect & DragDropEffects.Link) == DragDropEffects.Link) e.Effect = DragDropEffects.Link;
|
---|
[2989] | 97 | }
|
---|
| 98 | }
|
---|
[4445] | 99 | protected virtual void VariableValueView_DragDrop(object sender, DragEventArgs e) {
|
---|
[2989] | 100 | if (e.Effect != DragDropEffects.None) {
|
---|
| 101 | IItem item = e.Data.GetData("Value") as IItem;
|
---|
| 102 | if ((e.Effect & DragDropEffects.Copy) == DragDropEffects.Copy) item = (IItem)item.Clone();
|
---|
| 103 | Content.Value = item;
|
---|
| 104 | }
|
---|
| 105 | }
|
---|
| 106 | }
|
---|
| 107 | }
|
---|