summaryrefslogtreecommitdiff
path: root/vendor/github.com/gotk3/gotk3/gtk/actionable.go
blob: 70b357d0764e8bdc463e76bed4a96b4dcace2e43 (plain)
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
package gtk

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

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

func init() {
	tm := []glib.TypeMarshaler{
		{glib.Type(C.gtk_actionable_get_type()), marshalActionable},
	}

	glib.RegisterGValueMarshalers(tm)

	WrapMap["GtkActionable"] = marshalActionable
}

// IActionable is a representation of the GtkActionable GInterface,
// used to avoid duplication when embedding the type in a wrapper of another GObject-based type.
// The non-Interface version should only be used Actionable is used if the concrete type is not known.
type IActionable interface {
	Native() uintptr
	toActionable() *C.GtkActionable

	SetActionName(name string)
	GetActionName() (string, error)
	// SetActionTargetValue(value *glib.Variant)
	// GetActionTargetValue() (*glib.Variant, error)
	// SetActionTarget(string, params...)
	SetDetailedActionName(name string)
}

// Actionable is a representation of the GtkActionable GInterface.
// Do not embed this concrete type in implementing structs but rather use IActionable
// (see Button wrapper for an example)
type Actionable struct {
	*glib.Object
}

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

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

func wrapActionable(obj *glib.Object) *Actionable {
	return &Actionable{obj}
}

func (v *Actionable) toActionable() *C.GtkActionable {
	if v == nil {
		return nil
	}
	return v.native()
}

// SetActionName is a wrapper around gtk_actionable_set_action_name().
// Since 3.4
func (v *Actionable) SetActionName(action_name string) {
	cstr := C.CString(action_name)
	defer C.free(unsafe.Pointer(cstr))
	C.gtk_actionable_set_action_name(v.native(), (*C.gchar)(cstr))
}

// GetActionName is a wrapper around gtk_actionable_set_action_name().
// Since 3.4
func (v *Actionable) GetActionName() (string, error) {
	c := C.gtk_actionable_get_action_name(v.native())
	if c == nil {
		return "", nilPtrErr
	}
	return C.GoString((*C.char)(c)), nil
}

// SetDetailedActionName is a wrapper around gtk_actionable_set_detailed_action_name().
// Since 3.4
func (v *Actionable) SetDetailedActionName(detailed_action_name string) {
	cstr := C.CString(detailed_action_name)
	defer C.free(unsafe.Pointer(cstr))
	C.gtk_actionable_set_detailed_action_name(v.native(), (*C.gchar)(cstr))
}

// SetActionTargetValue is a wrapper around gtk_actionable_set_action_target_value().
// Since 3.4
/*func (v *Actionable) SetActionTargetValue(value *glib.Variant) {
	// FIXME ToGVariant does not work here
	C.gtk_actionable_set_action_target_value(v.native(), value.ToGVariant())
}*/

// GetActionTargetValue is a wrapper around gtk_actionable_get_action_target_value().
// Since 3.4
/*func (v *Actionable) GetActionTargetValue() (*glib.Variant, error) {
	// FIXME: newVariant is not exported from glib
	return newVariant(C.gtk_actionable_get_action_target_value(v.native(), cstr))
}*/

/*
// Since 3.4
void
gtk_actionable_set_action_target (GtkActionable *actionable,
                                  const gchar *format_string,
								  ...);
*/