umya_spreadsheet/structs/drawing/spreadsheet/
two_cell_anchor.rs1use super::super::super::EnumValue;
3use super::ConnectionShape;
4use super::EditAsValues;
5use super::GraphicFrame;
6use super::GroupShape;
7use super::MarkerType;
8use super::Picture;
9use super::Shape;
10use crate::helper::const_str::MC_NS;
11use crate::helper::const_str::*;
12use crate::reader::driver::*;
13use crate::structs::raw::RawRelationships;
14use crate::structs::BooleanValue;
15use crate::traits::AdjustmentCoordinate;
16use crate::traits::AdjustmentCoordinateWithSheet;
17use crate::writer::driver::*;
18use quick_xml::events::{BytesStart, Event};
19use quick_xml::Reader;
20use quick_xml::Writer;
21use std::io::Cursor;
22
23#[derive(Clone, Default, Debug)]
24pub struct TwoCellAnchor {
25 edit_as: EnumValue<EditAsValues>,
26 from_marker: MarkerType,
27 to_marker: MarkerType,
28 group_shape: Option<Box<GroupShape>>,
29 graphic_frame: Option<Box<GraphicFrame>>,
30 shape: Option<Box<Shape>>,
31 connection_shape: Option<Box<ConnectionShape>>,
32 picture: Option<Box<Picture>>,
33 is_alternate_content: BooleanValue,
34}
35
36impl TwoCellAnchor {
37 #[inline]
38 pub fn get_edit_as(&self) -> &EditAsValues {
39 self.edit_as.get_value()
40 }
41
42 #[inline]
43 pub fn set_edit_as(&mut self, value: EditAsValues) -> &mut Self {
44 self.edit_as.set_value(value);
45 self
46 }
47
48 #[inline]
49 pub fn get_from_marker(&self) -> &MarkerType {
50 &self.from_marker
51 }
52
53 #[inline]
54 pub fn get_from_marker_mut(&mut self) -> &mut MarkerType {
55 &mut self.from_marker
56 }
57
58 #[inline]
59 pub fn set_from_marker(&mut self, value: MarkerType) -> &mut Self {
60 self.from_marker = value;
61 self
62 }
63
64 #[inline]
65 pub fn get_to_marker(&self) -> &MarkerType {
66 &self.to_marker
67 }
68
69 #[inline]
70 pub fn get_to_marker_mut(&mut self) -> &mut MarkerType {
71 &mut self.to_marker
72 }
73
74 #[inline]
75 pub fn set_to_marker(&mut self, value: MarkerType) -> &mut Self {
76 self.to_marker = value;
77 self
78 }
79
80 #[inline]
81 pub fn get_group_shape(&self) -> Option<&GroupShape> {
82 self.group_shape.as_deref()
83 }
84
85 #[inline]
86 pub fn get_group_shape_mut(&mut self) -> Option<&mut GroupShape> {
87 self.group_shape.as_deref_mut()
88 }
89
90 #[inline]
91 pub fn set_group_shape(&mut self, value: GroupShape) -> &mut Self {
92 self.group_shape = Some(Box::new(value));
93 self
94 }
95
96 #[inline]
97 pub fn get_graphic_frame(&self) -> Option<&GraphicFrame> {
98 self.graphic_frame.as_deref()
99 }
100
101 #[inline]
102 pub fn get_graphic_frame_mut(&mut self) -> Option<&mut GraphicFrame> {
103 self.graphic_frame.as_deref_mut()
104 }
105
106 #[inline]
107 pub fn set_graphic_frame(&mut self, value: GraphicFrame) -> &mut Self {
108 self.graphic_frame = Some(Box::new(value));
109 self
110 }
111
112 #[inline]
113 pub fn get_shape(&self) -> Option<&Shape> {
114 self.shape.as_deref()
115 }
116
117 #[inline]
118 pub fn get_shape_mut(&mut self) -> Option<&mut Shape> {
119 self.shape.as_deref_mut()
120 }
121
122 #[inline]
123 pub fn set_shape(&mut self, value: Shape) -> &mut Self {
124 self.shape = Some(Box::new(value));
125 self
126 }
127
128 #[inline]
129 pub fn get_connection_shape(&self) -> Option<&ConnectionShape> {
130 self.connection_shape.as_deref()
131 }
132
133 #[inline]
134 pub fn get_connection_shape_mut(&mut self) -> Option<&mut ConnectionShape> {
135 self.connection_shape.as_deref_mut()
136 }
137
138 #[inline]
139 pub fn set_connection_shape(&mut self, value: ConnectionShape) -> &mut Self {
140 self.connection_shape = Some(Box::new(value));
141 self
142 }
143
144 #[inline]
145 pub fn get_picture(&self) -> Option<&Picture> {
146 self.picture.as_deref()
147 }
148
149 #[inline]
150 pub fn get_picture_mut(&mut self) -> Option<&mut Picture> {
151 self.picture.as_deref_mut()
152 }
153
154 #[inline]
155 pub fn set_picture(&mut self, value: Picture) -> &mut Self {
156 self.picture = Some(Box::new(value));
157 self
158 }
159
160 #[inline]
161 pub fn get_is_alternate_content(&self) -> &bool {
162 self.is_alternate_content.get_value()
163 }
164
165 #[inline]
166 pub fn set_is_alternate_content(&mut self, value: bool) -> &mut Self {
167 self.is_alternate_content.set_value(value);
168 self
169 }
170
171 #[inline]
172 pub(crate) fn is_support(&self) -> bool {
173 self.graphic_frame.as_ref().map_or(true, |v| {
174 v.get_graphic()
175 .get_graphic_data()
176 .get_chart_space()
177 .get_chart()
178 .get_plot_area()
179 .is_support()
180 })
181 }
182
183 #[inline]
184 pub(crate) fn is_chart(&self) -> bool {
185 self.graphic_frame.is_some()
186 }
187
188 #[inline]
189 pub(crate) fn is_image(&self) -> bool {
190 self.picture.is_some() || self.group_shape.is_some()
191 }
192
193 pub(crate) fn set_attributes<R: std::io::BufRead>(
194 &mut self,
195 reader: &mut Reader<R>,
196 e: &BytesStart,
197 drawing_relationships: Option<&RawRelationships>,
198 ) {
199 set_string_from_xml!(self, e, edit_as, "editAs");
200
201 xml_read_loop!(
202 reader,
203 Event::Start(ref e) => {
204 match e.name().into_inner() {
205 b"xdr:from" => {
206 self.from_marker.set_attributes(reader, e);
207 }
208 b"xdr:to" => {
209 self.to_marker.set_attributes(reader, e);
210 }
211 b"xdr:grpSp" => {
212 let mut obj = GroupShape::default();
213 obj.set_attributes(reader, e, drawing_relationships);
214 self.set_group_shape(obj);
215 }
216 b"xdr:graphicFrame" => {
217 let mut obj = GraphicFrame::default();
218 obj.set_attributes(reader, e, drawing_relationships);
219 self.set_graphic_frame(obj);
220 }
221 b"xdr:sp" => {
222 let mut obj = Shape::default();
223 obj.set_attributes(reader, e, drawing_relationships);
224 self.set_shape(obj);
225 }
226 b"xdr:cxnSp" => {
227 let mut obj = ConnectionShape::default();
228 obj.set_attributes(reader, e, drawing_relationships);
229 self.set_connection_shape(obj);
230 }
231 b"xdr:pic" => {
232 let mut obj = Picture::default();
233 obj.set_attributes(reader, e, drawing_relationships);
234 self.set_picture(obj);
235 }
236 _ => (),
237 }
238 },
239 Event::End(ref e) => {
240 if e.name().into_inner() == b"xdr:twoCellAnchor" {
241 return
242 }
243 },
244 Event::Eof => panic!("Error: Could not find {} end element", "xdr:twoCellAnchor")
245 );
246 }
247
248 pub(crate) fn write_to(
249 &self,
250 writer: &mut Writer<Cursor<Vec<u8>>>,
251 rel_list: &mut Vec<(String, String)>,
252 ole_id: &usize,
253 ) {
254 if *self.get_is_alternate_content() {
255 write_start_tag(
257 writer,
258 "mc:AlternateContent",
259 vec![("xmlns:mc", MC_NS)],
260 false,
261 );
262
263 write_start_tag(
265 writer,
266 "mc:Choice",
267 vec![("xmlns:a14", DRAWING_MAIN_NS), ("Requires", "a14")],
268 false,
269 );
270 }
271
272 let mut attributes: Vec<(&str, &str)> = Vec::new();
274 if self.edit_as.has_value() {
275 attributes.push(("editAs", self.edit_as.get_value_string()));
276 }
277 write_start_tag(writer, "xdr:twoCellAnchor", attributes, false);
278
279 self.from_marker.write_to_from(writer);
281
282 self.to_marker.write_to_to(writer);
284
285 if let Some(v) = &self.group_shape {
287 v.write_to(writer, rel_list);
288 }
289
290 if let Some(v) = &self.graphic_frame {
292 v.write_to(writer, rel_list);
293 }
294
295 if let Some(v) = &self.shape {
297 v.write_to(writer, rel_list, ole_id);
298 }
299
300 if let Some(v) = &self.connection_shape {
302 v.write_to(writer, rel_list)
303 }
304
305 if let Some(v) = &self.picture {
307 v.write_to(writer, rel_list);
308 }
309
310 write_start_tag(writer, "xdr:clientData", vec![], true);
312
313 write_end_tag(writer, "xdr:twoCellAnchor");
314
315 if *self.get_is_alternate_content() {
316 write_end_tag(writer, "mc:Choice");
317
318 write_start_tag(writer, "mc:Fallback", vec![], true);
320
321 write_end_tag(writer, "mc:AlternateContent");
322 }
323 }
324}
325impl AdjustmentCoordinate for TwoCellAnchor {
326 #[inline]
327 fn adjustment_insert_coordinate(
328 &mut self,
329 root_col_num: &u32,
330 offset_col_num: &u32,
331 root_row_num: &u32,
332 offset_row_num: &u32,
333 ) {
334 self.from_marker.adjustment_insert_coordinate(
335 root_col_num,
336 offset_col_num,
337 root_row_num,
338 offset_row_num,
339 );
340 self.to_marker.adjustment_insert_coordinate(
341 root_col_num,
342 offset_col_num,
343 root_row_num,
344 offset_row_num,
345 );
346 }
347
348 #[inline]
349 fn adjustment_remove_coordinate(
350 &mut self,
351 root_col_num: &u32,
352 offset_col_num: &u32,
353 root_row_num: &u32,
354 offset_row_num: &u32,
355 ) {
356 self.from_marker.adjustment_remove_coordinate(
357 root_col_num,
358 offset_col_num,
359 root_row_num,
360 offset_row_num,
361 );
362 self.to_marker.adjustment_remove_coordinate(
363 root_col_num,
364 offset_col_num,
365 root_row_num,
366 offset_row_num,
367 );
368 }
369
370 #[inline]
371 fn is_remove_coordinate(
372 &self,
373 root_col_num: &u32,
374 offset_col_num: &u32,
375 root_row_num: &u32,
376 offset_row_num: &u32,
377 ) -> bool {
378 self.from_marker.is_remove_coordinate(
379 root_col_num,
380 offset_col_num,
381 root_row_num,
382 offset_row_num,
383 ) || self.to_marker.is_remove_coordinate(
384 root_col_num,
385 offset_col_num,
386 root_row_num,
387 offset_row_num,
388 )
389 }
390}
391impl AdjustmentCoordinateWithSheet for TwoCellAnchor {
392 #[inline]
393 fn adjustment_insert_coordinate_with_sheet(
394 &mut self,
395 sheet_name: &str,
396 root_col_num: &u32,
397 offset_col_num: &u32,
398 root_row_num: &u32,
399 offset_row_num: &u32,
400 ) {
401 match &mut self.graphic_frame {
402 Some(v) => {
403 v.adjustment_insert_coordinate_with_sheet(
404 sheet_name,
405 root_col_num,
406 offset_col_num,
407 root_row_num,
408 offset_row_num,
409 );
410 }
411 None => {}
412 }
413 }
414
415 #[inline]
416 fn adjustment_remove_coordinate_with_sheet(
417 &mut self,
418 sheet_name: &str,
419 root_col_num: &u32,
420 offset_col_num: &u32,
421 root_row_num: &u32,
422 offset_row_num: &u32,
423 ) {
424 match &mut self.graphic_frame {
425 Some(v) => {
426 v.adjustment_remove_coordinate_with_sheet(
427 sheet_name,
428 root_col_num,
429 offset_col_num,
430 root_row_num,
431 offset_row_num,
432 );
433 }
434 None => {}
435 }
436 }
437}