#[doc(inline)]
pub use winit::platform::windows::{
IconExtWindows, MonitorHandleExtWindows, HINSTANCE, HMENU, HMONITOR, HWND,
};
use super::__private as sealed;
use crate::event_loop::EventLoopBuilder;
use crate::window::{Icon, Window, WindowBuilder};
use crate::ThreadSafety;
use std::os::raw::c_void;
use winit::platform::windows::{
EventLoopBuilderExtWindows as _, WindowBuilderExtWindows as _, WindowExtWindows as _,
};
pub trait EventLoopBuilderExtWindows: sealed::EventLoopBuilderPrivate {
fn with_any_thread(&mut self, any_thread: bool) -> &mut Self;
fn with_dpi_aware(&mut self, dpi_aware: bool) -> &mut Self;
fn with_msg_hook<F>(&mut self, callback: F) -> &mut Self
where
F: FnMut(*const c_void) -> bool + 'static;
}
impl EventLoopBuilderExtWindows for EventLoopBuilder {
fn with_any_thread(&mut self, any_thread: bool) -> &mut Self {
self.inner.with_any_thread(any_thread);
self
}
fn with_dpi_aware(&mut self, dpi_aware: bool) -> &mut Self {
self.inner.with_dpi_aware(dpi_aware);
self
}
fn with_msg_hook<F>(&mut self, callback: F) -> &mut Self
where
F: FnMut(*const c_void) -> bool + 'static,
{
self.inner.with_msg_hook(callback);
self
}
}
pub trait WindowExtWindows: sealed::WindowPrivate {
fn hinstance(&self) -> HINSTANCE;
fn hwnd(&self) -> HWND;
fn set_enable(&self, enabled: bool);
fn set_taskbar_icon(&self, taskbar_icon: Option<Icon>);
fn set_skip_taskbar(&self, skip: bool);
fn set_undecorated_shadow(&self, shadow: bool);
}
impl<TS: ThreadSafety> WindowExtWindows for Window<TS> {
fn hwnd(&self) -> HWND {
self.window().hwnd()
}
fn hinstance(&self) -> HINSTANCE {
self.window().hinstance()
}
fn set_enable(&self, enabled: bool) {
self.window().set_enable(enabled);
}
fn set_taskbar_icon(&self, taskbar_icon: Option<Icon>) {
self.window().set_taskbar_icon(taskbar_icon);
}
fn set_skip_taskbar(&self, skip: bool) {
self.window().set_skip_taskbar(skip);
}
fn set_undecorated_shadow(&self, shadow: bool) {
self.window().set_undecorated_shadow(shadow);
}
}
pub trait WindowBuilderExtWindows: sealed::WindowBuilderPrivate {
fn with_owner_window(self, parent: HWND) -> WindowBuilder;
fn with_menu(self, menu: HMENU) -> WindowBuilder;
fn with_taskbar_icon(self, taskbar_icon: Option<Icon>) -> WindowBuilder;
fn with_no_redirection_bitmap(self, flag: bool) -> WindowBuilder;
fn with_drag_and_drop(self, flag: bool) -> WindowBuilder;
fn with_skip_taskbar(self, skip: bool) -> WindowBuilder;
fn with_undecorated_shadow(self, shadow: bool) -> WindowBuilder;
}
#[derive(Default)]
pub(crate) struct PlatformSpecific {
owner_window: Option<HWND>,
menu: Option<HMENU>,
taskbar_icon: Option<Icon>,
no_redirection_bitmap: Option<bool>,
drag_and_drop: Option<bool>,
skip_taskbar: Option<bool>,
undecorated_shadow: Option<bool>,
}
impl PlatformSpecific {
pub(crate) fn apply_to(
self,
mut wb: winit::window::WindowBuilder,
) -> winit::window::WindowBuilder {
if let Some(owner_window) = self.owner_window {
wb = wb.with_owner_window(owner_window);
}
if let Some(menu) = self.menu {
wb = wb.with_menu(menu);
}
if let Some(taskbar_icon) = self.taskbar_icon {
wb = wb.with_taskbar_icon(Some(taskbar_icon));
}
if let Some(no_redirection_bitmap) = self.no_redirection_bitmap {
wb = wb.with_no_redirection_bitmap(no_redirection_bitmap);
}
if let Some(drag_and_drop) = self.drag_and_drop {
wb = wb.with_drag_and_drop(drag_and_drop);
}
if let Some(skip_taskbar) = self.skip_taskbar {
wb = wb.with_skip_taskbar(skip_taskbar);
}
if let Some(undecorated_shadow) = self.undecorated_shadow {
wb = wb.with_undecorated_shadow(undecorated_shadow);
}
wb
}
}