2022-12-31 13:16:30 +08:00
|
|
|
//----------------------------------------
|
|
|
|
//
|
|
|
|
// Copyright © yanghy. All Rights Reserved.
|
|
|
|
//
|
2023-02-19 23:21:47 +08:00
|
|
|
// Licensed under Apache License Version 2.0, January 2004
|
|
|
|
//
|
|
|
|
// https://www.apache.org/licenses/LICENSE-2.0
|
2022-12-31 13:16:30 +08:00
|
|
|
//
|
|
|
|
//----------------------------------------
|
|
|
|
|
2022-10-04 13:21:05 +08:00
|
|
|
package cef
|
|
|
|
|
2022-12-12 17:34:57 +08:00
|
|
|
import (
|
2023-03-01 13:38:43 +08:00
|
|
|
"errors"
|
2023-05-31 18:00:34 +08:00
|
|
|
"github.com/energye/energy/v2/common/imports"
|
|
|
|
"github.com/energye/energy/v2/consts"
|
|
|
|
"github.com/energye/energy/v2/types"
|
2022-12-29 22:40:36 +08:00
|
|
|
"github.com/energye/golcl/energy/emfs"
|
2022-12-12 17:34:57 +08:00
|
|
|
"github.com/energye/golcl/lcl"
|
2022-12-12 20:46:53 +08:00
|
|
|
"github.com/energye/golcl/lcl/api"
|
2022-12-30 18:22:21 +08:00
|
|
|
"io/ioutil"
|
2023-03-01 13:38:43 +08:00
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
2022-12-12 17:34:57 +08:00
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// TCEFWindowComponent 窗口组件
|
2022-12-12 17:34:57 +08:00
|
|
|
type TCEFWindowComponent struct {
|
2023-01-01 22:19:26 +08:00
|
|
|
lcl.IComponent
|
2022-12-12 17:34:57 +08:00
|
|
|
instance unsafe.Pointer
|
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// NewWindowComponent 创建一个Window组件
|
2022-12-12 17:34:57 +08:00
|
|
|
func NewWindowComponent(AOwner lcl.IComponent) *TCEFWindowComponent {
|
2023-02-13 21:25:35 +08:00
|
|
|
r1, _, _ := imports.Proc(internale_CEFWindowComponent_Create).Call(lcl.CheckPtr(AOwner))
|
2022-12-12 17:34:57 +08:00
|
|
|
return &TCEFWindowComponent{
|
|
|
|
instance: unsafe.Pointer(r1),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-01 13:38:43 +08:00
|
|
|
// Instance 实例
|
|
|
|
func (m *TCEFWindowComponent) Instance() uintptr {
|
|
|
|
return uintptr(m.instance)
|
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// CreateTopLevelWindow 创建顶层窗口
|
2022-12-12 17:34:57 +08:00
|
|
|
func (m *TCEFWindowComponent) CreateTopLevelWindow() {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_CreateTopLevelWindow).Call(m.Instance())
|
2022-12-12 17:34:57 +08:00
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// Show 显示窗口
|
2022-12-12 17:34:57 +08:00
|
|
|
func (m *TCEFWindowComponent) Show() {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_Show).Call(m.Instance())
|
2022-12-12 17:34:57 +08:00
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// Hide 显示窗口
|
2022-12-12 17:34:57 +08:00
|
|
|
func (m *TCEFWindowComponent) Hide() {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_Hide).Call(m.Instance())
|
2022-12-12 17:34:57 +08:00
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// CenterWindow 根据大小窗口居中
|
2022-12-27 21:38:01 +08:00
|
|
|
func (m *TCEFWindowComponent) CenterWindow(size *TCefSize) {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_CenterWindow).Call(m.Instance(), uintptr(unsafe.Pointer(size)))
|
2022-12-12 17:34:57 +08:00
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// Close 关闭窗口, 主窗口调用
|
2022-12-12 17:34:57 +08:00
|
|
|
func (m *TCEFWindowComponent) Close() {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_Close).Call(m.Instance())
|
2022-12-12 17:34:57 +08:00
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// Activate 激活窗口
|
2022-12-12 17:34:57 +08:00
|
|
|
func (m *TCEFWindowComponent) Activate() {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_Activate).Call(m.Instance())
|
2022-12-12 17:34:57 +08:00
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// Deactivate 停止激活窗口
|
2022-12-12 17:34:57 +08:00
|
|
|
func (m *TCEFWindowComponent) Deactivate() {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_Deactivate).Call(m.Instance())
|
2022-12-12 17:34:57 +08:00
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// BringToTop 将窗口移至最上层
|
2022-12-12 17:34:57 +08:00
|
|
|
func (m *TCEFWindowComponent) BringToTop() {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_BringToTop).Call(m.Instance())
|
2022-12-12 17:34:57 +08:00
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// Maximize 最大化窗口
|
2022-12-12 17:34:57 +08:00
|
|
|
func (m *TCEFWindowComponent) Maximize() {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_Maximize).Call(m.Instance())
|
2022-12-12 17:34:57 +08:00
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// Minimize 最小化窗口
|
2022-12-12 17:34:57 +08:00
|
|
|
func (m *TCEFWindowComponent) Minimize() {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_Minimize).Call(m.Instance())
|
2022-12-12 17:34:57 +08:00
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// Restore 窗口还原
|
2022-12-12 17:34:57 +08:00
|
|
|
func (m *TCEFWindowComponent) Restore() {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_Restore).Call(m.Instance())
|
2022-12-12 17:34:57 +08:00
|
|
|
}
|
|
|
|
|
2022-12-29 18:42:16 +08:00
|
|
|
//func (m *TCEFWindowComponent) AddOverlayView() {
|
2023-03-01 13:38:43 +08:00
|
|
|
//imports.Proc(internale_CEFWindowComponent_AddOverlayView).Call(m.Instance())
|
2022-12-29 18:42:16 +08:00
|
|
|
//}
|
2022-12-12 17:34:57 +08:00
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// ShowMenu 显示菜单
|
2022-12-12 17:34:57 +08:00
|
|
|
func (m *TCEFWindowComponent) ShowMenu(menuModel *ICefMenuModel, point TCefPoint, anchorPosition consts.TCefMenuAnchorPosition) {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_ShowMenu).Call(m.Instance(), uintptr(menuModel.instance), uintptr(unsafe.Pointer(&point)), uintptr(anchorPosition))
|
2022-12-12 17:34:57 +08:00
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// CancelMenu 取消菜单
|
2022-12-12 17:34:57 +08:00
|
|
|
func (m *TCEFWindowComponent) CancelMenu() {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_CancelMenu).Call(m.Instance())
|
2022-12-12 17:34:57 +08:00
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// SetDraggableRegions 设置拖拽区域
|
2023-01-07 23:39:34 +08:00
|
|
|
func (m *TCEFWindowComponent) SetDraggableRegions(regions []TCefDraggableRegion) {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_SetDraggableRegions).Call(m.Instance(), uintptr(int32(len(regions))), uintptr(unsafe.Pointer(®ions[0])), uintptr(int32(len(regions))))
|
2022-12-12 17:34:57 +08:00
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// SendKeyPress 发送键盘事件
|
2022-12-12 18:09:31 +08:00
|
|
|
func (m *TCEFWindowComponent) SendKeyPress(keyCode int32, eventFlags uint32) {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_SendKeyPress).Call(m.Instance(), uintptr(keyCode), uintptr(eventFlags))
|
2022-12-12 17:34:57 +08:00
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// SendMouseMove 发送鼠标移动事件
|
2022-12-12 18:09:31 +08:00
|
|
|
func (m *TCEFWindowComponent) SendMouseMove(screenX, screenY int32) {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_SendMouseMove).Call(m.Instance(), uintptr(screenX), uintptr(screenY))
|
2022-12-12 17:34:57 +08:00
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// SendMouseEvents 发送鼠标事件
|
2022-12-12 20:46:53 +08:00
|
|
|
func (m *TCEFWindowComponent) SendMouseEvents(button consts.TCefMouseButtonType, mouseDown, mouseUp bool) {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_SendMouseEvents).Call(m.Instance(), uintptr(button), api.PascalBool(mouseDown), api.PascalBool(mouseUp))
|
2022-12-12 17:34:57 +08:00
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// SetAccelerator 设置快捷键
|
2022-12-12 20:46:53 +08:00
|
|
|
func (m *TCEFWindowComponent) SetAccelerator(commandId, keyCode int32, shiftPressed, ctrlPressed, altPressed bool) {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_SetAccelerator).Call(m.Instance(), uintptr(commandId), uintptr(keyCode), api.PascalBool(shiftPressed), api.PascalBool(ctrlPressed), api.PascalBool(altPressed))
|
2022-12-12 17:34:57 +08:00
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// RemoveAccelerator 移除指定快捷键
|
2022-12-12 20:46:53 +08:00
|
|
|
func (m *TCEFWindowComponent) RemoveAccelerator(commandId int32) {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_RemoveAccelerator).Call(m.Instance(), uintptr(commandId))
|
2022-12-12 17:34:57 +08:00
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// RemoveAllAccelerators 移除所有快捷键
|
2022-12-12 17:34:57 +08:00
|
|
|
func (m *TCEFWindowComponent) RemoveAllAccelerators() {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_RemoveAllAccelerators).Call(m.Instance())
|
2022-12-12 17:34:57 +08:00
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// SetAlwaysOnTop 设置窗口是否置顶
|
2022-12-30 18:30:46 +08:00
|
|
|
func (m *TCEFWindowComponent) SetAlwaysOnTop(onTop bool) {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_SetAlwaysOnTop).Call(m.Instance(), api.PascalBool(onTop))
|
2022-12-30 18:30:46 +08:00
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// SetFullscreen 设置窗口全屏
|
2022-12-30 18:30:46 +08:00
|
|
|
func (m *TCEFWindowComponent) SetFullscreen(fullscreen bool) {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_SetFullscreen).Call(m.Instance(), api.PascalBool(fullscreen))
|
2022-12-30 18:30:46 +08:00
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// SetBackgroundColor 设置背景色
|
2023-01-07 11:48:19 +08:00
|
|
|
func (m *TCEFWindowComponent) SetBackgroundColor(rect *types.TCefColor) {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_SetBackgroundColor).Call(m.Instance(), rect.ToPtr())
|
2023-01-07 11:48:19 +08:00
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// SetBounds 获取窗口边界
|
2023-01-09 08:53:01 +08:00
|
|
|
func (m *TCEFWindowComponent) Bounds() (result *TCefRect) {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_Bounds).Call(m.Instance(), uintptr(unsafe.Pointer(result)))
|
2023-01-09 08:53:01 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// SetSize 获取窗口宽高
|
2023-01-09 08:53:01 +08:00
|
|
|
func (m *TCEFWindowComponent) Size() (result *TCefSize) {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_Size).Call(m.Instance(), uintptr(unsafe.Pointer(result)))
|
2023-01-09 08:53:01 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// Position 获取窗口位置
|
2023-01-09 08:53:01 +08:00
|
|
|
func (m *TCEFWindowComponent) Position() (result *TCefPoint) {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_Position).Call(m.Instance(), uintptr(unsafe.Pointer(result)))
|
2023-01-09 08:53:01 +08:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// SetBounds 设置窗口边界
|
2023-01-07 11:48:19 +08:00
|
|
|
func (m *TCEFWindowComponent) SetBounds(rect *TCefRect) {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_SetBounds).Call(m.Instance(), uintptr(unsafe.Pointer(rect)))
|
2023-01-07 11:48:19 +08:00
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// SetSize 设置窗口宽高
|
2023-01-07 11:48:19 +08:00
|
|
|
func (m *TCEFWindowComponent) SetSize(size *TCefSize) {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_SetSize).Call(m.Instance(), uintptr(unsafe.Pointer(size)))
|
2023-01-07 11:48:19 +08:00
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// SetPosition 设置窗口位置
|
2023-01-07 11:48:19 +08:00
|
|
|
func (m *TCEFWindowComponent) SetPosition(point *TCefPoint) {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_SetPosition).Call(m.Instance(), uintptr(unsafe.Pointer(point)))
|
2023-01-07 11:48:19 +08:00
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// SetTitle 设置窗口标题
|
2022-12-12 20:46:53 +08:00
|
|
|
func (m *TCEFWindowComponent) SetTitle(title string) {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_SetTitle).Call(m.Instance(), api.PascalStr(title))
|
2022-12-12 17:34:57 +08:00
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// GetTitle 获取窗口标题
|
2022-12-12 20:46:53 +08:00
|
|
|
func (m *TCEFWindowComponent) Title() string {
|
2023-03-01 13:38:43 +08:00
|
|
|
r1, _, _ := imports.Proc(internale_CEFWindowComponent_Title).Call(m.Instance())
|
2022-12-12 20:46:53 +08:00
|
|
|
return api.GoStr(r1)
|
2022-12-12 17:34:57 +08:00
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// WindowIcon 获取窗口图标
|
2022-12-12 20:46:53 +08:00
|
|
|
func (m *TCEFWindowComponent) WindowIcon() *ICefImage {
|
2023-03-01 13:38:43 +08:00
|
|
|
var result uintptr
|
|
|
|
imports.Proc(internale_CEFWindowComponent_WindowIcon).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
|
2022-12-12 20:46:53 +08:00
|
|
|
return &ICefImage{
|
2023-03-01 13:38:43 +08:00
|
|
|
instance: unsafe.Pointer(result),
|
2022-12-12 20:46:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// WindowAppIcon 获取窗口应用图标
|
|
|
|
func (m *TCEFWindowComponent) WindowAppIcon() *ICefImage {
|
2023-03-01 13:38:43 +08:00
|
|
|
var result uintptr
|
|
|
|
imports.Proc(internale_CEFWindowComponent_WindowAppIcon).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
|
2023-02-20 14:42:17 +08:00
|
|
|
return &ICefImage{
|
2023-03-01 13:38:43 +08:00
|
|
|
instance: unsafe.Pointer(result),
|
2023-02-20 14:42:17 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-01 13:38:43 +08:00
|
|
|
func (m *TCEFWindowComponent) SetWindowIcon(icon *ICefImage) {
|
|
|
|
imports.Proc(internale_CEFWindowComponent_SetWindowIcon).Call(m.Instance(), icon.Instance())
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *TCEFWindowComponent) checkICON(filename string) (string, error) {
|
|
|
|
ext := strings.ToLower(filepath.Ext(filename))
|
|
|
|
if ".png" != ext && ".jpeg" != ext {
|
|
|
|
return "", errors.New("only png and jpeg image formats are supported")
|
|
|
|
}
|
|
|
|
ext = ext[1:]
|
|
|
|
return ext, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetWindowIconByFile 设置窗口图标
|
|
|
|
func (m *TCEFWindowComponent) SetWindowIconByFile(scaleFactor float32, filename string) error {
|
|
|
|
var (
|
|
|
|
ext string
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
if ext, err = m.checkICON(filename); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-12-30 18:22:21 +08:00
|
|
|
bytes, err := ioutil.ReadFile(filename)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-03-01 13:38:43 +08:00
|
|
|
icon := ImageRef.New()
|
|
|
|
if "png" == ext {
|
|
|
|
icon.AddPng(scaleFactor, bytes)
|
|
|
|
} else if "jpeg" == ext {
|
|
|
|
icon.AddJpeg(scaleFactor, bytes)
|
|
|
|
}
|
|
|
|
m.SetWindowIcon(icon)
|
2022-12-30 18:22:21 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-03-01 13:38:43 +08:00
|
|
|
// SetWindowIconByFSFile 设置窗口图标
|
|
|
|
func (m *TCEFWindowComponent) SetWindowIconByFSFile(scaleFactor float32, filename string) error {
|
|
|
|
var (
|
|
|
|
ext string
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
if ext, err = m.checkICON(filename); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-12-29 22:40:36 +08:00
|
|
|
bytes, err := emfs.GetResources(filename)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-03-01 13:38:43 +08:00
|
|
|
icon := ImageRef.New()
|
|
|
|
if "png" == ext {
|
|
|
|
icon.AddPng(scaleFactor, bytes)
|
|
|
|
} else if "jpeg" == ext {
|
|
|
|
icon.AddJpeg(scaleFactor, bytes)
|
|
|
|
}
|
|
|
|
m.SetWindowIcon(icon)
|
2022-12-29 22:40:36 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-03-01 13:38:43 +08:00
|
|
|
func (m *TCEFWindowComponent) SetWindowAppIcon(icon *ICefImage) {
|
|
|
|
imports.Proc(internale_CEFWindowComponent_SetWindowAppIcon).Call(m.Instance(), icon.Instance())
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetWindowAppIconByFile 设置窗口应用图标
|
|
|
|
func (m *TCEFWindowComponent) SetWindowAppIconByFile(scaleFactor float32, filename string) error {
|
|
|
|
var (
|
|
|
|
ext string
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
if ext, err = m.checkICON(filename); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-12-30 18:22:21 +08:00
|
|
|
bytes, err := ioutil.ReadFile(filename)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-03-01 13:38:43 +08:00
|
|
|
icon := ImageRef.New()
|
|
|
|
if "png" == ext {
|
|
|
|
icon.AddPng(scaleFactor, bytes)
|
|
|
|
} else if "jpeg" == ext {
|
|
|
|
icon.AddJpeg(scaleFactor, bytes)
|
|
|
|
}
|
|
|
|
m.SetWindowAppIcon(icon)
|
2022-12-30 18:22:21 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-03-01 13:38:43 +08:00
|
|
|
// SetWindowAppIconByFSFile 设置窗口应用图标
|
|
|
|
func (m *TCEFWindowComponent) SetWindowAppIconByFSFile(scaleFactor float32, filename string) error {
|
|
|
|
var (
|
|
|
|
ext string
|
|
|
|
err error
|
|
|
|
)
|
|
|
|
if ext, err = m.checkICON(filename); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2022-12-29 22:40:36 +08:00
|
|
|
bytes, err := emfs.GetResources(filename)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2023-03-01 13:38:43 +08:00
|
|
|
icon := ImageRef.New()
|
|
|
|
if "png" == ext {
|
|
|
|
icon.AddPng(scaleFactor, bytes)
|
|
|
|
} else if "jpeg" == ext {
|
|
|
|
icon.AddJpeg(scaleFactor, bytes)
|
|
|
|
}
|
|
|
|
m.SetWindowAppIcon(icon)
|
2022-12-29 22:40:36 +08:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// Display
|
2022-12-13 09:14:59 +08:00
|
|
|
func (m *TCEFWindowComponent) Display() *ICefDisplay {
|
2023-03-01 13:38:43 +08:00
|
|
|
var result uintptr
|
|
|
|
imports.Proc(internale_CEFWindowComponent_Display).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
|
2022-12-13 09:14:59 +08:00
|
|
|
return &ICefDisplay{
|
2023-03-01 13:38:43 +08:00
|
|
|
instance: unsafe.Pointer(result),
|
2022-12-13 09:14:59 +08:00
|
|
|
}
|
2022-12-12 17:34:57 +08:00
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// ClientAreaBoundsInScreen 获取客户端所在指定屏幕位置
|
2022-12-13 09:14:59 +08:00
|
|
|
func (m *TCEFWindowComponent) ClientAreaBoundsInScreen() (result TCefRect) {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_ClientAreaBoundsInScreen).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
|
2022-12-13 09:14:59 +08:00
|
|
|
return
|
2022-12-12 17:34:57 +08:00
|
|
|
}
|
2022-12-13 09:14:59 +08:00
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// WindowHandle 获取窗口句柄
|
2022-12-13 09:14:59 +08:00
|
|
|
func (m *TCEFWindowComponent) WindowHandle() consts.TCefWindowHandle {
|
2023-03-01 13:38:43 +08:00
|
|
|
r1, _, _ := imports.Proc(internale_CEFWindowComponent_WindowHandle).Call(m.Instance())
|
2022-12-13 09:14:59 +08:00
|
|
|
return consts.TCefWindowHandle(r1)
|
2022-12-12 17:34:57 +08:00
|
|
|
}
|
2022-12-13 09:14:59 +08:00
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// IsClosed 是否关闭
|
2022-12-13 09:14:59 +08:00
|
|
|
func (m *TCEFWindowComponent) IsClosed() bool {
|
2023-03-01 13:38:43 +08:00
|
|
|
r1, _, _ := imports.Proc(internale_CEFWindowComponent_IsClosed).Call(m.Instance())
|
2022-12-13 09:14:59 +08:00
|
|
|
return api.GoBool(r1)
|
2022-12-12 17:34:57 +08:00
|
|
|
}
|
2022-12-13 09:14:59 +08:00
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// IsActive 是否激活
|
2022-12-13 09:14:59 +08:00
|
|
|
func (m *TCEFWindowComponent) IsActive() bool {
|
2023-03-01 13:38:43 +08:00
|
|
|
r1, _, _ := imports.Proc(internale_CEFWindowComponent_IsActive).Call(m.Instance())
|
2022-12-13 09:14:59 +08:00
|
|
|
return api.GoBool(r1)
|
2022-12-12 17:34:57 +08:00
|
|
|
}
|
2022-12-13 09:14:59 +08:00
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// IsAlwaysOnTop 窗口是否置顶
|
2022-12-13 09:14:59 +08:00
|
|
|
func (m *TCEFWindowComponent) IsAlwaysOnTop() bool {
|
2023-03-01 13:38:43 +08:00
|
|
|
r1, _, _ := imports.Proc(internale_CEFWindowComponent_IsAlwaysOnTop).Call(m.Instance())
|
2022-12-13 09:14:59 +08:00
|
|
|
return api.GoBool(r1)
|
2022-12-12 17:34:57 +08:00
|
|
|
}
|
2022-12-13 09:14:59 +08:00
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// IsFullscreen 是否全屏
|
2022-12-13 09:14:59 +08:00
|
|
|
func (m *TCEFWindowComponent) IsFullscreen() bool {
|
2023-03-01 13:38:43 +08:00
|
|
|
r1, _, _ := imports.Proc(internale_CEFWindowComponent_IsFullscreen).Call(m.Instance())
|
2022-12-13 09:14:59 +08:00
|
|
|
return api.GoBool(r1)
|
2022-12-12 17:34:57 +08:00
|
|
|
}
|
2022-12-13 09:14:59 +08:00
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// IsMaximized 是否最大化
|
2022-12-13 09:14:59 +08:00
|
|
|
func (m *TCEFWindowComponent) IsMaximized() bool {
|
2023-03-01 13:38:43 +08:00
|
|
|
r1, _, _ := imports.Proc(internale_CEFWindowComponent_IsMaximized).Call(m.Instance())
|
2022-12-13 09:14:59 +08:00
|
|
|
return api.GoBool(r1)
|
2022-12-12 17:34:57 +08:00
|
|
|
}
|
2022-12-13 09:14:59 +08:00
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// IsMinimized 是否最小化
|
2022-12-13 09:14:59 +08:00
|
|
|
func (m *TCEFWindowComponent) IsMinimized() bool {
|
2023-03-01 13:38:43 +08:00
|
|
|
r1, _, _ := imports.Proc(internale_CEFWindowComponent_IsMinimized).Call(m.Instance())
|
2022-12-13 09:14:59 +08:00
|
|
|
return api.GoBool(r1)
|
2022-12-12 17:34:57 +08:00
|
|
|
}
|
2022-12-13 09:14:59 +08:00
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// AddChildView 添加浏览器显示组件
|
2022-12-27 21:38:01 +08:00
|
|
|
func (m *TCEFWindowComponent) AddChildView(browserViewComponent *TCEFBrowserViewComponent) {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_AddChildView).Call(m.Instance(), browserViewComponent.Instance())
|
2022-12-27 21:38:01 +08:00
|
|
|
}
|
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// SetOnWindowCreated 窗口创建回调事件
|
2022-12-13 11:49:32 +08:00
|
|
|
func (m *TCEFWindowComponent) SetOnWindowCreated(fn WindowComponentOnWindowCreated) {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_SetOnWindowCreated).Call(m.Instance(), api.MakeEventDataPtr(fn))
|
2022-12-13 11:49:32 +08:00
|
|
|
}
|
2022-12-30 16:54:42 +08:00
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// SetOnWindowDestroyed 窗口销毁回调事件
|
2022-12-13 11:49:32 +08:00
|
|
|
func (m *TCEFWindowComponent) SetOnWindowDestroyed(fn WindowComponentOnWindowDestroyed) {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_SetOnWindowDestroyed).Call(m.Instance(), api.MakeEventDataPtr(fn))
|
2022-12-13 11:49:32 +08:00
|
|
|
}
|
2022-12-30 16:54:42 +08:00
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// SetOnWindowActivationChanged 窗口激活改变回调事件
|
2022-12-13 11:49:32 +08:00
|
|
|
func (m *TCEFWindowComponent) SetOnWindowActivationChanged(fn WindowComponentOnWindowActivationChanged) {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_SetOnWindowActivationChanged).Call(m.Instance(), api.MakeEventDataPtr(fn))
|
2022-12-13 11:49:32 +08:00
|
|
|
}
|
2022-12-30 16:54:42 +08:00
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// SetOnGetParentWindow 获取父组件回调事件
|
2022-12-13 11:49:32 +08:00
|
|
|
func (m *TCEFWindowComponent) SetOnGetParentWindow(fn WindowComponentOnGetParentWindow) {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_SetOnGetParentWindow).Call(m.Instance(), api.MakeEventDataPtr(fn))
|
2022-12-13 11:49:32 +08:00
|
|
|
}
|
2022-12-30 16:54:42 +08:00
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// SetOnGetInitialBounds 窗口初始窗口边界回调事件
|
2022-12-13 11:49:32 +08:00
|
|
|
func (m *TCEFWindowComponent) SetOnGetInitialBounds(fn WindowComponentOnGetInitialBounds) {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_SetOnGetInitialBounds).Call(m.Instance(), api.MakeEventDataPtr(fn))
|
2022-12-13 11:49:32 +08:00
|
|
|
}
|
2022-12-30 16:54:42 +08:00
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// SetOnGetInitialShowState 窗口初始显示状态回调事件
|
2022-12-13 11:49:32 +08:00
|
|
|
func (m *TCEFWindowComponent) SetOnGetInitialShowState(fn WindowComponentOnGetInitialShowState) {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_SetOnGetInitialShowState).Call(m.Instance(), api.MakeEventDataPtr(fn))
|
2022-12-13 11:49:32 +08:00
|
|
|
}
|
2022-12-30 16:54:42 +08:00
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// SetOnIsFrameless 窗口无边框回调事件
|
2022-12-13 11:49:32 +08:00
|
|
|
func (m *TCEFWindowComponent) SetOnIsFrameless(fn WindowComponentOnIsFrameless) {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_SetOnIsFrameless).Call(m.Instance(), api.MakeEventDataPtr(fn))
|
2022-12-13 11:49:32 +08:00
|
|
|
}
|
2022-12-30 16:54:42 +08:00
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// SetOnCanResize 设置窗口是否允许调整大小回调事件
|
2022-12-13 11:49:32 +08:00
|
|
|
func (m *TCEFWindowComponent) SetOnCanResize(fn WindowComponentOnCanResize) {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_SetOnCanResize).Call(m.Instance(), api.MakeEventDataPtr(fn))
|
2022-12-13 11:49:32 +08:00
|
|
|
}
|
2022-12-30 16:54:42 +08:00
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// SetOnCanMaximize 设置窗口是否允许最大化回调事件
|
2022-12-13 11:49:32 +08:00
|
|
|
func (m *TCEFWindowComponent) SetOnCanMaximize(fn WindowComponentOnCanMaximize) {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_SetOnCanMaximize).Call(m.Instance(), api.MakeEventDataPtr(fn))
|
2022-12-13 11:49:32 +08:00
|
|
|
}
|
2022-12-30 16:54:42 +08:00
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// SetOnCanMinimize 设置窗口是否允许最小化回调事件
|
2022-12-13 11:49:32 +08:00
|
|
|
func (m *TCEFWindowComponent) SetOnCanMinimize(fn WindowComponentOnCanMinimize) {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_SetOnCanMinimize).Call(m.Instance(), api.MakeEventDataPtr(fn))
|
2022-12-13 11:49:32 +08:00
|
|
|
}
|
2022-12-30 16:54:42 +08:00
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// SetOnCanClose 设置窗口是否允许关闭回调事件
|
2022-12-13 11:49:32 +08:00
|
|
|
func (m *TCEFWindowComponent) SetOnCanClose(fn WindowComponentOnCanClose) {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_SetOnCanClose).Call(m.Instance(), api.MakeEventDataPtr(fn))
|
2022-12-13 11:49:32 +08:00
|
|
|
}
|
2022-12-30 16:54:42 +08:00
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// SetOnAccelerator 设置快捷键回调事件
|
2022-12-13 11:49:32 +08:00
|
|
|
func (m *TCEFWindowComponent) SetOnAccelerator(fn WindowComponentOnAccelerator) {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_SetOnAccelerator).Call(m.Instance(), api.MakeEventDataPtr(fn))
|
2022-12-13 11:49:32 +08:00
|
|
|
}
|
2022-12-30 16:54:42 +08:00
|
|
|
|
2023-02-20 14:42:17 +08:00
|
|
|
// SetOnKeyEvent 设置键盘事件回调事件
|
2022-12-13 11:49:32 +08:00
|
|
|
func (m *TCEFWindowComponent) SetOnKeyEvent(fn WindowComponentOnKeyEvent) {
|
2023-03-01 13:38:43 +08:00
|
|
|
imports.Proc(internale_CEFWindowComponent_SetOnKeyEvent).Call(m.Instance(), api.MakeEventDataPtr(fn))
|
2022-12-13 11:49:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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 WindowComponentOnWindowCreated:
|
|
|
|
sender := getPtr(0)
|
|
|
|
window := getPtr(1)
|
|
|
|
fn.(WindowComponentOnWindowCreated)(lcl.AsObject(sender), &ICefWindow{instance: window})
|
|
|
|
case WindowComponentOnWindowDestroyed:
|
|
|
|
sender := getPtr(0)
|
|
|
|
window := getPtr(1)
|
|
|
|
fn.(WindowComponentOnWindowDestroyed)(lcl.AsObject(sender), &ICefWindow{instance: window})
|
|
|
|
case WindowComponentOnWindowActivationChanged:
|
|
|
|
sender := getPtr(0)
|
|
|
|
window := getPtr(1)
|
|
|
|
fn.(WindowComponentOnWindowActivationChanged)(lcl.AsObject(sender), &ICefWindow{instance: window}, api.GoBool(getVal(2)))
|
|
|
|
case WindowComponentOnGetParentWindow:
|
|
|
|
sender := getPtr(0)
|
|
|
|
window := getPtr(1)
|
|
|
|
resultWindowPtr := (*uintptr)(getPtr(4))
|
|
|
|
resultWindow := &ICefWindow{}
|
|
|
|
fn.(WindowComponentOnGetParentWindow)(lcl.AsObject(sender), &ICefWindow{instance: window}, (*bool)(getPtr(2)), (*bool)(getPtr(3)), resultWindow)
|
|
|
|
*resultWindowPtr = uintptr(resultWindow.instance)
|
|
|
|
case WindowComponentOnGetInitialBounds:
|
|
|
|
sender := getPtr(0)
|
|
|
|
window := getPtr(1)
|
2023-05-31 17:41:14 +08:00
|
|
|
resultRectPtr := (*TCefRect)(getPtr(2))
|
2022-12-28 22:08:44 +08:00
|
|
|
resultRect := new(TCefRect)
|
|
|
|
resultRect.X = 0
|
|
|
|
resultRect.Y = 0
|
2023-05-31 17:41:14 +08:00
|
|
|
resultRect.Width = 800
|
|
|
|
resultRect.Height = 600
|
2022-12-13 11:49:32 +08:00
|
|
|
fn.(WindowComponentOnGetInitialBounds)(lcl.AsObject(sender), &ICefWindow{instance: window}, resultRect)
|
2023-05-31 17:41:14 +08:00
|
|
|
*resultRectPtr = *resultRect
|
2022-12-13 11:49:32 +08:00
|
|
|
case WindowComponentOnGetInitialShowState:
|
|
|
|
sender := getPtr(0)
|
|
|
|
window := getPtr(1)
|
|
|
|
resultShowState := (*consts.TCefShowState)(getPtr(2))
|
|
|
|
fn.(WindowComponentOnGetInitialShowState)(lcl.AsObject(sender), &ICefWindow{instance: window}, resultShowState)
|
|
|
|
case WindowComponentOnIsFrameless:
|
|
|
|
sender := getPtr(0)
|
|
|
|
window := getPtr(1)
|
|
|
|
fn.(WindowComponentOnIsFrameless)(lcl.AsObject(sender), &ICefWindow{instance: window}, (*bool)(getPtr(2)))
|
|
|
|
case WindowComponentOnCanResize:
|
|
|
|
sender := getPtr(0)
|
|
|
|
window := getPtr(1)
|
|
|
|
fn.(WindowComponentOnCanResize)(lcl.AsObject(sender), &ICefWindow{instance: window}, (*bool)(getPtr(2)))
|
|
|
|
case WindowComponentOnCanMaximize:
|
|
|
|
sender := getPtr(0)
|
|
|
|
window := getPtr(1)
|
|
|
|
fn.(WindowComponentOnCanMaximize)(lcl.AsObject(sender), &ICefWindow{instance: window}, (*bool)(getPtr(2)))
|
|
|
|
case WindowComponentOnCanMinimize:
|
|
|
|
sender := getPtr(0)
|
|
|
|
window := getPtr(1)
|
|
|
|
fn.(WindowComponentOnCanMinimize)(lcl.AsObject(sender), &ICefWindow{instance: window}, (*bool)(getPtr(2)))
|
|
|
|
case WindowComponentOnCanClose:
|
|
|
|
sender := getPtr(0)
|
|
|
|
window := getPtr(1)
|
|
|
|
fn.(WindowComponentOnCanClose)(lcl.AsObject(sender), &ICefWindow{instance: window}, (*bool)(getPtr(2)))
|
|
|
|
case WindowComponentOnAccelerator:
|
|
|
|
sender := getPtr(0)
|
|
|
|
window := getPtr(1)
|
|
|
|
fn.(WindowComponentOnAccelerator)(lcl.AsObject(sender), &ICefWindow{instance: window}, int32(getVal(2)), (*bool)(getPtr(3)))
|
|
|
|
case WindowComponentOnKeyEvent:
|
|
|
|
sender := getPtr(0)
|
|
|
|
window := getPtr(1)
|
|
|
|
keyEvent := (*TCefKeyEvent)(getPtr(2))
|
|
|
|
fn.(WindowComponentOnKeyEvent)(lcl.AsObject(sender), &ICefWindow{instance: window}, keyEvent, (*bool)(getPtr(3)))
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
})
|
2022-10-04 13:21:05 +08:00
|
|
|
}
|