Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.MainForm.WindowsForms/3.2/View.cs @ 2746

Last change on this file since 2746 was 2723, checked in by mkommend, 15 years ago

corrected MainForm.ActiveViewChanged event and View.IsShown property (ticket #857)

File size: 4.8 KB
RevLine 
[2]1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 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.Text;
28using System.Xml;
29using System.Windows.Forms;
30
[2426]31namespace HeuristicLab.MainForm.WindowsForms {
[2696]32  public partial class View : UserControl, IView {
[2509]33    private bool initialized;
[2696]34    public View() {
[2233]35      InitializeComponent();
[2509]36      this.initialized = false;
[2711]37      this.isShown = false;
[2543]38      this.closeReason = CloseReason.None;
[2]39    }
[2456]40
[2]41    private string myCaption;
42    public string Caption {
43      get { return myCaption; }
44      set {
[2548]45        if (InvokeRequired) {
46          Action<string> action = delegate(string s) { this.Caption = s; };
47          Invoke(action, value);
48        } else {
49          if (value != myCaption) {
50            myCaption = value;
51            OnCaptionChanged();
52          }
[2]53        }
54      }
55    }
56
[2711]57    private bool isShown;
58    public bool IsShown {
59      get { return this.isShown; }
[2723]60      private set { this.isShown = value; }
[2711]61    }
62
[2704]63    public new void Show() {
[2696]64      MainForm mainform = MainFormManager.GetMainForm<MainForm>();
65      bool firstTimeShown = mainform.GetForm(this) == null;
66
[2723]67      this.IsShown = true;
68      mainform.ShowView(this, firstTimeShown);
[2696]69      if (firstTimeShown) {
70        Form form = mainform.GetForm(this);
71        form.FormClosed += new FormClosedEventHandler(OnClosedHelper);
72        form.FormClosing += new FormClosingEventHandler(OnClosingHelper);
73      }
[2723]74      this.OnShown(new ViewShownEventArgs(this, firstTimeShown));
[2696]75    }
76
77    public void Close() {
78      MainForm mainform = MainFormManager.GetMainForm<MainForm>();
79      Form form = mainform.GetForm(this);
[2723]80      if (form != null) {
81        this.IsShown = false;
[2696]82        mainform.CloseView(this);
[2723]83      }
[2696]84    }
85
86    public void Close(CloseReason closeReason) {
87      MainForm mainform = MainFormManager.GetMainForm<MainForm>();
88      Form form = mainform.GetForm(this);
[2723]89      if (form != null) {
90        this.IsShown = false;
91        mainform.CloseView(this, closeReason);
92      }
[2696]93    }
94
[2704]95    public new void Hide() {
[2723]96      this.IsShown = false;
[2696]97      MainFormManager.GetMainForm<MainForm>().HideView(this);
98      this.OnHidden(new EventArgs());
99    }
100
[2]101    public event EventHandler CaptionChanged;
102    protected virtual void OnCaptionChanged() {
103      if (CaptionChanged != null)
[2532]104        CaptionChanged(this, new EventArgs());
[2]105    }
106
[2426]107    public event EventHandler Changed;
108    protected virtual void OnChanged() {
[2548]109      if (InvokeRequired)
110        Invoke((MethodInvoker)OnChanged);
111      else if (Changed != null)
[2532]112        Changed(this, new EventArgs());
[2254]113    }
114
[2696]115    protected virtual void OnShown(ViewShownEventArgs e) {
[2]116    }
[2266]117
[2696]118    protected virtual void OnHidden(EventArgs e) {
119    }
120
[2543]121    internal CloseReason closeReason;
122    internal void OnClosingHelper(object sender, FormClosingEventArgs e) {
123      if (this.closeReason != CloseReason.None)
[2696]124        this.OnClosing(new FormClosingEventArgs(this.closeReason, e.Cancel));
[2543]125      else
[2696]126        this.OnClosing(e);
[2548]127
[2543]128      this.closeReason = CloseReason.None;
[2532]129    }
130
[2696]131    protected virtual void OnClosing(FormClosingEventArgs e) {
[2543]132    }
133
[2696]134    internal void OnClosedHelper(object sender, FormClosedEventArgs e) {
135      if (this.closeReason != CloseReason.None)
136        this.OnClosed(new FormClosedEventArgs(this.closeReason));
137      else
138        this.OnClosed(e);
139
140      Form form = (Form)sender;
141      form.FormClosed -= new FormClosedEventHandler(OnClosedHelper);
142      form.FormClosing -= new FormClosingEventHandler(OnClosingHelper);
143      this.closeReason = CloseReason.None;
[2266]144    }
[2509]145
[2696]146    protected virtual void OnClosed(FormClosedEventArgs e) {
147    }
[2509]148
149    private void ViewBase_Load(object sender, EventArgs e) {
150      if (!this.initialized && !this.DesignMode) {
[2696]151        this.OnInitialized(e);
[2509]152        this.initialized = true;
153      }
154    }
[2696]155
156    protected virtual void OnInitialized(EventArgs e) {
157    }
[2]158  }
159}
Note: See TracBrowser for help on using the repository browser.