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