2022-10-04 13:21:05 +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-10-04 13:21:05 +08:00
|
|
|
|
//
|
|
|
|
|
//----------------------------------------
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// LCL窗口组件定义和实现
|
2023-05-31 17:41:14 +08:00
|
|
|
|
|
2022-10-04 13:21:05 +08:00
|
|
|
|
package cef
|
|
|
|
|
|
|
|
|
|
import (
|
2022-10-27 21:03:15 +08:00
|
|
|
|
"fmt"
|
2023-07-20 19:52:58 +08:00
|
|
|
|
"github.com/energye/energy/v2/cef/internal/def"
|
2023-05-31 18:00:34 +08:00
|
|
|
|
"github.com/energye/energy/v2/cef/internal/window"
|
|
|
|
|
. "github.com/energye/energy/v2/common"
|
2023-07-20 19:52:58 +08:00
|
|
|
|
"github.com/energye/energy/v2/common/imports"
|
2023-05-31 18:00:34 +08:00
|
|
|
|
"github.com/energye/energy/v2/consts"
|
2023-07-17 15:12:01 +08:00
|
|
|
|
"github.com/energye/energy/v2/consts/messages"
|
2023-05-31 18:00:34 +08:00
|
|
|
|
"github.com/energye/energy/v2/logger"
|
|
|
|
|
"github.com/energye/energy/v2/pkgs/assetserve"
|
2023-07-20 19:52:58 +08:00
|
|
|
|
t "github.com/energye/energy/v2/types"
|
2023-01-09 11:47:30 +08:00
|
|
|
|
"github.com/energye/golcl/energy/emfs"
|
|
|
|
|
"github.com/energye/golcl/energy/tools"
|
2022-10-04 13:21:05 +08:00
|
|
|
|
"github.com/energye/golcl/lcl"
|
2023-07-14 18:50:14 +08:00
|
|
|
|
"github.com/energye/golcl/lcl/api"
|
2022-11-04 19:13:27 +08:00
|
|
|
|
"github.com/energye/golcl/lcl/rtl"
|
2022-10-04 13:21:05 +08:00
|
|
|
|
"github.com/energye/golcl/lcl/types"
|
2023-07-14 18:50:14 +08:00
|
|
|
|
"runtime"
|
2022-10-27 21:03:15 +08:00
|
|
|
|
"time"
|
2023-07-20 19:52:58 +08:00
|
|
|
|
"unsafe"
|
2022-10-04 13:21:05 +08:00
|
|
|
|
)
|
|
|
|
|
|
2023-02-12 17:28:31 +08:00
|
|
|
|
// LCLBrowserWindow 基于CEF lcl 窗口组件
|
2023-01-09 12:17:54 +08:00
|
|
|
|
//
|
2023-02-12 17:28:31 +08:00
|
|
|
|
// 该窗口使用CEF和LCL组件实现,CEF<=1.106.xx版本 在windows、MacOSX可正常使用, Linux无法输入中文, CEF>=2.107.xx版本linux强制使用 ViewsFrameworkBrowserWindow 窗口组件
|
2023-01-04 18:41:48 +08:00
|
|
|
|
type LCLBrowserWindow struct {
|
2023-07-20 22:35:49 +08:00
|
|
|
|
*lcl.TForm //window form
|
|
|
|
|
isFormCreate bool //是否创建完成 WindowForm
|
|
|
|
|
chromiumBrowser ICEFChromiumBrowser //浏览器
|
|
|
|
|
windowProperty *WindowProperty //窗口属性
|
|
|
|
|
windowId int32 //窗口ID
|
|
|
|
|
windowType consts.WINDOW_TYPE //窗口类型
|
|
|
|
|
isClosing bool //
|
|
|
|
|
canClose bool //
|
|
|
|
|
onResize TNotifyEvent //扩展事件
|
|
|
|
|
windowResize TNotifyEvent //扩展事件
|
|
|
|
|
onActivate TNotifyEvent //扩展事件
|
|
|
|
|
onShow TNotifyEvent //扩展事件
|
|
|
|
|
onClose TCloseEvent //扩展事件
|
|
|
|
|
onCloseQuery TCloseQueryEvent //扩展事件
|
|
|
|
|
onActivateAfter lcl.TNotifyEvent //扩展事件
|
|
|
|
|
auxTools IAuxTools //辅助工具
|
|
|
|
|
tray ITray //托盘
|
|
|
|
|
hWnd types.HWND //
|
|
|
|
|
cwcap *customWindowCaption //自定义窗口标题栏
|
|
|
|
|
drag *drag //自定义拖拽
|
2023-07-21 09:56:28 +08:00
|
|
|
|
wmPaintMessage wmPaint //
|
2023-07-20 22:35:49 +08:00
|
|
|
|
wmMoveMessage wmMove //
|
|
|
|
|
wmSizeMessage wmSize //
|
|
|
|
|
wmWindowPosChangedMessage wmWindowPosChanged //
|
2023-05-31 17:41:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NewLCLBrowserWindow 创建一个 LCL 带有 chromium 窗口
|
|
|
|
|
// 该窗口默认不具备默认事件处理能力, 通过 EnableDefaultEvent 函数注册事件处理
|
2023-06-19 12:41:52 +08:00
|
|
|
|
func NewLCLBrowserWindow(config *TCefChromiumConfig, windowProperty WindowProperty, owner ...lcl.IComponent) *LCLBrowserWindow {
|
2023-05-31 17:41:14 +08:00
|
|
|
|
var browseWindow = NewLCLWindow(windowProperty, owner...)
|
|
|
|
|
browseWindow.ChromiumCreate(config, windowProperty.Url)
|
2023-01-04 18:41:48 +08:00
|
|
|
|
//OnBeforeBrowser 是一个必须的默认事件,在浏览器创建时窗口序号会根据browserId生成
|
2023-05-31 17:41:14 +08:00
|
|
|
|
browseWindow.Chromium().SetOnBeforeBrowser(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, request *ICefRequest, userGesture, isRedirect bool) bool {
|
|
|
|
|
//chromiumOnBeforeBrowser(browser, frame)
|
2023-01-05 21:21:18 +08:00
|
|
|
|
return false
|
|
|
|
|
})
|
2023-05-31 17:41:14 +08:00
|
|
|
|
return browseWindow
|
2022-10-04 13:21:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-31 17:41:14 +08:00
|
|
|
|
// NewLCLWindow 创建一个LCL window窗口
|
2023-01-23 10:52:40 +08:00
|
|
|
|
func NewLCLWindow(windowProperty WindowProperty, owner ...lcl.IComponent) *LCLBrowserWindow {
|
2023-01-06 17:42:34 +08:00
|
|
|
|
var window = &LCLBrowserWindow{}
|
|
|
|
|
if len(owner) > 0 {
|
|
|
|
|
window.TForm = lcl.NewForm(owner[0])
|
|
|
|
|
} else {
|
2023-01-19 10:24:47 +08:00
|
|
|
|
window.TForm = lcl.NewForm(BrowserWindow.mainBrowserWindow)
|
|
|
|
|
//lcl.Application.CreateForm(&window)
|
2023-01-06 17:42:34 +08:00
|
|
|
|
}
|
2023-01-23 10:52:40 +08:00
|
|
|
|
window.windowProperty = &windowProperty
|
2023-01-24 12:23:03 +08:00
|
|
|
|
window.cwcap = &customWindowCaption{
|
|
|
|
|
bw: window,
|
|
|
|
|
}
|
2023-01-24 16:32:28 +08:00
|
|
|
|
window.SetWindowType(windowProperty.WindowType)
|
2023-01-16 17:27:58 +08:00
|
|
|
|
window.SetDoubleBuffered(true)
|
2023-01-06 17:42:34 +08:00
|
|
|
|
window.FormCreate()
|
|
|
|
|
window.SetShowInTaskBar()
|
|
|
|
|
window.defaultWindowEvent()
|
2023-01-23 10:52:40 +08:00
|
|
|
|
window.setProperty()
|
|
|
|
|
return window
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-12 17:28:31 +08:00
|
|
|
|
// 设置属性
|
2023-01-23 10:52:40 +08:00
|
|
|
|
func (m *LCLBrowserWindow) setProperty() {
|
|
|
|
|
m.SetTitle(m.windowProperty.Title)
|
|
|
|
|
if m.windowProperty.IconFS != "" {
|
|
|
|
|
if emfs.IsExist(m.windowProperty.IconFS) {
|
|
|
|
|
_ = lcl.Application.Icon().LoadFromFSFile(m.windowProperty.IconFS)
|
2023-01-09 11:47:30 +08:00
|
|
|
|
}
|
2023-01-23 10:52:40 +08:00
|
|
|
|
} else if m.windowProperty.Icon != "" {
|
|
|
|
|
if tools.IsExist(m.windowProperty.Icon) {
|
|
|
|
|
lcl.Application.Icon().LoadFromFile(m.windowProperty.Icon)
|
2023-01-09 11:47:30 +08:00
|
|
|
|
}
|
2023-01-06 17:42:34 +08:00
|
|
|
|
}
|
2023-01-23 19:14:19 +08:00
|
|
|
|
if m.windowProperty.EnableCenterWindow {
|
2023-01-23 10:52:40 +08:00
|
|
|
|
m.SetSize(m.windowProperty.Width, m.windowProperty.Height)
|
|
|
|
|
m.SetPosition(types.PoDesktopCenter)
|
|
|
|
|
} else {
|
|
|
|
|
m.SetPosition(types.PoDesigned)
|
|
|
|
|
m.SetBounds(m.windowProperty.X, m.windowProperty.Y, m.windowProperty.Width, m.windowProperty.Height)
|
|
|
|
|
}
|
|
|
|
|
if m.windowProperty.AlwaysOnTop {
|
|
|
|
|
m.SetFormStyle(types.FsSystemStayOnTop)
|
2023-01-06 17:42:34 +08:00
|
|
|
|
}
|
2023-02-12 17:28:31 +08:00
|
|
|
|
if m.windowProperty.EnableHideCaption {
|
2023-01-23 10:52:40 +08:00
|
|
|
|
m.HideTitle()
|
2023-01-23 12:55:32 +08:00
|
|
|
|
} else {
|
|
|
|
|
if !m.windowProperty.EnableMinimize {
|
|
|
|
|
m.DisableMinimize()
|
|
|
|
|
}
|
|
|
|
|
if !m.windowProperty.EnableMaximize {
|
|
|
|
|
m.DisableMaximize()
|
|
|
|
|
}
|
|
|
|
|
if !m.windowProperty.EnableResize {
|
|
|
|
|
m.SetBorderStyle(types.BsSingle)
|
|
|
|
|
}
|
2023-01-06 17:42:34 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// Handle 窗口句柄
|
2023-01-14 23:26:37 +08:00
|
|
|
|
func (m *LCLBrowserWindow) Handle() types.HWND {
|
|
|
|
|
if m.hWnd == 0 {
|
|
|
|
|
m.hWnd = m.TForm.Handle()
|
|
|
|
|
}
|
|
|
|
|
return m.hWnd
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-14 18:50:14 +08:00
|
|
|
|
// RunOnMainThread
|
|
|
|
|
// 在主线程中运行
|
|
|
|
|
func (m *LCLBrowserWindow) RunOnMainThread(fn func()) {
|
|
|
|
|
runtime.LockOSThread()
|
|
|
|
|
defer runtime.UnlockOSThread()
|
|
|
|
|
if api.DMainThreadId() == api.DCurrentThreadId() {
|
|
|
|
|
fn()
|
|
|
|
|
} else {
|
2023-07-14 23:02:45 +08:00
|
|
|
|
QueueAsyncCall(func(id int) {
|
|
|
|
|
//lcl.ThreadSync(func() {
|
2023-07-14 18:50:14 +08:00
|
|
|
|
fn()
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-31 17:41:14 +08:00
|
|
|
|
// BrowserWindow 返回LCL窗口组件实例对象
|
2023-01-06 13:50:44 +08:00
|
|
|
|
func (m *LCLBrowserWindow) BrowserWindow() *LCLBrowserWindow {
|
|
|
|
|
return m
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// AsViewsFrameworkBrowserWindow 转换为VF窗口组件,这里返回nil
|
2023-01-06 13:50:44 +08:00
|
|
|
|
func (m *LCLBrowserWindow) AsViewsFrameworkBrowserWindow() IViewsFrameworkBrowserWindow {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// AsLCLBrowserWindow 转换为LCL窗口组件,这里返回LCL窗口组件
|
2023-01-06 13:50:44 +08:00
|
|
|
|
func (m *LCLBrowserWindow) AsLCLBrowserWindow() ILCLBrowserWindow {
|
|
|
|
|
return m
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-31 17:41:14 +08:00
|
|
|
|
// SetCenterWindow 窗口居中
|
2023-01-06 18:55:13 +08:00
|
|
|
|
func (m *LCLBrowserWindow) SetCenterWindow(value bool) {
|
|
|
|
|
if m.TForm == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if value {
|
|
|
|
|
m.SetPosition(types.PoDesktopCenter)
|
|
|
|
|
} else {
|
|
|
|
|
m.SetPosition(types.PoDesigned)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// Close 关闭窗口 非browser窗口使用
|
2023-01-09 08:53:01 +08:00
|
|
|
|
func (m *LCLBrowserWindow) Close() {
|
|
|
|
|
if m.TForm == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
m.TForm.Close()
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// SetTitle 设置窗口标题栏标题
|
2023-01-06 13:50:44 +08:00
|
|
|
|
func (m *LCLBrowserWindow) SetTitle(title string) {
|
|
|
|
|
if m.TForm == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
2023-02-03 09:02:43 +08:00
|
|
|
|
m.WindowProperty().Title = title
|
2023-01-06 13:50:44 +08:00
|
|
|
|
m.TForm.SetCaption(title)
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// SetWidth 设置窗口宽
|
2023-01-06 18:55:13 +08:00
|
|
|
|
func (m *LCLBrowserWindow) SetWidth(value int32) {
|
|
|
|
|
if m.TForm == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
2023-02-03 09:02:43 +08:00
|
|
|
|
m.WindowProperty().Width = value
|
2023-01-06 18:55:13 +08:00
|
|
|
|
m.TForm.SetWidth(value)
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// SetHeight 设置窗口高
|
2023-01-06 18:55:13 +08:00
|
|
|
|
func (m *LCLBrowserWindow) SetHeight(value int32) {
|
|
|
|
|
if m.TForm == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
2023-02-03 09:02:43 +08:00
|
|
|
|
m.WindowProperty().Height = value
|
2023-01-06 18:55:13 +08:00
|
|
|
|
m.TForm.SetHeight(value)
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// Point 窗口坐标
|
2023-01-09 08:53:01 +08:00
|
|
|
|
func (m *LCLBrowserWindow) Point() *TCefPoint {
|
|
|
|
|
if m.TForm == nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
result := &TCefPoint{
|
|
|
|
|
X: m.Left(),
|
|
|
|
|
Y: m.Top(),
|
|
|
|
|
}
|
|
|
|
|
m.WindowProperty().X = result.X
|
|
|
|
|
m.WindowProperty().Y = result.Y
|
|
|
|
|
return result
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// Size 窗口宽高
|
2023-01-09 08:53:01 +08:00
|
|
|
|
func (m *LCLBrowserWindow) Size() *TCefSize {
|
|
|
|
|
if m.TForm == nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
result := &TCefSize{
|
|
|
|
|
Width: m.Width(),
|
|
|
|
|
Height: m.Height(),
|
|
|
|
|
}
|
|
|
|
|
m.WindowProperty().Width = result.Width
|
|
|
|
|
m.WindowProperty().Height = result.Height
|
|
|
|
|
return result
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// Bounds 窗口坐标和宽高
|
2023-01-09 08:53:01 +08:00
|
|
|
|
func (m *LCLBrowserWindow) Bounds() *TCefRect {
|
|
|
|
|
if m.TForm == nil {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
rect := m.BoundsRect()
|
|
|
|
|
result := &TCefRect{
|
|
|
|
|
X: rect.Left,
|
|
|
|
|
Y: rect.Top,
|
|
|
|
|
Width: rect.Width(),
|
|
|
|
|
Height: rect.Height(),
|
|
|
|
|
}
|
|
|
|
|
m.WindowProperty().X = result.X
|
|
|
|
|
m.WindowProperty().Y = result.Y
|
|
|
|
|
m.WindowProperty().Width = result.Width
|
|
|
|
|
m.WindowProperty().Height = result.Height
|
|
|
|
|
return result
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// SetPoint 设置窗口坐标
|
2023-01-07 21:29:08 +08:00
|
|
|
|
func (m *LCLBrowserWindow) SetPoint(x, y int32) {
|
2023-01-06 18:55:13 +08:00
|
|
|
|
if m.TForm == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
2023-02-03 09:02:43 +08:00
|
|
|
|
m.WindowProperty().X = x
|
|
|
|
|
m.WindowProperty().Y = y
|
2023-01-07 21:29:08 +08:00
|
|
|
|
m.TForm.SetLeft(x)
|
|
|
|
|
m.TForm.SetTop(y)
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// SetSize 设置窗口宽高
|
2023-01-07 21:29:08 +08:00
|
|
|
|
func (m *LCLBrowserWindow) SetSize(width, height int32) {
|
|
|
|
|
if m.TForm == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
2023-02-03 09:02:43 +08:00
|
|
|
|
m.WindowProperty().Width = width
|
|
|
|
|
m.WindowProperty().Height = height
|
2023-01-07 21:29:08 +08:00
|
|
|
|
m.SetWidth(width)
|
|
|
|
|
m.SetHeight(height)
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// SetBounds 设置窗口坐标和宽高
|
2023-01-07 21:29:08 +08:00
|
|
|
|
func (m *LCLBrowserWindow) SetBounds(x, y, width, height int32) {
|
|
|
|
|
if m.TForm == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
2023-02-03 09:02:43 +08:00
|
|
|
|
m.WindowProperty().X = x
|
|
|
|
|
m.WindowProperty().Y = y
|
|
|
|
|
m.WindowProperty().Width = width
|
|
|
|
|
m.WindowProperty().Height = height
|
2023-01-07 21:29:08 +08:00
|
|
|
|
m.TForm.SetBounds(x, y, width, height)
|
2023-01-06 18:55:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-06-15 18:29:23 +08:00
|
|
|
|
// GetAuxTools
|
|
|
|
|
func (m *LCLBrowserWindow) GetAuxTools() IAuxTools {
|
2023-01-06 13:50:44 +08:00
|
|
|
|
return m.auxTools
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// createAuxTools
|
2023-01-06 13:50:44 +08:00
|
|
|
|
func (m *LCLBrowserWindow) createAuxTools() {
|
|
|
|
|
if m.auxTools == nil {
|
|
|
|
|
m.auxTools = &auxTools{}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// Browser
|
2023-01-04 22:47:30 +08:00
|
|
|
|
func (m *LCLBrowserWindow) Browser() *ICefBrowser {
|
2023-02-26 19:14:49 +08:00
|
|
|
|
if m == nil || m.Chromium() == nil || !m.Chromium().Initialized() {
|
|
|
|
|
return nil
|
2023-01-06 13:50:44 +08:00
|
|
|
|
}
|
2023-02-26 19:14:49 +08:00
|
|
|
|
return m.Chromium().Browser()
|
2023-01-06 13:50:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-31 17:41:14 +08:00
|
|
|
|
// Chromium 返回 chromium
|
2023-01-04 18:41:48 +08:00
|
|
|
|
func (m *LCLBrowserWindow) Chromium() IChromium {
|
2023-05-31 17:41:14 +08:00
|
|
|
|
return m.chromiumBrowser.Chromium()
|
2023-01-04 18:41:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-05-31 17:41:14 +08:00
|
|
|
|
// Id 浏览器窗口ID
|
2023-01-04 18:41:48 +08:00
|
|
|
|
func (m *LCLBrowserWindow) Id() int32 {
|
2023-05-31 17:41:14 +08:00
|
|
|
|
if m.windowId == 0 {
|
|
|
|
|
m.windowId = m.Chromium().BrowserId()
|
|
|
|
|
}
|
2023-01-01 22:19:26 +08:00
|
|
|
|
return m.windowId
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// Show
|
2023-01-04 18:41:48 +08:00
|
|
|
|
func (m *LCLBrowserWindow) Show() {
|
|
|
|
|
if m.TForm == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
2022-10-04 13:21:05 +08:00
|
|
|
|
m.TForm.Show()
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// Hide
|
2023-01-04 18:41:48 +08:00
|
|
|
|
func (m *LCLBrowserWindow) Hide() {
|
|
|
|
|
if m.TForm == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
2022-10-04 13:21:05 +08:00
|
|
|
|
m.TForm.Hide()
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// WindowState 返回窗口最小化、最大化、全屏状态
|
|
|
|
|
func (m *LCLBrowserWindow) WindowState() types.TWindowState {
|
|
|
|
|
if m.TForm == nil {
|
|
|
|
|
return -1
|
|
|
|
|
}
|
|
|
|
|
return m.TForm.WindowState()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Visible
|
2023-01-04 18:41:48 +08:00
|
|
|
|
func (m *LCLBrowserWindow) Visible() bool {
|
|
|
|
|
if m.TForm == nil {
|
|
|
|
|
return false
|
|
|
|
|
}
|
2022-10-04 13:21:05 +08:00
|
|
|
|
return m.TForm.Visible()
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// SetVisible
|
2023-01-04 18:41:48 +08:00
|
|
|
|
func (m *LCLBrowserWindow) SetVisible(value bool) {
|
|
|
|
|
if m.TForm == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
2022-10-04 13:21:05 +08:00
|
|
|
|
m.TForm.SetVisible(value)
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// SetDefaultInTaskBar 以默认的方式展示在任务栏上
|
2023-01-04 18:41:48 +08:00
|
|
|
|
func (m *LCLBrowserWindow) SetDefaultInTaskBar() {
|
|
|
|
|
if m.TForm == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
2022-10-04 13:21:05 +08:00
|
|
|
|
m.TForm.SetShowInTaskBar(types.StDefault)
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// SetShowInTaskBar 展示在任务栏上
|
2023-01-04 18:41:48 +08:00
|
|
|
|
func (m *LCLBrowserWindow) SetShowInTaskBar() {
|
|
|
|
|
if m.TForm == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
2022-10-04 13:21:05 +08:00
|
|
|
|
m.TForm.SetShowInTaskBar(types.StAlways)
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// SetNotInTaskBar 不会展示在任务栏上
|
2023-01-04 18:41:48 +08:00
|
|
|
|
func (m *LCLBrowserWindow) SetNotInTaskBar() {
|
|
|
|
|
if m.TForm == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
2022-10-04 13:21:05 +08:00
|
|
|
|
m.TForm.SetShowInTaskBar(types.StNever)
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// WindowParent
|
2023-05-31 17:41:14 +08:00
|
|
|
|
// 返回chromium的父组件对象,该对象不是window组件对象,属于window的一个子组件
|
|
|
|
|
// 在windows下它是 TCEFWindowParent, linux或macOSx下它是 TCEFLinkedWindowParent
|
|
|
|
|
// 通过函数可调整该组件的属性
|
|
|
|
|
func (m *LCLBrowserWindow) WindowParent() ICEFWindowParent {
|
|
|
|
|
return m.chromiumBrowser.WindowParent()
|
2022-10-04 13:21:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// IsClosing 返回窗口是否正在关闭/或已关闭 true正在或已关闭
|
2023-01-04 18:41:48 +08:00
|
|
|
|
func (m *LCLBrowserWindow) IsClosing() bool {
|
2022-10-04 13:21:05 +08:00
|
|
|
|
return m.isClosing
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// SetWindowType 设置窗口类型
|
2023-01-04 18:41:48 +08:00
|
|
|
|
func (m *LCLBrowserWindow) SetWindowType(windowType consts.WINDOW_TYPE) {
|
2022-10-04 13:21:05 +08:00
|
|
|
|
m.windowType = windowType
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// WindowType 返回窗口类型
|
2023-01-04 18:41:48 +08:00
|
|
|
|
func (m *LCLBrowserWindow) WindowType() consts.WINDOW_TYPE {
|
2022-11-01 17:18:46 +08:00
|
|
|
|
return m.windowType
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// ChromiumCreate
|
2023-05-31 17:41:14 +08:00
|
|
|
|
// 创建window浏览器组件
|
|
|
|
|
// 不带有默认事件的chromium
|
2023-06-19 12:41:52 +08:00
|
|
|
|
func (m *LCLBrowserWindow) ChromiumCreate(config *TCefChromiumConfig, defaultUrl string) {
|
2023-05-31 17:41:14 +08:00
|
|
|
|
if m.chromiumBrowser != nil {
|
2022-10-04 13:21:05 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if config == nil {
|
|
|
|
|
config = NewChromiumConfig()
|
|
|
|
|
}
|
2023-05-31 17:41:14 +08:00
|
|
|
|
m.chromiumBrowser = NewChromiumBrowser(m, config)
|
|
|
|
|
m.Chromium().SetEnableMultiBrowserMode(true)
|
2022-10-04 13:21:05 +08:00
|
|
|
|
if defaultUrl != "" {
|
2023-05-31 17:41:14 +08:00
|
|
|
|
m.Chromium().SetDefaultURL(defaultUrl)
|
2022-10-04 13:21:05 +08:00
|
|
|
|
}
|
|
|
|
|
//windowParent
|
2023-05-31 17:41:14 +08:00
|
|
|
|
m.WindowParent().DefaultAnchors()
|
|
|
|
|
m.WindowParent().SetOnEnter(func(sender lcl.IObject) {
|
2022-10-04 13:21:05 +08:00
|
|
|
|
if m.isClosing {
|
|
|
|
|
return
|
|
|
|
|
}
|
2023-05-31 17:41:14 +08:00
|
|
|
|
m.Chromium().Initialized()
|
|
|
|
|
m.Chromium().FrameIsFocused()
|
|
|
|
|
m.Chromium().SetFocus(true)
|
2022-10-04 13:21:05 +08:00
|
|
|
|
})
|
2023-05-31 17:41:14 +08:00
|
|
|
|
m.WindowParent().SetOnExit(func(sender lcl.IObject) {
|
2022-10-04 13:21:05 +08:00
|
|
|
|
if m.isClosing {
|
|
|
|
|
return
|
|
|
|
|
}
|
2023-05-31 17:41:14 +08:00
|
|
|
|
m.Chromium().SendCaptureLostEvent()
|
2022-10-04 13:21:05 +08:00
|
|
|
|
})
|
2023-05-31 17:41:14 +08:00
|
|
|
|
// 主窗口、子窗口chromium检测
|
|
|
|
|
if m.WindowProperty().WindowType != consts.WT_DEV_TOOLS {
|
|
|
|
|
window.CurrentBrowseWindowCache = m
|
|
|
|
|
}
|
2022-10-04 13:21:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// WindowProperty 部分提供部分窗口属性设置
|
2023-01-06 18:26:40 +08:00
|
|
|
|
func (m *LCLBrowserWindow) WindowProperty() *WindowProperty {
|
|
|
|
|
return m.windowProperty
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// defaultChromiumEvent 默认的chromium事件
|
2023-01-04 18:41:48 +08:00
|
|
|
|
func (m *LCLBrowserWindow) defaultChromiumEvent() {
|
2023-01-01 23:24:00 +08:00
|
|
|
|
if m.WindowType() != consts.WT_DEV_TOOLS {
|
2023-01-04 18:41:48 +08:00
|
|
|
|
m.registerPopupEvent()
|
2022-10-04 13:21:05 +08:00
|
|
|
|
m.registerDefaultEvent()
|
|
|
|
|
m.registerDefaultChromiumCloseEvent()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// FormCreate
|
2023-05-31 17:41:14 +08:00
|
|
|
|
// 创建窗口
|
|
|
|
|
// 不带有默认事件的窗口
|
2023-01-04 18:41:48 +08:00
|
|
|
|
func (m *LCLBrowserWindow) FormCreate() {
|
2022-10-04 13:21:05 +08:00
|
|
|
|
if m.isFormCreate {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
m.isFormCreate = true
|
2022-10-27 21:03:15 +08:00
|
|
|
|
m.SetName(fmt.Sprintf("energy_window_name_%d", time.Now().UnixNano()/1e6))
|
2023-07-20 22:35:49 +08:00
|
|
|
|
m.onFormMessages()
|
2022-10-04 13:21:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// defaultWindowEvent 默认窗口活动/关闭处理事件
|
2023-01-04 18:41:48 +08:00
|
|
|
|
func (m *LCLBrowserWindow) defaultWindowEvent() {
|
2023-01-01 23:24:00 +08:00
|
|
|
|
if m.WindowType() != consts.WT_DEV_TOOLS {
|
2023-01-15 23:30:55 +08:00
|
|
|
|
m.TForm.SetOnActivate(m.activate)
|
2022-10-04 13:21:05 +08:00
|
|
|
|
}
|
2023-01-24 16:32:28 +08:00
|
|
|
|
m.TForm.SetOnResize(m.resize)
|
2023-01-15 23:30:55 +08:00
|
|
|
|
m.TForm.SetOnShow(m.show)
|
2022-10-04 13:21:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// defaultWindowCloseEvent 默认的窗口关闭事件
|
2023-01-04 18:41:48 +08:00
|
|
|
|
func (m *LCLBrowserWindow) defaultWindowCloseEvent() {
|
2023-01-15 23:30:55 +08:00
|
|
|
|
m.TForm.SetOnClose(m.close)
|
|
|
|
|
m.TForm.SetOnCloseQuery(m.closeQuery)
|
2022-10-04 13:21:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// EnableDefaultCloseEvent 启用默认关闭事件行为-该窗口将被关闭
|
2023-01-06 13:50:44 +08:00
|
|
|
|
func (m *LCLBrowserWindow) EnableDefaultCloseEvent() {
|
2023-01-04 18:41:48 +08:00
|
|
|
|
m.defaultWindowCloseEvent()
|
|
|
|
|
m.registerDefaultChromiumCloseEvent()
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// EnableAllDefaultEvent 启用所有默认事件行为
|
2023-01-04 18:41:48 +08:00
|
|
|
|
func (m *LCLBrowserWindow) EnableAllDefaultEvent() {
|
|
|
|
|
m.defaultWindowCloseEvent()
|
|
|
|
|
m.defaultChromiumEvent()
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-18 13:50:54 +08:00
|
|
|
|
// SetOnResize 事件,不会覆盖默认事件,返回值:false继续执行默认事件, true跳过默认事件
|
2023-01-15 23:30:55 +08:00
|
|
|
|
func (m *LCLBrowserWindow) SetOnResize(fn TNotifyEvent) {
|
|
|
|
|
m.onResize = fn
|
2022-10-04 13:21:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-18 13:50:54 +08:00
|
|
|
|
// SetOnActivate 事件,不会覆盖默认事件,返回值:false继续执行默认事件, true跳过默认事件
|
2023-01-15 23:30:55 +08:00
|
|
|
|
func (m *LCLBrowserWindow) SetOnActivate(fn TNotifyEvent) {
|
|
|
|
|
m.onActivate = fn
|
2022-10-04 13:21:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-18 13:50:54 +08:00
|
|
|
|
// SetOnShow 事件,不会覆盖默认事件,返回值:false继续执行默认事件, true跳过默认事件
|
2023-01-15 23:30:55 +08:00
|
|
|
|
func (m *LCLBrowserWindow) SetOnShow(fn TNotifyEvent) {
|
|
|
|
|
m.onShow = fn
|
2022-10-04 13:21:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-18 13:50:54 +08:00
|
|
|
|
// SetOnClose 事件,不会覆盖默认事件,返回值:false继续执行默认事件, true跳过默认事件
|
2023-01-15 23:30:55 +08:00
|
|
|
|
func (m *LCLBrowserWindow) SetOnClose(fn TCloseEvent) {
|
|
|
|
|
m.onClose = fn
|
2022-10-04 13:21:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-18 13:50:54 +08:00
|
|
|
|
// SetOnCloseQuery 事件,不会覆盖默认事件,返回值:false继续执行默认事件, true跳过默认事件
|
2023-01-15 23:30:55 +08:00
|
|
|
|
func (m *LCLBrowserWindow) SetOnCloseQuery(fn TCloseQueryEvent) {
|
|
|
|
|
m.onCloseQuery = fn
|
2022-10-04 13:21:05 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// SetOnActivateAfter 每次激活窗口之后执行一次
|
2023-01-04 18:41:48 +08:00
|
|
|
|
func (m *LCLBrowserWindow) SetOnActivateAfter(fn lcl.TNotifyEvent) {
|
2022-10-04 13:21:05 +08:00
|
|
|
|
m.onActivateAfter = fn
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// Minimize
|
2023-01-04 22:47:30 +08:00
|
|
|
|
func (m *LCLBrowserWindow) Minimize() {
|
|
|
|
|
if m.TForm == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
QueueAsyncCall(func(id int) {
|
|
|
|
|
m.SetWindowState(types.WsMinimized)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// Restore
|
2023-02-14 15:25:02 +08:00
|
|
|
|
func (m *LCLBrowserWindow) Restore() {
|
|
|
|
|
m.SetWindowState(types.WsNormal)
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// DisableTransparent 禁用口透明
|
2023-01-04 22:47:30 +08:00
|
|
|
|
func (m *LCLBrowserWindow) DisableTransparent() {
|
|
|
|
|
if m.TForm == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
m.SetAlphaBlend(false)
|
|
|
|
|
m.SetAlphaBlendValue(255)
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// EnableTransparent 使窗口透明 value 0 ~ 255
|
2023-01-04 22:47:30 +08:00
|
|
|
|
func (m *LCLBrowserWindow) EnableTransparent(value uint8) {
|
|
|
|
|
if m.TForm == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
m.SetAlphaBlend(true)
|
|
|
|
|
m.SetAlphaBlendValue(value)
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// DisableMinimize 禁用最小化按钮
|
2023-01-04 22:47:30 +08:00
|
|
|
|
func (m *LCLBrowserWindow) DisableMinimize() {
|
|
|
|
|
if m.TForm == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
2023-01-07 18:42:17 +08:00
|
|
|
|
//m.SetBorderIcons(m.BorderIcons().Exclude(types.BiMinimize))
|
2023-01-23 10:52:40 +08:00
|
|
|
|
m.WindowProperty().EnableMinimize = false
|
|
|
|
|
m.EnabledMinimize(m.WindowProperty().EnableMinimize)
|
2023-01-04 22:47:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// DisableMaximize 禁用最大化按钮
|
2023-01-04 22:47:30 +08:00
|
|
|
|
func (m *LCLBrowserWindow) DisableMaximize() {
|
|
|
|
|
if m.TForm == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
2023-01-07 18:42:17 +08:00
|
|
|
|
//m.SetBorderIcons(m.BorderIcons().Exclude(types.BiMaximize))
|
2023-01-23 10:52:40 +08:00
|
|
|
|
m.WindowProperty().EnableMaximize = false
|
|
|
|
|
m.EnabledMaximize(m.WindowProperty().EnableMaximize)
|
2023-01-07 18:42:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// DisableResize 禁用调整窗口大小
|
2023-01-07 18:42:17 +08:00
|
|
|
|
func (m *LCLBrowserWindow) DisableResize() {
|
|
|
|
|
if m.TForm == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
2023-01-23 10:52:40 +08:00
|
|
|
|
m.WindowProperty().EnableResize = false
|
2023-02-12 17:28:31 +08:00
|
|
|
|
if !m.WindowProperty().EnableHideCaption {
|
2023-01-23 10:52:40 +08:00
|
|
|
|
m.TForm.SetBorderStyle(types.BsSingle)
|
|
|
|
|
}
|
2023-01-04 22:47:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// DisableSystemMenu 禁用系统菜单-同时禁用最小化,最大化,关闭按钮
|
2023-01-04 22:47:30 +08:00
|
|
|
|
func (m *LCLBrowserWindow) DisableSystemMenu() {
|
|
|
|
|
if m.TForm == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
2023-01-07 18:42:17 +08:00
|
|
|
|
//m.SetBorderIcons(m.BorderIcons().Exclude(types.BiSystemMenu))
|
|
|
|
|
m.EnabledSystemMenu(false)
|
2023-01-04 22:47:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// DisableHelp 禁用帮助菜单
|
2023-01-04 22:47:30 +08:00
|
|
|
|
func (m *LCLBrowserWindow) DisableHelp() {
|
|
|
|
|
if m.TForm == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
m.SetBorderIcons(m.BorderIcons().Exclude(types.BiHelp))
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// EnableMinimize 启用最小化按钮
|
2023-01-04 22:47:30 +08:00
|
|
|
|
func (m *LCLBrowserWindow) EnableMinimize() {
|
|
|
|
|
if m.TForm == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
2023-01-07 18:42:17 +08:00
|
|
|
|
//m.SetBorderIcons(m.BorderIcons().Include(types.BiMinimize))
|
2023-01-23 10:52:40 +08:00
|
|
|
|
m.WindowProperty().EnableMinimize = true
|
|
|
|
|
m.EnabledMinimize(m.WindowProperty().EnableMinimize)
|
2023-01-04 22:47:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// EnableMaximize 启用最大化按钮
|
2023-01-04 22:47:30 +08:00
|
|
|
|
func (m *LCLBrowserWindow) EnableMaximize() {
|
|
|
|
|
if m.TForm == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
2023-01-07 18:42:17 +08:00
|
|
|
|
//m.SetBorderIcons(m.BorderIcons().Include(types.BiMaximize))
|
2023-01-23 10:52:40 +08:00
|
|
|
|
m.WindowProperty().EnableMaximize = true
|
|
|
|
|
m.EnabledMaximize(m.WindowProperty().EnableMaximize)
|
2023-01-07 18:42:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// EnableResize 启用允许调整窗口大小
|
2023-01-07 18:42:17 +08:00
|
|
|
|
func (m *LCLBrowserWindow) EnableResize() {
|
|
|
|
|
if m.TForm == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
2023-01-23 10:52:40 +08:00
|
|
|
|
m.WindowProperty().EnableResize = true
|
2023-02-12 17:28:31 +08:00
|
|
|
|
if !m.WindowProperty().EnableHideCaption {
|
2023-01-23 10:52:40 +08:00
|
|
|
|
m.TForm.SetBorderStyle(types.BsSizeable)
|
|
|
|
|
}
|
2023-01-04 22:47:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// EnableSystemMenu 启用系统菜单
|
2023-01-04 22:47:30 +08:00
|
|
|
|
func (m *LCLBrowserWindow) EnableSystemMenu() {
|
|
|
|
|
if m.TForm == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
2023-01-07 18:42:17 +08:00
|
|
|
|
//m.SetBorderIcons(m.BorderIcons().Include(types.BiSystemMenu))
|
|
|
|
|
m.EnabledSystemMenu(true)
|
2023-01-04 22:47:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// EnableHelp 启用帮助菜单
|
2023-01-04 22:47:30 +08:00
|
|
|
|
func (m *LCLBrowserWindow) EnableHelp() {
|
|
|
|
|
if m.TForm == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
m.SetBorderIcons(m.BorderIcons().Include(types.BiHelp))
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// IsViewsFramework 返回是否VF窗口组件,这里返回false
|
2023-01-06 17:42:34 +08:00
|
|
|
|
func (m *LCLBrowserWindow) IsViewsFramework() bool {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// IsLCL 返回是否LCL窗口组件,这里返回true
|
2023-01-06 17:42:34 +08:00
|
|
|
|
func (m *LCLBrowserWindow) IsLCL() bool {
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// show 内部调用
|
2023-01-04 18:41:48 +08:00
|
|
|
|
func (m *LCLBrowserWindow) show(sender lcl.IObject) {
|
2022-10-04 13:21:05 +08:00
|
|
|
|
if m.onShow != nil {
|
2023-07-07 15:27:26 +08:00
|
|
|
|
m.onShow(sender)
|
2022-10-04 13:21:05 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-06 11:18:08 +08:00
|
|
|
|
// SetCreateBrowserExtraInfo
|
|
|
|
|
// 设置 Chromium 创建浏览器时设置的扩展信息
|
|
|
|
|
func (m *LCLBrowserWindow) SetCreateBrowserExtraInfo(windowName string, context *ICefRequestContext, extraInfo *ICefDictionaryValue) {
|
|
|
|
|
if m.chromiumBrowser != nil {
|
|
|
|
|
m.chromiumBrowser.SetCreateBrowserExtraInfo(windowName, context, extraInfo)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// resize 内部调用
|
2023-01-04 18:41:48 +08:00
|
|
|
|
func (m *LCLBrowserWindow) resize(sender lcl.IObject) {
|
2022-10-04 13:21:05 +08:00
|
|
|
|
var ret bool
|
|
|
|
|
if m.onResize != nil {
|
2023-01-15 23:30:55 +08:00
|
|
|
|
if m.onResize(sender) {
|
|
|
|
|
ret = true
|
2022-10-04 13:21:05 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if !ret {
|
|
|
|
|
if m.isClosing {
|
|
|
|
|
return
|
|
|
|
|
}
|
2023-01-18 23:33:20 +08:00
|
|
|
|
if m.windowResize != nil {
|
|
|
|
|
m.windowResize(sender)
|
|
|
|
|
}
|
2023-05-31 17:41:14 +08:00
|
|
|
|
if m.chromiumBrowser != nil {
|
|
|
|
|
m.Chromium().NotifyMoveOrResizeStarted()
|
2023-06-02 08:46:24 +08:00
|
|
|
|
if m.chromiumBrowser.WindowParent() != nil {
|
|
|
|
|
m.chromiumBrowser.WindowParent().UpdateSize()
|
|
|
|
|
}
|
2022-10-04 13:21:05 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// activate 内部调用
|
2023-01-04 18:41:48 +08:00
|
|
|
|
func (m *LCLBrowserWindow) activate(sender lcl.IObject) {
|
2022-10-04 13:21:05 +08:00
|
|
|
|
var ret bool
|
|
|
|
|
if m.onActivate != nil {
|
2023-01-15 23:30:55 +08:00
|
|
|
|
ret = m.onActivate(sender)
|
2022-10-04 13:21:05 +08:00
|
|
|
|
}
|
|
|
|
|
if !ret {
|
|
|
|
|
if m.isClosing {
|
|
|
|
|
return
|
|
|
|
|
}
|
2023-07-07 15:27:26 +08:00
|
|
|
|
if m.chromiumBrowser != nil && !m.chromiumBrowser.IsCreated() {
|
|
|
|
|
if m.WindowProperty().WindowType != consts.WT_DEV_TOOLS {
|
|
|
|
|
m.chromiumBrowser.CreateBrowser()
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-10-04 13:21:05 +08:00
|
|
|
|
}
|
|
|
|
|
if m.onActivateAfter != nil {
|
|
|
|
|
m.onActivateAfter(sender)
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-02-20 00:20:01 +08:00
|
|
|
|
|
|
|
|
|
// registerDefaultEvent 注册默认事件 部分事件允许被覆盖
|
2023-01-04 18:41:48 +08:00
|
|
|
|
func (m *LCLBrowserWindow) registerDefaultEvent() {
|
|
|
|
|
var bwEvent = BrowserWindow.browserEvent
|
|
|
|
|
//默认自定义快捷键
|
|
|
|
|
defaultAcceleratorCustom()
|
2023-05-31 17:41:14 +08:00
|
|
|
|
m.Chromium().SetOnProcessMessageReceived(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, sourceProcess consts.CefProcessId, message *ICefProcessMessage) bool {
|
2022-10-04 13:21:05 +08:00
|
|
|
|
if bwEvent.onProcessMessageReceived != nil {
|
|
|
|
|
return bwEvent.onProcessMessageReceived(sender, browser, frame, sourceProcess, message)
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
})
|
2023-05-31 17:41:14 +08:00
|
|
|
|
m.Chromium().SetOnBeforeResourceLoad(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, request *ICefRequest, callback *ICefCallback, result *consts.TCefReturnValue) {
|
2023-01-04 18:41:48 +08:00
|
|
|
|
if assetserve.AssetsServerHeaderKeyValue != "" {
|
|
|
|
|
request.SetHeaderByName(assetserve.AssetsServerHeaderKeyName, assetserve.AssetsServerHeaderKeyValue, true)
|
|
|
|
|
}
|
|
|
|
|
if bwEvent.onBeforeResourceLoad != nil {
|
|
|
|
|
bwEvent.onBeforeResourceLoad(sender, browser, frame, request, callback, result)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
//事件可以被覆盖
|
2023-05-31 17:41:14 +08:00
|
|
|
|
m.Chromium().SetOnBeforeDownload(func(sender lcl.IObject, browser *ICefBrowser, beforeDownloadItem *ICefDownloadItem, suggestedName string, callback *ICefBeforeDownloadCallback) {
|
2023-01-04 18:41:48 +08:00
|
|
|
|
if bwEvent.onBeforeDownload != nil {
|
|
|
|
|
bwEvent.onBeforeDownload(sender, browser, beforeDownloadItem, suggestedName, callback)
|
|
|
|
|
} else {
|
|
|
|
|
callback.Cont(consts.ExePath+consts.Separator+suggestedName, true)
|
|
|
|
|
}
|
|
|
|
|
})
|
2023-05-31 17:41:14 +08:00
|
|
|
|
m.Chromium().SetOnBeforeContextMenu(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, params *ICefContextMenuParams, model *ICefMenuModel) {
|
2023-01-04 18:41:48 +08:00
|
|
|
|
if bwEvent.onBeforeContextMenu != nil {
|
|
|
|
|
bwEvent.onBeforeContextMenu(sender, browser, frame, params, model)
|
2023-01-09 13:11:42 +08:00
|
|
|
|
} else {
|
|
|
|
|
chromiumOnBeforeContextMenu(sender, browser, frame, params, model)
|
2023-01-04 18:41:48 +08:00
|
|
|
|
}
|
|
|
|
|
})
|
2023-05-31 17:41:14 +08:00
|
|
|
|
m.Chromium().SetOnContextMenuCommand(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, params *ICefContextMenuParams, commandId consts.MenuId, eventFlags uint32, result *bool) {
|
2023-01-04 18:41:48 +08:00
|
|
|
|
if bwEvent.onContextMenuCommand != nil {
|
|
|
|
|
bwEvent.onContextMenuCommand(sender, browser, frame, params, commandId, eventFlags, result)
|
2023-01-09 13:11:42 +08:00
|
|
|
|
} else {
|
|
|
|
|
chromiumOnContextMenuCommand(sender, browser, frame, params, commandId, eventFlags, result)
|
2023-01-04 18:41:48 +08:00
|
|
|
|
}
|
|
|
|
|
})
|
2023-05-31 17:41:14 +08:00
|
|
|
|
m.Chromium().SetOnFrameCreated(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame) {
|
2022-10-04 13:21:05 +08:00
|
|
|
|
if bwEvent.onFrameCreated != nil {
|
|
|
|
|
bwEvent.onFrameCreated(sender, browser, frame)
|
|
|
|
|
}
|
|
|
|
|
})
|
2023-05-31 17:41:14 +08:00
|
|
|
|
m.Chromium().SetOnFrameDetached(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame) {
|
2022-12-15 23:13:27 +08:00
|
|
|
|
chromiumOnFrameDetached(browser, frame)
|
2022-10-04 13:21:05 +08:00
|
|
|
|
if bwEvent.onFrameDetached != nil {
|
|
|
|
|
bwEvent.onFrameDetached(sender, browser, frame)
|
|
|
|
|
}
|
|
|
|
|
})
|
2023-05-31 17:41:14 +08:00
|
|
|
|
m.Chromium().SetOnAfterCreated(func(sender lcl.IObject, browser *ICefBrowser) {
|
2022-12-15 23:13:27 +08:00
|
|
|
|
if chromiumOnAfterCreate(browser) {
|
|
|
|
|
return
|
|
|
|
|
}
|
2022-10-04 13:21:05 +08:00
|
|
|
|
if bwEvent.onAfterCreated != nil {
|
|
|
|
|
bwEvent.onAfterCreated(sender, browser)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
//事件可以被覆盖
|
2023-05-31 17:41:14 +08:00
|
|
|
|
m.Chromium().SetOnKeyEvent(func(sender lcl.IObject, browser *ICefBrowser, event *TCefKeyEvent, osEvent *consts.TCefEventHandle, result *bool) {
|
2023-06-19 12:41:52 +08:00
|
|
|
|
if BrowserWindow.Config.ChromiumConfig().EnableDevTools() {
|
2022-10-04 13:21:05 +08:00
|
|
|
|
if winInfo := BrowserWindow.GetWindowInfo(browser.Identifier()); winInfo != nil {
|
2023-01-04 22:47:30 +08:00
|
|
|
|
if winInfo.WindowType() == consts.WT_DEV_TOOLS || winInfo.WindowType() == consts.WT_VIEW_SOURCE {
|
2022-10-04 13:21:05 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-31 17:41:14 +08:00
|
|
|
|
if event.WindowsKeyCode == consts.VkF12 && event.Kind == consts.KEYEVENT_RAW_KEYDOWN {
|
2022-10-04 13:21:05 +08:00
|
|
|
|
browser.ShowDevTools()
|
|
|
|
|
*result = true
|
2023-05-31 17:41:14 +08:00
|
|
|
|
} else if event.WindowsKeyCode == consts.VkF12 && event.Kind == consts.KEYEVENT_KEYUP {
|
2022-10-04 13:21:05 +08:00
|
|
|
|
*result = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if KeyAccelerator.accelerator(browser, event, result) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
if bwEvent.onKeyEvent != nil {
|
2023-06-13 12:12:21 +08:00
|
|
|
|
bwEvent.onKeyEvent(sender, browser, event, osEvent, m, result)
|
2022-10-04 13:21:05 +08:00
|
|
|
|
}
|
|
|
|
|
})
|
2023-05-31 17:41:14 +08:00
|
|
|
|
m.Chromium().SetOnBeforeBrowser(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, request *ICefRequest, userGesture, isRedirect bool) bool {
|
2022-10-04 13:21:05 +08:00
|
|
|
|
if bwEvent.onBeforeBrowser != nil {
|
2023-06-13 12:12:21 +08:00
|
|
|
|
return bwEvent.onBeforeBrowser(sender, browser, frame, request, userGesture, isRedirect, m)
|
2022-10-04 13:21:05 +08:00
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
|
})
|
2023-05-31 17:41:14 +08:00
|
|
|
|
m.Chromium().SetOnTitleChange(func(sender lcl.IObject, browser *ICefBrowser, title string) {
|
2022-10-04 13:21:05 +08:00
|
|
|
|
updateBrowserDevTools(browser, title)
|
|
|
|
|
if bwEvent.onTitleChange != nil {
|
2023-06-13 12:12:21 +08:00
|
|
|
|
bwEvent.onTitleChange(sender, browser, title, m)
|
2022-10-04 13:21:05 +08:00
|
|
|
|
}
|
|
|
|
|
})
|
2023-05-31 17:41:14 +08:00
|
|
|
|
m.Chromium().SetOnDragEnter(func(sender lcl.IObject, browser *ICefBrowser, dragData *ICefDragData, mask consts.TCefDragOperations, result *bool) {
|
2023-01-23 10:52:40 +08:00
|
|
|
|
*result = !m.WindowProperty().EnableDragFile
|
2023-01-08 18:05:03 +08:00
|
|
|
|
if bwEvent.onDragEnter != nil {
|
2023-06-13 12:12:21 +08:00
|
|
|
|
bwEvent.onDragEnter(sender, browser, dragData, mask, m, result)
|
2023-01-08 18:05:03 +08:00
|
|
|
|
}
|
|
|
|
|
})
|
2023-05-31 17:41:14 +08:00
|
|
|
|
m.Chromium().SetOnLoadEnd(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, httpStatusCode int32) {
|
2023-01-08 18:05:03 +08:00
|
|
|
|
if bwEvent.onLoadEnd != nil {
|
|
|
|
|
bwEvent.onLoadEnd(sender, browser, frame, httpStatusCode)
|
|
|
|
|
}
|
|
|
|
|
})
|
2023-07-18 15:38:11 +08:00
|
|
|
|
if application.EnableWebkitAppRegion() {
|
2023-05-31 17:41:14 +08:00
|
|
|
|
m.Chromium().SetOnDraggableRegionsChanged(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, regions *TCefDraggableRegions) {
|
2023-01-12 10:07:10 +08:00
|
|
|
|
if bwEvent.onDraggableRegionsChanged != nil {
|
2023-06-13 12:12:21 +08:00
|
|
|
|
bwEvent.onDraggableRegionsChanged(sender, browser, frame, regions, m)
|
2023-01-12 10:07:10 +08:00
|
|
|
|
}
|
2023-01-20 10:16:38 +08:00
|
|
|
|
m.cwcap.regions = regions
|
2023-01-18 16:34:04 +08:00
|
|
|
|
m.setDraggableRegions()
|
2023-01-12 10:07:10 +08:00
|
|
|
|
})
|
|
|
|
|
}
|
2022-10-04 13:21:05 +08:00
|
|
|
|
}
|
2023-01-04 18:41:48 +08:00
|
|
|
|
|
2023-06-14 17:30:45 +08:00
|
|
|
|
// registerPopupEvent 注册弹出子窗口事件
|
|
|
|
|
func (m *LCLBrowserWindow) registerPopupEvent() {
|
|
|
|
|
var bwEvent = BrowserWindow.browserEvent
|
|
|
|
|
m.Chromium().SetOnBeforePopup(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, beforePopupInfo *BeforePopupInfo, client *ICefClient, noJavascriptAccess *bool) bool {
|
2023-06-19 12:41:52 +08:00
|
|
|
|
if !BrowserWindow.Config.ChromiumConfig().EnableWindowPopup() {
|
2023-06-14 17:30:45 +08:00
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
if next := BrowserWindow.getNextLCLPopupWindow(); next != nil {
|
|
|
|
|
bw := next.AsLCLBrowserWindow().BrowserWindow()
|
|
|
|
|
bw.SetWindowType(consts.WT_POPUP_SUB_BROWSER)
|
|
|
|
|
bw.ChromiumCreate(BrowserWindow.Config.ChromiumConfig(), beforePopupInfo.TargetUrl)
|
|
|
|
|
var result = false
|
|
|
|
|
if bwEvent.onBeforePopup != nil {
|
|
|
|
|
result = bwEvent.onBeforePopup(sender, browser, frame, beforePopupInfo, bw, noJavascriptAccess)
|
|
|
|
|
}
|
|
|
|
|
if !result { // true 表示用户自行处理
|
|
|
|
|
bw.defaultWindowCloseEvent()
|
|
|
|
|
bw.defaultChromiumEvent()
|
|
|
|
|
bw.registerWindowsCompMsgEvent()
|
|
|
|
|
bw.setProperty()
|
|
|
|
|
QueueAsyncCall(func(id int) { // show window, run in main thread
|
|
|
|
|
if bw.WindowProperty().IsShowModel {
|
|
|
|
|
bw.ShowModal()
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
bw.Show()
|
|
|
|
|
})
|
|
|
|
|
result = true
|
|
|
|
|
}
|
|
|
|
|
return result
|
|
|
|
|
}
|
|
|
|
|
return true
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// CloseBrowserWindow 关闭带有浏览器的窗口
|
|
|
|
|
func (m *LCLBrowserWindow) CloseBrowserWindow() {
|
2023-07-21 10:16:51 +08:00
|
|
|
|
if m == nil || m.TForm == nil {
|
2023-06-14 17:30:45 +08:00
|
|
|
|
return
|
|
|
|
|
}
|
2023-07-21 10:16:51 +08:00
|
|
|
|
m.RunOnMainThread(func() {
|
2023-06-14 17:30:45 +08:00
|
|
|
|
if IsDarwin() {
|
|
|
|
|
//main window close
|
|
|
|
|
if m.WindowType() == consts.WT_MAIN_BROWSER {
|
|
|
|
|
m.Close()
|
|
|
|
|
} else {
|
|
|
|
|
//sub window close
|
|
|
|
|
m.isClosing = true
|
|
|
|
|
m.Hide()
|
|
|
|
|
m.Chromium().CloseBrowser(true)
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
m.isClosing = true
|
|
|
|
|
m.Hide()
|
|
|
|
|
m.Chromium().CloseBrowser(true)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// close 内部调用
|
2023-01-04 18:41:48 +08:00
|
|
|
|
func (m *LCLBrowserWindow) close(sender lcl.IObject, action *types.TCloseAction) {
|
2022-12-09 21:08:30 +08:00
|
|
|
|
var ret bool
|
|
|
|
|
if m.onClose != nil {
|
2023-01-15 23:30:55 +08:00
|
|
|
|
ret = m.onClose(sender, action)
|
2022-12-09 21:08:30 +08:00
|
|
|
|
}
|
|
|
|
|
if !ret {
|
2022-12-11 16:01:57 +08:00
|
|
|
|
logger.Debug("window.onClose")
|
2023-06-29 12:07:34 +08:00
|
|
|
|
if m.WindowType() == consts.WT_MAIN_BROWSER || !IsWindows() { // 主窗口 或 非windows
|
|
|
|
|
*action = types.CaFree
|
2023-06-29 12:37:47 +08:00
|
|
|
|
} else if IsWindows() { // windows 子窗口
|
2023-06-29 12:07:34 +08:00
|
|
|
|
*action = types.CaHide
|
|
|
|
|
}
|
2022-12-09 21:08:30 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// closeQuery 内部调用
|
2023-01-04 18:41:48 +08:00
|
|
|
|
func (m *LCLBrowserWindow) closeQuery(sender lcl.IObject, close *bool) {
|
2022-12-09 21:08:30 +08:00
|
|
|
|
var ret bool
|
|
|
|
|
if m.onCloseQuery != nil {
|
2023-01-15 23:30:55 +08:00
|
|
|
|
ret = m.onCloseQuery(sender, close)
|
2022-12-09 21:08:30 +08:00
|
|
|
|
}
|
|
|
|
|
if !ret {
|
2023-01-15 23:30:55 +08:00
|
|
|
|
if m.tray != nil {
|
|
|
|
|
m.tray.close()
|
|
|
|
|
}
|
2022-12-11 16:01:57 +08:00
|
|
|
|
logger.Debug("window.onCloseQuery windowType:", m.WindowType())
|
2022-12-09 21:08:30 +08:00
|
|
|
|
if IsDarwin() {
|
|
|
|
|
//main window close
|
2023-01-01 23:24:00 +08:00
|
|
|
|
if m.WindowType() == consts.WT_MAIN_BROWSER {
|
2022-12-09 21:08:30 +08:00
|
|
|
|
*close = true
|
2023-05-31 17:41:14 +08:00
|
|
|
|
desChildWind := m.WindowParent().DestroyChildWindow()
|
2022-12-11 16:01:57 +08:00
|
|
|
|
logger.Debug("window.onCloseQuery => windowParent.DestroyChildWindow:", desChildWind)
|
2022-12-09 21:08:30 +08:00
|
|
|
|
} else {
|
|
|
|
|
//sub window close
|
|
|
|
|
*close = m.canClose
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
*close = m.canClose
|
2023-06-13 12:12:21 +08:00
|
|
|
|
}
|
2023-06-14 17:30:45 +08:00
|
|
|
|
QueueAsyncCall(func(id int) {
|
|
|
|
|
if !m.isClosing {
|
|
|
|
|
m.isClosing = true
|
|
|
|
|
m.Chromium().CloseBrowser(true)
|
2023-06-15 21:22:27 +08:00
|
|
|
|
if IsDarwin() {
|
|
|
|
|
m.Show() // mac 主窗口未得到焦点时应用不退出, 所以show一下
|
|
|
|
|
}
|
2023-07-17 18:40:53 +08:00
|
|
|
|
m.Hide() // 更快的关闭效果, 先隐藏掉
|
2023-06-14 17:30:45 +08:00
|
|
|
|
}
|
|
|
|
|
})
|
2022-12-09 21:08:30 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2022-10-04 13:21:05 +08:00
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// registerDefaultChromiumCloseEvent 注册默认的chromium关闭事件
|
2023-01-04 18:41:48 +08:00
|
|
|
|
func (m *LCLBrowserWindow) registerDefaultChromiumCloseEvent() {
|
2022-10-04 13:21:05 +08:00
|
|
|
|
var bwEvent = BrowserWindow.browserEvent
|
2023-05-31 17:41:14 +08:00
|
|
|
|
m.Chromium().SetOnClose(func(sender lcl.IObject, browser *ICefBrowser, aAction *consts.TCefCloseBrowserAction) {
|
2022-12-11 16:01:57 +08:00
|
|
|
|
logger.Debug("chromium.onClose")
|
2023-06-14 17:30:45 +08:00
|
|
|
|
var flag = false
|
2022-10-04 13:21:05 +08:00
|
|
|
|
if bwEvent.onClose != nil {
|
2023-06-14 17:30:45 +08:00
|
|
|
|
flag = bwEvent.onClose(sender, browser, aAction, m)
|
|
|
|
|
}
|
|
|
|
|
if !flag {
|
|
|
|
|
if IsDarwin() { //MacOSX
|
|
|
|
|
desChildWind := m.WindowParent().DestroyChildWindow()
|
|
|
|
|
logger.Debug("chromium.onClose => windowParent.DestroyChildWindow:", desChildWind)
|
|
|
|
|
*aAction = consts.CbaClose
|
|
|
|
|
} else if IsLinux() {
|
|
|
|
|
*aAction = consts.CbaClose
|
|
|
|
|
} else if IsWindows() {
|
|
|
|
|
*aAction = consts.CbaDelay
|
|
|
|
|
}
|
|
|
|
|
if !IsDarwin() {
|
|
|
|
|
QueueAsyncCall(func(id int) { //run in main thread
|
|
|
|
|
m.WindowParent().Free()
|
|
|
|
|
logger.Debug("chromium.onClose => windowParent.Free")
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
m.cwcap.free() //释放自定义标题栏 rgn
|
2022-10-04 13:21:05 +08:00
|
|
|
|
}
|
|
|
|
|
})
|
2023-05-31 17:41:14 +08:00
|
|
|
|
m.Chromium().SetOnBeforeClose(func(sender lcl.IObject, browser *ICefBrowser) {
|
2022-12-11 16:01:57 +08:00
|
|
|
|
logger.Debug("chromium.onBeforeClose")
|
2023-06-14 17:30:45 +08:00
|
|
|
|
var flag = false
|
|
|
|
|
if bwEvent.onBeforeClose != nil {
|
|
|
|
|
flag = bwEvent.onBeforeClose(sender, browser, m)
|
|
|
|
|
}
|
|
|
|
|
if !flag {
|
|
|
|
|
m.canClose = true
|
|
|
|
|
var closeWindow = func() {
|
|
|
|
|
defer func() {
|
|
|
|
|
if err := recover(); err != nil {
|
|
|
|
|
logger.Error("chromium.OnBeforeClose Error:", err)
|
|
|
|
|
}
|
|
|
|
|
}()
|
2023-06-15 18:29:23 +08:00
|
|
|
|
if m.GetAuxTools() != nil {
|
|
|
|
|
m.GetAuxTools().SetViewSource(nil)
|
|
|
|
|
m.GetAuxTools().SetDevTools(nil)
|
2023-01-04 22:47:30 +08:00
|
|
|
|
}
|
2023-06-14 17:30:45 +08:00
|
|
|
|
|
|
|
|
|
// LCLBrowserWindow 关闭
|
2023-06-29 12:07:34 +08:00
|
|
|
|
if IsWindows() {
|
2023-07-17 15:12:01 +08:00
|
|
|
|
rtl.PostMessage(m.Handle(), messages.WM_CLOSE, 0, 0)
|
2023-06-29 12:07:34 +08:00
|
|
|
|
} else if IsDarwin() || IsLinux() {
|
2022-11-04 19:46:40 +08:00
|
|
|
|
m.Close()
|
2022-11-04 19:13:27 +08:00
|
|
|
|
}
|
2022-11-01 16:53:22 +08:00
|
|
|
|
}
|
2023-06-14 17:30:45 +08:00
|
|
|
|
QueueAsyncCall(func(id int) { // main thread run
|
|
|
|
|
closeWindow()
|
|
|
|
|
})
|
|
|
|
|
// 最后再移除
|
|
|
|
|
BrowserWindow.removeWindowInfo(m.windowId)
|
|
|
|
|
//chromiumOnBeforeClose(browser)
|
2022-10-04 13:21:05 +08:00
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
2023-07-20 19:52:58 +08:00
|
|
|
|
|
2023-07-20 22:35:49 +08:00
|
|
|
|
// wm message event
|
2023-07-20 19:52:58 +08:00
|
|
|
|
type messageType int32
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
mtMove messageType = iota + 1
|
|
|
|
|
mtSize
|
|
|
|
|
mtWindowPosChanged
|
2023-07-21 09:56:28 +08:00
|
|
|
|
mtPaint
|
2023-07-20 19:52:58 +08:00
|
|
|
|
)
|
|
|
|
|
|
2023-07-21 09:56:28 +08:00
|
|
|
|
type wmPaint func(message *t.TPaint)
|
2023-07-20 19:52:58 +08:00
|
|
|
|
type wmMove func(message *t.TMove)
|
|
|
|
|
type wmSize func(message *t.TSize)
|
|
|
|
|
type wmWindowPosChanged func(message *t.TWindowPosChanged)
|
|
|
|
|
|
2023-07-20 22:35:49 +08:00
|
|
|
|
func (m *LCLBrowserWindow) onFormMessages() {
|
2023-07-21 09:56:28 +08:00
|
|
|
|
m.setOnWMPaint(func(message *t.TPaint) {
|
|
|
|
|
if m.Chromium() != nil {
|
|
|
|
|
m.Chromium().NotifyMoveOrResizeStarted()
|
|
|
|
|
}
|
|
|
|
|
if m.wmPaintMessage != nil {
|
|
|
|
|
m.wmPaintMessage(message)
|
|
|
|
|
}
|
|
|
|
|
})
|
2023-07-20 22:35:49 +08:00
|
|
|
|
m.setOnWMMove(func(message *t.TMove) {
|
|
|
|
|
if m.Chromium() != nil {
|
|
|
|
|
m.Chromium().NotifyMoveOrResizeStarted()
|
|
|
|
|
}
|
|
|
|
|
if m.wmMoveMessage != nil {
|
|
|
|
|
m.wmMoveMessage(message)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
m.setOnWMSize(func(message *t.TSize) {
|
|
|
|
|
if m.Chromium() != nil {
|
|
|
|
|
m.Chromium().NotifyMoveOrResizeStarted()
|
|
|
|
|
}
|
|
|
|
|
if m.wmSizeMessage != nil {
|
|
|
|
|
m.wmSizeMessage(message)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
m.setOnWMWindowPosChanged(func(message *t.TWindowPosChanged) {
|
|
|
|
|
if m.Chromium() != nil {
|
|
|
|
|
m.Chromium().NotifyMoveOrResizeStarted()
|
|
|
|
|
}
|
|
|
|
|
if m.wmWindowPosChangedMessage != nil {
|
|
|
|
|
m.wmWindowPosChangedMessage(message)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-21 09:56:28 +08:00
|
|
|
|
func (m *LCLBrowserWindow) setOnWMPaint(fn wmPaint) {
|
|
|
|
|
imports.Proc(def.Form_SetOnMessagesEvent).Call(m.Instance(), uintptr(mtPaint), api.MakeEventDataPtr(fn))
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-20 22:35:49 +08:00
|
|
|
|
func (m *LCLBrowserWindow) setOnWMMove(fn wmMove) {
|
2023-07-20 19:52:58 +08:00
|
|
|
|
imports.Proc(def.Form_SetOnMessagesEvent).Call(m.Instance(), uintptr(mtMove), api.MakeEventDataPtr(fn))
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-20 22:35:49 +08:00
|
|
|
|
func (m *LCLBrowserWindow) setOnWMSize(fn wmSize) {
|
2023-07-20 19:52:58 +08:00
|
|
|
|
imports.Proc(def.Form_SetOnMessagesEvent).Call(m.Instance(), uintptr(mtSize), api.MakeEventDataPtr(fn))
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-20 22:35:49 +08:00
|
|
|
|
func (m *LCLBrowserWindow) setOnWMWindowPosChanged(fn wmWindowPosChanged) {
|
2023-07-20 19:52:58 +08:00
|
|
|
|
imports.Proc(def.Form_SetOnMessagesEvent).Call(m.Instance(), uintptr(mtWindowPosChanged), api.MakeEventDataPtr(fn))
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-21 09:56:28 +08:00
|
|
|
|
func (m *LCLBrowserWindow) SetOnWMPaint(fn wmPaint) {
|
|
|
|
|
m.wmPaintMessage = fn
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-20 22:35:49 +08:00
|
|
|
|
func (m *LCLBrowserWindow) SetOnWMMove(fn wmMove) {
|
|
|
|
|
m.wmMoveMessage = fn
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *LCLBrowserWindow) SetOnWMSize(fn wmSize) {
|
|
|
|
|
m.wmSizeMessage = fn
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *LCLBrowserWindow) SetOnWMWindowPosChanged(fn wmWindowPosChanged) {
|
|
|
|
|
m.wmWindowPosChangedMessage = fn
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-20 19:52:58 +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) {
|
2023-07-21 10:16:51 +08:00
|
|
|
|
case wmPaint:
|
|
|
|
|
fn.(wmPaint)((*t.TPaint)(getPtr(0)))
|
2023-07-20 19:52:58 +08:00
|
|
|
|
case wmMove:
|
|
|
|
|
fn.(wmMove)((*t.TMove)(getPtr(0)))
|
|
|
|
|
case wmSize:
|
|
|
|
|
fn.(wmSize)((*t.TSize)(getPtr(0)))
|
|
|
|
|
case wmWindowPosChanged:
|
|
|
|
|
fn.(wmWindowPosChanged)((*t.TWindowPosChanged)(getPtr(0)))
|
|
|
|
|
default:
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
return true
|
|
|
|
|
})
|
|
|
|
|
}
|