app/internal: [Windows] support Window.Close

Signed-off-by: Egon Elbre <egonelbre@gmail.com>
This commit is contained in:
Egon Elbre
2020-06-19 13:04:26 +03:00
committed by Elias Naur
parent c35d81e828
commit 0b713032fb
4 changed files with 13 additions and 8 deletions
-1
View File
@@ -133,7 +133,6 @@ func (w *window) SetAnimating(anim bool) {
} }
} }
// Close the window. Only implemented for macOS.
func (w *window) Close() { func (w *window) Close() {
runOnMain(func() { runOnMain(func() {
// Make sure the view is still valid. The window might've been closed // Make sure the view is still valid. The window might've been closed
+10 -5
View File
@@ -178,10 +178,13 @@ func createNativeWindow(opts *Options) (*window, error) {
} }
func windowProc(hwnd syscall.Handle, msg uint32, wParam, lParam uintptr) uintptr { func windowProc(hwnd syscall.Handle, msg uint32, wParam, lParam uintptr) uintptr {
var w *window win, exists := winMap.Load(hwnd)
if win, exists := winMap.Load(hwnd); exists { if !exists {
w = win.(*window) return windows.DefWindowProc(hwnd, msg, wParam, lParam)
} }
w := win.(*window)
switch msg { switch msg {
case windows.WM_UNICHAR: case windows.WM_UNICHAR:
if wParam == windows.UNICODE_NOCHAR { if wParam == windows.UNICODE_NOCHAR {
@@ -249,6 +252,7 @@ func windowProc(hwnd syscall.Handle, msg uint32, wParam, lParam uintptr) uintptr
w.setStage(system.StageRunning) w.setStage(system.StageRunning)
} }
} }
return windows.DefWindowProc(hwnd, msg, wParam, lParam) return windows.DefWindowProc(hwnd, msg, wParam, lParam)
} }
@@ -501,8 +505,9 @@ func (w *window) HWND() (syscall.Handle, int, int) {
return w.hwnd, w.width, w.height return w.hwnd, w.width, w.height
} }
// Close the window. Not implemented for Windows. func (w *window) Close() {
func (w *window) Close() {} windows.PostMessage(w.hwnd, windows.WM_CLOSE, 0, 0)
}
func convertKeyCode(code uintptr) (string, bool) { func convertKeyCode(code uintptr) (string, bool) {
if '0' <= code && code <= '9' || 'A' <= code && code <= 'Z' { if '0' <= code && code <= '9' || 'A' <= code && code <= 'Z' {
+1
View File
@@ -135,6 +135,7 @@ const (
WM_MOUSEMOVE = 0x0200 WM_MOUSEMOVE = 0x0200
WM_MOUSEWHEEL = 0x020A WM_MOUSEWHEEL = 0x020A
WM_PAINT = 0x000F WM_PAINT = 0x000F
WM_CLOSE = 0x0010
WM_QUIT = 0x0012 WM_QUIT = 0x0012
WM_SETFOCUS = 0x0007 WM_SETFOCUS = 0x0007
WM_KILLFOCUS = 0x0008 WM_KILLFOCUS = 0x0008
+2 -2
View File
@@ -211,8 +211,8 @@ func (w *Window) WriteClipboard(s string) {
// Close the window. The window's event loop should exit when it receives // Close the window. The window's event loop should exit when it receives
// system.DestroyEvent. // system.DestroyEvent.
// //
// Currently, only the macOS driver implements this functionality, all others // Currently, only macOS and Windows driver implements this functionality,
// are stubbed. // all others are stubbed.
func (w *Window) Close() { func (w *Window) Close() {
w.driverDo(func() { w.driverDo(func() {
w.driver.Close() w.driver.Close()