1// Same copyright and license as the rest of the files in this project
2// This file contains style related functions and structures
3
4package gtk
5
6// #include <gtk/gtk.h>
7// #include "gtk.go.h"
8import "C"
9import (
10	"unsafe"
11
12	"github.com/gotk3/gotk3/pango"
13
14	"github.com/gotk3/gotk3/glib"
15)
16
17/*
18 * GtkLabel
19 */
20
21// Label is a representation of GTK's GtkLabel.
22type Label struct {
23	Widget
24}
25
26// native returns a pointer to the underlying GtkLabel.
27func (v *Label) native() *C.GtkLabel {
28	if v == nil || v.GObject == nil {
29		return nil
30	}
31	p := unsafe.Pointer(v.GObject)
32	return C.toGtkLabel(p)
33}
34
35func marshalLabel(p uintptr) (interface{}, error) {
36	c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
37	obj := glib.Take(unsafe.Pointer(c))
38	return wrapLabel(obj), nil
39}
40
41func wrapLabel(obj *glib.Object) *Label {
42	return &Label{Widget{glib.InitiallyUnowned{obj}}}
43}
44
45func WidgetToLabel(widget *Widget) (interface{}, error) {
46	obj := glib.Take(unsafe.Pointer(widget.GObject))
47	return wrapLabel(obj), nil
48}
49
50// LabelNew is a wrapper around gtk_label_new().
51func LabelNew(str string) (*Label, error) {
52	cstr := C.CString(str)
53	defer C.free(unsafe.Pointer(cstr))
54	c := C.gtk_label_new((*C.gchar)(cstr))
55	if c == nil {
56		return nil, nilPtrErr
57	}
58	obj := glib.Take(unsafe.Pointer(c))
59	return wrapLabel(obj), nil
60}
61
62// SetText is a wrapper around gtk_label_set_text().
63func (v *Label) SetText(str string) {
64	cstr := C.CString(str)
65	defer C.free(unsafe.Pointer(cstr))
66	C.gtk_label_set_text(v.native(), (*C.gchar)(cstr))
67}
68
69// SetMarkup is a wrapper around gtk_label_set_markup().
70func (v *Label) SetMarkup(str string) {
71	cstr := C.CString(str)
72	defer C.free(unsafe.Pointer(cstr))
73	C.gtk_label_set_markup(v.native(), (*C.gchar)(cstr))
74}
75
76// SetMarkupWithMnemonic is a wrapper around
77// gtk_label_set_markup_with_mnemonic().
78func (v *Label) SetMarkupWithMnemonic(str string) {
79	cstr := C.CString(str)
80	defer C.free(unsafe.Pointer(cstr))
81	C.gtk_label_set_markup_with_mnemonic(v.native(), (*C.gchar)(cstr))
82}
83
84// SetPattern is a wrapper around gtk_label_set_pattern().
85func (v *Label) SetPattern(patern string) {
86	cstr := C.CString(patern)
87	defer C.free(unsafe.Pointer(cstr))
88	C.gtk_label_set_pattern(v.native(), (*C.gchar)(cstr))
89}
90
91// SetJustify is a wrapper around gtk_label_set_justify().
92func (v *Label) SetJustify(jtype Justification) {
93	C.gtk_label_set_justify(v.native(), C.GtkJustification(jtype))
94}
95
96// SetEllipsize is a wrapper around gtk_label_set_ellipsize().
97func (v *Label) SetEllipsize(mode pango.EllipsizeMode) {
98	C.gtk_label_set_ellipsize(v.native(), C.PangoEllipsizeMode(mode))
99}
100
101// GetWidthChars is a wrapper around gtk_label_get_width_chars().
102func (v *Label) GetWidthChars() int {
103	c := C.gtk_label_get_width_chars(v.native())
104	return int(c)
105}
106
107// SetWidthChars is a wrapper around gtk_label_set_width_chars().
108func (v *Label) SetWidthChars(nChars int) {
109	C.gtk_label_set_width_chars(v.native(), C.gint(nChars))
110}
111
112// GetMaxWidthChars is a wrapper around gtk_label_get_max_width_chars().
113func (v *Label) GetMaxWidthChars() int {
114	c := C.gtk_label_get_max_width_chars(v.native())
115	return int(c)
116}
117
118// SetMaxWidthChars is a wrapper around gtk_label_set_max_width_chars().
119func (v *Label) SetMaxWidthChars(nChars int) {
120	C.gtk_label_set_max_width_chars(v.native(), C.gint(nChars))
121}
122
123// GetLineWrap is a wrapper around gtk_label_get_line_wrap().
124func (v *Label) GetLineWrap() bool {
125	c := C.gtk_label_get_line_wrap(v.native())
126	return gobool(c)
127}
128
129// SetLineWrap is a wrapper around gtk_label_set_line_wrap().
130func (v *Label) SetLineWrap(wrap bool) {
131	C.gtk_label_set_line_wrap(v.native(), gbool(wrap))
132}
133
134// SetLineWrapMode is a wrapper around gtk_label_set_line_wrap_mode().
135func (v *Label) SetLineWrapMode(wrapMode pango.WrapMode) {
136	C.gtk_label_set_line_wrap_mode(v.native(), C.PangoWrapMode(wrapMode))
137}
138
139// GetSelectable is a wrapper around gtk_label_get_selectable().
140func (v *Label) GetSelectable() bool {
141	c := C.gtk_label_get_selectable(v.native())
142	return gobool(c)
143}
144
145// GetText is a wrapper around gtk_label_get_text().
146func (v *Label) GetText() (string, error) {
147	c := C.gtk_label_get_text(v.native())
148	if c == nil {
149		return "", nilPtrErr
150	}
151	return C.GoString((*C.char)(c)), nil
152}
153
154// GetJustify is a wrapper around gtk_label_get_justify().
155func (v *Label) GetJustify() Justification {
156	c := C.gtk_label_get_justify(v.native())
157	return Justification(c)
158}
159
160// GetEllipsize is a wrapper around gtk_label_get_ellipsize().
161func (v *Label) GetEllipsize() pango.EllipsizeMode {
162	c := C.gtk_label_get_ellipsize(v.native())
163	return pango.EllipsizeMode(c)
164}
165
166// GetCurrentUri is a wrapper around gtk_label_get_current_uri().
167func (v *Label) GetCurrentUri() string {
168	c := C.gtk_label_get_current_uri(v.native())
169	return C.GoString((*C.char)(c))
170}
171
172// GetTrackVisitedLinks is a wrapper around gtk_label_get_track_visited_links().
173func (v *Label) GetTrackVisitedLinks() bool {
174	c := C.gtk_label_get_track_visited_links(v.native())
175	return gobool(c)
176}
177
178// SetTrackVisitedLinks is a wrapper around gtk_label_set_track_visited_links().
179func (v *Label) SetTrackVisitedLinks(trackLinks bool) {
180	C.gtk_label_set_track_visited_links(v.native(), gbool(trackLinks))
181}
182
183// GetAngle is a wrapper around gtk_label_get_angle().
184func (v *Label) GetAngle() float64 {
185	c := C.gtk_label_get_angle(v.native())
186	return float64(c)
187}
188
189// SetAngle is a wrapper around gtk_label_set_angle().
190func (v *Label) SetAngle(angle float64) {
191	C.gtk_label_set_angle(v.native(), C.gdouble(angle))
192}
193
194// GetSelectionBounds is a wrapper around gtk_label_get_selection_bounds().
195func (v *Label) GetSelectionBounds() (start, end int, nonEmpty bool) {
196	var cstart, cend C.gint
197	c := C.gtk_label_get_selection_bounds(v.native(), &cstart, &cend)
198	return int(cstart), int(cend), gobool(c)
199}
200
201// GetSingleLineMode is a wrapper around gtk_label_get_single_line_mode().
202func (v *Label) GetSingleLineMode() bool {
203	c := C.gtk_label_get_single_line_mode(v.native())
204	return gobool(c)
205}
206
207// SetSingleLineMode is a wrapper around gtk_label_set_single_line_mode().
208func (v *Label) SetSingleLineMode(mode bool) {
209	C.gtk_label_set_single_line_mode(v.native(), gbool(mode))
210}
211
212// GetUseMarkup is a wrapper around gtk_label_get_use_markup().
213func (v *Label) GetUseMarkup() bool {
214	c := C.gtk_label_get_use_markup(v.native())
215	return gobool(c)
216}
217
218// SetUseMarkup is a wrapper around gtk_label_set_use_markup().
219func (v *Label) SetUseMarkup(use bool) {
220	C.gtk_label_set_use_markup(v.native(), gbool(use))
221}
222
223// GetUseUnderline is a wrapper around gtk_label_get_use_underline().
224func (v *Label) GetUseUnderline() bool {
225	c := C.gtk_label_get_use_underline(v.native())
226	return gobool(c)
227}
228
229// SetUseUnderline is a wrapper around gtk_label_set_use_underline().
230func (v *Label) SetUseUnderline(use bool) {
231	C.gtk_label_set_use_underline(v.native(), gbool(use))
232}
233
234// LabelNewWithMnemonic is a wrapper around gtk_label_new_with_mnemonic().
235func LabelNewWithMnemonic(str string) (*Label, error) {
236	cstr := C.CString(str)
237	defer C.free(unsafe.Pointer(cstr))
238	c := C.gtk_label_new_with_mnemonic((*C.gchar)(cstr))
239	if c == nil {
240		return nil, nilPtrErr
241	}
242	obj := glib.Take(unsafe.Pointer(c))
243	return wrapLabel(obj), nil
244}
245
246// SelectRegion is a wrapper around gtk_label_select_region().
247func (v *Label) SelectRegion(startOffset, endOffset int) {
248	C.gtk_label_select_region(v.native(), C.gint(startOffset),
249		C.gint(endOffset))
250}
251
252// SetSelectable is a wrapper around gtk_label_set_selectable().
253func (v *Label) SetSelectable(setting bool) {
254	C.gtk_label_set_selectable(v.native(), gbool(setting))
255}
256
257// SetLabel is a wrapper around gtk_label_set_label().
258func (v *Label) SetLabel(str string) {
259	cstr := C.CString(str)
260	defer C.free(unsafe.Pointer(cstr))
261	C.gtk_label_set_label(v.native(), (*C.gchar)(cstr))
262}
263
264// GetLabel is a wrapper around gtk_label_get_label().
265func (v *Label) GetLabel() string {
266	c := C.gtk_label_get_label(v.native())
267	if c == nil {
268		return ""
269	}
270	return C.GoString((*C.char)(c))
271}
272
273// GetMnemonicKeyval is a wrapper around gtk_label_get_mnemonic_keyval().
274func (v *Label) GetMnemonicKeyval() uint {
275	return uint(C.gtk_label_get_mnemonic_keyval(v.native()))
276}
277
278// SetMnemonicWidget is a wrapper around gtk_label_set_mnemonic_widget().
279func (v *Label) SetMnemonicWidget(widget IWidget) {
280	C.gtk_label_set_mnemonic_widget(v.native(), widget.toWidget())
281}
282