U: context-menu

This commit is contained in:
杨红岩 2023-07-23 00:08:18 +08:00
parent 45921e9fe4
commit 150e6ad5b4
6 changed files with 53 additions and 30 deletions

View File

@ -59,7 +59,7 @@ func main() {
radioDefault2Check consts.MenuId
)
//右键弹出菜单
event.SetOnBeforeContextMenu(func(sender lcl.IObject, browser *cef.ICefBrowser, frame *cef.ICefFrame, params *cef.ICefContextMenuParams, model *cef.ICefMenuModel) {
event.SetOnBeforeContextMenu(func(sender lcl.IObject, browser *cef.ICefBrowser, frame *cef.ICefFrame, params *cef.ICefContextMenuParams, model *cef.ICefMenuModel) bool {
//既然是自定义,当然要去除之前事先定义好的
model.Clear()
//开始创建菜单每个菜单项都有自己的ID, 所以要先定义一个能保存这些菜单项的ID的变量
@ -122,6 +122,7 @@ func main() {
radioDefault2Check = menuIdRadio201
}
model.SetChecked(radioDefault2Check, true)
return true
})
//右键菜单项命令
event.SetOnContextMenuCommand(func(sender lcl.IObject, browser *cef.ICefBrowser, frame *cef.ICefFrame, params *cef.ICefContextMenuParams, menuId consts.MenuId, eventFlags uint32, result *bool) {

View File

@ -19,8 +19,6 @@ import (
"github.com/energye/energy/v2/logger"
"github.com/energye/energy/v2/pkgs/assetserve"
"github.com/energye/golcl/lcl"
"os"
"path"
)
//go:embed resources
@ -44,40 +42,42 @@ func main() {
cef.BrowserWindow.SetBrowserInit(func(event *cef.BrowserEvent, window cef.IBrowserWindow) {
//window.DisableResize()
window.SetCenterWindow(true)
window.SetTitle("这里改变了窗口标题")
window.SetSize(1024, 900)
fmt.Println("cef.BrowserWindow.SetViewFrameBrowserInit", window)
fmt.Println("LCL", window.AsLCLBrowserWindow(), "VF", window.AsViewsFrameworkBrowserWindow())
window.AsViewsFrameworkBrowserWindow().SetOnWindowCreated(func(sender lcl.IObject, window *cef.ICefWindow) {
fmt.Println("WindowCreated.window", window.WindowAppIcon().Width(), window.WindowAppIcon().Height())
image := cef.ImageRef.New()
cw, _ := os.Getwd()
cw = path.Join(cw, "example", "dev-test", "vf-browser", "resources", "icon.png")
byt, err := os.ReadFile(cw)
fmt.Println("image icon.png", len(byt), err)
image.AddPng(1.2, byt)
fmt.Println("image", image.Width(), image.Height())
})
//window.SetTitle("这里改变了窗口标题")
//window.SetSize(1024, 900)
//fmt.Println("cef.BrowserWindow.SetViewFrameBrowserInit", window)
//fmt.Println("LCL", window.AsLCLBrowserWindow(), "VF", window.AsViewsFrameworkBrowserWindow())
//window.AsViewsFrameworkBrowserWindow().SetOnWindowCreated(func(sender lcl.IObject, window *cef.ICefWindow) {
// fmt.Println("WindowCreated.window", window.WindowAppIcon().Width(), window.WindowAppIcon().Height())
// image := cef.ImageRef.New()
// cw, _ := os.Getwd()
// cw = path.Join(cw, "example", "dev-test", "vf-browser", "resources", "icon.png")
// byt, err := os.ReadFile(cw)
// fmt.Println("image icon.png", len(byt), err)
// image.AddPng(1.2, byt)
// fmt.Println("image", image.Width(), image.Height())
//})
event.SetOnBeforePopup(func(sender lcl.IObject, browser *cef.ICefBrowser, frame *cef.ICefFrame, beforePopupInfo *cef.BeforePopupInfo, popupWindow cef.IBrowserWindow, noJavascriptAccess *bool) bool {
fmt.Println("IsViewsFramework:", popupWindow.IsViewsFramework())
popupWindow.SetTitle("修改了标题: " + beforePopupInfo.TargetUrl)
popupWindow.EnableResize()
popupWindow.DisableMaximize()
popupWindow.DisableResize()
popupWindow.DisableMinimize()
//popupWindow.SetTitle("修改了标题: " + beforePopupInfo.TargetUrl)
//popupWindow.EnableResize()
//popupWindow.DisableMaximize()
//popupWindow.DisableResize()
//popupWindow.DisableMinimize()
popupWindow.SetSize(800, 600)
browserWindow := popupWindow.AsViewsFrameworkBrowserWindow()
browserWindow.SetOnWindowCreated(func(sender lcl.IObject, window *cef.ICefWindow) {
fmt.Println("popupWindow.SetOnWindowCreated", window.WindowAppIcon())
})
//browserWindow.SetOnGetInitialBounds(func(sender lcl.IObject, window *cef.ICefWindow, aResult *cef.TCefRect) {
// fmt.Println("popupWindow.SetOnGetInitialBounds", *aResult)
browserWindow.Chromium().Config().SetEnableMenu(false)
//browserWindow.SetOnWindowCreated(func(sender lcl.IObject, window *cef.ICefWindow) {
// fmt.Println("popupWindow.SetOnWindowCreated", window.WindowAppIcon())
//})
//browserWindow.BrowserWindow().CreateTopLevelWindow()
//browserWindow.BrowserWindow().HideTitle()
fmt.Println("browserWindow:", browserWindow, browserWindow.WindowComponent().WindowHandle())
////browserWindow.SetOnGetInitialBounds(func(sender lcl.IObject, window *cef.ICefWindow, aResult *cef.TCefRect) {
//// fmt.Println("popupWindow.SetOnGetInitialBounds", *aResult)
////})
////browserWindow.BrowserWindow().CreateTopLevelWindow()
browserWindow.BrowserWindow().HideTitle()
//fmt.Println("browserWindow:", browserWindow, browserWindow.WindowComponent().WindowHandle())
return false
})
return
window.AsViewsFrameworkBrowserWindow().WindowComponent().SetOnWindowActivationChanged(func(sender lcl.IObject, window *cef.ICefWindow, active bool) {
fmt.Println("SetOnWindowActivationChanged", active)
})

View File

@ -0,0 +1,6 @@
### 窗口状态示例
### 窗口初始化时状态和动态控制窗口状态的示例
### 分别为 LCL 和 VF

View File

@ -0,0 +1,5 @@
package main
func main() {
}

View File

@ -0,0 +1,5 @@
package main
func main() {
}

View File

@ -124,7 +124,13 @@ func (m *MainWindowDemo) OnFormCreate(sender lcl.IObject) {
model.Clear()
})
//禁止弹出新窗口
chromiumBrowser.Chromium().SetOnOpenUrlFromTab(func(sender lcl.IObject, browser *cef.ICefBrowser, frame *cef.ICefFrame, targetUrl string, targetDisposition consts.TCefWindowOpenDisposition, userGesture bool) bool {
fmt.Println("OnOpenUrlFromTab")
return true
})
//禁止弹出新窗口
chromiumBrowser.Chromium().SetOnBeforePopup(func(sender lcl.IObject, browser *cef.ICefBrowser, frame *cef.ICefFrame, beforePopupInfo *cef.BeforePopupInfo, client *cef.ICefClient, noJavascriptAccess *bool) bool {
fmt.Println("OnBeforePopup")
return true
})