/
gtk_since_3_12.go
554 lines (461 loc) · 15.8 KB
/
gtk_since_3_12.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
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
// Copyright (c) 2013-2014 Conformal Systems <info@conformal.com>
//
// Wrapper for GtkPopover originated from: http://opensource.conformal.com/
//
// Permission to use, copy, modify, and distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
// +build !gtk_3_6,!gtk_3_8,!gtk_3_10
// not use this: go build -tags gtk_3_8'. Otherwise, if no build tags are used, GTK 3.10
package gtk
// #include <stdlib.h>
// #include <gtk/gtk.h>
// #include "gtk_since_3_12.go.h"
import "C"
import (
"errors"
"runtime"
"unsafe"
"github.com/gotk3/gotk3/gdk"
"github.com/gotk3/gotk3/glib"
)
/*
* Constants
*/
const (
STATE_FLAG_LINK StateFlags = C.GTK_STATE_FLAG_LINK
STATE_FLAG_VISITED StateFlags = C.GTK_STATE_FLAG_VISITED
)
const (
BUTTONBOX_EXPAND ButtonBoxStyle = C.GTK_BUTTONBOX_EXPAND
)
func init() {
tm := []glib.TypeMarshaler{
// Objects/Interfaces
{glib.Type(C.gtk_flow_box_get_type()), marshalFlowBox},
{glib.Type(C.gtk_flow_box_child_get_type()), marshalFlowBoxChild},
{glib.Type(C.gtk_popover_get_type()), marshalPopover},
}
glib.RegisterGValueMarshalers(tm)
//Contribute to casting
for k, v := range map[string]WrapFn{
"GtkFlowBox": wrapFlowBox,
"GtkFlowBoxChild": wrapFlowBoxChild,
"GtkPopover": wrapPopover,
} {
WrapMap[k] = v
}
}
// GetLocaleDirection() is a wrapper around gtk_get_locale_direction().
func GetLocaleDirection() TextDirection {
c := C.gtk_get_locale_direction()
return TextDirection(c)
}
/*
* GtkStack
*/
// TODO:
// GtkStackTransitionType
// GTK_STACK_TRANSITION_TYPE_OVER_UP
// GTK_STACK_TRANSITION_TYPE_OVER_DOWN
// GTK_STACK_TRANSITION_TYPE_OVER_LEFT
// GTK_STACK_TRANSITION_TYPE_OVER_RIGHT
// GTK_STACK_TRANSITION_TYPE_UNDER_UP
// GTK_STACK_TRANSITION_TYPE_UNDER_DOWN
// GTK_STACK_TRANSITION_TYPE_UNDER_LEFT
// GTK_STACK_TRANSITION_TYPE_UNDER_RIGHT
// GTK_STACK_TRANSITION_TYPE_OVER_UP_DOWN
/*
* Dialog
*/
// GetHeaderBar is a wrapper around gtk_dialog_get_header_bar().
func (v *Dialog) GetHeaderBar() *Widget {
c := C.gtk_dialog_get_header_bar(v.native())
if c == nil {
return nil
}
return wrapWidget(glib.Take(unsafe.Pointer(c)))
}
/*
* Entry
*/
// SetMaxWidthChars is a wrapper around gtk_entry_set_max_width_chars().
func (v *Entry) SetMaxWidthChars(nChars int) {
C.gtk_entry_set_max_width_chars(v.native(), C.gint(nChars))
}
// GetMaxWidthChars is a wrapper around gtk_entry_get_max_width_chars().
func (v *Entry) GetMaxWidthChars() int {
c := C.gtk_entry_get_max_width_chars(v.native())
return int(c)
}
/*
* HeaderBar
*/
// GetDecorationLayout is a wrapper around gtk_header_bar_get_decoration_layout().
func (v *HeaderBar) GetDecorationLayout() string {
c := C.gtk_header_bar_get_decoration_layout(v.native())
return C.GoString((*C.char)(c))
}
// SetDecorationLayout is a wrapper around gtk_header_bar_set_decoration_layout().
func (v *HeaderBar) SetDecorationLayout(layout string) {
cstr := C.CString(layout)
defer C.free(unsafe.Pointer(cstr))
C.gtk_header_bar_set_decoration_layout(v.native(), (*C.gchar)(cstr))
}
// GetHasSubtitle is a wrapper around gtk_header_bar_get_has_subtitle().
func (v *HeaderBar) GetHasSubtitle() bool {
c := C.gtk_header_bar_get_has_subtitle(v.native())
return gobool(c)
}
// SetHasSubtitle is a wrapper around gtk_header_bar_set_has_subtitle().
func (v *HeaderBar) SetHasSubtitle(setting bool) {
C.gtk_header_bar_set_has_subtitle(v.native(), gbool(setting))
}
/*
* MenuButton
*/
// SetPopover is a wrapper around gtk_menu_button_set_popover().
func (v *MenuButton) SetPopover(popover *Popover) {
C.gtk_menu_button_set_popover(v.native(), popover.toWidget())
}
// GetPopover is a wrapper around gtk_menu_button_get_popover().
func (v *MenuButton) GetPopover() *Popover {
c := C.gtk_menu_button_get_popover(v.native())
if c == nil {
return nil
}
return wrapPopover(glib.Take(unsafe.Pointer(c)))
}
// GetUsePopover is a wrapper around gtk_menu_button_get_use_popover().
func (v *MenuButton) GetUsePopover() bool {
c := C.gtk_menu_button_get_use_popover(v.native())
return gobool(c)
}
// SetUsePopover is a wrapper around gtk_menu_button_set_use_popover().
func (v *MenuButton) SetUsePopover(setting bool) {
C.gtk_menu_button_set_use_popover(v.native(), gbool(setting))
}
/*
* FlowBox
*/
type FlowBox struct {
Container
}
func (fb *FlowBox) native() *C.GtkFlowBox {
if fb == nil || fb.GObject == nil {
return nil
}
p := unsafe.Pointer(fb.GObject)
return C.toGtkFlowBox(p)
}
func marshalFlowBox(p uintptr) (interface{}, error) {
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
obj := glib.Take(unsafe.Pointer(c))
return wrapFlowBox(obj), nil
}
func wrapFlowBox(obj *glib.Object) *FlowBox {
return &FlowBox{Container{Widget{glib.InitiallyUnowned{obj}}}}
}
// FlowBoxNew is a wrapper around gtk_flow_box_new()
func FlowBoxNew() (*FlowBox, error) {
c := C.gtk_flow_box_new()
if c == nil {
return nil, nilPtrErr
}
return wrapFlowBox(glib.Take(unsafe.Pointer(c))), nil
}
// Insert is a wrapper around gtk_flow_box_insert()
func (fb *FlowBox) Insert(widget IWidget, position int) {
C.gtk_flow_box_insert(fb.native(), widget.toWidget(), C.gint(position))
}
// GetChildAtIndex is a wrapper around gtk_flow_box_get_child_at_index()
func (fb *FlowBox) GetChildAtIndex(idx int) *FlowBoxChild {
c := C.gtk_flow_box_get_child_at_index(fb.native(), C.gint(idx))
if c == nil {
return nil
}
return wrapFlowBoxChild(glib.Take(unsafe.Pointer(c)))
}
// TODO 3.22.6 gtk_flow_box_get_child_at_pos()
// SetHAdjustment is a wrapper around gtk_flow_box_set_hadjustment()
func (fb *FlowBox) SetHAdjustment(adjustment *Adjustment) {
C.gtk_flow_box_set_hadjustment(fb.native(), adjustment.native())
}
// SetVAdjustment is a wrapper around gtk_flow_box_set_vadjustment()
func (fb *FlowBox) SetVAdjustment(adjustment *Adjustment) {
C.gtk_flow_box_set_vadjustment(fb.native(), adjustment.native())
}
// SetHomogeneous is a wrapper around gtk_flow_box_set_homogeneous()
func (fb *FlowBox) SetHomogeneous(homogeneous bool) {
C.gtk_flow_box_set_homogeneous(fb.native(), gbool(homogeneous))
}
// GetHomogeneous is a wrapper around gtk_flow_box_get_homogeneous()
func (fb *FlowBox) GetHomogeneous() bool {
c := C.gtk_flow_box_get_homogeneous(fb.native())
return gobool(c)
}
// SetRowSpacing is a wrapper around gtk_flow_box_set_row_spacing()
func (fb *FlowBox) SetRowSpacing(spacing uint) {
C.gtk_flow_box_set_row_spacing(fb.native(), C.guint(spacing))
}
// GetRowSpacing is a wrapper around gtk_flow_box_get_row_spacing()
func (fb *FlowBox) GetRowSpacing() uint {
c := C.gtk_flow_box_get_row_spacing(fb.native())
return uint(c)
}
// SetColumnSpacing is a wrapper around gtk_flow_box_set_column_spacing()
func (fb *FlowBox) SetColumnSpacing(spacing uint) {
C.gtk_flow_box_set_column_spacing(fb.native(), C.guint(spacing))
}
// GetColumnSpacing is a wrapper around gtk_flow_box_get_column_spacing()
func (fb *FlowBox) GetColumnSpacing() uint {
c := C.gtk_flow_box_get_column_spacing(fb.native())
return uint(c)
}
// SetMinChildrenPerLine is a wrapper around gtk_flow_box_set_min_children_per_line()
func (fb *FlowBox) SetMinChildrenPerLine(n_children uint) {
C.gtk_flow_box_set_min_children_per_line(fb.native(), C.guint(n_children))
}
// GetMinChildrenPerLine is a wrapper around gtk_flow_box_get_min_children_per_line()
func (fb *FlowBox) GetMinChildrenPerLine() uint {
c := C.gtk_flow_box_get_min_children_per_line(fb.native())
return uint(c)
}
// SetMaxChildrenPerLine is a wrapper around gtk_flow_box_set_max_children_per_line()
func (fb *FlowBox) SetMaxChildrenPerLine(n_children uint) {
C.gtk_flow_box_set_max_children_per_line(fb.native(), C.guint(n_children))
}
// GetMaxChildrenPerLine is a wrapper around gtk_flow_box_get_max_children_per_line()
func (fb *FlowBox) GetMaxChildrenPerLine() uint {
c := C.gtk_flow_box_get_max_children_per_line(fb.native())
return uint(c)
}
// SetActivateOnSingleClick is a wrapper around gtk_flow_box_set_activate_on_single_click()
func (fb *FlowBox) SetActivateOnSingleClick(single bool) {
C.gtk_flow_box_set_activate_on_single_click(fb.native(), gbool(single))
}
// GetActivateOnSingleClick gtk_flow_box_get_activate_on_single_click()
func (fb *FlowBox) GetActivateOnSingleClick() bool {
c := C.gtk_flow_box_get_activate_on_single_click(fb.native())
return gobool(c)
}
// TODO: gtk_flow_box_selected_foreach()
// GetSelectedChildren is a wrapper around gtk_flow_box_get_selected_children()
func (fb *FlowBox) GetSelectedChildren() (rv []*FlowBoxChild) {
c := C.gtk_flow_box_get_selected_children(fb.native())
if c == nil {
return
}
list := glib.WrapList(uintptr(unsafe.Pointer(c)))
for l := list; l != nil; l = l.Next() {
o := wrapFlowBoxChild(glib.Take(l.Data().(unsafe.Pointer)))
rv = append(rv, o)
}
// We got a transfer container, so we must free the list.
list.Free()
return
}
// SelectChild is a wrapper around gtk_flow_box_select_child()
func (fb *FlowBox) SelectChild(child *FlowBoxChild) {
C.gtk_flow_box_select_child(fb.native(), child.native())
}
// UnselectChild is a wrapper around gtk_flow_box_unselect_child()
func (fb *FlowBox) UnselectChild(child *FlowBoxChild) {
C.gtk_flow_box_unselect_child(fb.native(), child.native())
}
// SelectAll is a wrapper around gtk_flow_box_select_all()
func (fb *FlowBox) SelectAll() {
C.gtk_flow_box_select_all(fb.native())
}
// UnselectAll is a wrapper around gtk_flow_box_unselect_all()
func (fb *FlowBox) UnselectAll() {
C.gtk_flow_box_unselect_all(fb.native())
}
// SetSelectionMode is a wrapper around gtk_flow_box_set_selection_mode()
func (fb *FlowBox) SetSelectionMode(mode SelectionMode) {
C.gtk_flow_box_set_selection_mode(fb.native(), C.GtkSelectionMode(mode))
}
// GetSelectionMode is a wrapper around gtk_flow_box_get_selection_mode()
func (fb *FlowBox) GetSelectionMode() SelectionMode {
c := C.gtk_flow_box_get_selection_mode(fb.native())
return SelectionMode(c)
}
// TODO gtk_flow_box_set_filter_func()
// TODO gtk_flow_box_invalidate_filter()
// TODO gtk_flow_box_set_sort_func()
// TODO gtk_flow_box_invalidate_sort()
// TODO 3.18 gtk_flow_box_bind_model()
/*
* FlowBoxChild
*/
type FlowBoxChild struct {
Bin
}
func (fbc *FlowBoxChild) native() *C.GtkFlowBoxChild {
if fbc == nil || fbc.GObject == nil {
return nil
}
p := unsafe.Pointer(fbc.GObject)
return C.toGtkFlowBoxChild(p)
}
func marshalFlowBoxChild(p uintptr) (interface{}, error) {
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
obj := glib.Take(unsafe.Pointer(c))
return wrapFlowBoxChild(obj), nil
}
func wrapFlowBoxChild(obj *glib.Object) *FlowBoxChild {
return &FlowBoxChild{Bin{Container{Widget{glib.InitiallyUnowned{obj}}}}}
}
// FlowBoxChildNew is a wrapper around gtk_flow_box_child_new()
func FlowBoxChildNew() (*FlowBoxChild, error) {
c := C.gtk_flow_box_child_new()
if c == nil {
return nil, nilPtrErr
}
return wrapFlowBoxChild(glib.Take(unsafe.Pointer(c))), nil
}
// GetIndex is a wrapper around gtk_flow_box_child_get_index()
func (fbc *FlowBoxChild) GetIndex() int {
c := C.gtk_flow_box_child_get_index(fbc.native())
return int(c)
}
// IsSelected is a wrapper around gtk_flow_box_child_is_selected()
func (fbc *FlowBoxChild) IsSelected() bool {
c := C.gtk_flow_box_child_is_selected(fbc.native())
return gobool(c)
}
// Changed is a wrapper around gtk_flow_box_child_changed()
func (fbc *FlowBoxChild) Changed() {
C.gtk_flow_box_child_changed(fbc.native())
}
/*
* GtkPlacesSidebar
*/
// TODO:
// gtk_places_sidebar_get_local_only().
// gtk_places_sidebar_set_local_only().
/*
* GtkPopover
*/
// Popover is a representation of GTK's GtkPopover.
type Popover struct {
Bin
}
func (v *Popover) native() *C.GtkPopover {
if v == nil || v.GObject == nil {
return nil
}
p := unsafe.Pointer(v.GObject)
return C.toGtkPopover(p)
}
func marshalPopover(p uintptr) (interface{}, error) {
c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
return wrapPopover(glib.Take(unsafe.Pointer(c))), nil
}
func wrapPopover(obj *glib.Object) *Popover {
return &Popover{Bin{Container{Widget{glib.InitiallyUnowned{obj}}}}}
}
// PopoverNew is a wrapper around gtk_popover_new().
func PopoverNew(relative IWidget) (*Popover, error) {
//Takes relative to widget
var c *C.struct__GtkWidget
if relative == nil {
c = C.gtk_popover_new(nil)
} else {
c = C.gtk_popover_new(relative.toWidget())
}
if c == nil {
return nil, nilPtrErr
}
return wrapPopover(glib.Take(unsafe.Pointer(c))), nil
}
// PopoverNewFromModel is a wrapper around gtk_popover_new_from_model().
func PopoverNewFromModel(relative IWidget, model *glib.MenuModel) (*Popover, error) {
//Takes relative to widget
var c *C.struct__GtkWidget
mptr := C.toGMenuModel(unsafe.Pointer(model.Native()))
if relative == nil {
c = C.gtk_popover_new_from_model(nil, mptr)
} else {
c = C.gtk_popover_new_from_model(relative.toWidget(), mptr)
}
if c == nil {
return nil, nilPtrErr
}
return wrapPopover(glib.Take(unsafe.Pointer(c))), nil
}
// BindModel is a wrapper around gtk_popover_bind_model().
func (v *Popover) BindModel(menuModel *glib.MenuModel, actionNamespace string) {
cstr := C.CString(actionNamespace)
defer C.free(unsafe.Pointer(cstr))
C.gtk_popover_bind_model(v.native(), C.toGMenuModel(unsafe.Pointer(menuModel.Native())), (*C.gchar)(cstr))
}
// SetRelativeTo is a wrapper around gtk_popover_set_relative_to().
func (v *Popover) SetRelativeTo(relative IWidget) {
C.gtk_popover_set_relative_to(v.native(), relative.toWidget())
}
// GetRelativeTo is a wrapper around gtk_popover_get_relative_to().
func (v *Popover) GetRelativeTo() *Widget {
c := C.gtk_popover_get_relative_to(v.native())
if c == nil {
return nil
}
return wrapWidget(glib.Take(unsafe.Pointer(c)))
}
// SetPointingTo is a wrapper around gtk_popover_set_pointing_to().
func (v *Popover) SetPointingTo(rect gdk.Rectangle) {
C.gtk_popover_set_pointing_to(v.native(), nativeGdkRectangle(rect))
}
// GetPointingTo is a wrapper around gtk_popover_get_pointing_to().
func (v *Popover) GetPointingTo() (*gdk.Rectangle, bool) {
var cRect *C.GdkRectangle
isSet := C.gtk_popover_get_pointing_to(v.native(), cRect)
rect := gdk.WrapRectangle(uintptr(unsafe.Pointer(cRect)))
return rect, gobool(isSet)
}
// SetPosition is a wrapper around gtk_popover_set_position().
func (v *Popover) SetPosition(position PositionType) {
C.gtk_popover_set_position(v.native(), C.GtkPositionType(position))
}
// GetPosition is a wrapper around gtk_popover_get_position().
func (v *Popover) GetPosition() PositionType {
c := C.gtk_popover_get_position(v.native())
return PositionType(c)
}
// SetModal is a wrapper around gtk_popover_set_modal().
func (v *Popover) SetModal(modal bool) {
C.gtk_popover_set_modal(v.native(), gbool(modal))
}
// GetModal is a wrapper around gtk_popover_get_modal().
func (v *Popover) GetModal() bool {
return gobool(C.gtk_popover_get_modal(v.native()))
}
/*
* TreePath
*/
// TreePathNewFromIndicesv() is a wrapper around gtk_tree_path_new_from_indicesv().
func TreePathNewFromIndicesv(indices []int) (*TreePath, error) {
if len(indices) == 0 {
return nil, errors.New("no indice")
}
var cIndices []C.gint
for i := 0; i < len(indices); i++ {
cIndices = append(cIndices, C.gint(indices[i]))
}
var cIndicesPointer *C.gint = &cIndices[0]
c := C.gtk_tree_path_new_from_indicesv(cIndicesPointer, C.gsize(len(indices)))
if c == nil {
return nil, nilPtrErr
}
t := &TreePath{c}
runtime.SetFinalizer(t, (*TreePath).free)
return t, nil
}