Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ParameterBinding/HeuristicLab.MainForm.WindowsForms/3.3/DockForm.cs @ 9134

Last change on this file since 9134 was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

File size: 3.4 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    private IView view;
76    public IView View {
77      get { return this.view; }
78    }
79
80    private void UpdateText() {
81      if (InvokeRequired)
82        Invoke(new MethodInvoker(UpdateText));
83      else
84        this.Text = this.View.Caption;
85    }
86
87    protected override void OnDockStateChanged(EventArgs e) {
88      base.OnDockStateChanged(e);
89      Sidebar sidebar = view as Sidebar;
90      if (sidebar != null) {
91        if (this.DockState == DockState.DockLeftAutoHide || this.DockState == DockState.DockRightAutoHide)
92          sidebar.Collapsed = true;
93        else
94          sidebar.Collapsed = false;
95      }
96    }
97
98    #region View Events
99    private void View_CaptionChanged(object sender, EventArgs e) {
100      UpdateText();
101    }
102    #endregion
103  }
104}
Note: See TracBrowser for help on using the repository browser.