Changeset 4011 for trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3
- Timestamp:
- 07/07/10 14:36:22 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3
- Files:
-
- 8 added
- 2 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/HeuristicLab.MainForm.WindowsForms-3.3.csproj
r3832 r4011 164 164 <DependentUpon>ViewHost.cs</DependentUpon> 165 165 </Compile> 166 <Compile Include="ViewHostPanel.cs">167 <SubType>Component</SubType>168 </Compile>169 <Compile Include="ViewHostPanel.Designer.cs">170 <DependentUpon>ViewHostPanel.cs</DependentUpon>171 </Compile>172 166 </ItemGroup> 173 167 <ItemGroup> -
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/HeuristicLabMainFormWindowsFormsPlugin.cs.frame
r3702 r4011 32 32 [PluginDependency("HeuristicLab.MainForm", "3.3")] 33 33 [PluginDependency("HeuristicLab.WinFormsUI", "2.3.1")] 34 public class HeuristicLabMainForm TestPlugin : PluginBase {34 public class HeuristicLabMainFormPlugin : PluginBase { 35 35 } 36 36 } -
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/ViewHost.Designer.cs
r3658 r4011 46 46 private void InitializeComponent() { 47 47 this.components = new System.ComponentModel.Container(); 48 this.viewPanel = new HeuristicLab.MainForm.WindowsForms.ViewHostPanel();49 48 this.messageLabel = new System.Windows.Forms.Label(); 50 49 this.viewsLabel = new System.Windows.Forms.Label(); … … 52 51 this.toolTip = new System.Windows.Forms.ToolTip(this.components); 53 52 this.SuspendLayout(); 54 //55 // viewPanel56 //57 this.viewPanel.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)58 | System.Windows.Forms.AnchorStyles.Left)59 | System.Windows.Forms.AnchorStyles.Right)));60 this.viewPanel.Location = new System.Drawing.Point(0, 0);61 this.viewPanel.Name = "viewPanel";62 this.viewPanel.Size = new System.Drawing.Size(205, 184);63 this.viewPanel.TabIndex = 1;64 this.viewPanel.Resize += new System.EventHandler(this.viewPanel_Resize);65 53 // 66 54 // messageLabel … … 80 68 this.viewsLabel.Image = HeuristicLab.Common.Resources.VS2008ImageLibrary.Windows; 81 69 this.viewsLabel.Location = new System.Drawing.Point(211, 0); 70 this.viewsLabel.Margin = new System.Windows.Forms.Padding(3); 82 71 this.viewsLabel.Name = "viewsLabel"; 83 72 this.viewsLabel.Size = new System.Drawing.Size(16, 16); … … 100 89 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 101 90 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 102 this.Controls.Add(this.viewPanel);103 91 this.Controls.Add(this.viewsLabel); 104 92 this.Controls.Add(this.messageLabel); … … 106 94 this.Size = new System.Drawing.Size(227, 184); 107 95 this.ResumeLayout(false); 108 109 96 } 110 97 111 98 #endregion 112 113 private ViewHostPanel viewPanel;114 99 private System.Windows.Forms.Label viewsLabel; 115 100 private System.Windows.Forms.Label messageLabel; -
trunk/sources/HeuristicLab.MainForm.WindowsForms/3.3/ViewHost.cs
r3924 r4011 33 33 InitializeComponent(); 34 34 cachedViews = new Dictionary<Type, IContentView>(); 35 viewType = null;36 35 startDragAndDrop = false; 37 36 viewContextMenuStrip.IgnoredViewTypes = new List<Type>() { typeof(ViewHost) }; 37 38 viewType = null; 38 39 activeView = null; 39 40 Content = null; 40 OnContentChanged();41 }42 43 private bool viewShown; 41 messageLabel.Visible = false; 42 viewsLabel.Visible = false; 43 } 44 44 45 private Dictionary<Type, IContentView> cachedViews; 45 46 public IEnumerable<IContentView> Views { … … 57 58 if (view != null) 58 59 view.OnHidden(EventArgs.Empty); 60 if (ActiveViewControl != null) 61 ActiveViewControl.Visible = false; 59 62 } 60 63 activeView = value; 61 64 if (activeView != null) { 62 ViewType = activeView.GetType();65 viewType = activeView.GetType(); 63 66 RegisterActiveViewEvents(); 64 67 View view = activeView as View; 65 68 if (view != null) 66 69 view.OnShown(new ViewShownEventArgs(view, false)); 70 if (ActiveViewControl != null) { 71 ActiveViewControl.Visible = true; 72 ActiveViewControl.BringToFront(); 73 } 67 74 } 68 ActiveViewChanged(); 69 } 70 } 71 } 75 OnActiveViewChanged(); 76 } 77 } 78 } 79 80 private Control ActiveViewControl { 81 get { return ActiveView as Control; } 82 } 83 72 84 private Type viewType; 73 85 public Type ViewType { … … 75 87 set { 76 88 if (viewType != value) { 77 if (value != null && !ViewCanShowContent(value, Content))89 if (value != null && Content != null && !ViewCanShowContent(value, Content)) 78 90 throw new ArgumentException(string.Format("View \"{0}\" cannot display content \"{1}\".", 79 91 value, Content.GetType())); … … 96 108 protected override void OnContentChanged() { 97 109 viewContextMenuStrip.Item = Content; 98 99 if (Content != null) { 100 if (viewContextMenuStrip.Items.Count == 0) { 101 messageLabel.Visible = true; 102 viewsLabel.Visible = false; 103 viewPanel.Visible = false; 104 } else { 105 messageLabel.Visible = false; 106 viewsLabel.Visible = true; 107 viewPanel.Visible = true; 108 } 109 110 //remove cached views which cannot show the content 111 foreach (Type type in cachedViews.Keys.ToList()) { 112 if (!ViewCanShowContent(type, Content)) { 113 Control c = cachedViews[type] as Control; 114 if (c != null) { 115 this.Controls.Remove(c); 116 c.Dispose(); 117 } 118 cachedViews.Remove(type); 119 } 120 } 121 122 //change ViewType if view of ViewType can not show content or is null 123 if (Content != null && !ViewCanShowContent(viewType, Content)) { 110 124 Type defaultViewType = MainFormManager.GetDefaultViewType(Content.GetType()); 111 if (ViewType == null || !ViewCanShowContent(viewType, Content)) { 112 cachedViews.Clear(); 113 if (defaultViewType == null) { 114 if (viewContextMenuStrip.Items.Count > 0) // create first available view if default view is not available 115 ViewType = (Type)viewContextMenuStrip.Items[0].Tag; 116 } else ViewType = defaultViewType; 117 } else { 118 foreach (Type type in cachedViews.Keys.ToList()) { 119 if (!ViewCanShowContent(type, Content)) { 120 Control c = cachedViews[type] as Control; 121 if (c != null) 122 c.Dispose(); 123 cachedViews.Remove(type); 124 } 125 } 126 } 127 UpdateActiveMenuItem(); 128 foreach (IContentView view in cachedViews.Values) 129 view.Content = this.Content; 125 if (defaultViewType != null) 126 ViewType = defaultViewType; 127 else if (viewContextMenuStrip.Items.Count > 0) // create first available view if no default view is available 128 ViewType = (Type)viewContextMenuStrip.Items[0].Tag; 129 else 130 ViewType = null; 131 } 132 133 foreach (IContentView view in cachedViews.Values) 134 view.Content = this.Content; 135 136 if (Content != null && viewType != null) 137 ActiveView = cachedViews[viewType]; 138 else 139 ActiveView = null; 140 141 if (Content != null && viewContextMenuStrip.Items.Count > 0) { 142 messageLabel.Visible = false; 143 viewsLabel.Visible = true; 144 } else if (Content != null) { 145 messageLabel.Visible = true; 146 viewsLabel.Visible = false; 130 147 } else { 131 148 messageLabel.Visible = false; 132 149 viewsLabel.Visible = false; 133 viewPanel.Visible = false;134 150 } 135 151 } 136 152 137 153 private void OnViewTypeChanged() { 138 for (int i = viewPanel.Controls.Count - 1; i > 0; i--) 139 viewPanel.Controls[i].Dispose(); 140 viewPanel.Controls.Clear(); 141 142 if (viewType == null || Content == null) 143 return; 144 if (!ViewCanShowContent(viewType, Content)) 145 throw new InvalidOperationException(string.Format("View \"{0}\" cannot display content \"{1}\".", 146 viewType, Content.GetType())); 147 if (viewPanel.Height <= 10 || viewPanel.Width <= 10) { 148 viewShown = false; 149 return; 150 } 151 152 viewShown = true; 153 UpdateActiveMenuItem(); 154 IContentView view; 155 if (cachedViews.ContainsKey(ViewType)) 156 view = cachedViews[ViewType]; 157 else { 158 view = MainFormManager.CreateView(viewType); 159 view.ReadOnly = this.ReadOnly; 160 view.Locked = this.Locked; 161 view.Content = Content; 162 cachedViews.Add(viewType, view); 163 } 164 this.ActiveView = view; 165 Control control = (Control)view; 166 control.Dock = DockStyle.Fill; 167 viewPanel.Controls.Add(control); 168 viewPanel.Visible = true; 169 } 170 171 private void viewPanel_Resize(object sender, EventArgs e) { 172 if (!viewShown) 173 this.OnViewTypeChanged(); 154 if (viewType != null) { 155 if (!ViewCanShowContent(viewType, Content)) 156 throw new InvalidOperationException(string.Format("View \"{0}\" cannot display content \"{1}\".", 157 viewType, Content.GetType())); 158 IContentView view; 159 if (!cachedViews.ContainsKey(ViewType)) { 160 view = MainFormManager.CreateView(viewType); 161 view.ReadOnly = this.ReadOnly; 162 view.Locked = this.Locked; 163 view.Content = Content; 164 cachedViews.Add(viewType, view); 165 Control c = view as Control; 166 if (c != null) 167 this.Controls.Add(c); 168 } 169 UpdateActiveMenuItem(); 170 ActiveView = cachedViews[viewType]; 171 } 172 } 173 174 private void OnActiveViewChanged() { 175 this.SuspendRepaint(); 176 if (activeView != null) { 177 UpdateActiveMenuItem(); 178 this.ActiveViewControl.Anchor = AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right; 179 this.ActiveViewControl.Size = new System.Drawing.Size(this.Width - this.viewsLabel.Width - this.viewsLabel.Margin.Left - this.viewsLabel.Margin.Right, this.Height); 180 this.ActiveViewChanged(); 181 } 182 this.ResumeRepaint(true); 183 } 184 185 protected override void OnSizeChanged(EventArgs e) { 186 //mkommend: solution to resizing issues. taken from http://support.microsoft.com/kb/953934 187 //not implemented with a panel to reduce the number of nested controls 188 if (this.Handle != null) 189 this.BeginInvoke((Action<EventArgs>)OnSizeChangedHelper, e); 190 } 191 private void OnSizeChangedHelper(EventArgs e) { 192 base.OnSizeChanged(e); 193 this.viewsLabel.Location = new System.Drawing.Point(this.Width - this.viewsLabel.Margin.Right - this.viewsLabel.Width, this.viewsLabel.Margin.Top); 174 194 } 175 195 … … 194 214 } 195 215 } 216 196 217 #region forwarding of view events 197 218 protected override void OnReadOnlyChanged() {
Note: See TracChangeset
for help on using the changeset viewer.