File: gactionmap.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 (66 lines) | stat: -rw-r--r-- 1,899 bytes parent folder | download | duplicates (2)
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
package glib

// #include <gio/gio.h>
// #include <glib.h>
// #include <glib-object.h>
// #include "glib.go.h"
import "C"
import "unsafe"

// IActionMap is an interface representation of ActionMap,
// used to avoid duplication when embedding the type in a wrapper of another GObject-based type.
type IActionMap interface {
	Native() uintptr

	LookupAction(actionName string) *Action
	AddAction(action IAction)
	RemoveAction(actionName string)
}

// ActionMap is a representation of glib's GActionMap GInterface
type ActionMap struct {
	*Object
}

// void g_action_map_add_action_entries (GActionMap *action_map, const GActionEntry *entries, gint n_entries, gpointer user_data);
// struct GActionEntry

// native() returns a pointer to the underlying GActionMap.
func (v *ActionMap) native() *C.GActionMap {
	if v == nil || v.GObject == nil {
		return nil
	}
	return C.toGActionMap(unsafe.Pointer(v.GObject))
}

func (v *ActionMap) Native() uintptr {
	return uintptr(unsafe.Pointer(v.native()))
}

func marshalActionMap(p uintptr) (interface{}, error) {
	c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
	return wrapActionMap(wrapObject(unsafe.Pointer(c))), nil
}

func wrapActionMap(obj *Object) *ActionMap {
	return &ActionMap{obj}
}

// LookupAction is a wrapper around g_action_map_lookup_action
func (v *ActionMap) LookupAction(actionName string) *Action {
	c := C.g_action_map_lookup_action(v.native(), (*C.gchar)(C.CString(actionName)))
	if c == nil {
		return nil
	}
	return wrapAction(wrapObject(unsafe.Pointer(c)))
}

// AddAction is a wrapper around g_action_map_add_action
func (v *ActionMap) AddAction(action IAction) {
	C.g_action_map_add_action(v.native(), action.toGAction())
}

// RemoveAction is a wrapper around g_action_map_remove_action
func (v *ActionMap) RemoveAction(actionName string) {
	C.g_action_map_remove_action(v.native(), (*C.gchar)(C.CString(actionName)))
}