From 0951ef084f95492eac27d9463888d2e114780a2e Mon Sep 17 00:00:00 2001
From: adelikat <adelikat@tasvideos.org>
Date: Sat, 29 Aug 2020 10:49:22 -0500
Subject: [PATCH] Tastudio - rework greenzone settings dialog to fix long
 descriptions, winforms is bad, this shouldn't have been this hard

---
 .../Extensions/ControlExtensions.cs           | 30 +++++++++++++++++++
 .../TAStudio/GreenzoneSettings.Designer.cs    | 11 +++----
 .../tools/TAStudio/GreenzoneSettings.cs       |  5 ++++
 3 files changed, 41 insertions(+), 5 deletions(-)

diff --git a/src/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs b/src/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs
index 01b0187b0f..6f71632472 100644
--- a/src/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs
+++ b/src/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs
@@ -334,5 +334,35 @@ namespace BizHawk.Client.EmuHawk
 
 		public static bool IsCtrlShift(this KeyEventArgs e, Keys key)
 			=> !e.Alt && e.Control && e.Shift && e.KeyCode == key;
+
+		// For inexplicable reasons, property grid does not expose a way to do this
+		// https://www.codeproject.com/Articles/28193/Change-the-height-of-a-PropertyGrid-s-description?msg=3379905#xx3379905xx
+		public static void SetDescriptionRowHeight(this PropertyGrid grid, int numRows)
+		{
+			try
+			{
+				var controlsProp = grid.GetType().GetProperty("Controls");
+				var controlsCollection = (Control.ControlCollection)controlsProp.GetValue(grid, null);
+
+				foreach(Control c in controlsCollection)
+				{
+					Type ct = c.GetType();
+					string sName = ct.Name;
+
+					if (sName == "DocComment")
+					{
+						var controlsProp2 = ct.GetProperty("Lines");
+						controlsProp2.SetValue(c, numRows, null);
+
+						FieldInfo fi = ct.BaseType.GetField("userSized", BindingFlags.Instance | BindingFlags.NonPublic);
+						fi.SetValue(c, true);
+					}
+				}
+			 }
+			 catch (Exception ex)
+			 {
+				// Eat it
+			 }
+		}
 	}
 }
diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/GreenzoneSettings.Designer.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/GreenzoneSettings.Designer.cs
index 5cda8768ff..b49f407c9f 100644
--- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/GreenzoneSettings.Designer.cs
+++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/GreenzoneSettings.Designer.cs
@@ -37,7 +37,7 @@
 			// OkBtn
 			// 
 			this.OkBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
-			this.OkBtn.Location = new System.Drawing.Point(227, 266);
+			this.OkBtn.Location = new System.Drawing.Point(227, 333);
 			this.OkBtn.Name = "OkBtn";
 			this.OkBtn.Size = new System.Drawing.Size(60, 23);
 			this.OkBtn.TabIndex = 3;
@@ -49,7 +49,7 @@
 			// 
 			this.CancelBtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
 			this.CancelBtn.DialogResult = System.Windows.Forms.DialogResult.Cancel;
-			this.CancelBtn.Location = new System.Drawing.Point(293, 266);
+			this.CancelBtn.Location = new System.Drawing.Point(293, 333);
 			this.CancelBtn.Name = "CancelBtn";
 			this.CancelBtn.Size = new System.Drawing.Size(60, 23);
 			this.CancelBtn.TabIndex = 2;
@@ -60,7 +60,7 @@
 			// DefaultsButton
 			// 
 			this.DefaultsButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
-			this.DefaultsButton.Location = new System.Drawing.Point(12, 266);
+			this.DefaultsButton.Location = new System.Drawing.Point(12, 333);
 			this.DefaultsButton.Name = "DefaultsButton";
 			this.DefaultsButton.Size = new System.Drawing.Size(101, 23);
 			this.DefaultsButton.TabIndex = 4;
@@ -76,7 +76,7 @@
 			this.SettingsPropertyGrid.Location = new System.Drawing.Point(12, 8);
 			this.SettingsPropertyGrid.Name = "SettingsPropertyGrid";
 			this.SettingsPropertyGrid.PropertySort = System.Windows.Forms.PropertySort.NoSort;
-			this.SettingsPropertyGrid.Size = new System.Drawing.Size(341, 252);
+			this.SettingsPropertyGrid.Size = new System.Drawing.Size(341, 319);
 			this.SettingsPropertyGrid.TabIndex = 5;
 			this.SettingsPropertyGrid.ToolbarVisible = false;
 			// 
@@ -86,7 +86,7 @@
 			this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
 			this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
 			this.CancelButton = this.CancelBtn;
-			this.ClientSize = new System.Drawing.Size(400, 301);
+			this.ClientSize = new System.Drawing.Size(400, 368);
 			this.Controls.Add(this.SettingsPropertyGrid);
 			this.Controls.Add(this.DefaultsButton);
 			this.Controls.Add(this.OkBtn);
@@ -94,6 +94,7 @@
 			this.Name = "GreenzoneSettings";
 			this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
 			this.Text = "Default Savestate History Settings";
+			this.Load += new System.EventHandler(this.GreenzoneSettings_Load);
 			this.ResumeLayout(false);
 
 		}
diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/GreenzoneSettings.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/GreenzoneSettings.cs
index 0b86914a70..4fa63f3805 100644
--- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/GreenzoneSettings.cs
+++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/GreenzoneSettings.cs
@@ -24,6 +24,11 @@ namespace BizHawk.Client.EmuHawk
 			SettingsPropertyGrid.SelectedObject = _settings;
 		}
 
+		private void GreenzoneSettings_Load(object sender, EventArgs e)
+		{
+			SettingsPropertyGrid.SetDescriptionRowHeight(9);
+		}
+
 		private void OkBtn_Click(object sender, EventArgs e)
 		{
 			bool keep = false;