OSDN Git Service

AppliStation-GUI,インストール除外リストの設定を設定ダイアログに追加
[applistation/AppliStation.git] / AppliStation / AppliStation.Util / OptionDialog.cs
1 using System;\r
2 using System.Drawing;\r
3 using System.Windows.Forms;\r
4 \r
5 namespace AppliStation.Util\r
6 {\r
7         /// <summary>\r
8         /// Description of OptionDialog.\r
9         /// </summary>\r
10         public partial class OptionDialog : Form\r
11         {\r
12                 private object userInputValue = null;\r
13                 \r
14                 public OptionDialog()\r
15                 {\r
16                         //\r
17                         // The InitializeComponent() call is required for Windows Forms designer support.\r
18                         //\r
19                         InitializeComponent();\r
20                 }\r
21                 \r
22                 private void SomeButtonClick(object sender, EventArgs e)\r
23                 {\r
24                         this.Close();\r
25                 }\r
26                 \r
27                 private void HandleUserInput(object sender, EventArgs e)\r
28                 {\r
29                         TextBoxBase textBox = sender as TextBoxBase;\r
30                         RadioButton radioButton = sender as RadioButton;\r
31                         \r
32                         if (textBox != null) {\r
33                                 this.userInputValue = textBox.Text;     \r
34                         }\r
35                         if (radioButton != null) {\r
36                                 this.userInputValue = radioButton.Tag;  \r
37                         }\r
38                 }\r
39                 \r
40                 public string MainInstructionText {\r
41                         set {\r
42                                 mainInstLabel.Text = value ?? string.Empty;\r
43                                 mainInstLabel.Visible = ! string.IsNullOrEmpty(value);\r
44                         }\r
45                         get {   return mainInstLabel.Text;      }\r
46                 }\r
47                 public string ContentText {\r
48                         set {\r
49                                 contentLabel.Text = value ?? string.Empty;\r
50                                 contentLabel.Visible = ! string.IsNullOrEmpty(value);\r
51                         }\r
52                         get {   return mainInstLabel.Text;      }\r
53                 }\r
54                 public Image Image {\r
55                         set {\r
56                                 iconPictureBox.Image = value;\r
57                                 if (value != null) {\r
58                                         iconPictureBox.Size = new Size(32, 32);\r
59                                 } else {\r
60                                         iconPictureBox.Size = new Size(0, 0);\r
61                                 }\r
62                         }\r
63                         get {   return iconPictureBox.Image;    }\r
64                 }\r
65                 public MessageBoxButtons Buttons {\r
66                         set {\r
67                                 okButton.Enabled         = okButton.Visible             = (value == MessageBoxButtons.OK) || (value == MessageBoxButtons.OKCancel);\r
68                                 cancelButton.Enabled = cancelButton.Visible     = (value == MessageBoxButtons.OKCancel) || (value == MessageBoxButtons.YesNoCancel);\r
69                                 yesButton.Enabled        = yesButton.Visible    = (value == MessageBoxButtons.YesNo) || (value == MessageBoxButtons.YesNoCancel);\r
70                                 noButton.Enabled         = noButton.Visible             = (value == MessageBoxButtons.YesNo) || (value == MessageBoxButtons.YesNoCancel);\r
71                                 \r
72                                 if (okButton.Enabled) {\r
73                                         this.AcceptButton = okButton;\r
74                                 } else if (yesButton.Enabled) {\r
75                                         this.AcceptButton = yesButton;\r
76                                 }\r
77                         }\r
78                         get {\r
79                                 bool ok = okButton.Enabled;\r
80                                 bool cancel = cancelButton.Enabled;\r
81                                 bool yes = yesButton.Enabled;\r
82                                 bool no = noButton.Enabled;\r
83                                 \r
84                                 if (ok && !cancel && !yes && !no) {\r
85                                         return MessageBoxButtons.OK;\r
86                                 } else if (ok && cancel && !yes && !no) {\r
87                                         return MessageBoxButtons.OKCancel;\r
88                                 } else if (!ok && !cancel && yes && no) {\r
89                                         return MessageBoxButtons.YesNo;\r
90                                 } else if (!ok && cancel && yes && no) {\r
91                                         return MessageBoxButtons.YesNoCancel;\r
92                                 } else {\r
93                                         return (MessageBoxButtons) 0xFFFFu;\r
94                                 }\r
95                         }\r
96                 }\r
97                 public Control.ControlCollection Content {\r
98                         get {   return contentFlowLayoutPanel.Controls; }\r
99                 }\r
100                 \r
101                 public object UserInputValue {\r
102                         get { return userInputValue; }\r
103                 }\r
104                 \r
105                 public void BuildRadioButtons(string[] options, int initialOption) {\r
106                         this.Content.Clear();\r
107                         \r
108                         for (int i = 0; i < options.Length; i++) {\r
109                                 RadioButton optRadios = new RadioButton();\r
110                                 optRadios.Text = options[i];\r
111                                 optRadios.Tag = i;\r
112                                 optRadios.Click += HandleUserInput;\r
113                                 optRadios.AutoSize = true;\r
114                                 \r
115                                 if (i == initialOption) {\r
116                                         optRadios.Checked = true;\r
117                                         this.userInputValue = initialOption;\r
118                                 } else {\r
119                                         optRadios.Checked = false;\r
120                                 }\r
121                                 \r
122                                 this.Content.Add(optRadios);\r
123                         }\r
124                 }\r
125                 \r
126                 public static OptionDialog createMessageDialog(string message, string title, string mainInstruction, Icon icon)\r
127                 {\r
128                         return createOptionDialog(message, title, mainInstruction, icon, MessageBoxButtons.OK, null, -1);\r
129                 }\r
130                 \r
131                 public static OptionDialog createConfirmDialog(string message, string title, string mainInstruction, Icon icon, MessageBoxButtons buttons)\r
132                 {\r
133                         return createOptionDialog(message, title, mainInstruction, icon, buttons, null, -1);\r
134                 }\r
135                 \r
136                 public static OptionDialog createOptionDialog(string message, string title, string mainInstruction, Icon icon, MessageBoxButtons buttons, string[] options, int initialOption)\r
137                 {\r
138                         OptionDialog dialog = new OptionDialog();\r
139                         dialog.Text = title;\r
140                         dialog.ContentText = message;\r
141                         dialog.MainInstructionText = mainInstruction;\r
142                         dialog.Image = (icon != null)? icon.ToBitmap() : null;\r
143                         dialog.Buttons = buttons;\r
144                         \r
145                         if (options != null) {\r
146                                 dialog.BuildRadioButtons(options, initialOption);\r
147                         }\r
148                         \r
149                         return dialog;\r
150                 }\r
151                 \r
152                 void OptionDialogStyleChanged(object sender, EventArgs e)\r
153                 {\r
154                         mainInstLabel.Font = SystemFonts.CaptionFont;\r
155                         if (System.Windows.Forms.VisualStyles.VisualStyleInformation.IsEnabledByUser) {\r
156                                 mainInstLabel.ForeColor = Color.FromArgb(0x003399);\r
157                                 \r
158                                 this.BackColor = SystemColors.Window;\r
159                                 this.ForeColor = SystemColors.WindowText;\r
160                                 separatorLabel.Visible = true;\r
161                         } else {\r
162                                 mainInstLabel.ForeColor = Color.Empty;\r
163                                 \r
164                                 this.BackColor = Color.Empty;\r
165                                 this.ForeColor = Color.Empty;\r
166                                 separatorLabel.Visible = false;\r
167                         }\r
168                 }\r
169         }\r
170 }\r