umya_spreadsheet/structs/drawing/spreadsheet/
one_cell_anchor.rs1use super::Extent;
3use super::GroupShape;
4use super::MarkerType;
5use super::Picture;
6use super::Shape;
7use crate::reader::driver::*;
8use crate::structs::raw::RawRelationships;
9use crate::traits::AdjustmentCoordinate;
10use crate::writer::driver::*;
11use quick_xml::events::{BytesStart, Event};
12use quick_xml::Reader;
13use quick_xml::Writer;
14use std::io::Cursor;
15
16#[derive(Clone, Default, Debug)]
17pub struct OneCellAnchor {
18 from_marker: MarkerType,
19 extent: Extent,
20 group_shape: Option<Box<GroupShape>>,
21 shape: Option<Box<Shape>>,
22 picture: Option<Box<Picture>>,
23}
24
25impl OneCellAnchor {
26 #[inline]
27 pub fn get_from_marker(&self) -> &MarkerType {
28 &self.from_marker
29 }
30
31 #[inline]
32 pub fn get_from_marker_mut(&mut self) -> &mut MarkerType {
33 &mut self.from_marker
34 }
35
36 #[inline]
37 pub fn set_from_marker(&mut self, value: MarkerType) -> &mut OneCellAnchor {
38 self.from_marker = value;
39 self
40 }
41
42 #[inline]
43 pub fn get_extent(&self) -> &Extent {
44 &self.extent
45 }
46
47 #[inline]
48 pub fn get_extent_mut(&mut self) -> &mut Extent {
49 &mut self.extent
50 }
51
52 #[inline]
53 pub fn set_extent(&mut self, value: Extent) -> &mut OneCellAnchor {
54 self.extent = value;
55 self
56 }
57
58 #[inline]
59 pub fn get_group_shape(&self) -> Option<&GroupShape> {
60 self.group_shape.as_deref()
61 }
62
63 #[inline]
64 pub fn get_group_shape_mut(&mut self) -> Option<&mut GroupShape> {
65 self.group_shape.as_deref_mut()
66 }
67
68 #[inline]
69 pub fn set_group_shape(&mut self, value: GroupShape) -> &mut Self {
70 self.group_shape = Some(Box::new(value));
71 self
72 }
73
74 #[inline]
75 pub fn get_shape(&self) -> Option<&Shape> {
76 self.shape.as_deref()
77 }
78
79 #[inline]
80 pub fn get_shape_mut(&mut self) -> Option<&mut Shape> {
81 self.shape.as_deref_mut()
82 }
83
84 #[inline]
85 pub fn set_shape(&mut self, value: Shape) -> &mut OneCellAnchor {
86 self.shape = Some(Box::new(value));
87 self
88 }
89
90 #[inline]
91 pub fn get_picture(&self) -> Option<&Picture> {
92 self.picture.as_deref()
93 }
94
95 #[inline]
96 pub fn get_picture_mut(&mut self) -> Option<&mut Picture> {
97 self.picture.as_deref_mut()
98 }
99
100 #[inline]
101 pub fn set_picture(&mut self, value: Picture) -> &mut Self {
102 self.picture = Some(Box::new(value));
103 self
104 }
105
106 #[inline]
107 pub(crate) fn is_image(&self) -> bool {
108 self.picture.is_some() || self.group_shape.is_some()
109 }
110
111 pub(crate) fn set_attributes<R: std::io::BufRead>(
112 &mut self,
113 reader: &mut Reader<R>,
114 _e: &BytesStart,
115 drawing_relationships: Option<&RawRelationships>,
116 ) {
117 xml_read_loop!(
118 reader,
119 Event::Start(ref e) => {
120 match e.name().into_inner() {
121 b"xdr:from" => {
122 self.from_marker.set_attributes(reader, e);
123 }
124 b"xdr:grpSp" => {
125 let mut obj = GroupShape::default();
126 obj.set_attributes(reader, e, drawing_relationships);
127 self.set_group_shape(obj);
128 }
129 b"xdr:sp" => {
130 let mut obj = Shape::default();
131 obj.set_attributes(reader, e, drawing_relationships);
132 self.set_shape(obj);
133 }
134 b"xdr:pic" => {
135 let mut obj = Picture::default();
136 obj.set_attributes(reader, e, drawing_relationships);
137 self.set_picture(obj);
138 }
139 _ => (),
140 }
141 },
142 Event::Empty(ref e) => {
143 if e.name().into_inner() == b"xdr:ext" {
144 self.extent.set_attributes(reader, e);
145 }
146 },
147 Event::End(ref e) => {
148 if e.name().into_inner() == b"xdr:oneCellAnchor" {
149 return
150 }
151 },
152 Event::Eof => panic!("Error: Could not find {} end element", "xdr:oneCellAnchor")
153 );
154 }
155
156 pub(crate) fn write_to(
157 &self,
158 writer: &mut Writer<Cursor<Vec<u8>>>,
159 rel_list: &mut Vec<(String, String)>,
160 ) {
161 write_start_tag(writer, "xdr:oneCellAnchor", vec![], false);
163
164 self.from_marker.write_to_from(writer);
166
167 self.extent.write_to(writer);
169
170 if let Some(v) = &self.group_shape {
172 v.write_to(writer, rel_list);
173 }
174
175 if let Some(v) = &self.shape {
177 v.write_to(writer, rel_list, &0);
178 }
179
180 if let Some(v) = &self.picture {
182 v.write_to(writer, rel_list);
183 }
184
185 write_start_tag(writer, "xdr:clientData", vec![], true);
187
188 write_end_tag(writer, "xdr:oneCellAnchor");
189 }
190}
191impl AdjustmentCoordinate for OneCellAnchor {
192 #[inline]
193 fn adjustment_insert_coordinate(
194 &mut self,
195 root_col_num: &u32,
196 offset_col_num: &u32,
197 root_row_num: &u32,
198 offset_row_num: &u32,
199 ) {
200 self.from_marker.adjustment_insert_coordinate(
201 root_col_num,
202 offset_col_num,
203 root_row_num,
204 offset_row_num,
205 );
206 }
207
208 #[inline]
209 fn adjustment_remove_coordinate(
210 &mut self,
211 root_col_num: &u32,
212 offset_col_num: &u32,
213 root_row_num: &u32,
214 offset_row_num: &u32,
215 ) {
216 self.from_marker.adjustment_remove_coordinate(
217 root_col_num,
218 offset_col_num,
219 root_row_num,
220 offset_row_num,
221 );
222 }
223
224 #[inline]
225 fn is_remove_coordinate(
226 &self,
227 root_col_num: &u32,
228 offset_col_num: &u32,
229 root_row_num: &u32,
230 offset_row_num: &u32,
231 ) -> bool {
232 self.from_marker.is_remove_coordinate(
233 root_col_num,
234 offset_col_num,
235 root_row_num,
236 offset_row_num,
237 )
238 }
239}