Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 2696 was 2696, checked in by mkommend, 14 years ago

first version of redesigned MainForm (ticket #857)

File size: 4.5 KB
Line 
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
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.closeReason = CloseReason.None;
38    }
39
40    private string myCaption;
41    public string Caption {
42      get { return myCaption; }
43      set {
44        if (InvokeRequired) {
45          Action<string> action = delegate(string s) { this.Caption = s; };
46          Invoke(action, value);
47        } else {
48          if (value != myCaption) {
49            myCaption = value;
50            OnCaptionChanged();
51          }
52        }
53      }
54    }
55
56    public void Show() {
57      MainForm mainform = MainFormManager.GetMainForm<MainForm>();
58      bool firstTimeShown = mainform.GetForm(this) == null;
59
60      MainFormManager.GetMainForm<MainForm>().ShowView(this,firstTimeShown);
61      if (firstTimeShown) {
62        Form form = mainform.GetForm(this);
63        form.FormClosed += new FormClosedEventHandler(OnClosedHelper);
64        form.FormClosing += new FormClosingEventHandler(OnClosingHelper);
65      }
66      this.OnShown(new ViewShownEventArgs(this,firstTimeShown));
67    }
68
69    public void Close() {
70      MainForm mainform = MainFormManager.GetMainForm<MainForm>();
71      Form form = mainform.GetForm(this);
72      if (form != null)
73        mainform.CloseView(this);
74    }
75
76    public void Close(CloseReason closeReason) {
77      MainForm mainform = MainFormManager.GetMainForm<MainForm>();
78      Form form = mainform.GetForm(this);
79      if (form != null)
80        mainform.CloseView(this,closeReason);
81    }
82
83    public void Hide() {
84      MainFormManager.GetMainForm<MainForm>().HideView(this);
85      this.OnHidden(new EventArgs());
86    }
87
88    public event EventHandler CaptionChanged;
89    protected virtual void OnCaptionChanged() {
90      if (CaptionChanged != null)
91        CaptionChanged(this, new EventArgs());
92    }
93
94    public event EventHandler Changed;
95    protected virtual void OnChanged() {
96      if (InvokeRequired)
97        Invoke((MethodInvoker)OnChanged);
98      else if (Changed != null)
99        Changed(this, new EventArgs());
100    }
101
102    protected virtual void OnShown(ViewShownEventArgs e) {
103    }
104
105    protected virtual void OnHidden(EventArgs e) {
106    }
107
108    internal CloseReason closeReason;
109    internal void OnClosingHelper(object sender, FormClosingEventArgs e) {
110      if (this.closeReason != CloseReason.None)
111        this.OnClosing(new FormClosingEventArgs(this.closeReason, e.Cancel));
112      else
113        this.OnClosing(e);
114
115      this.closeReason = CloseReason.None;
116    }
117
118    protected virtual void OnClosing(FormClosingEventArgs e) {
119    }
120
121    internal void OnClosedHelper(object sender, FormClosedEventArgs e) {
122      if (this.closeReason != CloseReason.None)
123        this.OnClosed(new FormClosedEventArgs(this.closeReason));
124      else
125        this.OnClosed(e);
126
127      Form form = (Form)sender;
128      form.FormClosed -= new FormClosedEventHandler(OnClosedHelper);
129      form.FormClosing -= new FormClosingEventHandler(OnClosingHelper);
130      this.closeReason = CloseReason.None;
131    }
132
133    protected virtual void OnClosed(FormClosedEventArgs e) {
134    }
135
136    private void ViewBase_Load(object sender, EventArgs e) {
137      if (!this.initialized && !this.DesignMode) {
138        this.OnInitialized(e);
139        this.initialized = true;
140      }
141    }
142
143    protected virtual void OnInitialized(EventArgs e) {
144    }
145  }
146}
Note: See TracBrowser for help on using the repository browser.