use std::any::Any;
use crate::decl::*;
use crate::gui::privs::*;
use crate::msg::*;
pub trait GuiWindow: Send {
#[must_use]
fn hwnd(&self) -> &HWND;
#[must_use]
fn as_any(&self) -> &dyn Any;
}
#[allow(private_bounds)]
pub trait GuiParent: GuiWindow + Clone + AsRef<BaseWnd> {
fn spawn_thread<F>(&self, func: F)
where
F: FnOnce() -> AnyResult<()> + Send + 'static,
{
self.as_ref().spawn_thread(func)
}
fn run_ui_thread<F>(&self, func: F)
where
F: FnOnce() -> AnyResult<()> + Send + 'static,
{
self.as_ref().run_ui_thread(func)
}
}
pub trait GuiControl: GuiWindow {
#[must_use]
fn ctrl_id(&self) -> u16;
fn focus(&self) -> SysResult<()> {
let hparent = self.hwnd().GetParent()?;
if hparent.is_dialog() {
unsafe {
hparent.SendMessage(wm::NextDlgCtl {
hwnd_focus: HwndFocus::Hwnd(self.hwnd().raw_copy()),
});
}
} else {
self.hwnd().SetFocus();
}
Ok(())
}
}