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
#![allow(unused_macros)]
/// Declares a native control, optionally with a single generic parameter.
macro_rules! native_ctrl {
(
$name:ident : $innerobj:ty $( , $genp:tt )? $( => $events:ident )?;
$( #[$doc:meta] )*
) => {
$( #[$doc] )*
pub struct $name<$( $genp: 'static = () )?>(Pin<Arc<$innerobj>>);
unsafe impl<$( $genp )?> Send for $name<$( $genp )?> {}
// A simple #[derive(Clone)] works for non-generic controls, but for
// generic ones, we need manual implementation.
// https://stackoverflow.com/q/39415052/6923555
impl<$( $genp )?> Clone for $name<$( $genp )?> {
fn clone(&self) -> Self {
Self(self.0.clone())
}
}
impl<$( $genp )?> crate::prelude::GuiWindow for $name<$( $genp )?> {
fn hwnd(&self) -> &crate::HWND {
self.0.base.hwnd()
}
fn as_any(&self) -> &dyn Any {
self
}
}
impl<$( $genp )?> crate::prelude::GuiControl for $name<$( $genp )?> {
fn ctrl_id(&self) -> u16 {
self.0.base.ctrl_id()
}
}
impl<$( $genp )?> $name<$( $genp )?> {
/// Exposes the subclass events. If at least one event exists, the control
/// will be
/// [subclassed](https://learn.microsoft.com/en-us/windows/win32/controls/subclassing-overview).
///
/// **Note:** Subclassing may impact performance, use with care.
///
/// # Panics
///
/// Panics if the control or the parent window are already created. Events
/// must be set before control and parent window creation.
#[must_use]
pub fn on_subclass(&self) -> &impl crate::prelude::GuiEventsWindow {
self.0.base.on_subclass()
}
$(
/// Exposes the specific control events.
///
/// # Panics
///
/// Panics if the control is already created. Events must be set before
/// control creation.
#[must_use]
pub fn on(&self) -> &impl $events {
if *self.hwnd() != crate::HWND::NULL {
panic!("Cannot add events after control creation.");
}
&self.0.events
}
)?
}
};
}