From b8c0ffd8772d8bac46514d6438524b37a79c3cb8 Mon Sep 17 00:00:00 2001 From: tombogle Date: Wed, 4 Feb 2026 15:51:08 -0500 Subject: [PATCH 1/2] +semver:major Added UiLanguageChanged event to ILocalizationManager, which is invoked when UI language changes Removed a lot of cruft (mostly left over from decision to jettison the localization dialog Removed the version of LocalizationManagerWinforms.Create that did not take an icon. Switched to C#8 Replaced deprecated code in GoogleTranslator with a supported approach --- CHANGELOG.md | 9 + Directory.Build.props | 1 + L10NSharp.sln.DotSettings | 11 + .../SampleApp.es.xlf | 43 + src/ExtractXliff/ExtractXliff.csproj | 3 + src/L10NSharp.Tests/CodeReaderTests.cs | 1 - src/L10NSharp.Tests/L10NCultureInfoTests.cs | 11 +- .../LocalizationManagerTestsBase.cs | 2 +- .../LocalizationManagerXliffTests.cs | 3 +- .../ILocalizableComponentTests.cs | 2 +- .../LanguageChoosingDialogViewModelTests.cs | 1 - .../LocalizationExtenderTests.cs | 3 - .../LocalizingInfoTests.cs | 2 - .../MockLocalizableComponent.cs | 3 - .../UtilsTests.cs | 1 - .../XliffLocalizationManagerTests.cs | 2 +- .../ILocalizationManagerInternalWinforms.cs | 5 +- src/L10NSharp.Windows.Forms/L10NExtender.cs | 9 +- .../L10NSharp.Windows.Forms.csproj | 32 +- .../LocalizationManagerInternalWinforms.cs | 88 +- .../LocalizationManagerWinforms.cs | 87 +- .../LocalizingInfoWinforms.cs | 2 +- .../UIComponents/ColorHelper.cs | 89 -- .../CustomDropDownComboBox.Designer.cs | 75 - .../UIComponents/CustomDropDownComboBox.cs | 283 ---- .../UIComponents/CustomDropDownComboBox.resx | 120 -- .../DontShowThisAgainButton.Designer.cs | 37 - .../UIComponents/DontShowThisAgainButton.cs | 108 -- ...EditSourceBeforeTranslatingDlg.Designer.cs | 209 --- .../EditSourceBeforeTranslatingDlg.cs | 50 - .../EditSourceBeforeTranslatingDlg.resx | 123 -- .../UIComponents/FallbackLanguagesDlg.cs | 6 - .../UIComponents/FallbackLanguagesDlgBase.cs | 32 +- .../UIComponents/Grid/LmButtonCell.cs | 464 ------ .../UIComponents/Grid/LmButtonColumn.cs | 214 --- .../UIComponents/Grid/LmGrid.cs | 1419 ----------------- .../HowToDistributeDialog.Designer.cs | 145 -- .../UIComponents/HowToDistributeDialog.cs | 96 -- .../UIComponents/HowToDistributeDialog.resx | 126 -- .../UIComponents/InitializationProgressDlg.cs | 1 - .../UIComponents/LanguageChoosingDialog.cs | 5 +- .../LanguageChoosingDialogViewModel.cs | 4 +- .../UIComponents/PaintingHelper.cs | 286 ---- .../UIComponents/PopupControl.cs | 367 ----- .../UIComponents/PopupControl.designer.cs | 33 - .../UIComponents/PopupControl.resx | 120 -- .../UIComponents/ShortcutKeysConverter.cs | 114 ++ .../UIComponents/ShortcutKeysDropDown.cs | 91 -- .../ShortcutKeysEditor.Designer.cs | 198 --- .../UIComponents/ShortcutKeysEditor.cs | 305 ---- .../UIComponents/ShortcutKeysEditor.resx | 123 -- .../UIComponents/TipDialog.cs | 109 -- .../UIComponents/TipDialog.designer.cs | 149 -- .../UIComponents/TipDialog.resx | 120 -- .../UIComponents/UILanguageComboBox.cs | 29 +- .../UIComponents/UILanguageListBox.cs | 1 - .../UIComponents/XButton.cs | 367 ----- src/L10NSharp.Windows.Forms/UtilsWinforms.cs | 2 - .../XliffLocalizationManagerWinforms.cs | 14 +- .../XliffLocalizedStringCacheWinforms.cs | 4 +- src/L10NSharp/ILocalizationManager.cs | 50 +- src/L10NSharp/ILocalizationManagerInternal.cs | 4 +- src/L10NSharp/L10NCultureInfo.cs | 8 +- src/L10NSharp/L10NSharp.csproj | 6 +- src/L10NSharp/LocalizationManager.cs | 92 +- src/L10NSharp/LocalizationManagerInternal.cs | 16 +- src/L10NSharp/Translators/GoogleTranslator.cs | 33 +- src/L10NSharp/Translators/TranslatorBase.cs | 16 +- src/L10NSharp/Utility/HttpEncoderFromMono.cs | 3 +- src/L10NSharp/Utils.cs | 25 +- src/L10NSharp/XLiffUtils/XLiffBody.cs | 18 +- src/L10NSharp/XLiffUtils/XLiffFile.cs | 18 +- .../XLiffUtils/XLiffTransUnitVariant.cs | 38 +- .../XLiffUtils/XliffLocalizationManager.cs | 61 +- .../XLiffUtils/XliffTransUnitUpdater.cs | 12 +- .../XLiffUtils/XliffXmlSerializationHelper.cs | 221 +-- src/SampleApp/Form1.Designer.cs | 285 ++-- src/SampleApp/Form1.cs | 22 +- src/SampleApp/Program.cs | 24 +- 79 files changed, 615 insertions(+), 6696 deletions(-) create mode 100644 LocalizationFilesFromInstaller/SampleApp.es.xlf delete mode 100644 src/L10NSharp.Windows.Forms/UIComponents/ColorHelper.cs delete mode 100644 src/L10NSharp.Windows.Forms/UIComponents/CustomDropDownComboBox.Designer.cs delete mode 100644 src/L10NSharp.Windows.Forms/UIComponents/CustomDropDownComboBox.cs delete mode 100644 src/L10NSharp.Windows.Forms/UIComponents/CustomDropDownComboBox.resx delete mode 100644 src/L10NSharp.Windows.Forms/UIComponents/DontShowThisAgainButton.Designer.cs delete mode 100644 src/L10NSharp.Windows.Forms/UIComponents/DontShowThisAgainButton.cs delete mode 100644 src/L10NSharp.Windows.Forms/UIComponents/EditSourceBeforeTranslatingDlg.Designer.cs delete mode 100644 src/L10NSharp.Windows.Forms/UIComponents/EditSourceBeforeTranslatingDlg.cs delete mode 100644 src/L10NSharp.Windows.Forms/UIComponents/EditSourceBeforeTranslatingDlg.resx delete mode 100644 src/L10NSharp.Windows.Forms/UIComponents/Grid/LmButtonCell.cs delete mode 100644 src/L10NSharp.Windows.Forms/UIComponents/Grid/LmButtonColumn.cs delete mode 100644 src/L10NSharp.Windows.Forms/UIComponents/Grid/LmGrid.cs delete mode 100644 src/L10NSharp.Windows.Forms/UIComponents/HowToDistributeDialog.Designer.cs delete mode 100644 src/L10NSharp.Windows.Forms/UIComponents/HowToDistributeDialog.cs delete mode 100644 src/L10NSharp.Windows.Forms/UIComponents/HowToDistributeDialog.resx delete mode 100644 src/L10NSharp.Windows.Forms/UIComponents/PaintingHelper.cs delete mode 100644 src/L10NSharp.Windows.Forms/UIComponents/PopupControl.cs delete mode 100644 src/L10NSharp.Windows.Forms/UIComponents/PopupControl.designer.cs delete mode 100644 src/L10NSharp.Windows.Forms/UIComponents/PopupControl.resx create mode 100644 src/L10NSharp.Windows.Forms/UIComponents/ShortcutKeysConverter.cs delete mode 100644 src/L10NSharp.Windows.Forms/UIComponents/ShortcutKeysDropDown.cs delete mode 100644 src/L10NSharp.Windows.Forms/UIComponents/ShortcutKeysEditor.Designer.cs delete mode 100644 src/L10NSharp.Windows.Forms/UIComponents/ShortcutKeysEditor.cs delete mode 100644 src/L10NSharp.Windows.Forms/UIComponents/ShortcutKeysEditor.resx delete mode 100644 src/L10NSharp.Windows.Forms/UIComponents/TipDialog.cs delete mode 100644 src/L10NSharp.Windows.Forms/UIComponents/TipDialog.designer.cs delete mode 100644 src/L10NSharp.Windows.Forms/UIComponents/TipDialog.resx delete mode 100644 src/L10NSharp.Windows.Forms/UIComponents/XButton.cs diff --git a/CHANGELOG.md b/CHANGELOG.md index cb72680..d385c59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +### Changed + - [L10NSharp] Removed emailForSubmissions parameter from LocalizationManager.Create. Since the localization dialog was jettisoned, it no longer makes sense to store this information on the localization manager. + - [L10NSharp.Windows.Forms] Removed emailForSubmissions parameter (8th parameter) from LocalizationManagerWinforms.Create. Since the localization dialog was jettisoned, it no longer makes sense to store this information on the localization manager. + +### Removed +- [L10NSharp] Removed EnableClickingOnControlToBringUpLocalizationDialog. Since the localization dialog was jettisoned, this is meaningless (and wouldn't belong in the Winforms agnostic namespace anyway). +- [L10NSharp] Removed EmailForSubmissions. Since the localization dialog was jettisoned, it no longer makes sense to store this information on the localization manager. + - [L10NSharp.Windows.Forms] Removed LmGrid, LmButtonColumn, LmButtonCell, TipDialog. + ## [9.0.0] - 2026-02-02 ### Changed diff --git a/Directory.Build.props b/Directory.Build.props index 7903aad..e035aee 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -26,6 +26,7 @@ See full changelog at https://github.com/sillsdev/l10nsharp/blob/master/CHANGELO true true true + 8.0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - \ No newline at end of file diff --git a/src/L10NSharp.Windows.Forms/UIComponents/DontShowThisAgainButton.Designer.cs b/src/L10NSharp.Windows.Forms/UIComponents/DontShowThisAgainButton.Designer.cs deleted file mode 100644 index 5563c81..0000000 --- a/src/L10NSharp.Windows.Forms/UIComponents/DontShowThisAgainButton.Designer.cs +++ /dev/null @@ -1,37 +0,0 @@ -namespace L10NSharp.Windows.Forms.UIComponents -{ - partial class DontShowThisAgainButton - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Component Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - components = new System.ComponentModel.Container(); - //this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - } - - #endregion - } -} diff --git a/src/L10NSharp.Windows.Forms/UIComponents/DontShowThisAgainButton.cs b/src/L10NSharp.Windows.Forms/UIComponents/DontShowThisAgainButton.cs deleted file mode 100644 index bb47056..0000000 --- a/src/L10NSharp.Windows.Forms/UIComponents/DontShowThisAgainButton.cs +++ /dev/null @@ -1,108 +0,0 @@ -using System; -using System.ComponentModel; -using System.ComponentModel.Design; -using System.Configuration; -using System.Diagnostics; -using System.Reflection; -using System.Windows.Forms; -using L10NSharp.Properties; - -namespace L10NSharp.Windows.Forms.UIComponents -{ - public partial class DontShowThisAgainButton : CheckBox - { - private ApplicationSettingsBase _settings; - private string _key; - - public DontShowThisAgainButton() - { - InitializeComponent(); - Click += DontShowThisAgainButton_Click; - } - - /// - /// Call this to decide whether to show the dialog - /// - /// enter your Settings.Default. Make sure you have a string property named DontShowThisAgain - /// A key to use for the list of things not-to-show. You're welcome to use a big long string (like a tip message itself); a hash will be used - /// true if you should show it - public bool GetOKToShow(ApplicationSettingsBase settings, string key = null ) - { - if (string.IsNullOrEmpty(key)) - { - _key = FindForm().Name; - } - else - { - _key = key.GetHashCode().ToString(); - } - _settings = settings; - if (settings == null || DesignMode) - return true; - - return !DialogsToHide.Contains(_key + ","); - } - - - - /// - /// This one uses the form's name as an id - /// - /// Your Settings.Default - /// Some string which can be used as a key into the don't-show index - public void CloseIfShouldNotShow(ApplicationSettingsBase settings, string customID = null) - { - if (!GetOKToShow(settings, customID)) - FindForm().Close(); - } - - /// - /// Start showing all dialogs again - /// - public void ResetDontShowMemory(ApplicationSettingsBase settings) - { - _settings = settings; - DialogsToHide = ""; - } - - private void DontShowThisAgainButton_Click(object sender, System.EventArgs e) - { - if (_settings == null) - { - Debug.Fail("You need to call GetOKToShow() on the DontShowThisAgainButton."); - } - var key = DialogsToHide + _key + ","; - DialogsToHide = DialogsToHide.Replace(key, ""); - if (this.Checked) - { - DialogsToHide = key; - } - } - - private string DialogsToHide - { - get - { - var propertyInfo = _settings.GetType().GetProperty("DontShowThisAgain"); - Debug.Assert(propertyInfo != null, "You need to have a string property named DontShowThisAgain in your Settings"); - return (string)propertyInfo.GetValue(_settings, null); - } - set - { - PropertyInfo propertyInfo = _settings.GetType().GetProperty("DontShowThisAgain"); - Debug.Assert(propertyInfo != null, "You need to have a string property named DontShowThisAgain in your Settings"); - propertyInfo.SetValue(_settings, Convert.ChangeType(value, propertyInfo.PropertyType), null); - } - } - - private new bool DesignMode - { - get - { - return (base.DesignMode || GetService(typeof(IDesignerHost)) != null) || - (LicenseManager.UsageMode == LicenseUsageMode.Designtime); - } - } - - } -} diff --git a/src/L10NSharp.Windows.Forms/UIComponents/EditSourceBeforeTranslatingDlg.Designer.cs b/src/L10NSharp.Windows.Forms/UIComponents/EditSourceBeforeTranslatingDlg.Designer.cs deleted file mode 100644 index 8c5432e..0000000 --- a/src/L10NSharp.Windows.Forms/UIComponents/EditSourceBeforeTranslatingDlg.Designer.cs +++ /dev/null @@ -1,209 +0,0 @@ -namespace L10NSharp.Windows.Forms.UIComponents -{ - partial class EditSourceBeforeTranslatingDlg - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(EditSourceBeforeTranslatingDlg)); - this._lableTarget = new System.Windows.Forms.Label(); - this._lableSource = new System.Windows.Forms.Label(); - this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); - this._buttonCopyAndClose = new System.Windows.Forms.Button(); - this._textBoxTarget = new System.Windows.Forms.TextBox(); - this._textBoxSource = new System.Windows.Forms.TextBox(); - this._buttonCancel = new System.Windows.Forms.Button(); - this._buttonTranslate = new System.Windows.Forms.Button(); - this._labelDescription = new System.Windows.Forms.Label(); - this.tableLayoutPanel1.SuspendLayout(); - this.SuspendLayout(); - // - // _lableTarget - // - this._lableTarget.AutoSize = true; - this.tableLayoutPanel1.SetColumnSpan(this._lableTarget, 3); - this._lableTarget.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this._lableTarget.Location = new System.Drawing.Point(0, 163); - this._lableTarget.Margin = new System.Windows.Forms.Padding(0, 10, 0, 0); - this._lableTarget.Name = "_lableTarget"; - this._lableTarget.Size = new System.Drawing.Size(14, 15); - this._lableTarget.TabIndex = 3; - this._lableTarget.Text = "#"; - // - // _lableSource - // - this._lableSource.AutoSize = true; - this.tableLayoutPanel1.SetColumnSpan(this._lableSource, 3); - this._lableSource.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this._lableSource.Location = new System.Drawing.Point(0, 55); - this._lableSource.Margin = new System.Windows.Forms.Padding(0, 10, 0, 0); - this._lableSource.Name = "_lableSource"; - this._lableSource.Size = new System.Drawing.Size(14, 15); - this._lableSource.TabIndex = 1; - this._lableSource.Text = "#"; - // - // tableLayoutPanel1 - // - this.tableLayoutPanel1.ColumnCount = 3; - this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); - this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); - this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); - this.tableLayoutPanel1.Controls.Add(this._buttonCopyAndClose, 0, 5); - this.tableLayoutPanel1.Controls.Add(this._textBoxTarget, 0, 4); - this.tableLayoutPanel1.Controls.Add(this._lableSource, 0, 1); - this.tableLayoutPanel1.Controls.Add(this._lableTarget, 0, 3); - this.tableLayoutPanel1.Controls.Add(this._textBoxSource, 0, 2); - this.tableLayoutPanel1.Controls.Add(this._buttonCancel, 1, 5); - this.tableLayoutPanel1.Controls.Add(this._buttonTranslate, 0, 5); - this.tableLayoutPanel1.Controls.Add(this._labelDescription, 0, 0); - this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill; - this.tableLayoutPanel1.Location = new System.Drawing.Point(12, 12); - this.tableLayoutPanel1.Name = "tableLayoutPanel1"; - this.tableLayoutPanel1.RowCount = 6; - this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); - this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); - this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); - this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50F)); - this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); - this.tableLayoutPanel1.Size = new System.Drawing.Size(565, 293); - this.tableLayoutPanel1.TabIndex = 0; - // - // _buttonCopyAndClose - // - this._buttonCopyAndClose.AutoSize = true; - this._buttonCopyAndClose.Location = new System.Drawing.Point(281, 267); - this._buttonCopyAndClose.Margin = new System.Windows.Forms.Padding(3, 6, 3, 0); - this._buttonCopyAndClose.MinimumSize = new System.Drawing.Size(75, 26); - this._buttonCopyAndClose.Name = "_buttonCopyAndClose"; - this._buttonCopyAndClose.Size = new System.Drawing.Size(203, 26); - this._buttonCopyAndClose.TabIndex = 6; - this._buttonCopyAndClose.Text = "&Copy {0} Text to Clipboard and Close"; - this._buttonCopyAndClose.UseVisualStyleBackColor = true; - // - // _textBoxTarget - // - this._textBoxTarget.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this._textBoxTarget.BackColor = System.Drawing.SystemColors.Window; - this.tableLayoutPanel1.SetColumnSpan(this._textBoxTarget, 3); - this._textBoxTarget.Location = new System.Drawing.Point(0, 181); - this._textBoxTarget.Margin = new System.Windows.Forms.Padding(0, 3, 0, 0); - this._textBoxTarget.Multiline = true; - this._textBoxTarget.Name = "_textBoxTarget"; - this._textBoxTarget.ReadOnly = true; - this._textBoxTarget.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; - this._textBoxTarget.Size = new System.Drawing.Size(565, 80); - this._textBoxTarget.TabIndex = 4; - // - // _textBoxSource - // - this._textBoxSource.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.tableLayoutPanel1.SetColumnSpan(this._textBoxSource, 3); - this._textBoxSource.Location = new System.Drawing.Point(0, 73); - this._textBoxSource.Margin = new System.Windows.Forms.Padding(0, 3, 0, 0); - this._textBoxSource.Multiline = true; - this._textBoxSource.Name = "_textBoxSource"; - this._textBoxSource.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; - this._textBoxSource.Size = new System.Drawing.Size(565, 80); - this._textBoxSource.TabIndex = 2; - // - // _buttonCancel - // - this._buttonCancel.AutoSize = true; - this._buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this._buttonCancel.Location = new System.Drawing.Point(490, 267); - this._buttonCancel.Margin = new System.Windows.Forms.Padding(3, 6, 0, 0); - this._buttonCancel.MinimumSize = new System.Drawing.Size(75, 26); - this._buttonCancel.Name = "_buttonCancel"; - this._buttonCancel.Size = new System.Drawing.Size(75, 26); - this._buttonCancel.TabIndex = 7; - this._buttonCancel.Text = "Cancel"; - this._buttonCancel.UseVisualStyleBackColor = true; - // - // _buttonTranslate - // - this._buttonTranslate.AutoSize = true; - this._buttonTranslate.Location = new System.Drawing.Point(0, 267); - this._buttonTranslate.Margin = new System.Windows.Forms.Padding(0, 6, 3, 0); - this._buttonTranslate.MinimumSize = new System.Drawing.Size(75, 26); - this._buttonTranslate.Name = "_buttonTranslate"; - this._buttonTranslate.Size = new System.Drawing.Size(130, 26); - this._buttonTranslate.TabIndex = 5; - this._buttonTranslate.Text = "&Translate from {0} to {1}"; - this._buttonTranslate.UseVisualStyleBackColor = true; - // - // _labelDescription - // - this._labelDescription.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this._labelDescription.AutoSize = true; - this.tableLayoutPanel1.SetColumnSpan(this._labelDescription, 3); - this._labelDescription.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this._labelDescription.Location = new System.Drawing.Point(0, 0); - this._labelDescription.Margin = new System.Windows.Forms.Padding(0); - this._labelDescription.Name = "_labelDescription"; - this._labelDescription.Size = new System.Drawing.Size(565, 45); - this._labelDescription.TabIndex = 0; - this._labelDescription.Text = resources.GetString("_labelDescription.Text"); - // - // EditSourceBeforeTranslatingDlg - // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.CancelButton = this._buttonCancel; - this.ClientSize = new System.Drawing.Size(589, 317); - this.Controls.Add(this.tableLayoutPanel1); - this.MaximizeBox = false; - this.MinimizeBox = false; - this.Name = "EditSourceBeforeTranslatingDlg"; - this.Padding = new System.Windows.Forms.Padding(12); - this.ShowIcon = false; - this.ShowInTaskbar = false; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; - this.Text = "Edit Source Before Translating"; - this.tableLayoutPanel1.ResumeLayout(false); - this.tableLayoutPanel1.PerformLayout(); - this.ResumeLayout(false); - - } - - #endregion - - private System.Windows.Forms.Label _lableTarget; - private System.Windows.Forms.Label _lableSource; - private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; - private System.Windows.Forms.TextBox _textBoxTarget; - private System.Windows.Forms.TextBox _textBoxSource; - private System.Windows.Forms.Button _buttonCancel; - private System.Windows.Forms.Button _buttonTranslate; - private System.Windows.Forms.Label _labelDescription; - private System.Windows.Forms.Button _buttonCopyAndClose; - } -} diff --git a/src/L10NSharp.Windows.Forms/UIComponents/EditSourceBeforeTranslatingDlg.cs b/src/L10NSharp.Windows.Forms/UIComponents/EditSourceBeforeTranslatingDlg.cs deleted file mode 100644 index ef047a3..0000000 --- a/src/L10NSharp.Windows.Forms/UIComponents/EditSourceBeforeTranslatingDlg.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System; -using System.Drawing; -using System.Globalization; -using System.Windows.Forms; -using L10NSharp.Translators; - -namespace L10NSharp.Windows.Forms.UIComponents -{ - public partial class EditSourceBeforeTranslatingDlg : Form - { - /// ------------------------------------------------------------------------------------ - public EditSourceBeforeTranslatingDlg() - { - InitializeComponent(); - } - - /// ------------------------------------------------------------------------------------ - public EditSourceBeforeTranslatingDlg(string sourceText, string srcLangId, - string tgtLangId, string translatorName, ITranslator translator) : this() - { - _textBoxSource.Font = SystemFonts.MessageBoxFont; - _textBoxTarget.Font = SystemFonts.MessageBoxFont; - - _labelDescription.Text = string.Format(_labelDescription.Text, translatorName); - _lableSource.Text = CultureInfo.GetCultureInfo(srcLangId).DisplayName; - _lableTarget.Text = CultureInfo.GetCultureInfo(tgtLangId).DisplayName; - _buttonTranslate.Text = string.Format(_buttonTranslate.Text, _lableSource.Text, _lableTarget.Text); - _buttonCopyAndClose.Text = string.Format(_buttonCopyAndClose.Text, _lableTarget.Text); - - _textBoxSource.Text = sourceText; - - _buttonCopyAndClose.Enabled = false; - _textBoxTarget.TextChanged += delegate - { - _buttonCopyAndClose.Enabled = !String.IsNullOrEmpty(_textBoxTarget.Text); - }; - - _buttonCopyAndClose.Click += delegate - { - Clipboard.SetText(_textBoxTarget.Text, TextDataFormat.UnicodeText); - Close(); - }; - - _buttonTranslate.Click += delegate - { - _textBoxTarget.Text = translator.TranslateText(_textBoxSource.Text.Trim()) ?? string.Empty; - }; - } - } -} diff --git a/src/L10NSharp.Windows.Forms/UIComponents/EditSourceBeforeTranslatingDlg.resx b/src/L10NSharp.Windows.Forms/UIComponents/EditSourceBeforeTranslatingDlg.resx deleted file mode 100644 index a6b818d..0000000 --- a/src/L10NSharp.Windows.Forms/UIComponents/EditSourceBeforeTranslatingDlg.resx +++ /dev/null @@ -1,123 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - text/microsoft-resx - - - 2.0 - - - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - The selected source text has been copied here for you to edit and experiment how {0} will translate the text. When you are satisfied with the translation, click the button to copy the text to the clipboard. Then paste the text in the localization dialog box. - - \ No newline at end of file diff --git a/src/L10NSharp.Windows.Forms/UIComponents/FallbackLanguagesDlg.cs b/src/L10NSharp.Windows.Forms/UIComponents/FallbackLanguagesDlg.cs index 8a6692c..3cb4562 100644 --- a/src/L10NSharp.Windows.Forms/UIComponents/FallbackLanguagesDlg.cs +++ b/src/L10NSharp.Windows.Forms/UIComponents/FallbackLanguagesDlg.cs @@ -1,11 +1,5 @@ -using System; -using System.Collections.Generic; using System.Globalization; using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Forms; -using L10NSharp; namespace L10NSharp.Windows.Forms.UIComponents { diff --git a/src/L10NSharp.Windows.Forms/UIComponents/FallbackLanguagesDlgBase.cs b/src/L10NSharp.Windows.Forms/UIComponents/FallbackLanguagesDlgBase.cs index 4f65c39..c4f32f9 100644 --- a/src/L10NSharp.Windows.Forms/UIComponents/FallbackLanguagesDlgBase.cs +++ b/src/L10NSharp.Windows.Forms/UIComponents/FallbackLanguagesDlgBase.cs @@ -1,9 +1,10 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Globalization; using System.Windows.Forms; -using L10NSharp; +using JetBrains.Annotations; namespace L10NSharp.Windows.Forms.UIComponents { @@ -19,22 +20,17 @@ public FallbackLanguagesDlgBase() } /// ------------------------------------------------------------------------------------ + [PublicAPI] public IEnumerable FallbackLanguageIds { get { return _listBoxFallbackLanguages.Items.Cast().Select(x => x.Name); } } /// ------------------------------------------------------------------------------------ - private CultureInfo SelectedAvailableLanguage - { - get { return _listBoxAvailableLanguages.SelectedItem as CultureInfo; } - } + private CultureInfo SelectedAvailableLanguage => _listBoxAvailableLanguages.SelectedItem as CultureInfo; /// ------------------------------------------------------------------------------------ - private CultureInfo SelectedFallbackLanguage - { - get { return _listBoxFallbackLanguages.SelectedItem as CultureInfo; } - } + private CultureInfo SelectedFallbackLanguage => _listBoxFallbackLanguages.SelectedItem as CultureInfo; /// ------------------------------------------------------------------------------------ protected void UpdateDisplay() @@ -43,25 +39,27 @@ protected void UpdateDisplay() { int i = Math.Max(0, _listBoxAvailableLanguages.SelectedIndex); _listBoxAvailableLanguages.SelectedItem = _listBoxAvailableLanguages.Items[i]; + Debug.Assert(SelectedAvailableLanguage != null); } if (SelectedFallbackLanguage == null) { int i = Math.Max(0, _listBoxFallbackLanguages.SelectedIndex); _listBoxFallbackLanguages.SelectedItem = _listBoxFallbackLanguages.Items[i]; + Debug.Assert(SelectedFallbackLanguage != null); } - _buttonAdd.Enabled = (_uiCulture.Name != SelectedAvailableLanguage.Name && - !_listBoxFallbackLanguages.Items.Contains(SelectedAvailableLanguage)); + _buttonAdd.Enabled = _uiCulture.Name != SelectedAvailableLanguage.Name && + !_listBoxFallbackLanguages.Items.Contains(SelectedAvailableLanguage); _buttonRemove.Enabled = - (SelectedFallbackLanguage.Name != LocalizationManager.kDefaultLang); + SelectedFallbackLanguage.Name != LocalizationManager.kDefaultLang; - _buttonMoveUp.Enabled = (_listBoxFallbackLanguages.SelectedIndex > 0 && - SelectedFallbackLanguage.Name != LocalizationManager.kDefaultLang); + _buttonMoveUp.Enabled = _listBoxFallbackLanguages.SelectedIndex > 0 && + SelectedFallbackLanguage.Name != LocalizationManager.kDefaultLang; _buttonMoveDown.Enabled = - (_listBoxFallbackLanguages.SelectedIndex < _listBoxFallbackLanguages.Items.Count - 2); + _listBoxFallbackLanguages.SelectedIndex < _listBoxFallbackLanguages.Items.Count - 2; } /// ------------------------------------------------------------------------------------ @@ -95,10 +93,10 @@ private void _buttonMoveDown_Click(object sender, EventArgs e) /// ------------------------------------------------------------------------------------ private void MoveSelectedFallbackLanguage(bool down) { - int dy = (down ? 1 : -1); + int dy = down ? 1 : -1; int i = _listBoxFallbackLanguages.SelectedIndex + dy; - var ci = _listBoxFallbackLanguages.SelectedItem as CultureInfo; + var ci = (CultureInfo)_listBoxFallbackLanguages.SelectedItem; _listBoxFallbackLanguages.Items.Remove(ci); _listBoxFallbackLanguages.Items.Insert(i, ci); _listBoxFallbackLanguages.SelectedItem = ci; diff --git a/src/L10NSharp.Windows.Forms/UIComponents/Grid/LmButtonCell.cs b/src/L10NSharp.Windows.Forms/UIComponents/Grid/LmButtonCell.cs deleted file mode 100644 index 6cff553..0000000 --- a/src/L10NSharp.Windows.Forms/UIComponents/Grid/LmButtonCell.cs +++ /dev/null @@ -1,464 +0,0 @@ -using System; -using System.Drawing; -using System.Windows.Forms; -using System.Windows.Forms.VisualStyles; - -namespace L10NSharp.Windows.Forms.UIComponents -{ - #region LmButtonCell class - /// ---------------------------------------------------------------------------------------- - public class LmButtonCell : DataGridViewTextBoxCell - { - private bool _mouseOverButton; - private bool _mouseDownOnButton; - private bool _enabled = true; - - /// ------------------------------------------------------------------------------------ - /// - /// Repaint the cell when it's enabled property changes. - /// - /// ------------------------------------------------------------------------------------ - public bool Enabled - { - get { return _enabled; } - set - { - _enabled = value; - DataGridView.InvalidateCell(this); - } - } - - /// ------------------------------------------------------------------------------------ - /// - /// Gets the cell's owning SilButtonColumn. - /// - /// ------------------------------------------------------------------------------------ - public LmButtonColumn OwningButtonColumn - { - get - { - if (DataGridView == null || ColumnIndex < 0 || ColumnIndex >= - DataGridView.Columns.Count) - { - return null; - } - - return (DataGridView.Columns[ColumnIndex] as LmButtonColumn); - } - } - - /// ------------------------------------------------------------------------------------ - /// - /// Gets a value indicating whether or not the cell's button should be shown. - /// - /// ------------------------------------------------------------------------------------ - public bool ShowButton - { - get - { - bool owningColShowValue = - (OwningButtonColumn != null && OwningButtonColumn.ShowButton); - - var row = DataGridView.CurrentRow; - - return (owningColShowValue && RowIndex >= 0 && - ((row == null && DataGridView.AllowUserToAddRows) || - (row != null && RowIndex == row.Index))); - } - } - - /// ------------------------------------------------------------------------------------ - /// - /// Gets a value indicating whether or not the specified point is over the cell's - /// radio button. The relativeToCell flag is true when the specified point's origin - /// is relative to the upper right corner of the cell. When false, it's assumed the - /// point's origin is relative to the cell's owning grid control. - /// - /// ------------------------------------------------------------------------------------ - public bool IsPointOverButton(Point pt, bool relativeToCell) - { - // Get the rectangle for the radion button area. - Rectangle rc = DataGridView.GetCellDisplayRectangle(ColumnIndex, RowIndex, false); - Rectangle rcrb; - Rectangle rcText; - GetRectangles(rc, out rcrb, out rcText); - - if (relativeToCell) - { - // Set the button's rectangle location - // relative to the cell instead of the grid. - rcrb.X -= rc.X; - rcrb.Y -= rc.Y; - } - - return rcrb.Contains(pt); - } - - /// ------------------------------------------------------------------------------------ - /// - /// - /// - /// ------------------------------------------------------------------------------------ - protected override void OnMouseLeave(int rowIndex) - { - base.OnMouseLeave(rowIndex); - _mouseOverButton = false; - DataGridView.InvalidateCell(this); - ManageButtonToolTip(); - } - - /// ------------------------------------------------------------------------------------ - /// - /// - /// - /// ------------------------------------------------------------------------------------ - protected override void OnMouseMove(DataGridViewCellMouseEventArgs e) - { - base.OnMouseMove(e); - - if (!_enabled) - return; - - if (!IsPointOverButton(e.Location, true) && _mouseOverButton) - { - _mouseOverButton = false; - DataGridView.InvalidateCell(this); - ManageButtonToolTip(); - } - else if (IsPointOverButton(e.Location, true) && !_mouseOverButton) - { - _mouseOverButton = true; - DataGridView.InvalidateCell(this); - ManageButtonToolTip(); - } - } - - /// ------------------------------------------------------------------------------------ - /// - /// Monitor when the mouse button goes down over the button. - /// - /// ------------------------------------------------------------------------------------ - protected override void OnMouseDown(DataGridViewCellMouseEventArgs e) - { - base.OnMouseDown(e); - - if (_mouseOverButton && !_mouseDownOnButton) - { - _mouseDownOnButton = true; - DataGridView.InvalidateCell(this); - ManageButtonToolTip(); - } - } - - /// ------------------------------------------------------------------------------------ - /// - /// Monitor when the user releases the mouse button. - /// - /// ------------------------------------------------------------------------------------ - protected override void OnMouseUp(DataGridViewCellMouseEventArgs e) - { - _mouseDownOnButton = false; - base.OnMouseUp(e); - DataGridView.InvalidateCell(this); - } - - /// ------------------------------------------------------------------------------------ - /// - /// - /// - /// ------------------------------------------------------------------------------------ - protected override void OnMouseClick(DataGridViewCellMouseEventArgs e) - { - if (!IsPointOverButton(e.Location, true) || !ShowButton || IsInEditMode) - { - base.OnMouseClick(e); - return; - } - - LmButtonColumn col = - DataGridView.Columns[ColumnIndex] as LmButtonColumn; - - if (col != null) - col.InvokeButtonClick(e); - } - - /// ------------------------------------------------------------------------------------ - /// - /// - /// - /// ------------------------------------------------------------------------------------ - private void ManageButtonToolTip() - { - if (OwningButtonColumn != null && _mouseOverButton && !_mouseDownOnButton) - OwningButtonColumn.ShowToolTip(); - else - OwningButtonColumn.HideToolTip(); - } - - /// ------------------------------------------------------------------------------------ - /// - /// - /// - /// ------------------------------------------------------------------------------------ - protected override void Paint(Graphics g, Rectangle clipBounds, - Rectangle bounds, int rowIndex, DataGridViewElementStates state, - object value, object formattedValue, string errorText, DataGridViewCellStyle style, - DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts parts) - { - bool useEllipsisPath = (OwningButtonColumn != null && - OwningButtonColumn.DrawTextWithEllipsisPath); - - if (!ShowButton && !useEllipsisPath) - { - base.Paint(g, clipBounds, bounds, rowIndex, state, value, - formattedValue, errorText, style, advancedBorderStyle, parts); - - return; - } - - // Draw default everything but text. - parts &= ~DataGridViewPaintParts.ContentForeground; - base.Paint(g, clipBounds, bounds, rowIndex, state, value, - formattedValue, errorText, style, advancedBorderStyle, parts); - - // Get the rectangles for the two parts of the cell. - Rectangle rcbtn; - Rectangle rcText; - GetRectangles(bounds, out rcbtn, out rcText); - DrawButton(g, rcbtn); - DrawCellText(g, value as string, style, rcText); - } - - /// ------------------------------------------------------------------------------------ - /// - /// Draws the button in the cell. - /// - /// ------------------------------------------------------------------------------------ - private void DrawButton(Graphics g, Rectangle rcbtn) - { - if (!ShowButton) - return; - - var buttonStyle = OwningButtonColumn.ButtonStyle; - - if (buttonStyle == LmButtonColumn.ButtonType.MinimalistCombo) - DrawMinimalistButton(g, rcbtn); - else - { - if ((buttonStyle == LmButtonColumn.ButtonType.VisualStyleCombo || - buttonStyle == LmButtonColumn.ButtonType.VisualStylePush) && - !DrawVisualStyledButton(buttonStyle, g, rcbtn)) - { - DrawPlainButton(buttonStyle, g, rcbtn); - } - } - - string buttonText = (OwningButtonColumn == null ? null : OwningButtonColumn.ButtonText); - if (string.IsNullOrEmpty(buttonText)) - return; - - Font buttonFont = (OwningButtonColumn == null ? - SystemInformation.MenuFont : OwningButtonColumn.ButtonFont); - - // Draw text - const TextFormatFlags flags = TextFormatFlags.HorizontalCenter | - TextFormatFlags.VerticalCenter | TextFormatFlags.SingleLine | - TextFormatFlags.NoPrefix | TextFormatFlags.EndEllipsis | - TextFormatFlags.NoPadding | TextFormatFlags.PreserveGraphicsClipping; - - Color clrText = (_enabled ? SystemColors.ControlText : SystemColors.GrayText); - TextRenderer.DrawText(g, buttonText, buttonFont, rcbtn, clrText, flags); - } - - /// ------------------------------------------------------------------------------------ - private void DrawMinimalistButton(Graphics g, Rectangle rc) - { - var element = GetVisualStyleComboButton(); - rc = AdjustRectToDefaultComboButtonWidth(rc); - - if (element != VisualStyleElement.ComboBox.DropDownButton.Normal && - element != VisualStyleElement.ComboBox.DropDownButton.Disabled && - PaintingHelper.CanPaintVisualStyle(element)) - { - var renderer = new VisualStyleRenderer(element); - renderer.DrawBackground(g, rc); - } - else - { - var pen = (element == VisualStyleElement.ComboBox.DropDownButton.Disabled ? - SystemPens.GrayText : SystemPens.WindowText); - - var x = rc.X + (int)Math.Round((rc.Width - 7) / 2f, MidpointRounding.AwayFromZero); - var y = rc.Y + (int)Math.Round((rc.Height - 4) / 2f, MidpointRounding.AwayFromZero); - g.DrawLine(pen, x, y, x + 6, y++); - g.DrawLine(pen, x + 1, y, x + 5, y++); - g.DrawLine(pen, x + 2, y, x + 4, y); - g.DrawLine(pen, x + 3, y, x + 3, y + 1); - return; - } - } - - /// ------------------------------------------------------------------------------------ - private bool DrawVisualStyledButton(LmButtonColumn.ButtonType buttonStyle, - IDeviceContext g, Rectangle rcbtn) - { - VisualStyleElement element = (buttonStyle == LmButtonColumn.ButtonType.VisualStyleCombo ? - GetVisualStyleComboButton() : GetVisualStylePushButton()); - - if (!PaintingHelper.CanPaintVisualStyle(element)) - return false; - - VisualStyleRenderer renderer = new VisualStyleRenderer(element); - rcbtn = AdjustRectToDefaultComboButtonWidth(rcbtn); - renderer.DrawBackground(g, rcbtn); - return true; - } - - /// ------------------------------------------------------------------------------------ - private Rectangle AdjustRectToDefaultComboButtonWidth(Rectangle rc) - { - if (!OwningButtonColumn.DrawDefaultComboButtonWidth) - return rc; - - var rcNew = rc; - rcNew.Width = SystemInformation.VerticalScrollBarWidth; - rcNew.X = (rc.Right - rcNew.Width); - return rcNew; - } - - /// ------------------------------------------------------------------------------------ - private void DrawPlainButton(LmButtonColumn.ButtonType type, Graphics g, Rectangle rcbtn) - { - ButtonState state = (_mouseDownOnButton && _mouseOverButton && _enabled ? - ButtonState.Pushed : ButtonState.Normal); - - if (!_enabled) - state |= ButtonState.Inactive; - - if (type != LmButtonColumn.ButtonType.PlainCombo) - ControlPaint.DrawButton(g, rcbtn, state); - else - { - rcbtn = AdjustRectToDefaultComboButtonWidth(rcbtn); - ControlPaint.DrawComboButton(g, rcbtn, state); - } - } - - /// ------------------------------------------------------------------------------------ - /// - /// Draws the cell's text. - /// - /// ------------------------------------------------------------------------------------ - private void DrawCellText(IDeviceContext g, string text, DataGridViewCellStyle style, - Rectangle rcText) - { - if (string.IsNullOrEmpty(text)) - return; - - // Determine the text's proper foreground color. - Color clrText = SystemColors.GrayText; - if (_enabled && DataGridView != null) - clrText = (Selected ? style.SelectionForeColor : style.ForeColor); - - bool useEllipsisPath = (OwningButtonColumn != null && - OwningButtonColumn.DrawTextWithEllipsisPath); - - TextFormatFlags flags = TextFormatFlags.LeftAndRightPadding | - TextFormatFlags.VerticalCenter | TextFormatFlags.SingleLine | - TextFormatFlags.NoPrefix | (useEllipsisPath ? - TextFormatFlags.PathEllipsis : TextFormatFlags.EndEllipsis) | - TextFormatFlags.PreserveGraphicsClipping; - - TextRenderer.DrawText(g, text, style.Font, rcText, clrText, flags); - } - - /// ------------------------------------------------------------------------------------ - /// - /// Gets the correct visual style push button given the state of the cell. - /// - /// ------------------------------------------------------------------------------------ - private VisualStyleElement GetVisualStylePushButton() - { - VisualStyleElement element = VisualStyleElement.Button.PushButton.Normal; - - if (!_enabled) - element = VisualStyleElement.Button.PushButton.Disabled; - else if (_mouseOverButton) - { - element = (_mouseDownOnButton ? - VisualStyleElement.Button.PushButton.Pressed : - VisualStyleElement.Button.PushButton.Hot); - } - - return element; - } - - /// ------------------------------------------------------------------------------------ - /// - /// Gets the correct visual style combo button given the state of the cell. - /// - /// ------------------------------------------------------------------------------------ - private VisualStyleElement GetVisualStyleComboButton() - { - VisualStyleElement element = VisualStyleElement.ComboBox.DropDownButton.Normal; - - if (!_enabled) - element = VisualStyleElement.ComboBox.DropDownButton.Disabled; - else if (_mouseOverButton) - { - element = (_mouseDownOnButton ? - VisualStyleElement.ComboBox.DropDownButton.Pressed : - VisualStyleElement.ComboBox.DropDownButton.Hot); - } - - return element; - } - - /// ------------------------------------------------------------------------------------ - /// - /// Gets the rectangle for the radio button and the text, given the specified cell - /// bounds. - /// - /// The rectangle of the entire cell. - /// The returned rectangle for the button. - /// The returned rectangle for the text. - /// ------------------------------------------------------------------------------------ - public void GetRectangles(Rectangle bounds, out Rectangle rcbtn, out Rectangle rcText) - { - if (!ShowButton) - { - rcbtn = Rectangle.Empty; - rcText = bounds; - return; - } - - int buttonWidth = (OwningButtonColumn == null ? - SystemInformation.VerticalScrollBarWidth : OwningButtonColumn.ButtonWidth); - - bool paintComboButton = (OwningButtonColumn == null ? false : - OwningButtonColumn.ButtonStyle != LmButtonColumn.ButtonType.PlainPush && - OwningButtonColumn.ButtonStyle != LmButtonColumn.ButtonType.VisualStylePush); - - if (paintComboButton) - buttonWidth += 2; - - rcText = bounds; - rcText.Width -= buttonWidth; - - rcbtn = bounds; - rcbtn.Width = buttonWidth; - rcbtn.X = bounds.Right - buttonWidth - 1; - rcbtn.Y--; - - if (paintComboButton) - { - rcbtn.Width -= 2; - rcbtn.Height -= 3; - rcbtn.X++; - rcbtn.Y += 2; - } - } - } - - #endregion -} diff --git a/src/L10NSharp.Windows.Forms/UIComponents/Grid/LmButtonColumn.cs b/src/L10NSharp.Windows.Forms/UIComponents/Grid/LmButtonColumn.cs deleted file mode 100644 index d716b1a..0000000 --- a/src/L10NSharp.Windows.Forms/UIComponents/Grid/LmButtonColumn.cs +++ /dev/null @@ -1,214 +0,0 @@ -using System; -using System.Drawing; -using System.Windows.Forms; - -namespace L10NSharp.Windows.Forms.UIComponents -{ - /// ---------------------------------------------------------------------------------------- - public class LmButtonColumn : DataGridViewColumn - { - public enum ButtonType - { - /// Draws just a simple drop-down arrow with no button border or background. - MinimalistCombo, - /// Draws a plain combo box button, not using visual styles. - PlainCombo, - /// Draws a plain push button, not using visual styles. - PlainPush, - /// Draws a combo box button using current visual style. - VisualStyleCombo, - /// Draws a normal button using current visual style. - VisualStylePush - } - - public event DataGridViewCellMouseEventHandler ButtonClicked; - private bool _showButton = true; - private string _buttonToolTip; - private ToolTip _toolTip; - private bool _showCellToolTips = true; - - /// ------------------------------------------------------------------------------------ - public LmButtonColumn() : base(new LmButtonCell()) - { - DrawDefaultComboButtonWidth = true; - ButtonWidth = SystemInformation.VerticalScrollBarWidth; - base.DefaultCellStyle.Font = SystemInformation.MenuFont; - ButtonFont = SystemInformation.MenuFont; - Width = 100 + ButtonWidth; - HeaderText = string.Empty; - } - - /// ------------------------------------------------------------------------------------ - public LmButtonColumn(string name) : this() - { - Name = name; - } - - /// ------------------------------------------------------------------------------------ - public LmButtonColumn(string name, bool showButton) : this() - { - Name = name; - _showButton = showButton; - } - - /// ------------------------------------------------------------------------------------ - /// - /// Make sure the template is always a radion button cell. - /// - /// ------------------------------------------------------------------------------------ - public override DataGridViewCell CellTemplate - { - get { return base.CellTemplate; } - set - { - if (value != null && !value.GetType().IsAssignableFrom(typeof(LmButtonCell))) - throw new InvalidCastException("Must be a SilButtonCell"); - - base.CellTemplate = value; - } - } - - /// ------------------------------------------------------------------------------------ - /// - /// Need to save the value of the owning grid's ShowCellToolTips value because we may - /// change it once in a while. - /// - /// ------------------------------------------------------------------------------------ - protected override void OnDataGridViewChanged() - { - base.OnDataGridViewChanged(); - if (DataGridView != null) - _showCellToolTips = DataGridView.ShowCellToolTips; - } - - /// ------------------------------------------------------------------------------------ - /// - /// Gets or sets the text of the button cells in this column. - /// - /// ------------------------------------------------------------------------------------ - public string ButtonText { get; set; } - - /// ------------------------------------------------------------------------------------ - /// - /// Gets or sets the text of the button cells in this column. - /// - /// ------------------------------------------------------------------------------------ - public Font ButtonFont { get; set; } - - /// ------------------------------------------------------------------------------------ - /// - /// Gets or sets the width of the button within the column's cells. - /// - /// ------------------------------------------------------------------------------------ - public int ButtonWidth { get; set; } - - /// ------------------------------------------------------------------------------------ - /// - /// Gets or sets a value indicating whether or not to paint a combo box style button - /// in the column's owned cells. If false, a push button style is drawn. - /// - /// ------------------------------------------------------------------------------------ - [Obsolete("Use ButtonStyle Property")] - public bool UseComboButtonStyle { get; set; } - - public ButtonType ButtonStyle { get; set; } - - /// ------------------------------------------------------------------------------------ - /// - /// Gets or sets a value indicating whether or not the combo button's width is - /// calculated automatically by the system (based on the theme). This value is only - /// relevant when UseComboButtonStyle is true and visual styles in the OS are - /// turned on. - /// - /// ------------------------------------------------------------------------------------ - public bool DrawDefaultComboButtonWidth { get; set; } - - /// ------------------------------------------------------------------------------------ - /// - /// Gets or sets a value indicating whether or not to show the button. - /// - /// ------------------------------------------------------------------------------------ - public bool ShowButton - { - get { return _showButton; } - set - { - _showButton = value; - if (DataGridView != null) - DataGridView.InvalidateColumn(Index); - } - } - - /// ------------------------------------------------------------------------------------ - /// - /// Gets or sets a value indicating whether or not text in the button cells in the - /// column will be drawn using ellipsis path string formatting. - /// - /// ------------------------------------------------------------------------------------ - public bool DrawTextWithEllipsisPath { get; set; } - - /// ------------------------------------------------------------------------------------ - /// - /// Gets or sets the tooltip text for the buttons in the button cells in this column. - /// - /// ------------------------------------------------------------------------------------ - public string ButtonToolTip - { - get { return _buttonToolTip; } - set - { - if (_toolTip != null) - { - _toolTip.Dispose(); - _toolTip = null; - } - - _buttonToolTip = value; - } - } - - /// ------------------------------------------------------------------------------------ - internal void ShowToolTip() - { - if ((_toolTip != null && _toolTip.Active) || string.IsNullOrEmpty(_buttonToolTip) || - DataGridView == null || DataGridView.FindForm() == null) - { - return; - } - - if (_toolTip == null) - _toolTip = new ToolTip(); - - DataGridView.ShowCellToolTips = false; - Size sz = SystemInformation.CursorSize; - Point pt = DataGridView.FindForm().PointToClient(Control.MousePosition); - pt.X += (int)(sz.Width * 0.6); - pt.Y += sz.Height; - _toolTip.Active = true; - _toolTip.Show(_buttonToolTip, DataGridView.FindForm(), pt); - } - - /// ------------------------------------------------------------------------------------ - internal void HideToolTip() - { - DataGridView.ShowCellToolTips = _showCellToolTips; - - if (_toolTip != null) - { - _toolTip.Hide(DataGridView); - _toolTip.Active = false; - } - } - - /// ------------------------------------------------------------------------------------ - /// - /// Provides a way for an owned cell to fire the button clicked event on the column. - /// - /// ------------------------------------------------------------------------------------ - internal void InvokeButtonClick(DataGridViewCellMouseEventArgs e) - { - if (ButtonClicked != null) - ButtonClicked(DataGridView, e); - } - } -} diff --git a/src/L10NSharp.Windows.Forms/UIComponents/Grid/LmGrid.cs b/src/L10NSharp.Windows.Forms/UIComponents/Grid/LmGrid.cs deleted file mode 100644 index 770e9ad..0000000 --- a/src/L10NSharp.Windows.Forms/UIComponents/Grid/LmGrid.cs +++ /dev/null @@ -1,1419 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.ComponentModel; -using System.Drawing; -using System.Linq; -using System.Windows.Forms; -using System.Windows.Forms.VisualStyles; - -namespace L10NSharp.Windows.Forms.UIComponents -{ - /// ---------------------------------------------------------------------------------------- - public class LmGrid : DataGridView - { - public delegate KeyValuePair> GetComboCellListHandler(object sender, - DataGridViewCell cell, DataGridViewEditingControlShowingEventArgs args); - - public event GetComboCellListHandler GetComboCellList; - - //public delegate void ComboCellListValueSelectedHandler(object sender, DataGridViewCell cell, object selectedValue); - //public event ComboCellListValueSelectedHandler ComboCellListValueSelected; - - /// Occurs when a row is entered and after the current row's index changes. - public event EventHandler CurrentRowChanged; - - public event DataGridViewCellPaintingEventHandler DrawFocusRectangle; - - public delegate void GetWaterMarkRectHandler(object sender, - Rectangle adjustedClientRect, ref Rectangle rcProposed); - - public event GetWaterMarkRectHandler GetWaterMarkRect; - - private const string kDropDownStyle = "DropDown"; - - protected Action RemoveRowAction; - protected Func GetRemoveRowToolTipText; - protected Image m_removeRowImageNormal; - protected Image m_removeRowImageHot; - - protected bool _isDirty; - protected bool _paintWaterMark; - protected bool _showWaterMarkWhenDirty; - protected string _waterMark = "!"; - protected int _prevRowIndex = -1; - - /// ------------------------------------------------------------------------------------ - public LmGrid() - { - DoubleBuffered = true; - AllowUserToOrderColumns = true; - AllowUserToResizeRows = false; - AllowUserToAddRows = false; - AllowUserToDeleteRows = false; - AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders; - FullRowFocusRectangleColor = SystemColors.ControlDark; - BackgroundColor = DefaultCellStyle.BackColor = SystemColors.Window; - base.ForeColor = DefaultCellStyle.ForeColor = SystemColors.WindowText; - SelectionMode = DataGridViewSelectionMode.FullRowSelect; - BorderStyle = BorderStyle.Fixed3D; - ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.None; - ColumnHeadersDefaultCellStyle.Font = SystemFonts.IconTitleFont; - Font = SystemFonts.IconTitleFont; - RowHeadersBorderStyle = DataGridViewHeaderBorderStyle.None; - RowHeadersWidth = 22; - Color clr = SystemColors.Window; - GridColor = Color.FromArgb(clr.R - 30, clr.G - 30, clr.B - 30); - MultiSelect = false; - PaintHeaderAcrossFullGridWidth = true; - TextBoxEditControlBorderColor = Color.Silver; - } - - #region Properties - /// ------------------------------------------------------------------------------------ - /// - /// Gets the count of rows in the grid, excluding the new row (which really isn't a - /// row until someone enters data into it). - /// - /// ------------------------------------------------------------------------------------ - public int RowCountLessNewRow - { - get { return (NewRowIndex == RowCount - 1 && RowCount > 0 ? RowCount - 1 : RowCount); } - } - - /// ------------------------------------------------------------------------------------ - /// - /// Gets or sets a value indicating whether or not the grid's contents are dirty. - /// - /// ------------------------------------------------------------------------------------ - public bool IsDirty - { - get {return _isDirty;} - set - { - _isDirty = value; - _paintWaterMark = (value && _showWaterMarkWhenDirty); - - if (_showWaterMarkWhenDirty) - Invalidate(); - } - } - - /// ------------------------------------------------------------------------------------ - /// - /// Paints a header in the gap (if there is one) between the furthest right column and - /// the right edge of the grid control. - /// - /// ------------------------------------------------------------------------------------ - [Browsable(true)] - [DefaultValue(false)] - public bool PaintHeaderAcrossFullGridWidth { get; set; } - - /// ------------------------------------------------------------------------------------ - /// - /// When the selection mode is full row and the right edge of the last column doesn't - /// extend to the right edge of the client area, setting this flag to true will cause - /// the full row selection rectangle to extend all the way to the right edge of the - /// grid. - /// - /// ------------------------------------------------------------------------------------ - [Browsable(true)] - [DefaultValue(false)] - public bool ExtendFullRowSelectRectangleToEdge { get; set; } - - /// ------------------------------------------------------------------------------------ - [Browsable(true)] - [DefaultValue(false)] - public bool PaintFullRowFocusRectangle { get; set; } - - /// ------------------------------------------------------------------------------------ - /// - /// Gets or sets a value determining whether or not to draw a border around a text - /// box cell's edit control when the cell is in the edit mode. - /// - /// ------------------------------------------------------------------------------------ - [Browsable(true)] - [DefaultValue(true)] - public bool DrawTextBoxEditControlBorder { get; set; } - - /// ------------------------------------------------------------------------------------ - [Browsable(true)] - public Color TextBoxEditControlBorderColor { get; set; } - - /// ------------------------------------------------------------------------------------ - [Browsable(true)] - public Color FullRowFocusRectangleColor { get; set; } - - /// ------------------------------------------------------------------------------------ - /// - /// Gets or sets the foreground color of the current cell in the current row - /// (i.e. when full row select is true). When this value is Color.Empty - /// (i.e. default), then the default selection color is used. - /// - /// ------------------------------------------------------------------------------------ - [Browsable(true)] - public Color SelectedCellForeColor { get; set; } - - /// ------------------------------------------------------------------------------------ - /// - /// Gets or sets the foreground color of cells that are not current but are in the - /// current row (i.e. when full row select is true). When this value is Color.Empty - /// (i.e. default), then the default selection color is used. - /// - /// ------------------------------------------------------------------------------------ - [Browsable(true)] - public Color SelectedRowForeColor { get; set; } - - /// ------------------------------------------------------------------------------------ - /// - /// Gets or sets the background color of the current cell in the current row - /// (i.e. when full row select is true). When this value is Color.Empty - /// (i.e. default), then the default selection color is used. - /// - /// ------------------------------------------------------------------------------------ - [Browsable(true)] - public Color SelectedCellBackColor { get; set; } - - /// ------------------------------------------------------------------------------------ - /// - /// Gets or sets the background color of cells that are not current but are in the - /// current row (i.e. when full row select is true). When this value is Color.Empty - /// (i.e. default), then the default selection color is used. - /// - /// ------------------------------------------------------------------------------------ - [Browsable(true)] - public Color SelectedRowBackColor { get; set; } - - #endregion - - #region Watermark handling methods - /// ------------------------------------------------------------------------------------ - /// - /// Gets or sets a value indicating whether or not a water mark is shown when the grid - /// is dirty. - /// - /// ------------------------------------------------------------------------------------ - public bool ShowWaterMarkWhenDirty - { - get { return _showWaterMarkWhenDirty; } - set - { - _showWaterMarkWhenDirty = value; - _paintWaterMark = (value && _isDirty); - Invalidate(); - } - } - - /// ------------------------------------------------------------------------------------ - /// - /// Gets or sets the character displayed as the water mark. - /// - /// ------------------------------------------------------------------------------------ - public string WaterMark - { - get { return _waterMark; } - set - { - _waterMark = value; - if (_paintWaterMark) - Invalidate(); - } - } - - /// ------------------------------------------------------------------------------------ - /// - /// Gets the rectangle in which the watermark is drawn. - /// - /// ------------------------------------------------------------------------------------ - private Rectangle WaterMarkRectangle - { - get - { - Rectangle rc; - int clientWidth = ClientSize.Width; - - if (Rows.Count > 0 && Columns.Count > 0 && FirstDisplayedCell != null) - { - // Determine whether or not the vertical scroll bar is showing. - int visibleRows = Rows.GetRowCount(DataGridViewElementStates.Visible); - rc = GetCellDisplayRectangle(0, FirstDisplayedCell.RowIndex, false); - if (rc.Height * visibleRows >= ClientSize.Height) - clientWidth -= SystemInformation.VerticalScrollBarWidth; - } - - // Modify the client rectangle so it doesn't - // include the vertical scroll bar width. - rc = ClientRectangle; - rc.Width = (int)(clientWidth * 0.5f); - rc.Height = (int)(rc.Height * 0.5f); - rc.X = (clientWidth - rc.Width) / 2; - rc.Y = (ClientRectangle.Height - rc.Height) / 2; - - // Get the rectangle from subscribers if there are any. - // If not, then just return a rectangle centered in the grid. - if (GetWaterMarkRect != null) - { - Rectangle rcAdjustedClientRect = ClientRectangle; - rcAdjustedClientRect.Width = clientWidth; - GetWaterMarkRect(this, rcAdjustedClientRect, ref rc); - } - - return rc; - } - } - - /// ------------------------------------------------------------------------------------ - /// - /// Update the water mark when the grid changes size. - /// - /// ------------------------------------------------------------------------------------ - protected override void OnSizeChanged(EventArgs e) - { - bool paintWaterMark = _paintWaterMark; - - if (_paintWaterMark) - { - // Clear previous water mark. - _paintWaterMark = false; - Invalidate(); - } - - base.OnSizeChanged(e); - - _paintWaterMark = paintWaterMark; - if (_paintWaterMark) - Invalidate(WaterMarkRectangle); - - if (!_paintWaterMark && Focused && PaintFullRowFocusRectangle && - CurrentCellAddress.Y >= 0 && CurrentCellAddress.Y < RowCount) - { - InvalidateRow(CurrentCellAddress.Y); - } - } - - /// ------------------------------------------------------------------------------------ - protected override void OnGotFocus(EventArgs e) - { - base.OnGotFocus(e); - - // For some reason, using OnEnter only redraws the current cell, not the - // entire row. This event works better. - InvalidateRowInFullRowSelectMode(CurrentCellAddress.Y); - } - - /// ------------------------------------------------------------------------------------ - protected override void OnLeave(EventArgs e) - { - base.OnLeave(e); - InvalidateRowInFullRowSelectMode(CurrentCellAddress.Y); - } - - /// ------------------------------------------------------------------------------------ - public VScrollBar VScrollBar - { - get { return Controls.OfType().Select(ctrl => ctrl).FirstOrDefault(); } - } - - /// ------------------------------------------------------------------------------------ - public HScrollBar HScrollBar - { - get { return Controls.OfType().Select(ctrl => ctrl).FirstOrDefault(); } - } - - /// ------------------------------------------------------------------------------------ - /// - /// Update the water mark when the grid scrolls. - /// - /// ------------------------------------------------------------------------------------ - protected override void OnScroll(ScrollEventArgs e) - { - bool paintWaterMark = _paintWaterMark; - - if (_paintWaterMark) - { - // Clear previous water mark. - _paintWaterMark = false; - Invalidate(); - } - - base.OnScroll(e); - - _paintWaterMark = paintWaterMark; - if (_paintWaterMark) - Invalidate(WaterMarkRectangle); - - // This chunk of code takes care of painting problems when scrolling and a full - // row focus rectangle is being drawn. The problems are: - // 1) When there are fixed columns and the grid scrolls horizontally so that it - // exposes columns that were scrolled out of view under some fixed columns, - // the top focus rect. line of the cells scrolling into view are not painted. - // 2) One problem has to do with the first row of pixels below the column headers. - // The focus rectangle color was getting left behind when selected rows were - // being scrolled upward, out of view. - // 3) Another problem has to do with the selected row losing the top edge of its - // focus rectangle when it is scrolled downward after having been the top visible row. - if (PaintFullRowFocusRectangle && SelectionMode == DataGridViewSelectionMode.FullRowSelect) - { - if (e.ScrollOrientation == ScrollOrientation.HorizontalScroll) - { - InvalidateRowInFullRowSelectMode(CurrentCellAddress.Y); - } - else - { - if (CurrentCellAddress.Y >= 0 && CurrentCellAddress.Y < RowCount) - { - Invalidate(new Rectangle(0, ColumnHeadersHeight - 1, ClientSize.Width, 2)); - - if (FirstDisplayedScrollingRowIndex == CurrentCellAddress.Y - 1) - InvalidateRowInFullRowSelectMode(CurrentCellAddress.Y); - } - } - } - } - - /// ------------------------------------------------------------------------------------ - /// - /// Paints a water mark when the results are stale (i.e. the query settings have been - /// changed since the results were shown). - /// - /// ------------------------------------------------------------------------------------ - protected override void OnPaint(PaintEventArgs e) - { - base.OnPaint(e); - - //if (!_paintWaterMark || string.IsNullOrEmpty(_waterMark)) - // return; - - //Rectangle rc = WaterMarkRectangle; - //GraphicsPath path = new GraphicsPath(); - //FontFamily family = FontFamily.GenericSerif; - - //// Find the first font size equal to or smaller than 256 that - //// fits in the water mark rectangle. - //for (int size = 256; size >= 0; size -= 2) - //{ - // using (Font fnt = FontHelper.MakeFont(family.Name, size, FontStyle.Bold)) - // { - // int height = TextRenderer.MeasureText(_waterMark, fnt).Height; - // if (height < rc.Height) - // { - // using (StringFormat sf = Utils.GetStringFormat(true)) - // path.AddString(_waterMark, family, (int)FontStyle.Bold, size, rc, sf); - - // break; - // } - // } - //} - - //path.AddEllipse(rc); - - //using (SolidBrush br = new SolidBrush(Color.FromArgb(35, DefaultCellStyle.ForeColor))) - // e.Graphics.FillRegion(br, new Region(path)); - } - - /// ------------------------------------------------------------------------------------ - /// - /// When a cell is in the edit mode and all the text in the edit control is selected, - /// pressing the home key changes the cell to the first cell in the row and pressing - /// the end key changes the cell to the last cell in the row. This seems counter - /// intuitive. I would expect the cursor to move to the beginning or end of the text - /// within the edit control, therefore, this method will trap those two keys and - /// force this desired behavior, then eat the key message as though it wasn't - /// dispatched. - /// - /// ------------------------------------------------------------------------------------ - protected override bool ProcessCmdKey(ref Message msg, Keys keyData) - { - if (IsCurrentCellInEditMode) - { - if (keyData == Keys.Escape) - { - CancelEdit(); - EndEdit(); - return true; - } - - if (EditingControl is TextBox) - { - var txtBox = ((TextBox)EditingControl); - - // Only override the default behavior when all the text in the edit control is selected. - if (keyData == Keys.Home || keyData == Keys.End && txtBox.SelectedText == txtBox.Text) - { - ProcessHomeAndEndKeys(txtBox, keyData); - return true; - } - - if (keyData == Keys.Up && ProcessUpKey(txtBox)) - return true; - - if (keyData == Keys.Down && ProcessDownKey(txtBox)) - return true; - } - } - - return base.ProcessCmdKey(ref msg, keyData); - } - - /// ------------------------------------------------------------------------------------ - /// - /// Processes the home and end keys. - /// - /// ------------------------------------------------------------------------------------ - private static void ProcessHomeAndEndKeys(TextBoxBase txtBox, Keys keys) - { - txtBox.SelectionStart = (keys == Keys.Home ? 0 : txtBox.Text.Length); - txtBox.SelectionLength = 0; - } - - /// ------------------------------------------------------------------------------------ - /// - /// Processes up key when a grid cell is in the edit mode. This overrides the default - /// behavior in a grid cell when it's being edited so using the up arrow will move the - /// IP up one line rather than moving to the previous row. - /// - /// ------------------------------------------------------------------------------------ - protected bool ProcessUpKey(TextBox txtBox) - { - // Don't override the default behavior if all the text is selected. - if (txtBox.SelectedText == txtBox.Text) - return false; - - Point pt = txtBox.GetPositionFromCharIndex(txtBox.SelectionStart); - - if (pt.Y == 0) - return false; - - pt.Y -= TextRenderer.MeasureText("x", txtBox.Font).Height; - txtBox.SelectionStart = txtBox.GetCharIndexFromPosition(pt); - return true; - } - - /// ------------------------------------------------------------------------------------ - /// - /// Processes down key when a grid cell is in the edit mode. This overrides the default - /// behavior in a grid cell when it's being edited so using the down arrow will move the - /// IP down one line rather than moving to the next row. - /// - /// ------------------------------------------------------------------------------------ - protected bool ProcessDownKey(TextBox txtBox) - { - // Don't override the default behavior if all the text is selected. - if (txtBox.SelectedText == txtBox.Text) - return false; - - int chrIndex = txtBox.SelectionStart; - Point pt = txtBox.GetPositionFromCharIndex(txtBox.SelectionStart); - pt.Y += TextRenderer.MeasureText("x", txtBox.Font).Height; - txtBox.SelectionStart = txtBox.GetCharIndexFromPosition(pt); - return (chrIndex != txtBox.SelectionStart); - } - - /// ------------------------------------------------------------------------------------ - /// - /// In order to achieve double buffering without the problem that arises from having - /// double buffering on while sizing rows and columns or dragging columns around, - /// monitor when the mouse goes down and turn off double buffering when it goes down - /// on a column heading or over the dividers between rows or the dividers between - /// columns. - /// - /// ------------------------------------------------------------------------------------ - protected override void OnCellMouseDown(DataGridViewCellMouseEventArgs e) - { - if (Cursor == Cursors.SizeNS || Cursor == Cursors.SizeWE) - DoubleBuffered = false; - - base.OnCellMouseDown(e); - } - - /// ------------------------------------------------------------------------------------ - /// - /// When double buffering is off, it means it was turned off in the cell mouse down - /// event. Therefore, turn it back on. - /// - /// ------------------------------------------------------------------------------------ - protected override void OnCellMouseUp(DataGridViewCellMouseEventArgs e) - { - if (!DoubleBuffered) - DoubleBuffered = true; - - base.OnCellMouseUp(e); - } - - /// ------------------------------------------------------------------------------------ - /// - /// For checkbox columns, force the click on the checkbox to get committed right - /// away. I can't think of when that wouldn't be expected. - /// - /// ------------------------------------------------------------------------------------ - protected override void OnCellContentClick(DataGridViewCellEventArgs e) - { - base.OnCellContentClick(e); - - if (e.ColumnIndex < 0 || e.RowIndex < 0) - return; - - if (Columns[e.ColumnIndex] is DataGridViewCheckBoxColumn) - { - // Force commital of the click's change. - CommitEdit(DataGridViewDataErrorContexts.Commit); - EndEdit(); - } - else if (e.RowIndex < NewRowIndex && RemoveRowAction != null && - GetColumnName(e.ColumnIndex) == "removerow") - { - RemoveRowAction(e.RowIndex); - RowCount--; - Invalidate(); - } - } - - /// ------------------------------------------------------------------------------------ - protected override void OnRowsAdded(DataGridViewRowsAddedEventArgs e) - { - base.OnRowsAdded(e); - IsDirty = true; - } - - /// ------------------------------------------------------------------------------------ - protected override void OnRowsRemoved(DataGridViewRowsRemovedEventArgs e) - { - base.OnRowsRemoved(e); - IsDirty = true; - } - - #endregion - - #region Events and methods for handling DropDown style combo box cells. - /// ------------------------------------------------------------------------------------ - protected override void OnCurrentCellDirtyStateChanged(EventArgs e) - { - if (!_isDirty) - IsDirty = IsCurrentCellDirty; - - base.OnCurrentCellDirtyStateChanged(e); - } - - /// ------------------------------------------------------------------------------------ - /// - /// Check if we need to modify the drop-down style of the grid's combo box. - /// - /// ------------------------------------------------------------------------------------ - protected override void OnEditingControlShowing(DataGridViewEditingControlShowingEventArgs e) - { - base.OnEditingControlShowing(e); - - if (DrawTextBoxEditControlBorder && e.Control is TextBox && e.Control.Parent is Panel) - { - e.Control.Parent.Tag = null; - e.Control.Parent.Paint -= HandleEditControlTextBoxPanelPaint; - e.Control.Parent.Paint += HandleEditControlTextBoxPanelPaint; - } - - var cbo = e.Control as ComboBox; - if (cbo == null) - return; - - InitializeComboCellList(cbo, OnGetComboCellList(CurrentCell, e)); - - // When the cell style's tag is storing a ComboBoxStyle value, we know that value is - // ComboBoxStyle.DropDown. Therefore, modify the control's DropDownStyle property. - if ((e.CellStyle.Tag as string) != kDropDownStyle) - return; - - cbo.DropDownStyle = ComboBoxStyle.DropDown; - - // ENHANCE: Should an event delegate be provided? One to allow - // subscribers to have a chance to use a custom sort. - if (GetComboCellList == null) - SortComboList(cbo); - - cbo.TextChanged += delegate - { - // This will make sure the validation process doesn't throw out text typed - // directly into the cell rather than the value being set from the drop-down - // list. I don't yet understand why this is necessary, but it works. - NotifyCurrentCellDirty(true); - }; - } - - /// ------------------------------------------------------------------------------------ - protected virtual KeyValuePair> OnGetComboCellList(DataGridViewCell cell, - DataGridViewEditingControlShowingEventArgs e) - { - // Allow delegates to provide combobox cell lists on the fly. - return (GetComboCellList == null ? - new KeyValuePair>(null, null) : - GetComboCellList(this, cell, e)); - } - - /// ------------------------------------------------------------------------------------ - private void InitializeComboCellList(ComboBox cbo, KeyValuePair> listInfo) - { - if (listInfo.Value == null) - return; - - //cbo.SelectionChangeCommitted -= HandleComboCellSelectionChangeCommitted; - //cbo.SelectionChangeCommitted += HandleComboCellSelectionChangeCommitted; - //cbo.HandleDestroyed -= HandleComboCellControlHandleDestroyed; - //cbo.HandleDestroyed += HandleComboCellControlHandleDestroyed; - cbo.Items.Clear(); - cbo.Items.AddRange(listInfo.Value.ToArray()); - - if (listInfo.Key == null || listInfo.Value.Count() == 0) - return; - - if (listInfo.Key.GetType() != typeof(int)) - cbo.SelectedItem = listInfo.Key; - else - { - int index = (int)listInfo.Key; - if (index >= 0 && index < cbo.Items.Count) - cbo.SelectedIndex = index; - } - } - - ///// ------------------------------------------------------------------------------------ - ///// - ///// After the user has selected an item from a combo box cell list, inform any - ///// delegates who would like to know. - ///// - ///// ------------------------------------------------------------------------------------ - //private void HandleComboCellSelectionChangeCommitted(object sender, EventArgs e) - //{ - // var cbo = sender as ComboBox; - // if (cbo != null) - // OnComboCellListValueSelected(CurrentCell, cbo.SelectedItem); - //} - - ///// ------------------------------------------------------------------------------------ - //protected virtual void OnComboCellListValueSelected(DataGridViewCell cell, object selectedItem) - //{ - // if (ComboCellListValueSelected == null) - // CurrentCell.Value = selectedItem; - // else - // ComboCellListValueSelected(this, cell, selectedItem); - //} - - ///// ------------------------------------------------------------------------------------ - //void HandleComboCellControlHandleDestroyed(object sender, EventArgs e) - //{ - // var cbo = sender as ComboBox; - // if (cbo == null) - // return; - - // cbo.SelectionChangeCommitted -= HandleComboCellSelectionChangeCommitted; - // cbo.HandleDestroyed += HandleComboCellControlHandleDestroyed; - //} - - /// ------------------------------------------------------------------------------------ - private void HandleEditControlTextBoxPanelPaint(object sender, PaintEventArgs e) - { - var pnl = sender as Panel; - var txt = pnl.Controls[0]; - - if (pnl.Tag == null) - { - txt.Width = pnl.Width - 6; - txt.Left = 3; - pnl.Tag = true; - } - - var rc = pnl.ClientRectangle; - rc.X++; - rc.Width -= 3; - rc.Height--; - - using (Pen pen = new Pen(TextBoxEditControlBorderColor)) - e.Graphics.DrawRectangle(pen, rc); - } - - /// ------------------------------------------------------------------------------------ - private static void SortComboList(ComboBox cbo) - { - var items = cbo.Items.Cast().OrderBy(o => o).ToArray(); - cbo.Items.Clear(); - cbo.Items.AddRange(items); - } - - /// ------------------------------------------------------------------------------------ - protected override void OnCellValidating(DataGridViewCellValidatingEventArgs e) - { - base.OnCellValidating(e); - - // If a delegate already cancelled or the cell is not in a column with the - // combo box drop-down style, then get out now. - if (e.Cancel) - return; - - try - { - var col = Columns[e.ColumnIndex] as DataGridViewComboBoxColumn; - if (col == null || (col.DefaultCellStyle.Tag as string) != kDropDownStyle) - return; - - // If the entered value is empty, then don't add it to the list. - var value = e.FormattedValue as string; - if (value != null && value.Trim() == string.Empty) - return; - - // Convert the formatted value to the type the column is expecting. Then add it - // to the combo list if it isn't already in there. - var obj = Convert.ChangeType(e.FormattedValue, col.ValueType); - if (obj != null && !(col.Items.Contains(obj))) - col.Items.Add(obj); - } - catch { } - } - - #endregion - - #region Methods for removing rows and the special column for removing rows. - /// ------------------------------------------------------------------------------------ - protected override void OnCellValueNeeded(DataGridViewCellValueEventArgs e) - { - if (e.RowIndex != NewRowIndex && GetColumnName(e.ColumnIndex) == "removerow") - { - var rc = GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false); - bool mouseOverRemoveImage = rc.Contains(PointToClient(MousePosition)); - - if (CurrentCellAddress.Y == e.RowIndex || mouseOverRemoveImage) - { - e.Value = (mouseOverRemoveImage ? - m_removeRowImageHot : m_removeRowImageNormal); - } - } - - base.OnCellValueNeeded(e); - } - - /// ------------------------------------------------------------------------------------ - protected override void OnCellMouseEnter(DataGridViewCellEventArgs e) - { - if (e.RowIndex < NewRowIndex && e.RowIndex >= 0 && GetColumnName(e.ColumnIndex) == "removerow") - InvalidateCell(e.ColumnIndex, e.RowIndex); - - base.OnCellMouseEnter(e); - } - - /// ------------------------------------------------------------------------------------ - protected override void OnCellMouseLeave(DataGridViewCellEventArgs e) - { - if (e.RowIndex < NewRowIndex && e.RowIndex >= 0 && GetColumnName(e.ColumnIndex) == "removerow") - InvalidateCell(e.ColumnIndex, e.RowIndex); - - base.OnCellMouseLeave(e); - } - - - /// ------------------------------------------------------------------------------------ - protected override void OnCellToolTipTextNeeded(DataGridViewCellToolTipTextNeededEventArgs e) - { - if (e.RowIndex < NewRowIndex && e.RowIndex >= 0 && - GetColumnName(e.ColumnIndex) == "removerow" && GetRemoveRowToolTipText != null) - { - e.ToolTipText = GetRemoveRowToolTipText(); - } - - base.OnCellToolTipTextNeeded(e); - } - - #endregion - - /// ------------------------------------------------------------------------------------ - public IEnumerable GetRows() - { - return Rows.Cast(); - } - - /// ------------------------------------------------------------------------------------ - public string GetColumnName(int index) - { - return (index >= 0 && index < ColumnCount ? Columns[index].Name : null); - } - - /// ------------------------------------------------------------------------------------ - public string GetCurrentColumnName() - { - return GetColumnName(CurrentCellAddress.X); - } - - /// ------------------------------------------------------------------------------------ - public void MakeFirstVisibleCellCurrentInRow(int rowIndex) - { - if (rowIndex < 0 || rowIndex >= RowCount) - return; - - var visibleCols = Columns.Cast() - .Where(col => col.Visible).OrderBy(col => col.DisplayIndex).ToArray(); - - if (visibleCols.Length > 0) - CurrentCell = this[visibleCols[0].Index, rowIndex]; - } - - /// ------------------------------------------------------------------------------------ - /// - /// For grids containing combo box columns created using the - /// CreateDropDownComboBoxColumn method, this way of adding rows should be used since - /// it will verify (before adding the row to the rows collection) that items added - /// to those columns will have corresponding items in their drop-down list. - /// - /// ------------------------------------------------------------------------------------ - public int AddRow(object[] items) - { - for (int i = 0; i < items.Length; i++) - { - DataGridViewComboBoxColumn col = Columns[i] as DataGridViewComboBoxColumn; - if (col == null || (col.DefaultCellStyle.Tag as string) != kDropDownStyle) - continue; - - // At this point, we know we're looking at a combo box column - // whose style is DropDown. Therefore, make sure the item is in - // it's list and if not, add it. - if (items[i] != null && !col.Items.Contains(items[i])) - col.Items.Add(items[i]); - } - - return Rows.Add(items); - } - - /// ------------------------------------------------------------------------------------ - /// - /// This method will go through the values in the specified row and verify, that for - /// each DropDown style combo. item in the row, the combo. list contains the item in - /// the row. - /// - /// ------------------------------------------------------------------------------------ - public void VerifyComboItemsFromRow(DataGridViewRow row) - { - foreach (DataGridViewCell cell in row.Cells) - { - DataGridViewComboBoxColumn col = Columns[cell.ColumnIndex] as DataGridViewComboBoxColumn; - if (col == null || (col.DefaultCellStyle.Tag as string) != kDropDownStyle) - continue; - - // At this point, we know we're looking at a combo box column - // whose style is DropDown. Therefore, make sure the item is in - // it's list and if not, add it. - if (cell.Value != null && !col.Items.Contains(cell.Value)) - col.Items.Add(cell.Value); - } - } - - /// ------------------------------------------------------------------------------------ - /// - /// Selects the first, visible column that is adjacent to the current column (i.e. - /// the column of the current cell). When searchLeftFirst is true, an attempt will - /// be made to first find a visible column to the left of the current column. If - /// that fails, then an attempt is made to find a visible column to the right of the - /// current column. Of course, if searchLeftFirst is false, then searching right is - /// first, then left. If a new column is successfully selected, true is returned. - /// Otherwise, false is returned. - /// - /// ------------------------------------------------------------------------------------ - public bool SelectAdjacentVisibleColumn(bool searchLeftFirst) - { - // Can't select a cell in the current row if there is no current row. - if (CurrentCellAddress.Y < 0) - return false; - - int inc = (searchLeftFirst ? -1 : 1); - - for (int pass = 0; pass < 2; pass++) - { - for (int i = CurrentCellAddress.X + inc; i >= 0 && i < ColumnCount; i += inc) - { - if (Columns[i].Visible) - { - CurrentCell = this[i, CurrentCellAddress.Y]; - return true; - } - } - - inc *= -1; - } - - return false; - } - - /// ------------------------------------------------------------------------------------ - protected override void OnCurrentCellChanged(EventArgs e) - { - base.OnCurrentCellChanged(e); - - if (_prevRowIndex != CurrentCellAddress.Y) - { - InvalidateRowInFullRowSelectMode(_prevRowIndex); - InvalidateRowInFullRowSelectMode(CurrentCellAddress.Y); - _prevRowIndex = CurrentCellAddress.Y; - OnCurrentRowChanged(EventArgs.Empty); - } - } - - /// ------------------------------------------------------------------------------------ - protected override void OnCellFormatting(DataGridViewCellFormattingEventArgs e) - { - if (CurrentCellAddress.Y == e.RowIndex) - { - if (CurrentCellAddress.X == e.ColumnIndex) - { - if (SelectedCellBackColor != Color.Empty) - e.CellStyle.SelectionBackColor = SelectedCellBackColor; - - if (SelectedCellForeColor != Color.Empty) - e.CellStyle.SelectionForeColor = SelectedCellForeColor; - } - else - { - if (SelectedRowBackColor != Color.Empty) - e.CellStyle.SelectionBackColor = SelectedRowBackColor; - - if (SelectedRowForeColor != Color.Empty) - e.CellStyle.SelectionForeColor = SelectedRowForeColor; - } - } - - // Make sure the remove row cell in the new row (if there is a new row) doesn't - // contain the default no image, image (i.e. white square box containing a red x). - if (e.RowIndex == NewRowIndex && GetColumnName(e.ColumnIndex) == "removerow") - e.Value = ((DataGridViewImageColumn)Columns["removerow"]).Image; - - base.OnCellFormatting(e); - } - - /// ------------------------------------------------------------------------------------ - protected override void OnCellPainting(DataGridViewCellPaintingEventArgs e) - { - if (e.RowIndex >= 0 && GetColumnName(e.ColumnIndex) == "removerow") - { - // Don't draw borders around remove row image cells. - e.AdvancedBorderStyle.Bottom = DataGridViewAdvancedCellBorderStyle.None; - e.AdvancedBorderStyle.Top = DataGridViewAdvancedCellBorderStyle.None; - e.AdvancedBorderStyle.Right = DataGridViewAdvancedCellBorderStyle.None; - e.CellStyle.SelectionBackColor = BackgroundColor; - } - else if (e.RowIndex == CurrentCellAddress.Y && e.ColumnIndex >= 0 && - Columns[e.ColumnIndex] is DataGridViewCheckBoxColumn) - { - if (SelectionMode == DataGridViewSelectionMode.FullRowSelect || - e.ColumnIndex == CurrentCellAddress.X) - { - // If we don't intervene, selected checkbox cells - // will get the default selection color. - var backColor = (e.ColumnIndex == CurrentCellAddress.X ? - SelectedCellBackColor : SelectedRowBackColor); - - if (backColor != Color.Empty) - { - e.CellStyle.SelectionBackColor = backColor; - e.Paint(e.CellBounds, e.PaintParts); - } - } - } - - base.OnCellPainting(e); - - if (e.RowIndex == -1 && e.ColumnIndex == 0 && PaintHeaderAcrossFullGridWidth && - ClientSize.Width > Columns.GetColumnsWidth(DataGridViewElementStates.Visible)) - { - OnDrawExtendedColumnHeaderRow(e); - } - - if (!e.Handled && Focused & PaintFullRowFocusRectangle && - SelectionMode == DataGridViewSelectionMode.FullRowSelect) - { - OnDrawFocusRectangle(e); - } - } - - /// ------------------------------------------------------------------------------------ - /// - /// This method fills in the gap between the header of the last visible column and the - /// right edge of the grid. That gap is filled with something that looks like one long - /// empty column header. - /// - /// ------------------------------------------------------------------------------------ - protected virtual void OnDrawExtendedColumnHeaderRow(DataGridViewCellPaintingEventArgs e) - { - Rectangle rc = e.CellBounds; - rc.Width = ClientSize.Width; - - VisualStyleElement element = VisualStyleElement.Header.Item.Normal; - if (PaintingHelper.CanPaintVisualStyle(element)) - { - if (ColumnHeadersBorderStyle == DataGridViewHeaderBorderStyle.Raised) - rc.Height--; - - VisualStyleRenderer renderer = new VisualStyleRenderer(element); - renderer.DrawBackground(e.Graphics, rc); - } - else - { - // Draw this way when themes aren't supported. - if (ColumnHeadersBorderStyle == DataGridViewHeaderBorderStyle.None) - e.Graphics.FillRectangle(SystemBrushes.Control, rc); - else if (ColumnHeadersBorderStyle == DataGridViewHeaderBorderStyle.Raised) - { - ControlPaint.DrawButton(e.Graphics, rc, ButtonState.Normal); - ControlPaint.DrawBorder3D(e.Graphics, rc, Border3DStyle.Flat, Border3DSide.Bottom); - } - } - - // Clean up the bottom edge. - if (ColumnHeadersBorderStyle == DataGridViewHeaderBorderStyle.Raised) - ControlPaint.DrawBorder3D(e.Graphics, rc, Border3DStyle.Etched, Border3DSide.Top); - } - - /// -------------------------------------------------------------------------------------------- - protected virtual void OnDrawFocusRectangle(DataGridViewCellPaintingEventArgs e) - { - e.Handled = true; - var paintParts = e.PaintParts; - var rc = e.CellBounds; - - paintParts &= ~DataGridViewPaintParts.Focus; - e.Paint(rc, paintParts); - - int rowAboveCurrent = (CurrentCellAddress.Y == FirstDisplayedScrollingRowIndex ? - -1 : CurrentCellAddress.Y - 1); - - if (e.RowIndex == rowAboveCurrent && CurrentCellAddress.Y >= FirstDisplayedScrollingRowIndex) - { - // This draws the line across the top of the cell. (It's really - // drawing the line across the bottom of the cell above the focused row.) - using (var pen = new Pen(FullRowFocusRectangleColor)) - e.Graphics.DrawLine(pen, rc.X, rc.Bottom - 1, rc.Right - 1, rc.Bottom - 1); - } - - if (e.RowIndex != CurrentCellAddress.Y) - return; - - using (var pen = new Pen(FullRowFocusRectangleColor)) - { - // Draw a line across the bottom of the cell. - e.Graphics.DrawLine(pen, rc.X, rc.Bottom - 1, rc.Right - 1, rc.Bottom - 1); - - // If the column is the furthest left, then draw a - // vertical line on the left edge of the cell. - if (e.ColumnIndex >= 0 && Columns[e.ColumnIndex].DisplayIndex == 0 && !RowHeadersVisible) - e.Graphics.DrawLine(pen, rc.X, rc.Y, rc.X, rc.Bottom - 1); - - // If the column is the furthest right, then draw a - // vertical line on the right edge of the cell. - if (e.ColumnIndex >= 0 && Columns[e.ColumnIndex].DisplayIndex == ColumnCount - 1) - e.Graphics.DrawLine(pen, rc.Right - 1, rc.Y, rc.Right - 1, rc.Bottom - 1); - } - - if (DrawFocusRectangle != null) - DrawFocusRectangle(this, e); - } - - /// ------------------------------------------------------------------------------------ - /// - /// This will only deal with painting in the area between the right edge of the - /// furthest right displayed cell and the right edge of the grid's client area. - /// - /// ------------------------------------------------------------------------------------ - protected override void OnRowPostPaint(DataGridViewRowPostPaintEventArgs e) - { - base.OnRowPostPaint(e); - - if ((e.State & DataGridViewElementStates.Selected) != DataGridViewElementStates.Selected || - !ExtendFullRowSelectRectangleToEdge || e.RowIndex < 0 || e.RowIndex >= RowCount) - { - return; - } - - // Determine whether or not there is any gap between the right edge of the last - // displayed cell and the right edge of the client area. - var sumOfColWidths = Columns.GetColumnsWidth(DataGridViewElementStates.Displayed); - if (sumOfColWidths > ClientSize.Width) - return; - - var rc = GetRowDisplayRectangle(e.RowIndex, false); - rc.Width -= (sumOfColWidths - 1); - rc.X += (sumOfColWidths - 1); - - // Fill the gap between the last displayed column and the right edge of the client area - // with the selection color so the row's selection highlighting spans the entire grid's - // client width. - var clr = (SelectedRowBackColor != Color.Empty ? - SelectedRowBackColor : DefaultCellStyle.SelectionBackColor); - - using (var br = new SolidBrush(clr)) - e.Graphics.FillRectangle(br, rc); - - if (!Focused || !PaintFullRowFocusRectangle || e.RowIndex != CurrentCellAddress.Y) - return; - - // Draw focus rectangle line across the top and bottom and along the right edge. - using (var pen = new Pen(FullRowFocusRectangleColor)) - { - e.Graphics.DrawLine(pen, rc.X, rc.Y - 1, rc.Right, rc.Y - 1); - e.Graphics.DrawLine(pen, rc.X, rc.Bottom - 1, rc.Right, rc.Bottom - 1); - e.Graphics.DrawLine(pen, rc.Right - 1, rc.Y, rc.Right - 1, rc.Bottom - 1); - } - } - - /// ------------------------------------------------------------------------------------ - protected virtual void InvalidateRowInFullRowSelectMode(int row) - { - if (PaintFullRowFocusRectangle && SelectionMode == DataGridViewSelectionMode.FullRowSelect && - row >= 0 && row < RowCount) - { - var rc = GetRowDisplayRectangle(row, false); - rc.Inflate(1, 2); - Invalidate(rc); - } - } - - /// ------------------------------------------------------------------------------------ - protected virtual void OnCurrentRowChanged(EventArgs e) - { - if (CurrentRowChanged != null) - CurrentRowChanged(this, EventArgs.Empty); - } - - #region Static methods for creating various column types - /// ------------------------------------------------------------------------------------ - /// - /// Creates a text box grid column. - /// - /// ------------------------------------------------------------------------------------ - public static DataGridViewColumn CreateTextBoxColumn(string name) - { - return CreateTextBoxColumn(name, name); - } - - /// ------------------------------------------------------------------------------------ - /// - /// Creates a text box grid column. - /// - /// ------------------------------------------------------------------------------------ - public static DataGridViewColumn CreateTextBoxColumn(string name, string headerText) - { - var col = new DataGridViewColumn(); - var templateCell = new DataGridViewTextBoxCell(); - templateCell.Style.Font = SystemFonts.MenuFont; - col.HeaderCell.Style.Font = SystemFonts.MenuFont; - col.CellTemplate = templateCell; - col.Name = name; - col.HeaderText = headerText; - - return col; - } - - ///// ------------------------------------------------------------------------------------ - ///// - ///// Creates a calendar control grid column that hosts calendar (date) cells. - ///// - ///// ------------------------------------------------------------------------------------ - //public static DataGridViewColumn CreateCalendarControlColumn(string name) - //{ - // return CreateCalendarControlColumn(name, name); - //} - - ///// ------------------------------------------------------------------------------------ - ///// - ///// Creates a calendar control grid column that hosts calendar (date) cells. - ///// - ///// ------------------------------------------------------------------------------------ - //public static DataGridViewColumn CreateCalendarControlColumn(string name, string headerText) - //{ - // var col = new SilCalendarColumn(); - // col.HeaderCell.Style.Font = SystemFonts.MenuFont; - // col.Name = name; - // col.HeaderText = headerText; - - // return col; - //} - - /// ------------------------------------------------------------------------------------ - /// - /// Creates a combo. box grid column whose cell values must be chosen from the - /// drop-down list. - /// - /// ------------------------------------------------------------------------------------ - public static DataGridViewComboBoxColumn CreateDropDownListComboBoxColumn(string name, IEnumerable items) - { - return CreateDropDownListComboBoxColumn(name, items.Cast()); - } - - /// ------------------------------------------------------------------------------------ - /// - /// Creates a combo. box grid column whose cell values must be chosen from the - /// drop-down list. - /// - /// ------------------------------------------------------------------------------------ - public static DataGridViewComboBoxColumn CreateDropDownListComboBoxColumn(string name, IEnumerable items) - { - return CreateDropDownListComboBoxColumn(name, items.ToArray()); - } - - /// ------------------------------------------------------------------------------------ - /// - /// Creates a combo. box grid column whose cell values must be chosen from the - /// drop-down list. - /// - /// ------------------------------------------------------------------------------------ - public static DataGridViewComboBoxColumn CreateDropDownListComboBoxColumn(string name, - ArrayList items) - { - return CreateDropDownListComboBoxColumn(name, (object[])items.ToArray(typeof(object))); - } - - /// ------------------------------------------------------------------------------------ - /// - /// Creates a combo. box grid column whose cell values must be chosen from the - /// drop-down list. - /// - /// ------------------------------------------------------------------------------------ - public static DataGridViewComboBoxColumn CreateDropDownListComboBoxColumn(string name, object[] items) - { - var col = new DataGridViewComboBoxColumn(); - var templateCell = new DataGridViewComboBoxCell(); - templateCell.DisplayStyleForCurrentCellOnly = true; - templateCell.Style.Font = SystemFonts.MenuFont; - templateCell.AutoComplete = true; - col.HeaderCell.Style.Font = SystemFonts.MenuFont; - col.CellTemplate = templateCell; - col.FlatStyle = FlatStyle.Standard; - col.MaxDropDownItems = 10; - col.Name = name; - col.HeaderText = name; - - // Set the data type expected for data in this column. - if (items.Length > 0) - col.ValueType = items[0].GetType(); - - //gridCol.DataSource = items; - col.Items.AddRange(items); - - return col; - } - - /// ------------------------------------------------------------------------------------ - /// - /// Creates a combo. box grid column whose cell values can be set by choosing a value - /// from the drop-down list or by typing one into the cell, even one that doesn't - /// appear in the drop-down list. If a value is typed into the cell that doesn't - /// appear in the drop-down list, that value is added to the list when the cell is - /// validated. - /// - /// ------------------------------------------------------------------------------------ - public static DataGridViewComboBoxColumn CreateDropDownComboBoxColumn(string name, IEnumerable items) - { - return CreateDropDownComboBoxColumn(name, items.Cast()); - } - - /// ------------------------------------------------------------------------------------ - /// - /// Creates a combo. box grid column whose cell values can be set by choosing a value - /// from the drop-down list or by typing one into the cell, even one that doesn't - /// appear in the drop-down list. If a value is typed into the cell that doesn't - /// appear in the drop-down list, that value is added to the list when the cell is - /// validated. - /// - /// ------------------------------------------------------------------------------------ - public static DataGridViewComboBoxColumn CreateDropDownComboBoxColumn(string name, IEnumerable items) - { - return CreateDropDownComboBoxColumn(name, items.ToArray()); - } - - /// ------------------------------------------------------------------------------------ - /// - /// Creates a combo. box grid column whose cell values can be set by choosing a value - /// from the drop-down list or by typing one into the cell, even one that doesn't - /// appear in the drop-down list. If a value is typed into the cell that doesn't - /// appear in the drop-down list, that value is added to the list when the cell is - /// validated. - /// - /// ------------------------------------------------------------------------------------ - public static DataGridViewComboBoxColumn CreateDropDownComboBoxColumn(string name, - ArrayList items) - { - return CreateDropDownComboBoxColumn(name, (object[])items.ToArray(typeof(object))); - } - - /// ------------------------------------------------------------------------------------ - /// - /// Creates a combo. box grid column whose cell values can be set by choosing a value - /// from the drop-down list or by typing one into the cell, even one that doesn't - /// appear in the drop-down list. If a value is typed into the cell that doesn't - /// appear in the drop-down list, that value is added to the list when the cell is - /// validated. - /// - /// ------------------------------------------------------------------------------------ - public static DataGridViewComboBoxColumn CreateDropDownComboBoxColumn(string name, object[] items) - { - var col = CreateDropDownListComboBoxColumn(name, items); - - // Store a flag in the default cell style's tag because that seems to be the only - // property for user data that is common to both the OnEditingControlShowing and - // OnCellValidating events. This flag is used in OnEditingControlShowing to - // indicate the combo box control's DropDownStyle should be set to DropDown. - col.DefaultCellStyle.Tag = kDropDownStyle; - - return col; - } - - /// ------------------------------------------------------------------------------------ - /// - /// Creates a check box grid column. - /// - /// ------------------------------------------------------------------------------------ - public static DataGridViewCheckBoxColumn CreateCheckBoxColumn(string name) - { - var col = new DataGridViewCheckBoxColumn(); - var templateCell = new DataGridViewCheckBoxCell(); - templateCell.Style.Font = SystemFonts.MenuFont; - col.CellTemplate = templateCell; - col.HeaderCell.Style.Font = SystemFonts.MenuFont; - col.Name = name; - col.HeaderText = name; - col.FlatStyle = FlatStyle.Standard; - - return col; - } - - /// ------------------------------------------------------------------------------------ - /// - /// Creates an image grid column. - /// - /// ------------------------------------------------------------------------------------ - public static DataGridViewImageColumn CreateImageColumn(string name) - { - var col = new DataGridViewImageColumn(); - var templateCell = new DataGridViewImageCell(); - templateCell.Style.Font = SystemFonts.MenuFont; - templateCell.ImageLayout = DataGridViewImageCellLayout.Normal; - col.CellTemplate = templateCell; - col.HeaderCell.Style.Font = SystemFonts.MenuFont; - col.ImageLayout = DataGridViewImageCellLayout.Normal; - col.Name = name; - col.HeaderText = name; - - return col; - } - - /// ------------------------------------------------------------------------------------ - /// - /// Creates a SilButtonColumn grid column. - /// - /// ------------------------------------------------------------------------------------ - public static LmButtonColumn CreateSilButtonColumn(string name) - { - var col = new LmButtonColumn(name); - var templateCell = new LmButtonCell(); - templateCell.Style.Font = SystemFonts.MenuFont; - templateCell.Style.SelectionForeColor = SystemColors.HighlightText; - col.CellTemplate = templateCell; - col.HeaderCell.Style.Font = SystemFonts.MenuFont; - col.HeaderText = name; - - return col; - } - - #endregion - } -} diff --git a/src/L10NSharp.Windows.Forms/UIComponents/HowToDistributeDialog.Designer.cs b/src/L10NSharp.Windows.Forms/UIComponents/HowToDistributeDialog.Designer.cs deleted file mode 100644 index 2639d72..0000000 --- a/src/L10NSharp.Windows.Forms/UIComponents/HowToDistributeDialog.Designer.cs +++ /dev/null @@ -1,145 +0,0 @@ -namespace L10NSharp.Windows.Forms.UIComponents -{ - partial class HowToDistributeDialog - { - /// - /// Required designer variable. - /// - private System.ComponentModel.IContainer components = null; - - /// - /// Clean up any resources being used. - /// - /// true if managed resources should be disposed; otherwise, false. - protected override void Dispose(bool disposing) - { - if (disposing && (components != null)) - { - components.Dispose(); - } - base.Dispose(disposing); - } - - #region Windows Form Designer generated code - - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(HowToDistributeDialog)); - this._lblLocalSharing = new System.Windows.Forms.Label(); - this._okButton = new System.Windows.Forms.Button(); - this._lblHowToDistribute = new System.Windows.Forms.LinkLabel(); - this._lblNoteAboutConflictingTranslations = new System.Windows.Forms.Label(); - this._table = new System.Windows.Forms.TableLayoutPanel(); - this._table.SuspendLayout(); - this.SuspendLayout(); - // - // _lblLocalSharing - // - this._lblLocalSharing.AutoSize = true; - this._lblLocalSharing.Font = new System.Drawing.Font("Segoe UI", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this._lblLocalSharing.Location = new System.Drawing.Point(3, 160); - this._lblLocalSharing.Margin = new System.Windows.Forms.Padding(3, 0, 3, 12); - this._lblLocalSharing.MaximumSize = new System.Drawing.Size(0, 180); - this._lblLocalSharing.Name = "_lblLocalSharing"; - this._lblLocalSharing.Size = new System.Drawing.Size(329, 95); - this._lblLocalSharing.TabIndex = 0; - this._lblLocalSharing.Text = resources.GetString("_lblLocalSharing.Text"); - // - // _okButton - // - this._okButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); - this._okButton.AutoSize = true; - this._okButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; - this._okButton.Location = new System.Drawing.Point(260, 374); - this._okButton.Name = "_okButton"; - this._okButton.Size = new System.Drawing.Size(75, 23); - this._okButton.TabIndex = 1; - this._okButton.Text = "&OK"; - this._okButton.UseVisualStyleBackColor = true; - // - // _lblHowToDistribute - // - this._lblHowToDistribute.AutoSize = true; - this._lblHowToDistribute.Font = new System.Drawing.Font("Segoe UI", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this._lblHowToDistribute.LinkArea = new System.Windows.Forms.LinkArea(81, 84); - this._lblHowToDistribute.Location = new System.Drawing.Point(3, 107); - this._lblHowToDistribute.Margin = new System.Windows.Forms.Padding(3, 0, 3, 12); - this._lblHowToDistribute.MaximumSize = new System.Drawing.Size(0, 180); - this._lblHowToDistribute.Name = "_lblHowToDistribute"; - this._lblHowToDistribute.Size = new System.Drawing.Size(322, 41); - this._lblHowToDistribute.TabIndex = 2; - this._lblHowToDistribute.TabStop = true; - this._lblHowToDistribute.Text = "To get your translation work into the next version of this program, email {0} to " + - "{1}"; - this._lblHowToDistribute.UseCompatibleTextRendering = true; - this._lblHowToDistribute.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.HandleLinkClicked); - // - // _lblNoteAboutConflictingTranslations - // - this._lblNoteAboutConflictingTranslations.AutoSize = true; - this._lblNoteAboutConflictingTranslations.Font = new System.Drawing.Font("Segoe UI", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this._lblNoteAboutConflictingTranslations.Location = new System.Drawing.Point(3, 0); - this._lblNoteAboutConflictingTranslations.Margin = new System.Windows.Forms.Padding(3, 0, 3, 12); - this._lblNoteAboutConflictingTranslations.MaximumSize = new System.Drawing.Size(0, 180); - this._lblNoteAboutConflictingTranslations.Name = "_lblNoteAboutConflictingTranslations"; - this._lblNoteAboutConflictingTranslations.Size = new System.Drawing.Size(332, 95); - this._lblNoteAboutConflictingTranslations.TabIndex = 6; - this._lblNoteAboutConflictingTranslations.Text = resources.GetString("_lblNoteAboutConflictingTranslations.Text"); - // - // _table - // - this._table.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) - | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this._table.ColumnCount = 1; - this._table.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); - this._table.Controls.Add(this._lblNoteAboutConflictingTranslations, 0, 0); - this._table.Controls.Add(this._lblHowToDistribute, 0, 1); - this._table.Controls.Add(this._okButton, 0, 3); - this._table.Controls.Add(this._lblLocalSharing, 0, 2); - this._table.Location = new System.Drawing.Point(12, 12); - this._table.Name = "_table"; - this._table.RowCount = 4; - this._table.RowStyles.Add(new System.Windows.Forms.RowStyle()); - this._table.RowStyles.Add(new System.Windows.Forms.RowStyle()); - this._table.RowStyles.Add(new System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100F)); - this._table.RowStyles.Add(new System.Windows.Forms.RowStyle()); - this._table.Size = new System.Drawing.Size(338, 400); - this._table.TabIndex = 7; - // - // HowToDistributeDialog - // - this.AcceptButton = this._okButton; - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.CancelButton = this._okButton; - this.ClientSize = new System.Drawing.Size(362, 424); - this.Controls.Add(this._table); - this.MaximizeBox = false; - this.MinimizeBox = false; - this.MinimumSize = new System.Drawing.Size(378, 463); - this.Name = "HowToDistributeDialog"; - this.ShowIcon = false; - this.ShowInTaskbar = false; - this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; - this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; - this.Text = "How To Distribute"; - this._table.ResumeLayout(false); - this._table.PerformLayout(); - this.ResumeLayout(false); - - } - - #endregion - - private System.Windows.Forms.Label _lblLocalSharing; - private System.Windows.Forms.Button _okButton; - private System.Windows.Forms.LinkLabel _lblHowToDistribute; - private System.Windows.Forms.Label _lblNoteAboutConflictingTranslations; - private System.Windows.Forms.TableLayoutPanel _table; - } -} diff --git a/src/L10NSharp.Windows.Forms/UIComponents/HowToDistributeDialog.cs b/src/L10NSharp.Windows.Forms/UIComponents/HowToDistributeDialog.cs deleted file mode 100644 index a4f954b..0000000 --- a/src/L10NSharp.Windows.Forms/UIComponents/HowToDistributeDialog.cs +++ /dev/null @@ -1,96 +0,0 @@ -using System; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Windows.Forms; -using L10NSharp; - -namespace L10NSharp.Windows.Forms.UIComponents -{ - public partial class HowToDistributeDialog : Form - { - private readonly string _emailForSubmissions; - private readonly string _targetTranslationFilePath; - - public HowToDistributeDialog(string emailForSubmissions, string targetTranslationFilePath) - { - _emailForSubmissions = emailForSubmissions; - _targetTranslationFilePath = targetTranslationFilePath; - InitializeComponent(); - - if (Utils.IsMono) - { - // In Mono, Label.AutoSize=true sets Size to PreferredSize (which is always - // one line high) even if the Size has already been explicitly set. In Windows, - // Label.AutoSize=false makes the labels disappear. So we need to turn off - // AutoSize here and set the multiline labels (which all have a max height set - // in Designer) to their largest possible heights. (That allows all the available - // space for localizations that may need more space.) - foreach (var label in Controls.OfType