types-pdfprint-callback.go 1.6 KB
Newer Older
yanghye's avatar
yanghye 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14
//----------------------------------------
//
// Copyright © yanghy. All Rights Reserved.
//
// Licensed under Apache License Version 2.0, January 2004
//
// https://www.apache.org/licenses/LICENSE-2.0
//
//----------------------------------------

// PDF 打印回调 PdfPrintCallbackRef.New
package cef

import (
yanghye's avatar
yanghye 已提交
15
	"github.com/energye/energy/v2/common/imports"
yanghye's avatar
yanghye 已提交
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
	"github.com/energye/golcl/lcl"
	"github.com/energye/golcl/lcl/api"
	"unsafe"
)

// PdfPrintCallbackRef -> ICefPdfPrintCallback
var PdfPrintCallbackRef pdfPrintCallback

type pdfPrintCallback uintptr

func (*pdfPrintCallback) New() *ICefPdfPrintCallback {
	var result uintptr
	imports.Proc(internale_CefPdfPrintCallback_Create).Call(uintptr(unsafe.Pointer(&result)))
	return &ICefPdfPrintCallback{instance: unsafe.Pointer(result)}
}

// Instance 实例
func (m *ICefPdfPrintCallback) Instance() uintptr {
	if m == nil {
		return 0
	}
	return uintptr(m.instance)
}

yanghye's avatar
yanghye 已提交
40 41 42 43 44 45 46
func (m *ICefPdfPrintCallback) Free() {
	if m.instance != nil {
		m.base.Free(m.Instance())
		m.instance = nil
	}
}

yanghye's avatar
yanghye 已提交
47 48 49 50 51 52 53 54 55 56 57 58 59
func (m *ICefPdfPrintCallback) IsValid() bool {
	if m == nil || m.instance == nil {
		return false
	}
	return m.instance != nil
}

func (m *ICefPdfPrintCallback) OnPdfPrintFinished(fn OnPdfPrintFinished) {
	imports.Proc(internale_CefPdfPrintCallback_OnPdfPrintFinished).Call(m.Instance(), api.MakeEventDataPtr(fn))
}

type OnPdfPrintFinished func(path string, ok bool)

yanghye's avatar
yanghye 已提交
60 61 62 63 64 65 66 67 68 69 70
func init() {
	lcl.RegisterExtEventCallback(func(fn interface{}, getVal func(idx int) uintptr) bool {
		switch fn.(type) {
		case OnPdfPrintFinished:
			fn.(OnPdfPrintFinished)(api.GoStr(getVal(0)), api.GoBool(getVal(1)))
		default:
			return false
		}
		return true
	})
}