Changeset 4510
- Timestamp:
- 09/26/10 23:56:25 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/ViewHost.cs
r4465 r4510 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Drawing; 24 25 using System.Linq; 25 26 using System.Windows.Forms; … … 41 42 } 42 43 44 private IContentView cachedView; 43 45 private IContentView activeView; 44 46 public IContentView ActiveView { 45 get { return this.activeView; }47 get { return activeView; } 46 48 private set { 47 49 if (activeView != value) { 48 50 if (activeView != null) { 51 cachedView = activeView; 49 52 DeregisterActiveViewEvents(); 50 View view = activeView as View; 51 if (view != null) { 52 view.OnHidden(EventArgs.Empty); 53 Controls.Remove(view); 54 view.Dispose(); 53 View cached = cachedView as View; 54 if (cached != null) { 55 cached.OnHidden(EventArgs.Empty); 56 cached.Visible = false; 55 57 } 56 58 } 57 59 activeView = value; 58 60 if (activeView != null) { 61 View cached = cachedView as View; 62 if (cached != null && activeView != cached) { 63 Controls.Remove(cached); 64 cached.Dispose(); 65 } 66 cachedView = null; 67 59 68 this.Caption = activeView.Caption; 60 69 viewType = activeView.GetType(); … … 62 71 View view = activeView as View; 63 72 if (view != null) { 73 view.Visible = true; 64 74 view.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right; 65 view.Size = new S ystem.Drawing.Size(this.Width - this.viewsLabel.Width - this.viewsLabel.Margin.Left - this.viewsLabel.Margin.Right, this.Height);75 view.Size = new Size(Width - this.viewsLabel.Width - this.viewsLabel.Margin.Left - this.viewsLabel.Margin.Right, this.Height); 66 76 view.OnShown(new ViewShownEventArgs(view, false)); 67 Controls.Add(view);77 if (!Controls.Contains((view))) Controls.Add(view); 68 78 } 69 79 } else viewType = null; … … 71 81 } 72 82 } 73 private Control ActiveViewControl {74 get { return ActiveView as Control; }75 }76 83 77 84 private Type viewType; 78 85 public Type ViewType { 79 get { return this.viewType; }86 get { return viewType; } 80 87 set { 81 88 if (viewType != value) { … … 89 96 } 90 97 98 protected override void SetEnabledStateOfControls() { 99 Enabled = Content != null; 100 } 101 91 102 protected override void OnContentChanged() { 92 103 viewContextMenuStrip.Item = Content; … … 95 106 if (!ViewCanShowContent(viewType, Content)) { 96 107 Type defaultViewType = MainFormManager.GetDefaultViewType(Content.GetType()); 97 if (defaultViewType != null) 108 if (cachedView != null && cachedView.GetType() == defaultViewType) 109 ActiveView = cachedView; 110 else if (defaultViewType != null) 98 111 ViewType = defaultViewType; 99 112 else if (viewContextMenuStrip.Items.Count > 0) // create first available view if no default view is available … … 128 141 throw new InvalidOperationException(string.Format("View \"{0}\" cannot display content \"{1}\".", 129 142 viewType, Content.GetType())); 130 IContentView view; 131 view = MainFormManager.CreateView(viewType); 132 view.Locked = this.Locked; 133 view.ReadOnly = this.ReadOnly; 143 IContentView view = MainFormManager.CreateView(viewType); 144 view.Locked = Locked; 145 view.ReadOnly = ReadOnly; 134 146 ActiveView = view; //necessary to allow the views to change the status of the viewhost 135 147 view.Content = Content; … … 148 160 } 149 161 private void activeView_CaptionChanged(object sender, EventArgs e) { 150 this.Caption = activeView.Caption;162 Caption = activeView.Caption; 151 163 } 152 164 private void activeView_LockedChanged(object sender, EventArgs e) { 153 this.Locked = activeView.Locked;165 Locked = activeView.Locked; 154 166 } 155 167 … … 157 169 //mkommend: solution to resizing issues. taken from http://support.microsoft.com/kb/953934 158 170 //not implemented with a panel to reduce the number of nested controls 159 if ( this.Handle != null)171 if (Handle != null) 160 172 this.BeginInvoke((Action<EventArgs>)OnSizeChangedHelper, e); 161 173 } 162 174 private void OnSizeChangedHelper(EventArgs e) { 163 175 base.OnSizeChanged(e); 164 this.viewsLabel.Location = new System.Drawing.Point(this.Width - this.viewsLabel.Margin.Right - this.viewsLabel.Width, this.viewsLabel.Margin.Top);176 viewsLabel.Location = new Point(Width - viewsLabel.Margin.Right - viewsLabel.Width, viewsLabel.Margin.Top); 165 177 } 166 178 … … 168 180 internal protected override void OnShown(ViewShownEventArgs e) { 169 181 base.OnShown(e); 170 View view = this.ActiveView as View;182 View view = ActiveView as View; 171 183 if (view != null) 172 184 view.OnShown(e); … … 174 186 internal protected override void OnHidden(EventArgs e) { 175 187 base.OnHidden(e); 176 View view = this.ActiveView as View;188 View view = ActiveView as View; 177 189 if (view != null) 178 190 view.OnHidden(e);
Note: See TracChangeset
for help on using the changeset viewer.