umya_spreadsheet/structs/drawing/spreadsheet/
graphic_frame.rs

1// xdr:graphicFrame
2use super::super::super::StringValue;
3use super::super::Graphic;
4use super::NonVisualGraphicFrameProperties;
5use super::Transform;
6use crate::reader::driver::*;
7use crate::structs::raw::RawRelationships;
8use crate::traits::AdjustmentCoordinateWithSheet;
9use crate::writer::driver::*;
10use quick_xml::events::{BytesStart, Event};
11use quick_xml::Reader;
12use quick_xml::Writer;
13use std::io::Cursor;
14
15#[derive(Clone, Default, Debug)]
16pub struct GraphicFrame {
17    r#macro: StringValue,
18    non_visual_graphic_frame_properties: NonVisualGraphicFrameProperties,
19    transform: Transform,
20    graphic: Graphic,
21}
22
23impl GraphicFrame {
24    #[inline]
25    pub fn get_macro(&self) -> &str {
26        self.r#macro.get_value_str()
27    }
28
29    #[inline]
30    pub fn set_macro<S: Into<String>>(&mut self, value: S) -> &mut GraphicFrame {
31        self.r#macro.set_value(value);
32        self
33    }
34
35    #[inline]
36    pub fn get_non_visual_graphic_frame_properties(&self) -> &NonVisualGraphicFrameProperties {
37        &self.non_visual_graphic_frame_properties
38    }
39
40    #[inline]
41    pub fn get_non_visual_graphic_frame_properties_mut(
42        &mut self,
43    ) -> &mut NonVisualGraphicFrameProperties {
44        &mut self.non_visual_graphic_frame_properties
45    }
46
47    #[inline]
48    pub fn set_non_visual_graphic_frame_properties(
49        &mut self,
50        value: NonVisualGraphicFrameProperties,
51    ) -> &mut Self {
52        self.non_visual_graphic_frame_properties = value;
53        self
54    }
55
56    #[inline]
57    pub fn get_transform(&self) -> &Transform {
58        &self.transform
59    }
60
61    #[inline]
62    pub fn get_transform_mut(&mut self) -> &mut Transform {
63        &mut self.transform
64    }
65
66    #[inline]
67    pub fn set_transform(&mut self, value: Transform) -> &mut Self {
68        self.transform = value;
69        self
70    }
71
72    #[inline]
73    pub fn get_graphic(&self) -> &Graphic {
74        &self.graphic
75    }
76
77    #[inline]
78    pub fn get_graphic_mut(&mut self) -> &mut Graphic {
79        &mut self.graphic
80    }
81
82    #[inline]
83    pub fn set_graphic(&mut self, value: Graphic) -> &mut Self {
84        self.graphic = value;
85        self
86    }
87
88    pub(crate) fn set_attributes<R: std::io::BufRead>(
89        &mut self,
90        reader: &mut Reader<R>,
91        e: &BytesStart,
92        drawing_relationships: Option<&RawRelationships>,
93    ) {
94        set_string_from_xml!(self, e, r#macro, "macro");
95
96        xml_read_loop!(
97            reader,
98            Event::Start(ref e) => {
99                match e.name().into_inner() {
100                    b"xdr:nvGraphicFramePr" => {
101                        self.non_visual_graphic_frame_properties
102                            .set_attributes(reader, e);
103                        }
104                    b"xdr:xfrm" => {
105                        self.transform.set_attributes(reader, e);
106                    }
107                    b"a:graphic" => {
108                        self.graphic
109                            .set_attributes(reader, e, drawing_relationships);
110                        }
111                    _ => (),
112                }
113            },
114            Event::End(ref e) => {
115                if  e.name().into_inner() == b"xdr:graphicFrame" {
116                    return
117                }
118            },
119            Event::Eof => panic!("Error: Could not find {} end element", "xdr:graphicFrame")
120        );
121    }
122
123    pub(crate) fn write_to(
124        &self,
125        writer: &mut Writer<Cursor<Vec<u8>>>,
126        rel_list: &mut Vec<(String, String)>,
127    ) {
128        // xdr:graphicFrame
129        write_start_tag(
130            writer,
131            "xdr:graphicFrame",
132            vec![("macro", self.r#macro.get_value_str())],
133            false,
134        );
135
136        // xdr:nvGraphicFramePr
137        self.non_visual_graphic_frame_properties.write_to(writer);
138
139        // xdr:xfrm
140        self.transform.write_to(writer);
141
142        // a:graphic
143        self.graphic.write_to(writer, rel_list);
144
145        write_end_tag(writer, "xdr:graphicFrame");
146    }
147}
148impl AdjustmentCoordinateWithSheet for GraphicFrame {
149    #[inline]
150    fn adjustment_insert_coordinate_with_sheet(
151        &mut self,
152        sheet_name: &str,
153        root_col_num: &u32,
154        offset_col_num: &u32,
155        root_row_num: &u32,
156        offset_row_num: &u32,
157    ) {
158        self.graphic.adjustment_insert_coordinate_with_sheet(
159            sheet_name,
160            root_col_num,
161            offset_col_num,
162            root_row_num,
163            offset_row_num,
164        );
165    }
166
167    #[inline]
168    fn adjustment_remove_coordinate_with_sheet(
169        &mut self,
170        sheet_name: &str,
171        root_col_num: &u32,
172        offset_col_num: &u32,
173        root_row_num: &u32,
174        offset_row_num: &u32,
175    ) {
176        self.graphic.adjustment_remove_coordinate_with_sheet(
177            sheet_name,
178            root_col_num,
179            offset_col_num,
180            root_row_num,
181            offset_row_num,
182        );
183    }
184}