winsafe\kernel/
enums.rs

1use crate::co;
2use crate::decl::*;
3use crate::kernel::privs::*;
4
5/// Variable parameter for:
6///
7/// * [`HINSTANCE::GetModuleHandleEx`](crate::HINSTANCE::GetModuleHandleEx)
8pub enum AddrStr {
9	/// No value, will pass `NULL` to the call.
10	None,
11	/// An address in the module.
12	Addr(*mut std::ffi::c_void),
13	/// Name of the loaded module.
14	Str(WString),
15}
16
17impl AddrStr {
18	/// Constructs the enum directly from a string.
19	#[must_use]
20	pub fn from_str(v: &str) -> Self {
21		Self::Str(WString::from_str(v))
22	}
23}
24
25/// Variable parameter for:
26///
27/// * [`CLAIM_SECURITY_ATTRIBUTE_V1`](crate::CLAIM_SECURITY_ATTRIBUTE_V1)
28pub enum ClaimSecurityAttr<'a> {
29	Int64(&'a [i64]),
30	Uint64(&'a [u64]),
31	String(Vec<String>),
32	Fbqn(&'a [CLAIM_SECURITY_ATTRIBUTE_FQBN_VALUE<'a>]),
33	OctetString(&'a [CLAIM_SECURITY_ATTRIBUTE_OCTET_STRING_VALUE<'a>]),
34}
35
36/// A resource identifier.
37///
38/// Variable parameter for:
39///
40/// * [`HINSTANCE::CreateDialogParam`](crate::HINSTANCE::CreateDialogParam)
41/// * [`HINSTANCE::EnumResourceLanguages`](crate::HINSTANCE::EnumResourceLanguages)
42/// * [`HINSTANCE::EnumResourceNames`](crate::HINSTANCE::EnumResourceNames)
43/// * [`HINSTANCE::FindResource`](crate::HINSTANCE::FindResource)
44/// * [`HINSTANCE::FindResourceEx`](crate::HINSTANCE::FindResourceEx)
45/// * [`HINSTANCE::LoadAccelerators`](crate::HINSTANCE::LoadAccelerators)
46/// * [`HINSTANCE::LoadMenu`](crate::HINSTANCE::LoadMenu)
47/// * [`HUPDATERSRC::UpdateResource`](crate::HUPDATERSRC::UpdateResource)
48/// * [`BmpIdbRes`](crate::BmpIdbRes)
49/// * [`IconRes`](crate::IconRes)
50/// * [`ResStrs`](crate::ResStrs)
51#[derive(Clone)]
52pub enum IdStr {
53	/// A resource ID.
54	Id(u16),
55	/// A resource string identifier.
56	Str(WString),
57}
58
59impl std::fmt::Display for IdStr {
60	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
61		match self {
62			Self::Id(rt) => write!(f, "ID: {}", rt),
63			Self::Str(str) => write!(f, "Str: {}", str),
64		}
65	}
66}
67
68impl IdStr {
69	/// Constructs the enum directly from a string.
70	#[must_use]
71	pub fn from_str(v: &str) -> Self {
72		Self::Str(WString::from_str(v))
73	}
74
75	/// Constructs the enum from a raw pointer.
76	///
77	/// # Safety
78	///
79	/// If string, be sure it is null-terminated, otherwise an invalid memory
80	/// location might be read.
81	#[must_use]
82	pub unsafe fn from_ptr(ptr: *const u16) -> IdStr {
83		if IS_INTRESOURCE(ptr) {
84			Self::Id(ptr as _)
85		} else {
86			Self::Str(unsafe { WString::from_wchars_nullt(ptr) })
87		}
88	}
89
90	/// Returns a pointer to the raw data content, or null if no content.
91	#[must_use]
92	pub fn as_ptr(&self) -> *const u16 {
93		match self {
94			Self::Id(id) => MAKEINTRESOURCE(*id as _),
95			Self::Str(ws) => ws.as_ptr(),
96		}
97	}
98}
99
100/// Variant parameter for:
101///
102/// * [`POWERBROADCAST_SETTING`](crate::POWERBROADCAST_SETTING)
103pub enum PowerSetting {
104	AcDcPowerSource(co::SYSTEM_POWER_CONDITION),
105	BatteryPercentageRemaining(u8),
106	ConsoleDisplayState(co::MONITOR_DISPLAY_STATE),
107	GlobalUserPresence(co::USER_ACTIVITY_PRESENCE),
108	IdleBackgroundTask,
109	MonitorPowerOn(bool),
110	PowerSavingStatus(bool),
111	PowerSchemePersonality(co::POWER_SAVINGS),
112	SessionDisplayStatus(co::MONITOR_DISPLAY_STATE),
113	SessionUserPresence(co::USER_ACTIVITY_PRESENCE),
114	LidSwitchStateChange(PowerSettingLid),
115	SystemAwayMode(PowerSettingAwayMode),
116}
117
118/// Variant parameter for:
119///
120/// * [`PowerSetting::SystemAwayMode`](crate::PowerSetting::SystemAwayMode)
121#[derive(Clone, Copy, PartialEq, Eq)]
122pub enum PowerSettingAwayMode {
123	Exiting,
124	Entering,
125}
126
127/// Variant parameter for:
128///
129/// * [`PowerSetting::LidSwitchStateChange`](crate::PowerSetting::LidSwitchStateChange)
130#[derive(Clone, Copy, PartialEq, Eq)]
131pub enum PowerSettingLid {
132	Closed,
133	Opened,
134}
135
136/// A predefined resource identifier.
137///
138/// Variant parameter for:
139///
140/// * [`HINSTANCE::EnumResourceLanguages`](crate::HINSTANCE::EnumResourceLanguages)
141/// * [`HINSTANCE::EnumResourceNames`](crate::HINSTANCE::EnumResourceNames)
142/// * [`HINSTANCE::EnumResourceTypes`](crate::HINSTANCE::EnumResourceTypes)
143/// * [`HINSTANCE::FindResource`](crate::HINSTANCE::FindResource)
144/// * [`HINSTANCE::FindResourceEx`](crate::HINSTANCE::FindResourceEx)
145/// * [`HUPDATERSRC`](crate::HUPDATERSRC::UpdateResource)
146#[derive(Clone)]
147pub enum RtStr {
148	/// A predefined resource ID.
149	Rt(co::RT),
150	/// A resource string identifier.
151	Str(WString),
152}
153
154impl std::fmt::Display for RtStr {
155	fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
156		match self {
157			Self::Rt(rt) => write!(f, "RT: {}", rt),
158			Self::Str(str) => write!(f, "Str: {}", str),
159		}
160	}
161}
162
163impl RtStr {
164	/// Constructs the enum directly from a string.
165	#[must_use]
166	pub fn from_str(v: &str) -> Self {
167		Self::Str(WString::from_str(v))
168	}
169
170	/// Constructs the enum from a pointer to raw data.
171	///
172	/// # Safety
173	///
174	/// If string, be sure it is null-terminated, otherwise an invalid memory
175	/// location might be read.
176	#[must_use]
177	pub unsafe fn from_ptr(ptr: *const u16) -> RtStr {
178		if IS_INTRESOURCE(ptr) {
179			Self::Rt(unsafe { co::RT::from_raw(ptr as _) })
180		} else {
181			Self::Str(unsafe { WString::from_wchars_nullt(ptr) })
182		}
183	}
184
185	/// Returns a pointer to the raw data content, or null if no content.
186	#[must_use]
187	pub fn as_ptr(&self) -> *const u16 {
188		match self {
189			Self::Rt(id) => MAKEINTRESOURCE(id.raw() as _),
190			Self::Str(ws) => ws.as_ptr(),
191		}
192	}
193}