1use std::cell::RefCell;
25use std::rc::Rc;
26
27use crate::oxml::shape::Sp as OxmlSp;
28use crate::oxml::slidemaster::SldMaster as OxmlSldMaster;
29
30#[derive(Debug, Clone)]
35pub struct SlideMasterRef {
36 #[allow(dead_code)]
38 pub(crate) idx: usize,
39 pub(crate) partname: String,
41 pub(crate) rid: String,
43 pub(crate) oxml: Rc<RefCell<OxmlSldMaster>>,
45}
46
47impl SlideMasterRef {
48 pub fn partname(&self) -> &str {
50 &self.partname
51 }
52 pub fn rid(&self) -> &str {
54 &self.rid
55 }
56
57 pub fn shapes(&self) -> Vec<OxmlSp> {
59 self.oxml.borrow().shapes.clone()
60 }
61 pub fn shapes_mut(&self) -> std::cell::RefMut<'_, Vec<OxmlSp>> {
63 std::cell::RefMut::map(self.oxml.borrow_mut(), |s| &mut s.shapes)
64 }
65
66 pub fn placeholders(&self) -> Vec<crate::slide_layouts::Placeholder> {
68 self.oxml
69 .borrow()
70 .shapes
71 .iter()
72 .filter(|s| s.is_placeholder)
73 .map(|s| crate::slide_layouts::Placeholder {
74 idx: s.ph_idx.unwrap_or(0),
75 ph_type: s.ph_type.clone().unwrap_or_else(|| "body".to_string()),
76 name: s.name.clone(),
77 })
78 .collect()
79 }
80
81 pub fn background(&self) -> Option<crate::oxml::slide::SlideBackground> {
88 self.oxml.borrow().background.clone()
89 }
90
91 pub fn set_background(&self, bg: Option<crate::oxml::slide::SlideBackground>) {
93 self.oxml.borrow_mut().background = bg;
94 }
95
96 pub fn set_background_solid(&self, color: crate::oxml::color::Color) {
101 self.oxml.borrow_mut().background = Some(crate::oxml::slide::SlideBackground::solid(color));
102 }
103
104 pub fn clear_background(&self) {
106 self.oxml.borrow_mut().background = None;
107 }
108
109 pub fn add_shape(&self, sp: OxmlSp) {
114 self.oxml.borrow_mut().shapes.push(sp);
115 }
116
117 pub fn remove_shape(&self, id: u32) -> Option<OxmlSp> {
119 let mut oxml = self.oxml.borrow_mut();
120 let pos = oxml.shapes.iter().position(|s| s.id == id)?;
121 Some(oxml.shapes.remove(pos))
122 }
123}
124
125#[derive(Debug, Default, Clone)]
130pub struct SlideMasters {
131 pub(crate) items: Vec<SlideMasterRef>,
132}
133
134impl SlideMasters {
135 pub fn new() -> Self {
137 SlideMasters::default()
138 }
139 pub fn len(&self) -> usize {
141 self.items.len()
142 }
143 pub fn is_empty(&self) -> bool {
145 self.items.is_empty()
146 }
147 pub fn iter(&self) -> std::slice::Iter<'_, SlideMasterRef> {
149 self.items.iter()
150 }
151 pub fn get(&self, idx: usize) -> Option<&SlideMasterRef> {
153 self.items.get(idx)
154 }
155 pub fn get_mut(&mut self, idx: usize) -> Option<&mut SlideMasterRef> {
157 self.items.get_mut(idx)
158 }
159
160 pub fn at(&self, idx: usize) -> Option<SlideMaster> {
164 self.items.get(idx).map(|_| SlideMaster {})
165 }
166
167 pub fn push(&mut self, master: SlideMasterRef) {
169 self.items.push(master);
170 }
171}
172
173#[derive(Debug, Clone)]
178pub struct SlideMaster {}