use crate::bitmap::Bitmap;
use crate::window::WxWidget;
use std::ffi::CString;
use wxdragon_sys as ffi;
pub struct AboutDialogInfo {
ptr: *mut ffi::wxd_AboutDialogInfo_t,
}
impl AboutDialogInfo {
pub fn new() -> Self {
let ptr = unsafe { ffi::wxd_AboutDialogInfo_Create() };
if ptr.is_null() {
panic!("Failed to create AboutDialogInfo");
}
AboutDialogInfo { ptr }
}
pub fn set_name(&mut self, name: &str) {
let c_name = CString::new(name).expect("CString::new failed");
unsafe {
ffi::wxd_AboutDialogInfo_SetName(self.ptr, c_name.as_ptr());
}
}
pub fn set_version(&mut self, version: &str) {
let c_version = CString::new(version).expect("CString::new failed");
unsafe {
ffi::wxd_AboutDialogInfo_SetVersion(self.ptr, c_version.as_ptr());
}
}
pub fn set_version_ex(&mut self, version: &str, long_version: &str) {
let c_version = CString::new(version).expect("CString::new failed");
let c_long = CString::new(long_version).expect("CString::new failed");
unsafe {
ffi::wxd_AboutDialogInfo_SetVersionEx(self.ptr, c_version.as_ptr(), c_long.as_ptr());
}
}
pub fn set_description(&mut self, description: &str) {
let c_desc = CString::new(description).expect("CString::new failed");
unsafe {
ffi::wxd_AboutDialogInfo_SetDescription(self.ptr, c_desc.as_ptr());
}
}
pub fn set_copyright(&mut self, copyright: &str) {
let c_copyright = CString::new(copyright).expect("CString::new failed");
unsafe {
ffi::wxd_AboutDialogInfo_SetCopyright(self.ptr, c_copyright.as_ptr());
}
}
pub fn set_licence(&mut self, licence: &str) {
let c_licence = CString::new(licence).expect("CString::new failed");
unsafe {
ffi::wxd_AboutDialogInfo_SetLicence(self.ptr, c_licence.as_ptr());
}
}
pub fn set_license(&mut self, license: &str) {
self.set_licence(license);
}
pub fn set_icon(&mut self, bitmap: &Bitmap) {
unsafe {
ffi::wxd_AboutDialogInfo_SetIcon(self.ptr, bitmap.as_const_ptr());
}
}
pub fn set_website(&mut self, url: &str) {
let c_url = CString::new(url).expect("CString::new failed");
unsafe {
ffi::wxd_AboutDialogInfo_SetWebSite(self.ptr, c_url.as_ptr());
}
}
pub fn set_website_ex(&mut self, url: &str, description: &str) {
let c_url = CString::new(url).expect("CString::new failed");
let c_desc = CString::new(description).expect("CString::new failed");
unsafe {
ffi::wxd_AboutDialogInfo_SetWebSiteEx(self.ptr, c_url.as_ptr(), c_desc.as_ptr());
}
}
pub fn add_developer(&mut self, developer: &str) {
let c_dev = CString::new(developer).expect("CString::new failed");
unsafe {
ffi::wxd_AboutDialogInfo_AddDeveloper(self.ptr, c_dev.as_ptr());
}
}
pub fn add_doc_writer(&mut self, doc_writer: &str) {
let c_doc = CString::new(doc_writer).expect("CString::new failed");
unsafe {
ffi::wxd_AboutDialogInfo_AddDocWriter(self.ptr, c_doc.as_ptr());
}
}
pub fn add_artist(&mut self, artist: &str) {
let c_artist = CString::new(artist).expect("CString::new failed");
unsafe {
ffi::wxd_AboutDialogInfo_AddArtist(self.ptr, c_artist.as_ptr());
}
}
pub fn add_translator(&mut self, translator: &str) {
let c_trans = CString::new(translator).expect("CString::new failed");
unsafe {
ffi::wxd_AboutDialogInfo_AddTranslator(self.ptr, c_trans.as_ptr());
}
}
pub fn as_ptr(&self) -> *const ffi::wxd_AboutDialogInfo_t {
self.ptr
}
}
impl Default for AboutDialogInfo {
fn default() -> Self {
Self::new()
}
}
impl Drop for AboutDialogInfo {
fn drop(&mut self) {
if !self.ptr.is_null() {
unsafe {
ffi::wxd_AboutDialogInfo_Destroy(self.ptr);
}
}
}
}
pub fn show_about_box(info: &AboutDialogInfo, parent: Option<&dyn WxWidget>) {
let parent_ptr = parent.map(|p| p.handle_ptr()).unwrap_or(std::ptr::null_mut());
unsafe {
ffi::wxd_AboutBox(info.as_ptr(), parent_ptr);
}
}