Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3068 was 2962, checked in by mkommend, 15 years ago

corrected access modifiers of some methods and fields (ticket #857)

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