energy/cef/cef-types-window.go

310 lines
10 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-02-20 14:42:17 +08:00
// cef window
//
// VF窗口组件
2022-12-30 18:22:21 +08:00
package cef
import (
"github.com/energye/energy/common/imports"
2022-12-30 18:22:21 +08:00
"github.com/energye/energy/consts"
"github.com/energye/energy/types"
2022-12-30 18:22:21 +08:00
"github.com/energye/golcl/energy/emfs"
"github.com/energye/golcl/lcl/api"
2023-02-14 15:25:02 +08:00
t "github.com/energye/golcl/lcl/types"
2022-12-30 18:22:21 +08:00
"io/ioutil"
"unsafe"
)
2023-03-14 22:20:08 +08:00
func (m *ICefWindow) Instance() uintptr {
return uintptr(m.instance)
}
func (m *ICefWindow) Free() {
if m.instance != nil {
m.base.Free(m.Instance())
m.instance = nil
}
}
2023-02-20 14:42:17 +08:00
// Show 显示窗口
2022-12-30 18:22:21 +08:00
func (m *ICefWindow) Show() {
imports.Proc(internale_ICEFWindow_Show).Call(uintptr(m.instance))
2022-12-30 18:22:21 +08:00
}
2023-02-20 14:42:17 +08:00
// Hide 显示窗口
2022-12-30 18:22:21 +08:00
func (m *ICefWindow) Hide() {
imports.Proc(internale_ICEFWindow_Hide).Call(uintptr(m.instance))
2022-12-30 18:22:21 +08:00
}
2023-02-20 14:42:17 +08:00
// CenterWindow 根据大小窗口居中
2022-12-30 18:22:21 +08:00
func (m *ICefWindow) CenterWindow(size *TCefSize) {
imports.Proc(internale_ICEFWindow_CenterWindow).Call(uintptr(m.instance), uintptr(unsafe.Pointer(size)))
2022-12-30 18:22:21 +08:00
}
2023-02-20 14:42:17 +08:00
// Close 关闭窗口, 主窗口调用
2022-12-30 18:22:21 +08:00
func (m *ICefWindow) Close() {
imports.Proc(internale_ICEFWindow_Close).Call(uintptr(m.instance))
2022-12-30 18:22:21 +08:00
}
2023-02-20 14:42:17 +08:00
// IsClosed 是否关闭
2022-12-30 18:22:21 +08:00
func (m *ICefWindow) IsClosed() bool {
r1, _, _ := imports.Proc(internale_ICEFWindow_IsClosed).Call(uintptr(m.instance))
2022-12-30 18:22:21 +08:00
return api.GoBool(r1)
}
2023-02-20 14:42:17 +08:00
// Activate 激活窗口
2022-12-30 18:22:21 +08:00
func (m *ICefWindow) Activate() {
imports.Proc(internale_ICEFWindow_Activate).Call(uintptr(m.instance))
2022-12-30 18:22:21 +08:00
}
2023-02-20 14:42:17 +08:00
// Deactivate 停止激活窗口
2022-12-30 18:22:21 +08:00
func (m *ICefWindow) Deactivate() {
imports.Proc(internale_ICEFWindow_Deactivate).Call(uintptr(m.instance))
2022-12-30 18:22:21 +08:00
}
2023-02-20 14:42:17 +08:00
// IsActive 是否激活
2022-12-30 18:22:21 +08:00
func (m *ICefWindow) IsActive() bool {
r1, _, _ := imports.Proc(internale_ICEFWindow_IsActive).Call(uintptr(m.instance))
2022-12-30 18:22:21 +08:00
return api.GoBool(r1)
}
2023-02-20 14:42:17 +08:00
// BringToTop 将窗口移至最上层
2022-12-30 18:22:21 +08:00
func (m *ICefWindow) BringToTop() {
imports.Proc(internale_ICEFWindow_BringToTop).Call(uintptr(m.instance))
2022-12-30 18:22:21 +08:00
}
2023-02-20 14:42:17 +08:00
// SetAlwaysOnTop 设置窗口是否置顶
2022-12-30 18:22:21 +08:00
func (m *ICefWindow) SetAlwaysOnTop(onTop bool) {
imports.Proc(internale_ICEFWindow_SetAlwaysOnTop).Call(uintptr(m.instance), api.PascalBool(onTop))
2022-12-30 18:22:21 +08:00
}
2023-02-20 14:42:17 +08:00
// IsAlwaysOnTop 窗口是否置顶
2022-12-30 18:22:21 +08:00
func (m *ICefWindow) IsAlwaysOnTop() bool {
r1, _, _ := imports.Proc(internale_ICEFWindow_IsAlwaysOnTop).Call(uintptr(m.instance))
2022-12-30 18:22:21 +08:00
return api.GoBool(r1)
}
2023-02-20 14:42:17 +08:00
// WindowState 返回窗口最小化、最大化、全屏状态
2023-02-14 15:25:02 +08:00
func (m *ICefWindow) WindowState() t.TWindowState {
if m.IsMinimized() {
return t.WsMinimized
} else if m.IsMaximized() {
return t.WsMaximized
} else if m.IsFullscreen() {
return t.WsFullScreen
}
return t.WsNormal
}
2023-02-20 14:42:17 +08:00
// Maximize 最大化窗口
2022-12-30 18:22:21 +08:00
func (m *ICefWindow) Maximize() {
imports.Proc(internale_ICEFWindow_Maximize).Call(uintptr(m.instance))
2022-12-30 18:22:21 +08:00
}
2023-02-20 14:42:17 +08:00
// Minimize 最小化窗口
2022-12-30 18:22:21 +08:00
func (m *ICefWindow) Minimize() {
imports.Proc(internale_ICEFWindow_Minimize).Call(uintptr(m.instance))
2022-12-30 18:22:21 +08:00
}
2023-02-20 14:42:17 +08:00
// Restore 窗口还原
2022-12-30 18:22:21 +08:00
func (m *ICefWindow) Restore() {
imports.Proc(internale_ICEFWindow_Restore).Call(uintptr(m.instance))
2022-12-30 18:22:21 +08:00
}
2023-02-20 14:42:17 +08:00
// SetFullscreen 设置窗口全屏
2022-12-30 18:22:21 +08:00
func (m *ICefWindow) SetFullscreen(fullscreen bool) {
imports.Proc(internale_ICEFWindow_SetFullscreen).Call(uintptr(m.instance), api.PascalBool(fullscreen))
2022-12-30 18:22:21 +08:00
}
2023-02-20 14:42:17 +08:00
// SetBackgroundColor 设置背景色
func (m *ICefWindow) SetBackgroundColor(rect *types.TCefColor) {
imports.Proc(internale_ICEFWindow_SetBackgroundColor).Call(uintptr(m.instance), rect.ToPtr())
}
2023-02-20 14:42:17 +08:00
// SetBounds 设置窗口边界
func (m *ICefWindow) SetBounds(rect *TCefRect) {
imports.Proc(internale_ICEFWindow_SetBounds).Call(uintptr(m.instance), uintptr(unsafe.Pointer(rect)))
}
2023-02-20 14:42:17 +08:00
// SetSize 设置窗口宽高
func (m *ICefWindow) SetSize(size *TCefSize) {
imports.Proc(internale_ICEFWindow_SetSize).Call(uintptr(m.instance), uintptr(unsafe.Pointer(size)))
}
2023-02-20 14:42:17 +08:00
// SetPosition 设置窗口位置
func (m *ICefWindow) SetPosition(point *TCefPoint) {
imports.Proc(internale_ICEFWindow_SetPosition).Call(uintptr(m.instance), uintptr(unsafe.Pointer(point)))
}
2023-02-20 14:42:17 +08:00
// IsMaximized 是否最大化
2022-12-30 18:22:21 +08:00
func (m *ICefWindow) IsMaximized() bool {
r1, _, _ := imports.Proc(internale_ICEFWindow_IsMaximized).Call(uintptr(m.instance))
2022-12-30 18:22:21 +08:00
return api.GoBool(r1)
}
2023-02-20 14:42:17 +08:00
// IsMinimized 是否最小化
2022-12-30 18:22:21 +08:00
func (m *ICefWindow) IsMinimized() bool {
r1, _, _ := imports.Proc(internale_ICEFWindow_IsMinimized).Call(uintptr(m.instance))
2022-12-30 18:22:21 +08:00
return api.GoBool(r1)
}
2023-02-20 14:42:17 +08:00
// IsFullscreen 是否全屏
2022-12-30 18:22:21 +08:00
func (m *ICefWindow) IsFullscreen() bool {
r1, _, _ := imports.Proc(internale_ICEFWindow_IsFullscreen).Call(uintptr(m.instance))
2022-12-30 18:22:21 +08:00
return api.GoBool(r1)
}
2023-02-20 14:42:17 +08:00
// SetTitle 设置窗口标题
2022-12-30 18:22:21 +08:00
func (m *ICefWindow) SetTitle(title string) {
imports.Proc(internale_ICEFWindow_SetTitle).Call(uintptr(m.instance), api.PascalStr(title))
2022-12-30 18:22:21 +08:00
}
2023-02-20 14:42:17 +08:00
// Title 获取窗口标题
func (m *ICefWindow) Title() string {
r1, _, _ := imports.Proc(internale_ICEFWindow_GetTitle).Call(uintptr(m.instance))
2022-12-30 18:22:21 +08:00
return api.GoStr(r1)
}
2023-02-20 14:42:17 +08:00
// SetWindowIcon 设置窗口图标
2022-12-30 18:22:21 +08:00
func (m *ICefWindow) SetWindowIcon(scaleFactor float32, filename string) error {
bytes, err := ioutil.ReadFile(filename)
if err != nil {
return err
}
imports.Proc(internale_ICEFWindow_SetWindowIcon).Call(uintptr(m.instance), uintptr(unsafe.Pointer(&scaleFactor)), uintptr(unsafe.Pointer(&bytes[0])), uintptr(int32(len(bytes))))
2022-12-30 18:22:21 +08:00
return nil
}
2023-02-20 14:42:17 +08:00
// SetWindowIconFS 设置窗口图标
2022-12-30 18:22:21 +08:00
func (m *ICefWindow) SetWindowIconFS(scaleFactor float32, filename string) error {
bytes, err := emfs.GetResources(filename)
if err != nil {
return err
}
imports.Proc(internale_ICEFWindow_SetWindowIcon).Call(uintptr(m.instance), uintptr(unsafe.Pointer(&scaleFactor)), uintptr(unsafe.Pointer(&bytes[0])), uintptr(int32(len(bytes))))
2022-12-30 18:22:21 +08:00
return nil
}
2023-02-20 14:42:17 +08:00
// WindowIcon 获取窗口图标
func (m *ICefWindow) WindowIcon() *ICefImage {
2023-03-01 13:38:43 +08:00
var result uintptr
imports.Proc(internale_ICEFWindow_GetWindowIcon).Call(uintptr(m.instance), uintptr(unsafe.Pointer(&result)))
2022-12-30 18:22:21 +08:00
return &ICefImage{
2023-03-01 13:38:43 +08:00
instance: unsafe.Pointer(result),
2022-12-30 18:22:21 +08:00
}
}
2023-02-20 14:42:17 +08:00
// WindowAppIcon 获取窗口应用图标
func (m *ICefWindow) WindowAppIcon() *ICefImage {
2023-03-01 13:38:43 +08:00
var result uintptr
imports.Proc(internale_ICEFWindow_GetWindowAppIcon).Call(uintptr(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
}
}
// SetWindowAppIcon 设置窗口应用图标
2022-12-30 18:22:21 +08:00
func (m *ICefWindow) SetWindowAppIcon(scaleFactor float32, filename string) error {
bytes, err := ioutil.ReadFile(filename)
if err != nil {
return err
}
imports.Proc(internale_ICEFWindow_SetWindowAppIcon).Call(uintptr(m.instance), uintptr(unsafe.Pointer(&scaleFactor)), uintptr(unsafe.Pointer(&bytes[0])), uintptr(int32(len(bytes))))
2022-12-30 18:22:21 +08:00
return nil
}
2023-02-20 14:42:17 +08:00
// SetWindowAppIconFS 设置窗口应用图标
2022-12-30 18:22:21 +08:00
func (m *ICefWindow) SetWindowAppIconFS(scaleFactor float32, filename string) error {
bytes, err := emfs.GetResources(filename)
if err != nil {
return err
}
imports.Proc(internale_ICEFWindow_SetWindowAppIcon).Call(uintptr(m.instance), uintptr(unsafe.Pointer(&scaleFactor)), uintptr(unsafe.Pointer(&bytes[0])), uintptr(int32(len(bytes))))
2022-12-30 18:22:21 +08:00
return nil
}
2023-02-20 14:42:17 +08:00
// AddOverlayView TODO 未实现
2022-12-30 18:22:21 +08:00
func (m *ICefWindow) AddOverlayView() {
//do not implement
//imports.Proc(internale_ICEFWindow_AddOverlayView).Call(uintptr(m.instance))
2022-12-30 18:22:21 +08:00
}
2023-02-20 14:42:17 +08:00
// ShowMenu 显示菜单
2022-12-30 18:22:21 +08:00
func (m *ICefWindow) ShowMenu(menuModel *ICefMenuModel, point TCefPoint, anchorPosition consts.TCefMenuAnchorPosition) {
imports.Proc(internale_ICEFWindow_ShowMenu).Call(uintptr(m.instance), uintptr(menuModel.instance), uintptr(unsafe.Pointer(&point)), uintptr(anchorPosition))
2022-12-30 18:22:21 +08:00
}
2023-02-20 14:42:17 +08:00
// CancelMenu 取消菜单
2022-12-30 18:22:21 +08:00
func (m *ICefWindow) CancelMenu() {
imports.Proc(internale_ICEFWindow_CancelMenu).Call(uintptr(m.instance))
2022-12-30 18:22:21 +08:00
}
2023-02-20 14:42:17 +08:00
// Display
func (m *ICefWindow) Display() *ICefDisplay {
2022-12-30 18:22:21 +08:00
var ret uintptr
imports.Proc(internale_ICEFWindow_GetDisplay).Call(uintptr(m.instance), uintptr(unsafe.Pointer(&ret)))
2022-12-30 18:22:21 +08:00
return &ICefDisplay{
instance: unsafe.Pointer(ret),
}
}
2023-02-20 14:42:17 +08:00
// ClientAreaBoundsInScreen 获取客户端所在指定屏幕位置
func (m *ICefWindow) ClientAreaBoundsInScreen() (result TCefRect) {
imports.Proc(internale_ICEFWindow_GetClientAreaBoundsInScreen).Call(uintptr(m.instance), uintptr(unsafe.Pointer(&result)))
2022-12-30 18:22:21 +08:00
return
}
2023-02-20 14:42:17 +08:00
// SetDraggableRegions 设置拖拽区域
func (m *ICefWindow) SetDraggableRegions(regions []TCefDraggableRegion) {
imports.Proc(internale_ICEFWindow_SetDraggableRegions).Call(uintptr(m.instance), uintptr(int32(len(regions))), uintptr(unsafe.Pointer(&regions[0])), uintptr(int32(len(regions))))
2022-12-30 18:22:21 +08:00
}
2023-02-20 14:42:17 +08:00
// WindowHandle 获取窗口句柄
func (m *ICefWindow) WindowHandle() consts.TCefWindowHandle {
r1, _, _ := imports.Proc(internale_ICEFWindow_GetWindowHandle).Call(uintptr(m.instance))
2022-12-30 18:22:21 +08:00
return consts.TCefWindowHandle(r1)
}
2023-02-20 14:42:17 +08:00
// SendKeyPress 发送键盘事件
2022-12-30 18:22:21 +08:00
func (m *ICefWindow) SendKeyPress(keyCode int32, eventFlags uint32) {
imports.Proc(internale_ICEFWindow_SendKeyPress).Call(uintptr(m.instance), uintptr(keyCode), uintptr(eventFlags))
2022-12-30 18:22:21 +08:00
}
2023-02-20 14:42:17 +08:00
// SendMouseMove 发送鼠标移动事件
2022-12-30 18:22:21 +08:00
func (m *ICefWindow) SendMouseMove(screenX, screenY int32) {
imports.Proc(internale_ICEFWindow_SendMouseMove).Call(uintptr(m.instance), uintptr(screenX), uintptr(screenY))
2022-12-30 18:22:21 +08:00
}
2023-02-20 14:42:17 +08:00
// SendMouseEvents 发送鼠标事件
2022-12-30 18:22:21 +08:00
func (m *ICefWindow) SendMouseEvents(button consts.TCefMouseButtonType, mouseDown, mouseUp bool) {
imports.Proc(internale_ICEFWindow_SendMouseEvents).Call(uintptr(m.instance), uintptr(button), api.PascalBool(mouseDown), api.PascalBool(mouseUp))
2022-12-30 18:22:21 +08:00
}
2023-02-20 14:42:17 +08:00
// SetAccelerator 设置快捷键
2022-12-30 18:22:21 +08:00
func (m *ICefWindow) SetAccelerator(commandId, keyCode int32, shiftPressed, ctrlPressed, altPressed bool) {
imports.Proc(internale_ICEFWindow_SetAccelerator).Call(uintptr(m.instance), uintptr(commandId), uintptr(keyCode), api.PascalBool(shiftPressed), api.PascalBool(ctrlPressed), api.PascalBool(altPressed))
2022-12-30 18:22:21 +08:00
}
2023-02-20 14:42:17 +08:00
// RemoveAccelerator 移除指定快捷键
2022-12-30 18:22:21 +08:00
func (m *ICefWindow) RemoveAccelerator(commandId int32) {
imports.Proc(internale_ICEFWindow_RemoveAccelerator).Call(uintptr(m.instance), uintptr(commandId))
2022-12-30 18:22:21 +08:00
}
2023-02-20 14:42:17 +08:00
// RemoveAllAccelerators 移除所有快捷键
2022-12-30 18:22:21 +08:00
func (m *ICefWindow) RemoveAllAccelerators() {
imports.Proc(internale_ICEFWindow_RemoveAllAccelerators).Call(uintptr(m.instance))
2022-12-30 18:22:21 +08:00
}
func (m *ICefWindow) SetWindow(window *ICefWindow) {
m.instance = window.instance
}