X-Git-Url: http://git.sourceforge.jp/view?a=blobdiff_plain;f=AppliStation%2FAppliStation.Util%2FGUIUtils.cs;h=bd2a8ff28e83a5739d174a40b69772b647d6c03c;hb=3033b219e37faf6ab6795219c2f6acfdaf47fec6;hp=7e235d6e38aba285da52692481137135fcabd037;hpb=b84c03d933677cd9b7f685b8d44330b7e96155a7;p=applistation%2FAppliStation.git
diff --git a/AppliStation/AppliStation.Util/GUIUtils.cs b/AppliStation/AppliStation.Util/GUIUtils.cs
index 7e235d6..bd2a8ff 100644
--- a/AppliStation/AppliStation.Util/GUIUtils.cs
+++ b/AppliStation/AppliStation.Util/GUIUtils.cs
@@ -1,7 +1,9 @@
using System;
using System.IO;
+using System.Runtime.InteropServices;
using System.Drawing;
using System.Drawing.Imaging;
+using System.Windows.Forms;
using NaGet.Packages;
using NaGet.Packages.Install;
@@ -12,6 +14,42 @@ namespace AppliStation.Util
///
public sealed class GUIUtils
{
+ #region ã¢ã¤ã³ã³é¢é£
+
+ #region ExtraIconé¢é£
+
+ ///
+ /// ã¢ã¤ã³ã³ãã¡ã¤ã«ï¼å®è¡ãã¡ã¤ã«ã»DLLï¼ãéãã¦ã¢ã¤ã³ã³ãä½ã
+ ///
+ /// ãã³ãã©
+ /// 対象ãã¡ã¤ã«ã¨ã¢ã¤ã³ã³ã¤ã³ããã¯ã¹ã®æåå表ç¾
+ /// çæãããã¢ã¤ã³ã³ã
+ public static Icon ExtractIcon(Form form, string lpszExeFileNameAndIndex)
+ {
+ int index = lpszExeFileNameAndIndex.LastIndexOf(',');
+ if (index >= 0) {
+ uint nIconIndex = uint.Parse(lpszExeFileNameAndIndex.Substring(index+1));
+ return NativeMethods.ExtractIcon(form, lpszExeFileNameAndIndex.Substring(0, index), nIconIndex);
+ } else {
+ return Icon.ExtractAssociatedIcon(lpszExeFileNameAndIndex);
+ }
+ }
+
+ ///
+ /// ã·ã§ã«ãããã©ã«ãã¼ã¢ã¤ã³ã³ãçæãã¦è¿ã
+ ///
+ /// ãã©ã«ãã¼ã¢ã¤ã³ã³
+ public static Icon ShellIconForFolder
+ {
+ get {
+ // Vista以éãªãã°ãSHGetStockIconInfo(SIID_FOLDER, SHGSI_ICON, &sInfo); ãP/Invokeå¼ã³åºãããã®ãçéãã¨
+ string windir = Environment.GetEnvironmentVariable("windir");
+ return NativeMethods.ExtractIcon(null, Path.Combine(windir, @"system32\shell32.dll"), 3);
+ }
+ }
+
+ #endregion
+
///
/// ããã±ã¼ã¸ã«å¯¾å¿ããã¢ã¤ã³ã³ãè¿ã
///
@@ -19,29 +57,31 @@ namespace AppliStation.Util
/// 対å¿ããã¢ã¤ã³ã³ãæ¤åºã§ããªãã£ãå ´åã¯nullã
public static Icon GetIconForPackage(InstalledPackage pkg)
{
- string iconPath = pkg.UninstallInfo.IconPath;
- if (! string.IsNullOrEmpty(iconPath)) {
- if (iconPath.EndsWith(",0") || iconPath.EndsWith(",-0")) {
- iconPath = iconPath.Substring(0, iconPath.LastIndexOf(','));
- }
- if (File.Exists(iconPath)) {
- return Icon.ExtractAssociatedIcon(iconPath);
- }
- } else if (pkg.Type == InstallerType.ARCHIVE) {
- string progGrp = Path.Combine(NaGet.Env.ArchiveProgramGroup, pkg.Name);
- if (Directory.Exists(progGrp)) {
- string[] lnkFiles = Directory.GetFiles(progGrp, "*.lnk");
-
- if (lnkFiles.Length >= 1) {
- using (NaGet.InteropServices.ShellLink link = new NaGet.InteropServices.ShellLink(lnkFiles[0])) {
- if (File.Exists(link.GetPath(0))) {
- return Icon.ExtractAssociatedIcon(link.GetPath(0));
+ Icon ico = null;
+ try {
+ string iconPath = pkg.UninstallInfo.IconPath;
+ if (! string.IsNullOrEmpty(iconPath)) {
+ ico = ExtractIcon(null, iconPath);
+ } else if ((pkg.Type == InstallerType.ARCHIVE)
+ ||(pkg.Type == InstallerType.ITSELF)) {
+ string progGrp = Path.Combine(NaGet.Env.ArchiveProgramGroup, pkg.Name);
+ if (Directory.Exists(progGrp)) {
+ string[] lnkFiles = Directory.GetFiles(progGrp, "*.lnk");
+
+ if (lnkFiles.Length >= 1) {
+ using (NaGet.InteropServices.ShellLink link = new NaGet.InteropServices.ShellLink(lnkFiles[0])) {
+ if (File.Exists(link.GetPath(0))) {
+ ico = Icon.ExtractAssociatedIcon(link.GetPath(0));
+ }
}
}
}
}
+ } catch (System.Runtime.InteropServices.COMException) {
+ // ShellLinkã®ãªã¼ãã³ãããã¯ããªã³ã¯å
解決ã«å¤±æããå ´å
+ } catch (Exception) {
}
- return null;
+ return ico;
}
///
@@ -57,11 +97,11 @@ namespace AppliStation.Util
const float b = 0.114478f;
ColorMatrix cm = new ColorMatrix(new float[][]{
- new float[]{r, r, r, 0, 0},
- new float[]{g, g, g, 0, 0},
- new float[]{b, b, b, 0, 0},
+ new float[]{r, r, r, 0, 0},
+ new float[]{g, g, g, 0, 0},
+ new float[]{b, b, b, 0, 0},
new float[]{0, 0, 0, alpha, 0},
- new float[]{0, 0, 0, 0, 1},
+ new float[]{0, 0, 0, 0, 1},
});
ImageAttributes ia = new ImageAttributes();
ia.SetColorMatrix(cm);
@@ -69,6 +109,13 @@ namespace AppliStation.Util
return ia;
}
+ ///
+ /// ç»åãæå®é åã®çä¸ã«æã
+ ///
+ /// æç»å¯¾è±¡ã®ã°ã©ãã£ãã¯ã¹
+ /// ç»å
+ /// æå®é å
+ /// ImageAttributesãnullã§ããã¾ããªã
public static void Graphics_DrawCenterImage(Graphics g, Image img, Rectangle b, ImageAttributes ia)
{
int x = b.Left + (b.Width - img.Width ) / 2;
@@ -79,5 +126,30 @@ namespace AppliStation.Util
0, 0, img.Width, img.Height,
GraphicsUnit.Pixel, ia);
}
+
+ #endregion
+
+ #region CheckedListBoxé¢é£
+
+ ///
+ /// ãã§ãã¯ãªã¹ãããã¯ã¹ã®ã¢ã¤ãã ãã¹ã¯ãããã
+ ///
+ /// æä½å¯¾è±¡ã®CheckedListBox
+ /// ã¢ã¤ãã ã¤ã³ããã¯ã¹
+ /// ã¢ã¤ãã ã¤ã³ããã¯ã¹
+ /// ã¤ã³ããã¯ã¹å¤ã®ãã§ãã¯ã¯æ¬ã¡ã½ããã§ã¯è¡ã£ã¦ããªã
+ public static void CheckedListBox_SwapItems(CheckedListBox checkedListBox, int indexA, int indexB) {
+ int itemCount = checkedListBox.Items.Count;
+ object tempItem = checkedListBox.Items[indexA];
+ CheckState tempState = checkedListBox.GetItemCheckState(indexA);
+
+ checkedListBox.Items[indexA] = checkedListBox.Items[indexB];
+ checkedListBox.SetItemCheckState(indexA, checkedListBox.GetItemCheckState(indexB));
+
+ checkedListBox.Items[indexB] = tempItem;
+ checkedListBox.SetItemCheckState(indexB, tempState);
+ }
+
+ #endregion
}
}