func DetachWindowEventHandler(hwnd win.HWND) { key := HWND(hwnd) if handler, exists := windowEventHandlers[hwnd]; exists { tag := uintptr(unsafe.Pointer(handler)) if ret := HTMLayoutWindowDetachEventHandler(key, goElementProc, tag); ret != HLDOM_OK { domPanic(C.HLDOM_RESULT(ret), "Failed to detach event handler from window") } delete(windowEventHandlers, hwnd) } }
func AttachWindowEventHandler(hwnd win.HWND, handler *EventHandler) { key := HWND(hwnd) tag := uintptr(unsafe.Pointer(handler)) if _, exists := windowEventHandlers[hwnd]; exists { if ret := HTMLayoutWindowDetachEventHandler(key, goElementProc, tag); ret != HLDOM_OK { domPanic(C.HLDOM_RESULT(ret), "Failed to detach event handler from window before adding the new one") } } // Overwrite if it exists windowEventHandlers[hwnd] = handler // Don't let the caller disable ATTACH/DETACH events, otherwise we // won't know when to throw out our event handler object subscription := handler.Subscription() subscription &= ^uint(DISABLE_INITIALIZATION & 0xffffffff) if ret := HTMLayoutWindowAttachEventHandler(key, goElementProc, tag, subscription); ret != HLDOM_OK { domPanic2(ret, "Failed to attach event handler to window") } }