Free cookie consent management tool by TermsFeed Policy Generator

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

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

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

File size: 4.9 KB
RevLine 
[2]1#region License Information
2/* HeuristicLab
[2790]3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[2]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);
[2793]98      this.OnHidden(EventArgs.Empty);
[2696]99    }
100
[2]101    public event EventHandler CaptionChanged;
102    protected virtual void OnCaptionChanged() {
103      if (CaptionChanged != null)
[2793]104        CaptionChanged(this, EventArgs.Empty);
[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)
[2793]112        Changed(this, EventArgs.Empty);
[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
[2962]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) {
[2543]128      if (this.closeReason != CloseReason.None)
[2696]129        this.OnClosing(new FormClosingEventArgs(this.closeReason, e.Cancel));
[2543]130      else
[2696]131        this.OnClosing(e);
[2548]132
[2543]133      this.closeReason = CloseReason.None;
[2532]134    }
135
[2696]136    protected virtual void OnClosing(FormClosingEventArgs e) {
[2543]137    }
138
[2962]139    private void OnClosedHelper(object sender, FormClosedEventArgs e) {
[2696]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;
[2266]149    }
[2509]150
[2696]151    protected virtual void OnClosed(FormClosedEventArgs e) {
152    }
[2509]153
[2813]154    private void View_Load(object sender, EventArgs e) {
[2509]155      if (!this.initialized && !this.DesignMode) {
[2696]156        this.OnInitialized(e);
[2509]157        this.initialized = true;
158      }
159    }
[2696]160
161    protected virtual void OnInitialized(EventArgs e) {
162    }
[2]163  }
164}
Note: See TracBrowser for help on using the repository browser.