示例#1
0
// Finalizer method, only to be called from Release or by
// the Go runtime
func (e *Element) finalize() {
	// Detach handlers
	if attachedHandlers, hasHandlers := eventHandlers[e.handle]; hasHandlers {
		for handler := range attachedHandlers {
			tag := uintptr(unsafe.Pointer(handler))
			C.HTMLayoutDetachEventHandler(e.handle, (*[0]byte)(unsafe.Pointer(goElementProc)), C.LPVOID(tag))
		}
		delete(eventHandlers, e.handle)
	}

	// Release the underlying htmlayout handle
	unuse(e.handle)
	e.handle = BAD_HELEMENT
}
示例#2
0
func (e *Element) DetachHandler(handler *EventHandler) {
	tag := uintptr(unsafe.Pointer(handler))
	if attachedHandlers, exists := eventHandlers[e.handle]; exists {
		if _, exists := attachedHandlers[handler]; exists {
			if ret := C.HTMLayoutDetachEventHandler(e.handle, (*[0]byte)(unsafe.Pointer(goElementProc)), C.LPVOID(tag)); ret != HLDOM_OK {
				domPanic(ret, "Failed to detach event handler from element")
			}
			delete(attachedHandlers, handler)
			if len(attachedHandlers) == 0 {
				delete(eventHandlers, e.handle)
			}
			return
		}
	}
	panic("cannot detach, handler was not registered")
}