From ccc2c2f6eadcb672be381bda0c24b2f0b14e5805 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E7=BA=A2=E5=B2=A9?= Date: Mon, 3 Jul 2023 13:35:38 +0800 Subject: [PATCH] A: TCEFButtonComponent Event Proc --- cef/internal/def/proc-def-index.go | 10 +++ cef/internal/def/proc-def.go | 10 +++ cef/types-buttoncomponent.go | 118 +++++++++++++++++++++++++++++ cef/types.go | 11 +++ consts/consts.go | 10 +++ 5 files changed, 159 insertions(+) create mode 100644 cef/types-buttoncomponent.go diff --git a/cef/internal/def/proc-def-index.go b/cef/internal/def/proc-def-index.go index c0baf04f..da7629ec 100644 --- a/cef/internal/def/proc-def-index.go +++ b/cef/internal/def/proc-def-index.go @@ -2384,4 +2384,14 @@ const ( ViewComponent_SetOnLayoutChanged ViewComponent_SetOnFocus ViewComponent_SetOnBlur + // TCEFButtonComponent + ButtonComponent_Create + ButtonComponent_SetInkDropEnabled + ButtonComponent_SetTooltipText + ButtonComponent_SetAccessibleName + ButtonComponent_AsLabelButton + ButtonComponent_GetState + ButtonComponent_SetState + ButtonComponent_SetOnButtonPressed + ButtonComponent_SetOnButtonStateChanged ) //end diff --git a/cef/internal/def/proc-def.go b/cef/internal/def/proc-def.go index dec53be0..cb5140c7 100644 --- a/cef/internal/def/proc-def.go +++ b/cef/internal/def/proc-def.go @@ -2384,6 +2384,16 @@ func init() { dllimports.NewEnergyImport("ViewComponent_SetOnLayoutChanged", 0), dllimports.NewEnergyImport("ViewComponent_SetOnFocus", 0), dllimports.NewEnergyImport("ViewComponent_SetOnBlur", 0), + // TCEFButtonComponent + dllimports.NewEnergyImport("ButtonComponent_Create", 0), + dllimports.NewEnergyImport("ButtonComponent_SetInkDropEnabled", 0), + dllimports.NewEnergyImport("ButtonComponent_SetTooltipText", 0), + dllimports.NewEnergyImport("ButtonComponent_SetAccessibleName", 0), + dllimports.NewEnergyImport("ButtonComponent_AsLabelButton", 0), + dllimports.NewEnergyImport("ButtonComponent_GetState", 0), + dllimports.NewEnergyImport("ButtonComponent_SetState", 0), + dllimports.NewEnergyImport("ButtonComponent_SetOnButtonPressed", 0), + dllimports.NewEnergyImport("ButtonComponent_SetOnButtonStateChanged", 0), } //end imports.SetEnergyImportDefs(energyImportDefs) } diff --git a/cef/types-buttoncomponent.go b/cef/types-buttoncomponent.go new file mode 100644 index 00000000..0662c1ed --- /dev/null +++ b/cef/types-buttoncomponent.go @@ -0,0 +1,118 @@ +//---------------------------------------- +// +// Copyright © yanghy. All Rights Reserved. +// +// Licensed under Apache License Version 2.0, January 2004 +// +// https//www.apache.org/licenses/LICENSE-2.0 +// +//---------------------------------------- + +package cef + +import ( + "github.com/energye/energy/v2/cef/internal/def" + "github.com/energye/energy/v2/common/imports" + "github.com/energye/energy/v2/consts" + "github.com/energye/golcl/lcl" + "github.com/energye/golcl/lcl/api" + "unsafe" +) + +// ButtonComponentRef -> TCEFButtonComponent +var ButtonComponentRef buttonComponent + +type buttonComponent uintptr + +func (*buttonComponent) New(AOwner lcl.IComponent) *TCEFButtonComponent { + var result uintptr + imports.Proc(def.ButtonComponent_Create).Call(AOwner.Instance(), uintptr(unsafe.Pointer(&result))) + if result != 0 { + return &TCEFButtonComponent{&TCEFViewComponent{instance: getInstance(result)}} + } + return nil +} + +func (m *TCEFButtonComponent) SetInkDropEnabled(enabled bool) { + if !m.IsValid() { + return + } + imports.Proc(def.ButtonComponent_SetInkDropEnabled).Call(m.Instance(), api.PascalBool(enabled)) +} + +func (m *TCEFButtonComponent) SetTooltipText(tooltipText string) { + if !m.IsValid() { + return + } + imports.Proc(def.ButtonComponent_SetTooltipText).Call(m.Instance(), api.PascalStr(tooltipText)) +} + +func (m *TCEFButtonComponent) SetAccessibleName(name string) { + if !m.IsValid() { + return + } + imports.Proc(def.ButtonComponent_SetAccessibleName).Call(m.Instance(), api.PascalStr(name)) +} + +func (m *TCEFButtonComponent) AsLabelButton() *ICefLabelButton { + if !m.IsValid() { + return nil + } + var result uintptr + imports.Proc(def.ButtonComponent_AsLabelButton).Call(m.Instance(), uintptr(unsafe.Pointer(&result))) + if result != 0 { + return &ICefLabelButton{&ICefButton{&ICefView{instance: getInstance(result)}}} + } + return nil +} + +func (m *TCEFButtonComponent) GetState() consts.TCefButtonState { + if !m.IsValid() { + return 0 + } + r1, _, _ := imports.Proc(def.ButtonComponent_GetState).Call(m.Instance()) + return consts.TCefButtonState(r1) +} + +func (m *TCEFButtonComponent) SetState(state consts.TCefButtonState) { + if !m.IsValid() { + return + } + imports.Proc(def.ButtonComponent_SetState).Call(m.Instance(), uintptr(state)) +} + +func (m *TCEFButtonComponent) SetOnButtonPressed(fn onButtonPressed) { + if !m.IsValid() { + return + } + imports.Proc(def.ButtonComponent_SetOnButtonPressed).Call(m.Instance(), api.MakeEventDataPtr(fn)) +} + +func (m *TCEFButtonComponent) SetOnButtonStateChanged(fn onButtonStateChanged) { + if !m.IsValid() { + return + } + imports.Proc(def.ButtonComponent_SetOnButtonStateChanged).Call(m.Instance(), api.MakeEventDataPtr(fn)) +} + +type onButtonPressed func(sender lcl.IObject, button *ICefButton) +type onButtonStateChanged func(sender lcl.IObject, button *ICefButton) + +func init() { + lcl.RegisterExtEventCallback(func(fn interface{}, getVal func(idx int) uintptr) bool { + getPtr := func(i int) unsafe.Pointer { + return unsafe.Pointer(getVal(i)) + } + switch fn.(type) { + case onButtonPressed: + button := (*ICefButton)(getPtr(1)) + fn.(onButtonPressed)(lcl.AsObject(getPtr(0)), button) + case onButtonStateChanged: + button := (*ICefButton)(getPtr(1)) + fn.(onButtonStateChanged)(lcl.AsObject(getPtr(0)), button) + default: + return false + } + return true + }) +} diff --git a/cef/types.go b/cef/types.go index ece3b252..f1146a9e 100644 --- a/cef/types.go +++ b/cef/types.go @@ -486,6 +486,12 @@ type ICefButton struct { *ICefView } +// ICefLabelButton +// /include/capi/views/cef_label_button_capi.h (cef_label_button_t) +type ICefLabelButton struct { + *ICefButton +} + // ICefPanel // /include/capi/views/cef_panel_capi.h (cef_panel_t) type ICefPanel struct { @@ -523,6 +529,11 @@ type TCEFViewComponent struct { instance unsafe.Pointer } +// TCEFButtonComponent +type TCEFButtonComponent struct { + *TCEFViewComponent +} + // TCefX509CertificateArray // []ICefX509Certificate type TCefX509CertificateArray struct { diff --git a/consts/consts.go b/consts/consts.go index 2964b9b7..723c9298 100644 --- a/consts/consts.go +++ b/consts/consts.go @@ -1474,3 +1474,13 @@ const ( MENUITEMTYPE_SEPARATOR MENUITEMTYPE_SUBMENU ) + +// /include/internal/cef_types.h (cef_button_state_t) +type TCefButtonState = types.Int32 + +const ( + CEF_BUTTON_STATE_NORMAL TCefButtonState = iota + CEF_BUTTON_STATE_HOVERED + CEF_BUTTON_STATE_PRESSED + CEF_BUTTON_STATE_DISABLED +)