OSDN Git Service

AppliStation-GUI,OptionDialogについてノート付きコマンドリンク形式に変更。
[applistation/AppliStation.git] / AppliStation / AppliStation.Util / OptionDialog.cs
index 13ebf38..70373d2 100644 (file)
@@ -27,13 +27,13 @@ namespace AppliStation.Util
                private void HandleUserInput(object sender, EventArgs e)\r
                {\r
                        TextBoxBase textBox = sender as TextBoxBase;\r
-                       RadioButton radioButton = sender as RadioButton;\r
+                       ButtonBase button       = sender as ButtonBase;\r
                        \r
                        if (textBox != null) {\r
                                this.userInputValue = textBox.Text;     \r
                        }\r
-                       if (radioButton != null) {\r
-                               this.userInputValue = radioButton.Tag;  \r
+                       if (button != null) {\r
+                               this.userInputValue = button.Tag;\r
                        }\r
                }\r
                \r
@@ -123,6 +123,65 @@ namespace AppliStation.Util
                        }\r
                }\r
                \r
+               public void BuildCommandLinkButtons(string[] options, int initialOption)\r
+               {\r
+                       OperatingSystem os = Environment.OSVersion;\r
+                       \r
+                       this.Content.Clear();\r
+                       \r
+                       int defaultButtonWidth = this.Content.Owner.Width;\r
+                       for (int i = 0; i < options.Length; i++) {\r
+                               Button button = null;\r
+                               if (os.Platform == PlatformID.Win32NT && os.Version.Major >= 6) {\r
+                                       button = new CommandLinkButton();\r
+                                       string[] labelData = options[i].Split(new char[]{';'}, 2);\r
+                                       button.Text = labelData[0];\r
+                                       if (labelData.Length > 1 && !string.IsNullOrEmpty(labelData[1])) {\r
+                                               ((CommandLinkButton) button).Note = labelData[1];\r
+                                               button.Size = new Size(defaultButtonWidth, 58);\r
+                                       } else {\r
+                                               button.Size = new Size(defaultButtonWidth, 41);\r
+                                       }\r
+                                       \r
+                                       this.Content.Add(button);\r
+                               } else {\r
+                                       button = new Button();\r
+                                       string[] labelData = options[i].Split(new char[]{';'}, 2);\r
+                                       button.Text = labelData[0];\r
+                                       button.Font = new Font(button.Font.FontFamily, button.Font.Size * 1.25f, FontStyle.Underline);\r
+                                       button.Size = new Size(defaultButtonWidth, button.Height);\r
+                                       button.TextAlign = ContentAlignment.MiddleLeft;\r
+                                       button.FlatStyle = FlatStyle.Flat;\r
+                                       button.FlatAppearance.BorderSize = 0;\r
+                                       button.FlatAppearance.MouseDownBackColor = SystemColors.ButtonShadow;\r
+                                       button.FlatAppearance.MouseOverBackColor = button.BackColor;\r
+                                       button.ForeColor = SystemColors.HotTrack;\r
+                                       button.Cursor = Cursors.Hand;\r
+                                       \r
+                                       this.Content.Add(button);\r
+                                       \r
+                                       if (labelData.Length > 1 && !string.IsNullOrEmpty(labelData[1])) {\r
+                                               Label label = new Label();\r
+                                               label.Text = labelData[1];\r
+                                               label.Margin = new Padding(10, 0, 0, 5);\r
+                                               label.AutoSize = true;\r
+                                               label.UseMnemonic = false;\r
+                                               this.Content.Add(label);\r
+                                       }\r
+                               }\r
+                               \r
+                               button.Tag = i;\r
+                               button.Click += HandleUserInput;\r
+                               button.DialogResult = DialogResult.OK;\r
+                               \r
+                               if (i == initialOption) {\r
+                                       button.Focus();\r
+                                       this.userInputValue = initialOption;\r
+                               }\r
+                       }\r
+                       this.Invalidate();\r
+               }\r
+               \r
                public static OptionDialog createMessageDialog(string message, string title, string mainInstruction, Icon icon)\r
                {\r
                        return createOptionDialog(message, title, mainInstruction, icon, MessageBoxButtons.OK, null, -1);\r
@@ -149,6 +208,23 @@ namespace AppliStation.Util
                        return dialog;\r
                }\r
                \r
+               public static OptionDialog createCommandSelectionDialog(string message, string title, string mainInstruction, Icon icon, string[] options, int initialOption)\r
+               {\r
+                       OptionDialog dialog = new OptionDialog();\r
+                       dialog.Text = title;\r
+                       dialog.ContentText = message;\r
+                       dialog.MainInstructionText = mainInstruction;\r
+                       dialog.Image = (icon != null)? icon.ToBitmap() : null;\r
+                       dialog.Buttons = MessageBoxButtons.OKCancel;\r
+                       \r
+                       if (options != null) {\r
+                               dialog.BuildCommandLinkButtons(options, initialOption);\r
+                               dialog.okButton.Visible = false;\r
+                       }\r
+                       \r
+                       return dialog;\r
+               }\r
+               \r
                void OptionDialogStyleChanged(object sender, EventArgs e)\r
                {\r
                        mainInstLabel.Font = SystemFonts.CaptionFont;\r
@@ -166,5 +242,49 @@ namespace AppliStation.Util
                                separatorLabel.Visible = false;\r
                        }\r
                }\r
+\r
+               #region CommandLinkButton\r
+\r
+               private class CommandLinkButton : Button\r
+               {\r
+                       private string note = null;\r
+                       \r
+                       private bool isCommandLink = false;\r
+                       \r
+                       public CommandLinkButton()\r
+                       {\r
+                               this.FlatStyle = FlatStyle.System;\r
+                       }\r
+                       \r
+                       protected override CreateParams CreateParams {\r
+                               get {\r
+                                       OperatingSystem os = Environment.OSVersion;\r
+                                       \r
+                                       CreateParams cParams = base.CreateParams;\r
+                                       // Vista未満はなにもしない\r
+                                       if (os.Platform == PlatformID.Win32NT && os.Version.Major >= 6) {\r
+                                               cParams.Style |= 0x0000000E;    // BS_COMMANDLINK\r
+                                               this.isCommandLink = true;\r
+                                       } else {\r
+                                               this.Padding = new Padding(5);\r
+                                       }\r
+                                       return cParams;\r
+                               }\r
+                       }\r
+                       \r
+                       public string Note {\r
+                               set {\r
+                                       if (this.isCommandLink) {\r
+                                               this.note = value;\r
+                                               //SendMessage(hWnd, BCM_SETNOTE, NULL, (PCWSTR)value);\r
+                                               NativeMethods.SendMessage(this.Handle, 0x00001609, IntPtr.Zero, System.Runtime.InteropServices.Marshal.StringToHGlobalAuto(value));\r
+                                       }\r
+                               }\r
+                               get { return this.note; }\r
+                       }\r
+                       \r
+               }\r
+               \r
+               #endregion\r
        }\r
 }\r