use std::cell::RefCell;
use std::rc::Rc;
use windows::Win32::System::Com::IDispatch;
use crate::connections::Connections;
pub(crate) type Shared = Rc<RefCell<Model>>;
pub(crate) struct Model {
pub text: String,
pub caption: String,
pub enabled: bool,
pub dirty: bool,
pub refresh: bool,
pub inside: bool,
connections: Connections<IDispatch>,
}
impl Model {
pub fn new() -> Shared {
Rc::new(RefCell::new(Self {
text: String::new(),
caption: "Denise".to_string(),
enabled: true,
dirty: false,
refresh: false,
inside: false,
connections: Connections::new(),
}))
}
pub fn touch(&mut self) {
self.dirty = true;
}
pub fn advise(&mut self, sink: IDispatch) -> u32 {
self.connections.advise(sink)
}
pub fn unadvise(&mut self, cookie: u32) -> bool {
self.connections.unadvise(cookie)
}
pub fn sinks(&self) -> Vec<IDispatch> {
self.connections.sinks()
}
pub fn clear_sinks(&mut self) {
self.connections.clear();
}
}