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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// xdr:graphicFrame
use super::super::super::StringValue;
use super::super::Graphic;
use super::NonVisualGraphicFrameProperties;
use super::Transform;
use structs::raw::RawRelationships;

use quick_xml::events::{BytesStart, Event};
use quick_xml::Reader;
use quick_xml::Writer;
use reader::driver::*;
use std::io::Cursor;
use writer::driver::*;

#[derive(Clone, Default, Debug)]
pub struct GraphicFrame {
    r#macro: StringValue,
    non_visual_graphic_frame_properties: NonVisualGraphicFrameProperties,
    transform: Transform,
    graphic: Graphic,
}

impl GraphicFrame {
    pub fn get_macro(&self) -> &str {
        self.r#macro.get_value()
    }

    pub fn set_macro<S: Into<String>>(&mut self, value: S) -> &mut GraphicFrame {
        self.r#macro.set_value(value);
        self
    }

    pub fn get_non_visual_graphic_frame_properties(&self) -> &NonVisualGraphicFrameProperties {
        &self.non_visual_graphic_frame_properties
    }

    pub fn get_non_visual_graphic_frame_properties_mut(
        &mut self,
    ) -> &mut NonVisualGraphicFrameProperties {
        &mut self.non_visual_graphic_frame_properties
    }

    pub fn set_non_visual_graphic_frame_properties(
        &mut self,
        value: NonVisualGraphicFrameProperties,
    ) -> &mut Self {
        self.non_visual_graphic_frame_properties = value;
        self
    }

    pub fn get_transform(&self) -> &Transform {
        &self.transform
    }

    pub fn get_transform_mut(&mut self) -> &mut Transform {
        &mut self.transform
    }

    pub fn set_transform(&mut self, value: Transform) -> &mut Self {
        self.transform = value;
        self
    }

    pub fn get_graphic(&self) -> &Graphic {
        &self.graphic
    }

    pub fn get_graphic_mut(&mut self) -> &mut Graphic {
        &mut self.graphic
    }

    pub fn set_graphic(&mut self, value: Graphic) -> &mut Self {
        self.graphic = value;
        self
    }

    pub(crate) fn set_attributes<R: std::io::BufRead>(
        &mut self,
        reader: &mut Reader<R>,
        e: &BytesStart,
        drawing_relationships: Option<&RawRelationships>,
    ) {
        set_string_from_xml!(self, e, r#macro, "macro");

        xml_read_loop!(
            reader,
            Event::Start(ref e) => {
                match e.name().into_inner() {
                    b"xdr:nvGraphicFramePr" => {
                        self.non_visual_graphic_frame_properties
                            .set_attributes(reader, e);
                        }
                    b"xdr:xfrm" => {
                        self.transform.set_attributes(reader, e);
                    }
                    b"a:graphic" => {
                        self.graphic
                            .set_attributes(reader, e, drawing_relationships);
                        }
                    _ => (),
                }
            },
            Event::End(ref e) => {
                if  e.name().into_inner() == b"xdr:graphicFrame" {
                    return
                }
            },
            Event::Eof => panic!("Error not find {} end element", "xdr:graphicFrame")
        );
    }

    pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>, r_id: &i32) {
        // xdr:graphicFrame
        write_start_tag(
            writer,
            "xdr:graphicFrame",
            vec![("macro", self.r#macro.get_value_string())],
            false,
        );

        // xdr:nvGraphicFramePr
        let _ = &self.non_visual_graphic_frame_properties.write_to(writer);

        // xdr:xfrm
        let _ = &self.transform.write_to(writer);

        // a:graphic
        let _ = &self.graphic.write_to(writer, r_id);

        write_end_tag(writer, "xdr:graphicFrame");
    }
}