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 if obj == nil { 43 return nil 44 } 45 46 return &Label{Widget{glib.InitiallyUnowned{obj}}} 47} 48 49// WidgetToLabel is a convience func that casts the given *Widget into a *Label. 50func WidgetToLabel(widget *Widget) (*Label, error) { 51 obj := glib.Take(unsafe.Pointer(widget.GObject)) 52 return wrapLabel(obj), nil 53} 54 55// LabelNew is a wrapper around gtk_label_new(). 56func LabelNew(str string) (*Label, error) { 57 cstr := C.CString(str) 58 defer C.free(unsafe.Pointer(cstr)) 59 c := C.gtk_label_new((*C.gchar)(cstr)) 60 if c == nil { 61 return nil, nilPtrErr 62 } 63 obj := glib.Take(unsafe.Pointer(c)) 64 return wrapLabel(obj), nil 65} 66 67// SetText is a wrapper around gtk_label_set_text(). 68func (v *Label) SetText(str string) { 69 cstr := C.CString(str) 70 defer C.free(unsafe.Pointer(cstr)) 71 C.gtk_label_set_text(v.native(), (*C.gchar)(cstr)) 72} 73 74// TODO: 75// gtk_label_set_text_with_mnemonic(). 76// gtk_label_get_attributes(). 77func (v *Label) SetAttributes(attributes *pango.AttrList) { 78 C.gtk_label_set_attributes(v.native(), (*C.PangoAttrList)(unsafe.Pointer(attributes.Native()))) 79} 80 81// SetMarkup is a wrapper around gtk_label_set_markup(). 82func (v *Label) SetMarkup(str string) { 83 cstr := C.CString(str) 84 defer C.free(unsafe.Pointer(cstr)) 85 C.gtk_label_set_markup(v.native(), (*C.gchar)(cstr)) 86} 87 88// SetMarkupWithMnemonic is a wrapper around 89// gtk_label_set_markup_with_mnemonic(). 90func (v *Label) SetMarkupWithMnemonic(str string) { 91 cstr := C.CString(str) 92 defer C.free(unsafe.Pointer(cstr)) 93 C.gtk_label_set_markup_with_mnemonic(v.native(), (*C.gchar)(cstr)) 94} 95 96// SetPattern is a wrapper around gtk_label_set_pattern(). 97func (v *Label) SetPattern(patern string) { 98 cstr := C.CString(patern) 99 defer C.free(unsafe.Pointer(cstr)) 100 C.gtk_label_set_pattern(v.native(), (*C.gchar)(cstr)) 101} 102 103// SetJustify is a wrapper around gtk_label_set_justify(). 104func (v *Label) SetJustify(jtype Justification) { 105 C.gtk_label_set_justify(v.native(), C.GtkJustification(jtype)) 106} 107 108// SetEllipsize is a wrapper around gtk_label_set_ellipsize(). 109func (v *Label) SetEllipsize(mode pango.EllipsizeMode) { 110 C.gtk_label_set_ellipsize(v.native(), C.PangoEllipsizeMode(mode)) 111} 112 113// GetWidthChars is a wrapper around gtk_label_get_width_chars(). 114func (v *Label) GetWidthChars() int { 115 c := C.gtk_label_get_width_chars(v.native()) 116 return int(c) 117} 118 119// SetWidthChars is a wrapper around gtk_label_set_width_chars(). 120func (v *Label) SetWidthChars(nChars int) { 121 C.gtk_label_set_width_chars(v.native(), C.gint(nChars)) 122} 123 124// GetMaxWidthChars is a wrapper around gtk_label_get_max_width_chars(). 125func (v *Label) GetMaxWidthChars() int { 126 c := C.gtk_label_get_max_width_chars(v.native()) 127 return int(c) 128} 129 130// SetMaxWidthChars is a wrapper around gtk_label_set_max_width_chars(). 131func (v *Label) SetMaxWidthChars(nChars int) { 132 C.gtk_label_set_max_width_chars(v.native(), C.gint(nChars)) 133} 134 135// GetLineWrap is a wrapper around gtk_label_get_line_wrap(). 136func (v *Label) GetLineWrap() bool { 137 c := C.gtk_label_get_line_wrap(v.native()) 138 return gobool(c) 139} 140 141// SetLineWrap is a wrapper around gtk_label_set_line_wrap(). 142func (v *Label) SetLineWrap(wrap bool) { 143 C.gtk_label_set_line_wrap(v.native(), gbool(wrap)) 144} 145 146// SetLineWrapMode is a wrapper around gtk_label_set_line_wrap_mode(). 147func (v *Label) SetLineWrapMode(wrapMode pango.WrapMode) { 148 C.gtk_label_set_line_wrap_mode(v.native(), C.PangoWrapMode(wrapMode)) 149} 150 151// TODO: 152// gtk_label_get_line_wrap_mode(). 153// gtk_label_get_layout_offsets(). 154// gtk_label_get_layout(). 155// gtk_label_get_mnemonic_widget(). 156 157// GetSelectable is a wrapper around gtk_label_get_selectable(). 158func (v *Label) GetSelectable() bool { 159 c := C.gtk_label_get_selectable(v.native()) 160 return gobool(c) 161} 162 163// GetText is a wrapper around gtk_label_get_text(). 164func (v *Label) GetText() (string, error) { 165 c := C.gtk_label_get_text(v.native()) 166 if c == nil { 167 return "", nilPtrErr 168 } 169 return C.GoString((*C.char)(c)), nil 170} 171 172// GetJustify is a wrapper around gtk_label_get_justify(). 173func (v *Label) GetJustify() Justification { 174 c := C.gtk_label_get_justify(v.native()) 175 return Justification(c) 176} 177 178// GetEllipsize is a wrapper around gtk_label_get_ellipsize(). 179func (v *Label) GetEllipsize() pango.EllipsizeMode { 180 c := C.gtk_label_get_ellipsize(v.native()) 181 return pango.EllipsizeMode(c) 182} 183 184// GetCurrentUri is a wrapper around gtk_label_get_current_uri(). 185func (v *Label) GetCurrentUri() string { 186 c := C.gtk_label_get_current_uri(v.native()) 187 return C.GoString((*C.char)(c)) 188} 189 190// GetTrackVisitedLinks is a wrapper around gtk_label_get_track_visited_links(). 191func (v *Label) GetTrackVisitedLinks() bool { 192 c := C.gtk_label_get_track_visited_links(v.native()) 193 return gobool(c) 194} 195 196// SetTrackVisitedLinks is a wrapper around gtk_label_set_track_visited_links(). 197func (v *Label) SetTrackVisitedLinks(trackLinks bool) { 198 C.gtk_label_set_track_visited_links(v.native(), gbool(trackLinks)) 199} 200 201// GetAngle is a wrapper around gtk_label_get_angle(). 202func (v *Label) GetAngle() float64 { 203 c := C.gtk_label_get_angle(v.native()) 204 return float64(c) 205} 206 207// SetAngle is a wrapper around gtk_label_set_angle(). 208func (v *Label) SetAngle(angle float64) { 209 C.gtk_label_set_angle(v.native(), C.gdouble(angle)) 210} 211 212// GetSelectionBounds is a wrapper around gtk_label_get_selection_bounds(). 213func (v *Label) GetSelectionBounds() (start, end int, nonEmpty bool) { 214 var cstart, cend C.gint 215 c := C.gtk_label_get_selection_bounds(v.native(), &cstart, &cend) 216 return int(cstart), int(cend), gobool(c) 217} 218 219// GetSingleLineMode is a wrapper around gtk_label_get_single_line_mode(). 220func (v *Label) GetSingleLineMode() bool { 221 c := C.gtk_label_get_single_line_mode(v.native()) 222 return gobool(c) 223} 224 225// SetSingleLineMode is a wrapper around gtk_label_set_single_line_mode(). 226func (v *Label) SetSingleLineMode(mode bool) { 227 C.gtk_label_set_single_line_mode(v.native(), gbool(mode)) 228} 229 230// GetUseMarkup is a wrapper around gtk_label_get_use_markup(). 231func (v *Label) GetUseMarkup() bool { 232 c := C.gtk_label_get_use_markup(v.native()) 233 return gobool(c) 234} 235 236// SetUseMarkup is a wrapper around gtk_label_set_use_markup(). 237func (v *Label) SetUseMarkup(use bool) { 238 C.gtk_label_set_use_markup(v.native(), gbool(use)) 239} 240 241// GetUseUnderline is a wrapper around gtk_label_get_use_underline(). 242func (v *Label) GetUseUnderline() bool { 243 c := C.gtk_label_get_use_underline(v.native()) 244 return gobool(c) 245} 246 247// SetUseUnderline is a wrapper around gtk_label_set_use_underline(). 248func (v *Label) SetUseUnderline(use bool) { 249 C.gtk_label_set_use_underline(v.native(), gbool(use)) 250} 251 252// LabelNewWithMnemonic is a wrapper around gtk_label_new_with_mnemonic(). 253func LabelNewWithMnemonic(str string) (*Label, error) { 254 cstr := C.CString(str) 255 defer C.free(unsafe.Pointer(cstr)) 256 c := C.gtk_label_new_with_mnemonic((*C.gchar)(cstr)) 257 if c == nil { 258 return nil, nilPtrErr 259 } 260 obj := glib.Take(unsafe.Pointer(c)) 261 return wrapLabel(obj), nil 262} 263 264// SelectRegion is a wrapper around gtk_label_select_region(). 265func (v *Label) SelectRegion(startOffset, endOffset int) { 266 C.gtk_label_select_region(v.native(), C.gint(startOffset), 267 C.gint(endOffset)) 268} 269 270// SetSelectable is a wrapper around gtk_label_set_selectable(). 271func (v *Label) SetSelectable(setting bool) { 272 C.gtk_label_set_selectable(v.native(), gbool(setting)) 273} 274 275// SetLabel is a wrapper around gtk_label_set_label(). 276func (v *Label) SetLabel(str string) { 277 cstr := C.CString(str) 278 defer C.free(unsafe.Pointer(cstr)) 279 C.gtk_label_set_label(v.native(), (*C.gchar)(cstr)) 280} 281 282// GetLabel is a wrapper around gtk_label_get_label(). 283func (v *Label) GetLabel() string { 284 c := C.gtk_label_get_label(v.native()) 285 if c == nil { 286 return "" 287 } 288 return C.GoString((*C.char)(c)) 289} 290 291// GetMnemonicKeyval is a wrapper around gtk_label_get_mnemonic_keyval(). 292func (v *Label) GetMnemonicKeyval() uint { 293 return uint(C.gtk_label_get_mnemonic_keyval(v.native())) 294} 295 296// SetMnemonicWidget is a wrapper around gtk_label_set_mnemonic_widget(). 297func (v *Label) SetMnemonicWidget(widget IWidget) { 298 C.gtk_label_set_mnemonic_widget(v.native(), widget.toWidget()) 299} 300