#![allow(unused_macros)]
macro_rules! const_basic_decl {
(
$name:ident : $ntype:ty;
$( #[$doc:meta] )*
) => {
newtype_num! {
$name: $ntype;
$( #[$doc] )*
}
impl std::fmt::LowerHex for $name {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
std::fmt::LowerHex::fmt(&self.0, f)
}
}
impl std::fmt::UpperHex for $name {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
std::fmt::UpperHex::fmt(&self.0, f)
}
}
impl std::fmt::Binary for $name {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
std::fmt::Binary::fmt(&self.0, f)
}
}
impl std::fmt::Octal for $name {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
std::fmt::Octal::fmt(&self.0, f)
}
}
};
}
macro_rules! const_impl_bitflag {
( $name:ident ) => {
impl std::ops::BitAnd for $name {
type Output = $name;
fn bitand(self, rhs: Self) -> Self::Output {
Self(self.0 & rhs.0)
}
}
impl std::ops::BitAndAssign for $name {
fn bitand_assign(&mut self, rhs: Self) {
*self = Self(self.0 & rhs.0);
}
}
impl std::ops::BitOr for $name {
type Output = $name;
fn bitor(self, rhs: Self) -> Self {
Self(self.0 | rhs.0)
}
}
impl std::ops::BitOrAssign for $name {
fn bitor_assign(&mut self, rhs: Self) {
*self = Self(self.0 | rhs.0);
}
}
impl std::ops::BitXor for $name {
type Output = $name;
fn bitxor(self, rhs: Self) -> Self::Output {
Self(self.0 ^ rhs.0)
}
}
impl std::ops::BitXorAssign for $name {
fn bitxor_assign(&mut self, rhs: Self) {
*self = Self(self.0 ^ rhs.0);
}
}
impl std::ops::Not for $name {
type Output = $name;
fn not(self) -> Self::Output {
Self(!self.0)
}
}
impl $name {
pub const fn has(&self, other: Self) -> bool {
(self.0 & other.0) != 0
}
}
};
}
macro_rules! const_impl_debug_display {
( $name:ident ) => {
impl std::fmt::Display for $name {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if self.0 as usize > 0xffff {
write!(f, "{}({:#010x})", stringify!($name), self.0)
} else {
write!(f, "{}({:#06x})", stringify!($name), self.0)
}
}
}
impl std::fmt::Debug for $name {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
if self.0 as usize > 0xffff {
write!(f, "{}({:#010x} {})", stringify!($name), self.0, self.0)
} else {
write!(f, "{}({:#06x} {})", stringify!($name), self.0, self.0)
}
}
}
};
}
macro_rules! const_values_pub {
(
$name:ident;
$(
$( #[$valdoc:meta] )*
$valname:ident $val:expr
)*
) => {
impl $name {
$(
$( #[$valdoc] )*
pub const $valname: Self = unsafe { Self::from_raw($val) };
)*
}
};
}
macro_rules! const_values_num_privs {
(
$( $name:ident $ty:ty = $val:expr )* // for integers
) => {
$( pub(crate) const $name: $ty = $val; )*
};
(
$( $name:ident : $ty:ty = $val:expr )* // for consts
) => {
$( pub(crate) const $name: $ty = unsafe { <$ty>::from_raw($val) }; )*
};
}
macro_rules! const_ordinary {
(
$name:ident : $ntype:ty;
$( #[$doc:meta] )*
=>
$(
$( #[$valdoc:meta] )*
$valname:ident $val:expr
)*
) => {
const_basic_decl! {
$name: $ntype;
$( #[$doc] )*
}
const_impl_debug_display!($name);
const_values_pub! {
$name;
$(
$( #[$valdoc] )*
$valname $val
)*
}
};
}
macro_rules! const_bitflag {
(
$name:ident : $ntype:ty;
$( #[$doc:meta] )*
=>
$(
$( #[$valdoc:meta] )*
$valname:ident $val:expr
)*
) => {
const_basic_decl! {
$name: $ntype;
$( #[$doc] )*
}
const_impl_bitflag!($name);
const_impl_debug_display!($name);
const_values_pub! {
$name;
$(
$( #[$valdoc] )*
$valname $val
)*
}
};
}
macro_rules! const_wm {
(
$name:ident;
$( #[$doc:meta] )*
=>
$(
$( #[$valdoc:meta] )*
$valname:ident $val:expr
)*
) => {
const_basic_decl! {
$name: u32;
$( #[$doc] )*
}
const_impl_bitflag!($name);
const_impl_debug_display!($name);
const_values_pub! {
$name;
$(
$( #[$valdoc] )*
$valname $val
)*
}
impl From<$name> for crate::co::WM {
fn from(v: $name) -> Self {
unsafe { Self::from_raw(v.0) }
}
}
};
}
macro_rules! const_cmd {
(
$name:ident;
$( #[$doc:meta] )*
=>
$(
$( #[$valdoc:meta] )*
$valname:ident $val:expr
)*
) => {
const_basic_decl! {
$name: u16;
$( #[$doc] )*
}
const_impl_bitflag!($name);
const_impl_debug_display!($name);
const_values_pub! {
$name;
$(
$( #[$valdoc] )*
$valname $val
)*
}
impl From<$name> for crate::co::CMD {
fn from(v: $name) -> Self {
Self(v.0)
}
}
};
}
macro_rules! const_nm {
(
$name:ident;
$( #[$doc:meta] )*
=>
$(
$( #[$valdoc:meta] )*
$valname:ident $val:expr
)*
) => {
const_basic_decl! {
$name: i32;
$( #[$doc] )*
}
const_impl_bitflag!($name);
const_impl_debug_display!($name);
const_values_pub! {
$name;
$(
$( #[$valdoc] )*
$valname $val
)*
}
impl From<$name> for crate::NmhdrCode {
fn from(v: $name) -> Self {
Self::from_code(v.raw())
}
}
impl TryFrom<crate::NmhdrCode> for $name {
type Error = crate::co::ERROR;
fn try_from(value: crate::NmhdrCode) -> Result<Self, Self::Error> {
$(
if value.raw() == $val { return Ok(Self::$valname); }
)*
Err(crate::co::ERROR::INVALID_DATA)
}
}
};
}
macro_rules! const_ws {
(
$name:ident : $ntype:ty;
$( #[$doc:meta] )*
=>
$(
$( #[$valdoc:meta] )*
$valname:ident $val:expr
)*
) => {
const_basic_decl! {
$name: $ntype;
$( #[$doc] )*
}
const_impl_bitflag!($name);
const_impl_debug_display!($name);
const_values_pub! {
$name;
$(
$( #[$valdoc] )*
$valname $val
)*
}
impl From<$name> for crate::co::WS {
fn from(v: $name) -> Self {
unsafe { Self::from_raw(v.0 as _) }
}
}
impl From<crate::co::WS> for $name {
fn from(v: crate::co::WS) -> Self {
unsafe { Self::from_raw(v.raw() as _) }
}
}
};
}
macro_rules! const_wsex {
(
$name:ident;
$( #[$doc:meta] )*
=>
$(
$( #[$valdoc:meta] )*
$valname:ident $val:expr
)*
) => {
const_basic_decl! {
$name: u32;
$( #[$doc] )*
}
const_impl_bitflag!($name);
const_impl_debug_display!($name);
const_values_pub! {
$name;
$(
$( #[$valdoc] )*
$valname $val
)*
}
impl From<$name> for crate::co::WS_EX {
fn from(v: $name) -> Self {
unsafe { Self::from_raw(v.0) }
}
}
impl From<crate::co::WS_EX> for $name {
fn from(v: crate::co::WS_EX) -> Self {
unsafe { Self::from_raw(v.raw() as _) }
}
}
};
}
macro_rules! const_str {
(
$name:ident;
$( #[$doc:meta] )*
=>
$(
$( #[$valdoc:meta] )*
$valname:ident $val:literal
)*
) => {
$( #[$doc] )*
#[derive(Clone, Copy, PartialEq, Eq)]
pub struct $name(&'static str);
impl TryFrom<&str> for $name {
type Error = crate::co::ERROR;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
$( $val => Ok(Self::$valname), )*
_ => Err(crate::co::ERROR::INVALID_DATA),
}
}
}
impl From<$name> for crate::WString {
fn from(v: $name) -> Self {
crate::WString::from_str(v.0)
}
}
impl std::fmt::Display for $name {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(self.0, f)
}
}
impl std::fmt::Debug for $name {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "\"{}\" {}", self.0, stringify!($name))
}
}
impl $name {
$(
$( #[$valdoc] )*
pub const $valname: Self = Self($val);
)*
}
};
}