Free cookie consent management tool by TermsFeed Policy Generator

source: branches/SuccessProgressAnalysis/HeuristicLab.MainForm.WindowsForms/3.3/DockForm.cs @ 5478

Last change on this file since 5478 was 5237, checked in by swagner, 14 years ago

#1324:

  • Added performance optimization in all other item collection views
  • Checked and refactored item event registration/deregistration
  • Enabled null items in item collection views
  • Moved non-default Dispose methods from designer files into user files
File size: 3.6 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.Windows.Forms;
24using WeifenLuo.WinFormsUI.Docking;
25
26namespace HeuristicLab.MainForm.WindowsForms {
27  /// <summary>
28  /// Displays the used view.
29  /// </summary>
30  internal partial class DockForm : DockContent {
31    public DockForm(IView view) {
32      InitializeComponent();
33      this.view = view;
34      if (view != null) {
35        if (view is UserControl) {
36          switch (((UserControl)view).Dock) {
37            case DockStyle.Left:
38              this.ShowHint = DockState.DockLeft;
39              break;
40            case DockStyle.Right:
41              this.ShowHint = DockState.DockRight;
42              break;
43            case DockStyle.Top:
44              this.ShowHint = DockState.DockTop;
45              break;
46            case DockStyle.Bottom:
47              this.ShowHint = DockState.DockBottom;
48              break;
49          }
50          Sidebar sidebar = view as Sidebar;
51          if (sidebar != null) {
52            if (sidebar.Collapsed)
53              this.ShowHint = DockState.DockLeftAutoHide;
54            else
55              this.ShowHint = DockState.DockLeft;
56            this.DockAreas = DockAreas.DockLeft | DockAreas.DockRight;
57          }
58
59          Type viewType = view.GetType();
60          Control control = (Control)view;
61          control.Dock = DockStyle.Fill;
62          this.view.CaptionChanged += new EventHandler(View_CaptionChanged);
63          UpdateText();
64          viewPanel.Controls.Add(control);
65        }
66      } else {
67        Label errorLabel = new Label();
68        errorLabel.Name = "errorLabel";
69        errorLabel.Text = "No view available";
70        errorLabel.AutoSize = false;
71        errorLabel.Dock = DockStyle.Fill;
72        viewPanel.Controls.Add(errorLabel);
73      }
74    }
75
76    protected override void Dispose(bool disposing) {
77      if (View != null)
78        View.CaptionChanged -= new System.EventHandler(View_CaptionChanged);
79      if (disposing && (components != null)) {
80        components.Dispose();
81      }
82      base.Dispose(disposing);
83    }
84
85    private IView view;
86    public IView View {
87      get { return this.view; }
88    }
89
90    private void UpdateText() {
91      if (InvokeRequired)
92        Invoke(new MethodInvoker(UpdateText));
93      else
94        this.Text = this.View.Caption;
95    }
96
97    protected override void OnDockStateChanged(EventArgs e) {
98      base.OnDockStateChanged(e);
99      Sidebar sidebar = view as Sidebar;
100      if (sidebar != null) {
101        if (this.DockState == DockState.DockLeftAutoHide || this.DockState == DockState.DockRightAutoHide)
102          sidebar.Collapsed = true;
103        else
104          sidebar.Collapsed = false;
105      }
106    }
107
108    #region View Events
109    private void View_CaptionChanged(object sender, EventArgs e) {
110      UpdateText();
111    }
112    #endregion
113  }
114}
Note: See TracBrowser for help on using the repository browser.