<commit_before>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Windows.Forms;
using L10NSharp;

namespace SIL.Windows.Forms
{
	/*  FlexibleMessageBox – A flexible replacement for the .NET MessageBox
	 * 
	 *  Author:		<NAME> (<EMAIL>)
	 *  Contributors:   Thanks to: <NAME>, Roink
	 *  Version:		1.3
	 *  Published at:   http://www.codeproject.com/Articles/601900/FlexibleMessageBox
	 *  
	 ************************************************************************************************************
	 * Features:
	 *  - It can be simply used instead of MessageBox since all important static "Show"-Functions are supported
	 *  - It is small, only one source file, which could be added easily to each solution 
	 *  - It can be resized and the content is correctly word-wrapped
	 *  - It tries to auto-size the width to show the longest text row
	 *  - It never exceeds the current desktop working area
	 *  - It displays a vertical scrollbar when needed
	 *  - It does support hyperlinks in text
	 *  - It allows copying of messages to clipboard
	 * 
	 *  Because the interface is identical to MessageBox, you can add this single source file to your project 
	 *  and use the FlexibleMessageBox almost everywhere you use a standard MessageBox. 
	 *  The goal was NOT to produce as many features as possible but to provide a simple replacement to fit my 
	 *  own needs. Feel free to add additional features on your own, but please left my credits in this class.
	 * 
	 ************************************************************************************************************
	 * Usage examples:
	 * 
	 *  FlexibleMessageBox.Show("Just a text");
	 * 
	 *  FlexibleMessageBox.Show("A text", "A caption"); 
	 *  
	 *  FlexibleMessageBox.Show("Some text with a link: www.google.com", 
	 *							"Some caption",
	 *							MessageBoxButtons.AbortRetryIgnore, 
	 *							MessageBoxIcon.Information,
	 *							MessageBoxDefaultButton.Button2);
	 *  
	 *  var dialogResult = FlexibleMessageBox.Show("Do you know the answer to life the universe and everything?", 
	 *											   "One short question",
	 *											   MessageBoxButtons.YesNo);	 
	 * 
	 ************************************************************************************************************
	 *  THE SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS", WITHOUT WARRANTY
	 *  OF ANY KIND, EXPRESS OR IMPLIED. IN NO EVENT SHALL THE AUTHOR BE
	 *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY ARISING FROM,
	 *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF THIS
	 *  SOFTWARE.
	 *  
	 ************************************************************************************************************
	 * History:
	 *	Adapted for use in libpalaso
	 *  - Added override to default handling of LinkClicked event
	 *  - Made localizatin extenisible without altering code
	 *	Version 1.3 - 19.Dezember 2014
	 *  - Added refactoring function GetButtonText()
	 *  - Used CurrentUICulture instead of InstalledUICulture
	 *  - Added more button localizations. Supported languages are now: ENGLISH, GERMAN, SPANISH, ITALIAN
	 *  - Added standard MessageBox handling for "copy to clipboard" with <Ctrl> + <C> and <Ctrl> + <Insert>
	 *  - Tab handling is now corrected (only tabbing over the visible buttons)
	 *  - Added standard MessageBox handling for ALT-Keyboard shortcuts
	 *  - SetDialogSizes: Refactored completely: Corrected sizing and added caption driven sizing
	 * 
	 *	Version 1.2 - 10.August 2013
	 *   - Do not ShowInTaskbar anymore (original MessageBox is also hidden in taskbar)
	 *   - Added handling for Escape-Button
	 *   - Adapted top right close button (red X) to behave like MessageBox (but hidden instead of deactivated)
	 * 
	 *	Version 1.1 - 14.June 2013
	 *   - Some Refactoring
	 *   - Added internal form class
	 *   - Added missing code comments, etc.
	 *  
	 *	Version 1.0 - 15.April 2013
	 *   - Initial Version
	 */
	public class FlexibleMessageBox
	{
		#region Public statics

		/// <summary>
		/// Defines the maximum width for all FlexibleMessageBox instances in percent of the working area.
		/// 
		/// Allowed values are 0.2 - 1.0 where: 
		/// 0.2 means:  The FlexibleMessageBox can be at most half as wide as the working area.
		/// 1.0 means:  The FlexibleMessageBox can be as wide as the working area.
		/// 
		/// Default is: 70% of the working area width.
		/// </summary>
		public static double MAX_WIDTH_FACTOR = 0.7;

		/// <summary>
		/// Defines the maximum height for all FlexibleMessageBox instances in percent of the working area.
		/// 
		/// Allowed values are 0.2 - 1.0 where: 
		/// 0.2 means:  The FlexibleMessageBox can be at most half as high as the working area.
		/// 1.0 means:  The FlexibleMessageBox can be as high as the working area.
		/// 
		/// Default is: 90% of the working area height.
		/// </summary>
		public static double MAX_HEIGHT_FACTOR = 0.9;

		/// <summary>
		/// Defines the font for all FlexibleMessageBox instances.
		/// 
		/// Default is: SystemFonts.MessageBoxFont
		/// </summary>
		public static Font FONT = SystemFonts.MessageBoxFont;

		public static IEnumerable<KeyValuePair<string, string>> GetButtonTextLocalizationKeys
		{
			get
			{
				yield return new KeyValuePair<string, string>("FlexibleMessageBoxBtn.Ok", "OK");
				yield return new KeyValuePair<string, string>("FlexibleMessageBoxBtn.Cancel", "Cancel");
				yield return new KeyValuePair<string, string>("FlexibleMessageBoxBtn.Yes", "&Yes");
				yield return new KeyValuePair<string, string>("FlexibleMessageBoxBtn.No", "&No");
				yield return new KeyValuePair<string, string>("FlexibleMessageBoxBtn.Abort", "&Abort");
				yield return new KeyValuePair<string, string>("FlexibleMessageBoxBtn.Retry", "&Retry");
				yield return new KeyValuePair<string, string>("FlexibleMessageBoxBtn.Ignore", "&Ignore");
			}
		}

		public static Func<string, string> GetButtonText { get; set; }

		/// <summary>
		/// Pass this in as the linkClickedAction to the Show methods to get a simple link-handler that fires off a
		/// process using the link text as it's parameter.
		/// </summary>
		public static LinkClickedEventHandler BasicLinkClickedEventHandler => richTextBoxMessage_LinkClicked;
			<commit_msg>Changed to use syntax compatible with older C# compiler used on TC.<commit_after>﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.Linq;
using System.Windows.Forms;
using L10NSharp;

namespace SIL.Windows.Forms
{
	/*  FlexibleMessageBox – A flexible replacement for the .NET MessageBox
	 * 
	 *  Author:		<NAME> (<EMAIL>)
	 *  Contributors:   Thanks to: <NAME>, Roink
	 *  Version:		1.3
	 *  Published at:   http://www.codeproject.com/Articles/601900/FlexibleMessageBox
	 *  
	 ************************************************************************************************************
	 * Features:
	 *  - It can be simply used instead of MessageBox since all important static "Show"-Functions are supported
	 *  - It is small, only one source file, which could be added easily to each solution 
	 *  - It can be resized and the content is correctly word-wrapped
	 *  - It tries to auto-size the width to show the longest text row
	 *  - It never exceeds the current desktop working area
	 *  - It displays a vertical scrollbar when needed
	 *  - It does support hyperlinks in text
	 *  - It allows copying of messages to clipboard
	 * 
	 *  Because the interface is identical to MessageBox, you can add this single source file to your project 
	 *  and use the FlexibleMessageBox almost everywhere you use a standard MessageBox. 
	 *  The goal was NOT to produce as many features as possible but to provide a simple replacement to fit my 
	 *  own needs. Feel free to add additional features on your own, but please left my credits in this class.
	 * 
	 ************************************************************************************************************
	 * Usage examples:
	 * 
	 *  FlexibleMessageBox.Show("Just a text");
	 * 
	 *  FlexibleMessageBox.Show("A text", "A caption"); 
	 *  
	 *  FlexibleMessageBox.Show("Some text with a link: www.google.com", 
	 *							"Some caption",
	 *							MessageBoxButtons.AbortRetryIgnore, 
	 *							MessageBoxIcon.Information,
	 *							MessageBoxDefaultButton.Button2);
	 *  
	 *  var dialogResult = FlexibleMessageBox.Show("Do you know the answer to life the universe and everything?", 
	 *											   "One short question",
	 *											   MessageBoxButtons.YesNo);	 
	 * 
	 ************************************************************************************************************
	 *  THE SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS", WITHOUT WARRANTY
	 *  OF ANY KIND, EXPRESS OR IMPLIED. IN NO EVENT SHALL THE AUTHOR BE
	 *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY ARISING FROM,
	 *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OF THIS
	 *  SOFTWARE.
	 *  
	 ************************************************************************************************************
	 * History:
	 *	Adapted for use in libpalaso
	 *  - Added override to default handling of LinkClicked event
	 *  - Made localizatin extenisible without altering code
	 *	Version 1.3 - 19.Dezember 2014
	 *  - Added refactoring function GetButtonText()
	 *  - Used CurrentUICulture instead of InstalledUICulture
	 *  - Added more button localizations. Supported languages are now: ENGLISH, GERMAN, SPANISH, ITALIAN
	 *  - Added standard MessageBox handling for "copy to clipboard" with <Ctrl> + <C> and <Ctrl> + <Insert>
	 *  - Tab handling is now corrected (only tabbing over the visible buttons)
	 *  - Added standard MessageBox handling for ALT-Keyboard shortcuts
	 *  - SetDialogSizes: Refactored completely: Corrected sizing and added caption driven sizing
	 * 
	 *	Version 1.2 - 10.August 2013
	 *   - Do not ShowInTaskbar anymore (original MessageBox is also hidden in taskbar)
	 *   - Added handling for Escape-Button
	 *   - Adapted top right close button (red X) to behave like MessageBox (but hidden instead of deactivated)
	 * 
	 *	Version 1.1 - 14.June 2013
	 *   - Some Refactoring
	 *   - Added internal form class
	 *   - Added missing code comments, etc.
	 *  
	 *	Version 1.0 - 15.April 2013
	 *   - Initial Version
	 */
	public class FlexibleMessageBox
	{
		#region Public statics

		/// <summary>
		/// Defines the maximum width for all FlexibleMessageBox instances in percent of the working area.
		/// 
		/// Allowed values are 0.2 - 1.0 where: 
		/// 0.2 means:  The FlexibleMessageBox can be at most half as wide as the working area.
		/// 1.0 means:  The FlexibleMessageBox can be as wide as the working area.
		/// 
		/// Default is: 70% of the working area width.
		/// </summary>
		public static double MAX_WIDTH_FACTOR = 0.7;

		/// <summary>
		/// Defines the maximum height for all FlexibleMessageBox instances in percent of the working area.
		/// 
		/// Allowed values are 0.2 - 1.0 where: 
		/// 0.2 means:  The FlexibleMessageBox can be at most half as high as the working area.
		/// 1.0 means:  The FlexibleMessageBox can be as high as the working area.
		/// 
		/// Default is: 90% of the working area height.
		/// </summary>
		public static double MAX_HEIGHT_FACTOR = 0.9;

		/// <summary>
		/// Defines the font for all FlexibleMessageBox instances.
		/// 
		/// Default is: SystemFonts.MessageBoxFont
		/// </summary>
		public static Font FONT = SystemFonts.MessageBoxFont;

		public static IEnumerable<KeyValuePair<string, string>> GetButtonTextLocalizationKeys
		{
			get
			{
				yield return new KeyValuePair<string, string>("FlexibleMessageBoxBtn.Ok", "OK");
				yield return new KeyValuePair<string, string>("FlexibleMessageBoxBtn.Cancel", "Cancel");
				yield return new KeyValuePair<string, string>("FlexibleMessageBoxBtn.Yes", "&Yes");
				yield return new KeyValuePair<string, string>("FlexibleMessageBoxBtn.No", "&No");
				yield return new KeyValuePair<string, string>("FlexibleMessageBoxBtn.Abort", "&Abort");
				yield return new KeyValuePair<string, string>("FlexibleMessageBoxBtn.Retry", "&Retry");
				yield return new KeyValuePair<string, string>("FlexibleMessageBoxBtn.Ignore", "&Ignore");
			}
		}

		public static Func<string, string> GetButtonText { get; set; }

		/// <summary>
		/// Pass this in as the linkClickedAction to the Show methods to get a simple link-handler that fires off a
		/// process using the link text as it's parameter.
		/// </summary>
		public static LinkClickedEventHandler BasicLinkClickedEventHandler { get { return richTextBoxMessage_LinkClicked; } }

{'fraction_non_alphanumeric': 0.14867090096447894, 'fraction_numerical': 0.01050733160824904, 'mean_word_length': 3.5019414048711615, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 54, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4369369', 'n_tokens_mistral': 3970, 'n_tokens_neox': 3358, 'n_words': 1321}