use hard_xml::{XmlRead, XmlWrite};
use std::borrow::Cow;
use crate::{
__setter, __string_enum, __xml_test_suites,
formatting::{TableBorders, TableIndent, TableJustification, TableWidth},
};
use super::table_margin::TableMargins;
#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
#[cfg_attr(test, derive(PartialEq))]
#[xml(tag = "w:tblPr")]
pub struct TableProperty<'a> {
#[xml(child = "w:tblStyle")]
pub style_id: Option<TableStyleId<'a>>,
#[xml(child = "w:tblW")]
pub width: Option<TableWidth>,
#[xml(child = "w:jc")]
pub justification: Option<TableJustification>,
#[xml(child = "w:tblInd")]
pub indent: Option<TableIndent>,
#[xml(child = "w:tblBorders")]
pub borders: Option<TableBorders<'a>>,
#[xml(child = "w:tblCellMar")]
pub margins: Option<TableMargins<'a>>,
}
impl<'a> TableProperty<'a> {
__setter!(style_id: Option<TableStyleId<'a>>);
__setter!(justification: Option<TableJustification>);
__setter!(borders: Option<TableBorders<'a>>);
__setter!(indent: Option<TableIndent>);
__setter!(width: Option<TableWidth>);
}
#[derive(Debug, XmlRead, XmlWrite, Clone)]
#[cfg_attr(test, derive(PartialEq))]
#[xml(tag = "w:tblStyle")]
pub struct TableStyleId<'a> {
#[xml(attr = "w:val")]
pub value: Cow<'a, str>,
}
impl<'a, T: Into<Cow<'a, str>>> From<T> for TableStyleId<'a> {
fn from(val: T) -> Self {
TableStyleId { value: val.into() }
}
}
#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
#[cfg_attr(test, derive(PartialEq))]
#[xml(tag = "w:tblStylePr")]
pub struct ConditionalTableProperty<'a> {
#[xml(attr = "type")]
pub condition: Option<ConditionType>,
#[xml(default, child = "w:pPr")]
pub paragraph: Option<super::ParagraphProperty<'a>>,
#[xml(default, child = "w:rPr")]
pub character: Option<super::CharacterProperty<'a>>,
#[xml(default, child = "w:tblPr")]
pub table: Option<TableProperty<'a>>,
#[xml(child = "w:trPr")]
pub table_row: Option<crate::formatting::TableRowProperty>,
#[xml(child = "w:tcPr")]
pub table_cell: Option<crate::formatting::TableCellProperty>,
}
#[derive(Debug, Default, Clone)]
#[cfg_attr(test, derive(PartialEq))]
pub enum ConditionType {
#[default]
WholeTable, FirstRow, LastRow, FirstCol, LastCol, Band1Vert, Band2Vert, Band1Horz, Band2Horz, NeCell, NwCell, SeCell, SwCell, }
__string_enum! {
ConditionType {
WholeTable = "wholeTable",
FirstRow = "firstRow",
LastRow = "lastRow",
FirstCol = "firstCol",
LastCol = "lastCol",
Band1Vert = "band1Vert",
Band2Vert = "band2Vert",
Band1Horz = "band1Horz",
Band2Horz = "band2Horz",
NeCell = "neCell",
NwCell = "nwCell",
SeCell = "seCell",
SwCell = "swCell",
}
}
__xml_test_suites!(
TableProperty,
TableProperty::default(),
r#"<w:tblPr/>"#,
TableProperty::default().style_id("id"),
r#"<w:tblPr><w:tblStyle w:val="id"/></w:tblPr>"#,
TableProperty::default().justification(crate::formatting::TableJustificationVal::Start),
r#"<w:tblPr><w:jc w:val="start"/></w:tblPr>"#,
TableProperty::default().borders(TableBorders::default()),
r#"<w:tblPr><w:tblBorders/></w:tblPr>"#,
TableProperty::default().indent(TableIndent::default()),
r#"<w:tblPr><w:tblInd/></w:tblPr>"#,
TableProperty::default().width(TableWidth::default()),
r#"<w:tblPr><w:tblW/></w:tblPr>"#,
);