From 1a5ece4f52ef17c7c868e95eb26e98137d5cab6f Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Sun, 7 Mar 2021 23:19:48 -0500 Subject: keyboard support in raleigh, word wrap and more in entry widget --- src/user/raleigh/window.cpp | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'src/user/raleigh/window.cpp') diff --git a/src/user/raleigh/window.cpp b/src/user/raleigh/window.cpp index c23545b..052422e 100644 --- a/src/user/raleigh/window.cpp +++ b/src/user/raleigh/window.cpp @@ -7,8 +7,8 @@ namespace raleigh { window::window(widget &root, _pixel_t bg_color, bool (*on_close)(window &)) - : handle(0), size(root.size), root(root), bg_color(bg_color), - needs_repaint(false), on_close(on_close) { + : handle(0), size(root.size), root(root), focussed(&root), + bg_color(bg_color), on_close(on_close) { root.w = this; root.window_offset = coord(0, 0); root.notify_window_change(); @@ -18,6 +18,8 @@ namespace raleigh { show_error_and_quitf("Failed to create %d byte pixel buffer\nfor requested %dx%d pixel window.", size.x * size.y * sizeof(_pixel_t), size.x, size.y); paint_full(); + root.on_focus(); + needs_repaint = false; } window::try_actions_return_t window::try_actions() { @@ -39,9 +41,15 @@ namespace raleigh { return DELETE; got = GOOD; if (wa.action_type == wa.MOUSE_DOWN) - root.try_handle_click(coord(wa.as_mouse.x, wa.as_mouse.y), wa.as_mouse.which, false); - if (wa.action_type == wa.MOUSE_UP) - root.try_handle_click(coord(wa.as_mouse.x, wa.as_mouse.y), wa.as_mouse.which, true); + root.handle_click(coord(wa.as_mouse.x, wa.as_mouse.y), wa.as_mouse.which, false); + else if (wa.action_type == wa.MOUSE_UP) + root.handle_click(coord(wa.as_mouse.x, wa.as_mouse.y), wa.as_mouse.which, true); + else if (wa.action_type == wa.KEY_DOWN) + focussed->handle_key(wa.as_key); + else if (wa.action_type == wa.FOCUS_ENTER) + focussed->on_focus(); + else if (wa.action_type == wa.FOCUS_LEAVE) + focussed->on_unfocus(); } } @@ -67,4 +75,12 @@ namespace raleigh { show_error_and_quitf("Failed to get window handle for requested window."); open_windows.add_front(*this); } + + void window::focus(widget &w) { + if (focussed != &w) { + focussed->on_unfocus(); + focussed = &w; + focussed->on_focus(); + } + } } \ No newline at end of file -- cgit v1.2.3