65 lines
1.7 KiB
C#
65 lines
1.7 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Drawing;
|
|
using System.Text;
|
|
using Speak.Interop;
|
|
|
|
namespace Speak.Opt
|
|
{
|
|
internal class Win32ImageList
|
|
{
|
|
private IntPtr handle;
|
|
private Dictionary<string, int> icons;
|
|
private int defaultIndex;
|
|
private string defaultName;
|
|
|
|
public Win32ImageList() : this (16, 16, 0) { }
|
|
|
|
public Win32ImageList(int width, int height, int count)
|
|
{
|
|
handle = WinApi.ImageList_Create(width, height, WinApi.ILC_MASK | WinApi.ILC_COLOR32, count, 0);
|
|
icons = new Dictionary<string, int>();
|
|
defaultIndex = -1;
|
|
defaultName = "xJuick_Default";
|
|
}
|
|
|
|
public int AddIcon(string iconKey, IntPtr hIcon)
|
|
{
|
|
int result = -1;
|
|
if (icons.ContainsKey(iconKey))
|
|
return icons[iconKey];
|
|
result = WinApi.ImageList_ReplaceIcon(handle, -1, hIcon);
|
|
|
|
if (result != -1)
|
|
{
|
|
icons.Add(iconKey, result);
|
|
if (defaultName.Equals(iconKey))
|
|
defaultIndex = result;
|
|
}
|
|
|
|
|
|
return result;
|
|
}
|
|
|
|
public IntPtr Handle
|
|
{
|
|
get { return handle; }
|
|
}
|
|
|
|
public int this[string iconKey]
|
|
{
|
|
get { return icons.ContainsKey(iconKey) ? icons[iconKey] : defaultIndex; }
|
|
}
|
|
|
|
public int Length
|
|
{
|
|
get { return icons.Count; }
|
|
}
|
|
public int GetIcon(string iconKey)
|
|
{
|
|
int icon = this.icons[iconKey];
|
|
return WinApi.ImageList_GetIcon(handle, icon, WinApi.ILD_NORMAL);
|
|
}
|
|
}
|
|
}
|