[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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.ComponentModel;
|
---|
| 25 | using System.Drawing;
|
---|
| 26 | using System.Data;
|
---|
| 27 | using System.Text;
|
---|
| 28 | using System.Xml;
|
---|
| 29 | using System.Windows.Forms;
|
---|
| 30 |
|
---|
[2426] | 31 | namespace 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;
|
---|
[2543] | 37 | this.closeReason = CloseReason.None;
|
---|
[2] | 38 | }
|
---|
[2456] | 39 |
|
---|
[2] | 40 | private string myCaption;
|
---|
| 41 | public string Caption {
|
---|
| 42 | get { return myCaption; }
|
---|
| 43 | set {
|
---|
[2548] | 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 | }
|
---|
[2] | 52 | }
|
---|
| 53 | }
|
---|
| 54 | }
|
---|
| 55 |
|
---|
[2696] | 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 |
|
---|
[2] | 88 | public event EventHandler CaptionChanged;
|
---|
| 89 | protected virtual void OnCaptionChanged() {
|
---|
| 90 | if (CaptionChanged != null)
|
---|
[2532] | 91 | CaptionChanged(this, new EventArgs());
|
---|
[2] | 92 | }
|
---|
| 93 |
|
---|
[2426] | 94 | public event EventHandler Changed;
|
---|
| 95 | protected virtual void OnChanged() {
|
---|
[2548] | 96 | if (InvokeRequired)
|
---|
| 97 | Invoke((MethodInvoker)OnChanged);
|
---|
| 98 | else if (Changed != null)
|
---|
[2532] | 99 | Changed(this, new EventArgs());
|
---|
[2254] | 100 | }
|
---|
| 101 |
|
---|
[2696] | 102 | protected virtual void OnShown(ViewShownEventArgs e) {
|
---|
[2] | 103 | }
|
---|
[2266] | 104 |
|
---|
[2696] | 105 | protected virtual void OnHidden(EventArgs e) {
|
---|
| 106 | }
|
---|
| 107 |
|
---|
[2543] | 108 | internal CloseReason closeReason;
|
---|
| 109 | internal void OnClosingHelper(object sender, FormClosingEventArgs e) {
|
---|
| 110 | if (this.closeReason != CloseReason.None)
|
---|
[2696] | 111 | this.OnClosing(new FormClosingEventArgs(this.closeReason, e.Cancel));
|
---|
[2543] | 112 | else
|
---|
[2696] | 113 | this.OnClosing(e);
|
---|
[2548] | 114 |
|
---|
[2543] | 115 | this.closeReason = CloseReason.None;
|
---|
[2532] | 116 | }
|
---|
| 117 |
|
---|
[2696] | 118 | protected virtual void OnClosing(FormClosingEventArgs e) {
|
---|
[2543] | 119 | }
|
---|
| 120 |
|
---|
[2696] | 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;
|
---|
[2266] | 131 | }
|
---|
[2509] | 132 |
|
---|
[2696] | 133 | protected virtual void OnClosed(FormClosedEventArgs e) {
|
---|
| 134 | }
|
---|
[2509] | 135 |
|
---|
| 136 | private void ViewBase_Load(object sender, EventArgs e) {
|
---|
| 137 | if (!this.initialized && !this.DesignMode) {
|
---|
[2696] | 138 | this.OnInitialized(e);
|
---|
[2509] | 139 | this.initialized = true;
|
---|
| 140 | }
|
---|
| 141 | }
|
---|
[2696] | 142 |
|
---|
| 143 | protected virtual void OnInitialized(EventArgs e) {
|
---|
| 144 | }
|
---|
[2] | 145 | }
|
---|
| 146 | }
|
---|