From 12acb7e1b0d20ef1e895df3a3af923da67fcdd26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E7=BA=A2=E5=B2=A9?= Date: Tue, 25 Jul 2023 16:59:40 +0800 Subject: [PATCH] A: displayRef proc api --- cef/internal/def/proc-def-index.go | 10 +++ cef/internal/def/proc-def.go | 10 +++ cef/types-display.go | 106 +++++++++++++++++++++++++++++ cef/types-x509-certificate.go | 4 +- cef/types.go | 8 +++ 5 files changed, 136 insertions(+), 2 deletions(-) diff --git a/cef/internal/def/proc-def-index.go b/cef/internal/def/proc-def-index.go index 6c02c336..e768ee6d 100644 --- a/cef/internal/def/proc-def-index.go +++ b/cef/internal/def/proc-def-index.go @@ -1206,6 +1206,16 @@ const ( CEFBrowserViewComponent_SetOnPopupBrowserViewCreated CEFBrowserViewComponent_SetOnGetChromeToolbarType // ICefDisplay + CEFDisplayRef_Primary + CEFDisplayRef_NearestPoint + CEFDisplayRef_MatchingBounds + CEFDisplayRef_GetCount + CEFDisplayRef_GetAlls + CEFDisplayRef_Get + CEFDisplayRef_ScreenPointToPixels + CEFDisplayRef_ScreenPointFromPixels + CEFDisplayRef_ScreenRectToPixels + CEFDisplayRef_ScreenRectFromPixels CEFDisplay_ID CEFDisplay_DeviceScaleFactor CEFDisplay_Rotation diff --git a/cef/internal/def/proc-def.go b/cef/internal/def/proc-def.go index 26f64aca..34addeb2 100644 --- a/cef/internal/def/proc-def.go +++ b/cef/internal/def/proc-def.go @@ -1206,6 +1206,16 @@ func init() { dllimports.NewEnergyImport("CEFBrowserViewComponent_SetOnPopupBrowserViewCreated", 0), dllimports.NewEnergyImport("CEFBrowserViewComponent_SetOnGetChromeToolbarType", 0), //ICefDisplay + dllimports.NewEnergyImport("CEFDisplayRef_Primary", 0), + dllimports.NewEnergyImport("CEFDisplayRef_NearestPoint", 0), + dllimports.NewEnergyImport("CEFDisplayRef_MatchingBounds", 0), + dllimports.NewEnergyImport("CEFDisplayRef_GetCount", 0), + dllimports.NewEnergyImport("CEFDisplayRef_GetAlls", 0), + dllimports.NewEnergyImport("CEFDisplayRef_Get", 0), + dllimports.NewEnergyImport("CEFDisplayRef_ScreenPointToPixels", 0), + dllimports.NewEnergyImport("CEFDisplayRef_ScreenPointFromPixels", 0), + dllimports.NewEnergyImport("CEFDisplayRef_ScreenRectToPixels", 0), + dllimports.NewEnergyImport("CEFDisplayRef_ScreenRectFromPixels", 0), dllimports.NewEnergyImport("CEFDisplay_ID", 0), dllimports.NewEnergyImport("CEFDisplay_DeviceScaleFactor", 0), dllimports.NewEnergyImport("CEFDisplay_Rotation", 0), diff --git a/cef/types-display.go b/cef/types-display.go index 871301f0..4b24dc18 100644 --- a/cef/types-display.go +++ b/cef/types-display.go @@ -13,9 +13,77 @@ package cef import ( "github.com/energye/energy/v2/cef/internal/def" "github.com/energye/energy/v2/common/imports" + "github.com/energye/golcl/lcl/api" + "github.com/energye/golcl/lcl/types" "unsafe" ) +// DisplayRef -> ICefDisplay +var DisplayRef display + +type display uintptr + +func (m *display) Primary() *ICefDisplay { + var result uintptr + imports.Proc(def.CEFDisplayRef_Primary).Call(uintptr(unsafe.Pointer(&result))) + if result != 0 { + return &ICefDisplay{instance: getInstance(result)} + } + return nil +} + +func (m *display) NearestPoint(point *TCefPoint, inputPixelCoords bool) *ICefDisplay { + var result uintptr + imports.Proc(def.CEFDisplayRef_NearestPoint).Call(uintptr(unsafe.Pointer(point)), api.PascalBool(inputPixelCoords), uintptr(unsafe.Pointer(&result))) + if result != 0 { + return &ICefDisplay{instance: getInstance(result)} + } + return nil +} + +func (m *display) MatchingBounds(point *TCefRect, inputPixelCoords bool) *ICefDisplay { + var result uintptr + imports.Proc(def.CEFDisplayRef_MatchingBounds).Call(uintptr(unsafe.Pointer(point)), api.PascalBool(inputPixelCoords), uintptr(unsafe.Pointer(&result))) + if result != 0 { + return &ICefDisplay{instance: getInstance(result)} + } + return nil +} + +func (m *display) GetCount() uint32 { + r1, _, _ := imports.Proc(def.CEFDisplayRef_GetCount).Call() + return uint32(r1) +} + +func (m *display) GetAlls() *ICefDisplayArray { + var result uintptr + r1, _, _ := imports.Proc(def.CEFDisplayRef_GetAlls).Call(uintptr(unsafe.Pointer(&result))) + if r1 != 0 && result != 0 { + return &ICefDisplayArray{instance: getInstance(result), count: m.GetCount()} + } + return nil +} + +func (m *display) ScreenPointToPixels(screenPoint *types.TPoint) (point types.TPoint) { + imports.Proc(def.CEFDisplayRef_ScreenPointToPixels).Call(uintptr(unsafe.Pointer(screenPoint)), uintptr(unsafe.Pointer(&point))) + return +} + +func (m *display) ScreenPointFromPixels(pixelsPoint *types.TPoint) (point types.TPoint) { + imports.Proc(def.CEFDisplayRef_ScreenPointFromPixels).Call(uintptr(unsafe.Pointer(pixelsPoint)), uintptr(unsafe.Pointer(&point))) + return +} + +func (m *display) ScreenRectToPixels(screenRect *types.TRect) (rect types.TRect) { + imports.Proc(def.CEFDisplayRef_ScreenRectToPixels).Call(uintptr(unsafe.Pointer(screenRect)), uintptr(unsafe.Pointer(&rect))) + return +} + +func (m *display) ScreenRectFromPixels(pixelsRect *types.TRect) (rect types.TRect) { + imports.Proc(def.CEFDisplayRef_ScreenRectFromPixels).Call(uintptr(unsafe.Pointer(pixelsRect)), uintptr(unsafe.Pointer(&rect))) + return +} + func (m *ICefDisplay) ID() (result int64) { if !m.IsValid() { return 0 @@ -74,3 +142,41 @@ func (m *ICefDisplay) IsValid() bool { } return m.instance != nil } + +func (m *ICefDisplayArray) Instance() uintptr { + return uintptr(m.instance) +} + +func (m *ICefDisplayArray) Free() { + if m.instance != nil { + m.instance = nil + } +} + +func (m *ICefDisplayArray) IsValid() bool { + if m == nil || m.instance == nil { + return false + } + return m.instance != nil +} + +func (m *ICefDisplayArray) Get(index uint32) *ICefDisplay { + if !m.IsValid() { + return nil + } + if index < m.count { + var result uintptr + r1, _, _ := imports.Proc(def.CEFDisplayRef_Get).Call(m.Instance(), uintptr(index), uintptr(unsafe.Pointer(&result))) + if r1 != 0 && result != 0 { + return &ICefDisplay{instance: getInstance(result)} + } + } + return nil +} + +func (m *ICefDisplayArray) Count() uint32 { + if !m.IsValid() { + return 0 + } + return m.count +} diff --git a/cef/types-x509-certificate.go b/cef/types-x509-certificate.go index 9a3d836c..62be9383 100644 --- a/cef/types-x509-certificate.go +++ b/cef/types-x509-certificate.go @@ -158,7 +158,7 @@ func (m *ICefX509Certificate) GetDEREncodedIssuerChain(chainCount uint32) *TCefB return nil } var result uintptr - imports.Proc(def.CefX509Certificate_GetDEREncodedIssuerChain).Call(m.Instance(), uintptr(unsafe.Pointer(&result))) + imports.Proc(def.CefX509Certificate_GetDEREncodedIssuerChain).Call(m.Instance(), uintptr(chainCount), uintptr(unsafe.Pointer(&result))) if result != 0 { return &TCefBinaryValueArray{count: chainCount, instance: unsafe.Pointer(result)} } @@ -170,7 +170,7 @@ func (m *ICefX509Certificate) GetPEMEncodedIssuerChain(chainCount uint32) *TCefB return nil } var result uintptr - imports.Proc(def.CefX509Certificate_GetPEMEncodedIssuerChain).Call(m.Instance(), uintptr(unsafe.Pointer(&result))) + imports.Proc(def.CefX509Certificate_GetPEMEncodedIssuerChain).Call(m.Instance(), uintptr(chainCount), uintptr(unsafe.Pointer(&result))) if result != 0 { return &TCefBinaryValueArray{count: chainCount, instance: unsafe.Pointer(result)} } diff --git a/cef/types.go b/cef/types.go index 0ec8e2eb..abc2fa32 100644 --- a/cef/types.go +++ b/cef/types.go @@ -345,6 +345,14 @@ type ICefDictionaryValue struct { listValues map[string]*ICefListValue } +// ICefDisplayArray +// []ICefDisplayArray +type ICefDisplayArray struct { + instance unsafe.Pointer + binaryValues []*ICefDisplayArray + count uint32 +} + // ICefDisplay type ICefDisplay struct { base TCefBaseRefCounted