提交 79129f28 编写于 作者: yanghye's avatar yanghye

增加 NewBrowserWindow

上级 4fc747d9
......@@ -50,6 +50,7 @@ type ViewsFrameworkBrowserWindow struct {
context *ICefRequestContext //
extraInfo *ICefDictionaryValue //
screen IScreen //屏幕
created bool //
}
// NewViewsFrameworkBrowserWindow 创建 ViewsFrameworkBrowserWindow 窗口
......@@ -71,25 +72,25 @@ func NewViewsFrameworkBrowserWindow(config *TCefChromiumConfig, windowProperty W
browserViewComponent: BrowserViewComponentRef.New(component),
}
m.SetWindowType(windowProperty.WindowType)
m.chromium.SetEnableMultiBrowserMode(true)
m.windowComponent.SetOnWindowCreated(func(sender lcl.IObject, window *ICefWindow) {
if m.chromium.CreateBrowserByBrowserViewComponent(windowProperty.Url, m.browserViewComponent, m.context, m.extraInfo) {
m.windowComponent.AddChildView(m.browserViewComponent)
m.Chromium().SetEnableMultiBrowserMode(true)
m.WindowComponent().SetOnWindowCreated(func(sender lcl.IObject, window *ICefWindow) {
if m.Chromium().CreateBrowserByBrowserViewComponent(windowProperty.Url, m.BrowserViewComponent(), m.context, m.extraInfo) {
m.WindowComponent().AddChildView(m.BrowserViewComponent())
if windowProperty.Title != "" {
m.windowComponent.SetTitle(windowProperty.Title)
m.WindowComponent().SetTitle(windowProperty.Title)
}
if windowProperty.EnableCenterWindow {
m.windowComponent.CenterWindow(NewCefSize(windowProperty.Width, windowProperty.Height))
m.WindowComponent().CenterWindow(NewCefSize(windowProperty.Width, windowProperty.Height))
}
if windowProperty.IconFS != "" {
if emfs.IsExist(windowProperty.IconFS) {
if err := m.windowComponent.SetWindowAppIconByFSFile(1, windowProperty.IconFS); err != nil {
if err := m.WindowComponent().SetWindowAppIconByFSFile(1, windowProperty.IconFS); err != nil {
logger.Error("set window application icon error:", err.Error())
}
}
} else if windowProperty.Icon != "" {
if tools.IsExist(windowProperty.Icon) {
if err := m.windowComponent.SetWindowAppIconByFile(1, windowProperty.Icon); err != nil {
if err := m.WindowComponent().SetWindowAppIconByFile(1, windowProperty.Icon); err != nil {
logger.Error("set window application icon error:", err.Error())
}
}
......@@ -100,11 +101,11 @@ func NewViewsFrameworkBrowserWindow(config *TCefChromiumConfig, windowProperty W
if iconData := assets.DefaultPNGICON(); iconData != nil {
icon := ImageRef.New()
icon.AddPng(1, assets.DefaultPNGICON())
m.windowComponent.SetWindowAppIcon(icon)
m.WindowComponent().SetWindowAppIcon(icon)
}
}
m.browserViewComponent.RequestFocus()
m.windowComponent.Show()
m.BrowserViewComponent().RequestFocus()
m.WindowComponent().Show()
if m.doOnWindowCreated != nil {
m.doOnWindowCreated(sender, window)
}
......@@ -138,7 +139,7 @@ func (m *browserWindow) appContextInitialized(app *TCEFApplication) {
vfMainWindow.ResetWindowPropertyForEvent()
vfMainWindow.registerPopupEvent(true)
vfMainWindow.registerDefaultEvent()
vfMainWindow.windowComponent.SetOnCanClose(func(sender lcl.IObject, window *ICefWindow, aResult *bool) {
vfMainWindow.WindowComponent().SetOnCanClose(func(sender lcl.IObject, window *ICefWindow, aResult *bool) {
*aResult = vfMainWindow.Chromium().TryCloseBrowser()
})
// 设置到 MainBrowser
......@@ -160,13 +161,13 @@ func (m *ViewsFrameworkBrowserWindow) createAfterWindowPropertyForEvent() {
// VF MinimumSize & MaximumSize 在事件中设置
// 如果动态设置,需要自己实现该回调函数
if wp.MinWidth > 0 && wp.MinHeight > 0 {
m.windowComponent.SetOnGetMinimumSize(func(view *ICefView, result *TCefSize) {
m.WindowComponent().SetOnGetMinimumSize(func(view *ICefView, result *TCefSize) {
result.Width = int32(wp.MinWidth)
result.Height = int32(wp.MinHeight)
})
}
if wp.MaxWidth > 0 && wp.MaxHeight > 0 {
m.windowComponent.SetOnGetMaximumSize(func(view *ICefView, result *TCefSize) {
m.WindowComponent().SetOnGetMaximumSize(func(view *ICefView, result *TCefSize) {
result.Width = int32(wp.MaxWidth)
result.Height = int32(wp.MaxHeight)
})
......@@ -179,7 +180,7 @@ func (m *ViewsFrameworkBrowserWindow) registerPopupEvent(isMain bool) {
var bwEvent = BrowserWindow.browserEvent
if !isMain {
// 子窗口关闭流程
m.chromium.SetOnBeforeClose(func(sender lcl.IObject, browser *ICefBrowser) {
m.Chromium().SetOnBeforeClose(func(sender lcl.IObject, browser *ICefBrowser) {
chromiumOnBeforeClose(browser)
})
}
......@@ -215,12 +216,12 @@ func (m *ViewsFrameworkBrowserWindow) registerPopupEvent(isMain bool) {
// ResetWindowPropertyForEvent 重置窗口属性-通过事件函数
func (m *ViewsFrameworkBrowserWindow) ResetWindowPropertyForEvent() {
wp := m.WindowProperty()
m.windowComponent.SetOnGetInitialShowState(func(sender lcl.IObject, window *ICefWindow, aResult *consts.TCefShowState) {
m.WindowComponent().SetOnGetInitialShowState(func(sender lcl.IObject, window *ICefWindow, aResult *consts.TCefShowState) {
*aResult = consts.TCefShowState(wp.WindowInitState + 1) // CEF 要 + 1
})
m.windowComponent.SetOnGetInitialBounds(func(sender lcl.IObject, window *ICefWindow, aResult *TCefRect) {
m.WindowComponent().SetOnGetInitialBounds(func(sender lcl.IObject, window *ICefWindow, aResult *TCefRect) {
if wp.EnableCenterWindow {
m.windowComponent.CenterWindow(NewCefSize(wp.Width, wp.Height))
m.WindowComponent().CenterWindow(NewCefSize(wp.Width, wp.Height))
aResult.Width = wp.Width
aResult.Height = wp.Height
} else {
......@@ -233,23 +234,23 @@ func (m *ViewsFrameworkBrowserWindow) ResetWindowPropertyForEvent() {
m.doOnGetInitialBounds(sender, window, aResult)
}
})
m.windowComponent.SetOnCanMinimize(func(sender lcl.IObject, window *ICefWindow, aResult *bool) {
m.WindowComponent().SetOnCanMinimize(func(sender lcl.IObject, window *ICefWindow, aResult *bool) {
*aResult = wp.EnableMinimize
})
m.windowComponent.SetOnCanResize(func(sender lcl.IObject, window *ICefWindow, aResult *bool) {
m.WindowComponent().SetOnCanResize(func(sender lcl.IObject, window *ICefWindow, aResult *bool) {
*aResult = wp.EnableResize
})
m.windowComponent.SetOnCanMaximize(func(sender lcl.IObject, window *ICefWindow, aResult *bool) {
m.WindowComponent().SetOnCanMaximize(func(sender lcl.IObject, window *ICefWindow, aResult *bool) {
*aResult = wp.EnableMaximize
})
m.windowComponent.SetOnCanClose(func(sender lcl.IObject, window *ICefWindow, aResult *bool) {
m.WindowComponent().SetOnCanClose(func(sender lcl.IObject, window *ICefWindow, aResult *bool) {
*aResult = wp.EnableClose
})
m.windowComponent.SetOnIsFrameless(func(sender lcl.IObject, window *ICefWindow, aResult *bool) {
m.WindowComponent().SetOnIsFrameless(func(sender lcl.IObject, window *ICefWindow, aResult *bool) {
*aResult = wp.EnableHideCaption
})
m.windowComponent.SetAlwaysOnTop(wp.AlwaysOnTop)
m.windowComponent.SetBounds(NewCefRect(wp.X, wp.Y, wp.Width, wp.Height))
m.WindowComponent().SetAlwaysOnTop(wp.AlwaysOnTop)
m.WindowComponent().SetBounds(NewCefRect(wp.X, wp.Y, wp.Width, wp.Height))
}
// registerDefaultEvent 注册默认事件
......@@ -257,13 +258,13 @@ func (m *ViewsFrameworkBrowserWindow) registerDefaultEvent() {
var bwEvent = BrowserWindow.browserEvent
//默认自定义快捷键
defaultAcceleratorCustom()
m.chromium.SetOnProcessMessageReceived(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, sourceProcess consts.CefProcessId, message *ICefProcessMessage) bool {
m.Chromium().SetOnProcessMessageReceived(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, sourceProcess consts.CefProcessId, message *ICefProcessMessage) bool {
if bwEvent.onProcessMessageReceived != nil {
return bwEvent.onProcessMessageReceived(sender, browser, frame, sourceProcess, message, m)
}
return false
})
m.chromium.SetOnBeforeResourceLoad(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, request *ICefRequest, callback *ICefCallback, result *consts.TCefReturnValue) {
m.Chromium().SetOnBeforeResourceLoad(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, request *ICefRequest, callback *ICefCallback, result *consts.TCefReturnValue) {
if assetserve.AssetsServerHeaderKeyValue != "" {
request.SetHeaderByName(assetserve.AssetsServerHeaderKeyName, assetserve.AssetsServerHeaderKeyValue, true)
}
......@@ -271,14 +272,14 @@ func (m *ViewsFrameworkBrowserWindow) registerDefaultEvent() {
bwEvent.onBeforeResourceLoad(sender, browser, frame, request, callback, result, m)
}
})
m.chromium.SetOnBeforeDownload(func(sender lcl.IObject, browser *ICefBrowser, beforeDownloadItem *ICefDownloadItem, suggestedName string, callback *ICefBeforeDownloadCallback) {
m.Chromium().SetOnBeforeDownload(func(sender lcl.IObject, browser *ICefBrowser, beforeDownloadItem *ICefDownloadItem, suggestedName string, callback *ICefBeforeDownloadCallback) {
if bwEvent.onBeforeDownload != nil {
bwEvent.onBeforeDownload(sender, browser, beforeDownloadItem, suggestedName, callback, m)
} else {
callback.Cont(consts.ExePath+consts.Separator+suggestedName, true)
}
})
m.chromium.SetOnBeforeContextMenu(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, params *ICefContextMenuParams, model *ICefMenuModel) {
m.Chromium().SetOnBeforeContextMenu(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, params *ICefContextMenuParams, model *ICefMenuModel) {
var flag bool
if bwEvent.onBeforeContextMenu != nil {
flag = bwEvent.onBeforeContextMenu(sender, browser, frame, params, model, m)
......@@ -287,7 +288,7 @@ func (m *ViewsFrameworkBrowserWindow) registerDefaultEvent() {
chromiumOnBeforeContextMenu(m, browser, frame, params, model)
}
})
m.chromium.SetOnContextMenuCommand(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, params *ICefContextMenuParams, commandId consts.MenuId, eventFlags uint32) bool {
m.Chromium().SetOnContextMenuCommand(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, params *ICefContextMenuParams, commandId consts.MenuId, eventFlags uint32) bool {
var result bool
if bwEvent.onContextMenuCommand != nil {
result = bwEvent.onContextMenuCommand(sender, browser, frame, params, commandId, eventFlags, m)
......@@ -297,7 +298,7 @@ func (m *ViewsFrameworkBrowserWindow) registerDefaultEvent() {
}
return result
})
m.chromium.SetOnAfterCreated(func(sender lcl.IObject, browser *ICefBrowser) {
m.Chromium().SetOnAfterCreated(func(sender lcl.IObject, browser *ICefBrowser) {
var flag bool
if bwEvent.onAfterCreated != nil {
flag = bwEvent.onAfterCreated(sender, browser, m)
......@@ -306,7 +307,7 @@ func (m *ViewsFrameworkBrowserWindow) registerDefaultEvent() {
chromiumOnAfterCreate(m, browser)
}
})
m.chromium.SetOnKeyEvent(func(sender lcl.IObject, browser *ICefBrowser, event *TCefKeyEvent, osEvent *consts.TCefEventHandle, result *bool) {
m.Chromium().SetOnKeyEvent(func(sender lcl.IObject, browser *ICefBrowser, event *TCefKeyEvent, osEvent *consts.TCefEventHandle, result *bool) {
if bwEvent.onKeyEvent != nil {
bwEvent.onKeyEvent(sender, browser, event, osEvent, m, result)
}
......@@ -327,36 +328,36 @@ func (m *ViewsFrameworkBrowserWindow) registerDefaultEvent() {
}
}
})
m.chromium.SetOnBeforeBrowser(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, request *ICefRequest, userGesture, isRedirect bool) bool {
m.Chromium().SetOnBeforeBrowser(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, request *ICefRequest, userGesture, isRedirect bool) bool {
chromiumOnBeforeBrowser(m, browser, frame, request) // default impl
if bwEvent.onBeforeBrowser != nil {
return bwEvent.onBeforeBrowser(sender, browser, frame, request, userGesture, isRedirect, m)
}
return false
})
m.chromium.SetOnTitleChange(func(sender lcl.IObject, browser *ICefBrowser, title string) {
m.Chromium().SetOnTitleChange(func(sender lcl.IObject, browser *ICefBrowser, title string) {
if bwEvent.onTitleChange != nil {
bwEvent.onTitleChange(sender, browser, title, m)
}
})
m.chromium.SetOnDragEnter(func(sender lcl.IObject, browser *ICefBrowser, dragData *ICefDragData, mask consts.TCefDragOperations, result *bool) {
m.Chromium().SetOnDragEnter(func(sender lcl.IObject, browser *ICefBrowser, dragData *ICefDragData, mask consts.TCefDragOperations, result *bool) {
*result = !m.WindowProperty().EnableDragFile
if bwEvent.onDragEnter != nil {
bwEvent.onDragEnter(sender, browser, dragData, mask, m, result)
}
})
m.chromium.SetOnLoadEnd(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, httpStatusCode int32) {
m.Chromium().SetOnLoadEnd(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, httpStatusCode int32) {
if bwEvent.onLoadEnd != nil {
bwEvent.onLoadEnd(sender, browser, frame, httpStatusCode, m)
}
})
if m.WindowProperty().EnableWebkitAppRegion {
m.chromium.SetOnDraggableRegionsChanged(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, regions *TCefDraggableRegions) {
m.Chromium().SetOnDraggableRegionsChanged(func(sender lcl.IObject, browser *ICefBrowser, frame *ICefFrame, regions *TCefDraggableRegions) {
if bwEvent.onDraggableRegionsChanged != nil {
bwEvent.onDraggableRegionsChanged(sender, browser, frame, regions, m)
}
m.regions = regions
m.windowComponent.SetDraggableRegions(regions.Regions())
m.WindowComponent().SetDraggableRegions(regions.Regions())
})
}
if localLoadRes.enable() {
......@@ -373,6 +374,11 @@ func (m *ViewsFrameworkBrowserWindow) registerDefaultEvent() {
}
}
// Created 窗口是否创建完, m.CreateTopLevelWindow() 之后
func (m *ViewsFrameworkBrowserWindow) Created() bool {
return m.created
}
// EnableAllDefaultEvent 启用所有默认事件行为
func (m *ViewsFrameworkBrowserWindow) EnableAllDefaultEvent() {
m.registerPopupEvent(false)
......@@ -434,41 +440,56 @@ func (m *ViewsFrameworkBrowserWindow) AsLCLBrowserWindow() ILCLBrowserWindow {
// SetTitle 设置窗口标题
func (m *ViewsFrameworkBrowserWindow) SetTitle(title string) {
m.WindowProperty().Title = title
m.WindowComponent().SetTitle(title)
}
// SetWidth 设置窗口宽
func (m *ViewsFrameworkBrowserWindow) SetWidth(value int32) {
m.WindowProperty().Width = value
size := m.Size()
if size != nil {
m.SetSize(value, size.Height)
}
}
// SetHeight 设置窗口高
func (m *ViewsFrameworkBrowserWindow) SetHeight(value int32) {
m.WindowProperty().Height = value
size := m.Size()
if size != nil {
m.SetSize(size.Width, value)
}
}
// Point 返回窗口坐标
func (m *ViewsFrameworkBrowserWindow) Point() *TCefPoint {
result := m.WindowComponent().Position()
m.WindowProperty().X = result.X
m.WindowProperty().Y = result.Y
if result != nil {
m.WindowProperty().X = result.X
m.WindowProperty().Y = result.Y
}
return result
}
// Size 返回窗口宽高
func (m *ViewsFrameworkBrowserWindow) Size() *TCefSize {
result := m.WindowComponent().Size()
m.WindowProperty().Width = result.Width
m.WindowProperty().Height = result.Height
if result != nil {
m.WindowProperty().Width = result.Width
m.WindowProperty().Height = result.Height
}
return result
}
// Bounds 返回窗口坐标和宽高
func (m *ViewsFrameworkBrowserWindow) Bounds() *TCefRect {
result := m.WindowComponent().Bounds()
m.WindowProperty().X = result.X
m.WindowProperty().Y = result.Y
m.WindowProperty().Width = result.Width
m.WindowProperty().Height = result.Height
if result != nil {
m.WindowProperty().X = result.X
m.WindowProperty().Y = result.Y
m.WindowProperty().Width = result.Width
m.WindowProperty().Height = result.Height
}
return result
}
......@@ -476,12 +497,14 @@ func (m *ViewsFrameworkBrowserWindow) Bounds() *TCefRect {
func (m *ViewsFrameworkBrowserWindow) SetPoint(x, y int32) {
m.WindowProperty().X = x
m.WindowProperty().Y = y
m.WindowComponent().SetPosition(&TCefPoint{X: x, Y: y})
}
// SetSize 设置窗口宽高
func (m *ViewsFrameworkBrowserWindow) SetSize(width, height int32) {
m.WindowProperty().Width = width
m.WindowProperty().Height = height
m.WindowComponent().SetSize(&TCefSize{Width: width, Height: height})
}
// SetBounds 设置窗口坐标和宽高
......@@ -490,6 +513,8 @@ func (m *ViewsFrameworkBrowserWindow) SetBounds(x, y, width, height int32) {
m.WindowProperty().Y = y
m.WindowProperty().Width = width
m.WindowProperty().Height = height
m.SetPoint(x, y)
m.SetSize(width, height)
}
// getAuxTools 获取辅助工具-开发者工具
......@@ -524,7 +549,11 @@ func (m *ViewsFrameworkBrowserWindow) Id() int32 {
// Show 显示窗口
func (m *ViewsFrameworkBrowserWindow) Show() {
m.WindowComponent().Show()
if m.Created() {
m.WindowComponent().Show()
} else {
m.CreateTopLevelWindow()
}
}
// Hide 隐藏窗口
......@@ -539,11 +568,11 @@ func (m *ViewsFrameworkBrowserWindow) Close() {
// WindowState 返回窗口最小化、最大化、全屏状态
func (m *ViewsFrameworkBrowserWindow) WindowState() types.TWindowState {
if m.windowComponent.IsMinimized() {
if m.WindowComponent().IsMinimized() {
return types.WsMinimized
} else if m.windowComponent.IsMaximized() {
} else if m.WindowComponent().IsMaximized() {
return types.WsMaximized
} else if m.windowComponent.IsFullscreen() {
} else if m.WindowComponent().IsFullscreen() {
return types.WsFullScreen
}
return types.WsNormal
......@@ -583,7 +612,7 @@ func (m *ViewsFrameworkBrowserWindow) Restore() {
// CloseBrowserWindow 关闭浏览器窗口
func (m *ViewsFrameworkBrowserWindow) CloseBrowserWindow() {
m.isClosing = true
m.chromium.CloseBrowser(true)
m.Chromium().CloseBrowser(true)
}
// CreateTopLevelWindow 创建顶层窗口
......@@ -592,6 +621,7 @@ func (m *ViewsFrameworkBrowserWindow) CreateTopLevelWindow() {
window.CurrentBrowseWindowCache = m
}
m.WindowComponent().CreateTopLevelWindow()
m.created = true
}
// CenterWindow 设置窗口居中,同时指定窗口大小
......@@ -602,6 +632,7 @@ func (m *ViewsFrameworkBrowserWindow) CenterWindow(size *TCefSize) {
// SetCenterWindow 设置窗口居中显示
func (m *ViewsFrameworkBrowserWindow) SetCenterWindow(value bool) {
m.WindowProperty().EnableCenterWindow = value
m.CenterWindow(m.Size())
}
// IsClosing 返回窗口是否正在关闭/或已关闭 true正在或已关闭
......
......@@ -198,3 +198,22 @@ func (m *auxTools) SetDevTools(devToolsWindow *devToolsWindow) {
func (m *auxTools) DevTools() *devToolsWindow {
return m.devToolsWindow
}
// NewBrowserWindow
// 创建浏览器窗口
// 根据当前主窗口类型创建
// 窗口类型
// LCL: 是基于LCL组件库创建的窗口,相比VF有多更的原生小部件使用,更多的窗口操作
// VF : 是基于CEF ViewFramework 组件创建的窗口, 相比LCL无法使用系统原生小部件,较少的窗口操作
func NewBrowserWindow(config *TCefChromiumConfig, windowProperty WindowProperty, owner ...lcl.IComponent) IBrowserWindow {
// 获取当前应用的主窗口
main := BrowserWindow.MainWindow()
if main.IsLCL() {
// 创建LCL窗口
return NewLCLBrowserWindow(config, windowProperty, owner...)
} else if main.IsViewsFramework() {
// 创建VF窗口
return NewViewsFrameworkBrowserWindow(config, windowProperty, owner...)
}
return nil
}
......@@ -437,71 +437,71 @@ func (m *TCEFViewComponent) GetHeightForWidth(width int32) int32 {
}
func (m *TCEFViewComponent) SetOnGetPreferredSize(fn onGetPreferredSize) {
if !m.IsValid() {
return
}
//if !m.IsValid() {
// return
//}
imports.Proc(def.ViewComponent_SetOnGetPreferredSize).Call(m.Instance(), api.MakeEventDataPtr(fn))
}
func (m *TCEFViewComponent) SetOnGetMinimumSize(fn onGetMinimumSize) {
if !m.IsValid() {
return
}
//if !m.IsValid() {
// return
//}
imports.Proc(def.ViewComponent_SetOnGetMinimumSize).Call(m.Instance(), api.MakeEventDataPtr(fn))
}
func (m *TCEFViewComponent) SetOnGetMaximumSize(fn onGetMaximumSize) {
if !m.IsValid() {
return
}
//if !m.IsValid() {
// return
//}
imports.Proc(def.ViewComponent_SetOnGetMaximumSize).Call(m.Instance(), api.MakeEventDataPtr(fn))
}
func (m *TCEFViewComponent) SetOnGetHeightForWidth(fn onGetHeightForWidth) {
if !m.IsValid() {
return
}
//if !m.IsValid() {
// return
//}
imports.Proc(def.ViewComponent_SetOnGetHeightForWidth).Call(m.Instance(), api.MakeEventDataPtr(fn))
}
func (m *TCEFViewComponent) SetOnParentViewChanged(fn onParentViewChanged) {
if !m.IsValid() {
return
}
//if !m.IsValid() {
// return
//}
imports.Proc(def.ViewComponent_SetOnParentViewChanged).Call(m.Instance(), api.MakeEventDataPtr(fn))
}
func (m *TCEFViewComponent) SetOnChildViewChanged(fn onChildViewChanged) {
if !m.IsValid() {
return
}
//if !m.IsValid() {
// return
//}
imports.Proc(def.ViewComponent_SetOnChildViewChanged).Call(m.Instance(), api.MakeEventDataPtr(fn))
}
func (m *TCEFViewComponent) SetOnWindowChanged(fn onWindowChanged) {
if !m.IsValid() {
return
}
//if !m.IsValid() {
// return
//}
imports.Proc(def.ViewComponent_SetOnWindowChanged).Call(m.Instance(), api.MakeEventDataPtr(fn))
}
func (m *TCEFViewComponent) SetOnLayoutChanged(fn onLayoutChanged) {
if !m.IsValid() {
return
}
//if !m.IsValid() {
// return
//}
imports.Proc(def.ViewComponent_SetOnLayoutChanged).Call(m.Instance(), api.MakeEventDataPtr(fn))
}
func (m *TCEFViewComponent) SetOnFocus(fn onFocus) {
if !m.IsValid() {
return
}
//if !m.IsValid() {
// return
//}
imports.Proc(def.ViewComponent_SetOnFocus).Call(m.Instance(), api.MakeEventDataPtr(fn))
}
func (m *TCEFViewComponent) SetOnBlur(fn onBlur) {
if !m.IsValid() {
return
}
//if !m.IsValid() {
// return
//}
imports.Proc(def.ViewComponent_SetOnBlur).Call(m.Instance(), api.MakeEventDataPtr(fn))
}
......@@ -45,51 +45,81 @@ func (m *TCEFWindowComponent) CreateTopLevelWindow() {
// Show 显示窗口
func (m *TCEFWindowComponent) Show() {
if !m.IsValid() {
return
}
imports.Proc(def.CEFWindowComponent_Show).Call(m.Instance())
}
// Hide 显示窗口
func (m *TCEFWindowComponent) Hide() {
if !m.IsValid() {
return
}
imports.Proc(def.CEFWindowComponent_Hide).Call(m.Instance())
}
// CenterWindow 根据大小窗口居中
func (m *TCEFWindowComponent) CenterWindow(size *TCefSize) {
if !m.IsValid() {
return
}
imports.Proc(def.CEFWindowComponent_CenterWindow).Call(m.Instance(), uintptr(unsafe.Pointer(size)))
}
// Close 关闭窗口, 主窗口调用
func (m *TCEFWindowComponent) Close() {
if !m.IsValid() {
return
}
imports.Proc(def.CEFWindowComponent_Close).Call(m.Instance())
}
// Activate 激活窗口
func (m *TCEFWindowComponent) Activate() {
if !m.IsValid() {
return
}
imports.Proc(def.CEFWindowComponent_Activate).Call(m.Instance())
}
// Deactivate 停止激活窗口
func (m *TCEFWindowComponent) Deactivate() {
if !m.IsValid() {
return
}
imports.Proc(def.CEFWindowComponent_Deactivate).Call(m.Instance())
}
// BringToTop 将窗口移至最上层
func (m *TCEFWindowComponent) BringToTop() {
if !m.IsValid() {
return
}
imports.Proc(def.CEFWindowComponent_BringToTop).Call(m.Instance())
}
// Maximize 最大化窗口
func (m *TCEFWindowComponent) Maximize() {
if !m.IsValid() {
return
}
imports.Proc(def.CEFWindowComponent_Maximize).Call(m.Instance())
}
// Minimize 最小化窗口
func (m *TCEFWindowComponent) Minimize() {
if !m.IsValid() {
return
}
imports.Proc(def.CEFWindowComponent_Minimize).Call(m.Instance())
}
// Restore 窗口还原
func (m *TCEFWindowComponent) Restore() {
if !m.IsValid() {
return
}
imports.Proc(def.CEFWindowComponent_Restore).Call(m.Instance())
}
......@@ -99,110 +129,173 @@ func (m *TCEFWindowComponent) Restore() {
// ShowMenu 显示菜单
func (m *TCEFWindowComponent) ShowMenu(menuModel *ICefMenuModel, point TCefPoint, anchorPosition consts.TCefMenuAnchorPosition) {
if !m.IsValid() {
return
}
imports.Proc(def.CEFWindowComponent_ShowMenu).Call(m.Instance(), uintptr(menuModel.instance), uintptr(unsafe.Pointer(&point)), uintptr(anchorPosition))
}
// CancelMenu 取消菜单
func (m *TCEFWindowComponent) CancelMenu() {
if !m.IsValid() {
return
}
imports.Proc(def.CEFWindowComponent_CancelMenu).Call(m.Instance())
}
// SetDraggableRegions 设置拖拽区域
func (m *TCEFWindowComponent) SetDraggableRegions(regions []TCefDraggableRegion) {
if !m.IsValid() {
return
}
imports.Proc(def.CEFWindowComponent_SetDraggableRegions).Call(m.Instance(), uintptr(int32(len(regions))), uintptr(unsafe.Pointer(&regions[0])), uintptr(int32(len(regions))))
}
// SendKeyPress 发送键盘事件
func (m *TCEFWindowComponent) SendKeyPress(keyCode int32, eventFlags uint32) {
if !m.IsValid() {
return
}
imports.Proc(def.CEFWindowComponent_SendKeyPress).Call(m.Instance(), uintptr(keyCode), uintptr(eventFlags))
}
// SendMouseMove 发送鼠标移动事件
func (m *TCEFWindowComponent) SendMouseMove(screenX, screenY int32) {
if !m.IsValid() {
return
}
imports.Proc(def.CEFWindowComponent_SendMouseMove).Call(m.Instance(), uintptr(screenX), uintptr(screenY))
}
// SendMouseEvents 发送鼠标事件
func (m *TCEFWindowComponent) SendMouseEvents(button consts.TCefMouseButtonType, mouseDown, mouseUp bool) {
if !m.IsValid() {
return
}
imports.Proc(def.CEFWindowComponent_SendMouseEvents).Call(m.Instance(), uintptr(button), api.PascalBool(mouseDown), api.PascalBool(mouseUp))
}
// SetAccelerator 设置快捷键
func (m *TCEFWindowComponent) SetAccelerator(commandId, keyCode int32, shiftPressed, ctrlPressed, altPressed bool) {
if !m.IsValid() {
return
}
imports.Proc(def.CEFWindowComponent_SetAccelerator).Call(m.Instance(), uintptr(commandId), uintptr(keyCode), api.PascalBool(shiftPressed), api.PascalBool(ctrlPressed), api.PascalBool(altPressed))
}
// RemoveAccelerator 移除指定快捷键
func (m *TCEFWindowComponent) RemoveAccelerator(commandId int32) {
if !m.IsValid() {
return
}
imports.Proc(def.CEFWindowComponent_RemoveAccelerator).Call(m.Instance(), uintptr(commandId))
}
// RemoveAllAccelerators 移除所有快捷键
func (m *TCEFWindowComponent) RemoveAllAccelerators() {
if !m.IsValid() {
return
}
imports.Proc(def.CEFWindowComponent_RemoveAllAccelerators).Call(m.Instance())
}
// SetAlwaysOnTop 设置窗口是否置顶
func (m *TCEFWindowComponent) SetAlwaysOnTop(onTop bool) {
if !m.IsValid() {
return
}
imports.Proc(def.CEFWindowComponent_SetAlwaysOnTop).Call(m.Instance(), api.PascalBool(onTop))
}
// SetFullscreen 设置窗口全屏
func (m *TCEFWindowComponent) SetFullscreen(fullscreen bool) {
if !m.IsValid() {
return
}
imports.Proc(def.CEFWindowComponent_SetFullscreen).Call(m.Instance(), api.PascalBool(fullscreen))
}
// SetBackgroundColor 设置背景色
func (m *TCEFWindowComponent) SetBackgroundColor(rect types.TCefColor) {
if !m.IsValid() {
return
}
imports.Proc(def.CEFWindowComponent_SetBackgroundColor).Call(m.Instance(), rect.ToPtr())
}
// SetBounds 获取窗口边界
// Bounds 获取窗口边界
func (m *TCEFWindowComponent) Bounds() (result *TCefRect) {
if !m.IsValid() {
return nil
}
imports.Proc(def.CEFWindowComponent_Bounds).Call(m.Instance(), uintptr(unsafe.Pointer(result)))
return
}
// SetSize 获取窗口宽高
// Size 获取窗口宽高
func (m *TCEFWindowComponent) Size() (result *TCefSize) {
if !m.IsValid() {
return nil
}
imports.Proc(def.CEFWindowComponent_Size).Call(m.Instance(), uintptr(unsafe.Pointer(result)))
return
}
// Position 获取窗口位置
func (m *TCEFWindowComponent) Position() (result *TCefPoint) {
if !m.IsValid() {
return nil
}
imports.Proc(def.CEFWindowComponent_Position).Call(m.Instance(), uintptr(unsafe.Pointer(result)))
return
}
// SetBounds 设置窗口边界
func (m *TCEFWindowComponent) SetBounds(rect *TCefRect) {
if !m.IsValid() {
return
}
imports.Proc(def.CEFWindowComponent_SetBounds).Call(m.Instance(), uintptr(unsafe.Pointer(rect)))
}
// SetSize 设置窗口宽高
func (m *TCEFWindowComponent) SetSize(size *TCefSize) {
if !m.IsValid() {
return
}
imports.Proc(def.CEFWindowComponent_SetSize).Call(m.Instance(), uintptr(unsafe.Pointer(size)))
}
// SetPosition 设置窗口位置
func (m *TCEFWindowComponent) SetPosition(point *TCefPoint) {
if !m.IsValid() {
return
}
imports.Proc(def.CEFWindowComponent_SetPosition).Call(m.Instance(), uintptr(unsafe.Pointer(point)))
}
// SetTitle 设置窗口标题
func (m *TCEFWindowComponent) SetTitle(title string) {
if !m.IsValid() {
return
}
imports.Proc(def.CEFWindowComponent_SetTitle).Call(m.Instance(), api.PascalStr(title))
}
// GetTitle 获取窗口标题
// Title 获取窗口标题
func (m *TCEFWindowComponent) Title() string {
if !m.IsValid() {
return ""
}
r1, _, _ := imports.Proc(def.CEFWindowComponent_Title).Call(m.Instance())
return api.GoStr(r1)
}
// WindowIcon 获取窗口图标
func (m *TCEFWindowComponent) WindowIcon() *ICefImage {
if !m.IsValid() {
return nil
}
var result uintptr
imports.Proc(def.CEFWindowComponent_WindowIcon).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
return &ICefImage{
......@@ -212,6 +305,9 @@ func (m *TCEFWindowComponent) WindowIcon() *ICefImage {
// WindowAppIcon 获取窗口应用图标
func (m *TCEFWindowComponent) WindowAppIcon() *ICefImage {
if !m.IsValid() {
return nil
}
var result uintptr
imports.Proc(def.CEFWindowComponent_WindowAppIcon).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
return &ICefImage{
......@@ -220,20 +316,28 @@ func (m *TCEFWindowComponent) WindowAppIcon() *ICefImage {
}
func (m *TCEFWindowComponent) SetWindowIcon(icon *ICefImage) {
if !m.IsValid() {
return
}
imports.Proc(def.CEFWindowComponent_SetWindowIcon).Call(m.Instance(), icon.Instance())
}
func (m *TCEFWindowComponent) checkICON(filename string) (string, error) {
if !m.IsValid() {
return "", errors.New("window component is nil")
}
ext := strings.ToLower(filepath.Ext(filename))
if ".png" != ext && ".jpeg" != ext {
return "", errors.New("only png and jpeg image formats are supported")
}
ext = ext[1:]
return ext, nil
return ext[1:], nil
}
// SetWindowIconByFile 设置窗口图标
func (m *TCEFWindowComponent) SetWindowIconByFile(scaleFactor float32, filename string) error {
if !m.IsValid() {
return errors.New("window component is nil")
}
var (
ext string
err error
......@@ -257,6 +361,9 @@ func (m *TCEFWindowComponent) SetWindowIconByFile(scaleFactor float32, filename
// SetWindowIconByFSFile 设置窗口图标
func (m *TCEFWindowComponent) SetWindowIconByFSFile(scaleFactor float32, filename string) error {
if !m.IsValid() {
return errors.New("window component is nil")
}
var (
ext string
err error
......@@ -279,11 +386,17 @@ func (m *TCEFWindowComponent) SetWindowIconByFSFile(scaleFactor float32, filenam
}
func (m *TCEFWindowComponent) SetWindowAppIcon(icon *ICefImage) {
if !m.IsValid() {
return
}
imports.Proc(def.CEFWindowComponent_SetWindowAppIcon).Call(m.Instance(), icon.Instance())
}
// SetWindowAppIconByFile 设置窗口应用图标
func (m *TCEFWindowComponent) SetWindowAppIconByFile(scaleFactor float32, filename string) error {
if !m.IsValid() {
return errors.New("window component is nil")
}
var (
ext string
err error
......@@ -307,6 +420,9 @@ func (m *TCEFWindowComponent) SetWindowAppIconByFile(scaleFactor float32, filena
// SetWindowAppIconByFSFile 设置窗口应用图标
func (m *TCEFWindowComponent) SetWindowAppIconByFSFile(scaleFactor float32, filename string) error {
if !m.IsValid() {
return errors.New("window component is nil")
}
var (
ext string
err error
......@@ -330,6 +446,9 @@ func (m *TCEFWindowComponent) SetWindowAppIconByFSFile(scaleFactor float32, file
// Display
func (m *TCEFWindowComponent) Display() *ICefDisplay {
if !m.IsValid() {
return nil
}
var result uintptr
imports.Proc(def.CEFWindowComponent_Display).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
return &ICefDisplay{
......@@ -339,54 +458,81 @@ func (m *TCEFWindowComponent) Display() *ICefDisplay {
// ClientAreaBoundsInScreen 获取客户端所在指定屏幕位置
func (m *TCEFWindowComponent) ClientAreaBoundsInScreen() (result TCefRect) {
if !m.IsValid() {
return
}
imports.Proc(def.CEFWindowComponent_ClientAreaBoundsInScreen).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
return
}
// WindowHandle 获取窗口句柄
func (m *TCEFWindowComponent) WindowHandle() consts.TCefWindowHandle {
if !m.IsValid() {
return 0
}
r1, _, _ := imports.Proc(def.CEFWindowComponent_WindowHandle).Call(m.Instance())
return consts.TCefWindowHandle(r1)
}
// IsClosed 是否关闭
func (m *TCEFWindowComponent) IsClosed() bool {
if !m.IsValid() {
return false
}
r1, _, _ := imports.Proc(def.CEFWindowComponent_IsClosed).Call(m.Instance())
return api.GoBool(r1)
}
// IsActive 是否激活
func (m *TCEFWindowComponent) IsActive() bool {
if !m.IsValid() {
return false
}
r1, _, _ := imports.Proc(def.CEFWindowComponent_IsActive).Call(m.Instance())
return api.GoBool(r1)
}
// IsAlwaysOnTop 窗口是否置顶
func (m *TCEFWindowComponent) IsAlwaysOnTop() bool {
if !m.IsValid() {
return false
}
r1, _, _ := imports.Proc(def.CEFWindowComponent_IsAlwaysOnTop).Call(m.Instance())
return api.GoBool(r1)
}
// IsFullscreen 是否全屏
func (m *TCEFWindowComponent) IsFullscreen() bool {
if !m.IsValid() {
return false
}
r1, _, _ := imports.Proc(def.CEFWindowComponent_IsFullscreen).Call(m.Instance())
return api.GoBool(r1)
}
// IsMaximized 是否最大化
func (m *TCEFWindowComponent) IsMaximized() bool {
if !m.IsValid() {
return false
}
r1, _, _ := imports.Proc(def.CEFWindowComponent_IsMaximized).Call(m.Instance())
return api.GoBool(r1)
}
// IsMinimized 是否最小化
func (m *TCEFWindowComponent) IsMinimized() bool {
if !m.IsValid() {
return false
}
r1, _, _ := imports.Proc(def.CEFWindowComponent_IsMinimized).Call(m.Instance())
return api.GoBool(r1)
}
// AddChildView 添加浏览器显示组件
func (m *TCEFWindowComponent) AddChildView(browserViewComponent *TCEFBrowserViewComponent) {
if !m.IsValid() {
return
}
imports.Proc(def.CEFWindowComponent_AddChildView).Call(m.Instance(), browserViewComponent.Instance())
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册