umya_spreadsheet/structs/drawing/spreadsheet/
non_visual_drawing_properties.rs1use std::io::Cursor;
3
4use quick_xml::{
5 Reader,
6 Writer,
7 events::{
8 BytesStart,
9 Event,
10 },
11};
12
13use super::super::super::{
14 BooleanValue,
15 StringValue,
16 UInt32Value,
17};
18use crate::{
19 reader::driver::{
20 get_attribute,
21 set_string_from_xml,
22 xml_read_loop,
23 },
24 writer::driver::{
25 write_end_tag,
26 write_start_tag,
27 },
28};
29
30#[derive(Clone, Default, Debug)]
31pub struct NonVisualDrawingProperties {
32 id: UInt32Value,
33 name: StringValue,
34 hidden: BooleanValue,
35}
36
37impl NonVisualDrawingProperties {
38 #[inline]
39 #[must_use]
40 pub fn id(&self) -> u32 {
41 self.id.value()
42 }
43
44 #[inline]
45 #[must_use]
46 #[deprecated(since = "3.0.0", note = "Use id()")]
47 pub fn get_id(&self) -> u32 {
48 self.id()
49 }
50
51 #[inline]
52 pub fn set_id(&mut self, value: u32) -> &mut Self {
53 self.id.set_value(value);
54 self
55 }
56
57 #[inline]
58 #[must_use]
59 pub fn name(&self) -> &str {
60 self.name.value_str()
61 }
62
63 #[inline]
64 #[must_use]
65 #[deprecated(since = "3.0.0", note = "Use name()")]
66 pub fn get_name(&self) -> &str {
67 self.name()
68 }
69
70 #[inline]
71 pub fn set_name<S: Into<String>>(&mut self, value: S) -> &mut Self {
72 self.name.set_value(value);
73 self
74 }
75
76 #[inline]
77 #[must_use]
78 pub fn hidden(&self) -> bool {
79 self.hidden.value()
80 }
81
82 #[inline]
83 #[must_use]
84 #[deprecated(since = "3.0.0", note = "Use hidden()")]
85 pub fn get_hidden(&self) -> bool {
86 self.hidden()
87 }
88
89 #[inline]
90 pub fn set_hidden(&mut self, value: bool) -> &mut Self {
91 self.hidden.set_value(value);
92 self
93 }
94
95 pub(crate) fn set_attributes<R: std::io::BufRead>(
96 &mut self,
97 reader: &mut Reader<R>,
98 e: &BytesStart,
99 empty_flg: bool,
100 ) {
101 self.id.set_value_string(get_attribute(e, b"id").unwrap());
102 self.name
103 .set_value_string(get_attribute(e, b"name").unwrap());
104 set_string_from_xml!(self, e, hidden, "hidden");
105
106 if empty_flg {
107 return;
108 }
109
110 xml_read_loop!(
111 reader,
112 Event::End(ref e) => {
113 if matches!(e.name().into_inner(), b"xdr:cNvPr" | b"cNvPr") {
114 return;
115 }
116 },
117 Event::Eof => panic!("Error: Could not find {} end element", "cNvPr")
118 );
119 }
120
121 pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>, ole_id: usize) {
122 let with_inner = ole_id > 0;
123 let mut attributes: crate::structs::AttrCollection = Vec::new();
125 let id = self.id.value_string();
126 attributes.push(("id", &id).into());
127 attributes.push(("name", self.name.value_str()).into());
128 if self.hidden.has_value() {
129 attributes.push(("hidden", self.hidden.value_string()).into());
130 }
131 write_start_tag(writer, "xdr:cNvPr", attributes, !with_inner);
132
133 if with_inner {
134 let spid = format!("_x0000_s{ole_id}");
135 write_start_tag(writer, "a:extLst", vec![], false);
136 write_start_tag(
137 writer,
138 "a:ext",
139 vec![("uri", "{63B3BB69-23CF-44E3-9099-C40C66FF867C}").into()],
140 false,
141 );
142 write_start_tag(writer, "a14:compatExt", vec![("spid", &spid).into()], true);
143
144 write_end_tag(writer, "a:ext");
145 write_end_tag(writer, "a:extLst");
146 write_end_tag(writer, "xdr:cNvPr");
147 }
148 }
149}