From: ttp Date: Sun, 8 May 2011 03:29:21 +0000 (+0900) Subject: AppliStation-GUI,OptionDialogについてノート付きコマンドリンク形式に変更。 X-Git-Tag: v1.4.0b1~5^2~11 X-Git-Url: http://git.sourceforge.jp/view?p=applistation%2FAppliStation.git;a=commitdiff_plain;h=00cce341a71184497ecc16688ee1135ee9169a96;hp=d4a1b4464182bbf36fc3eaed055059da088c841d AppliStation-GUI,OptionDialogについてノート付きコマンドリンク形式に変更。 XP以前はリンク風ボタン+ノート表示用ラベルで表示する。 現状コマンドリンクボタンは固定サイズなのだがどうするのかは現状気にしない。 --- diff --git a/AppliStation/AppliStation.Util/NativeMethods.cs b/AppliStation/AppliStation.Util/NativeMethods.cs index 22aedc7..14fc235 100644 --- a/AppliStation/AppliStation.Util/NativeMethods.cs +++ b/AppliStation/AppliStation.Util/NativeMethods.cs @@ -583,7 +583,7 @@ namespace AppliStation.Util #endregion - [DllImport("user32.dll", CharSet = CharSet.Auto)] + [DllImport("user32.dll", CharSet=CharSet.Auto)] internal static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam); [DllImport("user32.dll", CharSet=CharSet.Auto)] diff --git a/AppliStation/AppliStation.Util/OptionDialog.cs b/AppliStation/AppliStation.Util/OptionDialog.cs index 13ebf38..70373d2 100644 --- a/AppliStation/AppliStation.Util/OptionDialog.cs +++ b/AppliStation/AppliStation.Util/OptionDialog.cs @@ -27,13 +27,13 @@ namespace AppliStation.Util private void HandleUserInput(object sender, EventArgs e) { TextBoxBase textBox = sender as TextBoxBase; - RadioButton radioButton = sender as RadioButton; + ButtonBase button = sender as ButtonBase; if (textBox != null) { this.userInputValue = textBox.Text; } - if (radioButton != null) { - this.userInputValue = radioButton.Tag; + if (button != null) { + this.userInputValue = button.Tag; } } @@ -123,6 +123,65 @@ namespace AppliStation.Util } } + public void BuildCommandLinkButtons(string[] options, int initialOption) + { + OperatingSystem os = Environment.OSVersion; + + this.Content.Clear(); + + int defaultButtonWidth = this.Content.Owner.Width; + for (int i = 0; i < options.Length; i++) { + Button button = null; + if (os.Platform == PlatformID.Win32NT && os.Version.Major >= 6) { + button = new CommandLinkButton(); + string[] labelData = options[i].Split(new char[]{';'}, 2); + button.Text = labelData[0]; + if (labelData.Length > 1 && !string.IsNullOrEmpty(labelData[1])) { + ((CommandLinkButton) button).Note = labelData[1]; + button.Size = new Size(defaultButtonWidth, 58); + } else { + button.Size = new Size(defaultButtonWidth, 41); + } + + this.Content.Add(button); + } else { + button = new Button(); + string[] labelData = options[i].Split(new char[]{';'}, 2); + button.Text = labelData[0]; + button.Font = new Font(button.Font.FontFamily, button.Font.Size * 1.25f, FontStyle.Underline); + button.Size = new Size(defaultButtonWidth, button.Height); + button.TextAlign = ContentAlignment.MiddleLeft; + button.FlatStyle = FlatStyle.Flat; + button.FlatAppearance.BorderSize = 0; + button.FlatAppearance.MouseDownBackColor = SystemColors.ButtonShadow; + button.FlatAppearance.MouseOverBackColor = button.BackColor; + button.ForeColor = SystemColors.HotTrack; + button.Cursor = Cursors.Hand; + + this.Content.Add(button); + + if (labelData.Length > 1 && !string.IsNullOrEmpty(labelData[1])) { + Label label = new Label(); + label.Text = labelData[1]; + label.Margin = new Padding(10, 0, 0, 5); + label.AutoSize = true; + label.UseMnemonic = false; + this.Content.Add(label); + } + } + + button.Tag = i; + button.Click += HandleUserInput; + button.DialogResult = DialogResult.OK; + + if (i == initialOption) { + button.Focus(); + this.userInputValue = initialOption; + } + } + this.Invalidate(); + } + public static OptionDialog createMessageDialog(string message, string title, string mainInstruction, Icon icon) { return createOptionDialog(message, title, mainInstruction, icon, MessageBoxButtons.OK, null, -1); @@ -149,6 +208,23 @@ namespace AppliStation.Util return dialog; } + public static OptionDialog createCommandSelectionDialog(string message, string title, string mainInstruction, Icon icon, string[] options, int initialOption) + { + OptionDialog dialog = new OptionDialog(); + dialog.Text = title; + dialog.ContentText = message; + dialog.MainInstructionText = mainInstruction; + dialog.Image = (icon != null)? icon.ToBitmap() : null; + dialog.Buttons = MessageBoxButtons.OKCancel; + + if (options != null) { + dialog.BuildCommandLinkButtons(options, initialOption); + dialog.okButton.Visible = false; + } + + return dialog; + } + void OptionDialogStyleChanged(object sender, EventArgs e) { mainInstLabel.Font = SystemFonts.CaptionFont; @@ -166,5 +242,49 @@ namespace AppliStation.Util separatorLabel.Visible = false; } } + + #region CommandLinkButton + + private class CommandLinkButton : Button + { + private string note = null; + + private bool isCommandLink = false; + + public CommandLinkButton() + { + this.FlatStyle = FlatStyle.System; + } + + protected override CreateParams CreateParams { + get { + OperatingSystem os = Environment.OSVersion; + + CreateParams cParams = base.CreateParams; + // Vista未満はなにもしない + if (os.Platform == PlatformID.Win32NT && os.Version.Major >= 6) { + cParams.Style |= 0x0000000E; // BS_COMMANDLINK + this.isCommandLink = true; + } else { + this.Padding = new Padding(5); + } + return cParams; + } + } + + public string Note { + set { + if (this.isCommandLink) { + this.note = value; + //SendMessage(hWnd, BCM_SETNOTE, NULL, (PCWSTR)value); + NativeMethods.SendMessage(this.Handle, 0x00001609, IntPtr.Zero, System.Runtime.InteropServices.Marshal.StringToHGlobalAuto(value)); + } + } + get { return this.note; } + } + + } + + #endregion } } diff --git a/AppliStation/PackageListViewForm.cs b/AppliStation/PackageListViewForm.cs index 6bba833..773738c 100644 --- a/AppliStation/PackageListViewForm.cs +++ b/AppliStation/PackageListViewForm.cs @@ -316,13 +316,17 @@ namespace AppliStation void SoftCollectionFileExportToolStripMenuItemClick(object sender, EventArgs e) { string pwd = Directory.GetCurrentDirectory(); - string[] softtargets = new string[]{"PCにインストールされたソフト", "AppliStation内でインストールされたソフト", "インストールされたソフトすべて"}; + string[] softtargets = new string[]{ + "PCにインストールされたソフト", + "AppliStation内でインストールされたソフト", + "インストールされたソフトすべて;PCとAppliStationにインストールされたソフトの両方" + }; int softtargetid = softtargets.Length - 1; { - AppliStation.Util.OptionDialog optdialog = AppliStation.Util.OptionDialog.createOptionDialog( + AppliStation.Util.OptionDialog optdialog = AppliStation.Util.OptionDialog.createCommandSelectionDialog( "ソフトコレクションファイルに出力するソフトの種類を選択してください。", "エクスポート", "エクスポートするソフト", - System.Drawing.SystemIcons.Question, MessageBoxButtons.OKCancel, + System.Drawing.SystemIcons.Question, softtargets, softtargets.Length-1); if (optdialog.ShowDialog(this) != DialogResult.OK) { return; // canceled