energy/cef/cef-frame.go

191 lines
5.3 KiB
Go
Raw Normal View History

2023-02-20 14:42:17 +08:00
// ----------------------------------------
2022-10-04 13:21:05 +08:00
//
// Copyright © yanghy. All Rights Reserved.
//
2023-02-20 14:42:17 +08:00
// # Licensed under Apache License Version 2.0, January 2004
//
// https://www.apache.org/licenses/LICENSE-2.0
2022-10-04 13:21:05 +08:00
//
2023-02-20 14:42:17 +08:00
// ----------------------------------------
2022-10-04 13:21:05 +08:00
2023-02-20 14:42:17 +08:00
// CEF Frame
2022-10-04 13:21:05 +08:00
package cef
import (
"github.com/energye/energy/common/imports"
2022-10-04 22:34:57 +08:00
. "github.com/energye/energy/consts"
2023-03-14 12:13:30 +08:00
"github.com/energye/energy/ipc"
2023-03-14 17:07:15 +08:00
"github.com/energye/energy/pkgs/json"
2022-10-04 13:21:05 +08:00
"github.com/energye/golcl/lcl/api"
"unsafe"
)
// Instance 实例
func (m *ICefFrame) Instance() uintptr {
return uintptr(m.instance)
}
2023-02-20 14:42:17 +08:00
// Undo 撤销操作
2022-10-04 13:21:05 +08:00
func (m *ICefFrame) Undo() {
2023-02-26 19:14:49 +08:00
imports.Proc(internale_CEFFrame_Undo).Call(m.Instance())
2022-10-04 13:21:05 +08:00
}
2023-02-20 14:42:17 +08:00
// Redo 恢复
2022-10-04 13:21:05 +08:00
func (m *ICefFrame) Redo() {
2023-02-26 19:14:49 +08:00
imports.Proc(internale_CEFFrame_Redo).Call(m.Instance())
2022-10-04 13:21:05 +08:00
}
2023-02-20 14:42:17 +08:00
// Cut 剪切
2022-10-04 13:21:05 +08:00
func (m *ICefFrame) Cut() {
2023-02-26 19:14:49 +08:00
imports.Proc(internale_CEFFrame_Cut).Call(m.Instance())
2022-10-04 13:21:05 +08:00
}
2023-02-20 14:42:17 +08:00
// Copy 复制
2022-10-04 13:21:05 +08:00
func (m *ICefFrame) Copy() {
2023-02-26 19:14:49 +08:00
imports.Proc(internale_CEFFrame_Copy).Call(m.Instance())
2022-10-04 13:21:05 +08:00
}
2023-02-20 14:42:17 +08:00
// Paste 粘贴
2022-10-04 13:21:05 +08:00
func (m *ICefFrame) Paste() {
2023-02-26 19:14:49 +08:00
imports.Proc(internale_CEFFrame_Paste).Call(m.Instance())
2022-10-04 13:21:05 +08:00
}
2023-02-20 14:42:17 +08:00
// Del 删除
2022-10-04 13:21:05 +08:00
func (m *ICefFrame) Del() {
2023-02-26 19:14:49 +08:00
imports.Proc(internale_CEFFrame_Del).Call(m.Instance())
2022-10-04 13:21:05 +08:00
}
2023-02-20 14:42:17 +08:00
// SelectAll 选择所有
2022-10-04 13:21:05 +08:00
func (m *ICefFrame) SelectAll() {
2023-02-26 19:14:49 +08:00
imports.Proc(internale_CEFFrame_SelectAll).Call(m.Instance())
2022-10-04 13:21:05 +08:00
}
2023-02-20 14:42:17 +08:00
// ViewSource 显示源码
2022-10-04 13:21:05 +08:00
func (m *ICefFrame) ViewSource() {
2023-02-26 19:14:49 +08:00
imports.Proc(internale_CEFFrame_ViewSource).Call(m.Instance())
2022-10-04 13:21:05 +08:00
}
2023-02-20 14:42:17 +08:00
// LoadUrl 加载URL
2022-10-04 13:21:05 +08:00
func (m *ICefFrame) LoadUrl(url string) {
2023-02-26 19:14:49 +08:00
imports.Proc(internale_CEFFrame_LoadUrl).Call(m.Instance(), api.PascalStr(url))
2022-10-04 13:21:05 +08:00
}
2023-02-20 14:42:17 +08:00
// ExecuteJavaScript 执行JS
2022-10-04 13:21:05 +08:00
func (m *ICefFrame) ExecuteJavaScript(code, scriptUrl string, startLine int32) {
2023-02-26 19:14:49 +08:00
imports.Proc(internale_CEFFrame_ExecuteJavaScript).Call(m.Instance(), api.PascalStr(code), api.PascalStr(scriptUrl), uintptr(startLine))
2022-10-04 13:21:05 +08:00
}
2023-02-20 14:42:17 +08:00
// IsValid 该Frame是否有效
2022-10-04 13:21:05 +08:00
func (m *ICefFrame) IsValid() bool {
2023-03-14 17:07:15 +08:00
if m.instance == nil {
return false
}
2023-02-26 19:14:49 +08:00
r1, _, _ := imports.Proc(internale_CEFFrame_IsValid).Call(m.Instance())
2022-12-03 21:56:51 +08:00
return api.GoBool(r1)
2022-10-04 13:21:05 +08:00
}
2023-02-20 14:42:17 +08:00
// IsMain 是否为主Frame
2022-10-04 13:21:05 +08:00
func (m *ICefFrame) IsMain() bool {
2023-02-26 19:14:49 +08:00
r1, _, _ := imports.Proc(internale_CEFFrame_IsMain).Call(m.Instance())
2022-12-03 21:56:51 +08:00
return api.GoBool(r1)
2022-10-04 13:21:05 +08:00
}
2023-02-20 14:42:17 +08:00
// IsFocused 是否已获取焦点
2022-10-04 13:21:05 +08:00
func (m *ICefFrame) IsFocused() bool {
2023-02-26 19:14:49 +08:00
r1, _, _ := imports.Proc(internale_CEFFrame_IsFocused).Call(m.Instance())
2022-12-03 21:56:51 +08:00
return api.GoBool(r1)
2022-10-04 13:21:05 +08:00
}
2023-02-26 19:14:49 +08:00
// SendProcessMessage 发送进程消息
func (m *ICefFrame) SendProcessMessage(targetProcess CefProcessId, message *ICefProcessMessage) {
2023-03-14 17:07:15 +08:00
imports.Proc(internale_CEFFrame_SendProcessMessage).Call(m.Instance(), targetProcess.ToPtr(), message.Instance())
message.Free()
2023-03-14 12:13:30 +08:00
}
2023-03-16 22:58:31 +08:00
// SendProcessMessageForJSONBytes 发送进程消息
2023-03-17 14:43:31 +08:00
func (m *ICefFrame) SendProcessMessageForJSONBytes(messageName string, targetProcess CefProcessId, data []byte) {
imports.Proc(internale_CEFFrame_SendProcessMessageForJSONBytes).Call(m.Instance(), api.PascalStr(messageName), targetProcess.ToPtr(), uintptr(unsafe.Pointer(&data[0])), uintptr(uint32(len(data))))
2023-03-16 22:58:31 +08:00
}
2023-03-14 17:07:15 +08:00
// SendProcessMessageForIPC IPC 发送进程 消息
//
// messageId != 0 是带有回调函数消息
2023-03-18 00:54:54 +08:00
func (m *ICefFrame) EmitRender(messageId int32, eventName string, target ipc.ITarget, data ...any) {
2023-03-16 22:58:31 +08:00
message := json.NewJSONObject(nil)
message.Set(ipc_id, messageId)
message.Set(ipc_event, eventName)
argumentJSONArray := json.NewJSONArray(nil)
for _, result := range data {
switch result.(type) {
case error:
argumentJSONArray.Add(result.(error).Error())
default:
argumentJSONArray.Add(result)
2023-03-14 17:07:15 +08:00
}
}
2023-03-16 22:58:31 +08:00
message.Set(ipc_argumentList, argumentJSONArray)
2023-03-18 00:54:54 +08:00
m.SendProcessMessageForJSONBytes(internalProcessMessageIPCOn, PID_RENDER, message.Bytes())
2023-03-17 14:43:31 +08:00
message.Free()
}
2023-02-26 19:14:49 +08:00
func (m *ICefFrame) LoadRequest(request *ICefRequest) {
if m == nil || request == nil {
return
}
imports.Proc(internale_CEFFrame_LoadRequest).Call(m.Instance(), request.Instance())
}
func (m *ICefFrame) Browser() *ICefBrowser {
var result uintptr
imports.Proc(internale_CEFFrame_Browser).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
return &ICefBrowser{instance: unsafe.Pointer(result)}
}
func (m *ICefFrame) V8Context() *ICefV8Context {
var result uintptr
imports.Proc(internale_CEFFrame_GetV8Context).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
return &ICefV8Context{instance: unsafe.Pointer(result)}
}
func (m *ICefFrame) Identifier() int64 {
var result uintptr
imports.Proc(internale_CEFFrame_Identifier).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
return int64(result)
}
func (m *ICefFrame) Name() string {
r1, _, _ := imports.Proc(internale_CEFFrame_Name).Call(m.Instance())
return api.GoStr(r1)
}
func (m *ICefFrame) Url() string {
r1, _, _ := imports.Proc(internale_CEFFrame_Url).Call(m.Instance())
return api.GoStr(r1)
}
func (m *ICefFrame) Parent() *ICefFrame {
var result uintptr
imports.Proc(internale_CEFFrame_Parent).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
return &ICefFrame{instance: unsafe.Pointer(result)}
}
2023-03-04 11:19:45 +08:00
2023-03-09 19:27:00 +08:00
func (m *ICefFrame) Free() {
2023-03-12 15:29:46 +08:00
if m.instance != nil {
m.base.Free(m.Instance())
m.instance = nil
}
2023-03-09 19:27:00 +08:00
}
2023-03-04 11:19:45 +08:00
// FrameRef -> *ICefFrame
var FrameRef frameRef
// frameRef
type frameRef uintptr
func (m *frameRef) UnWrap(data *ICefFrame) *ICefFrame {
var result uintptr
imports.Proc(internale_CEFFrameRef_UnWrap).Call(data.Instance(), uintptr(unsafe.Pointer(&result)))
2023-03-04 11:58:35 +08:00
data.instance = unsafe.Pointer(result)
return data
2023-03-04 11:19:45 +08:00
}