File: icon_view.go

package info (click to toggle)
golang-github-gotk3-gotk3 0.6.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,392 kB
  • sloc: ansic: 914; makefile: 4
file content (483 lines) | stat: -rw-r--r-- 14,736 bytes parent folder | download
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
package gtk

// #include <gtk/gtk.h>
// #include "gtk.go.h"
import "C"
import (
	"runtime"
	"unsafe"

	"github.com/gotk3/gotk3/gdk"
	"github.com/gotk3/gotk3/glib"
)

/*
 * GtkIconView
 */

// IconView is a representation of GTK's GtkIconView.
type IconView struct {
	Container
}

// native returns a pointer to the underlying GtkIconView.
func (v *IconView) native() *C.GtkIconView {
	if v == nil || v.GObject == nil {
		return nil
	}
	p := unsafe.Pointer(v.GObject)
	return C.toGtkIconView(p)
}

func marshalIconView(p uintptr) (interface{}, error) {
	c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
	obj := glib.Take(unsafe.Pointer(c))
	return wrapIconView(obj), nil
}

func wrapIconView(obj *glib.Object) *IconView {
	if obj == nil {
		return nil
	}

	return &IconView{Container{Widget{glib.InitiallyUnowned{obj}}}}
}

// IconViewNew is a wrapper around gtk_icon_view_new().
func IconViewNew() (*IconView, error) {
	c := C.gtk_icon_view_new()
	if c == nil {
		return nil, nilPtrErr
	}

	return wrapIconView(glib.Take(unsafe.Pointer(c))), nil
}

// TODO:
// gtk_icon_view_new_with_area().

// IconViewNewWithModel is a wrapper around gtk_icon_view_new_with_model().
func IconViewNewWithModel(model ITreeModel) (*IconView, error) {
	c := C.gtk_icon_view_new_with_model(model.toTreeModel())
	if c == nil {
		return nil, nilPtrErr
	}
	obj := glib.Take(unsafe.Pointer(c))
	return wrapIconView(obj), nil
}

// SetModel is a wrapper around gtk_icon_view_set_model().
func (v *IconView) SetModel(model ITreeModel) {
	var mptr *C.GtkTreeModel
	if model != nil {
		mptr = model.toTreeModel()
	}
	C.gtk_icon_view_set_model(v.native(), mptr)
}

// GetModel is a wrapper around gtk_icon_view_get_model().
func (v *IconView) GetModel() (ITreeModel, error) {
	c := C.gtk_icon_view_get_model(v.native())
	if c == nil {
		return nil, nilPtrErr
	}
	return castTreeModel(c)
}

// SetTextColumn is a wrapper around gtk_icon_view_set_text_column().
func (v *IconView) SetTextColumn(column int) {
	C.gtk_icon_view_set_text_column(v.native(), C.gint(column))
}

// GetTextColumn is a wrapper around gtk_icon_view_get_text_column().
func (v *IconView) GetTextColumn() int {
	return int(C.gtk_icon_view_get_text_column(v.native()))
}

// SetMarkupColumn is a wrapper around gtk_icon_view_set_markup_column().
func (v *IconView) SetMarkupColumn(column int) {
	C.gtk_icon_view_set_markup_column(v.native(), C.gint(column))
}

// GetMarkupColumn is a wrapper around gtk_icon_view_get_markup_column().
func (v *IconView) GetMarkupColumn() int {
	return int(C.gtk_icon_view_get_markup_column(v.native()))
}

// SetPixbufColumn is a wrapper around gtk_icon_view_set_pixbuf_column().
func (v *IconView) SetPixbufColumn(column int) {
	C.gtk_icon_view_set_pixbuf_column(v.native(), C.gint(column))
}

// GetPixbufColumn is a wrapper around gtk_icon_view_get_pixbuf_column().
func (v *IconView) GetPixbufColumn() int {
	return int(C.gtk_icon_view_get_pixbuf_column(v.native()))
}

// GetPathAtPos is a wrapper around gtk_icon_view_get_path_at_pos().
func (v *IconView) GetPathAtPos(x, y int) *TreePath {
	var (
		cpath *C.GtkTreePath
		path  *TreePath
	)

	cpath = C.gtk_icon_view_get_path_at_pos(v.native(), C.gint(x), C.gint(y))

	if cpath != nil {
		path = &TreePath{cpath}
		runtime.SetFinalizer(path, func(v *TreePath) { glib.FinalizerStrategy(v.free) })
	}

	return path
}

// GetItemAtPos is a wrapper around gtk_icon_view_get_item_at_pos().
func (v *IconView) GetItemAtPos(x, y int) (*TreePath, *CellRenderer) {
	var (
		cpath *C.GtkTreePath
		ccell *C.GtkCellRenderer
		path  *TreePath
		cell  *CellRenderer
	)

	C.gtk_icon_view_get_item_at_pos(v.native(), C.gint(x), C.gint(y), &cpath, &ccell)

	if cpath != nil {
		path = &TreePath{cpath}
		runtime.SetFinalizer(path, func(v *TreePath) { glib.FinalizerStrategy(v.free) })
	}

	if ccell != nil {
		cell = wrapCellRenderer(glib.Take(unsafe.Pointer(ccell)))
	}

	return path, cell
}

// ConvertWidgetToBinWindowCoords is a wrapper around gtk_icon_view_convert_widget_to_bin_window_coords().
func (v *IconView) ConvertWidgetToBinWindowCoords(x, y int) (int, int) {
	var bx, by C.gint

	C.gtk_icon_view_convert_widget_to_bin_window_coords(v.native(), C.gint(x), C.gint(y), &bx, &by)

	return int(bx), int(by)
}

// SetCursor is a wrapper around gtk_icon_view_set_cursor().
func (v *IconView) SetCursor(path *TreePath, cell *CellRenderer, startEditing bool) {
	C.gtk_icon_view_set_cursor(v.native(), path.native(), cell.native(), gbool(startEditing))
}

// GetCursor is a wrapper around gtk_icon_view_get_cursor().
func (v *IconView) GetCursor() (*TreePath, *CellRenderer) {
	var (
		cpath *C.GtkTreePath
		ccell *C.GtkCellRenderer
		path  *TreePath
		cell  *CellRenderer
	)

	C.gtk_icon_view_get_cursor(v.native(), &cpath, &ccell)

	if cpath != nil {
		path = &TreePath{cpath}
		runtime.SetFinalizer(path, func(v *TreePath) { glib.FinalizerStrategy(v.free) })
	}

	if ccell != nil {
		cell = wrapCellRenderer(glib.Take(unsafe.Pointer(ccell)))
	}

	return path, cell
}

// TODO:
// gtk_icon_view_selected_foreach().
// func (v *IconView) SelectedForeach() {}

// SetSelectionMode is a wrapper around gtk_icon_view_set_selection_mode().
func (v *IconView) SetSelectionMode(mode SelectionMode) {
	C.gtk_icon_view_set_selection_mode(v.native(), C.GtkSelectionMode(mode))
}

// GetSelectionMode is a wrapper around gtk_icon_view_get_selection_mode().
func (v *IconView) GetSelectionMode() SelectionMode {
	return SelectionMode(C.gtk_icon_view_get_selection_mode(v.native()))
}

// SetItemOrientation is a wrapper around gtk_icon_view_set_item_orientation().
func (v *IconView) SetItemOrientation(orientation Orientation) {
	C.gtk_icon_view_set_item_orientation(v.native(), C.GtkOrientation(orientation))
}

// GetItemOrientation is a wrapper around gtk_icon_view_get_item_orientation().
func (v *IconView) GetItemOrientation() Orientation {
	return Orientation(C.gtk_icon_view_get_item_orientation(v.native()))
}

// SetColumns is a wrapper around gtk_icon_view_set_columns().
func (v *IconView) SetColumns(columns int) {
	C.gtk_icon_view_set_columns(v.native(), C.gint(columns))
}

// GetColumns is a wrapper around gtk_icon_view_get_columns().
func (v *IconView) GetColumns() int {
	return int(C.gtk_icon_view_get_columns(v.native()))
}

// SetItemWidth is a wrapper around gtk_icon_view_set_item_width().
func (v *IconView) SetItemWidth(width int) {
	C.gtk_icon_view_set_item_width(v.native(), C.gint(width))
}

// GetItemWidth is a wrapper around gtk_icon_view_get_item_width().
func (v *IconView) GetItemWidth() int {
	return int(C.gtk_icon_view_get_item_width(v.native()))
}

// SetSpacing is a wrapper around gtk_icon_view_set_spacing().
func (v *IconView) SetSpacing(spacing int) {
	C.gtk_icon_view_set_spacing(v.native(), C.gint(spacing))
}

// GetSpacing is a wrapper around gtk_icon_view_get_spacing().
func (v *IconView) GetSpacing() int {
	return int(C.gtk_icon_view_get_spacing(v.native()))
}

// SetRowSpacing is a wrapper around gtk_icon_view_set_row_spacing().
func (v *IconView) SetRowSpacing(rowSpacing int) {
	C.gtk_icon_view_set_row_spacing(v.native(), C.gint(rowSpacing))
}

// GetRowSpacing is a wrapper around gtk_icon_view_get_row_spacing().
func (v *IconView) GetRowSpacing() int {
	return int(C.gtk_icon_view_get_row_spacing(v.native()))
}

// SetColumnSpacing is a wrapper around gtk_icon_view_set_column_spacing().
func (v *IconView) SetColumnSpacing(columnSpacing int) {
	C.gtk_icon_view_set_column_spacing(v.native(), C.gint(columnSpacing))
}

// GetColumnSpacing is a wrapper around gtk_icon_view_get_column_spacing().
func (v *IconView) GetColumnSpacing() int {
	return int(C.gtk_icon_view_get_column_spacing(v.native()))
}

// SetMargin is a wrapper around gtk_icon_view_set_margin().
func (v *IconView) SetMargin(margin int) {
	C.gtk_icon_view_set_margin(v.native(), C.gint(margin))
}

// GetMargin is a wrapper around gtk_icon_view_get_margin().
func (v *IconView) GetMargin() int {
	return int(C.gtk_icon_view_get_margin(v.native()))
}

// SetItemPadding is a wrapper around gtk_icon_view_set_item_padding().
func (v *IconView) SetItemPadding(itemPadding int) {
	C.gtk_icon_view_set_item_padding(v.native(), C.gint(itemPadding))
}

// GetItemPadding is a wrapper around gtk_icon_view_get_item_padding().
func (v *IconView) GetItemPadding() int {
	return int(C.gtk_icon_view_get_item_padding(v.native()))
}

// SetActivateOnSingleClick is a wrapper around gtk_icon_view_set_activate_on_single_click().
func (v *IconView) SetActivateOnSingleClick(single bool) {
	C.gtk_icon_view_set_activate_on_single_click(v.native(), gbool(single))
}

// GetActivateOnSingleClick is a wrapper around gtk_icon_view_get_activate_on_single_click().
func (v *IconView) GetActivateOnSingleClick() bool {
	return gobool(C.gtk_icon_view_get_activate_on_single_click(v.native()))
}

// GetCellRect is a wrapper around gtk_icon_view_get_cell_rect().
func (v *IconView) GetCellRect(path *TreePath, cell *CellRenderer) *gdk.Rectangle {
	var crect C.GdkRectangle

	C.gtk_icon_view_get_cell_rect(v.native(), path.native(), cell.native(), &crect)

	return gdk.WrapRectangle(uintptr(unsafe.Pointer(&crect)))
}

// SelectPath is a wrapper around gtk_icon_view_select_path().
func (v *IconView) SelectPath(path *TreePath) {
	C.gtk_icon_view_select_path(v.native(), path.native())
}

// UnselectPath is a wrapper around gtk_icon_view_unselect_path().
func (v *IconView) UnselectPath(path *TreePath) {
	C.gtk_icon_view_unselect_path(v.native(), path.native())
}

// PathIsSelected is a wrapper around gtk_icon_view_path_is_selected().
func (v *IconView) PathIsSelected(path *TreePath) bool {
	return gobool(C.gtk_icon_view_path_is_selected(v.native(), path.native()))
}

// GetSelectedItems is a wrapper around gtk_icon_view_get_selected_items().
func (v *IconView) GetSelectedItems() *glib.List {
	clist := C.gtk_icon_view_get_selected_items(v.native())
	if clist == nil {
		return nil
	}

	glist := glib.WrapList(uintptr(unsafe.Pointer(clist)))
	glist.DataWrapper(func(ptr unsafe.Pointer) interface{} {
		return &TreePath{(*C.GtkTreePath)(ptr)}
	})
	runtime.SetFinalizer(glist, func(glist *glib.List) {
		glib.FinalizerStrategy(func() {
			glist.FreeFull(func(item interface{}) {
				path := item.(*TreePath)
				C.gtk_tree_path_free(path.GtkTreePath)
			})
		})
	})

	return glist
}

// SelectAll is a wrapper around gtk_icon_view_select_all().
func (v *IconView) SelectAll() {
	C.gtk_icon_view_select_all(v.native())
}

// UnselectAll is a wrapper around gtk_icon_view_unselect_all().
func (v *IconView) UnselectAll() {
	C.gtk_icon_view_unselect_all(v.native())
}

// ItemActivated is a wrapper around gtk_icon_view_item_activated().
func (v *IconView) ItemActivated(path *TreePath) {
	C.gtk_icon_view_item_activated(v.native(), path.native())
}

// ScrollToPath is a wrapper around gtk_icon_view_scroll_to_path().
func (v *IconView) ScrollToPath(path *TreePath, useAlign bool, rowAlign, colAlign float64) {
	C.gtk_icon_view_scroll_to_path(v.native(), path.native(), gbool(useAlign),
		C.gfloat(rowAlign), C.gfloat(colAlign))
}

// GetVisibleRange is a wrapper around gtk_icon_view_get_visible_range().
func (v *IconView) GetVisibleRange() (*TreePath, *TreePath) {
	var (
		cpathStart, cpathEnd *C.GtkTreePath
		pathStart, pathEnd   *TreePath
	)

	C.gtk_icon_view_get_visible_range(v.native(), &cpathStart, &cpathEnd)

	if cpathStart != nil {
		pathStart = &TreePath{cpathStart}
		runtime.SetFinalizer(pathStart, func(v *TreePath) { glib.FinalizerStrategy(v.free) })
	}

	if cpathEnd != nil {
		pathEnd = &TreePath{cpathEnd}
		runtime.SetFinalizer(pathEnd, func(v *TreePath) { glib.FinalizerStrategy(v.free) })
	}

	return pathStart, pathEnd
}

// SetTooltipItem is a wrapper around gtk_icon_view_set_tooltip_item().
func (v *IconView) SetTooltipItem(tooltip *Tooltip, path *TreePath) {
	C.gtk_icon_view_set_tooltip_item(v.native(), tooltip.native(), path.native())
}

// SetTooltipCell is a wrapper around gtk_icon_view_set_tooltip_cell().
func (v *IconView) SetTooltipCell(tooltip *Tooltip, path *TreePath, cell *CellRenderer) {
	C.gtk_icon_view_set_tooltip_cell(v.native(), tooltip.native(), path.native(), cell.native())
}

// GetTooltipContext is a wrapper around gtk_icon_view_get_tooltip_context().
func (v *IconView) GetTooltipContext(x, y int, keyboardTip bool) (*TreeModel, *TreePath, *TreeIter) {
	var (
		cmodel *C.GtkTreeModel
		cpath  *C.GtkTreePath
		citer  *C.GtkTreeIter
		model  *TreeModel
		path   *TreePath
		iter   *TreeIter
	)

	px := C.gint(x)
	py := C.gint(y)
	if !gobool(C.gtk_icon_view_get_tooltip_context(v.native(),
		&px,
		&py,
		gbool(keyboardTip),
		&cmodel,
		&cpath,
		citer,
	)) {
		return nil, nil, nil
	}

	if cmodel != nil {
		model = wrapTreeModel(glib.Take(unsafe.Pointer(cmodel)))
	}

	if cpath != nil {
		path = &TreePath{cpath}
		runtime.SetFinalizer(path, func(v *TreePath) { glib.FinalizerStrategy(v.free) })
	}

	if citer != nil {
		iter = &TreeIter{*citer}
		runtime.SetFinalizer(iter, func(v *TreeIter) { glib.FinalizerStrategy(v.free) })
	}

	return model, path, iter
}

// SetTooltipColumn is a wrapper around gtk_icon_view_set_tooltip_column().
func (v *IconView) SetTooltipColumn(column int) {
	C.gtk_icon_view_set_tooltip_column(v.native(), C.gint(column))
}

// GetTooltipColumn is a wrapper around gtk_icon_view_get_tooltip_column().
func (v *IconView) GetTooltipColumn() int {
	return int(C.gtk_icon_view_get_tooltip_column(v.native()))
}

// GetItemRow is a wrapper around gtk_icon_view_get_item_row().
func (v *IconView) GetItemRow(path *TreePath) int {
	return int(C.gtk_icon_view_get_item_row(v.native(), path.native()))
}

// TODO:
// gtk_icon_view_get_item_column().
// gtk_icon_view_enable_model_drag_source().
// func (v *IconView) EnableModelDragSource() {}
// gtk_icon_view_enable_model_drag_dest().
// func (v *IconView) EnableModelDragDest() {}
// gtk_icon_view_unset_model_drag_source().
// func (v *IconView) UnsetModelDragSource() {}
// gtk_icon_view_unset_model_drag_dest().
// func (v *IconView) UnsetModelDragDest() {}

// SetReorderable is a wrapper around gtk_icon_view_set_reorderable().
func (v *IconView) SetReorderable(reorderable bool) {
	C.gtk_icon_view_set_reorderable(v.native(), gbool(reorderable))
}

// GetReorderable is a wrapper around gtk_icon_view_get_reorderable().
func (v *IconView) GetReorderable() bool {
	return gobool(C.gtk_icon_view_get_reorderable(v.native()))
}

// TODO:
// gtk_icon_view_set_drag_dest_item().
// func (v *IconView) SetDragDestItem() {}
// gtk_icon_view_get_drag_dest_item().
// func (v *IconView) GetDragDestItem() {}
// gtk_icon_view_get_dest_item_at_pos().
// func (v *IconView) GetDestItemAtPos() {}
// gtk_icon_view_create_drag_icon().
// func (v *IconView) CreateDragIcon() {}