wxrust_base/generated/
class_t.rs

1use super::*;
2
3// wxTimer
4wxwidgets! {
5    /// The wxTimer class allows you to execute code at specified intervals.
6    /// - [`Timer`] represents a C++ `wxTimer` class instance which your code has ownership, [`TimerIsOwned`]`<false>` represents one which don't own.
7    /// - Use [`Timer`]'s `new()` to create an instance of this class.
8    /// - See [C++ `wxTimer` class's documentation](https://docs.wxwidgets.org/3.2/classwx_timer.html) for more details.
9    #[doc(alias = "wxTimer")]
10    #[doc(alias = "Timer")]
11    class Timer
12        = TimerIsOwned<true>(wxTimer) impl
13        TimerMethods,
14        EvtHandlerMethods,
15        ObjectMethods
16}
17impl<const OWNED: bool> TimerIsOwned<OWNED> {
18    /// Default constructor.
19    ///
20    /// See [C++ `wxTimer::wxTimer()`'s documentation](https://docs.wxwidgets.org/3.2/classwx_timer.html#a0560894a1ab57792f52992ffbc58e735).
21    pub fn new() -> TimerIsOwned<OWNED> {
22        unsafe { TimerIsOwned(ffi::wxTimer_new()) }
23    }
24    /// Creates a timer and associates it with owner.
25    ///
26    /// See [C++ `wxTimer::wxTimer()`'s documentation](https://docs.wxwidgets.org/3.2/classwx_timer.html#aeba595e67731d9f8ce07e4ac69a0ca65).
27    pub fn new_with_evthandler<E: EvtHandlerMethods>(
28        owner: Option<&E>,
29        id: c_int,
30    ) -> TimerIsOwned<OWNED> {
31        unsafe {
32            let owner = match owner {
33                Some(r) => r.as_ptr(),
34                None => ptr::null_mut(),
35            };
36            TimerIsOwned(ffi::wxTimer_new1(owner, id))
37        }
38    }
39    pub fn none() -> Option<&'static Self> {
40        None
41    }
42}
43impl<const OWNED: bool> Clone for TimerIsOwned<OWNED> {
44    fn clone(&self) -> Self {
45        Self(self.0)
46    }
47}
48impl<const OWNED: bool> From<TimerIsOwned<OWNED>> for EvtHandlerIsOwned<OWNED> {
49    fn from(o: TimerIsOwned<OWNED>) -> Self {
50        unsafe { Self::from_ptr(o.as_ptr()) }
51    }
52}
53impl<const OWNED: bool> From<TimerIsOwned<OWNED>> for ObjectIsOwned<OWNED> {
54    fn from(o: TimerIsOwned<OWNED>) -> Self {
55        unsafe { Self::from_ptr(o.as_ptr()) }
56    }
57}
58impl<const OWNED: bool> DynamicCast for TimerIsOwned<OWNED> {
59    fn class_info() -> ClassInfoIsOwned<false> {
60        unsafe { ClassInfoIsOwned::from_ptr(ffi::wxTimer_CLASSINFO()) }
61    }
62}
63
64// wxTimerEvent
65wxwidgets! {
66    /// wxTimerEvent object is passed to the event handler of timer events (see wxTimer::SetOwner).
67    /// - [`TimerEvent`] represents a C++ `wxTimerEvent` class instance which your code has ownership, [`TimerEventIsOwned`]`<false>` represents one which don't own.
68    /// - Use [`TimerEvent`]'s `new()` to create an instance of this class.
69    /// - See [C++ `wxTimerEvent` class's documentation](https://docs.wxwidgets.org/3.2/classwx_timer_event.html) for more details.
70    #[doc(alias = "wxTimerEvent")]
71    #[doc(alias = "TimerEvent")]
72    class TimerEvent
73        = TimerEventIsOwned<true>(wxTimerEvent) impl
74        TimerEventMethods,
75        EventMethods,
76        ObjectMethods
77}
78impl<const OWNED: bool> TimerEventIsOwned<OWNED> {
79    ///
80    /// See [C++ `wxTimerEvent::wxTimerEvent()`'s documentation](https://docs.wxwidgets.org/3.2/classwx_timer_event.html#aedca4f26719c256c2f8d9ef8486d2f86).
81    pub fn new<T: TimerMethods>(timer: &T) -> TimerEventIsOwned<OWNED> {
82        unsafe {
83            let timer = timer.as_ptr();
84            TimerEventIsOwned(ffi::wxTimerEvent_new(timer))
85        }
86    }
87    pub fn none() -> Option<&'static Self> {
88        None
89    }
90}
91impl Clone for TimerEventIsOwned<false> {
92    fn clone(&self) -> Self {
93        Self(self.0)
94    }
95}
96impl<const OWNED: bool> From<TimerEventIsOwned<OWNED>> for EventIsOwned<OWNED> {
97    fn from(o: TimerEventIsOwned<OWNED>) -> Self {
98        unsafe { Self::from_ptr(o.as_ptr()) }
99    }
100}
101impl<const OWNED: bool> From<TimerEventIsOwned<OWNED>> for ObjectIsOwned<OWNED> {
102    fn from(o: TimerEventIsOwned<OWNED>) -> Self {
103        unsafe { Self::from_ptr(o.as_ptr()) }
104    }
105}
106impl<const OWNED: bool> DynamicCast for TimerEventIsOwned<OWNED> {
107    fn class_info() -> ClassInfoIsOwned<false> {
108        unsafe { ClassInfoIsOwned::from_ptr(ffi::wxTimerEvent_CLASSINFO()) }
109    }
110}
111impl<const OWNED: bool> Drop for TimerEventIsOwned<OWNED> {
112    fn drop(&mut self) {
113        if OWNED {
114            unsafe { ffi::wxObject_delete(self.0) }
115        }
116    }
117}