use crate::event::WxEvtHandler;
use crate::prelude::*;
use crate::widgets::aui_mdi_parent_frame::AuiMdiParentFrame;
use crate::window::{WindowHandle, WxWidget};
use std::ffi::CString;
use std::marker::PhantomData;
use wxdragon_sys as ffi;
widget_style_enum!(
name: AuiMdiChildFrameStyle,
doc: "Style flags for AuiMdiChildFrame.",
variants: {
Default: ffi::WXD_DEFAULT_FRAME_STYLE, "Default frame style."
},
default_variant: Default
);
#[derive(Clone, Copy)]
pub struct AuiMdiChildFrame {
handle: WindowHandle,
#[allow(dead_code)]
parent_ptr: *mut ffi::wxd_AuiMDIParentFrame_t,
_marker: PhantomData<()>,
}
impl AuiMdiChildFrame {
fn from_ptr(ptr: *mut ffi::wxd_AuiMDIChildFrame_t, parent_ptr: *mut ffi::wxd_AuiMDIParentFrame_t) -> Self {
AuiMdiChildFrame {
handle: WindowHandle::new(ptr as *mut ffi::wxd_Window_t),
parent_ptr,
_marker: PhantomData,
}
}
pub fn builder<'a>(parent: &'a AuiMdiParentFrame) -> AuiMdiChildFrameBuilder<'a> {
AuiMdiChildFrameBuilder::new(parent)
}
#[inline]
#[allow(dead_code)]
fn child_frame_ptr(&self) -> *mut ffi::wxd_AuiMDIChildFrame_t {
self.handle
.get_ptr()
.map(|p| p as *mut ffi::wxd_AuiMDIChildFrame_t)
.unwrap_or(std::ptr::null_mut())
}
pub fn window_handle(&self) -> WindowHandle {
self.handle
}
}
#[derive(Clone)]
pub struct AuiMdiChildFrameBuilder<'a> {
parent: &'a AuiMdiParentFrame,
id: Id,
title: String,
pos: Point,
size: Size,
style: AuiMdiChildFrameStyle,
name: String,
}
impl<'a> AuiMdiChildFrameBuilder<'a> {
pub fn new(parent: &'a AuiMdiParentFrame) -> Self {
Self {
parent,
id: ID_ANY as Id,
title: String::new(),
pos: Point::DEFAULT_POSITION,
size: Size::DEFAULT_SIZE,
style: AuiMdiChildFrameStyle::Default,
name: "wxAuiMDIChildFrame".to_string(),
}
}
pub fn with_id(mut self, id: Id) -> Self {
self.id = id;
self
}
pub fn with_title(mut self, title: &str) -> Self {
self.title = title.to_string();
self
}
pub fn with_pos(mut self, pos: Point) -> Self {
self.pos = pos;
self
}
pub fn with_size(mut self, size: Size) -> Self {
self.size = size;
self
}
pub fn with_style(mut self, style: AuiMdiChildFrameStyle) -> Self {
self.style = style;
self
}
pub fn with_name(mut self, name: &str) -> Self {
self.name = name.to_string();
self
}
pub fn build(self) -> AuiMdiChildFrame {
let title_c = CString::new(self.title).expect("CString::new failed for title");
let name_c = CString::new(self.name).expect("CString::new failed for name");
let parent_ptr = self.parent.handle_ptr() as *mut ffi::wxd_AuiMDIParentFrame_t;
let ptr = unsafe {
ffi::wxd_AuiMDIChildFrame_Create(
parent_ptr,
self.id,
title_c.as_ptr(),
self.pos.into(),
self.size.into(),
self.style.bits(),
name_c.as_ptr(),
)
};
if ptr.is_null() {
panic!("Failed to create AuiMdiChildFrame: wxWidgets returned a null pointer.");
} else {
AuiMdiChildFrame::from_ptr(ptr, parent_ptr)
}
}
}
impl WxWidget for AuiMdiChildFrame {
fn handle_ptr(&self) -> *mut ffi::wxd_Window_t {
self.handle.get_ptr().unwrap_or(std::ptr::null_mut())
}
fn is_valid(&self) -> bool {
self.handle.is_valid()
}
}
impl WxEvtHandler for AuiMdiChildFrame {
unsafe fn get_event_handler_ptr(&self) -> *mut ffi::wxd_EvtHandler_t {
self.handle.get_ptr().unwrap_or(std::ptr::null_mut()) as *mut ffi::wxd_EvtHandler_t
}
}
impl crate::event::WindowEvents for AuiMdiChildFrame {}