winsafe\shell/
structs.rs

1#![allow(non_camel_case_types, non_snake_case)]
2
3use std::marker::PhantomData;
4
5use crate::co;
6use crate::decl::*;
7use crate::kernel::{ffi_types::*, privs::*};
8
9/// [`COMDLG_FILTERSPEC`](https://learn.microsoft.com/en-us/windows/win32/api/shtypes/ns-shtypes-comdlg_filterspec)
10/// struct.
11#[repr(C)]
12pub struct COMDLG_FILTERSPEC<'a, 'b> {
13	pszName: *mut u16,
14	pszSpec: *mut u16,
15
16	_pszName: PhantomData<&'a mut u16>,
17	_pszSpec: PhantomData<&'b mut u16>,
18}
19
20impl_default!(COMDLG_FILTERSPEC, 'a, 'b);
21
22impl<'a, 'b> COMDLG_FILTERSPEC<'a, 'b> {
23	pub_fn_string_ptr_get_set!('a, pszName, set_pszName);
24	pub_fn_string_ptr_get_set!('b, pszSpec, set_pszSpec);
25}
26
27/// [`ITEMIDLIST`](https://learn.microsoft.com/en-us/windows/win32/api/shtypes/ns-shtypes-itemidlist)
28/// struct.
29#[repr(C)]
30pub struct ITEMIDLIST {
31	pub mkid: SHITEMID,
32}
33
34/// [`NOTIFYICONDATA`](https://learn.microsoft.com/en-us/windows/win32/api/shellapi/ns-shellapi-notifyicondataw)
35/// struct.
36#[repr(C)]
37pub struct NOTIFYICONDATA {
38	cbSize: u32,
39	pub hWnd: HWND,
40	pub uID: u32,
41	pub uFlags: co::NIF,
42	pub uCallbackMessage: co::WM,
43	pub hIcon: HICON,
44	szTip: [u16; 128],
45	pub dwState: co::NIS,
46	pub dwStateMask: co::NIS,
47	szInfo: [u16; 256],
48	pub uVersion: u32, // union with uTimeout, which is deprecated
49	szInfoTitle: [u16; 64],
50	pub dwInfoFlags: co::NIIF,
51	pub guidItem: GUID,
52	pub hBalloonIcon: HICON,
53}
54
55impl_default!(NOTIFYICONDATA, cbSize);
56
57impl NOTIFYICONDATA {
58	pub_fn_string_arr_get_set!(szTip, set_szTip);
59	pub_fn_string_arr_get_set!(szInfo, set_szInfo);
60	pub_fn_string_arr_get_set!(szInfoTitle, set_szInfoTitle);
61}
62
63/// [`PIDL`](https://learn.microsoft.com/en-us/windows/win32/api/shtypes/ns-shtypes-itemidlist)
64/// struct.
65///
66/// # Examples
67///
68/// Retrieving the `PIDL` from an [`IShellItem`](crate::IShellItem) with
69/// [`SHGetIDListFromObject`](crate::SHGetIDListFromObject):
70///
71/// ```no_run
72/// use winsafe::{self as w, prelude::*, co};
73///
74/// let _com_guard = w::CoInitializeEx(
75///     co::COINIT::APARTMENTTHREADED | co::COINIT::DISABLE_OLE1DDE)?;
76///
77/// let f = w::SHCreateItemFromParsingName::<w::IShellItem>(
78///     "C:\\Temp",
79///     None::<&w::IBindCtx>,
80/// )?;
81///
82/// let pidl = w::SHGetIDListFromObject(&f)?;
83/// # w::HrResult::Ok(())
84/// ```
85#[repr(transparent)]
86pub struct PIDL(*mut ITEMIDLIST);
87
88impl PIDL {
89	/// Constructs a new `PIDL` object by wrapping a pointer.
90	///
91	/// This method can be used as an escape hatch to interoperate with other
92	/// libraries.
93	///
94	/// # Safety
95	///
96	/// Be sure the pointer has the correct type and isn’t owned by anyone else,
97	/// otherwise you may cause memory access violations.
98	#[must_use]
99	pub const unsafe fn from_ptr(p: *mut ITEMIDLIST) -> Self {
100		Self(p)
101	}
102
103	/// Returns the underlying [`ITEMIDLIST`](crate::ITEMIDLIST) pointer value.
104	#[must_use]
105	pub const fn ptr(&self) -> *mut ITEMIDLIST {
106		self.0
107	}
108}
109
110/// [`SHFILEINFO`](https://learn.microsoft.com/en-us/windows/win32/api/shellapi/ns-shellapi-shfileinfow)
111/// struct.
112#[repr(C)]
113pub struct SHFILEINFO {
114	pub hIcon: HICON,
115	pub iIcon: i32,
116	dwAttributes: u32,
117	szDisplayName: [u16; MAX_PATH],
118	szTypeName: [u16; 80],
119}
120
121impl_default!(SHFILEINFO);
122
123impl SHFILEINFO {
124	pub_fn_string_arr_get_set!(szDisplayName, set_szDisplayName);
125	pub_fn_string_arr_get_set!(szTypeName, set_szTypeName);
126}
127
128/// [`SHFILEOPSTRUCT`](https://learn.microsoft.com/en-us/windows/win32/api/shellapi/ns-shellapi-shfileopstructw)
129/// struct.
130#[repr(C)]
131pub struct SHFILEOPSTRUCT<'a, 'b, 'c> {
132	pub hwnd: HWND,
133	pub wFunc: co::FO,
134	pFrom: *mut u16, // double-null terminated
135	pTo: *mut u16,   // double-null terminated
136	pub fFlags: co::FOF,
137	fAnyOperationsAborted: BOOL,
138	hNameMappings: *mut std::ffi::c_void, // lots of stuff going here...
139	lpszProgressTitle: *mut u16,
140
141	_pFrom: PhantomData<&'a mut u16>,
142	_pTo: PhantomData<&'b mut u16>,
143	_lpszProgressTitle: PhantomData<&'c mut u16>,
144}
145
146impl_default!(SHFILEOPSTRUCT, 'a, 'b, 'c);
147
148impl<'a, 'b, 'c> SHFILEOPSTRUCT<'a, 'b, 'c> {
149	pub_fn_bool_get_set!(fAnyOperationsAborted, set_fAnyOperationsAborted);
150
151	/// Retrieves the `pFrom` field.
152	#[must_use]
153	pub fn pFrom(&self) -> Option<Vec<String>> {
154		unsafe { self.pFrom.as_mut().map(|p| parse_multi_z_str(p, None)) }
155	}
156
157	/// Sets the `pFrom` field.
158	///
159	/// **Note:** You must create the string with
160	/// [`WString::from_str_vec`](crate::WString::from_str_vec).
161	pub fn set_pFrom(&mut self, val: Option<&'a mut WString>) {
162		self.pFrom = val.map_or(std::ptr::null_mut(), |v| unsafe { v.as_mut_ptr() });
163	}
164
165	/// Retrieves the `pTo` field.
166	#[must_use]
167	pub fn pTo(&self) -> Option<Vec<String>> {
168		unsafe { self.pTo.as_mut().map(|p| parse_multi_z_str(p, None)) }
169	}
170
171	/// Sets the `pTo` field.
172	///
173	/// **Note:** You must create the string with
174	/// [`WString::from_str_vec`](crate::WString::from_str_vec).
175	pub fn set_pTo(&mut self, val: Option<&'b mut WString>) {
176		self.pTo = val.map_or(std::ptr::null_mut(), |v| unsafe { v.as_mut_ptr() });
177	}
178
179	pub_fn_string_ptr_get_set!('c, lpszProgressTitle, set_lpszProgressTitle);
180}
181
182/// [`SHITEMID`](https://learn.microsoft.com/en-us/windows/win32/api/shtypes/ns-shtypes-shitemid)
183/// struct.
184#[repr(C, packed)]
185pub struct SHITEMID {
186	cb: u16,
187	abID: [u8; 1],
188}
189
190/// [`SHSTOCKICONINFO`](https://learn.microsoft.com/en-us/windows/win32/api/shellapi/ns-shellapi-shstockiconinfo)
191/// struct.
192#[repr(C)]
193pub struct SHSTOCKICONINFO {
194	cbSize: u32,
195	pub hIcon: HICON,
196	pub iSysImageIndex: i32,
197	pub iIcon: i32,
198	szPath: [u16; MAX_PATH],
199}
200
201impl_default!(SHSTOCKICONINFO, cbSize);
202
203impl SHSTOCKICONINFO {
204	pub_fn_string_arr_get_set!(szPath, get_szPath);
205}