energy/cef/types-browser-view-component.go

136 lines
5.6 KiB
Go
Raw Normal View History

//----------------------------------------
//
// Copyright © yanghy. All Rights Reserved.
//
// Licensed under Apache License Version 2.0, January 2004
//
// https://www.apache.org/licenses/LICENSE-2.0
//
//----------------------------------------
2023-05-31 17:41:14 +08:00
// VF 窗口组件 BrowserView
package cef
import (
"github.com/energye/energy/v2/cef/internal/def"
2023-05-31 18:00:34 +08:00
"github.com/energye/energy/v2/common/imports"
"github.com/energye/energy/v2/consts"
"github.com/energye/golcl/lcl"
2022-12-13 22:43:31 +08:00
"github.com/energye/golcl/lcl/api"
"unsafe"
)
2023-02-20 00:20:01 +08:00
// TCEFBrowserViewComponent
type TCEFBrowserViewComponent struct {
lcl.IComponent
instance unsafe.Pointer
}
2023-02-20 00:20:01 +08:00
// NewBrowserViewComponent
2022-12-27 21:38:01 +08:00
func NewBrowserViewComponent(AOwner lcl.IComponent) *TCEFBrowserViewComponent {
2023-02-26 19:14:49 +08:00
var result uintptr
imports.Proc(def.CEFBrowserViewComponent_Create).Call(lcl.CheckPtr(AOwner), uintptr(unsafe.Pointer(&result)))
2023-02-28 21:52:13 +08:00
return &TCEFBrowserViewComponent{instance: unsafe.Pointer(result)}
2022-12-13 22:43:31 +08:00
}
2023-02-20 00:20:01 +08:00
// CreateBrowserView
2023-02-26 19:14:49 +08:00
func (m *TCEFBrowserViewComponent) CreateBrowserView(client *ICefClient, url string, requestContextSettings *TCefRequestContextSettings, browserSettings *TCefBrowserSettings, extraInfo *ICefDictionaryValue) {
2022-12-14 13:17:53 +08:00
contextSettingsPtr := requestContextSettings.ToPtr()
browserSettingsPtr := browserSettings.ToPtr()
2023-02-26 19:14:49 +08:00
if extraInfo == nil {
extraInfo = DictionaryValueRef.New()
2022-12-13 22:43:31 +08:00
}
imports.Proc(def.CEFBrowserViewComponent_CreateBrowserView).Call(m.Instance(), uintptr(client.instance), api.PascalStr(url), uintptr(unsafe.Pointer(&contextSettingsPtr)), uintptr(unsafe.Pointer(&browserSettingsPtr)), extraInfo.Instance())
2022-12-13 22:43:31 +08:00
}
2023-02-20 00:20:01 +08:00
// Instance
2022-12-27 21:38:01 +08:00
func (m *TCEFBrowserViewComponent) Instance() uintptr {
return uintptr(m.instance)
}
2023-02-20 00:20:01 +08:00
// GetForBrowser
2022-12-13 22:43:31 +08:00
func (m *TCEFBrowserViewComponent) GetForBrowser(browser *ICefBrowser) {
imports.Proc(def.CEFBrowserViewComponent_GetForBrowser).Call(m.Instance(), browser.Instance())
2022-12-13 22:43:31 +08:00
}
2023-02-20 00:20:01 +08:00
// SetPreferAccelerators
2022-12-14 19:18:11 +08:00
func (m *TCEFBrowserViewComponent) SetPreferAccelerators(preferAccelerators bool) {
imports.Proc(def.CEFBrowserViewComponent_SetPreferAccelerators).Call(m.Instance(), api.PascalBool(preferAccelerators))
2022-12-13 22:43:31 +08:00
}
2023-02-20 00:20:01 +08:00
// RequestFocus
2022-12-13 22:43:31 +08:00
func (m *TCEFBrowserViewComponent) RequestFocus() {
imports.Proc(def.CEFBrowserViewComponent_RequestFocus).Call(m.Instance())
2022-12-13 22:43:31 +08:00
}
2023-02-20 00:20:01 +08:00
// Browser
2022-12-14 19:18:11 +08:00
func (m *TCEFBrowserViewComponent) Browser() *ICefBrowser {
2023-02-26 19:14:49 +08:00
var result uintptr
imports.Proc(def.CEFBrowserViewComponent_Browser).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
2023-02-28 21:52:13 +08:00
return &ICefBrowser{instance: unsafe.Pointer(result)}
2022-12-13 22:43:31 +08:00
}
2022-12-14 19:18:11 +08:00
//func (m *TCEFBrowserViewComponent) BrowserView() {
// Proc(CEFBrowserViewComponent_BrowserView).Call(m.Instance())
2022-12-14 19:18:11 +08:00
//}
2022-12-13 22:43:31 +08:00
2023-02-20 00:20:01 +08:00
// SetOnBrowserCreated
2022-12-14 19:18:11 +08:00
func (m *TCEFBrowserViewComponent) SetOnBrowserCreated(fn BrowserViewComponentOnBrowserCreated) {
imports.Proc(def.CEFBrowserViewComponent_SetOnBrowserCreated).Call(m.Instance(), api.MakeEventDataPtr(fn))
2022-12-13 22:43:31 +08:00
}
2023-02-20 00:20:01 +08:00
// SetOnBrowserDestroyed
2022-12-14 19:18:11 +08:00
func (m *TCEFBrowserViewComponent) SetOnBrowserDestroyed(fn BrowserViewComponentOnBrowserDestroyed) {
imports.Proc(def.CEFBrowserViewComponent_SetOnBrowserDestroyed).Call(m.Instance(), api.MakeEventDataPtr(fn))
2022-12-13 22:43:31 +08:00
}
2023-02-20 00:20:01 +08:00
// SetOnGetDelegateForPopupBrowserView
2022-12-14 19:18:11 +08:00
func (m *TCEFBrowserViewComponent) SetOnGetDelegateForPopupBrowserView(fn BrowserViewComponentOnGetDelegateForPopupBrowserView) {
imports.Proc(def.CEFBrowserViewComponent_SetOnGetDelegateForPopupBrowserView).Call(m.Instance(), api.MakeEventDataPtr(fn))
2022-12-13 22:43:31 +08:00
}
2023-02-20 00:20:01 +08:00
// SetOnPopupBrowserViewCreated
2022-12-14 19:18:11 +08:00
func (m *TCEFBrowserViewComponent) SetOnPopupBrowserViewCreated(fn BrowserViewComponentOnPopupBrowserViewCreated) {
imports.Proc(def.CEFBrowserViewComponent_SetOnPopupBrowserViewCreated).Call(m.Instance(), api.MakeEventDataPtr(fn))
2022-12-13 22:43:31 +08:00
}
2023-02-20 00:20:01 +08:00
// SetOnGetChromeToolbarType
2022-12-14 19:18:11 +08:00
func (m *TCEFBrowserViewComponent) SetOnGetChromeToolbarType(fn BrowserViewComponentOnGetChromeToolbarType) {
imports.Proc(def.CEFBrowserViewComponent_SetOnGetChromeToolbarType).Call(m.Instance(), api.MakeEventDataPtr(fn))
2022-12-13 22:43:31 +08:00
}
func init() {
lcl.RegisterExtEventCallback(func(fn interface{}, getVal func(idx int) uintptr) bool {
2022-12-14 19:18:11 +08:00
getPtr := func(i int) unsafe.Pointer {
return unsafe.Pointer(getVal(i))
}
2022-12-13 22:43:31 +08:00
switch fn.(type) {
2022-12-14 19:18:11 +08:00
case BrowserViewComponentOnBrowserCreated:
2023-07-02 22:06:51 +08:00
browserView := &ICefBrowserView{&ICefView{instance: getPtr(1)}}
2023-02-26 19:14:49 +08:00
browser := &ICefBrowser{instance: getPtr(2)}
2022-12-14 19:18:11 +08:00
fn.(BrowserViewComponentOnBrowserCreated)(lcl.AsObject(getPtr(0)), browserView, browser)
case BrowserViewComponentOnBrowserDestroyed:
2023-07-02 22:06:51 +08:00
browserView := &ICefBrowserView{&ICefView{instance: getPtr(1)}}
2023-02-26 19:14:49 +08:00
browser := &ICefBrowser{instance: getPtr(2)}
2022-12-14 19:18:11 +08:00
fn.(BrowserViewComponentOnBrowserDestroyed)(lcl.AsObject(getPtr(0)), browserView, browser)
case BrowserViewComponentOnGetDelegateForPopupBrowserView:
2023-07-02 22:06:51 +08:00
browserView := &ICefBrowserView{&ICefView{instance: getPtr(1)}}
2022-12-14 19:18:11 +08:00
browserSettingsPtr := (*tCefBrowserSettingsPtr)(getPtr(2))
browserSettings := browserSettingsPtr.Convert()
2023-02-28 21:52:13 +08:00
client := &ICefClient{instance: getPtr(3)}
result := &ICefBrowserViewDelegate{&ICefViewDelegate{instance: getPtr(5)}}
2022-12-14 19:18:11 +08:00
fn.(BrowserViewComponentOnGetDelegateForPopupBrowserView)(lcl.AsObject(getPtr(0)), browserView, browserSettings, client, api.GoBool(getVal(4)), result)
case BrowserViewComponentOnPopupBrowserViewCreated:
2023-07-02 22:06:51 +08:00
browserView := &ICefBrowserView{&ICefView{instance: getPtr(1)}}
popupBrowserView := &ICefBrowserView{&ICefView{instance: getPtr(2)}}
2022-12-14 19:18:11 +08:00
fn.(BrowserViewComponentOnPopupBrowserViewCreated)(lcl.AsObject(getPtr(0)), browserView, popupBrowserView, api.GoBool(getVal(3)), (*bool)(getPtr(4)))
case BrowserViewComponentOnGetChromeToolbarType:
fn.(BrowserViewComponentOnGetChromeToolbarType)(lcl.AsObject(getPtr(0)), (*consts.TCefChromeToolbarType)(getPtr(1)))
2022-12-13 22:43:31 +08:00
default:
return false
}
return true
})
}