-
Notifications
You must be signed in to change notification settings - Fork 22
/
types_window.go
479 lines (425 loc) · 12.2 KB
/
types_window.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
//----------------------------------------
//
// 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 (
"errors"
"github.com/energye/energy/v2/cef/internal/def"
"github.com/energye/energy/v2/common/imports"
"github.com/energye/energy/v2/consts"
"github.com/energye/energy/v2/types"
"github.com/energye/golcl/energy/emfs"
"github.com/energye/golcl/lcl/api"
t "github.com/energye/golcl/lcl/types"
"io/ioutil"
"unsafe"
)
// CefWindowRef -> ICefWindow
var CefWindowRef cefWindow
type cefWindow uintptr
func (*cefWindow) New(windowComponent *TCEFWindowComponent) *ICefWindow {
if !windowComponent.IsValid() {
return nil
}
var result uintptr
imports.Proc(def.ICEFWindowRef_CreateTopLevel).Call(windowComponent.Instance(), uintptr(unsafe.Pointer(&result)))
if result != 0 {
return &ICefWindow{&ICefPanel{&ICefView{instance: getInstance(result)}}}
}
return nil
}
func (m *ICefWindow) Instance() uintptr {
if m == nil {
return 0
}
return uintptr(m.instance)
}
func (m *ICefWindow) Free() {
if m.instance != nil {
m.base.Free(m.Instance())
m.instance = nil
}
}
func (m *ICefWindow) IsValid() bool {
if m == nil || m.instance == nil {
return false
}
return true
}
// Show 显示窗口
func (m *ICefWindow) Show() {
if !m.IsValid() {
return
}
imports.Proc(def.ICEFWindow_Show).Call(m.Instance())
}
// ShowAsBrowserModalDialog 显示窗口 浏览器模式对话框
func (m *ICefWindow) ShowAsBrowserModalDialog(browserView *ICefBrowserView) {
if !m.IsValid() || !browserView.IsValid() {
return
}
imports.Proc(def.ICEFWindow_ShowAsBrowserModalDialog).Call(m.Instance(), browserView.Instance())
}
// Hide 显示窗口
func (m *ICefWindow) Hide() {
if !m.IsValid() {
return
}
imports.Proc(def.ICEFWindow_Hide).Call(m.Instance())
}
// CenterWindow 根据大小窗口居中
func (m *ICefWindow) CenterWindow(size *TCefSize) {
if !m.IsValid() {
return
}
imports.Proc(def.ICEFWindow_CenterWindow).Call(m.Instance(), uintptr(unsafe.Pointer(size)))
}
// Close 关闭窗口, 主窗口调用
func (m *ICefWindow) Close() {
if !m.IsValid() {
return
}
imports.Proc(def.ICEFWindow_Close).Call(m.Instance())
}
// IsClosed 是否关闭
func (m *ICefWindow) IsClosed() bool {
if !m.IsValid() {
return false
}
r1, _, _ := imports.Proc(def.ICEFWindow_IsClosed).Call(m.Instance())
return api.GoBool(r1)
}
// Activate 激活窗口
func (m *ICefWindow) Activate() {
if !m.IsValid() {
return
}
imports.Proc(def.ICEFWindow_Activate).Call(m.Instance())
}
// Deactivate 停止激活窗口
func (m *ICefWindow) Deactivate() {
if !m.IsValid() {
return
}
imports.Proc(def.ICEFWindow_Deactivate).Call(m.Instance())
}
// IsActive 是否激活
func (m *ICefWindow) IsActive() bool {
if !m.IsValid() {
return false
}
r1, _, _ := imports.Proc(def.ICEFWindow_IsActive).Call(m.Instance())
return api.GoBool(r1)
}
// BringToTop 将窗口移至最上层
func (m *ICefWindow) BringToTop() {
if !m.IsValid() {
return
}
imports.Proc(def.ICEFWindow_BringToTop).Call(m.Instance())
}
// SetAlwaysOnTop 设置窗口是否置顶
func (m *ICefWindow) SetAlwaysOnTop(onTop bool) {
if !m.IsValid() {
return
}
imports.Proc(def.ICEFWindow_SetAlwaysOnTop).Call(m.Instance(), api.PascalBool(onTop))
}
// IsAlwaysOnTop 窗口是否置顶
func (m *ICefWindow) IsAlwaysOnTop() bool {
if !m.IsValid() {
return false
}
r1, _, _ := imports.Proc(def.ICEFWindow_IsAlwaysOnTop).Call(m.Instance())
return api.GoBool(r1)
}
// WindowState 返回窗口最小化、最大化、全屏状态
func (m *ICefWindow) WindowState() t.TWindowState {
if !m.IsValid() {
return -1
}
if m.IsMinimized() {
return t.WsMinimized
} else if m.IsMaximized() {
return t.WsMaximized
} else if m.IsFullscreen() {
return t.WsFullScreen
}
return t.WsNormal
}
// Maximize 最大化窗口
func (m *ICefWindow) Maximize() {
if !m.IsValid() {
return
}
imports.Proc(def.ICEFWindow_Maximize).Call(m.Instance())
}
// Minimize 最小化窗口
func (m *ICefWindow) Minimize() {
if !m.IsValid() {
return
}
imports.Proc(def.ICEFWindow_Minimize).Call(m.Instance())
}
// Restore 窗口还原
func (m *ICefWindow) Restore() {
if !m.IsValid() {
return
}
imports.Proc(def.ICEFWindow_Restore).Call(m.Instance())
}
// SetFullscreen 设置窗口全屏
func (m *ICefWindow) SetFullscreen(fullscreen bool) {
if !m.IsValid() {
return
}
imports.Proc(def.ICEFWindow_SetFullscreen).Call(m.Instance(), api.PascalBool(fullscreen))
}
// SetBackgroundColor 设置背景色
func (m *ICefWindow) SetBackgroundColor(rect types.TCefColor) {
if !m.IsValid() {
return
}
imports.Proc(def.ICEFWindow_SetBackgroundColor).Call(m.Instance(), rect.ToPtr())
}
// SetBounds 设置窗口边界
func (m *ICefWindow) SetBounds(rect *TCefRect) {
if !m.IsValid() {
return
}
imports.Proc(def.ICEFWindow_SetBounds).Call(m.Instance(), uintptr(unsafe.Pointer(rect)))
}
// SetSize 设置窗口宽高
func (m *ICefWindow) SetSize(size *TCefSize) {
if !m.IsValid() {
return
}
imports.Proc(def.ICEFWindow_SetSize).Call(m.Instance(), uintptr(unsafe.Pointer(size)))
}
// SetPosition 设置窗口位置
func (m *ICefWindow) SetPosition(point *TCefPoint) {
if !m.IsValid() {
return
}
imports.Proc(def.ICEFWindow_SetPosition).Call(m.Instance(), uintptr(unsafe.Pointer(point)))
}
// IsMaximized 是否最大化
func (m *ICefWindow) IsMaximized() bool {
if !m.IsValid() {
return false
}
r1, _, _ := imports.Proc(def.ICEFWindow_IsMaximized).Call(m.Instance())
return api.GoBool(r1)
}
// IsMinimized 是否最小化
func (m *ICefWindow) IsMinimized() bool {
if !m.IsValid() {
return false
}
r1, _, _ := imports.Proc(def.ICEFWindow_IsMinimized).Call(m.Instance())
return api.GoBool(r1)
}
// IsFullscreen 是否全屏
func (m *ICefWindow) IsFullscreen() bool {
if !m.IsValid() {
return false
}
r1, _, _ := imports.Proc(def.ICEFWindow_IsFullscreen).Call(m.Instance())
return api.GoBool(r1)
}
// SetTitle 设置窗口标题
func (m *ICefWindow) SetTitle(title string) {
if !m.IsValid() {
return
}
imports.Proc(def.ICEFWindow_SetTitle).Call(m.Instance(), api.PascalStr(title))
}
// Title 获取窗口标题
func (m *ICefWindow) Title() string {
if !m.IsValid() {
return ""
}
r1, _, _ := imports.Proc(def.ICEFWindow_GetTitle).Call(m.Instance())
return api.GoStr(r1)
}
// SetWindowIcon 设置窗口图标
func (m *ICefWindow) SetWindowIcon(scaleFactor float32, filename string) error {
if !m.IsValid() {
return errors.New("invalid")
}
bytes, err := ioutil.ReadFile(filename)
if err != nil {
return err
}
imports.Proc(def.ICEFWindow_SetWindowIcon).Call(m.Instance(), uintptr(unsafe.Pointer(&scaleFactor)), uintptr(unsafe.Pointer(&bytes[0])), uintptr(int32(len(bytes))))
return nil
}
// SetWindowIconFS 设置窗口图标
func (m *ICefWindow) SetWindowIconFS(scaleFactor float32, filename string) error {
if !m.IsValid() {
return errors.New("invalid")
}
bytes, err := emfs.GetResources(filename)
if err != nil {
return err
}
imports.Proc(def.ICEFWindow_SetWindowIcon).Call(m.Instance(), uintptr(unsafe.Pointer(&scaleFactor)), uintptr(unsafe.Pointer(&bytes[0])), uintptr(int32(len(bytes))))
return nil
}
// WindowIcon 获取窗口图标
func (m *ICefWindow) WindowIcon() *ICefImage {
if !m.IsValid() {
return nil
}
var result uintptr
imports.Proc(def.ICEFWindow_GetWindowIcon).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
return &ICefImage{
instance: unsafe.Pointer(result),
}
}
// WindowAppIcon 获取窗口应用图标
func (m *ICefWindow) WindowAppIcon() *ICefImage {
if !m.IsValid() {
return nil
}
var result uintptr
imports.Proc(def.ICEFWindow_GetWindowAppIcon).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
return &ICefImage{
instance: unsafe.Pointer(result),
}
}
// SetWindowAppIcon 设置窗口应用图标
func (m *ICefWindow) SetWindowAppIcon(scaleFactor float32, filename string) error {
if !m.IsValid() {
return errors.New("invalid")
}
bytes, err := ioutil.ReadFile(filename)
if err != nil {
return err
}
imports.Proc(def.ICEFWindow_SetWindowAppIcon).Call(m.Instance(), uintptr(unsafe.Pointer(&scaleFactor)), uintptr(unsafe.Pointer(&bytes[0])), uintptr(int32(len(bytes))))
return nil
}
// SetWindowAppIconFS 设置窗口应用图标
func (m *ICefWindow) SetWindowAppIconFS(scaleFactor float32, filename string) error {
if !m.IsValid() {
return errors.New("invalid")
}
bytes, err := emfs.GetResources(filename)
if err != nil {
return err
}
imports.Proc(def.ICEFWindow_SetWindowAppIcon).Call(m.Instance(), uintptr(unsafe.Pointer(&scaleFactor)), uintptr(unsafe.Pointer(&bytes[0])), uintptr(int32(len(bytes))))
return nil
}
// AddOverlayView
func (m *ICefWindow) AddOverlayView(view *ICefView, dockingMode consts.TCefDockingMode) *ICefOverlayController {
if !m.IsValid() {
return nil
}
var result uintptr
imports.Proc(def.ICEFWindow_AddOverlayView).Call(m.Instance(), view.Instance(), uintptr(dockingMode), uintptr(unsafe.Pointer(&result)))
if result != 0 {
return &ICefOverlayController{instance: getInstance(result)}
}
return nil
}
// ShowMenu 显示菜单
func (m *ICefWindow) ShowMenu(menuModel *ICefMenuModel, point TCefPoint, anchorPosition consts.TCefMenuAnchorPosition) {
if !m.IsValid() {
return
}
imports.Proc(def.ICEFWindow_ShowMenu).Call(m.Instance(), menuModel.Instance(), uintptr(unsafe.Pointer(&point)), uintptr(anchorPosition))
}
// CancelMenu 取消菜单
func (m *ICefWindow) CancelMenu() {
if !m.IsValid() {
return
}
imports.Proc(def.ICEFWindow_CancelMenu).Call(m.Instance())
}
// Display
func (m *ICefWindow) Display() *ICefDisplay {
if !m.IsValid() {
return nil
}
var ret uintptr
imports.Proc(def.ICEFWindow_GetDisplay).Call(m.Instance(), uintptr(unsafe.Pointer(&ret)))
return &ICefDisplay{
instance: unsafe.Pointer(ret),
}
}
// ClientAreaBoundsInScreen 获取客户端所在指定屏幕位置
func (m *ICefWindow) ClientAreaBoundsInScreen() (result TCefRect) {
if !m.IsValid() {
return
}
imports.Proc(def.ICEFWindow_GetClientAreaBoundsInScreen).Call(m.Instance(), uintptr(unsafe.Pointer(&result)))
return
}
// SetDraggableRegions 设置拖拽区域
func (m *ICefWindow) SetDraggableRegions(regions []TCefDraggableRegion) {
if !m.IsValid() {
return
}
imports.Proc(def.ICEFWindow_SetDraggableRegions).Call(m.Instance(), uintptr(int32(len(regions))), uintptr(unsafe.Pointer(®ions[0])), uintptr(int32(len(regions))))
}
// WindowHandle 获取窗口句柄
func (m *ICefWindow) WindowHandle() consts.TCefWindowHandle {
if !m.IsValid() {
return 0
}
r1, _, _ := imports.Proc(def.ICEFWindow_GetWindowHandle).Call(m.Instance())
return consts.TCefWindowHandle(r1)
}
// SendKeyPress 发送键盘事件
func (m *ICefWindow) SendKeyPress(keyCode int32, eventFlags uint32) {
if !m.IsValid() {
return
}
imports.Proc(def.ICEFWindow_SendKeyPress).Call(m.Instance(), uintptr(keyCode), uintptr(eventFlags))
}
// SendMouseMove 发送鼠标移动事件
func (m *ICefWindow) SendMouseMove(screenX, screenY int32) {
if !m.IsValid() {
return
}
imports.Proc(def.ICEFWindow_SendMouseMove).Call(m.Instance(), uintptr(screenX), uintptr(screenY))
}
// SendMouseEvents 发送鼠标事件
func (m *ICefWindow) SendMouseEvents(button consts.TCefMouseButtonType, mouseDown, mouseUp bool) {
if !m.IsValid() {
return
}
imports.Proc(def.ICEFWindow_SendMouseEvents).Call(m.Instance(), uintptr(button), api.PascalBool(mouseDown), api.PascalBool(mouseUp))
}
// SetAccelerator 设置快捷键
func (m *ICefWindow) SetAccelerator(commandId, keyCode int32, shiftPressed, ctrlPressed, altPressed bool) {
if !m.IsValid() {
return
}
imports.Proc(def.ICEFWindow_SetAccelerator).Call(m.Instance(), uintptr(commandId), uintptr(keyCode), api.PascalBool(shiftPressed), api.PascalBool(ctrlPressed), api.PascalBool(altPressed))
}
// RemoveAccelerator 移除指定快捷键
func (m *ICefWindow) RemoveAccelerator(commandId int32) {
if !m.IsValid() {
return
}
imports.Proc(def.ICEFWindow_RemoveAccelerator).Call(m.Instance(), uintptr(commandId))
}
// RemoveAllAccelerators 移除所有快捷键
func (m *ICefWindow) RemoveAllAccelerators() {
if !m.IsValid() {
return
}
imports.Proc(def.ICEFWindow_RemoveAllAccelerators).Call(m.Instance())
}
func (m *ICefWindow) SetWindow(window *ICefWindow) {
m.instance = window.instance
}