1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
use crate::co;
use crate::comctl::privs::*;
use crate::decl::*;
use crate::kernel::privs::*;
use crate::prelude::*;

/// Variant parameter for:
///
/// * [`stm::GetImage`](crate::msg::stm::GetImage);
/// * [`stm::SetImage`](crate::msg::stm::SetImage).
pub enum BmpIconCurMeta {
	/// Bitmap.
	Bmp(HBITMAP),
	/// Icon.
	Icon(HICON),
	/// Cursor.
	Cur(HCURSOR),
	/// Enhanced metafile.
	Meta(HDC),
}

impl BmpIconCurMeta {
	/// Converts the contents into an `isize`.
	#[must_use]
	pub fn as_isize(&self) -> isize {
		unsafe {
			std::mem::transmute(match self {
				BmpIconCurMeta::Bmp(hbmp) => hbmp.ptr(),
				BmpIconCurMeta::Icon(hicon) => hicon.ptr(),
				BmpIconCurMeta::Cur(hcur) => hcur.ptr(),
				BmpIconCurMeta::Meta(hdc) => hdc.ptr(),
			})
		}
	}
}

/// Variant parameter for:
///
/// * [`TBADDBITMAP`](crate::TBADDBITMAP).
pub enum BmpIdbRes {
	/// An [`HBITMAP`](crate::HBITMAP).
	Bmp(HBITMAP),
	/// A system-defined [`co::IDB`](crate::co::IDB) bitmap.
	Idb(co::IDB),
	/// A bitmap resource.
	Res(IdStr, HINSTANCE),
}

/// Variant parameter for:
///
/// * [`TBREPLACEBITMAP`](crate::TBREPLACEBITMAP).
pub enum BmpInstId {
	/// Bitmap handle.
	Bmp(HBITMAP),
	/// Module handle and resource ID.
	InstId(HINSTANCE, u16),
}

/// Variant parameter for:
///
/// * [`HIMAGELIST::DrawEx`](crate::prelude::comctl_Himagelist::DrawEx).
pub enum ClrDefNone {
	/// A RGB color value.
	Clr(COLORREF),
	/// No color.
	None,
	/// The default color.
	Default,
}

impl ClrDefNone {
	/// Converts the contents into an `u32`.
	#[must_use]
	pub const fn as_u32(&self) -> u32 {
		match self {
			Self::Clr(c) => c.raw(),
			Self::None => CLR_NONE,
			Self::Default => CLR_DEFAULT,
		}
	}
}

/// Variant parameter for:
///
/// * [`TASKDIALOGCONFIG`](crate::TASKDIALOGCONFIG).
pub enum IconId {
	/// No icon.
	None,
	/// An icon handle.
	Icon(HICON),
	/// A resource ID.
	Id(u16),
}

/// Variant parameter for:
///
/// * [`TASKDIALOGCONFIG`](crate::TASKDIALOGCONFIG).
pub enum IconIdTdicon {
	/// No icon.
	None,
	/// An icon handle.
	Icon(HICON),
	/// A resource ID.
	Id(u16),
	/// A predefined icon.
	Tdicon(co::TD_ICON),
}

/// Variant parameter for:
///
/// * [`HWND::TaskDialog`](crate::prelude::comctl_Hwnd::TaskDialog).
#[derive(Clone)]
pub enum IconRes<'a> {
	/// No icon.
	None,
	/// Handle to the instance to load the icon from, and the icon resource
	/// identifier.
	Res(&'a HINSTANCE, IdStr),
	/// The [`co::TD_ICON::WARNING`](crate::co::TD_ICON::WARNING) constant.
	Warn,
	/// The [`co::TD_ICON::ERROR`](crate::co::TD_ICON::ERROR) constant.
	Error,
	/// The [`co::TD_ICON::INFORMATION`](crate::co::TD_ICON::INFORMATION)
	/// constant.
	Info,
	/// The [`co::TD_ICON::SHIELD`](crate::co::TD_ICON::SHIELD) constant.
	Shield,
}

impl<'a> IconRes<'a> {
	/// Returns the `HINSTANCE`, if any, and a pointer to the raw data content.
	#[must_use]
	pub fn as_ptr(&self) -> (HINSTANCE, *const u16) {
		match self {
			Self::None => (HINSTANCE::NULL, std::ptr::null()),
			Self::Res(hinst, id_str) => (unsafe { hinst.raw_copy() }, id_str.as_ptr()),
			Self::Warn => (HINSTANCE::NULL, MAKEINTRESOURCE(co::TD_ICON::WARNING.raw() as _)),
			Self::Error => (HINSTANCE::NULL, MAKEINTRESOURCE(co::TD_ICON::ERROR.raw() as _)),
			Self::Info => (HINSTANCE::NULL, MAKEINTRESOURCE(co::TD_ICON::INFORMATION.raw() as _)),
			Self::Shield => (HINSTANCE::NULL, MAKEINTRESOURCE(co::TD_ICON::SHIELD.raw() as _)),
		}
	}
}

/// Variant type for:
///
/// * [`tbm::ChangeBitmap`](crate::msg::tbm::ChangeBitmap).
#[derive(Clone, Copy)]
pub enum IdxCbNone {
	/// Index of an image in the toolbar's image list.
	Idx(u32),
	/// Toolbar will send `TBN_GETDISPINFO` notifications.
	Cb,
	/// Button doesn't have an image.
	None,
}

impl From<IdxCbNone> for isize {
	fn from(v: IdxCbNone) -> Self {
		match v {
			IdxCbNone::Idx(idx) => idx as _,
			IdxCbNone::Cb => I_IMAGECALLBACK,
			IdxCbNone::None => I_IMAGENONE,
		}
	}
}

/// Variant parameter for:
///
/// * [`TBBUTTON`](crate::TBBUTTON).
#[derive(Clone)]
pub enum IdxStr {
	/// Index of button string.
	Idx(u16),
	/// A string buffer.
	Str(WString),
}

/// Variant parameter for:
///
/// * [`hdm::SetHotDivider`](crate::msg::hdm::SetHotDivider).
pub enum PtIdx {
	/// X and Y coordinates of the pointer
	Pt(POINT),
	/// Index of the divider.
	Idx(u32),
}

/// Variant parameter for:
///
/// * [`tbm::AddString`](crate::msg::tbm::AddString).
pub enum ResStrs {
	/// A resource string resource.
	Res(IdStr, HINSTANCE),
	/// A multi-string composed of null-separated strings. To use this field,
	/// prefer the [`ResStrs::from_strs`](crate::ResStrs::from_strs) static
	/// method.
	Strs(WString),
}

impl ResStrs {
	/// Constructs the enum from a list of strings.
	#[must_use]
	pub fn from_strs(texts: &[impl AsRef<str>]) -> ResStrs {
		Self::Strs(WString::from_str_vec(texts))
	}
}

/// Variant parameter for:
///
/// * [`TVINSERTSTRUCT`](crate::TVINSERTSTRUCT).
pub enum TreeitemTvi {
	/// Handle to a tree view item.
	Treeitem(HTREEITEM),
	/// One of the predefined values.
	Tvi(co::TVI),
}

impl From<TreeitemTvi> for isize {
	fn from(v: TreeitemTvi) -> Self {
		match v {
			TreeitemTvi::Treeitem(htreeitem) => htreeitem.ptr() as _,
			TreeitemTvi::Tvi(tvi) => tvi.raw(),
		}
	}
}

impl TreeitemTvi {
	/// Constructs the enum from an `isize`.
	#[must_use]
	pub fn from_isize(val: isize) -> TreeitemTvi {
		match unsafe { co::TVI::from_raw(val) } {
			co::TVI::FIRST => Self::Tvi(co::TVI::FIRST),
			co::TVI::LAST => Self::Tvi(co::TVI::LAST),
			co::TVI::ROOT => Self::Tvi(co::TVI::ROOT),
			co::TVI::SORT => Self::Tvi(co::TVI::SORT),
			val => Self::Treeitem(unsafe { HTREEITEM::from_ptr(val.raw() as _) }),
		}
	}
}