source: trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/ContentView.cs @ 3727

Last change on this file since 3727 was 3727, checked in by mkommend, 12 years ago

added Suspend- and ResumeRepaint calls in View and ContentView (ticket #972)

File size: 3.6 KB
Line 
1#region License Information
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
22using System;
23using System.Collections.Generic;
24using System.ComponentModel;
25using System.Drawing;
26using System.Data;
27using System.Linq;
28using System.Text;
29using System.Windows.Forms;
30using HeuristicLab.Common;
31using System.Reflection;
32
33namespace HeuristicLab.MainForm.WindowsForms {
34  public partial class ContentView : View, IContentView {
35    public ContentView()
36      : base() {
37      InitializeComponent();
38      this.locked = false;
39    }
40
41    private IContent content;
42    public IContent Content {
43      get { return content; }
44      set {
45        if ((value != null) && (!MainFormManager.ViewCanViewContent(this, value)))
46          throw new ArgumentException(string.Format("View \"{0}\" cannot view object \"{1}\".", this.GetType().Name, value.GetType().Name));
47        if (InvokeRequired) {
48          Invoke(new Action<IContent>(delegate(IContent o) { this.Content = o; }), value);
49        } else {
50          if (this.content != value) {
51            this.SuspendRepaint();
52            if (this.content != null) this.DeregisterContentEvents();
53            this.content = value;
54            if (this.content != null) this.RegisterContentEvents();
55            this.OnContentChanged();
56            this.OnChanged();
57            this.ResumeRepaint(true);
58          }
59        }
60      }
61    }
62
63    private bool locked;
64    public virtual bool Locked {
65      get { return this.locked; }
66      set {
67        if (InvokeRequired) {
68          Action<bool> action = delegate(bool b) { this.Locked = b; };
69          Invoke(action, value);
70        } else {
71          if (value != locked) {
72            this.SuspendRepaint();
73            locked = value;
74            PropertyInfo prop = typeof(IContentView).GetProperty("Locked");
75            PropagateStateChanges(this, typeof(IContentView), prop);
76            OnLockedChanged();
77            OnChanged();
78            this.ResumeRepaint(true);
79          }
80        }
81      }
82    }
83    public event EventHandler LockedChanged;
84    protected virtual void OnLockedChanged() {
85      if (InvokeRequired)
86        Invoke((MethodInvoker)OnLockedChanged);
87      else {
88        EventHandler handler = LockedChanged;
89        if (handler != null)
90          handler(this, EventArgs.Empty);
91      }
92    }
93
94    /// <summary>
95    /// Adds eventhandlers to the current instance.
96    /// </summary>
97    protected virtual void RegisterContentEvents() {
98    }
99
100    /// <summary>
101    /// Removes the eventhandlers from the current instance.
102    /// </summary>
103    protected virtual void DeregisterContentEvents() {
104    }
105
106    /// <summary>
107    /// Is called when the content property changes.
108    /// </summary>
109    protected virtual void OnContentChanged() {
110    }
111  }
112}
Note: See TracBrowser for help on using the repository browser.