File: font_chooser.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 (276 lines) | stat: -rw-r--r-- 7,134 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
package gtk

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

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

func init() {
	tm := []glib.TypeMarshaler{
		{glib.Type(C.gtk_font_chooser_get_type()), marshalFontChooser},
		{glib.Type(C.gtk_font_button_get_type()), marshalFontButton},
	}

	glib.RegisterGValueMarshalers(tm)

	WrapMap["GtkFontChooser"] = wrapFontChooser
	WrapMap["GtkFontButton"] = wrapFontButton

}

/*
 * GtkFontChooser
 */

// FontChooser is a representation of GTK's GtkFontChooser GInterface.
type FontChooser struct {
	*glib.Object
}

// IFontChooser is an interface type implemented by all structs
// embedding an FontChooser. It is meant to be used as an argument type
// for wrapper functions that wrap around a C GTK function taking a
// GtkFontChooser.
type IFontChooser interface {
	toFontChooser() *C.GtkFontChooser
}

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

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

func wrapFontChooser(obj *glib.Object) *FontChooser {
	if obj == nil {
		return nil
	}

	return &FontChooser{obj}
}

func (v *FontChooser) toFontChooser() *C.GtkFontChooser {
	if v == nil {
		return nil
	}
	return v.native()
}

// GetFont is a wrapper around gtk_font_chooser_get_font().
func (v *FontChooser) GetFont() string {
	c := C.gtk_font_chooser_get_font(v.native())
	return goString(c)
}

// SetFont is a wrapper around gtk_font_chooser_set_font().
func (v *FontChooser) SetFont(font string) {
	cstr := C.CString(font)
	defer C.free(unsafe.Pointer(cstr))
	C.gtk_font_chooser_set_font(v.native(), (*C.gchar)(cstr))
}

//PangoFontFamily *	gtk_font_chooser_get_font_family ()
//PangoFontFace *	gtk_font_chooser_get_font_face ()
//gint	gtk_font_chooser_get_font_size ()
//PangoFontDescription *	gtk_font_chooser_get_font_desc ()
//void	gtk_font_chooser_set_font_desc ()
//gchar *	gtk_font_chooser_get_preview_text ()
//void	gtk_font_chooser_set_preview_text ()
//gboolean	gtk_font_chooser_get_show_preview_entry ()
//void	gtk_font_chooser_set_show_preview_entry ()
//gboolean	(*GtkFontFilterFunc) ()
//void	gtk_font_chooser_set_filter_func ()
//void	gtk_font_chooser_set_font_map ()
//PangoFontMap *	gtk_font_chooser_get_font_map ()

/*
 * GtkFontButton
 */

// FontButton is a representation of GTK's GtkFontButton.
type FontButton struct {
	Button

	// Interfaces
	FontChooser
}

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

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

func wrapFontButton(obj *glib.Object) *FontButton {
	if obj == nil {
		return nil
	}

	button := wrapButton(obj)
	fc := wrapFontChooser(obj)
	return &FontButton{*button, *fc}
}

// FontButtonNew is a wrapper around gtk_font_button_new().
func FontButtonNew() (*FontButton, error) {
	c := C.gtk_font_button_new()
	if c == nil {
		return nil, nilPtrErr
	}
	obj := glib.Take(unsafe.Pointer(c))
	return wrapFontButton(obj), nil
}

// FontButtonNewWithFont is a wrapper around gtk_font_button_new_with_font().
func FontButtonNewWithFont(fontname string) (*FontButton, error) {
	cstr := C.CString(fontname)
	defer C.free(unsafe.Pointer(cstr))
	c := C.gtk_font_button_new_with_font((*C.gchar)(cstr))
	if c == nil {
		return nil, nilPtrErr
	}
	obj := glib.Take(unsafe.Pointer(c))
	return wrapFontButton(obj), nil
}

// SetShowStyle is a wrapper around gtk_font_button_set_show_style().
func (v *FontButton) SetShowStyle(showStyle bool) {
	C.gtk_font_button_set_show_style(v.native(), gbool(showStyle))
}

// GetShowStyle is a wrapper around gtk_font_button_get_show_style().
func (v *FontButton) GetShowStyle() bool {
	c := C.gtk_font_button_get_show_style(v.native())
	return gobool(c)
}

// SetShowSize is a wrapper around gtk_font_button_set_show_size().
func (v *FontButton) SetShowSize(showSize bool) {
	C.gtk_font_button_set_show_size(v.native(), gbool(showSize))
}

// GetShowSize is a wrapper around gtk_font_button_get_show_size().
func (v *FontButton) GetShowSize() bool {
	c := C.gtk_font_button_get_show_size(v.native())
	return gobool(c)
}

// SetUseFont is a wrapper around gtk_font_button_set_use_font().
func (v *FontButton) SetUseFont(useFont bool) {
	C.gtk_font_button_set_use_font(v.native(), gbool(useFont))
}

// GetUseFont is a wrapper around gtk_font_button_get_use_font().
func (v *FontButton) GetUseFont() bool {
	c := C.gtk_font_button_get_use_font(v.native())
	return gobool(c)
}

// SetUseSize is a wrapper around gtk_font_button_set_use_size().
func (v *FontButton) SetUseSize(useSize bool) {
	C.gtk_font_button_set_use_size(v.native(), gbool(useSize))
}

// GetUseSize is a wrapper around gtk_font_button_get_use_size().
func (v *FontButton) GetUseSize() bool {
	c := C.gtk_font_button_get_use_size(v.native())
	return gobool(c)
}

// SetTitle is a wrapper around gtk_font_button_set_title().
func (v *FontButton) SetTitle(title string) {
	cstr := C.CString(title)
	defer C.free(unsafe.Pointer(cstr))
	C.gtk_font_button_set_title(v.native(), (*C.gchar)(cstr))
}

// GetTitle is a wrapper around gtk_font_button_get_title().
func (v *FontButton) GetTitle() string {
	c := C.gtk_font_button_get_title(v.native())
	defer C.free(unsafe.Pointer(c))
	return goString(c)
}

/*
 * GtkFontChooserDialog
 */

// FontChooserDialog is a representation of GTK's GtkFontChooserDialog.
type FontChooserDialog struct {
	Dialog

	// Interfaces
	FontChooser
}

// native returns a pointer to the underlying GtkFontChooserDialog.
func (v *FontChooserDialog) native() *C.GtkFontChooserDialog {
	if v == nil || v.GObject == nil {
		return nil
	}

	p := unsafe.Pointer(v.GObject)
	return C.toGtkFontChooserDialog(p)
}

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

func wrapFontChooserDialog(obj *glib.Object) *FontChooserDialog {
	if obj == nil {
		return nil
	}

	dialog := wrapDialog(obj)
	cc := wrapFontChooser(obj)
	return &FontChooserDialog{*dialog, *cc}
}

// FontChooserDialogNew() is a wrapper around gtk_font_chooser_dialog_new().
func FontChooserDialogNew(title string, parent IWindow) (*FontChooserDialog, error) {

	cstr := C.CString(title)
	defer C.free(unsafe.Pointer(cstr))

	var w *C.GtkWindow = nil
	if parent != nil {
		w = parent.toWindow()
	}

	c := C.gtk_font_chooser_dialog_new((*C.gchar)(cstr), w)
	if c == nil {
		return nil, nilPtrErr
	}
	return wrapFontChooserDialog(glib.Take(unsafe.Pointer(c))), nil
}

/*
 * GtkFontChooserWidget
 */

// TODO:
// gtk_font_chooser_widget_new().