PeripheralOptionPanel.cs
上传用户:szltgg
上传日期:2019-05-16
资源大小:604k
文件大小:12k
源码类别:

Telnet服务器

开发平台:

C#

  1. /*
  2. * Copyright (c) 2005 Poderosa Project, All Rights Reserved.
  3. * $Id: PeripheralOptionPanel.cs,v 1.2 2005/04/20 08:45:45 okajima Exp $
  4. */
  5. using System;
  6. using System.Windows.Forms;
  7. using System.Diagnostics;
  8. using Poderosa.Toolkit;
  9. using Poderosa.Config;
  10. using Poderosa.UI;
  11. namespace Poderosa.Forms
  12. {
  13. /// <summary>
  14. /// PeripheralOptionPanel 偺奣梫偺愢柧偱偡丅
  15. /// </summary>
  16. internal class PeripheralOptionPanel : OptionDialog.CategoryPanel
  17. {
  18. private System.Windows.Forms.Label _leftAltKeyLabel;
  19. private ComboBox _leftAltKeyAction;
  20. private System.Windows.Forms.Label _rightAltKeyLabel;
  21. private ComboBox _rightAltKeyAction;
  22. private System.Windows.Forms.Label _rightButtonActionLabel;
  23. private ComboBox _rightButtonAction;
  24. private CheckBox _autoCopyByLeftButton;
  25. private Label _additionalWordElementLabel;
  26. private TextBox _additionalWordElementBox;
  27. private CheckBox _send0x7FByDel;
  28. private System.Windows.Forms.Label _wheelAmountLabel;
  29. private TextBox _wheelAmount;
  30. private Label _localBufferScrollModifierLabel;
  31. private ComboBox _localBufferScrollModifierBox;
  32. public PeripheralOptionPanel()
  33. {
  34. InitializeComponent();
  35. FillText();
  36. }
  37. private void InitializeComponent() {
  38. this._leftAltKeyLabel = new System.Windows.Forms.Label();
  39. this._leftAltKeyAction = new ComboBox();
  40. this._rightAltKeyLabel = new System.Windows.Forms.Label();
  41. this._rightAltKeyAction = new ComboBox();
  42. this._send0x7FByDel = new CheckBox();
  43. this._autoCopyByLeftButton = new CheckBox();
  44. this._rightButtonActionLabel = new Label();
  45. this._rightButtonAction = new ComboBox();
  46. this._wheelAmountLabel = new Label();
  47. this._wheelAmount = new TextBox();
  48. this._additionalWordElementLabel = new Label();
  49. this._additionalWordElementBox = new TextBox();
  50. this._localBufferScrollModifierLabel = new Label();
  51. this._localBufferScrollModifierBox = new ComboBox();
  52. this.Controls.AddRange(new System.Windows.Forms.Control[] {
  53. this._leftAltKeyLabel,
  54. this._leftAltKeyAction,
  55. this._rightAltKeyLabel,
  56. this._rightAltKeyAction,
  57. this._send0x7FByDel,
  58. this._autoCopyByLeftButton,
  59. this._additionalWordElementLabel,
  60. this._additionalWordElementBox,
  61. this._rightButtonActionLabel,
  62. this._rightButtonAction,
  63. this._wheelAmountLabel,
  64. this._wheelAmount,
  65. this._localBufferScrollModifierLabel,
  66. this._localBufferScrollModifierBox});
  67. // 
  68. // _leftAltKeyLabel
  69. // 
  70. this._leftAltKeyLabel.Location = new System.Drawing.Point(24, 12);
  71. this._leftAltKeyLabel.Name = "_leftAltKeyLabel";
  72. this._leftAltKeyLabel.Size = new System.Drawing.Size(160, 23);
  73. this._leftAltKeyLabel.TabIndex = 0;
  74. this._leftAltKeyLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  75. // 
  76. // _leftAltKey
  77. // 
  78. this._leftAltKeyAction.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  79. this._leftAltKeyAction.Location = new System.Drawing.Point(264, 12);
  80. this._leftAltKeyAction.Name = "_leftAltKey";
  81. this._leftAltKeyAction.Size = new System.Drawing.Size(152, 19);
  82. this._leftAltKeyAction.TabIndex = 1;
  83. // 
  84. // _rightAltKeyLabel
  85. // 
  86. this._rightAltKeyLabel.Location = new System.Drawing.Point(24, 36);
  87. this._rightAltKeyLabel.Name = "_rightAltKeyLabel";
  88. this._rightAltKeyLabel.Size = new System.Drawing.Size(160, 23);
  89. this._rightAltKeyLabel.TabIndex = 2;
  90. this._rightAltKeyLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  91. // 
  92. // _rightAltKey
  93. // 
  94. this._rightAltKeyAction.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  95. this._rightAltKeyAction.Location = new System.Drawing.Point(264, 36);
  96. this._rightAltKeyAction.Name = "_rightAltKey";
  97. this._rightAltKeyAction.Size = new System.Drawing.Size(152, 19);
  98. this._rightAltKeyAction.TabIndex = 3;
  99. // 
  100. // _send0x7FByDel
  101. // 
  102. this._send0x7FByDel.Location = new System.Drawing.Point(24, 60);
  103. this._send0x7FByDel.Name = "_send0x7FByDel";
  104. this._send0x7FByDel.FlatStyle = FlatStyle.System;
  105. this._send0x7FByDel.Size = new System.Drawing.Size(192, 20);
  106. this._send0x7FByDel.TabIndex = 4;
  107. // 
  108. // _autoCopyByLeftButton
  109. // 
  110. this._autoCopyByLeftButton.Location = new System.Drawing.Point(24, 84);
  111. this._autoCopyByLeftButton.Name = "_autoCopyByLeftButton";
  112. this._autoCopyByLeftButton.FlatStyle = FlatStyle.System;
  113. this._autoCopyByLeftButton.Size = new System.Drawing.Size(288, 20);
  114. this._autoCopyByLeftButton.TabIndex = 5;
  115. // 
  116. // _additionalWordElementLabel
  117. // 
  118. this._additionalWordElementLabel.Location = new System.Drawing.Point(24, 108);
  119. this._additionalWordElementLabel.Size = new System.Drawing.Size(192, 23);
  120. this._additionalWordElementLabel.TabIndex = 6;
  121. this._additionalWordElementLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  122. // 
  123. // _additionalWordElementBox
  124. // 
  125. this._additionalWordElementBox.Location = new System.Drawing.Point(264, 108);
  126. this._additionalWordElementBox.Size = new System.Drawing.Size(152, 23);
  127. this._additionalWordElementBox.TabIndex = 7;
  128. // 
  129. // _rightButtonActionLabel
  130. // 
  131. this._rightButtonActionLabel.Location = new System.Drawing.Point(24, 132);
  132. this._rightButtonActionLabel.Name = "_rightButtonActionLabel";
  133. this._rightButtonActionLabel.Size = new System.Drawing.Size(160, 23);
  134. this._rightButtonActionLabel.TabIndex = 8;
  135. this._rightButtonActionLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  136. // 
  137. // _rightButtonAction
  138. // 
  139. this._rightButtonAction.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  140. this._rightButtonAction.Location = new System.Drawing.Point(264, 132);
  141. this._rightButtonAction.Name = "_rightButtonAction";
  142. this._rightButtonAction.Size = new System.Drawing.Size(152, 19);
  143. this._rightButtonAction.TabIndex = 9;
  144. // 
  145. // _wheelAmountLabel
  146. // 
  147. this._wheelAmountLabel.Location = new System.Drawing.Point(24, 156);
  148. this._wheelAmountLabel.Name = "_wheelAmountLabel";
  149. this._wheelAmountLabel.Size = new System.Drawing.Size(176, 23);
  150. this._wheelAmountLabel.TabIndex = 10;
  151. this._wheelAmountLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  152. // 
  153. // _wheelAmount
  154. // 
  155. this._wheelAmount.Location = new System.Drawing.Point(264, 156);
  156. this._wheelAmount.Name = "_wheelAmount";
  157. this._wheelAmount.Size = new System.Drawing.Size(152, 19);
  158. this._wheelAmount.TabIndex = 11;
  159. this._wheelAmount.MaxLength = 2;
  160. // 
  161. // _localBufferScrollModifierLabel
  162. // 
  163. this._localBufferScrollModifierLabel.Location = new System.Drawing.Point(24, 180);
  164. this._localBufferScrollModifierLabel.Name = "_localBufferScrollModifierLabel";
  165. this._localBufferScrollModifierLabel.Size = new System.Drawing.Size(240, 23);
  166. this._localBufferScrollModifierLabel.TabIndex = 12;
  167. this._localBufferScrollModifierLabel.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  168. // 
  169. // _localBufferScrollModifierBox
  170. // 
  171. this._localBufferScrollModifierBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  172. this._localBufferScrollModifierBox.Location = new System.Drawing.Point(264, 180);
  173. this._localBufferScrollModifierBox.Name = "_localBufferScrollModifierBox";
  174. this._localBufferScrollModifierBox.Size = new System.Drawing.Size(152, 19);
  175. this._localBufferScrollModifierBox.TabIndex = 13;
  176. this.BackColor = ThemeUtil.TabPaneBackColor;
  177. }
  178. private void FillText() {
  179. this._leftAltKeyLabel.Text = GApp.Strings.GetString("Form.OptionDialog._leftAltKeyLabel");
  180. this._rightAltKeyLabel.Text = GApp.Strings.GetString("Form.OptionDialog._rightAltKeyLabel");
  181. this._send0x7FByDel.Text = GApp.Strings.GetString("Form.OptionDialog._send0x7FByDel");
  182. this._autoCopyByLeftButton.Text = GApp.Strings.GetString("Form.OptionDialog._autoCopyByLeftButton");
  183. this._rightButtonActionLabel.Text = GApp.Strings.GetString("Form.OptionDialog._rightButtonActionLabel");
  184. this._wheelAmountLabel.Text = GApp.Strings.GetString("Form.OptionDialog._wheelAmountLabel");
  185. this._additionalWordElementLabel.Text = GApp.Strings.GetString("Form.OptionDialog._additionalWordElementLabel");
  186. this._localBufferScrollModifierLabel.Text = GApp.Strings.GetString("Form.OptionDialog._localBufferScrollModifierLabel");
  187. _leftAltKeyAction.Items.AddRange(EnumDescAttribute.For(typeof(AltKeyAction)).DescriptionCollection());
  188. _rightAltKeyAction.Items.AddRange(EnumDescAttribute.For(typeof(AltKeyAction)).DescriptionCollection());
  189. _rightButtonAction.Items.AddRange(EnumDescAttribute.For(typeof(RightButtonAction)).DescriptionCollection());
  190. _localBufferScrollModifierBox.Items.AddRange(new object[] { "Control", "Shift" });
  191. }
  192. public override void InitUI(ContainerOptions options) {
  193. _leftAltKeyAction.SelectedIndex = (int)options.LeftAltKey;
  194. _rightAltKeyAction.SelectedIndex = (int)options.RightAltKey;
  195. _send0x7FByDel.Checked = options.Send0x7FByDel;
  196. _autoCopyByLeftButton.Checked = options.AutoCopyByLeftButton;
  197. _rightButtonAction.SelectedIndex = (int)options.RightButtonAction;
  198. _wheelAmount.Text = options.WheelAmount.ToString();
  199. _additionalWordElementBox.Text = options.AdditionalWordElement;
  200. _localBufferScrollModifierBox.SelectedIndex = LocalBufferScrollModifierIndex(options.LocalBufferScrollModifier);
  201. }
  202. public override bool Commit(ContainerOptions options) {
  203. bool successful = false;
  204. string itemname = null;
  205. try {
  206. //Win9x偱偼丄嵍塃偺Alt偺嬫暿偑偱偒側偄偺偱暿乆偺愝掕偵偡傞偙偲傪嬛巭偡傞
  207. if(System.Environment.OSVersion.Platform==PlatformID.Win32Windows &&
  208. _leftAltKeyAction.SelectedIndex!=_rightAltKeyAction.SelectedIndex) {
  209. GUtil.Warning(this, GApp.Strings.GetString("Message.OptionDialog.AltKeyOnWin9x"));
  210. return false;
  211. }
  212. options.LeftAltKey = (AltKeyAction)_leftAltKeyAction.SelectedIndex;
  213. options.RightAltKey = (AltKeyAction)_rightAltKeyAction.SelectedIndex;
  214. options.Send0x7FByDel = _send0x7FByDel.Checked;
  215. options.AutoCopyByLeftButton = _autoCopyByLeftButton.Checked;
  216. options.RightButtonAction = (RightButtonAction)_rightButtonAction.SelectedIndex;
  217. itemname = GApp.Strings.GetString("Caption.OptionDialog.MousewheelAmount");
  218. options.WheelAmount = Int32.Parse(_wheelAmount.Text);
  219. options.LocalBufferScrollModifier = LocalBufferScrollModifierKey(_localBufferScrollModifierBox.SelectedIndex);
  220. foreach(char ch in _additionalWordElementBox.Text) {
  221. if(ch>=0x100) {
  222. GUtil.Warning(this, GApp.Strings.GetString("Message.OptionDialog.InvalidAdditionalWordElement"));
  223. return false;
  224. }
  225. }
  226. options.AdditionalWordElement = _additionalWordElementBox.Text;
  227. successful = true;
  228. }
  229. catch(FormatException) {
  230. GUtil.Warning(this, String.Format(GApp.Strings.GetString("Message.OptionDialog.InvalidItem"), itemname));
  231. }
  232. catch(InvalidOptionException ex) {
  233. GUtil.Warning(this, ex.Message);
  234. }
  235. return successful;
  236. }
  237. private static int LocalBufferScrollModifierIndex(Keys key) {
  238. if(key==Keys.Control)
  239. return 0;
  240. else if(key==Keys.Shift)
  241. return 1;
  242. else if(key==Keys.Alt)
  243. return 2;
  244. else
  245. return -1; //never comes
  246. }
  247. private static Keys LocalBufferScrollModifierKey(int index) {
  248. if(index==0)
  249. return Keys.Control;
  250. else if(index==1)
  251. return Keys.Shift;
  252. else if(index==2)
  253. return Keys.Alt;
  254. else
  255. return Keys.Control;
  256. }
  257. }
  258. }