From e67ed61331149456785a45cefcfdf6caf7e19389 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E7=BA=A2=E5=B2=A9?= Date: Mon, 9 Jan 2023 18:32:21 +0800 Subject: [PATCH] v2.2.21 Fixed Chinese input and gtk3 issues for linux packagin --- cef/cef-lcl-commponent-tray.go | 63 ++++++++++++------- cef/cef-lcl-commponent-tray_windows.go | 58 ++++++++++------- ...cef-views-frame-commponent-tray_windows.go | 57 ++++++++++------- .../src/browser-process.go | 2 +- 4 files changed, 110 insertions(+), 70 deletions(-) diff --git a/cef/cef-lcl-commponent-tray.go b/cef/cef-lcl-commponent-tray.go index 0888702a..3b9e850a 100644 --- a/cef/cef-lcl-commponent-tray.go +++ b/cef/cef-lcl-commponent-tray.go @@ -32,92 +32,107 @@ type ITray interface { SetHint(value string) //设置托盘hint(鼠标移动到托盘图标显示的文字) ShowBalloon() //显示托盘气泡 SetBalloon(title, content string, timeout int32) ITray //设置托盘气泡内容 - Tray() *Tray //获得 Tray, ( CefTray 返回 nil ) + Tray() ITray //获得 LCLTray, ( CefTray 返回 nil ) + AsViewsFrameTray() *ViewsFrameTray + AsCEFTray() *CEFTray + AsLCLTray() *LCLTray } //系统托盘 -type Tray struct { +type LCLTray struct { owner lcl.IComponent trayIcon *lcl.TTrayIcon popupMenu *lcl.TPopupMenu } //创建系统托盘 -func newTray(owner lcl.IComponent) *Tray { +func newTray(owner lcl.IComponent) *LCLTray { trayIcon := lcl.NewTrayIcon(owner) popupMenu := lcl.NewPopupMenu(trayIcon) trayIcon.SetPopupMenu(popupMenu) trayIcon.SetVisible(true) - return &Tray{ + return &LCLTray{ owner: owner, trayIcon: trayIcon, popupMenu: popupMenu, } } -func (m *Tray) Tray() *Tray { +func (m *LCLTray) AsViewsFrameTray() *ViewsFrameTray { + return nil +} + +func (m *LCLTray) AsCEFTray() *CEFTray { + return nil +} + +func (m *LCLTray) AsLCLTray() *LCLTray { return m } -func (m *Tray) SetVisible(v bool) { +func (m *LCLTray) Tray() ITray { + return m +} + +func (m *LCLTray) SetVisible(v bool) { m.trayIcon.SetVisible(v) } -func (m *Tray) Visible() bool { +func (m *LCLTray) Visible() bool { return m.trayIcon.Visible() } -func (m *Tray) Show() { +func (m *LCLTray) Show() { m.SetVisible(true) } -func (m *Tray) Hide() { +func (m *LCLTray) Hide() { m.SetVisible(false) } -func (m *Tray) close() { +func (m *LCLTray) close() { m.Hide() } -func (m *Tray) SetOnDblClick(fn lcl.TNotifyEvent) { +func (m *LCLTray) SetOnDblClick(fn lcl.TNotifyEvent) { m.trayIcon.SetOnDblClick(fn) } -func (m *Tray) SetOnClick(fn lcl.TNotifyEvent) { +func (m *LCLTray) SetOnClick(fn lcl.TNotifyEvent) { m.trayIcon.SetOnClick(fn) } -func (m *Tray) SetOnMouseUp(fn TMouseEvent) { +func (m *LCLTray) SetOnMouseUp(fn TMouseEvent) { m.trayIcon.SetOnMouseUp(func(sender lcl.IObject, button types.TMouseButton, shift types.TShiftState, x, y int32) { fn(sender, button, shift, x, y) }) } -func (m *Tray) SetOnMouseDown(fn lcl.TMouseEvent) { +func (m *LCLTray) SetOnMouseDown(fn lcl.TMouseEvent) { m.trayIcon.SetOnMouseDown(fn) } -func (m *Tray) SetOnMouseMove(fn lcl.TMouseMoveEvent) { +func (m *LCLTray) SetOnMouseMove(fn lcl.TMouseMoveEvent) { m.trayIcon.SetOnMouseMove(fn) } //返回托盘根菜单 PopupMenu -func (m *Tray) TrayMenu() *lcl.TPopupMenu { +func (m *LCLTray) TrayMenu() *lcl.TPopupMenu { return m.popupMenu } //设置托盘图标 -func (m *Tray) SetIconFS(iconResourcePath string) { +func (m *LCLTray) SetIconFS(iconResourcePath string) { m.trayIcon.Icon().LoadFromFSFile(iconResourcePath) } //设置托盘图标 -func (m *Tray) SetIcon(iconResourcePath string) { +func (m *LCLTray) SetIcon(iconResourcePath string) { m.trayIcon.Icon().LoadFromFile(iconResourcePath) } -func (m *Tray) SetHint(value string) { +func (m *LCLTray) SetHint(value string) { m.trayIcon.SetHint(value) } -func (m *Tray) SetTitle(title string) { +func (m *LCLTray) SetTitle(title string) { m.trayIcon.SetHint(title) } @@ -128,7 +143,7 @@ func (m *Tray) SetTitle(title string) { //content 气泡内容 // //timeout 显示时间(毫秒) -func (m *Tray) SetBalloon(title, content string, timeout int32) ITray { +func (m *LCLTray) SetBalloon(title, content string, timeout int32) ITray { m.trayIcon.SetBalloonTitle(title) m.trayIcon.SetBalloonHint(content) m.trayIcon.SetBalloonTimeout(timeout) @@ -136,12 +151,12 @@ func (m *Tray) SetBalloon(title, content string, timeout int32) ITray { } //显示托盘气泡 -func (m *Tray) ShowBalloon() { +func (m *LCLTray) ShowBalloon() { m.trayIcon.ShowBalloonHint() } //创建一个菜单,还未添加到托盘 -func (m *Tray) NewMenuItem(caption string, onClick func(lcl.IObject)) *lcl.TMenuItem { +func (m *LCLTray) NewMenuItem(caption string, onClick func(lcl.IObject)) *lcl.TMenuItem { item := lcl.NewMenuItem(m.trayIcon) item.SetCaption(caption) if onClick != nil { @@ -151,7 +166,7 @@ func (m *Tray) NewMenuItem(caption string, onClick func(lcl.IObject)) *lcl.TMenu } //添加一个托盘菜单 -func (m *Tray) AddMenuItem(caption string, onClick func(lcl.IObject)) *lcl.TMenuItem { +func (m *LCLTray) AddMenuItem(caption string, onClick func(lcl.IObject)) *lcl.TMenuItem { item := m.NewMenuItem(caption, onClick) m.popupMenu.Items().Add(item) return item diff --git a/cef/cef-lcl-commponent-tray_windows.go b/cef/cef-lcl-commponent-tray_windows.go index 7aade01b..37b5cd00 100644 --- a/cef/cef-lcl-commponent-tray_windows.go +++ b/cef/cef-lcl-commponent-tray_windows.go @@ -23,7 +23,7 @@ import ( ) //Cef托盘 -type tLCLTrayWindow struct { +type CEFTray struct { *lcl.TForm owner lcl.IComponent trayIcon *lcl.TTrayIcon @@ -35,8 +35,8 @@ type tLCLTrayWindow struct { url string } -func newLCLTrayWindow(owner lcl.IComponent, width, height int32, url string) *tLCLTrayWindow { - var trayForm *tLCLTrayWindow +func newLCLTrayWindow(owner lcl.IComponent, width, height int32, url string) *CEFTray { + var trayForm *CEFTray lcl.Application.CreateForm(&trayForm) trayForm.trayIcon = lcl.NewTrayIcon(owner) trayForm.trayIcon.SetVisible(true) @@ -51,26 +51,38 @@ func newLCLTrayWindow(owner lcl.IComponent, width, height int32, url string) *tL return trayForm } -func (m *tLCLTrayWindow) OnFormCreate(sender lcl.IObject) { +func (m *CEFTray) OnFormCreate(sender lcl.IObject) { m.SetShowInTaskBar(types.StNever) } -func (m *tLCLTrayWindow) Tray() *Tray { +func (m *CEFTray) AsViewsFrameTray() *ViewsFrameTray { return nil } -func (m *tLCLTrayWindow) Show() { +func (m *CEFTray) AsCEFTray() *CEFTray { + return m +} + +func (m *CEFTray) AsLCLTray() *LCLTray { + return nil +} + +func (m *CEFTray) Tray() ITray { + return m +} + +func (m *CEFTray) Show() { if BrowserWindow.mainBrowserWindow.Chromium() == nil || !BrowserWindow.mainBrowserWindow.Chromium().Initialized() { return } m.TForm.Show() } -func (m *tLCLTrayWindow) Hide() { +func (m *CEFTray) Hide() { m.TForm.Hide() } -func (m *tLCLTrayWindow) close() { +func (m *CEFTray) close() { if m.isClosing { return } @@ -79,41 +91,41 @@ func (m *tLCLTrayWindow) close() { m.TForm.Close() } -func (m *tLCLTrayWindow) SetOnDblClick(fn lcl.TNotifyEvent) { +func (m *CEFTray) SetOnDblClick(fn lcl.TNotifyEvent) { m.trayIcon.SetOnDblClick(fn) } -func (m *tLCLTrayWindow) SetOnClick(fn lcl.TNotifyEvent) { +func (m *CEFTray) SetOnClick(fn lcl.TNotifyEvent) { m.trayIcon.SetOnClick(fn) } -func (m *tLCLTrayWindow) SetOnMouseUp(fn TMouseEvent) { +func (m *CEFTray) SetOnMouseUp(fn TMouseEvent) { m.mouseUp = fn } -func (m *tLCLTrayWindow) SetOnMouseDown(fn lcl.TMouseEvent) { +func (m *CEFTray) SetOnMouseDown(fn lcl.TMouseEvent) { m.trayIcon.SetOnMouseDown(fn) } -func (m *tLCLTrayWindow) SetOnMouseMove(fn lcl.TMouseMoveEvent) { +func (m *CEFTray) SetOnMouseMove(fn lcl.TMouseMoveEvent) { m.trayIcon.SetOnMouseMove(fn) } -func (m *tLCLTrayWindow) Visible() bool { +func (m *CEFTray) Visible() bool { return m.TForm.Visible() } -func (m *tLCLTrayWindow) SetVisible(v bool) { +func (m *CEFTray) SetVisible(v bool) { m.trayIcon.SetVisible(v) } -func (m *tLCLTrayWindow) SetHint(value string) { +func (m *CEFTray) SetHint(value string) { m.trayIcon.SetHint(value) } -func (m *tLCLTrayWindow) SetTitle(title string) { +func (m *CEFTray) SetTitle(title string) { m.TForm.SetCaption(title) } -func (m *tLCLTrayWindow) onMouseEvent() { +func (m *CEFTray) onMouseEvent() { QueueAsyncCall(func(id int) { m.trayIcon.SetOnMouseUp(func(sender lcl.IObject, button types.TMouseButton, shift types.TShiftState, x, y int32) { var monitor = m.TForm.Monitor() @@ -150,7 +162,7 @@ func (m *tLCLTrayWindow) onMouseEvent() { //title 气泡标题 //content 气泡内容 //timeout 显示时间(毫秒) -func (m *tLCLTrayWindow) SetBalloon(title, content string, timeout int32) ITray { +func (m *CEFTray) SetBalloon(title, content string, timeout int32) ITray { m.trayIcon.SetBalloonTitle(title) m.trayIcon.SetBalloonHint(content) m.trayIcon.SetBalloonTimeout(timeout) @@ -158,11 +170,11 @@ func (m *tLCLTrayWindow) SetBalloon(title, content string, timeout int32) ITray } //显示托盘气泡 -func (m *tLCLTrayWindow) ShowBalloon() { +func (m *CEFTray) ShowBalloon() { m.trayIcon.ShowBalloonHint() } -func (m *tLCLTrayWindow) createTrayWindow() { +func (m *CEFTray) createTrayWindow() { m.TForm.SetBorderStyle(types.BsNone) m.TForm.SetFormStyle(types.FsStayOnTop) m.TForm.SetBounds(-(m.w * 2), -(m.h * 2), m.w, m.h) @@ -246,11 +258,11 @@ func (m *tLCLTrayWindow) createTrayWindow() { } //设置托盘图标 -func (m *tLCLTrayWindow) SetIconFS(iconResourcePath string) { +func (m *CEFTray) SetIconFS(iconResourcePath string) { m.trayIcon.Icon().LoadFromFSFile(iconResourcePath) } //设置托盘图标 -func (m *tLCLTrayWindow) SetIcon(iconResourcePath string) { +func (m *CEFTray) SetIcon(iconResourcePath string) { m.trayIcon.Icon().LoadFromFile(iconResourcePath) } diff --git a/cef/cef-views-frame-commponent-tray_windows.go b/cef/cef-views-frame-commponent-tray_windows.go index 38fe0858..43e98935 100644 --- a/cef/cef-views-frame-commponent-tray_windows.go +++ b/cef/cef-views-frame-commponent-tray_windows.go @@ -21,7 +21,7 @@ import ( ) //Cef托盘 -type tViewsFrameTrayWindow struct { +type ViewsFrameTray struct { trayWindow *ViewsFrameworkBrowserWindow trayIcon *lcl.TTrayIcon x, y, w, h int32 @@ -29,8 +29,8 @@ type tViewsFrameTrayWindow struct { isClosing bool } -func newViewsFrameTray(owner lcl.IComponent, width, height int32, url string) *tViewsFrameTrayWindow { - var tray = &tViewsFrameTrayWindow{} +func newViewsFrameTray(owner lcl.IComponent, width, height int32, url string) *ViewsFrameTray { + var tray = &ViewsFrameTray{} cc := NewChromiumConfig() cc.SetEnableMenu(false) wp := NewWindowProperty() @@ -58,7 +58,7 @@ func newViewsFrameTray(owner lcl.IComponent, width, height int32, url string) *t return tray } -func (m *tViewsFrameTrayWindow) registerMouseEvent() { +func (m *ViewsFrameTray) registerMouseEvent() { m.trayWindow.WindowComponent().SetOnWindowActivationChanged(func(sender lcl.IObject, window *ICefWindow, active bool) { if active { } else { @@ -108,7 +108,7 @@ func (m *tViewsFrameTrayWindow) registerMouseEvent() { }) } -func (m *tViewsFrameTrayWindow) registerChromiumEvent() { +func (m *ViewsFrameTray) registerChromiumEvent() { m.trayWindow.Chromium().SetOnBeforeContextMenu(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, params *ICefContextMenuParams, model *ICefMenuModel) { model.Clear() }) @@ -130,66 +130,79 @@ func (m *tViewsFrameTrayWindow) registerChromiumEvent() { }) } -func (m *tViewsFrameTrayWindow) Tray() *Tray { +func (m *ViewsFrameTray) AsViewsFrameTray() *ViewsFrameTray { + return m +} + +func (m *ViewsFrameTray) AsCEFTray() *CEFTray { return nil } -func (m *tViewsFrameTrayWindow) Show() { +func (m *ViewsFrameTray) AsLCLTray() *LCLTray { + return nil +} + +func (m *ViewsFrameTray) Tray() ITray { + return m +} + +func (m *ViewsFrameTray) Show() { m.trayWindow.Show() } -func (m *tViewsFrameTrayWindow) Hide() { +func (m *ViewsFrameTray) Hide() { m.trayWindow.Hide() } -func (m *tViewsFrameTrayWindow) close() { +func (m *ViewsFrameTray) close() { if m.isClosing { return } m.trayIcon.SetVisible(false) m.Hide() + m.trayIcon.Free() } -func (m *tViewsFrameTrayWindow) SetOnDblClick(fn lcl.TNotifyEvent) { +func (m *ViewsFrameTray) SetOnDblClick(fn lcl.TNotifyEvent) { m.trayIcon.SetOnDblClick(fn) } -func (m *tViewsFrameTrayWindow) SetOnClick(fn lcl.TNotifyEvent) { +func (m *ViewsFrameTray) SetOnClick(fn lcl.TNotifyEvent) { m.trayIcon.SetOnClick(fn) } -func (m *tViewsFrameTrayWindow) SetOnMouseUp(fn TMouseEvent) { +func (m *ViewsFrameTray) SetOnMouseUp(fn TMouseEvent) { m.mouseUp = fn } -func (m *tViewsFrameTrayWindow) SetOnMouseDown(fn lcl.TMouseEvent) { +func (m *ViewsFrameTray) SetOnMouseDown(fn lcl.TMouseEvent) { m.trayIcon.SetOnMouseDown(fn) } -func (m *tViewsFrameTrayWindow) SetOnMouseMove(fn lcl.TMouseMoveEvent) { +func (m *ViewsFrameTray) SetOnMouseMove(fn lcl.TMouseMoveEvent) { m.trayIcon.SetOnMouseMove(fn) } -func (m *tViewsFrameTrayWindow) Visible() bool { +func (m *ViewsFrameTray) Visible() bool { return false } -func (m *tViewsFrameTrayWindow) SetVisible(v bool) { +func (m *ViewsFrameTray) SetVisible(v bool) { m.trayIcon.SetVisible(v) } -func (m *tViewsFrameTrayWindow) SetHint(value string) { +func (m *ViewsFrameTray) SetHint(value string) { m.trayIcon.SetHint(value) } -func (m *tViewsFrameTrayWindow) SetTitle(title string) { +func (m *ViewsFrameTray) SetTitle(title string) { } //设置托盘气泡 //title 气泡标题 //content 气泡内容 //timeout 显示时间(毫秒) -func (m *tViewsFrameTrayWindow) SetBalloon(title, content string, timeout int32) ITray { +func (m *ViewsFrameTray) SetBalloon(title, content string, timeout int32) ITray { m.trayIcon.SetBalloonTitle(title) m.trayIcon.SetBalloonHint(content) m.trayIcon.SetBalloonTimeout(timeout) @@ -197,16 +210,16 @@ func (m *tViewsFrameTrayWindow) SetBalloon(title, content string, timeout int32) } //显示托盘气泡 -func (m *tViewsFrameTrayWindow) ShowBalloon() { +func (m *ViewsFrameTray) ShowBalloon() { m.trayIcon.ShowBalloonHint() } //设置托盘图标 -func (m *tViewsFrameTrayWindow) SetIconFS(iconResourcePath string) { +func (m *ViewsFrameTray) SetIconFS(iconResourcePath string) { m.trayIcon.Icon().LoadFromFSFile(iconResourcePath) } //设置托盘图标 -func (m *tViewsFrameTrayWindow) SetIcon(iconResourcePath string) { +func (m *ViewsFrameTray) SetIcon(iconResourcePath string) { m.trayIcon.Icon().LoadFromFile(iconResourcePath) } diff --git a/example/dev-test/combination-sundry-browser/src/browser-process.go b/example/dev-test/combination-sundry-browser/src/browser-process.go index e36feb12..a6e6b91f 100644 --- a/example/dev-test/combination-sundry-browser/src/browser-process.go +++ b/example/dev-test/combination-sundry-browser/src/browser-process.go @@ -450,7 +450,7 @@ func tray(browserWindow cef.IBrowserWindow) { window := browserWindow.AsLCLBrowserWindow().BrowserWindow() //托盘 windows linux macos 系统托盘 newTray := window.NewTray() - tray := newTray.Tray() + tray := newTray.AsLCLTray() tray.SetIconFS("resources/icon.ico") menu1 := tray.AddMenuItem("父菜单", nil) menu1.Add(tray.NewMenuItem("子菜单", func(object lcl.IObject) {