2023-01-07 21:29:08 +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
|
2023-01-07 21:29:08 +08:00
|
|
|
|
//
|
|
|
|
|
//----------------------------------------
|
|
|
|
|
|
|
|
|
|
//go:build !windows
|
2024-01-01 01:41:04 +08:00
|
|
|
|
// +build !windows
|
2023-01-07 21:29:08 +08:00
|
|
|
|
|
2023-02-20 00:20:01 +08:00
|
|
|
|
// LCL窗口组件定义和实现-非windows平台
|
2023-05-31 17:41:14 +08:00
|
|
|
|
|
2023-01-07 21:29:08 +08:00
|
|
|
|
package cef
|
|
|
|
|
|
2023-01-18 17:21:55 +08:00
|
|
|
|
import (
|
2023-11-09 19:47:44 +08:00
|
|
|
|
"github.com/energye/energy/v2/cef/winapi"
|
2023-05-31 18:00:34 +08:00
|
|
|
|
"github.com/energye/energy/v2/common"
|
2023-11-09 19:47:44 +08:00
|
|
|
|
et "github.com/energye/energy/v2/types"
|
|
|
|
|
"github.com/energye/golcl/lcl"
|
2023-01-18 17:21:55 +08:00
|
|
|
|
"github.com/energye/golcl/lcl/types"
|
|
|
|
|
)
|
2023-01-07 21:35:32 +08:00
|
|
|
|
|
2023-02-14 15:25:02 +08:00
|
|
|
|
// TODO no
|
2023-01-20 10:17:45 +08:00
|
|
|
|
type customWindowCaption struct {
|
2023-01-25 22:26:08 +08:00
|
|
|
|
bw *LCLBrowserWindow
|
|
|
|
|
regions *TCefDraggableRegions
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *customWindowCaption) free() {
|
|
|
|
|
//TODO no
|
2023-01-20 10:17:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-14 15:25:02 +08:00
|
|
|
|
// 显示标题栏
|
2023-01-07 21:29:08 +08:00
|
|
|
|
func (m *LCLBrowserWindow) ShowTitle() {
|
|
|
|
|
if m.TForm == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
2023-02-16 17:26:38 +08:00
|
|
|
|
m.WindowProperty().EnableHideCaption = false
|
|
|
|
|
m.SetBorderStyle(types.BsSizeable)
|
2023-01-07 21:29:08 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-02-14 15:25:02 +08:00
|
|
|
|
// 隐藏标题栏
|
2023-01-07 21:29:08 +08:00
|
|
|
|
func (m *LCLBrowserWindow) HideTitle() {
|
|
|
|
|
if m.TForm == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
2023-02-16 17:26:38 +08:00
|
|
|
|
m.WindowProperty().EnableHideCaption = true
|
|
|
|
|
m.SetBorderStyle(types.BsNone)
|
2023-01-07 21:29:08 +08:00
|
|
|
|
}
|
2023-01-18 08:37:08 +08:00
|
|
|
|
|
|
|
|
|
// 默认事件注册 windows 消息事件
|
|
|
|
|
func (m *LCLBrowserWindow) registerWindowsCompMsgEvent() {
|
2023-07-13 10:56:49 +08:00
|
|
|
|
//TODO no impl
|
2023-01-18 08:37:08 +08:00
|
|
|
|
}
|
2023-01-18 16:34:04 +08:00
|
|
|
|
|
|
|
|
|
func (m *LCLBrowserWindow) setDraggableRegions() {
|
2023-07-13 10:56:49 +08:00
|
|
|
|
//TODO no impl
|
2023-01-18 16:34:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-07-13 16:40:37 +08:00
|
|
|
|
// FramelessForLine 窗口四边框是一条细线
|
|
|
|
|
func (m *LCLBrowserWindow) FramelessForLine() {
|
|
|
|
|
//TODO no impl
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-09 19:47:44 +08:00
|
|
|
|
func (m *LCLBrowserWindow) SetRoundRectRgn(rgn int) {
|
|
|
|
|
if m.rgn == 0 && rgn > 0 {
|
|
|
|
|
m.rgn = rgn
|
|
|
|
|
m.SetOnPaint(func(sender lcl.IObject) {
|
|
|
|
|
hnd := winapi.CreateRoundRectRgn(0, 0, et.LongInt(m.Width()), et.LongInt(m.Height()), et.LongInt(m.rgn), et.LongInt(m.rgn))
|
|
|
|
|
winapi.SetWindowRgn(et.HWND(m.Handle()), hnd, true)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (m *LCLBrowserWindow) Frameless() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-14 22:45:49 +08:00
|
|
|
|
func (m *LCLBrowserWindow) taskMenu() {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2023-11-06 16:27:38 +08:00
|
|
|
|
// Restore 非Windows平台,窗口还原
|
|
|
|
|
func (m *LCLBrowserWindow) Restore() {
|
|
|
|
|
if m.TForm == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
2024-01-04 12:50:25 +08:00
|
|
|
|
RunOnMainThread(func() {
|
2023-11-06 16:27:38 +08:00
|
|
|
|
m.SetWindowState(types.WsNormal)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Minimize 非Windows平台,窗口最小化
|
|
|
|
|
func (m *LCLBrowserWindow) Minimize() {
|
|
|
|
|
if m.TForm == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
2024-01-04 12:50:25 +08:00
|
|
|
|
RunOnMainThread(func() {
|
2023-11-06 16:27:38 +08:00
|
|
|
|
m.SetWindowState(types.WsMinimized)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Maximize 非Windows平台,窗口最大化/还原
|
2023-01-18 16:34:04 +08:00
|
|
|
|
func (m *LCLBrowserWindow) Maximize() {
|
|
|
|
|
if m.TForm == nil {
|
|
|
|
|
return
|
|
|
|
|
}
|
2024-01-04 12:50:25 +08:00
|
|
|
|
RunOnMainThread(func() {
|
2023-07-23 17:42:29 +08:00
|
|
|
|
if m.WindowState() == types.WsMaximized {
|
2023-12-05 21:55:45 +08:00
|
|
|
|
// 当前窗口是最大化状态 > 恢复窗口
|
|
|
|
|
// 此时记录窗口状态
|
|
|
|
|
m.WindowProperty().current.ws = types.WsNormal
|
2023-07-23 17:42:29 +08:00
|
|
|
|
m.SetWindowState(types.WsNormal)
|
|
|
|
|
if common.IsDarwin() { //要这样重复设置2次不然不启作用
|
2023-01-18 16:34:04 +08:00
|
|
|
|
m.SetWindowState(types.WsMaximized)
|
2023-07-23 17:42:29 +08:00
|
|
|
|
m.SetWindowState(types.WsNormal)
|
2023-01-18 16:34:04 +08:00
|
|
|
|
}
|
2023-12-05 21:55:45 +08:00
|
|
|
|
// 当前窗口如果是无标题栏窗口需要恢复到之前记录的窗口属性
|
|
|
|
|
wp := m.WindowProperty()
|
|
|
|
|
if wp.EnableHideCaption {
|
|
|
|
|
m.SetBounds(wp.current.x, wp.current.y, wp.current.w, wp.current.h)
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-23 17:42:29 +08:00
|
|
|
|
} else if m.WindowState() == types.WsNormal {
|
2023-12-05 21:55:45 +08:00
|
|
|
|
// 当前状态是正常的 > 将窗口最大化
|
|
|
|
|
// 在无标题栏窗口时,最大化和全屏正常是无法改变窗口状态
|
|
|
|
|
// 因此需要自己处理窗口大小, 在此之前需要记录窗口状态
|
|
|
|
|
m.setCurrentProperty()
|
|
|
|
|
m.WindowProperty().current.ws = types.WsMaximized
|
|
|
|
|
if m.WindowProperty().EnableHideCaption {
|
|
|
|
|
// 无标题窗口时调整窗口大小,设置为工作窗口大小
|
|
|
|
|
m.SetBoundsRect(m.Monitor().WorkareaRect())
|
|
|
|
|
}
|
|
|
|
|
// 触发窗口最大化
|
2023-07-23 17:42:29 +08:00
|
|
|
|
m.SetWindowState(types.WsMaximized)
|
2023-01-18 16:34:04 +08:00
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
2023-07-14 18:50:14 +08:00
|
|
|
|
|
2023-12-05 21:55:45 +08:00
|
|
|
|
// FullScreen 窗口全屏
|
|
|
|
|
func (m *LCLBrowserWindow) FullScreen() {
|
2024-01-04 12:50:25 +08:00
|
|
|
|
RunOnMainThread(func() {
|
2023-12-05 21:55:45 +08:00
|
|
|
|
// 将窗口全屏
|
|
|
|
|
// 在无标题栏窗口时,最大化和全屏正常是无法改变窗口状态
|
|
|
|
|
// 因此需要自己处理窗口大小, 在此之前需要记录窗口状态
|
|
|
|
|
m.setCurrentProperty()
|
|
|
|
|
m.WindowProperty().current.ws = types.WsFullScreen
|
|
|
|
|
// 触发全屏
|
|
|
|
|
m.SetWindowState(types.WsFullScreen)
|
|
|
|
|
if m.WindowProperty().EnableHideCaption {
|
|
|
|
|
// 设置为屏幕大小
|
|
|
|
|
m.SetBoundsRect(m.Monitor().BoundsRect())
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ExitFullScreen 窗口退出全屏
|
|
|
|
|
func (m *LCLBrowserWindow) ExitFullScreen() {
|
2024-01-04 12:50:25 +08:00
|
|
|
|
RunOnMainThread(func() {
|
2023-12-05 21:55:45 +08:00
|
|
|
|
// 恢复窗口大小
|
|
|
|
|
wp := m.WindowProperty()
|
|
|
|
|
if wp.EnableHideCaption {
|
|
|
|
|
m.SetBounds(wp.current.x, wp.current.y, wp.current.w, wp.current.h)
|
|
|
|
|
}
|
|
|
|
|
// 记录当前窗口状态
|
|
|
|
|
wp.current.ws = types.WsNormal
|
|
|
|
|
// 触发窗口还原正常
|
|
|
|
|
m.SetWindowState(types.WsNormal)
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IsFullScreen 是否全屏
|
|
|
|
|
func (m *LCLBrowserWindow) IsFullScreen() bool {
|
|
|
|
|
return m.WindowState() == types.WsFullScreen
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-16 20:46:00 +08:00
|
|
|
|
// SetFocus 设置窗口焦点
|
|
|
|
|
func (m *LCLBrowserWindow) SetFocus() {
|
|
|
|
|
if m.TForm != nil {
|
|
|
|
|
m.TForm.SetFocus()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-18 12:00:49 +08:00
|
|
|
|
func (m *LCLBrowserWindow) doDrag() {
|
|
|
|
|
// MacOS/Linux Drag Window
|
|
|
|
|
if m.drag != nil {
|
|
|
|
|
m.drag.drag()
|
|
|
|
|
}
|
2023-07-14 18:50:14 +08:00
|
|
|
|
}
|