1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
use std::marker::PhantomPinned;
use std::pin::Pin;
use std::sync::Arc;
use crate::co;
use crate::decl::*;
use crate::gui::{privs::*, *};
use crate::prelude::*;
struct RawModelessObj {
raw_base: RawBase,
_pin: PhantomPinned,
}
/// An ordinary modeless window.
///
/// Hierarchy: `BaseWnd` -> `RawBase` -> `RawModeless`.
#[derive(Clone)]
pub(in crate::gui) struct RawModeless(Pin<Arc<RawModelessObj>>);
impl RawModeless {
#[must_use]
pub(in crate::gui) fn new(
parent: &(impl GuiParent + 'static),
opts: WindowModelessOpts,
) -> Self {
let new_self = Self(Arc::pin(RawModelessObj {
raw_base: RawBase::new(),
_pin: PhantomPinned,
}));
let self2 = new_self.clone();
let parent2 = parent.clone();
let opts2: WindowModelessOptsObj = opts.into();
parent
.as_ref()
.before_on()
.wm(parent.as_ref().wnd_ty().creation_msg(), move |_| {
let hinst = parent2.hwnd().hinstance();
let atom = self2.0.raw_base.register_class(
&hinst,
&opts2.class_name,
opts2.class_style,
&opts2.class_icon,
&opts2.class_bg_brush,
&opts2.class_cursor,
);
let rc_parent = parent2
.hwnd()
.ClientToScreenRc(parent2.hwnd().GetClientRect().expect(DONTFAIL))
.expect(DONTFAIL);
self2.0.raw_base.create_window(
opts2.ex_style,
atom,
Some(&opts2.title),
opts2.style,
POINT::with(
opts2.position.0 + rc_parent.left,
opts2.position.1 + rc_parent.top,
),
opts2.size.into(),
Some(parent2.hwnd()),
IdMenu::None,
&hinst,
);
Ok(0) // ignored
});
new_self
}
#[must_use]
pub(in crate::gui) fn raw_base(&self) -> &RawBase {
&self.0.raw_base
}
}
/// Options to create a [`WindowModeless`](crate::gui::WindowModeless)
/// programmatically with
/// [`WindowModeless::new`](crate::gui::WindowModeless::new).
pub struct WindowModelessOpts<'a> {
/// Window class name to be
/// [registered](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-registerclassexw).
///
/// Defaults to an auto-generated string.
pub class_name: &'a str,
/// Window class styles to be
/// [registered](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-registerclassexw).
///
/// Defaults to `co::CS::DBLCLKS`.
pub class_style: co::CS,
/// Window main icon to be
/// [registered](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-registerclassexw).
///
/// Defaults to `gui::Icon::None`.
pub class_icon: Icon,
/// Window cursor to be
/// [registered](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-registerclassexw).
///
/// Defaults to `gui::Cursor::Idc(co::IDC::ARROW)`.
pub class_cursor: Cursor,
/// Window background brush to be
/// [registered](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-registerclassexw).
///
/// Defaults to `gui::Brush::Color(co::COLOR::BTNFACE)`.
pub class_bg_brush: Brush,
/// Window title to be
/// [created](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-createwindowexw).
///
/// Defaults to empty string.
pub title: &'a str,
/// Left and top position coordinates of control within parent's client
/// area, to be
/// [created](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-createwindowexw).
///
/// Defaults to `gui::dpi(0, 0)`.
pub position: (i32, i32),
/// Width and height of window client area, in pixels, to be
/// [created](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-createwindowexw).
/// Does not include title bar or borders.
///
/// Defaults to `gui::dpi(220, 150)`.
pub size: (i32, i32),
/// Window styles to be
/// [created](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-createwindowexw).
///
/// Defaults to `WS::CAPTION | WS::SYSMENU | WS::CLIPCHILDREN | WS::BORDER | WS::VISIBLE`.
///
/// Suggestions:
/// * `WS::SIZEBOX` to make the window resizable.
pub style: co::WS,
/// Extended window styles to be
/// [created](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-createwindowexw).
///
/// Defaults to `WS_EX::LEFT | WS_EX::TOOLWINDOW`.
pub ex_style: co::WS_EX,
}
impl<'a> Default for WindowModelessOpts<'a> {
fn default() -> Self {
Self {
class_name: "",
class_style: co::CS::DBLCLKS,
class_icon: Icon::None,
class_cursor: Cursor::Idc(co::IDC::ARROW),
class_bg_brush: Brush::Color(co::COLOR::BTNFACE),
title: "",
position: dpi(0, 0),
size: dpi(220, 150),
style: co::WS::CAPTION
| co::WS::SYSMENU
| co::WS::CLIPCHILDREN
| co::WS::BORDER
| co::WS::VISIBLE,
ex_style: co::WS_EX::LEFT | co::WS_EX::TOOLWINDOW,
}
}
}
impl<'a> Into<WindowModelessOptsObj> for WindowModelessOpts<'a> {
fn into(self) -> WindowModelessOptsObj {
WindowModelessOptsObj {
class_name: self.class_name.to_owned(),
class_style: self.class_style,
class_icon: self.class_icon,
class_cursor: self.class_cursor,
class_bg_brush: self.class_bg_brush,
title: self.title.to_owned(),
position: self.position,
size: self.size,
style: self.style,
ex_style: self.ex_style,
}
}
}
/// To be stored inside the object.
struct WindowModelessOptsObj {
class_name: String,
class_style: co::CS,
class_icon: Icon,
class_cursor: Cursor,
class_bg_brush: Brush,
title: String,
position: (i32, i32),
size: (i32, i32),
style: co::WS,
ex_style: co::WS_EX,
}