2023-05-31 17:41:14 +08:00
|
|
|
//----------------------------------------
|
|
|
|
//
|
|
|
|
// Copyright © yanghy. All Rights Reserved.
|
|
|
|
//
|
|
|
|
// Licensed under Apache License Version 2.0, January 2004
|
|
|
|
//
|
|
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
//----------------------------------------
|
|
|
|
|
|
|
|
package cef
|
|
|
|
|
|
|
|
import (
|
2023-06-11 00:10:55 +08:00
|
|
|
"github.com/energye/energy/v2/cef/internal/def"
|
2023-05-31 18:00:34 +08:00
|
|
|
"github.com/energye/energy/v2/common"
|
|
|
|
"github.com/energye/energy/v2/common/imports"
|
|
|
|
"github.com/energye/energy/v2/consts"
|
2023-05-31 17:41:14 +08:00
|
|
|
"github.com/energye/golcl/lcl"
|
|
|
|
"github.com/energye/golcl/lcl/api"
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ************************** creates ************************** //
|
|
|
|
|
|
|
|
// DragHandlerRef -> ICefDragHandler
|
|
|
|
var DragHandlerRef dragHandler
|
|
|
|
|
|
|
|
type dragHandler uintptr
|
|
|
|
|
|
|
|
func (*dragHandler) New() *ICefDragHandler {
|
|
|
|
var result uintptr
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefDragHandlerRef_Create).Call(uintptr(unsafe.Pointer(&result)))
|
2023-05-31 17:41:14 +08:00
|
|
|
if result != 0 {
|
|
|
|
return &ICefDragHandler{instance: unsafe.Pointer(result)}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ************************** impl ************************** //
|
|
|
|
|
|
|
|
// Instance 实例
|
|
|
|
func (m *ICefDragHandler) Instance() uintptr {
|
|
|
|
if m == nil {
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
return uintptr(m.instance)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *ICefDragHandler) Free() {
|
|
|
|
if m.instance != nil {
|
|
|
|
m.base.Free(m.Instance())
|
|
|
|
m.instance = nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *ICefDragHandler) IsValid() bool {
|
|
|
|
if m == nil || m.instance == nil {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return m.instance != nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *ICefDragHandler) SetOnDragEnter(fn onDragEnter) {
|
|
|
|
if !m.IsValid() {
|
|
|
|
return
|
|
|
|
}
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefDragHandler_OnDragEnter).Call(m.Instance(), api.MakeEventDataPtr(fn))
|
2023-05-31 17:41:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func (m *ICefDragHandler) SetOnDraggableRegionsChanged(fn onDraggableRegionsChanged) {
|
|
|
|
if !m.IsValid() {
|
|
|
|
return
|
|
|
|
}
|
2023-06-11 00:10:55 +08:00
|
|
|
imports.Proc(def.CefDragHandler_OnDraggableRegionsChanged).Call(m.Instance(), api.MakeEventDataPtr(fn))
|
2023-05-31 17:41:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ************************** events ************************** //
|
|
|
|
|
|
|
|
type onDragEnter func(browser *ICefBrowser, dragData *ICefDragData, mask consts.TCefDragOperations) bool
|
|
|
|
type onDraggableRegionsChanged func(browser *ICefBrowser, frame *ICefFrame, regions *TCefDraggableRegions)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
lcl.RegisterExtEventCallback(func(fn interface{}, getVal func(idx int) uintptr) bool {
|
|
|
|
getPtr := func(i int) unsafe.Pointer {
|
|
|
|
return unsafe.Pointer(getVal(i))
|
|
|
|
}
|
|
|
|
switch fn.(type) {
|
|
|
|
case onDragEnter:
|
|
|
|
browse := &ICefBrowser{instance: getPtr(0)}
|
|
|
|
dragData := &ICefDragData{instance: getPtr(1)}
|
|
|
|
mask := consts.TCefDragOperations(getVal(2))
|
|
|
|
result := (*bool)(getPtr(3))
|
|
|
|
*result = fn.(onDragEnter)(browse, dragData, mask)
|
|
|
|
case onDraggableRegionsChanged:
|
|
|
|
browse := &ICefBrowser{instance: getPtr(0)}
|
|
|
|
frame := &ICefFrame{instance: getPtr(1)}
|
|
|
|
regionsCount := int32(getVal(2))
|
|
|
|
regions := NewCefDraggableRegions()
|
|
|
|
var region TCefDraggableRegion
|
|
|
|
var regionSize = unsafe.Sizeof(region)
|
|
|
|
for i := 0; i < int(regionsCount); i++ {
|
|
|
|
region = *(*TCefDraggableRegion)(common.GetParamPtr(getVal(3), i*int(regionSize)))
|
|
|
|
regions.Append(region)
|
|
|
|
}
|
|
|
|
fn.(onDraggableRegionsChanged)(browse, frame, regions)
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
})
|
|
|
|
}
|