umya_spreadsheet/structs/drawing/
list_style.rs

1// a:lstStyle
2use super::EffectList;
3use super::TextParagraphPropertiesType;
4use crate::reader::driver::*;
5use crate::writer::driver::*;
6use quick_xml::events::{BytesStart, Event};
7use quick_xml::Reader;
8use quick_xml::Writer;
9use std::collections::HashMap;
10use std::io::Cursor;
11
12#[derive(Clone, Default, Debug)]
13pub struct ListStyle {
14    effect_list: Option<Box<EffectList>>,
15    text_paragraph_properties_type: HashMap<Box<str>, Box<TextParagraphPropertiesType>>,
16}
17
18impl ListStyle {
19    #[inline]
20    pub fn get_effect_list(&self) -> Option<&EffectList> {
21        self.effect_list.as_deref()
22    }
23
24    #[inline]
25    pub fn get_effect_list_mut(&mut self) -> Option<&mut EffectList> {
26        self.effect_list.as_deref_mut()
27    }
28
29    #[inline]
30    pub fn set_effect_list(&mut self, value: EffectList) -> &mut Self {
31        self.effect_list = Some(Box::new(value));
32        self
33    }
34
35    #[inline]
36    pub fn get_default_paragraph_properties(&self) -> Option<&TextParagraphPropertiesType> {
37        self.text_paragraph_properties_type
38            .get("def")
39            .map(Box::as_ref)
40    }
41
42    #[inline]
43    pub fn get_default_paragraph_properties_mut(
44        &mut self,
45    ) -> Option<&mut TextParagraphPropertiesType> {
46        self.text_paragraph_properties_type
47            .get_mut("def")
48            .map(Box::as_mut)
49    }
50
51    #[inline]
52    pub fn set_default_paragraph_properties(
53        &mut self,
54        value: TextParagraphPropertiesType,
55    ) -> &mut Self {
56        self.text_paragraph_properties_type
57            .insert(String::from("def").into_boxed_str(), Box::new(value));
58        self
59    }
60
61    #[inline]
62    pub fn get_level1_paragraph_properties(&self) -> Option<&TextParagraphPropertiesType> {
63        self.text_paragraph_properties_type
64            .get("lv1")
65            .map(Box::as_ref)
66    }
67
68    #[inline]
69    pub fn get_level1_paragraph_properties_mut(
70        &mut self,
71    ) -> Option<&mut TextParagraphPropertiesType> {
72        self.text_paragraph_properties_type
73            .get_mut("lv1")
74            .map(Box::as_mut)
75    }
76
77    #[inline]
78    pub fn set_level1_paragraph_properties(
79        &mut self,
80        value: TextParagraphPropertiesType,
81    ) -> &mut Self {
82        self.text_paragraph_properties_type
83            .insert(String::from("lv1").into_boxed_str(), Box::new(value));
84        self
85    }
86
87    #[inline]
88    pub fn get_level2_paragraph_properties(&self) -> Option<&TextParagraphPropertiesType> {
89        self.text_paragraph_properties_type
90            .get("lv2")
91            .map(Box::as_ref)
92    }
93
94    #[inline]
95    pub fn get_level2_paragraph_properties_mut(
96        &mut self,
97    ) -> Option<&mut TextParagraphPropertiesType> {
98        self.text_paragraph_properties_type
99            .get_mut("lv2")
100            .map(Box::as_mut)
101    }
102
103    #[inline]
104    pub fn set_level2_paragraph_properties(
105        &mut self,
106        value: TextParagraphPropertiesType,
107    ) -> &mut Self {
108        self.text_paragraph_properties_type
109            .insert(String::from("lv2").into_boxed_str(), Box::new(value));
110        self
111    }
112
113    #[inline]
114    pub fn get_level3_paragraph_properties(&self) -> Option<&TextParagraphPropertiesType> {
115        self.text_paragraph_properties_type
116            .get("lv3")
117            .map(Box::as_ref)
118    }
119
120    #[inline]
121    pub fn get_level3_paragraph_properties_mut(
122        &mut self,
123    ) -> Option<&mut TextParagraphPropertiesType> {
124        self.text_paragraph_properties_type
125            .get_mut("lv3")
126            .map(Box::as_mut)
127    }
128
129    #[inline]
130    pub fn set_level3_paragraph_properties(
131        &mut self,
132        value: TextParagraphPropertiesType,
133    ) -> &mut Self {
134        self.text_paragraph_properties_type
135            .insert(String::from("lv3").into_boxed_str(), Box::new(value));
136        self
137    }
138
139    #[inline]
140    pub fn get_level4_paragraph_properties(&self) -> Option<&TextParagraphPropertiesType> {
141        self.text_paragraph_properties_type
142            .get("lv4")
143            .map(Box::as_ref)
144    }
145
146    #[inline]
147    pub fn get_level4_paragraph_properties_mut(
148        &mut self,
149    ) -> Option<&mut TextParagraphPropertiesType> {
150        self.text_paragraph_properties_type
151            .get_mut("lv4")
152            .map(Box::as_mut)
153    }
154
155    #[inline]
156    pub fn set_level4_paragraph_properties(
157        &mut self,
158        value: TextParagraphPropertiesType,
159    ) -> &mut Self {
160        self.text_paragraph_properties_type
161            .insert(String::from("lv4").into_boxed_str(), Box::new(value));
162        self
163    }
164
165    #[inline]
166    pub fn get_level5_paragraph_properties(&self) -> Option<&TextParagraphPropertiesType> {
167        self.text_paragraph_properties_type
168            .get("lv5")
169            .map(Box::as_ref)
170    }
171
172    #[inline]
173    pub fn get_level5_paragraph_properties_mut(
174        &mut self,
175    ) -> Option<&mut TextParagraphPropertiesType> {
176        self.text_paragraph_properties_type
177            .get_mut("lv5")
178            .map(Box::as_mut)
179    }
180
181    #[inline]
182    pub fn set_level5_paragraph_properties(
183        &mut self,
184        value: TextParagraphPropertiesType,
185    ) -> &mut Self {
186        self.text_paragraph_properties_type
187            .insert(String::from("lv5").into_boxed_str(), Box::new(value));
188        self
189    }
190
191    #[inline]
192    pub fn get_level6_paragraph_properties(&self) -> Option<&TextParagraphPropertiesType> {
193        self.text_paragraph_properties_type
194            .get("lv6")
195            .map(Box::as_ref)
196    }
197
198    #[inline]
199    pub fn get_level6_paragraph_properties_mut(
200        &mut self,
201    ) -> Option<&mut TextParagraphPropertiesType> {
202        self.text_paragraph_properties_type
203            .get_mut("lv6")
204            .map(Box::as_mut)
205    }
206
207    #[inline]
208    pub fn set_level6_paragraph_properties(
209        &mut self,
210        value: TextParagraphPropertiesType,
211    ) -> &mut Self {
212        self.text_paragraph_properties_type
213            .insert(String::from("lv6").into_boxed_str(), Box::new(value));
214        self
215    }
216
217    #[inline]
218    pub fn get_level7_paragraph_properties(&self) -> Option<&TextParagraphPropertiesType> {
219        self.text_paragraph_properties_type
220            .get("lv7")
221            .map(Box::as_ref)
222    }
223
224    #[inline]
225    pub fn get_level7_paragraph_properties_mut(
226        &mut self,
227    ) -> Option<&mut TextParagraphPropertiesType> {
228        self.text_paragraph_properties_type
229            .get_mut("lv7")
230            .map(Box::as_mut)
231    }
232
233    #[inline]
234    pub fn set_level7_paragraph_properties(
235        &mut self,
236        value: TextParagraphPropertiesType,
237    ) -> &mut Self {
238        self.text_paragraph_properties_type
239            .insert(String::from("lv7").into_boxed_str(), Box::new(value));
240        self
241    }
242
243    #[inline]
244    pub fn get_level8_paragraph_properties(&self) -> Option<&TextParagraphPropertiesType> {
245        self.text_paragraph_properties_type
246            .get("lv8")
247            .map(Box::as_ref)
248    }
249
250    #[inline]
251    pub fn get_level8_paragraph_properties_mut(
252        &mut self,
253    ) -> Option<&mut TextParagraphPropertiesType> {
254        self.text_paragraph_properties_type
255            .get_mut("lv8")
256            .map(Box::as_mut)
257    }
258
259    #[inline]
260    pub fn set_level8_paragraph_properties(
261        &mut self,
262        value: TextParagraphPropertiesType,
263    ) -> &mut Self {
264        self.text_paragraph_properties_type
265            .insert(String::from("lv8").into_boxed_str(), Box::new(value));
266        self
267    }
268
269    #[inline]
270    pub fn get_level9_paragraph_properties(&self) -> Option<&TextParagraphPropertiesType> {
271        self.text_paragraph_properties_type
272            .get("lv9")
273            .map(Box::as_ref)
274    }
275
276    #[inline]
277    pub fn get_level9_paragraph_properties_mut(
278        &mut self,
279    ) -> Option<&mut TextParagraphPropertiesType> {
280        self.text_paragraph_properties_type
281            .get_mut("lv9")
282            .map(Box::as_mut)
283    }
284
285    #[inline]
286    pub fn set_level9_paragraph_properties(
287        &mut self,
288        value: TextParagraphPropertiesType,
289    ) -> &mut Self {
290        self.text_paragraph_properties_type
291            .insert(String::from("lv9").into_boxed_str(), Box::new(value));
292        self
293    }
294
295    pub(crate) fn set_attributes<R: std::io::BufRead>(
296        &mut self,
297        reader: &mut Reader<R>,
298        _e: &BytesStart,
299    ) {
300        xml_read_loop!(
301            reader,
302            Event::Start(ref e) => {
303                match e.name().into_inner() {
304                    b"a:effectLst" => {
305                        let obj = EffectList::default();
306                        self.set_effect_list(obj);
307                    }
308                    b"a:defPPr" => {
309                        let mut obj = TextParagraphPropertiesType::default();
310                        obj.set_attributes(reader, e);
311                        self.set_default_paragraph_properties(obj);
312                    }
313                    b"a:lvl1pPr" => {
314                        let mut obj = TextParagraphPropertiesType::default();
315                        obj.set_attributes(reader, e);
316                        self.set_level1_paragraph_properties(obj);
317                    }
318                    b"a:lvl2pPr" => {
319                        let mut obj = TextParagraphPropertiesType::default();
320                        obj.set_attributes(reader, e);
321                        self.set_level2_paragraph_properties(obj);
322                    }
323                    b"a:lvl3pPr" => {
324                        let mut obj = TextParagraphPropertiesType::default();
325                        obj.set_attributes(reader, e);
326                        self.set_level3_paragraph_properties(obj);
327                    }
328                    b"a:lvl4pPr" => {
329                        let mut obj = TextParagraphPropertiesType::default();
330                        obj.set_attributes(reader, e);
331                        self.set_level4_paragraph_properties(obj);
332                    }
333                    b"a:lvl5pPr" => {
334                        let mut obj = TextParagraphPropertiesType::default();
335                        obj.set_attributes(reader, e);
336                        self.set_level5_paragraph_properties(obj);
337                    }
338                    b"a:lvl6pPr" => {
339                        let mut obj = TextParagraphPropertiesType::default();
340                        obj.set_attributes(reader, e);
341                        self.set_level6_paragraph_properties(obj);
342                    }
343                    b"a:lvl7pPr" => {
344                        let mut obj = TextParagraphPropertiesType::default();
345                        obj.set_attributes(reader, e);
346                        self.set_level7_paragraph_properties(obj);
347                    }
348                    b"a:lvl8pPr" => {
349                        let mut obj = TextParagraphPropertiesType::default();
350                        obj.set_attributes(reader, e);
351                        self.set_level8_paragraph_properties(obj);
352                    }
353                    b"a:lvl9pPr" => {
354                        let mut obj = TextParagraphPropertiesType::default();
355                        obj.set_attributes(reader, e);
356                        self.set_level9_paragraph_properties(obj);
357                    }
358                    _ => (),
359                }
360            },
361            Event::End(ref e) => {
362                if e.name().into_inner() == b"a:lstStyle" {
363                    return;
364                }
365            },
366            Event::Eof => panic!("Error: Could not find {} end element", "a:lstStyle")
367        );
368    }
369
370    #[inline]
371    fn is_empty(&self) -> bool {
372        self.effect_list.is_none() && self.text_paragraph_properties_type.is_empty()
373    }
374
375    pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
376        // a:lstStyle
377        let is_empty = self.is_empty();
378        write_start_tag(writer, "a:lstStyle", vec![], is_empty);
379
380        // a:defPPr
381        match &self.text_paragraph_properties_type.get("def") {
382            Some(v) => {
383                v.write_to_default(writer);
384            }
385            None => {}
386        }
387
388        // a:lvl1pPr
389        match &self.text_paragraph_properties_type.get("lv1") {
390            Some(v) => {
391                v.write_to_lvl1(writer);
392            }
393            None => {}
394        }
395
396        // a:lvl2pPr
397        match &self.text_paragraph_properties_type.get("lv2") {
398            Some(v) => {
399                v.write_to_lvl2(writer);
400            }
401            None => {}
402        }
403
404        // a:lvl3pPr
405        match &self.text_paragraph_properties_type.get("lv3") {
406            Some(v) => {
407                v.write_to_lvl3(writer);
408            }
409            None => {}
410        }
411
412        // a:lvl4pPr
413        match &self.text_paragraph_properties_type.get("lv4") {
414            Some(v) => {
415                v.write_to_lvl4(writer);
416            }
417            None => {}
418        }
419
420        // a:lvl5pPr
421        match &self.text_paragraph_properties_type.get("lv5") {
422            Some(v) => {
423                v.write_to_lvl5(writer);
424            }
425            None => {}
426        }
427
428        // a:lvl6pPr
429        match &self.text_paragraph_properties_type.get("lv6") {
430            Some(v) => {
431                v.write_to_lvl6(writer);
432            }
433            None => {}
434        }
435
436        // a:lvl7pPr
437        match &self.text_paragraph_properties_type.get("lv7") {
438            Some(v) => {
439                v.write_to_lvl7(writer);
440            }
441            None => {}
442        }
443
444        // a:lvl8pPr
445        match &self.text_paragraph_properties_type.get("lv8") {
446            Some(v) => {
447                v.write_to_lvl8(writer);
448            }
449            None => {}
450        }
451
452        // a:lvl9pPr
453        match &self.text_paragraph_properties_type.get("lv9") {
454            Some(v) => {
455                v.write_to_lvl9(writer);
456            }
457            None => {}
458        }
459
460        if !is_empty {
461            write_end_tag(writer, "a:lstStyle");
462        }
463    }
464}