use super::chart::Anchor;
use crate::style::Font;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ControlKind {
Button,
CheckBox,
OptionButton,
ComboBox,
ListBox,
Spinner,
ScrollBar,
GroupBox,
Label,
}
impl ControlKind {
pub(crate) fn from_vml(name: &str) -> Option<Self> {
Some(match name {
"Button" => Self::Button,
"Checkbox" => Self::CheckBox,
"Radio" => Self::OptionButton,
"Drop" => Self::ComboBox,
"List" => Self::ListBox,
"Spin" => Self::Spinner,
"Scroll" => Self::ScrollBar,
"GBox" => Self::GroupBox,
"Label" => Self::Label,
_ => return None,
})
}
#[cfg(feature = "write")]
pub(crate) const fn vml_name(self) -> &'static str {
match self {
Self::Button => "Button",
Self::CheckBox => "Checkbox",
Self::OptionButton => "Radio",
Self::ComboBox => "Drop",
Self::ListBox => "List",
Self::Spinner => "Spin",
Self::ScrollBar => "Scroll",
Self::GroupBox => "GBox",
Self::Label => "Label",
}
}
#[cfg(feature = "write")]
pub(crate) const fn names(self) -> (&'static str, &'static str) {
match self {
Self::Button => ("Button", "Button"),
Self::CheckBox => ("CheckBox", "Check Box"),
Self::OptionButton => ("Radio", "Option Button"),
Self::ComboBox => ("Drop", "Drop Down"),
Self::ListBox => ("List", "List Box"),
Self::Spinner => ("Spin", "Spinner"),
Self::ScrollBar => ("Scroll", "Scroll Bar"),
Self::GroupBox => ("GBox", "Group Box"),
Self::Label => ("Label", "Label"),
}
}
pub(crate) fn from_biff(ot: u16) -> Option<Self> {
Some(match ot {
0x06 => Self::Label,
0x07 => Self::Button,
0x0B => Self::CheckBox,
0x0C => Self::OptionButton,
0x10 => Self::Spinner,
0x11 => Self::ScrollBar,
0x12 => Self::ListBox,
0x13 => Self::GroupBox,
0x14 => Self::ComboBox,
_ => return None,
})
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CheckState {
Unchecked,
Checked,
Mixed,
}
impl CheckState {
pub(crate) fn from_number(value: u32) -> Self {
match value {
0 => Self::Unchecked,
1 => Self::Checked,
_ => Self::Mixed,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct ScrollValues {
pub value: i32,
pub min: i32,
pub max: i32,
pub step: i32,
pub page: i32,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FormControl {
pub kind: ControlKind,
pub anchor: Anchor,
pub text: Option<String>,
pub linked_cell: Option<String>,
pub input_range: Option<String>,
pub checked: Option<CheckState>,
pub scroll: Option<ScrollValues>,
pub macro_name: Option<String>,
pub font: Option<Font>,
}
impl FormControl {
#[must_use]
pub fn new(kind: ControlKind, anchor: Anchor) -> Self {
Self {
kind,
anchor,
text: None,
linked_cell: None,
input_range: None,
checked: None,
scroll: None,
macro_name: None,
font: None,
}
}
}