umya_spreadsheet/structs/office2019/
threaded_comment.rs1use crate::office2019::threaded_comment_text::ThreadedCommentText;
3use crate::reader::driver::get_attribute;
4use crate::writer::driver::{write_end_tag, write_start_tag, write_text_node};
5use crate::{
6 set_string_from_xml, xml_read_loop, AdjustmentCoordinate, AdjustmentValue, Coordinate,
7 DateTimeValue, StringValue,
8};
9use quick_xml::events::{BytesStart, Event};
10use quick_xml::{Reader, Writer};
11use std::io::Cursor;
12
13#[derive(Clone, Default, Debug)]
14pub struct ThreadedComment {
15 coordinate: Coordinate,
16 d_t: DateTimeValue,
17 threaded_comment_text: ThreadedCommentText,
18 id: StringValue,
19}
20
21impl ThreadedComment {
22 #[inline]
23 pub fn get_coordinate(&self) -> &Coordinate {
24 &self.coordinate
25 }
26
27 #[inline]
28 pub fn get_coordinate_mut(&mut self) -> &mut Coordinate {
29 &mut self.coordinate
30 }
31
32 #[inline]
33 pub fn get_d_t(&self) -> &str {
34 self.d_t.get_value_str()
35 }
36
37 #[inline]
38 pub fn set_d_t<S: Into<String>>(&mut self, value: S) -> &mut Self {
39 self.d_t.set_value(value);
40 self
41 }
42
43 #[inline]
44 pub fn get_id(&self) -> &str {
45 &self.id.get_value_str()
46 }
47
48 #[inline]
49 pub(crate) fn set_id<S: Into<String>>(&mut self, value: S) -> &mut Self {
50 self.id.set_value(value);
51 self
52 }
53
54 pub(crate) fn set_attributes<R: std::io::BufRead>(
55 &mut self,
56 reader: &mut Reader<R>,
57 e: &BytesStart,
58 ) {
59 let coordinate = get_attribute(e, b"ref").unwrap();
60 self.get_coordinate_mut().set_coordinate(coordinate);
61
62 set_string_from_xml!(self, e, d_t, "dT");
63 set_string_from_xml!(self, e, id, "id");
64
65 xml_read_loop!(
66 reader,
67 Event::Start(ref e) => {
68 if e.name().into_inner() == b"text" {
69 self.threaded_comment_text.set_attributes(reader, e);
70 }
71 },
72 Event::End(ref e) => {
73 if e.name().into_inner() == b"threadedComment" {
74 return
75 }
76 },
77 Event::Eof => panic!("Error: Could not find {} end element", "threadedComment")
78 );
79 }
80
81 pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
82 let mut attributes: Vec<(&str, &str)> = Vec::new();
84 let coordinate = self.coordinate.to_string();
85 attributes.push(("ref", &coordinate));
86
87 if self.d_t.has_value() {
88 attributes.push(("dT", self.d_t.get_value_str()));
89 }
90 attributes.push(("personId", "{00000000-0000-0000-0000-000000000000}"));
91 if self.id.has_value() {
92 attributes.push(("id", self.id.get_value_str()));
93 }
94 write_start_tag(writer, "threadedComment", attributes, false);
95
96 self.threaded_comment_text.write_to(writer);
98
99 write_end_tag(writer, "threadedComment");
100 }
101}
102impl AdjustmentCoordinate for ThreadedComment {
103 #[inline]
104 fn adjustment_insert_coordinate(
105 &mut self,
106 root_col_num: &u32,
107 offset_col_num: &u32,
108 root_row_num: &u32,
109 offset_row_num: &u32,
110 ) {
111 self.coordinate.adjustment_insert_coordinate(
112 root_col_num,
113 offset_col_num,
114 root_row_num,
115 offset_row_num,
116 );
117 }
118
119 #[inline]
120 fn adjustment_remove_coordinate(
121 &mut self,
122 root_col_num: &u32,
123 offset_col_num: &u32,
124 root_row_num: &u32,
125 offset_row_num: &u32,
126 ) {
127 self.coordinate.adjustment_remove_coordinate(
128 root_col_num,
129 offset_col_num,
130 root_row_num,
131 offset_row_num,
132 );
133 }
134
135 #[inline]
136 fn is_remove_coordinate(
137 &self,
138 root_col_num: &u32,
139 offset_col_num: &u32,
140 root_row_num: &u32,
141 offset_row_num: &u32,
142 ) -> bool {
143 self.coordinate.is_remove_coordinate(
144 root_col_num,
145 offset_col_num,
146 root_row_num,
147 offset_row_num,
148 )
149 }
150}