1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// a:sysClr
use super::super::super::EnumValue;
use super::super::super::StringValue;
use super::SystemColorValues;
use quick_xml::events::BytesStart;
use quick_xml::Reader;
use quick_xml::Writer;
use reader::driver::*;
use std::io::Cursor;
use writer::driver::*;

#[derive(Clone, Default, Debug)]
pub struct SystemColor {
    val: EnumValue<SystemColorValues>,
    last_color: StringValue,
}
impl SystemColor {
    pub fn get_val(&self) -> &SystemColorValues {
        self.val.get_value()
    }

    pub fn set_val(&mut self, value: SystemColorValues) -> &mut Self {
        self.val.set_value(value);
        self
    }

    pub fn get_last_color(&self) -> &str {
        self.last_color.get_value()
    }

    pub fn set_last_color<S: Into<String>>(&mut self, value: S) {
        self.last_color.set_value(value.into());
    }

    pub(crate) fn set_attributes<R: std::io::BufRead>(
        &mut self,
        _reader: &mut Reader<R>,
        e: &BytesStart,
    ) {
        match get_attribute(e, b"val") {
            Some(v) => {
                self.val.set_value_string(v);
            }
            None => {}
        }
        match get_attribute(e, b"lastClr") {
            Some(v) => {
                self.last_color.set_value_string(v);
            }
            None => {}
        }
    }

    pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
        // a:srgbClr
        let mut attributes: Vec<(&str, &str)> = Vec::new();
        let val = self.val.get_value_string();
        if self.val.has_value() {
            attributes.push(("val", val));
        }
        let last_color = self.last_color.get_value_string();
        if self.last_color.has_value() {
            attributes.push(("lastClr", last_color));
        }
        write_start_tag(writer, "a:sysClr", attributes, true);
    }
}