OSDN Git Service

AppliStation-GUI,OptionDialogについてノート付きコマンドリンク形式に変更。
authorttp <ttp@users.sourceforge.jp>
Sun, 8 May 2011 03:29:21 +0000 (12:29 +0900)
committerttp <ttp@users.sourceforge.jp>
Sun, 8 May 2011 03:30:46 +0000 (12:30 +0900)
XP以前はリンク風ボタン+ノート表示用ラベルで表示する。
現状コマンドリンクボタンは固定サイズなのだがどうするのかは現状気にしない。

AppliStation/AppliStation.Util/NativeMethods.cs
AppliStation/AppliStation.Util/OptionDialog.cs
AppliStation/PackageListViewForm.cs

index 22aedc7..14fc235 100644 (file)
@@ -583,7 +583,7 @@ namespace AppliStation.Util
                \r
                #endregion\r
                \r
-               [DllImport("user32.dll", CharSet = CharSet.Auto)]\r
+               [DllImport("user32.dll", CharSet=CharSet.Auto)]\r
                internal static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);\r
                \r
                [DllImport("user32.dll", CharSet=CharSet.Auto)]\r
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
index e348e6f..213ca10 100644 (file)
@@ -316,13 +316,17 @@ namespace AppliStation
                void SoftCollectionFileExportToolStripMenuItemClick(object sender, EventArgs e)\r
                {\r
                        string pwd = Directory.GetCurrentDirectory();\r
-                       string[] softtargets = new string[]{"PCにインストールされたソフト", "AppliStation内でインストールされたソフト", "インストールされたソフトすべて"};\r
+                       string[] softtargets = new string[]{\r
+                               "PCにインストールされたソフト",\r
+                               "AppliStation内でインストールされたソフト",\r
+                               "インストールされたソフトすべて;PCとAppliStationにインストールされたソフトの両方"\r
+                       };\r
                        int softtargetid = softtargets.Length - 1;\r
                        \r
                        {\r
-                               AppliStation.Util.OptionDialog optdialog = AppliStation.Util.OptionDialog.createOptionDialog(\r
+                               AppliStation.Util.OptionDialog optdialog = AppliStation.Util.OptionDialog.createCommandSelectionDialog(\r
                                        "ソフトコレクションファイルに出力するソフトの種類を選択してください。", "エクスポート", "エクスポートするソフト",\r
-                                       System.Drawing.SystemIcons.Question, MessageBoxButtons.OKCancel,\r
+                                       System.Drawing.SystemIcons.Question,\r
                                        softtargets, softtargets.Length-1);\r
                                if (optdialog.ShowDialog(this) != DialogResult.OK) {\r
                                        return; // canceled\r