Esempio n. 1
0
func DetachWindowEventHandler(hwnd uint32) {
	key := uintptr(hwnd)
	if handler, exists := windowEventHandlers[hwnd]; exists {
		tag := uintptr(unsafe.Pointer(handler))
		if ret := C.HTMLayoutWindowDetachEventHandler(C.HWND(C.HANDLE(key)), (*[0]byte)(unsafe.Pointer(goElementProc)), C.LPVOID(tag)); ret != HLDOM_OK {
			domPanic(ret, "Failed to detach event handler from window")
		}
		delete(windowEventHandlers, hwnd)
	}
}
Esempio n. 2
0
func AttachWindowEventHandler(hwnd uint32, handler *EventHandler) {
	key := uintptr(hwnd)
	tag := uintptr(unsafe.Pointer(handler))

	if _, exists := windowEventHandlers[hwnd]; exists {
		if ret := C.HTMLayoutWindowDetachEventHandler(C.HWND(C.HANDLE(key)), (*[0]byte)(unsafe.Pointer(goElementProc)), C.LPVOID(tag)); ret != HLDOM_OK {
			domPanic(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 &= ^uint32(DISABLE_INITIALIZATION & 0xffffffff)

	if ret := C.HTMLayoutWindowAttachEventHandler(C.HWND(C.HANDLE(key)), (*[0]byte)(unsafe.Pointer(goElementProc)), C.LPVOID(tag), C.UINT(subscription)); ret != HLDOM_OK {
		domPanic(ret, "Failed to attach event handler to window")
	}
}