winsafe\uxtheme\handles/
htheme.rs

1#![allow(non_camel_case_types, non_snake_case)]
2
3use crate::co;
4use crate::decl::*;
5use crate::guard::*;
6use crate::kernel::privs::*;
7use crate::ole::privs::*;
8use crate::prelude::*;
9use crate::uxtheme::ffi;
10
11handle! { HTHEME;
12	/// Handle to a
13	/// [theme](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/).
14}
15
16impl HTHEME {
17	/// [`DrawThemeBackground`](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/nf-uxtheme-drawthemebackground)
18	/// function.
19	pub fn DrawThemeBackground(
20		&self,
21		hdc: &HDC,
22		part_state: co::VS,
23		rc: RECT,
24		rc_clip: Option<RECT>,
25	) -> HrResult<()> {
26		ok_to_hrresult(unsafe {
27			ffi::DrawThemeBackground(
28				self.ptr(),
29				hdc.ptr(),
30				part_state.part,
31				part_state.state,
32				pcvoid(&rc),
33				pcvoid_or_null(rc_clip.as_ref()),
34			)
35		})
36	}
37
38	/// [`GetThemeAppProperties`](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/nf-uxtheme-getthemeappproperties)
39	/// function.
40	#[must_use]
41	pub fn GetThemeAppProperties() -> co::STAP {
42		unsafe { co::STAP::from_raw(ffi::GetThemeAppProperties()) }
43	}
44
45	/// [`GetThemeBackgroundContentRect`](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/nf-uxtheme-getthemebackgroundcontentrect)
46	/// function.
47	#[must_use]
48	pub fn GetThemeBackgroundContentRect(
49		&self,
50		hdc: &HDC,
51		part_state: co::VS,
52		bounds: RECT,
53	) -> HrResult<RECT> {
54		let mut rc_content = RECT::default();
55		ok_to_hrresult(unsafe {
56			ffi::GetThemeBackgroundContentRect(
57				self.ptr(),
58				hdc.ptr(),
59				part_state.part,
60				part_state.state,
61				pcvoid(&bounds),
62				pvoid(&mut rc_content),
63			)
64		})
65		.map(|_| rc_content)
66	}
67
68	/// [`GetThemeBackgroundExtent`](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/nf-uxtheme-getthemebackgroundextent)
69	/// function.
70	#[must_use]
71	pub fn GetThemeBackgroundExtent(
72		&self,
73		hdc: &HDC,
74		part_state: co::VS,
75		rc_content: RECT,
76	) -> HrResult<RECT> {
77		let mut rc_extent = RECT::default();
78
79		ok_to_hrresult(unsafe {
80			ffi::GetThemeBackgroundExtent(
81				self.ptr(),
82				hdc.ptr(),
83				part_state.part,
84				part_state.state,
85				pcvoid(&rc_content),
86				pvoid(&mut rc_extent),
87			)
88		})
89		.map(|_| rc_extent)
90	}
91
92	/// [`GetThemeBackgroundRegion`](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/nf-uxtheme-getthemebackgroundregion)
93	/// function.
94	#[must_use]
95	pub fn GetThemeBackgroundRegion(
96		&self,
97		hdc: &HDC,
98		part_state: co::VS,
99		rc: RECT,
100	) -> HrResult<DeleteObjectGuard<HRGN>> {
101		let mut hrgn = HRGN::NULL;
102		unsafe {
103			ok_to_hrresult(ffi::GetThemeBackgroundRegion(
104				self.ptr(),
105				hdc.ptr(),
106				part_state.part,
107				part_state.state,
108				pcvoid(&rc),
109				hrgn.as_mut(),
110			))
111			.map(|_| DeleteObjectGuard::new(hrgn))
112		}
113	}
114
115	/// [`GetThemeColor`](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/nf-uxtheme-getthemecolor)
116	/// function.
117	#[must_use]
118	pub fn GetThemeColor(&self, part_state: co::VS, prop: co::TMT) -> HrResult<COLORREF> {
119		let mut color = COLORREF::default();
120		ok_to_hrresult(unsafe {
121			ffi::GetThemeColor(
122				self.ptr(),
123				part_state.part,
124				part_state.state,
125				prop.raw(),
126				color.as_mut(),
127			)
128		})
129		.map(|_| color)
130	}
131
132	/// [`GetThemeMargins`](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/nf-uxtheme-getthememargins)
133	/// function.
134	#[must_use]
135	pub fn GetThemeMargins(
136		&self,
137		hdc_fonts: Option<&HDC>,
138		part_state: co::VS,
139		prop: co::TMT,
140		draw_dest: Option<&RECT>,
141	) -> HrResult<MARGINS> {
142		let mut margins = MARGINS::default();
143		ok_to_hrresult(unsafe {
144			ffi::GetThemeMargins(
145				self.ptr(),
146				hdc_fonts.map_or(std::ptr::null_mut(), |h| h.ptr()),
147				part_state.part(),
148				part_state.state(),
149				prop.raw(),
150				pcvoid_or_null(draw_dest),
151				pvoid(&mut margins),
152			)
153		})
154		.map(|_| margins)
155	}
156
157	/// [`GetThemeMetric`](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/nf-uxtheme-getthememetric)
158	/// function.
159	#[must_use]
160	pub fn GetThemeMetric(
161		&self,
162		hdc_fonts: Option<&HDC>,
163		part_state: co::VS,
164		prop: co::TMT,
165	) -> HrResult<i32> {
166		let mut val = 0i32;
167		ok_to_hrresult(unsafe {
168			ffi::GetThemeMetric(
169				self.ptr(),
170				hdc_fonts.map_or(std::ptr::null_mut(), |h| h.ptr()),
171				part_state.part(),
172				part_state.state(),
173				prop.raw(),
174				&mut val,
175			)
176		})
177		.map(|_| val)
178	}
179
180	/// [`GetThemePartSize`](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/nf-uxtheme-getthemepartsize)
181	/// function.
182	#[must_use]
183	pub fn GetThemePartSize(
184		&self,
185		hdc_fonts: Option<&HDC>,
186		part_state: co::VS,
187		draw_dest: Option<&RECT>,
188		esize: co::THEMESIZE,
189	) -> HrResult<SIZE> {
190		let mut sz = SIZE::default();
191		ok_to_hrresult(unsafe {
192			ffi::GetThemePartSize(
193				self.ptr(),
194				hdc_fonts.map_or(std::ptr::null_mut(), |h| h.ptr()),
195				part_state.part(),
196				part_state.state(),
197				pcvoid_or_null(draw_dest),
198				esize.raw(),
199				pvoid(&mut sz),
200			)
201		})
202		.map(|_| sz)
203	}
204
205	/// [`GetThemePosition`](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/nf-uxtheme-getthemeposition)
206	/// function.
207	#[must_use]
208	pub fn GetThemePosition(&self, part_state: co::VS, prop: co::TMT) -> HrResult<POINT> {
209		let mut pt = POINT::default();
210		ok_to_hrresult(unsafe {
211			ffi::GetThemePosition(
212				self.ptr(),
213				part_state.part(),
214				part_state.state(),
215				prop.raw(),
216				pvoid(&mut pt),
217			)
218		})
219		.map(|_| pt)
220	}
221
222	/// [`GetThemePropertyOrigin`](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/nf-uxtheme-getthemepropertyorigin)
223	/// function.
224	#[must_use]
225	pub fn GetThemePropertyOrigin(
226		&self,
227		part_state: co::VS,
228		prop: co::TMT,
229	) -> HrResult<co::PROPERTYORIGIN> {
230		let mut origin = co::PROPERTYORIGIN::default();
231		ok_to_hrresult(unsafe {
232			ffi::GetThemePropertyOrigin(
233				self.ptr(),
234				part_state.part(),
235				part_state.state(),
236				prop.raw(),
237				origin.as_mut(),
238			)
239		})
240		.map(|_| origin)
241	}
242
243	/// [`GetThemeRect`](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/nf-uxtheme-getthemerect)
244	/// function.
245	#[must_use]
246	pub fn GetThemeRect(&self, part_state: co::VS, prop: co::TMT) -> HrResult<RECT> {
247		let mut rc = RECT::default();
248		ok_to_hrresult(unsafe {
249			ffi::GetThemeRect(
250				self.ptr(),
251				part_state.part(),
252				part_state.state(),
253				prop.raw(),
254				pvoid(&mut rc),
255			)
256		})
257		.map(|_| rc)
258	}
259
260	/// [`IsThemeBackgroundPartiallyTransparent`](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/nf-uxtheme-isthemebackgroundpartiallytransparent)
261	/// function.
262	#[must_use]
263	pub fn IsThemeBackgroundPartiallyTransparent(&self, part_state: co::VS) -> bool {
264		unsafe {
265			ffi::IsThemeBackgroundPartiallyTransparent(
266				self.ptr(),
267				part_state.part,
268				part_state.state,
269			) != 0
270		}
271	}
272
273	/// [`IsThemePartDefined`](https://learn.microsoft.com/en-us/windows/win32/api/uxtheme/nf-uxtheme-isthemepartdefined)
274	/// function.
275	#[must_use]
276	pub fn IsThemePartDefined(&self, part_state: co::VS) -> bool {
277		unsafe { ffi::IsThemePartDefined(self.ptr(), part_state.part, part_state.state) != 0 }
278	}
279}