-
Notifications
You must be signed in to change notification settings - Fork 23
/
types_print_handler.go
154 lines (135 loc) · 4.43 KB
/
types_print_handler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
//----------------------------------------
//
// 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/golcl/lcl"
"github.com/energye/golcl/lcl/api"
"unsafe"
)
// ************************** creates ************************** //
// PrintHandlerRef -> ICefPrintHandler
var PrintHandlerRef printSpanHandler
type printSpanHandler uintptr
func (*printSpanHandler) New() *ICefPrintHandler {
var result uintptr
imports.Proc(def.CefPrintHandlerRef_Create).Call(uintptr(unsafe.Pointer(&result)))
if result != 0 {
return &ICefPrintHandler{instance: unsafe.Pointer(result)}
}
return nil
}
// ************************** impl ************************** //
// Instance 实例
func (m *ICefPrintHandler) Instance() uintptr {
if m == nil {
return 0
}
return uintptr(m.instance)
}
func (m *ICefPrintHandler) Free() {
if m.instance != nil {
m.base.Free(m.Instance())
m.instance = nil
}
}
func (m *ICefPrintHandler) IsValid() bool {
if m == nil || m.instance == nil {
return false
}
return m.instance != nil
}
func (m *ICefPrintHandler) SetOnPrintStart(fn onPrintStart) {
if !m.IsValid() {
return
}
imports.Proc(def.CefPrintHandler_OnPrintStart).Call(m.Instance(), api.MakeEventDataPtr(fn))
}
func (m *ICefPrintHandler) SetOnPrintSettings(fn onPrintSettings) {
if !m.IsValid() {
return
}
imports.Proc(def.CefPrintHandler_OnPrintSettings).Call(m.Instance(), api.MakeEventDataPtr(fn))
}
func (m *ICefPrintHandler) SetOnPrintDialog(fn onPrintDialog) {
if !m.IsValid() {
return
}
imports.Proc(def.CefPrintHandler_OnPrintDialog).Call(m.Instance(), api.MakeEventDataPtr(fn))
}
func (m *ICefPrintHandler) SetOnPrintJob(fn onPrintJob) {
if !m.IsValid() {
return
}
imports.Proc(def.CefPrintHandler_OnPrintJob).Call(m.Instance(), api.MakeEventDataPtr(fn))
}
func (m *ICefPrintHandler) SetOnPrintReset(fn onPrintReset) {
if !m.IsValid() {
return
}
imports.Proc(def.CefPrintHandler_OnPrintReset).Call(m.Instance(), api.MakeEventDataPtr(fn))
}
func (m *ICefPrintHandler) SetGetPDFPaperSize(fn getPDFPaperSize) {
if !m.IsValid() {
return
}
imports.Proc(def.CefPrintHandler_GetPDFPaperSize).Call(m.Instance(), api.MakeEventDataPtr(fn))
}
// ************************** events ************************** //
type onPrintStart func(browser *ICefBrowser)
type onPrintSettings func(browser *ICefBrowser, settings *ICefPrintSettings, getDefaults bool)
type onPrintDialog func(browser *ICefBrowser, hasSelection bool, callback *ICefPrintDialogCallback) bool
type onPrintJob func(browser *ICefBrowser, documentName, PDFFilePath string, callback *ICefPrintJobCallback) bool
type onPrintReset func(browser *ICefBrowser)
type getPDFPaperSize func(browser *ICefBrowser, deviceUnitsPerInch int32) *TCefSize
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 onPrintStart:
browse := &ICefBrowser{instance: getPtr(0)}
fn.(onPrintStart)(browse)
case onPrintSettings:
browse := &ICefBrowser{instance: getPtr(0)}
settings := &ICefPrintSettings{instance: getPtr(1)}
getDefaults := api.GoBool(getVal(2))
fn.(onPrintSettings)(browse, settings, getDefaults)
case onPrintDialog:
browse := &ICefBrowser{instance: getPtr(0)}
hasSelection := api.GoBool(getVal(1))
callback := &ICefPrintDialogCallback{instance: getPtr(2)}
result := (*bool)(getPtr(3))
*result = fn.(onPrintDialog)(browse, hasSelection, callback)
case onPrintJob:
browse := &ICefBrowser{instance: getPtr(0)}
documentName, PDFFilePath := api.GoStr(getVal(1)), api.GoStr(getVal(2))
callback := &ICefPrintJobCallback{instance: getPtr(3)}
result := (*bool)(getPtr(4))
*result = fn.(onPrintJob)(browse, documentName, PDFFilePath, callback)
case onPrintReset:
browse := &ICefBrowser{instance: getPtr(0)}
fn.(onPrintReset)(browse)
case getPDFPaperSize:
browse := &ICefBrowser{instance: getPtr(0)}
deviceUnitsPerInch := int32(getVal(1))
sizePtr := (*uintptr)(getPtr(2))
size := fn.(getPDFPaperSize)(browse, deviceUnitsPerInch)
if size != nil {
*sizePtr = uintptr(unsafe.Pointer(size))
}
default:
return false
}
return true
})
}