pub mod checkbox;
pub mod combobox;
pub mod commandbutton;
pub mod custom;
pub mod data;
pub mod dirlistbox;
pub mod drivelistbox;
pub mod filelistbox;
pub mod form;
pub mod form_root;
pub mod frame;
pub mod image;
pub mod label;
pub mod line;
pub mod listbox;
pub mod mdiform;
pub mod menus;
pub mod ole;
pub mod optionbutton;
pub mod picturebox;
pub mod scrollbars;
pub mod shape;
pub mod textbox;
pub mod timer;
use std::convert::{From, TryFrom};
use std::fmt::{Display, Formatter};
use std::str::FromStr;
use num_enum::TryFromPrimitive;
use serde::Serialize;
use crate::errors::{FormError, ErrorKind};
use crate::language::PropertyGroup;
use crate::language::controls::{
checkbox::CheckBoxProperties,
combobox::ComboBoxProperties,
commandbutton::CommandButtonProperties,
custom::CustomControlProperties,
data::DataProperties,
dirlistbox::DirListBoxProperties,
drivelistbox::DriveListBoxProperties,
filelistbox::FileListBoxProperties,
frame::FrameProperties,
image::ImageProperties,
label::LabelProperties,
line::LineProperties,
listbox::ListBoxProperties,
menus::{MenuControl, MenuProperties},
ole::OLEProperties,
optionbutton::OptionButtonProperties,
picturebox::PictureBoxProperties,
scrollbars::ScrollBarProperties,
shape::ShapeProperties,
textbox::TextBoxProperties,
timer::TimerProperties,
};
pub use form_root::{Form, FormRoot, MDIForm};
#[derive(
Debug, PartialEq, Eq, Clone, Serialize, Default, TryFromPrimitive, Copy, Hash, PartialOrd, Ord,
)]
#[repr(i32)]
pub enum AutoRedraw {
#[default]
Manual = 0,
Automatic = -1,
}
impl TryFrom<&str> for AutoRedraw {
type Error = ErrorKind;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"0" => Ok(AutoRedraw::Manual),
"-1" => Ok(AutoRedraw::Automatic),
_ => Err(ErrorKind::Form(FormError::InvalidAutoRedraw {
value: value.to_string(),
})),
}
}
}
impl FromStr for AutoRedraw {
type Err = ErrorKind;
fn from_str(s: &str) -> Result<Self, Self::Err> {
AutoRedraw::try_from(s)
}
}
impl From<bool> for AutoRedraw {
fn from(value: bool) -> Self {
if value {
AutoRedraw::Automatic
} else {
AutoRedraw::Manual
}
}
}
impl Display for AutoRedraw {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let text = match self {
AutoRedraw::Manual => "Manual",
AutoRedraw::Automatic => "Automatic",
};
write!(f, "{text}")
}
}
#[derive(
Debug, PartialEq, Eq, Clone, Serialize, Default, TryFromPrimitive, Copy, Hash, PartialOrd, Ord,
)]
#[repr(i32)]
pub enum TextDirection {
#[default]
LeftToRight = 0,
RightToLeft = -1,
}
impl TryFrom<&str> for TextDirection {
type Error = ErrorKind;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"0" => Ok(TextDirection::LeftToRight),
"-1" => Ok(TextDirection::RightToLeft),
_ => Err(ErrorKind::Form(FormError::InvalidTextDirection {
value: value.to_string(),
})),
}
}
}
impl FromStr for TextDirection {
type Err = ErrorKind;
fn from_str(s: &str) -> Result<Self, ErrorKind> {
TextDirection::try_from(s)
}
}
impl From<bool> for TextDirection {
fn from(value: bool) -> Self {
if value {
TextDirection::RightToLeft
} else {
TextDirection::LeftToRight
}
}
}
impl Display for TextDirection {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let text = match self {
TextDirection::LeftToRight => "Left to Right",
TextDirection::RightToLeft => "Right to Left",
};
write!(f, "{text}")
}
}
#[derive(
Debug,
PartialEq,
Eq,
Clone,
serde::Serialize,
Default,
TryFromPrimitive,
Copy,
Hash,
PartialOrd,
Ord,
)]
#[repr(i32)]
pub enum AutoSize {
#[default]
Fixed = 0,
Resize = -1,
}
impl TryFrom<&str> for AutoSize {
type Error = ErrorKind;
fn try_from(value: &str) -> Result<Self, ErrorKind> {
match value {
"0" => Ok(AutoSize::Fixed),
"-1" => Ok(AutoSize::Resize),
_ => Err(ErrorKind::Form(FormError::InvalidAutoSize {
value: value.to_string(),
})),
}
}
}
impl From<bool> for AutoSize {
fn from(value: bool) -> Self {
if value {
AutoSize::Resize
} else {
AutoSize::Fixed
}
}
}
impl FromStr for AutoSize {
type Err = ErrorKind;
fn from_str(s: &str) -> Result<Self, ErrorKind> {
AutoSize::try_from(s)
}
}
impl Display for AutoSize {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let text = match self {
AutoSize::Fixed => "Fixed",
AutoSize::Resize => "Resize",
};
write!(f, "{text}")
}
}
#[derive(
Debug,
PartialEq,
Eq,
Clone,
serde::Serialize,
Default,
TryFromPrimitive,
Copy,
Hash,
PartialOrd,
Ord,
)]
#[repr(i32)]
pub enum Activation {
Disabled = 0,
#[default]
Enabled = -1,
}
impl From<bool> for Activation {
fn from(value: bool) -> Self {
if value {
Activation::Enabled
} else {
Activation::Disabled
}
}
}
impl TryFrom<&str> for Activation {
type Error = ErrorKind;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"0" => Ok(Activation::Disabled),
"-1" => Ok(Activation::Enabled),
_ => Err(ErrorKind::Form(FormError::InvalidActivation {
value: value.to_string(),
})),
}
}
}
impl Display for Activation {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let text = match self {
Activation::Disabled => "Disabled",
Activation::Enabled => "Enabled",
};
write!(f, "{text}")
}
}
#[derive(
Debug,
PartialEq,
Eq,
Clone,
serde::Serialize,
Default,
TryFromPrimitive,
Copy,
Hash,
PartialOrd,
Ord,
)]
#[repr(i32)]
pub enum TabStop {
ProgrammaticOnly = 0,
#[default]
Included = -1,
}
impl From<bool> for TabStop {
fn from(value: bool) -> Self {
if value {
TabStop::Included
} else {
TabStop::ProgrammaticOnly
}
}
}
impl TryFrom<&str> for TabStop {
type Error = ErrorKind;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"0" => Ok(TabStop::ProgrammaticOnly),
"-1" => Ok(TabStop::Included),
_ => Err(ErrorKind::Form(FormError::InvalidTabStop {
value: value.to_string(),
})),
}
}
}
impl Display for TabStop {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let text = match self {
TabStop::ProgrammaticOnly => "Programmatic Only",
TabStop::Included => "Included",
};
write!(f, "{text}")
}
}
#[derive(
Debug, PartialEq, Eq, Clone, Serialize, Default, TryFromPrimitive, Copy, Hash, PartialOrd, Ord,
)]
#[repr(i32)]
pub enum Visibility {
Hidden = 0,
#[default]
Visible = -1,
}
impl TryFrom<&str> for Visibility {
type Error = ErrorKind;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"0" => Ok(Visibility::Hidden),
"-1" => Ok(Visibility::Visible),
_ => Err(ErrorKind::Form(FormError::InvalidVisibility {
value: value.to_string(),
})),
}
}
}
impl FromStr for Visibility {
type Err = ErrorKind;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Visibility::try_from(s)
}
}
impl From<bool> for Visibility {
fn from(value: bool) -> Self {
if value {
Visibility::Visible
} else {
Visibility::Hidden
}
}
}
impl Display for Visibility {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let text = match self {
Visibility::Hidden => "Hidden",
Visibility::Visible => "Visible",
};
write!(f, "{text}")
}
}
#[derive(
Debug, PartialEq, Eq, Clone, Serialize, Default, TryFromPrimitive, Copy, Hash, PartialOrd, Ord,
)]
#[repr(i32)]
pub enum HasDeviceContext {
NoContext = 0,
#[default]
HasContext = -1,
}
impl TryFrom<&str> for HasDeviceContext {
type Error = ErrorKind;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"0" => Ok(HasDeviceContext::NoContext),
"-1" => Ok(HasDeviceContext::HasContext),
_ => Err(ErrorKind::Form(FormError::InvalidHasDeviceContext {
value: value.to_string(),
})),
}
}
}
impl FromStr for HasDeviceContext {
type Err = ErrorKind;
fn from_str(s: &str) -> Result<Self, Self::Err> {
HasDeviceContext::try_from(s)
}
}
impl From<bool> for HasDeviceContext {
fn from(value: bool) -> Self {
if value {
HasDeviceContext::HasContext
} else {
HasDeviceContext::NoContext
}
}
}
impl Display for HasDeviceContext {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let text = match self {
HasDeviceContext::NoContext => "No Context",
HasDeviceContext::HasContext => "Has Context",
};
write!(f, "{text}")
}
}
#[derive(
Debug, PartialEq, Eq, Clone, Serialize, Default, TryFromPrimitive, Copy, Hash, PartialOrd, Ord,
)]
#[repr(i32)]
pub enum UseMaskColor {
#[default]
DoNotUseMaskColor = 0,
UseMaskColor = -1,
}
impl Display for UseMaskColor {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let text = match self {
UseMaskColor::DoNotUseMaskColor => "Do not use Mask Color",
UseMaskColor::UseMaskColor => "Use Mask Color",
};
write!(f, "{text}")
}
}
#[derive(
Debug,
PartialEq,
Eq,
Clone,
serde::Serialize,
Default,
TryFromPrimitive,
Copy,
Hash,
PartialOrd,
Ord,
)]
#[repr(i32)]
pub enum CausesValidation {
No = 0,
#[default]
Yes = -1,
}
impl TryFrom<&str> for CausesValidation {
type Error = ErrorKind;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"0" => Ok(CausesValidation::No),
"-1" => Ok(CausesValidation::Yes),
_ => Err(ErrorKind::Form(FormError::InvalidCausesValidation {
value: value.to_string(),
})),
}
}
}
impl FromStr for CausesValidation {
type Err = ErrorKind;
fn from_str(s: &str) -> Result<Self, Self::Err> {
CausesValidation::try_from(s)
}
}
impl From<bool> for CausesValidation {
fn from(value: bool) -> Self {
if value {
CausesValidation::Yes
} else {
CausesValidation::No
}
}
}
impl Display for CausesValidation {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let text = match self {
CausesValidation::No => "No",
CausesValidation::Yes => "Yes",
};
write!(f, "{text}")
}
}
#[derive(
Debug,
PartialEq,
Eq,
Clone,
Default,
TryFromPrimitive,
serde::Serialize,
Copy,
Hash,
PartialOrd,
Ord,
)]
#[repr(i32)]
pub enum Movability {
Fixed = 0,
#[default]
Moveable = -1,
}
impl TryFrom<&str> for Movability {
type Error = ErrorKind;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"0" => Ok(Movability::Fixed),
"-1" => Ok(Movability::Moveable),
_ => Err(ErrorKind::Form(FormError::InvalidMovability {
value: value.to_string(),
})),
}
}
}
impl FromStr for Movability {
type Err = ErrorKind;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Movability::try_from(s)
}
}
impl From<bool> for Movability {
fn from(value: bool) -> Self {
if value {
Movability::Moveable
} else {
Movability::Fixed
}
}
}
impl Display for Movability {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let text = match self {
Movability::Fixed => "Fixed",
Movability::Moveable => "Moveable",
};
write!(f, "{text}")
}
}
#[derive(
Debug,
PartialEq,
Eq,
Clone,
Default,
TryFromPrimitive,
serde::Serialize,
Copy,
Hash,
PartialOrd,
Ord,
)]
#[repr(i32)]
pub enum FontTransparency {
Opaque = 0,
#[default]
Transparent = -1,
}
impl TryFrom<&str> for FontTransparency {
type Error = ErrorKind;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"0" => Ok(FontTransparency::Opaque),
"-1" => Ok(FontTransparency::Transparent),
_ => Err(ErrorKind::Form(FormError::InvalidFontTransparency {
value: value.to_string(),
})),
}
}
}
impl FromStr for FontTransparency {
type Err = ErrorKind;
fn from_str(s: &str) -> Result<Self, Self::Err> {
FontTransparency::try_from(s)
}
}
impl From<bool> for FontTransparency {
fn from(value: bool) -> Self {
if value {
FontTransparency::Transparent
} else {
FontTransparency::Opaque
}
}
}
impl Display for FontTransparency {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let text = match self {
FontTransparency::Opaque => "Opaque",
FontTransparency::Transparent => "Transparent",
};
write!(f, "{text}")
}
}
#[derive(
Debug,
PartialEq,
Eq,
Clone,
Default,
TryFromPrimitive,
serde::Serialize,
Copy,
Hash,
PartialOrd,
Ord,
)]
#[repr(i32)]
pub enum WhatsThisHelp {
#[default]
F1Help = 0,
WhatsThisHelp = -1,
}
impl TryFrom<&str> for WhatsThisHelp {
type Error = ErrorKind;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"0" => Ok(WhatsThisHelp::F1Help),
"-1" => Ok(WhatsThisHelp::WhatsThisHelp),
_ => Err(ErrorKind::Form(FormError::InvalidWhatsThisHelp {
value: value.to_string(),
})),
}
}
}
impl From<bool> for WhatsThisHelp {
fn from(value: bool) -> Self {
if value {
WhatsThisHelp::WhatsThisHelp
} else {
WhatsThisHelp::F1Help
}
}
}
impl FromStr for WhatsThisHelp {
type Err = ErrorKind;
fn from_str(s: &str) -> Result<Self, Self::Err> {
WhatsThisHelp::try_from(s)
}
}
impl Display for WhatsThisHelp {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let text = match self {
WhatsThisHelp::F1Help => "F1Help",
WhatsThisHelp::WhatsThisHelp => "WhatsThisHelp",
};
write!(f, "{text}")
}
}
#[derive(
Debug,
PartialEq,
Eq,
Clone,
serde::Serialize,
Default,
TryFromPrimitive,
Copy,
Hash,
PartialOrd,
Ord,
)]
#[repr(i32)]
pub enum FormLinkMode {
#[default]
None = 0,
Source = 1,
}
impl TryFrom<&str> for FormLinkMode {
type Error = ErrorKind;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"0" => Ok(FormLinkMode::None),
"1" => Ok(FormLinkMode::Source),
_ => Err(ErrorKind::Form(FormError::InvalidFormLinkMode {
value: value.to_string(),
})),
}
}
}
impl FromStr for FormLinkMode {
type Err = ErrorKind;
fn from_str(s: &str) -> Result<Self, Self::Err> {
FormLinkMode::try_from(s)
}
}
impl From<bool> for FormLinkMode {
fn from(value: bool) -> Self {
if value {
FormLinkMode::Source
} else {
FormLinkMode::None
}
}
}
impl Display for FormLinkMode {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let text = match self {
FormLinkMode::None => "None",
FormLinkMode::Source => "Source",
};
write!(f, "{text}")
}
}
#[derive(
Debug,
PartialEq,
Eq,
Clone,
serde::Serialize,
Default,
TryFromPrimitive,
Copy,
Hash,
PartialOrd,
Ord,
)]
#[repr(i32)]
pub enum WindowState {
#[default]
Normal = 0,
Minimized = 1,
Maximized = 2,
}
impl TryFrom<&str> for WindowState {
type Error = ErrorKind;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"0" => Ok(WindowState::Normal),
"1" => Ok(WindowState::Minimized),
"2" => Ok(WindowState::Maximized),
_ => Err(ErrorKind::Form(FormError::InvalidWindowState {
value: value.to_string(),
})),
}
}
}
impl FromStr for WindowState {
type Err = ErrorKind;
fn from_str(s: &str) -> Result<Self, Self::Err> {
WindowState::try_from(s)
}
}
impl Display for WindowState {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let text = match self {
WindowState::Normal => "Normal",
WindowState::Minimized => "Minimized",
WindowState::Maximized => "Maximized",
};
write!(f, "{text}")
}
}
#[derive(Debug, PartialEq, Eq, Clone, serde::Serialize, Default, Copy, Hash, PartialOrd, Ord)]
pub enum StartUpPosition {
Manual {
client_height: i32,
client_width: i32,
client_top: i32,
client_left: i32,
},
CenterOwner,
CenterScreen,
#[default]
WindowsDefault,
}
impl Display for StartUpPosition {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
StartUpPosition::Manual {
client_height,
client_width,
client_top,
client_left,
} => write!(
f,
"Manual {{ client height: {client_height}, client width: {client_width}, client top: {client_top}, client left: {client_left} }}"
),
StartUpPosition::CenterOwner => write!(f, "CenterOwner"),
StartUpPosition::CenterScreen => write!(f, "CenterScreen"),
StartUpPosition::WindowsDefault => write!(f, "WindowsDefault"),
}
}
}
#[derive(Debug, PartialEq, Clone, Serialize)]
pub enum ReferenceOrValue<T> {
Reference { filename: String, offset: u32 },
Value(T),
}
impl<T> Display for ReferenceOrValue<T> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
ReferenceOrValue::Reference { filename, offset } => {
write!(f, "Reference {{ filename: {filename}, offset: {offset} }}",)
}
ReferenceOrValue::Value(_) => write!(f, "Value"),
}
}
}
#[derive(Debug, PartialEq, Clone, Serialize)]
pub struct Control {
name: String,
tag: String,
index: i32,
kind: ControlKind,
}
impl Control {
#[must_use]
pub fn new(name: String, tag: String, index: i32, kind: ControlKind) -> Self {
Self {
name,
tag,
index,
kind,
}
}
#[must_use]
pub fn name(&self) -> &str {
&self.name
}
#[must_use]
pub fn tag(&self) -> &str {
&self.tag
}
#[must_use]
pub fn index(&self) -> i32 {
self.index
}
#[must_use]
pub fn kind(&self) -> &ControlKind {
&self.kind
}
#[must_use]
pub fn into_name(self) -> String {
self.name
}
#[must_use]
pub fn into_tag(self) -> String {
self.tag
}
#[must_use]
pub fn into_kind(self) -> ControlKind {
self.kind
}
#[must_use]
pub fn into_parts(self) -> (String, String, i32, ControlKind) {
(self.name, self.tag, self.index, self.kind)
}
pub fn set_name(&mut self, name: String) {
self.name = name;
}
}
impl Display for Control {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(f, "Control: {} ({})", self.name, self.kind)
}
}
#[derive(Debug, PartialEq, Clone, Serialize)]
pub enum ControlKind {
CommandButton {
properties: CommandButtonProperties,
},
Data {
properties: DataProperties,
},
TextBox {
properties: TextBoxProperties,
},
CheckBox {
properties: CheckBoxProperties,
},
Line {
properties: LineProperties,
},
Shape {
properties: ShapeProperties,
},
ListBox {
properties: ListBoxProperties,
},
Timer {
properties: TimerProperties,
},
Label {
properties: LabelProperties,
},
Frame {
properties: FrameProperties,
controls: Vec<Control>,
},
PictureBox {
properties: PictureBoxProperties,
controls: Vec<Control>,
},
FileListBox {
properties: FileListBoxProperties,
},
DriveListBox {
properties: DriveListBoxProperties,
},
DirListBox {
properties: DirListBoxProperties,
},
Ole {
properties: OLEProperties,
},
OptionButton {
properties: OptionButtonProperties,
},
Image {
properties: ImageProperties,
},
ComboBox {
properties: ComboBoxProperties,
},
HScrollBar {
properties: ScrollBarProperties,
},
VScrollBar {
properties: ScrollBarProperties,
},
Menu {
properties: MenuProperties,
sub_menus: Vec<MenuControl>,
},
Custom {
properties: CustomControlProperties,
property_groups: Vec<PropertyGroup>,
},
}
impl Display for ControlKind {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
ControlKind::CommandButton { .. } => write!(f, "CommandButton"),
ControlKind::Data { .. } => write!(f, "Data"),
ControlKind::TextBox { .. } => write!(f, "TextBox"),
ControlKind::CheckBox { .. } => write!(f, "CheckBox"),
ControlKind::Line { .. } => write!(f, "Line"),
ControlKind::Shape { .. } => write!(f, "Shape"),
ControlKind::ListBox { .. } => write!(f, "ListBox"),
ControlKind::Timer { .. } => write!(f, "Timer"),
ControlKind::Label { .. } => write!(f, "Label"),
ControlKind::Frame { .. } => write!(f, "Frame"),
ControlKind::PictureBox { .. } => write!(f, "PictureBox"),
ControlKind::FileListBox { .. } => write!(f, "FileListBox"),
ControlKind::DriveListBox { .. } => write!(f, "DriveListBox"),
ControlKind::DirListBox { .. } => write!(f, "DirListBox"),
ControlKind::Ole { .. } => write!(f, "OLE"),
ControlKind::OptionButton { .. } => write!(f, "OptionButton"),
ControlKind::Image { .. } => write!(f, "Image"),
ControlKind::ComboBox { .. } => write!(f, "ComboBox"),
ControlKind::HScrollBar { .. } => write!(f, "HScrollBar"),
ControlKind::VScrollBar { .. } => write!(f, "VScrollBar"),
ControlKind::Menu { .. } => write!(f, "Menu"),
ControlKind::Custom { .. } => write!(f, "Custom"),
}
}
}
impl ControlKind {
#[must_use]
pub fn is_menu(&self) -> bool {
matches!(self, ControlKind::Menu { .. })
}
#[must_use]
pub fn can_contain_children(&self) -> bool {
matches!(
self,
ControlKind::Frame { .. } | ControlKind::PictureBox { .. }
)
}
#[must_use]
pub fn can_contain_menus(&self) -> bool {
false
}
#[must_use]
pub fn has_menu(&self) -> bool {
false
}
#[must_use]
pub fn has_children(&self) -> bool {
matches!(
self,
ControlKind::Frame { controls, .. } |
ControlKind::PictureBox { controls, .. } if !controls.is_empty()
)
}
#[must_use]
pub fn children(&self) -> Option<impl Iterator<Item = &Control>> {
match self {
ControlKind::Frame { controls, .. } | ControlKind::PictureBox { controls, .. } => {
Some(controls.iter())
}
_ => None,
}
}
#[must_use]
pub fn menus(&self) -> Option<impl Iterator<Item = &MenuControl>> {
None::<std::iter::Empty<&MenuControl>>
}
#[must_use]
pub fn descendants(&self) -> Box<dyn Iterator<Item = &Control> + '_> {
Box::new(
self.children()
.into_iter()
.flatten()
.flat_map(|child| child.descendants()),
)
}
}
impl Control {
#[must_use]
pub fn is_menu(&self) -> bool {
self.kind.is_menu()
}
#[must_use]
pub fn has_menu(&self) -> bool {
self.kind.has_menu()
}
#[must_use]
pub fn menus(&self) -> Option<impl Iterator<Item = &MenuControl>> {
self.kind.menus()
}
#[must_use]
pub fn can_contain_menus(&self) -> bool {
self.kind.can_contain_menus()
}
#[must_use]
pub fn can_contain_children(&self) -> bool {
self.kind.can_contain_children()
}
#[must_use]
pub fn children(&self) -> Option<impl Iterator<Item = &Control>> {
self.kind.children()
}
#[must_use]
pub fn has_children(&self) -> bool {
matches!(
self.kind,
ControlKind::Frame { .. } | ControlKind::PictureBox { .. }
)
}
#[must_use]
pub fn descendants(&self) -> Box<dyn Iterator<Item = &Control> + '_> {
Box::new(std::iter::once(self).chain(self.kind.descendants()))
}
}
#[derive(
Debug, PartialEq, Eq, Clone, Serialize, Default, TryFromPrimitive, Copy, Hash, PartialOrd, Ord,
)]
#[repr(i32)]
pub enum Align {
#[default]
None = 0,
Top = 1,
Bottom = 2,
Left = 3,
Right = 4,
}
impl TryFrom<&str> for Align {
type Error = ErrorKind;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"0" => Ok(Align::None),
"1" => Ok(Align::Top),
"2" => Ok(Align::Bottom),
"3" => Ok(Align::Left),
"4" => Ok(Align::Right),
_ => Err(ErrorKind::Form(FormError::InvalidAlign {
value: value.to_string(),
})),
}
}
}
impl FromStr for Align {
type Err = ErrorKind;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Align::try_from(s)
}
}
impl Display for Align {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let text = match self {
Align::None => "None",
Align::Top => "Top",
Align::Bottom => "Bottom",
Align::Left => "Left",
Align::Right => "Right",
};
write!(f, "{text}")
}
}
#[derive(
Debug, PartialEq, Eq, Clone, Serialize, TryFromPrimitive, Default, Copy, Hash, PartialOrd, Ord,
)]
#[repr(i32)]
pub enum JustifyAlignment {
#[default]
LeftJustify = 0,
RightJustify = 1,
}
impl TryFrom<&str> for JustifyAlignment {
type Error = ErrorKind;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"0" => Ok(JustifyAlignment::LeftJustify),
"1" => Ok(JustifyAlignment::RightJustify),
_ => Err(ErrorKind::Form(FormError::InvalidJustifyAlignment {
value: value.to_string(),
})),
}
}
}
impl FromStr for JustifyAlignment {
type Err = ErrorKind;
fn from_str(s: &str) -> Result<Self, Self::Err> {
JustifyAlignment::try_from(s)
}
}
impl Display for JustifyAlignment {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let text = match self {
JustifyAlignment::LeftJustify => "Left Justify",
JustifyAlignment::RightJustify => "Right Justify",
};
write!(f, "{text}")
}
}
#[derive(
Debug, PartialEq, Eq, Clone, Serialize, TryFromPrimitive, Default, Copy, Hash, PartialOrd, Ord,
)]
#[repr(i32)]
pub enum Alignment {
#[default]
LeftJustify = 0,
RightJustify = 1,
Center = 2,
}
impl TryFrom<&str> for Alignment {
type Error = ErrorKind;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"0" => Ok(Alignment::LeftJustify),
"1" => Ok(Alignment::RightJustify),
"2" => Ok(Alignment::Center),
_ => Err(ErrorKind::Form(FormError::InvalidAlignment {
value: value.to_string(),
})),
}
}
}
impl FromStr for Alignment {
type Err = ErrorKind;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Alignment::try_from(s)
}
}
impl Display for Alignment {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let text = match self {
Alignment::LeftJustify => "LeftJustify",
Alignment::RightJustify => "RightJustify",
Alignment::Center => "Center",
};
write!(f, "{text}")
}
}
#[derive(
Debug, PartialEq, Eq, Clone, Serialize, Default, TryFromPrimitive, Copy, Hash, PartialOrd, Ord,
)]
#[repr(i32)]
pub enum BackStyle {
Transparent = 0,
#[default]
Opaque = 1,
}
impl TryFrom<&str> for BackStyle {
type Error = ErrorKind;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"0" => Ok(BackStyle::Transparent),
"1" => Ok(BackStyle::Opaque),
_ => Err(ErrorKind::Form(FormError::InvalidBackStyle {
value: value.to_string(),
})),
}
}
}
impl FromStr for BackStyle {
type Err = ErrorKind;
fn from_str(s: &str) -> Result<Self, Self::Err> {
BackStyle::try_from(s)
}
}
impl Display for BackStyle {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let text = match self {
BackStyle::Transparent => "Transparent",
BackStyle::Opaque => "Opaque",
};
write!(f, "{text}")
}
}
#[derive(
Debug, PartialEq, Eq, Clone, Serialize, TryFromPrimitive, Default, Copy, Hash, PartialOrd, Ord,
)]
#[repr(i32)]
pub enum Appearance {
Flat = 0,
#[default]
ThreeD = 1,
}
impl TryFrom<&str> for Appearance {
type Error = ErrorKind;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"0" => Ok(Appearance::Flat),
"1" => Ok(Appearance::ThreeD),
_ => Err(ErrorKind::Form(FormError::InvalidAppearance {
value: value.to_string(),
})),
}
}
}
impl FromStr for Appearance {
type Err = ErrorKind;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Appearance::try_from(s)
}
}
impl Display for Appearance {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let text = match self {
Appearance::Flat => "Flat",
Appearance::ThreeD => "ThreeD",
};
write!(f, "{text}")
}
}
#[derive(
Debug, PartialEq, Eq, Clone, Serialize, Default, TryFromPrimitive, Copy, Hash, PartialOrd, Ord,
)]
#[repr(i32)]
pub enum BorderStyle {
None = 0,
#[default]
FixedSingle = 1,
}
impl TryFrom<&str> for BorderStyle {
type Error = ErrorKind;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"0" => Ok(BorderStyle::None),
"1" => Ok(BorderStyle::FixedSingle),
_ => Err(ErrorKind::Form(FormError::InvalidBorderStyle {
value: value.to_string(),
})),
}
}
}
impl FromStr for BorderStyle {
type Err = ErrorKind;
fn from_str(s: &str) -> Result<Self, Self::Err> {
BorderStyle::try_from(s)
}
}
impl Display for BorderStyle {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let text = match self {
BorderStyle::None => "None",
BorderStyle::FixedSingle => "FixedSingle",
};
write!(f, "{text}")
}
}
#[derive(
Debug, PartialEq, Eq, Clone, Serialize, Default, TryFromPrimitive, Copy, Hash, PartialOrd, Ord,
)]
#[repr(i32)]
pub enum DragMode {
#[default]
Manual = 0,
Automatic = 1,
}
impl TryFrom<&str> for DragMode {
type Error = ErrorKind;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"0" => Ok(DragMode::Manual),
"1" => Ok(DragMode::Automatic),
_ => Err(ErrorKind::Form(FormError::InvalidDragMode {
value: value.to_string(),
})),
}
}
}
impl FromStr for DragMode {
type Err = ErrorKind;
fn from_str(s: &str) -> Result<Self, Self::Err> {
DragMode::try_from(s)
}
}
impl Display for DragMode {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let text = match self {
DragMode::Manual => "Manual",
DragMode::Automatic => "Automatic",
};
write!(f, "{text}")
}
}
#[derive(
Debug, PartialEq, Eq, Clone, Serialize, Default, TryFromPrimitive, Copy, Hash, PartialOrd, Ord,
)]
#[repr(i32)]
pub enum DrawMode {
Blackness = 1,
NotMergePen = 2,
MaskNotPen = 3,
NotCopyPen = 4,
MaskPenNot = 5,
Invert = 6,
XorPen = 7,
NotMaskPen = 8,
MaskPen = 9,
NotXorPen = 10,
Nop = 11,
MergeNotPen = 12,
#[default]
CopyPen = 13,
MergePenNot = 14,
MergePen = 15,
Whiteness = 16,
}
impl TryFrom<&str> for DrawMode {
type Error = ErrorKind;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"1" => Ok(DrawMode::Blackness),
"2" => Ok(DrawMode::NotMergePen),
"3" => Ok(DrawMode::MaskNotPen),
"4" => Ok(DrawMode::NotCopyPen),
"5" => Ok(DrawMode::MaskPenNot),
"6" => Ok(DrawMode::Invert),
"7" => Ok(DrawMode::XorPen),
"8" => Ok(DrawMode::NotMaskPen),
"9" => Ok(DrawMode::MaskPen),
"10" => Ok(DrawMode::NotXorPen),
"11" => Ok(DrawMode::Nop),
"12" => Ok(DrawMode::MergeNotPen),
"13" => Ok(DrawMode::CopyPen),
"14" => Ok(DrawMode::MergePenNot),
"15" => Ok(DrawMode::MergePen),
"16" => Ok(DrawMode::Whiteness),
_ => Err(ErrorKind::Form(FormError::InvalidDrawMode {
value: value.to_string(),
})),
}
}
}
impl FromStr for DrawMode {
type Err = ErrorKind;
fn from_str(s: &str) -> Result<Self, Self::Err> {
DrawMode::try_from(s)
}
}
impl Display for DrawMode {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let text = match self {
DrawMode::Blackness => "Blackness",
DrawMode::NotMergePen => "Not Merge Pen",
DrawMode::MaskNotPen => "Mask Not Pen",
DrawMode::NotCopyPen => "Not Copy Pen",
DrawMode::MaskPenNot => "Mask Pen Not",
DrawMode::Invert => "Invert",
DrawMode::XorPen => "Xor Pen",
DrawMode::NotMaskPen => "Not Mask Pen",
DrawMode::MaskPen => "Mask Pen",
DrawMode::NotXorPen => "Not Xor Pen",
DrawMode::Nop => "Nop",
DrawMode::MergeNotPen => "Merge Not Pen",
DrawMode::CopyPen => "Copy Pen",
DrawMode::MergePenNot => "Merge Pen Not",
DrawMode::MergePen => "Merge Pen",
DrawMode::Whiteness => "Whiteness",
};
write!(f, "{text}")
}
}
#[derive(
Debug, PartialEq, Eq, Clone, Serialize, Default, TryFromPrimitive, Copy, Hash, PartialOrd, Ord,
)]
#[repr(i32)]
pub enum DrawStyle {
#[default]
Solid = 0,
Dash = 1,
Dot = 2,
DashDot = 3,
DashDotDot = 4,
Transparent = 5,
InsideSolid = 6,
}
impl TryFrom<&str> for DrawStyle {
type Error = ErrorKind;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"0" => Ok(DrawStyle::Solid),
"1" => Ok(DrawStyle::Dash),
"2" => Ok(DrawStyle::Dot),
"3" => Ok(DrawStyle::DashDot),
"4" => Ok(DrawStyle::DashDotDot),
"5" => Ok(DrawStyle::Transparent),
"6" => Ok(DrawStyle::InsideSolid),
_ => Err(ErrorKind::Form(FormError::InvalidDrawStyle {
value: value.to_string(),
})),
}
}
}
impl FromStr for DrawStyle {
type Err = ErrorKind;
fn from_str(s: &str) -> Result<Self, Self::Err> {
DrawStyle::try_from(s)
}
}
impl Display for DrawStyle {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let text = match self {
DrawStyle::Solid => "Solid",
DrawStyle::Dash => "Dash",
DrawStyle::Dot => "Dot",
DrawStyle::DashDot => "DashDot",
DrawStyle::DashDotDot => "DashDotDot",
DrawStyle::Transparent => "Transparent",
DrawStyle::InsideSolid => "InsideSolid",
};
write!(f, "{text}")
}
}
#[derive(
Debug, PartialEq, Eq, Clone, Serialize, Default, TryFromPrimitive, Copy, Hash, PartialOrd, Ord,
)]
#[repr(i32)]
pub enum MousePointer {
#[default]
Default = 0,
Arrow = 1,
Cross = 2,
IBeam = 3,
Icon = 4,
Size = 5,
SizeNESW = 6,
SizeNS = 7,
SizeNWSE = 8,
SizeWE = 9,
UpArrow = 10,
Hourglass = 11,
NoDrop = 12,
ArrowHourglass = 13,
ArrowQuestion = 14,
SizeAll = 15,
Custom = 99,
}
impl TryFrom<&str> for MousePointer {
type Error = ErrorKind;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"0" => Ok(MousePointer::Default),
"1" => Ok(MousePointer::Arrow),
"2" => Ok(MousePointer::Cross),
"3" => Ok(MousePointer::IBeam),
"4" => Ok(MousePointer::Icon),
"5" => Ok(MousePointer::Size),
"6" => Ok(MousePointer::SizeNESW),
"7" => Ok(MousePointer::SizeNS),
"8" => Ok(MousePointer::SizeNWSE),
"9" => Ok(MousePointer::SizeWE),
"10" => Ok(MousePointer::UpArrow),
"11" => Ok(MousePointer::Hourglass),
"12" => Ok(MousePointer::NoDrop),
"13" => Ok(MousePointer::ArrowHourglass),
"14" => Ok(MousePointer::ArrowQuestion),
"15" => Ok(MousePointer::SizeAll),
"99" => Ok(MousePointer::Custom),
_ => Err(ErrorKind::Form(FormError::InvalidMousePointer {
value: value.to_string(),
})),
}
}
}
impl FromStr for MousePointer {
type Err = ErrorKind;
fn from_str(s: &str) -> Result<Self, Self::Err> {
MousePointer::try_from(s)
}
}
impl Display for MousePointer {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let text = match self {
MousePointer::Default => "Default",
MousePointer::Arrow => "Arrow",
MousePointer::Cross => "Cross",
MousePointer::IBeam => "IBeam",
MousePointer::Icon => "Icon",
MousePointer::Size => "Size",
MousePointer::SizeNESW => "SizeNESW",
MousePointer::SizeNS => "SizeNS",
MousePointer::SizeNWSE => "SizeNWSE",
MousePointer::SizeWE => "SizeWE",
MousePointer::UpArrow => "UpArrow",
MousePointer::Hourglass => "Hourglass",
MousePointer::NoDrop => "NoDrop",
MousePointer::ArrowHourglass => "ArrowHourglass",
MousePointer::ArrowQuestion => "ArrowQuestion",
MousePointer::SizeAll => "SizeAll",
MousePointer::Custom => "Custom",
};
write!(f, "{text}")
}
}
#[derive(
Debug, PartialEq, Eq, Clone, Serialize, Default, TryFromPrimitive, Copy, Hash, PartialOrd, Ord,
)]
#[repr(i32)]
pub enum OLEDragMode {
#[default]
Manual = 0,
Automatic = 1,
}
impl TryFrom<&str> for OLEDragMode {
type Error = ErrorKind;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"0" => Ok(OLEDragMode::Manual),
"1" => Ok(OLEDragMode::Automatic),
_ => Err(ErrorKind::Form(FormError::InvalidOLEDragMode {
value: value.to_string(),
})),
}
}
}
impl FromStr for OLEDragMode {
type Err = ErrorKind;
fn from_str(s: &str) -> Result<Self, Self::Err> {
OLEDragMode::try_from(s)
}
}
impl Display for OLEDragMode {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let text = match self {
OLEDragMode::Manual => "Manual",
OLEDragMode::Automatic => "Automatic",
};
write!(f, "{text}")
}
}
#[derive(
Debug, PartialEq, Eq, Clone, Serialize, Default, TryFromPrimitive, Copy, Hash, PartialOrd, Ord,
)]
#[repr(i32)]
pub enum OLEDropMode {
#[default]
None = 0,
Manual = 1,
}
impl TryFrom<&str> for OLEDropMode {
type Error = ErrorKind;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"0" => Ok(OLEDropMode::None),
"1" => Ok(OLEDropMode::Manual),
_ => Err(ErrorKind::Form(FormError::InvalidOLEDropMode {
value: value.to_string(),
})),
}
}
}
impl FromStr for OLEDropMode {
type Err = ErrorKind;
fn from_str(s: &str) -> Result<Self, Self::Err> {
OLEDropMode::try_from(s)
}
}
impl Display for OLEDropMode {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let text = match self {
OLEDropMode::None => "None",
OLEDropMode::Manual => "Manual",
};
write!(f, "{text}")
}
}
#[derive(
Debug, PartialEq, Eq, Clone, Serialize, Default, TryFromPrimitive, Copy, Hash, PartialOrd, Ord,
)]
#[repr(i32)]
pub enum ClipControls {
Unbounded = 0,
#[default]
Clipped = 1,
}
impl TryFrom<&str> for ClipControls {
type Error = ErrorKind;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"0" => Ok(ClipControls::Unbounded),
"1" => Ok(ClipControls::Clipped),
_ => Err(ErrorKind::Form(FormError::InvalidClipControls {
value: value.to_string(),
})),
}
}
}
impl FromStr for ClipControls {
type Err = ErrorKind;
fn from_str(s: &str) -> Result<Self, Self::Err> {
ClipControls::try_from(s)
}
}
impl Display for ClipControls {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let text = match self {
ClipControls::Unbounded => "Unbounded",
ClipControls::Clipped => "Clipped",
};
write!(f, "{text}")
}
}
#[derive(
Debug, PartialEq, Eq, Clone, Serialize, Default, TryFromPrimitive, Copy, Hash, PartialOrd, Ord,
)]
#[repr(i32)]
pub enum Style {
#[default]
Standard = 0,
Graphical = 1,
}
impl TryFrom<&str> for Style {
type Error = ErrorKind;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"0" => Ok(Style::Standard),
"1" => Ok(Style::Graphical),
_ => Err(ErrorKind::Form(FormError::InvalidStyle {
value: value.to_string(),
})),
}
}
}
impl FromStr for Style {
type Err = ErrorKind;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Style::try_from(s)
}
}
impl Display for Style {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let text = match self {
Style::Standard => "Standard",
Style::Graphical => "Graphical",
};
write!(f, "{text}")
}
}
#[derive(
Debug, PartialEq, Eq, Clone, Serialize, Default, TryFromPrimitive, Copy, Hash, PartialOrd, Ord,
)]
#[repr(i32)]
pub enum FillStyle {
Solid = 0,
#[default]
Transparent = 1,
HorizontalLine = 2,
VerticalLine = 3,
UpwardDiagonal = 4,
DownwardDiagonal = 5,
Cross = 6,
DiagonalCross = 7,
}
impl TryFrom<&str> for FillStyle {
type Error = ErrorKind;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"0" => Ok(FillStyle::Solid),
"1" => Ok(FillStyle::Transparent),
"2" => Ok(FillStyle::HorizontalLine),
"3" => Ok(FillStyle::VerticalLine),
"4" => Ok(FillStyle::UpwardDiagonal),
"5" => Ok(FillStyle::DownwardDiagonal),
"6" => Ok(FillStyle::Cross),
"7" => Ok(FillStyle::DiagonalCross),
_ => Err(ErrorKind::Form(FormError::InvalidFillStyle {
value: value.to_string(),
})),
}
}
}
impl FromStr for FillStyle {
type Err = ErrorKind;
fn from_str(s: &str) -> Result<Self, Self::Err> {
FillStyle::try_from(s)
}
}
impl Display for FillStyle {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let text = match self {
FillStyle::Solid => "Solid",
FillStyle::Transparent => "Transparent",
FillStyle::HorizontalLine => "HorizontalLine",
FillStyle::VerticalLine => "VerticalLine",
FillStyle::UpwardDiagonal => "UpwardDiagonal",
FillStyle::DownwardDiagonal => "DownwardDiagonal",
FillStyle::Cross => "Cross",
FillStyle::DiagonalCross => "DiagonalCross",
};
write!(f, "{text}")
}
}
#[derive(
Debug, PartialEq, Eq, Clone, Serialize, TryFromPrimitive, Default, Copy, Hash, PartialOrd, Ord,
)]
#[repr(i32)]
pub enum LinkMode {
#[default]
None = 0,
Automatic = 1,
Manual = 2,
Notify = 3,
}
impl TryFrom<&str> for LinkMode {
type Error = ErrorKind;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"0" => Ok(LinkMode::None),
"1" => Ok(LinkMode::Automatic),
"2" => Ok(LinkMode::Manual),
"3" => Ok(LinkMode::Notify),
_ => Err(ErrorKind::Form(FormError::InvalidLinkMode {
value: value.to_string(),
})),
}
}
}
impl FromStr for LinkMode {
type Err = ErrorKind;
fn from_str(s: &str) -> Result<Self, Self::Err> {
LinkMode::try_from(s)
}
}
impl Display for LinkMode {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let text = match self {
LinkMode::None => "None",
LinkMode::Automatic => "Automatic",
LinkMode::Manual => "Manual",
LinkMode::Notify => "Notify",
};
write!(f, "{text}")
}
}
#[derive(
Debug, PartialEq, Eq, Clone, Serialize, Default, TryFromPrimitive, Copy, Hash, PartialOrd, Ord,
)]
#[repr(i32)]
pub enum MultiSelect {
#[default]
None = 0,
Simple = 1,
Extended = 2,
}
impl TryFrom<&str> for MultiSelect {
type Error = ErrorKind;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"0" => Ok(MultiSelect::None),
"1" => Ok(MultiSelect::Simple),
"2" => Ok(MultiSelect::Extended),
_ => Err(ErrorKind::Form(FormError::InvalidMultiSelect {
value: value.to_string(),
})),
}
}
}
impl FromStr for MultiSelect {
type Err = ErrorKind;
fn from_str(s: &str) -> Result<Self, Self::Err> {
MultiSelect::try_from(s)
}
}
impl Display for MultiSelect {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let text = match self {
MultiSelect::None => "None",
MultiSelect::Simple => "Simple",
MultiSelect::Extended => "Extended",
};
write!(f, "{text}")
}
}
#[derive(
Debug, PartialEq, Eq, Clone, Serialize, Default, TryFromPrimitive, Copy, Hash, PartialOrd, Ord,
)]
#[repr(i32)]
pub enum ScaleMode {
User = 0,
#[default]
Twip = 1,
Point = 2,
Pixel = 3,
Character = 4,
Inches = 5,
Millimeter = 6,
Centimeter = 7,
HiMetric = 8,
ContainerPosition = 9,
ContainerSize = 10,
}
impl FromStr for ScaleMode {
type Err = ErrorKind;
fn from_str(s: &str) -> Result<Self, Self::Err> {
ScaleMode::try_from(s)
}
}
impl TryFrom<&str> for ScaleMode {
type Error = ErrorKind;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"0" => Ok(ScaleMode::User),
"1" => Ok(ScaleMode::Twip),
"2" => Ok(ScaleMode::Point),
"3" => Ok(ScaleMode::Pixel),
"4" => Ok(ScaleMode::Character),
"5" => Ok(ScaleMode::Inches),
"6" => Ok(ScaleMode::Millimeter),
"7" => Ok(ScaleMode::Centimeter),
"8" => Ok(ScaleMode::HiMetric),
"9" => Ok(ScaleMode::ContainerPosition),
"10" => Ok(ScaleMode::ContainerSize),
_ => Err(ErrorKind::Form(FormError::InvalidScaleMode {
value: value.to_string(),
})),
}
}
}
impl Display for ScaleMode {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let text = match self {
ScaleMode::User => "User",
ScaleMode::Twip => "Twip",
ScaleMode::Point => "Point",
ScaleMode::Pixel => "Pixel",
ScaleMode::Character => "Character",
ScaleMode::Inches => "Inches",
ScaleMode::Millimeter => "Millimeter",
ScaleMode::Centimeter => "Centimeter",
ScaleMode::HiMetric => "HiMetric",
ScaleMode::ContainerPosition => "ContainerPosition",
ScaleMode::ContainerSize => "ContainerSize",
};
write!(f, "{text}")
}
}
#[derive(
Debug, PartialEq, Eq, Clone, Serialize, Default, TryFromPrimitive, Copy, Hash, PartialOrd, Ord,
)]
#[repr(i32)]
pub enum SizeMode {
#[default]
Clip = 0,
Stretch = 1,
AutoSize = 2,
Zoom = 3,
}
impl TryFrom<&str> for SizeMode {
type Error = ErrorKind;
fn try_from(value: &str) -> Result<Self, Self::Error> {
match value {
"0" => Ok(SizeMode::Clip),
"1" => Ok(SizeMode::Stretch),
"2" => Ok(SizeMode::AutoSize),
"3" => Ok(SizeMode::Zoom),
_ => Err(ErrorKind::Form(FormError::InvalidSizeMode {
value: value.to_string(),
})),
}
}
}
impl FromStr for SizeMode {
type Err = ErrorKind;
fn from_str(s: &str) -> Result<Self, Self::Err> {
SizeMode::try_from(s)
}
}
impl Display for SizeMode {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
let text = match self {
SizeMode::Clip => "Clip",
SizeMode::Stretch => "Stretch",
SizeMode::AutoSize => "AutoSize",
SizeMode::Zoom => "Zoom",
};
write!(f, "{text}")
}
}