Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/3.0@4633 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
5 changed files with 164 additions and 0 deletions
@ -0,0 +1,71 @@
@@ -0,0 +1,71 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections; |
||||
using System.ComponentModel; |
||||
using System.Windows.Forms; |
||||
|
||||
namespace ICSharpCode.PythonBinding |
||||
{ |
||||
public class PythonTableLayoutPanelComponent : PythonDesignerComponent |
||||
{ |
||||
public PythonTableLayoutPanelComponent(PythonDesignerComponent parent, IComponent component) |
||||
: base(parent, component) |
||||
{ |
||||
} |
||||
|
||||
public override void AppendMethodCallWithArrayParameter(PythonCodeBuilder codeBuilder, string propertyOwnerName, object propertyOwner, PropertyDescriptor propertyDescriptor) |
||||
{ |
||||
if (IsStylesProperty(propertyDescriptor.Name)) { |
||||
ICollection collection = propertyDescriptor.GetValue(propertyOwner) as ICollection; |
||||
if (collection != null) { |
||||
AppendStylesCollection(codeBuilder, collection, propertyOwnerName); |
||||
} |
||||
} else { |
||||
base.AppendMethodCallWithArrayParameter(codeBuilder, propertyOwnerName, propertyOwner, propertyDescriptor); |
||||
} |
||||
} |
||||
|
||||
bool IsStylesProperty(string name) |
||||
{ |
||||
return "ColumnStyles".Equals(name, StringComparison.InvariantCultureIgnoreCase) || "RowStyles".Equals(name, StringComparison.InvariantCultureIgnoreCase); |
||||
} |
||||
|
||||
void AppendStylesCollection(PythonCodeBuilder codeBuilder, ICollection collection, string propertyOwnerName) |
||||
{ |
||||
string newPropertyOwnerName = propertyOwnerName; |
||||
SizeType sizeType = SizeType.Absolute; |
||||
float width = 0; |
||||
foreach (object item in collection) { |
||||
ColumnStyle columnStyle = item as ColumnStyle; |
||||
RowStyle rowStyle = item as RowStyle; |
||||
if (columnStyle != null) { |
||||
sizeType = columnStyle.SizeType; |
||||
width = columnStyle.Width; |
||||
newPropertyOwnerName = propertyOwnerName + ".ColumnStyles"; |
||||
} |
||||
if (rowStyle != null) { |
||||
sizeType = rowStyle.SizeType; |
||||
width = rowStyle.Height; |
||||
newPropertyOwnerName = propertyOwnerName + ".RowStyles"; |
||||
} |
||||
AppendStyle(codeBuilder, newPropertyOwnerName, item.GetType(), sizeType, width); |
||||
} |
||||
} |
||||
|
||||
void AppendStyle(PythonCodeBuilder codeBuilder, string propertyOwnerName, Type type, SizeType sizeType, float value) |
||||
{ |
||||
codeBuilder.AppendIndented(propertyOwnerName + ".Add("); |
||||
codeBuilder.Append(type.FullName + "("); |
||||
codeBuilder.Append(typeof(SizeType).FullName + "." + sizeType + ", "); |
||||
codeBuilder.Append(value + ")"); |
||||
codeBuilder.Append(")"); |
||||
codeBuilder.AppendLine(); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,89 @@
@@ -0,0 +1,89 @@
|
||||
// <file>
|
||||
// <copyright see="prj:///doc/copyright.txt"/>
|
||||
// <license see="prj:///doc/license.txt"/>
|
||||
// <owner name="Matthew Ward" email="mrward@users.sourceforge.net"/>
|
||||
// <version>$Revision$</version>
|
||||
// </file>
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.ComponentModel; |
||||
using System.ComponentModel.Design; |
||||
using System.ComponentModel.Design.Serialization; |
||||
using System.Drawing; |
||||
using System.Windows.Forms; |
||||
using ICSharpCode.PythonBinding; |
||||
using NUnit.Framework; |
||||
using PythonBinding.Tests.Utils; |
||||
|
||||
namespace PythonBinding.Tests.Designer |
||||
{ |
||||
[TestFixture] |
||||
public class GenerateTableLayoutPanelTestFixture |
||||
{ |
||||
string generatedPythonCode; |
||||
|
||||
[TestFixtureSetUp] |
||||
public void SetUpFixture() |
||||
{ |
||||
using (DesignSurface designSurface = new DesignSurface(typeof(Form))) { |
||||
IDesignerHost host = (IDesignerHost)designSurface.GetService(typeof(IDesignerHost)); |
||||
IEventBindingService eventBindingService = new MockEventBindingService(host); |
||||
Form form = (Form)host.RootComponent; |
||||
form.ClientSize = new Size(200, 300); |
||||
|
||||
PropertyDescriptorCollection descriptors = TypeDescriptor.GetProperties(form); |
||||
PropertyDescriptor namePropertyDescriptor = descriptors.Find("Name", false); |
||||
namePropertyDescriptor.SetValue(form, "MainForm"); |
||||
|
||||
// Add table layout panel.
|
||||
TableLayoutPanel tableLayoutPanel1 = (TableLayoutPanel)host.CreateComponent(typeof(TableLayoutPanel), "tableLayoutPanel1"); |
||||
tableLayoutPanel1.ColumnCount = 2; |
||||
tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 40F)); |
||||
tableLayoutPanel1.ColumnStyles.Add(new ColumnStyle(SizeType.Percent, 60F)); |
||||
tableLayoutPanel1.Location = new System.Drawing.Point(0, 0); |
||||
tableLayoutPanel1.RowCount = 2; |
||||
tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 20F)); |
||||
tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.Absolute, 25F)); |
||||
tableLayoutPanel1.Size = new System.Drawing.Size(200, 100); |
||||
tableLayoutPanel1.TabIndex = 0; |
||||
|
||||
form.Controls.Add(tableLayoutPanel1); |
||||
|
||||
PythonControl pythonControl = new PythonControl(" "); |
||||
generatedPythonCode = pythonControl.GenerateInitializeComponentMethod(form); |
||||
} |
||||
} |
||||
|
||||
[Test] |
||||
public void GeneratedCode() |
||||
{ |
||||
string expectedCode = "def InitializeComponent(self):\r\n" + |
||||
" self._tableLayoutPanel1 = System.Windows.Forms.TableLayoutPanel()\r\n" + |
||||
" self.SuspendLayout()\r\n" + |
||||
" # \r\n" + |
||||
" # tableLayoutPanel1\r\n" + |
||||
" # \r\n" + |
||||
" self._tableLayoutPanel1.ColumnCount = 2\r\n" + |
||||
" self._tableLayoutPanel1.ColumnStyles.Add(System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 40))\r\n" + |
||||
" self._tableLayoutPanel1.ColumnStyles.Add(System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 60))\r\n" + |
||||
" self._tableLayoutPanel1.Location = System.Drawing.Point(0, 0)\r\n" + |
||||
" self._tableLayoutPanel1.Name = \"tableLayoutPanel1\"\r\n" + |
||||
" self._tableLayoutPanel1.RowCount = 2\r\n" + |
||||
" self._tableLayoutPanel1.RowStyles.Add(System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 20))\r\n" + |
||||
" self._tableLayoutPanel1.RowStyles.Add(System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Absolute, 25))\r\n" + |
||||
" self._tableLayoutPanel1.Size = System.Drawing.Size(200, 100)\r\n" + |
||||
" self._tableLayoutPanel1.TabIndex = 0\r\n" + |
||||
" # \r\n" + |
||||
" # MainForm\r\n" + |
||||
" # \r\n" + |
||||
" self.ClientSize = System.Drawing.Size(200, 300)\r\n" + |
||||
" self.Controls.Add(self._tableLayoutPanel1)\r\n" + |
||||
" self.Name = \"MainForm\"\r\n" + |
||||
" self.ResumeLayout(False)\r\n" + |
||||
" self.PerformLayout()\r\n"; |
||||
|
||||
Assert.AreEqual(expectedCode, generatedPythonCode, generatedPythonCode); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue