Skip to content

Commit 60fa439

Browse files
committed
win32: use common process function for Window
fixes #49
1 parent 4948fdd commit 60fa439

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

src/backends/win32/backend.zig

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -178,24 +178,22 @@ pub const Window = struct {
178178
return 1;
179179
}
180180

181-
fn process(hwnd: HWND, wm: c_uint, wp: WPARAM, lp: LPARAM) callconv(WINAPI) LRESULT {
182-
switch (wm) {
183-
win32.WM_SIZE => {
184-
_ = win32.EnumChildWindows(hwnd, relayoutChild, @as(isize, @bitCast(@intFromPtr(hwnd))));
185-
},
186-
win32.WM_DPICHANGED => {
187-
// TODO: update scale factor
188-
},
189-
else => {},
190-
}
191-
return win32.DefWindowProcW(hwnd, wm, wp, lp);
181+
pub fn onResize(data: *EventUserData, hwnd: HWND) void {
182+
_ = data;
183+
_ = win32.EnumChildWindows(hwnd, relayoutChild, @as(isize, @bitCast(@intFromPtr(hwnd))));
184+
}
185+
186+
pub fn onDpiChanged(self: *EventUserData, hwnd: HWND) void {
187+
_ = hwnd;
188+
_ = self;
189+
// TODO: update scale factor
192190
}
193191

194192
pub fn create() !Window {
195193
var wc: win32.WNDCLASSEXW = .{
196194
.cbSize = @sizeOf(win32.WNDCLASSEXW),
197195
.style = win32.WNDCLASS_STYLES.initFlags(.{ .HREDRAW = 1, .VREDRAW = 1 }),
198-
.lpfnWndProc = process,
196+
.lpfnWndProc = Window.process,
199197
.cbClsExtra = 0,
200198
.cbWndExtra = 0,
201199
.hInstance = hInst,
@@ -328,18 +326,20 @@ pub fn Events(comptime T: type) type {
328326
switch (wm) {
329327
win32.WM_COMMAND => {
330328
const code = @as(u16, @intCast(wp >> 16));
331-
const data = getEventUserData(@as(HWND, @ptrFromInt(@as(usize, @bitCast(lp)))));
332-
switch (code) {
333-
win32.BN_CLICKED => {
334-
if (data.user.clickHandler) |handler|
335-
handler(data.userdata);
336-
},
337-
win32.EN_CHANGE => {
338-
// Doesn't appear to work.
339-
if (data.user.changedTextHandler) |handler|
340-
handler(data.userdata);
341-
},
342-
else => {},
329+
if (lp != 0) {
330+
const data = getEventUserData(@as(HWND, @ptrFromInt(@as(usize, @bitCast(lp)))));
331+
switch (code) {
332+
win32.BN_CLICKED => {
333+
if (data.user.clickHandler) |handler|
334+
handler(data.userdata);
335+
},
336+
win32.EN_CHANGE => {
337+
// Doesn't appear to work.
338+
if (data.user.changedTextHandler) |handler|
339+
handler(data.userdata);
340+
},
341+
else => {},
342+
}
343343
}
344344
},
345345
win32.WM_CTLCOLOREDIT => {
@@ -439,8 +439,10 @@ pub fn Events(comptime T: type) type {
439439
}
440440
}
441441
},
442-
win32.WM_PAINT => {
442+
win32.WM_PAINT => blk: {
443443
const data = getEventUserData(hwnd);
444+
if (data.class.drawHandler == null and data.user.drawHandler == null) break :blk;
445+
444446
var rc: win32.RECT = undefined;
445447
_ = win32.GetClientRect(hwnd, &rc);
446448

0 commit comments

Comments
 (0)