From 05b3e8cdc7f6cf7056c96d9cd150a0e2a8fb85a4 Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Fri, 28 Oct 2016 17:55:06 +0200 Subject: Rewrite event handler to use shared_ptr Events instead of raw pointers. --- plugingui/nativewindow_win32.cc | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'plugingui/nativewindow_win32.cc') diff --git a/plugingui/nativewindow_win32.cc b/plugingui/nativewindow_win32.cc index f49f3c6..b318f59 100644 --- a/plugingui/nativewindow_win32.cc +++ b/plugingui/nativewindow_win32.cc @@ -52,7 +52,7 @@ LRESULT CALLBACK NativeWindowWin32::dialogProc(HWND hwnd, UINT msg, static bool first = true; if(!first) { - ResizeEvent* resizeEvent = new ResizeEvent(); + auto resizeEvent = std::make_shared(); resizeEvent->width = LOWORD(lp); resizeEvent->height = HIWORD(lp); native->event_queue.push(resizeEvent); @@ -63,7 +63,7 @@ LRESULT CALLBACK NativeWindowWin32::dialogProc(HWND hwnd, UINT msg, case WM_MOVE: { -// MoveEvent* moveEvent = new MoveEvent(); +// auto moveEvent = std::make_shared(); // moveEvent->x = (short)LOWORD(lp); // moveEvent->y = (short)HIWORD(lp); // native->event_queue.push(moveEvent); @@ -72,7 +72,7 @@ LRESULT CALLBACK NativeWindowWin32::dialogProc(HWND hwnd, UINT msg, case WM_CLOSE: { - CloseEvent* closeEvent = new CloseEvent(); + auto closeEvent = std::make_shared(); native->event_queue.push(closeEvent); } break; @@ -91,7 +91,7 @@ LRESULT CALLBACK NativeWindowWin32::dialogProc(HWND hwnd, UINT msg, // return 0; case WM_MOUSEMOVE: { - MouseMoveEvent* mouseMoveEvent = new MouseMoveEvent(); + auto mouseMoveEvent = std::make_shared(); mouseMoveEvent->x = (short)LOWORD(lp); mouseMoveEvent->y = (short)HIWORD(lp); native->event_queue.push(mouseMoveEvent); @@ -100,7 +100,7 @@ LRESULT CALLBACK NativeWindowWin32::dialogProc(HWND hwnd, UINT msg, case WM_MOUSEWHEEL: { - ScrollEvent* scrollEvent = new ScrollEvent(); + auto scrollEvent = std::make_shared(); // NOTE: lp is coordinates in screen space, not client space. POINT p; @@ -125,7 +125,7 @@ LRESULT CALLBACK NativeWindowWin32::dialogProc(HWND hwnd, UINT msg, case WM_MBUTTONDBLCLK: case WM_MBUTTONDOWN: { - ButtonEvent* buttonEvent = new ButtonEvent(); + auto buttonEvent = std::make_shared(); buttonEvent->x = (short)LOWORD(lp); buttonEvent->y = (short)HIWORD(lp); @@ -178,7 +178,7 @@ LRESULT CALLBACK NativeWindowWin32::dialogProc(HWND hwnd, UINT msg, case WM_KEYDOWN: case WM_KEYUP: { - KeyEvent* keyEvent = new KeyEvent(); + auto keyEvent = std::make_shared(); switch(wp) { case VK_LEFT: keyEvent->keycode = Key::left; break; @@ -207,7 +207,7 @@ LRESULT CALLBACK NativeWindowWin32::dialogProc(HWND hwnd, UINT msg, { if(wp >= ' ') // Filter control chars. { - KeyEvent* keyEvent = new KeyEvent(); + auto keyEvent = std::make_shared(); keyEvent->keycode = Key::character; keyEvent->text += (char)wp; keyEvent->direction = Direction::up; @@ -218,7 +218,7 @@ LRESULT CALLBACK NativeWindowWin32::dialogProc(HWND hwnd, UINT msg, case WM_PAINT: { - RepaintEvent* repaintEvent = new RepaintEvent(); + auto repaintEvent = std::make_shared(); repaintEvent->x = 0; repaintEvent->y = 0; repaintEvent->width = 100; @@ -417,7 +417,7 @@ bool NativeWindowWin32::hasEvent() return false; } -Event* NativeWindowWin32::getNextEvent() +std::shared_ptr NativeWindowWin32::getNextEvent() { if(!event_queue.empty()) { @@ -447,7 +447,7 @@ Event* NativeWindowWin32::getNextEvent() return event; } -Event* NativeWindowWin32::peekNextEvent() +std::shared_ptr NativeWindowWin32::peekNextEvent() { if(!event_queue.empty()) { -- cgit v1.2.3