use crate::*;
use std::cell::Cell;
use tokio::sync::oneshot;
use std::sync::Arc;
use windows::Win32::{Foundation::LPARAM, UI::WindowsAndMessaging::*};
#[derive(Clone, Debug)]
pub struct Draw {
pub invalidate_rect: PhysicalRect<i32>,
}
#[derive(Clone, Debug)]
pub struct Moved {
pub position: ScreenPosition<i32>,
}
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum ResizingEdge {
Left,
Right,
Top,
Bottom,
TopLeft,
TopRight,
BottomLeft,
BottomRight,
}
#[derive(Clone, Debug)]
pub struct Resizing {
pub size: PhysicalSize<u32>,
pub edge: ResizingEdge,
}
#[derive(Clone, Debug)]
pub struct Resized {
pub size: PhysicalSize<u32>,
}
#[derive(Clone, Debug)]
pub struct MouseInput {
pub button: MouseButton,
pub button_state: ButtonState,
pub mouse_state: MouseState,
}
#[derive(Clone, Debug)]
pub struct CursorMoved {
pub mouse_state: MouseState,
}
#[derive(Clone, Debug)]
pub struct CursorEntered {
pub mouse_state: MouseState,
}
#[derive(Debug)]
pub struct CursorLeft {
pub position: PhysicalPosition<i32>,
}
#[derive(Clone, Debug)]
pub struct MouseWheel {
pub axis: MouseWheelAxis,
pub distance: i32,
pub mouse_state: MouseState,
}
#[derive(Clone, Debug)]
pub struct KeyInput {
pub key_code: KeyCode,
pub key_state: KeyState,
pub prev_pressed: bool,
}
impl KeyInput {
#[inline]
pub fn is(&self, key_code: impl Into<KeyCode>, key_state: KeyState) -> bool {
self.key_code == key_code.into() && self.key_state == key_state
}
}
#[derive(Clone, Debug)]
pub struct CharInput {
pub c: char,
}
#[derive(Debug)]
pub struct ImeBeginComposition {
position: Cell<PhysicalPosition<i32>>,
dpi: i32,
tx: Option<oneshot::Sender<PhysicalPosition<i32>>>,
}
impl ImeBeginComposition {
pub(crate) fn new(dpi: i32, tx: oneshot::Sender<PhysicalPosition<i32>>) -> Self {
Self {
position: Cell::new(PhysicalPosition::new(0, 0)),
dpi,
tx: Some(tx),
}
}
#[inline]
pub fn set_position(
&self,
position: impl ToPhysical<i32, Output<i32> = PhysicalPosition<i32>>,
) {
self.position.set(position.to_physical(self.dpi));
}
}
impl std::ops::Drop for ImeBeginComposition {
#[inline]
fn drop(&mut self) {
self.tx.take().unwrap().send(self.position.get()).ok();
}
}
#[derive(Clone, Debug)]
pub struct ImeUpdateComposition {
pub chars: Vec<char>,
pub clauses: Vec<ime::Clause>,
pub cursor_position: usize,
}
#[derive(Clone, Debug)]
pub struct ImeEndComposition {
pub result: Option<String>,
}
#[derive(Clone, Debug)]
pub struct ImeUpdateCandidateList {
pub selection: usize,
pub items: Vec<String>,
}
#[derive(Clone, Debug)]
pub struct Maximized {
pub size: PhysicalSize<u32>,
}
#[derive(Clone, Debug)]
pub struct Restored {
pub size: PhysicalSize<u32>,
}
#[derive(Clone, Debug)]
pub struct DpiChanged {
pub new_dpi: u32,
}
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
#[repr(u32)]
pub enum NcHitTestValue {
Border = HTBORDER,
Bottom = HTBOTTOM,
BottomLeft = HTBOTTOMLEFT,
BottomRight = HTBOTTOMRIGHT,
Left = HTLEFT,
Right = HTRIGHT,
Top = HTTOP,
TopLeft = HTTOPLEFT,
TopRight = HTTOPRIGHT,
Caption = HTCAPTION,
Client = HTCLIENT,
Size = HTSIZE,
Help = HTHELP,
HScroll = HTHSCROLL,
VScroll = HTVSCROLL,
Menu = HTMENU,
MaxButton = HTMAXBUTTON,
MinButton = HTMINBUTTON,
CloseButton = HTCLOSE,
SysMenu = HTSYSMENU,
Error = HTERROR as u32,
Transparent = HTTRANSPARENT as u32,
}
#[derive(Debug)]
pub struct NcHitTest {
pub position: PhysicalPosition<i32>,
value: Cell<Option<NcHitTestValue>>,
tx: Option<oneshot::Sender<Option<NcHitTestValue>>>,
}
impl NcHitTest {
pub(crate) fn new(lparam: LPARAM, tx: oneshot::Sender<Option<NcHitTestValue>>) -> Self {
let position = lparam_to_point(lparam);
Self {
position,
value: Cell::new(None),
tx: Some(tx),
}
}
#[inline]
pub fn get(&self) -> Option<NcHitTestValue> {
self.value.get()
}
#[inline]
pub fn set(&self, value: Option<NcHitTestValue>) {
self.value.set(value);
}
}
impl std::ops::Drop for NcHitTest {
fn drop(&mut self) {
self.tx.take().unwrap().send(self.value.get()).ok();
}
}
#[derive(Clone, Debug)]
pub struct NotifyIcon {
pub id: super::NotifyIcon,
pub event: NotifyIconEvent,
}
impl PartialEq<super::NotifyIcon> for NotifyIcon {
#[inline]
fn eq(&self, other: &super::NotifyIcon) -> bool {
&self.id == other
}
}
impl PartialEq<NotifyIcon> for super::NotifyIcon {
#[inline]
fn eq(&self, other: &NotifyIcon) -> bool {
self == &other.id
}
}
#[derive(Clone, Debug)]
pub struct MenuCommand {
pub index: usize,
pub handle: MenuHandle,
}
#[derive(Clone, Debug)]
pub struct ContextMenu {
pub clicked_window: WindowHandle,
pub position: ScreenPosition<i32>,
}
#[derive(Clone, Debug)]
pub struct ColorModeChanged {
pub current: ColorModeState,
pub previous: ColorModeState,
}
#[derive(Debug)]
pub struct DragEnter {
pub position: PhysicalPosition<i32>,
pub modifier_keys: ModifierKey,
pub data: Arc<drag_drop::Data>,
pub effect: drag_drop::Effect,
pub(crate) tx: Option<oneshot::Sender<drag_drop::Effect>>,
}
impl std::ops::Drop for DragEnter {
fn drop(&mut self) {
let tx = self.tx.take().unwrap();
tx.send(self.effect).ok();
}
}
#[derive(Debug)]
pub struct DragOver {
pub position: PhysicalPosition<i32>,
pub modifier_keys: ModifierKey,
pub data: Arc<drag_drop::Data>,
pub effect: drag_drop::Effect,
pub(crate) tx: Option<oneshot::Sender<drag_drop::Effect>>,
}
impl std::ops::Drop for DragOver {
fn drop(&mut self) {
let tx = self.tx.take().unwrap();
tx.send(self.effect).ok();
}
}
#[derive(Debug)]
pub struct Drop {
pub position: PhysicalPosition<i32>,
pub modifier_keys: ModifierKey,
pub data: Arc<drag_drop::Data>,
pub effect: drag_drop::Effect,
pub(crate) tx: Option<oneshot::Sender<drag_drop::Effect>>,
}
impl std::ops::Drop for Drop {
fn drop(&mut self) {
let tx = self.tx.take().unwrap();
tx.send(self.effect).ok();
}
}
#[derive(Clone, Debug)]
pub struct CloseRequest {
handle: WindowHandle,
}
impl CloseRequest {
pub(crate) fn new(handle: WindowHandle) -> Self {
Self { handle }
}
#[inline]
pub fn destroy(&self) {
let handle = self.handle;
UiThread::send_task(move || unsafe {
DestroyWindow(handle.as_hwnd()).ok();
});
}
}
#[derive(Clone, Debug)]
pub struct App {
pub index: u32,
pub value0: usize,
pub value1: isize,
}
impl App {
#[inline]
pub fn new(index: u32, value0: usize, value1: isize) -> Self {
Self {
index,
value0,
value1,
}
}
}
#[derive(Clone, Debug)]
pub struct Other {
pub msg: u32,
pub wparam: usize,
pub lparam: isize,
}
#[derive(Debug)]
#[non_exhaustive]
pub enum Event {
Activated,
Inactivated,
Draw(Draw),
Moved(Moved),
EnterResizing,
Resizing(Resizing),
Resized(Resized),
MouseInput(MouseInput),
CursorMoved(CursorMoved),
CursorEntered(CursorEntered),
CursorLeft(CursorLeft),
MouseWheel(MouseWheel),
KeyInput(KeyInput),
CharInput(CharInput),
ImeBeginComposition(ImeBeginComposition),
ImeUpdateComposition(ImeUpdateComposition),
ImeEndComposition(ImeEndComposition),
ImeBeginCandidateList,
ImeUpdateCandidateList(ImeUpdateCandidateList),
ImeEndCandidateList,
MenuCommand(MenuCommand),
ContextMenu(ContextMenu),
Minizmized,
Maximized(Maximized),
Restored(Restored),
DpiChanged(DpiChanged),
NcHitTest(NcHitTest),
NotifyIcon(NotifyIcon),
ColorModeChanged(ColorModeChanged),
DragEnter(DragEnter),
DragOver(DragOver),
DragLeave,
Drop(Drop),
CloseRequest(CloseRequest),
Closed,
App(App),
Other(Other),
}