U: window state

A: default window attribute configuration
This commit is contained in:
杨红岩 2023-07-23 21:15:32 +08:00
parent 5bd100bd27
commit 43deb13e67
4 changed files with 92 additions and 14 deletions

View File

@ -38,7 +38,16 @@ func dragExtensionHandler() {
}
energyExtensionHandler := V8HandlerRef.New()
energyExtensionHandler.Execute(func(name string, object *ICefV8Value, arguments *TCefV8ValueArray, retVal *ResultV8Value, exception *ResultString) bool {
if name == mouseUp || name == mouseDown {
if name == mouseDown {
return true
} else if name == mouseUp {
message := &ipcArgument.List{
Id: -1,
BId: ipc.RenderChan().BrowserId(),
Name: internalIPCDRAG,
Data: &drag{T: dragUp},
}
ipc.RenderChan().IPC().Send(message.Bytes())
return true
} else if name == mouseMove {
message := &ipcArgument.List{
@ -85,13 +94,15 @@ func dragExtensionHandler() {
mouseMove();
}
energyExtension.drag.mouseUp = function (e) {
if (!energyExtension.drag.enableDrag || !energyExtension.drag.shouldDrag) {
if (!energyExtension.drag.enableDrag) {
return
}
energyExtension.drag.shouldDrag = false;
//document.body.style.cursor = "default";
native function mouseUp();
mouseUp();
if (energyExtension.drag.war(e)) {
e.preventDefault();
native function mouseUp();
mouseUp();
}
}
energyExtension.drag.mouseDown = function (e) {
if (!energyExtension.drag.enableDrag || ((e.offsetX > e.target.clientWidth || e.offsetY > e.target.clientHeight))) {
@ -123,5 +134,9 @@ func dragExtensionHandler() {
}
func (m *drag) drag() {
if m.T == dragUp {
if m.window.IsLCL() {
m.window.AsLCLBrowserWindow().BrowserWindow().cwcap.canCaption = false
}
}
}

View File

@ -114,7 +114,7 @@ func (m *LCLBrowserWindow) setProperty() {
}
if wp.EnableCenterWindow {
m.SetSize(wp.Width, wp.Height)
m.SetPosition(types.PoDesktopCenter) // TODO 多显示器时有bug
m.SetCenterWindow(true)
} else {
m.SetPosition(types.PoDesigned)
m.SetBounds(wp.X, wp.Y, wp.Width, wp.Height)
@ -148,10 +148,33 @@ func (m *LCLBrowserWindow) setProperty() {
}
// 只有隐藏窗口标题时才全屏 TODO 拖拽时的问题不还原窗口
if wp.EnableHideCaption && wp.WindowInitState == types.WsFullScreen {
m.SetBoundsRect(m.Monitor().BoundsRect())
m.FullScreen()
} else {
m.SetWindowState(wp.WindowInitState)
}
// 当前窗口状态
m.setCurrentProperty()
}
// FullScreen 窗口全屏
func (m *LCLBrowserWindow) FullScreen() bool {
if m.WindowProperty().EnableHideCaption {
m.WindowProperty().current.ws = types.WsFullScreen
m.setCurrentProperty()
m.SetBoundsRect(m.Monitor().BoundsRect())
return true
}
return false
}
// ExitFullScreen 窗口退出全屏
func (m *LCLBrowserWindow) ExitFullScreen() {
wp := m.WindowProperty()
if wp.EnableHideCaption && wp.current.ws == types.WsFullScreen {
wp.current.ws = types.WsNormal
m.SetWindowState(types.WsNormal)
m.SetBounds(wp.current.x, wp.current.y, wp.current.w, wp.current.h)
}
}
// Handle 窗口句柄
@ -191,7 +214,7 @@ func (m *LCLBrowserWindow) AsLCLBrowserWindow() ILCLBrowserWindow {
return m
}
// SetCenterWindow 窗口居中
// SetCenterWindow 窗口居中 // TODO 多显示器时有bug
func (m *LCLBrowserWindow) SetCenterWindow(value bool) {
if m.TForm == nil {
return
@ -728,6 +751,7 @@ func (m *LCLBrowserWindow) resize(sender lcl.IObject) {
if m.isClosing {
return
}
m.setCurrentProperty()
if m.windowResize != nil {
m.windowResize(sender)
}
@ -740,6 +764,18 @@ func (m *LCLBrowserWindow) resize(sender lcl.IObject) {
}
}
// 在窗口坐标、大小、全屏时保存当前窗口属性
func (m *LCLBrowserWindow) setCurrentProperty() {
if m.WindowProperty().current.ws == types.WsFullScreen {
return
}
boundRect := m.BoundsRect()
m.WindowProperty().current.x = boundRect.Left
m.WindowProperty().current.y = boundRect.Top
m.WindowProperty().current.w = boundRect.Width()
m.WindowProperty().current.h = boundRect.Height()
}
// activate 内部调用
func (m *LCLBrowserWindow) activate(sender lcl.IObject) {
var ret bool
@ -1079,6 +1115,7 @@ func (m *LCLBrowserWindow) onFormMessages() {
}
})
m.setOnWMMove(func(message *t.TMove) {
m.setCurrentProperty()
if m.Chromium() != nil {
m.Chromium().NotifyMoveOrResizeStarted()
}

View File

@ -180,18 +180,22 @@ func (m *customWindowCaption) onCanBorder(x, y int32, rect *types.TRect) (int, b
// onNCLButtonDown NC 鼠标左键按下
func (m *customWindowCaption) onNCLButtonDown(hWND types.HWND, message *types.TMessage, lResult *types.LRESULT, aHandled *bool) {
if m.canCaption { // 标题栏
x, y := m.toPoint(message)
*lResult = messages.HTCAPTION
m.borderMD = true
*aHandled = true
//全屏时不能移动窗口
if m.bw.WindowProperty().current.ws == types.WsFullScreen {
return
}
x, y := m.toPoint(message)
m.borderMD = true
if win.ReleaseCapture() {
win.PostMessage(hWND, messages.WM_NCLBUTTONDOWN, messages.HTCAPTION, rtl.MakeLParam(uint16(x), uint16(y)))
}
} else if m.canBorder { // 边框
x, y := m.toPoint(message)
*lResult = types.LRESULT(m.borderHT)
m.borderMD = true
*aHandled = true
m.borderMD = true
if win.ReleaseCapture() {
win.PostMessage(hWND, messages.WM_SYSCOMMAND, uintptr(messages.SC_SIZE|m.borderWMSZ), rtl.MakeLParam(uint16(x), uint16(y)))
}
@ -263,6 +267,10 @@ func (m *LCLBrowserWindow) doOnRenderCompMsg(message *types.TMessage, lResult *t
*lResult = messages.HTCAPTION
*aHandled = true
} else if m.WindowProperty().EnableHideCaption && m.WindowProperty().EnableResize && m.WindowState() == types.WsNormal { //1.窗口隐藏标题栏 2.启用了调整窗口大小 3.非最大化、最小化、全屏状态
//全屏时不能调整窗口大小
if m.WindowProperty().current.ws == types.WsFullScreen {
return
}
rect := m.BoundsRect()
if result, handled := m.cwcap.onCanBorder(x, y, &rect); handled {
*lResult = types.LRESULT(result)
@ -362,7 +370,18 @@ func (m *LCLBrowserWindow) Maximize() {
func (m *LCLBrowserWindow) doDrag() {
// Windows Drag Window
if win.ReleaseCapture() {
win.PostMessage(m.Handle(), messages.WM_NCLBUTTONDOWN, messages.HTCAPTION, 0)
// m.drag != nil 时,这里处理的是 up 事件, 给标题栏标记为false
if m.drag != nil {
m.drag.drag()
} else {
// 全屏时不能拖拽窗口
if m.WindowProperty().current.ws == types.WsFullScreen {
return
}
// 此时是 down 事件, 拖拽窗口
if win.ReleaseCapture() {
win.PostMessage(m.Handle(), messages.WM_NCLBUTTONDOWN, messages.HTCAPTION, 0)
m.cwcap.canCaption = true
}
}
}

View File

@ -25,6 +25,12 @@ type auxTools struct {
viewSourceWindow IBrowserWindow //viewSource
}
// 窗口当前属性
type windowCurrentProperty struct {
ws types.TWindowState
x, y, w, h int32
}
// WindowProperty
// 提供部分窗口属性配置,初始化时生效
// 如需更多属性配置或自定义窗口行为请在`SetBrowserInit`回调函数中使用
@ -52,6 +58,7 @@ type WindowProperty struct {
MinHeight types.TConstraintSize // 窗口 最小高, EnableResize = true 与 MinWidth > 0 生效
MaxWidth types.TConstraintSize // 窗口 最大宽, EnableResize = true 与 MaxHeight > 0 生效
MaxHeight types.TConstraintSize // 窗口 最大高, EnableResize = true 与 MaxWidth > 0 生效
current windowCurrentProperty // 窗口 当前属性
}
// IBrowserWindow