Codebase list golang-github-gotk3-gotk3 / 388e54c
New upstream version 0.6.1 Sascha Steinbiss 2 years ago
217 changed file(s) with 16584 addition(s) and 5316 deletion(s). Raw diff Collapse all Expand all
0 ---
1 name: Bug report
2 about: Create a report to help us improve
3 title: "[BUG] title"
4 labels: bug
5 assignees: ''
6
7 ---
8
9 **Describe the bug**
10 A clear and concise description of what the bug is.
11
12 **To Reproduce**
13 Steps to reproduce the behavior:
14
15
16 **Expected behavior**
17 A clear and concise description of what you expected to happen.
18
19 **Error messages**
20 If applicable, add copy the log message to help explain your problem.
21
22 **Environment:**
23 gtk3 version: '...'
24 go version: '...'
25 os: '...'
26 other stuff: '...'
27
28 **Additional context**
29 Add any other context about the problem here.
0 ---
1 name: Feature request
2 about: Suggest an idea for this project
3 title: "[Feature] title"
4 labels: enhancement, missing binding
5 assignees: ''
6
7 ---
8
9 **Is your feature request related to a problem? Please describe.**
10 A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
11
12 **Describe the solution you'd like**
13 A clear and concise description of what you want to happen.
14
15 **Describe alternatives you've considered**
16 A clear and concise description of any alternative solutions or features you've considered.
17
18 **Additional context**
19 Add any other context or screenshots about the feature request here.
0 ---
1 name: Project question
2 about: Do you have a question then ask this one here
3 title: "[Project question] title"
4 labels: question
5 assignees: ''
6
7 ---
8
9 Help us make this better
0 ./idea/*
0 .vscode
1 .idea
2
66
77 jobs:
88 include:
9 # Testing on trusty, gtk 3.10
10 - os: linux
11 dist: trusty
12 go: "1.13"
13
14 # Testing on xenial, gtk 3.18
9 # Testing on xenial, gtk 3.18.9 (gdk has same version), glib 2.48.0 (gio has same version), gdk-pixbuf 2.32.2
1510 - os: linux
1611 dist: xenial
1712 go: "1.13"
1813
19 # Testing on bionic, gtk 3.22
14 # Testing on bionic, gtk 3.22.30 (gdk has same version), glib 2.56.1 (gio has same version), gdk-pixbuf 2.36.11
15 - os: linux
16 dist: bionic
17 go: "1.14"
18
19 # Testing on focal, gtk 3.24.14 (gdk has same version), glib 2.64.1 (gio has same version), gdk-pixbuf 2.40.0
2020 # Majority of the go versions here for compatibility checking
2121 - os: linux
22 dist: bionic
23 go: "1.8"
24 - os: linux
25 dist: bionic
26 go: "1.9"
27 - os: linux
28 dist: bionic
29 go: "1.10"
30 - os: linux
31 dist: bionic
32 go: "1.11"
33 - os: linux
34 dist: bionic
22 dist: focal
3523 go: "1.12"
3624 - os: linux
37 dist: bionic
25 dist: focal
3826 go: "1.13"
3927 - os: linux
40 dist: bionic
28 dist: focal
29 go: "1.14"
30 - os: linux
31 dist: focal
32 go: "1.15"
33 - os: linux
34 dist: focal
4135 go: tip
4236
4337 addons:
4943
5044 before_install:
5145 - "export DISPLAY=:99.0"
52 - sudo /usr/bin/Xvfb $DISPLAY 2>1 > /dev/null &
46 - sudo /usr/bin/Xvfb $DISPLAY &> /dev/null &
5347 - "export GTK_VERSION=$(pkg-config --modversion gtk+-3.0 | tr . _| cut -d '_' -f 1-2)"
54 - "export Glib_VERSION=$(pkg-config --modversion glib-2.0)"
48 - "export Glib_VERSION=$(pkg-config --modversion glib-2.0 | tr . _| cut -d '_' -f 1-2)"
49 - "export GDK_Pixbuf_VERSION=$(pkg-config --modversion gdk-pixbuf-2.0 | tr . _| cut -d '_' -f 1-2)"
5550 - "export Cairo_VERSION=$(pkg-config --modversion cairo)"
5651 - "export Pango_VERSION=$(pkg-config --modversion pango)"
57 - echo "GTK version ${GTK_VERSION} (Glib ${Glib_VERSION}, Cairo ${Cairo_VERSION}, Pango ${Pango_VERSION})"
52 - echo "GTK/GDK version ${GTK_VERSION} Glib/Gio version ${Glib_VERSION} Gdk-Pixbuf version ${GDK_Pixbuf_VERSION} (Cairo ${Cairo_VERSION}, Pango ${Pango_VERSION})"
5853
5954 install:
60 - go get -t -tags "gtk_${GTK_VERSION}" ./...
55 - go get -t -tags "gtk_${GTK_VERSION} glib_${Glib_VERSION} gdk_pixbuf_${GDK_Pixbuf_VERSION}" ./...
6156
6257 script:
63 - go test -tags "gtk_${GTK_VERSION}" ./...
58 - go test -tags "gtk_${GTK_VERSION} glib_${Glib_VERSION} gdk_pixbuf_${GDK_Pixbuf_VERSION}" ./...
22 Go bindings for GTK3
33 ============================================================================
44
5 Changes for next Version
6 - Add new binding support
7 - gdk: fix memory leak in Pixbuf finalizers
8 - gdk: new functions for Pixbuf: ApplyEmbeddedOrientation, SaveJPEG, SavePNG
9 - gdk: PixbufLoader wrapper
10 - gtk: new functions for Adjustment: GetPageSize, SetPageSize, Configure
11 - gtk: new functions for Range: SetIncrements, SetRange
12 - gtk: new wrappers: IRecentChooser, RecentChooser, RecentChooserMenu,
13 - gtk: RecentFilter, RecentManager, IScrollable, Scrollable, IViewport, Viewport, Allocation
14 - gtk: new function for ScrolledWindow: SetHAdjustment
15 - gtk: new function for SpinButton: SetIncrements
16 - gtk: new functions for Widget: GetAllocation, SetAllocation, SizeAllocate
17 - gtk: new function RecentChooser
18 - gtk: added Widget.GetStyleContext, new wrappers for GtkCssProvider
19 - API Break Warning: no longer support for gtk 3.16 deprecated mark functions/elements
20
21 Changes in 0.3.0 (Wed Jun 10 2015)
22 - API Break Warning: function signatures changed
23 - Add new binding support
24 - GtkBuilder
25 - GtkButton
26 - GtkCellRenderer
27 - GtkStatusIcon
28 - GtkStatusbar
29 - GtkTreeView
30 - better and more support for cairo
31 - better and more support for pango
32
33 Changes in 0.2.0 (Mon Feb 10 2014)
34 - API BREAK: Modify function signatures for ListStore bindings so unset
35 iterators need not be created and passed as pointers to be set
36
37 - Add cairo package (currently targeting cairo 1.10) and add initial binding
38 support for cairo Surface and Context
39
40 - Add new binding support for the following GTK classes:
41 - GdkPixbuf (https://github.com/geoffholden/gotk3/issues/40)
42 - GtkAboutDialog
43 - GtkAlignment
44 - GtkArrow
45 - GtkCalendar
46 - GtkDrawingArea
47 - GtkEventBox
48 - GtkOffscreenWindow (https://github.com/geoffholden/gotk3/issues/33)
49 - GtkSpinner
50 - GtkSwitch
51
52 - Add additional bindings for gtk.Label
53
54 - Add glib.TimeoutAdd (https://github.com/geoffholden/gotk3/issues/41)
55
56 - Call correct C function to create a new TextTagTable
57 (https://github.com/geoffholden/gotk3/issues/40)
58
59 - Create correct go values from glib values
60 (https://github.com/geoffholden/gotk3/issues/39 and
61 https://github.com/geoffholden/gotk3/issues/41)
62
63 Changes in 0.1.1 (Tue Jan 14 2014)
64 - Fix a (*glib.Object).Connect crash where an allocated GValue was
65 prematurely unset
66
67 - Fix memory leaks when adding callbacks with (*glib.Object).Connect and
68 glib.IdleAdd
69
70 - Make all constants typed for increased compile-time type safety
71
72 - Remove a duplicate example file (resulting in two main functions)
73 which broke recursive go get
74
75 - Add ALIGN_BASELINE const (since GTK 3.10)
76
77 Changes in 0.1.0 (Thu Jan 09 2014)
78 - Modify signal callback API to remove glib.CallbackContext
79
80 - New support for the following types:
81 - gtk.CellRendererToggle
82 - gtk.HeaderBar
83 - gtk.TextView
84
85 - Additional function support for the following types:
86 - gtk.MessageDialog
87 - gtk.Window
88
89 - Add examples for gtk.TextView bindings
90
91 - Fix build when building with gccgo
92 (https://github.com/geoffholden/gotk3/issues/19 and
93 https://github.com/geoffholden/gotk3/issues/20)
94
95 Changes in 0.0.2 (Wed Nov 13 2013)
96 - Begin GTK 3.10 support
97
98 - Add support for targeting GTK 3.6
99
100 - Add build tags to target previous GTK releases
101
102 - Additional function support for the following types:
103 - gtk.Label
104 - gtk.Misc
105 - gtk.Scrollbar
106 - gtk.SpinButton
107 - gtk.Window
108
109 - New support for the following types:
110 - gtk.Builder
111 - gtk.CheckButton
112 - gtk.Frame
113 - gtk.Range
114 - gtk.Scrollbar
115 - gtk.Separator
116 - gtk.SeparatorMenuItem
117 - gtk.ShadowType
118 - gtk.ToggleButton
119
120 - Add glib.GetUserSpecialDir
121
122 - Use C constants directly instead of using iota
123
124 - Fix several nil pointer dereferences
125
126 - General code cleanup
127
128 Initial Release 0.0.1 (Tue Jul 16 2013)
129 - Initial release
5 Changes for next Version 0.6.0
6 - Breaking changes in API
7 - General code cleanup
8 - #685 Refactor Gtk callback setters and types enhancement missing binding
9 - #706 Refactor internal closure handling and several API changes breaking changes
10 - #746 Add build tag pango_1_42 for Pango
11 - #743 Solving #741- Add possibility to use GVariant in signal handler
12 - #740 Add binding for GtkRadioMenuItem
13 - #738 Adds binding for gtk_cell_layout_clear_attributes()
14 - #737 Adds bindings for gdk_pixbuf_new_from_resource() and gdk_pixbuf_new_from_resource_at_scale()
15 - #736 Add bindings/helper methods GdkRectangle GdkPoint
16 - #735 Add GtkMenuItem bindings
17 - #734 Add bindings GtkMenuShell
18 - #732 add as contributor
19 - #731 add bindings to GtkMenu
20 - #730 Solve GtkAccelKey issue with golang 1.16
21 - #728 It is not safe to reference memory returned in a signal callback.
22 - #687 Don't merge until publication of Golang v1.16: GtkAccelKey v1.16 issue fix next version
23 - #724 Implemented CellRenderer.SetAlignment
24 - #723 Added SetOrientation to gkt.SpinButton
25 - #720 Add Prgname getter and setter
26 - #716 Add (Get/Set) methods to GdkRGBA & GdkVisual & GdkDisplayManager bind…
27 - #715 Add some GtkRange bindings
28 - #712 glib.Take to return nil and gtk.marshal* to allow nil
88 - [raichu](https://github.com/raichu/gotk3)
99 - [juniorz](https://github.com/juniorz)
1010 - [thanhps42](https://github.com/thanhps42)
11 - [MJacred](https://github.com/MJacred/gotk3)
12 - you?
11 - [cubiest](https://github.com/cubiest/gotk3) - [MJacred](https://github.com/MJacred) & [founderio](https://github.com/founderio)
12 - [hfmrow (H.F.M)](https://github.com/hfmrow/)
13 - you?
0 ISC License
1
02 Copyright (c) 2013-2014 Conformal Systems LLC.
13 Copyright (c) 2015-2018 gotk3 contributors
24
22
33 [![Build Status](https://travis-ci.org/gotk3/gotk3.svg?branch=master)](https://travis-ci.org/gotk3/gotk3)
44
5 The gotk3 project provides Go bindings for GTK+3 and dependent
5 The gotk3 project provides Go bindings for GTK 3 and dependent
66 projects. Each component is given its own subdirectory, which is used
77 as the import path for the package. Partial binding support for the
88 following libraries is currently implemented:
99
10 - GTK+3 (3.12 and later)
10 - GTK 3 (3.12 and later)
1111 - GDK 3 (3.12 and later)
1212 - GLib 2 (2.36 and later)
1313 - Cairo (1.10 and later)
1515 Care has been taken for memory management to work seamlessly with Go's
1616 garbage collector without the need to use or understand GObject's
1717 floating references.
18
19 for better understanding see
20 [package reference documation](https://pkg.go.dev/github.com/gotk3/gotk3/gtk?tab=doc)
21
22 On Linux, see which version your distribution has [here](https://pkgs.org) with the search terms:
23 * libgtk-3
24 * libglib2
25 * libgdk-pixbuf2
1826
1927 ## Sample Use
2028
188196
189197 ## Installation
190198
191 gotk3 currently requires GTK 3.6-3.22, GLib 2.36-2.40, and
199 gotk3 currently requires GTK 3.6-3.24, GLib 2.36-2.46, and
192200 Cairo 1.10 or 1.12. A recent Go (1.8 or newer) is also required.
193201
194202 For detailed instructions see the wiki pages: [installation](https://github.com/gotk3/gotk3/wiki#installation)
195203
204 ## Using deprecated features
205
206 By default, deprecated GTK features are not included in the build.
207
208 By specifying the e.g. build tag `gtk_3_20`, any feature deprecated in GTK 3.20 or earlier will NOT be available.
209 To enable deprecated features in the build, add the tag `gtk_deprecated`.
210 Example:
211 ```shell
212 $ go build -tags "gtk_3_10 gtk_deprecated" example.go
213 ```
214
215 The same goes for
216 * gdk-pixbuf: gdk_pixbuf_deprecated
217
196218 ## TODO
197219
198 - Add bindings for all of GTK+
220 - Add bindings for all of GTK functions
199221 - Add tests for each implemented binding
222 - See the next steps: [wiki page](https://github.com/gotk3/gotk3/wiki/The-future-and-what-happens-next) and add [your suggestion](https://github.com/gotk3/gotk3/issues/576)
223
200224
201225 ## License
202226
203227 Package gotk3 is licensed under the liberal ISC License.
204228
205229 Actually if you use gotk3, then gotk3 is statically linked into your application (with the ISC licence).
206 The system libraries (e.g. GTK+, GLib) used via cgo use dynamic linking.
230 The system libraries (e.g. GTK+, GLib) used via cgo use dynamic linking.
1515 ANTIALIAS_NONE Antialias = C.CAIRO_ANTIALIAS_NONE
1616 ANTIALIAS_GRAY Antialias = C.CAIRO_ANTIALIAS_GRAY
1717 ANTIALIAS_SUBPIXEL Antialias = C.CAIRO_ANTIALIAS_SUBPIXEL
18 // ANTIALIAS_FAST Antialias = C.CAIRO_ANTIALIAS_FAST (since 1.12)
19 // ANTIALIAS_GOOD Antialias = C.CAIRO_ANTIALIAS_GOOD (since 1.12)
20 // ANTIALIAS_BEST Antialias = C.CAIRO_ANTIALIAS_BEST (since 1.12)
18 ANTIALIAS_FAST Antialias = C.CAIRO_ANTIALIAS_FAST // (since 1.12)
19 ANTIALIAS_GOOD Antialias = C.CAIRO_ANTIALIAS_GOOD // (since 1.12)
20 ANTIALIAS_BEST Antialias = C.CAIRO_ANTIALIAS_BEST // (since 1.12)
2121 )
2222
2323 func marshalAntialias(p uintptr) (interface{}, error) {
109109 }
110110
111111 // TODO(jrick) PopGroup (depends on Pattern)
112 // cairo_pop_group
112113
113114 // PopGroupToSource is a wrapper around cairo_pop_group_to_source().
114115 func (v *Context) PopGroupToSource() {
142143 }
143144
144145 // TODO(jrick) SetSource (depends on Pattern)
146 // cairo_set_source
145147
146148 // SetSourceSurface is a wrapper around cairo_set_source_surface().
147149 func (v *Context) SetSourceSurface(surface *Surface, x, y float64) {
150152 }
151153
152154 // TODO(jrick) GetSource (depends on Pattern)
155 // cairo_get_source
153156
154157 // SetAntialias is a wrapper around cairo_set_antialias().
155158 func (v *Context) SetAntialias(antialias Antialias) {
324327 C.cairo_move_to(v.native(), C.double(x), C.double(y))
325328 }
326329
327 // TODO(jrick) CopyRectangleList (depends on RectangleList)
330 // TODO(jrick) CopyClipRectangleList (depends on RectangleList)
331 // cairo_copy_clip_rectangle_list
328332
329333 // Fill is a wrapper around cairo_fill().
330334 func (v *Context) Fill() {
366370 }
367371
368372 // TODO(jrick) Mask (depends on Pattern)
373 // cairo_mask_surface
369374
370375 // MaskSurface is a wrapper around cairo_mask_surface().
371376 func (v *Context) MaskSurface(surface *Surface, surfaceX, surfaceY float64) {
2424 c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
2525 return Format(c), nil
2626 }
27
28 // FormatStrideForWidth is a wrapper for cairo_format_stride_for_width().
29 func FormatStrideForWidth(format Format, width int) int {
30 c := C.cairo_format_stride_for_width(C.cairo_format_t(format), C.int(width))
31 return int(c)
32 }
0 // region.go
1
2 package cairo
3
4 // #include <cairo.h>
5 // #include <cairo-gobject.h>
6 import "C"
7
8 import (
9 "runtime"
10 "unsafe"
11
12 "github.com/gotk3/gotk3/glib"
13 )
14
15 func init() {
16 tm := []glib.TypeMarshaler{
17 // Enums
18 {glib.Type(C.cairo_gobject_region_overlap_get_type()), marshalRegionOverlap},
19
20 // Boxed
21 {glib.Type(C.cairo_gobject_region_get_type()), marshalRegion},
22 }
23 glib.RegisterGValueMarshalers(tm)
24 }
25
26 // RegionOverlap is a representation of Cairo's cairo_region_overlap_t.
27 type RegionOverlap int
28
29 const (
30 REGION_OVERLAP_IN RegionOverlap = C.CAIRO_REGION_OVERLAP_IN
31 REGION_OVERLAP_OUT RegionOverlap = C.CAIRO_REGION_OVERLAP_OUT
32 REGION_OVERLAP_PART RegionOverlap = C.CAIRO_REGION_OVERLAP_PART
33 )
34
35 func marshalRegionOverlap(p uintptr) (interface{}, error) {
36 c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
37 return RegionOverlap(c), nil
38 }
39
40 /*
41 * Rectangle
42 */
43
44 // Rectangle is a representation of Cairo's cairo_rectangle_int_t.
45 type Rectangle struct {
46 X, Y int
47 Width, Height int
48 }
49
50 // commodity function to ceate Rectangle cairo object.
51 func RectangleNew(x, y, width, height int) *Rectangle {
52 r := new(Rectangle)
53 r.X = x
54 r.Y = y
55 r.Width = width
56 r.Height = height
57 return r
58 }
59
60 func (v *Rectangle) native() *C.cairo_rectangle_int_t {
61 r := new(C.cairo_rectangle_int_t)
62 r.x = C.int(v.X)
63 r.y = C.int(v.Y)
64 r.width = C.int(v.Width)
65 r.height = C.int(v.Height)
66 return r
67 }
68
69 func toRectangle(cr *C.cairo_rectangle_int_t) *Rectangle {
70 return &Rectangle{
71 X: int(cr.x), Y: int(cr.y),
72 Width: int(cr.width), Height: int(cr.height)}
73 }
74
75 /*
76 * Region
77 */
78
79 // Region is a representation of Cairo's cairo_region_t.
80 type Region struct {
81 region *C.cairo_region_t
82 }
83
84 // native returns a pointer to the underlying cairo_region_t.
85 func (v *Region) native() *C.cairo_region_t {
86 if v == nil {
87 return nil
88 }
89 return v.region
90 }
91
92 // Native returns a pointer to the underlying cairo_region_t.
93 func (v *Region) Native() uintptr {
94 return uintptr(unsafe.Pointer(v.native()))
95 }
96
97 func marshalRegion(p uintptr) (interface{}, error) {
98 c := C.g_value_get_boxed((*C.GValue)(unsafe.Pointer(p)))
99 region := (*C.cairo_region_t)(unsafe.Pointer(c))
100 return wrapRegion(region), nil
101 }
102
103 func wrapRegion(region *C.cairo_region_t) *Region {
104 return &Region{region}
105 }
106
107 // newRegionFromNative that handle finalizer.
108 func newRegionFromNative(regionNative *C.cairo_region_t) (*Region, error) {
109 ptr := wrapRegion(regionNative)
110 e := ptr.Status().ToError()
111 if e != nil {
112 return nil, e
113 }
114 runtime.SetFinalizer(ptr, (*Region).destroy)
115 return ptr, nil
116 }
117
118 // RegionCreate is a wrapper around cairo_region_create().
119 func RegionCreate() (*Region, error) {
120
121 return newRegionFromNative(C.cairo_region_create())
122 }
123
124 // CreateRectangle is a wrapper around cairo_region_create_rectangle().
125 func (v *Region) CreateRectangle(rectangle *Rectangle) (*Region, error) {
126
127 return newRegionFromNative(C.cairo_region_create_rectangle(
128 rectangle.native()))
129 }
130
131 // CreateRectangles is a wrapper around cairo_region_create_rectangles().
132 func (v *Region) CreateRectangles(rectangles ...*Rectangle) (*Region, error) {
133
134 length := len(rectangles)
135
136 cRectangles := make([]C.cairo_rectangle_int_t, length)
137
138 for i := 0; i < length; i++ {
139 cRectangles[i] = *rectangles[i].native()
140 }
141
142 pRect := &cRectangles[0]
143
144 return newRegionFromNative(
145 C.cairo_region_create_rectangles(
146 pRect,
147 C.int(length)))
148 }
149
150 // Copy is a wrapper around cairo_region_copy().
151 func (v *Region) Copy() (*Region, error) {
152
153 return newRegionFromNative(C.cairo_region_copy(v.native()))
154 }
155
156 // reference is a wrapper around cairo_region_reference().
157 func (v *Region) reference() {
158 v.region = C.cairo_region_reference(v.native())
159 }
160
161 // destroy is a wrapper around cairo_region_destroy().
162 func (v *Region) destroy() {
163 C.cairo_region_destroy(v.native())
164 }
165
166 // Status is a wrapper around cairo_region_status().
167 func (v *Region) Status() Status {
168 c := C.cairo_region_status(v.native())
169 return Status(c)
170 }
171
172 // GetExtents is a wrapper around cairo_region_get_extents().
173 func (v *Region) GetExtents(extents *Rectangle) {
174
175 C.cairo_region_get_extents(v.native(), extents.native())
176 }
177
178 // NumRectangles is a wrapper around cairo_region_num_rectangles().
179 func (v *Region) NumRectangles() int {
180
181 return int(C.cairo_region_num_rectangles(v.native()))
182 }
183
184 // GetRectangle is a wrapper around cairo_region_get_rectangle().
185 func (v *Region) GetRectangle(nth int) *Rectangle {
186
187 cr := new(C.cairo_rectangle_int_t)
188 C.cairo_region_get_rectangle(v.native(), C.int(nth), cr)
189
190 return toRectangle(cr)
191 }
192
193 // IsEmpty is a wrapper around cairo_region_is_empty().
194 func (v *Region) IsEmpty() bool {
195
196 return gobool(C.cairo_region_is_empty(v.native()))
197 }
198
199 // ContainsPoint is a wrapper around cairo_region_contains_point().
200 func (v *Region) ContainsPoint(x, y int) bool {
201
202 return gobool(C.cairo_region_contains_point(
203 v.native(), C.int(x), C.int(y)))
204 }
205
206 // ContainsRectangle is a wrapper around cairo_region_contains_rectangle().
207 func (v *Region) ContainsRectangle(rectangle *Rectangle) RegionOverlap {
208
209 return RegionOverlap(
210 C.cairo_region_contains_rectangle(
211 v.native(), rectangle.native()))
212 }
213
214 // Equal is a wrapper around cairo_region_equal().
215 func (v *Region) Equal(region *Region) bool {
216
217 return gobool(C.cairo_region_equal(v.native(), region.native()))
218 }
219
220 // Translate is a wrapper around cairo_region_translate().
221 func (v *Region) Translate(dx, dy int) {
222
223 C.cairo_region_translate(v.native(), C.int(dx), C.int(dy))
224 }
225
226 // Intersect is a wrapper around cairo_region_intersect().
227 // Note: contrary to the original statement, the source
228 // 'Region' remains preserved.
229 func (v *Region) Intersect(other *Region) (*Region, error) {
230
231 dst, err := v.Copy()
232 if err != nil {
233 return nil, err
234 }
235 err = Status(
236 C.cairo_region_intersect(
237 dst.native(),
238 other.native())).ToError()
239 if err != nil {
240 return nil, err
241 }
242
243 return dst, nil
244 }
245
246 // IntersectRectangle is a wrapper around cairo_region_intersect_rectangle().
247 // Note: contrary to the original statement, the source 'Region' remains preserved.
248 func (v *Region) IntersectRectangle(rectangle *Rectangle) (*Region, error) {
249
250 dst, err := v.Copy()
251 if err != nil {
252 return nil, err
253 }
254 err = Status(
255 C.cairo_region_intersect_rectangle(
256 dst.native(),
257 rectangle.native())).ToError()
258 if err != nil {
259 return nil, err
260 }
261
262 return dst, nil
263 }
264
265 // Substract is a wrapper around cairo_region_subtract().
266 // Note: contrary to the original statement, the source
267 // 'Region' remains preserved.
268 func (v *Region) Substract(other *Region) (*Region, error) {
269
270 dst, err := v.Copy()
271 if err != nil {
272 return nil, err
273 }
274 err = Status(
275 C.cairo_region_subtract(
276 dst.native(),
277 other.native())).ToError()
278 if err != nil {
279 return nil, err
280 }
281
282 return dst, nil
283 }
284
285 // SubstractRectangle is a wrapper around cairo_region_subtract_rectangle().
286 // Note: contrary to the original statement, the source 'Region' remains preserved.
287 func (v *Region) SubstractRectangle(rectangle *Rectangle) (*Region, error) {
288
289 dst, err := v.Copy()
290 if err != nil {
291 return nil, err
292 }
293 err = Status(
294 C.cairo_region_subtract_rectangle(
295 dst.native(),
296 rectangle.native())).ToError()
297 if err != nil {
298 return nil, err
299 }
300
301 return dst, nil
302 }
303
304 // Union is a wrapper around cairo_region_union().
305 // Note: contrary to the original statement, the source
306 // 'Region' remains preserved.
307 func (v *Region) Union(other *Region) (*Region, error) {
308
309 dst, err := v.Copy()
310 if err != nil {
311 return nil, err
312 }
313 err = Status(
314 C.cairo_region_union(
315 dst.native(),
316 other.native())).ToError()
317 if err != nil {
318 return nil, err
319 }
320
321 return dst, nil
322 }
323
324 // UnionRectangle is a wrapper around cairo_region_union_rectangle().
325 // Note: contrary to the original statement, the source 'Region' remains preserved.
326 func (v *Region) UnionRectangle(rectangle *Rectangle) (*Region, error) {
327
328 dst, err := v.Copy()
329 if err != nil {
330 return nil, err
331 }
332 err = Status(
333 C.cairo_region_union_rectangle(
334 dst.native(),
335 rectangle.native())).ToError()
336 if err != nil {
337 return nil, err
338 }
339
340 return dst, nil
341 }
342
343 // Xor is a wrapper around cairo_region_xor().
344 // Note: contrary to the original statement, the source
345 // 'Region' remains preserved.
346 func (v *Region) Xor(other *Region) (*Region, error) {
347
348 dst, err := v.Copy()
349 if err != nil {
350 return nil, err
351 }
352 err = Status(
353 C.cairo_region_xor(
354 dst.native(),
355 other.native())).ToError()
356 if err != nil {
357 return nil, err
358 }
359
360 return dst, nil
361 }
362
363 // XorRectangle is a wrapper around cairo_region_xor_rectangle().
364 // Note: contrary to the original statement, the source 'Region' remains preserved.
365 func (v *Region) XorRectangle(rectangle *Rectangle) (*Region, error) {
366
367 dst, err := v.Copy()
368 if err != nil {
369 return nil, err
370 }
371 err = Status(
372 C.cairo_region_xor_rectangle(
373 dst.native(),
374 rectangle.native())).ToError()
375 if err != nil {
376 return nil, err
377 }
378
379 return dst, nil
380 }
1010 "unsafe"
1111 )
1212
13 // TODO(jrick) SetUserData (depends on UserDataKey and DestroyFunc)
14
15 // TODO(jrick) GetUserData (depends on UserDataKey)
16
1713 /*
1814 * cairo_surface_t
1915 */
3632 }
3733
3834 return &Surface{surfaceNative}, nil
35 }
36
37 // CreateImageSurfaceForData is a wrapper around cairo_image_surface_create_for_data().
38 func CreateImageSurfaceForData(data []byte, format Format, width, height, stride int) (*Surface, error) {
39 surfaceNative := C.cairo_image_surface_create_for_data((*C.uchar)(unsafe.Pointer(&data[0])),
40 C.cairo_format_t(format), C.int(width), C.int(height), C.int(stride))
41
42 status := Status(C.cairo_surface_status(surfaceNative))
43 if status != STATUS_SUCCESS {
44 return nil, ErrorStatus(status)
45 }
46
47 s := wrapSurface(surfaceNative)
48
49 runtime.SetFinalizer(s, (*Surface).destroy)
50
51 return s, nil
3952 }
4053
4154 // CreateImageSurface is a wrapper around cairo_image_surface_create().
7790 // Native returns a pointer to the underlying cairo_surface_t.
7891 func (v *Surface) Native() uintptr {
7992 return uintptr(unsafe.Pointer(v.native()))
93 }
94
95 func (v *Surface) GetCSurface() *C.cairo_surface_t {
96 return v.native()
8097 }
8198
8299 func marshalSurface(p uintptr) (interface{}, error) {
155172 }
156173
157174 // TODO(jrick) GetDevice (requires Device bindings)
175 // cairo_surface_get_device
158176
159177 // TODO(jrick) GetFontOptions (require FontOptions bindings)
178 // cairo_surface_get_font_options
160179
161180 // TODO(jrick) GetContent (requires Content bindings)
181 // cairo_surface_get_content
162182
163183 // MarkDirty is a wrapper around cairo_surface_mark_dirty().
164184 func (v *Surface) MarkDirty() {
190210 C.double(yPPI))
191211 }
192212
193 // GetFallbackResolution is a wrapper around
194 // cairo_surface_get_fallback_resolution().
213 // GetFallbackResolution is a wrapper around cairo_surface_get_fallback_resolution().
195214 func (v *Surface) GetFallbackResolution() (xPPI, yPPI float64) {
196215 var x, y C.double
197216 C.cairo_surface_get_fallback_resolution(v.native(), &x, &y)
205224 }
206225
207226 // TODO(jrick) SetUserData (depends on UserDataKey and DestroyFunc)
227 // cairo_surface_set_user_data
208228
209229 // TODO(jrick) GetUserData (depends on UserDataKey)
230 // cairo_surface_get_user_data
210231
211232 // CopyPage is a wrapper around cairo_surface_copy_page().
212233 func (v *Surface) CopyPage() {
225246 }
226247
227248 // TODO(jrick) SetMimeData (depends on DestroyFunc)
249 // cairo_surface_set_mime_data
228250
229251 // GetMimeData is a wrapper around cairo_surface_get_mime_data(). The
230252 // returned mimetype data is returned as a Go byte slice.
253275 }
254276
255277 // TODO(jrick) SupportsMimeType (since 1.12)
278 // cairo_surface_supports_mime_type
256279
257280 // TODO(jrick) MapToImage (since 1.12)
281 // cairo_surface_map_to_image
258282
259283 // TODO(jrick) UnmapImage (since 1.12)
284 // cairo_surface_unmap_image
260285
261286 // GetHeight is a wrapper around cairo_image_surface_get_height().
262287 func (v *Surface) GetHeight() int {
+1283
-1020
gdk/gdk.go less more
2222 import "C"
2323 import (
2424 "errors"
25 "reflect"
2625 "runtime"
27 "strconv"
2826 "unsafe"
2927
28 "github.com/gotk3/gotk3/cairo"
3029 "github.com/gotk3/gotk3/glib"
3130 )
3231
3837 {glib.Type(C.gdk_event_type_get_type()), marshalEventType},
3938 {glib.Type(C.gdk_interp_type_get_type()), marshalInterpType},
4039 {glib.Type(C.gdk_modifier_type_get_type()), marshalModifierType},
41 {glib.Type(C.gdk_pixbuf_alpha_mode_get_type()), marshalPixbufAlphaMode},
4240 {glib.Type(C.gdk_event_mask_get_type()), marshalEventMask},
41 {glib.Type(C.gdk_gravity_get_type()), marshalGravity},
42 {glib.Type(C.gdk_visual_type_get_type()), marshalVisualType},
4343
4444 // Objects/Interfaces
4545 {glib.Type(C.gdk_device_get_type()), marshalDevice},
46 {glib.Type(C.gdk_display_manager_get_type()), marshalDisplayManager},
4647 {glib.Type(C.gdk_cursor_get_type()), marshalCursor},
4748 {glib.Type(C.gdk_device_manager_get_type()), marshalDeviceManager},
4849 {glib.Type(C.gdk_display_get_type()), marshalDisplay},
4950 {glib.Type(C.gdk_drag_context_get_type()), marshalDragContext},
50 {glib.Type(C.gdk_pixbuf_get_type()), marshalPixbuf},
51 {glib.Type(C.gdk_pixbuf_animation_get_type()), marshalPixbufAnimation},
5251 {glib.Type(C.gdk_rgba_get_type()), marshalRGBA},
5352 {glib.Type(C.gdk_screen_get_type()), marshalScreen},
5453 {glib.Type(C.gdk_visual_get_type()), marshalVisual},
8685 /*
8786 * Constants
8887 */
88
89 // VisualType is a representation of GDK's GdkVisualType.
90 type VisualType int
91
92 const (
93 VISUAL_STATIC_GRAY VisualType = C.GDK_VISUAL_STATIC_GRAY
94 VISUAL_GRAYSCALE VisualType = C.GDK_VISUAL_GRAYSCALE
95 VISUAL_STATIC_COLOR VisualType = C.GDK_VISUAL_STATIC_COLOR
96 ISUAL_PSEUDO_COLOR VisualType = C.GDK_VISUAL_PSEUDO_COLOR
97 VISUAL_TRUE_COLOR VisualType = C.GDK_VISUAL_TRUE_COLOR
98 VISUAL_DIRECT_COLOR VisualType = C.GDK_VISUAL_DIRECT_COLOR
99 )
100
101 func marshalVisualType(p uintptr) (interface{}, error) {
102 c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
103 return VisualType(c), nil
104 }
89105
90106 // DragAction is a representation of GDK's GdkDragAction.
91107 type DragAction int
126142 INTERP_HYPER InterpType = C.GDK_INTERP_HYPER
127143 )
128144
129 // PixbufRotation is a representation of GDK's GdkPixbufRotation.
130 type PixbufRotation int
131
132 const (
133 PIXBUF_ROTATE_NONE PixbufRotation = C.GDK_PIXBUF_ROTATE_NONE
134 PIXBUF_ROTATE_COUNTERCLOCKWISE PixbufRotation = C.GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE
135 PIXBUF_ROTATE_UPSIDEDOWN PixbufRotation = C.GDK_PIXBUF_ROTATE_UPSIDEDOWN
136 PIXBUF_ROTATE_CLOCKWISE PixbufRotation = C.GDK_PIXBUF_ROTATE_CLOCKWISE
137 )
138
139145 func marshalInterpType(p uintptr) (interface{}, error) {
140146 c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
141147 return InterpType(c), nil
145151 type ModifierType uint
146152
147153 const (
148 GDK_SHIFT_MASK ModifierType = C.GDK_SHIFT_MASK
149 GDK_LOCK_MASK = C.GDK_LOCK_MASK
150 GDK_CONTROL_MASK = C.GDK_CONTROL_MASK
151 GDK_MOD1_MASK = C.GDK_MOD1_MASK
152 GDK_MOD2_MASK = C.GDK_MOD2_MASK
153 GDK_MOD3_MASK = C.GDK_MOD3_MASK
154 GDK_MOD4_MASK = C.GDK_MOD4_MASK
155 GDK_MOD5_MASK = C.GDK_MOD5_MASK
156 GDK_BUTTON1_MASK = C.GDK_BUTTON1_MASK
157 GDK_BUTTON2_MASK = C.GDK_BUTTON2_MASK
158 GDK_BUTTON3_MASK = C.GDK_BUTTON3_MASK
159 GDK_BUTTON4_MASK = C.GDK_BUTTON4_MASK
160 GDK_BUTTON5_MASK = C.GDK_BUTTON5_MASK
161 GDK_SUPER_MASK = C.GDK_SUPER_MASK
162 GDK_HYPER_MASK = C.GDK_HYPER_MASK
163 GDK_META_MASK = C.GDK_META_MASK
164 GDK_RELEASE_MASK = C.GDK_RELEASE_MASK
165 GDK_MODIFIER_MASK = C.GDK_MODIFIER_MASK
154 SHIFT_MASK ModifierType = C.GDK_SHIFT_MASK
155 LOCK_MASK = C.GDK_LOCK_MASK
156 CONTROL_MASK = C.GDK_CONTROL_MASK
157 MOD1_MASK = C.GDK_MOD1_MASK
158 MOD2_MASK = C.GDK_MOD2_MASK
159 MOD3_MASK = C.GDK_MOD3_MASK
160 MOD4_MASK = C.GDK_MOD4_MASK
161 MOD5_MASK = C.GDK_MOD5_MASK
162 BUTTON1_MASK = C.GDK_BUTTON1_MASK
163 BUTTON2_MASK = C.GDK_BUTTON2_MASK
164 BUTTON3_MASK = C.GDK_BUTTON3_MASK
165 BUTTON4_MASK = C.GDK_BUTTON4_MASK
166 BUTTON5_MASK = C.GDK_BUTTON5_MASK
167 SUPER_MASK = C.GDK_SUPER_MASK
168 HYPER_MASK = C.GDK_HYPER_MASK
169 META_MASK = C.GDK_META_MASK
170 RELEASE_MASK = C.GDK_RELEASE_MASK
171 MODIFIER_MASK = C.GDK_MODIFIER_MASK
166172 )
167173
168174 func marshalModifierType(p uintptr) (interface{}, error) {
169 c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
175 c := C.g_value_get_flags((*C.GValue)(unsafe.Pointer(p)))
170176 return ModifierType(c), nil
171 }
172
173 // PixbufAlphaMode is a representation of GDK's GdkPixbufAlphaMode.
174 type PixbufAlphaMode int
175
176 const (
177 GDK_PIXBUF_ALPHA_BILEVEL PixbufAlphaMode = C.GDK_PIXBUF_ALPHA_BILEVEL
178 GDK_PIXBUF_ALPHA_FULL PixbufAlphaMode = C.GDK_PIXBUF_ALPHA_FULL
179 )
180
181 func marshalPixbufAlphaMode(p uintptr) (interface{}, error) {
182 c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
183 return PixbufAlphaMode(c), nil
184177 }
185178
186179 // Selections
241234
242235 // added by lazyshot
243236 // ScrollDirection is a representation of GDK's GdkScrollDirection
244
245237 type ScrollDirection int
246238
247239 const (
250242 SCROLL_LEFT ScrollDirection = C.GDK_SCROLL_LEFT
251243 SCROLL_RIGHT ScrollDirection = C.GDK_SCROLL_RIGHT
252244 SCROLL_SMOOTH ScrollDirection = C.GDK_SCROLL_SMOOTH
245 )
246
247 // WindowEdge is a representation of GDK's GdkWindowEdge
248 type WindowEdge int
249
250 const (
251 WINDOW_EDGE_NORTH_WEST WindowEdge = C.GDK_WINDOW_EDGE_NORTH_WEST
252 WINDOW_EDGE_NORTH WindowEdge = C.GDK_WINDOW_EDGE_NORTH
253 WINDOW_EDGE_NORTH_EAST WindowEdge = C.GDK_WINDOW_EDGE_NORTH_EAST
254 WINDOW_EDGE_WEST WindowEdge = C.GDK_WINDOW_EDGE_WEST
255 WINDOW_EDGE_EAST WindowEdge = C.GDK_WINDOW_EDGE_EAST
256 WINDOW_EDGE_SOUTH_WEST WindowEdge = C.GDK_WINDOW_EDGE_SOUTH_WEST
257 WINDOW_EDGE_SOUTH WindowEdge = C.GDK_WINDOW_EDGE_SOUTH
258 WINDOW_EDGE_SOUTH_EAST WindowEdge = C.GDK_WINDOW_EDGE_SOUTH_EAST
253259 )
254260
255261 // WindowState is a representation of GDK's GdkWindowState
287293 WINDOW_TYPE_HINT_DND WindowTypeHint = C.GDK_WINDOW_TYPE_HINT_DND
288294 )
289295
296 // WindowHints is a representation of GDK's GdkWindowHints
297 type WindowHints int
298
299 const (
300 HINT_POS WindowHints = C.GDK_HINT_POS
301 HINT_MIN_SIZE WindowHints = C.GDK_HINT_MIN_SIZE
302 HINT_MAX_SIZE WindowHints = C.GDK_HINT_MAX_SIZE
303 HINT_BASE_SIZE WindowHints = C.GDK_HINT_BASE_SIZE
304 HINT_ASPECT WindowHints = C.GDK_HINT_ASPECT
305 HINT_RESIZE_INC WindowHints = C.GDK_HINT_RESIZE_INC
306 HINT_WIN_GRAVITY WindowHints = C.GDK_HINT_WIN_GRAVITY
307 HINT_USER_POS WindowHints = C.GDK_HINT_USER_POS
308 HINT_USER_SIZE WindowHints = C.GDK_HINT_USER_SIZE
309 )
310
290311 // CURRENT_TIME is a representation of GDK_CURRENT_TIME
291312
292313 const CURRENT_TIME = C.GDK_CURRENT_TIME
299320 GRAB_SUCCESS GrabStatus = C.GDK_GRAB_SUCCESS
300321 GRAB_ALREADY_GRABBED GrabStatus = C.GDK_GRAB_ALREADY_GRABBED
301322 GRAB_INVALID_TIME GrabStatus = C.GDK_GRAB_INVALID_TIME
323 GRAB_NOT_VIEWABLE GrabStatus = C.GDK_GRAB_NOT_VIEWABLE
302324 GRAB_FROZEN GrabStatus = C.GDK_GRAB_FROZEN
303 // Only exists since 3.16
304 // GRAB_FAILED GrabStatus = C.GDK_GRAB_FAILED
305 GRAB_FAILED GrabStatus = 5
306325 )
307326
308327 // GrabOwnership is a representation of GdkGrabOwnership
315334 OWNERSHIP_APPLICATION GrabOwnership = C.GDK_OWNERSHIP_APPLICATION
316335 )
317336
337 // TODO:
338 // GdkInputSource
339 // GdkInputMode
340 // GdkAxisUse
341 // GdkAxisFlags
342 // GdkDeviceToolType
343
318344 // DeviceType is a representation of GdkDeviceType
319345
320346 type DeviceType int
325351 DEVICE_TYPE_FLOATING DeviceType = C.GDK_DEVICE_TYPE_FLOATING
326352 )
327353
354 // TODO:
355 // GdkColorspace
356 // GdkVisualType
357 // GdkTimeCoord
358
328359 // EventPropagation constants
329360
330361 const (
331362 GDK_EVENT_PROPAGATE bool = C.GDK_EVENT_PROPAGATE != 0
332363 GDK_EVENT_STOP bool = C.GDK_EVENT_STOP != 0
364 )
365
366 // Button constants
367 type Button uint
368
369 const (
370 BUTTON_PRIMARY Button = C.GDK_BUTTON_PRIMARY
371 BUTTON_MIDDLE Button = C.GDK_BUTTON_MIDDLE
372 BUTTON_SECONDARY Button = C.GDK_BUTTON_SECONDARY
333373 )
334374
335375 // CrossingMode is a representation of GDK's GdkCrossingMode.
360400 NOTIFY_NONLINEAR_VIRTUAL NotifyType = C.GDK_NOTIFY_NONLINEAR_VIRTUAL
361401 NOTIFY_UNKNOWN NotifyType = C.GDK_NOTIFY_UNKNOWN
362402 )
363
364 /*
365 * GdkAtom
366 */
367
368 // Atom is a representation of GDK's GdkAtom.
369 type Atom uintptr
370
371 // native returns the underlying GdkAtom.
372 func (v Atom) native() C.GdkAtom {
373 return C.toGdkAtom(unsafe.Pointer(uintptr(v)))
374 }
375
376 func (v Atom) Name() string {
377 c := C.gdk_atom_name(v.native())
378 defer C.g_free(C.gpointer(c))
379 return C.GoString((*C.char)(c))
380 }
381
382 // GdkAtomIntern is a wrapper around gdk_atom_intern
383 func GdkAtomIntern(atomName string, onlyIfExists bool) Atom {
384 cstr := C.CString(atomName)
385 defer C.free(unsafe.Pointer(cstr))
386 c := C.gdk_atom_intern((*C.gchar)(cstr), gbool(onlyIfExists))
387 return Atom(uintptr(unsafe.Pointer(c)))
388 }
389
390 /*
391 * GdkDevice
392 */
393
394 // Device is a representation of GDK's GdkDevice.
395 type Device struct {
396 *glib.Object
397 }
398
399 // native returns a pointer to the underlying GdkDevice.
400 func (v *Device) native() *C.GdkDevice {
401 if v == nil || v.GObject == nil {
402 return nil
403 }
404 p := unsafe.Pointer(v.GObject)
405 return C.toGdkDevice(p)
406 }
407
408 // Native returns a pointer to the underlying GdkDevice.
409 func (v *Device) Native() uintptr {
410 return uintptr(unsafe.Pointer(v.native()))
411 }
412
413 func marshalDevice(p uintptr) (interface{}, error) {
414 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
415 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
416 return &Device{obj}, nil
417 }
418
419 /*
420 * GdkCursor
421 */
422
423 // Cursor is a representation of GdkCursor.
424 type Cursor struct {
425 *glib.Object
426 }
427
428 // CursorNewFromName is a wrapper around gdk_cursor_new_from_name().
429 func CursorNewFromName(display *Display, name string) (*Cursor, error) {
430 cstr := C.CString(name)
431 defer C.free(unsafe.Pointer(cstr))
432 c := C.gdk_cursor_new_from_name(display.native(), (*C.gchar)(cstr))
433 if c == nil {
434 return nil, nilPtrErr
435 }
436
437 return &Cursor{glib.Take(unsafe.Pointer(c))}, nil
438 }
439
440 // native returns a pointer to the underlying GdkCursor.
441 func (v *Cursor) native() *C.GdkCursor {
442 if v == nil || v.GObject == nil {
443 return nil
444 }
445 p := unsafe.Pointer(v.GObject)
446 return C.toGdkCursor(p)
447 }
448
449 // Native returns a pointer to the underlying GdkCursor.
450 func (v *Cursor) Native() uintptr {
451 return uintptr(unsafe.Pointer(v.native()))
452 }
453
454 func marshalCursor(p uintptr) (interface{}, error) {
455 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
456 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
457 return &Cursor{obj}, nil
458 }
459
460 /*
461 * GdkDeviceManager
462 */
463
464 // DeviceManager is a representation of GDK's GdkDeviceManager.
465 type DeviceManager struct {
466 *glib.Object
467 }
468
469 // native returns a pointer to the underlying GdkDeviceManager.
470 func (v *DeviceManager) native() *C.GdkDeviceManager {
471 if v == nil || v.GObject == nil {
472 return nil
473 }
474 p := unsafe.Pointer(v.GObject)
475 return C.toGdkDeviceManager(p)
476 }
477
478 // Native returns a pointer to the underlying GdkDeviceManager.
479 func (v *DeviceManager) Native() uintptr {
480 return uintptr(unsafe.Pointer(v.native()))
481 }
482
483 func marshalDeviceManager(p uintptr) (interface{}, error) {
484 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
485 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
486 return &DeviceManager{obj}, nil
487 }
488
489 // GetDisplay() is a wrapper around gdk_device_manager_get_display().
490 func (v *DeviceManager) GetDisplay() (*Display, error) {
491 c := C.gdk_device_manager_get_display(v.native())
492 if c == nil {
493 return nil, nilPtrErr
494 }
495
496 return &Display{glib.Take(unsafe.Pointer(c))}, nil
497 }
498
499 /*
500 * GdkDisplay
501 */
502
503 // Display is a representation of GDK's GdkDisplay.
504 type Display struct {
505 *glib.Object
506 }
507
508 // native returns a pointer to the underlying GdkDisplay.
509 func (v *Display) native() *C.GdkDisplay {
510 if v == nil || v.GObject == nil {
511 return nil
512 }
513 p := unsafe.Pointer(v.GObject)
514 return C.toGdkDisplay(p)
515 }
516
517 // Native returns a pointer to the underlying GdkDisplay.
518 func (v *Display) Native() uintptr {
519 return uintptr(unsafe.Pointer(v.native()))
520 }
521
522 func marshalDisplay(p uintptr) (interface{}, error) {
523 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
524 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
525 return &Display{obj}, nil
526 }
527
528 func toDisplay(s *C.GdkDisplay) (*Display, error) {
529 if s == nil {
530 return nil, nilPtrErr
531 }
532 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(s))}
533 return &Display{obj}, nil
534 }
535
536 // DisplayOpen() is a wrapper around gdk_display_open().
537 func DisplayOpen(displayName string) (*Display, error) {
538 cstr := C.CString(displayName)
539 defer C.free(unsafe.Pointer(cstr))
540 c := C.gdk_display_open((*C.gchar)(cstr))
541 if c == nil {
542 return nil, nilPtrErr
543 }
544
545 return &Display{glib.Take(unsafe.Pointer(c))}, nil
546 }
547
548 // DisplayGetDefault() is a wrapper around gdk_display_get_default().
549 func DisplayGetDefault() (*Display, error) {
550 c := C.gdk_display_get_default()
551 if c == nil {
552 return nil, nilPtrErr
553 }
554
555 return &Display{glib.Take(unsafe.Pointer(c))}, nil
556 }
557
558 // GetName() is a wrapper around gdk_display_get_name().
559 func (v *Display) GetName() (string, error) {
560 c := C.gdk_display_get_name(v.native())
561 if c == nil {
562 return "", nilPtrErr
563 }
564 return C.GoString((*C.char)(c)), nil
565 }
566
567 // GetDefaultScreen() is a wrapper around gdk_display_get_default_screen().
568 func (v *Display) GetDefaultScreen() (*Screen, error) {
569 c := C.gdk_display_get_default_screen(v.native())
570 if c == nil {
571 return nil, nilPtrErr
572 }
573
574 return &Screen{glib.Take(unsafe.Pointer(c))}, nil
575 }
576
577 // DeviceIsGrabbed() is a wrapper around gdk_display_device_is_grabbed().
578 func (v *Display) DeviceIsGrabbed(device *Device) bool {
579 c := C.gdk_display_device_is_grabbed(v.native(), device.native())
580 return gobool(c)
581 }
582
583 // Beep() is a wrapper around gdk_display_beep().
584 func (v *Display) Beep() {
585 C.gdk_display_beep(v.native())
586 }
587
588 // Sync() is a wrapper around gdk_display_sync().
589 func (v *Display) Sync() {
590 C.gdk_display_sync(v.native())
591 }
592
593 // Flush() is a wrapper around gdk_display_flush().
594 func (v *Display) Flush() {
595 C.gdk_display_flush(v.native())
596 }
597
598 // Close() is a wrapper around gdk_display_close().
599 func (v *Display) Close() {
600 C.gdk_display_close(v.native())
601 }
602
603 // IsClosed() is a wrapper around gdk_display_is_closed().
604 func (v *Display) IsClosed() bool {
605 c := C.gdk_display_is_closed(v.native())
606 return gobool(c)
607 }
608
609 // GetEvent() is a wrapper around gdk_display_get_event().
610 func (v *Display) GetEvent() (*Event, error) {
611 c := C.gdk_display_get_event(v.native())
612 if c == nil {
613 return nil, nilPtrErr
614 }
615
616 //The finalizer is not on the glib.Object but on the event.
617 e := &Event{c}
618 runtime.SetFinalizer(e, (*Event).free)
619 return e, nil
620 }
621
622 // PeekEvent() is a wrapper around gdk_display_peek_event().
623 func (v *Display) PeekEvent() (*Event, error) {
624 c := C.gdk_display_peek_event(v.native())
625 if c == nil {
626 return nil, nilPtrErr
627 }
628
629 //The finalizer is not on the glib.Object but on the event.
630 e := &Event{c}
631 runtime.SetFinalizer(e, (*Event).free)
632 return e, nil
633 }
634
635 // PutEvent() is a wrapper around gdk_display_put_event().
636 func (v *Display) PutEvent(event *Event) {
637 C.gdk_display_put_event(v.native(), event.native())
638 }
639
640 // HasPending() is a wrapper around gdk_display_has_pending().
641 func (v *Display) HasPending() bool {
642 c := C.gdk_display_has_pending(v.native())
643 return gobool(c)
644 }
645
646 // SetDoubleClickTime() is a wrapper around gdk_display_set_double_click_time().
647 func (v *Display) SetDoubleClickTime(msec uint) {
648 C.gdk_display_set_double_click_time(v.native(), C.guint(msec))
649 }
650
651 // SetDoubleClickDistance() is a wrapper around gdk_display_set_double_click_distance().
652 func (v *Display) SetDoubleClickDistance(distance uint) {
653 C.gdk_display_set_double_click_distance(v.native(), C.guint(distance))
654 }
655
656 // SupportsColorCursor() is a wrapper around gdk_display_supports_cursor_color().
657 func (v *Display) SupportsColorCursor() bool {
658 c := C.gdk_display_supports_cursor_color(v.native())
659 return gobool(c)
660 }
661
662 // SupportsCursorAlpha() is a wrapper around gdk_display_supports_cursor_alpha().
663 func (v *Display) SupportsCursorAlpha() bool {
664 c := C.gdk_display_supports_cursor_alpha(v.native())
665 return gobool(c)
666 }
667
668 // GetDefaultCursorSize() is a wrapper around gdk_display_get_default_cursor_size().
669 func (v *Display) GetDefaultCursorSize() uint {
670 c := C.gdk_display_get_default_cursor_size(v.native())
671 return uint(c)
672 }
673
674 // GetMaximalCursorSize() is a wrapper around gdk_display_get_maximal_cursor_size().
675 func (v *Display) GetMaximalCursorSize() (width, height uint) {
676 var w, h C.guint
677 C.gdk_display_get_maximal_cursor_size(v.native(), &w, &h)
678 return uint(w), uint(h)
679 }
680
681 // GetDefaultGroup() is a wrapper around gdk_display_get_default_group().
682 func (v *Display) GetDefaultGroup() (*Window, error) {
683 c := C.gdk_display_get_default_group(v.native())
684 if c == nil {
685 return nil, nilPtrErr
686 }
687
688 return &Window{glib.Take(unsafe.Pointer(c))}, nil
689 }
690
691 // SupportsSelectionNotification() is a wrapper around
692 // gdk_display_supports_selection_notification().
693 func (v *Display) SupportsSelectionNotification() bool {
694 c := C.gdk_display_supports_selection_notification(v.native())
695 return gobool(c)
696 }
697
698 // RequestSelectionNotification() is a wrapper around
699 // gdk_display_request_selection_notification().
700 func (v *Display) RequestSelectionNotification(selection Atom) bool {
701 c := C.gdk_display_request_selection_notification(v.native(),
702 selection.native())
703 return gobool(c)
704 }
705
706 // SupportsClipboardPersistence() is a wrapper around
707 // gdk_display_supports_clipboard_persistence().
708 func (v *Display) SupportsClipboardPersistence() bool {
709 c := C.gdk_display_supports_clipboard_persistence(v.native())
710 return gobool(c)
711 }
712
713 // TODO(jrick)
714 func (v *Display) StoreClipboard(clipboardWindow *Window, time uint32, targets ...Atom) {
715 panic("Not implemented")
716 }
717
718 // SupportsShapes() is a wrapper around gdk_display_supports_shapes().
719 func (v *Display) SupportsShapes() bool {
720 c := C.gdk_display_supports_shapes(v.native())
721 return gobool(c)
722 }
723
724 // SupportsInputShapes() is a wrapper around gdk_display_supports_input_shapes().
725 func (v *Display) SupportsInputShapes() bool {
726 c := C.gdk_display_supports_input_shapes(v.native())
727 return gobool(c)
728 }
729
730 // TODO(jrick) glib.AppLaunchContext GdkAppLaunchContext
731 func (v *Display) GetAppLaunchContext() {
732 panic("Not implemented")
733 }
734
735 // NotifyStartupComplete() is a wrapper around gdk_display_notify_startup_complete().
736 func (v *Display) NotifyStartupComplete(startupID string) {
737 cstr := C.CString(startupID)
738 defer C.free(unsafe.Pointer(cstr))
739 C.gdk_display_notify_startup_complete(v.native(), (*C.gchar)(cstr))
740 }
741403
742404 // EventType is a representation of GDK's GdkEventType.
743405 // Do not confuse these event types with the signals that GTK+ widgets emit
762424 EVENT_BUTTON_RELEASE EventType = C.GDK_BUTTON_RELEASE
763425 EVENT_KEY_PRESS EventType = C.GDK_KEY_PRESS
764426 EVENT_KEY_RELEASE EventType = C.GDK_KEY_RELEASE
765 EVENT_LEAVE_NOTIFY EventType = C.GDK_ENTER_NOTIFY
427 EVENT_ENTER_NOTIFY EventType = C.GDK_ENTER_NOTIFY
428 EVENT_LEAVE_NOTIFY EventType = C.GDK_LEAVE_NOTIFY
766429 EVENT_FOCUS_CHANGE EventType = C.GDK_FOCUS_CHANGE
767430 EVENT_CONFIGURE EventType = C.GDK_CONFIGURE
768431 EVENT_MAP EventType = C.GDK_MAP
795458 )
796459
797460 /*
461 * General
462 */
463
464 // TODO:
465 // gdk_init().
466 // gdk_init_check().
467 // gdk_parse_args().
468 // gdk_get_display_arg_name().
469 // gdk_notify_startup_complete().
470 // gdk_notify_startup_complete_with_id().
471 // gdk_get_program_class().
472 // gdk_set_program_class().
473 // gdk_get_display(). deprecated since version 3.8
474 // gdk_flush(). deprecated
475 // gdk_screen_width(). deprecated since version 3.22
476 // gdk_screen_height(). deprecated since version 3.22
477 // gdk_screen_width_mm(). deprecated since version 3.22
478 // gdk_screen_height_mm(). deprecated since version 3.22
479 // gdk_set_double_click_time(). deprecated
480 // gdk_beep(). deprecated
481 // gdk_error_trap_push(). deprecated
482 // gdk_error_trap_pop(). deprecated
483 // gdk_error_trap_pop_ignored(). deprecated
484
485 // SetAllowedBackends is a wrapper around gdk_set_allowed_backends
486 func SetAllowedBackends(backends string) {
487 cstr := C.CString(backends)
488 defer C.free(unsafe.Pointer(cstr))
489 C.gdk_set_allowed_backends((*C.gchar)(cstr))
490 }
491
492 /*
493 * GdkAtom
494 */
495
496 // Atom is a representation of GDK's GdkAtom.
497 type Atom uintptr
498
499 // native returns the underlying GdkAtom.
500 func (v Atom) native() C.GdkAtom {
501 return C.toGdkAtom(unsafe.Pointer(uintptr(v)))
502 }
503
504 func (v Atom) Name() string {
505 c := C.gdk_atom_name(v.native())
506 defer C.g_free(C.gpointer(c))
507 return C.GoString((*C.char)(c))
508 }
509
510 // GdkAtomIntern is a wrapper around gdk_atom_intern
511 func GdkAtomIntern(atomName string, onlyIfExists bool) Atom {
512 cstr := C.CString(atomName)
513 defer C.free(unsafe.Pointer(cstr))
514 c := C.gdk_atom_intern((*C.gchar)(cstr), gbool(onlyIfExists))
515 return Atom(uintptr(unsafe.Pointer(c)))
516 }
517
518 /*
519 * GdkDevice
520 */
521
522 // Device is a representation of GDK's GdkDevice.
523 type Device struct {
524 *glib.Object
525 }
526
527 // native returns a pointer to the underlying GdkDevice.
528 func (v *Device) native() *C.GdkDevice {
529 if v == nil || v.GObject == nil {
530 return nil
531 }
532 p := unsafe.Pointer(v.GObject)
533 return C.toGdkDevice(p)
534 }
535
536 // Native returns a pointer to the underlying GdkDevice.
537 func (v *Device) Native() uintptr {
538 return uintptr(unsafe.Pointer(v.native()))
539 }
540
541 func marshalDevice(p uintptr) (interface{}, error) {
542 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
543 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
544 return &Device{obj}, nil
545 }
546
547 func toDevice(d *C.GdkDevice) (*Device, error) {
548 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(d))}
549 return &Device{obj}, nil
550 }
551
552 func (v *Device) GetPosition(screen **Screen, x, y *int) error {
553 cs := (**C.GdkScreen)(unsafe.Pointer(uintptr(0)))
554 if screen != nil {
555 var cval *C.GdkScreen
556 cs = &cval
557 }
558
559 cx := (*C.gint)(unsafe.Pointer(uintptr(0)))
560 if x != nil {
561 var cval C.gint
562 cx = &cval
563 }
564
565 cy := (*C.gint)(unsafe.Pointer(uintptr(0)))
566 if y != nil {
567 var cval C.gint
568 cy = &cval
569 }
570 C.gdk_device_get_position(v.native(), cs, cx, cy)
571
572 if cs != (**C.GdkScreen)(unsafe.Pointer(uintptr(0))) {
573 ms, err := toScreen(*cs)
574 if err != nil {
575 return err
576 }
577 *screen = ms
578 }
579 if cx != (*C.gint)(unsafe.Pointer(uintptr(0))) {
580 *x = int(*cx)
581 }
582 if cy != (*C.gint)(unsafe.Pointer(uintptr(0))) {
583 *y = int(*cy)
584 }
585 return nil
586 }
587
588 // TODO:
589 // gdk_device_get_name().
590 // gdk_device_get_source().
591 // gdk_device_set_mode().
592 // gdk_device_get_mode().
593 // gdk_device_set_key().
594 // gdk_device_get_key().
595 // gdk_device_set_axis_use().
596 // gdk_device_get_axis_use().
597 // gdk_device_get_associated_device().
598 // gdk_device_list_slave_devices().
599 // gdk_device_get_device_type().
600 // gdk_device_get_display().
601 // gdk_device_get_has_cursor().
602 // gdk_device_get_n_axes().
603 // gdk_device_get_n_keys().
604 // gdk_device_warp().
605 // gdk_device_get_state().
606 // gdk_device_get_window_at_position().
607 // gdk_device_get_window_at_position_double().
608 // gdk_device_get_history().
609 // gdk_device_free_history().
610 // gdk_device_get_axis().
611 // gdk_device_list_axes().
612 // gdk_device_get_axis_value().
613
614 /*
615 * GdkCursor
616 */
617
618 // Cursor is a representation of GdkCursor.
619 type Cursor struct {
620 *glib.Object
621 }
622
623 // CursorNewFromName is a wrapper around gdk_cursor_new_from_name().
624 func CursorNewFromName(display *Display, name string) (*Cursor, error) {
625 cstr := C.CString(name)
626 defer C.free(unsafe.Pointer(cstr))
627 c := C.gdk_cursor_new_from_name(display.native(), (*C.gchar)(cstr))
628 if c == nil {
629 return nil, nilPtrErr
630 }
631
632 return &Cursor{glib.Take(unsafe.Pointer(c))}, nil
633 }
634
635 // native returns a pointer to the underlying GdkCursor.
636 func (v *Cursor) native() *C.GdkCursor {
637 if v == nil || v.GObject == nil {
638 return nil
639 }
640 p := unsafe.Pointer(v.GObject)
641 return C.toGdkCursor(p)
642 }
643
644 // Native returns a pointer to the underlying GdkCursor.
645 func (v *Cursor) Native() uintptr {
646 return uintptr(unsafe.Pointer(v.native()))
647 }
648
649 func marshalCursor(p uintptr) (interface{}, error) {
650 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
651 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
652 return &Cursor{obj}, nil
653 }
654
655 /*
656 * GdkDeviceManager
657 */
658
659 // DeviceManager is a representation of GDK's GdkDeviceManager.
660 type DeviceManager struct {
661 *glib.Object
662 }
663
664 // native returns a pointer to the underlying GdkDeviceManager.
665 func (v *DeviceManager) native() *C.GdkDeviceManager {
666 if v == nil || v.GObject == nil {
667 return nil
668 }
669 p := unsafe.Pointer(v.GObject)
670 return C.toGdkDeviceManager(p)
671 }
672
673 // Native returns a pointer to the underlying GdkDeviceManager.
674 func (v *DeviceManager) Native() uintptr {
675 return uintptr(unsafe.Pointer(v.native()))
676 }
677
678 func marshalDeviceManager(p uintptr) (interface{}, error) {
679 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
680 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
681 return &DeviceManager{obj}, nil
682 }
683
684 // GetDisplay() is a wrapper around gdk_device_manager_get_display().
685 func (v *DeviceManager) GetDisplay() (*Display, error) {
686 c := C.gdk_device_manager_get_display(v.native())
687 if c == nil {
688 return nil, nilPtrErr
689 }
690
691 return &Display{glib.Take(unsafe.Pointer(c))}, nil
692 }
693
694 /*
695 * GdkDisplay
696 */
697
698 // Display is a representation of GDK's GdkDisplay.
699 type Display struct {
700 *glib.Object
701 }
702
703 // native returns a pointer to the underlying GdkDisplay.
704 func (v *Display) native() *C.GdkDisplay {
705 if v == nil || v.GObject == nil {
706 return nil
707 }
708 p := unsafe.Pointer(v.GObject)
709 return C.toGdkDisplay(p)
710 }
711
712 // Native returns a pointer to the underlying GdkDisplay.
713 func (v *Display) Native() uintptr {
714 return uintptr(unsafe.Pointer(v.native()))
715 }
716
717 func marshalDisplay(p uintptr) (interface{}, error) {
718 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
719 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
720 return &Display{obj}, nil
721 }
722
723 func toDisplay(s *C.GdkDisplay) (*Display, error) {
724 if s == nil {
725 return nil, nilPtrErr
726 }
727 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(s))}
728 return &Display{obj}, nil
729 }
730
731 // DisplayOpen is a wrapper around gdk_display_open().
732 func DisplayOpen(displayName string) (*Display, error) {
733 cstr := C.CString(displayName)
734 defer C.free(unsafe.Pointer(cstr))
735 c := C.gdk_display_open((*C.gchar)(cstr))
736 if c == nil {
737 return nil, nilPtrErr
738 }
739
740 return &Display{glib.Take(unsafe.Pointer(c))}, nil
741 }
742
743 // DisplayGetDefault is a wrapper around gdk_display_get_default().
744 func DisplayGetDefault() (*Display, error) {
745 c := C.gdk_display_get_default()
746 if c == nil {
747 return nil, nilPtrErr
748 }
749
750 return &Display{glib.Take(unsafe.Pointer(c))}, nil
751 }
752
753 // GetName is a wrapper around gdk_display_get_name().
754 func (v *Display) GetName() (string, error) {
755 c := C.gdk_display_get_name(v.native())
756 if c == nil {
757 return "", nilPtrErr
758 }
759 return C.GoString((*C.char)(c)), nil
760 }
761
762 // GetDefaultScreen is a wrapper around gdk_display_get_default_screen().
763 func (v *Display) GetDefaultScreen() (*Screen, error) {
764 c := C.gdk_display_get_default_screen(v.native())
765 if c == nil {
766 return nil, nilPtrErr
767 }
768
769 return &Screen{glib.Take(unsafe.Pointer(c))}, nil
770 }
771
772 // DeviceIsGrabbed is a wrapper around gdk_display_device_is_grabbed().
773 func (v *Display) DeviceIsGrabbed(device *Device) bool {
774 c := C.gdk_display_device_is_grabbed(v.native(), device.native())
775 return gobool(c)
776 }
777
778 // Beep is a wrapper around gdk_display_beep().
779 func (v *Display) Beep() {
780 C.gdk_display_beep(v.native())
781 }
782
783 // Sync is a wrapper around gdk_display_sync().
784 func (v *Display) Sync() {
785 C.gdk_display_sync(v.native())
786 }
787
788 // Flush is a wrapper around gdk_display_flush().
789 func (v *Display) Flush() {
790 C.gdk_display_flush(v.native())
791 }
792
793 // Close is a wrapper around gdk_display_close().
794 func (v *Display) Close() {
795 C.gdk_display_close(v.native())
796 }
797
798 // IsClosed is a wrapper around gdk_display_is_closed().
799 func (v *Display) IsClosed() bool {
800 c := C.gdk_display_is_closed(v.native())
801 return gobool(c)
802 }
803
804 // GetEvent is a wrapper around gdk_display_get_event().
805 func (v *Display) GetEvent() (*Event, error) {
806 c := C.gdk_display_get_event(v.native())
807 if c == nil {
808 return nil, nilPtrErr
809 }
810
811 //The finalizer is not on the glib.Object but on the event.
812 e := &Event{c}
813 runtime.SetFinalizer(e, (*Event).free)
814 return e, nil
815 }
816
817 // PeekEvent is a wrapper around gdk_display_peek_event().
818 func (v *Display) PeekEvent() (*Event, error) {
819 c := C.gdk_display_peek_event(v.native())
820 if c == nil {
821 return nil, nilPtrErr
822 }
823
824 //The finalizer is not on the glib.Object but on the event.
825 e := &Event{c}
826 runtime.SetFinalizer(e, (*Event).free)
827 return e, nil
828 }
829
830 // PutEvent is a wrapper around gdk_display_put_event().
831 func (v *Display) PutEvent(event *Event) {
832 C.gdk_display_put_event(v.native(), event.native())
833 }
834
835 // HasPending is a wrapper around gdk_display_has_pending().
836 func (v *Display) HasPending() bool {
837 c := C.gdk_display_has_pending(v.native())
838 return gobool(c)
839 }
840
841 // SetDoubleClickTime is a wrapper around gdk_display_set_double_click_time().
842 func (v *Display) SetDoubleClickTime(msec uint) {
843 C.gdk_display_set_double_click_time(v.native(), C.guint(msec))
844 }
845
846 // SetDoubleClickDistance is a wrapper around gdk_display_set_double_click_distance().
847 func (v *Display) SetDoubleClickDistance(distance uint) {
848 C.gdk_display_set_double_click_distance(v.native(), C.guint(distance))
849 }
850
851 // SupportsColorCursor is a wrapper around gdk_display_supports_cursor_color().
852 func (v *Display) SupportsColorCursor() bool {
853 c := C.gdk_display_supports_cursor_color(v.native())
854 return gobool(c)
855 }
856
857 // SupportsCursorAlpha is a wrapper around gdk_display_supports_cursor_alpha().
858 func (v *Display) SupportsCursorAlpha() bool {
859 c := C.gdk_display_supports_cursor_alpha(v.native())
860 return gobool(c)
861 }
862
863 // GetDefaultCursorSize is a wrapper around gdk_display_get_default_cursor_size().
864 func (v *Display) GetDefaultCursorSize() uint {
865 c := C.gdk_display_get_default_cursor_size(v.native())
866 return uint(c)
867 }
868
869 // GetMaximalCursorSize is a wrapper around gdk_display_get_maximal_cursor_size().
870 func (v *Display) GetMaximalCursorSize() (width, height uint) {
871 var w, h C.guint
872 C.gdk_display_get_maximal_cursor_size(v.native(), &w, &h)
873 return uint(w), uint(h)
874 }
875
876 // GetDefaultGroup is a wrapper around gdk_display_get_default_group().
877 func (v *Display) GetDefaultGroup() (*Window, error) {
878 c := C.gdk_display_get_default_group(v.native())
879 if c == nil {
880 return nil, nilPtrErr
881 }
882
883 return &Window{glib.Take(unsafe.Pointer(c))}, nil
884 }
885
886 // SupportsSelectionNotification is a wrapper around gdk_display_supports_selection_notification().
887 func (v *Display) SupportsSelectionNotification() bool {
888 c := C.gdk_display_supports_selection_notification(v.native())
889 return gobool(c)
890 }
891
892 // RequestSelectionNotification is a wrapper around gdk_display_request_selection_notification().
893 func (v *Display) RequestSelectionNotification(selection Atom) bool {
894 c := C.gdk_display_request_selection_notification(v.native(),
895 selection.native())
896 return gobool(c)
897 }
898
899 // SupportsClipboardPersistence is a wrapper around gdk_display_supports_clipboard_persistence().
900 func (v *Display) SupportsClipboardPersistence() bool {
901 c := C.gdk_display_supports_clipboard_persistence(v.native())
902 return gobool(c)
903 }
904
905 // TODO:
906 // gdk_display_store_clipboard().
907 // func (v *Display) StoreClipboard(clipboardWindow *Window, time uint32, targets ...Atom) {
908 // panic("Not implemented")
909 // }
910
911 // SupportsShapes is a wrapper around gdk_display_supports_shapes().
912 func (v *Display) SupportsShapes() bool {
913 c := C.gdk_display_supports_shapes(v.native())
914 return gobool(c)
915 }
916
917 // SupportsInputShapes is a wrapper around gdk_display_supports_input_shapes().
918 func (v *Display) SupportsInputShapes() bool {
919 c := C.gdk_display_supports_input_shapes(v.native())
920 return gobool(c)
921 }
922
923 // TODO:
924 // gdk_display_get_app_launch_context().
925 // func (v *Display) GetAppLaunchContext() {
926 // panic("Not implemented")
927 // }
928
929 // NotifyStartupComplete is a wrapper around gdk_display_notify_startup_complete().
930 func (v *Display) NotifyStartupComplete(startupID string) {
931 cstr := C.CString(startupID)
932 defer C.free(unsafe.Pointer(cstr))
933 C.gdk_display_notify_startup_complete(v.native(), (*C.gchar)(cstr))
934 }
935
936 /*
937 * GdkDisplayManager
938 */
939 // DisplayManager is a representation of GDK's GdkDisplayManager.
940 type DisplayManager struct {
941 *glib.Object
942 }
943
944 // native returns a pointer to the underlying GdkDisplayManager.
945 func (v *DisplayManager) native() *C.GdkDisplayManager {
946 if v == nil || v.GObject == nil {
947 return nil
948 }
949 p := unsafe.Pointer(v.GObject)
950 return C.toGdkDisplayManager(p)
951 }
952
953 // Native returns a pointer to the underlying GdkDisplayManager.
954 func (v *DisplayManager) Native() uintptr {
955 return uintptr(unsafe.Pointer(v.native()))
956 }
957
958 func marshalDisplayManager(p uintptr) (interface{}, error) {
959 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
960 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
961 return &DisplayManager{obj}, nil
962 }
963
964 func wrapDisplayManager(obj *glib.Object) *DisplayManager {
965 if obj == nil {
966 return nil
967 }
968 return &DisplayManager{obj}
969 }
970
971 // DisplayManagerGet is a wrapper around gdk_display_manager_get().
972 func DisplayManagerGet() (*DisplayManager, error) {
973 c := C.gdk_display_manager_get()
974 if c == nil {
975 return nil, nilPtrErr
976 }
977 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
978 return &DisplayManager{obj}, nil
979 }
980
981 // GetDefaultDisplay is a wrapper around gdk_display_manager_get_default_display().
982 func (v *DisplayManager) GetDefaultDisplay() (*Display, error) {
983 c := C.gdk_display_manager_get_default_display(v.native())
984 if c == nil {
985 return nil, nilPtrErr
986 }
987 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
988 return &Display{obj}, nil
989 }
990
991 // SetDefaultDisplay is a wrapper around gdk_display_manager_set_default_display().
992 func (v *DisplayManager) SetDefaultDisplay(display *Display) {
993 C.gdk_display_manager_set_default_display(v.native(), display.native())
994 }
995
996 // ListDisplays is a wrapper around gdk_display_manager_list_displays().
997 func (v *DisplayManager) ListDisplays() *[]Display {
998
999 clist := C.gdk_display_manager_list_displays(v.native())
1000 if clist == nil {
1001 return nil
1002 }
1003 dlist := glib.WrapSList(uintptr(unsafe.Pointer(clist)))
1004 defer dlist.Free()
1005
1006 var displays = make([]Display, 0, dlist.Length())
1007 for ; dlist.DataRaw() != nil; dlist = dlist.Next() {
1008 d := (*C.GdkDisplay)(dlist.DataRaw())
1009 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(d))}
1010 displays = append(displays, Display{obj})
1011 }
1012 return &displays
1013 }
1014
1015 // OpenDisplay is a representation of gdk_display_manager_open_display().
1016 func (v *DisplayManager) OpenDisplay(name string) (*Display, error) {
1017 cstr := (*C.gchar)(C.CString(name))
1018 defer C.free(unsafe.Pointer(cstr))
1019
1020 c := C.gdk_display_manager_open_display(v.native(), cstr)
1021 if c == nil {
1022 return nil, nilPtrErr
1023 }
1024 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
1025 return &Display{obj}, nil
1026 }
1027
1028 /*
1029 * GdkKeymap
1030 */
1031
1032 type Keymap struct {
1033 *glib.Object
1034 }
1035
1036 // native returns a pointer to the underlying GdkKeymap.
1037 func (v *Keymap) native() *C.GdkKeymap {
1038 if v == nil || v.GObject == nil {
1039 return nil
1040 }
1041 p := unsafe.Pointer(v.GObject)
1042 return C.toGdkKeymap(p)
1043 }
1044
1045 // Native returns a pointer to the underlying GdkKeymap.
1046 func (v *Keymap) Native() uintptr {
1047 return uintptr(unsafe.Pointer(v.native()))
1048 }
1049
1050 func marshalKeymap(p uintptr) (interface{}, error) {
1051 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
1052 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
1053 return &Keymap{obj}, nil
1054 }
1055
1056 func wrapKeymap(obj *glib.Object) *Keymap {
1057 return &Keymap{obj}
1058 }
1059
1060 // GetKeymap is a wrapper around gdk_keymap_get_for_display().
1061 func (v *Display) GetKeymap() (*Keymap, error) {
1062 c := C.gdk_keymap_get_for_display(v.native())
1063 if c == nil {
1064 return nil, nilPtrErr
1065 }
1066 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
1067 return &Keymap{obj}, nil
1068 }
1069
1070 // TranslateKeyboardState is a wrapper around gdk_keymap_translate_keyboard_state().
1071 func (v *Keymap) TranslateKeyboardState(hardwareKeycode uint, state ModifierType, group int) (bool, *uint, *int, *int, *ModifierType) {
1072
1073 var cKeyval C.guint
1074 var keyval *uint
1075 var cEffectiveGroup, cLevel C.gint
1076 var effectiveGroup, level *int
1077 var cConsumedModifiers C.GdkModifierType
1078 var consumedModifiers *ModifierType
1079
1080 c := C.gdk_keymap_translate_keyboard_state(
1081 v.native(),
1082 C.guint(hardwareKeycode),
1083 C.GdkModifierType(state),
1084 C.gint(group),
1085 &cKeyval,
1086 &cEffectiveGroup,
1087 &cLevel,
1088 &cConsumedModifiers,
1089 )
1090
1091 if &cKeyval == nil {
1092 keyval = nil
1093 } else {
1094 *keyval = uint(cKeyval)
1095 }
1096 if &cEffectiveGroup == nil {
1097 effectiveGroup = nil
1098 } else {
1099 *effectiveGroup = int(cEffectiveGroup)
1100 }
1101 if &cLevel == nil {
1102 level = nil
1103 } else {
1104 *level = int(cLevel)
1105 }
1106 if &cConsumedModifiers == nil {
1107 consumedModifiers = nil
1108 } else {
1109 *consumedModifiers = ModifierType(cConsumedModifiers)
1110 }
1111
1112 return gobool(c), keyval, effectiveGroup, level, consumedModifiers
1113 }
1114
1115 // HaveBidiLayouts is a wrapper around gdk_keymap_have_bidi_layouts().
1116 func (v *Keymap) HaveBidiLayouts() bool {
1117 return gobool(C.gdk_keymap_have_bidi_layouts(v.native()))
1118 }
1119
1120 // GetCapsLockState is a wrapper around gdk_keymap_get_caps_lock_state().
1121 func (v *Keymap) GetCapsLockState() bool {
1122 return gobool(C.gdk_keymap_get_caps_lock_state(v.native()))
1123 }
1124
1125 // GetNumLockState is a wrapper around gdk_keymap_get_num_lock_state().
1126 func (v *Keymap) GetNumLockState() bool {
1127 return gobool(C.gdk_keymap_get_num_lock_state(v.native()))
1128 }
1129
1130 // GetModifierState is a wrapper around gdk_keymap_get_modifier_state().
1131 func (v *Keymap) GetModifierState() uint {
1132 return uint(C.gdk_keymap_get_modifier_state(v.native()))
1133 }
1134
1135 // TODO:
1136 // gdk_keymap_get_default(). deprecated since 3.22
1137 // gdk_keymap_get_direction().
1138 // gdk_keymap_add_virtual_modifiers().
1139 // gdk_keymap_map_virtual_modifiers().
1140 // gdk_keymap_get_modifier_mask().
1141
1142 /*
1143 * GdkKeymapKey
1144 */
1145
1146 // TODO:
1147 // gdk_keymap_lookup_key().
1148 // gdk_keymap_get_entries_for_keyval().
1149 // gdk_keymap_get_entries_for_keycode().
1150
1151 /*
7981152 * GDK Keyval
7991153 */
1154
1155 // TODO:
1156 // gdk_keyval_name().
8001157
8011158 // KeyvalFromName() is a wrapper around gdk_keyval_from_name().
8021159 func KeyvalFromName(keyvalName string) uint {
8051162 return uint(C.gdk_keyval_from_name(str))
8061163 }
8071164
1165 // KeyvalConvertCase is a wrapper around gdk_keyval_convert_case().
8081166 func KeyvalConvertCase(v uint) (lower, upper uint) {
8091167 var l, u C.guint
8101168 l = 0
8131171 return uint(l), uint(u)
8141172 }
8151173
1174 // KeyvalIsLower is a wrapper around gdk_keyval_is_lower().
8161175 func KeyvalIsLower(v uint) bool {
8171176 return gobool(C.gdk_keyval_is_lower(C.guint(v)))
8181177 }
8191178
1179 // KeyvalIsUpper is a wrapper around gdk_keyval_is_upper().
8201180 func KeyvalIsUpper(v uint) bool {
8211181 return gobool(C.gdk_keyval_is_upper(C.guint(v)))
8221182 }
8231183
1184 // KeyvalToLower is a wrapper around gdk_keyval_to_lower().
8241185 func KeyvalToLower(v uint) uint {
8251186 return uint(C.gdk_keyval_to_lower(C.guint(v)))
8261187 }
8271188
1189 // KeyvalToUpper is a wrapper around gdk_keyval_to_upper().
8281190 func KeyvalToUpper(v uint) uint {
8291191 return uint(C.gdk_keyval_to_upper(C.guint(v)))
8301192 }
8311193
1194 // KeyvalToUnicode is a wrapper around gdk_keyval_to_unicode().
8321195 func KeyvalToUnicode(v uint) rune {
8331196 return rune(C.gdk_keyval_to_unicode(C.guint(v)))
8341197 }
8351198
1199 // UnicodeToKeyval is a wrapper around gdk_unicode_to_keyval().
8361200 func UnicodeToKeyval(v rune) uint {
8371201 return uint(C.gdk_unicode_to_keyval(C.guint32(v)))
8381202 }
8671231 }
8681232
8691233 func (v *DragContext) ListTargets() *glib.List {
870 c := C.gdk_drag_context_list_targets(v.native())
871 return glib.WrapList(uintptr(unsafe.Pointer(c)))
1234 clist := C.gdk_drag_context_list_targets(v.native())
1235 if clist == nil {
1236 return nil
1237 }
1238 return glib.WrapList(uintptr(unsafe.Pointer(clist)))
8721239 }
8731240
8741241 /*
9611328 return float64(c)
9621329 }
9631330
964 func (v *EventButton) Button() uint {
1331 func (v *EventButton) Button() Button {
9651332 c := v.native().button
966 return uint(c)
1333 return Button(c)
9671334 }
9681335
9691336 func (v *EventButton) State() uint {
9921359 x := v.native().x_root
9931360 y := v.native().y_root
9941361 return float64(x), float64(y)
995 }
996
997 func (v *EventButton) ButtonVal() uint {
998 c := v.native().button
999 return uint(c)
10001362 }
10011363
10021364 /*
10411403 return uint(c)
10421404 }
10431405
1406 func (v *EventKey) HardwareKeyCode() uint16 {
1407 c := v.native().hardware_keycode
1408 return uint16(c)
1409 }
1410
10441411 func (v *EventKey) Type() EventType {
10451412 c := v.native()._type
10461413 return EventType(c)
14061773 /*
14071774 * GdkGravity
14081775 */
1409 type GdkGravity int
1776
1777 type Gravity int
14101778
14111779 const (
14121780 GDK_GRAVITY_NORTH_WEST = C.GDK_GRAVITY_NORTH_WEST
14211789 GDK_GRAVITY_STATIC = C.GDK_GRAVITY_STATIC
14221790 )
14231791
1424 /*
1425 * GdkPixbuf
1426 */
1427
1428 // Pixbuf is a representation of GDK's GdkPixbuf.
1429 type Pixbuf struct {
1430 *glib.Object
1431 }
1432
1433 // native returns a pointer to the underlying GdkPixbuf.
1434 func (v *Pixbuf) native() *C.GdkPixbuf {
1435 if v == nil || v.GObject == nil {
1436 return nil
1437 }
1438 p := unsafe.Pointer(v.GObject)
1439 return C.toGdkPixbuf(p)
1440 }
1441
1442 // Native returns a pointer to the underlying GdkPixbuf.
1443 func (v *Pixbuf) Native() uintptr {
1444 return uintptr(unsafe.Pointer(v.native()))
1445 }
1446
1447 func (v *Pixbuf) NativePrivate() *C.GdkPixbuf {
1448 if v == nil || v.GObject == nil {
1449 return nil
1450 }
1451 p := unsafe.Pointer(v.GObject)
1452 return C.toGdkPixbuf(p)
1453 }
1454
1455 func marshalPixbuf(p uintptr) (interface{}, error) {
1456 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
1457 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
1458 return &Pixbuf{obj}, nil
1459 }
1460
1461 // GetColorspace is a wrapper around gdk_pixbuf_get_colorspace().
1462 func (v *Pixbuf) GetColorspace() Colorspace {
1463 c := C.gdk_pixbuf_get_colorspace(v.native())
1464 return Colorspace(c)
1465 }
1466
1467 // GetNChannels is a wrapper around gdk_pixbuf_get_n_channels().
1468 func (v *Pixbuf) GetNChannels() int {
1469 c := C.gdk_pixbuf_get_n_channels(v.native())
1470 return int(c)
1471 }
1472
1473 // GetHasAlpha is a wrapper around gdk_pixbuf_get_has_alpha().
1474 func (v *Pixbuf) GetHasAlpha() bool {
1475 c := C.gdk_pixbuf_get_has_alpha(v.native())
1476 return gobool(c)
1477 }
1478
1479 // GetBitsPerSample is a wrapper around gdk_pixbuf_get_bits_per_sample().
1480 func (v *Pixbuf) GetBitsPerSample() int {
1481 c := C.gdk_pixbuf_get_bits_per_sample(v.native())
1482 return int(c)
1483 }
1484
1485 // GetPixels is a wrapper around gdk_pixbuf_get_pixels_with_length().
1486 // A Go slice is used to represent the underlying Pixbuf data array, one
1487 // byte per channel.
1488 func (v *Pixbuf) GetPixels() (channels []byte) {
1489 var length C.guint
1490 c := C.gdk_pixbuf_get_pixels_with_length(v.native(), &length)
1491 sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&channels))
1492 sliceHeader.Data = uintptr(unsafe.Pointer(c))
1493 sliceHeader.Len = int(length)
1494 sliceHeader.Cap = int(length)
1495
1496 // To make sure the slice doesn't outlive the Pixbuf, add a reference
1497 v.Ref()
1498 runtime.SetFinalizer(&channels, func(_ *[]byte) {
1499 v.Unref()
1500 })
1501 return
1502 }
1503
1504 // GetWidth is a wrapper around gdk_pixbuf_get_width().
1505 func (v *Pixbuf) GetWidth() int {
1506 c := C.gdk_pixbuf_get_width(v.native())
1507 return int(c)
1508 }
1509
1510 // GetHeight is a wrapper around gdk_pixbuf_get_height().
1511 func (v *Pixbuf) GetHeight() int {
1512 c := C.gdk_pixbuf_get_height(v.native())
1513 return int(c)
1514 }
1515
1516 // GetRowstride is a wrapper around gdk_pixbuf_get_rowstride().
1517 func (v *Pixbuf) GetRowstride() int {
1518 c := C.gdk_pixbuf_get_rowstride(v.native())
1519 return int(c)
1520 }
1521
1522 // GetByteLength is a wrapper around gdk_pixbuf_get_byte_length().
1523 func (v *Pixbuf) GetByteLength() int {
1524 c := C.gdk_pixbuf_get_byte_length(v.native())
1525 return int(c)
1526 }
1527
1528 // GetOption is a wrapper around gdk_pixbuf_get_option(). ok is true if
1529 // the key has an associated value.
1530 func (v *Pixbuf) GetOption(key string) (value string, ok bool) {
1531 cstr := C.CString(key)
1532 defer C.free(unsafe.Pointer(cstr))
1533 c := C.gdk_pixbuf_get_option(v.native(), (*C.gchar)(cstr))
1534 if c == nil {
1535 return "", false
1536 }
1537 return C.GoString((*C.char)(c)), true
1538 }
1539
1540 // PixbufNew is a wrapper around gdk_pixbuf_new().
1541 func PixbufNew(colorspace Colorspace, hasAlpha bool, bitsPerSample, width, height int) (*Pixbuf, error) {
1542 c := C.gdk_pixbuf_new(C.GdkColorspace(colorspace), gbool(hasAlpha),
1543 C.int(bitsPerSample), C.int(width), C.int(height))
1544 if c == nil {
1545 return nil, nilPtrErr
1546 }
1547
1548 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
1549 p := &Pixbuf{obj}
1550 //obj.Ref()
1551 runtime.SetFinalizer(p, func(_ interface{}) { obj.Unref() })
1552 return p, nil
1553 }
1554
1555 // PixbufCopy is a wrapper around gdk_pixbuf_copy().
1556 func PixbufCopy(v *Pixbuf) (*Pixbuf, error) {
1557 c := C.gdk_pixbuf_copy(v.native())
1558 if c == nil {
1559 return nil, nilPtrErr
1560 }
1561
1562 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
1563 p := &Pixbuf{obj}
1564 //obj.Ref()
1565 runtime.SetFinalizer(p, func(_ interface{}) { obj.Unref() })
1566 return p, nil
1567 }
1568
1569 // PixbufNewFromFile is a wrapper around gdk_pixbuf_new_from_file().
1570 func PixbufNewFromFile(filename string) (*Pixbuf, error) {
1571 cstr := C.CString(filename)
1572 defer C.free(unsafe.Pointer(cstr))
1573
1574 var err *C.GError
1575 c := C.gdk_pixbuf_new_from_file((*C.char)(cstr), &err)
1576 if c == nil {
1577 defer C.g_error_free(err)
1578 return nil, errors.New(C.GoString((*C.char)(err.message)))
1579 }
1580
1581 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
1582 p := &Pixbuf{obj}
1583 //obj.Ref()
1584 runtime.SetFinalizer(p, func(_ interface{}) { obj.Unref() })
1585 return p, nil
1586 }
1587
1588 // PixbufNewFromFileAtSize is a wrapper around gdk_pixbuf_new_from_file_at_size().
1589 func PixbufNewFromFileAtSize(filename string, width, height int) (*Pixbuf, error) {
1590 cstr := C.CString(filename)
1591 defer C.free(unsafe.Pointer(cstr))
1592
1593 var err *C.GError = nil
1594 c := C.gdk_pixbuf_new_from_file_at_size(cstr, C.int(width), C.int(height), &err)
1595 if err != nil {
1596 defer C.g_error_free(err)
1597 return nil, errors.New(C.GoString((*C.char)(err.message)))
1598 }
1599
1600 if c == nil {
1601 return nil, nilPtrErr
1602 }
1603
1604 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
1605 p := &Pixbuf{obj}
1606 //obj.Ref()
1607 runtime.SetFinalizer(p, func(_ interface{}) { obj.Unref() })
1608 return p, nil
1609 }
1610
1611 // PixbufNewFromFileAtScale is a wrapper around gdk_pixbuf_new_from_file_at_scale().
1612 func PixbufNewFromFileAtScale(filename string, width, height int, preserveAspectRatio bool) (*Pixbuf, error) {
1613 cstr := C.CString(filename)
1614 defer C.free(unsafe.Pointer(cstr))
1615
1616 var err *C.GError = nil
1617 c := C.gdk_pixbuf_new_from_file_at_scale(cstr, C.int(width), C.int(height),
1618 gbool(preserveAspectRatio), &err)
1619 if err != nil {
1620 defer C.g_error_free(err)
1621 return nil, errors.New(C.GoString((*C.char)(err.message)))
1622 }
1623
1624 if c == nil {
1625 return nil, nilPtrErr
1626 }
1627
1628 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
1629 p := &Pixbuf{obj}
1630 //obj.Ref()
1631 runtime.SetFinalizer(p, func(_ interface{}) { obj.Unref() })
1632 return p, nil
1633 }
1634
1635 // ScaleSimple is a wrapper around gdk_pixbuf_scale_simple().
1636 func (v *Pixbuf) ScaleSimple(destWidth, destHeight int, interpType InterpType) (*Pixbuf, error) {
1637 c := C.gdk_pixbuf_scale_simple(v.native(), C.int(destWidth),
1638 C.int(destHeight), C.GdkInterpType(interpType))
1639 if c == nil {
1640 return nil, nilPtrErr
1641 }
1642
1643 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
1644 p := &Pixbuf{obj}
1645 //obj.Ref()
1646 runtime.SetFinalizer(p, func(_ interface{}) { obj.Unref() })
1647 return p, nil
1648 }
1649
1650 // RotateSimple is a wrapper around gdk_pixbuf_rotate_simple().
1651 func (v *Pixbuf) RotateSimple(angle PixbufRotation) (*Pixbuf, error) {
1652 c := C.gdk_pixbuf_rotate_simple(v.native(), C.GdkPixbufRotation(angle))
1653 if c == nil {
1654 return nil, nilPtrErr
1655 }
1656
1657 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
1658 p := &Pixbuf{obj}
1659 //obj.Ref()
1660 runtime.SetFinalizer(p, func(_ interface{}) { obj.Unref() })
1661 return p, nil
1662 }
1663
1664 // ApplyEmbeddedOrientation is a wrapper around gdk_pixbuf_apply_embedded_orientation().
1665 func (v *Pixbuf) ApplyEmbeddedOrientation() (*Pixbuf, error) {
1666 c := C.gdk_pixbuf_apply_embedded_orientation(v.native())
1667 if c == nil {
1668 return nil, nilPtrErr
1669 }
1670
1671 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
1672 p := &Pixbuf{obj}
1673 //obj.Ref()
1674 runtime.SetFinalizer(p, func(_ interface{}) { obj.Unref() })
1675 return p, nil
1676 }
1677
1678 // Flip is a wrapper around gdk_pixbuf_flip().
1679 func (v *Pixbuf) Flip(horizontal bool) (*Pixbuf, error) {
1680 c := C.gdk_pixbuf_flip(v.native(), gbool(horizontal))
1681 if c == nil {
1682 return nil, nilPtrErr
1683 }
1684
1685 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
1686 p := &Pixbuf{obj}
1687 //obj.Ref()
1688 runtime.SetFinalizer(p, func(_ interface{}) { obj.Unref() })
1689 return p, nil
1690 }
1691
1692 // SaveJPEG is a wrapper around gdk_pixbuf_save().
1693 // Quality is a number between 0...100
1694 func (v *Pixbuf) SaveJPEG(path string, quality int) error {
1695 cpath := C.CString(path)
1696 cquality := C.CString(strconv.Itoa(quality))
1697 defer C.free(unsafe.Pointer(cpath))
1698 defer C.free(unsafe.Pointer(cquality))
1699
1700 var err *C.GError
1701 c := C._gdk_pixbuf_save_jpeg(v.native(), cpath, &err, cquality)
1702 if !gobool(c) {
1703 defer C.g_error_free(err)
1704 return errors.New(C.GoString((*C.char)(err.message)))
1705 }
1706
1707 return nil
1708 }
1709
1710 // SavePNG is a wrapper around gdk_pixbuf_save().
1711 // Compression is a number between 0...9
1712 func (v *Pixbuf) SavePNG(path string, compression int) error {
1713 cpath := C.CString(path)
1714 ccompression := C.CString(strconv.Itoa(compression))
1715 defer C.free(unsafe.Pointer(cpath))
1716 defer C.free(unsafe.Pointer(ccompression))
1717
1718 var err *C.GError
1719 c := C._gdk_pixbuf_save_png(v.native(), cpath, &err, ccompression)
1720 if !gobool(c) {
1721 defer C.g_error_free(err)
1722 return errors.New(C.GoString((*C.char)(err.message)))
1723 }
1724 return nil
1725 }
1726
1727 // PixbufGetFileInfo is a wrapper around gdk_pixbuf_get_file_info().
1728 // TODO: need to wrap the returned format to GdkPixbufFormat.
1729 func PixbufGetFileInfo(filename string) (format interface{}, width, height int) {
1730 cstr := C.CString(filename)
1731 defer C.free(unsafe.Pointer(cstr))
1732 var cw, ch C.gint
1733 format = C.gdk_pixbuf_get_file_info((*C.gchar)(cstr), &cw, &ch)
1734 // TODO: need to wrap the returned format to GdkPixbufFormat.
1735 return format, int(cw), int(ch)
1736 }
1737
1738 /*
1739 * GdkPixbufAnimation
1740 */
1741
1742 // PixbufAnimation is a representation of GDK's GdkPixbufAnimation.
1743 type PixbufAnimation struct {
1744 *glib.Object
1745 }
1746
1747 // native returns a pointer to the underlying GdkPixbufAnimation.
1748 func (v *PixbufAnimation) native() *C.GdkPixbufAnimation {
1749 if v == nil || v.GObject == nil {
1750 return nil
1751 }
1752 p := unsafe.Pointer(v.GObject)
1753 return C.toGdkPixbufAnimation(p)
1754 }
1755
1756 func (v *PixbufAnimation) NativePrivate() *C.GdkPixbufAnimation {
1757 if v == nil || v.GObject == nil {
1758 return nil
1759 }
1760 p := unsafe.Pointer(v.GObject)
1761 return C.toGdkPixbufAnimation(p)
1762 }
1763
1764 func marshalPixbufAnimation(p uintptr) (interface{}, error) {
1765 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
1766 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
1767 return &PixbufAnimation{obj}, nil
1768 }
1769
1770 // PixbufAnimationNewFromFile is a wrapper around gdk_pixbuf_animation_new_from_file().
1771 func PixbufAnimationNewFromFile(filename string) (*PixbufAnimation, error) {
1772 cstr := C.CString(filename)
1773 defer C.free(unsafe.Pointer(cstr))
1774
1775 var err *C.GError
1776 c := C.gdk_pixbuf_animation_new_from_file((*C.char)(cstr), &err)
1777 if c == nil {
1778 defer C.g_error_free(err)
1779 return nil, errors.New(C.GoString((*C.char)(err.message)))
1780 }
1781
1782 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
1783 p := &PixbufAnimation{obj}
1784 runtime.SetFinalizer(p, func(_ interface{}) { obj.Unref() })
1785 return p, nil
1786 }
1787
1788 /*
1789 * GdkPixbufLoader
1790 */
1791
1792 // PixbufLoader is a representation of GDK's GdkPixbufLoader.
1793 // Users of PixbufLoader are expected to call Close() when they are finished.
1794 type PixbufLoader struct {
1795 *glib.Object
1796 }
1797
1798 // native() returns a pointer to the underlying GdkPixbufLoader.
1799 func (v *PixbufLoader) native() *C.GdkPixbufLoader {
1800 if v == nil || v.GObject == nil {
1801 return nil
1802 }
1803 p := unsafe.Pointer(v.GObject)
1804 return C.toGdkPixbufLoader(p)
1805 }
1806
1807 // PixbufLoaderNew() is a wrapper around gdk_pixbuf_loader_new().
1808 func PixbufLoaderNew() (*PixbufLoader, error) {
1809 c := C.gdk_pixbuf_loader_new()
1810 if c == nil {
1811 return nil, nilPtrErr
1812 }
1813
1814 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
1815 p := &PixbufLoader{obj}
1816 obj.Ref()
1817 runtime.SetFinalizer(p, func(_ interface{}) { obj.Unref() })
1818 return p, nil
1819 }
1820
1821 // PixbufLoaderNewWithType() is a wrapper around gdk_pixbuf_loader_new_with_type().
1822 func PixbufLoaderNewWithType(t string) (*PixbufLoader, error) {
1823 var err *C.GError
1824
1825 cstr := C.CString(t)
1826 defer C.free(unsafe.Pointer(cstr))
1827
1828 c := C.gdk_pixbuf_loader_new_with_type((*C.char)(cstr), &err)
1829 if err != nil {
1830 defer C.g_error_free(err)
1831 return nil, errors.New(C.GoString((*C.char)(err.message)))
1832 }
1833
1834 if c == nil {
1835 return nil, nilPtrErr
1836 }
1837
1838 return &PixbufLoader{glib.Take(unsafe.Pointer(c))}, nil
1839 }
1840
1841 // Write() is a wrapper around gdk_pixbuf_loader_write(). The
1842 // function signature differs from the C equivalent to satisify the
1843 // io.Writer interface.
1844 func (v *PixbufLoader) Write(data []byte) (int, error) {
1845 // n is set to 0 on error, and set to len(data) otherwise.
1846 // This is a tiny hacky to satisfy io.Writer and io.WriteCloser,
1847 // which would allow access to all io and ioutil goodies,
1848 // and play along nice with go environment.
1849
1850 if len(data) == 0 {
1851 return 0, nil
1852 }
1853
1854 var err *C.GError
1855 c := C.gdk_pixbuf_loader_write(v.native(),
1856 (*C.guchar)(unsafe.Pointer(&data[0])), C.gsize(len(data)),
1857 &err)
1858
1859 if !gobool(c) {
1860 defer C.g_error_free(err)
1861 return 0, errors.New(C.GoString((*C.char)(err.message)))
1862 }
1863
1864 return len(data), nil
1865 }
1866
1867 func (v *PixbufLoader) WriteAndReturnPixbuf(data []byte) (*Pixbuf, error) {
1868
1869 if len(data) == 0 {
1870 return nil, errors.New("no data")
1871 }
1872
1873 var err *C.GError
1874 c := C.gdk_pixbuf_loader_write(v.native(), (*C.guchar)(unsafe.Pointer(&data[0])), C.gsize(len(data)), &err)
1875
1876 if !gobool(c) {
1877 defer C.g_error_free(err)
1878 return nil, errors.New(C.GoString((*C.char)(err.message)))
1879 }
1880
1881 v.Close()
1882
1883 c2 := C.gdk_pixbuf_loader_get_pixbuf(v.native())
1884 if c2 == nil {
1885 return nil, nilPtrErr
1886 }
1887
1888 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c2))}
1889 p := &Pixbuf{obj}
1890 //obj.Ref() // Don't call Ref here, gdk_pixbuf_loader_get_pixbuf already did that for us.
1891 runtime.SetFinalizer(p, func(_ interface{}) { obj.Unref() })
1892
1893 return p, nil
1894 }
1895
1896 // Close is a wrapper around gdk_pixbuf_loader_close(). An error is
1897 // returned instead of a bool like the native C function to support the
1898 // io.Closer interface.
1899 func (v *PixbufLoader) Close() error {
1900 var err *C.GError
1901
1902 if ok := gobool(C.gdk_pixbuf_loader_close(v.native(), &err)); !ok {
1903 defer C.g_error_free(err)
1904 return errors.New(C.GoString((*C.char)(err.message)))
1905 }
1906 return nil
1907 }
1908
1909 // SetSize is a wrapper around gdk_pixbuf_loader_set_size().
1910 func (v *PixbufLoader) SetSize(width, height int) {
1911 C.gdk_pixbuf_loader_set_size(v.native(), C.int(width), C.int(height))
1912 }
1913
1914 // GetPixbuf is a wrapper around gdk_pixbuf_loader_get_pixbuf().
1915 func (v *PixbufLoader) GetPixbuf() (*Pixbuf, error) {
1916 c := C.gdk_pixbuf_loader_get_pixbuf(v.native())
1917 if c == nil {
1918 return nil, nilPtrErr
1919 }
1920
1921 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
1922 p := &Pixbuf{obj}
1923 //obj.Ref() // Don't call Ref here, gdk_pixbuf_loader_get_pixbuf already did that for us.
1924 runtime.SetFinalizer(p, func(_ interface{}) { obj.Unref() })
1925 return p, nil
1926 }
1927
1928 // GetAnimation is a wrapper around gdk_pixbuf_loader_get_animation().
1929 func (v *PixbufLoader) GetAnimation() (*PixbufAnimation, error) {
1930 c := C.gdk_pixbuf_loader_get_animation(v.native())
1931 if c == nil {
1932 return nil, nilPtrErr
1933 }
1934
1935 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
1936 p := &PixbufAnimation{obj}
1937 runtime.SetFinalizer(p, func(_ interface{}) { obj.Unref() })
1938 return p, nil
1939 }
1940
1941 // Convenient function like above for Pixbuf. Write data, close loader and return PixbufAnimation.
1942 func (v *PixbufLoader) WriteAndReturnPixbufAnimation(data []byte) (*PixbufAnimation, error) {
1943
1944 if len(data) == 0 {
1945 return nil, errors.New("no data")
1946 }
1947
1948 var err *C.GError
1949 c := C.gdk_pixbuf_loader_write(v.native(), (*C.guchar)(unsafe.Pointer(&data[0])), C.gsize(len(data)), &err)
1950
1951 if !gobool(c) {
1952 defer C.g_error_free(err)
1953 return nil, errors.New(C.GoString((*C.char)(err.message)))
1954 }
1955
1956 v.Close()
1957
1958 c2 := C.gdk_pixbuf_loader_get_animation(v.native())
1959 if c2 == nil {
1960 return nil, nilPtrErr
1961 }
1962
1963 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c2))}
1964 p := &PixbufAnimation{obj}
1965 runtime.SetFinalizer(p, func(_ interface{}) { obj.Unref() })
1966
1967 return p, nil
1968 }
1969
1792 func marshalGravity(p uintptr) (interface{}, error) {
1793 c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
1794 return Gravity(c), nil
1795 }
1796
1797 /*
1798 * GdkRGBA
1799 */
1800 // To create a GdkRGBA you have to use NewRGBA function.
19701801 type RGBA struct {
19711802 rgba *C.GdkRGBA
19721803 }
19801811 return wrapRGBA((*C.GdkRGBA)(p))
19811812 }
19821813
1983 func wrapRGBA(obj *C.GdkRGBA) *RGBA {
1984 return &RGBA{obj}
1814 func wrapRGBA(cRgba *C.GdkRGBA) *RGBA {
1815 if cRgba == nil {
1816 return nil
1817 }
1818 return &RGBA{cRgba}
19851819 }
19861820
19871821 func NewRGBA(values ...float64) *RGBA {
1988 cval := C.GdkRGBA{}
1989 c := &RGBA{&cval}
1990 if len(values) > 0 {
1991 c.rgba.red = C.gdouble(values[0])
1992 }
1993 if len(values) > 1 {
1994 c.rgba.green = C.gdouble(values[1])
1995 }
1996 if len(values) > 2 {
1997 c.rgba.blue = C.gdouble(values[2])
1998 }
1999 if len(values) > 3 {
2000 c.rgba.alpha = C.gdouble(values[3])
2001 }
2002 return c
1822 cRgba := new(C.GdkRGBA)
1823 for i, value := range values {
1824 switch i {
1825 case 0:
1826 cRgba.red = C.gdouble(value)
1827 case 1:
1828 cRgba.green = C.gdouble(value)
1829 case 2:
1830 cRgba.blue = C.gdouble(value)
1831 case 3:
1832 cRgba.alpha = C.gdouble(value)
1833 }
1834 }
1835 return wrapRGBA(cRgba)
20031836 }
20041837
20051838 func (c *RGBA) Floats() []float64 {
2006 return []float64{float64(c.rgba.red), float64(c.rgba.green), float64(c.rgba.blue), float64(c.rgba.alpha)}
1839 return []float64{
1840 float64(c.rgba.red),
1841 float64(c.rgba.green),
1842 float64(c.rgba.blue),
1843 float64(c.rgba.alpha)}
1844 }
1845
1846 func (c *RGBA) Native() uintptr {
1847 return uintptr(unsafe.Pointer(c.rgba))
20071848 }
20081849
20091850 // SetColors sets all colors values in the RGBA.
20141855 c.rgba.alpha = C.gdouble(a)
20151856 }
20161857
2017 func (v *RGBA) Native() uintptr {
2018 return uintptr(unsafe.Pointer(v.rgba))
1858 /*
1859 * The following methods (Get/Set) are made for
1860 * more convenient use of the GdkRGBA object
1861 */
1862 // GetRed get red value from the RGBA.
1863 func (c *RGBA) GetRed() float64 {
1864 return float64(c.rgba.red)
1865 }
1866
1867 // GetGreen get green value from the RGBA.
1868 func (c *RGBA) GetGreen() float64 {
1869 return float64(c.rgba.green)
1870 }
1871
1872 // GetBlue get blue value from the RGBA.
1873 func (c *RGBA) GetBlue() float64 {
1874 return float64(c.rgba.blue)
1875 }
1876
1877 // GetAlpha get alpha value from the RGBA.
1878 func (c *RGBA) GetAlpha() float64 {
1879 return float64(c.rgba.alpha)
1880 }
1881
1882 // SetRed set red value in the RGBA.
1883 func (c *RGBA) SetRed(red float64) {
1884 c.rgba.red = C.gdouble(red)
1885 }
1886
1887 // SetGreen set green value in the RGBA.
1888 func (c *RGBA) SetGreen(green float64) {
1889 c.rgba.green = C.gdouble(green)
1890 }
1891
1892 // SetBlue set blue value in the RGBA.
1893 func (c *RGBA) SetBlue(blue float64) {
1894 c.rgba.blue = C.gdouble(blue)
1895 }
1896
1897 // SetAlpha set alpha value in the RGBA.
1898 func (c *RGBA) SetAlpha(alpha float64) {
1899 c.rgba.alpha = C.gdouble(alpha)
20191900 }
20201901
20211902 // Parse is a representation of gdk_rgba_parse().
2022 func (v *RGBA) Parse(spec string) bool {
1903 func (c *RGBA) Parse(spec string) bool {
20231904 cstr := (*C.gchar)(C.CString(spec))
20241905 defer C.free(unsafe.Pointer(cstr))
20251906
2026 return gobool(C.gdk_rgba_parse(v.rgba, cstr))
1907 return gobool(C.gdk_rgba_parse(c.rgba, cstr))
20271908 }
20281909
20291910 // String is a representation of gdk_rgba_to_string().
2030 func (v *RGBA) String() string {
2031 return C.GoString((*C.char)(C.gdk_rgba_to_string(v.rgba)))
2032 }
2033
2034 // GdkRGBA * gdk_rgba_copy ()
2035 // void gdk_rgba_free ()
2036 // gboolean gdk_rgba_equal ()
2037 // guint gdk_rgba_hash ()
2038
2039 // PixbufGetType is a wrapper around gdk_pixbuf_get_type().
2040 func PixbufGetType() glib.Type {
2041 return glib.Type(C.gdk_pixbuf_get_type())
1911 func (c *RGBA) String() string {
1912 return C.GoString((*C.char)(C.gdk_rgba_to_string(c.rgba)))
1913 }
1914
1915 // free is a representation of gdk_rgba_free().
1916 func (c *RGBA) free() {
1917 C.gdk_rgba_free(c.rgba)
1918 }
1919
1920 // Copy is a representation of gdk_rgba_copy().
1921 func (c *RGBA) Copy() (*RGBA, error) {
1922 cRgba := C.gdk_rgba_copy(c.rgba)
1923
1924 if c == nil {
1925 return nil, nilPtrErr
1926 }
1927 obj := wrapRGBA(cRgba)
1928
1929 runtime.SetFinalizer(obj, (*RGBA).free)
1930 return obj, nil
1931 }
1932
1933 // Equal is a representation of gdk_rgba_equal().
1934 func (c *RGBA) Equal(rgba *RGBA) bool {
1935 return gobool(C.gdk_rgba_equal(
1936 C.gconstpointer(c.rgba),
1937 C.gconstpointer(rgba.rgba)))
1938 }
1939
1940 // Hash is a representation of gdk_rgba_hash().
1941 func (c *RGBA) Hash() uint {
1942 return uint(C.gdk_rgba_hash(C.gconstpointer(c.rgba)))
1943 }
1944
1945 /*
1946 * GdkPoint
1947 */
1948
1949 // Point is a representation of GDK's GdkPoint type.
1950 type Point struct {
1951 GdkPoint C.GdkPoint
1952 }
1953
1954 func WrapPoint(p uintptr) *Point {
1955 return wrapPoint((*C.GdkPoint)(unsafe.Pointer(p)))
1956 }
1957
1958 func wrapPoint(obj *C.GdkPoint) *Point {
1959 if obj == nil {
1960 return nil
1961 }
1962 return &Point{*obj}
1963 }
1964
1965 // Native() returns a pointer to the underlying GdkPoint.
1966 func (v *Point) native() *C.GdkPoint {
1967 return &v.GdkPoint
1968 }
1969
1970 // PointNew helper function to create a GdkPoint
1971 func PointNew(x, y int) *Point {
1972 var p C.GdkPoint
1973 p.x = C.gint(x)
1974 p.y = C.gint(y)
1975 return &Point{p}
1976 }
1977
1978 // GetPointInt helper function to get GdkPoint values
1979 func (v *Point) GetPointInt() (x, y int) {
1980 return int(v.native().x), int(v.native().y)
1981 }
1982
1983 // SetPointInt helper function to set GdkPoint values
1984 func (v *Point) SetPointInt(x, y int) {
1985 v.native().x = C.gint(x)
1986 v.native().y = C.gint(y)
1987 }
1988
1989 // GetX returns x field of the underlying GdkPoint.
1990 func (v *Point) GetX() int {
1991 return int(v.native().x)
1992 }
1993
1994 // SetX sets x field of the underlying GdkPoint.
1995 func (v *Point) SetX(x int) {
1996 v.native().x = C.gint(x)
1997 }
1998
1999 // GetY returns y field of the underlying GdkPoint.
2000 func (v *Point) GetY() int {
2001 return int(v.native().y)
2002 }
2003
2004 // SetY sets y field of the underlying GdkPoint.
2005 func (v *Point) SetY(y int) {
2006 v.native().y = C.gint(y)
20422007 }
20432008
20442009 /*
20662031 return &r.GdkRectangle
20672032 }
20682033
2034 // RectangleIntersect is a wrapper around gdk_rectangle_intersect().
2035 func (v *Rectangle) RectangleIntersect(rect *Rectangle) (*Rectangle, bool) {
2036 r := new(C.GdkRectangle)
2037 c := C.gdk_rectangle_intersect(v.native(), rect.native(), r)
2038 return wrapRectangle(r), gobool(c)
2039 }
2040
2041 // RectangleUnion is a wrapper around gdk_rectangle_union().
2042 func (v *Rectangle) RectangleUnion(rect *Rectangle) *Rectangle {
2043 r := new(C.GdkRectangle)
2044 C.gdk_rectangle_union(v.native(), rect.native(), r)
2045 return wrapRectangle(r)
2046 }
2047
2048 // RectangleNew helper function to create a GdkRectanlge
2049 func RectangleNew(x, y, width, height int) *Rectangle {
2050 var r C.GdkRectangle
2051 r.x = C.int(x)
2052 r.y = C.int(y)
2053 r.width = C.int(width)
2054 r.height = C.int(height)
2055 return &Rectangle{r}
2056 }
2057
2058 // SetRectangleInt helper function to set GdkRectanlge values
2059 func (v *Rectangle) SetRectangleInt(x, y, width, height int) {
2060 v.native().x = C.int(x)
2061 v.native().y = C.int(y)
2062 v.native().width = C.int(width)
2063 v.native().height = C.int(height)
2064 }
2065
2066 // GetRectangleInt helper function to get GdkRectanlge values
2067 func (v *Rectangle) GetRectangleInt() (x, y, width, height int) {
2068 return int(v.native().x),
2069 int(v.native().y),
2070 int(v.native().width),
2071 int(v.native().height)
2072 }
2073
20692074 // GetX returns x field of the underlying GdkRectangle.
20702075 func (r *Rectangle) GetX() int {
20712076 return int(r.native().x)
21042109 // SetHeight sets height field of the underlying GdkRectangle.
21052110 func (r *Rectangle) SetHeight(height int) {
21062111 r.native().height = C.int(height)
2112 }
2113
2114 /*
2115 * GdkGeometry
2116 */
2117
2118 type Geometry struct {
2119 GdkGeometry C.GdkGeometry
2120 }
2121
2122 func WrapGeometry(p uintptr) *Geometry {
2123 return wrapGeometry((*C.GdkGeometry)(unsafe.Pointer(p)))
2124 }
2125
2126 func wrapGeometry(obj *C.GdkGeometry) *Geometry {
2127 if obj == nil {
2128 return nil
2129 }
2130 return &Geometry{*obj}
2131 }
2132
2133 // native returns a pointer to the underlying GdkGeometry.
2134 func (r *Geometry) native() *C.GdkGeometry {
2135 return &r.GdkGeometry
2136 }
2137
2138 // GetMinWidth returns min_width field of the underlying GdkGeometry.
2139 func (r *Geometry) GetMinWidth() int {
2140 return int(r.native().min_width)
2141 }
2142
2143 // SetMinWidth sets min_width field of the underlying GdkGeometry.
2144 func (r *Geometry) SetMinWidth(minWidth int) {
2145 r.native().min_width = C.gint(minWidth)
2146 }
2147
2148 // GetMinHeight returns min_height field of the underlying GdkGeometry.
2149 func (r *Geometry) GetMinHeight() int {
2150 return int(r.native().min_height)
2151 }
2152
2153 // SetMinHeight sets min_height field of the underlying GdkGeometry.
2154 func (r *Geometry) SetMinHeight(minHeight int) {
2155 r.native().min_height = C.gint(minHeight)
2156 }
2157
2158 // GetMaxWidth returns max_width field of the underlying GdkGeometry.
2159 func (r *Geometry) GetMaxWidth() int {
2160 return int(r.native().max_width)
2161 }
2162
2163 // SetMaxWidth sets max_width field of the underlying GdkGeometry.
2164 func (r *Geometry) SetMaxWidth(maxWidth int) {
2165 r.native().max_width = C.gint(maxWidth)
2166 }
2167
2168 // GetMaxHeight returns max_height field of the underlying GdkGeometry.
2169 func (r *Geometry) GetMaxHeight() int {
2170 return int(r.native().max_height)
2171 }
2172
2173 // SetMaxHeight sets max_height field of the underlying GdkGeometry.
2174 func (r *Geometry) SetMaxHeight(maxHeight int) {
2175 r.native().max_height = C.gint(maxHeight)
2176 }
2177
2178 // GetBaseWidth returns base_width field of the underlying GdkGeometry.
2179 func (r *Geometry) GetBaseWidth() int {
2180 return int(r.native().base_width)
2181 }
2182
2183 // SetBaseWidth sets base_width field of the underlying GdkGeometry.
2184 func (r *Geometry) SetBaseWidth(baseWidth int) {
2185 r.native().base_width = C.gint(baseWidth)
2186 }
2187
2188 // GetBaseHeight returns base_height field of the underlying GdkGeometry.
2189 func (r *Geometry) GetBaseHeight() int {
2190 return int(r.native().base_height)
2191 }
2192
2193 // SetBaseHeight sets base_height field of the underlying GdkGeometry.
2194 func (r *Geometry) SetBaseHeight(baseHeight int) {
2195 r.native().base_height = C.gint(baseHeight)
2196 }
2197
2198 // GetWidthInc returns width_inc field of the underlying GdkGeometry.
2199 func (r *Geometry) GetWidthInc() int {
2200 return int(r.native().width_inc)
2201 }
2202
2203 // SetWidthInc sets width_inc field of the underlying GdkGeometry.
2204 func (r *Geometry) SetWidthInc(widthInc int) {
2205 r.native().width_inc = C.gint(widthInc)
2206 }
2207
2208 // GetHeightInc returns height_inc field of the underlying GdkGeometry.
2209 func (r *Geometry) GetHeightInc() int {
2210 return int(r.native().height_inc)
2211 }
2212
2213 // SetHeightInc sets height_inc field of the underlying GdkGeometry.
2214 func (r *Geometry) SetHeightInc(heightInc int) {
2215 r.native().height_inc = C.gint(heightInc)
2216 }
2217
2218 // GetMinAspect returns min_aspect field of the underlying GdkGeometry.
2219 func (r *Geometry) GetMinAspect() float64 {
2220 return float64(r.native().min_aspect)
2221 }
2222
2223 // SetMinAspect sets min_aspect field of the underlying GdkGeometry.
2224 func (r *Geometry) SetMinAspect(minAspect float64) {
2225 r.native().min_aspect = C.gdouble(minAspect)
2226 }
2227
2228 // GetMaxAspect returns max_aspect field of the underlying GdkGeometry.
2229 func (r *Geometry) GetMaxAspect() float64 {
2230 return float64(r.native().max_aspect)
2231 }
2232
2233 // SetMaxAspect sets max_aspect field of the underlying GdkGeometry.
2234 func (r *Geometry) SetMaxAspect(maxAspect float64) {
2235 r.native().max_aspect = C.gdouble(maxAspect)
2236 }
2237
2238 // GetWinGravity returns win_gravity field of the underlying GdkGeometry.
2239 func (r *Geometry) GetWinGravity() Gravity {
2240 return Gravity(r.native().win_gravity)
2241 }
2242
2243 // SetWinGravity sets win_gravity field of the underlying GdkGeometry.
2244 func (r *Geometry) SetWinGravity(winGravity Gravity) {
2245 r.native().win_gravity = C.GdkGravity(winGravity)
21072246 }
21082247
21092248 /*
21332272 return &Visual{obj}, nil
21342273 }
21352274
2275 // GetBluePixelDetails is a wrapper around gdk_visual_get_blue_pixel_details().
2276 func (v *Visual) GetBluePixelDetails() (*uint32, *int, *int) {
2277 var (
2278 m *uint32 = nil
2279 s, p *int = nil, nil
2280 mask C.guint32
2281 shift, precision C.gint
2282 )
2283 C.gdk_visual_get_blue_pixel_details(v.native(), &mask, &shift, &precision)
2284 if &mask != nil {
2285 m = new(uint32)
2286 *m = uint32(mask)
2287 }
2288 if &shift != nil {
2289 s = new(int)
2290 *s = int(shift)
2291 }
2292 if &precision != nil {
2293 p = new(int)
2294 *p = int(precision)
2295 }
2296 return m, s, p
2297 }
2298
2299 // GetDepth is a wrapper around gdk_visual_get_depth().
2300 func (v *Visual) GetDepth() int {
2301 return int(C.gdk_visual_get_depth(v.native()))
2302 }
2303
2304 // GetGreenPixelDetails is a wrapper around gdk_visual_get_green_pixel_details().
2305 func (v *Visual) GetGreenPixelDetails() (*uint32, *int, *int) {
2306 var (
2307 m *uint32 = nil
2308 s, p *int = nil, nil
2309 mask C.guint32
2310 shift, precision C.gint
2311 )
2312 C.gdk_visual_get_green_pixel_details(v.native(), &mask, &shift, &precision)
2313 if &mask != nil {
2314 m = new(uint32)
2315 *m = uint32(mask)
2316 }
2317 if &shift != nil {
2318 s = new(int)
2319 *s = int(shift)
2320 }
2321 if &precision != nil {
2322 p = new(int)
2323 *p = int(precision)
2324 }
2325 return m, s, p
2326 }
2327
2328 // GetRedPixelDetails is a wrapper around gdk_visual_get_red_pixel_details().
2329 func (v *Visual) GetRedPixelDetails() (*uint32, *int, *int) {
2330 var (
2331 m *uint32 = nil
2332 s, p *int = nil, nil
2333 mask C.guint32
2334 shift, precision C.gint
2335 )
2336 C.gdk_visual_get_red_pixel_details(v.native(), &mask, &shift, &precision)
2337 if &mask != nil {
2338 m = new(uint32)
2339 *m = uint32(mask)
2340 }
2341 if &shift != nil {
2342 s = new(int)
2343 *s = int(shift)
2344 }
2345 if &precision != nil {
2346 p = new(int)
2347 *p = int(precision)
2348 }
2349 return m, s, p
2350 }
2351
2352 // GetVisualType is a wrapper around gdk_visual_get_visual_type().
2353 func (v *Visual) GetVisualType() VisualType {
2354 return VisualType(C.gdk_visual_get_visual_type(v.native()))
2355 }
2356
2357 // GetScreen is a wrapper around gdk_visual_get_screen().
2358 func (v *Visual) GetScreen() (*Screen, error) {
2359 return toScreen(C.gdk_visual_get_screen(v.native()))
2360 }
2361
21362362 /*
21372363 * GdkWindow
21382364 */
21692395 // WindowGetHeight is a wrapper around gdk_window_get_height()
21702396 func (v *Window) WindowGetHeight() (height int) {
21712397 return int(C.gdk_window_get_height(v.native()))
2398 }
2399
2400 // CreateSimilarSurface is a wrapper around gdk_window_create_similar_surface().
2401 func (v *Window) CreateSimilarSurface(content cairo.Content, w, h int) (*cairo.Surface, error) {
2402 surface := C.gdk_window_create_similar_surface(v.native(), C.cairo_content_t(content), C.gint(w), C.gint(h))
2403
2404 status := cairo.Status(C.cairo_surface_status(surface))
2405 if status != cairo.STATUS_SUCCESS {
2406 return nil, cairo.ErrorStatus(status)
2407 }
2408
2409 return cairo.NewSurface(uintptr(unsafe.Pointer(surface)), false), nil
21722410 }
21732411
21742412 //PixbufGetFromWindow is a wrapper around gdk_pixbuf_get_from_window()
21852423 return p, nil
21862424 }
21872425
2426 // GetDevicePosition is a wrapper around gdk_window_get_device_position()
2427 func (v *Window) GetDevicePosition(d *Device) (*Window, int, int, ModifierType) {
2428 var x C.gint
2429 var y C.gint
2430 var mt C.GdkModifierType
2431 underneathWindow := C.gdk_window_get_device_position(v.native(), d.native(), &x, &y, &mt)
2432 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(underneathWindow))}
2433 rw := &Window{obj}
2434 runtime.SetFinalizer(rw, func(_ interface{}) { obj.Unref() })
2435 return rw, int(x), int(y), ModifierType(mt)
2436 }
2437
2438 func PixbufGetFromSurface(surface *cairo.Surface, src_x, src_y, width, height int) (*Pixbuf, error) {
2439 c := C.gdk_pixbuf_get_from_surface((*C.cairo_surface_t)(unsafe.Pointer(surface.Native())), C.gint(src_x), C.gint(src_y), C.gint(width), C.gint(height))
2440 if c == nil {
2441 return nil, nilPtrErr
2442 }
2443
2444 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
2445 p := &Pixbuf{obj}
2446 //obj.Ref()
2447 runtime.SetFinalizer(p, func(_ interface{}) { obj.Unref() })
2448 return p, nil
2449 }
2450
21882451 func marshalWindow(p uintptr) (interface{}, error) {
21892452 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
21902453 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
1818 #include <stdlib.h>
1919
2020 // Type Casting
21 static GdkAtom
22 toGdkAtom(void *p)
23 {
24 return ((GdkAtom)p);
21 static GdkAtom toGdkAtom(void *p) { return ((GdkAtom)p); }
22
23 static GdkDevice *toGdkDevice(void *p) { return (GDK_DEVICE(p)); }
24
25 static GdkCursor *toGdkCursor(void *p) { return (GDK_CURSOR(p)); }
26
27 static GdkDeviceManager *toGdkDeviceManager(void *p) {
28 return (GDK_DEVICE_MANAGER(p));
2529 }
2630
27 static GdkDevice *
28 toGdkDevice(void *p)
29 {
30 return (GDK_DEVICE(p));
31 static GdkDisplay *toGdkDisplay(void *p) { return (GDK_DISPLAY(p)); }
32
33 static GdkDisplayManager *toGdkDisplayManager(void *p) { return (GDK_DISPLAY_MANAGER(p)); }
34
35 static GdkKeymap *toGdkKeymap(void *p) { return (GDK_KEYMAP(p)); }
36
37 static GdkDragContext *toGdkDragContext(void *p) {
38 return (GDK_DRAG_CONTEXT(p));
3139 }
3240
33 static GdkCursor *
34 toGdkCursor(void *p)
35 {
36 return (GDK_CURSOR(p));
37 }
41 static GdkScreen *toGdkScreen(void *p) { return (GDK_SCREEN(p)); }
3842
39 static GdkDeviceManager *
40 toGdkDeviceManager(void *p)
41 {
42 return (GDK_DEVICE_MANAGER(p));
43 }
43 static GdkVisual *toGdkVisual(void *p) { return (GDK_VISUAL(p)); }
4444
45 static GdkDisplay *
46 toGdkDisplay(void *p)
47 {
48 return (GDK_DISPLAY(p));
49 }
45 static GdkWindow *toGdkWindow(void *p) { return (GDK_WINDOW(p)); }
5046
51 static GdkDragContext *
52 toGdkDragContext(void *p)
53 {
54 return (GDK_DRAG_CONTEXT(p));
55 }
56
57 static GdkPixbuf *
58 toGdkPixbuf(void *p)
59 {
60 return (GDK_PIXBUF(p));
61 }
62
63 static GdkPixbufAnimation *
64 toGdkPixbufAnimation(void *p)
65 {
66 return (GDK_PIXBUF_ANIMATION(p));
67 }
68
69 static gboolean
70 _gdk_pixbuf_save_png(GdkPixbuf *pixbuf,
71 const char *filename, GError ** err, const char *compression)
72 {
73 return gdk_pixbuf_save(pixbuf, filename, "png", err, "compression", compression, NULL);
74 }
75
76 static gboolean
77 _gdk_pixbuf_save_jpeg(GdkPixbuf *pixbuf,
78 const char *filename, GError ** err, const char *quality)
79 {
80 return gdk_pixbuf_save(pixbuf, filename, "jpeg", err, "quality", quality, NULL);
81 }
82
83 static GdkPixbufLoader *
84 toGdkPixbufLoader(void *p)
85 {
86 return (GDK_PIXBUF_LOADER(p));
87 }
88
89 static GdkScreen *
90 toGdkScreen(void *p)
91 {
92 return (GDK_SCREEN(p));
93 }
94
95 static GdkVisual *
96 toGdkVisual(void *p)
97 {
98 return (GDK_VISUAL(p));
99 }
100
101 static GdkWindow *
102 toGdkWindow(void *p)
103 {
104 return (GDK_WINDOW(p));
105 }
106
107 static inline gchar** next_gcharptr(gchar** s) { return (s+1); }
47 static inline gchar **next_gcharptr(gchar **s) { return (s + 1); }
0 // Copyright (c) 2013-2014 Conformal Systems <info@conformal.com>
1 //
2 // This file originated from: http://opensource.conformal.com/
3 //
4 // Permission to use, copy, modify, and distribute this software for any
5 // purpose with or without fee is hereby granted, provided that the above
6 // copyright notice and this permission notice appear in all copies.
7 //
8 // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
16 // This file includes wrappers for symbols deprecated beginning with GTK 3.10,
17 // and should only be included in a build targeted intended to target GTK
18 // 3.8 or earlier. To target an earlier build build, use the build tag
19 // gtk_MAJOR_MINOR. For example, to target GTK 3.8, run
20 // 'go build -tags gtk_3_8'.
21 // +build gtk_3_6 gtk_3_8 gtk_deprecated
22
23 package gdk
24
25 // #include <gdk/gdk.h>
26 import "C"
27
28 // GetNScreens is a wrapper around gdk_display_get_n_screens().
29 func (v *Display) GetNScreens() int {
30 c := C.gdk_display_get_n_screens(v.native())
31 return int(c)
32 }
0 //+build gtk_3_6 gtk_3_8 gtk_3_10 gtk_3_12 gtk_3_14
0 //+build gtk_3_6 gtk_3_8 gtk_3_10 gtk_3_12 gtk_3_14 gtk_deprecated
11
22 package gdk
33
0 //+build gtk_3_6 gtk_3_8 gtk_3_10 gtk_3_12 gtk_3_14 gtk_3_16 gtk_3_18
0 //+build gtk_3_6 gtk_3_8 gtk_3_10 gtk_3_12 gtk_3_14 gtk_3_16 gtk_3_18 gtk_deprecated
11
22 package gdk
33
0 //+build gtk_3_6 gtk_3_8 gtk_3_10 gtk_3_12 gtk_3_14 gtk_3_16 gtk_3_18 gtk_3_20
0 //+build gtk_3_6 gtk_3_8 gtk_3_10 gtk_3_12 gtk_3_14 gtk_3_16 gtk_3_18 gtk_3_20 gtk_deprecated
11
22 package gdk
33
44 // #include <gdk/gdk.h>
55 import "C"
6
7 /*
8 * Constants
9 */
10
11 // TODO:
12 // GdkByteOrder
13
14 /*
15 * GdkScreen
16 */
617
718 // GetActiveWindow is a wrapper around gdk_screen_get_active_window().
819 func (v *Screen) GetActiveWindow() (*Window, error) {
8091 func (v *Screen) MakeDisplayName() (string, error) {
8192 return toString(C.gdk_screen_make_display_name(v.native()))
8293 }
94
95 /*
96 * GdkVisuals
97 */
98
99 // TODO:
100 // gdk_query_depths().
101 // gdk_query_visual_types().
102 // gdk_list_visuals().
103 // gdk_visual_get_bits_per_rgb().
104 // gdk_visual_get_byte_order().
105 // gdk_visual_get_colormap_size().
106 // gdk_visual_get_best_depth().
107 // gdk_visual_get_best_type().
108 // gdk_visual_get_system().
109 // gdk_visual_get_best().
110 // gdk_visual_get_best_with_depth().
111 // gdk_visual_get_best_with_type().
112 // gdk_visual_get_best_with_both().
+0
-33
gdk/gdk_deprecated_since_3_8.go less more
0 // Copyright (c) 2013-2014 Conformal Systems <info@conformal.com>
1 //
2 // This file originated from: http://opensource.conformal.com/
3 //
4 // Permission to use, copy, modify, and distribute this software for any
5 // purpose with or without fee is hereby granted, provided that the above
6 // copyright notice and this permission notice appear in all copies.
7 //
8 // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 // WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 // MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 // ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 // WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15
16 // This file includes wrappers for symbols deprecated beginning with GTK 3.10,
17 // and should only be included in a build targeted intended to target GTK
18 // 3.8 or earlier. To target an earlier build build, use the build tag
19 // gtk_MAJOR_MINOR. For example, to target GTK 3.8, run
20 // 'go build -tags gtk_3_8'.
21 // +build gtk_3_6 gtk_3_8
22
23 package gdk
24
25 // #include <gdk/gdk.h>
26 import "C"
27
28 // GetNScreens is a wrapper around gdk_display_get_n_screens().
29 func (v *Display) GetNScreens() int {
30 c := C.gdk_display_get_n_screens(v.native())
31 return int(c)
32 }
+0
-89
gdk/gdk_pixbuf_format.go less more
0 package gdk
1
2 // #include <gdk/gdk.h>
3 // #include "gdk.go.h"
4 import "C"
5 import (
6 "unsafe"
7
8 "github.com/gotk3/gotk3/glib"
9 )
10
11 type PixbufFormat struct {
12 format *C.GdkPixbufFormat
13 }
14
15 // native returns a pointer to the underlying GdkPixbuf.
16 func (v *PixbufFormat) native() *C.GdkPixbufFormat {
17 if v == nil {
18 return nil
19 }
20
21 return v.format
22 }
23
24 // Native returns a pointer to the underlying GdkPixbuf.
25 func (v *PixbufFormat) Native() uintptr {
26 return uintptr(unsafe.Pointer(v.native()))
27 }
28
29 func (f *PixbufFormat) GetName() (string, error) {
30 c := C.gdk_pixbuf_format_get_name(f.native())
31 return C.GoString((*C.char)(c)), nil
32 }
33
34 func (f *PixbufFormat) GetDescription() (string, error) {
35 c := C.gdk_pixbuf_format_get_description(f.native())
36 return C.GoString((*C.char)(c)), nil
37 }
38
39 func (f *PixbufFormat) GetLicense() (string, error) {
40 c := C.gdk_pixbuf_format_get_license(f.native())
41 return C.GoString((*C.char)(c)), nil
42 }
43
44 // GetMimeTypes is a wrapper around gdk_pixbuf_format_get_mime_types().
45 func (f *PixbufFormat) GetMimeTypes() []string {
46 var types []string
47 c := C.gdk_pixbuf_format_get_mime_types(f.native())
48 if c == nil {
49 return nil
50 }
51 for *c != nil {
52 types = append(types, C.GoString((*C.char)(*c)))
53 c = C.next_gcharptr(c)
54 }
55 return types
56 }
57
58 // GetExtensions is a wrapper around gdk_pixbuf_format_get_extensions().
59 func (f *PixbufFormat) GetExtensions() []string {
60 var extensions []string
61 c := C.gdk_pixbuf_format_get_extensions(f.native())
62 if c == nil {
63 return nil
64 }
65 for *c != nil {
66 extensions = append(extensions, C.GoString((*C.char)(*c)))
67 c = C.next_gcharptr(c)
68 }
69 return extensions
70 }
71
72 func PixbufGetFormats() []*PixbufFormat {
73 l := (*C.struct__GSList)(C.gdk_pixbuf_get_formats())
74 formats := glib.WrapSList(uintptr(unsafe.Pointer(l)))
75 if formats == nil {
76 return nil // no error. A nil list is considered to be empty.
77 }
78
79 // "The structures themselves are owned by GdkPixbuf". Free the list only.
80 defer formats.Free()
81
82 ret := make([]*PixbufFormat, 0, formats.Length())
83 formats.Foreach(func(ptr unsafe.Pointer) {
84 ret = append(ret, &PixbufFormat{(*C.GdkPixbufFormat)(ptr)})
85 })
86
87 return ret
88 }
0 // +build !gtk_3_6,!gtk_3_8
1 // Supports building with gtk 3.10+
2
3 package gdk
4
5 // #cgo pkg-config: gdk-3.0 glib-2.0 gobject-2.0
6 // #include <gdk/gdk.h>
7 // #include "gdk.go.h"
8 import "C"
9 import (
10 "runtime"
11 "unsafe"
12
13 "github.com/gotk3/gotk3/cairo"
14 )
15
16 // TODO:
17 // gdk_device_get_position_double().
18
19 // GetScaleFactor is a wrapper around gdk_window_get_scale_factor().
20 func (v *Window) GetScaleFactor() int {
21 return int(C.gdk_window_get_scale_factor(v.native()))
22 }
23
24 // CreateSimilarImageSurface is a wrapper around gdk_window_create_similar_image_surface().
25 func (v *Window) CreateSimilarImageSurface(format cairo.Format, w, h, scale int) (*cairo.Surface, error) {
26 surface := C.gdk_window_create_similar_image_surface(v.native(), C.cairo_format_t(format), C.gint(w), C.gint(h), C.gint(scale))
27
28 status := cairo.Status(C.cairo_surface_status(surface))
29 if status != cairo.STATUS_SUCCESS {
30 return nil, cairo.ErrorStatus(status)
31 }
32
33 return cairo.NewSurface(uintptr(unsafe.Pointer(surface)), false), nil
34 }
35
36 // CairoSurfaceCreateFromPixbuf is a wrapper around gdk_cairo_surface_create_from_pixbuf().
37 func CairoSurfaceCreateFromPixbuf(pixbuf *Pixbuf, scale int, window *Window) (*cairo.Surface, error) {
38 v := C.gdk_cairo_surface_create_from_pixbuf(pixbuf.native(), C.gint(scale), window.native())
39
40 status := cairo.Status(C.cairo_surface_status(v))
41 if status != cairo.STATUS_SUCCESS {
42 return nil, cairo.ErrorStatus(status)
43 }
44
45 surface := cairo.WrapSurface(uintptr(unsafe.Pointer(v)))
46 runtime.SetFinalizer(surface, (*cairo.Surface).Close)
47
48 return surface, nil
49 }
0 // +build !gtk_3_6,!gtk_3_8,!gtk_3_10
1 // Supports building with gtk 3.12+
2
3 package gdk
4
5 // TODO:
6 // gdk_device_get_last_event_window().
3838
3939 glib.RegisterGValueMarshalers(tm)
4040 }
41
42 /*
43 * Constants
44 */
45
46 const (
47 GRAB_FAILED GrabStatus = C.GDK_GRAB_FAILED
48 )
49
50 /*
51 * GdkDevice
52 */
53
54 // TODO:
55 // gdk_device_get_vendor_id().
56 // gdk_device_get_product_id().
4157
4258 /*
4359 * GdkGLContext
1818 #include <stdlib.h>
1919
2020 // Type Casting
21 static GdkGLContext *
22 toGdkGLContext(void *p)
23 {
24 return (GDK_GL_CONTEXT(p));
25 }
21 static GdkGLContext *toGdkGLContext(void *p) { return (GDK_GL_CONTEXT(p)); }
0 // Same copyright and license as the rest of the files in this project
1
2 // +build !gtk_3_6,!gtk_3_8,!gtk_3_10,!gtk_3_12,!gtk_3_14,!gtk_3_16
3 // Supports building with gtk 3.18+
4
5 package gdk
6
7 // #include <gdk/gdk.h>
8 import "C"
9
10 /*
11 * GdkKeymap
12 */
13
14 // GetScrollLockState is a wrapper around gdk_keymap_get_scroll_lock_state().
15 func (v *Keymap) GetScrollLockState() bool {
16 return gobool(C.gdk_keymap_get_scroll_lock_state(v.native()))
17 }
18
19 /*
20 * GdkWindow
21 */
22
23 // SetPassThrough is a wrapper around gdk_window_set_pass_through().
24 func (v *Window) SetPassThrough(passThrough bool) {
25 C.gdk_window_set_pass_through(v.native(), gbool(passThrough))
26 }
27
28 // GetPassThrough is a wrapper around gdk_window_get_pass_through().
29 func (v *Window) GetPassThrough() bool {
30 return gobool(C.gdk_window_get_pass_through(v.native()))
31 }
22
33 package gdk
44
5 import (
6 "unsafe"
7
8 "github.com/gotk3/gotk3/glib"
9 )
10
511 // #include <gdk/gdk.h>
12 // #include "gdk_since_3_20.go.h"
613 import "C"
14
15 /*
16 * GdkGLContext
17 */
718
819 // IsLegacy is a wrapper around gdk_gl_context_is_legacy().
920 func (v *GLContext) IsLegacy() bool {
1021 return gobool(C.gdk_gl_context_is_legacy(v.native()))
1122 }
23
24 /*
25 * GdkDisplay
26 */
27
28 func (v *Display) GetDefaultSeat() (*Seat, error) {
29 return toSeat(C.gdk_display_get_default_seat(v.native()))
30 }
31
32 // gdk_display_list_seats().
33
34 /*
35 * GdkDevice
36 */
37
38 // TODO:
39 // gdk_device_get_axes().
40 // gdk_device_get_seat().
41
42 /*
43 * GdkSeat
44 */
45
46 type Seat struct {
47 *glib.Object
48 }
49
50 func (v *Seat) native() *C.GdkSeat {
51 if v == nil || v.GObject == nil {
52 return nil
53 }
54 p := unsafe.Pointer(v.GObject)
55 return C.toGdkSeat(p)
56 }
57
58 // Native returns a pointer to the underlying GdkCursor.
59 func (v *Seat) Native() uintptr {
60 return uintptr(unsafe.Pointer(v.native()))
61 }
62
63 func marshalSeat(p uintptr) (interface{}, error) {
64 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
65 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
66 return &Seat{obj}, nil
67 }
68
69 func toSeat(s *C.GdkSeat) (*Seat, error) {
70 if s == nil {
71 return nil, nilPtrErr
72 }
73 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(s))}
74 return &Seat{obj}, nil
75 }
76
77 func (v *Seat) GetPointer() (*Device, error) {
78 return toDevice(C.gdk_seat_get_pointer(v.native()))
79 }
80
81 /*
82 * GdkRectangle
83 */
84
85 // RectangleEqual is a wrapper around gdk_rectangle_equal().
86 func (v *Rectangle) RectangleEqual(rect *Rectangle) bool {
87 return gobool(C.gdk_rectangle_equal(v.native(), rect.native()))
88 }
0 /*
1 * Copyright (c) 2013-2014 Conformal Systems <info@conformal.com>
2 *
3 * This file originated from: http://opensource.conformal.com/
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18 //#include <stdlib.h>
19
20 static GdkSeat *toGdkSeat(void *p) { return ((GdkSeat *)p); }
2727 "github.com/gotk3/gotk3/glib"
2828 )
2929
30 func init() {
31
32 tm := []glib.TypeMarshaler{
33 {glib.Type(C.gdk_subpixel_layout_get_type()), marshalSubpixelLayout},
34 }
35
36 glib.RegisterGValueMarshalers(tm)
37 }
38
39 /*
40 * Constants
41 */
42
43 // TODO:
44 // GdkSeatCapabilities
45
46 // SubpixelLayout is a representation of GDK's GdkSubpixelLayout.
47 type SubpixelLayout int
48
49 const (
50 SUBPIXEL_LAYOUT_UNKNOWN SubpixelLayout = C.GDK_SUBPIXEL_LAYOUT_UNKNOWN
51 SUBPIXEL_LAYOUT_NONE SubpixelLayout = C.GDK_SUBPIXEL_LAYOUT_NONE
52 SUBPIXEL_LAYOUT_HORIZONTAL_RGB SubpixelLayout = C.GDK_SUBPIXEL_LAYOUT_HORIZONTAL_RGB
53 SUBPIXEL_LAYOUT_HORIZONTAL_BGR SubpixelLayout = C.GDK_SUBPIXEL_LAYOUT_HORIZONTAL_BGR
54 SUBPIXEL_LAYOUT_VERTICAL_RGB SubpixelLayout = C.GDK_SUBPIXEL_LAYOUT_VERTICAL_RGB
55 SUBPIXEL_LAYOUT_VERTICAL_BGR SubpixelLayout = C.GDK_SUBPIXEL_LAYOUT_VERTICAL_BGR
56 )
57
58 func marshalSubpixelLayout(p uintptr) (interface{}, error) {
59 c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
60 return SubpixelLayout(c), nil
61 }
62
3063 /*
3164 * GdkDisplay
3265 */
75108 }
76109
77110 /*
111 * GdkSeat
112 */
113
114 // TODO:
115 // GdkSeatGrabPrepareFunc
116 // gdk_seat_get_display().
117 // gdk_seat_grab().
118 // gdk_seat_ungrab().
119 // gdk_seat_get_capabilities().
120 // gdk_seat_get_pointer().
121 // gdk_seat_get_keyboard().
122 // gdk_seat_get_slaves().
123
124 /*
78125 * GdkMonitor
79126 */
80127
111158 return &Monitor{obj}, nil
112159 }
113160
161 // GetDisplay is a wrapper around gdk_monitor_get_display().
162 func (v *Monitor) GetDisplay() (*Display, error) {
163 return toDisplay(C.gdk_monitor_get_display(v.native()))
164 }
165
114166 // GetGeometry is a wrapper around gdk_monitor_get_geometry().
115167 func (v *Monitor) GetGeometry() *Rectangle {
116168 var rect C.GdkRectangle
117169
118170 C.gdk_monitor_get_geometry(v.native(), &rect)
119171
120 return WrapRectangle(uintptr(unsafe.Pointer(&rect)))
121 }
172 return wrapRectangle(&rect)
173 }
174
175 // GetWorkarea is a wrapper around gdk_monitor_get_workarea().
176 func (v *Monitor) GetWorkarea() *Rectangle {
177 var rect C.GdkRectangle
178
179 C.gdk_monitor_get_workarea(v.native(), &rect)
180
181 return wrapRectangle(&rect)
182 }
183
184 // GetWidthMM is a wrapper around gdk_monitor_get_width_mm().
185 func (v *Monitor) GetWidthMM() int {
186 return int(C.gdk_monitor_get_width_mm(v.native()))
187 }
188
189 // GetHeightMM is a wrapper around gdk_monitor_get_height_mm().
190 func (v *Monitor) GetHeightMM() int {
191 return int(C.gdk_monitor_get_height_mm(v.native()))
192 }
193
194 // GetManufacturer is a wrapper around gdk_monitor_get_manufacturer().
195 func (v *Monitor) GetManufacturer() string {
196 // transfer none: don't free data after the code is done.
197 return C.GoString(C.gdk_monitor_get_manufacturer(v.native()))
198 }
199
200 // GetModel is a wrapper around gdk_monitor_get_model().
201 func (v *Monitor) GetModel() string {
202 // transfer none: don't free data after the code is done.
203 return C.GoString(C.gdk_monitor_get_model(v.native()))
204 }
205
206 // GetScaleFactor is a wrapper around gdk_monitor_get_scale_factor().
207 func (v *Monitor) GetScaleFactor() int {
208 return int(C.gdk_monitor_get_scale_factor(v.native()))
209 }
210
211 // GetRefreshRate is a wrapper around gdk_monitor_get_refresh_rate().
212 func (v *Monitor) GetRefreshRate() int {
213 return int(C.gdk_monitor_get_refresh_rate(v.native()))
214 }
215
216 // GetSubpixelLayout is a wrapper around gdk_monitor_get_subpixel_layout().
217 func (v *Monitor) GetSubpixelLayout() SubpixelLayout {
218 return SubpixelLayout(C.gdk_monitor_get_subpixel_layout(v.native()))
219 }
220
221 // IsPrimary is a wrapper around gdk_monitor_is_primary().
222 func (v *Monitor) IsPrimary() bool {
223 return gobool(C.gdk_monitor_is_primary(v.native()))
224 }
225
226 /*
227 * GdkDevice
228 */
229
230 // TODO:
231 // gdk_device_get_axes().
232 // gdk_device_tool_get_serial().
233 // gdk_device_tool_get_tool_type().
234
235 /*
236 * GdkGLContext
237 */
122238
123239 // GetUseES is a wrapper around gdk_gl_context_get_use_es().
124240 func (v *GLContext) GetUseES() bool {
1818 //#include <stdlib.h>
1919
2020 // Type Casting
21 static GdkMonitor *
22 toGdkMonitor(void *p)
23 {
24 return (GDK_MONITOR(p));
25 }
21 static GdkMonitor *toGdkMonitor(void *p) { return (GDK_MONITOR(p)); }
4747 type ClockPhase int
4848
4949 const (
50 PHASE_NONE ClockPhase = C.GDK_FRAME_CLOCK_PHASE_NONE
51 PHASE_FLUSH_EVENTS ClockPhase = C.GDK_FRAME_CLOCK_PHASE_FLUSH_EVENTS
52 PHASE_BEFORE_PAINT ClockPhase = C.GDK_FRAME_CLOCK_PHASE_BEFORE_PAINT
53 PHASE_UPDATE ClockPhase = C.GDK_FRAME_CLOCK_PHASE_UPDATE
54 PHASE_LAYOUT ClockPhase = C.GDK_FRAME_CLOCK_PHASE_LAYOUT
55 PHASE_PAINT ClockPhase = C.GDK_FRAME_CLOCK_PHASE_PAINT
50 PHASE_NONE ClockPhase = C.GDK_FRAME_CLOCK_PHASE_NONE
51 PHASE_FLUSH_EVENTS ClockPhase = C.GDK_FRAME_CLOCK_PHASE_FLUSH_EVENTS
52 PHASE_BEFORE_PAINT ClockPhase = C.GDK_FRAME_CLOCK_PHASE_BEFORE_PAINT
53 PHASE_UPDATE ClockPhase = C.GDK_FRAME_CLOCK_PHASE_UPDATE
54 PHASE_LAYOUT ClockPhase = C.GDK_FRAME_CLOCK_PHASE_LAYOUT
55 PHASE_PAINT ClockPhase = C.GDK_FRAME_CLOCK_PHASE_PAINT
5656 PHASE_RESUME_EVENTS ClockPhase = C.GDK_FRAME_CLOCK_PHASE_RESUME_EVENTS
57 PHASE_AFTER_PAINT ClockPhase = C.GDK_FRAME_CLOCK_PHASE_AFTER_PAINT
57 PHASE_AFTER_PAINT ClockPhase = C.GDK_FRAME_CLOCK_PHASE_AFTER_PAINT
5858 )
5959
6060 func marshalClockPhase(p uintptr) (interface{}, error) {
141141 // GetRefreshInfo is a wrapper around gdk_frame_clock_get_refresh_info().
142142 func (v *FrameClock) GetRefreshInfo(baseTime int64) (int64, int64) {
143143 var cr, cp (*C.gint64)
144 defer C.free(unsafe.Pointer(cr)); defer C.free(unsafe.Pointer(cp))
144 defer C.free(unsafe.Pointer(cr))
145 defer C.free(unsafe.Pointer(cp))
145146 b := C.gint64(baseTime)
146
147
147148 C.gdk_frame_clock_get_refresh_info(v.native(), b, cr, cp)
148149 r, p := int64(*cr), int64(*cp)
149 return r,p
150 return r, p
150151 }
151152
152153 // RequestPhase is a wrapper around gdk_frame_clock_request_phase().
177178 return uintptr(unsafe.Pointer(v.native()))
178179 }
179180
180 func wrapFrameTimings(ptr unsafe.Pointer) (*FrameTimings) {
181 func wrapFrameTimings(ptr unsafe.Pointer) *FrameTimings {
181182 obj := &glib.Object{glib.ToGObject(ptr)}
182183 return &FrameTimings{obj}
183184 }
1818 #include <stdlib.h>
1919
2020 // Type Casting
21 static GdkFrameClock *
22 toGdkFrameClock(void *p)
23 {
24 return (GDK_FRAME_CLOCK(p));
25 }
21 static GdkFrameClock *toGdkFrameClock(void *p) { return (GDK_FRAME_CLOCK(p)); }
2622
27 static GdkFrameTimings *
28 toGdkFrameTimings(void *p)
29 {
30 return ((GdkFrameTimings*)p);
23 static GdkFrameTimings *toGdkFrameTimings(void *p) {
24 return ((GdkFrameTimings *)p);
3125 }
0 // Same copyright and license as the rest of the files in this project
1
2 package gdk
3
4 // #cgo pkg-config: gdk-3.0 glib-2.0 gobject-2.0
5 // #include <gdk/gdk.h>
6 // #include "gdk.go.h"
7 // #include "pixbuf.go.h"
8 import "C"
9 import (
10 "errors"
11 "reflect"
12 "runtime"
13 "strconv"
14 "unsafe"
15
16 "github.com/gotk3/gotk3/glib"
17 )
18
19 func init() {
20 tm := []glib.TypeMarshaler{
21 // Enums
22 {glib.Type(C.gdk_pixbuf_alpha_mode_get_type()), marshalPixbufAlphaMode},
23
24 // Objects/Interfaces
25 {glib.Type(C.gdk_pixbuf_get_type()), marshalPixbuf},
26 {glib.Type(C.gdk_pixbuf_animation_get_type()), marshalPixbufAnimation},
27 {glib.Type(C.gdk_pixbuf_loader_get_type()), marshalPixbufLoader},
28 }
29 glib.RegisterGValueMarshalers(tm)
30 }
31
32 /*
33 * Constants
34 */
35
36 // TODO:
37 // GdkPixbufError
38
39 // PixbufRotation is a representation of GDK's GdkPixbufRotation.
40 type PixbufRotation int
41
42 const (
43 PIXBUF_ROTATE_NONE PixbufRotation = C.GDK_PIXBUF_ROTATE_NONE
44 PIXBUF_ROTATE_COUNTERCLOCKWISE PixbufRotation = C.GDK_PIXBUF_ROTATE_COUNTERCLOCKWISE
45 PIXBUF_ROTATE_UPSIDEDOWN PixbufRotation = C.GDK_PIXBUF_ROTATE_UPSIDEDOWN
46 PIXBUF_ROTATE_CLOCKWISE PixbufRotation = C.GDK_PIXBUF_ROTATE_CLOCKWISE
47 )
48
49 // PixbufAlphaMode is a representation of GDK's GdkPixbufAlphaMode.
50 type PixbufAlphaMode int
51
52 const (
53 GDK_PIXBUF_ALPHA_BILEVEL PixbufAlphaMode = C.GDK_PIXBUF_ALPHA_BILEVEL
54 GDK_PIXBUF_ALPHA_FULL PixbufAlphaMode = C.GDK_PIXBUF_ALPHA_FULL
55 )
56
57 func marshalPixbufAlphaMode(p uintptr) (interface{}, error) {
58 c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
59 return PixbufAlphaMode(c), nil
60 }
61
62 /*
63 * GdkPixbuf
64 */
65
66 // PixbufGetType is a wrapper around gdk_pixbuf_get_type().
67 func PixbufGetType() glib.Type {
68 return glib.Type(C.gdk_pixbuf_get_type())
69 }
70
71 // Pixbuf is a representation of GDK's GdkPixbuf.
72 type Pixbuf struct {
73 *glib.Object
74 }
75
76 // native returns a pointer to the underlying GdkPixbuf.
77 func (v *Pixbuf) native() *C.GdkPixbuf {
78 if v == nil || v.GObject == nil {
79 return nil
80 }
81 p := unsafe.Pointer(v.GObject)
82 return C.toGdkPixbuf(p)
83 }
84
85 // Native returns a pointer to the underlying GdkPixbuf.
86 func (v *Pixbuf) Native() uintptr {
87 return uintptr(unsafe.Pointer(v.native()))
88 }
89
90 func (v *Pixbuf) NativePrivate() *C.GdkPixbuf {
91 if v == nil || v.GObject == nil {
92 return nil
93 }
94 p := unsafe.Pointer(v.GObject)
95 return C.toGdkPixbuf(p)
96 }
97
98 func marshalPixbuf(p uintptr) (interface{}, error) {
99 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
100 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
101 return &Pixbuf{obj}, nil
102 }
103
104 // PixbufNew is a wrapper around gdk_pixbuf_new().
105 func PixbufNew(colorspace Colorspace, hasAlpha bool, bitsPerSample, width, height int) (*Pixbuf, error) {
106 c := C.gdk_pixbuf_new(C.GdkColorspace(colorspace), gbool(hasAlpha),
107 C.int(bitsPerSample), C.int(width), C.int(height))
108 if c == nil {
109 return nil, nilPtrErr
110 }
111
112 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
113 p := &Pixbuf{obj}
114 //obj.Ref()
115 runtime.SetFinalizer(p, func(_ interface{}) { obj.Unref() })
116 return p, nil
117 }
118
119 // File Loading
120
121 // PixbufNewFromFile is a wrapper around gdk_pixbuf_new_from_file().
122 func PixbufNewFromFile(filename string) (*Pixbuf, error) {
123 cstr := C.CString(filename)
124 defer C.free(unsafe.Pointer(cstr))
125
126 var err *C.GError
127 c := C.gdk_pixbuf_new_from_file((*C.char)(cstr), &err)
128 if c == nil {
129 defer C.g_error_free(err)
130 return nil, errors.New(C.GoString((*C.char)(err.message)))
131 }
132
133 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
134 p := &Pixbuf{obj}
135 //obj.Ref()
136 runtime.SetFinalizer(p, func(_ interface{}) { obj.Unref() })
137 return p, nil
138 }
139
140 // Image Data in Memory
141
142 // PixbufNewFromData is a wrapper around gdk_pixbuf_new_from_data().
143 func PixbufNewFromData(pixbufData []byte, cs Colorspace, hasAlpha bool, bitsPerSample, width, height, rowStride int) (*Pixbuf, error) {
144 arrayPtr := (*C.guchar)(unsafe.Pointer(&pixbufData[0]))
145
146 c := C.gdk_pixbuf_new_from_data(
147 arrayPtr,
148 C.GdkColorspace(cs),
149 gbool(hasAlpha),
150 C.int(bitsPerSample),
151 C.int(width),
152 C.int(height),
153 C.int(rowStride),
154 nil, // TODO: missing support for GdkPixbufDestroyNotify
155 nil,
156 )
157
158 if c == nil {
159 return nil, nilPtrErr
160 }
161
162 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
163 p := &Pixbuf{obj}
164 //obj.Ref()
165 runtime.SetFinalizer(p, func(_ interface{}) { obj.Unref() })
166
167 return p, nil
168 }
169
170 // PixbufNewFromDataOnly is a convenient alternative to PixbufNewFromData() and also a wrapper around gdk_pixbuf_new_from_data().
171 func PixbufNewFromDataOnly(pixbufData []byte) (*Pixbuf, error) {
172 pixbufLoader, err := PixbufLoaderNew()
173 if err != nil {
174 return nil, err
175 }
176 return pixbufLoader.WriteAndReturnPixbuf(pixbufData)
177 }
178
179 // PixbufNewFromResource is a wrapper around gdk_pixbuf_new_from_resource()
180 func PixbufNewFromResource(resourcePath string) (*Pixbuf, error) {
181 var gerr *C.GError
182
183 cstr := C.CString(resourcePath)
184 defer C.free(unsafe.Pointer(cstr))
185
186 c := C.gdk_pixbuf_new_from_resource((*C.gchar)(cstr), &gerr)
187
188 if gerr != nil {
189 defer C.g_error_free(gerr)
190 return nil, errors.New(C.GoString(gerr.message))
191 }
192
193 obj := glib.Take(unsafe.Pointer(c))
194 return &Pixbuf{obj}, nil
195 }
196
197 // PixbufNewFromResourceAtScale is a wrapper around gdk_pixbuf_new_from_resource_at_scale()
198 func PixbufNewFromResourceAtScale(resourcePath string, width, height int, preserveAspectRatio bool) (*Pixbuf, error) {
199 var gerr *C.GError
200
201 cstr := C.CString(resourcePath)
202 defer C.free(unsafe.Pointer(cstr))
203
204 cPreserveAspectRatio := gbool(preserveAspectRatio)
205
206 c := C.gdk_pixbuf_new_from_resource_at_scale(
207 (*C.gchar)(cstr),
208 C.gint(width),
209 C.gint(height),
210 C.gboolean(cPreserveAspectRatio),
211 &gerr,
212 )
213
214 if gerr != nil {
215 defer C.g_error_free(gerr)
216 return nil, errors.New(C.GoString(gerr.message))
217 }
218
219 obj := glib.Take(unsafe.Pointer(c))
220 return &Pixbuf{obj}, nil
221 }
222
223 // TODO:
224 // gdk_pixbuf_new_from_xpm_data().
225 // gdk_pixbuf_new_subpixbuf()
226
227 // PixbufCopy is a wrapper around gdk_pixbuf_copy().
228 func PixbufCopy(v *Pixbuf) (*Pixbuf, error) {
229 c := C.gdk_pixbuf_copy(v.native())
230 if c == nil {
231 return nil, nilPtrErr
232 }
233
234 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
235 p := &Pixbuf{obj}
236 //obj.Ref()
237 runtime.SetFinalizer(p, func(_ interface{}) { obj.Unref() })
238 return p, nil
239 }
240
241 // The GdkPixbuf Structure
242
243 // GetColorspace is a wrapper around gdk_pixbuf_get_colorspace().
244 func (v *Pixbuf) GetColorspace() Colorspace {
245 c := C.gdk_pixbuf_get_colorspace(v.native())
246 return Colorspace(c)
247 }
248
249 // GetNChannels is a wrapper around gdk_pixbuf_get_n_channels().
250 func (v *Pixbuf) GetNChannels() int {
251 c := C.gdk_pixbuf_get_n_channels(v.native())
252 return int(c)
253 }
254
255 // GetHasAlpha is a wrapper around gdk_pixbuf_get_has_alpha().
256 func (v *Pixbuf) GetHasAlpha() bool {
257 c := C.gdk_pixbuf_get_has_alpha(v.native())
258 return gobool(c)
259 }
260
261 // GetBitsPerSample is a wrapper around gdk_pixbuf_get_bits_per_sample().
262 func (v *Pixbuf) GetBitsPerSample() int {
263 c := C.gdk_pixbuf_get_bits_per_sample(v.native())
264 return int(c)
265 }
266
267 // GetPixels is a wrapper around gdk_pixbuf_get_pixels_with_length().
268 // A Go slice is used to represent the underlying Pixbuf data array, one
269 // byte per channel.
270 func (v *Pixbuf) GetPixels() (channels []byte) {
271 var length C.guint
272 c := C.gdk_pixbuf_get_pixels_with_length(v.native(), &length)
273 sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&channels))
274 sliceHeader.Data = uintptr(unsafe.Pointer(c))
275 sliceHeader.Len = int(length)
276 sliceHeader.Cap = int(length)
277
278 // To make sure the slice doesn't outlive the Pixbuf, add a reference
279 v.Ref()
280 runtime.SetFinalizer(&channels, func(_ *[]byte) {
281 v.Unref()
282 })
283 return
284 }
285
286 // GetWidth is a wrapper around gdk_pixbuf_get_width().
287 func (v *Pixbuf) GetWidth() int {
288 c := C.gdk_pixbuf_get_width(v.native())
289 return int(c)
290 }
291
292 // GetHeight is a wrapper around gdk_pixbuf_get_height().
293 func (v *Pixbuf) GetHeight() int {
294 c := C.gdk_pixbuf_get_height(v.native())
295 return int(c)
296 }
297
298 // GetRowstride is a wrapper around gdk_pixbuf_get_rowstride().
299 func (v *Pixbuf) GetRowstride() int {
300 c := C.gdk_pixbuf_get_rowstride(v.native())
301 return int(c)
302 }
303
304 // GetOption is a wrapper around gdk_pixbuf_get_option(). ok is true if
305 // the key has an associated value.
306 func (v *Pixbuf) GetOption(key string) (value string, ok bool) {
307 cstr := C.CString(key)
308 defer C.free(unsafe.Pointer(cstr))
309 c := C.gdk_pixbuf_get_option(v.native(), (*C.gchar)(cstr))
310 if c == nil {
311 return "", false
312 }
313 return C.GoString((*C.char)(c)), true
314 }
315
316 // Scaling
317
318 // ScaleSimple is a wrapper around gdk_pixbuf_scale_simple().
319 func (v *Pixbuf) ScaleSimple(destWidth, destHeight int, interpType InterpType) (*Pixbuf, error) {
320 c := C.gdk_pixbuf_scale_simple(v.native(), C.int(destWidth),
321 C.int(destHeight), C.GdkInterpType(interpType))
322 if c == nil {
323 return nil, nilPtrErr
324 }
325
326 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
327 p := &Pixbuf{obj}
328 //obj.Ref()
329 runtime.SetFinalizer(p, func(_ interface{}) { obj.Unref() })
330 return p, nil
331 }
332
333 // Scale is a wrapper around gdk_pixbuf_scale().
334 func (v *Pixbuf) Scale(dest *Pixbuf, destX, destY, destWidth, destHeight int, offsetX, offsetY, scaleX, scaleY float64, interpType InterpType) {
335 C.gdk_pixbuf_scale(
336 v.native(),
337 dest.native(),
338 C.int(destX),
339 C.int(destY),
340 C.int(destWidth),
341 C.int(destHeight),
342 C.double(offsetX),
343 C.double(offsetY),
344 C.double(scaleX),
345 C.double(scaleY),
346 C.GdkInterpType(interpType),
347 )
348 }
349
350 // Composite is a wrapper around gdk_pixbuf_composite().
351 func (v *Pixbuf) Composite(dest *Pixbuf, destX, destY, destWidth, destHeight int, offsetX, offsetY, scaleX, scaleY float64, interpType InterpType, overallAlpha int) {
352 C.gdk_pixbuf_composite(
353 v.native(),
354 dest.native(),
355 C.int(destX),
356 C.int(destY),
357 C.int(destWidth),
358 C.int(destHeight),
359 C.double(offsetX),
360 C.double(offsetY),
361 C.double(scaleX),
362 C.double(scaleY),
363 C.GdkInterpType(interpType),
364 C.int(overallAlpha),
365 )
366 }
367
368 // TODO:
369 // gdk_pixbuf_composite_color_simple().
370 // gdk_pixbuf_composite_color().
371
372 // Utilities
373
374 // TODO:
375 // gdk_pixbuf_copy_area().
376 // gdk_pixbuf_saturate_and_pixelate().
377
378 // Fill is a wrapper around gdk_pixbuf_fill(). The given pixel is an RGBA value.
379 func (v *Pixbuf) Fill(pixel uint32) {
380 C.gdk_pixbuf_fill(v.native(), C.guint32(pixel))
381 }
382
383 // AddAlpha is a wrapper around gdk_pixbuf_add_alpha(). If substituteColor is
384 // true, then the color specified by r, g and b will be assigned zero opacity.
385 func (v *Pixbuf) AddAlpha(substituteColor bool, r, g, b uint8) *Pixbuf {
386 c := C.gdk_pixbuf_add_alpha(v.native(), gbool(substituteColor), C.guchar(r), C.guchar(g), C.guchar(b))
387
388 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
389 p := &Pixbuf{obj}
390 runtime.SetFinalizer(p, func(_ interface{}) { obj.Unref() })
391
392 return p
393 }
394
395 // File saving
396
397 // TODO:
398 // gdk_pixbuf_savev().
399 // gdk_pixbuf_save().
400
401 // SaveJPEG is a convenience wrapper around gdk_pixbuf_save() for saving image as jpeg file.
402 // Quality is a number between 0...100
403 func (v *Pixbuf) SaveJPEG(path string, quality int) error {
404 cpath := C.CString(path)
405 cquality := C.CString(strconv.Itoa(quality))
406 defer C.free(unsafe.Pointer(cpath))
407 defer C.free(unsafe.Pointer(cquality))
408
409 var err *C.GError
410 c := C._gdk_pixbuf_save_jpeg(v.native(), cpath, &err, cquality)
411 if !gobool(c) {
412 defer C.g_error_free(err)
413 return errors.New(C.GoString((*C.char)(err.message)))
414 }
415
416 return nil
417 }
418
419 // SavePNG is a convenience wrapper around gdk_pixbuf_save() for saving image as png file.
420 // Compression is a number between 0...9
421 func (v *Pixbuf) SavePNG(path string, compression int) error {
422 cpath := C.CString(path)
423 ccompression := C.CString(strconv.Itoa(compression))
424 defer C.free(unsafe.Pointer(cpath))
425 defer C.free(unsafe.Pointer(ccompression))
426
427 var err *C.GError
428 c := C._gdk_pixbuf_save_png(v.native(), cpath, &err, ccompression)
429 if !gobool(c) {
430 defer C.g_error_free(err)
431 return errors.New(C.GoString((*C.char)(err.message)))
432 }
433 return nil
434 }
435
436 /*
437 * PixbufFormat
438 */
439
440 type PixbufFormat struct {
441 format *C.GdkPixbufFormat
442 }
443
444 // native returns a pointer to the underlying GdkPixbuf.
445 func (v *PixbufFormat) native() *C.GdkPixbufFormat {
446 if v == nil {
447 return nil
448 }
449
450 return v.format
451 }
452
453 func wrapPixbufFormat(obj *C.GdkPixbufFormat) *PixbufFormat {
454 return &PixbufFormat{obj}
455 }
456
457 // Native returns a pointer to the underlying GdkPixbuf.
458 func (v *PixbufFormat) Native() uintptr {
459 return uintptr(unsafe.Pointer(v.native()))
460 }
461
462 /*
463 * GdkPixbufAnimation
464 */
465
466 // PixbufAnimation is a representation of GDK's GdkPixbufAnimation.
467 type PixbufAnimation struct {
468 *glib.Object
469 }
470
471 // native returns a pointer to the underlying GdkPixbufAnimation.
472 func (v *PixbufAnimation) native() *C.GdkPixbufAnimation {
473 if v == nil || v.GObject == nil {
474 return nil
475 }
476 p := unsafe.Pointer(v.GObject)
477 return C.toGdkPixbufAnimation(p)
478 }
479
480 func (v *PixbufAnimation) NativePrivate() *C.GdkPixbufAnimation {
481 if v == nil || v.GObject == nil {
482 return nil
483 }
484 p := unsafe.Pointer(v.GObject)
485 return C.toGdkPixbufAnimation(p)
486 }
487
488 func (v *PixbufAnimation) GetStaticImage() *Pixbuf {
489 c := C.gdk_pixbuf_animation_get_static_image(v.native())
490 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
491 p := &Pixbuf{obj}
492
493 // Add a reference so the pixbuf doesn't outlive the parent pixbuf
494 // animation.
495 v.Ref()
496 runtime.SetFinalizer(p, func(*Pixbuf) { v.Unref() })
497
498 return p
499 }
500
501 func marshalPixbufAnimation(p uintptr) (interface{}, error) {
502 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
503 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
504 return &PixbufAnimation{obj}, nil
505 }
506
507 // PixbufAnimationNewFromFile is a wrapper around gdk_pixbuf_animation_new_from_file().
508 func PixbufAnimationNewFromFile(filename string) (*PixbufAnimation, error) {
509 cstr := C.CString(filename)
510 defer C.free(unsafe.Pointer(cstr))
511
512 var err *C.GError
513 c := C.gdk_pixbuf_animation_new_from_file((*C.char)(cstr), &err)
514 if c == nil {
515 defer C.g_error_free(err)
516 return nil, errors.New(C.GoString((*C.char)(err.message)))
517 }
518
519 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
520 p := &PixbufAnimation{obj}
521 runtime.SetFinalizer(p, func(_ interface{}) { obj.Unref() })
522 return p, nil
523 }
524
525 // TODO:
526 // gdk_pixbuf_animation_new_from_resource().
527
528 /*
529 * GdkPixbufLoader
530 */
531
532 // PixbufLoader is a representation of GDK's GdkPixbufLoader.
533 // Users of PixbufLoader are expected to call Close() when they are finished.
534 type PixbufLoader struct {
535 *glib.Object
536 }
537
538 // native() returns a pointer to the underlying GdkPixbufLoader.
539 func (v *PixbufLoader) native() *C.GdkPixbufLoader {
540 if v == nil || v.GObject == nil {
541 return nil
542 }
543 p := unsafe.Pointer(v.GObject)
544 return C.toGdkPixbufLoader(p)
545 }
546
547 func marshalPixbufLoader(p uintptr) (interface{}, error) {
548 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
549 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
550 return &PixbufLoader{obj}, nil
551 }
552
553 // PixbufLoaderNew() is a wrapper around gdk_pixbuf_loader_new().
554 func PixbufLoaderNew() (*PixbufLoader, error) {
555 c := C.gdk_pixbuf_loader_new()
556 if c == nil {
557 return nil, nilPtrErr
558 }
559 return &PixbufLoader{glib.AssumeOwnership(unsafe.Pointer(c))}, nil
560 }
561
562 // PixbufLoaderNewWithType() is a wrapper around gdk_pixbuf_loader_new_with_type().
563 func PixbufLoaderNewWithType(t string) (*PixbufLoader, error) {
564 var err *C.GError
565
566 cstr := C.CString(t)
567 defer C.free(unsafe.Pointer(cstr))
568
569 c := C.gdk_pixbuf_loader_new_with_type((*C.char)(cstr), &err)
570 if err != nil {
571 defer C.g_error_free(err)
572 return nil, errors.New(C.GoString((*C.char)(err.message)))
573 }
574
575 if c == nil {
576 return nil, nilPtrErr
577 }
578
579 return &PixbufLoader{glib.AssumeOwnership(unsafe.Pointer(c))}, nil
580 }
581
582 // Write() is a wrapper around gdk_pixbuf_loader_write(). The
583 // function signature differs from the C equivalent to satisify the
584 // io.Writer interface.
585 func (v *PixbufLoader) Write(data []byte) (int, error) {
586 // n is set to 0 on error, and set to len(data) otherwise.
587 // This is a tiny hacky to satisfy io.Writer and io.WriteCloser,
588 // which would allow access to all io and ioutil goodies,
589 // and play along nice with go environment.
590
591 if len(data) == 0 {
592 return 0, nil
593 }
594
595 var err *C.GError
596 c := C.gdk_pixbuf_loader_write(v.native(),
597 (*C.guchar)(unsafe.Pointer(&data[0])), C.gsize(len(data)),
598 &err)
599
600 if !gobool(c) {
601 defer C.g_error_free(err)
602 return 0, errors.New(C.GoString((*C.char)(err.message)))
603 }
604
605 return len(data), nil
606 }
607
608 // Convenient function like above for Pixbuf. Write data, close loader and return Pixbuf.
609 func (v *PixbufLoader) WriteAndReturnPixbuf(data []byte) (*Pixbuf, error) {
610 _, err := v.Write(data)
611 if err != nil {
612 return nil, err
613 }
614
615 if err := v.Close(); err != nil {
616 return nil, err
617 }
618
619 return v.GetPixbuf()
620 }
621
622 // Close is a wrapper around gdk_pixbuf_loader_close(). An error is
623 // returned instead of a bool like the native C function to support the
624 // io.Closer interface.
625 func (v *PixbufLoader) Close() error {
626 var err *C.GError
627
628 if ok := gobool(C.gdk_pixbuf_loader_close(v.native(), &err)); !ok {
629 defer C.g_error_free(err)
630 return errors.New(C.GoString((*C.char)(err.message)))
631 }
632 return nil
633 }
634
635 // GetPixbuf is a wrapper around gdk_pixbuf_loader_get_pixbuf().
636 func (v *PixbufLoader) GetPixbuf() (*Pixbuf, error) {
637 c := C.gdk_pixbuf_loader_get_pixbuf(v.native())
638 if c == nil {
639 return nil, nilPtrErr
640 }
641
642 return &Pixbuf{glib.Take(unsafe.Pointer(c))}, nil
643 }
644
645 // GetAnimation is a wrapper around gdk_pixbuf_loader_get_animation().
646 func (v *PixbufLoader) GetAnimation() (*PixbufAnimation, error) {
647 c := C.gdk_pixbuf_loader_get_animation(v.native())
648 if c == nil {
649 return nil, nilPtrErr
650 }
651
652 return &PixbufAnimation{glib.Take(unsafe.Pointer(c))}, nil
653 }
654
655 // Convenient function like above for Pixbuf. Write data, close loader and return PixbufAnimation.
656 func (v *PixbufLoader) WriteAndReturnPixbufAnimation(data []byte) (*PixbufAnimation, error) {
657 _, err := v.Write(data)
658 if err != nil {
659 return nil, err
660 }
661
662 if err := v.Close(); err != nil {
663 return nil, err
664 }
665
666 return v.GetAnimation()
667 }
0 // Same copyright and license as the rest of the files in this project
1
2 #include <stdlib.h>
3
4 static GdkPixbuf *toGdkPixbuf(void *p) { return (GDK_PIXBUF(p)); }
5
6 static GdkPixbufAnimation *toGdkPixbufAnimation(void *p) {
7 return (GDK_PIXBUF_ANIMATION(p));
8 }
9 static gboolean
10
11 _gdk_pixbuf_save_png(GdkPixbuf *pixbuf, const char *filename, GError **err,
12 const char *compression) {
13 return gdk_pixbuf_save(pixbuf, filename, "png", err, "compression",
14 compression, NULL);
15 }
16
17 static gboolean _gdk_pixbuf_save_jpeg(GdkPixbuf *pixbuf, const char *filename,
18 GError **err, const char *quality) {
19 return gdk_pixbuf_save(pixbuf, filename, "jpeg", err, "quality", quality,
20 NULL);
21 }
22
23 static GdkPixbufLoader *toGdkPixbufLoader(void *p) {
24 return (GDK_PIXBUF_LOADER(p));
25 }
0 // Same copyright and license as the rest of the files in this project
1
2 //+build gdk_pixbuf_2_2 gdk_pixbuf_2_4 gdk_pixbuf_2_6 gdk_pixbuf_2_8 gdk_pixbuf_2_12 gdk_pixbuf_2_14 gdk_pixbuf_2_24 gdk_pixbuf_2_26 gdk_pixbuf_2_28 gdk_pixbuf_2_30 gdk_pixbuf_deprecated
3
4 package gdk
5
6 // #cgo pkg-config: gdk-3.0 glib-2.0 gobject-2.0
7 // #include <gdk/gdk.h>
8 // #include "gdk.go.h"
9 // #include "pixbuf.go.h"
10 import "C"
11
12 // Image Data in Memory
13
14 // TODO:
15 // gdk_pixbuf_new_from_inline().
0 // Same copyright and license as the rest of the files in this project
1
2 // +build !gdk_pixbuf_2_2,!gdk_pixbuf_2_4,!gdk_pixbuf_2_6,!gdk_pixbuf_2_8
3
4 package gdk
5
6 // #cgo pkg-config: gdk-3.0 glib-2.0 gobject-2.0
7 // #include <gdk/gdk.h>
8 // #include "gdk.go.h"
9 // #include "pixbuf.go.h"
10 import "C"
11 import (
12 "runtime"
13 "unsafe"
14
15 "github.com/gotk3/gotk3/glib"
16 )
17
18 // Utilities
19
20 // ApplyEmbeddedOrientation is a wrapper around gdk_pixbuf_apply_embedded_orientation().
21 func (v *Pixbuf) ApplyEmbeddedOrientation() (*Pixbuf, error) {
22 c := C.gdk_pixbuf_apply_embedded_orientation(v.native())
23 if c == nil {
24 return nil, nilPtrErr
25 }
26
27 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
28 p := &Pixbuf{obj}
29 //obj.Ref()
30 runtime.SetFinalizer(p, func(_ interface{}) { obj.Unref() })
31 return p, nil
32 }
0 // Same copyright and license as the rest of the files in this project
1
2 // +build !gdk_pixbuf_2_2,!gdk_pixbuf_2_4,!gdk_pixbuf_2_6,!gdk_pixbuf_2_8,!gdk_pixbuf_2_12
3
4 package gdk
5
6 // #cgo pkg-config: gdk-3.0 glib-2.0 gobject-2.0
7 // #include <gdk/gdk.h>
8 // #include "gdk.go.h"
9 // #include "pixbuf.go.h"
10 import "C"
11
12 // File Loading
13
14 // TODO:
15 // gdk_pixbuf_new_from_stream().
16 // gdk_pixbuf_new_from_stream_async().
17 // gdk_pixbuf_new_from_stream_at_scale().
18
19 // File saving
20
21 // TODO:
22 // gdk_pixbuf_save_to_stream().
0 // Same copyright and license as the rest of the files in this project
1
2 package gdk
3
4 // #cgo pkg-config: gdk-3.0 glib-2.0 gobject-2.0
5 // #include <gdk/gdk.h>
6 // #include "gdk.go.h"
7 // #include "pixbuf.go.h"
8 import "C"
9 import (
10 "unsafe"
11
12 "github.com/gotk3/gotk3/glib"
13 )
14
15 // The GdkPixbuf Structure
16
17 // TODO:
18 // gdk_pixbuf_set_option().
19
20 /*
21 * GdkPixbufLoader
22 */
23
24 // SetSize is a wrapper around gdk_pixbuf_loader_set_size().
25 func (v *PixbufLoader) SetSize(width, height int) {
26 C.gdk_pixbuf_loader_set_size(v.native(), C.int(width), C.int(height))
27 }
28
29 /*
30 * PixbufFormat
31 */
32
33 // PixbufGetFormats is a wrapper around gdk_pixbuf_get_formats().
34 func PixbufGetFormats() []*PixbufFormat {
35 l := (*C.struct__GSList)(C.gdk_pixbuf_get_formats())
36 formats := glib.WrapSList(uintptr(unsafe.Pointer(l)))
37 if formats == nil {
38 return nil // no error. A nil list is considered to be empty.
39 }
40
41 // "The structures themselves are owned by GdkPixbuf". Free the list only.
42 defer formats.Free()
43
44 ret := make([]*PixbufFormat, 0, formats.Length())
45 formats.Foreach(func(item interface{}) {
46 ret = append(
47 ret,
48 &PixbufFormat{
49 (*C.GdkPixbufFormat)(item.(unsafe.Pointer))})
50 })
51
52 return ret
53 }
54
55 // GetName is a wrapper around gdk_pixbuf_format_get_name().
56 func (f *PixbufFormat) GetName() (string, error) {
57 c := C.gdk_pixbuf_format_get_name(f.native())
58 return C.GoString((*C.char)(c)), nil
59 }
60
61 // GetDescription is a wrapper around gdk_pixbuf_format_get_description().
62 func (f *PixbufFormat) GetDescription() (string, error) {
63 c := C.gdk_pixbuf_format_get_description(f.native())
64 return C.GoString((*C.char)(c)), nil
65 }
66
67 // GetMimeTypes is a wrapper around gdk_pixbuf_format_get_mime_types().
68 func (f *PixbufFormat) GetMimeTypes() []string {
69 var types []string
70 c := C.gdk_pixbuf_format_get_mime_types(f.native())
71 if c == nil {
72 return nil
73 }
74 for *c != nil {
75 types = append(types, C.GoString((*C.char)(*c)))
76 c = C.next_gcharptr(c)
77 }
78 return types
79 }
80
81 // GetExtensions is a wrapper around gdk_pixbuf_format_get_extensions().
82 func (f *PixbufFormat) GetExtensions() []string {
83 var extensions []string
84 c := C.gdk_pixbuf_format_get_extensions(f.native())
85 if c == nil {
86 return nil
87 }
88 for *c != nil {
89 extensions = append(extensions, C.GoString((*C.char)(*c)))
90 c = C.next_gcharptr(c)
91 }
92 return extensions
93 }
94
95 // GetLicense is a wrapper around gdk_pixbuf_format_get_license().
96 func (f *PixbufFormat) GetLicense() (string, error) {
97 c := C.gdk_pixbuf_format_get_license(f.native())
98 return C.GoString((*C.char)(c)), nil
99 }
0 // Same copyright and license as the rest of the files in this project
1
2 // +build !gdk_pixbuf_2_2,!gdk_pixbuf_2_4,!gdk_pixbuf_2_6,!gdk_pixbuf_2_8,!gdk_pixbuf_2_12,!gdk_pixbuf_2_14
3
4 package gdk
5
6 // #cgo pkg-config: gdk-3.0 glib-2.0 gobject-2.0
7 // #include <gdk/gdk.h>
8 // #include "gdk.go.h"
9 // #include "pixbuf.go.h"
10 import "C"
11
12 /*
13 * PixbufFormat
14 */
15
16 // TODO:
17 // gdk_pixbuf_format_copy().
0 // Same copyright and license as the rest of the files in this project
1
2 // +build !gdk_pixbuf_2_2,!gdk_pixbuf_2_4,!gdk_pixbuf_2_6,!gdk_pixbuf_2_8,!gdk_pixbuf_2_12,!gdk_pixbuf_2_14,!gdk_pixbuf_2_22
3
4 package gdk
5
6 // #cgo pkg-config: gdk-3.0 glib-2.0 gobject-2.0
7 // #include <gdk/gdk.h>
8 // #include "gdk.go.h"
9 // #include "pixbuf.go.h"
10 import "C"
11
12 // File Loading
13
14 // TODO:
15 // gdk_pixbuf_new_from_stream_finish().
16 // gdk_pixbuf_new_from_stream_at_scale_async().
17
18 // File saving
19
20 // TODO:
21 // gdk_pixbuf_save_to_stream_async().
22 // gdk_pixbuf_save_to_stream_finish().
0 // Same copyright and license as the rest of the files in this project
1
2 // +build !gdk_pixbuf_2_2,!gdk_pixbuf_2_4,!gdk_pixbuf_2_6,!gdk_pixbuf_2_8,!gdk_pixbuf_2_12,!gdk_pixbuf_2_14,!gdk_pixbuf_2_22,!gdk_pixbuf_2_24
3
4 package gdk
5
6 // #cgo pkg-config: gdk-3.0 glib-2.0 gobject-2.0
7 // #include <gdk/gdk.h>
8 // #include "gdk.go.h"
9 // #include "pixbuf.go.h"
10 import "C"
11
12 // File Loading
13
14 // TODO:
15 // gdk_pixbuf_new_from_resource().
16 // gdk_pixbuf_new_from_resource_at_scale().
17
18 // The GdkPixbuf Structure
19
20 // GetByteLength is a wrapper around gdk_pixbuf_get_byte_length().
21 func (v *Pixbuf) GetByteLength() int {
22 c := C.gdk_pixbuf_get_byte_length(v.native())
23 return int(c)
24 }
0 // Same copyright and license as the rest of the files in this project
1
2 // +build !gdk_pixbuf_2_2,!gdk_pixbuf_2_4,!gdk_pixbuf_2_6,!gdk_pixbuf_2_8,!gdk_pixbuf_2_12,!gdk_pixbuf_2_14,!gdk_pixbuf_2_22,!gdk_pixbuf_2_24,!gdk_pixbuf_2_26,!gdk_pixbuf_2_28,!gdk_pixbuf_2_30
3
4 package gdk
5
6 // #cgo pkg-config: gdk-3.0 glib-2.0 gobject-2.0
7 // #include <gdk/gdk.h>
8 // #include "gdk.go.h"
9 // #include "pixbuf.go.h"
10 import "C"
11 import (
12 "runtime"
13 "unsafe"
14
15 "github.com/gotk3/gotk3/glib"
16 )
17
18 // Image Data in Memory
19
20 // PixbufNewFromBytes is a wrapper around gdk_pixbuf_new_from_bytes().
21 // see go package "encoding/base64"
22 func PixbufNewFromBytes(pixbufData []byte, cs Colorspace, hasAlpha bool, bitsPerSample, width, height, rowStride int) (*Pixbuf, error) {
23 arrayPtr := (*C.GBytes)(unsafe.Pointer(&pixbufData[0]))
24
25 c := C.gdk_pixbuf_new_from_bytes(
26 arrayPtr,
27 C.GdkColorspace(cs),
28 gbool(hasAlpha),
29 C.int(bitsPerSample),
30 C.int(width),
31 C.int(height),
32 C.int(rowStride),
33 )
34
35 if c == nil {
36 return nil, nilPtrErr
37 }
38
39 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
40 p := &Pixbuf{obj}
41 //obj.Ref()
42 runtime.SetFinalizer(p, func(_ interface{}) { obj.Unref() })
43
44 return p, nil
45 }
46
47 // PixbufNewFromBytesOnly is a convenient alternative to PixbufNewFromBytes() and also a wrapper around gdk_pixbuf_new_from_bytes().
48 // see go package "encoding/base64"
49 func PixbufNewFromBytesOnly(pixbufData []byte) (*Pixbuf, error) {
50 pixbufLoader, err := PixbufLoaderNew()
51 if err != nil {
52 return nil, err
53 }
54 return pixbufLoader.WriteAndReturnPixbuf(pixbufData)
55 }
56
57 // File loading
58
59 // TODO:
60 // gdk_pixbuf_get_file_info_async().
61 // gdk_pixbuf_get_file_info_finish().
62
63 // The GdkPixbuf Structure
64
65 // TODO:
66 // gdk_pixbuf_get_options().
67 // gdk_pixbuf_read_pixels().
0 // Same copyright and license as the rest of the files in this project
1
2 // +build !gdk_pixbuf_2_2,!gdk_pixbuf_2_4,!gdk_pixbuf_2_6,!gdk_pixbuf_2_8,!gdk_pixbuf_2_12,!gdk_pixbuf_2_14,!gdk_pixbuf_2_22,!gdk_pixbuf_2_24,!gdk_pixbuf_2_26,!gdk_pixbuf_2_28,!gdk_pixbuf_2_30,!gdk_pixbuf_2_32
3
4 package gdk
5
6 // #cgo pkg-config: gdk-3.0 glib-2.0 gobject-2.0
7 // #include <gdk/gdk.h>
8 // #include "gdk.go.h"
9 // #include "pixbuf.go.h"
10 import "C"
11
12 // File saving
13
14 // TODO:
15 // gdk_pixbuf_save_to_streamv().
16 // gdk_pixbuf_save_to_streamv_async().
17
18 // The GdkPixbuf Structure
19
20 // TODO:
21 // gdk_pixbuf_remove_option().
22 // gdk_pixbuf_copy_options().
0 // Same copyright and license as the rest of the files in this project
1
2 // +build !gdk_pixbuf_2_2
3
4 package gdk
5
6 // #cgo pkg-config: gdk-3.0 glib-2.0 gobject-2.0 gmodule-2.0
7 // #include <glib.h>
8 // #include <gmodule.h>
9 // #include <gdk/gdk.h>
10 // #include "gdk.go.h"
11 // #include "pixbuf.go.h"
12 // #include "pixbuf_since_2_4.go.h"
13 import "C"
14 import (
15 "errors"
16 "io"
17 "reflect"
18 "runtime"
19 "strconv"
20 "unsafe"
21
22 "github.com/gotk3/gotk3/glib"
23 "github.com/gotk3/gotk3/internal/callback"
24 )
25
26 // File saving
27
28 //export goPixbufSaveCallback
29 func goPixbufSaveCallback(buf *C.gchar, count C.gsize, gerr **C.GError, id C.gpointer) C.gboolean {
30 v := callback.Get(uintptr(id))
31
32 if v == nil {
33 C._pixbuf_error_set_callback_not_found(gerr)
34 return C.FALSE
35 }
36
37 var bytes []byte
38 header := (*reflect.SliceHeader)((unsafe.Pointer(&bytes)))
39 header.Cap = int(count)
40 header.Len = int(count)
41 header.Data = uintptr(unsafe.Pointer(buf))
42
43 _, err := v.(io.Writer).Write(bytes)
44 if err != nil {
45 cerr := C.CString(err.Error())
46 defer C.free(unsafe.Pointer(cerr))
47
48 C._pixbuf_error_set(gerr, cerr)
49 return C.FALSE
50 }
51
52 return C.TRUE
53 }
54
55 // WritePNG is a convenience wrapper around gdk_pixbuf_save_to_callback() for
56 // saving images using a streaming callback API. Compression is a number from 0
57 // to 9.
58 func (v *Pixbuf) WritePNG(w io.Writer, compression int) error {
59 ccompression := C.CString(strconv.Itoa(compression))
60 defer C.free(unsafe.Pointer(ccompression))
61
62 id := callback.Assign(w)
63
64 var err *C.GError
65 c := C._gdk_pixbuf_save_png_writer(v.native(), C.gpointer(id), &err, ccompression)
66
67 callback.Delete(id)
68
69 if !gobool(c) {
70 defer C.g_error_free(err)
71 return errors.New(C.GoString((*C.char)(err.message)))
72 }
73
74 return nil
75 }
76
77 // WriteJPEG is a convenience wrapper around gdk_pixbuf_save_to_callback() for
78 // saving images using a streaming callback API. Quality is a number from 0 to
79 // 100.
80 func (v *Pixbuf) WriteJPEG(w io.Writer, quality int) error {
81 cquality := C.CString(strconv.Itoa(quality))
82 defer C.free(unsafe.Pointer(cquality))
83
84 id := callback.Assign(w)
85
86 var err *C.GError
87 c := C._gdk_pixbuf_save_jpeg_writer(v.native(), C.gpointer(id), &err, cquality)
88
89 callback.Delete(id)
90
91 if !gobool(c) {
92 defer C.g_error_free(err)
93 return errors.New(C.GoString((*C.char)(err.message)))
94 }
95
96 return nil
97 }
98
99 // TODO:
100 // GdkPixbufSaveFunc
101 // gdk_pixbuf_save_to_callback().
102 // gdk_pixbuf_save_to_callbackv().
103 // gdk_pixbuf_save_to_buffer().
104 // gdk_pixbuf_save_to_bufferv().
105
106 // File Loading
107
108 // PixbufNewFromFileAtSize is a wrapper around gdk_pixbuf_new_from_file_at_size().
109 func PixbufNewFromFileAtSize(filename string, width, height int) (*Pixbuf, error) {
110 cstr := C.CString(filename)
111 defer C.free(unsafe.Pointer(cstr))
112
113 var err *C.GError = nil
114 c := C.gdk_pixbuf_new_from_file_at_size(cstr, C.int(width), C.int(height), &err)
115 if err != nil {
116 defer C.g_error_free(err)
117 return nil, errors.New(C.GoString((*C.char)(err.message)))
118 }
119
120 if c == nil {
121 return nil, nilPtrErr
122 }
123
124 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
125 p := &Pixbuf{obj}
126 //obj.Ref()
127 runtime.SetFinalizer(p, func(_ interface{}) { obj.Unref() })
128 return p, nil
129 }
130
131 // PixbufGetFileInfo is a wrapper around gdk_pixbuf_get_file_info().
132 func PixbufGetFileInfo(filename string) (*PixbufFormat, int, int, error) {
133 cstr := C.CString(filename)
134 defer C.free(unsafe.Pointer(cstr))
135 var cw, ch C.gint
136 format := C.gdk_pixbuf_get_file_info((*C.gchar)(cstr), &cw, &ch)
137 if format == nil {
138 return nil, -1, -1, nilPtrErr
139 }
140 // The returned PixbufFormat value is owned by Pixbuf and should not be freed.
141 return wrapPixbufFormat(format), int(cw), int(ch), nil
142 }
0 // Same copyright and license as the rest of the files in this project
1
2 #include <stdlib.h>
3
4 extern gboolean goPixbufSaveCallback(gchar *buf, gsize count, GError **error,
5 gpointer data);
6
7 static inline gboolean _gdk_pixbuf_save_png_writer(GdkPixbuf *pixbuf,
8 gpointer callback_id,
9 GError **err,
10 const char *compression) {
11 return gdk_pixbuf_save_to_callback(
12 pixbuf, (GdkPixbufSaveFunc)(goPixbufSaveCallback), callback_id, "png",
13 err, "compression", compression, NULL);
14 }
15
16 static inline gboolean _gdk_pixbuf_save_jpeg_writer(GdkPixbuf *pixbuf,
17 gpointer callback_id,
18 GError **err,
19 const char *quality) {
20 return gdk_pixbuf_save_to_callback(
21 pixbuf, (GdkPixbufSaveFunc)(goPixbufSaveCallback), callback_id, "jpeg",
22 err, "quality", quality, NULL);
23 }
24
25 static inline void _pixbuf_error_set_callback_not_found(GError **err) {
26 GQuark domain = g_quark_from_static_string("go error");
27 g_set_error_literal(err, domain, 1, "pixbuf callback not found");
28 }
29
30 static inline void _pixbuf_error_set(GError **err, char *message) {
31 GQuark domain = g_quark_from_static_string("go error");
32 g_set_error_literal(err, domain, 1, message);
33 }
0 // Same copyright and license as the rest of the files in this project
1
2 // +build !gdk_pixbuf_2_2,!gdk_pixbuf_2_4
3
4 package gdk
5
6 // #cgo pkg-config: gdk-3.0 glib-2.0 gobject-2.0
7 // #include <gdk/gdk.h>
8 // #include "gdk.go.h"
9 // #include "pixbuf.go.h"
10 import "C"
11 import (
12 "errors"
13 "runtime"
14 "unsafe"
15
16 "github.com/gotk3/gotk3/glib"
17 )
18
19 // File Loading
20
21 // PixbufNewFromFileAtScale is a wrapper around gdk_pixbuf_new_from_file_at_scale().
22 func PixbufNewFromFileAtScale(filename string, width, height int, preserveAspectRatio bool) (*Pixbuf, error) {
23 cstr := C.CString(filename)
24 defer C.free(unsafe.Pointer(cstr))
25
26 var err *C.GError = nil
27 c := C.gdk_pixbuf_new_from_file_at_scale(cstr, C.int(width), C.int(height),
28 gbool(preserveAspectRatio), &err)
29 if err != nil {
30 defer C.g_error_free(err)
31 return nil, errors.New(C.GoString((*C.char)(err.message)))
32 }
33
34 if c == nil {
35 return nil, nilPtrErr
36 }
37
38 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
39 p := &Pixbuf{obj}
40 //obj.Ref()
41 runtime.SetFinalizer(p, func(_ interface{}) { obj.Unref() })
42 return p, nil
43 }
44
45 // Scaling
46
47 // RotateSimple is a wrapper around gdk_pixbuf_rotate_simple().
48 func (v *Pixbuf) RotateSimple(angle PixbufRotation) (*Pixbuf, error) {
49 c := C.gdk_pixbuf_rotate_simple(v.native(), C.GdkPixbufRotation(angle))
50 if c == nil {
51 return nil, nilPtrErr
52 }
53
54 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
55 p := &Pixbuf{obj}
56 //obj.Ref()
57 runtime.SetFinalizer(p, func(_ interface{}) { obj.Unref() })
58 return p, nil
59 }
60
61 // Flip is a wrapper around gdk_pixbuf_flip().
62 func (v *Pixbuf) Flip(horizontal bool) (*Pixbuf, error) {
63 c := C.gdk_pixbuf_flip(v.native(), gbool(horizontal))
64 if c == nil {
65 return nil, nilPtrErr
66 }
67
68 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
69 p := &Pixbuf{obj}
70 //obj.Ref()
71 runtime.SetFinalizer(p, func(_ interface{}) { obj.Unref() })
72 return p, nil
73 }
102102 C.gdk_screen_set_resolution(v.native(), C.gdouble(r))
103103 }
104104
105 // TODO:
105106 // void gdk_screen_set_font_options ()
106107 // gboolean gdk_screen_get_setting ()
107108 // const cairo_font_options_t * gdk_screen_get_font_options ()
0 package gdk
1
2 // #include <gdk/gdk.h>
3 import "C"
4
5 // TestRenderSync retrieves a pixel from window to force the windowing system to carry out any pending rendering commands.
6 // This function is intended to be used to synchronize with rendering pipelines, to benchmark windowing system rendering operations.
7 // This is a wrapper around gdk_test_render_sync().
8 func TestRenderSync(window *Window) {
9 C.gdk_test_render_sync(window.native())
10 }
11
12 // TestSimulateButton simulates a single mouse button event (press or release) at the given coordinates relative to the window.
13 // Hint: a single click of a button requires this method to be called twice, once for pressed and once for released.
14 // In most cases, gtk.TestWidgetClick() should be used.
15 //
16 // button: Mouse button number, starts with 0
17 // modifiers: Keyboard modifiers for the button event
18 // buttonPressRelease: either GDK_BUTTON_PRESS or GDK_BUTTON_RELEASE
19 //
20 // This is a wrapper around gdk_test_simulate_button().
21 func TestSimulateButton(window *Window, x, y int, button Button, modifiers ModifierType, buttonPressRelease EventType) bool {
22 return gobool(C.gdk_test_simulate_button(window.native(), C.gint(x), C.gint(y), C.guint(button), C.GdkModifierType(modifiers), C.GdkEventType(buttonPressRelease)))
23 }
24
25 // TestSimulateButton simulates a keyboard event (press or release) at the given coordinates relative to the window.
26 // If the coordinates (-1, -1) are used, the window origin is used instead.
27 // Hint: a single key press requires this method to be called twice, once for pressed and once for released.
28 // In most cases, gtk.TestWidgetSendKey() should be used.
29 //
30 // keyval: A GDK keyboard value (See KeyvalFromName(), UnicodeToKeyval(), ...)
31 // modifiers: Keyboard modifiers for the key event
32 // buttonPressRelease: either GDK_BUTTON_PRESS or GDK_BUTTON_RELEASE
33 //
34 // This is a wrapper around gdk_test_simulate_key().
35 func TestSimulateKey(window *Window, x, y int, keyval uint, modifiers ModifierType, buttonPressRelease EventType) bool {
36 return gobool(C.gdk_test_simulate_key(window.native(), C.gint(x), C.gint(y), C.guint(keyval), C.GdkModifierType(modifiers), C.GdkEventType(buttonPressRelease)))
37 }
0 // package resource wraps operations over GResource
1 package gio
2
3 // #cgo pkg-config: gio-2.0 glib-2.0 gobject-2.0
4 // #include <gio/gio.h>
5 // #include <stdlib.h>
6 // #include "gresource.go.h"
7 import "C"
8 import (
9 "errors"
10 "unsafe"
11 )
12
13 // ResourceLookupFlags is a representation of GTK's GResourceLookupFlags
14 type ResourceLookupFlags int
15
16 func (f ResourceLookupFlags) native() C.GResourceLookupFlags {
17 return (C.GResourceLookupFlags)(f)
18 }
19
20 const (
21 G_RESOURCE_LOOKUP_FLAGS_NONE ResourceLookupFlags = C.G_RESOURCE_LOOKUP_FLAGS_NONE
22 )
23
24 // GResource wraps native GResource object
25 //
26 // See: https://developer.gnome.org/gio/stable/GResource.html
27 type GResource *C.GResource
28
29 // LoadGResource is a wrapper around g_resource_load()
30 //
31 // See: https://developer.gnome.org/gio/stable/GResource.html#g-resource-load
32 func LoadGResource(path string) (GResource, error) {
33 cpath := C.CString(path)
34 defer C.free(unsafe.Pointer(cpath))
35 var gerr *C.GError
36
37 resPtr := C.g_resource_load((*C.gchar)(unsafe.Pointer(cpath)), &gerr)
38 if gerr != nil {
39 defer C.g_error_free(gerr)
40 return nil, errors.New(goString(gerr.message))
41 }
42
43 res := wrapGResource(resPtr)
44 return res, nil
45 }
46
47 // NewGResourceFromData is a wrapper around g_resource_new_from_data()
48 //
49 // See: https://developer.gnome.org/gio/stable/GResource.html#g-resource-new-from-data
50 func NewGResourceFromData(data []byte) (GResource, error) {
51 arrayPtr := (*C.GBytes)(unsafe.Pointer(&data[0]))
52 var gerr *C.GError
53 resPtr := C.g_resource_new_from_data(arrayPtr, &gerr)
54 if gerr != nil {
55 defer C.g_error_free(gerr)
56 return nil, errors.New(goString(gerr.message))
57 }
58
59 res := wrapGResource(resPtr)
60 return res, nil
61 }
62
63 // Register wraps g_resources_register()
64 //
65 // See: https://developer.gnome.org/gio/stable/GResource.html#g-resources-register
66 func RegisterGResource(res GResource) {
67 C.g_resources_register(res)
68 }
69
70 // Unregister wraps g_resources_unregister()
71 //
72 // See: https://developer.gnome.org/gio/stable/GResource.html#g-resources-unregister
73 func UnregisterGResource(res GResource) {
74 C.g_resources_unregister(res)
75 }
76
77 // GResourceEnumerateChildren wraps g_resources_enumerate_children()
78 //
79 // See: https://developer.gnome.org/gio/stable/GResource.html#g-resources-enumerate-children
80 func GResourceEnumerateChildren(path string, flags ResourceLookupFlags) ([]string, error) {
81 cpath := C.CString(path)
82 defer C.free(unsafe.Pointer(cpath))
83 var gerr *C.GError
84 arrChildren := C.g_resources_enumerate_children(cpath, flags.native(), &gerr)
85 if gerr != nil {
86 defer C.g_error_free(gerr)
87 return nil, errors.New(goString(gerr.message))
88 }
89
90 if arrChildren == nil {
91 return nil, errors.New("unexpected nil pointer from g_resources_enumerate_children")
92 }
93
94 arr := toGoStringArray(arrChildren)
95 return arr, nil
96 }
97
98 func wrapGResource(resPtr *C.GResource) GResource {
99 res := GResource(resPtr)
100 return res
101 }
0 #pragma once
1
2 #include <glib.h>
3 #include <stdint.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <string.h>
7
8 static inline char **next_charptr(char **s) { return (s + 1); }
9
10 static inline void char_g_strfreev(char **s) { g_strfreev((gchar **)s); }
0 package gio
1
2 // #include <glib.h>
3 // #include "gresource.go.h"
4 import "C"
5
6 // same implementation as package glib
7 func toGoStringArray(c **C.char) []string {
8 var strs []string
9 originalc := c
10 defer C.char_g_strfreev(originalc)
11
12 for *c != nil {
13 strs = append(strs, C.GoString((*C.char)(*c)))
14 c = C.next_charptr(c)
15 }
16
17 return strs
18 }
19
20 func goString(cstr *C.gchar) string {
21 return C.GoString((*C.char)(cstr))
22 }
23
24 func gbool(b bool) C.gboolean {
25 if b {
26 return C.gboolean(1)
27 }
28 return C.gboolean(0)
29 }
30
31 func gobool(b C.gboolean) bool {
32 return b != C.FALSE
33 }
9393 C.g_application_set_flags(v.native(), C.GApplicationFlags(flags))
9494 }
9595
96 // Only available in GLib 2.42+
97 // // GetResourceBasePath is a wrapper around g_application_get_resource_base_path().
98 // func (v *Application) GetResourceBasePath() string {
99 // c := C.g_application_get_resource_base_path(v.native())
100
101 // return C.GoString((*C.char)(c))
102 // }
103
104 // Only available in GLib 2.42+
105 // // SetResourceBasePath is a wrapper around g_application_set_resource_base_path().
106 // func (v *Application) SetResourceBasePath(bp string) {
107 // cstr1 := (*C.gchar)(C.CString(bp))
108 // defer C.free(unsafe.Pointer(cstr1))
109
110 // C.g_application_set_resource_base_path(v.native(), cstr1)
111 // }
112
11396 // GetDbusObjectPath is a wrapper around g_application_get_dbus_object_path().
11497 func (v *Application) GetDbusObjectPath() string {
11598 c := C.g_application_get_dbus_object_path(v.native())
201184 return int(C.g_application_run(v.native(), C.int(len(args)), cargs))
202185 }
203186
204 // Only available in GLib 2.44+
205 // // GetIsBusy is a wrapper around g_application_get_is_busy().
206 // func (v *Application) GetIsBusy() bool {
207 // return gobool(C.g_application_get_is_busy(v.native()))
208 // }
209
210187 // void g_application_bind_busy_property ()
211188 // void g_application_unbind_busy_property ()
212189 // gboolean g_application_register () // requires GCancellable
0 package glib
1
2 type WrapFn interface{}
3
4 var WrapMap = map[string]WrapFn{
5 "GMenu": wrapMenuModel,
6 }
44 // #include "glib.go.h"
55 import "C"
66 import (
7 "errors"
87 "reflect"
98 "unsafe"
9
10 "github.com/gotk3/gotk3/internal/closure"
1011 )
1112
1213 /*
1314 * Events
1415 */
1516
17 // SignalHandle is the ID of a signal handler.
1618 type SignalHandle uint
1719
18 func (v *Object) connectClosure(after bool, detailedSignal string, f interface{}, userData ...interface{}) (SignalHandle, error) {
19 if len(userData) > 1 {
20 return 0, errors.New("userData len must be 0 or 1")
20 // Connect is a wrapper around g_signal_connect_closure(). f must be a function
21 // with at least one parameter matching the type it is connected to.
22 //
23 // It is optional to list the rest of the required types from Gtk, as values
24 // that don't fit into the function parameter will simply be ignored; however,
25 // extraneous types will trigger a runtime panic. Arguments for f must be a
26 // matching Go equivalent type for the C callback, or an interface type which
27 // the value may be packed in. If the type is not suitable, a runtime panic will
28 // occur when the signal is emitted.
29 //
30 // Circular References
31 //
32 // To prevent circular references, prefer declaring Connect functions like so:
33 //
34 // obj.Connect(func(obj *ObjType) { obj.Do() })
35 //
36 // Instead of directly referencing the object from outside like so:
37 //
38 // obj.Connect(func() { obj.Do() })
39 //
40 // When using Connect, beware of referencing variables outside the closure that
41 // may cause a circular reference that prevents both Go from garbage collecting
42 // the callback and GTK from successfully unreferencing its values.
43 //
44 // Below is an example piece of code that is considered "leaky":
45 //
46 // type ChatBox struct {
47 // gtk.TextView
48 // Loader *gdk.PixbufLoader
49 //
50 // State State
51 // }
52 //
53 // func (box *ChatBox) Method() {
54 // box.Loader.Connect("size-allocate", func(loader *gdk.PixbufLoader) {
55 // // Here, we're dereferencing box to get the state, which might
56 // // keep box alive along with the PixbufLoader, causing a circular
57 // // reference.
58 // loader.SetSize(box.State.Width, box.State.Height)
59 // })
60 // }
61 //
62 // There are many solutions to fix the above piece of code. For example,
63 // box.Loader could be discarded manually immediately after it's done by setting
64 // it to nil, or the signal handle could be disconnected manually, or box could
65 // be set to nil after its first call in the callback.
66 func (v *Object) Connect(detailedSignal string, f interface{}) SignalHandle {
67 return v.connectClosure(false, detailedSignal, f)
68 }
69
70 // ConnectAfter is a wrapper around g_signal_connect_closure(). The difference
71 // between Connect and ConnectAfter is that the latter will be invoked after the
72 // default handler, not before. For more information, refer to Connect.
73 func (v *Object) ConnectAfter(detailedSignal string, f interface{}) SignalHandle {
74 return v.connectClosure(true, detailedSignal, f)
75 }
76
77 // ClosureCheckReceiver, if true, will make GLib check for every single
78 // closure's first argument to ensure that it is correct, otherwise it will
79 // panic with a message warning about the possible circular references. The
80 // receiver in this case is most often the first argument of the callback.
81 //
82 // This constant can be changed by using go.mod's replace directive for
83 // debugging purposes.
84 const ClosureCheckReceiver = false
85
86 func (v *Object) connectClosure(after bool, detailedSignal string, f interface{}) SignalHandle {
87 fs := closure.NewFuncStack(f, 2)
88
89 if ClosureCheckReceiver {
90 // This is a bit slow, but we could be careful.
91 objValue, err := v.goValue()
92 if err == nil {
93 fsType := fs.Func.Type()
94 if fsType.NumIn() < 1 {
95 fs.Panicf("callback should have the object receiver to avoid circular references")
96 }
97 objType := reflect.TypeOf(objValue)
98 if first := fsType.In(0); !objType.ConvertibleTo(first) {
99 fs.Panicf("receiver not convertible to expected type %s, got %s", objType, first)
100 }
101 }
102
103 // Allow the type check to fail if we can't get a value marshaler. This
104 // rarely happens, but it might, and we want to at least allow working
105 // around it.
21106 }
22107
23108 cstr := C.CString(detailedSignal)
24109 defer C.free(unsafe.Pointer(cstr))
25110
26 closure, err := ClosureNew(f, userData...)
27 if err != nil {
28 return 0, err
29 }
111 gclosure := ClosureNewFunc(fs)
112 c := C.g_signal_connect_closure(C.gpointer(v.native()), (*C.gchar)(cstr), gclosure, gbool(after))
30113
31 C._g_closure_add_finalize_notifier(closure)
114 // TODO: There's a slight race condition here, where
115 // g_signal_connect_closure may trigger signal callbacks before the signal
116 // is registered. It is therefore ideal to have another intermediate ID to
117 // pass into the connect function. This is not a big issue though, since
118 // there isn't really any guarantee that signals should arrive until after
119 // the Connect functions return successfully.
120 closure.RegisterSignal(uint(c), unsafe.Pointer(gclosure))
32121
33 c := C.g_signal_connect_closure(C.gpointer(v.native()),
34 (*C.gchar)(cstr), closure, gbool(after))
35 handle := SignalHandle(c)
36
37 // Map the signal handle to the closure.
38 signals[handle] = closure
39
40 return handle, nil
122 return SignalHandle(c)
41123 }
42124
43 // Connect is a wrapper around g_signal_connect_closure(). f must be
44 // a function with a signaure matching the callback signature for
45 // detailedSignal. userData must either 0 or 1 elements which can
46 // be optionally passed to f. If f takes less arguments than it is
47 // passed from the GLib runtime, the extra arguments are ignored.
48 //
49 // Arguments for f must be a matching Go equivalent type for the
50 // C callback, or an interface type which the value may be packed in.
51 // If the type is not suitable, a runtime panic will occur when the
52 // signal is emitted.
53 func (v *Object) Connect(detailedSignal string, f interface{}, userData ...interface{}) (SignalHandle, error) {
54 return v.connectClosure(false, detailedSignal, f, userData...)
125 // ClosureNew creates a new GClosure and adds its callback function to the
126 // internal registry. It's exported for visibility to other gotk3 packages and
127 // should not be used in a regular application.
128 func ClosureNew(f interface{}) *C.GClosure {
129 return ClosureNewFunc(closure.NewFuncStack(f, 2))
55130 }
56131
57 // ConnectAfter is a wrapper around g_signal_connect_closure(). f must be
58 // a function with a signaure matching the callback signature for
59 // detailedSignal. userData must either 0 or 1 elements which can
60 // be optionally passed to f. If f takes less arguments than it is
61 // passed from the GLib runtime, the extra arguments are ignored.
62 //
63 // Arguments for f must be a matching Go equivalent type for the
64 // C callback, or an interface type which the value may be packed in.
65 // If the type is not suitable, a runtime panic will occur when the
66 // signal is emitted.
67 //
68 // The difference between Connect and ConnectAfter is that the latter
69 // will be invoked after the default handler, not before.
70 func (v *Object) ConnectAfter(detailedSignal string, f interface{}, userData ...interface{}) (SignalHandle, error) {
71 return v.connectClosure(true, detailedSignal, f, userData...)
132 // ClosureNewFunc creates a new GClosure and adds its callback function to the
133 // internal registry. It's exported for visibility to other gotk3 packages; it
134 // cannot be used in application code, as package closure is part of the
135 // internals.
136 func ClosureNewFunc(funcStack closure.FuncStack) *C.GClosure {
137 gclosure := C._g_closure_new()
138 closure.Assign(unsafe.Pointer(gclosure), funcStack)
139
140 return gclosure
72141 }
73142
74 // ClosureNew creates a new GClosure and adds its callback function
75 // to the internally-maintained map. It's exported for visibility to other
76 // gotk3 packages and shouldn't be used in application code.
77 func ClosureNew(f interface{}, marshalData ...interface{}) (*C.GClosure, error) {
78 // Create a reflect.Value from f. This is called when the
79 // returned GClosure runs.
80 rf := reflect.ValueOf(f)
81
82 // Create closure context which points to the reflected func.
83 cc := closureContext{rf: rf}
84
85 // Closures can only be created from funcs.
86 if rf.Type().Kind() != reflect.Func {
87 return nil, errors.New("value is not a func")
88 }
89
90 if len(marshalData) > 0 {
91 cc.userData = reflect.ValueOf(marshalData[0])
92 }
93
94 c := C._g_closure_new()
95
96 // Associate the GClosure with rf. rf will be looked up in this
97 // map by the closure when the closure runs.
98 closures.Lock()
99 closures.m[c] = cc
100 closures.Unlock()
101
102 return c, nil
103 }
104
105 // removeClosure removes a closure from the internal closures map. This is
143 // removeClosure removes a closure from the internal closures map. This is
106144 // needed to prevent a leak where Go code can access the closure context
107145 // (along with rf and userdata) even after an object has been destroyed and
108146 // the GClosure is invalidated and will never run.
109147 //
110148 //export removeClosure
111 func removeClosure(_ C.gpointer, closure *C.GClosure) {
112 closures.Lock()
113 delete(closures.m, closure)
114 closures.Unlock()
149 func removeClosure(_ C.gpointer, gclosure *C.GClosure) {
150 closure.Delete(unsafe.Pointer(gclosure))
115151 }
44 // #include <glib-object.h>
55 // #include "glib.go.h"
66 import "C"
7 import "unsafe"
7 import (
8 "unsafe"
9 )
10
11 func init() {
12 tm := []TypeMarshaler{
13 // Objects/Interfaces
14 {Type(C.g_simple_action_get_type()), marshalSimpleAction},
15 {Type(C.g_action_get_type()), marshalAction},
16 {Type(C.g_property_action_get_type()), marshalPropertyAction},
17 }
18 RegisterGValueMarshalers(tm)
19 }
820
921 // Action is a representation of glib's GAction GInterface.
1022 type Action struct {
3244 }
3345
3446 // gboolean g_action_parse_detailed_name (const gchar *detailed_name, gchar **action_name, GVariant **target_value, GError **error);
35 // gchar * g_action_print_detailed_name (const gchar *action_name, GVariant *target_value);
47
48 // ActionPrintDetailedName is a wrapper around g_action_print_detailed_name().
49 func ActionPrintDetailedName(action_name string, target_value *Variant) string {
50 cstr := C.CString(action_name)
51 defer C.free(unsafe.Pointer(cstr))
52 return C.GoString((*C.char)(C.g_action_print_detailed_name((*C.gchar)(cstr), target_value.native())))
53 }
3654
3755 // native() returns a pointer to the underlying GAction.
3856 func (v *Action) native() *C.GAction {
173191 C.g_simple_action_set_state(v.native(), value.native())
174192 }
175193
176 // SetStateHint is a wrapper around g_simple_action_set_state_hint
177 // GLib 2.44 only (currently no build tags, so commented out)
178 /*func (v *SimpleAction) SetStateHint(stateHint *Variant) {
179 C.g_simple_action_set_state_hint(v.native(), stateHint.native())
180 }*/
181
182194 // PropertyAction is a representation of GPropertyAction
183195 type PropertyAction struct {
184196 Action
0 package glib
1
2 // #include <gio/gio.h>
3 // #include <glib.h>
4 // #include <glib-object.h>
5 // #include "glib.go.h"
6 import "C"
7 import (
8 "errors"
9 "unsafe"
10 )
11
12 // IAsyncResult is an interface representation of AsyncResult,
13 // used to avoid duplication when embedding the type in a wrapper of another GObject-based type.
14 type IAsyncResult interface {
15 GetUserData() uintptr
16 GetSourceObject() *Object
17 IsTagged(sourceTag uintptr) bool
18 LegacyPropagateError() error
19 }
20
21 // AsyncReadyCallback is a representation of GAsyncReadyCallback
22 type AsyncReadyCallback func(object *Object, res *AsyncResult)
23
24 // AsyncResult is a representation of GIO's GAsyncResult.
25 type AsyncResult struct {
26 *Object
27 }
28
29 // native() returns a pointer to the underlying GAsyncResult.
30 func (v *AsyncResult) native() *C.GAsyncResult {
31 if v == nil || v.GObject == nil {
32 return nil
33 }
34 return C.toGAsyncResult(unsafe.Pointer(v.GObject))
35 }
36
37 func wrapAsyncResult(obj *Object) *AsyncResult {
38 return &AsyncResult{obj}
39 }
40
41 // GetUserData is a wrapper around g_async_result_get_user_data()
42 func (v *AsyncResult) GetUserData() uintptr {
43 c := C.g_async_result_get_user_data(v.native())
44 return uintptr(unsafe.Pointer(c))
45 }
46
47 // GetSourceObject is a wrapper around g_async_result_get_source_object
48 func (v *AsyncResult) GetSourceObject() *Object {
49 obj := C.g_async_result_get_source_object(v.native())
50 if obj == nil {
51 return nil
52 }
53 return wrapObject(unsafe.Pointer(obj))
54 }
55
56 // IsTagged is a wrapper around g_async_result_is_tagged
57 func (v *AsyncResult) IsTagged(sourceTag uintptr) bool {
58 c := C.g_async_result_is_tagged(v.native(), C.gpointer(sourceTag))
59 return gobool(c)
60 }
61
62 // LegacyPropagateError is a wrapper around g_async_result_legacy_propagate_error
63 func (v *AsyncResult) LegacyPropagateError() error {
64 var err *C.GError
65 c := C.g_async_result_legacy_propagate_error(v.native(), &err)
66 isSimpleAsyncResult := gobool(c)
67 if isSimpleAsyncResult {
68 defer C.g_error_free(err)
69 return errors.New(C.GoString((*C.char)(err.message)))
70 }
71 return nil
72 }
0 package glib
1
2 // #include <gio/gio.h>
3 // #include <glib.h>
4 // #include <glib-object.h>
5 // #include "glib.go.h"
6 import "C"
7 import (
8 "errors"
9 "unsafe"
10 )
11
12 // Cancellable is a representation of GIO's GCancellable.
13 type Cancellable struct {
14 *Object
15 }
16
17 // native returns a pointer to the underlying GCancellable.
18 func (v *Cancellable) native() *C.GCancellable {
19 if v == nil || v.GObject == nil {
20 return nil
21 }
22 return C.toCancellable(unsafe.Pointer(v.GObject))
23 }
24
25 func marshalCancellable(p uintptr) (interface{}, error) {
26 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
27 return wrapCancellable(wrapObject(unsafe.Pointer(c))), nil
28 }
29
30 func wrapCancellable(obj *Object) *Cancellable {
31 return &Cancellable{obj}
32 }
33
34 // CancellableNew is a wrapper around g_cancellable_new().
35 func CancellableNew() (*Cancellable, error) {
36 c := C.g_cancellable_new()
37 if c == nil {
38 return nil, nilPtrErr
39 }
40 return wrapCancellable(wrapObject(unsafe.Pointer(c))), nil
41 }
42
43 // IsCancelled is a wrapper around g_cancellable_is_cancelled().
44 func (v *Cancellable) IsCancelled() bool {
45 c := C.g_cancellable_is_cancelled(v.native())
46 return gobool(c)
47 }
48
49 // SetErrorIfCancelled is a wrapper around g_cancellable_set_error_if_cancelled().
50 func (v *Cancellable) SetErrorIfCancelled() error {
51 var err *C.GError
52 c := C.g_cancellable_set_error_if_cancelled(v.native(), &err)
53 cancelled := gobool(c)
54 if cancelled {
55 defer C.g_error_free(err)
56 return errors.New(C.GoString((*C.char)(err.message)))
57 }
58 return nil
59 }
60
61 // GetFD is a wrapper around g_cancellable_get_fd().
62 func (v *Cancellable) GetFD() int {
63 c := C.g_cancellable_get_fd(v.native())
64 return int(c)
65 }
66
67 // MakePollFD is a wrapper around g_cancellable_make_pollfd().
68 // func (v *Cancellable) MakePollFD(pollFD *PollFD) bool {
69 // c := C.g_cancellable_make_pollfd(v.native(), )
70 // return gobool(c)
71 // }
72
73 // ReleaseFD is a wrapper around g_cancellable_release_fd().
74 func (v *Cancellable) ReleaseFD() {
75 C.g_cancellable_release_fd(v.native())
76 }
77
78 // SourceNew is a wrapper around g_cancellable_source_new().
79 func (v *Cancellable) SourceNew() *Source {
80 c := C.g_cancellable_source_new(v.native())
81 return wrapSource(c)
82 }
0 package glib
1
2 // #include <gio/gio.h>
3 // #include <glib.h>
4 // #include <glib-object.h>
5 // #include "glib.go.h"
6 // #include "gfile.go.h"
7 import "C"
8 import (
9 "errors"
10 "unsafe"
11 )
12
13 func init() {
14
15 tm := []TypeMarshaler{
16 {Type(C.g_file_get_type()), marshalFile},
17 {Type(C.g_file_input_stream_get_type()), marshalFileInputStream},
18 {Type(C.g_file_output_stream_get_type()), marshalFileOutputStream},
19 }
20
21 RegisterGValueMarshalers(tm)
22 }
23
24 func goString(cstr *C.gchar) string {
25 return C.GoString((*C.char)(cstr))
26 }
27
28 /*
29 * GFile
30 */
31
32 // File is a representation of GIO's GFile.
33 type File struct {
34 *Object
35 }
36
37 // native returns a pointer to the underlying GFile.
38 func (v *File) native() *C.GFile {
39 if v == nil || v.GObject == nil {
40 return nil
41 }
42 p := unsafe.Pointer(v.GObject)
43 return C.toGFile(p)
44 }
45
46 // NativePrivate: to be used inside Gotk3 only.
47 func (v *File) NativePrivate() *C.GFile {
48 if v == nil || v.GObject == nil {
49 return nil
50 }
51 p := unsafe.Pointer(v.GObject)
52 return C.toGFile(p)
53 }
54
55 // Native returns a pointer to the underlying GFile.
56 func (v *File) Native() uintptr {
57 return uintptr(unsafe.Pointer(v.native()))
58 }
59
60 func marshalFile(p uintptr) (interface{}, error) {
61 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
62 obj := Take(unsafe.Pointer(c))
63 return wrapFile(obj), nil
64 }
65
66 func wrapFile(obj *Object) *File {
67 return &File{obj}
68 }
69
70 // FileNew is a wrapper around g_file_new_for_path().
71 // To avoid breaking previous implementation of GFile ...
72 func FileNew(path string) *File {
73 f, e := FileNewForPath(path)
74 if e != nil {
75 return nil
76 }
77 return f
78 }
79
80 // FileNewForPath is a wrapper around g_file_new_for_path().
81 func FileNewForPath(path string) (*File, error) {
82 cstr := (*C.char)(C.CString(path))
83 defer C.free(unsafe.Pointer(cstr))
84
85 c := C.g_file_new_for_path(cstr)
86 if c == nil {
87 return nil, nilPtrErr
88 }
89 return wrapFile(Take(unsafe.Pointer(c))), nil
90 }
91
92 // TODO g_file_*** and more
93 /*
94 void (*GFileProgressCallback) ()
95 gboolean (*GFileReadMoreCallback) ()
96 void (*GFileMeasureProgressCallback) ()
97 GFile * g_file_new_for_uri ()
98 GFile * g_file_new_for_commandline_arg ()
99 GFile * g_file_new_for_commandline_arg_and_cwd ()
100 GFile * g_file_new_tmp ()
101 GFile * g_file_parse_name ()
102 GFile * g_file_new_build_filename ()
103 GFile * g_file_dup ()
104 guint g_file_hash ()
105 gboolean g_file_equal ()
106 char * g_file_get_basename ()
107 */
108
109 /*
110 char *
111 g_file_get_path (GFile *file);
112 */
113 // GetPath is a wrapper around g_file_get_path().
114 func (v *File) GetPath() string {
115 var s string
116 if c := C.g_file_get_path(v.native()); c != nil {
117 s = C.GoString(c)
118 defer C.g_free((C.gpointer)(c))
119 }
120
121 return s
122 }
123
124 /*
125 const char * g_file_peek_path ()
126 char * g_file_get_uri ()
127 char * g_file_get_parse_name ()
128 GFile * g_file_get_parent ()
129 gboolean g_file_has_parent ()
130 GFile * g_file_get_child ()
131 GFile * g_file_get_child_for_display_name ()
132 gboolean g_file_has_prefix ()
133 char * g_file_get_relative_path ()
134 GFile * g_file_resolve_relative_path ()
135 gboolean g_file_is_native ()
136 gboolean g_file_has_uri_scheme ()
137 char * g_file_get_uri_scheme ()
138 */
139
140 /*
141 GFileInputStream *
142 g_file_read (GFile *file,
143 GCancellable *cancellable,
144 GError **error);
145 */
146 // Read is a wrapper around g_file_read().
147 // Object.Unref() must be used after use
148 func (v *File) Read(cancellable *Cancellable) (*FileInputStream, error) {
149 var gerr *C.GError
150 c := C.g_file_read(
151 v.native(),
152 cancellable.native(),
153 &gerr)
154 if c == nil {
155 defer C.g_error_free(gerr)
156 return nil, errors.New(goString(gerr.message))
157 }
158 return wrapFileInputStream(Take(unsafe.Pointer(c))), nil
159 }
160
161 /*
162 void g_file_read_async ()
163 GFileInputStream * g_file_read_finish ()
164 GFileOutputStream * g_file_append_to ()
165 GFileOutputStream * g_file_create ()
166 GFileOutputStream * g_file_replace ()
167 void g_file_append_to_async ()
168 GFileOutputStream * g_file_append_to_finish ()
169 void g_file_create_async ()
170 GFileOutputStream * g_file_create_finish ()
171 void g_file_replace_async ()
172 GFileOutputStream * g_file_replace_finish ()
173 GFileInfo * g_file_query_info ()
174 void g_file_query_info_async ()
175 GFileInfo * g_file_query_info_finish ()
176 gboolean g_file_query_exists ()
177 GFileType g_file_query_file_type ()
178 GFileInfo * g_file_query_filesystem_info ()
179 void g_file_query_filesystem_info_async ()
180 GFileInfo * g_file_query_filesystem_info_finish ()
181 GAppInfo * g_file_query_default_handler ()
182 void g_file_query_default_handler_async ()
183 GAppInfo * g_file_query_default_handler_finish ()
184 gboolean g_file_measure_disk_usage ()
185 void g_file_measure_disk_usage_async ()
186 gboolean g_file_measure_disk_usage_finish ()
187 GMount * g_file_find_enclosing_mount ()
188 void g_file_find_enclosing_mount_async ()
189 GMount * g_file_find_enclosing_mount_finish ()
190 GFileEnumerator * g_file_enumerate_children ()
191 void g_file_enumerate_children_async ()
192 GFileEnumerator * g_file_enumerate_children_finish ()
193 GFile * g_file_set_display_name ()
194 void g_file_set_display_name_async ()
195 GFile * g_file_set_display_name_finish ()
196 gboolean g_file_delete ()
197 void g_file_delete_async ()
198 gboolean g_file_delete_finish ()
199 gboolean g_file_trash ()
200 void g_file_trash_async ()
201 gboolean g_file_trash_finish ()
202 gboolean g_file_copy ()
203 void g_file_copy_async ()
204 gboolean g_file_copy_finish ()
205 gboolean g_file_move ()
206 gboolean g_file_make_directory ()
207 void g_file_make_directory_async ()
208 gboolean g_file_make_directory_finish ()
209 gboolean g_file_make_directory_with_parents ()
210 gboolean g_file_make_symbolic_link ()
211 GFileAttributeInfoList * g_file_query_settable_attributes ()
212 GFileAttributeInfoList * g_file_query_writable_namespaces ()
213 gboolean g_file_set_attribute ()
214 gboolean g_file_set_attributes_from_info ()
215 void g_file_set_attributes_async ()
216 gboolean g_file_set_attributes_finish ()
217 gboolean g_file_set_attribute_string ()
218 gboolean g_file_set_attribute_byte_string ()
219 gboolean g_file_set_attribute_uint32 ()
220 gboolean g_file_set_attribute_int32 ()
221 gboolean g_file_set_attribute_uint64 ()
222 gboolean g_file_set_attribute_int64 ()
223 void g_file_mount_mountable ()
224 GFile * g_file_mount_mountable_finish ()
225 void g_file_unmount_mountable ()
226 gboolean g_file_unmount_mountable_finish ()
227 void g_file_unmount_mountable_with_operation ()
228 gboolean g_file_unmount_mountable_with_operation_finish ()
229 void g_file_eject_mountable ()
230 gboolean g_file_eject_mountable_finish ()
231 void g_file_eject_mountable_with_operation ()
232 gboolean g_file_eject_mountable_with_operation_finish ()
233 void g_file_start_mountable ()
234 gboolean g_file_start_mountable_finish ()
235 void g_file_stop_mountable ()
236 gboolean g_file_stop_mountable_finish ()
237 void g_file_poll_mountable ()
238 gboolean g_file_poll_mountable_finish ()
239 void g_file_mount_enclosing_volume ()
240 gboolean g_file_mount_enclosing_volume_finish ()
241 GFileMonitor * g_file_monitor_directory ()
242 GFileMonitor * g_file_monitor_file ()
243 GFileMonitor * g_file_monitor ()
244 GBytes * g_file_load_bytes ()
245 void g_file_load_bytes_async ()
246 GBytes * g_file_load_bytes_finish ()
247 gboolean g_file_load_contents ()
248 void g_file_load_contents_async ()
249 gboolean g_file_load_contents_finish ()
250 void g_file_load_partial_contents_async ()
251 gboolean g_file_load_partial_contents_finish ()
252 gboolean g_file_replace_contents ()
253 void g_file_replace_contents_async ()
254 void g_file_replace_contents_bytes_async ()
255 gboolean g_file_replace_contents_finish ()
256 gboolean g_file_copy_attributes ()
257 GFileIOStream * g_file_create_readwrite ()
258 void g_file_create_readwrite_async ()
259 GFileIOStream * g_file_create_readwrite_finish ()
260 GFileIOStream * g_file_open_readwrite ()
261 void g_file_open_readwrite_async ()
262 GFileIOStream * g_file_open_readwrite_finish ()
263 GFileIOStream * g_file_replace_readwrite ()
264 void g_file_replace_readwrite_async ()
265 GFileIOStream * g_file_replace_readwrite_finish ()
266 gboolean g_file_supports_thread_contexts ()
267 */
268
269 /*
270 * GFileInputStream
271 */
272
273 // FileInputStream is a representation of GIO's GFileInputStream.
274 type FileInputStream struct {
275 *InputStream
276 }
277
278 // native returns a pointer to the underlying GFileInputStream.
279 func (v *FileInputStream) native() *C.GFileInputStream {
280 if v == nil || v.GObject == nil {
281 return nil
282 }
283 p := unsafe.Pointer(v.GObject)
284 return C.toGFileInputStream(p)
285 }
286
287 // NativePrivate: to be used inside Gotk3 only.
288 func (v *FileInputStream) NativePrivate() *C.GFileInputStream {
289 if v == nil || v.GObject == nil {
290 return nil
291 }
292 p := unsafe.Pointer(v.GObject)
293 return C.toGFileInputStream(p)
294 }
295
296 // Native returns a pointer to the underlying GFileInputStream.
297 func (v *FileInputStream) Native() uintptr {
298 return uintptr(unsafe.Pointer(v.native()))
299 }
300
301 func marshalFileInputStream(p uintptr) (interface{}, error) {
302 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
303 obj := Take(unsafe.Pointer(c))
304 return wrapFileInputStream(obj), nil
305 }
306
307 func wrapFileInputStream(obj *Object) *FileInputStream {
308 return &FileInputStream{wrapInputStream(obj)}
309 }
310
311 // TODO g_file_input_stream_query_info and more
312 /*
313 GFileInfo * g_file_input_stream_query_info ()
314 void g_file_input_stream_query_info_async ()
315 GFileInfo * g_file_input_stream_query_info_finish ()
316 */
317
318 /*
319 * GFileOutputStream
320 */
321
322 // FileOutputStream is a representation of GIO's GFileOutputStream.
323 type FileOutputStream struct {
324 *OutputStream
325 }
326
327 // native returns a pointer to the underlying GFileOutputStream.
328 func (v *FileOutputStream) native() *C.GFileOutputStream {
329 if v == nil || v.GObject == nil {
330 return nil
331 }
332 p := unsafe.Pointer(v.GObject)
333 return C.toGFileOutputStream(p)
334 }
335
336 // NativePrivate: to be used inside Gotk3 only.
337 func (v *FileOutputStream) NativePrivate() *C.GFileOutputStream {
338 if v == nil || v.GObject == nil {
339 return nil
340 }
341 p := unsafe.Pointer(v.GObject)
342 return C.toGFileOutputStream(p)
343 }
344
345 // Native returns a pointer to the underlying GFileOutputStream.
346 func (v *FileOutputStream) Native() uintptr {
347 return uintptr(unsafe.Pointer(v.native()))
348 }
349
350 func marshalFileOutputStream(p uintptr) (interface{}, error) {
351 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
352 obj := Take(unsafe.Pointer(c))
353 return wrapFileOutputStream(obj), nil
354 }
355
356 func wrapFileOutputStream(obj *Object) *FileOutputStream {
357 return &FileOutputStream{wrapOutputStream(obj)}
358 }
359
360 // TODO g_file_output_stream_query_info and more
361 /*
362 GFileInfo * g_file_output_stream_query_info ()
363 void g_file_output_stream_query_info_async ()
364 GFileInfo * g_file_output_stream_query_info_finish ()
365 char * g_file_output_stream_get_etag ()
366 */
0 #include <stdint.h>
1 #include <stdio.h>
2 #include <stdlib.h>
3
4 #include <gio/gio.h>
5
6 static GFileInputStream *toGFileInputStream(void *p) {
7 return (G_FILE_INPUT_STREAM(p));
8 }
9
10 static GFileOutputStream *toGFileOutputStream(void *p) {
11 return (G_FILE_OUTPUT_STREAM(p));
12 }
0 package glib
1
2 // #include <gio/gio.h>
3 // #include <glib.h>
4 // #include <glib-object.h>
5 // #include "glib.go.h"
6 import "C"
7 import (
8 "errors"
9 "runtime"
10 "unsafe"
11 )
12
13 func init() {
14
15 tm := []TypeMarshaler{
16 {Type(C.g_file_get_type()), marshalFile},
17 {Type(C.g_file_icon_get_type()), marshalFileIcon},
18 }
19
20 RegisterGValueMarshalers(tm)
21 }
22
23 /*
24 * GIcon
25 */
26
27 // Icon is a representation of GIO's GIcon.
28 // Interface for icons
29 type Icon struct {
30 *Object
31 }
32
33 // native returns a pointer to the underlying GIcon.
34 func (v *Icon) native() *C.GIcon {
35 if v == nil || v.GObject == nil {
36 return nil
37 }
38 p := unsafe.Pointer(v.GObject)
39 return C.toGIcon(p)
40 }
41
42 // NativePrivate: to be used inside Gotk3 only.
43 func (v *Icon) NativePrivate() *C.GIcon {
44 if v == nil || v.GObject == nil {
45 return nil
46 }
47 p := unsafe.Pointer(v.GObject)
48 return C.toGIcon(p)
49 }
50
51 // Native returns a pointer to the underlying GIcon.
52 func (v *Icon) Native() uintptr {
53 return uintptr(unsafe.Pointer(v.native()))
54 }
55
56 func marshalIcon(p uintptr) (interface{}, error) {
57 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
58 obj := Take(unsafe.Pointer(c))
59 return wrapIcon(obj), nil
60 }
61
62 func wrapIcon(obj *Object) *Icon {
63 return &Icon{obj}
64 }
65
66 // TODO I dont know how to handle it ...
67 /*
68 guint
69 g_icon_hash (gconstpointer icon);
70 */
71
72 // Equal is a wrapper around g_icon_equal().
73 func (v *Icon) Equal(icon *Icon) bool {
74 return gobool(C.g_icon_equal(v.native(), icon.native()))
75 }
76
77 // ToString is a wrapper around g_icon_to_string().
78 func (v *Icon) ToString() string {
79 var s string
80 if c := C.g_icon_to_string(v.native()); c != nil {
81 s = goString(c)
82 defer C.g_free((C.gpointer)(c))
83 }
84
85 return s
86 }
87
88 // IconNewForString is a wrapper around g_icon_new_for_string().
89 func IconNewForString(str string) (*Icon, error) {
90 cstr := C.CString(str)
91 defer C.free(unsafe.Pointer(cstr))
92
93 var err *C.GError
94 c := C.g_icon_new_for_string((*C.gchar)(cstr), &err)
95 if c == nil {
96 defer C.g_error_free(err)
97 return nil, errors.New(C.GoString((*C.char)(err.message)))
98 }
99
100 obj := &Object{ToGObject(unsafe.Pointer(c))}
101 i := &Icon{obj}
102
103 runtime.SetFinalizer(i, func(_ interface{}) { obj.Unref() })
104 return i, nil
105 }
106
107 // TODO Requiere GVariant
108 /*
109 GVariant * g_icon_serialize ()
110 GIcon * g_icon_deserialize ()
111 */
112
113 /*
114 * GFileIcon
115 */
116
117 // FileIcon is a representation of GIO's GFileIcon.
118 type FileIcon struct {
119 *Object
120 }
121
122 // native returns a pointer to the underlying GFileIcon.
123 func (v *FileIcon) native() *C.GFileIcon {
124 if v == nil || v.GObject == nil {
125 return nil
126 }
127 p := unsafe.Pointer(v.GObject)
128 return C.toGFileIcon(p)
129 }
130
131 // NativePrivate: to be used inside Gotk3 only.
132 func (v *FileIcon) NativePrivate() *C.GFileIcon {
133 if v == nil || v.GObject == nil {
134 return nil
135 }
136 p := unsafe.Pointer(v.GObject)
137 return C.toGFileIcon(p)
138 }
139
140 // Native returns a pointer to the underlying GFileIcon.
141 func (v *FileIcon) Native() uintptr {
142 return uintptr(unsafe.Pointer(v.native()))
143 }
144
145 func marshalFileIcon(p uintptr) (interface{}, error) {
146 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
147 obj := Take(unsafe.Pointer(c))
148 return wrapFileIcon(obj), nil
149 }
150
151 func wrapFileIcon(obj *Object) *FileIcon {
152 return &FileIcon{obj}
153 }
154
155 // FileIconNewN is a wrapper around g_file_icon_new().
156 // This version respect Gtk3 documentation.
157 func FileIconNewN(file *File) (*Icon, error) {
158
159 c := C.g_file_icon_new(file.native())
160 if c == nil {
161 return nil, nilPtrErr
162 }
163 return wrapIcon(Take(unsafe.Pointer(c))), nil
164 }
165
166 // FileIconNew is a wrapper around g_file_icon_new().
167 // To not break previous implementation of GFileIcon ...
168 func FileIconNew(path string) *Icon {
169 file := FileNew(path)
170
171 c := C.g_file_icon_new(file.native())
172 if c == nil {
173 return nil
174 }
175 return wrapIcon(Take(unsafe.Pointer(c)))
176 }
0 package glib
1
2 // #cgo pkg-config: gio-2.0 glib-2.0 gobject-2.0
3 // #include <gio/gio.h>
4 // #include <stdlib.h>
5 // #include "giostream.go.h"
6 import "C"
7 import (
8 "bytes"
9 "errors"
10 "unsafe"
11 )
12
13 func init() {
14
15 tm := []TypeMarshaler{
16 {Type(C.g_io_stream_get_type()), marshalIOStream},
17 {Type(C.g_output_stream_get_type()), marshalOutputStream},
18 {Type(C.g_input_stream_get_type()), marshalInputStream},
19 }
20
21 RegisterGValueMarshalers(tm)
22 }
23
24 // OutputStreamSpliceFlags is a representation of GTK's GOutputStreamSpliceFlags.
25 type OutputStreamSpliceFlags int
26
27 const (
28 OUTPUT_STREAM_SPLICE_NONE OutputStreamSpliceFlags = C.G_OUTPUT_STREAM_SPLICE_NONE
29 OUTPUT_STREAM_SPLICE_CLOSE_SOURCE = C.G_OUTPUT_STREAM_SPLICE_CLOSE_SOURCE
30 OUTPUT_STREAM_SPLICE_CLOSE_TARGET = C.G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET
31 )
32
33 /*
34 * GIOStream
35 */
36
37 // IOStream is a representation of GIO's GIOStream.
38 // Base class for implementing read/write streams
39 type IOStream struct {
40 *Object
41 }
42
43 // native returns a pointer to the underlying GIOStream.
44 func (v *IOStream) native() *C.GIOStream {
45 if v == nil || v.GObject == nil {
46 return nil
47 }
48 p := unsafe.Pointer(v.GObject)
49 return C.toGIOStream(p)
50 }
51
52 // NativePrivate: to be used inside Gotk3 only.
53 func (v *IOStream) NativePrivate() *C.GIOStream {
54 if v == nil || v.GObject == nil {
55 return nil
56 }
57 p := unsafe.Pointer(v.GObject)
58 return C.toGIOStream(p)
59 }
60
61 // Native returns a pointer to the underlying GIOStream.
62 func (v *IOStream) Native() uintptr {
63 return uintptr(unsafe.Pointer(v.native()))
64 }
65
66 func marshalIOStream(p uintptr) (interface{}, error) {
67 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
68 obj := Take(unsafe.Pointer(c))
69 return wrapIOStream(obj), nil
70 }
71
72 func wrapIOStream(obj *Object) *IOStream {
73 return &IOStream{obj}
74 }
75
76 /*
77 GInputStream * g_io_stream_get_input_stream ()
78 GOutputStream * g_io_stream_get_output_stream ()
79 void g_io_stream_splice_async ()
80 gboolean g_io_stream_splice_finish ()
81 */
82
83 // Close is a wrapper around g_io_stream_close().
84 func (v *IOStream) Close(cancellable *Cancellable) (bool, error) {
85 var gerr *C.GError
86 ok := gobool(C.g_io_stream_close(
87 v.native(),
88 cancellable.native(),
89 &gerr))
90 if !ok {
91 defer C.g_error_free(gerr)
92 return false, errors.New(goString(gerr.message))
93 }
94 return ok, nil
95 }
96
97 /*
98 void g_io_stream_close_async ()
99 gboolean g_io_stream_close_finish ()
100 gboolean g_io_stream_is_closed ()
101 gboolean g_io_stream_has_pending ()
102 gboolean g_io_stream_set_pending ()
103 void g_io_stream_clear_pending ()
104 */
105
106 /*
107 * GInputStream
108 */
109
110 // InputStream is a representation of GIO's GInputStream.
111 // Base class for implementing streaming input
112 type InputStream struct {
113 *Object
114 }
115
116 // native returns a pointer to the underlying GInputStream.
117 func (v *InputStream) native() *C.GInputStream {
118 if v == nil || v.GObject == nil {
119 return nil
120 }
121 p := unsafe.Pointer(v.GObject)
122 return C.toGInputStream(p)
123 }
124
125 // NativePrivate: to be used inside Gotk3 only.
126 func (v *InputStream) NativePrivate() *C.GInputStream {
127 if v == nil || v.GObject == nil {
128 return nil
129 }
130 p := unsafe.Pointer(v.GObject)
131 return C.toGInputStream(p)
132 }
133
134 // Native returns a pointer to the underlying GInputStream.
135 func (v *InputStream) Native() uintptr {
136 return uintptr(unsafe.Pointer(v.native()))
137 }
138
139 func marshalInputStream(p uintptr) (interface{}, error) {
140 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
141 obj := Take(unsafe.Pointer(c))
142 return wrapInputStream(obj), nil
143 }
144
145 func wrapInputStream(obj *Object) *InputStream {
146 return &InputStream{obj}
147 }
148
149 // Read is a wrapper around g_input_stream_read().
150 func (v *InputStream) Read(length uint, cancellable *Cancellable) (*bytes.Buffer, int, error) {
151 var gerr *C.GError
152 var buffer = bytes.NewBuffer(make([]byte, length))
153
154 c := C.g_input_stream_read(
155 v.native(),
156 unsafe.Pointer(&buffer.Bytes()[0]),
157 C.gsize(length),
158 cancellable.native(),
159 &gerr)
160 if c == -1 {
161 defer C.g_error_free(gerr)
162 return nil, -1, errors.New(goString(gerr.message))
163 }
164 return buffer, int(c), nil
165 }
166
167 // TODO find a way to get size to be read without asking for ...
168 /*
169 gboolean
170 g_input_stream_read_all (GInputStream *stream,
171 void *buffer,
172 gsize count,
173 gsize *bytes_read,
174 GCancellable *cancellable,
175 GError **error);
176 */
177
178 /*
179 void g_input_stream_read_all_async ()
180 gboolean g_input_stream_read_all_finish ()
181 gssize g_input_stream_skip ()
182 */
183
184 // Close is a wrapper around g_input_stream_close().
185 func (v *InputStream) Close(cancellable *Cancellable) (bool, error) {
186 var gerr *C.GError
187 ok := gobool(C.g_input_stream_close(
188 v.native(),
189 cancellable.native(),
190 &gerr))
191 if !ok {
192 defer C.g_error_free(gerr)
193 return false, errors.New(goString(gerr.message))
194 }
195 return ok, nil
196 }
197
198 // TODO g_input_stream***
199 /*
200 void g_input_stream_read_async ()
201 gssize g_input_stream_read_finish ()
202 void g_input_stream_skip_async ()
203 gssize g_input_stream_skip_finish ()
204 void g_input_stream_close_async ()
205 gboolean g_input_stream_close_finish ()
206 */
207
208 // IsClosed is a wrapper around g_input_stream_is_closed().
209 func (v *InputStream) IsClosed() bool {
210 return gobool(C.g_input_stream_is_closed(v.native()))
211 }
212
213 // HasPending is a wrapper around g_input_stream_has_pending().
214 func (v *InputStream) HasPending() bool {
215 return gobool(C.g_input_stream_has_pending(v.native()))
216 }
217
218 // SetPending is a wrapper around g_input_stream_set_pending().
219 func (v *InputStream) SetPending() (bool, error) {
220 var gerr *C.GError
221 ok := gobool(C.g_input_stream_set_pending(
222 v.native(),
223 &gerr))
224 if !ok {
225 defer C.g_error_free(gerr)
226 return false, errors.New(goString(gerr.message))
227 }
228 return ok, nil
229 }
230
231 // ClearPending is a wrapper around g_input_stream_clear_pending().
232 func (v *InputStream) ClearPending() {
233 C.g_input_stream_clear_pending(v.native())
234 }
235
236 /* Useless functions due to Go language specification and actual
237 implementation of (*InputStream).Read that do same thing.
238
239 GBytes * g_input_stream_read_bytes ()
240 void g_input_stream_read_bytes_async ()
241 GBytes * g_input_stream_read_bytes_finish ()
242 */
243
244 /*
245 * GOutputStream
246 */
247
248 // OutputStream is a representation of GIO's GOutputStream.
249 // Base class for implementing streaming output
250 type OutputStream struct {
251 *Object
252 }
253
254 // native returns a pointer to the underlying GOutputStream.
255 func (v *OutputStream) native() *C.GOutputStream {
256 if v == nil || v.GObject == nil {
257 return nil
258 }
259 p := unsafe.Pointer(v.GObject)
260 return C.toGOutputStream(p)
261 }
262
263 // NativePrivate: to be used inside Gotk3 only.
264 func (v *OutputStream) NativePrivate() *C.GOutputStream {
265 if v == nil || v.GObject == nil {
266 return nil
267 }
268 p := unsafe.Pointer(v.GObject)
269 return C.toGOutputStream(p)
270 }
271
272 // Native returns a pointer to the underlying GOutputStream.
273 func (v *OutputStream) Native() uintptr {
274 return uintptr(unsafe.Pointer(v.native()))
275 }
276
277 func marshalOutputStream(p uintptr) (interface{}, error) {
278 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
279 obj := Take(unsafe.Pointer(c))
280 return wrapOutputStream(obj), nil
281 }
282
283 func wrapOutputStream(obj *Object) *OutputStream {
284 return &OutputStream{obj}
285 }
286
287 /*
288 gssize
289 g_output_stream_write (GOutputStream *stream,
290 const void *buffer,
291 gsize count,
292 GCancellable *cancellable,
293 GError **error);
294 */
295
296 // Write is a wrapper around g_output_stream_write().
297 // buffer := bytes.NewBuffer(make([]byte, length))
298 func (v *OutputStream) Write(buffer *bytes.Buffer, cancellable *Cancellable) (int, error) {
299 var gerr *C.GError
300 length := buffer.Len()
301
302 c := C.g_output_stream_write(
303 v.native(),
304 unsafe.Pointer(&buffer.Bytes()[0]),
305 C.gsize(length),
306 cancellable.native(),
307 &gerr)
308 if c == -1 {
309 defer C.g_error_free(gerr)
310 return -1, errors.New(goString(gerr.message))
311 }
312 return int(c), nil
313 }
314
315 // Write is a wrapper around g_output_stream_write().
316 // func (v *OutputStream) Write(buffer *[]byte, cancellable *Cancellable) (int, error) {
317 // // cdata := C.CString(data)
318 // // defer C.free(unsafe.Pointer(cdata))
319 // var gerr *C.GError
320 // c := C.g_output_stream_write(
321 // v.native(),
322 // unsafe.Pointer(buffer),
323 // C.gsize(len(*buffer)),
324 // cancellable.native(),
325 // &gerr)
326 // if c == -1 {
327 // defer C.g_error_free(gerr)
328 // return 0, errors.New(goString(gerr.message))
329 // }
330 // return int(c), nil
331 // }
332
333 /*
334 gboolean g_output_stream_write_all ()
335 */
336
337 // TODO outputStream asynch functions
338 /*
339 void g_output_stream_write_all_async ()
340 gboolean g_output_stream_write_all_finish ()
341 gboolean g_output_stream_writev ()
342 gboolean g_output_stream_writev_all ()
343 void g_output_stream_writev_async ()
344 gboolean g_output_stream_writev_finish ()
345 void g_output_stream_writev_all_async ()
346 gboolean g_output_stream_writev_all_finish ()
347 */
348 /*
349 gssize
350 g_output_stream_splice (GOutputStream *stream,
351 GInputStream *source,
352 GOutputStreamSpliceFlags flags,
353 GCancellable *cancellable,
354 GError **error);
355 */
356
357 // Flush is a wrapper around g_output_stream_flush().
358 func (v *OutputStream) Flush(cancellable *Cancellable) (bool, error) {
359 var gerr *C.GError
360 ok := gobool(C.g_output_stream_flush(
361 v.native(),
362 cancellable.native(),
363 &gerr))
364 if !ok {
365 defer C.g_error_free(gerr)
366 return false, errors.New(goString(gerr.message))
367 }
368 return ok, nil
369 }
370
371 // Close is a wrapper around g_output_stream_close().
372 func (v *OutputStream) Close(cancellable *Cancellable) (bool, error) {
373 var gerr *C.GError
374 ok := gobool(C.g_output_stream_close(
375 v.native(),
376 cancellable.native(),
377 &gerr))
378 if !ok {
379 defer C.g_error_free(gerr)
380 return false, errors.New(goString(gerr.message))
381 }
382 return ok, nil
383 }
384
385 // TODO outputStream asynch functions
386 /*
387 void g_output_stream_write_async ()
388 gssize g_output_stream_write_finish ()
389 void g_output_stream_splice_async ()
390 gssize g_output_stream_splice_finish ()
391 void g_output_stream_flush_async ()
392 gboolean g_output_stream_flush_finish ()
393 void g_output_stream_close_async ()
394 gboolean g_output_stream_close_finish ()
395 */
396
397 // IsClosing is a wrapper around g_output_stream_is_closing().
398 func (v *OutputStream) IsClosing() bool {
399 return gobool(C.g_output_stream_is_closing(v.native()))
400 }
401
402 // IsClosed is a wrapper around g_output_stream_is_closed().
403 func (v *OutputStream) IsClosed() bool {
404 return gobool(C.g_output_stream_is_closed(v.native()))
405 }
406
407 // HasPending is a wrapper around g_output_stream_has_pending().
408 func (v *OutputStream) HasPending() bool {
409 return gobool(C.g_output_stream_has_pending(v.native()))
410 }
411
412 // SetPending is a wrapper around g_output_stream_set_pending().
413 func (v *OutputStream) SetPending() (bool, error) {
414 var gerr *C.GError
415 ok := gobool(C.g_output_stream_set_pending(
416 v.native(),
417 &gerr))
418 if !ok {
419 defer C.g_error_free(gerr)
420 return false, errors.New(goString(gerr.message))
421 }
422 return ok, nil
423 }
424
425 // ClearPending is a wrapper around g_output_stream_clear_pending().
426 func (v *OutputStream) ClearPending() {
427 C.g_output_stream_clear_pending(v.native())
428 }
429
430 /*
431 gssize g_output_stream_write_bytes ()
432 void g_output_stream_write_bytes_async ()
433 gssize g_output_stream_write_bytes_finish ()
434 gboolean g_output_stream_printf ()
435 gboolean g_output_stream_vprintf ()
436 */
0 #pragma once
1
2 #include <gio/gio.h>
3 #include <glib.h>
4 #include <stdint.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8
9 static GIOStream *toGIOStream(void *p) { return (G_IO_STREAM(p)); }
10
11 static GInputStream *toGInputStream(void *p) { return (G_INPUT_STREAM(p)); }
12
13 static GOutputStream *toGOutputStream(void *p) { return (G_OUTPUT_STREAM(p)); }
1313 // ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1414 // OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1515
16 // Package glib provides Go bindings for GLib 2. Supports version 2.36
17 // and later.
16 // Package glib provides Go bindings for GLib 2. It supports version 2.36 and
17 // later.
1818 package glib
1919
2020 // #cgo pkg-config: gio-2.0 glib-2.0 gobject-2.0
2121 // #include <gio/gio.h>
22 // #include <stdlib.h>
2223 // #include <glib.h>
2324 // #include <glib-object.h>
2425 // #include "glib.go.h"
2728 import (
2829 "errors"
2930 "fmt"
30 "os"
3131 "reflect"
3232 "runtime"
33 "sync"
3433 "unsafe"
34
35 "github.com/gotk3/gotk3/internal/callback"
36 "github.com/gotk3/gotk3/internal/closure"
3537 )
3638
3739 /*
4446 }
4547 return C.gboolean(0)
4648 }
49
4750 func gobool(b C.gboolean) bool {
4851 if b != 0 {
4952 return true
5558 * Unexported vars
5659 */
5760
58 type closureContext struct {
59 rf reflect.Value
60 userData reflect.Value
61 }
62
63 var (
64 errNilPtr = errors.New("cgo returned unexpected nil pointer")
65
66 closures = struct {
67 sync.RWMutex
68 m map[*C.GClosure]closureContext
69 }{
70 m: make(map[*C.GClosure]closureContext),
71 }
72
73 signals = make(map[SignalHandle]*C.GClosure)
74 )
61 var nilPtrErr = errors.New("cgo returned unexpected nil pointer")
7562
7663 /*
7764 * Constants
10592 TYPE_VARIANT Type = C.G_TYPE_VARIANT
10693 )
10794
95 // IsValue checks whether the passed in type can be used for g_value_init().
96 func (t Type) IsValue() bool {
97 return gobool(C._g_type_is_value(C.GType(t)))
98 }
99
108100 // Name is a wrapper around g_type_name().
109101 func (t Type) Name() string {
110102 return C.GoString((*C.char)(C.g_type_name(C.GType(t))))
119111 func (t Type) Parent() Type {
120112 return Type(C.g_type_parent(C.GType(t)))
121113 }
114
115 // IsA is a wrapper around g_type_is_a().
116 func (t Type) IsA(isAType Type) bool {
117 return gobool(C.g_type_is_a(C.GType(t), C.GType(isAType)))
118 }
119
120 // TypeFromName is a wrapper around g_type_from_name
121 func TypeFromName(typeName string) Type {
122 cstr := (*C.gchar)(C.CString(typeName))
123 defer C.free(unsafe.Pointer(cstr))
124 return Type(C.g_type_from_name(cstr))
125 }
126
127 //TypeNextBase is a wrapper around g_type_next_base
128 func TypeNextBase(leafType, rootType Type) Type {
129 return Type(C.g_type_next_base(C.GType(leafType), C.GType(rootType)))
130 }
131
132 // SettingsBindFlags is a representation of GLib's GSettingsBindFlags.
133 type SettingsBindFlags int
134
135 const (
136 SETTINGS_BIND_DEFAULT SettingsBindFlags = C.G_SETTINGS_BIND_DEFAULT
137 SETTINGS_BIND_GET SettingsBindFlags = C.G_SETTINGS_BIND_GET
138 SETTINGS_BIND_SET SettingsBindFlags = C.G_SETTINGS_BIND_SET
139 SETTINGS_BIND_NO_SENSITIVITY SettingsBindFlags = C.G_SETTINGS_BIND_NO_SENSITIVITY
140 SETTINGS_BIND_GET_NO_CHANGES SettingsBindFlags = C.G_SETTINGS_BIND_GET_NO_CHANGES
141 SETTINGS_BIND_INVERT_BOOLEAN SettingsBindFlags = C.G_SETTINGS_BIND_INVERT_BOOLEAN
142 )
122143
123144 // UserDirectory is a representation of GLib's GUserDirectory.
124145 type UserDirectory int
154175 // goMarshal is called by the GLib runtime when a closure needs to be invoked.
155176 // The closure will be invoked with as many arguments as it can take, from 0 to
156177 // the full amount provided by the call. If the closure asks for more parameters
157 // than there are to give, a warning is printed to stderr and the closure is
158 // not run.
178 // than there are to give, then a runtime panic will occur.
159179 //
160180 //export goMarshal
161 func goMarshal(closure *C.GClosure, retValue *C.GValue,
162 nParams C.guint, params *C.GValue,
163 invocationHint C.gpointer, marshalData *C.GValue) {
164
165 // Get the context associated with this callback closure.
166 closures.RLock()
167 cc := closures.m[closure]
168 closures.RUnlock()
169
170 // Get number of parameters passed in. If user data was saved with the
171 // closure context, increment the total number of parameters.
181 func goMarshal(
182 gclosure *C.GClosure,
183 retValue *C.GValue,
184 nParams C.guint,
185 params *C.GValue,
186 invocationHint C.gpointer,
187 marshalData *C.GValue) {
188
189 // Get the function value associated with this callback closure.
190 fs := closure.Get(unsafe.Pointer(gclosure))
191 if !fs.IsValid() {
192 // Possible data race, bail.
193 return
194 }
195
196 fsType := fs.Func.Type()
197
198 // Get number of parameters passed in.
172199 nGLibParams := int(nParams)
173200 nTotalParams := nGLibParams
174 if cc.userData.IsValid() {
175 nTotalParams++
176 }
177
178 // Get number of parameters from the callback closure. If this exceeds
179 // the total number of marshaled parameters, a warning will be printed
180 // to stderr, and the callback will not be run.
181 nCbParams := cc.rf.Type().NumIn()
201
202 // Reflect may panic, so we defer recover here to re-panic with our trace.
203 defer fs.TryRepanic()
204
205 // Get number of parameters from the callback closure. If this exceeds
206 // the total number of marshaled parameters, trigger a runtime panic.
207 nCbParams := fsType.NumIn()
182208 if nCbParams > nTotalParams {
183 fmt.Fprintf(os.Stderr,
184 "too many closure args: have %d, max allowed %d\n",
185 nCbParams, nTotalParams)
186 return
209 fs.Panicf("too many closure args: have %d, max %d", nCbParams, nTotalParams)
187210 }
188211
189212 // Create a slice of reflect.Values as arguments to call the function.
193216 // Fill beginning of args, up to the minimum of the total number of callback
194217 // parameters and parameters from the glib runtime.
195218 for i := 0; i < nCbParams && i < nGLibParams; i++ {
196 v := &Value{&gValues[i]}
219 v := Value{&gValues[i]}
220
197221 val, err := v.GoValue()
198222 if err != nil {
199 fmt.Fprintf(os.Stderr,
200 "no suitable Go value for arg %d: %v\n", i, err)
201 return
202 }
203 // Parameters that are descendants of GObject come wrapped in another GObject.
204 // For C applications, the default marshaller (g_cclosure_marshal_VOID__VOID in
205 // gmarshal.c in the GTK glib library) 'peeks' into the enclosing object and
206 // passes the wrapped object to the handler. Use the *Object.goValue function
207 // to emulate that for Go signal handlers.
223 fs.Panicf("no suitable Go value for arg %d: %v", i, err)
224 }
225
226 // Parameters that are descendants of GObject come wrapped in another
227 // GObject. For C applications, the default marshaller
228 // (g_cclosure_marshal_VOID__VOID in gmarshal.c in the GTK glib library)
229 // 'peeks' into the enclosing object and passes the wrapped object to
230 // the handler. Use the *Object.goValue function to emulate that for Go
231 // signal handlers.
208232 switch objVal := val.(type) {
209233 case *Object:
210 innerVal, err := objVal.goValue()
211 if err != nil {
212 // print warning and leave val unchanged to preserve old
213 // behavior
214 fmt.Fprintf(os.Stderr,
215 "warning: no suitable Go value from object for arg %d: %v\n", i, err)
216 } else {
234 if innerVal, err := objVal.goValue(); err == nil {
217235 val = innerVal
218236 }
219 }
220 rv := reflect.ValueOf(val)
221 args = append(args, rv.Convert(cc.rf.Type().In(i)))
222 }
223
224 // If non-nil user data was passed in and not all args have been set,
225 // get and set the reflect.Value directly from the GValue.
226 if cc.userData.IsValid() && len(args) < cap(args) {
227 args = append(args, cc.userData.Convert(cc.rf.Type().In(nCbParams-1)))
228 }
229
230 // Call closure with args. If the callback returns one or more
231 // values, save the GValue equivalent of the first.
232 rv := cc.rf.Call(args)
237
238 case *Variant:
239 switch ts := objVal.TypeString(); ts {
240 case "s":
241 val = objVal.GetString()
242 case "b":
243 val = gobool(C.g_variant_get_boolean(objVal.native()))
244 case "d":
245 val = float64(C.g_variant_get_double(objVal.native()))
246 case "n":
247 val = int16(C.g_variant_get_int16(objVal.native()))
248 case "i":
249 val = int32(C.g_variant_get_int32(objVal.native()))
250 case "x":
251 val = int64(C.g_variant_get_int64(objVal.native()))
252 case "y":
253 val = uint8(C.g_variant_get_byte(objVal.native()))
254 case "q":
255 val = uint16(C.g_variant_get_uint16(objVal.native()))
256 case "u":
257 val = uint32(C.g_variant_get_uint32(objVal.native()))
258 case "t":
259 val = uint64(C.g_variant_get_uint64(objVal.native()))
260 default:
261 fs.Panicf("variant conversion not yet implemented for type %s", ts)
262 }
263 }
264
265 args = append(args, reflect.ValueOf(val).Convert(fsType.In(i)))
266 }
267
268 // Call closure with args. If the callback returns one or more values, save
269 // the GValue equivalent of the first.
270 rv := fs.Func.Call(args)
233271 if retValue != nil && len(rv) > 0 {
234 if g, err := GValue(rv[0].Interface()); err != nil {
235 fmt.Fprintf(os.Stderr,
236 "cannot save callback return value: %v", err)
237 } else {
238 *retValue = *g.native()
239 }
272 g, err := GValue(rv[0].Interface())
273 if err != nil {
274 fs.Panicf("cannot save callback return value: %v", err)
275 }
276
277 t, _, err := g.Type()
278 if err != nil {
279 fs.Panicf("cannot determine callback return value: %v", err)
280 }
281
282 // Explicitly copy the return value as it may point to go-owned memory.
283 C.g_value_unset(retValue)
284 C.g_value_init(retValue, C.GType(t))
285 C.g_value_copy(g.native(), retValue)
240286 }
241287 }
242288
253299 * Main event loop
254300 */
255301
302 // Priority is the enumerated type for GLib priority event sources.
303 type Priority int
304
305 const (
306 PRIORITY_HIGH Priority = C.G_PRIORITY_HIGH
307 PRIORITY_DEFAULT Priority = C.G_PRIORITY_DEFAULT // TimeoutAdd
308 PRIORITY_HIGH_IDLE Priority = C.G_PRIORITY_HIGH_IDLE
309 PRIORITY_DEFAULT_IDLE Priority = C.G_PRIORITY_DEFAULT_IDLE // IdleAdd
310 PRIORITY_LOW Priority = C.G_PRIORITY_LOW
311 )
312
256313 type SourceHandle uint
257314
258 // IdleAdd adds an idle source to the default main event loop
259 // context. After running once, the source func will be removed
260 // from the main event loop, unless f returns a single bool true.
315 // sourceFunc is the callback for g_idle_add_full and g_timeout_add_full that
316 // replaces the GClosure API.
261317 //
262 // This function will cause a panic when f eventually runs if the
263 // types of args do not match those of f.
264 func IdleAdd(f interface{}, args ...interface{}) (SourceHandle, error) {
265 // f must be a func with no parameters.
266 rf := reflect.ValueOf(f)
267 if rf.Type().Kind() != reflect.Func {
268 return 0, errors.New("f is not a function")
269 }
270
271 // Create an idle source func to be added to the main loop context.
272 idleSrc := C.g_idle_source_new()
273 if idleSrc == nil {
274 return 0, errNilPtr
275 }
276 return sourceAttach(idleSrc, rf, args...)
277 }
278
279 // TimeoutAdd adds an timeout source to the default main event loop
280 // context. After running once, the source func will be removed
281 // from the main event loop, unless f returns a single bool true.
318 //export sourceFunc
319 func sourceFunc(data C.gpointer) C.gboolean {
320 v := callback.Get(uintptr(data))
321 fs := v.(closure.FuncStack)
322
323 rv := fs.Func.Call(nil)
324 if len(rv) == 1 && rv[0].Bool() {
325 return C.TRUE
326 }
327
328 return C.FALSE
329 }
330
331 //export removeSourceFunc
332 func removeSourceFunc(data C.gpointer) {
333 callback.Delete(uintptr(data))
334 }
335
336 var (
337 _sourceFunc = (*[0]byte)(C.sourceFunc)
338 _removeSourceFunc = (*[0]byte)(C.removeSourceFunc)
339 )
340
341 // IdleAdd adds an idle source to the default main event loop context with the
342 // DefaultIdle priority. If f is not a function with no parameter, then IdleAdd
343 // will panic.
282344 //
283 // This function will cause a panic when f eventually runs if the
284 // types of args do not match those of f.
285 // timeout is in milliseconds
286 func TimeoutAdd(timeout uint, f interface{}, args ...interface{}) (SourceHandle, error) {
287 // f must be a func with no parameters.
288 rf := reflect.ValueOf(f)
289 if rf.Type().Kind() != reflect.Func {
290 return 0, errors.New("f is not a function")
291 }
292
293 // Create a timeout source func to be added to the main loop context.
294 timeoutSrc := C.g_timeout_source_new(C.guint(timeout))
295 if timeoutSrc == nil {
296 return 0, errNilPtr
297 }
298
299 return sourceAttach(timeoutSrc, rf, args...)
300 }
301
302 // sourceAttach attaches a source to the default main loop context.
303 func sourceAttach(src *C.struct__GSource, rf reflect.Value, args ...interface{}) (SourceHandle, error) {
304 if src == nil {
305 return 0, errNilPtr
306 }
307
308 // rf must be a func with no parameters.
309 if rf.Type().Kind() != reflect.Func {
310 C.g_source_destroy(src)
311 return 0, errors.New("rf is not a function")
312 }
313
314 // Create a new GClosure from f that invalidates itself when
315 // f returns false. The error is ignored here, as this will
316 // always be a function.
317 var closure *C.GClosure
318 closure, _ = ClosureNew(rf.Interface(), args...)
319
320 // Remove closure context when closure is finalized.
321 C._g_closure_add_finalize_notifier(closure)
322
323 // Set closure to run as a callback when the idle source runs.
324 C.g_source_set_closure(src, closure)
325
326 // Attach the idle source func to the default main event loop
327 // context.
328 cid := C.g_source_attach(src, nil)
329 return SourceHandle(cid), nil
345 // After running once, the source func will be removed from the main event loop,
346 // unless f returns a single bool true.
347 func IdleAdd(f interface{}) SourceHandle {
348 return idleAdd(PRIORITY_DEFAULT_IDLE, f)
349 }
350
351 // IdleAddPriority adds an idle source to the default main event loop context
352 // with the given priority. Its behavior is the same as IdleAdd.
353 func IdleAddPriority(priority Priority, f interface{}) SourceHandle {
354 return idleAdd(priority, f)
355 }
356
357 func idleAdd(priority Priority, f interface{}) SourceHandle {
358 fs := closure.NewIdleFuncStack(f, 2)
359 id := C.gpointer(callback.Assign(fs))
360 h := C.g_idle_add_full(C.gint(priority), _sourceFunc, id, _removeSourceFunc)
361
362 return SourceHandle(h)
363 }
364
365 // TimeoutAdd adds an timeout source to the default main event loop context.
366 // Timeout is in milliseconds. If f is not a function with no parameter, then it
367 // will panic.
368 //
369 // After running once, the source func will be removed from the main event loop,
370 // unless f returns a single bool true.
371 func TimeoutAdd(milliseconds uint, f interface{}) SourceHandle {
372 return timeoutAdd(milliseconds, false, PRIORITY_DEFAULT, f)
373 }
374
375 // TimeoutAddPriority is similar to TimeoutAdd with the given priority. Refer to
376 // TimeoutAdd for more information.
377 func TimeoutAddPriority(milliseconds uint, priority Priority, f interface{}) SourceHandle {
378 return timeoutAdd(milliseconds, false, priority, f)
379 }
380
381 // TimeoutSecondsAdd is similar to TimeoutAdd, except with seconds granularity.
382 func TimeoutSecondsAdd(seconds uint, f interface{}) SourceHandle {
383 return timeoutAdd(seconds, true, PRIORITY_DEFAULT, f)
384 }
385
386 // TimeoutSecondsAddPriority adds a timeout source with the given priority.
387 // Refer to TimeoutSecondsAdd for more information.
388 func TimeoutSecondsAddPriority(seconds uint, priority Priority, f interface{}) SourceHandle {
389 return timeoutAdd(seconds, true, priority, f)
390 }
391
392 func timeoutAdd(time uint, sec bool, priority Priority, f interface{}) SourceHandle {
393 fs := closure.NewIdleFuncStack(f, 2)
394 id := C.gpointer(callback.Assign(fs))
395
396 var h C.guint
397 if sec {
398 h = C.g_timeout_add_seconds_full(C.gint(priority), C.guint(time), _sourceFunc, id, _removeSourceFunc)
399 } else {
400 h = C.g_timeout_add_full(C.gint(priority), C.guint(time), _sourceFunc, id, _removeSourceFunc)
401 }
402
403 return SourceHandle(h)
330404 }
331405
332406 // Destroy is a wrapper around g_source_destroy()
398472 func GetUserSpecialDir(directory UserDirectory) (string, error) {
399473 c := C.g_get_user_special_dir(C.GUserDirectory(directory))
400474 if c == nil {
401 return "", errNilPtr
475 return "", nilPtrErr
402476 }
403477 return C.GoString((*C.char)(c)), nil
478 }
479
480 // FormatSize is a wrapper around g_format_size().
481 func FormatSize(size uint64) string {
482 char := C.g_format_size(C.guint64(size))
483 defer C.free(unsafe.Pointer(char))
484
485 return C.GoString(char)
486 }
487
488 // FormatSizeFlags are flags to modify the format of the string returned by
489 // FormatSizeFull.
490 type FormatSizeFlags int
491
492 const (
493 FORMAT_SIZE_DEFAULT FormatSizeFlags = C.G_FORMAT_SIZE_DEFAULT
494 FORMAT_SIZE_LONG_FORMAT FormatSizeFlags = C.G_FORMAT_SIZE_LONG_FORMAT
495 FORMAT_SIZE_IEC_UNITS FormatSizeFlags = C.G_FORMAT_SIZE_IEC_UNITS
496 FORMAT_SIZE_BITS FormatSizeFlags = C.G_FORMAT_SIZE_BITS
497 )
498
499 // FormatSizeFull is a wrapper around g_format_size_full().
500 func FormatSizeFull(size uint64, flags FormatSizeFlags) string {
501 char := C.g_format_size_full(C.guint64(size), C.GFormatSizeFlags(flags))
502 defer C.free(unsafe.Pointer(char))
503
504 return C.GoString(char)
505 }
506
507 // SpacedPrimesClosest is a wrapper around g_spaced_primes_closest().
508 func SpacedPrimesClosest(num uint) uint {
509 return uint(C.g_spaced_primes_closest(C.guint(num)))
404510 }
405511
406512 /*
408514 */
409515
410516 // IObject is an interface type implemented by Object and all types which embed
411 // an Object. It is meant to be used as a type for function arguments which
517 // an Object. It is meant to be used as a type for function arguments which
412518 // require GObjects or any subclasses thereof.
413519 type IObject interface {
414520 toGObject() *C.GObject
433539
434540 // newObject creates a new Object from a GObject pointer.
435541 func newObject(p *C.GObject) *Object {
542 if p == nil {
543 return nil
544 }
436545 return &Object{GObject: p}
437546 }
438547
468577 // Take wraps a unsafe.Pointer as a glib.Object, taking ownership of it.
469578 // This function is exported for visibility in other gotk3 packages and
470579 // is not meant to be used by applications.
580 //
581 // To be clear, this should mostly be used when Gtk says "transfer none". Refer
582 // to AssumeOwnership for more details.
471583 func Take(ptr unsafe.Pointer) *Object {
472584 obj := newObject(ToGObject(ptr))
473
474 if obj.IsFloating() {
475 obj.RefSink()
476 } else {
477 obj.Ref()
478 }
479
585 if obj == nil {
586 return nil
587 }
588
589 obj.RefSink()
590 runtime.SetFinalizer(obj, (*Object).Unref)
591 return obj
592 }
593
594 // AssumeOwnership is similar to Take, except the function does not take a
595 // reference. This is usually used for newly constructed objects that for some
596 // reason does not have an initial floating reference.
597 //
598 // To be clear, this should often be used when Gtk says "transfer full", as it
599 // means the ownership is transferred to the caller, so we can assume that much.
600 // This is in contrary to Take, which is used when Gtk says "transfer none", as
601 // we're now referencing an object that might possibly be kept, so we should
602 // mark as such.
603 func AssumeOwnership(ptr unsafe.Pointer) *Object {
604 obj := newObject(ToGObject(ptr))
480605 runtime.SetFinalizer(obj, (*Object).Unref)
481606 return obj
482607 }
501626 // This function is exported for visibility in other gotk3 packages and
502627 // is not meant to be used by applications.
503628 func ToGObject(p unsafe.Pointer) *C.GObject {
504 return C.toGObject(p)
629 return (*C.GObject)(p)
630 // return C.toGObject(p)
505631 }
506632
507633 // Ref is a wrapper around g_object_ref().
538664 (*C.gchar)(cstr))
539665 }
540666
541 // Set is a wrapper around g_object_set(). However, unlike
542 // g_object_set(), this function only sets one name value pair. Make
543 // multiple calls to this function to set multiple properties.
667 // Set calls SetProperty.
544668 func (v *Object) Set(name string, value interface{}) error {
545669 return v.SetProperty(name, value)
546 /*
547 cstr := C.CString(name)
548 defer C.free(unsafe.Pointer(cstr))
549
550 if _, ok := value.(Object); ok {
551 value = value.(Object).GObject
552 }
553
554 // Can't call g_object_set() as it uses a variable arg list, use a
555 // wrapper instead
556 var p unsafe.Pointer
557 switch v := value.(type) {
558 case bool:
559 c := gbool(v)
560 p = unsafe.Pointer(&c)
561
562 case int8:
563 c := C.gint8(v)
564 p = unsafe.Pointer(&c)
565
566 case int16:
567 c := C.gint16(v)
568 p = unsafe.Pointer(&c)
569
570 case int32:
571 c := C.gint32(v)
572 p = unsafe.Pointer(&c)
573
574 case int64:
575 c := C.gint64(v)
576 p = unsafe.Pointer(&c)
577
578 case int:
579 c := C.gint(v)
580 p = unsafe.Pointer(&c)
581
582 case uint8:
583 c := C.guchar(v)
584 p = unsafe.Pointer(&c)
585
586 case uint16:
587 c := C.guint16(v)
588 p = unsafe.Pointer(&c)
589
590 case uint32:
591 c := C.guint32(v)
592 p = unsafe.Pointer(&c)
593
594 case uint64:
595 c := C.guint64(v)
596 p = unsafe.Pointer(&c)
597
598 case uint:
599 c := C.guint(v)
600 p = unsafe.Pointer(&c)
601
602 case uintptr:
603 p = unsafe.Pointer(C.gpointer(v))
604
605 case float32:
606 c := C.gfloat(v)
607 p = unsafe.Pointer(&c)
608
609 case float64:
610 c := C.gdouble(v)
611 p = unsafe.Pointer(&c)
612
613 case string:
614 cstr := C.CString(v)
615 defer C.g_free(C.gpointer(unsafe.Pointer(cstr)))
616 p = unsafe.Pointer(&cstr)
617
618 default:
619 if pv, ok := value.(unsafe.Pointer); ok {
620 p = pv
621 } else {
622 val := reflect.ValueOf(value)
623 switch val.Kind() {
624 case reflect.Int, reflect.Int8, reflect.Int16,
625 reflect.Int32, reflect.Int64:
626 c := C.int(val.Int())
627 p = unsafe.Pointer(&c)
628
629 case reflect.Uintptr, reflect.Ptr, reflect.UnsafePointer:
630 p = unsafe.Pointer(C.gpointer(val.Pointer()))
631 }
632 }
633 }
634 if p == nil {
635 return errors.New("Unable to perform type conversion")
636 }
637 C._g_object_set_one(C.gpointer(v.GObject), (*C.gchar)(cstr), p)
638 return nil*/
639670 }
640671
641672 // GetPropertyType returns the Type of a property of the underlying GObject.
685716 C.g_object_set_property(v.GObject, (*C.gchar)(cstr), p.native())
686717 return nil
687718 }
688
689 // pointerVal attempts to return an unsafe.Pointer for value.
690 // Not all types are understood, in which case a nil Pointer
691 // is returned.
692 /*func pointerVal(value interface{}) unsafe.Pointer {
693 var p unsafe.Pointer
694 switch v := value.(type) {
695 case bool:
696 c := gbool(v)
697 p = unsafe.Pointer(&c)
698
699 case int8:
700 c := C.gint8(v)
701 p = unsafe.Pointer(&c)
702
703 case int16:
704 c := C.gint16(v)
705 p = unsafe.Pointer(&c)
706
707 case int32:
708 c := C.gint32(v)
709 p = unsafe.Pointer(&c)
710
711 case int64:
712 c := C.gint64(v)
713 p = unsafe.Pointer(&c)
714
715 case int:
716 c := C.gint(v)
717 p = unsafe.Pointer(&c)
718
719 case uint8:
720 c := C.guchar(v)
721 p = unsafe.Pointer(&c)
722
723 case uint16:
724 c := C.guint16(v)
725 p = unsafe.Pointer(&c)
726
727 case uint32:
728 c := C.guint32(v)
729 p = unsafe.Pointer(&c)
730
731 case uint64:
732 c := C.guint64(v)
733 p = unsafe.Pointer(&c)
734
735 case uint:
736 c := C.guint(v)
737 p = unsafe.Pointer(&c)
738
739 case uintptr:
740 p = unsafe.Pointer(C.gpointer(v))
741
742 case float32:
743 c := C.gfloat(v)
744 p = unsafe.Pointer(&c)
745
746 case float64:
747 c := C.gdouble(v)
748 p = unsafe.Pointer(&c)
749
750 case string:
751 cstr := C.CString(v)
752 defer C.free(unsafe.Pointer(cstr))
753 p = unsafe.Pointer(cstr)
754
755 default:
756 if pv, ok := value.(unsafe.Pointer); ok {
757 p = pv
758 } else {
759 val := reflect.ValueOf(value)
760 switch val.Kind() {
761 case reflect.Int, reflect.Int8, reflect.Int16,
762 reflect.Int32, reflect.Int64:
763 c := C.int(val.Int())
764 p = unsafe.Pointer(&c)
765
766 case reflect.Uintptr, reflect.Ptr, reflect.UnsafePointer:
767 p = unsafe.Pointer(C.gpointer(val.Pointer()))
768 }
769 }
770 }
771
772 return p
773 }*/
774719
775720 /*
776721 * GObject Signals
831776
832777 // HandlerDisconnect is a wrapper around g_signal_handler_disconnect().
833778 func (v *Object) HandlerDisconnect(handle SignalHandle) {
779 // Ensure that Gtk will not use the closure beforehand.
834780 C.g_signal_handler_disconnect(C.gpointer(v.GObject), C.gulong(handle))
835 C.g_closure_invalidate(signals[handle])
836 delete(closures.m, signals[handle])
837 delete(signals, handle)
781 closure.DisconnectSignal(uint(handle))
838782 }
839783
840784 // Wrapper function for new objects with reference management.
841785 func wrapObject(ptr unsafe.Pointer) *Object {
842 obj := &Object{ToGObject(ptr)}
843
844 if obj.IsFloating() {
845 obj.RefSink()
846 } else {
847 obj.Ref()
848 }
849
850 runtime.SetFinalizer(obj, (*Object).Unref)
851 return obj
786 return Take(ptr)
852787 }
853788
854789 /*
893828 }
894829
895830 // Native returns a pointer to the underlying GValue.
896 func (v *Value) Native() unsafe.Pointer {
897 return unsafe.Pointer(v.native())
831 func (v *Value) Native() uintptr {
832 return uintptr(unsafe.Pointer(v.native()))
833 }
834
835 // IsValue checks if value is a valid and initialized GValue structure.
836 func (v *Value) IsValue() bool {
837 return gobool(C._g_is_value(v.native()))
838 }
839
840 // TypeName gets the type name of value.
841 func (v *Value) TypeName() string {
842 return C.GoString((*C.char)(C._g_value_type_name(v.native())))
898843 }
899844
900845 // ValueAlloc allocates a Value and sets a runtime finalizer to call
903848 func ValueAlloc() (*Value, error) {
904849 c := C._g_value_alloc()
905850 if c == nil {
906 return nil, errNilPtr
851 return nil, nilPtrErr
907852 }
908853
909854 v := &Value{c}
912857 //We need to double check before unsetting, to prevent:
913858 //`g_value_unset: assertion 'G_IS_VALUE (value)' failed`
914859 runtime.SetFinalizer(v, func(f *Value) {
915 if t, _, err := f.Type(); err != nil || t == TYPE_INVALID || t == TYPE_NONE {
860
861 if !f.IsValue() {
916862 C.g_free(C.gpointer(f.native()))
917863 return
918864 }
930876 func ValueInit(t Type) (*Value, error) {
931877 c := C._g_value_init(C.GType(t))
932878 if c == nil {
933 return nil, errNilPtr
879 return nil, nilPtrErr
934880 }
935881
936882 v := &Value{c}
949895 C.g_value_unset(v.native())
950896 }
951897
898 // Unset is wrapper for g_value_unset
899 func (v *Value) Unset() {
900 v.unset()
901 }
902
952903 // Type is a wrapper around the G_VALUE_HOLDS_GTYPE() macro and
953904 // the g_value_get_gtype() function. GetType() returns TYPE_INVALID if v
954905 // does not hold a Type, or otherwise returns the Type of v.
955906 func (v *Value) Type() (actual Type, fundamental Type, err error) {
956 if !gobool(C._g_is_value(v.native())) {
907 if !v.IsValue() {
957908 return actual, fundamental, errors.New("invalid GValue")
958909 }
959910 cActual := C._g_value_type(v.native())
11201071 }
11211072
11221073 // RegisterGValueMarshalers adds marshalers for several types to the
1123 // internal marshalers map. Once registered, calling GoValue on any
1124 // Value witha registered type will return the data returned by the
1074 // internal marshalers map. Once registered, calling GoValue on any
1075 // Value with a registered type will return the data returned by the
11251076 // marshaler.
11261077 func RegisterGValueMarshalers(tm []TypeMarshaler) {
11271078 gValueMarshalers.register(tm)
12811232 }
12821233
12831234 func marshalVariant(p uintptr) (interface{}, error) {
1284 return nil, errors.New("variant conversion not yet implemented")
1235 c := C.g_value_get_variant((*C.GValue)(unsafe.Pointer(p)))
1236 return newVariant((*C.GVariant)(c)), nil
12851237 }
12861238
12871239 // GoValue converts a Value to comparable Go type. GoValue()
13761328 func (v *Value) GetString() (string, error) {
13771329 c := C.g_value_get_string(v.native())
13781330 if c == nil {
1379 return "", errNilPtr
1331 return "", nilPtrErr
13801332 }
13811333 return C.GoString((*C.char)(c)), nil
13821334 }
14081360
14091361 type Quark uint32
14101362
1363 // GetPrgname is a wrapper around g_get_prgname().
1364 func GetPrgname() string {
1365 c := C.g_get_prgname()
1366
1367 return C.GoString((*C.char)(c))
1368 }
1369
1370 // SetPrgname is a wrapper around g_set_prgname().
1371 func SetPrgname(name string) {
1372 cstr := (*C.gchar)(C.CString(name))
1373 defer C.free(unsafe.Pointer(cstr))
1374
1375 C.g_set_prgname(cstr)
1376 }
1377
14111378 // GetApplicationName is a wrapper around g_get_application_name().
14121379 func GetApplicationName() string {
14131380 c := C.g_get_application_name()
1919 #define __GLIB_GO_H__
2020
2121 #include <stdint.h>
22 #include <stdio.h>
2223 #include <stdlib.h>
23 #include <stdio.h>
2424
2525 #include <gio/gio.h>
2626 #define G_SETTINGS_ENABLE_BACKEND
2727 #include <gio/gsettingsbackend.h>
28 #include <glib-object.h>
2829 #include <glib.h>
29 #include <glib-object.h>
3030 #include <glib/gi18n.h>
3131 #include <locale.h>
3232
3333 /* GObject Type Casting */
34 static GObject *
35 toGObject(void *p)
36 {
37 return (G_OBJECT(p));
34 static GObject *toGObject(void *p) { return (G_OBJECT(p)); }
35
36 static GAction *toGAction(void *p) { return (G_ACTION(p)); }
37
38 static GActionGroup *toGActionGroup(void *p) { return (G_ACTION_GROUP(p)); }
39
40 static GActionMap *toGActionMap(void *p) { return (G_ACTION_MAP(p)); }
41
42 static GAsyncResult *toGAsyncResult(void *p) { return (G_ASYNC_RESULT(p)); }
43
44 static GSimpleAction *toGSimpleAction(void *p) { return (G_SIMPLE_ACTION(p)); }
45
46 static GSimpleActionGroup *toGSimpleActionGroup(void *p) {
47 return (G_SIMPLE_ACTION_GROUP(p));
3848 }
3949
40 static GAction *
41 toGAction(void *p)
42 {
43 return (G_ACTION(p));
50 static GPropertyAction *toGPropertyAction(void *p) {
51 return (G_PROPERTY_ACTION(p));
4452 }
4553
46 static GActionGroup *
47 toGActionGroup(void *p)
48 {
49 return (G_ACTION_GROUP(p));
54 static GMenuModel *toGMenuModel(void *p) { return (G_MENU_MODEL(p)); }
55
56 static GMenu *toGMenu(void *p) { return (G_MENU(p)); }
57
58 static GMenuItem *toGMenuItem(void *p) { return (G_MENU_ITEM(p)); }
59
60 static GNotification *toGNotification(void *p) { return (G_NOTIFICATION(p)); }
61
62 static GPermission *toGPermission(void *p) { return (G_PERMISSION(p)); }
63
64 static GCancellable *toCancellable(void *p) { return (G_CANCELLABLE(p)); }
65
66 static GIcon *toGIcon(void *p) { return (G_ICON(p)); }
67 static GFileIcon *toGFileIcon(void *p) { return (G_FILE_ICON(p)); }
68
69 static GFile *toGFile(void *p) { return (G_FILE(p)); }
70
71 static GApplication *toGApplication(void *p) { return (G_APPLICATION(p)); }
72
73 static GSettings *toGSettings(void *p) { return (G_SETTINGS(p)); }
74
75 static GSettingsBackend *toGSettingsBackend(void *p) {
76 return (G_SETTINGS_BACKEND(p));
5077 }
5178
52 static GActionMap *
53 toGActionMap(void *p)
54 {
55 return (G_ACTION_MAP(p));
56 }
79 static GBinding *toGBinding(void *p) { return (G_BINDING(p)); }
5780
58 static GSimpleAction *
59 toGSimpleAction(void *p)
60 {
61 return (G_SIMPLE_ACTION(p));
62 }
63
64 static GSimpleActionGroup *
65 toGSimpleActionGroup(void *p)
66 {
67 return (G_SIMPLE_ACTION_GROUP(p));
68 }
69
70 static GPropertyAction *
71 toGPropertyAction(void *p)
72 {
73 return (G_PROPERTY_ACTION(p));
74 }
75
76 static GMenuModel *
77 toGMenuModel(void *p)
78 {
79 return (G_MENU_MODEL(p));
80 }
81
82 static GMenu *
83 toGMenu(void *p)
84 {
85 return (G_MENU(p));
86 }
87
88 static GMenuItem *
89 toGMenuItem(void *p)
90 {
91 return (G_MENU_ITEM(p));
92 }
93
94 static GNotification *
95 toGNotification(void *p)
96 {
97 return (G_NOTIFICATION(p));
98 }
99
100 static GApplication *
101 toGApplication(void *p)
102 {
103 return (G_APPLICATION(p));
104 }
105
106 static GSettings *
107 toGSettings(void *p)
108 {
109 return (G_SETTINGS(p));
110 }
111
112 static GSettingsBackend *
113 toGSettingsBackend(void *p)
114 {
115 return (G_SETTINGS_BACKEND(p));
116 }
117
118 static GBinding*
119 toGBinding(void *p)
120 {
121 return (G_BINDING(p));
122 }
123
124 static GType
125 _g_type_from_instance(gpointer instance)
126 {
127 return (G_TYPE_FROM_INSTANCE(instance));
81 static GType _g_type_from_instance(gpointer instance) {
82 return (G_TYPE_FROM_INSTANCE(instance));
12883 }
12984
13085 /* Wrapper to avoid variable arg list */
131 static void
132 _g_object_set_one(gpointer object, const gchar *property_name, void *val)
133 {
134 g_object_set(object, property_name, *(gpointer **)val, NULL);
86 static void _g_object_set_one(gpointer object, const gchar *property_name,
87 void *val) {
88 g_object_set(object, property_name, *(gpointer **)val, NULL);
13589 }
13690
137 static GValue *
138 alloc_gvalue_list(int n)
139 {
140 GValue *valv;
91 static GValue *alloc_gvalue_list(int n) {
92 GValue *valv;
14193
142 valv = g_new0(GValue, n);
143 return (valv);
94 valv = g_new0(GValue, n);
95 return (valv);
14496 }
14597
146 static void
147 val_list_insert(GValue *valv, int i, GValue *val)
148 {
149 valv[i] = *val;
98 static void val_list_insert(GValue *valv, int i, GValue *val) {
99 valv[i] = *val;
150100 }
151101
152102 /*
153103 * GValue
154104 */
155105
156 static GValue *
157 _g_value_alloc()
158 {
159 return (g_new0(GValue, 1));
106 static GValue *_g_value_alloc() { return (g_new0(GValue, 1)); }
107
108 static GValue *_g_value_init(GType g_type) {
109 GValue *value;
110
111 value = g_new0(GValue, 1);
112 return (g_value_init(value, g_type));
160113 }
161114
162 static GValue *
163 _g_value_init(GType g_type)
164 {
165 GValue *value;
166
167 value = g_new0(GValue, 1);
168 return (g_value_init(value, g_type));
115 static gboolean _g_type_is_value(GType g_type) {
116 return (G_TYPE_IS_VALUE(g_type));
169117 }
170118
171 static gboolean
172 _g_is_value(GValue *val)
173 {
174 return (G_IS_VALUE(val));
119 static gboolean _g_is_value(GValue *val) { return (G_IS_VALUE(val)); }
120
121 static GType _g_value_type(GValue *val) { return (G_VALUE_TYPE(val)); }
122
123 static const gchar *_g_value_type_name(GValue *val) {
124 return (G_VALUE_TYPE_NAME(val));
175125 }
176126
177 static GType
178 _g_value_type(GValue *val)
179 {
180 return (G_VALUE_TYPE(val));
127 static GType _g_value_fundamental(GType type) {
128 return (G_TYPE_FUNDAMENTAL(type));
181129 }
182130
183 static GType
184 _g_value_fundamental(GType type)
185 {
186 return (G_TYPE_FUNDAMENTAL(type));
187 }
188
189 static GObjectClass *
190 _g_object_get_class (GObject *object)
191 {
192 return (G_OBJECT_GET_CLASS(object));
131 static GObjectClass *_g_object_get_class(GObject *object) {
132 return (G_OBJECT_GET_CLASS(object));
193133 }
194134
195135 /*
196136 * Closure support
197137 */
198138
199 extern void goMarshal(GClosure *, GValue *, guint, GValue *, gpointer, GValue *);
139 extern void removeSourceFunc(gpointer data);
140 extern gboolean sourceFunc(gpointer data);
200141
201 static GClosure *
202 _g_closure_new()
203 {
204 GClosure *closure;
142 extern void goMarshal(GClosure *, GValue *, guint, GValue *, gpointer,
143 GValue *);
144 extern void removeClosure(gpointer, GClosure *);
205145
206 closure = g_closure_new_simple(sizeof(GClosure), NULL);
207 g_closure_set_marshal(closure, (GClosureMarshal)(goMarshal));
208 return (closure);
209 }
146 static inline GClosure *_g_closure_new() {
147 GClosure *closure;
210148
211 extern void removeClosure(gpointer, GClosure *);
212
213 static void
214 _g_closure_add_finalize_notifier(GClosure *closure)
215 {
216 g_closure_add_finalize_notifier(closure, NULL, removeClosure);
149 closure = g_closure_new_simple(sizeof(GClosure), NULL);
150 g_closure_set_marshal(closure, (GClosureMarshal)(goMarshal));
151 g_closure_add_finalize_notifier(closure, NULL,
152 (GClosureNotify)(removeClosure));
153 return closure;
217154 }
218155
219156 static inline guint _g_signal_new(const gchar *name) {
220 return g_signal_new(name,
221 G_TYPE_OBJECT,
222 G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
223 0, NULL, NULL,
224 g_cclosure_marshal_VOID__POINTER,
225 G_TYPE_NONE,
226 0);
157 return g_signal_new(name, G_TYPE_OBJECT, G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
158 0, NULL, NULL, g_cclosure_marshal_VOID__POINTER,
159 G_TYPE_NONE, 0);
227160 }
228161
229162 static void init_i18n(const char *domain, const char *dir) {
233166 textdomain(domain);
234167 }
235168
236 static const char* localize(const char *string) {
237 return _(string);
169 static const char *localize(const char *string) { return _(string); }
170
171 static inline char **make_strings(int count) {
172 return (char **)malloc(sizeof(char *) * count);
238173 }
239174
240 static inline char** make_strings(int count) {
241 return (char**)malloc(sizeof(char*) * count);
175 static inline void destroy_strings(char **strings) { free(strings); }
176
177 static inline char *get_string(char **strings, int n) { return strings[n]; }
178
179 static inline void set_string(char **strings, int n, char *str) {
180 strings[n] = str;
242181 }
243182
244 static inline void destroy_strings(char** strings) {
245 free(strings);
246 }
183 static inline gchar **next_gcharptr(gchar **s) { return (s + 1); }
247184
248 static inline char* get_string(char** strings, int n) {
249 return strings[n];
250 }
251
252 static inline void set_string(char** strings, int n, char* str) {
253 strings[n] = str;
254 }
255
256 static inline gchar** next_gcharptr(gchar** s) { return (s+1); }
185 extern gint goCompareDataFuncs(gconstpointer a, gconstpointer b,
186 gpointer user_data);
257187
258188 #endif
0 package glib
1
2 // #cgo pkg-config: gio-2.0
3 // #include <gio/gio.h>
4 import "C"
5 import (
6 "unsafe"
7
8 "github.com/gotk3/gotk3/internal/callback"
9 )
10
11 //export goAsyncReadyCallbacks
12 func goAsyncReadyCallbacks(sourceObject *C.GObject, res *C.GAsyncResult, userData C.gpointer) {
13 var source *Object
14 if sourceObject != nil {
15 source = wrapObject(unsafe.Pointer(sourceObject))
16 }
17
18 fn := callback.Get(uintptr(userData)).(AsyncReadyCallback)
19 fn(source, wrapAsyncResult(wrapObject(unsafe.Pointer(res))))
20 }
21
22 //export goCompareDataFuncs
23 func goCompareDataFuncs(a, b C.gconstpointer, userData C.gpointer) C.gint {
24 fn := callback.Get(uintptr(userData)).(CompareDataFunc)
25 return C.gint(fn(uintptr(a), uintptr(b)))
26 }
0 // Same copyright and license as the rest of the files in this project
1
2 // +build !glib_2_40
3
4 package glib
5
6 // #include <gio/gio.h>
7 // #include <glib.h>
8 // #include <glib-object.h>
9 // #include "glib.go.h"
10 import "C"
11 import "unsafe"
12
13 /*
14 * Notification
15 */
16
17 // NotificationPriority is a representation of GLib's GNotificationPriority.
18 type NotificationPriority int
19
20 const (
21 NOTIFICATION_PRIORITY_NORMAL NotificationPriority = C.G_NOTIFICATION_PRIORITY_NORMAL
22 NOTIFICATION_PRIORITY_LOW NotificationPriority = C.G_NOTIFICATION_PRIORITY_LOW
23 NOTIFICATION_PRIORITY_HIGH NotificationPriority = C.G_NOTIFICATION_PRIORITY_HIGH
24 NOTIFICATION_PRIORITY_URGENT NotificationPriority = C.G_NOTIFICATION_PRIORITY_URGENT
25 )
26
27 // SetPriority is a wrapper around g_notification_set_priority().
28 func (v *Notification) SetPriority(prio NotificationPriority) {
29 C.g_notification_set_priority(v.native(), C.GNotificationPriority(prio))
30 }
31
32 /*
33 * Application
34 */
35
36 // GetResourceBasePath is a wrapper around g_application_get_resource_base_path().
37 func (v *Application) GetResourceBasePath() string {
38 c := C.g_application_get_resource_base_path(v.native())
39
40 return C.GoString((*C.char)(c))
41 }
42
43 // SetResourceBasePath is a wrapper around g_application_set_resource_base_path().
44 func (v *Application) SetResourceBasePath(bp string) {
45 cstr1 := (*C.gchar)(C.CString(bp))
46 defer C.free(unsafe.Pointer(cstr1))
47
48 C.g_application_set_resource_base_path(v.native(), cstr1)
49 }
0 // Same copyright and license as the rest of the files in this project
1
2 // +build !glib_2_40,!glib_2_42
3
4 package glib
5
6 // #include <gio/gio.h>
7 // #include <glib.h>
8 // #include <glib-object.h>
9 // #include "glib.go.h"
10 // #include "glib_since_2_44.go.h"
11 import "C"
12
13 /*
14 * Application
15 */
16
17 // GetIsBusy is a wrapper around g_application_get_is_busy().
18 func (v *Application) GetIsBusy() bool {
19 return gobool(C.g_application_get_is_busy(v.native()))
20 }
21
22 /*
23 * SimpleAction
24 */
25
26 // SetStateHint is a wrapper around g_simple_action_set_state_hint
27 func (v *SimpleAction) SetStateHint(stateHint *Variant) {
28 C.g_simple_action_set_state_hint(v.native(), stateHint.native())
29 }
0 // Same copyright and license as the rest of the files in this project
1
2 #include <stdlib.h>
3
4 #include <glib-object.h>
5 #include <glib.h>
6
7 static GListModel *toGListModel(void *p) { return (G_LIST_MODEL(p)); }
8
9 static GListStore *toGListStore(void *p) { return (G_LIST_STORE(p)); }
10
11 static inline void _g_list_store_insert_sorted(GListStore *model, gpointer item,
12 gpointer user_data) {
13 g_list_store_insert_sorted(model, item,
14 (GCompareDataFunc)(goCompareDataFuncs), user_data);
15 }
0 // Same copyright and license as the rest of the files in this project
1
2 // +build !glib_2_40,!glib_2_42,!glib_2_44
3
4 package glib
5
6 // #include <gio/gio.h>
7 // #include <glib.h>
8 // #include <glib-object.h>
9 // #include "glib.go.h"
10 // #include "glib_since_2_44.go.h"
11 // #include "glib_since_2_46.go.h"
12 import "C"
13 import "github.com/gotk3/gotk3/internal/callback"
14
15 /*
16 * GListStore
17 */
18
19 // Sort is a wrapper around g_list_store_sort().
20 func (v *ListStore) Sort(compareFunc CompareDataFunc) {
21 C._g_list_store_sort(v.native(), C.gpointer(callback.Assign(compareFunc)))
22 }
0 // Same copyright and license as the rest of the files in this project
1
2 #include <stdlib.h>
3
4 #include <glib-object.h>
5 #include <glib.h>
6
7 static inline void _g_list_store_sort(GListStore *model, gpointer user_data) {
8 g_list_store_sort(model, (GCompareDataFunc)(goCompareDataFuncs), user_data);
9 }
0 // Same copyright and license as the rest of the files in this project
1
2 // +build !glib_2_40,!glib_2_42,!glib_2_44,!glib_2_46,!glib_2_48,!glib_2_50,!glib_2_52,!glib_2_54,!glib_2_56,!glib_2_58,!glib_2_60,!glib_2_62
3
4 package glib
5
6 // // #include <gio/gio.h>
7 // // #include <glib.h>
8 // // #include <glib-object.h>
9 // // #include "glib.go.h"
10 // // #include "glib_since_2_44.go.h"
11 // import "C"
12
13 /*
14 * GListStore
15 */
16
17 // TODO
18 // g_list_store_find
19 // g_list_store_find_with_equal_func
5555
5656 gtk.Main()
5757 }
58
59 // TestTypeNames tests both glib.TypeFromName and glib.Type.Name
60 func TestTypeNames(t *testing.T) {
61 tp := glib.TypeFromName("GtkWindow")
62 name := tp.Name()
63
64 if name != "GtkWindow" {
65 t.Error("Expected GtkWindow, got", name)
66 }
67 }
68
69 func TestTypeIsA(t *testing.T) {
70 tp := glib.TypeFromName("GtkApplicationWindow")
71 tpParent := glib.TypeFromName("GtkWindow")
72
73 isA := tp.IsA(tpParent)
74
75 if !isA {
76 t.Error("Expected true, GtkApplicationWindow is a GtkWindow")
77 }
78 }
79
80 func TestTypeNextBase(t *testing.T) {
81 tpLeaf := glib.TypeFromName("GtkWindow")
82 tpParent := glib.TypeFromName("GtkContainer")
83
84 tpNextBase := glib.TypeNextBase(tpLeaf, tpParent)
85 name := tpNextBase.Name()
86
87 if name != "GtkBin" {
88 t.Error("Expected GtkBin, got", name)
89 }
90 }
91
92 func TestValueString_NonEmpty(t *testing.T) {
93
94 expected := "test"
95
96 value, err := glib.GValue(expected)
97 if err != nil {
98 t.Error("acquiring gvalue failed:", err.Error())
99 return
100 }
101
102 actual, err := value.GetString()
103 if err != nil {
104 t.Error(err.Error())
105 return
106 }
107
108 if actual != expected {
109 t.Errorf("Expected %q, got %q", expected, actual)
110 }
111 }
112
113 func TestValueString_Empty(t *testing.T) {
114
115 expected := ""
116
117 value, err := glib.GValue(expected)
118 if err != nil {
119 t.Error("acquiring gvalue failed:", err.Error())
120 return
121 }
122
123 actual, err := value.GetString()
124 if err != nil {
125 t.Error(err.Error())
126 return
127 }
128
129 if actual != expected {
130 t.Errorf("Expected %q, got %q", expected, actual)
131 }
132 }
0 // Same copyright and license as the rest of the files in this project
1
2 // +build !glib_2_40,!glib_2_42
3
4 package glib
5
6 // #include <gio/gio.h>
7 // #include <glib.h>
8 // #include <glib-object.h>
9 // #include "glib.go.h"
10 // #include "glib_since_2_44.go.h"
11 import "C"
12 import (
13 "unsafe"
14
15 "github.com/gotk3/gotk3/internal/callback"
16 )
17
18 /*
19 * GListModel
20 */
21
22 // IListModel is an interface representation of ListModel,
23 // used to avoid duplication when embedding the type in a wrapper of another GObject-based type.
24 type IListModel interface {
25 toGListModel() *C.GListModel
26 }
27
28 // ListModel is a representation of GIO's GListModel.
29 type ListModel struct {
30 *Object
31 }
32
33 func (v *ListModel) toGListModel() *C.GListModel {
34 if v == nil {
35 return nil
36 }
37 return v.native()
38 }
39
40 // native returns a pointer to the underlying GListModel.
41 func (v *ListModel) native() *C.GListModel {
42 if v == nil || v.GObject == nil {
43 return nil
44 }
45 return C.toGListModel(unsafe.Pointer(v.GObject))
46 }
47
48 // Native returns a pointer to the underlying GListModel.
49 func (v *ListModel) Native() uintptr {
50 return uintptr(unsafe.Pointer(v.native()))
51 }
52
53 func marshalListModel(p uintptr) (interface{}, error) {
54 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
55 return wrapListModel(wrapObject(unsafe.Pointer(c))), nil
56 }
57
58 func wrapListModel(obj *Object) *ListModel {
59 return &ListModel{obj}
60 }
61
62 // GetItemType is a wrapper around g_list_model_get_item_type().
63 func (v *ListModel) GetItemType() Type {
64 return Type(C.g_list_model_get_item_type(v.native()))
65 }
66
67 // GetNItems is a wrapper around g_list_model_get_n_items().
68 func (v *ListModel) GetNItems() uint {
69 return uint(C.g_list_model_get_n_items(v.native()))
70 }
71
72 // GetItem is a wrapper around g_list_model_get_item().
73 func (v *ListModel) GetItem(position uint) uintptr {
74 c := C.g_list_model_get_item(v.native(), C.guint(position))
75 return uintptr(unsafe.Pointer(c))
76 }
77
78 // GetObject is a wrapper around g_list_model_get_object().
79 func (v *ListModel) GetObject(position uint) *Object {
80 c := C.g_list_model_get_object(v.native(), C.guint(position))
81 return wrapObject(unsafe.Pointer(c))
82 }
83
84 // ItemsChanged is a wrapper around g_list_model_items_changed().
85 func (v *ListModel) ItemsChanged(position, removed, added uint) {
86 C.g_list_model_items_changed(v.native(), C.guint(position), C.guint(removed), C.guint(added))
87 }
88
89 /*
90 * GListStore
91 */
92
93 // ListStore is a representation of GListStore
94 type ListStore struct {
95 ListModel
96 }
97
98 func (v *ListStore) native() *C.GListStore {
99 if v == nil || v.GObject == nil {
100 return nil
101 }
102 return C.toGListStore(unsafe.Pointer(v.GObject))
103 }
104
105 func (v *ListStore) Native() uintptr {
106 return uintptr(unsafe.Pointer(v.native()))
107 }
108
109 func marshalListStore(p uintptr) (interface{}, error) {
110 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
111 return wrapListStore(wrapObject(unsafe.Pointer(c))), nil
112 }
113
114 func wrapListStore(obj *Object) *ListStore {
115 return &ListStore{ListModel{obj}}
116 }
117
118 // ListStoreNew is a wrapper around g_list_store_new().
119 func ListStoreNew(itemType Type) *ListStore {
120 c := C.g_list_store_new(C.GType(itemType))
121 if c == nil {
122 return nil
123 }
124 return wrapListStore(wrapObject(unsafe.Pointer(c)))
125 }
126
127 // Insert is a wrapper around g_list_store_insert().
128 func (v *ListStore) Insert(position uint, item interface{}) {
129 gItem := ToGObject(unsafe.Pointer(&item))
130 C.g_list_store_insert(v.native(), C.guint(position), C.gpointer(gItem))
131 }
132
133 // InsertSorted is a wrapper around g_list_store_insert_sorted().
134 func (v *ListStore) InsertSorted(item interface{}, compareFunc CompareDataFunc) {
135 gItem := ToGObject(unsafe.Pointer(&item))
136 C._g_list_store_insert_sorted(v.native(), C.gpointer(gItem), C.gpointer(callback.Assign(compareFunc)))
137 }
138
139 // Append is a wrapper around g_list_store_append().
140 func (v *ListStore) Append(item interface{}) {
141 gItem := ToGObject(unsafe.Pointer(&item))
142 C.g_list_store_append(v.native(), C.gpointer(gItem))
143 }
144
145 // Remove is a wrapper around g_list_store_remove().
146 func (v *ListStore) Remove(position uint) {
147 C.g_list_store_remove(v.native(), C.guint(position))
148 }
149
150 // Splice is a wrapper around g_list_store_splice().
151 func (v *ListStore) Splice(position uint, removalLength uint, additions []interface{}) {
152
153 additionsLength := len(additions)
154 gAdditions := make([]*C.GObject, additionsLength)
155 for i, add := range additions {
156 gAdditions[i] = ToGObject(unsafe.Pointer(&add))
157 }
158 gAdditions = append(gAdditions, nil)
159
160 additionsPtr := C.gpointer(gAdditions[0])
161
162 C.g_list_store_splice(v.native(), C.guint(position), C.guint(removalLength), &additionsPtr, C.guint(additionsLength))
163 }
2424 return (*MainContext)(c)
2525 }
2626
27 // Iteration is a wrapper around g_main_context_iteration()
28 func (v *MainContext) Iteration(mayBlock bool) bool {
29 return gobool(C.g_main_context_iteration(v.native(), gbool(mayBlock)))
30 }
31
32 // Pending is a wrapper around g_main_context_pending()
33 func (v *MainContext) Pending() bool {
34 return gobool(C.g_main_context_pending(v.native()))
35 }
36
2737 // MainDepth is a wrapper around g_main_depth().
2838 func MainDepth() int {
2939 return int(C.g_main_depth())
3848 return (*Source)(c)
3949 }
4050
41 // SourceRemove is a wrapper around g_main_context_pending()
42 func (v *MainContext) Pending(src SourceHandle) bool {
43 return gobool(C.g_main_context_pending(v.native()))
51 // Acquire is a wrapper around g_main_context_acquire().
52 func (v *MainContext) Acquire() bool {
53 return gobool(C.g_main_context_acquire(v.native()))
4454 }
55
56 // Release is a wrapper around g_main_context_release().
57 func (v *MainContext) Release() {
58 C.g_main_context_release(v.native())
59 }
60
61 // IsOwner is a wrapper around g_main_context_is_owner().
62 func (v *MainContext) IsOwner() bool {
63 return gobool(C.g_main_context_is_owner(v.native()))
64 }
0 package glib
1
2 // #include <gio/gio.h>
3 // #include <glib.h>
4 // #include <glib-object.h>
5 // #include "glib.go.h"
6 // #include "gpermission.go.h"
7 import "C"
8 import (
9 "errors"
10 "unsafe"
11
12 "github.com/gotk3/gotk3/internal/callback"
13 )
14
15 // Permission is a representation of GIO's GPermission.
16 type Permission struct {
17 *Object
18 }
19
20 func (v *Permission) native() *C.GPermission {
21 if v == nil || v.GObject == nil {
22 return nil
23 }
24 return C.toGPermission(unsafe.Pointer(v.GObject))
25 }
26
27 // Native returns a uintptr to the underlying C.GPermission.
28 func (v *Permission) Native() uintptr {
29 return uintptr(unsafe.Pointer(v.native()))
30 }
31
32 func marshalPermission(p uintptr) (interface{}, error) {
33 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
34 return wrapPermission(wrapObject(unsafe.Pointer(c))), nil
35 }
36
37 func wrapPermission(obj *Object) *Permission {
38 return &Permission{obj}
39 }
40
41 // WrapPermission wraps given unsafe pointer into Permission.
42 func WrapPermission(ptr unsafe.Pointer) *Permission {
43 return wrapPermission(wrapObject(ptr))
44 }
45
46 // GetAllowed is a wrapper around g_permission_get_allowed().
47 func (v *Permission) GetAllowed() bool {
48 c := C.g_permission_get_allowed(v.native())
49 return gobool(c)
50 }
51
52 // GetCanAcquire is a wrapper around g_permission_get_can_acquire().
53 func (v *Permission) GetCanAcquire() bool {
54 c := C.g_permission_get_can_acquire(v.native())
55 return gobool(c)
56 }
57
58 // GetCanRelease is a wrapper around g_permission_get_can_release().
59 func (v *Permission) GetCanRelease() bool {
60 c := C.g_permission_get_can_release(v.native())
61 return gobool(c)
62 }
63
64 // Acquire is a wrapper around g_permission_acquire().
65 func (v *Permission) Acquire(cancellable *Cancellable) error {
66 var err *C.GError
67 c := C.g_permission_acquire(v.native(), cancellable.native(), &err)
68 acquired := gobool(c)
69 if !acquired {
70 defer C.g_error_free(err)
71 return errors.New(C.GoString((*C.char)(err.message)))
72 }
73 return nil
74 }
75
76 // AcquireAsync is a wrapper around g_permission_acquire_async().
77 func (v *Permission) AcquireAsync(cancellable *Cancellable, fn AsyncReadyCallback) {
78 C._g_permission_acquire_async(v.native(), cancellable.native(), C.gpointer(callback.Assign(fn)))
79 }
80
81 // AcquireFinish is a wrapper around g_permission_acquire_finish().
82 func (v *Permission) AcquireFinish(result *AsyncResult) error {
83 var err *C.GError
84 c := C.g_permission_acquire_finish(v.native(), result.native(), &err)
85 acquired := gobool(c)
86 if !acquired {
87 defer C.g_error_free(err)
88 return errors.New(C.GoString((*C.char)(err.message)))
89 }
90 return nil
91 }
92
93 // Release is a wrapper around g_permission_release().
94 func (v *Permission) Release(cancellable *Cancellable) error {
95 var err *C.GError
96 c := C.g_permission_release(v.native(), cancellable.native(), &err)
97 released := gobool(c)
98 if !released {
99 defer C.g_error_free(err)
100 return errors.New(C.GoString((*C.char)(err.message)))
101 }
102 return nil
103 }
104
105 // ReleaseAsync is a wrapper around g_permission_release_async().
106 func (v *Permission) ReleaseAsync(cancellable *Cancellable, fn AsyncReadyCallback) {
107 C._g_permission_release_async(v.native(), cancellable.native(), C.gpointer(callback.Assign(fn)))
108 }
109
110 // ReleaseFinish is a wrapper around g_permission_release_finish().
111 func (v *Permission) ReleaseFinish(result *AsyncResult) error {
112 var err *C.GError
113 c := C.g_permission_release_finish(v.native(), result.native(), &err)
114 released := gobool(c)
115 if !released {
116 defer C.g_error_free(err)
117 return errors.New(C.GoString((*C.char)(err.message)))
118 }
119 return nil
120 }
121
122 // ImplUpdate is a wrapper around g_permission_impl_update().
123 func (v *Permission) ImplUpdate(allowed, canAcquire, canRelease bool) {
124 C.g_permission_impl_update(v.native(), gbool(allowed), gbool(canAcquire), gbool(canRelease))
125 }
0 // Same copyright and license as the rest of the files in this project
1
2 /*
3 * GAsyncReadyCallback
4 */
5
6 extern void goAsyncReadyCallbacks(GObject *source_object, GAsyncResult *res,
7 gpointer user_data);
8
9 static inline void _g_permission_acquire_async(GPermission *permission,
10 GCancellable *cancellable,
11 gpointer user_data) {
12 g_permission_acquire_async(permission, cancellable,
13 (GAsyncReadyCallback)(goAsyncReadyCallbacks),
14 user_data);
15 }
16
17 static inline void _g_permission_release_async(GPermission *permission,
18 GCancellable *cancellable,
19 gpointer user_data) {
20 g_permission_release_async(permission, cancellable,
21 (GAsyncReadyCallback)(goAsyncReadyCallbacks),
22 user_data);
23 }
1515 return (*C.GSource)(v)
1616 }
1717
18 func wrapSource(sourcePtr *C.GSource) *Source {
19 source := Source(*sourcePtr)
20 return &source
21 }
22
1823 // MainCurrentSource is a wrapper around g_main_current_source().
1924 func MainCurrentSource() *Source {
2025 c := C.g_main_current_source()
77 import "C"
88
99 import (
10 "errors"
1011 "fmt"
12 "runtime"
1113 "unsafe"
1214 )
1315
4244 return v
4345 }
4446
45 // newVariant creates a new Variant from a GVariant pointer.
46 func newVariant(p *C.GVariant) *Variant {
47 return &Variant{GVariant: p}
48 }
49
50 // VariantFromUnsafePointer returns a Variant from an unsafe pointer.
51 // XXX: unnecessary footgun?
52 //func VariantFromUnsafePointer(p unsafe.Pointer) *Variant {
53 // return &Variant{C.toGVariant(p)}
54 //}
55
5647 // native returns a pointer to the underlying GVariant.
5748 func (v *Variant) native() *C.GVariant {
5849 if v == nil || v.GVariant == nil {
6657 return uintptr(unsafe.Pointer(v.native()))
6758 }
6859
60 // newVariant wraps a native GVariant.
61 // Does NOT handle reference counting! Use takeVariant() to take ownership of values.
62 func newVariant(p *C.GVariant) *Variant {
63 if p == nil {
64 return nil
65 }
66 return &Variant{GVariant: p}
67 }
68
69 // TakeVariant wraps a unsafe.Pointer as a glib.Variant, taking ownership of it.
70 // This function is exported for visibility in other gotk3 packages and
71 // is not meant to be used by applications.
72 func TakeVariant(ptr unsafe.Pointer) *Variant {
73 return takeVariant(C.toGVariant(ptr))
74 }
75
76 // takeVariant wraps a native GVariant,
77 // takes ownership and sets up a finalizer to free the instance during GC.
78 func takeVariant(p *C.GVariant) *Variant {
79 if p == nil {
80 return nil
81 }
82 obj := &Variant{GVariant: p}
83
84 if obj.IsFloating() {
85 obj.RefSink()
86 } else {
87 obj.Ref()
88 }
89
90 runtime.SetFinalizer(obj, (*Variant).Unref)
91 return obj
92 }
93
94 // IsFloating returns true if the variant has a floating reference count.
95 // Reference counting is usually handled in the gotk layer,
96 // most applications should not call this.
97 func (v *Variant) IsFloating() bool {
98 return gobool(C.g_variant_is_floating(v.native()))
99 }
100
101 // Ref is a wrapper around g_variant_ref.
102 // Reference counting is usually handled in the gotk layer,
103 // most applications should not need to call this.
104 func (v *Variant) Ref() {
105 C.g_variant_ref(v.native())
106 }
107
108 // RefSink is a wrapper around g_variant_ref_sink.
109 // Reference counting is usually handled in the gotk layer,
110 // most applications should not need to call this.
111 func (v *Variant) RefSink() {
112 C.g_variant_ref_sink(v.native())
113 }
114
115 // TakeRef is a wrapper around g_variant_take_ref.
116 // Reference counting is usually handled in the gotk layer,
117 // most applications should not need to call this.
118 func (v *Variant) TakeRef() {
119 C.g_variant_take_ref(v.native())
120 }
121
122 // Unref is a wrapper around g_variant_unref.
123 // Reference counting is usually handled in the gotk layer,
124 // most applications should not need to call this.
125 func (v *Variant) Unref() {
126 C.g_variant_unref(v.native())
127 }
128
129 // VariantFromInt16 is a wrapper around g_variant_new_int16
130 func VariantFromInt16(value int16) *Variant {
131 return takeVariant(C.g_variant_new_int16(C.gint16(value)))
132 }
133
134 // VariantFromInt32 is a wrapper around g_variant_new_int32
135 func VariantFromInt32(value int32) *Variant {
136 return takeVariant(C.g_variant_new_int32(C.gint32(value)))
137 }
138
139 // VariantFromInt64 is a wrapper around g_variant_new_int64
140 func VariantFromInt64(value int64) *Variant {
141 return takeVariant(C.g_variant_new_int64(C.gint64(value)))
142 }
143
144 // VariantFromByte is a wrapper around g_variant_new_byte
145 func VariantFromByte(value uint8) *Variant {
146 return takeVariant(C.g_variant_new_byte(C.guint8(value)))
147 }
148
149 // VariantFromUint16 is a wrapper around g_variant_new_uint16
150 func VariantFromUint16(value uint16) *Variant {
151 return takeVariant(C.g_variant_new_uint16(C.guint16(value)))
152 }
153
154 // VariantFromUint32 is a wrapper around g_variant_new_uint32
155 func VariantFromUint32(value uint32) *Variant {
156 return takeVariant(C.g_variant_new_uint32(C.guint32(value)))
157 }
158
159 // VariantFromUint64 is a wrapper around g_variant_new_uint64
160 func VariantFromUint64(value uint64) *Variant {
161 return takeVariant(C.g_variant_new_uint64(C.guint64(value)))
162 }
163
164 // VariantFromBoolean is a wrapper around g_variant_new_boolean
165 func VariantFromBoolean(value bool) *Variant {
166 return takeVariant(C.g_variant_new_boolean(gbool(value)))
167 }
168
169 // VariantFromFloat64 is a wrapper around g_variant_new_double().
170 // I chose to respect the Golang float64 nomenclature instead
171 // of 'double' 'C'. Corresponding VariantType is: 'VARIANT_TYPE_DOUBLE'
172 func VariantFromFloat64(value float64) *Variant {
173 return takeVariant(C.g_variant_new_double(C.gdouble(value)))
174 }
175
176 // VariantFromString is a wrapper around g_variant_new_string/g_variant_new_take_string.
177 // Uses g_variant_new_take_string to reduce memory allocations if possible.
178 func VariantFromString(value string) *Variant {
179 cstr := (*C.gchar)(C.CString(value))
180 // g_variant_new_take_string takes owhership of the cstring and will call free() on it when done.
181 // Do NOT free this string in this function!
182 return takeVariant(C.g_variant_new_take_string(cstr))
183 }
184
185 // VariantFromVariant is a wrapper around g_variant_new_variant.
186 func VariantFromVariant(value *Variant) *Variant {
187 return takeVariant(C.g_variant_new_variant(value.native()))
188 }
189
69190 // TypeString returns the g variant type string for this variant.
70191 func (v *Variant) TypeString() string {
71192 // the string returned from this belongs to GVariant and must not be freed.
77198 return gobool(C.g_variant_is_container(v.native()))
78199 }
79200
80 // IsFloating returns true if the variant has a floating reference count.
81 // XXX: this isn't useful without ref_sink/take_ref, which are themselves
82 // perhaps not useful for most Go code that may use variants.
83 //func (v *Variant) IsFloating() bool {
84 // return gobool(C.g_variant_is_floating(v.native()))
85 //}
86
87201 // GetBoolean returns the bool value of this variant.
88202 func (v *Variant) GetBoolean() bool {
89203 return gobool(C.g_variant_get_boolean(v.native()))
90204 }
91205
92 // GetString returns the string value of the variant.
206 // GetDouble is a wrapper around g_variant_get_double()
207 func (v *Variant) GetDouble() float64 {
208 return float64(C.g_variant_get_double(v.native()))
209 }
210
211 // GetString is a wrapper around g_variant_get_string.
212 // It returns the string value of the variant.
93213 func (v *Variant) GetString() string {
214
215 // The string value remains valid as long as the GVariant exists, do NOT free the cstring in this function.
94216 var len C.gsize
95217 gc := C.g_variant_get_string(v.native(), &len)
96 defer C.g_free(C.gpointer(gc))
218
219 // This is opposed to g_variant_dup_string, which copies the string.
220 // g_variant_dup_string is not implemented,
221 // as we copy the string value anyways when converting to a go string.
222
97223 return C.GoStringN((*C.char)(gc), (C.int)(len))
224 }
225
226 // GetVariant is a wrapper around g_variant_get_variant.
227 // It unboxes a nested GVariant.
228 func (v *Variant) GetVariant() *Variant {
229 c := C.g_variant_get_variant(v.native())
230 if c == nil {
231 return nil
232 }
233 // The returned value is returned with full ownership transfer,
234 // only Unref(), don't Ref().
235 obj := newVariant(c)
236 runtime.SetFinalizer(obj, (*Variant).Unref)
237 return obj
98238 }
99239
100240 // GetStrv returns a slice of strings from this variant. It wraps
102242 func (v *Variant) GetStrv() []string {
103243 gstrv := C.g_variant_get_strv(v.native(), nil)
104244 // we do not own the memory for these strings, so we must not use strfreev
105 // but we must free the actual pointer we receive.
245 // but we must free the actual pointer we receive (transfer container).
246 // We don't implement g_variant_dup_strv which copies the strings,
247 // as we need to copy anyways when converting to go strings.
248 c := gstrv
249 defer C.g_free(C.gpointer(gstrv))
250 var strs []string
251
252 for *c != nil {
253 strs = append(strs, C.GoString((*C.char)(*c)))
254 c = C.next_gcharptr(c)
255 }
256 return strs
257 }
258
259 // GetObjv returns a slice of object paths from this variant. It wraps
260 // g_variant_get_objv, but returns copies of the strings instead.
261 func (v *Variant) GetObjv() []string {
262 gstrv := C.g_variant_get_objv(v.native(), nil)
263 // we do not own the memory for these strings, so we must not use strfreev
264 // but we must free the actual pointer we receive (transfer container).
265 // We don't implement g_variant_dup_objv which copies the strings,
266 // as we need to copy anyways when converting to go strings.
106267 c := gstrv
107268 defer C.g_free(C.gpointer(gstrv))
108269 var strs []string
118279 // an error otherwise. It wraps variouns `g_variant_get_*` functions dealing
119280 // with integers of different sizes.
120281 func (v *Variant) GetInt() (int64, error) {
121 t := v.Type().String()
282 t := v.TypeString()
122283 var i int64
123284 switch t {
124 case "y":
125 i = int64(C.g_variant_get_byte(v.native()))
126285 case "n":
127286 i = int64(C.g_variant_get_int16(v.native()))
128 case "q":
129 i = int64(C.g_variant_get_uint16(v.native()))
130287 case "i":
131288 i = int64(C.g_variant_get_int32(v.native()))
132 case "u":
133 i = int64(C.g_variant_get_uint32(v.native()))
134289 case "x":
135290 i = int64(C.g_variant_get_int64(v.native()))
291 default:
292 return 0, fmt.Errorf("variant type %s not a signed integer type", t)
293 }
294 return i, nil
295 }
296
297 // GetUint returns the uint64 value of the variant if it is an integer type, and
298 // an error otherwise. It wraps variouns `g_variant_get_*` functions dealing
299 // with integers of different sizes.
300 func (v *Variant) GetUint() (uint64, error) {
301 t := v.TypeString()
302 var i uint64
303 switch t {
304 case "y":
305 i = uint64(C.g_variant_get_byte(v.native()))
306 case "q":
307 i = uint64(C.g_variant_get_uint16(v.native()))
308 case "u":
309 i = uint64(C.g_variant_get_uint32(v.native()))
136310 case "t":
137 i = int64(C.g_variant_get_uint64(v.native()))
311 i = uint64(C.g_variant_get_uint64(v.native()))
138312 default:
139 return 0, fmt.Errorf("variant type %s not an integer type", t)
313 return 0, fmt.Errorf("variant type %s not an unsigned integer type", t)
140314 }
141315 return i, nil
142316 }
143317
144318 // Type returns the VariantType for this variant.
145319 func (v *Variant) Type() *VariantType {
320 // The return value is valid for the lifetime of value and must not be freed.
146321 return newVariantType(C.g_variant_get_type(v.native()))
147322 }
148323
167342 return C.GoString((*C.char)(gc))
168343 }
169344
170 //void g_variant_unref ()
171 //GVariant * g_variant_ref ()
172 //GVariant * g_variant_ref_sink ()
173 //GVariant * g_variant_take_ref ()
345 // TODO:
174346 //gint g_variant_compare ()
175347 //GVariantClass g_variant_classify ()
176348 //gboolean g_variant_check_format_string ()
178350 //void g_variant_get_va ()
179351 //GVariant * g_variant_new ()
180352 //GVariant * g_variant_new_va ()
181 //GVariant * g_variant_new_boolean ()
182 //GVariant * g_variant_new_byte ()
183 //GVariant * g_variant_new_int16 ()
184 //GVariant * g_variant_new_uint16 ()
185 //GVariant * g_variant_new_int32 ()
186 //GVariant * g_variant_new_uint32 ()
187 //GVariant * g_variant_new_int64 ()
188 //GVariant * g_variant_new_uint64 ()
189353 //GVariant * g_variant_new_handle ()
190 //GVariant * g_variant_new_double ()
191 //GVariant * g_variant_new_string ()
192 //GVariant * g_variant_new_take_string ()
193354 //GVariant * g_variant_new_printf ()
194355 //GVariant * g_variant_new_object_path ()
195356 //gboolean g_variant_is_object_path ()
196357 //GVariant * g_variant_new_signature ()
197358 //gboolean g_variant_is_signature ()
198 //GVariant * g_variant_new_variant ()
199359 //GVariant * g_variant_new_strv ()
200360 //GVariant * g_variant_new_objv ()
201361 //GVariant * g_variant_new_bytestring ()
209369 //guint64 g_variant_get_uint64 ()
210370 //gint32 g_variant_get_handle ()
211371 //gdouble g_variant_get_double ()
212 //const gchar * g_variant_get_string ()
213 //gchar * g_variant_dup_string ()
214 //GVariant * g_variant_get_variant ()
215 //const gchar ** g_variant_get_strv ()
216 //gchar ** g_variant_dup_strv ()
217 //const gchar ** g_variant_get_objv ()
218 //gchar ** g_variant_dup_objv ()
219372 //const gchar * g_variant_get_bytestring ()
220373 //gchar * g_variant_dup_bytestring ()
221374 //const gchar ** g_variant_get_bytestring_array ()
277430 //gboolean g_variant_dict_remove ()
278431 //GVariant * g_variant_dict_end ()
279432 //#define G_VARIANT_PARSE_ERROR
280 //GVariant * g_variant_parse ()
433
434 // VariantParse is a wrapper around g_variant_parse()
435 func VariantParse(vType *VariantType, text string) (*Variant, error) {
436 cstr := C.CString(text)
437 defer C.free(unsafe.Pointer(cstr))
438 var gerr *C.GError
439 c := C.g_variant_parse(vType.native(), (*C.gchar)(cstr), nil, nil, &gerr)
440 if c == nil {
441 defer C.g_error_free(gerr)
442 return nil, errors.New(goString(gerr.message))
443 }
444 // will be freed during GC
445 return takeVariant(c), nil
446 }
447
281448 //GVariant * g_variant_new_parsed_va ()
282449 //GVariant * g_variant_new_parsed ()
283450 //gchar * g_variant_parse_error_print_context ()
00 // Same copyright and license as the rest of the files in this project
11
2 //GVariant : GVariant — strongly typed value datatype
2 // GVariant : GVariant — strongly typed value datatype
33 // https://developer.gnome.org/glib/2.26/glib-GVariant.html
44
55 #ifndef __GVARIANT_GO_H__
66 #define __GVARIANT_GO_H__
77
8 #include <glib.h>
89 #include <stdint.h>
10 #include <stdio.h>
911 #include <stdlib.h>
10 #include <stdio.h>
11 #include <glib.h>
1212
1313 // Type Casting
1414
15 static GVariant *
16 toGVariant(void *p)
17 {
18 return (GVariant*)p;
15 static GVariant *toGVariant(void *p) { return (GVariant *)p; }
16
17 static GVariantBuilder *toGVariantBuilder(void *p) {
18 return (GVariantBuilder *)p;
1919 }
2020
21 static GVariantBuilder *
22 toGVariantBuilder(void *p)
23 {
24 return (GVariantBuilder*)p;
25 }
21 static GVariantDict *toGVariantDict(void *p) { return (GVariantDict *)p; }
2622
27 static GVariantDict *
28 toGVariantDict(void *p)
29 {
30 return (GVariantDict*)p;
31 }
32
33 static GVariantIter *
34 toGVariantIter(void *p)
35 {
36 return (GVariantIter*)p;
37 }
23 static GVariantIter *toGVariantIter(void *p) { return (GVariantIter *)p; }
3824
3925 #endif
22 package glib_test
33
44 import (
5 "math"
56 "testing"
7
8 "github.com/gotk3/gotk3/glib"
69 )
710
8 func Test_AcceleratorParse(t *testing.T) {
9 /*
10 testVariant := &Variant{}
11 t.Log("native: " + testVariant.Native())
12 */
11 func TestVariantGetInt(t *testing.T) {
12 t.Run("int16", func(t *testing.T) {
13 expected := int16(math.MinInt16)
14 variant := glib.VariantFromInt16(expected)
15 actual, err := variant.GetInt()
16 if err != nil {
17 t.Error("Unexpected error:", err.Error())
18 }
19 if int64(expected) != actual {
20 t.Error("Expected", expected, "got", actual)
21 }
22 })
23
24 t.Run("int32", func(t *testing.T) {
25 expected := int32(math.MinInt32)
26 variant := glib.VariantFromInt32(expected)
27 actual, err := variant.GetInt()
28 if err != nil {
29 t.Error("Unexpected error:", err.Error())
30 }
31 if int64(expected) != actual {
32 t.Error("Expected", expected, "got", actual)
33 }
34 })
35
36 t.Run("int64", func(t *testing.T) {
37 expected := int64(math.MinInt64)
38 variant := glib.VariantFromInt64(expected)
39 actual, err := variant.GetInt()
40 if err != nil {
41 t.Error("Unexpected error:", err.Error())
42 }
43 if expected != actual {
44 t.Error("Expected", expected, "got", actual)
45 }
46 })
47
48 t.Run("other type", func(t *testing.T) {
49 variant := glib.VariantFromUint64(987)
50 _, err := variant.GetInt()
51 if err == nil {
52 t.Error("expected error, did not get one")
53 }
54 })
1355 }
56
57 func TestVariantGetUint(t *testing.T) {
58 t.Run("byte", func(t *testing.T) {
59 expected := uint8(math.MaxUint8)
60 variant := glib.VariantFromByte(expected)
61 actual, err := variant.GetUint()
62 if err != nil {
63 t.Error("Unexpected error:", err.Error())
64 }
65 if uint64(expected) != actual {
66 t.Error("Expected", expected, "got", actual)
67 }
68 })
69
70 t.Run("int16", func(t *testing.T) {
71 expected := uint16(math.MaxUint16)
72 variant := glib.VariantFromUint16(expected)
73 actual, err := variant.GetUint()
74 if err != nil {
75 t.Error("Unexpected error:", err.Error())
76 }
77 if uint64(expected) != actual {
78 t.Error("Expected", expected, "got", actual)
79 }
80 })
81
82 t.Run("int32", func(t *testing.T) {
83 expected := uint32(math.MaxUint32)
84 variant := glib.VariantFromUint32(expected)
85 actual, err := variant.GetUint()
86 if err != nil {
87 t.Error("Unexpected error:", err.Error())
88 }
89 if uint64(expected) != actual {
90 t.Error("Expected", expected, "got", actual)
91 }
92 })
93
94 t.Run("int64", func(t *testing.T) {
95 expected := uint64(math.MaxUint64)
96 variant := glib.VariantFromUint64(expected)
97 actual, err := variant.GetUint()
98 if err != nil {
99 t.Error("Unexpected error:", err.Error())
100 }
101 if expected != actual {
102 t.Error("Expected", expected, "got", actual)
103 }
104 })
105
106 t.Run("other type", func(t *testing.T) {
107 variant := glib.VariantFromInt64(987)
108 _, err := variant.GetUint()
109 if err == nil {
110 t.Error("expected error, did not get one")
111 }
112 })
113 }
114
115 func TestVariantType(t *testing.T) {
116 variant := glib.VariantFromBoolean(true)
117 variantType := variant.Type()
118 if !glib.VariantTypeEqual(glib.VARIANT_TYPE_BOOLEAN, variantType) {
119 t.Error("Expected", glib.VARIANT_TYPE_BOOLEAN, "got", variantType)
120 }
121 }
122
123 func TestVariantBool(t *testing.T) {
124 testCases := []struct {
125 desc string
126 value bool
127 }{
128 {
129 desc: "true",
130 value: true,
131 },
132 {
133 desc: "false",
134 value: false,
135 },
136 }
137 for _, tC := range testCases {
138 t.Run(tC.desc, func(t *testing.T) {
139 variant := glib.VariantFromBoolean(tC.value)
140 actual := variant.GetBoolean()
141 if tC.value != actual {
142 t.Error("Expected", tC.value, "got", actual)
143 }
144 })
145 }
146 }
147
148 func TestVariantString(t *testing.T) {
149 testCases := []struct {
150 desc string
151 value string
152 }{
153 {
154 desc: "Plain string",
155 value: "Simple Data",
156 },
157 {
158 desc: "String with special characters",
159 value: "Üö@/Data",
160 },
161 {
162 desc: "Empty String",
163 value: "",
164 },
165 }
166 for _, tC := range testCases {
167 t.Run(tC.desc, func(t *testing.T) {
168 variant := glib.VariantFromString(tC.value)
169 actual := variant.GetString()
170 if tC.value != actual {
171 t.Error("Expected", tC.value, "got", actual)
172 }
173 })
174 }
175 }
176
177 func TestVariantVariant(t *testing.T) {
178
179 boxed := glib.VariantFromString("I'm in a box")
180
181 variant := glib.VariantFromVariant(boxed)
182
183 actual := variant.GetVariant()
184 if boxed.Native() != actual.Native() {
185 t.Error("Expected", boxed.Native(), "got", actual.Native())
186 }
187 }
44
55 package glib
66
7 // #include <stdlib.h>
78 // #include <glib.h>
89 // #include "gvarianttype.go.h"
910 import "C"
11
12 import (
13 "runtime"
14 "unsafe"
15 )
1016
1117 // A VariantType is a wrapper for the GVariantType, which encodes type
1218 // information for GVariants.
2834 return C.GoString((*C.char)(ch))
2935 }
3036
37 // newVariantType wraps a native GVariantType.
38 // Does not create a finalizer.
39 // Use takeVariantType for instances which need to be freed after use.
3140 func newVariantType(v *C.GVariantType) *VariantType {
41 if v == nil {
42 return nil
43 }
3244 return &VariantType{v}
45 }
46
47 // takeVariantType wraps a native GVariantType
48 // and sets up a finalizer to free the instance during GC.
49 func takeVariantType(v *C.GVariantType) *VariantType {
50 if v == nil {
51 return nil
52 }
53 obj := &VariantType{v}
54 runtime.SetFinalizer(obj, (*VariantType).Free)
55 return obj
3356 }
3457
3558 // Variant types for comparing between them. Cannot be const because
3659 // they are pointers.
60 // Note that variant types cannot be compared by value, use VariantTypeEqual() instead.
3761 var (
3862 VARIANT_TYPE_BOOLEAN = newVariantType(C._G_VARIANT_TYPE_BOOLEAN)
3963 VARIANT_TYPE_BYTE = newVariantType(C._G_VARIANT_TYPE_BYTE)
4670 VARIANT_TYPE_HANDLE = newVariantType(C._G_VARIANT_TYPE_HANDLE)
4771 VARIANT_TYPE_DOUBLE = newVariantType(C._G_VARIANT_TYPE_DOUBLE)
4872 VARIANT_TYPE_STRING = newVariantType(C._G_VARIANT_TYPE_STRING)
73 VARIANT_TYPE_OBJECT_PATH = newVariantType(C._G_VARIANT_TYPE_OBJECT_PATH)
74 VARIANT_TYPE_SIGNATURE = newVariantType(C._G_VARIANT_TYPE_SIGNATURE)
75 VARIANT_TYPE_VARIANT = newVariantType(C._G_VARIANT_TYPE_VARIANT)
4976 VARIANT_TYPE_ANY = newVariantType(C._G_VARIANT_TYPE_ANY)
5077 VARIANT_TYPE_BASIC = newVariantType(C._G_VARIANT_TYPE_BASIC)
78 VARIANT_TYPE_MAYBE = newVariantType(C._G_VARIANT_TYPE_MAYBE)
79 VARIANT_TYPE_ARRAY = newVariantType(C._G_VARIANT_TYPE_ARRAY)
5180 VARIANT_TYPE_TUPLE = newVariantType(C._G_VARIANT_TYPE_TUPLE)
5281 VARIANT_TYPE_UNIT = newVariantType(C._G_VARIANT_TYPE_UNIT)
82 VARIANT_TYPE_DICT_ENTRY = newVariantType(C._G_VARIANT_TYPE_DICT_ENTRY)
5383 VARIANT_TYPE_DICTIONARY = newVariantType(C._G_VARIANT_TYPE_DICTIONARY)
5484 VARIANT_TYPE_STRING_ARRAY = newVariantType(C._G_VARIANT_TYPE_STRING_ARRAY)
5585 VARIANT_TYPE_OBJECT_PATH_ARRAY = newVariantType(C._G_VARIANT_TYPE_OBJECT_PATH_ARRAY)
5787 VARIANT_TYPE_BYTESTRING_ARRAY = newVariantType(C._G_VARIANT_TYPE_BYTESTRING_ARRAY)
5888 VARIANT_TYPE_VARDICT = newVariantType(C._G_VARIANT_TYPE_VARDICT)
5989 )
90
91 // Free is a wrapper around g_variant_type_free.
92 // Reference counting is usually handled in the gotk layer,
93 // most applications should not call this.
94 func (v *VariantType) Free() {
95 C.g_variant_type_free(v.native())
96 }
97
98 // VariantTypeNew is a wrapper around g_variant_type_new.
99 func VariantTypeNew(typeString string) *VariantType {
100 cstr := (*C.gchar)(C.CString(typeString))
101 defer C.free(unsafe.Pointer(cstr))
102
103 c := C.g_variant_type_new(cstr)
104 return takeVariantType(c)
105 }
106
107 // VariantTypeStringIsValid is a wrapper around g_variant_type_string_is_valid.
108 func VariantTypeStringIsValid(typeString string) bool {
109 cstr := (*C.gchar)(C.CString(typeString))
110 defer C.free(unsafe.Pointer(cstr))
111
112 return gobool(C.g_variant_type_string_is_valid(cstr))
113 }
114
115 // VariantTypeEqual is a wrapper around g_variant_type_equal
116 func VariantTypeEqual(type1, type2 *VariantType) bool {
117 return gobool(C.g_variant_type_equal(C.gconstpointer(type1.native()), C.gconstpointer(type2.native())))
118 }
119
120 // IsSubtypeOf is a wrapper around g_variant_type_is_subtype_of
121 func (v *VariantType) IsSubtypeOf(supertype *VariantType) bool {
122 return gobool(C.g_variant_type_is_subtype_of(v.native(), supertype.native()))
123 }
124
125 // TODO:
126 // g_variant_type_copy
127 // g_variant_type_string_scan
128 // g_variant_type_is_definite
129 // g_variant_type_is_container
130 // g_variant_type_is_basic
131 // g_variant_type_is_maybe
132 // g_variant_type_is_array
133 // g_variant_type_is_tuple
134 // g_variant_type_is_dict_entry
135 // g_variant_type_is_variant
136 // g_variant_type_hash
137 // g_variant_type_new_maybe
138 // g_variant_type_new_array
139 // g_variant_type_new_tuple
140 // g_variant_type_new_dict_entry
141 // g_variant_type_element
142 // g_variant_type_n_items
143 // g_variant_type_first
144 // g_variant_type_next
145 // g_variant_type_key
146 // g_variant_type_value
00 // Same copyright and license as the rest of the files in this project
11
2 //GVariant : GVariant — strongly typed value datatype
2 // GVariant : GVariant — strongly typed value datatype
33 // https://developer.gnome.org/glib/2.26/glib-GVariant.html
44
55 #ifndef __GVARIANTTYPE_GO_H__
66 #define __GVARIANTTYPE_GO_H__
77
8 const GVariantType* _G_VARIANT_TYPE_BOOLEAN = G_VARIANT_TYPE_BOOLEAN;
9 const GVariantType* _G_VARIANT_TYPE_BYTE = G_VARIANT_TYPE_BYTE;
10 const GVariantType* _G_VARIANT_TYPE_INT16 = G_VARIANT_TYPE_INT16;
11 const GVariantType* _G_VARIANT_TYPE_UINT16 = G_VARIANT_TYPE_UINT16;
12 const GVariantType* _G_VARIANT_TYPE_INT32 = G_VARIANT_TYPE_INT32;
13 const GVariantType* _G_VARIANT_TYPE_UINT32 = G_VARIANT_TYPE_UINT32;
14 const GVariantType* _G_VARIANT_TYPE_INT64 = G_VARIANT_TYPE_INT64;
15 const GVariantType* _G_VARIANT_TYPE_UINT64 = G_VARIANT_TYPE_UINT64;
16 const GVariantType* _G_VARIANT_TYPE_HANDLE = G_VARIANT_TYPE_HANDLE;
17 const GVariantType* _G_VARIANT_TYPE_DOUBLE = G_VARIANT_TYPE_DOUBLE;
18 const GVariantType* _G_VARIANT_TYPE_STRING = G_VARIANT_TYPE_STRING;
19 const GVariantType* _G_VARIANT_TYPE_OBJECT_PATH = G_VARIANT_TYPE_OBJECT_PATH;
20 const GVariantType* _G_VARIANT_TYPE_SIGNATURE = G_VARIANT_TYPE_SIGNATURE;
21 const GVariantType* _G_VARIANT_TYPE_VARIANT = G_VARIANT_TYPE_VARIANT;
22 const GVariantType* _G_VARIANT_TYPE_ANY = G_VARIANT_TYPE_ANY;
23 const GVariantType* _G_VARIANT_TYPE_BASIC = G_VARIANT_TYPE_BASIC;
24 const GVariantType* _G_VARIANT_TYPE_MAYBE = G_VARIANT_TYPE_MAYBE;
25 const GVariantType* _G_VARIANT_TYPE_ARRAY = G_VARIANT_TYPE_ARRAY;
26 const GVariantType* _G_VARIANT_TYPE_TUPLE = G_VARIANT_TYPE_TUPLE;
27 const GVariantType* _G_VARIANT_TYPE_UNIT = G_VARIANT_TYPE_UNIT;
28 const GVariantType* _G_VARIANT_TYPE_DICT_ENTRY = G_VARIANT_TYPE_DICT_ENTRY;
29 const GVariantType* _G_VARIANT_TYPE_DICTIONARY = G_VARIANT_TYPE_DICTIONARY;
30 const GVariantType* _G_VARIANT_TYPE_STRING_ARRAY = G_VARIANT_TYPE_STRING_ARRAY;
31 const GVariantType* _G_VARIANT_TYPE_OBJECT_PATH_ARRAY = G_VARIANT_TYPE_OBJECT_PATH_ARRAY;
32 const GVariantType* _G_VARIANT_TYPE_BYTESTRING = G_VARIANT_TYPE_BYTESTRING;
33 const GVariantType* _G_VARIANT_TYPE_BYTESTRING_ARRAY = G_VARIANT_TYPE_BYTESTRING_ARRAY;
34 const GVariantType* _G_VARIANT_TYPE_VARDICT = G_VARIANT_TYPE_VARDICT;
8 const GVariantType *_G_VARIANT_TYPE_BOOLEAN = G_VARIANT_TYPE_BOOLEAN;
9 const GVariantType *_G_VARIANT_TYPE_BYTE = G_VARIANT_TYPE_BYTE;
10 const GVariantType *_G_VARIANT_TYPE_INT16 = G_VARIANT_TYPE_INT16;
11 const GVariantType *_G_VARIANT_TYPE_UINT16 = G_VARIANT_TYPE_UINT16;
12 const GVariantType *_G_VARIANT_TYPE_INT32 = G_VARIANT_TYPE_INT32;
13 const GVariantType *_G_VARIANT_TYPE_UINT32 = G_VARIANT_TYPE_UINT32;
14 const GVariantType *_G_VARIANT_TYPE_INT64 = G_VARIANT_TYPE_INT64;
15 const GVariantType *_G_VARIANT_TYPE_UINT64 = G_VARIANT_TYPE_UINT64;
16 const GVariantType *_G_VARIANT_TYPE_HANDLE = G_VARIANT_TYPE_HANDLE;
17 const GVariantType *_G_VARIANT_TYPE_DOUBLE = G_VARIANT_TYPE_DOUBLE;
18 const GVariantType *_G_VARIANT_TYPE_STRING = G_VARIANT_TYPE_STRING;
19 const GVariantType *_G_VARIANT_TYPE_OBJECT_PATH = G_VARIANT_TYPE_OBJECT_PATH;
20 const GVariantType *_G_VARIANT_TYPE_SIGNATURE = G_VARIANT_TYPE_SIGNATURE;
21 const GVariantType *_G_VARIANT_TYPE_VARIANT = G_VARIANT_TYPE_VARIANT;
22 const GVariantType *_G_VARIANT_TYPE_ANY = G_VARIANT_TYPE_ANY;
23 const GVariantType *_G_VARIANT_TYPE_BASIC = G_VARIANT_TYPE_BASIC;
24 const GVariantType *_G_VARIANT_TYPE_MAYBE = G_VARIANT_TYPE_MAYBE;
25 const GVariantType *_G_VARIANT_TYPE_ARRAY = G_VARIANT_TYPE_ARRAY;
26 const GVariantType *_G_VARIANT_TYPE_TUPLE = G_VARIANT_TYPE_TUPLE;
27 const GVariantType *_G_VARIANT_TYPE_UNIT = G_VARIANT_TYPE_UNIT;
28 const GVariantType *_G_VARIANT_TYPE_DICT_ENTRY = G_VARIANT_TYPE_DICT_ENTRY;
29 const GVariantType *_G_VARIANT_TYPE_DICTIONARY = G_VARIANT_TYPE_DICTIONARY;
30 const GVariantType *_G_VARIANT_TYPE_STRING_ARRAY = G_VARIANT_TYPE_STRING_ARRAY;
31 const GVariantType *_G_VARIANT_TYPE_OBJECT_PATH_ARRAY =
32 G_VARIANT_TYPE_OBJECT_PATH_ARRAY;
33 const GVariantType *_G_VARIANT_TYPE_BYTESTRING = G_VARIANT_TYPE_BYTESTRING;
34 const GVariantType *_G_VARIANT_TYPE_BYTESTRING_ARRAY =
35 G_VARIANT_TYPE_BYTESTRING_ARRAY;
36 const GVariantType *_G_VARIANT_TYPE_VARDICT = G_VARIANT_TYPE_VARDICT;
3537
3638 #endif
0 // Same copyright and license as the rest of the files in this project
1
2 package glib_test
3
4 import (
5 "testing"
6
7 "github.com/gotk3/gotk3/glib"
8 )
9
10 func TestVariantTypeEqual(t *testing.T) {
11 testCases := []struct {
12 desc string
13 type1 *glib.VariantType
14 type2 *glib.VariantType
15 expected bool
16 }{
17 {
18 desc: "bool == bool constants",
19 type1: glib.VARIANT_TYPE_BOOLEAN,
20 type2: glib.VARIANT_TYPE_BOOLEAN,
21 expected: true,
22 },
23 {
24 desc: "bool != string constants",
25 type1: glib.VARIANT_TYPE_BOOLEAN,
26 type2: glib.VARIANT_TYPE_STRING,
27 expected: false,
28 },
29 {
30 desc: "bool == bool dynamic",
31 type1: glib.VARIANT_TYPE_BOOLEAN,
32 type2: glib.VariantTypeNew("b"),
33 expected: true,
34 },
35 {
36 desc: "bool != string dynamic",
37 type1: glib.VariantTypeNew("b"),
38 type2: glib.VariantTypeNew("s"),
39 expected: false,
40 },
41 }
42 for _, tC := range testCases {
43 t.Run(tC.desc, func(t *testing.T) {
44 actual := glib.VariantTypeEqual(tC.type1, tC.type2)
45 if tC.expected != actual {
46 t.Error("Expected", tC.expected, "got", actual)
47 }
48 })
49 }
50 }
51
52 func TestVariantTypeStringIsValid(t *testing.T) {
53 testCases := []struct {
54 desc string
55 input string
56 expected bool
57 }{
58 {
59 desc: "String",
60 input: "s",
61 expected: true,
62 },
63 {
64 desc: "Boolean",
65 input: "b",
66 expected: true,
67 },
68 {
69 desc: "Tuple of String and Boolean",
70 input: "(sb)",
71 expected: true,
72 },
73 {
74 desc: "Junk",
75 input: "r{{sb}",
76 expected: false,
77 },
78 }
79 for _, tC := range testCases {
80 t.Run(tC.desc, func(t *testing.T) {
81 actual := glib.VariantTypeStringIsValid(tC.input)
82 if tC.expected != actual {
83 t.Error("Expected", tC.expected, "got", actual)
84 }
85 })
86 }
87 }
88
89 func TestVariantIsSubtypeOf(t *testing.T) {
90 testCases := []struct {
91 desc string
92 type1 *glib.VariantType
93 superType *glib.VariantType
94 expected bool
95 }{
96 {
97 desc: "bool is not a supertype",
98 type1: glib.VARIANT_TYPE_STRING,
99 superType: glib.VARIANT_TYPE_BOOLEAN,
100 expected: false,
101 },
102 {
103 desc: "a* is supertype of as",
104 type1: glib.VariantTypeNew("as"),
105 superType: glib.VariantTypeNew("a*"),
106 expected: true,
107 },
108 }
109 for _, tC := range testCases {
110 t.Run(tC.desc, func(t *testing.T) {
111 actual := tC.type1.IsSubtypeOf(tC.superType)
112 if tC.expected != actual {
113 t.Error("Expected", tC.expected, "got", actual)
114 }
115 })
116 }
117 }
33 // #include <glib-object.h>
44 // #include "glib.go.h"
55 import "C"
6 import "unsafe"
6 import (
7 "unsafe"
8 )
79
810 /*
911 * Linked Lists
1214 // List is a representation of Glib's GList.
1315 type List struct {
1416 list *C.struct__GList
15 // If set, dataWrap is called every time NthDataWrapped()
16 // or DataWrapped() is called to wrap raw underlying
17 // If set, dataWrap is called every time NthData()
18 // or Data() is called to wrap raw underlying
1719 // value into appropriate type.
1820 dataWrap func(unsafe.Pointer) interface{}
1921 }
5052 return v.list
5153 }
5254
53 // DataWapper sets wrap functions, which is called during NthDataWrapped()
54 // and DataWrapped(). It's used to cast raw C data into appropriate
55 // DataWapper sets wrap functions, which is called during NthData()
56 // and Data(). It's used to cast raw C data into appropriate
5557 // Go structures and types every time that data is retreived.
5658 func (v *List) DataWrapper(fn func(unsafe.Pointer) interface{}) {
5759 if v == nil {
9597 return list
9698 }
9799
98 // NthDataWrapped acts the same as g_list_nth_data(), but passes
100 // NthData acts the same as g_list_nth_data(), but passes
99101 // retrieved value before returning through wrap function, set by DataWrapper().
100102 // If no wrap function is set, it returns raw unsafe.Pointer.
101103 func (v *List) NthData(n uint) interface{} {
121123 return v.wrapNewHead(v.native().prev)
122124 }
123125
126 // First is a wrapper around g_list_first().
127 func (v *List) First() *List {
128 return v.wrapNewHead(C.g_list_first(v.native()))
129 }
130
131 // Last is a wrapper around g_list_last().
132 func (v *List) Last() *List {
133 return v.wrapNewHead(C.g_list_last(v.native()))
134 }
135
136 // Reverse is a wrapper around g_list_reverse().
137 func (v *List) Reverse() *List {
138 return v.wrapNewHead(C.g_list_reverse(v.native()))
139 }
140
124141 // dataRaw is a wrapper around the data struct field
125142 func (v *List) dataRaw() unsafe.Pointer {
126143 return unsafe.Pointer(v.native().data)
127144 }
128145
129 // DataWrapped acts the same as data struct field, but passes
146 // Data acts the same as data struct field, but passes
130147 // retrieved value before returning through wrap function, set by DataWrapper().
131148 // If no wrap function is set, it returns raw unsafe.Pointer.
132149 func (v *List) Data() interface{} {
152169 v.Foreach(fn)
153170 v.Free()
154171 }
172
173 // CompareDataFunc is a representation of GCompareDataFunc
174 type CompareDataFunc func(a, b uintptr) int
66 import "C"
77 import "unsafe"
88
9 // Predefined attribute names for GMenu
10 var (
11 MENU_ATTRIBUTE_ACTION string = C.G_MENU_ATTRIBUTE_ACTION
12 MENU_ATTRIBUTE_ACTION_NAMESPACE string = C.G_MENU_ATTRIBUTE_ACTION_NAMESPACE
13 MENU_ATTRIBUTE_TARGET string = C.G_MENU_ATTRIBUTE_TARGET
14 MENU_ATTRIBUTE_LABEL string = C.G_MENU_ATTRIBUTE_LABEL
15 MENU_ATTRIBUTE_ICON string = C.G_MENU_ATTRIBUTE_ICON
16 )
17
18 // Predefined link names for GMenu
19 var (
20 MENU_LINK_SECTION string = C.G_MENU_LINK_SECTION
21 MENU_LINK_SUBMENU string = C.G_MENU_LINK_SUBMENU
22 )
23
924 // MenuModel is a representation of GMenuModel.
1025 type MenuModel struct {
1126 *Object
1227 }
1328
14 // native() returns a pointer to the underlying GMenuModel.
29 // native returns a pointer to the underlying GMenuModel.
1530 func (v *MenuModel) native() *C.GMenuModel {
1631 if v == nil || v.GObject == nil {
1732 return nil
1934 return C.toGMenuModel(unsafe.Pointer(v.GObject))
2035 }
2136
37 // Native returns a pointer to the underlying GMenuModel.
2238 func (v *MenuModel) Native() uintptr {
2339 return uintptr(unsafe.Pointer(v.native()))
2440 }
6985 }
7086
7187 // native() returns a pointer to the underlying GMenu.
72 func (m *Menu) native() *C.GMenu {
73 if m == nil || m.GObject == nil {
74 return nil
75 }
76 p := unsafe.Pointer(m.GObject)
88 func (v *Menu) native() *C.GMenu {
89 if v == nil || v.GObject == nil {
90 return nil
91 }
92 p := unsafe.Pointer(v.GObject)
7793 return C.toGMenu(p)
7894 }
7995
101117 }
102118
103119 // Insert is a wrapper around g_menu_insert().
104 func (v *Menu) Insert(position int, label, detailed_action string) {
105 cstr1 := (*C.gchar)(C.CString(label))
106 defer C.free(unsafe.Pointer(cstr1))
107
108 cstr2 := (*C.gchar)(C.CString(detailed_action))
120 func (v *Menu) Insert(position int, label, detailedAction string) {
121 cstr1 := (*C.gchar)(C.CString(label))
122 defer C.free(unsafe.Pointer(cstr1))
123
124 cstr2 := (*C.gchar)(C.CString(detailedAction))
109125 defer C.free(unsafe.Pointer(cstr2))
110126
111127 C.g_menu_insert(v.native(), C.gint(position), cstr1, cstr2)
112128 }
113129
114130 // Prepend is a wrapper around g_menu_prepend().
115 func (v *Menu) Prepend(label, detailed_action string) {
116 cstr1 := (*C.gchar)(C.CString(label))
117 defer C.free(unsafe.Pointer(cstr1))
118
119 cstr2 := (*C.gchar)(C.CString(detailed_action))
131 func (v *Menu) Prepend(label, detailedAction string) {
132 cstr1 := (*C.gchar)(C.CString(label))
133 defer C.free(unsafe.Pointer(cstr1))
134
135 cstr2 := (*C.gchar)(C.CString(detailedAction))
120136 defer C.free(unsafe.Pointer(cstr2))
121137
122138 C.g_menu_prepend(v.native(), cstr1, cstr2)
123139 }
124140
125141 // Append is a wrapper around g_menu_append().
126 func (v *Menu) Append(label, detailed_action string) {
127 cstr1 := (*C.gchar)(C.CString(label))
128 defer C.free(unsafe.Pointer(cstr1))
129
130 cstr2 := (*C.gchar)(C.CString(detailed_action))
142 func (v *Menu) Append(label, detailedAction string) {
143 cstr1 := (*C.gchar)(C.CString(label))
144 defer C.free(unsafe.Pointer(cstr1))
145
146 cstr2 := (*C.gchar)(C.CString(detailedAction))
131147 defer C.free(unsafe.Pointer(cstr2))
132148
133149 C.g_menu_append(v.native(), cstr1, cstr2)
230246 }
231247
232248 // native() returns a pointer to the underlying GMenuItem.
233 func (m *MenuItem) native() *C.GMenuItem {
234 if m == nil || m.GObject == nil {
235 return nil
236 }
237 p := unsafe.Pointer(m.GObject)
249 func (v *MenuItem) native() *C.GMenuItem {
250 if v == nil || v.GObject == nil {
251 return nil
252 }
253 p := unsafe.Pointer(v.GObject)
238254 return C.toGMenuItem(p)
239255 }
240256
247263 return &MenuItem{obj}
248264 }
249265
250 // MenuItemNew is a wrapper around g_menu_item_new().
251 func MenuItemNew(label, detailed_action string) *MenuItem {
252 cstr1 := (*C.gchar)(C.CString(label))
253 defer C.free(unsafe.Pointer(cstr1))
254
255 cstr2 := (*C.gchar)(C.CString(detailed_action))
266 // MenuItemNew is a wrapper around g_menu_item_new(NULL, NULL).
267 func MenuItemNew() *MenuItem {
268 c := C.g_menu_item_new(nil, nil)
269 if c == nil {
270 return nil
271 }
272 return wrapMenuItem(wrapObject(unsafe.Pointer(c)))
273 }
274
275 // MenuItemNewWithLabel is a wrapper around g_menu_item_new(label, NULL).
276 func MenuItemNewWithLabel(label string) *MenuItem {
277 cstr1 := (*C.gchar)(C.CString(label))
278 defer C.free(unsafe.Pointer(cstr1))
279
280 c := C.g_menu_item_new(cstr1, nil)
281 if c == nil {
282 return nil
283 }
284 return wrapMenuItem(wrapObject(unsafe.Pointer(c)))
285 }
286
287 // MenuItemNewWithAction is a wrapper around g_menu_item_new(NULL, detailedAction).
288 func MenuItemNewWithAction(detailedAction string) *MenuItem {
289 cstr1 := (*C.gchar)(C.CString(detailedAction))
290 defer C.free(unsafe.Pointer(cstr1))
291
292 c := C.g_menu_item_new(nil, cstr1)
293 if c == nil {
294 return nil
295 }
296 return wrapMenuItem(wrapObject(unsafe.Pointer(c)))
297 }
298
299 // MenuItemNewWithLabelAndAction is a wrapper around g_menu_item_new(label, detailedAction).
300 func MenuItemNewWithLabelAndAction(label, detailedAction string) *MenuItem {
301 cstr1 := (*C.gchar)(C.CString(label))
302 defer C.free(unsafe.Pointer(cstr1))
303
304 cstr2 := (*C.gchar)(C.CString(detailedAction))
256305 defer C.free(unsafe.Pointer(cstr2))
257306
258307 c := C.g_menu_item_new(cstr1, cstr2)
295344 return wrapMenuItem(wrapObject(unsafe.Pointer(c)))
296345 }
297346
298 //SetLabel is a wrapper around g_menu_item_set_label().
347 // SetLabel is a wrapper around g_menu_item_set_label().
299348 func (v *MenuItem) SetLabel(label string) {
300349 cstr1 := (*C.gchar)(C.CString(label))
301350 defer C.free(unsafe.Pointer(cstr1))
303352 C.g_menu_item_set_label(v.native(), cstr1)
304353 }
305354
306 //SetDetailedAction is a wrapper around g_menu_item_set_detailed_action().
355 // UnsetLabel is a wrapper around g_menu_item_set_label(NULL).
356 func (v *MenuItem) UnsetLabel() {
357 C.g_menu_item_set_label(v.native(), nil)
358 }
359
360 // SetDetailedAction is a wrapper around g_menu_item_set_detailed_action().
307361 func (v *MenuItem) SetDetailedAction(act string) {
308362 cstr1 := (*C.gchar)(C.CString(act))
309363 defer C.free(unsafe.Pointer(cstr1))
311365 C.g_menu_item_set_detailed_action(v.native(), cstr1)
312366 }
313367
314 //SetSection is a wrapper around g_menu_item_set_section().
368 // SetSection is a wrapper around g_menu_item_set_section().
315369 func (v *MenuItem) SetSection(section *MenuModel) {
316370 C.g_menu_item_set_section(v.native(), section.native())
317371 }
318372
319 //SetSubmenu is a wrapper around g_menu_item_set_submenu().
373 // SetSubmenu is a wrapper around g_menu_item_set_submenu().
320374 func (v *MenuItem) SetSubmenu(submenu *MenuModel) {
321375 C.g_menu_item_set_submenu(v.native(), submenu.native())
322376 }
323377
324 //GetLink is a wrapper around g_menu_item_get_link().
378 // GetLink is a wrapper around g_menu_item_get_link().
325379 func (v *MenuItem) GetLink(link string) *MenuModel {
326380 cstr1 := (*C.gchar)(C.CString(link))
327381 defer C.free(unsafe.Pointer(cstr1))
333387 return wrapMenuModel(wrapObject(unsafe.Pointer(c)))
334388 }
335389
336 //SetLink is a wrapper around g_menu_item_Set_link().
390 // SetLink is a wrapper around g_menu_item_Set_link().
337391 func (v *MenuItem) SetLink(link string, model *MenuModel) {
338392 cstr1 := (*C.gchar)(C.CString(link))
339393 defer C.free(unsafe.Pointer(cstr1))
341395 C.g_menu_item_set_link(v.native(), cstr1, model.native())
342396 }
343397
344 // void g_menu_item_set_action_and_target_value ()
398 // SetActionAndTargetValue is a wrapper around g_menu_item_set_action_and_target_value()
399 func (v *MenuItem) SetActionAndTargetValue(action string, targetValue IVariant) {
400 cstr1 := (*C.gchar)(C.CString(action))
401 defer C.free(unsafe.Pointer(cstr1))
402
403 var c *C.GVariant
404 if targetValue != nil {
405 c = targetValue.ToGVariant()
406 }
407
408 C.g_menu_item_set_action_and_target_value(v.native(), cstr1, c)
409 }
410
411 // UnsetAction is a wrapper around g_menu_item_set_action_and_target_value(NULL, NULL)
412 // Unsets both action and target value. Unsetting the action also clears the target value.
413 func (v *MenuItem) UnsetAction() {
414 C.g_menu_item_set_action_and_target_value(v.native(), nil, nil)
415 }
416
417 // SetAttributeValue is a wrapper around g_menu_item_set_attribute_value()
418 func (v *MenuItem) SetAttributeValue(attribute string, value IVariant) {
419 var c *C.GVariant
420 if value != nil {
421 c = value.ToGVariant()
422 }
423
424 cstr1 := (*C.gchar)(C.CString(attribute))
425 defer C.free(unsafe.Pointer(cstr1))
426
427 C.g_menu_item_set_attribute_value(v.native(), cstr1, c)
428 }
429
430 // GetAttributeValue is a wrapper around g_menu_item_get_attribute_value()
431 func (v *MenuItem) GetAttributeValue(attribute string, expectedType *VariantType) *Variant {
432 cstr1 := (*C.gchar)(C.CString(attribute))
433 defer C.free(unsafe.Pointer(cstr1))
434
435 c := C.g_menu_item_get_attribute_value(v.native(), cstr1, expectedType.native())
436 if c == nil {
437 return nil
438 }
439 return newVariant(c)
440 }
441
442 // TODO: These require positional parameters with *any* type, according to the format string passed.
443 // This is likely not possible to represent 1:1 in go.
444 // gboolean g_menu_item_get_attribute ()
445 // void g_menu_item_set_attribute ()
345446 // void g_menu_item_set_action_and_target ()
346 // GVariant * g_menu_item_get_attribute_value ()
347 // gboolean g_menu_item_get_attribute ()
348 // void g_menu_item_set_attribute_value ()
349 // void g_menu_item_set_attribute ()
0 package glib_test
1
2 import (
3 "testing"
4
5 "github.com/gotk3/gotk3/glib"
6 )
7
8 func TestGetSetAttributeValueCustomBool(t *testing.T) {
9 testCases := []struct {
10 desc string
11 value bool
12 }{
13 {
14 desc: "true",
15 value: true,
16 },
17 {
18 desc: "false",
19 value: false,
20 },
21 }
22
23 menuItem := glib.MenuItemNew()
24
25 for _, tC := range testCases {
26 t.Run(tC.desc, func(t *testing.T) {
27 variant := glib.VariantFromBoolean(tC.value)
28
29 menuItem.SetAttributeValue("custom-bool-attribute", variant)
30 actual := menuItem.GetAttributeValue("custom-bool-attribute", glib.VARIANT_TYPE_BOOLEAN)
31
32 if !actual.IsType(glib.VARIANT_TYPE_BOOLEAN) {
33 t.Error("Expected value of type", glib.VARIANT_TYPE_BOOLEAN, "got", actual.Type())
34 }
35
36 if tC.value != actual.GetBoolean() {
37 t.Error("Expected", tC.value, "got", actual)
38 }
39 })
40 }
41 }
42
43 func TestUnsetLabel(t *testing.T) {
44 menuItem := glib.MenuItemNewWithLabel("unit_label")
45
46 menuItem.UnsetLabel()
47
48 value := menuItem.GetAttributeValue(glib.MENU_ATTRIBUTE_LABEL, glib.VARIANT_TYPE_STRING)
49 actual := value.GetString()
50
51 if "" != actual {
52 t.Error("Expected empty string, got", actual)
53 }
54 }
55
56 func TestSetLabel(t *testing.T) {
57 menuItem := glib.MenuItemNewWithLabel("unit_label")
58
59 expected := "New Label"
60 menuItem.SetLabel(expected)
61
62 value := menuItem.GetAttributeValue(glib.MENU_ATTRIBUTE_LABEL, glib.VARIANT_TYPE_STRING)
63 actual := value.GetString()
64
65 if expected != actual {
66 t.Error("Expected", expected, "got", actual)
67 }
68 }
69
70 func TestSetDetailedAction(t *testing.T) {
71 menuItem := glib.MenuItemNewWithAction("unit_action")
72
73 expected := "new-action"
74 menuItem.SetDetailedAction(expected)
75
76 value := menuItem.GetAttributeValue(glib.MENU_ATTRIBUTE_ACTION, glib.VARIANT_TYPE_STRING)
77 actual := value.GetString()
78
79 if expected != actual {
80 t.Error("Expected", expected, "got", actual)
81 }
82 }
83
84 func TestSetActionAndTargetValue(t *testing.T) {
85 menuItem := glib.MenuItemNew()
86
87 t.Run("Action, Value", func(t *testing.T) {
88 expectedValue := glib.VariantFromString("Hello!")
89 expected := "act1"
90 menuItem.SetActionAndTargetValue(expected, expectedValue)
91
92 // Check target value
93 actualValue := menuItem.GetAttributeValue(glib.MENU_ATTRIBUTE_TARGET, glib.VARIANT_TYPE_STRING)
94 if expectedValue.Native() != actualValue.Native() {
95 t.Error("Expected", expectedValue.Native(), "got", actualValue.Native())
96 }
97
98 // Check action value
99 actualAction := menuItem.GetAttributeValue(glib.MENU_ATTRIBUTE_ACTION, glib.VARIANT_TYPE_STRING).GetString()
100 if expected != actualAction {
101 t.Error("Expected", expected, "got", actualAction)
102 }
103 })
104 t.Run("Action, Null Value", func(t *testing.T) {
105 expected := "act2"
106 menuItem.SetActionAndTargetValue(expected, nil)
107
108 // Check target value
109 actualValue := menuItem.GetAttributeValue(glib.MENU_ATTRIBUTE_TARGET, glib.VARIANT_TYPE_STRING)
110 if actualValue != nil {
111 t.Error("Expected nil value got", actualValue.Native())
112 }
113
114 // Check action value
115 actualAction := menuItem.GetAttributeValue(glib.MENU_ATTRIBUTE_ACTION, glib.VARIANT_TYPE_STRING).GetString()
116 if expected != actualAction {
117 t.Error("Expected", expected, "got", actualAction)
118 }
119 })
120 }
121
122 func TestUnsetAction(t *testing.T) {
123 menuItem := glib.MenuItemNew()
124
125 initialValue := glib.VariantFromString("Hello!")
126 initial := "act1"
127 menuItem.SetActionAndTargetValue(initial, initialValue)
128
129 menuItem.UnsetAction()
130
131 // Check target value
132 actualValue := menuItem.GetAttributeValue(glib.MENU_ATTRIBUTE_TARGET, glib.VARIANT_TYPE_STRING)
133 if actualValue != nil {
134 t.Error("Expected nil value got", actualValue.Native())
135 }
136
137 // Check action value
138 actualAction := menuItem.GetAttributeValue(glib.MENU_ATTRIBUTE_ACTION, glib.VARIANT_TYPE_STRING)
139 if actualAction != nil {
140 t.Error("Expected nil action got", actualAction.Native())
141 }
142 }
55 // #include "glib.go.h"
66 import "C"
77 import "unsafe"
8
9 // Only available from 2.42
10 // // NotificationPriority is a representation of GLib's GNotificationPriority.
11 // type NotificationPriority int
12
13 // const (
14 // NOTIFICATION_PRIORITY_NORMAL NotificationPriority = C.G_NOTIFICATION_PRIORITY_NORMAL
15 // NOTIFICATION_PRIORITY_LOW NotificationPriority = C.G_NOTIFICATION_PRIORITY_LOW
16 // NOTIFICATION_PRIORITY_HIGH NotificationPriority = C.G_NOTIFICATION_PRIORITY_HIGH
17 // NOTIFICATION_PRIORITY_URGENT NotificationPriority = C.G_NOTIFICATION_PRIORITY_URGENT
18 // )
198
209 // Notification is a representation of GNotification.
2110 type Notification struct {
7160 C.g_notification_set_body(v.native(), cstr1)
7261 }
7362
74 // Only available from 2.42
75 // // SetPriority is a wrapper around g_notification_set_priority().
76 // func (v *Notification) SetPriority(prio NotificationPriority) {
77 // C.g_notification_set_priority(v.native(), C.GNotificationPriority(prio))
78 // }
79
8063 // SetDefaultAction is a wrapper around g_notification_set_default_action().
8164 func (v *Notification) SetDefaultAction(detailedAction string) {
8265 cstr1 := (*C.gchar)(C.CString(detailedAction))
9679 C.g_notification_add_button(v.native(), cstr1, cstr2)
9780 }
9881
82 // SetIcon is a wrapper around g_notification_set_icon().
83 func (v *Notification) SetIcon(iconPath string) {
84 fileIcon := FileIconNew(iconPath)
85
86 C.g_notification_set_icon(v.native(), (*C.GIcon)(fileIcon.native()))
87 }
88
9989 // void g_notification_set_default_action_and_target () // requires varargs
10090 // void g_notification_set_default_action_and_target_value () // requires variant
10191 // void g_notification_add_button_with_target () // requires varargs
10292 // void g_notification_add_button_with_target_value () //requires variant
10393 // void g_notification_set_urgent () // Deprecated, so not implemented
104 // void g_notification_set_icon () // Requires support for GIcon, which we don't have yet.
0 package glib
1
2 import (
3 "unsafe"
4 )
5
6 // #include <glib.h>
7 // #include <stdlib.h>
8 import "C"
9
10 // QuarkFromString is a wrapper around g_quark_from_string().
11 func QuarkFromString(str string) Quark {
12 cstr := (*C.gchar)(C.CString(str))
13 defer C.free(unsafe.Pointer(cstr))
14
15 return Quark(C.g_quark_from_string(cstr))
16 }
99 // by either calling Free() or FreeFull()
1010 type SList struct {
1111 list *C.struct__GSList
12 // If set, dataWrap is called every time Data()
13 // is called to wrap raw underlying
14 // value into appropriate type.
15 dataWrap func(unsafe.Pointer) interface{}
1216 }
1317
1418 func WrapSList(obj uintptr) *SList {
2327 //NOTE a list should be freed by calling either
2428 //g_slist_free() or g_slist_free_full(). However, it's not possible to use a
2529 //finalizer for this.
26 return &SList{obj}
30 return &SList{list: obj}
31 }
32
33 func (v *SList) wrapNewHead(obj *C.struct__GSList) *SList {
34 if obj == nil {
35 return nil
36 }
37 return &SList{
38 list: obj,
39 dataWrap: v.dataWrap,
40 }
2741 }
2842
2943 func (v *SList) Native() uintptr {
3549 return nil
3650 }
3751 return v.list
52 }
53
54 // DataWapper sets wrap functions, which is called during NthData()
55 // and Data(). It's used to cast raw C data into appropriate
56 // Go structures and types every time that data is retreived.
57 func (v *SList) DataWrapper(fn func(unsafe.Pointer) interface{}) {
58 if v == nil {
59 return
60 }
61 v.dataWrap = fn
3862 }
3963
4064 func (v *SList) Append(data uintptr) *SList {
6185 return wrapSList(n.next)
6286 }
6387
88 // dataRaw is a wrapper around the data struct field
89 func (v *SList) dataRaw() unsafe.Pointer {
90 n := v.native()
91 if n == nil {
92 return nil
93 }
94 return unsafe.Pointer(n.data)
95 }
96
97 // DataRaw is a wrapper around the data struct field
98 func (v *SList) DataRaw() unsafe.Pointer {
99 n := v.native()
100 if n == nil {
101 return nil
102 }
103 return unsafe.Pointer(n.data)
104 }
105
106 // Data acts the same as data struct field, but it returns raw unsafe.Pointer as interface.
107 // TODO: Align with List struct and add member + logic for `dataWrap func(unsafe.Pointer) interface{}`?
108 func (v *SList) Data() interface{} {
109 ptr := v.dataRaw()
110 if v.dataWrap != nil {
111 return v.dataWrap(ptr)
112 }
113 return ptr
114 }
115
64116 // Foreach acts the same as g_slist_foreach().
65117 // No user_data argument is implemented because of Go clojure capabilities.
66 func (v *SList) Foreach(fn func(ptr unsafe.Pointer)) {
118 func (v *SList) Foreach(fn func(item interface{})) {
67119 for l := v; l != nil; l = l.Next() {
68 fn(unsafe.Pointer(l.native().data))
120 fn(l.Data())
69121 }
70122 }
71123
72124 // Free is a wrapper around g_slist_free().
73125 func (v *SList) Free() {
74126 C.g_slist_free(v.native())
75 v.list = nil
76127 }
77128
78129 // FreeFull is a wrapper around g_slist_free_full().
79130 func (v *SList) FreeFull() {
80131 //TODO implement GDestroyNotify callback
81132 C.g_slist_free_full(v.native(), nil)
82 v.list = nil
83133 }
84134
85135 // GSList * g_slist_alloc ()
0 module github.com/gotk3/gotk3
1
2 go 1.14
4444 }
4545
4646 func wrapAboutDialog(obj *glib.Object) *AboutDialog {
47 if obj == nil {
48 return nil
49 }
50
4751 return &AboutDialog{Dialog{Window{Bin{Container{Widget{glib.InitiallyUnowned{obj}}}}}}}
4852 }
4953
162166 break
163167 }
164168 authors = append(authors, C.GoString((*C.char)(*cauthors)))
165 cauthors = C.next_gcharptr(cauthors)
169 cauthors = nextgcharptr(cauthors)
166170 }
167171 return authors
168172 }
193197 break
194198 }
195199 artists = append(artists, C.GoString((*C.char)(*cartists)))
196 cartists = C.next_gcharptr(cartists)
200 cartists = nextgcharptr(cartists)
197201 }
198202 return artists
199203 }
224228 break
225229 }
226230 documenters = append(documenters, C.GoString((*C.char)(*cdocumenters)))
227 cdocumenters = C.next_gcharptr(cdocumenters)
231 cdocumenters = nextgcharptr(cdocumenters)
228232 }
229233 return documenters
230234 }
6868 }
6969
7070 /*
71 * GtkAccelLabel
72 */
73
74 // TODO:
75 // gtk_accel_label_new().
76 // gtk_accel_label_set_accel_closure().
77 // gtk_accel_label_get_accel_widget().
78 // gtk_accel_label_set_accel_widget().
79 // gtk_accel_label_get_accel_width().
80 // gtk_accel_label_set_accel(). since GTK 3.6
81 // gtk_accel_label_get_accel(). since GTK 3.12
82 // gtk_accel_label_refetch().
83
84 /*
7185 * GtkAccelGroup
7286 */
7387
92106 }
93107
94108 func wrapAccelGroup(obj *glib.Object) *AccelGroup {
109 if obj == nil {
110 return nil
111 }
112
95113 return &AccelGroup{obj}
96114 }
97115
107125
108126 // Connect is a wrapper around gtk_accel_group_connect().
109127 func (v *AccelGroup) Connect(key uint, mods gdk.ModifierType, flags AccelFlags, f interface{}) {
110 closure, _ := glib.ClosureNew(f)
128 closure := glib.ClosureNew(f)
111129 cl := (*C.struct__GClosure)(unsafe.Pointer(closure))
112130 C.gtk_accel_group_connect(
113131 v.native(),
119137
120138 // ConnectByPath is a wrapper around gtk_accel_group_connect_by_path().
121139 func (v *AccelGroup) ConnectByPath(path string, f interface{}) {
122 closure, _ := glib.ClosureNew(f)
140 closure := glib.ClosureNew(f)
123141 cl := (*C.struct__GClosure)(unsafe.Pointer(closure))
124142
125143 cstr := C.CString(path)
133151
134152 // Disconnect is a wrapper around gtk_accel_group_disconnect().
135153 func (v *AccelGroup) Disconnect(f interface{}) {
136 closure, _ := glib.ClosureNew(f)
154 closure := glib.ClosureNew(f)
137155 cl := (*C.struct__GClosure)(unsafe.Pointer(closure))
138156 C.gtk_accel_group_disconnect(v.native(), cl)
139157 }
160178
161179 // AccelGroupFromClosure is a wrapper around gtk_accel_group_from_accel_closure().
162180 func AccelGroupFromClosure(f interface{}) *AccelGroup {
163 closure, _ := glib.ClosureNew(f)
181 closure := glib.ClosureNew(f)
164182 cl := (*C.struct__GClosure)(unsafe.Pointer(closure))
165183 c := C.gtk_accel_group_from_accel_closure(cl)
166184 if c == nil {
190208 if res == nil {
191209 return nil
192210 }
211
212 // TODO: call DataWrapper on SList and wrap them to gtk.AccelGroup
213
193214 return (*glib.SList)(unsafe.Pointer(res))
194215 }
195216
218239 }
219240
220241 func wrapAccelMap(obj *glib.Object) *AccelMap {
242 if obj == nil {
243 return nil
244 }
245
221246 return &AccelMap{obj}
222247 }
223248
229254 C.gtk_accel_map_add_entry((*C.gchar)(cstr), C.guint(key), C.GdkModifierType(mods))
230255 }
231256
232 type AccelKey struct {
233 key uint
234 mods gdk.ModifierType
235 flags uint16
236 }
237
238 func (v *AccelKey) native() *C.struct__GtkAccelKey {
257 type AccelKey C.GtkAccelKey
258
259 func (v *AccelKey) native() *C.GtkAccelKey {
239260 if v == nil {
240261 return nil
241262 }
242
243 var val C.struct__GtkAccelKey
244 val.accel_key = C.guint(v.key)
245 val.accel_mods = C.GdkModifierType(v.mods)
246 val.accel_flags = v.flags
247 return &val
248 }
249
250 func wrapAccelKey(obj *C.struct__GtkAccelKey) *AccelKey {
251 var v AccelKey
252
253 v.key = uint(obj.accel_key)
254 v.mods = gdk.ModifierType(obj.accel_mods)
255 v.flags = uint16(obj.accel_flags)
256
257 return &v
263 return (*C.GtkAccelKey)(v)
258264 }
259265
260266 // AccelMapLookupEntry is a wrapper around gtk_accel_map_lookup_entry().
262268 cstr := C.CString(path)
263269 defer C.free(unsafe.Pointer(cstr))
264270
265 var v *C.struct__GtkAccelKey
266
267 C.gtk_accel_map_lookup_entry((*C.gchar)(cstr), v)
268 return wrapAccelKey(v)
271 var v = new(AccelKey)
272
273 C.gtk_accel_map_lookup_entry((*C.gchar)(cstr), v.native())
274 return v
269275 }
270276
271277 // AccelMapChangeEntry is a wrapper around gtk_accel_map_change_entry().
416422 C.gtk_window_add_accel_group(v.native(), accelGroup.native())
417423 }
418424
419 // RemoveAccelGroup() is a wrapper around gtk_window_add_accel_group().
425 // RemoveAccelGroup() is a wrapper around gtk_window_remove_accel_group().
420426 func (v *Window) RemoveAccelGroup(accelGroup *AccelGroup) {
421427 C.gtk_window_remove_accel_group(v.native(), accelGroup.native())
422428 }
431437 // TODO: gtk_accel_map_foreach - can't be done without a function type
432438
433439 // TODO: gtk_accel_map_load_scanner
434 // TODO: gtk_widget_list_accel_closures
440
441 /*
442 * GtkWidget
443 */
444
445 // TODO:
446 // gtk_widget_list_accel_closures
5757 }
5858
5959 func wrapActionable(obj *glib.Object) *Actionable {
60 if obj == nil {
61 return nil
62 }
63
6064 return &Actionable{obj}
6165 }
6266
0 static GtkActionable *
1 toGtkActionable(void *p)
2 {
3 return (GTK_ACTIONABLE(p));
4 }
0 static GtkActionable *toGtkActionable(void *p) { return (GTK_ACTIONABLE(p)); }
4343 WrapMap["GtkActionBar"] = wrapActionBar
4444 }
4545
46 //GtkActionBar
46 // ActionBar is a representation of GtkActionBar
4747 type ActionBar struct {
4848 Bin
4949 }
6363 }
6464
6565 func wrapActionBar(obj *glib.Object) *ActionBar {
66 if obj == nil {
67 return nil
68 }
69
6670 return &ActionBar{Bin{Container{Widget{glib.InitiallyUnowned{obj}}}}}
6771 }
6872
69 //gtk_action_bar_new()
73 // ActionBarNew is a wrapper around gtk_action_bar_new()
7074 func ActionBarNew() (*ActionBar, error) {
7175 c := C.gtk_action_bar_new()
7276 if c == nil {
7579 return wrapActionBar(glib.Take(unsafe.Pointer(c))), nil
7680 }
7781
78 //gtk_action_bar_pack_start(GtkActionBar *action_bar,GtkWidget *child)
82 // PackStart is a wrapper around gtk_action_bar_pack_start().
7983 func (a *ActionBar) PackStart(child IWidget) {
8084 C.gtk_action_bar_pack_start(a.native(), child.toWidget())
8185 }
8286
83 //gtk_action_bar_pack_end(GtkActionBar *action_bar,GtkWidget *child)
87 // PackEnd is a wrapper around gtk_action_bar_pack_end().
8488 func (a *ActionBar) PackEnd(child IWidget) {
8589 C.gtk_action_bar_pack_end(a.native(), child.toWidget())
8690 }
8791
88 //gtk_action_bar_set_center_widget(GtkActionBar *action_bar,GtkWidget *center_widget)
92 // SetCenterWidget is a wrapper around gtk_action_bar_set_center_widget().
8993 func (a *ActionBar) SetCenterWidget(child IWidget) {
9094 if child == nil {
9195 C.gtk_action_bar_set_center_widget(a.native(), nil)
9498 }
9599 }
96100
97 //gtk_action_bar_get_center_widget(GtkActionBar *action_bar)
98 func (a *ActionBar) GetCenterWidget() *Widget {
101 // GetCenterWidget is a wrapper around gtk_action_bar_get_center_widget().
102 func (a *ActionBar) GetCenterWidget() (IWidget, error) {
99103 w := C.gtk_action_bar_get_center_widget(a.native())
100104 if w == nil {
101 return nil
105 return nil, nil
102106 }
103 return &Widget{glib.InitiallyUnowned{glib.Take(unsafe.Pointer(w))}}
107 return castWidget(w)
104108 }
1717 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1818 */
1919
20 static GtkActionBar *
21 toGtkActionBar(void *p)
22 {
23 return (GTK_ACTION_BAR(p));
24 }
20 static GtkActionBar *toGtkActionBar(void *p) { return (GTK_ACTION_BAR(p)); }
5757 }
5858
5959 func wrapAppChooser(obj *glib.Object) *AppChooser {
60 if obj == nil {
61 return nil
62 }
63
6064 return &AppChooser{obj}
6165 }
6266
110114 }
111115
112116 func wrapAppChooserButton(obj *glib.Object) *AppChooserButton {
117 if obj == nil {
118 return nil
119 }
120
113121 cl := wrapCellLayout(obj)
122 ce := wrapCellEditable(obj)
114123 ac := wrapAppChooser(obj)
115 return &AppChooserButton{ComboBox{Bin{Container{Widget{glib.InitiallyUnowned{obj}}}}, *cl}, *ac}
124 return &AppChooserButton{ComboBox{Bin{Container{Widget{glib.InitiallyUnowned{obj}}}}, *cl, *ce}, *ac}
116125 }
117126
118127 // AppChooserButtonNew() is a wrapper around gtk_app_chooser_button_new().
208217 }
209218
210219 func wrapAppChooserWidget(obj *glib.Object) *AppChooserWidget {
220 if obj == nil {
221 return nil
222 }
223
211224 box := wrapBox(obj)
212225 ac := wrapAppChooser(obj)
213226 return &AppChooserWidget{*box, *ac}
321334 }
322335
323336 func wrapAppChooserDialog(obj *glib.Object) *AppChooserDialog {
337 if obj == nil {
338 return nil
339 }
340
324341 dialog := wrapDialog(obj)
325342 ac := wrapAppChooser(obj)
326343 return &AppChooserDialog{*dialog, *ac}
327344 }
328345
329 // TODO: Uncomment when gio builds successfully
330 // AppChooserDialogNew() is a wrapper around gtk_app_chooser_dialog_new().
331 // func AppChooserDialogNew(parent IWindow, flags DialogFlags, file *gio.File) (*AppChooserDialog, error) {
332 // var gfile *C.GFile
333 // if file != nil {
334 // gfile = (*C.GFile)(unsafe.Pointer(file.Native()))
335 // }
336 // c := C.gtk_app_chooser_dialog_new(parent.toWindow(), C.GtkDialogFlags(flags), gfile)
337 // if c == nil {
338 // return nil, nilPtrErr
339 // }
340 // return wrapAppChooserDialog(glib.Take(unsafe.Pointer(c))), nil
341 // }
346 // AppChooserDialogNew is a wrapper around gtk_app_chooser_dialog_new().
347 func AppChooserDialogNew(parent IWindow, flags DialogFlags, file *glib.File) (*AppChooserDialog, error) {
348
349 var gfile *C.GFile
350 if file != nil {
351 gfile = (*C.GFile)(unsafe.Pointer(file.Native()))
352 }
353
354 var pw *C.GtkWindow = nil
355 if parent != nil {
356 pw = parent.toWindow()
357 }
358
359 c := C.gtk_app_chooser_dialog_new(pw, C.GtkDialogFlags(flags), gfile)
360 if c == nil {
361 return nil, nilPtrErr
362 }
363 return wrapAppChooserDialog(glib.Take(unsafe.Pointer(c))), nil
364 }
342365
343366 // AppChooserDialogNewForContentType() is a wrapper around gtk_app_chooser_dialog_new_for_content_type().
344367 func AppChooserDialogNewForContentType(parent IWindow, flags DialogFlags, content_type string) (*AppChooserDialog, error) {
368
345369 cstr := C.CString(content_type)
346370 defer C.free(unsafe.Pointer(cstr))
347 c := C.gtk_app_chooser_dialog_new_for_content_type(parent.toWindow(), C.GtkDialogFlags(flags), (*C.gchar)(cstr))
371
372 var pw *C.GtkWindow = nil
373 if parent != nil {
374 pw = parent.toWindow()
375 }
376
377 c := C.gtk_app_chooser_dialog_new_for_content_type(pw, C.GtkDialogFlags(flags), (*C.gchar)(cstr))
348378 if c == nil {
349379 return nil, nilPtrErr
350380 }
4646 }
4747
4848 func wrapApplication(obj *glib.Object) *Application {
49 if obj == nil {
50 return nil
51 }
52
4953 am := &glib.ActionMap{obj}
5054 ag := &glib.ActionGroup{obj}
5155 return &Application{glib.Application{obj, am, ag}}
132136 }
133137
134138 // Inhibited is a wrapper around gtk_application_inhibit().
135 func (v *Application) Inhibited(w IWindow, flags ApplicationInhibitFlags, reason string) uint {
139 func (v *Application) Inhibited(window IWindow, flags ApplicationInhibitFlags, reason string) uint {
140
136141 cstr1 := (*C.gchar)(C.CString(reason))
137142 defer C.free(unsafe.Pointer(cstr1))
138143
139 return uint(C.gtk_application_inhibit(v.native(), w.toWindow(), C.GtkApplicationInhibitFlags(flags), cstr1))
144 var w *C.GtkWindow = nil
145 if window != nil {
146 w = window.toWindow()
147 }
148
149 return uint(C.gtk_application_inhibit(v.native(), w, C.GtkApplicationInhibitFlags(flags), cstr1))
140150 }
141151
142152 // void gtk_application_add_accelerator () // deprecated and uses a gvariant paramater
145155 // GetWindows is a wrapper around gtk_application_get_windows().
146156 // Returned list is wrapped to return *gtk.Window elements.
147157 func (v *Application) GetWindows() *glib.List {
148 glist := C.gtk_application_get_windows(v.native())
149 list := glib.WrapList(uintptr(unsafe.Pointer(glist)))
150 list.DataWrapper(func(ptr unsafe.Pointer) interface{} {
158 clist := C.gtk_application_get_windows(v.native())
159 if clist == nil {
160 return nil
161 }
162
163 glist := glib.WrapList(uintptr(unsafe.Pointer(clist)))
164 glist.DataWrapper(func(ptr unsafe.Pointer) interface{} {
151165 return wrapWindow(glib.Take(ptr))
152166 })
153 runtime.SetFinalizer(list, func(l *glib.List) {
167 runtime.SetFinalizer(glist, func(l *glib.List) {
154168 l.Free()
155169 })
156 return list
170 return glist
157171 }
2020
2121 for *c != nil {
2222 descs = append(descs, C.GoString((*C.char)(*c)))
23 c = C.next_gcharptr(c)
23 c = nextgcharptr(c)
2424 }
2525
2626 return descs
5454
5555 for *c != nil {
5656 descs = append(descs, C.GoString((*C.char)(*c)))
57 c = C.next_gcharptr(c)
57 c = nextgcharptr(c)
5858 }
5959
6060 return descs
2929
3030 for *c != nil {
3131 acts = append(acts, C.GoString((*C.char)(*c)))
32 c = C.next_gcharptr(c)
32 c = nextgcharptr(c)
3333 }
3434
3535 return acts
4040 }
4141
4242 func wrapApplicationWindow(obj *glib.Object) *ApplicationWindow {
43 if obj == nil {
44 return nil
45 }
46
4347 am := &glib.ActionMap{obj}
4448 ag := &glib.ActionGroup{obj}
4549 return &ApplicationWindow{Window{Bin{Container{Widget{glib.InitiallyUnowned{obj}}}}}, am, ag}
0 // Same copyright and license as the rest of the files in this project
1
2 // +build !gtk_3_6,!gtk_3_8,!gtk_3_10,!gtk_3_12,!gtk_3_14,!gtk_3_16,!gtk_3_18
3
4 package gtk
5
6 // #include <gtk/gtk.h>
7 // #include "gtk.go.h"
8 import "C"
9 import (
10 "unsafe"
11
12 "github.com/gotk3/gotk3/glib"
13 )
14
15 // SetHelpOverlay is a wrapper around gtk_application_window_set_help_overlay().
16 func (v *ApplicationWindow) SetHelpOverlay(helpOverlay *ShortcutsWindow) {
17 C.gtk_application_window_set_help_overlay(v.native(), helpOverlay.native())
18 }
19
20 // GetHelpOverlay is a wrapper around gtk_application_window_get_help_overlay().
21 func (v *ApplicationWindow) GetHelpOverlay() *ShortcutsWindow {
22 c := C.gtk_application_window_get_help_overlay(v.native())
23 if c == nil {
24 return nil
25 }
26 return wrapShortcutsWindow(glib.Take(unsafe.Pointer(c)))
27 }
2727 // #include <gtk/gtk.h>
2828 // #include "gtk.go.h"
2929 import "C"
30 import (
31 "unsafe"
3230
33 "github.com/gotk3/gotk3/glib"
34 )
35
36 //gtk_box_bar_set_center_widget(GtkBox *box,GtkWidget *center_widget)
31 // SetCenterWidget is a wrapper around gtk_box_set_center_widget().
3732 func (a *Box) SetCenterWidget(child IWidget) {
3833 if child == nil {
3934 C.gtk_box_set_center_widget(a.native(), nil)
4237 }
4338 }
4439
45 //gtk_box_bar_get_center_widget(GtkBox *box)
46 func (a *Box) GetCenterWidget() *Widget {
40 // GetCenterWidget is a wrapper around gtk_box_get_center_widget().
41 func (a *Box) GetCenterWidget() (IWidget, error) {
4742 w := C.gtk_box_get_center_widget(a.native())
4843 if w == nil {
49 return nil
44 return nil, nil
5045 }
51 return &Widget{glib.InitiallyUnowned{glib.Take(unsafe.Pointer(w))}}
46 return castWidget(w)
5247 }
66 // #include "gtk.go.h"
77 import "C"
88 import (
9 "unsafe"
10
911 "github.com/gotk3/gotk3/glib"
10 "unsafe"
1112 )
1213
1314 type ButtonBoxStyle int
4546 }
4647
4748 func wrapButtonBox(obj *glib.Object) *ButtonBox {
49 if obj == nil {
50 return nil
51 }
52
4853 return &ButtonBox{Box{Container{Widget{glib.InitiallyUnowned{obj}}}}}
4954 }
5055
0 // Same copyright and license as the rest of the files in this project
1
2 package gtk
3
4 // #include <gtk/gtk.h>
5 // #include "gtk.go.h"
6 import "C"
7 import (
8 "fmt"
9 "unsafe"
10
11 "github.com/gotk3/gotk3/cairo"
12 "github.com/gotk3/gotk3/gdk"
13 "github.com/gotk3/gotk3/glib"
14 )
15
16 /*
17 * GtkCellArea
18 */
19
20 // TODO: macro
21 // GTK_CELL_AREA_WARN_INVALID_CELL_PROPERTY_ID(object, property_id, pspec)
22 // object - the GObject on which set_cell_property() or get_cell_property() was called
23 // property_id - the numeric id of the property
24 // pspec - the GParamSpec of the property
25 // C.GTK_CELL_AREA_WARN_INVALID_CELL_PROPERTY_ID
26
27 // CellArea is a representation of GTK's GtkCellArea.
28 type CellArea struct {
29 glib.InitiallyUnowned
30 }
31
32 type ICellArea interface {
33 toCellArea() *C.GtkCellArea
34 ToCellArea() *CellArea
35 }
36
37 // native returns a pointer to the underlying GtkCellArea.
38 func (v *CellArea) native() *C.GtkCellArea {
39 if v == nil || v.GObject == nil {
40 return nil
41 }
42 p := unsafe.Pointer(v.GObject)
43 return C.toGtkCellArea(p)
44 }
45
46 func (v *CellArea) toCellArea() *C.GtkCellArea {
47 if v == nil {
48 return nil
49 }
50 return v.native()
51 }
52
53 // ToCellArea is a helper getter, in case you use the interface gtk.ICellArea in your program.
54 // It returns e.g. *gtk.CellAreaBox as a *gtk.CellArea.
55 func (v *CellArea) ToCellArea() *CellArea {
56 return v
57 }
58
59 func marshalCellArea(p uintptr) (interface{}, error) {
60 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
61 obj := glib.Take(unsafe.Pointer(c))
62 return wrapCellArea(obj), nil
63 }
64
65 func wrapCellArea(obj *glib.Object) *CellArea {
66 if obj == nil {
67 return nil
68 }
69
70 return &CellArea{glib.InitiallyUnowned{obj}}
71 }
72
73 // Add is a wrapper around gtk_cell_area_add().
74 func (v *CellArea) Add(renderer ICellRenderer) {
75 C.gtk_cell_area_add(v.native(), renderer.toCellRenderer())
76 }
77
78 // Remove is a wrapper around gtk_cell_area_remove().
79 func (v *CellArea) Remove(renderer ICellRenderer) {
80 C.gtk_cell_area_remove(v.native(), renderer.toCellRenderer())
81 }
82
83 // HasRenderer is a wrapper around gtk_cell_area_has_renderer().
84 func (v *CellArea) HasRenderer(renderer ICellRenderer) bool {
85 return gobool(C.gtk_cell_area_has_renderer(v.native(), renderer.toCellRenderer()))
86 }
87
88 // TODO:
89 // depends on GtkCellCallback
90 // Foreach is a wrapper around gtk_cell_area_foreach().
91 // func (v *CellArea) Foreach(cb CellCallback, callbackData interface{}) {
92 // }
93
94 // TODO:
95 // depends on GtkCellAllocCallback
96 // ForeachAlloc is a wrapper around gtk_cell_area_foreach_alloc().
97 // func (v *CellArea) ForeachAlloc(context *CellAreaContext, widget IWidget, cellArea, backgroundArea *gdk.Rectangle, cb CellAllocCallback, callbackData interface{}) {
98 // }
99
100 // AreaEvent is a wrapper around gtk_cell_area_event().
101 func (v *CellArea) AreaEvent(context *CellAreaContext, widget IWidget,
102 event *gdk.Event, cellArea *gdk.Rectangle, flags CellRendererState) int {
103
104 e := (*C.GdkEvent)(unsafe.Pointer(event.Native()))
105 c := C.gtk_cell_area_event(v.native(), context.native(), widget.toWidget(),
106 e, nativeGdkRectangle(*cellArea), C.GtkCellRendererState(flags))
107
108 return int(c)
109 }
110
111 // Render is a wrapper around gtk_cell_area_render().
112 func (v *CellArea) Render(context *CellAreaContext, widget IWidget, cr *cairo.Context,
113 backgroundArea, cellArea *gdk.Rectangle, flags CellRendererState, paintFocus bool) {
114
115 cairoContext := (*C.cairo_t)(unsafe.Pointer(cr.Native()))
116
117 C.gtk_cell_area_render(v.native(), context.native(), widget.toWidget(), cairoContext,
118 nativeGdkRectangle(*backgroundArea), nativeGdkRectangle(*cellArea),
119 C.GtkCellRendererState(flags), gbool(paintFocus))
120 }
121
122 // GetCellAllocation is a wrapper around gtk_cell_area_get_cell_allocation().
123 func (v *CellArea) GetCellAllocation(context *CellAreaContext, widget IWidget,
124 renderer ICellRenderer, cellArea *gdk.Rectangle) *gdk.Rectangle {
125
126 var cRect *C.GdkRectangle
127 C.gtk_cell_area_get_cell_allocation(v.native(), context.native(), widget.toWidget(),
128 renderer.toCellRenderer(), nativeGdkRectangle(*cellArea), cRect)
129 allocation := gdk.WrapRectangle(uintptr(unsafe.Pointer(cRect)))
130 return allocation
131
132 }
133
134 // GetCellAtPosition is a wrapper around gtk_cell_area_get_cell_at_position().
135 func (v *CellArea) GetCellAtPosition(context *CellAreaContext, widget IWidget,
136 cellArea *gdk.Rectangle, x, y int) (ICellRenderer, *gdk.Rectangle, error) {
137
138 var cRect *C.GdkRectangle
139
140 renderer := C.gtk_cell_area_get_cell_at_position(v.native(), context.native(), widget.toWidget(),
141 nativeGdkRectangle(*cellArea), C.gint(x), C.gint(y), cRect)
142
143 var allocation *gdk.Rectangle
144
145 if cRect != nil {
146 allocation = gdk.WrapRectangle(uintptr(unsafe.Pointer(cRect)))
147 }
148
149 r, err := castCellRenderer(renderer)
150
151 return r, allocation, err
152 }
153
154 // CreateContext is a wrapper around gtk_cell_area_create_context().
155 func (v *CellArea) CreateContext() (*CellAreaContext, error) {
156 c := C.gtk_cell_area_create_context(v.native())
157 if c == nil {
158 return nil, nilPtrErr
159 }
160 return wrapCellAreaContext(glib.Take(unsafe.Pointer(c))), nil
161 }
162
163 // CopyContext is a wrapper around gtk_cell_area_copy_context().
164 func (v *CellArea) CopyContext(context *CellAreaContext) (*CellAreaContext, error) {
165 c := C.gtk_cell_area_copy_context(v.native(), context.native())
166 if c == nil {
167 return nil, nilPtrErr
168 }
169 return wrapCellAreaContext(glib.Take(unsafe.Pointer(c))), nil
170 }
171
172 // TODO:
173 // depends on GtkSizeRequestMode
174 // gtk_cell_area_get_request_mode
175
176 // GetPreferredWidth is a wrapper around gtk_cell_area_get_preferred_width().
177 func (v *CellArea) GetPreferredWidth(context *CellAreaContext, widget IWidget) (int, int) {
178 var minWidth C.gint
179 var naturalWidth C.gint
180 C.gtk_cell_area_get_preferred_width(v.native(), context.native(), widget.toWidget(),
181 &minWidth, &naturalWidth)
182
183 return int(minWidth), int(naturalWidth)
184 }
185
186 // GetPreferredHeightForWidth is a wrapper around gtk_cell_area_get_preferred_height_for_width().
187 func (v *CellArea) GetPreferredHeightForWidth(context *CellAreaContext, widget IWidget, width int) (int, int) {
188 var minHeight C.gint
189 var naturalHeight C.gint
190 C.gtk_cell_area_get_preferred_height_for_width(v.native(), context.native(), widget.toWidget(),
191 C.gint(width), &minHeight, &naturalHeight)
192
193 return int(minHeight), int(naturalHeight)
194 }
195
196 // GetPreferredHeight is a wrapper around gtk_cell_area_get_preferred_height().
197 func (v *CellArea) GetPreferredHeight(context *CellAreaContext, widget IWidget) (int, int) {
198 var minHeight C.gint
199 var naturalHeight C.gint
200 C.gtk_cell_area_get_preferred_height(v.native(), context.native(), widget.toWidget(),
201 &minHeight, &naturalHeight)
202
203 return int(minHeight), int(naturalHeight)
204 }
205
206 // GetPreferredWidthForHeight is a wrapper around gtk_cell_area_get_preferred_width_for_height().
207 func (v *CellArea) GetPreferredWidthForHeight(context *CellAreaContext, widget IWidget, height int) (int, int) {
208 var minWidth C.gint
209 var naturalWidth C.gint
210 C.gtk_cell_area_get_preferred_width_for_height(v.native(), context.native(), widget.toWidget(),
211 C.gint(height), &minWidth, &naturalWidth)
212
213 return int(minWidth), int(naturalWidth)
214 }
215
216 // GetCurrentPathString is a wrapper around gtk_cell_area_get_current_path_string().
217 func (v *CellArea) GetCurrentPathString() string {
218 c := C.gtk_cell_area_get_current_path_string(v.native())
219 // This string belongs to the area and should not be freed.
220 return goString(c)
221 }
222
223 // ApplyAttributes is a wrapper around gtk_cell_area_apply_attributes().
224 func (v *CellArea) ApplyAttributes(model ITreeModel, iter *TreeIter, isExpander, isExpanded bool) {
225 C.gtk_cell_area_apply_attributes(v.native(), model.toTreeModel(), iter.native(),
226 gbool(isExpander), gbool(isExpanded))
227 }
228
229 // AttributeConnect is a wrapper around gtk_cell_area_attribute_connect().
230 func (v *CellArea) AttributeConnect(renderer ICellRenderer, attribute string, column int) {
231 cstr := C.CString(attribute)
232 defer C.free(unsafe.Pointer(cstr))
233 C.gtk_cell_area_attribute_connect(v.native(), renderer.toCellRenderer(), (*C.gchar)(cstr), C.gint(column))
234 }
235
236 // AttributeDisconnect is a wrapper around gtk_cell_area_attribute_disconnect().
237 func (v *CellArea) AttributeDisconnect(renderer ICellRenderer, attribute string) {
238 cstr := C.CString(attribute)
239 defer C.free(unsafe.Pointer(cstr))
240 C.gtk_cell_area_attribute_disconnect(v.native(), renderer.toCellRenderer(), (*C.gchar)(cstr))
241 }
242
243 // TODO:
244 // gtk_cell_area_class_install_cell_property // depends on GParamSpec
245 // gtk_cell_area_class_find_cell_property // depends on GParamSpec
246 // gtk_cell_area_class_list_cell_properties // depends on GParamSpec
247 // gtk_cell_area_add_with_properties
248 // gtk_cell_area_cell_set
249 // gtk_cell_area_cell_get
250 // gtk_cell_area_cell_set_valist
251 // gtk_cell_area_cell_get_valist
252
253 // CellSetProperty is a wrapper around gtk_cell_area_cell_set_property().
254 func (v *CellArea) CellSetProperty(renderer ICellRenderer, propertyName string, value interface{}) error {
255 gval, err := glib.GValue(value)
256 if err != nil {
257 return err
258 }
259 cstr := C.CString(propertyName)
260 defer C.free(unsafe.Pointer(cstr))
261 C.gtk_cell_area_cell_set_property(v.native(), renderer.toCellRenderer(), (*C.gchar)(cstr),
262 (*C.GValue)(unsafe.Pointer(gval.Native())))
263 return nil
264 }
265
266 // CellGetProperty is a wrapper around gtk_cell_area_cell_get_property().
267 func (v *CellArea) CellGetProperty(renderer ICellRenderer, propertyName string) (interface{}, error) {
268 cstr := C.CString(propertyName)
269 defer C.free(unsafe.Pointer(cstr))
270
271 var gval C.GValue
272 C.gtk_cell_area_cell_get_property(v.native(), renderer.toCellRenderer(), (*C.gchar)(cstr), &gval)
273 value := glib.ValueFromNative(unsafe.Pointer(&gval))
274 return value.GoValue()
275 }
276
277 // IsActivatable is a wrapper around gtk_cell_area_is_activatable().
278 func (v *CellArea) IsActivatable() bool {
279 return gobool(C.gtk_cell_area_is_activatable(v.native()))
280 }
281
282 // Activate is a wrapper around gtk_cell_area_activate().
283 func (v *CellArea) Activate(context *CellAreaContext, widget IWidget,
284 cellArea *gdk.Rectangle, flags CellRendererState, editOnly bool) {
285
286 C.gtk_cell_area_activate(v.native(), context.native(), widget.toWidget(),
287 nativeGdkRectangle(*cellArea), C.GtkCellRendererState(flags), gbool(editOnly))
288 }
289
290 // Focus is a wrapper around gtk_cell_area_focus().
291 func (v *CellArea) Focus(direction DirectionType) bool {
292 return gobool(C.gtk_cell_area_focus(v.native(), C.GtkDirectionType(direction)))
293 }
294
295 // SetFocusCell is a wrapper around gtk_cell_area_set_focus_cell().
296 func (v *CellArea) SetFocusCell(renderer ICellRenderer) {
297 C.gtk_cell_area_set_focus_cell(v.native(), renderer.toCellRenderer())
298 }
299
300 // GetFocusCell is a wrapper around gtk_cell_area_get_focus_cell().
301 func (v *CellArea) GetFocusCell() (ICellRenderer, error) {
302 c := C.gtk_cell_area_get_focus_cell(v.native())
303 return castCellRenderer(c)
304 }
305
306 // AddFocusSibling is a wrapper around gtk_cell_area_add_focus_sibling().
307 func (v *CellArea) AddFocusSibling(renderer, sibling ICellRenderer) {
308 C.gtk_cell_area_add_focus_sibling(v.native(), renderer.toCellRenderer(), sibling.toCellRenderer())
309 }
310
311 // RemoveFocusSibling is a wrapper around gtk_cell_area_remove_focus_sibling().
312 func (v *CellArea) RemoveFocusSibling(renderer, sibling ICellRenderer) {
313 C.gtk_cell_area_remove_focus_sibling(v.native(), renderer.toCellRenderer(), sibling.toCellRenderer())
314 }
315
316 // IsFocusSibling is a wrapper around gtk_cell_area_is_focus_sibling().
317 func (v *CellArea) IsFocusSibling(renderer, sibling ICellRenderer) bool {
318 return gobool(C.gtk_cell_area_is_focus_sibling(v.native(), renderer.toCellRenderer(), sibling.toCellRenderer()))
319 }
320
321 // GetFocusSiblings is a wrapper around gtk_cell_area_get_focus_siblings().
322 func (v *CellArea) GetFocusSiblings(renderer ICellRenderer) ([]ICellRenderer, error) {
323 clist := C.gtk_cell_area_get_focus_siblings(v.native(), renderer.toCellRenderer())
324 if clist == nil {
325 return nil, nilPtrErr
326 }
327
328 // The returned list is internal and should not be freed.
329 var cellRendererList []ICellRenderer
330 wlist := glib.WrapList(uintptr(unsafe.Pointer(clist)))
331 for ; wlist.Data() != nil; wlist = wlist.Next() {
332 w, ok := wlist.Data().(*CellRenderer)
333 if !ok {
334 return nil, fmt.Errorf("element is not of type *CellRenderer, got %T", w)
335 }
336 cRenderer, err := castCellRenderer(w.toCellRenderer())
337 if err != nil {
338 return nil, err
339 }
340 cellRendererList = append(cellRendererList, cRenderer)
341 }
342
343 return cellRendererList, nil
344 }
345
346 // GetFocusFromSibling is a wrapper around gtk_cell_area_get_focus_from_sibling().
347 func (v *CellArea) GetFocusFromSibling(renderer ICellRenderer) (ICellRenderer, error) {
348 c := C.gtk_cell_area_get_focus_from_sibling(v.native(), renderer.toCellRenderer())
349 return castCellRenderer(c)
350 }
351
352 // GetEditedCell is a wrapper around gtk_cell_area_get_edited_cell().
353 func (v *CellArea) GetEditedCell() (ICellRenderer, error) {
354 c := C.gtk_cell_area_get_edited_cell(v.native())
355 return castCellRenderer(c)
356 }
357
358 // GetEditWidget is a wrapper around gtk_cell_area_get_edit_widget().
359 func (v *CellArea) GetEditWidget() (ICellEditable, error) {
360 c := C.gtk_cell_area_get_edit_widget(v.native())
361 return castCellEditable(c)
362 }
363
364 // ActivateCell is a wrapper around gtk_cell_area_activate_cell().
365 func (v *CellArea) ActivateCell(widget IWidget, renderer ICellRenderer,
366 event *gdk.Event, cellArea *gdk.Rectangle, flags CellRendererState) bool {
367
368 e := (*C.GdkEvent)(unsafe.Pointer(event.Native()))
369 c := C.gtk_cell_area_activate_cell(v.native(), widget.toWidget(), renderer.toCellRenderer(),
370 e, nativeGdkRectangle(*cellArea), C.GtkCellRendererState(flags))
371
372 return gobool(c)
373 }
374
375 // StopEditing is a wrapper around gtk_cell_area_stop_editing().
376 func (v *CellArea) StopEditing(cancelled bool) {
377 C.gtk_cell_area_stop_editing(v.native(), gbool(cancelled))
378 }
379
380 // InnerCellArea is a wrapper around gtk_cell_area_inner_cell_area().
381 func (v *CellArea) InnerCellArea(widget IWidget, cellArea *gdk.Rectangle) *gdk.Rectangle {
382 var cRect *C.GdkRectangle
383 C.gtk_cell_area_inner_cell_area(v.native(), widget.toWidget(), nativeGdkRectangle(*cellArea), cRect)
384 innerArea := gdk.WrapRectangle(uintptr(unsafe.Pointer(cRect)))
385 return innerArea
386 }
387
388 // RequestRenderer is a wrapper around gtk_cell_area_request_renderer().
389 func (v *CellArea) RequestRenderer(renderer ICellRenderer, orientation Orientation,
390 widget IWidget, forSize int) (int, int) {
391
392 var minSize C.gint
393 var naturalSize C.gint
394
395 C.gtk_cell_area_request_renderer(v.native(), renderer.toCellRenderer(), C.GtkOrientation(orientation),
396 widget.toWidget(), C.gint(forSize), &minSize, &naturalSize)
397
398 return int(minSize), int(naturalSize)
399 }
400
401 /*
402 * GtkCellAreaContext
403 */
404
405 type CellAreaContext struct {
406 *glib.Object
407 }
408
409 // native returns a pointer to the underlying GtkCellAreaContext.
410 func (v *CellAreaContext) native() *C.GtkCellAreaContext {
411 if v == nil || v.GObject == nil {
412 return nil
413 }
414 p := unsafe.Pointer(v.GObject)
415 return C.toGtkCellAreaContext(p)
416 }
417
418 func (v *CellAreaContext) toCellAreaContext() *C.GtkCellAreaContext {
419 if v == nil {
420 return nil
421 }
422 return v.native()
423 }
424
425 func marshalCellAreaContext(p uintptr) (interface{}, error) {
426 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
427 obj := glib.Take(unsafe.Pointer(c))
428 return wrapCellAreaContext(obj), nil
429 }
430
431 func wrapCellAreaContext(obj *glib.Object) *CellAreaContext {
432 if obj == nil {
433 return nil
434 }
435
436 return &CellAreaContext{obj}
437 }
438
439 // GetArea is a wrapper around gtk_cell_area_context_get_area().
440 func (v *CellAreaContext) GetArea() (*CellArea, error) {
441 c := C.gtk_cell_area_context_get_area(v.native())
442 if c == nil {
443 return nil, nilPtrErr
444 }
445 return wrapCellArea(glib.Take(unsafe.Pointer(c))), nil
446 }
447
448 // Allocate is a wrapper around gtk_cell_area_context_allocate().
449 func (v *CellAreaContext) Allocate(width, height int) {
450 C.gtk_cell_area_context_allocate(v.native(), C.gint(width), C.gint(height))
451 }
452
453 // Reset is a wrapper around gtk_cell_area_context_reset().
454 func (v *CellAreaContext) Reset(width, height int) {
455 C.gtk_cell_area_context_reset(v.native())
456 }
457
458 // GetPreferredWidth is a wrapper around gtk_cell_area_context_get_preferred_width().
459 func (v *CellAreaContext) GetPreferredWidth() (int, int) {
460 var minWidth C.gint
461 var naturalWidth C.gint
462 C.gtk_cell_area_context_get_preferred_width(v.native(), &minWidth, &naturalWidth)
463 return int(minWidth), int(naturalWidth)
464 }
465
466 // GetPreferredHeight is a wrapper around gtk_cell_area_context_get_preferred_height().
467 func (v *CellAreaContext) GetPreferredHeight() (int, int) {
468 var minHeight C.gint
469 var naturalHeight C.gint
470 C.gtk_cell_area_context_get_preferred_height(v.native(), &minHeight, &naturalHeight)
471 return int(minHeight), int(naturalHeight)
472 }
473
474 // GetPreferredHeightForWidth is a wrapper around gtk_cell_area_context_get_preferred_height_for_width().
475 func (v *CellAreaContext) GetPreferredHeightForWidth(width int) (int, int) {
476 var minHeight C.gint
477 var naturalHeight C.gint
478 C.gtk_cell_area_context_get_preferred_height_for_width(v.native(), C.gint(width), &minHeight, &naturalHeight)
479 return int(minHeight), int(naturalHeight)
480 }
481
482 // GetPreferredWidthForHeight is a wrapper around gtk_cell_area_context_get_preferred_width_for_height().
483 func (v *CellAreaContext) GetPreferredWidthForHeight(height int) (int, int) {
484 var minWidth C.gint
485 var naturalWidth C.gint
486 C.gtk_cell_area_context_get_preferred_width_for_height(v.native(), C.gint(height), &minWidth, &naturalWidth)
487 return int(minWidth), int(naturalWidth)
488 }
489
490 // GetAllocation is a wrapper around gtk_cell_area_context_get_allocation().
491 func (v *CellAreaContext) GetAllocation() (int, int) {
492 var height C.gint
493 var width C.gint
494 C.gtk_cell_area_context_get_allocation(v.native(), &height, &width)
495 return int(height), int(width)
496 }
497
498 // PushPreferredWidth is a wrapper around gtk_cell_area_context_push_preferred_width().
499 func (v *CellAreaContext) PushPreferredWidth(minWidth, naturalWidth int) {
500 C.gtk_cell_area_context_push_preferred_width(v.native(), C.gint(minWidth), C.gint(naturalWidth))
501 }
502
503 // PushPreferredHeight is a wrapper around gtk_cell_area_context_push_preferred_height().
504 func (v *CellAreaContext) PushPreferredHeight(minHeight, naturalHeight int) {
505 C.gtk_cell_area_context_push_preferred_height(v.native(), C.gint(minHeight), C.gint(naturalHeight))
506 }
507
508 /*
509 * GtkCellAreaBox
510 */
511
512 // CellAreaBox is a representation of GTK's GtkCellAreaBox.
513 type CellAreaBox struct {
514 CellArea
515
516 // Interfaces
517 Orientable
518 }
519
520 // native returns a pointer to the underlying GtkCellAreaBox.
521 func (v *CellAreaBox) native() *C.GtkCellAreaBox {
522 if v == nil || v.CellArea.GObject == nil {
523 return nil
524 }
525 p := unsafe.Pointer(v.CellArea.GObject)
526 return C.toGtkCellAreaBox(p)
527 }
528
529 func (v *CellArea) toOrientable() *C.GtkOrientable {
530 if v == nil {
531 return nil
532 }
533 return C.toGtkOrientable(unsafe.Pointer(v.GObject))
534 }
535
536 func marshalCellAreaBox(p uintptr) (interface{}, error) {
537 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
538 obj := glib.Take(unsafe.Pointer(c))
539 return wrapCellAreaBox(obj), nil
540 }
541
542 func wrapCellAreaBox(obj *glib.Object) *CellAreaBox {
543 if obj == nil {
544 return nil
545 }
546
547 cellArea := wrapCellArea(obj)
548 o := wrapOrientable(obj)
549 return &CellAreaBox{*cellArea, *o}
550 }
551
552 // CellAreaBoxNew is a wrapper around gtk_cell_area_box_new().
553 func CellAreaBoxNew() (*CellAreaBox, error) {
554 c := C.gtk_cell_area_box_new()
555 if c == nil {
556 return nil, nilPtrErr
557 }
558 return wrapCellAreaBox(glib.Take(unsafe.Pointer(c))), nil
559 }
560
561 // PackStart is a wrapper around gtk_cell_area_box_pack_start().
562 func (v *CellAreaBox) PackStart(renderer ICellRenderer, expand, align, fixed bool) {
563 C.gtk_cell_area_box_pack_start(v.native(), renderer.toCellRenderer(), gbool(expand), gbool(align), gbool(fixed))
564 }
565
566 // PackEnd is a wrapper around gtk_cell_area_box_pack_end().
567 func (v *CellAreaBox) PackEnd(renderer ICellRenderer, expand, align, fixed bool) {
568 C.gtk_cell_area_box_pack_end(v.native(), renderer.toCellRenderer(), gbool(expand), gbool(align), gbool(fixed))
569 }
570
571 // GetSpacing is a wrapper around gtk_cell_area_box_get_spacing().
572 func (v *CellAreaBox) GetSpacing() int {
573 return int(C.gtk_cell_area_box_get_spacing(v.native()))
574 }
575
576 // SetSpacing is a wrapper around gtk_cell_area_box_set_spacing().
577 func (v *CellAreaBox) SetSpacing(spacing int) {
578 C.gtk_cell_area_box_set_spacing(v.native(), C.gint(spacing))
579 }
0 // Same copyright and license as the rest of the files in this project
1 // See: https://developer.gnome.org/gtk3/3.14/api-index-3-14.html
2
3 // +build !gtk_3_6,!gtk_3_8,!gtk_3_10,!gtk_3_12
4
5 package gtk
6
7 // #include <gtk/gtk.h>
8 // #include "gtk.go.h"
9 import "C"
10 import "unsafe"
11
12 /*
13 * GtkCellArea
14 */
15
16 // AttributeGetColumn is a wrapper around gtk_cell_area_attribute_get_column().
17 func (v *CellArea) AttributeGetColumn(renderer ICellRenderer, attribute string) int {
18 cstr := C.CString(attribute)
19 defer C.free(unsafe.Pointer(cstr))
20 column := C.gtk_cell_area_attribute_get_column(v.native(), renderer.toCellRenderer(), (*C.gchar)(cstr))
21 return int(column)
22 }
5454 }
5555
5656 func wrapColorChooser(obj *glib.Object) *ColorChooser {
57 if obj == nil {
58 return nil
59 }
60
5761 return &ColorChooser{obj}
5862 }
5963
130134 }
131135
132136 func wrapColorChooserDialog(obj *glib.Object) *ColorChooserDialog {
137 if obj == nil {
138 return nil
139 }
140
133141 dialog := wrapDialog(obj)
134142 cc := wrapColorChooser(obj)
135143 return &ColorChooserDialog{*dialog, *cc}
137145
138146 // ColorChooserDialogNew() is a wrapper around gtk_color_chooser_dialog_new().
139147 func ColorChooserDialogNew(title string, parent IWindow) (*ColorChooserDialog, error) {
148
140149 cstr := C.CString(title)
141150 defer C.free(unsafe.Pointer(cstr))
142 c := C.gtk_color_chooser_dialog_new((*C.gchar)(cstr), parent.toWindow())
151
152 var w *C.GtkWindow = nil
153 if parent != nil {
154 w = parent.toWindow()
155 }
156
157 c := C.gtk_color_chooser_dialog_new((*C.gchar)(cstr), w)
143158 if c == nil {
144159 return nil, nilPtrErr
145160 }
146161 return wrapColorChooserDialog(glib.Take(unsafe.Pointer(c))), nil
147162 }
163
164 /*
165 * GtkColorChooserWidget
166 */
167
168 // TODO:
169 // gtk_color_chooser_widget_new().
44 import "C"
55 import (
66 "errors"
7 "fmt"
78 "unsafe"
89
10 "github.com/gotk3/gotk3/gdk"
911 "github.com/gotk3/gotk3/glib"
1012 )
1113
3133
3234 // Interfaces
3335 CellLayout
36 CellEditable
3437 }
3538
3639 // native returns a pointer to the underlying GtkComboBox.
5659 }
5760
5861 func wrapComboBox(obj *glib.Object) *ComboBox {
62 if obj == nil {
63 return nil
64 }
65
5966 cl := wrapCellLayout(obj)
60 return &ComboBox{Bin{Container{Widget{glib.InitiallyUnowned{obj}}}}, *cl}
61 }
62
63 // ComboBoxNew() is a wrapper around gtk_combo_box_new().
67 ce := wrapCellEditable(obj)
68 return &ComboBox{Bin{Container{Widget{glib.InitiallyUnowned{obj}}}}, *cl, *ce}
69 }
70
71 // ComboBoxNew is a wrapper around gtk_combo_box_new().
6472 func ComboBoxNew() (*ComboBox, error) {
6573 c := C.gtk_combo_box_new()
6674 if c == nil {
7078 return wrapComboBox(obj), nil
7179 }
7280
73 // ComboBoxNewWithEntry() is a wrapper around gtk_combo_box_new_with_entry().
81 // ComboBoxNewWithEntry is a wrapper around gtk_combo_box_new_with_entry().
7482 func ComboBoxNewWithEntry() (*ComboBox, error) {
7583 c := C.gtk_combo_box_new_with_entry()
7684 if c == nil {
8088 return wrapComboBox(obj), nil
8189 }
8290
83 // ComboBoxNewWithModel() is a wrapper around gtk_combo_box_new_with_model().
91 // ComboBoxNewWithModel is a wrapper around gtk_combo_box_new_with_model().
8492 func ComboBoxNewWithModel(model ITreeModel) (*ComboBox, error) {
8593 c := C.gtk_combo_box_new_with_model(model.toTreeModel())
8694 if c == nil {
9098 return wrapComboBox(obj), nil
9199 }
92100
93 // GetActive() is a wrapper around gtk_combo_box_get_active().
101 // is a wrapper around gtk_combo_box_new_with_model_and_entry().
102 func ComboBoxNewWithModelAndEntry(model ITreeModel) (*ComboBox, error) {
103 c := C.gtk_combo_box_new_with_model_and_entry(model.toTreeModel())
104 if c == nil {
105 return nil, nilPtrErr
106 }
107 obj := glib.Take(unsafe.Pointer(c))
108 return wrapComboBox(obj), nil
109 }
110
111 // GetWrapWidth is a wrapper around gtk_combo_box_get_wrap_width().
112 func (v *ComboBox) GetWrapWidth() int {
113 c := C.gtk_combo_box_get_wrap_width(v.native())
114 return int(c)
115 }
116
117 // SetWrapWidth is a wrapper around gtk_combo_box_set_wrap_width().
118 func (v *ComboBox) SetWrapWidth(wrapWidth int) {
119 C.gtk_combo_box_set_wrap_width(v.native(), C.gint(wrapWidth))
120 }
121
122 // GetRowSpanColumn is a wrapper around gtk_combo_box_get_row_span_column().
123 func (v *ComboBox) GetRowSpanColumn() int {
124 c := C.gtk_combo_box_get_row_span_column(v.native())
125 return int(c)
126 }
127
128 // SetRowSpanColumn is a wrapper around gtk_combo_box_set_row_span_column().
129 func (v *ComboBox) SetRowSpanColumn(rowSpan int) {
130 C.gtk_combo_box_set_row_span_column(v.native(), C.gint(rowSpan))
131 }
132
133 // GetColumnSpanColumn is a wrapper around gtk_combo_box_get_column_span_column().
134 func (v *ComboBox) GetColumnSpanColumn() int {
135 c := C.gtk_combo_box_get_column_span_column(v.native())
136 return int(c)
137 }
138
139 // SetColumnSpanColumn is a wrapper around gtk_combo_box_set_column_span_column().
140 func (v *ComboBox) SetColumnSpanColumn(wrapWidth int) {
141 C.gtk_combo_box_set_column_span_column(v.native(), C.gint(wrapWidth))
142 }
143
144 // GetActive is a wrapper around gtk_combo_box_get_active().
94145 func (v *ComboBox) GetActive() int {
95146 c := C.gtk_combo_box_get_active(v.native())
96147 return int(c)
97148 }
98149
99 // SetActive() is a wrapper around gtk_combo_box_set_active().
150 // SetActive is a wrapper around gtk_combo_box_set_active().
100151 func (v *ComboBox) SetActive(index int) {
101152 C.gtk_combo_box_set_active(v.native(), C.gint(index))
102153 }
120171 C.gtk_combo_box_set_active_iter(v.native(), cIter)
121172 }
122173
123 // GetEntryTextColumn is a wrapper around gtk_combo_box_get_entry_text_column()
124 func (v *ComboBox) GetEntryTextColumn() int {
125 c := C.gtk_combo_box_get_entry_text_column(v.native())
126 return int(c)
127 }
128
129 // SetEntryTextColumn is a wrapper around gtk_combo_box_set_entry_text_column()
130 func (v *ComboBox) SetEntryTextColumn(textColumn int) {
131 C.gtk_combo_box_set_entry_text_column(v.native(), C.gint(textColumn))
174 // GetIDColumn is a wrapper around gtk_combo_box_get_id_column()
175 func (v *ComboBox) GetIDColumn() int {
176 c := C.gtk_combo_box_get_id_column(v.native())
177 return int(c)
178 }
179
180 // SetIDColumn is a wrapper around gtk_combo_box_set_id_column()
181 func (v *ComboBox) SetIDColumn(idColumn int) {
182 C.gtk_combo_box_set_id_column(v.native(), C.gint(idColumn))
132183 }
133184
134185 // GetActiveID is a wrapper around gtk_combo_box_get_active_id().
146197 }
147198
148199 // GetModel is a wrapper around gtk_combo_box_get_model().
149 func (v *ComboBox) GetModel() (*TreeModel, error) {
200 func (v *ComboBox) GetModel() (ITreeModel, error) {
150201 c := C.gtk_combo_box_get_model(v.native())
151202 if c == nil {
152203 return nil, nilPtrErr
153204 }
154 obj := glib.Take(unsafe.Pointer(c))
155 return wrapTreeModel(obj), nil
205 return castTreeModel(c)
156206 }
157207
158208 // SetModel is a wrapper around gtk_combo_box_set_model().
164214 C.gtk_combo_box_set_model(v.native(), mptr)
165215 }
166216
217 // PopupForDevice is a wrapper around gtk_combo_box_popup_for_device()
218 func (v *ComboBox) PopupForDevice(device *gdk.Device) {
219 var devicePtr *C.GdkDevice
220 if device != nil {
221 devicePtr = (*C.GdkDevice)(unsafe.Pointer(device.Native()))
222 }
223 C.gtk_combo_box_popup_for_device(v.native(), devicePtr)
224 }
225
226 // Popup is a wrapper around gtk_combo_box_popup().
167227 func (v *ComboBox) Popup() {
168228 C.gtk_combo_box_popup(v.native())
169229 }
170230
231 // Popdown is a wrapper around gtk_combo_box_popdown().
171232 func (v *ComboBox) Popdown() {
172233 C.gtk_combo_box_popdown(v.native())
173234 }
174235
175 // GetIDColumn is a wrapper around gtk_combo_box_get_id_column()
176 func (v *ComboBox) GetIDColumn() int {
177 c := C.gtk_combo_box_get_id_column(v.native())
178 return int(c)
179 }
180
181 // SetIDColumn is a wrapper around gtk_combo_box_set_id_column()
182 func (v *ComboBox) SetIDColumn(idColumn int) {
183 C.gtk_combo_box_set_id_column(v.native(), C.gint(idColumn))
236 // GetHasEntry is a wrapper around gtk_combo_box_get_has_entry().
237 func (v *ComboBox) GetHasEntry() bool {
238 c := C.gtk_combo_box_get_has_entry(v.native())
239 return gobool(c)
240 }
241
242 // SetEntryTextColumn is a wrapper around gtk_combo_box_set_entry_text_column().
243 func (v *ComboBox) SetEntryTextColumn(textColumn int) {
244 C.gtk_combo_box_set_entry_text_column(v.native(), C.gint(textColumn))
245 }
246
247 // GetEntryTextColumn is a wrapper around gtk_combo_box_get_entry_text_column().
248 func (v *ComboBox) GetEntryTextColumn() int {
249 c := C.gtk_combo_box_get_entry_text_column(v.native())
250 return int(c)
251 }
252
253 // SetPopupFixedWidth is a wrapper around gtk_combo_box_set_popup_fixed_width
254 func (v *ComboBox) SetPopupFixedWidth(fixedWidth bool) {
255 C.gtk_combo_box_set_popup_fixed_width(v.native(), gbool(fixedWidth))
256 }
257
258 // GetPopupFixedWidth is a wrapper around gtk_combo_box_get_popup_fixed_width
259 func (v *ComboBox) GetPopupFixedWidth() bool {
260 c := C.gtk_combo_box_get_popup_fixed_width(v.native())
261 return gobool(c)
262 }
263
264 // GetEntry is a convenience func to get the Entry within the ComboBox.
265 // If the Combobox does not contain an Entry, an error is returned.
266 func (v *ComboBox) GetEntry() (*Entry, error) {
267 hasEntry := C.gtk_combo_box_get_has_entry(v.native())
268 if hasEntry == C.FALSE {
269 return nil, errors.New("combobox has no entry")
270 }
271 bin := &v.Bin
272 widget, err := bin.GetChild()
273 if err != nil {
274 return nil, err
275 }
276 entry, ok := widget.(*Entry)
277 if !ok {
278 return nil, fmt.Errorf("expected child to be of type *gtk.Entry, got %T", widget)
279 }
280 return entry, nil
184281 }
185282
186283 /*
208305 }
209306
210307 func wrapComboBoxText(obj *glib.Object) *ComboBoxText {
308 if obj == nil {
309 return nil
310 }
311
211312 return &ComboBoxText{*wrapComboBox(obj)}
212313 }
213314
295396 defer C.free(unsafe.Pointer(c))
296397 return C.GoString(c)
297398 }
399
400 // gtk_combo_box_new_with_area, requires GtkCellArea
401 // gtk_combo_box_new_with_area_and_entry, requires GtkCellArea
402 // gtk_combo_box_get_row_separator_func, requires GtkTreeViewRowSeparatorFunc
403 // gtk_combo_box_set_row_separator_func, requires GtkTreeViewRowSeparatorFunc
404 // gtk_combo_box_get_popup_accessible, requires AtkObject
405 // gtk_combo_box_set_add_tearoffs, deprecated since 3.10
406 // gtk_combo_box_get_add_tearoffs, deprecated since 3.10
407 // gtk_combo_box_set_title, deprecated since 3.10
408 // gtk_combo_box_get_title, deprecated since 3.10
409 // gtk_combo_box_set_focus_on_click, deprecated since 3.20
410 // gtk_combo_box_get_focus_on_click, deprecated since 3.20
411 // gtk_combo_box_set_button_sensitivity, requires GtkSensitivityType
412 // gtk_combo_box_get_button_sensitivity, requires GtkSensitivityType
4343 }
4444
4545 func wrapFixed(obj *glib.Object) *Fixed {
46 if obj == nil {
47 return nil
48 }
49
4650 return &Fixed{Container{Widget{glib.InitiallyUnowned{obj}}}}
4751 }
4852
0 static GtkFixed *
1 toGtkFixed(void *p)
2 {
3 return (GTK_FIXED(p));
4 }
0 static GtkFixed *toGtkFixed(void *p) { return (GTK_FIXED(p)); }
5454 }
5555
5656 func wrapFontChooser(obj *glib.Object) *FontChooser {
57 if obj == nil {
58 return nil
59 }
60
5761 return &FontChooser{obj}
5862 }
5963
119123 }
120124
121125 func wrapFontButton(obj *glib.Object) *FontButton {
126 if obj == nil {
127 return nil
128 }
129
122130 button := wrapButton(obj)
123131 fc := wrapFontChooser(obj)
124132 return &FontButton{*button, *fc}
145153 obj := glib.Take(unsafe.Pointer(c))
146154 return wrapFontButton(obj), nil
147155 }
156
157 // SetShowStyle is a wrapper around gtk_font_button_set_show_style().
158 func (v *FontButton) SetShowStyle(showStyle bool) {
159 C.gtk_font_button_set_show_style(v.native(), gbool(showStyle))
160 }
161
162 // GetShowStyle is a wrapper around gtk_font_button_get_show_style().
163 func (v *FontButton) GetShowStyle() bool {
164 c := C.gtk_font_button_get_show_style(v.native())
165 return gobool(c)
166 }
167
168 // SetShowSize is a wrapper around gtk_font_button_set_show_size().
169 func (v *FontButton) SetShowSize(showSize bool) {
170 C.gtk_font_button_set_show_size(v.native(), gbool(showSize))
171 }
172
173 // GetShowSize is a wrapper around gtk_font_button_get_show_size().
174 func (v *FontButton) GetShowSize() bool {
175 c := C.gtk_font_button_get_show_size(v.native())
176 return gobool(c)
177 }
178
179 // SetUseFont is a wrapper around gtk_font_button_set_use_font().
180 func (v *FontButton) SetUseFont(useFont bool) {
181 C.gtk_font_button_set_use_font(v.native(), gbool(useFont))
182 }
183
184 // GetUseFont is a wrapper around gtk_font_button_get_use_font().
185 func (v *FontButton) GetUseFont() bool {
186 c := C.gtk_font_button_get_use_font(v.native())
187 return gobool(c)
188 }
189
190 // SetUseSize is a wrapper around gtk_font_button_set_use_size().
191 func (v *FontButton) SetUseSize(useSize bool) {
192 C.gtk_font_button_set_use_size(v.native(), gbool(useSize))
193 }
194
195 // GetUseSize is a wrapper around gtk_font_button_get_use_size().
196 func (v *FontButton) GetUseSize() bool {
197 c := C.gtk_font_button_get_use_size(v.native())
198 return gobool(c)
199 }
200
201 // SetTitle is a wrapper around gtk_font_button_set_title().
202 func (v *FontButton) SetTitle(title string) {
203 cstr := C.CString(title)
204 defer C.free(unsafe.Pointer(cstr))
205 C.gtk_font_button_set_title(v.native(), (*C.gchar)(cstr))
206 }
207
208 // GetTitle is a wrapper around gtk_font_button_get_title().
209 func (v *FontButton) GetTitle() string {
210 c := C.gtk_font_button_get_title(v.native())
211 defer C.free(unsafe.Pointer(c))
212 return goString(c)
213 }
214
215 /*
216 * GtkFontChooserWidget
217 */
218
219 // TODO:
220 // gtk_font_chooser_widget_new().
1717 height: C.int(rect.GetHeight()),
1818 }
1919 }
20
21 func nativeGdkGeometry(geom gdk.Geometry) *C.GdkGeometry {
22 // Note: Here we can't use geom.GdkGeometry because it would return
23 // C type prefixed with gdk package. A ways how to resolve this Go
24 // issue with same C structs in different Go packages is documented
25 // here https://github.com/golang/go/issues/13467 .
26 // This is the easiest way how to resolve the problem.
27 return &C.GdkGeometry{
28 min_width: C.gint(geom.GetMinWidth()),
29 min_height: C.gint(geom.GetMinHeight()),
30 max_width: C.gint(geom.GetMaxWidth()),
31 max_height: C.gint(geom.GetMaxHeight()),
32 base_width: C.gint(geom.GetBaseWidth()),
33 base_height: C.gint(geom.GetBaseHeight()),
34 width_inc: C.gint(geom.GetWidthInc()),
35 height_inc: C.gint(geom.GetHeightInc()),
36 min_aspect: C.gdouble(geom.GetMinAspect()),
37 max_aspect: C.gdouble(geom.GetMaxAspect()),
38 win_gravity: C.GdkGravity(geom.GetWinGravity()),
39 }
40 }
6767 }
6868
6969 func wrapGLArea(obj *glib.Object) *GLArea {
70 if obj == nil {
71 return nil
72 }
73
7074 return &GLArea{Widget{glib.InitiallyUnowned{obj}}}
7175 }
7276
106110 C.gtk_gl_area_set_required_version(v.native(), (C.gint)(major), (C.gint)(minor))
107111 }
108112
113 // TODO:
114 // gtk_gl_area_set_has_alpha().
115 // gtk_gl_area_get_has_alpha().
116
109117 // HasDepthBuffer is a wrapper around gtk_gl_area_get_has_depth_buffer().
110118 func (v *GLArea) HasDepthBuffer() bool {
111119 return gobool(C.gtk_gl_area_get_has_depth_buffer(v.native()))
131139 return gobool(C.gtk_gl_area_get_auto_render(v.native()))
132140 }
133141
134 // SetAutoRender is a wrapper around gtk_gl_area_set_has_stencil_buffer().
142 // SetAutoRender is a wrapper around gtk_gl_area_set_auto_render().
135143 func (v *GLArea) SetAutoRender(autoRender bool) {
136144 C.gtk_gl_area_set_auto_render(v.native(), gbool(autoRender))
137145 }
161169 C.gtk_gl_area_attach_buffers(v.native())
162170 }
163171
164 // GError* gtk_gl_area_get_error (GtkGLArea *area);
172 // GetError is a wrapper around gtk_gl_area_get_error().
165173 func (v *GLArea) GetError() error {
166174 var err *C.GError = nil
167175 err = C.gtk_gl_area_get_error(v.native())
172180 return nil
173181 }
174182
175 // void gtk_gl_area_set_error (GtkGLArea *area, const GError *error);
183 // SetError is a wrapper around gtk_gl_area_set_error().
184 func (v *GLArea) SetError(domain glib.Quark, code int, err error) {
185 cstr := (*C.gchar)(C.CString(err.Error()))
186 defer C.free(unsafe.Pointer(cstr))
187
188 gerr := C.g_error_new_literal(C.GQuark(domain), C.gint(code), cstr)
189 defer C.g_error_free(gerr)
190
191 C.gtk_gl_area_set_error(v.native(), gerr)
192 }
1414 func (v *GLArea) SetUseES(es bool) {
1515 C.gtk_gl_area_set_use_es(v.native(), gbool(es))
1616 }
17
0 package gtk
1
2 // #include <gtk/gtk.h>
3 // #include "gtk.go.h"
4 import "C"
5 import (
6 "unsafe"
7
8 "github.com/gotk3/gotk3/glib"
9 )
10
11 func nativeGPermission(permission *glib.Permission) *C.GPermission {
12 // Note: would return C type prefixed with glib package.
13 // Go issue: here https://github.com/golang/go/issues/13467.
14 var perm *C.GPermission
15 if permission != nil {
16 perm = (*C.GPermission)(unsafe.Pointer(permission.Native()))
17 }
18 return perm
19 }
4444 package gtk
4545
4646 // #cgo pkg-config: gdk-3.0 gio-2.0 glib-2.0 gobject-2.0 gtk+-3.0
47 // #include <gio/gio.h>
4748 // #include <gtk/gtk.h>
4849 // #include "gtk.go.h"
4950 import "C"
5859 "github.com/gotk3/gotk3/cairo"
5960 "github.com/gotk3/gotk3/gdk"
6061 "github.com/gotk3/gotk3/glib"
62 "github.com/gotk3/gotk3/internal/callback"
63 "github.com/gotk3/gotk3/pango"
6164 )
6265
6366 func init() {
7275 {glib.Type(C.gtk_assistant_page_type_get_type()), marshalAssistantPageType},
7376 {glib.Type(C.gtk_buttons_type_get_type()), marshalButtonsType},
7477 {glib.Type(C.gtk_calendar_display_options_get_type()), marshalCalendarDisplayOptions},
78 {glib.Type(C.gtk_cell_renderer_accel_mode_get_type()), marshalCellRendererAccelMode},
79 {glib.Type(C.gtk_cell_renderer_mode_get_type()), marshalCellRendererMode},
80 {glib.Type(C.gtk_cell_renderer_state_get_type()), marshalCellRendererState},
7581 {glib.Type(C.gtk_corner_type_get_type()), marshalCornerType},
7682 {glib.Type(C.gtk_dest_defaults_get_type()), marshalDestDefaults},
7783 {glib.Type(C.gtk_dialog_flags_get_type()), marshalDialogFlags},
8288 {glib.Type(C.gtk_image_type_get_type()), marshalImageType},
8389 {glib.Type(C.gtk_input_hints_get_type()), marshalInputHints},
8490 {glib.Type(C.gtk_input_purpose_get_type()), marshalInputPurpose},
91 {glib.Type(C.gtk_direction_type_get_type()), marshalDirectionType},
8592 {glib.Type(C.gtk_justification_get_type()), marshalJustification},
8693 {glib.Type(C.gtk_license_get_type()), marshalLicense},
8794 {glib.Type(C.gtk_message_type_get_type()), marshalMessageType},
93100 {glib.Type(C.gtk_relief_style_get_type()), marshalReliefStyle},
94101 {glib.Type(C.gtk_response_type_get_type()), marshalResponseType},
95102 {glib.Type(C.gtk_selection_mode_get_type()), marshalSelectionMode},
103 {glib.Type(C.gtk_scroll_type_get_type()), marshalScrollType},
104 {glib.Type(C.gtk_scroll_step_get_type()), marshalScrollStep},
105 {glib.Type(C.gtk_sensitivity_type_get_type()), marshalSensitivityType},
96106 {glib.Type(C.gtk_shadow_type_get_type()), marshalShadowType},
97107 {glib.Type(C.gtk_sort_type_get_type()), marshalSortType},
108 {glib.Type(C.gtk_spin_button_update_policy_get_type()), marshalSpinButtonUpdatePolicy},
109 {glib.Type(C.gtk_spin_type_get_type()), marshalSpinType},
98110 {glib.Type(C.gtk_state_flags_get_type()), marshalStateFlags},
99111 {glib.Type(C.gtk_target_flags_get_type()), marshalTargetFlags},
100112 {glib.Type(C.gtk_text_direction_get_type()), marshalTextDirection},
119131 {glib.Type(C.gtk_box_get_type()), marshalBox},
120132 {glib.Type(C.gtk_calendar_get_type()), marshalCalendar},
121133 {glib.Type(C.gtk_cell_layout_get_type()), marshalCellLayout},
134 {glib.Type(C.gtk_cell_editable_get_type()), marshalCellEditable},
122135 {glib.Type(C.gtk_cell_renderer_get_type()), marshalCellRenderer},
123136 {glib.Type(C.gtk_cell_renderer_spinner_get_type()), marshalCellRendererSpinner},
124137 {glib.Type(C.gtk_cell_renderer_pixbuf_get_type()), marshalCellRendererPixbuf},
125138 {glib.Type(C.gtk_cell_renderer_text_get_type()), marshalCellRendererText},
126139 {glib.Type(C.gtk_cell_renderer_progress_get_type()), marshalCellRendererProgress},
127140 {glib.Type(C.gtk_cell_renderer_toggle_get_type()), marshalCellRendererToggle},
141 {glib.Type(C.gtk_cell_renderer_combo_get_type()), marshalCellRendererCombo},
142 {glib.Type(C.gtk_cell_renderer_accel_get_type()), marshalCellRendererAccel},
143 {glib.Type(C.gtk_cell_renderer_spin_get_type()), marshalCellRendererSpin},
128144 {glib.Type(C.gtk_check_button_get_type()), marshalCheckButton},
129145 {glib.Type(C.gtk_check_menu_item_get_type()), marshalCheckMenuItem},
130146 {glib.Type(C.gtk_clipboard_get_type()), marshalClipboard},
148164 {glib.Type(C.gtk_image_get_type()), marshalImage},
149165 {glib.Type(C.gtk_label_get_type()), marshalLabel},
150166 {glib.Type(C.gtk_link_button_get_type()), marshalLinkButton},
167 {glib.Type(C.gtk_lock_button_get_type()), marshalLockButton},
151168 {glib.Type(C.gtk_layout_get_type()), marshalLayout},
169 {glib.Type(C.gtk_tree_model_sort_get_type()), marshalTreeModelSort},
152170 {glib.Type(C.gtk_list_store_get_type()), marshalListStore},
153171 {glib.Type(C.gtk_menu_get_type()), marshalMenu},
154172 {glib.Type(C.gtk_menu_bar_get_type()), marshalMenuBar},
170188 {glib.Type(C.gtk_scrollbar_get_type()), marshalScrollbar},
171189 {glib.Type(C.gtk_scrolled_window_get_type()), marshalScrolledWindow},
172190 {glib.Type(C.gtk_search_entry_get_type()), marshalSearchEntry},
173 //{glib.Type(C.gtk_selection_data_get_type()), marshalSelectionData},
191 {glib.Type(C.gtk_selection_data_get_type()), marshalSelectionData},
174192 {glib.Type(C.gtk_separator_get_type()), marshalSeparator},
175193 {glib.Type(C.gtk_separator_menu_item_get_type()), marshalSeparatorMenuItem},
176194 {glib.Type(C.gtk_separator_tool_item_get_type()), marshalSeparatorToolItem},
189207 {glib.Type(C.gtk_tool_item_get_type()), marshalToolItem},
190208 {glib.Type(C.gtk_tooltip_get_type()), marshalTooltip},
191209 {glib.Type(C.gtk_tree_model_get_type()), marshalTreeModel},
210 {glib.Type(C.gtk_tree_sortable_get_type()), marshalTreeSortable},
192211 {glib.Type(C.gtk_tree_selection_get_type()), marshalTreeSelection},
193212 {glib.Type(C.gtk_tree_store_get_type()), marshalTreeStore},
194213 {glib.Type(C.gtk_tree_view_get_type()), marshalTreeView},
195214 {glib.Type(C.gtk_tree_view_column_get_type()), marshalTreeViewColumn},
215 {glib.Type(C.gtk_cell_area_get_type()), marshalCellArea},
216 {glib.Type(C.gtk_cell_area_context_get_type()), marshalCellAreaContext},
217 {glib.Type(C.gtk_cell_area_box_get_type()), marshalCellAreaBox},
196218 {glib.Type(C.gtk_volume_button_get_type()), marshalVolumeButton},
197219 {glib.Type(C.gtk_widget_get_type()), marshalWidget},
198220 {glib.Type(C.gtk_window_get_type()), marshalWindow},
221 {glib.Type(C.gtk_window_group_get_type()), marshalWindowGroup},
199222
200223 // Boxed
201224 {glib.Type(C.gtk_target_entry_get_type()), marshalTargetEntry},
205228 {glib.Type(C.gtk_tree_path_get_type()), marshalTreePath},
206229 }
207230 glib.RegisterGValueMarshalers(tm)
231 }
232
233 /*
234 * Callback helpers
235 */
236
237 //export gotk3_callbackDelete
238 func gotk3_callbackDelete(callbackID C.gpointer) {
239 callback.Delete(uintptr(callbackID))
208240 }
209241
210242 /*
249281 }
250282 }
251283
284 // nextguchar increments guchar by 1. Hopefully, this could be inlined by the Go
285 // compiler.
286 func nextguchar(guchar *C.guchar) *C.guchar {
287 return (*C.guchar)(unsafe.Pointer(uintptr(unsafe.Pointer(guchar)) + 1))
288 }
289
290 // ucharString returns a copy of the given guchar pointer. The pointer guchar
291 // array is assumed to have valid UTF-8.
292 func ucharString(guchar *C.guchar) string {
293 // Seek and find the string length.
294 var strlen int
295 for ptr := guchar; *ptr != 0; ptr = nextguchar(ptr) {
296 strlen++
297 }
298
299 // Array of unsigned char means GoString is unavailable, so maybe this is
300 // fine.
301 var data []byte
302 sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&data))
303 sliceHeader.Len = strlen
304 sliceHeader.Cap = strlen
305 sliceHeader.Data = uintptr(unsafe.Pointer(guchar))
306
307 // Return a copy of the string.
308 return string(data)
309 }
310
311 // nextgcharptr increments gcharptr by 1. Hopefully, this could be inlined by
312 // the Go compiler.
313 func nextgcharptr(gcharptr **C.gchar) **C.gchar {
314 return (**C.gchar)(unsafe.Pointer(uintptr(unsafe.Pointer(gcharptr)) + 1))
315 }
316
252317 func goString(cstr *C.gchar) string {
253318 return C.GoString((*C.char)(cstr))
319 }
320
321 // same implementation as package glib
322 func toGoStringArray(c **C.gchar) []string {
323 if c == nil {
324 return nil
325 }
326
327 // free when done
328 defer C.g_strfreev(c)
329
330 strsLen := 0
331 for scan := c; *scan != nil; scan = nextgcharptr(scan) {
332 strsLen++
333 }
334
335 strs := make([]string, strsLen)
336 for i := range strs {
337 strs[i] = C.GoString((*C.char)(*c))
338 c = nextgcharptr(c)
339 }
340
341 return strs
254342 }
255343
256344 // Wrapper function for TestBoolConvs since cgo can't be used with
358446 return ButtonsType(c), nil
359447 }
360448
449 // SensitivityType is a representation of GTK's GtkSensitivityType
450 type SensitivityType int
451
452 const (
453 SENSITIVITY_AUTO SensitivityType = C.GTK_SENSITIVITY_AUTO
454 SENSITIVITY_ON SensitivityType = C.GTK_SENSITIVITY_ON
455 SENSITIVITY_OFF SensitivityType = C.GTK_SENSITIVITY_OFF
456 )
457
458 func marshalSensitivityType(p uintptr) (interface{}, error) {
459 c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
460 return SensitivityType(c), nil
461 }
462
361463 // CalendarDisplayOptions is a representation of GTK's GtkCalendarDisplayOptions
362464 type CalendarDisplayOptions int
363465
435537
436538 const (
437539 ICON_LOOKUP_NO_SVG IconLookupFlags = C.GTK_ICON_LOOKUP_NO_SVG
438 ICON_LOOKUP_FORCE_SVG = C.GTK_ICON_LOOKUP_FORCE_SVG
439 ICON_LOOKUP_USE_BUILTIN = C.GTK_ICON_LOOKUP_USE_BUILTIN
440 ICON_LOOKUP_GENERIC_FALLBACK = C.GTK_ICON_LOOKUP_GENERIC_FALLBACK
441 ICON_LOOKUP_FORCE_SIZE = C.GTK_ICON_LOOKUP_FORCE_SIZE
540 ICON_LOOKUP_FORCE_SVG IconLookupFlags = C.GTK_ICON_LOOKUP_FORCE_SVG
541 ICON_LOOKUP_USE_BUILTIN IconLookupFlags = C.GTK_ICON_LOOKUP_USE_BUILTIN
542 ICON_LOOKUP_GENERIC_FALLBACK IconLookupFlags = C.GTK_ICON_LOOKUP_GENERIC_FALLBACK
543 ICON_LOOKUP_FORCE_SIZE IconLookupFlags = C.GTK_ICON_LOOKUP_FORCE_SIZE
442544 )
443545
444546 func marshalIconLookupFlags(p uintptr) (interface{}, error) {
476578 IMAGE_ICON_NAME ImageType = C.GTK_IMAGE_ICON_NAME
477579 IMAGE_GICON ImageType = C.GTK_IMAGE_GICON
478580 )
581
582 // TODO: add GTK_IMAGE_SURFACE for GTK 3.10
479583
480584 func marshalImageType(p uintptr) (interface{}, error) {
481585 c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
496600 INPUT_HINT_UPPERCASE_SENTENCES InputHints = C.GTK_INPUT_HINT_UPPERCASE_SENTENCES
497601 INPUT_HINT_INHIBIT_OSK InputHints = C.GTK_INPUT_HINT_INHIBIT_OSK
498602 )
603
604 // TODO:
605 // GTK_INPUT_HINT_VERTICAL_WRITING Since 3.18
606 // GTK_INPUT_HINT_EMOJI Since 3.22.20
607 // GTK_INPUT_HINT_NO_EMOJI Since 3.22.20
499608
500609 func marshalInputHints(p uintptr) (interface{}, error) {
501610 c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
523632 return InputPurpose(c), nil
524633 }
525634
526 // Justify is a representation of GTK's GtkJustification.
635 // TODO:
636 // GtkBaselinePosition
637 // GtkDeleteType
638
639 // DirectionType is a representation of GTK's GtkDirectionType.
640 type DirectionType int
641
642 const (
643 DIR_TAB_FORWARD DirectionType = C.GTK_DIR_TAB_FORWARD
644 DIR_TAB_BACKWARD DirectionType = C.GTK_DIR_TAB_BACKWARD
645 DIR_UP DirectionType = C.GTK_DIR_UP
646 DIR_DOWN DirectionType = C.GTK_DIR_DOWN
647 DIR_LEFT DirectionType = C.GTK_DIR_LEFT
648 DIR_RIGHT DirectionType = C.GTK_DIR_RIGHT
649 )
650
651 func marshalDirectionType(p uintptr) (interface{}, error) {
652 c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
653 return DirectionType(c), nil
654 }
655
656 // Justification is a representation of GTK's GtkJustification.
527657 type Justification int
528658
529659 const (
574704 return MessageType(c), nil
575705 }
576706
707 // TODO:
708 // GtkMovementStep
709
577710 // Orientation is a representation of GTK's GtkOrientation.
578711 type Orientation int
579712
628761 return PolicyType(c), nil
629762 }
630763
631 // TreeViewGridLine is a representation of GTK's GtkTreeViewGridLine.
764 // SpinButtonUpdatePolicy is a representation of GTK's GtkSpinButtonUpdatePolicy.
765 type SpinButtonUpdatePolicy int
766
767 const (
768 UPDATE_ALWAYS SpinButtonUpdatePolicy = C.GTK_UPDATE_ALWAYS
769 UPDATE_IF_VALID SpinButtonUpdatePolicy = C.GTK_UPDATE_IF_VALID
770 )
771
772 func marshalSpinButtonUpdatePolicy(p uintptr) (interface{}, error) {
773 c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
774 return SpinButtonUpdatePolicy(c), nil
775 }
776
777 // SpinType is a representation of GTK's GtkSpinType.
778 type SpinType int
779
780 const (
781 SPIN_STEP_FORWARD SpinType = C.GTK_SPIN_STEP_FORWARD
782 SPIN_STEP_BACKWARD SpinType = C.GTK_SPIN_STEP_BACKWARD
783 SPIN_PAGE_BACKWARD SpinType = C.GTK_SPIN_PAGE_BACKWARD
784 SPIN_HOME SpinType = C.GTK_SPIN_HOME
785 SPIN_END SpinType = C.GTK_SPIN_END
786 SPIN_USER_DEFINED SpinType = C.GTK_SPIN_USER_DEFINED
787 )
788
789 func marshalSpinType(p uintptr) (interface{}, error) {
790 c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
791 return SpinType(c), nil
792 }
793
794 // TreeViewGridLine is a representation of GTK's GtkTreeViewGridLines.
632795 type TreeViewGridLines int
633796
634797 const (
637800 TREE_VIEW_GRID_LINES_VERTICAL TreeViewGridLines = C.GTK_TREE_VIEW_GRID_LINES_VERTICAL
638801 TREE_VIEW_GRID_LINES_BOTH TreeViewGridLines = C.GTK_TREE_VIEW_GRID_LINES_BOTH
639802 )
803
804 // CellRendererAccelMode is a representation of GtkCellRendererAccelMode
805 type CellRendererAccelMode int
806
807 const (
808 // CELL_RENDERER_ACCEL_MODE_GTK is documented as GTK+ accelerators mode
809 CELL_RENDERER_ACCEL_MODE_GTK CellRendererAccelMode = C.GTK_CELL_RENDERER_ACCEL_MODE_GTK
810 // CELL_RENDERER_ACCEL_MODE_OTHER is documented as Other accelerator mode
811 CELL_RENDERER_ACCEL_MODE_OTHER CellRendererAccelMode = C.GTK_CELL_RENDERER_ACCEL_MODE_OTHER
812 )
813
814 func marshalCellRendererAccelMode(p uintptr) (interface{}, error) {
815 c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
816 return CellRendererAccelMode(c), nil
817 }
818
819 // CellRendererState is a representation of GTK's GtkCellRendererState
820 type CellRendererState int
821
822 const (
823 CELL_RENDERER_SELECTED CellRendererState = C.GTK_CELL_RENDERER_SELECTED
824 CELL_RENDERER_PRELIT CellRendererState = C.GTK_CELL_RENDERER_PRELIT
825 CELL_RENDERER_INSENSITIVE CellRendererState = C.GTK_CELL_RENDERER_INSENSITIVE
826 CELL_RENDERER_SORTED CellRendererState = C.GTK_CELL_RENDERER_SORTED
827 CELL_RENDERER_FOCUSED CellRendererState = C.GTK_CELL_RENDERER_FOCUSED
828 CELL_RENDERER_EXPANDABLE CellRendererState = C.GTK_CELL_RENDERER_EXPANDABLE // since 3.4
829 CELL_RENDERER_EXPANDED CellRendererState = C.GTK_CELL_RENDERER_EXPANDED // since 3.4
830 )
831
832 func marshalCellRendererState(p uintptr) (interface{}, error) {
833 c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
834 return CellRendererState(c), nil
835 }
836
837 // CellRendererMode is a representation of GTK's GtkCellRendererMode
838 type CellRendererMode int
839
840 const (
841 CELL_RENDERER_MODE_INERT CellRendererMode = C.GTK_CELL_RENDERER_MODE_INERT
842 CELL_RENDERER_MODE_ACTIVATABLE CellRendererMode = C.GTK_CELL_RENDERER_MODE_ACTIVATABLE
843 CELL_RENDERER_MODE_EDITABLE CellRendererMode = C.GTK_CELL_RENDERER_MODE_EDITABLE
844 )
845
846 func marshalCellRendererMode(p uintptr) (interface{}, error) {
847 c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
848 return CellRendererMode(c), nil
849 }
640850
641851 // PositionType is a representation of GTK's GtkPositionType.
642852 type PositionType int
689899 return ResponseType(c), nil
690900 }
691901
902 // ScrollType is a representation of GTK's GtkScrollType.
903 type ScrollType int
904
905 const (
906 SCROLL_NONE ScrollType = C.GTK_SCROLL_NONE
907 SCROLL_JUMP ScrollType = C.GTK_SCROLL_JUMP
908 SCROLL_STEP_BACKWARD ScrollType = C.GTK_SCROLL_STEP_BACKWARD
909 SCROLL_STEP_FORWARD ScrollType = C.GTK_SCROLL_STEP_FORWARD
910 SCROLL_PAGE_BACKWARD ScrollType = C.GTK_SCROLL_PAGE_BACKWARD
911 SCROLL_PAGE_FORWARD ScrollType = C.GTK_SCROLL_PAGE_FORWARD
912 SCROLL_STEP_UP ScrollType = C.GTK_SCROLL_STEP_UP
913 SCROLL_STEP_DOWN ScrollType = C.GTK_SCROLL_STEP_DOWN
914 SCROLL_PAGE_UP ScrollType = C.GTK_SCROLL_PAGE_UP
915 SCROLL_PAGE_DOWN ScrollType = C.GTK_SCROLL_PAGE_DOWN
916 SCROLL_STEP_LEFT ScrollType = C.GTK_SCROLL_STEP_LEFT
917 SCROLL_STEP_RIGHT ScrollType = C.GTK_SCROLL_STEP_RIGHT
918 SCROLL_PAGE_LEFT ScrollType = C.GTK_SCROLL_PAGE_LEFT
919 SCROLL_PAGE_RIGHT ScrollType = C.GTK_SCROLL_PAGE_RIGHT
920 SCROLL_START ScrollType = C.GTK_SCROLL_START
921 SCROLL_END ScrollType = C.GTK_SCROLL_END
922 )
923
924 func marshalScrollType(p uintptr) (interface{}, error) {
925 c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
926 return ScrollType(c), nil
927 }
928
929 // ScrollStep is a representation of GTK's GtkScrollStep.
930 type ScrollStep int
931
932 const (
933 SCROLL_STEPS ScrollStep = C.GTK_SCROLL_STEPS
934 SCROLL_PAGES ScrollStep = C.GTK_SCROLL_PAGES
935 SCROLL_ENDS ScrollStep = C.GTK_SCROLL_ENDS
936 SCROLL_HORIZONTAL_STEPS ScrollStep = C.GTK_SCROLL_HORIZONTAL_STEPS
937 SCROLL_HORIZONTAL_PAGES ScrollStep = C.GTK_SCROLL_HORIZONTAL_PAGES
938 SCROLL_HORIZONTAL_ENDS ScrollStep = C.GTK_SCROLL_HORIZONTAL_ENDS
939 )
940
941 func marshalScrollStep(p uintptr) (interface{}, error) {
942 c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
943 return ScrollStep(c), nil
944 }
945
692946 // SelectionMode is a representation of GTK's GtkSelectionMode.
693947 type SelectionMode int
694948
10321286 }
10331287
10341288 func wrapAdjustment(obj *glib.Object) *Adjustment {
1289 if obj == nil {
1290 return nil
1291 }
1292
10351293 return &Adjustment{glib.InitiallyUnowned{obj}}
10361294 }
10371295
11601418 }
11611419
11621420 func wrapAssistant(obj *glib.Object) *Assistant {
1421 if obj == nil {
1422 return nil
1423 }
1424
11631425 return &Assistant{Window{Bin{Container{Widget{glib.InitiallyUnowned{obj}}}}}}
11641426 }
11651427
11911453 }
11921454
11931455 // GetNthPage is a wrapper around gtk_assistant_get_nth_page().
1194 func (v *Assistant) GetNthPage(pageNum int) (*Widget, error) {
1456 func (v *Assistant) GetNthPage(pageNum int) (IWidget, error) {
11951457 c := C.gtk_assistant_get_nth_page(v.native(), C.gint(pageNum))
11961458 if c == nil {
11971459 return nil, fmt.Errorf("page %d is out of bounds", pageNum)
11981460 }
1199
1200 obj := glib.Take(unsafe.Pointer(c))
1201 return wrapWidget(obj), nil
1461 return castWidget(c)
12021462 }
12031463
12041464 // PrependPage is a wrapper around gtk_assistant_prepend_page().
13191579 }
13201580
13211581 func wrapBin(obj *glib.Object) *Bin {
1582 if obj == nil {
1583 return nil
1584 }
1585
13221586 return &Bin{Container{Widget{glib.InitiallyUnowned{obj}}}}
13231587 }
13241588
13251589 // GetChild is a wrapper around gtk_bin_get_child().
1326 func (v *Bin) GetChild() (*Widget, error) {
1590 func (v *Bin) GetChild() (IWidget, error) {
13271591 c := C.gtk_bin_get_child(v.native())
13281592 if c == nil {
1329 return nil, nilPtrErr
1330 }
1331 obj := glib.Take(unsafe.Pointer(c))
1332 return wrapWidget(obj), nil
1593 return nil, nil
1594 }
1595 return castWidget(c)
13331596 }
13341597
13351598 /*
13621625 if c == nil {
13631626 return nil, nilPtrErr
13641627 }
1365 obj := glib.Take(unsafe.Pointer(c))
1366 return &Builder{obj}, nil
1367 }
1368
1369 // BuilderNewFromFile is a wrapper around gtk_builder_new_from_file().
1370 func BuilderNewFromFile(filePath string) (*Builder, error) {
1371 cstr := C.CString(filePath)
1372 defer C.free(unsafe.Pointer(cstr))
1373
1374 c := C.gtk_builder_new_from_file((*C.gchar)(cstr))
1375 if c == nil {
1376 return nil, nilPtrErr
1377 }
1378
1379 obj := glib.Take(unsafe.Pointer(c))
1380 return &Builder{obj}, nil
1381 }
1382
1383 // BuilderNewFromResource is a wrapper around gtk_builder_new_from_resource().
1384 func BuilderNewFromResource(resourcePath string) (*Builder, error) {
1385 cstr := C.CString(resourcePath)
1386 defer C.free(unsafe.Pointer(cstr))
1387
1388 c := C.gtk_builder_new_from_resource((*C.gchar)(cstr))
1389 if c == nil {
1390 return nil, nilPtrErr
1391 }
1392
13931628 obj := glib.Take(unsafe.Pointer(c))
13941629 return &Builder{obj}, nil
13951630 }
14821717 }
14831718
14841719 /*
1720 * GtkBuildable
1721 */
1722
1723 // TODO:
1724 // GtkBuildableIface
1725 // gtk_buildable_set_name().
1726 // gtk_buildable_get_name().
1727 // gtk_buildable_add_child().
1728 // gtk_buildable_set_buildable_property().
1729 // gtk_buildable_construct_child().
1730 // gtk_buildable_custom_tag_start().
1731 // gtk_buildable_custom_tag_end().
1732 // gtk_buildable_custom_finished().
1733 // gtk_buildable_parser_finished().
1734 // gtk_buildable_get_internal_child().
1735
1736 /*
14851737 * GtkButton
14861738 */
14871739
15091761 }
15101762
15111763 func wrapButton(obj *glib.Object) *Button {
1764 if obj == nil {
1765 return nil
1766 }
1767
15121768 actionable := &Actionable{obj}
15131769 return &Button{Bin{Container{Widget{glib.InitiallyUnowned{obj}}}}, actionable}
15141770 }
15961852 }
15971853
15981854 // GetImage() is a wrapper around gtk_button_get_image().
1599 func (v *Button) GetImage() (*Widget, error) {
1855 func (v *Button) GetImage() (IWidget, error) {
16001856 c := C.gtk_button_get_image(v.native())
16011857 if c == nil {
1602 return nil, nilPtrErr
1603 }
1604 obj := glib.Take(unsafe.Pointer(c))
1605 return wrapWidget(obj), nil
1858 return nil, nil
1859 }
1860 return castWidget(c)
16061861 }
16071862
16081863 // SetImagePosition() is a wrapper around gtk_button_set_image_position().
16601915 }
16611916
16621917 func wrapColorButton(obj *glib.Object) *ColorButton {
1918 if obj == nil {
1919 return nil
1920 }
1921
16631922 cc := wrapColorChooser(obj)
16641923 actionable := wrapActionable(obj)
16651924 return &ColorButton{Button{Bin{Container{Widget{
16841943 return wrapColorButton(glib.Take(unsafe.Pointer(c))), nil
16851944 }
16861945
1946 // SetTitle is a wrapper around gtk_color_button_set_title().
1947 func (v *ColorButton) SetTitle(title string) {
1948 cstr := C.CString(title)
1949 defer C.free(unsafe.Pointer(cstr))
1950 C.gtk_color_button_set_title(v.native(), (*C.gchar)(cstr))
1951 }
1952
1953 // GetTitle is a wrapper around gtk_color_button_get_title().
1954 func (v *ColorButton) GetTitle() string {
1955 c := C.gtk_color_button_get_title(v.native())
1956 defer C.free(unsafe.Pointer(c))
1957 return goString(c)
1958 }
1959
16871960 /*
16881961 * GtkBox
16891962 */
17091982 }
17101983
17111984 func wrapBox(obj *glib.Object) *Box {
1985 if obj == nil {
1986 return nil
1987 }
1988
17121989 return &Box{Container{Widget{glib.InitiallyUnowned{obj}}}}
17131990 }
17141991
18202097 }
18212098
18222099 func wrapCalendar(obj *glib.Object) *Calendar {
2100 if obj == nil {
2101 return nil
2102 }
2103
18232104 return &Calendar{Widget{glib.InitiallyUnowned{obj}}}
18242105 }
2106
2107 // TODO:
2108 // GtkCalendarDetailFunc
18252109
18262110 // CalendarNew is a wrapper around gtk_calendar_new().
18272111 func CalendarNew() (*Calendar, error) {
18832167 return uint(cyear), uint(cmonth), uint(cday)
18842168 }
18852169
1886 // TODO gtk_calendar_set_detail_func
2170 // TODO:
2171 // gtk_calendar_set_detail_func().
18872172
18882173 // GetDetailWidthChars is a wrapper around gtk_calendar_get_detail_width_chars().
18892174 func (v *Calendar) GetDetailWidthChars() int {
19402225 }
19412226
19422227 func wrapCellLayout(obj *glib.Object) *CellLayout {
2228 if obj == nil {
2229 return nil
2230 }
2231
19432232 return &CellLayout{obj}
19442233 }
19452234
19502239 return v.native()
19512240 }
19522241
1953 // PackStart() is a wrapper around gtk_cell_layout_pack_start().
2242 // PackStart is a wrapper around gtk_cell_layout_pack_start().
19542243 func (v *CellLayout) PackStart(cell ICellRenderer, expand bool) {
19552244 C.gtk_cell_layout_pack_start(v.native(), cell.toCellRenderer(),
19562245 gbool(expand))
19572246 }
19582247
1959 // AddAttribute() is a wrapper around gtk_cell_layout_add_attribute().
2248 // AddAttribute is a wrapper around gtk_cell_layout_add_attribute().
19602249 func (v *CellLayout) AddAttribute(cell ICellRenderer, attribute string, column int) {
19612250 cstr := C.CString(attribute)
19622251 defer C.free(unsafe.Pointer(cstr))
19632252 C.gtk_cell_layout_add_attribute(v.native(), cell.toCellRenderer(),
19642253 (*C.gchar)(cstr), C.gint(column))
2254 }
2255
2256 // ClearAttributes is a wrapper around gtk_cell_layout_clear_attributes()
2257 func (v *CellLayout) ClearAttributes(cell ICellRenderer) {
2258 C.gtk_cell_layout_clear_attributes(v.native(), cell.toCellRenderer())
2259 }
2260
2261 /*
2262 * GtkCellView
2263 */
2264
2265 // TODO:
2266 // GtkCellView
2267 // gtk_cell_view_new().
2268 // gtk_cell_view_new_with_context().
2269 // gtk_cell_view_new_with_text().
2270 // gtk_cell_view_new_with_markup().
2271 // gtk_cell_view_new_with_pixbuf().
2272 // gtk_cell_view_set_model().
2273 // gtk_cell_view_get_model().
2274 // gtk_cell_view_set_displayed_row().
2275 // gtk_cell_view_get_displayed_row().
2276 // gtk_cell_view_set_background_rgba().
2277 // gtk_cell_view_set_draw_sensitive().
2278 // gtk_cell_view_get_draw_sensitive().
2279 // gtk_cell_view_set_fit_model().
2280 // gtk_cell_view_get_fit_model().
2281
2282 /*
2283 * GtkCellEditable
2284 */
2285
2286 // CellEditable is a representation of GTK's GtkCellEditable GInterface.
2287 type CellEditable struct {
2288 glib.InitiallyUnowned
2289 // Widget
2290 }
2291
2292 // ICellEditable is an interface type implemented by all structs
2293 // embedding an CellEditable. It is meant to be used as an argument type
2294 // for wrapper functions that wrap around a C GTK function taking a
2295 // GtkCellEditable.
2296 type ICellEditable interface {
2297 toCellEditable() *C.GtkCellEditable
2298 ToEntry() *Entry
2299 }
2300
2301 // native() returns a pointer to the underlying GObject as a GtkCellEditable.
2302 func (v *CellEditable) native() *C.GtkCellEditable {
2303 if v == nil || v.GObject == nil {
2304 return nil
2305 }
2306 p := unsafe.Pointer(v.GObject)
2307 return C.toGtkCellEditable(p)
2308 }
2309
2310 func marshalCellEditable(p uintptr) (interface{}, error) {
2311 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
2312 obj := glib.Take(unsafe.Pointer(c))
2313 return wrapCellEditable(obj), nil
2314 }
2315
2316 func wrapCellEditable(obj *glib.Object) *CellEditable {
2317 if obj == nil {
2318 return nil
2319 }
2320
2321 // return &CellEditable{Widget{glib.InitiallyUnowned{obj}}}
2322 return &CellEditable{glib.InitiallyUnowned{obj}}
2323 }
2324
2325 func (v *CellEditable) toCellEditable() *C.GtkCellEditable {
2326 if v == nil {
2327 return nil
2328 }
2329 return v.native()
2330 }
2331
2332 // ToEntry is a helper tool, e.g: it returns *gtk.CellEditable as a *gtk.Entry
2333 // that embedding this CellEditable instance, then it can be used with
2334 // CellRendererText to adding EntryCompletion tools or intercepting EntryBuffer,
2335 // (to bypass "canceled" signal for example) then record entry, and much more.
2336 func (v *CellEditable) ToEntry() *Entry {
2337 return &Entry{Widget{glib.InitiallyUnowned{v.Object}},
2338 Editable{v.Object},
2339 *v}
2340 }
2341
2342 // StartEditing is a wrapper around gtk_cell_editable_start_editing().
2343 func (v *CellEditable) StartEditing(event *gdk.Event) {
2344 C.gtk_cell_editable_start_editing(v.native(),
2345 (*C.GdkEvent)(unsafe.Pointer(event.Native())))
2346 }
2347
2348 // EditingDone is a wrapper around gtk_cell_editable_editing_done().
2349 func (v *CellEditable) EditingDone() {
2350 C.gtk_cell_editable_editing_done(v.native())
2351 }
2352
2353 // RemoveWidget is a wrapper around gtk_cell_editable_remove_widget().
2354 func (v *CellEditable) RemoveWidget() {
2355 C.gtk_cell_editable_remove_widget(v.native())
19652356 }
19662357
19672358 /*
20042395 }
20052396
20062397 func wrapCellRenderer(obj *glib.Object) *CellRenderer {
2398 if obj == nil {
2399 return nil
2400 }
2401
20072402 return &CellRenderer{glib.InitiallyUnowned{obj}}
20082403 }
2404
2405 // Activate is a wrapper around gtk_cell_renderer_activate().
2406 func (v *CellRenderer) Activate(event *gdk.Event, widget IWidget, path string,
2407 backgroundArea, cellArea *gdk.Rectangle, flags CellRendererState) bool {
2408
2409 cstr := C.CString(path)
2410 defer C.free(unsafe.Pointer(cstr))
2411 e := (*C.GdkEvent)(unsafe.Pointer(event.Native()))
2412
2413 c := C.gtk_cell_renderer_activate(v.native(), e, widget.toWidget(),
2414 (*C.gchar)(cstr), nativeGdkRectangle(*backgroundArea),
2415 nativeGdkRectangle(*cellArea), C.GtkCellRendererState(flags))
2416
2417 return gobool(c)
2418 }
2419
2420 // StartEditing is a wrapper around gtk_cell_renderer_start_editing().
2421 func (v *CellRenderer) StartEditing(event *gdk.Event, widget IWidget, path string,
2422 backgroundArea, cellArea *gdk.Rectangle, flags CellRendererState) (ICellEditable, error) {
2423
2424 cstr := C.CString(path)
2425 defer C.free(unsafe.Pointer(cstr))
2426 e := (*C.GdkEvent)(unsafe.Pointer(event.Native()))
2427
2428 c := C.gtk_cell_renderer_start_editing(v.native(), e, widget.toWidget(),
2429 (*C.gchar)(cstr), nativeGdkRectangle(*backgroundArea),
2430 nativeGdkRectangle(*cellArea), C.GtkCellRendererState(flags))
2431
2432 return castCellEditable(c)
2433 }
2434
2435 // StopEditing is a wrapper around gtk_cell_renderer_stop_editing().
2436 func (v *CellRenderer) StopEditing(canceled bool) {
2437 C.gtk_cell_renderer_stop_editing(v.native(), gbool(canceled))
2438 }
2439
2440 // GetVisible is a wrapper around gtk_cell_renderer_get_visible().
2441 func (v *CellRenderer) GetVisible() bool {
2442 return gobool(C.gtk_cell_renderer_get_visible(v.native()))
2443 }
2444
2445 // SetVisible is a wrapper around gtk_cell_renderer_set_visible().
2446 func (v *CellRenderer) SetVisible(visible bool) {
2447 C.gtk_cell_renderer_set_visible(v.native(), gbool(visible))
2448 }
2449
2450 // GetSensitive is a wrapper around gtk_cell_renderer_get_sensitive().
2451 func (v *CellRenderer) GetSensitive() bool {
2452 return gobool(C.gtk_cell_renderer_get_sensitive(v.native()))
2453 }
2454
2455 // SetSentitive is a wrapper around gtk_cell_renderer_set_sensitive().
2456 func (v *CellRenderer) SetSentitive(sensitive bool) {
2457 C.gtk_cell_renderer_set_sensitive(v.native(), gbool(sensitive))
2458 }
2459
2460 // IsActivatable is a wrapper around gtk_cell_renderer_is_activatable().
2461 func (v *CellRenderer) IsActivatable() bool {
2462 return gobool(C.gtk_cell_renderer_is_activatable(v.native()))
2463 }
2464
2465 // GetState is a wrapper around gtk_cell_renderer_get_state().
2466 func (v *CellRenderer) GetState(widget IWidget,
2467 flags CellRendererState) StateFlags {
2468
2469 return StateFlags(C.gtk_cell_renderer_get_state(v.native(),
2470 widget.toWidget(),
2471 C.GtkCellRendererState(flags)))
2472 }
2473
2474 // SetAlignment is a wrapper around gtk_tree_view_column_set_alignment().
2475 func (v *CellRenderer) SetAlignment(xalign float64, yalign float64) {
2476 C.gtk_cell_renderer_set_alignment(v.native(), C.gfloat(xalign), C.gfloat(yalign))
2477 }
2478
2479 // TODO: gtk_cell_renderer_get_aligned_area
2480 // TODO: gtk_cell_renderer_get_size
2481 // TODO: gtk_cell_renderer_render
2482 // TODO: gtk_cell_renderer_activate
2483 // TODO: gtk_cell_renderer_start_editing
2484 // TODO: gtk_cell_renderer_stop_editing
2485 // TODO: gtk_cell_renderer_get_fixed_size
2486 // TODO: gtk_cell_renderer_set_fixed_size
2487 // TODO: gtk_cell_renderer_get_visible
2488 // TODO: gtk_cell_renderer_set_visible
2489 // TODO: gtk_cell_renderer_get_sensitive
2490 // TODO: gtk_cell_renderer_set_sensitive
2491 // TODO: gtk_cell_renderer_get_alignment
2492 // TODO: gtk_cell_renderer_set_alignment
2493 // TODO: gtk_cell_renderer_get_padding
2494 // TODO: gtk_cell_renderer_set_padding
2495 // TODO: gtk_cell_renderer_get_state
2496 // TODO: gtk_cell_renderer_is_activatable
2497 // TODO: gtk_cell_renderer_get_preferred_height
2498 // TODO: gtk_cell_renderer_get_preferred_height_for_width
2499 // TODO: gtk_cell_renderer_get_preferred_size
2500 // TODO: gtk_cell_renderer_get_preferred_width
2501 // TODO: gtk_cell_renderer_get_preferred_width_for_height
2502 // TODO: gtk_cell_renderer_get_request_mode
20092503
20102504 /*
20112505 * GtkCellRendererSpinner
20322526 }
20332527
20342528 func wrapCellRendererSpinner(obj *glib.Object) *CellRendererSpinner {
2529 if obj == nil {
2530 return nil
2531 }
2532
20352533 return &CellRendererSpinner{CellRenderer{glib.InitiallyUnowned{obj}}}
20362534 }
20372535
20702568 }
20712569
20722570 func wrapCellRendererPixbuf(obj *glib.Object) *CellRendererPixbuf {
2571 if obj == nil {
2572 return nil
2573 }
2574
20732575 return &CellRendererPixbuf{CellRenderer{glib.InitiallyUnowned{obj}}}
20742576 }
20752577
21082610 }
21092611
21102612 func wrapCellRendererProgress(obj *glib.Object) *CellRendererProgress {
2613 if obj == nil {
2614 return nil
2615 }
2616
21112617 return &CellRendererProgress{CellRenderer{glib.InitiallyUnowned{obj}}}
21122618 }
21132619
21462652 }
21472653
21482654 func wrapCellRendererText(obj *glib.Object) *CellRendererText {
2655 if obj == nil {
2656 return nil
2657 }
2658
21492659 return &CellRendererText{CellRenderer{glib.InitiallyUnowned{obj}}}
21502660 }
21512661
21592669 return wrapCellRendererText(obj), nil
21602670 }
21612671
2672 // SetFixedHeightFromFont is a wrapper around gtk_cell_renderer_text_set_fixed_height_from_font
2673 func (v *CellRendererText) SetFixedHeightFromFont(numberOfRows int) {
2674 C.gtk_cell_renderer_text_set_fixed_height_from_font(v.native(), C.gint(numberOfRows))
2675 }
2676
21622677 /*
21632678 * GtkCellRendererToggle
21642679 */
21912706 }
21922707
21932708 func wrapCellRendererToggle(obj *glib.Object) *CellRendererToggle {
2709 if obj == nil {
2710 return nil
2711 }
2712
21942713 return &CellRendererToggle{CellRenderer{glib.InitiallyUnowned{obj}}}
21952714 }
21962715
22392758 }
22402759
22412760 /*
2761 * GtkCellRendererAccel
2762 */
2763
2764 // CellRendererAccel is a representation of GtkCellRendererAccel.
2765 type CellRendererAccel struct {
2766 CellRendererText
2767 }
2768
2769 // native returns a pointer to the underlying GtkCellRendererAccel.
2770 func (v *CellRendererAccel) native() *C.GtkCellRendererAccel {
2771 if v == nil || v.GObject == nil {
2772 return nil
2773 }
2774 p := unsafe.Pointer(v.GObject)
2775 return C.toGtkCellRendererAccel(p)
2776 }
2777
2778 func marshalCellRendererAccel(p uintptr) (interface{}, error) {
2779 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
2780 obj := glib.Take(unsafe.Pointer(c))
2781 return wrapCellRendererAccel(obj), nil
2782 }
2783
2784 func wrapCellRendererAccel(obj *glib.Object) *CellRendererAccel {
2785 if obj == nil {
2786 return nil
2787 }
2788
2789 return &CellRendererAccel{CellRendererText{CellRenderer{glib.InitiallyUnowned{obj}}}}
2790 }
2791
2792 // CellRendererAccelNew is a wrapper around gtk_cell_renderer_accel_new().
2793 func CellRendererAccelNew() (*CellRendererAccel, error) {
2794 c := C.gtk_cell_renderer_accel_new()
2795 if c == nil {
2796 return nil, nilPtrErr
2797 }
2798 obj := glib.Take(unsafe.Pointer(c))
2799 return wrapCellRendererAccel(obj), nil
2800 }
2801
2802 /*
2803 * GtkCellRendererCombo
2804 */
2805
2806 // CellRendererCombo is a representation of GtkCellRendererCombo.
2807 type CellRendererCombo struct {
2808 CellRendererText
2809 }
2810
2811 // native returns a pointer to the underlying GtkCellRendererCombo.
2812 func (v *CellRendererCombo) native() *C.GtkCellRendererCombo {
2813 if v == nil || v.GObject == nil {
2814 return nil
2815 }
2816 p := unsafe.Pointer(v.GObject)
2817 return C.toGtkCellRendererCombo(p)
2818 }
2819
2820 func marshalCellRendererCombo(p uintptr) (interface{}, error) {
2821 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
2822 obj := glib.Take(unsafe.Pointer(c))
2823 return wrapCellRendererCombo(obj), nil
2824 }
2825
2826 func wrapCellRendererCombo(obj *glib.Object) *CellRendererCombo {
2827 if obj == nil {
2828 return nil
2829 }
2830
2831 return &CellRendererCombo{CellRendererText{CellRenderer{glib.InitiallyUnowned{obj}}}}
2832 }
2833
2834 // CellRendererComboNew is a wrapper around gtk_cell_renderer_combo_new().
2835 func CellRendererComboNew() (*CellRendererCombo, error) {
2836 c := C.gtk_cell_renderer_combo_new()
2837 if c == nil {
2838 return nil, nilPtrErr
2839 }
2840 obj := glib.Take(unsafe.Pointer(c))
2841 return wrapCellRendererCombo(obj), nil
2842 }
2843
2844 /*
2845 * GtkCellRendererSpin
2846 */
2847
2848 // CellRendererSpin is a representation of GtkCellRendererSpin.
2849 type CellRendererSpin struct {
2850 CellRendererText
2851 }
2852
2853 // native returns a pointer to the underlying GtkCellRendererSpin.
2854 func (v *CellRendererSpin) native() *C.GtkCellRendererSpin {
2855 if v == nil || v.GObject == nil {
2856 return nil
2857 }
2858 p := unsafe.Pointer(v.GObject)
2859 return C.toGtkCellRendererSpin(p)
2860 }
2861
2862 func marshalCellRendererSpin(p uintptr) (interface{}, error) {
2863 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
2864 obj := glib.Take(unsafe.Pointer(c))
2865 return wrapCellRendererSpin(obj), nil
2866 }
2867
2868 func wrapCellRendererSpin(obj *glib.Object) *CellRendererSpin {
2869 if obj == nil {
2870 return nil
2871 }
2872
2873 return &CellRendererSpin{CellRendererText{CellRenderer{glib.InitiallyUnowned{obj}}}}
2874 }
2875
2876 // CellRendererSpinNew is a wrapper around gtk_cell_renderer_spin_new().
2877 func CellRendererSpinNew() (*CellRendererSpin, error) {
2878 c := C.gtk_cell_renderer_spin_new()
2879 if c == nil {
2880 return nil, nilPtrErr
2881 }
2882 obj := glib.Take(unsafe.Pointer(c))
2883 return wrapCellRendererSpin(obj), nil
2884 }
2885
2886 /*
22422887 * GtkCheckButton
22432888 */
22442889
22632908 }
22642909
22652910 func wrapCheckButton(obj *glib.Object) *CheckButton {
2911 if obj == nil {
2912 return nil
2913 }
2914
22662915 actionable := wrapActionable(obj)
22672916 return &CheckButton{ToggleButton{Button{Bin{Container{Widget{
22682917 glib.InitiallyUnowned{obj}}}}, actionable}}}
23272976 }
23282977
23292978 func wrapCheckMenuItem(obj *glib.Object) *CheckMenuItem {
2979 if obj == nil {
2980 return nil
2981 }
2982
23302983 return &CheckMenuItem{MenuItem{Bin{Container{Widget{
23312984 glib.InitiallyUnowned{obj}}}}}}
23322985 }
23412994 return wrapCheckMenuItem(obj), nil
23422995 }
23432996
2344 // CheckMenuItemNewWithLabel is a wrapper around
2345 // gtk_check_menu_item_new_with_label().
2997 // CheckMenuItemNewWithLabel is a wrapper around gtk_check_menu_item_new_with_label().
23462998 func CheckMenuItemNewWithLabel(label string) (*CheckMenuItem, error) {
23472999 cstr := C.CString(label)
23483000 defer C.free(unsafe.Pointer(cstr))
23543006 return wrapCheckMenuItem(obj), nil
23553007 }
23563008
2357 // CheckMenuItemNewWithMnemonic is a wrapper around
2358 // gtk_check_menu_item_new_with_mnemonic().
3009 // CheckMenuItemNewWithMnemonic is a wrapper around gtk_check_menu_item_new_with_mnemonic().
23593010 func CheckMenuItemNewWithMnemonic(label string) (*CheckMenuItem, error) {
23603011 cstr := C.CString(label)
23613012 defer C.free(unsafe.Pointer(cstr))
24303081 }
24313082
24323083 func wrapClipboard(obj *glib.Object) *Clipboard {
3084 if obj == nil {
3085 return nil
3086 }
3087
24333088 return &Clipboard{obj}
24343089 }
24353090
25623217 }
25633218
25643219 func wrapContainer(obj *glib.Object) *Container {
3220 if obj == nil {
3221 return nil
3222 }
3223
25653224 return &Container{Widget{glib.InitiallyUnowned{obj}}}
25663225 }
25673226
25873246 // GetChildren is a wrapper around gtk_container_get_children().
25883247 func (v *Container) GetChildren() *glib.List {
25893248 clist := C.gtk_container_get_children(v.native())
3249 if clist == nil {
3250 return nil
3251 }
3252
25903253 glist := glib.WrapList(uintptr(unsafe.Pointer(clist)))
25913254 glist.DataWrapper(func(ptr unsafe.Pointer) interface{} {
25923255 return wrapWidget(glib.Take(ptr))
25983261 // TODO: gtk_container_get_path_for_child
25993262
26003263 // GetFocusChild is a wrapper around gtk_container_get_focus_child().
2601 func (v *Container) GetFocusChild() *Widget {
3264 func (v *Container) GetFocusChild() (IWidget, error) {
26023265 c := C.gtk_container_get_focus_child(v.native())
26033266 if c == nil {
2604 return nil
2605 }
2606 obj := glib.Take(unsafe.Pointer(c))
2607 return wrapWidget(obj)
3267 return nil, nil
3268 }
3269 return castWidget(c)
26083270 }
26093271
26103272 // SetFocusChild is a wrapper around gtk_container_set_focus_child().
26123274 C.gtk_container_set_focus_child(v.native(), child.toWidget())
26133275 }
26143276
2615 // GetFocusVAdjustment is a wrapper around
2616 // gtk_container_get_focus_vadjustment().
3277 // GetFocusVAdjustment is a wrapper around gtk_container_get_focus_vadjustment().
26173278 func (v *Container) GetFocusVAdjustment() *Adjustment {
26183279 c := C.gtk_container_get_focus_vadjustment(v.native())
26193280 if c == nil {
26233284 return wrapAdjustment(obj)
26243285 }
26253286
2626 // SetFocusVAdjustment is a wrapper around
2627 // gtk_container_set_focus_vadjustment().
3287 // SetFocusVAdjustment is a wrapper around gtk_container_set_focus_vadjustment().
26283288 func (v *Container) SetFocusVAdjustment(adjustment *Adjustment) {
26293289 C.gtk_container_set_focus_vadjustment(v.native(), adjustment.native())
26303290 }
26313291
2632 // GetFocusHAdjustment is a wrapper around
2633 // gtk_container_get_focus_hadjustment().
3292 // GetFocusHAdjustment is a wrapper around gtk_container_get_focus_hadjustment().
26343293 func (v *Container) GetFocusHAdjustment() *Adjustment {
26353294 c := C.gtk_container_get_focus_hadjustment(v.native())
26363295 if c == nil {
26403299 return wrapAdjustment(obj)
26413300 }
26423301
2643 // SetFocusHAdjustment is a wrapper around
2644 // gtk_container_set_focus_hadjustment().
3302 // SetFocusHAdjustment is a wrapper around gtk_container_set_focus_hadjustment().
26453303 func (v *Container) SetFocusHAdjustment(adjustment *Adjustment) {
26463304 C.gtk_container_set_focus_hadjustment(v.native(), adjustment.native())
26473305 }
26523310 return glib.Type(c)
26533311 }
26543312
2655 // TODO: gtk_container_child_get_valist
2656 // TODO: gtk_container_child_set_valist
3313 // TODO:
3314 // gtk_container_child_get().
3315 // gtk_container_child_set().
26573316
26583317 // ChildNotify is a wrapper around gtk_container_child_notify().
26593318 func (v *Container) ChildNotify(child IWidget, childProperty string) {
26893348 return nil
26903349 }
26913350
2692 // TODO: gtk_container_forall
3351 // TODO:
3352 // gtk_container_child_get_valist().
3353 // gtk_container_child_set_valist().
3354 // gtk_container_child_notify_by_pspec().
3355 // gtk_container_forall().
26933356
26943357 // GetBorderWidth is a wrapper around gtk_container_get_border_width().
26953358 func (v *Container) GetBorderWidth() uint {
27073370 context := (*C.cairo_t)(unsafe.Pointer(cr.Native()))
27083371 C.gtk_container_propagate_draw(v.native(), child.toWidget(), context)
27093372 }
3373
3374 // TODO:
3375 // gtk_container_class_find_child_property().
3376 // gtk_container_class_install_child_property().
3377 // gtk_container_class_install_child_properties().
3378 // gtk_container_class_list_child_properties().
3379 // gtk_container_class_handle_border_width().
3380 // GtkResizeMode
27103381
27113382 // GdkCairoSetSourcePixBuf() is a wrapper around gdk_cairo_set_source_pixbuf().
27123383 func GdkCairoSetSourcePixBuf(cr *cairo.Context, pixbuf *gdk.Pixbuf, pixbufX, pixbufY float64) {
27413412 }
27423413
27433414 func wrapCssProvider(obj *glib.Object) *CssProvider {
3415 if obj == nil {
3416 return nil
3417 }
3418
27443419 return &CssProvider{obj}
27453420 }
27463421
27873462 return C.GoString(c), nil
27883463 }
27893464
2790 // GetNamed is a wrapper around gtk_css_provider_get_named().
3465 // CssProviderGetNamed is a wrapper around gtk_css_provider_get_named().
27913466 func CssProviderGetNamed(name string, variant string) (*CssProvider, error) {
27923467 cname := C.CString(name)
27933468 defer C.free(unsafe.Pointer(cname))
28283503 }
28293504
28303505 func wrapDialog(obj *glib.Object) *Dialog {
3506 if obj == nil {
3507 return nil
3508 }
3509
28313510 return &Dialog{Window{Bin{Container{Widget{glib.InitiallyUnowned{obj}}}}}}
28323511 }
28333512
28663545 return wrapButton(obj), nil
28673546 }
28683547
3548 // TODO:
3549 // gtk_dialog_add_buttons().
3550
28693551 // AddActionWidget() is a wrapper around gtk_dialog_add_action_widget().
28703552 func (v *Dialog) AddActionWidget(child IWidget, id ResponseType) {
28713553 C.gtk_dialog_add_action_widget(v.native(), child.toWidget(), C.gint(id))
28763558 C.gtk_dialog_set_default_response(v.native(), C.gint(id))
28773559 }
28783560
2879 // SetResponseSensitive() is a wrapper around
2880 // gtk_dialog_set_response_sensitive().
3561 // SetResponseSensitive() is a wrapper around gtk_dialog_set_response_sensitive().
28813562 func (v *Dialog) SetResponseSensitive(id ResponseType, setting bool) {
28823563 C.gtk_dialog_set_response_sensitive(v.native(), C.gint(id),
28833564 gbool(setting))
28843565 }
28853566
2886 // GetResponseForWidget() is a wrapper around
2887 // gtk_dialog_get_response_for_widget().
3567 // GetResponseForWidget is a wrapper around gtk_dialog_get_response_for_widget().
28883568 func (v *Dialog) GetResponseForWidget(widget IWidget) ResponseType {
28893569 c := C.gtk_dialog_get_response_for_widget(v.native(), widget.toWidget())
28903570 return ResponseType(c)
28913571 }
28923572
2893 // GetWidgetForResponse() is a wrapper around
2894 // gtk_dialog_get_widget_for_response().
2895 func (v *Dialog) GetWidgetForResponse(id ResponseType) (*Widget, error) {
3573 // GetWidgetForResponse is a wrapper around gtk_dialog_get_widget_for_response().
3574 func (v *Dialog) GetWidgetForResponse(id ResponseType) (IWidget, error) {
28963575 c := C.gtk_dialog_get_widget_for_response(v.native(), C.gint(id))
28973576 if c == nil {
2898 return nil, nilPtrErr
2899 }
2900 obj := glib.Take(unsafe.Pointer(c))
2901 return wrapWidget(obj), nil
3577 return nil, nil
3578 }
3579 return castWidget(c)
29023580 }
29033581
29043582 // GetContentArea() is a wrapper around gtk_dialog_get_content_area().
29413619 return
29423620 }
29433621
2944 // TODO(jrick)
2945 /*
2946 func (v *gdk.Screen) AlternativeDialogButtonOrder() bool {
2947 c := C.gtk_alternative_dialog_button_order(v.native())
2948 return gobool(c)
2949 }
2950 */
2951
2952 // TODO(jrick)
2953 /*
2954 func SetAlternativeButtonOrder(ids ...ResponseType) {
2955 }
2956 */
2957
29583622 /*
29593623 * GtkDrawingArea
29603624 */
29803644 }
29813645
29823646 func wrapDrawingArea(obj *glib.Object) *DrawingArea {
3647 if obj == nil {
3648 return nil
3649 }
3650
29833651 return &DrawingArea{Widget{glib.InitiallyUnowned{obj}}}
29843652 }
29853653
30263694 }
30273695
30283696 func wrapEditable(obj *glib.Object) *Editable {
3697 if obj == nil {
3698 return nil
3699 }
3700
30293701 return &Editable{obj}
30303702 }
30313703
31263798
31273799 // Interfaces
31283800 Editable
3801 CellEditable
31293802 }
31303803
31313804 type IEntry interface {
31523825 }
31533826
31543827 func wrapEntry(obj *glib.Object) *Entry {
3828 if obj == nil {
3829 return nil
3830 }
3831
31553832 e := wrapEditable(obj)
3156 return &Entry{Widget{glib.InitiallyUnowned{obj}}, *e}
3833 ce := wrapCellEditable(obj)
3834 return &Entry{Widget{glib.InitiallyUnowned{obj}}, *e, *ce}
31573835 }
31583836
31593837 // EntryNew() is a wrapper around gtk_entry_new().
32133891 return uint16(c)
32143892 }
32153893
3216 // TODO(jrick) GdkRectangle
3217 /*
3218 func (v *Entry) GetTextArea() {
3219 }
3220 */
3221
3222 // SetVisibility() is a wrapper around gtk_entry_set_visibility().
3894 // GetTextArea is a wrapper around gtk_entry_get_text_area().
3895 func (v *Entry) GetTextArea() *gdk.Rectangle {
3896 var cRect *C.GdkRectangle
3897 C.gtk_entry_get_text_area(v.native(), cRect)
3898 textArea := gdk.WrapRectangle(uintptr(unsafe.Pointer(cRect)))
3899 return textArea
3900 }
3901
3902 // SetVisibility is a wrapper around gtk_entry_set_visibility().
32233903 func (v *Entry) SetVisibility(visible bool) {
32243904 C.gtk_entry_set_visibility(v.native(), gbool(visible))
32253905 }
32263906
3227 // SetInvisibleChar() is a wrapper around gtk_entry_set_invisible_char().
3907 // SetInvisibleChar is a wrapper around gtk_entry_set_invisible_char().
32283908 func (v *Entry) SetInvisibleChar(ch rune) {
32293909 C.gtk_entry_set_invisible_char(v.native(), C.gunichar(ch))
32303910 }
32313911
3232 // UnsetInvisibleChar() is a wrapper around gtk_entry_unset_invisible_char().
3912 // UnsetInvisibleChar is a wrapper around gtk_entry_unset_invisible_char().
32333913 func (v *Entry) UnsetInvisibleChar() {
32343914 C.gtk_entry_unset_invisible_char(v.native())
32353915 }
32363916
3237 // SetMaxLength() is a wrapper around gtk_entry_set_max_length().
3917 // SetMaxLength is a wrapper around gtk_entry_set_max_length().
32383918 func (v *Entry) SetMaxLength(len int) {
32393919 C.gtk_entry_set_max_length(v.native(), C.gint(len))
32403920 }
32413921
3242 // GetActivatesDefault() is a wrapper around gtk_entry_get_activates_default().
3922 // GetActivatesDefault is a wrapper around gtk_entry_get_activates_default().
32433923 func (v *Entry) GetActivatesDefault() bool {
32443924 c := C.gtk_entry_get_activates_default(v.native())
32453925 return gobool(c)
32463926 }
32473927
3248 // GetHasFrame() is a wrapper around gtk_entry_get_has_frame().
3928 // GetHasFrame is a wrapper around gtk_entry_get_has_frame().
32493929 func (v *Entry) GetHasFrame() bool {
32503930 c := C.gtk_entry_get_has_frame(v.native())
32513931 return gobool(c)
32523932 }
32533933
3254 // GetWidthChars() is a wrapper around gtk_entry_get_width_chars().
3934 // GetWidthChars is a wrapper around gtk_entry_get_width_chars().
32553935 func (v *Entry) GetWidthChars() int {
32563936 c := C.gtk_entry_get_width_chars(v.native())
32573937 return int(c)
32583938 }
32593939
3260 // SetActivatesDefault() is a wrapper around gtk_entry_set_activates_default().
3940 // SetActivatesDefault is a wrapper around gtk_entry_set_activates_default().
32613941 func (v *Entry) SetActivatesDefault(setting bool) {
32623942 C.gtk_entry_set_activates_default(v.native(), gbool(setting))
32633943 }
32643944
3265 // SetHasFrame() is a wrapper around gtk_entry_set_has_frame().
3945 // SetHasFrame is a wrapper around gtk_entry_set_has_frame().
32663946 func (v *Entry) SetHasFrame(setting bool) {
32673947 C.gtk_entry_set_has_frame(v.native(), gbool(setting))
32683948 }
32693949
3270 // SetWidthChars() is a wrapper around gtk_entry_set_width_chars().
3950 // SetWidthChars is a wrapper around gtk_entry_set_width_chars().
32713951 func (v *Entry) SetWidthChars(nChars int) {
32723952 C.gtk_entry_set_width_chars(v.native(), C.gint(nChars))
32733953 }
32743954
3275 // GetInvisibleChar() is a wrapper around gtk_entry_get_invisible_char().
3955 // GetInvisibleChar is a wrapper around gtk_entry_get_invisible_char().
32763956 func (v *Entry) GetInvisibleChar() rune {
32773957 c := C.gtk_entry_get_invisible_char(v.native())
32783958 return rune(c)
32793959 }
32803960
3281 // SetAlignment() is a wrapper around gtk_entry_set_alignment().
3961 // SetAlignment is a wrapper around gtk_entry_set_alignment().
32823962 func (v *Entry) SetAlignment(xalign float32) {
32833963 C.gtk_entry_set_alignment(v.native(), C.gfloat(xalign))
32843964 }
32853965
3286 // GetAlignment() is a wrapper around gtk_entry_get_alignment().
3966 // GetAlignment is a wrapper around gtk_entry_get_alignment().
32873967 func (v *Entry) GetAlignment() float32 {
32883968 c := C.gtk_entry_get_alignment(v.native())
32893969 return float32(c)
32903970 }
32913971
3292 // SetPlaceholderText() is a wrapper around gtk_entry_set_placeholder_text().
3972 // SetPlaceholderText is a wrapper around gtk_entry_set_placeholder_text().
32933973 func (v *Entry) SetPlaceholderText(text string) {
32943974 cstr := C.CString(text)
32953975 defer C.free(unsafe.Pointer(cstr))
32963976 C.gtk_entry_set_placeholder_text(v.native(), (*C.gchar)(cstr))
32973977 }
32983978
3299 // GetPlaceholderText() is a wrapper around gtk_entry_get_placeholder_text().
3979 // GetPlaceholderText is a wrapper around gtk_entry_get_placeholder_text().
33003980 func (v *Entry) GetPlaceholderText() (string, error) {
33013981 c := C.gtk_entry_get_placeholder_text(v.native())
33023982 if c == nil {
33053985 return goString(c), nil
33063986 }
33073987
3308 // SetOverwriteMode() is a wrapper around gtk_entry_set_overwrite_mode().
3988 // SetOverwriteMode is a wrapper around gtk_entry_set_overwrite_mode().
33093989 func (v *Entry) SetOverwriteMode(overwrite bool) {
33103990 C.gtk_entry_set_overwrite_mode(v.native(), gbool(overwrite))
33113991 }
33123992
3313 // GetOverwriteMode() is a wrapper around gtk_entry_get_overwrite_mode().
3993 // GetOverwriteMode is a wrapper around gtk_entry_get_overwrite_mode().
33143994 func (v *Entry) GetOverwriteMode() bool {
33153995 c := C.gtk_entry_get_overwrite_mode(v.native())
33163996 return gobool(c)
33173997 }
33183998
3319 // TODO(jrick) Pangolayout
3320 /*
3321 func (v *Entry) GetLayout() {
3322 }
3323 */
3324
3325 // GetLayoutOffsets() is a wrapper around gtk_entry_get_layout_offsets().
3999 // GetLayout is a wrapper around gtk_entry_get_layout().
4000 func (v *Entry) GetLayout() *pango.Layout {
4001 c := C.gtk_entry_get_layout(v.native())
4002 return pango.WrapLayout(uintptr(unsafe.Pointer(c)))
4003 }
4004
4005 // GetLayoutOffsets is a wrapper around gtk_entry_get_layout_offsets().
33264006 func (v *Entry) GetLayoutOffsets() (x, y int) {
33274007 var gx, gy C.gint
33284008 C.gtk_entry_get_layout_offsets(v.native(), &gx, &gy)
33294009 return int(gx), int(gy)
33304010 }
33314011
3332 // LayoutIndexToTextIndex() is a wrapper around
3333 // gtk_entry_layout_index_to_text_index().
4012 // LayoutIndexToTextIndex is a wrapper around gtk_entry_layout_index_to_text_index().
33344013 func (v *Entry) LayoutIndexToTextIndex(layoutIndex int) int {
33354014 c := C.gtk_entry_layout_index_to_text_index(v.native(),
33364015 C.gint(layoutIndex))
33374016 return int(c)
33384017 }
33394018
3340 // TextIndexToLayoutIndex() is a wrapper around
3341 // gtk_entry_text_index_to_layout_index().
4019 // TextIndexToLayoutIndex is a wrapper around gtk_entry_text_index_to_layout_index().
33424020 func (v *Entry) TextIndexToLayoutIndex(textIndex int) int {
33434021 c := C.gtk_entry_text_index_to_layout_index(v.native(),
33444022 C.gint(textIndex))
33454023 return int(c)
33464024 }
33474025
3348 // TODO(jrick) PandoAttrList
3349 /*
3350 func (v *Entry) SetAttributes() {
3351 }
3352 */
3353
3354 // TODO(jrick) PandoAttrList
3355 /*
3356 func (v *Entry) GetAttributes() {
3357 }
3358 */
3359
3360 // GetMaxLength() is a wrapper around gtk_entry_get_max_length().
4026 // TODO: depends on PandoAttrList
4027 // SetAttributes is a wrapper around gtk_entry_set_attributes().
4028 // func (v *Entry) SetAttributes(attrList *pango.AttrList) {
4029 // C.gtk_entry_set_attributes(v.native(), (*C.PangoAttrList)(unsafe.Pointer(attrList.Native())))
4030 // }
4031
4032 // TODO: depends on PandoAttrList
4033 // GetAttributes is a wrapper around gtk_entry_get_attributes().
4034 // func (v *Entry) GetAttributes() (*pango.AttrList, error) {
4035 // c := C.gtk_entry_get_attributes(v.native())
4036 // if c == nil {
4037 // return nil, nilPtrErr
4038 // }
4039 // return &pango.AttrList{unsafe.Pointer(c)}, nil
4040 // }
4041
4042 // GetMaxLength is a wrapper around gtk_entry_get_max_length().
33614043 func (v *Entry) GetMaxLength() int {
33624044 c := C.gtk_entry_get_max_length(v.native())
33634045 return int(c)
33644046 }
33654047
3366 // GetVisibility() is a wrapper around gtk_entry_get_visibility().
4048 // GetVisibility is a wrapper around gtk_entry_get_visibility().
33674049 func (v *Entry) GetVisibility() bool {
33684050 c := C.gtk_entry_get_visibility(v.native())
33694051 return gobool(c)
33704052 }
33714053
3372 // SetCompletion() is a wrapper around gtk_entry_set_completion().
4054 // SetCompletion is a wrapper around gtk_entry_set_completion().
33734055 func (v *Entry) SetCompletion(completion *EntryCompletion) {
33744056 C.gtk_entry_set_completion(v.native(), completion.native())
33754057 }
33764058
3377 // GetCompletion() is a wrapper around gtk_entry_get_completion().
4059 // GetCompletion is a wrapper around gtk_entry_get_completion().
33784060 func (v *Entry) GetCompletion() (*EntryCompletion, error) {
33794061 c := C.gtk_entry_get_completion(v.native())
33804062 if c == nil {
33854067 return e, nil
33864068 }
33874069
3388 // SetCursorHAdjustment() is a wrapper around
3389 // gtk_entry_set_cursor_hadjustment().
4070 // SetCursorHAdjustment is a wrapper around gtk_entry_set_cursor_hadjustment().
33904071 func (v *Entry) SetCursorHAdjustment(adjustment *Adjustment) {
33914072 C.gtk_entry_set_cursor_hadjustment(v.native(), adjustment.native())
33924073 }
33934074
3394 // GetCursorHAdjustment() is a wrapper around
3395 // gtk_entry_get_cursor_hadjustment().
4075 // GetCursorHAdjustment is a wrapper around gtk_entry_get_cursor_hadjustment().
33964076 func (v *Entry) GetCursorHAdjustment() (*Adjustment, error) {
33974077 c := C.gtk_entry_get_cursor_hadjustment(v.native())
33984078 if c == nil {
34024082 return &Adjustment{glib.InitiallyUnowned{obj}}, nil
34034083 }
34044084
3405 // SetProgressFraction() is a wrapper around gtk_entry_set_progress_fraction().
4085 // SetProgressFraction is a wrapper around gtk_entry_set_progress_fraction().
34064086 func (v *Entry) SetProgressFraction(fraction float64) {
34074087 C.gtk_entry_set_progress_fraction(v.native(), C.gdouble(fraction))
34084088 }
34094089
3410 // GetProgressFraction() is a wrapper around gtk_entry_get_progress_fraction().
4090 // GetProgressFraction is a wrapper around gtk_entry_get_progress_fraction().
34114091 func (v *Entry) GetProgressFraction() float64 {
34124092 c := C.gtk_entry_get_progress_fraction(v.native())
34134093 return float64(c)
34144094 }
34154095
3416 // SetProgressPulseStep() is a wrapper around
3417 // gtk_entry_set_progress_pulse_step().
4096 // SetProgressPulseStep is a wrapper around gtk_entry_set_progress_pulse_step().
34184097 func (v *Entry) SetProgressPulseStep(fraction float64) {
34194098 C.gtk_entry_set_progress_pulse_step(v.native(), C.gdouble(fraction))
34204099 }
34214100
3422 // GetProgressPulseStep() is a wrapper around
3423 // gtk_entry_get_progress_pulse_step().
4101 // GetProgressPulseStep is a wrapper around gtk_entry_get_progress_pulse_step().
34244102 func (v *Entry) GetProgressPulseStep() float64 {
34254103 c := C.gtk_entry_get_progress_pulse_step(v.native())
34264104 return float64(c)
34274105 }
34284106
3429 // ProgressPulse() is a wrapper around gtk_entry_progress_pulse().
4107 // ProgressPulse is a wrapper around gtk_entry_progress_pulse().
34304108 func (v *Entry) ProgressPulse() {
34314109 C.gtk_entry_progress_pulse(v.native())
34324110 }
34334111
3434 // TODO(jrick) GdkEventKey
3435 /*
3436 func (v *Entry) IMContextFilterKeypress() {
3437 }
3438 */
3439
3440 // ResetIMContext() is a wrapper around gtk_entry_reset_im_context().
4112 // IMContextFilterKeypress is a wrapper around gtk_entry_im_context_filter_keypress().
4113 func (v *Entry) IMContextFilterKeypress(eventKey *gdk.EventKey) bool {
4114 key := (*C.GdkEventKey)(unsafe.Pointer(eventKey.Native()))
4115 c := C.gtk_entry_im_context_filter_keypress(v.native(), key)
4116 return gobool(c)
4117 }
4118
4119 // ResetIMContext is a wrapper around gtk_entry_reset_im_context().
34414120 func (v *Entry) ResetIMContext() {
34424121 C.gtk_entry_reset_im_context(v.native())
34434122 }
34444123
34454124 // SetIconFromPixbuf is a wrapper around gtk_entry_set_icon_from_pixbuf().
34464125 func (v *Entry) SetIconFromPixbuf(iconPos EntryIconPosition, pixbuf *gdk.Pixbuf) {
3447 C.gtk_entry_set_icon_from_pixbuf(v.native(),
4126 var pb *C.GdkPixbuf
4127 if pixbuf != nil {
4128 pb = (*C.GdkPixbuf)(unsafe.Pointer(pixbuf.Native()))
4129 }
4130
4131 C.gtk_entry_set_icon_from_pixbuf(v.native(), C.GtkEntryIconPosition(iconPos), pb)
4132 }
4133
4134 // SetIconFromIconName is a wrapper around gtk_entry_set_icon_from_icon_name().
4135 func (v *Entry) SetIconFromIconName(iconPos EntryIconPosition, name string) {
4136 var icon *C.gchar
4137 if name != "" {
4138 n := C.CString(name)
4139 defer C.free(unsafe.Pointer(n))
4140 icon = (*C.gchar)(n)
4141 }
4142
4143 C.gtk_entry_set_icon_from_icon_name(v.native(), C.GtkEntryIconPosition(iconPos), icon)
4144 }
4145
4146 // RemoveIcon is a convenience func to set a nil pointer to the icon name.
4147 func (v *Entry) RemoveIcon(iconPos EntryIconPosition) {
4148 C.gtk_entry_set_icon_from_icon_name(v.native(), C.GtkEntryIconPosition(iconPos), nil)
4149 }
4150
4151 // TODO: Needs gio/GIcon implemented first
4152 // SetIconFromGIcon is a wrapper around gtk_entry_set_icon_from_gicon().
4153 func (v *Entry) SetIconFromGIcon(iconPos EntryIconPosition, icon *glib.Icon) {
4154 C.gtk_entry_set_icon_from_gicon(v.native(),
34484155 C.GtkEntryIconPosition(iconPos),
3449 (*C.GdkPixbuf)(unsafe.Pointer(pixbuf.Native())))
3450 }
3451
3452 // SetIconFromIconName() is a wrapper around
3453 // gtk_entry_set_icon_from_icon_name().
3454 func (v *Entry) SetIconFromIconName(iconPos EntryIconPosition, name string) {
3455 cstr := C.CString(name)
3456 defer C.free(unsafe.Pointer(cstr))
3457 C.gtk_entry_set_icon_from_icon_name(v.native(),
3458 C.GtkEntryIconPosition(iconPos), (*C.gchar)(cstr))
3459 }
3460
3461 // RemoveIcon() is a wrapper around gtk_entry_set_icon_from_icon_name()
3462 // with a nil pointer to the icon name.
3463 func (v *Entry) RemoveIcon(iconPos EntryIconPosition) {
3464 C.gtk_entry_set_icon_from_icon_name(v.native(),
3465 C.GtkEntryIconPosition(iconPos), nil)
3466 }
3467
3468 // TODO(jrick) GIcon
3469 /*
3470 func (v *Entry) SetIconFromGIcon() {
3471 }
3472 */
3473
3474 // GetIconStorageType() is a wrapper around gtk_entry_get_icon_storage_type().
4156 (*C.GIcon)(icon.NativePrivate()))
4157 }
4158
4159 // GetIconStorageType is a wrapper around gtk_entry_get_icon_storage_type().
34754160 func (v *Entry) GetIconStorageType(iconPos EntryIconPosition) ImageType {
3476 c := C.gtk_entry_get_icon_storage_type(v.native(),
3477 C.GtkEntryIconPosition(iconPos))
4161 c := C.gtk_entry_get_icon_storage_type(v.native(), C.GtkEntryIconPosition(iconPos))
34784162 return ImageType(c)
34794163 }
34804164
3481 // TODO(jrick) GdkPixbuf
3482 /*
3483 func (v *Entry) GetIconPixbuf() {
3484 }
3485 */
3486
3487 // GetIconName() is a wrapper around gtk_entry_get_icon_name().
4165 // GetIconPixbuf is a wrapper around gtk_entry_get_icon_pixbuf().
4166 func (v *Entry) GetIconPixbuf(iconPos EntryIconPosition) (*gdk.Pixbuf, error) {
4167 c := C.gtk_entry_get_icon_pixbuf(v.native(), C.GtkEntryIconPosition(iconPos))
4168 if c == nil {
4169 return nil, nilPtrErr
4170 }
4171 return &gdk.Pixbuf{glib.Take(unsafe.Pointer(c))}, nil
4172 }
4173
4174 // GetIconName is a wrapper around gtk_entry_get_icon_name().
34884175 func (v *Entry) GetIconName(iconPos EntryIconPosition) (string, error) {
3489 c := C.gtk_entry_get_icon_name(v.native(),
3490 C.GtkEntryIconPosition(iconPos))
4176 c := C.gtk_entry_get_icon_name(v.native(), C.GtkEntryIconPosition(iconPos))
34914177 if c == nil {
34924178 return "", nilPtrErr
34934179 }
34944180 return goString(c), nil
34954181 }
34964182
3497 // TODO(jrick) GIcon
3498 /*
3499 func (v *Entry) GetIconGIcon() {
3500 }
3501 */
3502
3503 // SetIconActivatable() is a wrapper around gtk_entry_set_icon_activatable().
4183 // GetIconGIcon is a wrapper around gtk_entry_get_icon_gicon().
4184 func (v *Entry) GetIconGIcon(iconPos EntryIconPosition) (*glib.Icon, error) {
4185 c := C.gtk_entry_get_icon_gicon(v.native(), C.GtkEntryIconPosition(iconPos))
4186 if c == nil {
4187 return nil, nilPtrErr
4188 }
4189 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
4190 i := &glib.Icon{obj}
4191 runtime.SetFinalizer(i, func(_ interface{}) { obj.Unref() })
4192 return i, nil
4193 }
4194
4195 // SetIconActivatable is a wrapper around gtk_entry_set_icon_activatable().
35044196 func (v *Entry) SetIconActivatable(iconPos EntryIconPosition, activatable bool) {
3505 C.gtk_entry_set_icon_activatable(v.native(),
3506 C.GtkEntryIconPosition(iconPos), gbool(activatable))
3507 }
3508
3509 // GetIconActivatable() is a wrapper around gtk_entry_get_icon_activatable().
4197 C.gtk_entry_set_icon_activatable(v.native(), C.GtkEntryIconPosition(iconPos), gbool(activatable))
4198 }
4199
4200 // GetIconActivatable is a wrapper around gtk_entry_get_icon_activatable().
35104201 func (v *Entry) GetIconActivatable(iconPos EntryIconPosition) bool {
3511 c := C.gtk_entry_get_icon_activatable(v.native(),
3512 C.GtkEntryIconPosition(iconPos))
4202 c := C.gtk_entry_get_icon_activatable(v.native(), C.GtkEntryIconPosition(iconPos))
35134203 return gobool(c)
35144204 }
35154205
3516 // SetIconSensitive() is a wrapper around gtk_entry_set_icon_sensitive().
4206 // SetIconSensitive is a wrapper around gtk_entry_set_icon_sensitive().
35174207 func (v *Entry) SetIconSensitive(iconPos EntryIconPosition, sensitive bool) {
3518 C.gtk_entry_set_icon_sensitive(v.native(),
3519 C.GtkEntryIconPosition(iconPos), gbool(sensitive))
3520 }
3521
3522 // GetIconSensitive() is a wrapper around gtk_entry_get_icon_sensitive().
4208 C.gtk_entry_set_icon_sensitive(v.native(), C.GtkEntryIconPosition(iconPos), gbool(sensitive))
4209 }
4210
4211 // GetIconSensitive is a wrapper around gtk_entry_get_icon_sensitive().
35234212 func (v *Entry) GetIconSensitive(iconPos EntryIconPosition) bool {
3524 c := C.gtk_entry_get_icon_sensitive(v.native(),
3525 C.GtkEntryIconPosition(iconPos))
4213 c := C.gtk_entry_get_icon_sensitive(v.native(), C.GtkEntryIconPosition(iconPos))
35264214 return gobool(c)
35274215 }
35284216
3529 // GetIconAtPos() is a wrapper around gtk_entry_get_icon_at_pos().
4217 // GetIconAtPos is a wrapper around gtk_entry_get_icon_at_pos().
35304218 func (v *Entry) GetIconAtPos(x, y int) int {
35314219 c := C.gtk_entry_get_icon_at_pos(v.native(), C.gint(x), C.gint(y))
35324220 return int(c)
35334221 }
35344222
3535 // SetIconTooltipText() is a wrapper around gtk_entry_set_icon_tooltip_text().
4223 // SetIconTooltipText is a wrapper around gtk_entry_set_icon_tooltip_text().
35364224 func (v *Entry) SetIconTooltipText(iconPos EntryIconPosition, tooltip string) {
3537 cstr := C.CString(tooltip)
3538 defer C.free(unsafe.Pointer(cstr))
3539 C.gtk_entry_set_icon_tooltip_text(v.native(),
3540 C.GtkEntryIconPosition(iconPos), (*C.gchar)(cstr))
3541 }
3542
3543 // GetIconTooltipText() is a wrapper around gtk_entry_get_icon_tooltip_text().
4225 var text *C.gchar
4226 if tooltip != "" {
4227 cstr := C.CString(tooltip)
4228 defer C.free(unsafe.Pointer(cstr))
4229 text = cstr
4230 }
4231
4232 C.gtk_entry_set_icon_tooltip_text(v.native(), C.GtkEntryIconPosition(iconPos), text)
4233 }
4234
4235 // GetIconTooltipText is a wrapper around gtk_entry_get_icon_tooltip_text().
35444236 func (v *Entry) GetIconTooltipText(iconPos EntryIconPosition) (string, error) {
35454237 c := C.gtk_entry_get_icon_tooltip_text(v.native(),
35464238 C.GtkEntryIconPosition(iconPos))
35504242 return goString(c), nil
35514243 }
35524244
3553 // SetIconTooltipMarkup() is a wrapper around
3554 // gtk_entry_set_icon_tooltip_markup().
4245 // SetIconTooltipMarkup is a wrapper around gtk_entry_set_icon_tooltip_markup().
35554246 func (v *Entry) SetIconTooltipMarkup(iconPos EntryIconPosition, tooltip string) {
3556 cstr := C.CString(tooltip)
3557 defer C.free(unsafe.Pointer(cstr))
3558 C.gtk_entry_set_icon_tooltip_markup(v.native(),
3559 C.GtkEntryIconPosition(iconPos), (*C.gchar)(cstr))
3560 }
3561
3562 // GetIconTooltipMarkup() is a wrapper around
3563 // gtk_entry_get_icon_tooltip_markup().
4247 var text *C.gchar
4248 if tooltip != "" {
4249 cstr := C.CString(tooltip)
4250 defer C.free(unsafe.Pointer(cstr))
4251 text = cstr
4252 }
4253
4254 C.gtk_entry_set_icon_tooltip_markup(v.native(), C.GtkEntryIconPosition(iconPos), text)
4255 }
4256
4257 // GetIconTooltipMarkup is a wrapper around gtk_entry_get_icon_tooltip_markup().
35644258 func (v *Entry) GetIconTooltipMarkup(iconPos EntryIconPosition) (string, error) {
35654259 c := C.gtk_entry_get_icon_tooltip_markup(v.native(),
35664260 C.GtkEntryIconPosition(iconPos))
35704264 return goString(c), nil
35714265 }
35724266
3573 // TODO(jrick) GdkDragAction
3574 /*
3575 func (v *Entry) SetIconDragSource() {
3576 }
3577 */
3578
3579 // GetCurrentIconDragSource() is a wrapper around
3580 // gtk_entry_get_current_icon_drag_source().
4267 // TODO: depends on GtkTargetList
4268 // SetIconDragSource is a wrapper around gtk_entry_set_icon_drag_source().
4269 // func (v *Entry) SetIconDragSource(iconPos EntryIconPosition, targetList *TargetList, action gdk.DragAction) {
4270 // C.gtk_entry_set_icon_drag_source(v.native(), C.GtkEntryIconPosition(iconPos),
4271 // targetList.native(), C.GdkDragAction(action))
4272 // }
4273
4274 // GetCurrentIconDragSource is a wrapper around gtk_entry_get_current_icon_drag_source().
35814275 func (v *Entry) GetCurrentIconDragSource() int {
35824276 c := C.gtk_entry_get_current_icon_drag_source(v.native())
35834277 return int(c)
35844278 }
35854279
3586 // TODO(jrick) GdkRectangle
3587 /*
3588 func (v *Entry) GetIconArea() {
3589 }
3590 */
3591
3592 // SetInputPurpose() is a wrapper around gtk_entry_set_input_purpose().
4280 // GetIconArea is a wrapper around gtk_entry_get_icon_area().
4281 func (v *Entry) GetIconArea(iconPos EntryIconPosition) *gdk.Rectangle {
4282 var cRect *C.GdkRectangle
4283 C.gtk_entry_get_icon_area(v.native(), C.GtkEntryIconPosition(iconPos), cRect)
4284 iconArea := gdk.WrapRectangle(uintptr(unsafe.Pointer(cRect)))
4285 return iconArea
4286 }
4287
4288 // SetInputPurpose is a wrapper around gtk_entry_set_input_purpose().
35934289 func (v *Entry) SetInputPurpose(purpose InputPurpose) {
35944290 C.gtk_entry_set_input_purpose(v.native(), C.GtkInputPurpose(purpose))
35954291 }
35964292
3597 // GetInputPurpose() is a wrapper around gtk_entry_get_input_purpose().
4293 // GetInputPurpose is a wrapper around gtk_entry_get_input_purpose().
35984294 func (v *Entry) GetInputPurpose() InputPurpose {
35994295 c := C.gtk_entry_get_input_purpose(v.native())
36004296 return InputPurpose(c)
36014297 }
36024298
3603 // SetInputHints() is a wrapper around gtk_entry_set_input_hints().
4299 // SetInputHints is a wrapper around gtk_entry_set_input_hints().
36044300 func (v *Entry) SetInputHints(hints InputHints) {
36054301 C.gtk_entry_set_input_hints(v.native(), C.GtkInputHints(hints))
36064302 }
36074303
3608 // GetInputHints() is a wrapper around gtk_entry_get_input_hints().
4304 // GetInputHints is a wrapper around gtk_entry_get_input_hints().
36094305 func (v *Entry) GetInputHints() InputHints {
36104306 c := C.gtk_entry_get_input_hints(v.native())
36114307 return InputHints(c)
36364332 }
36374333
36384334 func wrapEntryBuffer(obj *glib.Object) *EntryBuffer {
4335 if obj == nil {
4336 return nil
4337 }
4338
36394339 return &EntryBuffer{obj}
36404340 }
36414341
37494449 }
37504450
37514451 func wrapEntryCompletion(obj *glib.Object) *EntryCompletion {
4452 if obj == nil {
4453 return nil
4454 }
4455
37524456 return &EntryCompletion{obj}
37534457 }
4458
4459 // TODO:
4460 // GtkEntryCompletionMatchFunc
37544461
37554462 // EntryCompletionNew is a wrapper around gtk_entry_completion_new
37564463 func EntryCompletionNew() (*EntryCompletion, error) {
37614468 obj := glib.Take(unsafe.Pointer(c))
37624469 return wrapEntryCompletion(obj), nil
37634470 }
4471
4472 // TODO:
4473 // gtk_entry_completion_new_with_area().
4474 // gtk_entry_completion_get_entry().
37644475
37654476 // SetModel is a wrapper around gtk_entry_completion_set_model
37664477 func (v *EntryCompletion) SetModel(model ITreeModel) {
37724483 }
37734484
37744485 // GetModel is a wrapper around gtk_entry_completion_get_model
3775 func (v *EntryCompletion) GetModel() (*TreeModel, error) {
4486 func (v *EntryCompletion) GetModel() (ITreeModel, error) {
37764487 c := C.gtk_entry_completion_get_model(v.native())
37774488 if c == nil {
37784489 return nil, nilPtrErr
37794490 }
3780 obj := glib.Take(unsafe.Pointer(c))
3781 return wrapTreeModel(obj), nil
3782 }
4491 return castTreeModel(c)
4492 }
4493
4494 // TODO:
4495 // gtk_entry_completion_set_match_func().
37834496
37844497 // SetMinimumKeyLength is a wrapper around gtk_entry_completion_set_minimum_key_length
37854498 func (v *EntryCompletion) SetMinimumKeyLength(minimumLength int) {
37924505 return int(c)
37934506 }
37944507
4508 // TODO:
4509 // gtk_entry_completion_compute_prefix().
4510 // gtk_entry_completion_complete().
4511 // gtk_entry_completion_get_completion_prefix().
4512 // gtk_entry_completion_insert_prefix().
4513 // gtk_entry_completion_insert_action_text().
4514 // gtk_entry_completion_insert_action_markup().
4515 // gtk_entry_completion_delete_action().
4516
37954517 // SetTextColumn is a wrapper around gtk_entry_completion_set_text_column
37964518 func (v *EntryCompletion) SetTextColumn(textColumn int) {
37974519 C.gtk_entry_completion_set_text_column(v.native(), C.gint(textColumn))
38144536 return gobool(c)
38154537 }
38164538
4539 // TODO
4540 // gtk_entry_completion_set_inline_selection().
4541 // gtk_entry_completion_get_inline_selection().
4542
38174543 // SetPopupCompletion is a wrapper around gtk_entry_completion_set_popup_completion
38184544 func (v *EntryCompletion) SetPopupCompletion(popupCompletion bool) {
38194545 C.gtk_entry_completion_set_popup_completion(v.native(), gbool(popupCompletion))
38364562 return gobool(c)
38374563 }
38384564
4565 // TODO:
4566 // gtk_entry_completion_set_popup_single_match().
4567 // gtk_entry_completion_get_popup_single_match().
4568
38394569 /*
38404570 * GtkEventBox
38414571 */
38614591 }
38624592
38634593 func wrapEventBox(obj *glib.Object) *EventBox {
4594 if obj == nil {
4595 return nil
4596 }
4597
38644598 return &EventBox{Bin{Container{Widget{glib.InitiallyUnowned{obj}}}}}
38654599 }
38664600
39214655 }
39224656
39234657 func wrapExpander(obj *glib.Object) *Expander {
4658 if obj == nil {
4659 return nil
4660 }
4661
39244662 return &Expander{Bin{Container{Widget{glib.InitiallyUnowned{obj}}}}}
39254663 }
39264664
39284666 func ExpanderNew(label string) (*Expander, error) {
39294667 var cstr *C.gchar
39304668 if label != "" {
3931 cstr := C.CString(label)
4669 cstr = (*C.gchar)(C.CString(label))
39324670 defer C.free(unsafe.Pointer(cstr))
39334671 }
3934 c := C.gtk_expander_new((*C.gchar)(cstr))
4672 c := C.gtk_expander_new(cstr)
39354673 if c == nil {
39364674 return nil, nilPtrErr
39374675 }
39384676 obj := glib.Take(unsafe.Pointer(c))
39394677 return wrapExpander(obj), nil
39404678 }
4679
4680 // TODO:
4681 // gtk_expander_new_with_mnemonic().
39414682
39424683 // SetExpanded is a wrapper around gtk_expander_set_expanded().
39434684 func (v *Expander) SetExpanded(expanded bool) {
39664707 return goString(c)
39674708 }
39684709
4710 // TODO:
4711 // gtk_expander_set_use_underline().
4712 // gtk_expander_get_use_underline().
4713 // gtk_expander_set_use_markup().
4714 // gtk_expander_get_use_markup().
4715
39694716 // SetLabelWidget is a wrapper around gtk_expander_set_label_widget().
39704717 func (v *Expander) SetLabelWidget(widget IWidget) {
39714718 C.gtk_expander_set_label_widget(v.native(), widget.toWidget())
39724719 }
39734720
4721 // TODO:
4722 // gtk_expander_get_label_widget().
4723 // gtk_expander_set_label_fill().
4724 // gtk_expander_get_label_fill().
4725 // gtk_expander_set_resize_toplevel().
4726 // gtk_expander_get_resize_toplevel().
4727
39744728 /*
39754729 * GtkFileChooser
39764730 */
39964750 }
39974751
39984752 func wrapFileChooser(obj *glib.Object) *FileChooser {
4753 if obj == nil {
4754 return nil
4755 }
4756
39994757 return &FileChooser{obj}
40004758 }
40014759
40154773 return s
40164774 }
40174775
4776 // SelectFilename is a wrapper around gtk_file_chooser_select_filename().
4777 func (v *FileChooser) SelectFilename(filename string) bool {
4778 cstr := C.CString(filename)
4779 defer C.free(unsafe.Pointer(cstr))
4780 c := C.gtk_file_chooser_select_filename(v.native(), cstr)
4781 return gobool(c)
4782 }
4783
4784 // UnselectFilename is a wrapper around gtk_file_chooser_unselect_filename().
4785 func (v *FileChooser) UnselectFilename(filename string) {
4786 cstr := C.CString(filename)
4787 defer C.free(unsafe.Pointer(cstr))
4788 C.gtk_file_chooser_unselect_filename(v.native(), cstr)
4789 }
4790
4791 // SelectAll is a wrapper around gtk_file_chooser_select_all().
4792 func (v *FileChooser) SelectAll() {
4793 C.gtk_file_chooser_select_all(v.native())
4794 }
4795
4796 // UnselectAll is a wrapper around gtk_file_chooser_unselect_all().
4797 func (v *FileChooser) UnselectAll() {
4798 C.gtk_file_chooser_unselect_all(v.native())
4799 }
4800
40184801 // GetFilenames is a wrapper around gtk_file_chooser_get_filenames().
4019 func (v *FileChooser) GetFilenames() (*glib.SList, error) {
4020 c := C.gtk_file_chooser_get_filenames(v.native())
4021 if c == nil {
4022 return nil, nilPtrErr
4023 }
4024 return glib.WrapSList(uintptr(unsafe.Pointer(c))), nil
4802 func (v *FileChooser) GetFilenames() ([]string, error) {
4803 clist := C.gtk_file_chooser_get_filenames(v.native())
4804 if clist == nil {
4805 return nil, nilPtrErr
4806 }
4807
4808 slist := glib.WrapSList(uintptr(unsafe.Pointer(clist)))
4809 defer slist.Free()
4810
4811 var filenames = make([]string, 0, slist.Length())
4812 for ; slist.DataRaw() != nil; slist = slist.Next() {
4813 w := (*C.char)(slist.DataRaw())
4814 defer C.free(unsafe.Pointer(w))
4815
4816 filenames = append(filenames, C.GoString(w))
4817 }
4818
4819 return filenames, nil
40254820 }
40264821
40274822 // GetURIs is a wrapper around gtk_file_chooser_get_uris().
4028 func (v FileChooser) GetURIs() (*glib.SList, error) {
4029 c := C.gtk_file_chooser_get_uris(v.native())
4030 if c == nil {
4031 return nil, nilPtrErr
4032 }
4033 return glib.WrapSList(uintptr(unsafe.Pointer(c))), nil
4823 func (v FileChooser) GetURIs() ([]string, error) {
4824 // TODO: do the same as in (v *FileChooser) GetFilenames()
4825 clist := C.gtk_file_chooser_get_uris(v.native())
4826 if clist == nil {
4827 return nil, nilPtrErr
4828 }
4829
4830 slist := glib.WrapSList(uintptr(unsafe.Pointer(clist)))
4831 defer slist.Free()
4832
4833 var uris = make([]string, 0, slist.Length())
4834 for ; slist.DataRaw() != nil; slist = slist.Next() {
4835 w := (*C.char)(slist.DataRaw())
4836 defer C.free(unsafe.Pointer(w))
4837
4838 uris = append(uris, C.GoString(w))
4839 }
4840
4841 return uris, nil
40344842 }
40354843
40364844 // SetDoOverwriteConfirmation is a wrapper around gtk_file_chooser_set_do_overwrite_confirmation().
41794987 }
41804988
41814989 func wrapFileChooserButton(obj *glib.Object) *FileChooserButton {
4990 if obj == nil {
4991 return nil
4992 }
4993
41824994 fc := wrapFileChooser(obj)
41834995 return &FileChooserButton{Box{Container{Widget{glib.InitiallyUnowned{obj}}}}, *fc}
41844996 }
41965008 return wrapFileChooserButton(obj), nil
41975009 }
41985010
5011 // FileChooserButtonNewWithDialog is a wrapper around gtk_file_chooser_button_new_with_dialog().
5012 func FileChooserButtonNewWithDialog(dialog IWidget) (*FileChooserButton, error) {
5013 c := C.gtk_file_chooser_button_new_with_dialog(dialog.toWidget())
5014 if c == nil {
5015 return nil, nilPtrErr
5016 }
5017 return wrapFileChooserButton(glib.Take(unsafe.Pointer(c))), nil
5018 }
5019
5020 // GetTitle is a wrapper around gtk_file_chooser_button_get_title().
5021 func (v *FileChooserButton) GetTitle() string {
5022 // docs say: The returned value should not be modified or freed.
5023 return goString(C.gtk_file_chooser_button_get_title(v.native()))
5024 }
5025
5026 // SetTitle is a wrapper around gtk_file_chooser_button_set_title().
5027 func (v *FileChooserButton) SetTitle(title string) {
5028 cstr := C.CString(title)
5029 defer C.free(unsafe.Pointer(cstr))
5030 C.gtk_file_chooser_button_set_title(v.native(), (*C.gchar)(cstr))
5031 }
5032
5033 // GetWidthChars is a wrapper around gtk_file_chooser_button_get_width_chars().
5034 func (v *FileChooserButton) GetWidthChars() int {
5035 return int(C.gtk_file_chooser_button_get_width_chars(v.native()))
5036 }
5037
5038 // SetWidthChars is a wrapper around gtk_file_chooser_button_set_width_chars().
5039 func (v *FileChooserButton) SetWidthChars(width int) {
5040 C.gtk_file_chooser_button_set_width_chars(v.native(), C.gint(width))
5041 }
5042
41995043 /*
42005044 * GtkFileChooserDialog
42015045 */
42245068 }
42255069
42265070 func wrapFileChooserDialog(obj *glib.Object) *FileChooserDialog {
5071 if obj == nil {
5072 return nil
5073 }
5074
42275075 fc := wrapFileChooser(obj)
42285076 return &FileChooserDialog{Dialog{Window{Bin{Container{Widget{glib.InitiallyUnowned{obj}}}}}}, *fc}
42295077 }
42355083 action FileChooserAction,
42365084 first_button_text string,
42375085 first_button_id ResponseType) (*FileChooserDialog, error) {
5086
5087 var w *C.GtkWindow = nil
5088 if parent != nil {
5089 w = parent.toWindow()
5090 }
5091
42385092 c_title := C.CString(title)
42395093 defer C.free(unsafe.Pointer(c_title))
42405094 c_first_button_text := C.CString(first_button_text)
42415095 defer C.free(unsafe.Pointer(c_first_button_text))
42425096 c := C.gtk_file_chooser_dialog_new_1(
4243 (*C.gchar)(c_title), parent.toWindow(), C.GtkFileChooserAction(action),
5097 (*C.gchar)(c_title), w, C.GtkFileChooserAction(action),
42445098 (*C.gchar)(c_first_button_text), C.int(first_button_id))
42455099 if c == nil {
42465100 return nil, nilPtrErr
42585112 first_button_id ResponseType,
42595113 second_button_text string,
42605114 second_button_id ResponseType) (*FileChooserDialog, error) {
5115
5116 var w *C.GtkWindow = nil
5117 if parent != nil {
5118 w = parent.toWindow()
5119 }
5120
42615121 c_title := C.CString(title)
42625122 defer C.free(unsafe.Pointer(c_title))
42635123 c_first_button_text := C.CString(first_button_text)
42655125 c_second_button_text := C.CString(second_button_text)
42665126 defer C.free(unsafe.Pointer(c_second_button_text))
42675127 c := C.gtk_file_chooser_dialog_new_2(
4268 (*C.gchar)(c_title), parent.toWindow(), C.GtkFileChooserAction(action),
5128 (*C.gchar)(c_title), w, C.GtkFileChooserAction(action),
42695129 (*C.gchar)(c_first_button_text), C.int(first_button_id),
42705130 (*C.gchar)(c_second_button_text), C.int(second_button_id))
42715131 if c == nil {
43035163 }
43045164
43055165 func wrapFileChooserWidget(obj *glib.Object) *FileChooserWidget {
5166 if obj == nil {
5167 return nil
5168 }
5169
43065170 fc := wrapFileChooser(obj)
43075171 return &FileChooserWidget{Box{Container{Widget{glib.InitiallyUnowned{obj}}}}, *fc}
43085172 }
43425206 }
43435207
43445208 func wrapFileFilter(obj *glib.Object) *FileFilter {
5209 if obj == nil {
5210 return nil
5211 }
5212
43455213 return &FileFilter{obj}
43465214 }
43475215
43625230 C.gtk_file_filter_set_name(v.native(), (*C.gchar)(cstr))
43635231 }
43645232
5233 // GetName is a wrapper around gtk_file_filter_get_name().
5234 func (v *FileFilter) GetName() (name string) {
5235 cstr := C.gtk_file_filter_get_name(v.native())
5236 if cstr != nil {
5237 name = goString(cstr)
5238 }
5239 return
5240 }
5241
5242 // AddMimeType is a wrapper around gtk_file_filter_add_mime_type().
5243 func (v *FileFilter) AddMimeType(mimeType string) {
5244 cstr := C.CString(mimeType)
5245 defer C.free(unsafe.Pointer(cstr))
5246 C.gtk_file_filter_add_mime_type(v.native(), (*C.gchar)(cstr))
5247 }
5248
43655249 // AddPattern is a wrapper around gtk_file_filter_add_pattern().
43665250 func (v *FileFilter) AddPattern(pattern string) {
43675251 cstr := C.CString(pattern)
43995283 }
44005284
44015285 func wrapFrame(obj *glib.Object) *Frame {
5286 if obj == nil {
5287 return nil
5288 }
5289
44025290 return &Frame{Bin{Container{Widget{glib.InitiallyUnowned{obj}}}}}
44035291 }
44045292
44545342 }
44555343
44565344 // GetLabelWidget is a wrapper around gtk_frame_get_label_widget().
4457 func (v *Frame) GetLabelWidget() (*Widget, error) {
5345 func (v *Frame) GetLabelWidget() (IWidget, error) {
44585346 c := C.gtk_frame_get_label_widget(v.native())
44595347 if c == nil {
4460 return nil, nilPtrErr
4461 }
4462 obj := glib.Take(unsafe.Pointer(c))
4463 return wrapWidget(obj), nil
5348 return nil, nil
5349 }
5350 return castWidget(c)
44645351 }
44655352
44665353 // GetShadowType is a wrapper around gtk_frame_get_shadow_type().
44945381 }
44955382
44965383 func wrapAspectFrame(obj *glib.Object) *AspectFrame {
5384 if obj == nil {
5385 return nil
5386 }
5387
44975388 return &AspectFrame{Frame{Bin{Container{Widget{glib.InitiallyUnowned{obj}}}}}}
44985389 }
44995390
5391 // AspectFrameNew is a wrapper around gtk_aspect_frame_new().
45005392 func AspectFrameNew(label string, xalign, yalign, ratio float32, obeyChild bool) (*AspectFrame, error) {
45015393 var cstr *C.char
45025394 if label != "" {
45115403 return wrapAspectFrame(obj), nil
45125404 }
45135405
5406 // TODO:
5407 // gtk_aspect_frame_set().
5408
45145409 /*
45155410 * GtkGrid
45165411 */
45465441 }
45475442
45485443 func wrapGrid(obj *glib.Object) *Grid {
5444 if obj == nil {
5445 return nil
5446 }
5447
45495448 o := wrapOrientable(obj)
45505449 return &Grid{Container{Widget{glib.InitiallyUnowned{obj}}}, *o}
45515450 }
45745473 }
45755474
45765475 // GetChildAt() is a wrapper around gtk_grid_get_child_at().
4577 func (v *Grid) GetChildAt(left, top int) (*Widget, error) {
5476 func (v *Grid) GetChildAt(left, top int) (IWidget, error) {
45785477 c := C.gtk_grid_get_child_at(v.native(), C.gint(left), C.gint(top))
45795478 if c == nil {
4580 return nil, nilPtrErr
4581 }
4582 obj := glib.Take(unsafe.Pointer(c))
4583 return wrapWidget(obj), nil
5479 return nil, nil
5480 }
5481 return castWidget(c)
45845482 }
45855483
45865484 // InsertRow() is a wrapper around gtk_grid_insert_row().
46845582 return &gdk.Pixbuf{glib.Take(unsafe.Pointer(c))}, nil
46855583 }
46865584
5585 // HasIcon is a wrapper around gtk_icon_theme_has_icon().
5586 func (v *IconTheme) HasIcon(iconName string) bool {
5587 cstr := C.CString(iconName)
5588 defer C.free(unsafe.Pointer(cstr))
5589
5590 c := C.gtk_icon_theme_has_icon(v.Theme, (*C.gchar)(cstr))
5591 return gobool(c)
5592 }
5593
46875594 /*
46885595 * GtkImage
46895596 */
47095616 }
47105617
47115618 func wrapImage(obj *glib.Object) *Image {
5619 if obj == nil {
5620 return nil
5621 }
5622
47125623 return &Image{Widget{glib.InitiallyUnowned{obj}}}
47135624 }
47145625
47555666 obj := glib.Take(unsafe.Pointer(c))
47565667 return wrapImage(obj), nil
47575668 }
4758
4759 // TODO(jrick) GtkIconSet
4760 /*
4761 func ImageNewFromIconSet() {
4762 }
4763 */
4764
4765 // TODO(jrick) GdkPixbufAnimation
4766 /*
4767 func ImageNewFromAnimation() {
4768 }
4769 */
47705669
47715670 // ImageNewFromIconName() is a wrapper around gtk_image_new_from_icon_name().
47725671 func ImageNewFromIconName(iconName string, size IconSize) (*Image, error) {
47815680 return wrapImage(obj), nil
47825681 }
47835682
4784 // TODO(jrick) GIcon
4785 /*
4786 func ImageNewFromGIcon() {
4787 }
4788 */
5683 // ImageNewFromGIcon is a wrapper around gtk_image_new_from_gicon()
5684 func ImageNewFromGIcon(icon *glib.Icon, size IconSize) (*Image, error) {
5685 c := C.gtk_image_new_from_gicon(
5686 (*C.GIcon)(icon.NativePrivate()),
5687 C.GtkIconSize(size))
5688
5689 if c == nil {
5690 return nil, nilPtrErr
5691 }
5692 obj := glib.Take(unsafe.Pointer(c))
5693 return wrapImage(obj), nil
5694 }
47895695
47905696 // Clear() is a wrapper around gtk_image_clear().
47915697 func (v *Image) Clear() {
48115717 pbptr := (*C.GdkPixbuf)(unsafe.Pointer(pixbuf.Native()))
48125718 C.gtk_image_set_from_pixbuf(v.native(), pbptr)
48135719 }
4814
4815 // TODO(jrick) GtkIconSet
4816 /*
4817 func (v *Image) SetFromIconSet() {
4818 }
4819 */
4820
4821 // TODO(jrick) GdkPixbufAnimation
4822 /*
4823 func (v *Image) SetFromAnimation() {
4824 }
4825 */
48265720
48275721 // SetFromIconName() is a wrapper around gtk_image_set_from_icon_name().
48285722 func (v *Image) SetFromIconName(iconName string, size IconSize) {
48325726 C.GtkIconSize(size))
48335727 }
48345728
4835 // TODO(jrick) GIcon
4836 /*
4837 func (v *Image) SetFromGIcon() {
4838 }
4839 */
5729 // SetFromGIcon is a wrapper around gtk_image_set_from_gicon()
5730 func (v *Image) SetFromGIcon(icon *glib.Icon, size IconSize) {
5731 C.gtk_image_set_from_gicon(
5732 v.native(),
5733 (*C.GIcon)(icon.NativePrivate()),
5734 C.GtkIconSize(size))
5735 }
48405736
48415737 // SetPixelSize() is a wrapper around gtk_image_set_pixel_size().
48425738 func (v *Image) SetPixelSize(pixelSize int) {
48595755 pb := &gdk.Pixbuf{glib.Take(unsafe.Pointer(c))}
48605756 return pb
48615757 }
4862
4863 // TODO(jrick) GtkIconSet
4864 /*
4865 func (v *Image) GetIconSet() {
4866 }
4867 */
48685758
48695759 // GetAnimation() is a wrapper around gtk_image_get_animation()
48705760 func (v *Image) GetAnimation() *gdk.PixbufAnimation {
48995789 return goString(iconName), IconSize(size)
49005790 }
49015791
4902 // TODO(jrick) GIcon
4903 /*
4904 func (v *Image) GetGIcon() {
4905 }
4906 */
5792 // GetGIcon is a wrapper around gtk_image_get_gicon()
5793 func (v *Image) GetGIcon() (*glib.Icon, IconSize, error) {
5794 var gicon *C.GIcon
5795 var size *C.GtkIconSize
5796 C.gtk_image_get_gicon(
5797 v.native(),
5798 &gicon,
5799 size)
5800
5801 if gicon == nil {
5802 return nil, ICON_SIZE_INVALID, nilPtrErr
5803 }
5804
5805 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(gicon))}
5806 i := &glib.Icon{obj}
5807
5808 runtime.SetFinalizer(i, func(_ interface{}) { obj.Unref() })
5809 return i, IconSize(*size), nil
5810 }
49075811
49085812 // GetPixelSize() is a wrapper around gtk_image_get_pixel_size().
49095813 func (v *Image) GetPixelSize() int {
49375841 }
49385842
49395843 func wrapLayout(obj *glib.Object) *Layout {
5844 if obj == nil {
5845 return nil
5846 }
5847
49405848 return &Layout{Container{Widget{glib.InitiallyUnowned{obj}}}}
49415849 }
49425850
49725880 return uint(w), uint(h)
49735881 }
49745882
5883 // TODO:
5884 // gtk_layout_get_bin_window().
5885
49755886 /*
49765887 * GtkLinkButton
49775888 */
49975908 }
49985909
49995910 func wrapLinkButton(obj *glib.Object) *LinkButton {
5911 if obj == nil {
5912 return nil
5913 }
5914
50005915 actionable := wrapActionable(obj)
50015916 return &LinkButton{Button{Bin{Container{Widget{
50025917 glib.InitiallyUnowned{obj}}}}, actionable}}
50385953 C.gtk_link_button_set_uri(v.native(), (*C.gchar)(cstr))
50395954 }
50405955
5956 // GetVisited is a wrapper around gtk_link_button_get_visited().
5957 func (v *LinkButton) GetVisited() bool {
5958 c := C.gtk_link_button_get_visited(v.native())
5959 return gobool(c)
5960 }
5961
5962 // SetVisited is a wrapper around gtk_link_button_set_visited().
5963 func (v *LinkButton) SetVisited(visited bool) {
5964 C.gtk_link_button_set_visited(v.native(), gbool(visited))
5965 }
5966
5967 /*
5968 * GtkLockButton
5969 */
5970
5971 // LockButton is a representation of GTK's GtkLockButton.
5972 type LockButton struct {
5973 Button
5974 }
5975
5976 // native returns a pointer to the underlying GtkLockButton.
5977 func (v *LockButton) native() *C.GtkLockButton {
5978 if v == nil || v.GObject == nil {
5979 return nil
5980 }
5981 p := unsafe.Pointer(v.GObject)
5982 return C.toGtkLockButton(p)
5983 }
5984
5985 func marshalLockButton(p uintptr) (interface{}, error) {
5986 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
5987 obj := glib.Take(unsafe.Pointer(c))
5988 return wrapLockButton(obj), nil
5989 }
5990
5991 func wrapLockButton(obj *glib.Object) *LockButton {
5992 if obj == nil {
5993 return nil
5994 }
5995
5996 actionable := wrapActionable(obj)
5997 return &LockButton{Button{Bin{Container{Widget{
5998 glib.InitiallyUnowned{obj}}}}, actionable}}
5999 }
6000
6001 // LockButtonNew is a wrapper around gtk_lock_button_new().
6002 func LockButtonNew(permission *glib.Permission) (*LockButton, error) {
6003 c := C.gtk_lock_button_new(nativeGPermission(permission))
6004 if c == nil {
6005 return nil, nilPtrErr
6006 }
6007 return wrapLockButton(glib.Take(unsafe.Pointer(c))), nil
6008 }
6009
6010 // GetPermission is a wrapper around gtk_lock_button_get_permission().
6011 func (v *LockButton) GetPermission() *glib.Permission {
6012 c := C.gtk_lock_button_get_permission(v.native())
6013 return glib.WrapPermission(unsafe.Pointer(c))
6014 }
6015
6016 // SetPermission is a wrapper around gtk_lock_button_set_permission().
6017 func (v *LockButton) SetPermission(permission *glib.Permission) {
6018 C.gtk_lock_button_set_permission(v.native(), nativeGPermission(permission))
6019 }
6020
50416021 /*
50426022 * GtkListStore
50436023 */
50486028
50496029 // Interfaces
50506030 TreeModel
6031 TreeSortable
50516032 }
50526033
50536034 // native returns a pointer to the underlying GtkListStore.
50666047 }
50676048
50686049 func wrapListStore(obj *glib.Object) *ListStore {
6050 if obj == nil {
6051 return nil
6052 }
6053
50696054 tm := wrapTreeModel(obj)
5070 return &ListStore{obj, *tm}
6055 ts := wrapTreeSortable(obj)
6056 return &ListStore{obj, *tm, *ts}
50716057 }
50726058
50736059 func (v *ListStore) toTreeModel() *C.GtkTreeModel {
51066092 return gobool(c)
51076093 }
51086094
5109 // TODO(jrick)
5110 /*
6095 // SetColumnTypes is a wrapper around gtk_list_store_set_column_types().
6096 // The size of glib.Type must match the number of columns
51116097 func (v *ListStore) SetColumnTypes(types ...glib.Type) {
5112 }
5113 */
6098 gtypes := C.alloc_types(C.int(len(types)))
6099 for n, val := range types {
6100 C.set_type(gtypes, C.int(n), C.GType(val))
6101 }
6102 defer C.g_free(C.gpointer(gtypes))
6103 C.gtk_list_store_set_column_types(v.native(), C.gint(len(types)), gtypes)
6104 }
51146105
51156106 // Set() is a wrapper around gtk_list_store_set_value() but provides
51166107 // a function similar to gtk_list_store_set() in that multiple columns
51576148 // v.TreeModel = *wrapTreeModel(obj)
51586149 //}
51596150
5160 // SetSortColumnId() is a wrapper around gtk_tree_sortable_set_sort_column_id().
5161 func (v *ListStore) SetSortColumnId(column int, order SortType) {
5162 sort := C.toGtkTreeSortable(unsafe.Pointer(v.Native()))
5163 C.gtk_tree_sortable_set_sort_column_id(sort, C.gint(column), C.GtkSortType(order))
5164 }
5165
5166 // SetSortFunc() is a wrapper around gtk_tree_sortable_set_sort_func().
5167 func (v *ListStore) SetSortFunc(sortColumn int, f TreeIterCompareFunc, data ...interface{}) error {
5168 return v.toTreeSortable().setSortFunc(sortColumn, f, data)
5169 }
5170
51716151 func (v *ListStore) SetCols(iter *TreeIter, cols Cols) error {
51726152 for key, value := range cols {
51736153 err := v.SetValue(iter, key, value)
51986178 return err
51996179 }
52006180
5201 var cvp *C.GValue = (*C.GValue)(gv.Native())
6181 var cvp *C.GValue = (*C.GValue)(unsafe.Pointer(gv.Native()))
52026182 cValues = append(cValues, *cvp)
52036183 }
5204 var cColumnsPointer *C.gint = &cColumns[0]
5205 var cValuesPointer *C.GValue = &cValues[0]
6184 var cColumnsPointer *C.gint
6185 if len(cColumns) > 0 {
6186 cColumnsPointer = &cColumns[0]
6187 }
6188 var cValuesPointer *C.GValue
6189 if len(cValues) > 0 {
6190 cValuesPointer = &cValues[0]
6191 }
52066192
52076193 C.gtk_list_store_insert_with_valuesv(v.native(), iter.native(), C.gint(position), cColumnsPointer, cValuesPointer, C.gint(length))
52086194
52096195 return nil
6196 }
6197
6198 // Insert() is a wrapper around gtk_list_store_insert().
6199 func (v *ListStore) Insert(position int) *TreeIter {
6200 var ti C.GtkTreeIter
6201 C.gtk_list_store_insert(v.native(), &ti, C.gint(position))
6202 iter := &TreeIter{ti}
6203 return iter
52106204 }
52116205
52126206 // InsertBefore() is a wrapper around gtk_list_store_insert_before().
53006294 }
53016295
53026296 func wrapMenuBar(obj *glib.Object) *MenuBar {
6297 if obj == nil {
6298 return nil
6299 }
6300
53036301 return &MenuBar{MenuShell{Container{Widget{glib.InitiallyUnowned{obj}}}}}
53046302 }
53056303
53376335 }
53386336
53396337 func wrapMenuButton(obj *glib.Object) *MenuButton {
6338 if obj == nil {
6339 return nil
6340 }
6341
53406342 actionable := wrapActionable(obj)
53416343 return &MenuButton{ToggleButton{Button{Bin{Container{Widget{
53426344 glib.InitiallyUnowned{obj}}}}, actionable}}}
53966398 }
53976399
53986400 // GetAlignWidget is a wrapper around gtk_menu_button_get_align_widget().
5399 func (v *MenuButton) GetAlignWidget() *Widget {
6401 func (v *MenuButton) GetAlignWidget() (IWidget, error) {
54006402 c := C.gtk_menu_button_get_align_widget(v.native())
54016403 if c == nil {
5402 return nil
5403 }
5404 return wrapWidget(glib.Take(unsafe.Pointer(c)))
6404 return nil, nil
6405 }
6406 return castWidget(c)
54056407 }
54066408
54076409 /*
54456447 }
54466448
54476449 func wrapMenuItem(obj *glib.Object) *MenuItem {
6450 if obj == nil {
6451 return nil
6452 }
6453
54486454 return &MenuItem{Bin{Container{Widget{glib.InitiallyUnowned{obj}}}}}
54496455 }
54506456
54686474 return wrapMenuItem(glib.Take(unsafe.Pointer(c))), nil
54696475 }
54706476
5471 // MenuItemNewWithMnemonic() is a wrapper around
5472 // gtk_menu_item_new_with_mnemonic().
6477 // MenuItemNewWithMnemonic() is a wrapper around gtk_menu_item_new_with_mnemonic().
54736478 func MenuItemNewWithMnemonic(label string) (*MenuItem, error) {
54746479 cstr := C.CString(label)
54756480 defer C.free(unsafe.Pointer(cstr))
54856490 C.gtk_menu_item_set_submenu(v.native(), submenu.toWidget())
54866491 }
54876492
5488 // Sets text on the menu_item label
6493 // GetSubmenu is a wrapper around gtk_menu_item_get_submenu().
6494 func (v *MenuItem) GetSubmenu() (IMenu, error) {
6495 c := C.gtk_menu_item_get_submenu(v.native())
6496 if c == nil {
6497 return nil, nilPtrErr
6498 }
6499 obj := glib.Take(unsafe.Pointer(c))
6500 return wrapMenu(obj), nil
6501 }
6502
6503 // SetLabel is a wrapper around gtk_menu_item_set_label().
54896504 func (v *MenuItem) SetLabel(label string) {
54906505 cstr := C.CString(label)
54916506 defer C.free(unsafe.Pointer(cstr))
54926507 C.gtk_menu_item_set_label(v.native(), (*C.gchar)(cstr))
54936508 }
54946509
5495 // Gets text on the menu_item label
6510 // GetLabel is a wrapper around gtk_menu_item_get_label().
54966511 func (v *MenuItem) GetLabel() string {
54976512 l := C.gtk_menu_item_get_label(v.native())
54986513 return goString(l)
55096524 return gobool(c)
55106525 }
55116526
6527 // Select is a wrapper around gtk_menu_item_select()
6528 func (v *MenuItem) Select() {
6529 C.gtk_menu_item_select(v.native())
6530 }
6531
6532 // Deselect is a wrapper around gtk_menu_item_deselect()
6533 func (v *MenuItem) Deselect() {
6534 C.gtk_menu_item_deselect(v.native())
6535 }
6536
6537 // Activate is a wrapper around gtk_menu_item_activate()
6538 func (v *MenuItem) Activate() {
6539 C.gtk_menu_item_activate(v.native())
6540 }
6541
6542 // ToggleSizeRequest is a wrapper around gtk_menu_item_toggle_size_request()
6543 func (v *MenuItem) ToggleSizeRequest(requisition int) int {
6544 cint := new(C.gint)
6545 *cint = C.gint(requisition)
6546 C.gtk_menu_item_toggle_size_request(v.native(), cint)
6547 return int(*cint)
6548 }
6549
6550 // ToggleSizeAllocate is a wrapper around gtk_menu_item_toggle_size_allocate()
6551 func (v *MenuItem) ToggleSizeAllocate(allocation int) {
6552 C.gtk_menu_item_toggle_size_allocate(v.native(), C.gint(allocation))
6553 }
6554
6555 // GetReserveIndicator is a wrapper around gtk_menu_item_get_reserve_indicator().
6556 func (v *MenuItem) GetReserveIndicator() bool {
6557 return gobool(C.gtk_menu_item_get_reserve_indicator(v.native()))
6558 }
6559
6560 // SetReserveIndicator is a wrapper around gtk_menu_item_set_reserve_indicator().
6561 func (v *MenuItem) SetReserveIndicator(reserve bool) {
6562 C.gtk_menu_item_set_reserve_indicator(v.native(), gbool(reserve))
6563 }
6564
55126565 /*
55136566 * GtkMessageDialog
55146567 */
55346587 }
55356588
55366589 func wrapMessageDialog(obj *glib.Object) *MessageDialog {
6590 if obj == nil {
6591 return nil
6592 }
6593
55376594 return &MessageDialog{Dialog{Window{Bin{Container{Widget{glib.InitiallyUnowned{obj}}}}}}}
55386595 }
55396596
55406597 // MessageDialogNew() is a wrapper around gtk_message_dialog_new().
55416598 // The text is created and formatted by the format specifier and any
55426599 // additional arguments.
5543 func MessageDialogNew(parent IWindow, flags DialogFlags, mType MessageType, buttons ButtonsType, format string, a ...interface{}) *MessageDialog {
5544 s := fmt.Sprintf(format, a...)
6600 func MessageDialogNew(parent IWindow, flags DialogFlags, mType MessageType, buttons ButtonsType, format string, args ...interface{}) *MessageDialog {
6601 s := fmt.Sprintf(format, args...)
55456602 cstr := C.CString(s)
55466603 defer C.free(unsafe.Pointer(cstr))
55476604 var w *C.GtkWindow = nil
55566613
55576614 // MessageDialogNewWithMarkup is a wrapper around
55586615 // gtk_message_dialog_new_with_markup().
5559 func MessageDialogNewWithMarkup(parent IWindow, flags DialogFlags, mType MessageType, buttons ButtonsType, format string, a ...interface{}) *MessageDialog {
5560 s := fmt.Sprintf(format, a...)
6616 func MessageDialogNewWithMarkup(parent IWindow, flags DialogFlags, mType MessageType, buttons ButtonsType, format string, args ...interface{}) *MessageDialog {
6617 s := fmt.Sprintf(format, args...)
55616618 cstr := C.CString(s)
55626619 defer C.free(unsafe.Pointer(cstr))
55636620 var w *C.GtkWindow = nil
55796636
55806637 // FormatSecondaryText is a wrapper around
55816638 // gtk_message_dialog_format_secondary_text().
5582 func (v *MessageDialog) FormatSecondaryText(format string, a ...interface{}) {
5583 s := fmt.Sprintf(format, a...)
6639 func (v *MessageDialog) FormatSecondaryText(format string, args ...interface{}) {
6640 s := fmt.Sprintf(format, args...)
55846641 cstr := C.CString(s)
55856642 defer C.free(unsafe.Pointer(cstr))
55866643 C._gtk_message_dialog_format_secondary_text(v.native(),
55896646
55906647 // FormatSecondaryMarkup is a wrapper around
55916648 // gtk_message_dialog_format_secondary_text().
5592 func (v *MessageDialog) FormatSecondaryMarkup(format string, a ...interface{}) {
5593 s := fmt.Sprintf(format, a...)
6649 func (v *MessageDialog) FormatSecondaryMarkup(format string, args ...interface{}) {
6650 s := fmt.Sprintf(format, args...)
55946651 cstr := C.CString(s)
55956652 defer C.free(unsafe.Pointer(cstr))
55966653 C._gtk_message_dialog_format_secondary_markup(v.native(),
56336690 }
56346691
56356692 func wrapNotebook(obj *glib.Object) *Notebook {
6693 if obj == nil {
6694 return nil
6695 }
6696
56366697 return &Notebook{Container{Widget{glib.InitiallyUnowned{obj}}}}
56376698 }
56386699
57526813 }
57536814
57546815 // GetMenuLabel() is a wrapper around gtk_notebook_get_menu_label().
5755 func (v *Notebook) GetMenuLabel(child IWidget) (*Widget, error) {
6816 func (v *Notebook) GetMenuLabel(child IWidget) (IWidget, error) {
57566817 c := C.gtk_notebook_get_menu_label(v.native(), child.toWidget())
57576818 if c == nil {
5758 return nil, nilPtrErr
5759 }
5760 return wrapWidget(glib.Take(unsafe.Pointer(c))), nil
6819 return nil, nil
6820 }
6821 return castWidget(c)
57616822 }
57626823
57636824 // GetNthPage() is a wrapper around gtk_notebook_get_nth_page().
5764 func (v *Notebook) GetNthPage(pageNum int) (*Widget, error) {
6825 func (v *Notebook) GetNthPage(pageNum int) (IWidget, error) {
57656826 c := C.gtk_notebook_get_nth_page(v.native(), C.gint(pageNum))
57666827 if c == nil {
5767 return nil, nilPtrErr
5768 }
5769 return wrapWidget(glib.Take(unsafe.Pointer(c))), nil
6828 return nil, fmt.Errorf("page %d is out of bounds", pageNum)
6829 }
6830 return castWidget(c)
57706831 }
57716832
57726833 // GetNPages() is a wrapper around gtk_notebook_get_n_pages().
57766837 }
57776838
57786839 // GetTabLabel() is a wrapper around gtk_notebook_get_tab_label().
5779 func (v *Notebook) GetTabLabel(child IWidget) (*Widget, error) {
6840 func (v *Notebook) GetTabLabel(child IWidget) (IWidget, error) {
57806841 c := C.gtk_notebook_get_tab_label(v.native(), child.toWidget())
57816842 if c == nil {
5782 return nil, nilPtrErr
5783 }
5784 return wrapWidget(glib.Take(unsafe.Pointer(c))), nil
6843 return nil, nil
6844 }
6845 return castWidget(c)
57856846 }
57866847
57876848 // SetMenuLabel() is a wrapper around gtk_notebook_set_menu_label().
59066967 }
59076968
59086969 // GetActionWidget() is a wrapper around gtk_notebook_get_action_widget().
5909 func (v *Notebook) GetActionWidget(packType PackType) (*Widget, error) {
5910 c := C.gtk_notebook_get_action_widget(v.native(),
5911 C.GtkPackType(packType))
5912 if c == nil {
5913 return nil, nilPtrErr
5914 }
5915 return wrapWidget(glib.Take(unsafe.Pointer(c))), nil
6970 func (v *Notebook) GetActionWidget(packType PackType) (IWidget, error) {
6971 c := C.gtk_notebook_get_action_widget(v.native(), C.GtkPackType(packType))
6972 if c == nil {
6973 return nil, nil
6974 }
6975 return castWidget(c)
59166976 }
59176977
59186978 /*
59407000 }
59417001
59427002 func wrapOffscreenWindow(obj *glib.Object) *OffscreenWindow {
7003 if obj == nil {
7004 return nil
7005 }
7006
59437007 return &OffscreenWindow{Window{Bin{Container{Widget{
59447008 glib.InitiallyUnowned{obj}}}}}}
59457009 }
60117075 }
60127076
60137077 func wrapOrientable(obj *glib.Object) *Orientable {
7078 if obj == nil {
7079 return nil
7080 }
7081
60147082 return &Orientable{obj}
60157083 }
60167084
6017 // GetOrientation() is a wrapper around gtk_orientable_get_orientation().
7085 // GetOrientation is a wrapper around gtk_orientable_get_orientation().
60187086 func (v *Orientable) GetOrientation() Orientation {
60197087 c := C.gtk_orientable_get_orientation(v.native())
60207088 return Orientation(c)
60217089 }
60227090
6023 // SetOrientation() is a wrapper around gtk_orientable_set_orientation().
7091 // SetOrientation is a wrapper around gtk_orientable_set_orientation().
60247092 func (v *Orientable) SetOrientation(orientation Orientation) {
60257093 C.gtk_orientable_set_orientation(v.native(),
60267094 C.GtkOrientation(orientation))
60517119 }
60527120
60537121 func wrapOverlay(obj *glib.Object) *Overlay {
7122 if obj == nil {
7123 return nil
7124 }
7125
60547126 return &Overlay{Bin{Container{Widget{glib.InitiallyUnowned{obj}}}}}
60557127 }
60567128
60937165 }
60947166
60957167 func wrapPaned(obj *glib.Object) *Paned {
7168 if obj == nil {
7169 return nil
7170 }
7171
60967172 return &Paned{Bin{Container{Widget{glib.InitiallyUnowned{obj}}}}}
60977173 }
60987174
61317207 }
61327208
61337209 // GetChild1() is a wrapper around gtk_paned_get_child1().
6134 func (v *Paned) GetChild1() (*Widget, error) {
7210 func (v *Paned) GetChild1() (IWidget, error) {
61357211 c := C.gtk_paned_get_child1(v.native())
61367212 if c == nil {
6137 return nil, nilPtrErr
6138 }
6139 return wrapWidget(glib.Take(unsafe.Pointer(c))), nil
7213 return nil, nil
7214 }
7215 return castWidget(c)
61407216 }
61417217
61427218 // GetChild2() is a wrapper around gtk_paned_get_child2().
6143 func (v *Paned) GetChild2() (*Widget, error) {
7219 func (v *Paned) GetChild2() (IWidget, error) {
61447220 c := C.gtk_paned_get_child2(v.native())
61457221 if c == nil {
6146 return nil, nilPtrErr
6147 }
6148 return wrapWidget(glib.Take(unsafe.Pointer(c))), nil
7222 return nil, nil
7223 }
7224 return castWidget(c)
61497225 }
61507226
61517227 // GetHandleWindow() is a wrapper around gtk_paned_get_handle_window().
61617237 func (v *Paned) GetPosition() int {
61627238 return int(C.gtk_paned_get_position(v.native()))
61637239 }
7240
7241 /*
7242 * GtkInvisible
7243 */
7244
7245 // TODO:
7246 // gtk_invisible_new().
7247 // gtk_invisible_new_for_screen().
7248 // gtk_invisible_set_screen().
7249 // gtk_invisible_get_screen().
61647250
61657251 /*
61667252 * GtkProgressBar
61897275 }
61907276
61917277 func wrapProgressBar(obj *glib.Object) *ProgressBar {
7278 if obj == nil {
7279 return nil
7280 }
7281
61927282 o := wrapOrientable(obj)
61937283 return &ProgressBar{Widget{glib.InitiallyUnowned{obj}}, *o}
61947284 }
61957285
6196 // ProgressBarNew() is a wrapper around gtk_progress_bar_new().
7286 // ProgressBarNew is a wrapper around gtk_progress_bar_new().
61977287 func ProgressBarNew() (*ProgressBar, error) {
61987288 c := C.gtk_progress_bar_new()
61997289 if c == nil {
62027292 return wrapProgressBar(glib.Take(unsafe.Pointer(c))), nil
62037293 }
62047294
6205 // SetFraction() is a wrapper around gtk_progress_bar_set_fraction().
7295 // SetFraction is a wrapper around gtk_progress_bar_set_fraction().
62067296 func (v *ProgressBar) SetFraction(fraction float64) {
62077297 C.gtk_progress_bar_set_fraction(v.native(), C.gdouble(fraction))
62087298 }
62097299
6210 // GetFraction() is a wrapper around gtk_progress_bar_get_fraction().
7300 // GetFraction is a wrapper around gtk_progress_bar_get_fraction().
62117301 func (v *ProgressBar) GetFraction() float64 {
62127302 c := C.gtk_progress_bar_get_fraction(v.native())
62137303 return float64(c)
62247314 return gobool(c)
62257315 }
62267316
6227 // SetText() is a wrapper around gtk_progress_bar_set_text().
7317 // SetText is a wrapper around gtk_progress_bar_set_text().
62287318 func (v *ProgressBar) SetText(text string) {
62297319 cstr := C.CString(text)
62307320 defer C.free(unsafe.Pointer(cstr))
62317321 C.gtk_progress_bar_set_text(v.native(), (*C.gchar)(cstr))
62327322 }
62337323
7324 // TODO:
7325 // gtk_progress_bar_get_text().
7326 // gtk_progress_bar_set_ellipsize().
7327 // gtk_progress_bar_get_ellipsize().
7328
62347329 // SetPulseStep is a wrapper around gtk_progress_bar_set_pulse_step().
62357330 func (v *ProgressBar) SetPulseStep(fraction float64) {
62367331 C.gtk_progress_bar_set_pulse_step(v.native(), C.gdouble(fraction))
62837378 }
62847379
62857380 func wrapRadioButton(obj *glib.Object) *RadioButton {
7381 if obj == nil {
7382 return nil
7383 }
7384
62867385 actionable := wrapActionable(obj)
62877386 return &RadioButton{CheckButton{ToggleButton{Button{Bin{Container{
62887387 Widget{glib.InitiallyUnowned{obj}}}}, actionable}}}}
62977396 return wrapRadioButton(glib.Take(unsafe.Pointer(c))), nil
62987397 }
62997398
6300 // RadioButtonNewFromWidget is a wrapper around
6301 // gtk_radio_button_new_from_widget().
7399 // RadioButtonNewFromWidget is a wrapper around gtk_radio_button_new_from_widget().
63027400 func RadioButtonNewFromWidget(radioGroupMember *RadioButton) (*RadioButton, error) {
63037401 c := C.gtk_radio_button_new_from_widget(radioGroupMember.native())
63047402 if c == nil {
63077405 return wrapRadioButton(glib.Take(unsafe.Pointer(c))), nil
63087406 }
63097407
6310 // RadioButtonNewWithLabel is a wrapper around
6311 // gtk_radio_button_new_with_label().
7408 // RadioButtonNewWithLabel is a wrapper around gtk_radio_button_new_with_label().
63127409 func RadioButtonNewWithLabel(group *glib.SList, label string) (*RadioButton, error) {
63137410 cstr := C.CString(label)
63147411 defer C.free(unsafe.Pointer(cstr))
63197416 return wrapRadioButton(glib.Take(unsafe.Pointer(c))), nil
63207417 }
63217418
6322 // RadioButtonNewWithLabelFromWidget is a wrapper around
6323 // gtk_radio_button_new_with_label_from_widget().
7419 // RadioButtonNewWithLabelFromWidget is a wrapper around gtk_radio_button_new_with_label_from_widget().
63247420 func RadioButtonNewWithLabelFromWidget(radioGroupMember *RadioButton, label string) (*RadioButton, error) {
63257421 cstr := C.CString(label)
63267422 defer C.free(unsafe.Pointer(cstr))
63357431 return wrapRadioButton(glib.Take(unsafe.Pointer(c))), nil
63367432 }
63377433
6338 // RadioButtonNewWithMnemonic is a wrapper around
6339 // gtk_radio_button_new_with_mnemonic()
7434 // RadioButtonNewWithMnemonic is a wrapper around gtk_radio_button_new_with_mnemonic().
63407435 func RadioButtonNewWithMnemonic(group *glib.SList, label string) (*RadioButton, error) {
63417436 cstr := C.CString(label)
63427437 defer C.free(unsafe.Pointer(cstr))
63477442 return wrapRadioButton(glib.Take(unsafe.Pointer(c))), nil
63487443 }
63497444
6350 // RadioButtonNewWithMnemonicFromWidget is a wrapper around
6351 // gtk_radio_button_new_with_mnemonic_from_widget().
7445 // RadioButtonNewWithMnemonicFromWidget is a wrapper around gtk_radio_button_new_with_mnemonic_from_widget().
63527446 func RadioButtonNewWithMnemonicFromWidget(radioGroupMember *RadioButton, label string) (*RadioButton, error) {
63537447 cstr := C.CString(label)
63547448 defer C.free(unsafe.Pointer(cstr))
63757469 if c == nil {
63767470 return nil, nilPtrErr
63777471 }
7472
7473 // TODO: call DataWrapper on SList and wrap them to gtk.RadioButton
7474
63787475 return glib.WrapSList(uintptr(unsafe.Pointer(c))), nil
63797476 }
63807477
64127509 }
64137510
64147511 func wrapRadioMenuItem(obj *glib.Object) *RadioMenuItem {
7512 if obj == nil {
7513 return nil
7514 }
7515
64157516 return &RadioMenuItem{CheckMenuItem{MenuItem{Bin{Container{
64167517 Widget{glib.InitiallyUnowned{obj}}}}}}}
64177518 }
64257526 return wrapRadioMenuItem(glib.Take(unsafe.Pointer(c))), nil
64267527 }
64277528
6428 // RadioMenuItemNewWithLabel is a wrapper around
6429 // gtk_radio_menu_item_new_with_label().
7529 // RadioMenuItemNewWithLabel is a wrapper around gtk_radio_menu_item_new_with_label().
64307530 func RadioMenuItemNewWithLabel(group *glib.SList, label string) (*RadioMenuItem, error) {
64317531 cstr := C.CString(label)
64327532 defer C.free(unsafe.Pointer(cstr))
64377537 return wrapRadioMenuItem(glib.Take(unsafe.Pointer(c))), nil
64387538 }
64397539
6440 // RadioMenuItemNewWithMnemonic is a wrapper around
6441 // gtk_radio_menu_item_new_with_mnemonic().
7540 // RadioMenuItemNewWithMnemonic is a wrapper around gtk_radio_menu_item_new_with_mnemonic().
64427541 func RadioMenuItemNewWithMnemonic(group *glib.SList, label string) (*RadioMenuItem, error) {
64437542 cstr := C.CString(label)
64447543 defer C.free(unsafe.Pointer(cstr))
64497548 return wrapRadioMenuItem(glib.Take(unsafe.Pointer(c))), nil
64507549 }
64517550
6452 // RadioMenuItemNewFromWidget is a wrapper around
6453 // gtk_radio_menu_item_new_from_widget().
7551 // RadioMenuItemNewFromWidget is a wrapper around gtk_radio_menu_item_new_from_widget().
64547552 func RadioMenuItemNewFromWidget(group *RadioMenuItem) (*RadioMenuItem, error) {
64557553 c := C.gtk_radio_menu_item_new_from_widget(group.native())
64567554 if c == nil {
64597557 return wrapRadioMenuItem(glib.Take(unsafe.Pointer(c))), nil
64607558 }
64617559
6462 // RadioMenuItemNewWithLabelFromWidget is a wrapper around
6463 // gtk_radio_menu_item_new_with_label_from_widget().
7560 // RadioMenuItemNewWithLabelFromWidget is a wrapper around gtk_radio_menu_item_new_with_label_from_widget().
64647561 func RadioMenuItemNewWithLabelFromWidget(group *RadioMenuItem, label string) (*RadioMenuItem, error) {
64657562 cstr := C.CString(label)
64667563 defer C.free(unsafe.Pointer(cstr))
64727569 return wrapRadioMenuItem(glib.Take(unsafe.Pointer(c))), nil
64737570 }
64747571
6475 // RadioMenuItemNewWithMnemonicFromWidget is a wrapper around
6476 // gtk_radio_menu_item_new_with_mnemonic_from_widget().
7572 // RadioMenuItemNewWithMnemonicFromWidget is a wrapper around gtk_radio_menu_item_new_with_mnemonic_from_widget().
64777573 func RadioMenuItemNewWithMnemonicFromWidget(group *RadioMenuItem, label string) (*RadioMenuItem, error) {
64787574 cstr := C.CString(label)
64797575 defer C.free(unsafe.Pointer(cstr))
64967592 if c == nil {
64977593 return nil, nilPtrErr
64987594 }
7595
7596 // TODO: call DataWrapper on SList and wrap them to gtk.RadioMenuItem
7597
64997598 return glib.WrapSList(uintptr(unsafe.Pointer(c))), nil
65007599 }
65017600
65247623 }
65257624
65267625 func wrapRange(obj *glib.Object) *Range {
7626 if obj == nil {
7627 return nil
7628 }
7629
65277630 return &Range{Widget{glib.InitiallyUnowned{obj}}}
7631 }
7632
7633 // GetFillLevel is a wrapper around gtk_range_get_fill_level().
7634 func (v *Range) GetFillLevel() float64 {
7635 return float64(C.gtk_range_get_fill_level(v.native()))
7636 }
7637
7638 // GetRestrictToFillLevel is a wrapper around gtk_range_get_restrict_to_fill_level().
7639 func (v *Range) GetRestrictToFillLevel() bool {
7640 return gobool(C.gtk_range_get_restrict_to_fill_level(v.native()))
7641 }
7642
7643 // GetShowFillLevel is a wrapper around gtk_range_get_show_fill_level().
7644 func (v *Range) GetShowFillLevel() bool {
7645 return gobool(C.gtk_range_get_show_fill_level(v.native()))
7646 }
7647
7648 // SetFillLevel is a wrapper around gtk_range_set_fill_level().
7649 func (v *Range) SetFillLevel(fill_level float64) {
7650 C.gtk_range_set_fill_level(v.native(), C.gdouble(fill_level))
7651 }
7652
7653 // RestrictToFillLevel is a wrapper around gtk_range_set_restrict_to_fill_level().
7654 func (v *Range) RestrictToFillLevel(restrict_to_fill_level bool) {
7655 C.gtk_range_set_restrict_to_fill_level(v.native(), gbool(restrict_to_fill_level))
7656 }
7657
7658 // SetShowFillLevel is a wrapper around gtk_range_set_show_fill_level().
7659 func (v *Range) SetShowFillLevel(show_fill_level bool) {
7660 C.gtk_range_set_show_fill_level(v.native(), gbool(show_fill_level))
7661 }
7662
7663 // GetAdjustment is a wrapper around gtk_range_get_adjustment().
7664 func (v *Range) GetAdjustment() *Adjustment {
7665
7666 c := C.gtk_range_get_adjustment(v.native())
7667 if c == nil {
7668 return nil
7669 }
7670 obj := glib.Take(unsafe.Pointer(c))
7671 return wrapAdjustment(obj)
7672 }
7673
7674 // SetAdjustment is a wrapper around gtk_range_set_adjustment().
7675 func (v *Range) SetAdjustment(adjustment *Adjustment) {
7676 C.gtk_range_set_adjustment(v.native(), adjustment.native())
65287677 }
65297678
65307679 // GetValue is a wrapper around gtk_range_get_value().
65387687 C.gtk_range_set_value(v.native(), C.gdouble(value))
65397688 }
65407689
6541 // SetIncrements() is a wrapper around gtk_range_set_increments().
7690 // SetIncrements is a wrapper around gtk_range_set_increments().
65427691 func (v *Range) SetIncrements(step, page float64) {
65437692 C.gtk_range_set_increments(v.native(), C.gdouble(step), C.gdouble(page))
65447693 }
65457694
6546 // SetRange() is a wrapper around gtk_range_set_range().
7695 // SetRange is a wrapper around gtk_range_set_range().
65477696 func (v *Range) SetRange(min, max float64) {
65487697 C.gtk_range_set_range(v.native(), C.gdouble(min), C.gdouble(max))
65497698 }
65507699
6551 // GetInverted() is a wrapper around gtk_range_get_inverted().
7700 // GetInverted is a wrapper around gtk_range_get_inverted().
65527701 func (v *Range) GetInverted() bool {
65537702 c := C.gtk_range_get_inverted(v.native())
65547703 return gobool(c)
65557704 }
65567705
6557 // SetInverted() is a wrapper around gtk_range_set_inverted().
7706 // SetInverted is a wrapper around gtk_range_set_inverted().
65587707 func (v *Range) SetInverted(inverted bool) {
65597708 C.gtk_range_set_inverted(v.native(), gbool(inverted))
7709 }
7710
7711 // GetRoundDigits is a wrapper around gtk_range_get_round_digits().
7712 func (v *Range) GetRoundDigits() int {
7713 return int(C.gtk_range_get_round_digits(v.native()))
7714 }
7715
7716 // SetRoundDigits is a wrapper around gtk_range_set_round_digits().
7717 func (v *Range) SetRoundDigits(round_digits int) {
7718 C.gtk_range_set_round_digits(v.native(), C.gint(round_digits))
7719 }
7720
7721 // SetLowerStepperSensitivity is a wrapper around gtk_range_set_lower_stepper_sensitivity().
7722 func (v *Range) SetLowerStepperSensitivity(sensitivity SensitivityType) {
7723 C.gtk_range_set_lower_stepper_sensitivity(
7724 v.native(),
7725 C.GtkSensitivityType(sensitivity))
7726 }
7727
7728 // GetLowerStepperSensitivity is a wrapper around gtk_range_get_lower_stepper_sensitivity().
7729 func (v *Range) GetLowerStepperSensitivity() SensitivityType {
7730 return SensitivityType(C.gtk_range_get_lower_stepper_sensitivity(
7731 v.native()))
7732 }
7733
7734 // SetUpperStepperSensitivity is a wrapper around gtk_range_set_upper_stepper_sensitivity().
7735 func (v *Range) SetUpperStepperSensitivity(sensitivity SensitivityType) {
7736 C.gtk_range_set_upper_stepper_sensitivity(
7737 v.native(),
7738 C.GtkSensitivityType(sensitivity))
7739 }
7740
7741 // GetUpperStepperSensitivity is a wrapper around gtk_range_get_upper_stepper_sensitivity().
7742 func (v *Range) GetUpperStepperSensitivity() SensitivityType {
7743 return SensitivityType(C.gtk_range_get_upper_stepper_sensitivity(
7744 v.native()))
7745 }
7746
7747 // GetFlippable is a wrapper around gtk_range_get_flippable().
7748 func (v *Range) GetFlippable() bool {
7749 return gobool(C.gtk_range_get_flippable(v.native()))
7750 }
7751
7752 // SetFlippable is a wrapper around gtk_range_set_flippable().
7753 func (v *Range) SetFlippable(flippable bool) {
7754 C.gtk_range_set_flippable(v.native(), gbool(flippable))
7755 }
7756
7757 // GetRangeRect is a wrapper around gtk_range_get_range_rect().
7758 func (v *Range) GetRangeRect() *gdk.Rectangle {
7759 var cRect *C.GdkRectangle
7760 C.gtk_range_get_range_rect(v.native(), cRect)
7761 return gdk.WrapRectangle(uintptr(unsafe.Pointer(cRect)))
7762 }
7763
7764 // GetSliderRange is a wrapper around gtk_range_get_slider_range().
7765 func (v *Range) GetSliderRange() (int, int) {
7766 var cStart, cEnd C.gint
7767 C.gtk_range_get_slider_range(v.native(), &cStart, &cEnd)
7768 return int(cStart), int(cEnd)
7769 }
7770
7771 // GetSliderFixedSize is a wrapper gtk_range_get_slider_size_fixed().
7772 func (v *Range) GetSliderFixedSize() bool {
7773 return gobool(C.gtk_range_get_slider_size_fixed(v.native()))
7774 }
7775
7776 // SetSliderFixedSize is a wrapper around gtk_range_set_slider_size_fixed().
7777 func (v *Range) SetSliderFixedSize(size_fixed bool) {
7778 C.gtk_range_set_slider_size_fixed(v.native(), gbool(size_fixed))
65607779 }
65617780
65627781 // IRecentChooser is an interface type implemented by all structs
65867805 }
65877806
65887807 func wrapRecentChooser(obj *glib.Object) *RecentChooser {
7808 if obj == nil {
7809 return nil
7810 }
7811
65897812 return &RecentChooser{obj}
65907813 }
65917814
66057828 func (v *RecentChooser) RemoveFilter(filter *RecentFilter) {
66067829 C.gtk_recent_chooser_remove_filter(v.native(), filter.native())
66077830 }
7831
7832 /*
7833 * GtkRecentChooserWidget
7834 */
7835
7836 // TODO:
7837 // gtk_recent_chooser_widget_new().
7838 // gtk_recent_chooser_widget_new_for_manager().
66087839
66097840 /*
66107841 * GtkRecentChooserMenu
66267857 }
66277858
66287859 func wrapRecentChooserMenu(obj *glib.Object) *RecentChooserMenu {
7860 if obj == nil {
7861 return nil
7862 }
7863
66297864 return &RecentChooserMenu{
66307865 Menu{MenuShell{Container{Widget{glib.InitiallyUnowned{obj}}}}},
66317866 RecentChooser{obj},
66517886 }
66527887
66537888 func wrapRecentFilter(obj *glib.Object) *RecentFilter {
7889 if obj == nil {
7890 return nil
7891 }
7892
66547893 return &RecentFilter{glib.InitiallyUnowned{obj}}
66557894 }
66567895
66887927 }
66897928
66907929 func wrapRecentManager(obj *glib.Object) *RecentManager {
7930 if obj == nil {
7931 return nil
7932 }
7933
66917934 return &RecentManager{obj}
66927935 }
66937936
67357978 }
67367979
67377980 func wrapScale(obj *glib.Object) *Scale {
7981 if obj == nil {
7982 return nil
7983 }
7984
67387985 return &Scale{Range{Widget{glib.InitiallyUnowned{obj}}}}
67397986 }
67407987
67588005 return wrapScale(glib.Take(unsafe.Pointer(c))), nil
67598006 }
67608007
6761 // SetDrawValue() is a wrapper around gtk_scale_set_draw_value().
8008 // TODO:
8009 // gtk_scale_set_digits().
8010
8011 // SetDrawValue is a wrapper around gtk_scale_set_draw_value().
67628012 func (v *Scale) SetDrawValue(drawValue bool) {
67638013 C.gtk_scale_set_draw_value(v.native(), gbool(drawValue))
8014 }
8015
8016 // TODO:
8017 // gtk_scale_set_has_origin().
8018 // gtk_scale_set_value_pos().
8019 // gtk_scale_get_digits().
8020 // gtk_scale_get_draw_value().
8021 // gtk_scale_get_has_origin().
8022 // gtk_scale_get_value_pos().
8023 // gtk_scale_get_layout().
8024 // gtk_scale_get_layout_offsets().
8025
8026 // AddMark is a wrpaper around gtk_scale_add_mark.
8027 func (v *Scale) AddMark(value float64, pos PositionType, markup string) {
8028 var markupchar *C.gchar
8029 if markup != "" {
8030 markupchar = (*C.gchar)(C.CString(markup))
8031 defer C.free(unsafe.Pointer(markupchar))
8032 }
8033
8034 C.gtk_scale_add_mark(v.native(), C.gdouble(value), C.GtkPositionType(pos), markupchar)
8035 }
8036
8037 // ClearMarks is a wrapper around gtk_scale_clear_marks.
8038 func (v *Scale) ClearMarks() {
8039 C.gtk_scale_clear_marks(v.native())
67648040 }
67658041
67668042 /*
67728048 Button
67738049 }
67748050
6775 // native() returns a pointer to the underlying GtkScaleButton.
8051 // native returns a pointer to the underlying GtkScaleButton.
67768052 func (v *ScaleButton) native() *C.GtkScaleButton {
67778053 if v == nil || v.GObject == nil {
67788054 return nil
67888064 }
67898065
67908066 func wrapScaleButton(obj *glib.Object) *ScaleButton {
8067 if obj == nil {
8068 return nil
8069 }
8070
67918071 actionable := wrapActionable(obj)
67928072 return &ScaleButton{Button{Bin{Container{Widget{glib.InitiallyUnowned{obj}}}}, actionable}}
67938073 }
67948074
6795 // ScaleButtonNew() is a wrapper around gtk_scale_button_new().
8075 // ScaleButtonNew is a wrapper around gtk_scale_button_new().
67968076 func ScaleButtonNew(size IconSize, min, max, step float64, icons []string) (*ScaleButton, error) {
67978077 cicons := make([]*C.gchar, len(icons))
67988078 for i, icon := range icons {
68128092 return wrapScaleButton(glib.Take(unsafe.Pointer(c))), nil
68138093 }
68148094
6815 // GetAdjustment() is a wrapper around gtk_scale_button_get_adjustment().
8095 // GetPopup is a wrapper around gtk_scale_button_get_popup().
8096 func (v *ScaleButton) GetPopup() (IWidget, error) {
8097 c := C.gtk_scale_button_get_popup(v.native())
8098 if c == nil {
8099 return nil, nilPtrErr
8100 }
8101 return castWidget(c)
8102 }
8103
8104 // GetValue is a wrapper around gtk_scale_button_get_value().
8105 func (v *ScaleButton) GetValue() float64 {
8106 return float64(C.gtk_scale_button_get_value(v.native()))
8107 }
8108
8109 // SetValue is a wrapper around gtk_scale_button_set_value().
8110 func (v *ScaleButton) SetValue(value float64) {
8111 C.gtk_scale_button_set_value(v.native(), C.gdouble(value))
8112 }
8113
8114 // SetIcons is a wrapper around gtk_scale_button_set_icons().
8115 func (v *ScaleButton) SetIcons() []string {
8116 var iconNames *C.gchar = nil
8117 C.gtk_scale_button_set_icons(v.native(), &iconNames)
8118 return toGoStringArray(&iconNames)
8119 }
8120
8121 // GetAdjustment is a wrapper around gtk_scale_button_get_adjustment().
68168122 func (v *ScaleButton) GetAdjustment() *Adjustment {
68178123 c := C.gtk_scale_button_get_adjustment(v.native())
68188124 obj := glib.Take(unsafe.Pointer(c))
68198125 return &Adjustment{glib.InitiallyUnowned{obj}}
68208126 }
68218127
6822 // GetPopup() is a wrapper around gtk_scale_button_get_popup().
6823 func (v *ScaleButton) GetPopup() (*Widget, error) {
6824 c := C.gtk_scale_button_get_popup(v.native())
6825 if c == nil {
6826 return nil, nilPtrErr
6827 }
6828 return wrapWidget(glib.Take(unsafe.Pointer(c))), nil
6829 }
6830
6831 // GetValue() is a wrapper around gtk_scale_button_get_value().
6832 func (v *ScaleButton) GetValue() float64 {
6833 return float64(C.gtk_scale_button_get_value(v.native()))
6834 }
6835
6836 // SetAdjustment() is a wrapper around gtk_scale_button_set_adjustment().
8128 // SetAdjustment is a wrapper around gtk_scale_button_set_adjustment().
68378129 func (v *ScaleButton) SetAdjustment(adjustment *Adjustment) {
68388130 C.gtk_scale_button_set_adjustment(v.native(), adjustment.native())
68398131 }
68408132
6841 // SetValue() is a wrapper around gtk_scale_button_set_value().
6842 func (v *ScaleButton) SetValue(value float64) {
6843 C.gtk_scale_button_set_value(v.native(), C.gdouble(value))
8133 // GetPlusButton is a wrapper around gtk_scale_button_get_plus_button().
8134 func (v *ScaleButton) GetPlusButton() (IWidget, error) {
8135 c := C.gtk_scale_button_get_plus_button(v.native())
8136 if c == nil {
8137 return nil, nilPtrErr
8138 }
8139 return castWidget(c)
8140 }
8141
8142 // GetMinusButton is a wrapper around gtk_scale_button_get_minus_button().
8143 func (v *ScaleButton) GetMinusButton() (IWidget, error) {
8144 c := C.gtk_scale_button_get_minus_button(v.native())
8145 if c == nil {
8146 return nil, nilPtrErr
8147 }
8148 return castWidget(c)
68448149 }
68458150
68468151 /*
68708175 }
68718176
68728177 func wrapScrollable(obj *glib.Object) *Scrollable {
8178 if obj == nil {
8179 return nil
8180 }
8181
68738182 return &Scrollable{obj}
68748183 }
68758184
69338242 }
69348243
69358244 func wrapScrollbar(obj *glib.Object) *Scrollbar {
8245 if obj == nil {
8246 return nil
8247 }
8248
69368249 return &Scrollbar{Range{Widget{glib.InitiallyUnowned{obj}}}}
69378250 }
69388251
69708283 }
69718284
69728285 func wrapScrolledWindow(obj *glib.Object) *ScrolledWindow {
8286 if obj == nil {
8287 return nil
8288 }
8289
69738290 return &ScrolledWindow{Bin{Container{Widget{glib.InitiallyUnowned{obj}}}}}
69748291 }
69758292
69818298 return nil, nilPtrErr
69828299 }
69838300 return wrapScrolledWindow(glib.Take(unsafe.Pointer(c))), nil
8301 }
8302
8303 // GetPolicy() is a wrapper around gtk_scrolled_window_get_policy().
8304 func (v *ScrolledWindow) GetPolicy() (hScrollbarPolicy, vScrollbarPolicy PolicyType) {
8305 var hScrPol, vScrPol C.GtkPolicyType
8306 C.gtk_scrolled_window_get_policy(v.native(), &hScrPol, &vScrPol)
8307 hScrollbarPolicy, vScrollbarPolicy = PolicyType(hScrPol), PolicyType(vScrPol)
8308 return
69848309 }
69858310
69868311 // SetPolicy() is a wrapper around gtk_scrolled_window_set_policy().
70188343 C.gtk_scrolled_window_set_vadjustment(v.native(), adjustment.native())
70198344 }
70208345
8346 // GetHScrollbar is a wrapper around gtk_scrolled_window_get_hscrollbar().
8347 func (v *ScrolledWindow) GetHScrollbar() *Scrollbar {
8348 c := C.gtk_scrolled_window_get_hscrollbar(v.native())
8349 if c == nil {
8350 return nil
8351 }
8352 return wrapScrollbar(glib.Take(unsafe.Pointer(c)))
8353 }
8354
8355 // GetVScrollbar is a wrapper around gtk_scrolled_window_get_vscrollbar().
8356 func (v *ScrolledWindow) GetVScrollbar() *Scrollbar {
8357 c := C.gtk_scrolled_window_get_vscrollbar(v.native())
8358 if c == nil {
8359 return nil
8360 }
8361 return wrapScrollbar(glib.Take(unsafe.Pointer(c)))
8362 }
8363
8364 // GetPlacement is a wrapper around gtk_scrolled_window_get_placement().
8365 func (v *ScrolledWindow) GetPlacement() CornerType {
8366 c := C.gtk_scrolled_window_get_placement(v.native())
8367 return CornerType(c)
8368 }
8369
8370 // SetPlacement is a wrapper around gtk_scrolled_window_set_placement().
8371 func (v *ScrolledWindow) SetPlacement(windowPlacement CornerType) {
8372 C.gtk_scrolled_window_set_placement(v.native(), C.GtkCornerType(windowPlacement))
8373 }
8374
8375 // UnsetPlacement is a wrapper around gtk_scrolled_window_unset_placement().
8376 func (v *ScrolledWindow) UnsetPlacement() {
8377 C.gtk_scrolled_window_unset_placement(v.native())
8378 }
8379
70218380 // GetShadowType is a wrapper around gtk_scrolled_window_get_shadow_type().
70228381 func (v *ScrolledWindow) GetShadowType() ShadowType {
70238382 c := C.gtk_scrolled_window_get_shadow_type(v.native())
70298388 C.gtk_scrolled_window_set_shadow_type(v.native(), C.GtkShadowType(t))
70308389 }
70318390
8391 // GetKineticScrolling is a wrapper around gtk_scrolled_window_get_kinetic_scrolling().
8392 func (v *ScrolledWindow) GetKineticScrolling() bool {
8393 c := C.gtk_scrolled_window_get_kinetic_scrolling(v.native())
8394 return gobool(c)
8395 }
8396
8397 // SetKineticScrolling is a wrapper around gtk_scrolled_window_set_kinetic_scrolling().
8398 func (v *ScrolledWindow) SetKineticScrolling(kineticScrolling bool) {
8399 C.gtk_scrolled_window_set_kinetic_scrolling(v.native(), gbool(kineticScrolling))
8400 }
8401
8402 // GetCaptureButtonPress is a wrapper around gtk_scrolled_window_get_capture_button_press().
8403 func (v *ScrolledWindow) GetCaptureButtonPress() bool {
8404 c := C.gtk_scrolled_window_get_capture_button_press(v.native())
8405 return gobool(c)
8406 }
8407
8408 // SetCaptureButtonPress is a wrapper around gtk_scrolled_window_set_capture_button_press().
8409 func (v *ScrolledWindow) SetCaptureButtonPress(captureButtonPress bool) {
8410 C.gtk_scrolled_window_set_capture_button_press(v.native(), gbool(captureButtonPress))
8411 }
8412
8413 // GetMinContentWidth is a wrapper around gtk_scrolled_window_get_min_content_width().
8414 func (v *ScrolledWindow) GetMinContentWidth() int {
8415 c := C.gtk_scrolled_window_get_min_content_width(v.native())
8416 return int(c)
8417 }
8418
8419 // SetMinContentWidth is a wrapper around gtk_scrolled_window_set_min_content_width().
8420 func (v *ScrolledWindow) SetMinContentWidth(width int) {
8421 C.gtk_scrolled_window_set_min_content_width(v.native(), C.gint(width))
8422 }
8423
8424 // GetMinContentHeight is a wrapper around gtk_scrolled_window_get_min_content_height().
8425 func (v *ScrolledWindow) GetMinContentHeight() int {
8426 c := C.gtk_scrolled_window_get_min_content_height(v.native())
8427 return int(c)
8428 }
8429
8430 // SetMinContentHeight is a wrapper around gtk_scrolled_window_set_min_content_height().
8431 func (v *ScrolledWindow) SetMinContentHeight(width int) {
8432 C.gtk_scrolled_window_set_min_content_height(v.native(), C.gint(width))
8433 }
8434
70328435 /*
70338436 * GtkSearchEntry
70348437 */
70548457 }
70558458
70568459 func wrapSearchEntry(obj *glib.Object) *SearchEntry {
8460 if obj == nil {
8461 return nil
8462 }
8463
70578464 e := wrapEditable(obj)
7058 return &SearchEntry{Entry{Widget{glib.InitiallyUnowned{obj}}, *e}}
8465 ce := wrapCellEditable(obj)
8466 return &SearchEntry{Entry{Widget{glib.InitiallyUnowned{obj}}, *e, *ce}}
70598467 }
70608468
70618469 // SearchEntryNew is a wrapper around gtk_search_entry_new().
70848492 if v == nil {
70858493 return nil
70868494 }
7087 return v.GtkSelectionData
7088 }
7089
7090 // GetLength is a wrapper around gtk_selection_data_get_length
8495
8496 // I don't understand why we need this, but we do.
8497 c := (*C.GValue)(unsafe.Pointer(v))
8498 p := (*C.GtkSelectionData)(unsafe.Pointer(c))
8499 return p
8500 }
8501
8502 // GetLength is a wrapper around gtk_selection_data_get_length().
70918503 func (v *SelectionData) GetLength() int {
70928504 return int(C.gtk_selection_data_get_length(v.native()))
70938505 }
70948506
7095 // GetData is a wrapper around gtk_selection_data_get_data_with_length.
7096 // It returns a slice of the correct size with the selection's data.
7097 func (v *SelectionData) GetData() (data []byte) {
8507 // GetData is a wrapper around gtk_selection_data_get_data_with_length().
8508 // It returns a slice of the correct size with the copy of the selection's data.
8509 func (v *SelectionData) GetData() []byte {
70988510 var length C.gint
70998511 c := C.gtk_selection_data_get_data_with_length(v.native(), &length)
8512
8513 // Only set if length is valid.
8514 if int(length) < 1 {
8515 return nil
8516 }
8517
8518 var data []byte
71008519 sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&data))
7101 sliceHeader.Data = uintptr(unsafe.Pointer(c))
71028520 sliceHeader.Len = int(length)
71038521 sliceHeader.Cap = int(length)
7104 return
7105 }
7106
7107 //fixed GetData directly from ptr
7108 func GetData(pointer uintptr) (data []byte) {
7109 c := (*C.GValue)(unsafe.Pointer(pointer))
7110 p := (*C.GtkSelectionData)(unsafe.Pointer(c))
7111 C.gtk_selection_data_get_text(p)
7112
7113 var byteData []byte
7114 var length C.gint
7115 cptr := C.gtk_selection_data_get_data_with_length(p, &length)
7116 sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&byteData))
7117 sliceHeader.Data = uintptr(unsafe.Pointer(cptr))
7118 sliceHeader.Len = int(length)
7119 sliceHeader.Cap = int(length)
7120
7121 return byteData
7122 }
7123
7124 //for "drag-data-get"
7125 func SetData(pointer uintptr, atom gdk.Atom, data []byte) {
7126 c := (*C.GValue)(unsafe.Pointer(pointer))
7127 p := (*C.GtkSelectionData)(unsafe.Pointer(c))
7128 C.gtk_selection_data_set(p, C.GdkAtom(unsafe.Pointer(atom)), C.gint(8), (*C.guchar)(unsafe.Pointer(&data[0])), C.gint(len(data)))
8522 sliceHeader.Data = uintptr(unsafe.Pointer(c))
8523
8524 // Keep the SelectionData alive for as long as the byte slice is.
8525 runtime.SetFinalizer(&data, func(*[]byte) {
8526 runtime.KeepAlive(v)
8527 })
8528
8529 return data
8530 }
8531
8532 // SetData is a wrapper around gtk_selection_data_set_data_with_length().
8533 func (v *SelectionData) SetData(atom gdk.Atom, data []byte) {
8534 C.gtk_selection_data_set(
8535 v.native(),
8536 C.GdkAtom(unsafe.Pointer(atom)),
8537 C.gint(8), (*C.guchar)(&data[0]), C.gint(len(data)),
8538 )
8539 }
8540
8541 // GetText is a wrapper around gtk_selection_data_get_text(). It returns a copy
8542 // of the string from SelectionData and frees the C reference.
8543 func (v *SelectionData) GetText() string {
8544 charptr := C.gtk_selection_data_get_text(v.native())
8545 if charptr == nil {
8546 return ""
8547 }
8548
8549 defer C.g_free(C.gpointer(charptr))
8550
8551 return ucharString(charptr)
8552 }
8553
8554 // SetText is a wrapper around gtk_selection_data_set_text().
8555 func (v *SelectionData) SetText(text string) bool {
8556 textPtr := *(*[]byte)(unsafe.Pointer(&text))
8557
8558 return gobool(C.gtk_selection_data_set_text(
8559 v.native(),
8560 // https://play.golang.org/p/PmGaLDhRuEU
8561 // This is probably safe since we expect Gdk to copy the string anyway.
8562 (*C.gchar)(unsafe.Pointer(&textPtr[0])), C.int(len(text)),
8563 ))
8564 }
8565
8566 // SetPixbuf is a wrapper around gtk_selection_data_set_pixbuf().
8567 func (v *SelectionData) SetPixbuf(pixbuf *gdk.Pixbuf) bool {
8568 return gobool(C.gtk_selection_data_set_pixbuf(
8569 v.native(),
8570 (*C.GdkPixbuf)(unsafe.Pointer(pixbuf.Native())),
8571 ))
8572 }
8573
8574 // GetPixbuf is a wrapper around gtk_selection_data_get_pixbuf(). It returns nil
8575 // if the data is a recognized image type that could be converted to a new
8576 // Pixbuf.
8577 func (v *SelectionData) GetPixbuf() *gdk.Pixbuf {
8578 c := C.gtk_selection_data_get_pixbuf(v.native())
8579 if c == nil {
8580 return nil
8581 }
8582
8583 obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
8584 p := &gdk.Pixbuf{obj}
8585 runtime.SetFinalizer(p, func(_ interface{}) { obj.Unref() })
8586
8587 return p
8588 }
8589
8590 // SetURIs is a wrapper around gtk_selection_data_set_uris().
8591 func (v *SelectionData) SetURIs(uris []string) bool {
8592 var clist = C.make_strings(C.int(len(uris)))
8593 for i := range uris {
8594 cstring := C.CString(uris[i])
8595 // This defer will only run once the function exits, not once the loop
8596 // exits, so it's perfectly fine.
8597 defer C.free(unsafe.Pointer(cstring))
8598
8599 C.set_string(clist, C.int(i), (*C.gchar)(cstring))
8600 }
8601
8602 return gobool(C.gtk_selection_data_set_uris(v.native(), clist))
8603 }
8604
8605 // GetURIs is a wrapper around gtk_selection_data_get_uris().
8606 func (v *SelectionData) GetURIs() []string {
8607 uriPtrs := C.gtk_selection_data_get_uris(v.native())
8608 return toGoStringArray(uriPtrs)
71298609 }
71308610
71318611 func (v *SelectionData) free() {
71328612 C.gtk_selection_data_free(v.native())
71338613 }
71348614
7135 //for "drag-begin" event
7136 func DragSetIconPixbuf(context *gdk.DragContext, pixbuf *gdk.Pixbuf, hot_x int, hot_y int) {
8615 // DragSetIconPixbuf is used for the "drag-begin" event. It is a wrapper around
8616 // gtk_drag_set_icon_pixbuf().
8617 func DragSetIconPixbuf(context *gdk.DragContext, pixbuf *gdk.Pixbuf, hotX, hotY int) {
71378618 ctx := unsafe.Pointer(context.Native())
71388619 pix := unsafe.Pointer(pixbuf.Native())
7139 C.gtk_drag_set_icon_pixbuf((*C.GdkDragContext)(ctx), (*C.GdkPixbuf)(pix), C.gint(hot_x), C.gint(hot_y))
8620 C.gtk_drag_set_icon_pixbuf((*C.GdkDragContext)(ctx), (*C.GdkPixbuf)(pix), C.gint(hotX), C.gint(hotY))
8621 }
8622
8623 // DragSetIconWidget is a wrapper around gtk_drag_set_icon_widget().
8624 func DragSetIconWidget(context *gdk.DragContext, w IWidget, hotX, hotY int) {
8625 ctx := unsafe.Pointer(context.Native())
8626 C.gtk_drag_set_icon_widget((*C.GdkDragContext)(ctx), w.toWidget(), C.gint(hotX), C.gint(hotY))
8627 }
8628
8629 // DragSetIconSurface is a wrapper around gtk_drag_set_icon_surface().
8630 func DragSetIconSurface(context *gdk.DragContext, surface *cairo.Surface) {
8631 ctx := unsafe.Pointer(context.Native())
8632 sur := unsafe.Pointer(surface.Native())
8633 C.gtk_drag_set_icon_surface((*C.GdkDragContext)(ctx), (*C.cairo_surface_t)(sur))
8634 }
8635
8636 // DragSetIconName is a wrapper around gtk_drag_set_icon_name().
8637 func DragSetIconName(context *gdk.DragContext, iconName string, hotX, hotY int) {
8638 ctx := unsafe.Pointer(context.Native())
8639 ico := (*C.gchar)(C.CString(iconName))
8640 defer C.free(unsafe.Pointer(ico))
8641
8642 C.gtk_drag_set_icon_name((*C.GdkDragContext)(ctx), ico, C.gint(hotX), C.gint(hotY))
8643 }
8644
8645 // DragSetIconDefault is a wrapper around gtk_drag_set_icon_default().
8646 func DragSetIconDefault(context *gdk.DragContext) {
8647 ctx := unsafe.Pointer(context.Native())
8648 C.gtk_drag_set_icon_default((*C.GdkDragContext)(ctx))
71408649 }
71418650
71428651 /*
71648673 }
71658674
71668675 func wrapSeparator(obj *glib.Object) *Separator {
8676 if obj == nil {
8677 return nil
8678 }
8679
71678680 return &Separator{Widget{glib.InitiallyUnowned{obj}}}
71688681 }
71698682
72018714 }
72028715
72038716 func wrapSeparatorMenuItem(obj *glib.Object) *SeparatorMenuItem {
8717 if obj == nil {
8718 return nil
8719 }
8720
72048721 return &SeparatorMenuItem{MenuItem{Bin{Container{Widget{glib.InitiallyUnowned{obj}}}}}}
72058722 }
72068723
72388755 }
72398756
72408757 func wrapSeparatorToolItem(obj *glib.Object) *SeparatorToolItem {
8758 if obj == nil {
8759 return nil
8760 }
8761
72418762 return &SeparatorToolItem{ToolItem{Bin{Container{Widget{
72428763 glib.InitiallyUnowned{obj}}}}}}
72438764 }
72878808 }
72888809
72898810 func wrapSizeGroup(obj *glib.Object) *SizeGroup {
8811 if obj == nil {
8812 return nil
8813 }
8814
72908815 return &SizeGroup{obj}
72918816 }
72928817
73208845 if c == nil {
73218846 return nil
73228847 }
8848
8849 // TODO: call DataWrapper on SList and wrap them to gtk.IWidget
8850 // see (v *Container) GetFocusChain()
8851
73238852 return glib.WrapSList(uintptr(unsafe.Pointer(c)))
73248853 }
73258854
73308859 // SpinButton is a representation of GTK's GtkSpinButton.
73318860 type SpinButton struct {
73328861 Entry
8862 Orientable
73338863 }
73348864
73358865 // native returns a pointer to the underlying GtkSpinButton.
73488878 }
73498879
73508880 func wrapSpinButton(obj *glib.Object) *SpinButton {
8881 if obj == nil {
8882 return nil
8883 }
8884
73518885 e := wrapEditable(obj)
7352 return &SpinButton{Entry{Widget{glib.InitiallyUnowned{obj}}, *e}}
7353 }
7354
7355 // Configure() is a wrapper around gtk_spin_button_configure().
8886 ce := wrapCellEditable(obj)
8887 o := wrapOrientable(obj)
8888 return &SpinButton{Entry{Widget{glib.InitiallyUnowned{obj}}, *e, *ce}, *o}
8889 }
8890
8891 // Configure is a wrapper around gtk_spin_button_configure().
73568892 func (v *SpinButton) Configure(adjustment *Adjustment, climbRate float64, digits uint) {
73578893 C.gtk_spin_button_configure(v.native(), adjustment.native(),
73588894 C.gdouble(climbRate), C.guint(digits))
73598895 }
73608896
7361 // SpinButtonNew() is a wrapper around gtk_spin_button_new().
8897 // SpinButtonNew is a wrapper around gtk_spin_button_new().
73628898 func SpinButtonNew(adjustment *Adjustment, climbRate float64, digits uint) (*SpinButton, error) {
73638899 c := C.gtk_spin_button_new(adjustment.native(),
73648900 C.gdouble(climbRate), C.guint(digits))
73688904 return wrapSpinButton(glib.Take(unsafe.Pointer(c))), nil
73698905 }
73708906
7371 // SpinButtonNewWithRange() is a wrapper around
7372 // gtk_spin_button_new_with_range().
8907 // SpinButtonNewWithRange is a wrapper around gtk_spin_button_new_with_range().
73738908 func SpinButtonNewWithRange(min, max, step float64) (*SpinButton, error) {
73748909 c := C.gtk_spin_button_new_with_range(C.gdouble(min), C.gdouble(max),
73758910 C.gdouble(step))
73798914 return wrapSpinButton(glib.Take(unsafe.Pointer(c))), nil
73808915 }
73818916
7382 // GetValueAsInt() is a wrapper around gtk_spin_button_get_value_as_int().
7383 func (v *SpinButton) GetValueAsInt() int {
7384 c := C.gtk_spin_button_get_value_as_int(v.native())
7385 return int(c)
8917 // SetAdjustment() is a wrapper around gtk_spin_button_set_adjustment().
8918 func (v *SpinButton) SetAdjustment(adjustment *Adjustment) {
8919 C.gtk_spin_button_set_adjustment(v.native(), adjustment.native())
8920 }
8921
8922 // GetAdjustment() is a wrapper around gtk_spin_button_get_adjustment
8923 func (v *SpinButton) GetAdjustment() *Adjustment {
8924 c := C.gtk_spin_button_get_adjustment(v.native())
8925 if c == nil {
8926 return nil
8927 }
8928 return wrapAdjustment(glib.Take(unsafe.Pointer(c)))
8929 }
8930
8931 // SetDigits() is a wrapper around gtk_spin_button_set_digits().
8932 func (v *SpinButton) SetDigits(digits uint) {
8933 C.gtk_spin_button_set_digits(v.native(), C.guint(digits))
8934 }
8935
8936 // SetIncrements() is a wrapper around gtk_spin_button_set_increments().
8937 func (v *SpinButton) SetIncrements(step, page float64) {
8938 C.gtk_spin_button_set_increments(v.native(), C.gdouble(step), C.gdouble(page))
8939 }
8940
8941 // SetRange is a wrapper around gtk_spin_button_set_range().
8942 func (v *SpinButton) SetRange(min, max float64) {
8943 C.gtk_spin_button_set_range(v.native(), C.gdouble(min), C.gdouble(max))
73868944 }
73878945
73888946 // SetValue() is a wrapper around gtk_spin_button_set_value().
73968954 return float64(c)
73978955 }
73988956
7399 // GetAdjustment() is a wrapper around gtk_spin_button_get_adjustment
7400 func (v *SpinButton) GetAdjustment() *Adjustment {
7401 c := C.gtk_spin_button_get_adjustment(v.native())
7402 if c == nil {
7403 return nil
7404 }
7405 return wrapAdjustment(glib.Take(unsafe.Pointer(c)))
7406 }
7407
7408 // SetRange is a wrapper around gtk_spin_button_set_range().
7409 func (v *SpinButton) SetRange(min, max float64) {
7410 C.gtk_spin_button_set_range(v.native(), C.gdouble(min), C.gdouble(max))
7411 }
7412
7413 // SetIncrements() is a wrapper around gtk_spin_button_set_increments().
7414 func (v *SpinButton) SetIncrements(step, page float64) {
7415 C.gtk_spin_button_set_increments(v.native(), C.gdouble(step), C.gdouble(page))
7416 }
8957 // GetValueAsInt is a wrapper around gtk_spin_button_get_value_as_int().
8958 func (v *SpinButton) GetValueAsInt() int {
8959 c := C.gtk_spin_button_get_value_as_int(v.native())
8960 return int(c)
8961 }
8962
8963 // SetUpdatePolicy() is a wrapper around gtk_spin_button_set_update_policy().
8964 func (v *SpinButton) SetUpdatePolicy(policy SpinButtonUpdatePolicy) {
8965 C.gtk_spin_button_set_update_policy(
8966 v.native(),
8967 C.GtkSpinButtonUpdatePolicy(policy))
8968 }
8969
8970 // SetNumeric() is a wrapper around gtk_spin_button_set_numeric().
8971 func (v *SpinButton) SetNumeric(numeric bool) {
8972 C.gtk_spin_button_set_numeric(v.native(), gbool(numeric))
8973 }
8974
8975 // Spin() is a wrapper around gtk_spin_button_spin().
8976 func (v *SpinButton) Spin(direction SpinType, increment float64) {
8977 C.gtk_spin_button_spin(
8978 v.native(),
8979 C.GtkSpinType(direction),
8980 C.gdouble(increment))
8981 }
8982
8983 // gtk_spin_button_set_wrap().
8984 // gtk_spin_button_set_snap_to_ticks().
8985
8986 // Update() is a wrapper around gtk_spin_button_update().
8987 func (v *SpinButton) Update() {
8988 C.gtk_spin_button_update(v.native())
8989 }
8990
8991 // GetDigits() is a wrapper around gtk_spin_button_get_digits().
8992 func (v *SpinButton) GetDigits() uint {
8993 return uint(C.gtk_spin_button_get_digits(v.native()))
8994 }
8995
8996 // gtk_spin_button_get_increments().
8997 // gtk_spin_button_get_numeric().
8998 // gtk_spin_button_get_range().
8999 // gtk_spin_button_get_snap_to_ticks().
9000
9001 // GetUpdatePolicy() is a wrapper around gtk_spin_button_get_update_policy().
9002 func (v *SpinButton) GetUpdatePolicy() SpinButtonUpdatePolicy {
9003 return SpinButtonUpdatePolicy(
9004 C.gtk_spin_button_get_update_policy(
9005 v.native()))
9006 }
9007
9008 // gtk_spin_button_get_wrap().
74179009
74189010 /*
74199011 * GtkSpinner
74409032 }
74419033
74429034 func wrapSpinner(obj *glib.Object) *Spinner {
9035 if obj == nil {
9036 return nil
9037 }
9038
74439039 return &Spinner{Widget{glib.InitiallyUnowned{obj}}}
74449040 }
74459041
74879083 }
74889084
74899085 func wrapStatusbar(obj *glib.Object) *Statusbar {
9086 if obj == nil {
9087 return nil
9088 }
9089
74909090 return &Statusbar{Box{Container{Widget{glib.InitiallyUnowned{obj}}}}}
74919091 }
74929092
75619161 }
75629162
75639163 func wrapSwitch(obj *glib.Object) *Switch {
9164 if obj == nil {
9165 return nil
9166 }
9167
75649168 return &Switch{Widget{glib.InitiallyUnowned{obj}}}
75659169 }
75669170
76429246 }
76439247
76449248 func wrapTextTag(obj *glib.Object) *TextTag {
9249 if obj == nil {
9250 return nil
9251 }
9252
76459253 return &TextTag{obj}
76469254 }
76479255
9256 // TextTagNew is a wrapper around gtk_text_tag_new(). If name is empty, then the
9257 // tag is anonymous.
76489258 func TextTagNew(name string) (*TextTag, error) {
7649 cname := C.CString(name)
7650 defer C.free(unsafe.Pointer(cname))
7651 c := C.gtk_text_tag_new((*C.gchar)(cname))
7652 if c == nil {
7653 return nil, nilPtrErr
7654 }
9259 var gchar *C.gchar
9260 if name != "" {
9261 gchar = (*C.gchar)(C.CString(name))
9262 defer C.free(unsafe.Pointer(gchar))
9263 }
9264
9265 c := C.gtk_text_tag_new(gchar)
9266 if c == nil {
9267 return nil, nilPtrErr
9268 }
9269
76559270 return wrapTextTag(glib.Take(unsafe.Pointer(c))), nil
76569271 }
76579272
76999314 }
77009315
77019316 func wrapTextTagTable(obj *glib.Object) *TextTagTable {
9317 if obj == nil {
9318 return nil
9319 }
9320
77029321 return &TextTagTable{obj}
77039322 }
77049323
77579376 }
77589377
77599378 func wrapTextBuffer(obj *glib.Object) *TextBuffer {
9379 if obj == nil {
9380 return nil
9381 }
9382
77609383 return &TextBuffer{obj}
77619384 }
77629385
77929415 // CreateChildAnchor() is a wrapper around gtk_text_buffer_create_child_anchor().
77939416 // Since it copies garbage from the stack into the padding bytes of iter,
77949417 // iter can't be reliably reused after this call unless GODEBUG=cgocheck=0.
7795 func (v *TextBuffer) CreateChildAnchor(iter *TextIter) *TextChildAnchor {
7796 ret := C.gtk_text_buffer_create_child_anchor(v.native(), iter.native())
7797 return (*TextChildAnchor)(ret)
9418 func (v *TextBuffer) CreateChildAnchor(iter *TextIter) (*TextChildAnchor, error) {
9419 c := C.gtk_text_buffer_create_child_anchor(v.native(), iter.native())
9420 if c == nil {
9421 return nil, nilPtrErr
9422 }
9423 return wrapTextChildAnchor(glib.Take(unsafe.Pointer(c))), nil
77989424 }
77999425
78009426 // Delete() is a wrapper around gtk_text_buffer_delete().
79369562 // GetIterAtMark() is a wrapper around gtk_text_buffer_get_iter_at_mark().
79379563 func (v *TextBuffer) GetIterAtMark(mark *TextMark) *TextIter {
79389564 var iter C.GtkTextIter
7939 C.gtk_text_buffer_get_iter_at_mark(v.native(), &iter, (*C.GtkTextMark)(mark))
9565 C.gtk_text_buffer_get_iter_at_mark(v.native(), &iter, mark.native())
79409566 return (*TextIter)(&iter)
79419567 }
79429568
79459571 cstr := C.CString(mark_name)
79469572 defer C.free(unsafe.Pointer(cstr))
79479573 ret := C.gtk_text_buffer_create_mark(v.native(), (*C.gchar)(cstr), (*C.GtkTextIter)(where), gbool(left_gravity))
7948 return (*TextMark)(ret)
9574 return wrapTextMark(glib.Take(unsafe.Pointer(ret)))
79499575 }
79509576
79519577 // GetMark() is a wrapper around gtk_text_buffer_get_mark().
79539579 cstr := C.CString(mark_name)
79549580 defer C.free(unsafe.Pointer(cstr))
79559581 ret := C.gtk_text_buffer_get_mark(v.native(), (*C.gchar)(cstr))
7956 return (*TextMark)(ret)
9582 return wrapTextMark(glib.Take(unsafe.Pointer(ret)))
79579583 }
79589584
79599585 // DeleteMark() is a wrapper around gtk_text_buffer_delete_mark()
79609586 func (v *TextBuffer) DeleteMark(mark *TextMark) {
7961 C.gtk_text_buffer_delete_mark(v.native(), (*C.GtkTextMark)(mark))
9587 C.gtk_text_buffer_delete_mark(v.native(), mark.native())
79629588 }
79639589
79649590 // DeleteMarkByName() is a wrapper around gtk_text_buffer_delete_mark_by_name()
79879613 // GetSelectionBound() is a wrapper around gtk_text_buffer_get_selection_bound().
79889614 func (v *TextBuffer) GetSelectionBound() *TextMark {
79899615 ret := C.gtk_text_buffer_get_selection_bound(v.native())
7990 return (*TextMark)(ret)
9616 return wrapTextMark(glib.Take(unsafe.Pointer(ret)))
79919617 }
79929618
79939619 // GetSelectionBounds() is a wrapper around gtk_text_buffer_get_selection_bounds().
80789704 // GetInsert() is a wrapper around gtk_text_buffer_get_insert().
80799705 func (v *TextBuffer) GetInsert() *TextMark {
80809706 ret := C.gtk_text_buffer_get_insert(v.native())
8081 return (*TextMark)(ret)
9707 return wrapTextMark(glib.Take(unsafe.Pointer(ret)))
80829708 }
80839709
80849710 // CopyClipboard() is a wrapper around gtk_text_buffer_copy_clipboard().
81139739 return
81149740 }
81159741
9742 // InsertInteractiveAtCursor() is a wrapper around gtk_text_buffer_insert_interactive_at_cursor().
9743 func (v *TextBuffer) InsertInteractiveAtCursor(text string, editable bool) bool {
9744 cstr := C.CString(text)
9745 defer C.free(unsafe.Pointer(cstr))
9746
9747 return gobool(C.gtk_text_buffer_insert_interactive_at_cursor(
9748 v.native(),
9749 (*C.gchar)(cstr),
9750 C.gint(len(text)),
9751 gbool(editable)))
9752 }
9753
9754 // InsertInteractive() is a wrapper around gtk_text_buffer_insert_interactive().
9755 func (v *TextBuffer) InsertInteractive(iter *TextIter, text string, editable bool) bool {
9756 cstr := C.CString(text)
9757 defer C.free(unsafe.Pointer(cstr))
9758
9759 return gobool(C.gtk_text_buffer_insert_interactive(
9760 v.native(),
9761 (*C.GtkTextIter)(iter),
9762 (*C.gchar)(cstr),
9763 C.gint(len(text)),
9764 gbool(editable)))
9765 }
9766
9767 // InsertRangeInteractive() is a wrapper around gtk_text_buffer_insert_range_interactive().
9768 func (v *TextBuffer) InsertRangeInteractive(iter, start, end *TextIter, editable bool) bool {
9769
9770 return gobool(C.gtk_text_buffer_insert_range_interactive(
9771 v.native(),
9772 (*C.GtkTextIter)(iter),
9773 (*C.GtkTextIter)(start),
9774 (*C.GtkTextIter)(end),
9775 gbool(editable)))
9776 }
9777
9778 // InsertRange() is a wrapper around gtk_text_buffer_insert_range().
9779 func (v *TextBuffer) InsertRange(iter, start, end *TextIter) {
9780
9781 C.gtk_text_buffer_insert_range(
9782 v.native(),
9783 (*C.GtkTextIter)(iter),
9784 (*C.GtkTextIter)(start),
9785 (*C.GtkTextIter)(end))
9786 }
9787
9788 // DeleteInteractive() is a wrapper around gtk_text_buffer_delete_interactive().
9789 func (v *TextBuffer) DeleteInteractive(start, end *TextIter, editable bool) bool {
9790
9791 return gobool(C.gtk_text_buffer_delete_interactive(
9792 v.native(),
9793 (*C.GtkTextIter)(start),
9794 (*C.GtkTextIter)(end),
9795 gbool(editable)))
9796 }
9797
9798 // BeginUserAction() is a wrapper around gtk_text_buffer_begin_user_action().
9799 func (v *TextBuffer) BeginUserAction() {
9800
9801 C.gtk_text_buffer_begin_user_action(v.native())
9802 }
9803
9804 // EndUserAction() is a wrapper around gtk_text_buffer_end_user_action().
9805 func (v *TextBuffer) EndUserAction() {
9806
9807 C.gtk_text_buffer_end_user_action(v.native())
9808 }
9809
81169810 /*
81179811 * GtkToggleButton
81189812 */
81389832 }
81399833
81409834 func wrapToggleButton(obj *glib.Object) *ToggleButton {
9835 if obj == nil {
9836 return nil
9837 }
9838
81419839 actionable := wrapActionable(obj)
81429840 return &ToggleButton{Button{Bin{Container{Widget{
81439841 glib.InitiallyUnowned{obj}}}}, actionable}}
81989896 C.gtk_toggle_button_set_mode(v.native(), gbool(drawIndicator))
81999897 }
82009898
9899 // Toggled is a wrapper around gtk_toggle_button_toggled().
9900 func (v *ToggleButton) Toggled() {
9901 C.gtk_toggle_button_toggled(v.native())
9902 }
9903
9904 // GetInconsistent gtk_toggle_button_get_inconsistent().
9905 func (v *ToggleButton) GetInconsistent() bool {
9906 c := C.gtk_toggle_button_get_inconsistent(v.native())
9907 return gobool(c)
9908 }
9909
9910 // SetInconsistent gtk_toggle_button_set_inconsistent().
9911 func (v *ToggleButton) SetInconsistent(setting bool) {
9912 C.gtk_toggle_button_set_inconsistent(v.native(), gbool(setting))
9913 }
9914
82019915 /*
82029916 * GtkToolbar
82039917 */
82239937 }
82249938
82259939 func wrapToolbar(obj *glib.Object) *Toolbar {
9940 if obj == nil {
9941 return nil
9942 }
9943
82269944 return &Toolbar{Container{Widget{glib.InitiallyUnowned{obj}}}}
82279945 }
82289946
82679985 return int(c)
82689986 }
82699987
8270 // SetDropHighlightItem is a wrapper around
8271 // gtk_toolbar_set_drop_highlight_item().
9988 // SetDropHighlightItem is a wrapper around gtk_toolbar_set_drop_highlight_item().
82729989 func (v *Toolbar) SetDropHighlightItem(toolItem IToolItem, index int) {
82739990 C.gtk_toolbar_set_drop_highlight_item(v.native(),
82749991 toolItem.toToolItem(), C.gint(index))
834810065 }
834910066
835010067 func wrapToolButton(obj *glib.Object) *ToolButton {
10068 if obj == nil {
10069 return nil
10070 }
10071
835110072 return &ToolButton{ToolItem{Bin{Container{Widget{
835210073 glib.InitiallyUnowned{obj}}}}}}
835310074 }
840710128 }
840810129
840910130 // GetIconWidget is a wrapper around gtk_tool_button_get_icon_widget().
8410 func (v *ToolButton) GetIconWidget() *Widget {
10131 func (v *ToolButton) GetIconWidget() (IWidget, error) {
841110132 c := C.gtk_tool_button_get_icon_widget(v.native())
841210133 if c == nil {
8413 return nil
8414 }
8415 return wrapWidget(glib.Take(unsafe.Pointer(c)))
10134 return nil, nil
10135 }
10136 return castWidget(c)
841610137 }
841710138
841810139 // SetLabelWidget is a wrapper around gtk_tool_button_set_label_widget().
842110142 }
842210143
842310144 // GetLabelWidget is a wrapper around gtk_tool_button_get_label_widget().
8424 func (v *ToolButton) GetLabelWidget() *Widget {
10145 func (v *ToolButton) GetLabelWidget() (IWidget, error) {
842510146 c := C.gtk_tool_button_get_label_widget(v.native())
842610147 if c == nil {
8427 return nil
8428 }
8429 return wrapWidget(glib.Take(unsafe.Pointer(c)))
10148 return nil, nil
10149 }
10150 return castWidget(c)
843010151 }
843110152
843210153 /*
845410175 }
845510176
845610177 func wrapToggleToolButton(obj *glib.Object) *ToggleToolButton {
10178 if obj == nil {
10179 return nil
10180 }
10181
845710182 return &ToggleToolButton{ToolButton{ToolItem{Bin{Container{Widget{
845810183 glib.InitiallyUnowned{obj}}}}}}}
845910184 }
851410239 }
851510240
851610241 func wrapToolItem(obj *glib.Object) *ToolItem {
10242 if obj == nil {
10243 return nil
10244 }
10245
851710246 return &ToolItem{Bin{Container{Widget{glib.InitiallyUnowned{obj}}}}}
851810247 }
851910248
857310302 return gobool(c)
857410303 }
857510304
8576 // SetVisibleHorizontal is a wrapper around
8577 // gtk_tool_item_set_visible_horizontal().
10305 // SetVisibleHorizontal is a wrapper around gtk_tool_item_set_visible_horizontal().
857810306 func (v *ToolItem) SetVisibleHorizontal(visibleHorizontal bool) {
857910307 C.gtk_tool_item_set_visible_horizontal(v.native(),
858010308 gbool(visibleHorizontal))
858110309 }
858210310
8583 // GetVisibleHorizontal is a wrapper around
8584 // gtk_tool_item_get_visible_horizontal().
10311 // GetVisibleHorizontal is a wrapper around gtk_tool_item_get_visible_horizontal().
858510312 func (v *ToolItem) GetVisibleHorizontal() bool {
858610313 c := C.gtk_tool_item_get_visible_horizontal(v.native())
858710314 return gobool(c)
862410351 }
862510352
862610353 // GetToolbarStyle is a wrapper around gtk_tool_item_get_toolbar_style().
8627 func (v *ToolItem) gtk_tool_item_get_toolbar_style() ToolbarStyle {
10354 func (v *ToolItem) GetToolbarStyle() ToolbarStyle {
862810355 c := C.gtk_tool_item_get_toolbar_style(v.native())
862910356 return ToolbarStyle(c)
863010357 }
864710374 return Orientation(c)
864810375 }
864910376
8650 // RetrieveProxyMenuItem is a wrapper around
8651 // gtk_tool_item_retrieve_proxy_menu_item()
10377 // RetrieveProxyMenuItem is a wrapper around gtk_tool_item_retrieve_proxy_menu_item()
865210378 func (v *ToolItem) RetrieveProxyMenuItem() *MenuItem {
865310379 c := C.gtk_tool_item_retrieve_proxy_menu_item(v.native())
865410380 if c == nil {
865610382 }
865710383 return wrapMenuItem(glib.Take(unsafe.Pointer(c)))
865810384 }
10385
10386 // TODO:
10387 // gtk_tool_item_get_proxy_menu_item().
865910388
866010389 // SetProxyMenuItem is a wrapper around gtk_tool_item_set_proxy_menu_item().
866110390 func (v *ToolItem) SetProxyMenuItem(menuItemId string, menuItem IMenuItem) {
867810407 // TODO: gtk_tool_item_get_text_size_group
867910408
868010409 /*
10410 * GtkToolItemGroup
10411 */
10412
10413 // TODO:
10414 // gtk_tool_item_group_get_collapsed().
10415 // gtk_tool_item_group_get_drop_item().
10416 // gtk_tool_item_group_get_ellipsize().
10417 // gtk_tool_item_group_get_item_position().
10418 // gtk_tool_item_group_get_n_items().
10419 // gtk_tool_item_group_get_label().
10420 // gtk_tool_item_group_get_label_widget().
10421 // gtk_tool_item_group_get_nth_item().
10422 // gtk_tool_item_group_get_header_relief().
10423 // gtk_tool_item_group_insert().
10424 // gtk_tool_item_group_new().
10425 // gtk_tool_item_group_set_collapsed().
10426 // gtk_tool_item_group_set_ellipsize().
10427 // gtk_tool_item_group_set_item_position().
10428 // gtk_tool_item_group_set_label().
10429 // gtk_tool_item_group_set_label_widget().
10430 // gtk_tool_item_group_set_header_relief().
10431
10432 /*
10433 * GtkToolPalette
10434 */
10435
10436 // TODO:
10437 // gtk_tool_palette_new().
10438 // gtk_tool_palette_get_exclusive().
10439 // gtk_tool_palette_set_exclusive().
10440 // gtk_tool_palette_get_expand().
10441 // gtk_tool_palette_set_expand().
10442 // gtk_tool_palette_get_group_position().
10443 // gtk_tool_palette_set_group_position().
10444 // gtk_tool_palette_get_icon_size().
10445 // gtk_tool_palette_set_icon_size().
10446 // gtk_tool_palette_unset_icon_size().
10447 // gtk_tool_palette_get_style().
10448 // gtk_tool_palette_set_style().
10449 // gtk_tool_palette_unset_style().
10450 // gtk_tool_palette_add_drag_dest().
10451 // gtk_tool_palette_get_drag_item().
10452 // gtk_tool_palette_get_drag_target_group().
10453 // gtk_tool_palette_get_drag_target_item().
10454 // gtk_tool_palette_get_drop_group().
10455 // gtk_tool_palette_get_drop_item().
10456 // gtk_tool_palette_set_drag_source().
10457 // GtkToolPaletteDragTargets
10458
10459 /*
868110460 * GtkTreeIter
868210461 */
868310462
870410483 }
870510484
870610485 // Copy() is a wrapper around gtk_tree_iter_copy().
10486 //
10487 // Caution: when this method is used together with selection.GetSelectedRows(),
10488 // it might cause random crash issue. See issue #590 and #610.
870710489 func (v *TreeIter) Copy() (*TreeIter, error) {
870810490 c := C.gtk_tree_iter_copy(v.native())
870910491 if c == nil {
872910511 // GtkTreeModel.
873010512 type ITreeModel interface {
873110513 toTreeModel() *C.GtkTreeModel
10514 ToTreeModel() *TreeModel
873210515 }
873310516
873410517 // native returns a pointer to the underlying GObject as a GtkTreeModel.
875410537 }
875510538
875610539 func wrapTreeModel(obj *glib.Object) *TreeModel {
10540 if obj == nil {
10541 return nil
10542 }
10543
875710544 return &TreeModel{obj}
10545 }
10546
10547 // ToTreeModel is a helper getter, e.g.: it returns *gtk.TreeStore/ListStore as a *gtk.TreeModel.
10548 // In other cases, where you have a gtk.ITreeModel, use the type assertion.
10549 func (v *TreeModel) ToTreeModel() *TreeModel {
10550 return v
875810551 }
875910552
876010553 // GetFlags() is a wrapper around gtk_tree_model_get_flags().
882310616 return p, nil
882410617 }
882510618
10619 // GetStringFromIter() is a wrapper around gtk_tree_model_get_string_from_iter().
10620 func (v *TreeModel) GetStringFromIter(iter *TreeIter) string {
10621 c := C.gtk_tree_model_get_string_from_iter(v.native(), iter.native())
10622 s := goString(c)
10623 defer C.g_free((C.gpointer)(c))
10624 return s
10625 }
10626
882610627 // GetValue() is a wrapper around gtk_tree_model_get_value().
882710628 func (v *TreeModel) GetValue(iter *TreeIter, column int) (*glib.Value, error) {
882810629 val, err := glib.ValueAlloc()
883010631 return nil, err
883110632 }
883210633 C.gtk_tree_model_get_value(
8833 (*C.GtkTreeModel)(unsafe.Pointer(v.native())),
10634 v.native(),
883410635 iter.native(),
883510636 C.gint(column),
883610637 (*C.GValue)(unsafe.Pointer(val.Native())))
890010701
890110702 // TreeModelForeachFunc defines the function prototype for the foreach function (f arg) for
890210703 // (* TreeModel).ForEach
8903 type TreeModelForeachFunc func(model *TreeModel, path *TreePath, iter *TreeIter, userData interface{}) bool
8904
8905 type treeModelForeachFuncData struct {
8906 fn TreeModelForeachFunc
8907 userData interface{}
8908 }
8909
8910 var (
8911 treeModelForeachFuncRegistry = struct {
8912 sync.RWMutex
8913 next int
8914 m map[int]treeModelForeachFuncData
8915 }{
8916 next: 1,
8917 m: make(map[int]treeModelForeachFuncData),
8918 }
8919 )
10704 type TreeModelForeachFunc func(model *TreeModel, path *TreePath, iter *TreeIter) bool
892010705
892110706 // ForEach() is a wrapper around gtk_tree_model_foreach ()
8922 func (v *TreeModel) ForEach(f TreeModelForeachFunc, userData ...interface{}) error {
8923 if len(userData) > 1 {
8924 return errors.New("userData len must be 0 or 1")
8925 }
8926
8927 t := treeModelForeachFuncData{fn: f}
8928 if len(userData) > 0 {
8929 t.userData = userData[0]
8930 }
8931 treeModelForeachFuncRegistry.Lock()
8932 id := treeModelForeachFuncRegistry.next
8933 treeModelForeachFuncRegistry.next++
8934 treeModelForeachFuncRegistry.m[id] = t
8935 treeModelForeachFuncRegistry.Unlock()
8936
8937 C._gtk_tree_model_foreach(v.toTreeModel(), C.gpointer(uintptr(id)))
8938 return nil
10707 func (v *TreeModel) ForEach(f TreeModelForeachFunc) {
10708 id := callback.Assign(f)
10709 defer callback.Delete(id)
10710
10711 C._gtk_tree_model_foreach(v.toTreeModel(), C.gpointer(id))
893910712 }
894010713
894110714 /*
897210745 }
897310746
897410747 func wrapTreeModelFilter(obj *glib.Object) *TreeModelFilter {
10748 if obj == nil {
10749 return nil
10750 }
10751
897510752 tm := wrapTreeModel(obj)
897610753 return &TreeModelFilter{obj, *tm}
897710754 }
897910756 // SetVisibleColumn is a wrapper around gtk_tree_model_filter_set_visible_column().
898010757 func (v *TreeModelFilter) SetVisibleColumn(column int) {
898110758 C.gtk_tree_model_filter_set_visible_column(v.native(), C.gint(column))
10759 }
10760
10761 // ConvertChildPathToPath is a wrapper around gtk_tree_model_filter_convert_child_path_to_path().
10762 func (v *TreeModelFilter) ConvertChildPathToPath(childPath *TreePath) *TreePath {
10763 path := C.gtk_tree_model_filter_convert_child_path_to_path(v.native(), childPath.native())
10764 if path == nil {
10765 return nil
10766 }
10767 p := &TreePath{path}
10768 runtime.SetFinalizer(p, (*TreePath).free)
10769 return p
10770 }
10771
10772 // ConvertChildIterToIter is a wrapper around gtk_tree_model_filter_convert_child_iter_to_iter().
10773 func (v *TreeModelFilter) ConvertChildIterToIter(childIter *TreeIter) (*TreeIter, bool) {
10774 var iter C.GtkTreeIter
10775 ok := gobool(C.gtk_tree_model_filter_convert_child_iter_to_iter(v.native(), &iter, childIter.native()))
10776 t := &TreeIter{iter}
10777 return t, ok
898210778 }
898310779
898410780 // ConvertIterToChildIter is a wrapper around gtk_tree_model_filter_convert_child_iter_to_iter().
899510791 if path == nil {
899610792 return nil
899710793 }
8998
899910794 p := &TreePath{path}
900010795 runtime.SetFinalizer(p, (*TreePath).free)
9001
900210796 return p
900310797 }
900410798
900910803
901010804 // TreeModelFilterVisibleFunc defines the function prototype for the filter visibility function (f arg)
901110805 // to TreeModelFilter.SetVisibleFunc.
9012 type TreeModelFilterVisibleFunc func(model *TreeModelFilter, iter *TreeIter, userData interface{}) bool
9013
9014 type treeModelFilterVisibleFuncData struct {
9015 fn TreeModelFilterVisibleFunc
9016 userData interface{}
9017 }
9018
9019 var (
9020 treeModelVisibleFilterFuncRegistry = struct {
9021 sync.RWMutex
9022 next int
9023 m map[int]treeModelFilterVisibleFuncData
9024 }{
9025 next: 1,
9026 m: make(map[int]treeModelFilterVisibleFuncData),
9027 }
9028 )
10806 type TreeModelFilterVisibleFunc func(model *TreeModel, iter *TreeIter) bool
902910807
903010808 // SetVisibleFunc is a wrapper around gtk_tree_model_filter_set_visible_func().
9031 func (v *TreeModelFilter) SetVisibleFunc(f TreeModelFilterVisibleFunc, userData ...interface{}) error {
9032 if len(userData) > 1 {
9033 return errors.New("userData len must be 0 or 1")
9034 }
9035
9036 t := treeModelFilterVisibleFuncData{fn: f}
9037 if len(userData) > 0 {
9038 t.userData = userData[0]
9039 }
9040 treeModelVisibleFilterFuncRegistry.Lock()
9041 id := treeModelVisibleFilterFuncRegistry.next
9042 treeModelVisibleFilterFuncRegistry.next++
9043 treeModelVisibleFilterFuncRegistry.m[id] = t
9044 treeModelVisibleFilterFuncRegistry.Unlock()
9045
9046 C._gtk_tree_model_filter_set_visible_func(v.native(), C.gpointer(uintptr(id)))
9047 return nil
10809 func (v *TreeModelFilter) SetVisibleFunc(f TreeModelFilterVisibleFunc) {
10810 C._gtk_tree_model_filter_set_visible_func(v.native(), C.gpointer(callback.Assign(f)))
904810811 }
904910812
905010813 // Down() is a wrapper around gtk_tree_path_down()
921210975 }
921310976
921410977 func wrapTreeSelection(obj *glib.Object) *TreeSelection {
10978 if obj == nil {
10979 return nil
10980 }
10981
921510982 return &TreeSelection{obj}
921610983 }
921710984
932111088
932211089 // PathIsSelected() is a wrapper around gtk_tree_selection_path_is_selected().
932311090 func (v *TreeSelection) PathIsSelected(path *TreePath) bool {
9324
932511091 return gobool(C.gtk_tree_selection_path_is_selected(v.native(), path.native()))
932611092 }
932711093
932811094 // TreeSelectionForeachFunc defines the function prototype for the selected_foreach function (f arg) for
932911095 // (* TreeSelection).SelectedForEach
9330 type TreeSelectionForeachFunc func(model *TreeModel, path *TreePath, iter *TreeIter, userData interface{})
9331
9332 type treeSelectionForeachFuncData struct {
9333 fn TreeSelectionForeachFunc
9334 userData interface{}
9335 }
9336
9337 var (
9338 treeSelectionForeachFuncRegistry = struct {
9339 sync.RWMutex
9340 next int
9341 m map[int]treeSelectionForeachFuncData
9342 }{
9343 next: 1,
9344 m: make(map[int]treeSelectionForeachFuncData),
9345 }
9346 )
11096 type TreeSelectionForeachFunc func(model *TreeModel, path *TreePath, iter *TreeIter)
934711097
934811098 // SelectedForEach() is a wrapper around gtk_tree_selection_selected_foreach()
9349 func (v *TreeSelection) SelectedForEach(f TreeSelectionForeachFunc, userData ...interface{}) error {
9350 if len(userData) > 1 {
9351 return errors.New("userData len must be 0 or 1")
9352 }
9353
9354 t := treeSelectionForeachFuncData{fn: f}
9355 if len(userData) > 0 {
9356 t.userData = userData[0]
9357 }
9358 treeSelectionForeachFuncRegistry.Lock()
9359 id := treeSelectionForeachFuncRegistry.next
9360 treeSelectionForeachFuncRegistry.next++
9361 treeSelectionForeachFuncRegistry.m[id] = t
9362 treeSelectionForeachFuncRegistry.Unlock()
9363
9364 C._gtk_tree_selection_selected_foreach(v.native(), C.gpointer(uintptr(id)))
9365 return nil
11099 func (v *TreeSelection) SelectedForEach(f TreeSelectionForeachFunc) {
11100 id := callback.Assign(f)
11101 defer callback.Delete(id)
11102
11103 C._gtk_tree_selection_selected_foreach(v.native(), C.gpointer(id))
11104 }
11105
11106 // TreeSelectionFunc defines the function prototype for the gtk_tree_selection_set_select_function
11107 // function (f arg) for (* TreeSelection).SetSelectFunction
11108 type TreeSelectionFunc func(selection *TreeSelection, model *TreeModel, path *TreePath, selected bool) bool
11109
11110 // SetSelectFunction() is a wrapper around gtk_tree_selection_set_select_function()
11111 func (v *TreeSelection) SetSelectFunction(f TreeSelectionFunc) {
11112 C._gtk_tree_selection_set_select_function(v.native(), C.gpointer(callback.Assign(f)))
936611113 }
936711114
936811115 /*
940811155 }
940911156
941011157 // GetModel is a wrapper around gtk_tree_row_reference_get_path.
9411 func (v *TreeRowReference) GetModel() ITreeModel {
11158 func (v *TreeRowReference) GetModel() (ITreeModel, error) {
941211159 c := C.gtk_tree_row_reference_get_model(v.native())
941311160 if c == nil {
9414 return nil
9415 }
9416 m := wrapTreeModel(glib.Take(unsafe.Pointer(c)))
9417 return m
11161 return nil, nilPtrErr
11162 }
11163 return castTreeModel(c)
941811164 }
941911165
942011166 // Valid is a wrapper around gtk_tree_row_reference_valid.
942411170 }
942511171
942611172 /*
11173 * GtkTreeSortable
11174 */
11175
11176 // TreeSortable is a representation of GTK's GtkTreeSortable
11177 type TreeSortable struct {
11178 *glib.Object
11179 }
11180
11181 // ITreeSortable is an interface type implemented by all structs
11182 // embedding a TreeSortable. It is meant to be used as an argument type
11183 // for wrapper functions that wrap around a C GTK function taking a
11184 // GtkTreeSortable.
11185 type ITreeSortable interface {
11186 toTreeSortable() *C.GtkTreeSortable
11187 }
11188
11189 // native returns a pointer to the underlying GtkTreeSortable
11190 func (v *TreeSortable) native() *C.GtkTreeSortable {
11191 if v == nil || v.GObject == nil {
11192 return nil
11193 }
11194 p := unsafe.Pointer(v.GObject)
11195 return C.toGtkTreeSortable(p)
11196 }
11197
11198 func (v *TreeSortable) toTreeSortable() *C.GtkTreeSortable {
11199 if v == nil {
11200 return nil
11201 }
11202 return v.native()
11203 }
11204
11205 func marshalTreeSortable(p uintptr) (interface{}, error) {
11206 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
11207 obj := glib.Take(unsafe.Pointer(c))
11208 return wrapTreeSortable(obj), nil
11209 }
11210
11211 func wrapTreeSortable(obj *glib.Object) *TreeSortable {
11212 if obj == nil {
11213 return nil
11214 }
11215
11216 return &TreeSortable{obj}
11217 }
11218
11219 // TreeIterCompareFunc is a representation of GtkTreeIterCompareFunc.
11220 // It defines the function prototype for the sort function (f arg) for (* TreeSortable).SetSortFunc
11221 type TreeIterCompareFunc func(model *TreeModel, a, b *TreeIter) int
11222
11223 // GetSortColumnId() is a wrapper around gtk_tree_sortable_get_sort_column_id().
11224 func (v *TreeSortable) GetSortColumnId() (int, SortType, bool) {
11225 var column C.gint
11226 var order C.GtkSortType
11227 ok := gobool(C.gtk_tree_sortable_get_sort_column_id(v.native(), &column, &order))
11228 return int(column), SortType(order), ok
11229 }
11230
11231 // SetSortColumnId() is a wrapper around gtk_tree_sortable_set_sort_column_id().
11232 func (v *TreeSortable) SetSortColumnId(column int, order SortType) {
11233 C.gtk_tree_sortable_set_sort_column_id(v.native(), C.gint(column), C.GtkSortType(order))
11234 }
11235
11236 // SetSortFunc() is a wrapper around gtk_tree_sortable_set_sort_func().
11237 func (v *TreeSortable) SetSortFunc(sortColumn int, f TreeIterCompareFunc) {
11238 C._gtk_tree_sortable_set_sort_func(v.native(), C.gint(sortColumn), C.gpointer(callback.Assign(f)))
11239 }
11240
11241 // SetDefaultSortFunc() is a wrapper around gtk_tree_sortable_set_default_sort_func().
11242 func (v *TreeSortable) SetDefaultSortFunc(f TreeIterCompareFunc) {
11243 C._gtk_tree_sortable_set_default_sort_func(v.native(), C.gpointer(callback.Assign(f)))
11244 }
11245
11246 func (v *TreeSortable) HasDefaultSortFunc() bool {
11247 return gobool(C.gtk_tree_sortable_has_default_sort_func(v.native()))
11248 }
11249
11250 /*
11251 * GtkTreeModelSort
11252 */
11253
11254 // TreeModelSort is a representation of GTK's GtkTreeModelSort
11255 type TreeModelSort struct {
11256 *glib.Object
11257
11258 // Interfaces
11259 TreeModel
11260 TreeSortable
11261 }
11262
11263 // native returns a pointer to the underlying GtkTreeModelSort
11264 func (v *TreeModelSort) native() *C.GtkTreeModelSort {
11265 if v == nil || v.GObject == nil {
11266 return nil
11267 }
11268 p := unsafe.Pointer(v.GObject)
11269 return C.toGtkTreeModelSort(p)
11270 }
11271
11272 func marshalTreeModelSort(p uintptr) (interface{}, error) {
11273 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
11274 obj := glib.Take(unsafe.Pointer(c))
11275 return wrapTreeModelSort(obj), nil
11276 }
11277
11278 func wrapTreeModelSort(obj *glib.Object) *TreeModelSort {
11279 if obj == nil {
11280 return nil
11281 }
11282
11283 tm := wrapTreeModel(obj)
11284 ts := wrapTreeSortable(obj)
11285 return &TreeModelSort{obj, *tm, *ts}
11286 }
11287
11288 func (v *TreeModelSort) toTreeModel() *C.GtkTreeModel {
11289 if v == nil {
11290 return nil
11291 }
11292 return C.toGtkTreeModel(unsafe.Pointer(v.GObject))
11293 }
11294
11295 func (v *TreeModelSort) toTreeSortable() *C.GtkTreeSortable {
11296 if v == nil {
11297 return nil
11298 }
11299 return C.toGtkTreeSortable(unsafe.Pointer(v.GObject))
11300 }
11301
11302 // TreeModelSortNew is a wrapper around gtk_tree_model_sort_new_with_model():
11303 func TreeModelSortNew(model ITreeModel) (*TreeModelSort, error) {
11304 var mptr *C.GtkTreeModel
11305 if model != nil {
11306 mptr = model.toTreeModel()
11307 }
11308 c := C.gtk_tree_model_sort_new_with_model(mptr)
11309 if c == nil {
11310 return nil, nilPtrErr
11311 }
11312
11313 tms := wrapTreeModelSort(glib.Take(unsafe.Pointer(c)))
11314 return tms, nil
11315 }
11316
11317 // GetModel is a wrapper around gtk_tree_model_sort_get_model()
11318 func (v *TreeModelSort) GetModel() (ITreeModel, error) {
11319 c := C.gtk_tree_model_sort_get_model(v.native())
11320 if c == nil {
11321 return nil, nilPtrErr
11322 }
11323 return castTreeModel(c)
11324 }
11325
11326 // ConvertChildPathToPath is a wrapper around gtk_tree_model_sort_convert_child_path_to_path().
11327 func (v *TreeModelSort) ConvertChildPathToPath(childPath *TreePath) *TreePath {
11328 path := C.gtk_tree_model_sort_convert_child_path_to_path(v.native(), childPath.native())
11329 if path == nil {
11330 return nil
11331 }
11332 p := &TreePath{path}
11333 runtime.SetFinalizer(p, (*TreePath).free)
11334 return p
11335 }
11336
11337 // ConvertChildIterToIter is a wrapper around gtk_tree_model_sort_convert_child_iter_to_iter().
11338 func (v *TreeModelSort) ConvertChildIterToIter(childIter *TreeIter) (*TreeIter, bool) {
11339 var iter C.GtkTreeIter
11340 ok := gobool(C.gtk_tree_model_sort_convert_child_iter_to_iter(v.native(), &iter, childIter.native()))
11341 t := &TreeIter{iter}
11342 return t, ok
11343 }
11344
11345 // ConvertPathToChildPath is a wrapper around gtk_tree_model_sort_convert_path_to_child_path().
11346 func (v *TreeModelSort) ConvertPathToChildPath(sortPath *TreePath) *TreePath {
11347 path := C.gtk_tree_model_sort_convert_path_to_child_path(v.native(), sortPath.native())
11348 if path == nil {
11349 return nil
11350 }
11351 p := &TreePath{path}
11352 runtime.SetFinalizer(p, (*TreePath).free)
11353 return p
11354 }
11355
11356 // ConvertIterToChildIter is a wrapper around gtk_tree_model_sort_convert_iter_to_child_iter().
11357 func (v *TreeModelSort) ConvertIterToChildIter(sortIter *TreeIter) *TreeIter {
11358 var iter C.GtkTreeIter
11359 C.gtk_tree_model_sort_convert_iter_to_child_iter(v.native(), &iter, sortIter.native())
11360 t := &TreeIter{iter}
11361 return t
11362 }
11363
11364 // ResetDefaultSortFunc is a wrapper around gtk_tree_model_sort_reset_default_sort_func().
11365 func (v *TreeModelSort) ResetDefaultSortFunc() {
11366 C.gtk_tree_model_sort_reset_default_sort_func(v.native())
11367 }
11368
11369 // ClearCache is a wrapper around gtk_tree_model_sort_clear_cache().
11370 func (v *TreeModelSort) ClearCache() {
11371 C.gtk_tree_model_sort_clear_cache(v.native())
11372 }
11373
11374 // IterIsValid is a wrapper around gtk_tree_model_sort_iter_is_valid().
11375 func (v *TreeModelSort) IterIsValid(iter *TreeIter) bool {
11376 return gobool(C.gtk_tree_model_sort_iter_is_valid(v.native(), iter.native()))
11377 }
11378
11379 /*
942711380 * GtkTreeStore
942811381 */
942911382
943311386
943411387 // Interfaces
943511388 TreeModel
11389 TreeSortable
943611390 }
943711391
943811392 // native returns a pointer to the underlying GtkTreeStore.
945111405 }
945211406
945311407 func wrapTreeStore(obj *glib.Object) *TreeStore {
11408 if obj == nil {
11409 return nil
11410 }
11411
945411412 tm := wrapTreeModel(obj)
9455 return &TreeStore{obj, *tm}
11413 ts := wrapTreeSortable(obj)
11414 return &TreeStore{obj, *tm, *ts}
945611415 }
945711416
945811417 func (v *TreeStore) toTreeModel() *C.GtkTreeModel {
946011419 return nil
946111420 }
946211421 return C.toGtkTreeModel(unsafe.Pointer(v.GObject))
11422 }
11423
11424 func (v *TreeStore) toTreeSortable() *C.GtkTreeSortable {
11425 if v == nil {
11426 return nil
11427 }
11428 return C.toGtkTreeSortable(unsafe.Pointer(v.GObject))
946311429 }
946411430
946511431 // TreeStoreNew is a wrapper around gtk_tree_store_newv().
948611452 cParent = parent.native()
948711453 }
948811454 C.gtk_tree_store_append(v.native(), &ti, cParent)
11455 iter := &TreeIter{ti}
11456 return iter
11457 }
11458
11459 // Prepend is a wrapper around gtk_tree_store_prepend().
11460 func (v *TreeStore) Prepend(parent *TreeIter) *TreeIter {
11461 var ti C.GtkTreeIter
11462 var cParent *C.GtkTreeIter
11463 if parent != nil {
11464 cParent = parent.native()
11465 }
11466 C.gtk_tree_store_prepend(v.native(), &ti, cParent)
948911467 iter := &TreeIter{ti}
949011468 return iter
949111469 }
955811536 length = len(inValues)
955911537 }
956011538
9561 var cColumns []C.gint
9562 var cValues []C.GValue
11539 cColumns := make([]C.gint, 0, length)
11540 cValues := make([]C.GValue, 0, length)
11541
956311542 for i := 0; i < length; i++ {
11543
11544 value := inValues[i]
11545 var gvalue *C.GValue
11546
11547 switch value.(type) {
11548 case *gdk.Pixbuf:
11549 pix := value.(*gdk.Pixbuf)
11550
11551 if pix == nil {
11552 continue
11553 }
11554
11555 gvalue = (*C.GValue)(unsafe.Pointer(pix.Native()))
11556
11557 default:
11558 gv, err := glib.GValue(value)
11559 if err != nil {
11560 return err
11561 }
11562 gvalue = (*C.GValue)(C.gpointer(gv.Native()))
11563 }
11564
956411565 cColumns = append(cColumns, C.gint(inColumns[i]))
9565
9566 gv, err := glib.GValue(inValues[i])
9567 if err != nil {
9568 return err
9569 }
9570
9571 var cvp *C.GValue = (*C.GValue)(gv.Native())
9572 cValues = append(cValues, *cvp)
9573 }
9574 var cColumnsPointer *C.gint = &cColumns[0]
9575 var cValuesPointer *C.GValue = &cValues[0]
9576
9577 C.gtk_tree_store_insert_with_valuesv(v.native(), iter.native(), parent.native(), C.gint(position), cColumnsPointer, cValuesPointer, C.gint(length))
11566 cValues = append(cValues, *gvalue)
11567 }
11568
11569 var cColumnsPointer *C.gint
11570 if len(cColumns) > 0 {
11571 cColumnsPointer = &cColumns[0]
11572 }
11573 var cValuesPointer *C.GValue
11574 if len(cValues) > 0 {
11575 cValuesPointer = &cValues[0]
11576 }
11577
11578 C.gtk_tree_store_insert_with_valuesv(v.native(), iter.native(), parent.native(), C.gint(position), cColumnsPointer, cValuesPointer, C.gint(len(cColumns)))
957811579
957911580 return nil
958011581 }
958111582
9582 /*
9583 * TreeSortable
9584 */
9585
9586 // TreeSortable is a representation of GTK's GtkTreeSortable Interface.
9587 type TreeSortable interface {
9588 SetSortColumnId(column int, order SortType)
9589 }
9590
9591 // SetSortColumnId() is a wrapper around gtk_tree_sortable_set_sort_column_id().
9592 func (v *TreeStore) SetSortColumnId(column int, order SortType) {
9593 sort := C.toGtkTreeSortable(unsafe.Pointer(v.Native()))
9594 C.gtk_tree_sortable_set_sort_column_id(sort, C.gint(column), C.GtkSortType(order))
9595 }
9596
9597 // TreeIterCompareFunc defines the function prototype for the sort function (f arg) for
9598 // (* TreeSortable).SetSortFunc
9599 type TreeIterCompareFunc func(model *TreeModel, a, b *TreeIter, userData interface{}) int
9600
9601 type treeStoreSortFuncData struct {
9602 fn TreeIterCompareFunc
9603 userData interface{}
9604 }
9605
9606 var (
9607 treeStoreSortFuncRegistry = struct {
9608 sync.RWMutex
9609 next int
9610 m map[int]treeStoreSortFuncData
9611 }{
9612 next: 1,
9613 m: make(map[int]treeStoreSortFuncData),
9614 }
9615 )
9616
9617 func (v *C.GtkTreeSortable) setSortFunc(sortColumn int, f TreeIterCompareFunc, userData ...interface{}) error {
9618 if len(userData) > 1 {
9619 return errors.New("userData len must be 0 or 1")
9620 }
9621
9622 t := treeStoreSortFuncData{fn: f}
9623 if len(userData) > 0 {
9624 t.userData = userData[0]
9625 }
9626 treeStoreSortFuncRegistry.Lock()
9627 id := treeStoreSortFuncRegistry.next
9628 treeStoreSortFuncRegistry.next++
9629 treeStoreSortFuncRegistry.m[id] = t
9630 treeStoreSortFuncRegistry.Unlock()
9631
9632 C._gtk_tree_sortable_set_sort_func(v, C.gint(sortColumn), C.gpointer(uintptr(id)))
9633 return nil
11583 // MoveBefore is a wrapper around gtk_tree_store_move_before().
11584 func (v *TreeStore) MoveBefore(iter, position *TreeIter) {
11585 C.gtk_tree_store_move_before(v.native(), iter.native(),
11586 position.native())
11587 }
11588
11589 // MoveAfter is a wrapper around gtk_tree_store_move_after().
11590 func (v *TreeStore) MoveAfter(iter, position *TreeIter) {
11591 C.gtk_tree_store_move_after(v.native(), iter.native(),
11592 position.native())
11593 }
11594
11595 // Swap is a wrapper around gtk_tree_store_swap().
11596 func (v *TreeStore) Swap(a, b *TreeIter) {
11597 C.gtk_tree_store_swap(v.native(), a.native(), b.native())
11598 }
11599
11600 // SetColumnTypes is a wrapper around gtk_tree_store_set_column_types().
11601 // The size of glib.Type must match the number of columns
11602 func (v *TreeStore) SetColumnTypes(types ...glib.Type) {
11603 gtypes := C.alloc_types(C.int(len(types)))
11604 for n, val := range types {
11605 C.set_type(gtypes, C.int(n), C.GType(val))
11606 }
11607 defer C.g_free(C.gpointer(gtypes))
11608 C.gtk_tree_store_set_column_types(v.native(), C.gint(len(types)), gtypes)
963411609 }
963511610
963611611 /*
966311638 }
966411639
966511640 func wrapViewport(obj *glib.Object) *Viewport {
11641 if obj == nil {
11642 return nil
11643 }
11644
966611645 b := wrapBin(obj)
966711646 s := wrapScrollable(obj)
966811647 return &Viewport{
968711666 return wrapViewport(glib.Take(unsafe.Pointer(c))), nil
968811667 }
968911668
9690 func (v *Viewport) SetHAdjustment(adjustment *Adjustment) {
9691 wrapScrollable(v.Object).SetHAdjustment(adjustment)
9692 }
9693
9694 func (v *Viewport) GetHAdjustment() (*Adjustment, error) {
9695 return wrapScrollable(v.Object).GetHAdjustment()
9696 }
9697
9698 func (v *Viewport) SetVAdjustment(adjustment *Adjustment) {
9699 wrapScrollable(v.Object).SetVAdjustment(adjustment)
9700 }
9701
9702 func (v *Viewport) GetVAdjustment() (*Adjustment, error) {
9703 return wrapScrollable(v.Object).GetVAdjustment()
11669 // SetShadowType is a wrapper around gtk_viewport_set_shadow_type().
11670 func (v *Viewport) SetShadowType(shadowType ShadowType) {
11671 C.gtk_viewport_set_shadow_type(v.native(), C.GtkShadowType(shadowType))
11672 }
11673
11674 // GetShadowType is a wrapper around gtk_viewport_get_shadow_type().
11675 func (v *Viewport) GetShadowType() ShadowType {
11676 c := C.gtk_viewport_get_shadow_type(v.native())
11677 return ShadowType(c)
11678 }
11679
11680 // GetBinWindow is a wrapper around gtk_viewport_get_bin_window().
11681 func (v *Viewport) GetBinWindow() *gdk.Window {
11682 c := C.gtk_viewport_get_bin_window(v.native())
11683 if c == nil {
11684 return nil
11685 }
11686 return &gdk.Window{glib.Take(unsafe.Pointer(c))}
11687 }
11688
11689 // GetViewWindow is a wrapper around gtk_viewport_get_view_window().
11690 func (v *Viewport) GetViewWindow() *gdk.Window {
11691 c := C.gtk_viewport_get_view_window(v.native())
11692 if c == nil {
11693 return nil
11694 }
11695 return &gdk.Window{glib.Take(unsafe.Pointer(c))}
970411696 }
970511697
970611698 /*
972811720 }
972911721
973011722 func wrapVolumeButton(obj *glib.Object) *VolumeButton {
11723 if obj == nil {
11724 return nil
11725 }
11726
973111727 actionable := wrapActionable(obj)
973211728 return &VolumeButton{ScaleButton{Button{Bin{Container{Widget{glib.InitiallyUnowned{obj}}}}, actionable}}}
973311729 }
973411730
9735 // VolumeButtonNew() is a wrapper around gtk_button_new().
11731 // VolumeButtonNew is a wrapper around gtk_volume_button_new().
973611732 func VolumeButtonNew() (*VolumeButton, error) {
973711733 c := C.gtk_volume_button_new()
973811734 if c == nil {
975211748 "GtkBin": wrapBin,
975311749 "GtkBox": wrapBox,
975411750 "GtkButton": wrapButton,
11751 "GtkButtonBox": wrapButtonBox,
975511752 "GtkCalendar": wrapCalendar,
975611753 "GtkCellLayout": wrapCellLayout,
11754 "GtkCellEditable": wrapCellEditable,
975711755 "GtkCellRenderer": wrapCellRenderer,
975811756 "GtkCellRendererSpinner": wrapCellRendererSpinner,
975911757 "GtkCellRendererPixbuf": wrapCellRendererPixbuf,
976011758 "GtkCellRendererText": wrapCellRendererText,
976111759 "GtkCellRendererProgress": wrapCellRendererProgress,
976211760 "GtkCellRendererToggle": wrapCellRendererToggle,
11761 "GtkCellRendererCombo": wrapCellRendererCombo,
11762 "GtkCellRendererAccel": wrapCellRendererAccel,
11763 "GtkCellRendererSpin": wrapCellRendererSpin,
976311764 "GtkCheckButton": wrapCheckButton,
976411765 "GtkCheckMenuItem": wrapCheckMenuItem,
976511766 "GtkClipboard": wrapClipboard,
981711818 "GtkSpinner": wrapSpinner,
981811819 "GtkStatusbar": wrapStatusbar,
981911820 "GtkSwitch": wrapSwitch,
9820 "GtkTextView": wrapTextView,
982111821 "GtkTextBuffer": wrapTextBuffer,
11822 "GtkTextChildAnchor": wrapTextChildAnchor,
982211823 "GtkTextTag": wrapTextTag,
982311824 "GtkTextTagTable": wrapTextTagTable,
11825 "GtkTextView": wrapTextView,
982411826 "GtkToggleButton": wrapToggleButton,
982511827 "GtkToolbar": wrapToolbar,
982611828 "GtkToolButton": wrapToolButton,
982811830 "GtkToolItem": wrapToolItem,
982911831 "GtkTreeModel": wrapTreeModel,
983011832 "GtkTreeModelFilter": wrapTreeModelFilter,
11833 "GtkTreeModelSort": wrapTreeModelSort,
983111834 "GtkTreeSelection": wrapTreeSelection,
983211835 "GtkTreeStore": wrapTreeStore,
983311836 "GtkTreeView": wrapTreeView,
983811841 "GtkWindow": wrapWindow,
983911842 }
984011843
9841 // cast takes a native GObject and casts it to the appropriate Go struct.
9842 //TODO change all wrapFns to return an IObject
9843 func cast(c *C.GObject) (glib.IObject, error) {
9844 var (
9845 className = goString(C.object_get_class_name(c))
9846 obj = glib.Take(unsafe.Pointer(c))
9847 )
9848
11844 // castInternal casts the given object to the appropriate Go struct, but returns it as interface for later type assertions.
11845 // The className is the results of C.object_get_class_name(c) called on the native object.
11846 // The obj is the result of glib.Take(unsafe.Pointer(c)), used as a parameter for the wrapper functions.
11847 func castInternal(className string, obj *glib.Object) (interface{}, error) {
984911848 fn, ok := WrapMap[className]
985011849 if !ok {
9851 return nil, errors.New("unrecognized class name '" + className + "'")
9852 }
9853
11850 fn, ok = glib.WrapMap[className]
11851 if !ok {
11852 return nil, errors.New("unrecognized class name '" + className + "'")
11853 }
11854 }
11855
11856 // Check that the wrapper function is actually a function
985411857 rf := reflect.ValueOf(fn)
985511858 if rf.Type().Kind() != reflect.Func {
985611859 return nil, errors.New("wraper is not a function")
985711860 }
985811861
11862 // Call the wraper function with the *glib.Object as first parameter
11863 // e.g. "wrapWindow(obj)"
985911864 v := reflect.ValueOf(obj)
986011865 rv := rf.Call([]reflect.Value{v})
986111866
11867 // At most/max 1 return value
986211868 if len(rv) != 1 {
986311869 return nil, errors.New("wrapper did not return")
986411870 }
986511871
11872 // Needs to be a pointer of some sort
986611873 if k := rv[0].Kind(); k != reflect.Ptr {
986711874 return nil, fmt.Errorf("wrong return type %s", k)
986811875 }
986911876
9870 ret, ok := rv[0].Interface().(glib.IObject)
11877 // Only get an interface value, type check will be done in more specific functions
11878 return rv[0].Interface(), nil
11879 }
11880
11881 // cast takes a native GObject and casts it to the appropriate Go struct.
11882 //TODO change all wrapFns to return an IObject
11883 //^- not sure about this TODO. This may make some usages of the wrapper functions quite verbose, no?
11884 func cast(c *C.GObject) (glib.IObject, error) {
11885 ptr := unsafe.Pointer(c)
11886 var (
11887 className = goString(C.object_get_class_name(C.toGObject(ptr)))
11888 obj = glib.Take(ptr)
11889 )
11890
11891 intf, err := castInternal(className, obj)
11892 if err != nil {
11893 return nil, err
11894 }
11895
11896 ret, ok := intf.(glib.IObject)
987111897 if !ok {
987211898 return nil, errors.New("did not return an IObject")
987311899 }
987411900
987511901 return ret, nil
987611902 }
11903
11904 // castWidget takes a native GtkWidget and casts it to the appropriate Go struct.
11905 func castWidget(c *C.GtkWidget) (IWidget, error) {
11906 ptr := unsafe.Pointer(c)
11907 var (
11908 className = goString(C.object_get_class_name(C.toGObject(ptr)))
11909 obj = glib.Take(ptr)
11910 )
11911
11912 intf, err := castInternal(className, obj)
11913 if err != nil {
11914 return nil, err
11915 }
11916
11917 ret, ok := intf.(IWidget)
11918 if !ok {
11919 return nil, fmt.Errorf("expected value of type IWidget, got %T", intf)
11920 }
11921
11922 return ret, nil
11923 }
11924
11925 // castCellRenderer takes a native GtkCellRenderer and casts it to the appropriate Go struct.
11926 func castCellRenderer(c *C.GtkCellRenderer) (ICellRenderer, error) {
11927 ptr := unsafe.Pointer(c)
11928 var (
11929 className = goString(C.object_get_class_name(C.toGObject(ptr)))
11930 obj = glib.Take(ptr)
11931 )
11932
11933 intf, err := castInternal(className, obj)
11934 if err != nil {
11935 return nil, err
11936 }
11937
11938 ret, ok := intf.(ICellRenderer)
11939 if !ok {
11940 return nil, fmt.Errorf("expected value of type ICellRenderer, got %T", intf)
11941 }
11942
11943 return ret, nil
11944 }
11945
11946 // castTreeModel takes a native GtkCellTreeModel and casts it to the appropriate Go struct.
11947 func castTreeModel(c *C.GtkTreeModel) (ITreeModel, error) {
11948 ptr := unsafe.Pointer(c)
11949 var (
11950 className = goString(C.object_get_class_name(C.toGObject(ptr)))
11951 obj = glib.Take(ptr)
11952 )
11953
11954 intf, err := castInternal(className, obj)
11955 if err != nil {
11956 return nil, err
11957 }
11958
11959 ret, ok := intf.(ITreeModel)
11960 if !ok {
11961 return nil, fmt.Errorf("expected value of type ITreeModel, got %T", intf)
11962 }
11963
11964 return ret, nil
11965 }
11966
11967 // castCellEditable takes a native GtkCellEditable and casts it to the appropriate Go struct.
11968 func castCellEditable(c *C.GtkCellEditable) (ICellEditable, error) {
11969 ptr := unsafe.Pointer(c)
11970 var (
11971 className = goString(C.object_get_class_name(C.toGObject(ptr)))
11972 obj = glib.Take(ptr)
11973 )
11974
11975 intf, err := castInternal(className, obj)
11976 if err != nil {
11977 return nil, err
11978 }
11979
11980 ret, ok := intf.(ICellEditable)
11981 if !ok {
11982 return nil, fmt.Errorf("expected value of type ICellEditable, got %T", intf)
11983 }
11984
11985 return ret, nil
11986 }
2121 #include <stdlib.h>
2222 #include <string.h>
2323
24 static GtkAboutDialog *
25 toGtkAboutDialog(void *p)
26 {
27 return (GTK_ABOUT_DIALOG(p));
28 }
29
30 static GtkAppChooser *
31 toGtkAppChooser(void *p)
32 {
33 return (GTK_APP_CHOOSER(p));
34 }
35
36 static GtkAppChooserButton *
37 toGtkAppChooserButton(void *p)
38 {
39 return (GTK_APP_CHOOSER_BUTTON(p));
40 }
41
42 static GtkAppChooserDialog *
43 toGtkAppChooserDialog(void *p)
44 {
45 return (GTK_APP_CHOOSER_DIALOG(p));
46 }
47
48 static GtkAppChooserWidget *
49 toGtkAppChooserWidget(void *p)
50 {
51 return (GTK_APP_CHOOSER_WIDGET(p));
52 }
53
54 static GtkApplication *
55 toGtkApplication(void *p)
56 {
57 return (GTK_APPLICATION(p));
58 }
59
60 static GtkApplicationWindow *
61 toGtkApplicationWindow(void *p)
62 {
63 return (GTK_APPLICATION_WINDOW(p));
64 }
65
66 static GtkAssistant *
67 toGtkAssistant(void *p)
68 {
69 return (GTK_ASSISTANT(p));
70 }
71
72 static GtkCalendar *
73 toGtkCalendar(void *p)
74 {
75 return (GTK_CALENDAR(p));
76 }
77
78 static GtkColorChooserDialog *
79 toGtkColorChooserDialog(void *p)
80 {
81 return (GTK_COLOR_CHOOSER_DIALOG(p));
82 }
83
84 static GtkDrawingArea *
85 toGtkDrawingArea(void *p)
86 {
87 return (GTK_DRAWING_AREA(p));
88 }
89
90 static GtkCellRendererSpinner *
91 toGtkCellRendererSpinner(void *p)
92 {
93 return (GTK_CELL_RENDERER_SPINNER(p));
94 }
95
96 static GtkEventBox *
97 toGtkEventBox(void *p)
98 {
99 return (GTK_EVENT_BOX(p));
100 }
101
102 static GtkGrid *
103 toGtkGrid(void *p)
104 {
105 return (GTK_GRID(p));
106 }
107
108 static GtkWidget *
109 toGtkWidget(void *p)
110 {
111 return (GTK_WIDGET(p));
112 }
113
114 static GtkContainer *
115 toGtkContainer(void *p)
116 {
117 return (GTK_CONTAINER(p));
118 }
119
120 static GtkOverlay *
121 toGtkOverlay(void *p)
122 {
123 return (GTK_OVERLAY(p));
124 }
125
126 static GtkPageSetup *
127 toGtkPageSetup(void *p)
128 {
129 return (GTK_PAGE_SETUP(p));
130 }
131
132 static GtkPaned *
133 toGtkPaned(void *p)
134 {
135 return (GTK_PANED(p));
136 }
137
138 static GtkPrintContext *
139 toGtkPrintContext(void *p)
140 {
141 return (GTK_PRINT_CONTEXT(p));
142 }
143
144 static GtkPrintOperation *
145 toGtkPrintOperation(void *p)
146 {
147 return (GTK_PRINT_OPERATION(p));
148 }
149
150 static GtkPrintOperationPreview *
151 toGtkPrintOperationPreview(void *p)
152 {
153 return (GTK_PRINT_OPERATION_PREVIEW(p));
154 }
155
156 static GtkPrintSettings *
157 toGtkPrintSettings(void *p)
158 {
159 return (GTK_PRINT_SETTINGS(p));
160 }
161
162 static GtkProgressBar *
163 toGtkProgressBar(void *p)
164 {
165 return (GTK_PROGRESS_BAR(p));
166 }
167
168 static GtkLevelBar *
169 toGtkLevelBar(void *p)
170 {
171 return (GTK_LEVEL_BAR(p));
172 }
173
174 static GtkBin *
175 toGtkBin(void *p)
176 {
177 return (GTK_BIN(p));
178 }
179
180 static GtkWindow *
181 toGtkWindow(void *p)
182 {
183 return (GTK_WINDOW(p));
184 }
185
186 static GtkBox *
187 toGtkBox(void *p)
188 {
189 return (GTK_BOX(p));
190 }
191
192 static GtkStatusbar *
193 toGtkStatusbar(void *p)
194 {
195 return (GTK_STATUSBAR(p));
196 }
197
198 static GtkLabel *
199 toGtkLabel(void *p)
200 {
201 return (GTK_LABEL(p));
202 }
203
204 static GtkNotebook *
205 toGtkNotebook(void *p)
206 {
207 return (GTK_NOTEBOOK(p));
208 }
209
210 static GtkEntry *
211 toGtkEntry(void *p)
212 {
213 return (GTK_ENTRY(p));
214 }
215
216 static GtkEntryBuffer *
217 toGtkEntryBuffer(void *p)
218 {
219 return (GTK_ENTRY_BUFFER(p));
220 }
221
222 static GtkEntryCompletion *
223 toGtkEntryCompletion(void *p)
224 {
225 return (GTK_ENTRY_COMPLETION(p));
226 }
227
228 static GtkAdjustment *
229 toGtkAdjustment(void *p)
230 {
231 return (GTK_ADJUSTMENT(p));
232 }
233
234 static GtkAccelGroup *
235 toGtkAccelGroup(void *p)
236 {
237 return (GTK_ACCEL_GROUP(p));
238 }
239
240 static GtkAccelMap *
241 toGtkAccelMap(void *p)
242 {
243 return (GTK_ACCEL_MAP(p));
244 }
245
246 static GtkTextTag *
247 toGtkTextTag(void *p)
248 {
249 return (GTK_TEXT_TAG(p));
250 }
251
252 static GtkIconView *
253 toGtkIconView(void *p)
254 {
255 return (GTK_ICON_VIEW(p));
256 }
257
258 static GtkImage *
259 toGtkImage(void *p)
260 {
261 return (GTK_IMAGE(p));
262 }
263
264 static GtkButtonBox *
265 toGtkButtonBox(void *p)
266 {
267 return (GTK_BUTTON_BOX(p));
268 }
269
270 static GtkButton *
271 toGtkButton(void *p)
272 {
273 return (GTK_BUTTON(p));
274 }
275
276 static GtkScaleButton *
277 toGtkScaleButton(void *p)
278 {
279 return (GTK_SCALE_BUTTON(p));
280 }
281
282 static GtkColorButton *
283 toGtkColorButton(void *p)
284 {
285 return (GTK_COLOR_BUTTON(p));
286 }
287
288 static GtkViewport *
289 toGtkViewport(void *p)
290 {
291 return (GTK_VIEWPORT(p));
292 }
293
294 static GtkVolumeButton *
295 toGtkVolumeButton(void *p)
296 {
297 return (GTK_VOLUME_BUTTON(p));
298 }
299
300 static GtkScrollable *
301 toGtkScrollable(void *p)
302 {
303 return (GTK_SCROLLABLE(p));
304 }
305
306 static GtkScrolledWindow *
307 toGtkScrolledWindow(void *p)
308 {
309 return (GTK_SCROLLED_WINDOW(p));
310 }
311
312 static GtkMenuItem *
313 toGtkMenuItem(void *p)
314 {
315 return (GTK_MENU_ITEM(p));
316 }
317
318 static GtkMenu *
319 toGtkMenu(void *p)
320 {
321 return (GTK_MENU(p));
322 }
323
324 static GtkMenuShell *
325 toGtkMenuShell(void *p)
326 {
327 return (GTK_MENU_SHELL(p));
328 }
329
330 static GtkMenuBar *
331 toGtkMenuBar(void *p)
332 {
333 return (GTK_MENU_BAR(p));
334 }
335
336 static GtkSizeGroup *
337 toGtkSizeGroup(void *p)
338 {
339 return (GTK_SIZE_GROUP(p));
340 }
341
342 static GtkSpinButton *
343 toGtkSpinButton(void *p)
344 {
345 return (GTK_SPIN_BUTTON(p));
346 }
347
348 static GtkSpinner *
349 toGtkSpinner(void *p)
350 {
351 return (GTK_SPINNER(p));
352 }
353
354 static GtkComboBox *
355 toGtkComboBox(void *p)
356 {
357 return (GTK_COMBO_BOX(p));
358 }
359
360 static GtkComboBoxText *
361 toGtkComboBoxText(void *p)
362 {
363 return (GTK_COMBO_BOX_TEXT(p));
364 }
365
366 static GtkLinkButton *
367 toGtkLinkButton(void *p)
368 {
369 return (GTK_LINK_BUTTON(p));
370 }
371
372 static GtkLayout *
373 toGtkLayout(void *p)
374 {
375 return (GTK_LAYOUT(p));
376 }
377
378 static GtkListStore *
379 toGtkListStore(void *p)
380 {
381 return (GTK_LIST_STORE(p));
382 }
383
384 static GtkSwitch *
385 toGtkSwitch(void *p)
386 {
387 return (GTK_SWITCH(p));
388 }
389
390 static GtkTextView *
391 toGtkTextView(void *p)
392 {
393 return (GTK_TEXT_VIEW(p));
394 }
395
396 static GtkTextTagTable *
397 toGtkTextTagTable(void *p)
398 {
399 return (GTK_TEXT_TAG_TABLE(p));
400 }
401
402 static GtkTextBuffer *
403 toGtkTextBuffer(void *p)
404 {
405 return (GTK_TEXT_BUFFER(p));
406 }
407
408 static GtkTreeModel *
409 toGtkTreeModel(void *p)
410 {
411 return (GTK_TREE_MODEL(p));
412 }
413
414 static GtkTreeModelFilter *
415 toGtkTreeModelFilter(void *p)
416 {
417 return (GTK_TREE_MODEL_FILTER(p));
418 }
419
420 static GtkCellRenderer *
421 toGtkCellRenderer(void *p)
422 {
423 return (GTK_CELL_RENDERER(p));
424 }
425
426 static GtkCellRendererPixbuf *
427 toGtkCellRendererPixbuf(void *p)
428 {
429 return (GTK_CELL_RENDERER_PIXBUF(p));
430 }
431
432 static GtkCellRendererProgress *
433 toGtkCellRendererProgress(void *p)
434 {
435 return (GTK_CELL_RENDERER_PROGRESS(p));
436 }
437
438 static GtkCellRendererText *
439 toGtkCellRendererText(void *p)
440 {
441 return (GTK_CELL_RENDERER_TEXT(p));
442 }
443
444 static GtkCellRendererToggle *
445 toGtkCellRendererToggle(void *p)
446 {
447 return (GTK_CELL_RENDERER_TOGGLE(p));
448 }
449
450 static GtkCellLayout *
451 toGtkCellLayout(void *p)
452 {
453 return (GTK_CELL_LAYOUT(p));
454 }
455
456 static GtkOrientable *
457 toGtkOrientable(void *p)
458 {
459 return (GTK_ORIENTABLE(p));
460 }
461
462 static GtkTreeStore *
463 toGtkTreeStore (void *p)
464 {
465 return (GTK_TREE_STORE(p));
466 }
467
468 static GtkTreeView *
469 toGtkTreeView(void *p)
470 {
471 return (GTK_TREE_VIEW(p));
472 }
473
474 static GtkTreeViewColumn *
475 toGtkTreeViewColumn(void *p)
476 {
477 return (GTK_TREE_VIEW_COLUMN(p));
478 }
479
480 static GtkTreeSelection *
481 toGtkTreeSelection(void *p)
482 {
483 return (GTK_TREE_SELECTION(p));
484 }
485
486 static GtkTreeSortable *
487 toGtkTreeSortable(void *p)
488 {
489 return (GTK_TREE_SORTABLE(p));
490 }
491
492 static GtkClipboard *
493 toGtkClipboard(void *p)
494 {
495 return (GTK_CLIPBOARD(p));
496 }
497
498 static GtkDialog *
499 toGtkDialog(void *p)
500 {
501 return (GTK_DIALOG(p));
502 }
503
504 static GtkMessageDialog *
505 toGtkMessageDialog(void *p)
506 {
507 return (GTK_MESSAGE_DIALOG(p));
508 }
509
510 static GtkBuilder *
511 toGtkBuilder(void *p)
512 {
513 return (GTK_BUILDER(p));
514 }
515
516 static GtkSeparatorMenuItem *
517 toGtkSeparatorMenuItem(void *p)
518 {
519 return (GTK_SEPARATOR_MENU_ITEM(p));
520 }
521
522 static GtkCheckButton *
523 toGtkCheckButton(void *p)
524 {
525 return (GTK_CHECK_BUTTON(p));
526 }
527
528 static GtkToggleButton *
529 toGtkToggleButton(void *p)
530 {
531 return (GTK_TOGGLE_BUTTON(p));
532 }
533
534 static GtkFontButton *
535 toGtkFontButton(void *p)
536 {
537 return (GTK_FONT_BUTTON(p));
538 }
539
540 static GtkFrame *
541 toGtkFrame(void *p)
542 {
543 return (GTK_FRAME(p));
544 }
545
546 static GtkAspectFrame *
547 toGtkAspectFrame(void *p)
548 {
549 return (GTK_ASPECT_FRAME(p));
550 }
551
552 static GtkSeparator *
553 toGtkSeparator(void *p)
554 {
555 return (GTK_SEPARATOR(p));
556 }
557
558 static GtkScale*
559 toGtkScale(void *p)
560 {
561 return (GTK_SCALE(p));
562 }
563
564 static GtkScrollbar *
565 toGtkScrollbar(void *p)
566 {
567 return (GTK_SCROLLBAR(p));
568 }
569
570 static GtkRange *
571 toGtkRange(void *p)
572 {
573 return (GTK_RANGE(p));
574 }
575
576 static GtkSearchEntry *
577 toGtkSearchEntry(void *p)
578 {
579 return (GTK_SEARCH_ENTRY(p));
580 }
581
582 static GtkOffscreenWindow *
583 toGtkOffscreenWindow(void *p)
584 {
585 return (GTK_OFFSCREEN_WINDOW(p));
586 }
587
588 static GtkExpander *
589 toGtkExpander(void *p)
590 {
591 return (GTK_EXPANDER(p));
592 }
593
594 static GtkFileChooser *
595 toGtkFileChooser(void *p)
596 {
597 return (GTK_FILE_CHOOSER(p));
598 }
599
600 static GtkFileChooserButton *
601 toGtkFileChooserButton(void *p)
602 {
603 return (GTK_FILE_CHOOSER_BUTTON(p));
604 }
605
606 static GtkFileChooserDialog *
607 toGtkFileChooserDialog(void *p)
608 {
609 return (GTK_FILE_CHOOSER_DIALOG(p));
610 }
611
612 static GtkFileChooserWidget *
613 toGtkFileChooserWidget(void *p)
614 {
615 return (GTK_FILE_CHOOSER_WIDGET(p));
616 }
617
618 static GtkFileFilter *
619 toGtkFileFilter(void *p)
620 {
621 return (GTK_FILE_FILTER(p));
622 }
623
624 static GtkMenuButton *
625 toGtkMenuButton(void *p)
626 {
627 return (GTK_MENU_BUTTON(p));
628 }
629
630 static GtkRadioButton *
631 toGtkRadioButton(void *p)
632 {
633 return (GTK_RADIO_BUTTON(p));
634 }
635
636 static GtkRecentChooser *
637 toGtkRecentChooser(void *p)
638 {
639 return (GTK_RECENT_CHOOSER(p));
640 }
641
642 static GtkRecentChooserMenu *
643 toGtkRecentChooserMenu(void *p)
644 {
645 return (GTK_RECENT_CHOOSER_MENU(p));
646 }
647
648 static GtkColorChooser *
649 toGtkColorChooser(void *p)
650 {
651 return (GTK_COLOR_CHOOSER(p));
652 }
653
654 static GtkFontChooser *
655 toGtkFontChooser(void *p)
656 {
657 return (GTK_FONT_CHOOSER(p));
658 }
659
660 static GtkRecentFilter *
661 toGtkRecentFilter(void *p)
662 {
663 return (GTK_RECENT_FILTER(p));
664 }
665
666 static GtkRecentManager *
667 toGtkRecentManager(void *p)
668 {
669 return (GTK_RECENT_MANAGER(p));
670 }
671
672 static GtkCheckMenuItem *
673 toGtkCheckMenuItem(void *p)
674 {
675 return (GTK_CHECK_MENU_ITEM(p));
676 }
677
678 static GtkRadioMenuItem *
679 toGtkRadioMenuItem(void *p)
680 {
681 return (GTK_RADIO_MENU_ITEM(p));
682 }
683
684 static GtkToolItem *
685 toGtkToolItem(void *p)
686 {
687 return (GTK_TOOL_ITEM(p));
688 }
689
690 static GtkToolbar *
691 toGtkToolbar(void *p)
692 {
693 return (GTK_TOOLBAR(p));
694 }
695
696 static GtkTooltip *
697 toGtkTooltip(void *p)
698 {
699 return (GTK_TOOLTIP(p));
700 }
701
702 static GtkEditable *
703 toGtkEditable(void *p)
704 {
705 return (GTK_EDITABLE(p));
706 }
707
708 static GtkToolButton *
709 toGtkToolButton(void *p)
710 {
711 return (GTK_TOOL_BUTTON(p));
712 }
713
714 static GtkToggleToolButton *
715 toGtkToggleToolButton(void *p)
716 {
717 return (GTK_TOGGLE_TOOL_BUTTON(p));
718 }
719
720 static GtkSeparatorToolItem *
721 toGtkSeparatorToolItem(void *p)
722 {
723 return (GTK_SEPARATOR_TOOL_ITEM(p));
724 }
725
726 static GtkCssProvider *
727 toGtkCssProvider(void *p)
728 {
729 return (GTK_CSS_PROVIDER(p));
730 }
731
732 static GtkStyleContext *
733 toGtkStyleContext(void *p)
734 {
735 return (GTK_STYLE_CONTEXT(p));
736 }
737
738 static GtkStyleProvider *
739 toGtkStyleProvider(void *p)
740 {
741 return (GTK_STYLE_PROVIDER(p));
742 }
743
744 static GtkInfoBar *
745 toGtkInfoBar(void *p)
746 {
747 return (GTK_INFO_BAR(p));
748 }
749
750 static GMenuModel *
751 toGMenuModel(void *p)
752 {
753 return (G_MENU_MODEL(p));
754 }
755
756 static GActionGroup *
757 toGActionGroup(void *p)
758 {
759 return (G_ACTION_GROUP(p));
760 }
761
762 static GdkPixbuf *
763 toGdkPixbuf(void *p)
764 {
765 return (GDK_PIXBUF(p));
766 }
767
768 static GType *
769 alloc_types(int n) {
770 return ((GType *)g_new0(GType, n));
771 }
772
773 static void
774 set_type(GType *types, int n, GType t)
775 {
776 types[n] = t;
777 }
778
779 static GtkTreeViewColumn *
780 _gtk_tree_view_column_new_with_attributes_one(const gchar *title,
781 GtkCellRenderer *renderer, const gchar *attribute, gint column)
782 {
783 GtkTreeViewColumn *tvc;
784
785 tvc = gtk_tree_view_column_new_with_attributes(title, renderer,
786 attribute, column, NULL);
787 return (tvc);
788 }
789
790 static void
791 _gtk_list_store_set(GtkListStore *list_store, GtkTreeIter *iter, gint column,
792 void* value)
793 {
794 gtk_list_store_set(list_store, iter, column, value, -1);
795 }
796
797 static void
798 _gtk_tree_store_set(GtkTreeStore *store, GtkTreeIter *iter, gint column,
799 void* value)
800 {
801 gtk_tree_store_set(store, iter, column, value, -1);
802 }
803
804 extern gboolean substring_match_equal_func(GtkTreeModel *model,
805 gint column,
806 gchar *key,
807 GtkTreeIter *iter,
808 gpointer data);
809
810 static GtkWidget *
811 _gtk_message_dialog_new(GtkWindow *parent, GtkDialogFlags flags,
812 GtkMessageType type, GtkButtonsType buttons, char *msg)
813 {
814 GtkWidget *w;
815
816 w = gtk_message_dialog_new(parent, flags, type, buttons, "%s", msg);
817 return (w);
818 }
819
820 static GtkWidget *
821 _gtk_message_dialog_new_with_markup(GtkWindow *parent, GtkDialogFlags flags,
822 GtkMessageType type, GtkButtonsType buttons, char *msg)
823 {
824 GtkWidget *w;
825
826 w = gtk_message_dialog_new_with_markup(parent, flags, type, buttons,
827 "%s", msg);
828 return (w);
24 // gotk3_callbackDelete satisfies the GDestroyNotify type.
25 extern void gotk3_callbackDelete(gpointer callback_id);
26
27 static GtkAboutDialog *toGtkAboutDialog(void *p) {
28 return (GTK_ABOUT_DIALOG(p));
29 }
30
31 static GtkAppChooser *toGtkAppChooser(void *p) { return (GTK_APP_CHOOSER(p)); }
32
33 static GtkAppChooserButton *toGtkAppChooserButton(void *p) {
34 return (GTK_APP_CHOOSER_BUTTON(p));
35 }
36
37 static GtkAppChooserDialog *toGtkAppChooserDialog(void *p) {
38 return (GTK_APP_CHOOSER_DIALOG(p));
39 }
40
41 static GtkAppChooserWidget *toGtkAppChooserWidget(void *p) {
42 return (GTK_APP_CHOOSER_WIDGET(p));
43 }
44
45 static GtkApplication *toGtkApplication(void *p) {
46 return (GTK_APPLICATION(p));
47 }
48
49 static GtkApplicationWindow *toGtkApplicationWindow(void *p) {
50 return (GTK_APPLICATION_WINDOW(p));
51 }
52
53 static GtkAssistant *toGtkAssistant(void *p) { return (GTK_ASSISTANT(p)); }
54
55 static GtkCalendar *toGtkCalendar(void *p) { return (GTK_CALENDAR(p)); }
56
57 static GtkColorChooserDialog *toGtkColorChooserDialog(void *p) {
58 return (GTK_COLOR_CHOOSER_DIALOG(p));
59 }
60
61 static GtkDrawingArea *toGtkDrawingArea(void *p) {
62 return (GTK_DRAWING_AREA(p));
63 }
64
65 static GtkCellRendererSpinner *toGtkCellRendererSpinner(void *p) {
66 return (GTK_CELL_RENDERER_SPINNER(p));
67 }
68
69 static GtkEventBox *toGtkEventBox(void *p) { return (GTK_EVENT_BOX(p)); }
70
71 static GtkGrid *toGtkGrid(void *p) { return (GTK_GRID(p)); }
72
73 static GtkWidget *toGtkWidget(void *p) { return (GTK_WIDGET(p)); }
74
75 static GtkContainer *toGtkContainer(void *p) { return (GTK_CONTAINER(p)); }
76
77 static GtkOverlay *toGtkOverlay(void *p) { return (GTK_OVERLAY(p)); }
78
79 static GtkPageSetup *toGtkPageSetup(void *p) { return (GTK_PAGE_SETUP(p)); }
80
81 static GtkPaned *toGtkPaned(void *p) { return (GTK_PANED(p)); }
82
83 static GtkPrintContext *toGtkPrintContext(void *p) {
84 return (GTK_PRINT_CONTEXT(p));
85 }
86
87 static GtkPrintOperation *toGtkPrintOperation(void *p) {
88 return (GTK_PRINT_OPERATION(p));
89 }
90
91 static GtkPrintOperationPreview *toGtkPrintOperationPreview(void *p) {
92 return (GTK_PRINT_OPERATION_PREVIEW(p));
93 }
94
95 static GtkPrintSettings *toGtkPrintSettings(void *p) {
96 return (GTK_PRINT_SETTINGS(p));
97 }
98
99 static GtkProgressBar *toGtkProgressBar(void *p) {
100 return (GTK_PROGRESS_BAR(p));
101 }
102
103 static GtkLevelBar *toGtkLevelBar(void *p) { return (GTK_LEVEL_BAR(p)); }
104
105 static GtkBin *toGtkBin(void *p) { return (GTK_BIN(p)); }
106
107 static GtkWindow *toGtkWindow(void *p) { return (GTK_WINDOW(p)); }
108
109 static GtkWindowGroup *toGtkWindowGroup(void *p) {
110 return (GTK_WINDOW_GROUP(p));
111 }
112
113 static GtkBox *toGtkBox(void *p) { return (GTK_BOX(p)); }
114
115 static GtkStatusbar *toGtkStatusbar(void *p) { return (GTK_STATUSBAR(p)); }
116
117 static GtkLabel *toGtkLabel(void *p) { return (GTK_LABEL(p)); }
118
119 static GtkNotebook *toGtkNotebook(void *p) { return (GTK_NOTEBOOK(p)); }
120
121 static GtkEntry *toGtkEntry(void *p) { return (GTK_ENTRY(p)); }
122
123 static GtkEntryBuffer *toGtkEntryBuffer(void *p) {
124 return (GTK_ENTRY_BUFFER(p));
125 }
126
127 static GtkEntryCompletion *toGtkEntryCompletion(void *p) {
128 return (GTK_ENTRY_COMPLETION(p));
129 }
130
131 static GtkAdjustment *toGtkAdjustment(void *p) { return (GTK_ADJUSTMENT(p)); }
132
133 static GtkAccelGroup *toGtkAccelGroup(void *p) { return (GTK_ACCEL_GROUP(p)); }
134
135 static GtkAccelMap *toGtkAccelMap(void *p) { return (GTK_ACCEL_MAP(p)); }
136
137 static GtkTextTag *toGtkTextTag(void *p) { return (GTK_TEXT_TAG(p)); }
138
139 static GtkIconView *toGtkIconView(void *p) { return (GTK_ICON_VIEW(p)); }
140
141 static GtkImage *toGtkImage(void *p) { return (GTK_IMAGE(p)); }
142
143 static GtkButtonBox *toGtkButtonBox(void *p) { return (GTK_BUTTON_BOX(p)); }
144
145 static GtkButton *toGtkButton(void *p) { return (GTK_BUTTON(p)); }
146
147 static GtkScaleButton *toGtkScaleButton(void *p) {
148 return (GTK_SCALE_BUTTON(p));
149 }
150
151 static GtkColorButton *toGtkColorButton(void *p) {
152 return (GTK_COLOR_BUTTON(p));
153 }
154
155 static GtkViewport *toGtkViewport(void *p) { return (GTK_VIEWPORT(p)); }
156
157 static GtkVolumeButton *toGtkVolumeButton(void *p) {
158 return (GTK_VOLUME_BUTTON(p));
159 }
160
161 static GtkScrollable *toGtkScrollable(void *p) { return (GTK_SCROLLABLE(p)); }
162
163 static GtkScrolledWindow *toGtkScrolledWindow(void *p) {
164 return (GTK_SCROLLED_WINDOW(p));
165 }
166
167 static GtkMenuItem *toGtkMenuItem(void *p) { return (GTK_MENU_ITEM(p)); }
168
169 static GtkMenu *toGtkMenu(void *p) { return (GTK_MENU(p)); }
170
171 static GtkMenuShell *toGtkMenuShell(void *p) { return (GTK_MENU_SHELL(p)); }
172
173 static GtkMenuBar *toGtkMenuBar(void *p) { return (GTK_MENU_BAR(p)); }
174
175 static GtkSizeGroup *toGtkSizeGroup(void *p) { return (GTK_SIZE_GROUP(p)); }
176
177 static GtkSpinButton *toGtkSpinButton(void *p) { return (GTK_SPIN_BUTTON(p)); }
178
179 static GtkSpinner *toGtkSpinner(void *p) { return (GTK_SPINNER(p)); }
180
181 static GtkComboBox *toGtkComboBox(void *p) { return (GTK_COMBO_BOX(p)); }
182
183 static GtkComboBoxText *toGtkComboBoxText(void *p) {
184 return (GTK_COMBO_BOX_TEXT(p));
185 }
186
187 static GtkLinkButton *toGtkLinkButton(void *p) { return (GTK_LINK_BUTTON(p)); }
188
189 static GtkLockButton *toGtkLockButton(void *p) { return (GTK_LOCK_BUTTON(p)); }
190
191 static GtkLayout *toGtkLayout(void *p) { return (GTK_LAYOUT(p)); }
192
193 static GtkTreeModelSort *toGtkTreeModelSortable(void *p) {
194 return (GTK_TREE_MODEL_SORT(p));
195 }
196
197 static GtkListStore *toGtkListStore(void *p) { return (GTK_LIST_STORE(p)); }
198
199 static GtkSwitch *toGtkSwitch(void *p) { return (GTK_SWITCH(p)); }
200
201 static GtkTextView *toGtkTextView(void *p) { return (GTK_TEXT_VIEW(p)); }
202
203 static GtkTextMark *toGtkTextMark(void *p) { return (GTK_TEXT_MARK(p)); }
204
205 static GtkTextTagTable *toGtkTextTagTable(void *p) {
206 return (GTK_TEXT_TAG_TABLE(p));
207 }
208
209 static GtkTextBuffer *toGtkTextBuffer(void *p) { return (GTK_TEXT_BUFFER(p)); }
210
211 static GtkTreeModel *toGtkTreeModel(void *p) { return (GTK_TREE_MODEL(p)); }
212
213 static GtkTreeModelFilter *toGtkTreeModelFilter(void *p) {
214 return (GTK_TREE_MODEL_FILTER(p));
215 }
216
217 static GtkCellRenderer *toGtkCellRenderer(void *p) {
218 return (GTK_CELL_RENDERER(p));
219 }
220
221 static GtkCellEditable *toGtkCellEditable(void *p) {
222 return (GTK_CELL_EDITABLE(p));
223 }
224
225 static GtkCellRendererPixbuf *toGtkCellRendererPixbuf(void *p) {
226 return (GTK_CELL_RENDERER_PIXBUF(p));
227 }
228
229 static GtkCellRendererProgress *toGtkCellRendererProgress(void *p) {
230 return (GTK_CELL_RENDERER_PROGRESS(p));
231 }
232
233 static GtkCellRendererText *toGtkCellRendererText(void *p) {
234 return (GTK_CELL_RENDERER_TEXT(p));
235 }
236
237 static GtkCellRendererToggle *toGtkCellRendererToggle(void *p) {
238 return (GTK_CELL_RENDERER_TOGGLE(p));
239 }
240
241 static GtkCellRendererCombo *toGtkCellRendererCombo(void *p) {
242 return (GTK_CELL_RENDERER_COMBO(p));
243 }
244
245 static GtkCellRendererAccel *toGtkCellRendererAccel(void *p) {
246 return (GTK_CELL_RENDERER_ACCEL(p));
247 }
248
249 static GtkCellRendererSpin *toGtkCellRendererSpin(void *p) {
250 return (GTK_CELL_RENDERER_SPIN(p));
251 }
252
253 static GtkCellLayout *toGtkCellLayout(void *p) { return (GTK_CELL_LAYOUT(p)); }
254
255 static GtkCellArea *toGtkCellArea(void *p) { return (GTK_CELL_AREA(p)); }
256
257 static GtkCellAreaContext *toGtkCellAreaContext(void *p) {
258 return (GTK_CELL_AREA_CONTEXT(p));
259 }
260
261 static GtkCellAreaBox *toGtkCellAreaBox(void *p) {
262 return (GTK_CELL_AREA_BOX(p));
263 }
264
265 static GtkOrientable *toGtkOrientable(void *p) { return (GTK_ORIENTABLE(p)); }
266
267 static GtkTreeStore *toGtkTreeStore(void *p) { return (GTK_TREE_STORE(p)); }
268
269 static GtkTreeView *toGtkTreeView(void *p) { return (GTK_TREE_VIEW(p)); }
270
271 static GtkTreeViewColumn *toGtkTreeViewColumn(void *p) {
272 return (GTK_TREE_VIEW_COLUMN(p));
273 }
274
275 static GtkTreeSelection *toGtkTreeSelection(void *p) {
276 return (GTK_TREE_SELECTION(p));
277 }
278
279 static GtkTreeModelSort *toGtkTreeModelSort(void *p) {
280 return (GTK_TREE_MODEL_SORT(p));
281 }
282
283 static GtkTreeSortable *toGtkTreeSortable(void *p) {
284 return (GTK_TREE_SORTABLE(p));
285 }
286
287 static GtkClipboard *toGtkClipboard(void *p) { return (GTK_CLIPBOARD(p)); }
288
289 static GtkDialog *toGtkDialog(void *p) { return (GTK_DIALOG(p)); }
290
291 static GtkMessageDialog *toGtkMessageDialog(void *p) {
292 return (GTK_MESSAGE_DIALOG(p));
293 }
294
295 static GtkBuilder *toGtkBuilder(void *p) { return (GTK_BUILDER(p)); }
296
297 static GtkSeparatorMenuItem *toGtkSeparatorMenuItem(void *p) {
298 return (GTK_SEPARATOR_MENU_ITEM(p));
299 }
300
301 static GtkCheckButton *toGtkCheckButton(void *p) {
302 return (GTK_CHECK_BUTTON(p));
303 }
304
305 static GtkToggleButton *toGtkToggleButton(void *p) {
306 return (GTK_TOGGLE_BUTTON(p));
307 }
308
309 static GtkFontButton *toGtkFontButton(void *p) { return (GTK_FONT_BUTTON(p)); }
310
311 static GtkFrame *toGtkFrame(void *p) { return (GTK_FRAME(p)); }
312
313 static GtkAspectFrame *toGtkAspectFrame(void *p) {
314 return (GTK_ASPECT_FRAME(p));
315 }
316
317 static GtkSeparator *toGtkSeparator(void *p) { return (GTK_SEPARATOR(p)); }
318
319 static GtkScale *toGtkScale(void *p) { return (GTK_SCALE(p)); }
320
321 static GtkScrollbar *toGtkScrollbar(void *p) { return (GTK_SCROLLBAR(p)); }
322
323 static GtkRange *toGtkRange(void *p) { return (GTK_RANGE(p)); }
324
325 static GtkSearchEntry *toGtkSearchEntry(void *p) {
326 return (GTK_SEARCH_ENTRY(p));
327 }
328
329 static GtkOffscreenWindow *toGtkOffscreenWindow(void *p) {
330 return (GTK_OFFSCREEN_WINDOW(p));
331 }
332
333 static GtkExpander *toGtkExpander(void *p) { return (GTK_EXPANDER(p)); }
334
335 static GtkFileChooser *toGtkFileChooser(void *p) {
336 return (GTK_FILE_CHOOSER(p));
337 }
338
339 static GtkFileChooserButton *toGtkFileChooserButton(void *p) {
340 return (GTK_FILE_CHOOSER_BUTTON(p));
341 }
342
343 static GtkFileChooserDialog *toGtkFileChooserDialog(void *p) {
344 return (GTK_FILE_CHOOSER_DIALOG(p));
345 }
346
347 static GtkFileChooserWidget *toGtkFileChooserWidget(void *p) {
348 return (GTK_FILE_CHOOSER_WIDGET(p));
349 }
350
351 static GtkFileFilter *toGtkFileFilter(void *p) { return (GTK_FILE_FILTER(p)); }
352
353 static GtkMenuButton *toGtkMenuButton(void *p) { return (GTK_MENU_BUTTON(p)); }
354
355 static GtkRadioButton *toGtkRadioButton(void *p) {
356 return (GTK_RADIO_BUTTON(p));
357 }
358
359 static GtkRecentChooser *toGtkRecentChooser(void *p) {
360 return (GTK_RECENT_CHOOSER(p));
361 }
362
363 static GtkRecentChooserMenu *toGtkRecentChooserMenu(void *p) {
364 return (GTK_RECENT_CHOOSER_MENU(p));
365 }
366
367 static GtkColorChooser *toGtkColorChooser(void *p) {
368 return (GTK_COLOR_CHOOSER(p));
369 }
370
371 static GtkFontChooser *toGtkFontChooser(void *p) {
372 return (GTK_FONT_CHOOSER(p));
373 }
374
375 static GtkRecentFilter *toGtkRecentFilter(void *p) {
376 return (GTK_RECENT_FILTER(p));
377 }
378
379 static GtkRecentManager *toGtkRecentManager(void *p) {
380 return (GTK_RECENT_MANAGER(p));
381 }
382
383 static GtkCheckMenuItem *toGtkCheckMenuItem(void *p) {
384 return (GTK_CHECK_MENU_ITEM(p));
385 }
386
387 static GtkRadioMenuItem *toGtkRadioMenuItem(void *p) {
388 return (GTK_RADIO_MENU_ITEM(p));
389 }
390
391 static GtkToolItem *toGtkToolItem(void *p) { return (GTK_TOOL_ITEM(p)); }
392
393 static GtkToolbar *toGtkToolbar(void *p) { return (GTK_TOOLBAR(p)); }
394
395 static GtkTooltip *toGtkTooltip(void *p) { return (GTK_TOOLTIP(p)); }
396
397 static GtkEditable *toGtkEditable(void *p) { return (GTK_EDITABLE(p)); }
398
399 static GtkToolButton *toGtkToolButton(void *p) { return (GTK_TOOL_BUTTON(p)); }
400
401 static GtkToggleToolButton *toGtkToggleToolButton(void *p) {
402 return (GTK_TOGGLE_TOOL_BUTTON(p));
403 }
404
405 static GtkSeparatorToolItem *toGtkSeparatorToolItem(void *p) {
406 return (GTK_SEPARATOR_TOOL_ITEM(p));
407 }
408
409 static GtkCssProvider *toGtkCssProvider(void *p) {
410 return (GTK_CSS_PROVIDER(p));
411 }
412
413 static GtkStyleContext *toGtkStyleContext(void *p) {
414 return (GTK_STYLE_CONTEXT(p));
415 }
416
417 static GtkStyleProvider *toGtkStyleProvider(void *p) {
418 return (GTK_STYLE_PROVIDER(p));
419 }
420
421 static GtkInfoBar *toGtkInfoBar(void *p) { return (GTK_INFO_BAR(p)); }
422
423 static GMenuModel *toGMenuModel(void *p) { return (G_MENU_MODEL(p)); }
424
425 static GActionGroup *toGActionGroup(void *p) { return (G_ACTION_GROUP(p)); }
426
427 static GdkPixbuf *toGdkPixbuf(void *p) { return (GDK_PIXBUF(p)); }
428
429 static GdkScreen *toGdkScreen(void *p) { return (GDK_SCREEN(p)); }
430
431 static GdkDevice *toGdkDevice(void *p) { return (GDK_DEVICE(p)); }
432
433 static GObject *toGObject(void *p) { return (G_OBJECT(p)); }
434
435 static GType *alloc_types(int n) { return ((GType *)g_new0(GType, n)); }
436
437 static void set_type(GType *types, int n, GType t) { types[n] = t; }
438
439 // _gtk_test_init is a wrapper to use gtk_test_init directly from go.
440 // The variadic part on gtk_test_init is not used at the moment, according to
441 // the documentation.
442 static void _gtk_test_init(int *argcp, char ***argvp) {
443 gtk_test_init(argcp, argvp);
444 }
445
446 static GtkTreeViewColumn *_gtk_tree_view_column_new_with_attributes_one(
447 const gchar *title, GtkCellRenderer *renderer, const gchar *attribute,
448 gint column) {
449 GtkTreeViewColumn *tvc;
450
451 tvc = gtk_tree_view_column_new_with_attributes(title, renderer, attribute,
452 column, NULL);
453 return (tvc);
454 }
455
456 static void _gtk_list_store_set(GtkListStore *list_store, GtkTreeIter *iter,
457 gint column, void *value) {
458 gtk_list_store_set(list_store, iter, column, value, -1);
459 }
460
461 static void _gtk_tree_store_set(GtkTreeStore *store, GtkTreeIter *iter,
462 gint column, void *value) {
463 gtk_tree_store_set(store, iter, column, value, -1);
464 }
465
466 extern gboolean substring_match_equal_func(GtkTreeModel *model, gint column,
467 gchar *key, GtkTreeIter *iter,
468 gpointer data);
469
470 static GtkWidget *_gtk_message_dialog_new(GtkWindow *parent,
471 GtkDialogFlags flags,
472 GtkMessageType type,
473 GtkButtonsType buttons, char *msg) {
474 GtkWidget *w;
475
476 w = gtk_message_dialog_new(parent, flags, type, buttons, "%s", msg);
477 return (w);
478 }
479
480 static GtkWidget *_gtk_message_dialog_new_with_markup(GtkWindow *parent,
481 GtkDialogFlags flags,
482 GtkMessageType type,
483 GtkButtonsType buttons,
484 char *msg) {
485 GtkWidget *w;
486
487 w = gtk_message_dialog_new_with_markup(parent, flags, type, buttons, "%s",
488 msg);
489 return (w);
829490 }
830491
831492 static void
832493 _gtk_message_dialog_format_secondary_text(GtkMessageDialog *message_dialog,
833 const gchar *msg)
834 {
835 gtk_message_dialog_format_secondary_text(message_dialog, "%s", msg);
494 const gchar *msg) {
495 gtk_message_dialog_format_secondary_text(message_dialog, "%s", msg);
836496 }
837497
838498 static void
839499 _gtk_message_dialog_format_secondary_markup(GtkMessageDialog *message_dialog,
840 const gchar *msg)
841 {
842 gtk_message_dialog_format_secondary_markup(message_dialog, "%s", msg);
843 }
844
845 static const gchar *
846 object_get_class_name(GObject *object)
847 {
848 return G_OBJECT_CLASS_NAME(G_OBJECT_GET_CLASS(object));
849 }
850
851 static GtkWidget *
852 gtk_file_chooser_dialog_new_1(
853 const gchar *title,
854 GtkWindow *parent,
855 GtkFileChooserAction action,
856 const gchar *first_button_text, int first_button_id
857 ) {
858 return gtk_file_chooser_dialog_new(
859 title, parent, action,
860 first_button_text, first_button_id,
861 NULL);
862 }
863
864 static GtkWidget *
865 gtk_file_chooser_dialog_new_2(
866 const gchar *title,
867 GtkWindow *parent,
868 GtkFileChooserAction action,
869 const gchar *first_button_text, int first_button_id,
870 const gchar *second_button_text, int second_button_id
871 ) {
872 return gtk_file_chooser_dialog_new(
873 title, parent, action,
874 first_button_text, first_button_id,
875 second_button_text, second_button_id,
876 NULL);
877 }
878
879 static void _gtk_widget_hide_on_delete(GtkWidget* w) {
880 g_signal_connect(GTK_WIDGET(w), "delete-event", G_CALLBACK(gtk_widget_hide_on_delete), NULL);
881 }
882
883 static inline gchar** make_strings(int count) {
884 return (gchar**)malloc(sizeof(gchar*) * count);
885 }
886
887 static inline void destroy_strings(gchar** strings) {
888 free(strings);
889 }
890
891 static inline gchar* get_string(gchar** strings, int n) {
892 return strings[n];
893 }
894
895 static inline void set_string(gchar** strings, int n, gchar* str) {
896 strings[n] = str;
897 }
898
899 static inline gchar** next_gcharptr(gchar** s) { return (s+1); }
900
901 extern void goBuilderConnect (GtkBuilder *builder,
902 GObject *object,
903 gchar *signal_name,
904 gchar *handler_name,
905 GObject *connect_object,
906 GConnectFlags flags,
907 gpointer user_data);
500 const gchar *msg) {
501 gtk_message_dialog_format_secondary_markup(message_dialog, "%s", msg);
502 }
503
504 static const gchar *object_get_class_name(GObject *object) {
505 return G_OBJECT_CLASS_NAME(G_OBJECT_GET_CLASS(object));
506 }
507
508 static GtkWidget *gtk_file_chooser_dialog_new_1(const gchar *title,
509 GtkWindow *parent,
510 GtkFileChooserAction action,
511 const gchar *first_button_text,
512 int first_button_id) {
513 return gtk_file_chooser_dialog_new(title, parent, action, first_button_text,
514 first_button_id, NULL);
515 }
516
517 static GtkWidget *gtk_file_chooser_dialog_new_2(
518 const gchar *title, GtkWindow *parent, GtkFileChooserAction action,
519 const gchar *first_button_text, int first_button_id,
520 const gchar *second_button_text, int second_button_id) {
521 return gtk_file_chooser_dialog_new(title, parent, action, first_button_text,
522 first_button_id, second_button_text,
523 second_button_id, NULL);
524 }
525
526 static void _gtk_widget_hide_on_delete(GtkWidget *w) {
527 g_signal_connect(GTK_WIDGET(w), "delete-event",
528 G_CALLBACK(gtk_widget_hide_on_delete), NULL);
529 }
530
531 static inline gchar **make_strings(int count) {
532 return (gchar **)malloc(sizeof(gchar *) * count);
533 }
534
535 static inline void destroy_strings(gchar **strings) { free(strings); }
536
537 static inline gchar *get_string(gchar **strings, int n) { return strings[n]; }
538
539 static inline void set_string(gchar **strings, int n, gchar *str) {
540 strings[n] = str;
541 }
542
543 extern void goBuilderConnect(GtkBuilder *builder, GObject *object,
544 gchar *signal_name, gchar *handler_name,
545 GObject *connect_object, GConnectFlags flags,
546 gpointer user_data);
908547
909548 static inline void _gtk_builder_connect_signals_full(GtkBuilder *builder) {
910 gtk_builder_connect_signals_full(builder, (GtkBuilderConnectFunc)(goBuilderConnect), NULL);
911 }
912
913 extern void goPrintSettings (gchar *key,
914 gchar *value,
915 gpointer user_data);
916
917 static inline void _gtk_print_settings_foreach(GtkPrintSettings *ps, gpointer user_data) {
918 gtk_print_settings_foreach(ps, (GtkPrintSettingsFunc)(goPrintSettings), user_data);
919 }
920
921 extern void goPageSetupDone (GtkPageSetup *setup,
922 gpointer data);
923
924 static inline void _gtk_print_run_page_setup_dialog_async(GtkWindow *parent, GtkPageSetup *setup,
925 GtkPrintSettings *settings, gpointer data) {
926 gtk_print_run_page_setup_dialog_async(parent, setup, settings,
927 (GtkPageSetupDoneFunc)(goPageSetupDone), data);
928 }
929
930 extern gboolean goTreeModelFilterFuncs (GtkTreeModel *model, GtkTreeIter *iter, gpointer data);
931
932 static inline void _gtk_tree_model_filter_set_visible_func(GtkTreeModelFilter *filter, gpointer user_data) {
933 gtk_tree_model_filter_set_visible_func(filter, (GtkTreeModelFilterVisibleFunc)(goTreeModelFilterFuncs), user_data, NULL);
934 }
935
936 static inline void _gtk_text_buffer_insert_with_tag_by_name(GtkTextBuffer* buffer, GtkTextIter* iter, const gchar* text, gint len, const gchar* first_tag_name) {
937 gtk_text_buffer_insert_with_tags_by_name(buffer, iter, text, len, first_tag_name, NULL);
938 }
939
940 static inline void _gtk_text_buffer_insert_with_tag(GtkTextBuffer* buffer, GtkTextIter* iter, const gchar* text, gint len, GtkTextTag* tag) {
941 gtk_text_buffer_insert_with_tags(buffer, iter, text, len, tag, NULL);
942 }
943
944 extern gint goTreeSortableSortFuncs(GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer data);
945
946 static inline void _gtk_tree_sortable_set_sort_func(GtkTreeSortable *sortable, gint sort_column_id, gpointer user_data) {
947 gtk_tree_sortable_set_sort_func(sortable, sort_column_id, (GtkTreeIterCompareFunc)(goTreeSortableSortFuncs), user_data, NULL);
948 }
949
950 static GtkWidget *
951 _gtk_dialog_new_with_buttons(const gchar *title,
952 GtkWindow *parent,
953 GtkDialogFlags flags,
954 const gchar *first_button_text) {
955 GtkWidget *w;
956
957 w = gtk_dialog_new_with_buttons(title, parent, flags, first_button_text, NULL);
958 return (w);
959 }
960
961 extern gint goTreeModelForeachFunc(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data);
962
963 static inline void _gtk_tree_model_foreach(GtkTreeModel *model, gpointer user_data) {
964 gtk_tree_model_foreach(model, (GtkTreeModelForeachFunc)(goTreeModelForeachFunc), user_data);
965
966 }
967
968 extern void goTreeSelectionForeachFunc(GtkTreeModel *model, GtkTreePath *path, GtkTreeIter *iter, gpointer data);
969
970 static inline void _gtk_tree_selection_selected_foreach(GtkTreeSelection *selection, gpointer user_data) {
971 gtk_tree_selection_selected_foreach(selection, (GtkTreeSelectionForeachFunc)(goTreeSelectionForeachFunc), user_data);
972 }
549 gtk_builder_connect_signals_full(
550 builder, (GtkBuilderConnectFunc)(goBuilderConnect), NULL);
551 }
552
553 extern gboolean goTreeViewSearchEqualFunc(GtkTreeModel *model, gint column,
554 gchar *key, GtkTreeIter *iter,
555 gpointer data);
556
557 static inline void _gtk_tree_view_set_search_equal_func(GtkTreeView *tree_view,
558 gpointer user_data) {
559 gtk_tree_view_set_search_equal_func(
560 tree_view, (GtkTreeViewSearchEqualFunc)(goTreeViewSearchEqualFunc),
561 user_data, (GDestroyNotify)(gotk3_callbackDelete));
562 }
563
564 extern gboolean goTreeModelFilterVisibleFunc(GtkTreeModel *model,
565 GtkTreeIter *iter, gpointer data);
566
567 static inline void
568 _gtk_tree_model_filter_set_visible_func(GtkTreeModelFilter *filter,
569 gpointer user_data) {
570 gtk_tree_model_filter_set_visible_func(
571 filter, (GtkTreeModelFilterVisibleFunc)(goTreeModelFilterVisibleFunc),
572 user_data, (GDestroyNotify)(gotk3_callbackDelete));
573 }
574
575 static inline void _gtk_text_buffer_insert_with_tag_by_name(
576 GtkTextBuffer *buffer, GtkTextIter *iter, const gchar *text, gint len,
577 const gchar *first_tag_name) {
578 gtk_text_buffer_insert_with_tags_by_name(buffer, iter, text, len,
579 first_tag_name, NULL);
580 }
581
582 static inline void _gtk_text_buffer_insert_with_tag(GtkTextBuffer *buffer,
583 GtkTextIter *iter,
584 const gchar *text, gint len,
585 GtkTextTag *tag) {
586 gtk_text_buffer_insert_with_tags(buffer, iter, text, len, tag, NULL);
587 }
588
589 extern gint goTreeSortableSortFunc(GtkTreeModel *model, GtkTreeIter *a,
590 GtkTreeIter *b, gpointer data);
591
592 static inline void _gtk_tree_sortable_set_sort_func(GtkTreeSortable *sortable,
593 gint sort_column_id,
594 gpointer user_data) {
595 gtk_tree_sortable_set_sort_func(
596 sortable, sort_column_id,
597 (GtkTreeIterCompareFunc)(goTreeSortableSortFunc), user_data, NULL);
598 }
599
600 static inline void
601 _gtk_tree_sortable_set_default_sort_func(GtkTreeSortable *sortable,
602 gpointer user_data) {
603 gtk_tree_sortable_set_default_sort_func(
604 sortable, (GtkTreeIterCompareFunc)(goTreeSortableSortFunc), user_data,
605 (GDestroyNotify)(gotk3_callbackDelete));
606 }
607
608 static GtkWidget *_gtk_dialog_new_with_buttons(const gchar *title,
609 GtkWindow *parent,
610 GtkDialogFlags flags,
611 const gchar *first_button_text) {
612 GtkWidget *w;
613
614 w = gtk_dialog_new_with_buttons(title, parent, flags, first_button_text,
615 NULL);
616 return (w);
617 }
618
619 extern gint goTreeModelForeachFunc(GtkTreeModel *model, GtkTreePath *path,
620 GtkTreeIter *iter, gpointer data);
621
622 static inline void _gtk_tree_model_foreach(GtkTreeModel *model,
623 gpointer user_data) {
624 gtk_tree_model_foreach(
625 model, (GtkTreeModelForeachFunc)(goTreeModelForeachFunc), user_data);
626 }
627
628 extern void goTreeSelectionForeachFunc(GtkTreeModel *model, GtkTreePath *path,
629 GtkTreeIter *iter, gpointer data);
630
631 static inline void
632 _gtk_tree_selection_selected_foreach(GtkTreeSelection *selection,
633 gpointer user_data) {
634 gtk_tree_selection_selected_foreach(
635 selection, (GtkTreeSelectionForeachFunc)(goTreeSelectionForeachFunc),
636 user_data);
637 }
638
639 extern gboolean goTreeSelectionFunc(GtkTreeSelection *selection,
640 GtkTreeModel *model, GtkTreePath *path,
641 gboolean selected, gpointer data);
642
643 static inline void
644 _gtk_tree_selection_set_select_function(GtkTreeSelection *selection,
645 gpointer user_data) {
646 gtk_tree_selection_set_select_function(
647
648 selection, (GtkTreeSelectionFunc)(goTreeSelectionFunc), user_data,
649 (GDestroyNotify)(gotk3_callbackDelete));
650 }
1818 // 3.8 or earlier. To target an earlier build build, use the build tag
1919 // gtk_MAJOR_MINOR. For example, to target GTK 3.8, run
2020 // 'go build -tags gtk_3_8'.
21 // +build gtk_3_6 gtk_3_8
21 // +build gtk_3_6 gtk_3_8 gtk_deprecated
2222
2323 package gtk
2424
7171 C.GtkEntryIconPosition(iconPos), (*C.gchar)(cstr))
7272 }
7373
74 /*
75 * GtkImage
76 */
77
78 // TODO:
79
80 /*
81 // gtk_image_get_icon_set().
82 func (v *Image) GetIconSet() {
83 }
84 */
85
86 // gtk_image_get_stock().
87
88 /*
89 // gtk_image_new_from_icon_set().
90 func ImageNewFromIconSet() {
91 }
92 */
93
7494 // ImageNewFromStock is a wrapper around gtk_image_new_from_stock().
7595 func ImageNewFromStock(stock Stock, size IconSize) (*Image, error) {
7696 cstr := C.CString(string(stock))
89109 C.gtk_image_set_from_stock(v.native(), (*C.gchar)(cstr),
90110 C.GtkIconSize(size))
91111 }
112
113 // TODO:
114 /*
115 // gtk_image_set_from_icon_set().
116 func (v *Image) SetFromIconSet() {
117 }
118 */
92119
93120 // StatusIconNewFromStock is a wrapper around gtk_status_icon_new_from_stock().
94121 // Deprecated since 3.10, use StatusIconNewFromIconName (gtk_status_icon_new_from_icon_name) instead.
241268 func (v *Window) ReshowWithInitialSize() {
242269 C.gtk_window_reshow_with_initial_size(v.native())
243270 }
271
272 /*
273 * GtkWidget
274 */
275
276 // TODO:
277 // gtk_widget_render_icon_pixbuf().
278 // gtk_widget_pop_composite_child().
279 // gtk_widget_push_composite_child().
280 // gtk_widget_set_composite_name().
281
282 /*
283 * GtkContainer
284 */
285
286 // TODO:
287 // gtk_container_resize_children().
288
289 /*
290 * GtkImageMenuItem
291 */
292
293 // TODO:
294 // gtk_image_menu_item_set_image().
295 // gtk_image_menu_item_get_image().
296 // gtk_image_menu_item_new().
297 // gtk_image_menu_item_new_from_stock().
298 // gtk_image_menu_item_new_with_label().
299 // gtk_image_menu_item_new_with_mnemonic().
300 // gtk_image_menu_item_get_use_stock().
301 // gtk_image_menu_item_set_use_stock().
302 // gtk_image_menu_item_get_always_show_image().
303 // gtk_image_menu_item_set_always_show_image().
304 // gtk_image_menu_item_set_accel_group().
305
306 /*
307 * GtkToolButton
308 */
309
310 // TODO:
311 // gtk_tool_button_new_from_stock().
312 // gtk_tool_button_set_stock_id().
313 // gtk_tool_button_get_stock_id().
314
315 /*
316 * GtkDialog
317 */
318
319 // TODO:
320
321 /*
322 // gtk_dialog_set_alternative_button_order().
323 func SetAlternativeButtonOrder(ids ...ResponseType) {
324 }
325 */
326
327 /*
328 // gtk_alternative_dialog_button_order().
329 func (v *gdk.Screen) AlternativeDialogButtonOrder() bool {
330 c := C.gtk_alternative_dialog_button_order(v.native())
331 return gobool(c)
332 }
333 */
334
335 // gtk_dialog_set_alternative_button_order_from_array
1818 // 3.10 or earlier. To target an earlier build build, use the build tag
1919 // gtk_MAJOR_MINOR. For example, to target GTK 3.8, run
2020 // 'go build -tags gtk_3_8'.
21 // +build gtk_3_6 gtk_3_8 gtk_3_10
21 // +build gtk_3_6 gtk_3_8 gtk_3_10 gtk_deprecated
2222
2323 package gtk
2424
2525 // #include <gtk/gtk.h>
2626 import "C"
27 import (
28 "unsafe"
29
30 "github.com/gotk3/gotk3/glib"
31 )
3227
3328 /*
3429 * GtkDialog
3530 */
3631
3732 // GetActionArea() is a wrapper around gtk_dialog_get_action_area().
38 func (v *Dialog) GetActionArea() (*Widget, error) {
33 func (v *Dialog) GetActionArea() (IWidget, error) {
3934 c := C.gtk_dialog_get_action_area(v.native())
4035 if c == nil {
4136 return nil, nilPtrErr
4237 }
43 return wrapWidget(glib.Take(unsafe.Pointer(c))), nil
38 return castWidget(c)
4439 }
4540
4641 /*
4843 */
4944
5045 // GetImage is a wrapper around gtk_message_dialog_get_image().
51 func (v *MessageDialog) GetImage() (*Widget, error) {
46 func (v *MessageDialog) GetImage() (IWidget, error) {
5247 c := C.gtk_message_dialog_get_image(v.native())
5348 if c == nil {
5449 return nil, nilPtrErr
5550 }
56 return wrapWidget(glib.Take(unsafe.Pointer(c))), nil
51 return castWidget(c)
5752 }
5853
5954 // SetImage is a wrapper around gtk_message_dialog_set_image().
8681 func (v *Widget) SetMarginRight(margin int) {
8782 C.gtk_widget_set_margin_right(v.native(), C.gint(margin))
8883 }
84
85 // TODO:
86 // gtk_widget_get_root_window().
87
88 /*
89 * GtkContainer
90 */
91
92 // TODO:
93 // gtk_container_get_resize_mode().
94 // gtk_container_set_resize_mode().
0 // +build gtk_3_6 gtk_3_8 gtk_3_10 gtk_3_12
0 // +build gtk_3_6 gtk_3_8 gtk_3_10 gtk_3_12 gtk_deprecated
11
22 package gtk
33
3636 * deprecated since version 3.14 and should not be used in newly-written code
3737 */
3838
39 // ResizeGripIsVisible is a wrapper around
40 // gtk_window_resize_grip_is_visible().
41 func (v *Window) ResizeGripIsVisible() bool {
42 c := C.gtk_window_resize_grip_is_visible(v.native())
43 return gobool(c)
44 }
39 /*
40 * GtkTreeView
41 */
42
43 // TODO:
44 // gtk_tree_view_set_rules_hint().
45 // gtk_tree_view_get_rules_hint().
46
47 /*
48 * GtkWindow
49 */
4550
4651 // SetHasResizeGrip is a wrapper around gtk_window_set_has_resize_grip().
4752 func (v *Window) SetHasResizeGrip(setting bool) {
5459 return gobool(c)
5560 }
5661
62 // ResizeGripIsVisible is a wrapper around gtk_window_resize_grip_is_visible().
63 func (v *Window) ResizeGripIsVisible() bool {
64 c := C.gtk_window_resize_grip_is_visible(v.native())
65 return gobool(c)
66 }
67
68 // GetResizeGripArea is a wrapper around gtk_window_get_resize_grip_area().
69 func (v *Window) GetResizeGripArea() (*gdk.Rectangle, bool) {
70 var cRect *C.GdkRectangle
71 wasRetrieved := C.gtk_window_get_resize_grip_area(v.native(), cRect)
72 rect := gdk.WrapRectangle(uintptr(unsafe.Pointer(cRect)))
73 return rect, gobool(wasRetrieved)
74 }
75
76 /*
77 * GtkWidget
78 */
79
5780 // Reparent() is a wrapper around gtk_widget_reparent().
5881 func (v *Widget) Reparent(newParent IWidget) {
5982 C.gtk_widget_reparent(v.native(), newParent.toWidget())
6083 }
84
85 // SetDoubleBuffered is a wrapper around gtk_widget_set_double_buffered().
86 func (v *Widget) SetDoubleBuffered(doubleBuffered bool) {
87 C.gtk_widget_set_double_buffered(v.native(), gbool(doubleBuffered))
88 }
89
90 // GetDoubleBuffered is a wrapper around gtk_widget_get_double_buffered().
91 func (v *Widget) GetDoubleBuffered() bool {
92 c := C.gtk_widget_get_double_buffered(v.native())
93 return gobool(c)
94 }
95
96 // TODO:
97 // gtk_widget_region_intersect().
6198
6299 // GetPadding is a wrapper around gtk_alignment_get_padding().
63100 func (v *Alignment) GetPadding() (top, bottom, left, right uint) {
128165 return float32(x), float32(y)
129166 }
130167
131 // SetReallocateRedraws is a wrapper around
132 // gtk_container_set_reallocate_redraws().
168 // SetReallocateRedraws is a wrapper around gtk_container_set_reallocate_redraws().
133169 func (v *Container) SetReallocateRedraws(needsRedraws bool) {
134170 C.gtk_container_set_reallocate_redraws(v.native(), gbool(needsRedraws))
135171 }
158194 C.gtk_misc_set_padding(v.native(), C.gint(xPad), C.gint(yPad))
159195 }
160196
161 // SetDoubleBuffered is a wrapper around gtk_widget_set_double_buffered().
162 func (v *Widget) SetDoubleBuffered(doubleBuffered bool) {
163 C.gtk_widget_set_double_buffered(v.native(), gbool(doubleBuffered))
164 }
165
166 // GetDoubleBuffered is a wrapper around gtk_widget_get_double_buffered().
167 func (v *Widget) GetDoubleBuffered() bool {
168 c := C.gtk_widget_get_double_buffered(v.native())
169 return gobool(c)
170 }
171
172197 /*
173198 * GtkArrow
174199 * deprecated since version 3.14
189214 }
190215
191216 func wrapArrow(obj *glib.Object) *Arrow {
217 if obj == nil {
218 return nil
219 }
220
192221 return &Arrow{Misc{Widget{glib.InitiallyUnowned{obj}}}}
193222 }
194223
217246 }
218247
219248 func wrapAlignment(obj *glib.Object) *Alignment {
249 if obj == nil {
250 return nil
251 }
252
220253 return &Alignment{Bin{Container{Widget{glib.InitiallyUnowned{obj}}}}}
221254 }
222255
239272 }
240273
241274 func wrapStatusIcon(obj *glib.Object) *StatusIcon {
275 if obj == nil {
276 return nil
277 }
278
242279 return &StatusIcon{obj}
243280 }
244281
429466
430467 // PopupAtStatusIcon() is a wrapper around gtk_menu_popup() specific to usage with GtkStatusIcon.
431468 // gomenu_popup() is defined in menu.go.h, this is a workaround to pass gtk_status_icon_position_menu as the GtkMenuPositionFunc.
432 func (v *Menu) PopupAtStatusIcon(statusIcon *StatusIcon, button uint, activateTime uint32) {
469 func (v *Menu) PopupAtStatusIcon(statusIcon *StatusIcon, button gdk.Button, activateTime uint32) {
433470 C.gotk_menu_popup_at_status_icon(v.native(), statusIcon.native(), C.guint(button), C.guint32(activateTime))
434471 }
435472
458495 }
459496
460497 func wrapMisc(obj *glib.Object) *Misc {
498 if obj == nil {
499 return nil
500 }
501
461502 return &Misc{Widget{glib.InitiallyUnowned{obj}}}
462503 }
463504
22 * deprecated since version 3.14
33 */
44
5 // Wrapper for gtk_menu_popup to allow calling gtk_status_icon_position_menu as callback from go code
6 // Used in func (v *Menu) PopupAtStatusIcon
7 static void
8 gotk_menu_popup_at_status_icon(GtkMenu *menu, GtkStatusIcon *status_icon, guint button, guint32 activate_time)
9 {
10 gtk_menu_popup(menu, NULL, NULL, gtk_status_icon_position_menu, status_icon, button, activate_time);
5 // Wrapper for gtk_menu_popup to allow calling gtk_status_icon_position_menu as
6 // callback from go code Used in func (v *Menu) PopupAtStatusIcon
7 static void gotk_menu_popup_at_status_icon(GtkMenu *menu,
8 GtkStatusIcon *status_icon,
9 guint button,
10 guint32 activate_time) {
11 gtk_menu_popup(menu, NULL, NULL, gtk_status_icon_position_menu, status_icon,
12 button, activate_time);
1113 }
1214
13 static GtkAlignment *
14 toGtkAlignment(void *p)
15 {
16 return (GTK_ALIGNMENT(p));
17 }
15 static GtkAlignment *toGtkAlignment(void *p) { return (GTK_ALIGNMENT(p)); }
1816
19 static GtkArrow *
20 toGtkArrow(void *p)
21 {
22 return (GTK_ARROW(p));
23 }
17 static GtkArrow *toGtkArrow(void *p) { return (GTK_ARROW(p)); }
2418
25 static GtkMisc *
26 toGtkMisc(void *p)
27 {
28 return (GTK_MISC(p));
29 }
19 static GtkMisc *toGtkMisc(void *p) { return (GTK_MISC(p)); }
3020
31 static GtkStatusIcon *
32 toGtkStatusIcon(void *p)
33 {
34 return (GTK_STATUS_ICON(p));
35 }
21 static GtkStatusIcon *toGtkStatusIcon(void *p) { return (GTK_STATUS_ICON(p)); }
3622
37 static GdkPixbuf *
38 toGdkPixbuf(void *p)
39 {
40 return (GDK_PIXBUF(p));
41 }
23 static GdkPixbuf *toGdkPixbuf(void *p) { return (GDK_PIXBUF(p)); }
4224
4325 /*
4426 * End deprecated since version 3.14
0 //+build gtk_3_6 gtk_3_8 gtk_3_10 gtk_3_12 gtk_3_14
0 //+build gtk_3_6 gtk_3_8 gtk_3_10 gtk_3_12 gtk_3_14 gtk_deprecated
11
22 package gtk
33
2121 C.gtk_widget_override_color(v.native(), C.GtkStateFlags(state), cColor)
2222 }
2323
24 // OverrideBackgroundColor is a wrapper around gtk_widget_override_background_color().
2425 func (v *Widget) OverrideBackgroundColor(state StateFlags, color *gdk.RGBA) {
2526 var cColor *C.GdkRGBA
2627 if color != nil {
2930 C.gtk_widget_override_background_color(v.native(), C.GtkStateFlags(state), cColor)
3031 }
3132
33 // SetColor is a convenience func to override the background color of the given button.
3234 func (v *Button) SetColor(color string) {
3335 rgba := C.GdkRGBA{}
3436 C.gdk_rgba_parse(&rgba, (*C.gchar)(C.CString(color)))
4345 C.gtk_widget_override_font(v.native(), c)
4446 }
4547
48 // TODO:
49 // gtk_widget_override_symbolic_color().
50 // gtk_widget_override_cursor().
51
4652 func (v *Label) SetFont(font string) {
4753 v.OverrideFont(font)
4854 }
0 //+build gtk_3_6 gtk_3_8 gtk_3_10 gtk_3_12 gtk_3_14 gtk_3_16 gtk_deprecated
1
2 package gtk
3
4 /*
5 * GtkPlacesSidebar
6 */
7
8 // TODO:
9 // gtk_places_sidebar_get_show_connect_to_server().
10 // gtk_places_sidebar_set_show_connect_to_server().
0 //+build gtk_3_6 gtk_3_8 gtk_3_10 gtk_3_12 gtk_3_14 gtk_3_16 gtk_3_18
0 //+build gtk_3_6 gtk_3_8 gtk_3_10 gtk_3_12 gtk_3_14 gtk_3_16 gtk_3_18 gtk_deprecated
11
22 package gtk
33
44 // #include <gtk/gtk.h>
55 // #include <stdlib.h>
66 import "C"
7 import (
8 "unsafe"
9 )
710
8 // GetFocusOnClick() is a wrapper around gtk_button_get_focus_on_click().
11 /*
12 * GtkRange
13 */
14
15 // TODO:
16 // gtk_range_get_min_slider_size().
17 // gtk_range_set_min_slider_size().
18
19 /*
20 * GtkToolbar
21 */
22
23 // TODO:
24 // GtkToolbarSpaceStyle
25
26 /*
27 * GtkFileChooserButton
28 */
29
30 // GetFocusOnClick is a wrapper around gtk_file_chooser_button_get_focus_on_click().
31 func (v *FileChooserButton) GetFocusOnClick() bool {
32 return gobool(C.gtk_file_chooser_button_get_focus_on_click(v.native()))
33 }
34
35 // SetFocusOnClick is a wrapper around gtk_file_chooser_button_set_focus_on_click().
36 func (v *FileChooserButton) SetFocusOnClick(grabFocus bool) {
37 C.gtk_file_chooser_button_set_focus_on_click(v.native(), gbool(grabFocus))
38 }
39
40 /*
41 * GtkButton
42 */
43
44 // GetFocusOnClick is a wrapper around gtk_button_get_focus_on_click().
945 func (v *Button) GetFocusOnClick() bool {
1046 c := C.gtk_button_get_focus_on_click(v.native())
1147 return gobool(c)
1248 }
1349
50 // SetFocusOnClick is a wrapper around gtk_button_set_focus_on_click().
51 func (v *Button) SetFocusOnClick(focusOnClick bool) {
52 C.gtk_button_set_focus_on_click(v.native(), gbool(focusOnClick))
53 }
54
55 /*
56 * GtkTextIter
57 */
58
1459 // BeginsTag is a wrapper around gtk_text_iter_begins_tag().
1560 func (v *TextIter) BeginsTag(v1 *TextTag) bool {
1661 return gobool(C.gtk_text_iter_begins_tag(v.native(), v1.native()))
62 }
63
64 /*
65 * GtkWindow
66 */
67
68 // ParseGeometry is a wrapper around gtk_window_parse_geometry().
69 func (v *Window) ParseGeometry(geometry string) bool {
70 cstr := C.CString(geometry)
71 defer C.free(unsafe.Pointer(cstr))
72 c := C.gtk_window_parse_geometry(v.native(), (*C.gchar)(cstr))
73 return gobool(c)
1774 }
1875
1976 // ResizeToGeometry is a wrapper around gtk_window_resize_to_geometry().
2683 C.gtk_window_set_default_geometry(v.native(), C.gint(width),
2784 C.gint(height))
2885 }
29
30 // SetFocusOnClick() is a wrapper around gtk_button_set_focus_on_click().
31 func (v *Button) SetFocusOnClick(focusOnClick bool) {
32 C.gtk_button_set_focus_on_click(v.native(), gbool(focusOnClick))
33 }
0 //+build gtk_3_6 gtk_3_8 gtk_3_10 gtk_3_12 gtk_3_14 gtk_3_16 gtk_3_18 gtk_3_20
0 //+build gtk_3_6 gtk_3_8 gtk_3_10 gtk_3_12 gtk_3_14 gtk_3_16 gtk_3_18 gtk_3_20 gtk_deprecated
11
22 package gtk
33
77
88 import (
99 "unsafe"
10
11 "github.com/gotk3/gotk3/gdk"
1012 )
1113
14 /*
15 * GtkWidget
16 */
17
18 // TODO:
19 // gtk_widget_send_expose().
20 // gtk_widget_is_composited().
21
1222 // PopupAtMouse() is a wrapper for gtk_menu_popup(), without the option for a custom positioning function.
13 func (v *Menu) PopupAtMouseCursor(parentMenuShell IMenu, parentMenuItem IMenuItem, button int, activateTime uint32) {
23 func (v *Menu) PopupAtMouseCursor(parentMenuShell IMenu, parentMenuItem IMenuItem, button gdk.Button, activateTime uint32) {
1424 wshell := nullableWidget(parentMenuShell)
1525 witem := nullableWidget(parentMenuItem)
1626
0 //+build gtk_3_6 gtk_3_8 gtk_3_10 gtk_3_12 gtk_3_14 gtk_3_16 gtk_3_18 gtk_3_20 gtk_3_22
0 //+build gtk_3_6 gtk_3_8 gtk_3_10 gtk_3_12 gtk_3_14 gtk_3_16 gtk_3_18 gtk_3_20 gtk_3_22 gtk_deprecated
11
22 package gtk
33
55 // #include <stdlib.h>
66 import "C"
77 import (
8 "fmt"
89 "unsafe"
910
1011 "github.com/gotk3/gotk3/glib"
1112 )
1213
1314 // GetFocusChain is a wrapper around gtk_container_get_focus_chain().
14 func (v *Container) GetFocusChain() ([]*Widget, bool) {
15 func (v *Container) GetFocusChain() ([]IWidget, bool, error) {
1516 var cwlist *C.GList
1617 c := C.gtk_container_get_focus_chain(v.native(), &cwlist)
1718
18 var widgets []*Widget
19 if cwlist == nil {
20 return nil, gobool(c), nil
21 }
22
23 var widgets []IWidget
1924 wlist := glib.WrapList(uintptr(unsafe.Pointer(cwlist)))
2025 for ; wlist.Data() != nil; wlist = wlist.Next() {
21 widgets = append(widgets, wrapWidget(glib.Take(wlist.Data().(unsafe.Pointer))))
26 w, ok := wlist.Data().(*Widget)
27 if !ok {
28 return nil, gobool(c), fmt.Errorf("element is not of type *Widget, got %T", w)
29 }
30 widget, err := castWidget(w.toWidget())
31 if err != nil {
32 return nil, gobool(c), err
33 }
34 widgets = append(widgets, widget)
2235 }
23 return widgets, gobool(c)
36 return widgets, gobool(c), nil
2437 }
38
39 /*
40 * GtkContainer
41 */
2542
2643 // SetFocusChain is a wrapper around gtk_container_set_focus_chain().
2744 func (v *Container) SetFocusChain(focusableWidgets []IWidget) {
3451 C.gtk_container_set_focus_chain(v.native(), glist)
3552 }
3653
54 // TODO:
55 // gtk_container_unset_focus_chain
56
3757 // CssProviderGetDefault is a wrapper around gtk_css_provider_get_default().
3858 func CssProviderGetDefault() (*CssProvider, error) {
3959 c := C.gtk_css_provider_get_default()
1818 // 3.6 or earlier. To target an earlier build build, use the build tag
1919 // gtk_MAJOR_MINOR. For example, to target GTK 3.6, run
2020 // 'go build -tags gtk_3_6'.
21 // +build gtk_3_6
21 // +build gtk_3_6 gtk_deprecated
2222
2323 package gtk
2424
44 */
55 import "C"
66 import (
7 "strings"
87 "unsafe"
98
109 "github.com/gotk3/gotk3/glib"
10 "github.com/gotk3/gotk3/internal/callback"
1111 )
1212
13 //export substring_match_equal_func
14 func substring_match_equal_func(model *C.GtkTreeModel,
15 column C.gint,
16 key *C.gchar,
17 iter *C.GtkTreeIter,
18 data C.gpointer) C.gboolean {
19
20 goModel := &TreeModel{glib.Take(unsafe.Pointer(model))}
21 goIter := &TreeIter{(C.GtkTreeIter)(*iter)}
22
23 value, err := goModel.GetValue(goIter, int(column))
24 if err != nil {
25 return gbool(true)
26 }
27
28 str, _ := value.GetString()
29 if str == "" {
30 return gbool(true)
31 }
32
33 subStr := C.GoString((*C.char)(key))
34 res := strings.Contains(str, subStr)
35 return gbool(!res)
36 }
37
3813 //export goBuilderConnect
39 func goBuilderConnect(builder *C.GtkBuilder,
14 func goBuilderConnect(
15 builder *C.GtkBuilder,
4016 object *C.GObject,
4117 signal_name *C.gchar,
4218 handler_name *C.gchar,
6945 gobj.Connect(s, handler)
7046 }
7147
72 //export goPageSetupDone
73 func goPageSetupDone(setup *C.GtkPageSetup,
74 data C.gpointer) {
75
76 id := int(uintptr(data))
77
78 pageSetupDoneCallbackRegistry.Lock()
79 r := pageSetupDoneCallbackRegistry.m[id]
80 delete(pageSetupDoneCallbackRegistry.m, id)
81 pageSetupDoneCallbackRegistry.Unlock()
82
83 obj := glib.Take(unsafe.Pointer(setup))
84 r.fn(wrapPageSetup(obj), r.data)
85
48 //export goTreeViewSearchEqualFunc
49 func goTreeViewSearchEqualFunc(model *C.GtkTreeModel, column C.gint, key *C.gchar, iter *C.GtkTreeIter, data C.gpointer) C.gboolean {
50 fn := callback.Get(uintptr(data)).(TreeViewSearchEqualFunc)
51 return gbool(fn(
52 wrapTreeModel(glib.Take(unsafe.Pointer(model))),
53 int(column),
54 C.GoString(key),
55 &TreeIter{(C.GtkTreeIter)(*iter)},
56 ))
8657 }
8758
88 //export goPrintSettings
89 func goPrintSettings(key *C.gchar,
90 value *C.gchar,
91 userData C.gpointer) {
92
93 id := int(uintptr(userData))
94
95 printSettingsCallbackRegistry.Lock()
96 r := printSettingsCallbackRegistry.m[id]
97 // TODO: figure out a way to determine when we can clean up
98 //delete(printSettingsCallbackRegistry.m, id)
99 printSettingsCallbackRegistry.Unlock()
100
101 r.fn(C.GoString((*C.char)(key)), C.GoString((*C.char)(value)), r.userData)
102
59 //export goTreeModelFilterVisibleFunc
60 func goTreeModelFilterVisibleFunc(model *C.GtkTreeModel, iter *C.GtkTreeIter, data C.gpointer) C.gboolean {
61 goIter := &TreeIter{(C.GtkTreeIter)(*iter)}
62 fn := callback.Get(uintptr(data)).(TreeModelFilterVisibleFunc)
63 return gbool(fn(
64 wrapTreeModel(glib.Take(unsafe.Pointer(model))),
65 goIter,
66 ))
10367 }
10468
105 //export goTreeModelFilterFuncs
106 func goTreeModelFilterFuncs(filter *C.GtkTreeModelFilter, iter *C.GtkTreeIter, data C.gpointer) C.gboolean {
107 id := int(uintptr(data))
108
109 treeModelVisibleFilterFuncRegistry.Lock()
110 r := treeModelVisibleFilterFuncRegistry.m[id]
111 treeModelVisibleFilterFuncRegistry.Unlock()
112
113 goIter := &TreeIter{(C.GtkTreeIter)(*iter)}
114 return gbool(r.fn(
115 wrapTreeModelFilter(glib.Take(unsafe.Pointer(filter))),
116 goIter,
117 r.userData))
118 }
119
120 //export goTreeSortableSortFuncs
121 func goTreeSortableSortFuncs(model *C.GtkTreeModel, a, b *C.GtkTreeIter, data C.gpointer) C.gint {
122 id := int(uintptr(data))
123
124 treeStoreSortFuncRegistry.Lock()
125 r := treeStoreSortFuncRegistry.m[id]
126 treeStoreSortFuncRegistry.Unlock()
127
128 goIterA := &TreeIter{(C.GtkTreeIter)(*a)}
129 goIterB := &TreeIter{(C.GtkTreeIter)(*b)}
130
131 return C.gint(r.fn(wrapTreeModel(glib.Take(unsafe.Pointer(model))), goIterA, goIterB, r.userData))
69 //export goTreeSortableSortFunc
70 func goTreeSortableSortFunc(model *C.GtkTreeModel, a, b *C.GtkTreeIter, data C.gpointer) C.gint {
71 fn := callback.Get(uintptr(data)).(TreeIterCompareFunc)
72 return C.gint(fn(
73 wrapTreeModel(glib.Take(unsafe.Pointer(model))),
74 &TreeIter{(C.GtkTreeIter)(*a)},
75 &TreeIter{(C.GtkTreeIter)(*b)},
76 ))
13277 }
13378
13479 //export goTreeModelForeachFunc
13580 func goTreeModelForeachFunc(model *C.GtkTreeModel, path *C.GtkTreePath, iter *C.GtkTreeIter, data C.gpointer) C.gboolean {
136 id := int(uintptr(data))
137
138 treeModelForeachFuncRegistry.Lock()
139 r := treeModelForeachFuncRegistry.m[id]
140 treeModelForeachFuncRegistry.Unlock()
141
142 goPath := &TreePath{(*C.GtkTreePath)(path)}
143 goIter := &TreeIter{(C.GtkTreeIter)(*iter)}
144 return gbool(r.fn(
81 fn := callback.Get(uintptr(data)).(TreeModelForeachFunc)
82 return gbool(fn(
14583 wrapTreeModel(glib.Take(unsafe.Pointer(model))),
146 goPath,
147 goIter,
148 r.userData))
84 &TreePath{(*C.GtkTreePath)(path)},
85 &TreeIter{(C.GtkTreeIter)(*iter)},
86 ))
14987 }
15088
15189 //export goTreeSelectionForeachFunc
15290 func goTreeSelectionForeachFunc(model *C.GtkTreeModel, path *C.GtkTreePath, iter *C.GtkTreeIter, data C.gpointer) {
153 id := int(uintptr(data))
91 fn := callback.Get(uintptr(data)).(TreeSelectionForeachFunc)
92 fn(
93 wrapTreeModel(glib.Take(unsafe.Pointer(model))),
94 &TreePath{(*C.GtkTreePath)(path)},
95 &TreeIter{(C.GtkTreeIter)(*iter)},
96 )
97 }
15498
155 treeSelectionForeachFuncRegistry.Lock()
156 r := treeSelectionForeachFuncRegistry.m[id]
157 treeSelectionForeachFuncRegistry.Unlock()
158
159 goPath := &TreePath{(*C.GtkTreePath)(path)}
160 goIter := &TreeIter{(C.GtkTreeIter)(*iter)}
161
162 r.fn(
99 //export goTreeSelectionFunc
100 func goTreeSelectionFunc(selection *C.GtkTreeSelection, model *C.GtkTreeModel, path *C.GtkTreePath, selected C.gboolean, data C.gpointer) C.gboolean {
101 fn := callback.Get(uintptr(data)).(TreeSelectionFunc)
102 return gbool(fn(
103 wrapTreeSelection(glib.Take(unsafe.Pointer(selection))),
163104 wrapTreeModel(glib.Take(unsafe.Pointer(model))),
164 goPath,
165 goIter,
166 r.userData)
105 &TreePath{(*C.GtkTreePath)(path)},
106 gobool(selected),
107 ))
167108 }
77 "unsafe"
88
99 "github.com/gotk3/gotk3/glib"
10 "github.com/gotk3/gotk3/internal/callback"
1011 )
11
12 // TODO: figure out a way to determine when we can clean up
1312
1413 //export goListBoxFilterFuncs
1514 func goListBoxFilterFuncs(row *C.GtkListBoxRow, userData C.gpointer) C.gboolean {
16 id := int(uintptr(userData))
17
18 listBoxFilterFuncRegistry.Lock()
19 r := listBoxFilterFuncRegistry.m[id]
20 //delete(listBoxFilterFuncRegistry.m, id)
21 listBoxFilterFuncRegistry.Unlock()
22
23 return gbool(r.fn(wrapListBoxRow(glib.Take(unsafe.Pointer(row))), r.userData))
15 fn := callback.Get(uintptr(userData)).(ListBoxFilterFunc)
16 return gbool(fn(wrapListBoxRow(glib.Take(unsafe.Pointer(row)))))
2417 }
2518
2619 //export goListBoxHeaderFuncs
2720 func goListBoxHeaderFuncs(row *C.GtkListBoxRow, before *C.GtkListBoxRow, userData C.gpointer) {
28 id := int(uintptr(userData))
29
30 listBoxHeaderFuncRegistry.Lock()
31 r := listBoxHeaderFuncRegistry.m[id]
32 //delete(listBoxHeaderFuncRegistry.m, id)
33 listBoxHeaderFuncRegistry.Unlock()
34
35 r.fn(wrapListBoxRow(glib.Take(unsafe.Pointer(row))), wrapListBoxRow(glib.Take(unsafe.Pointer(before))), r.userData)
21 fn := callback.Get(uintptr(userData)).(ListBoxHeaderFunc)
22 fn(
23 wrapListBoxRow(glib.Take(unsafe.Pointer(row))),
24 wrapListBoxRow(glib.Take(unsafe.Pointer(before))),
25 )
3626 }
3727
3828 //export goListBoxSortFuncs
3929 func goListBoxSortFuncs(row1 *C.GtkListBoxRow, row2 *C.GtkListBoxRow, userData C.gpointer) C.gint {
40 id := int(uintptr(userData))
41
42 listBoxSortFuncRegistry.Lock()
43 r := listBoxSortFuncRegistry.m[id]
44 //delete(listBoxSortFuncRegistry.m, id)
45 listBoxSortFuncRegistry.Unlock()
46
47 return C.gint(r.fn(wrapListBoxRow(glib.Take(unsafe.Pointer(row1))), wrapListBoxRow(glib.Take(unsafe.Pointer(row2))), r.userData))
30 fn := callback.Get(uintptr(userData)).(ListBoxSortFunc)
31 return C.gint(fn(
32 wrapListBoxRow(glib.Take(unsafe.Pointer(row1))),
33 wrapListBoxRow(glib.Take(unsafe.Pointer(row2))),
34 ))
4835 }
0 // Same copyright and license as the rest of the files in this project
1 // +build !gtk_3_6,!gtk_3_8,!gtk_3_10,!gtk_3_12
2
3 package gtk
4
5 // #include <gtk/gtk.h>
6 import "C"
7 import (
8 "unsafe"
9
10 "github.com/gotk3/gotk3/glib"
11 "github.com/gotk3/gotk3/internal/callback"
12 )
13
14 //export goListBoxForEachFuncs
15 func goListBoxForEachFuncs(box *C.GtkListBox, row *C.GtkListBoxRow, userData C.gpointer) {
16 fn := callback.Get(uintptr(userData)).(ListBoxForeachFunc)
17 fn(wrapListBox(glib.Take(unsafe.Pointer(box))), wrapListBoxRow(glib.Take(unsafe.Pointer(row))))
18 }
0 // Same copyright and license as the rest of the files in this project
1 // +build !gtk_3_6,!gtk_3_8,!gtk_3_10,!gtk_3_12,!gtk_3_14
2
3 package gtk
4
5 // #include <gtk/gtk.h>
6 import "C"
7 import "github.com/gotk3/gotk3/internal/callback"
8
9 //export goListBoxCreateWidgetFuncs
10 func goListBoxCreateWidgetFuncs(item, userData C.gpointer) {
11 fn := callback.Get(uintptr(userData)).(ListBoxCreateWidgetFunc)
12 fn(uintptr(item))
13 }
1010 // #include "gtk_since_3_10.go.h"
1111 import "C"
1212 import (
13 "sync"
13 "errors"
1414 "unsafe"
1515
16 "github.com/gotk3/gotk3/cairo"
1617 "github.com/gotk3/gotk3/gdk"
1718 "github.com/gotk3/gotk3/glib"
19 "github.com/gotk3/gotk3/internal/callback"
20 "github.com/gotk3/gotk3/pango"
1821 )
1922
2023 func init() {
5558 ALIGN_BASELINE Align = C.GTK_ALIGN_BASELINE
5659 )
5760
61 // ImageType
62 const (
63 IMAGE_SURFACE ImageType = C.GTK_IMAGE_SURFACE
64 )
65
5866 // RevealerTransitionType is a representation of GTK's GtkRevealerTransitionType.
5967 type RevealerTransitionType int
6068
92100 }
93101
94102 /*
103 * GtkWidget
104 */
105
106 // TODO:
107 // gtk_widget_get_composite_name().
108
109 /*
110 * GtkImage
111 */
112
113 // ImageNewFromSurface is a wrapper around gtk_image_new_from_surface().
114 func ImageNewFromSurface(surface *cairo.Surface) (*Image, error) {
115 c := C.gtk_image_new_from_surface((*C.cairo_surface_t)(surface.GetCSurface()))
116 if c == nil {
117 return nil, nilPtrErr
118 }
119 obj := glib.Take(unsafe.Pointer(c))
120 return wrapImage(obj), nil
121 }
122
123 // SetFromSurface is a wrapper around gtk_image_set_from_surface().
124 func (v *Image) SetFromSurface(surface *cairo.Surface) {
125 csurface := (*C.cairo_surface_t)(surface.GetCSurface())
126 C.gtk_image_set_from_surface(v.native(), csurface)
127 }
128
129 /*
130 * GtkIconTheme
131 */
132
133 // HasIcon is a wrapper around gtk_icon_theme_load_icon_for_scale().
134 func (v *IconTheme) LoadIconForScale(iconName string, size, scale int, flags IconLookupFlags) (*gdk.Pixbuf, error) {
135 cstr := C.CString(iconName)
136 defer C.free(unsafe.Pointer(cstr))
137
138 var err *C.GError = nil
139 c := C.gtk_icon_theme_load_icon_for_scale(v.Theme, (*C.gchar)(cstr), C.gint(size), C.gint(scale), C.GtkIconLookupFlags(flags), &err)
140 if c == nil {
141 defer C.g_error_free(err)
142 return nil, errors.New(goString(err.message))
143 }
144 return &gdk.Pixbuf{glib.Take(unsafe.Pointer(c))}, nil
145 }
146
147 /*
148 * GtkEntry
149 */
150
151 // GetTabs is a wrapper around gtk_entry_get_tabs().
152 func (v *Entry) GetTabs() (*pango.TabArray, error) {
153 c := C.gtk_entry_get_tabs(v.native())
154 if c == nil {
155 return nil, nilPtrErr
156 }
157 return pango.WrapTabArray(uintptr(unsafe.Pointer(c))), nil
158 }
159
160 // SetTabs is a wrapper around gtk_entry_set_tabs().
161 func (v *Entry) SetTabs(tabs *pango.TabArray) {
162 C.gtk_entry_set_tabs(v.native(), (*C.PangoTabArray)(unsafe.Pointer(tabs.Native())))
163 }
164
165 /*
95166 * GtkButton
96167 */
97168
108179 }
109180
110181 /*
182 * GtkBox
183 */
184
185 // TODO:
186 // gtk_box_get_baseline_position().
187 // gtk_box_set_baseline_position().
188
189 /*
111190 * GtkGrid
112191 */
113192
114 // RemoveRow() is a wrapper around gtk_grid_remove_row().
193 // RemoveRow is a wrapper around gtk_grid_remove_row().
115194 func (v *Grid) RemoveRow(position int) {
116195 C.gtk_grid_remove_row(v.native(), C.gint(position))
117196 }
118197
119 // RemoveColumn() is a wrapper around gtk_grid_remove_column().
198 // RemoveColumn is a wrapper around gtk_grid_remove_column().
120199 func (v *Grid) RemoveColumn(position int) {
121200 C.gtk_grid_remove_column(v.native(), C.gint(position))
122201 }
123202
203 // TODO:
204 // gtk_grid_get_baseline_row().
205 // gtk_grid_set_baseline_row().
206 // gtk_grid_get_row_baseline_position().
207 // gtk_grid_set_row_baseline_position().
208
124209 /*
125210 * GtkHeaderBar
126211 */
127212
213 // HeaderBar is a representation of GtkHeaderBar
128214 type HeaderBar struct {
129215 Container
130216 }
145231 }
146232
147233 func wrapHeaderBar(obj *glib.Object) *HeaderBar {
234 if obj == nil {
235 return nil
236 }
237
148238 return &HeaderBar{Container{Widget{glib.InitiallyUnowned{obj}}}}
149239 }
150240
189279 }
190280
191281 // GetCustomTitle is a wrapper around gtk_header_bar_get_custom_title().
192 func (v *HeaderBar) GetCustomTitle() (*Widget, error) {
282 func (v *HeaderBar) GetCustomTitle() (IWidget, error) {
193283 c := C.gtk_header_bar_get_custom_title(v.native())
194284 if c == nil {
195 return nil, nilPtrErr
196 }
197 return wrapWidget(glib.Take(unsafe.Pointer(c))), nil
285 return nil, nil
286 }
287 return castWidget(c)
198288 }
199289
200290 // PackStart is a wrapper around gtk_header_bar_pack_start().
222312 * GtkLabel
223313 */
224314
225 // GetLines() is a wrapper around gtk_label_get_lines().
315 // GetLines is a wrapper around gtk_label_get_lines().
226316 func (v *Label) GetLines() int {
227317 c := C.gtk_label_get_lines(v.native())
228318 return int(c)
229319 }
230320
231 // SetLines() is a wrapper around gtk_label_set_lines().
321 // SetLines is a wrapper around gtk_label_set_lines().
232322 func (v *Label) SetLines(lines int) {
233323 C.gtk_label_set_lines(v.native(), C.gint(lines))
234324 }
258348 }
259349
260350 func wrapListBox(obj *glib.Object) *ListBox {
351 if obj == nil {
352 return nil
353 }
354
261355 return &ListBox{Container{Widget{glib.InitiallyUnowned{obj}}}}
262356 }
263357
366460 C.gtk_list_box_invalidate_sort(v.native())
367461 }
368462
369 type ListBoxFilterFunc func(row *ListBoxRow, userData uintptr) bool
370
371 type listBoxFilterFuncData struct {
372 fn ListBoxFilterFunc
373 userData uintptr
374 }
375
376 var (
377 listBoxFilterFuncRegistry = struct {
378 sync.RWMutex
379 next int
380 m map[int]listBoxFilterFuncData
381 }{
382 next: 1,
383 m: make(map[int]listBoxFilterFuncData),
384 }
385 )
386
387 func (v *ListBox) SetFilterFunc(fn ListBoxFilterFunc, userData uintptr) {
388 listBoxFilterFuncRegistry.Lock()
389 id := listBoxFilterFuncRegistry.next
390 listBoxFilterFuncRegistry.next++
391 listBoxFilterFuncRegistry.m[id] = listBoxFilterFuncData{fn: fn, userData: userData}
392 listBoxFilterFuncRegistry.Unlock()
393
394 C._gtk_list_box_set_filter_func(v.native(), C.gpointer(uintptr(id)))
395 }
396
397 type ListBoxHeaderFunc func(row *ListBoxRow, before *ListBoxRow, userData uintptr)
398
399 type listBoxHeaderFuncData struct {
400 fn ListBoxHeaderFunc
401 userData uintptr
402 }
403
404 var (
405 listBoxHeaderFuncRegistry = struct {
406 sync.RWMutex
407 next int
408 m map[int]listBoxHeaderFuncData
409 }{
410 next: 1,
411 m: make(map[int]listBoxHeaderFuncData),
412 }
413 )
414
415 func (v *ListBox) SetHeaderFunc(fn ListBoxHeaderFunc, userData uintptr) {
416 listBoxHeaderFuncRegistry.Lock()
417 id := listBoxHeaderFuncRegistry.next
418 listBoxHeaderFuncRegistry.next++
419 listBoxHeaderFuncRegistry.m[id] = listBoxHeaderFuncData{fn: fn, userData: userData}
420 listBoxHeaderFuncRegistry.Unlock()
421
422 C._gtk_list_box_set_header_func(v.native(), C.gpointer(uintptr(id)))
423 }
424
425 type ListBoxSortFunc func(row1 *ListBoxRow, row2 *ListBoxRow, userData uintptr) int
426
427 type listBoxSortFuncData struct {
428 fn ListBoxSortFunc
429 userData uintptr
430 }
431
432 var (
433 listBoxSortFuncRegistry = struct {
434 sync.RWMutex
435 next int
436 m map[int]listBoxSortFuncData
437 }{
438 next: 1,
439 m: make(map[int]listBoxSortFuncData),
440 }
441 )
442
443 func (v *ListBox) SetSortFunc(fn ListBoxSortFunc, userData uintptr) {
444 listBoxSortFuncRegistry.Lock()
445 id := listBoxSortFuncRegistry.next
446 listBoxSortFuncRegistry.next++
447 listBoxSortFuncRegistry.m[id] = listBoxSortFuncData{fn: fn, userData: userData}
448 listBoxSortFuncRegistry.Unlock()
449
450 C._gtk_list_box_set_sort_func(v.native(), C.gpointer(uintptr(id)))
463 // ListBoxFilterFunc is a representation of GtkListBoxFilterFunc
464 type ListBoxFilterFunc func(row *ListBoxRow) bool
465
466 // SetFilterFunc is a wrapper around gtk_list_box_set_filter_func
467 func (v *ListBox) SetFilterFunc(fn ListBoxFilterFunc) {
468 C._gtk_list_box_set_filter_func(v.native(), C.gpointer(callback.Assign(fn)))
469 }
470
471 // ListBoxHeaderFunc is a representation of GtkListBoxUpdateHeaderFunc
472 type ListBoxHeaderFunc func(row *ListBoxRow, before *ListBoxRow)
473
474 // SetHeaderFunc is a wrapper around gtk_list_box_set_header_func
475 func (v *ListBox) SetHeaderFunc(fn ListBoxHeaderFunc) {
476 C._gtk_list_box_set_header_func(v.native(), C.gpointer(callback.Assign(fn)))
477 }
478
479 // ListBoxSortFunc is a representation of GtkListBoxSortFunc
480 type ListBoxSortFunc func(row1 *ListBoxRow, row2 *ListBoxRow) int
481
482 // SetSortFunc is a wrapper around gtk_list_box_set_sort_func
483 func (v *ListBox) SetSortFunc(fn ListBoxSortFunc) {
484 C._gtk_list_box_set_sort_func(v.native(), C.gpointer(callback.Assign(fn)))
451485 }
452486
453487 // DragHighlightRow is a wrapper around gtk_list_box_drag_highlight_row()
455489 C.gtk_list_box_drag_highlight_row(v.native(), row.native())
456490 }
457491
492 // DragUnhighlightRow is a wrapper around gtk_list_box_drag_unhighlight_row().
493 func (v *ListBox) DragUnhighlightRow() {
494 C.gtk_list_box_drag_unhighlight_row(v.native())
495 }
496
458497 /*
459498 * GtkListBoxRow
460499 */
480519 }
481520
482521 func wrapListBoxRow(obj *glib.Object) *ListBoxRow {
522 if obj == nil {
523 return nil
524 }
525
483526 return &ListBoxRow{Bin{Container{Widget{glib.InitiallyUnowned{obj}}}}}
484527 }
485528
529 // ListBoxRowNew is a wrapper around gtk_list_box_row_new().
486530 func ListBoxRowNew() (*ListBoxRow, error) {
487531 c := C.gtk_list_box_row_new()
488532 if c == nil {
497541 }
498542
499543 // GetHeader is a wrapper around gtk_list_box_row_get_header().
500 func (v *ListBoxRow) GetHeader() *Widget {
544 func (v *ListBoxRow) GetHeader() (IWidget, error) {
501545 c := C.gtk_list_box_row_get_header(v.native())
502546 if c == nil {
503 return nil
504 }
505 return wrapWidget(glib.Take(unsafe.Pointer(c)))
506 }
507
508 // SetHeader is a wrapper around gtk_list_box_row_get_header().
547 return nil, nil
548 }
549 return castWidget(c)
550 }
551
552 // SetHeader is a wrapper around gtk_list_box_row_set_header().
509553 func (v *ListBoxRow) SetHeader(header IWidget) {
554 if header == nil {
555 C.gtk_list_box_row_set_header(v.native(), nil)
556 return
557 }
510558 C.gtk_list_box_row_set_header(v.native(), header.toWidget())
511559 }
512560
517565 }
518566
519567 /*
568 * GtkPlacesSidebar
569 */
570
571 // TODO:
572 // gtk_places_sidebar_new().
573 // gtk_places_sidebar_set_open_flags().
574 // gtk_places_sidebar_get_open_flags().
575 // gtk_places_sidebar_set_location().
576 // gtk_places_sidebar_get_location().
577 // gtk_places_sidebar_set_show_desktop().
578 // gtk_places_sidebar_get_show_desktop().
579 // gtk_places_sidebar_add_shortcut().
580 // gtk_places_sidebar_remove_shortcut().
581 // gtk_places_sidebar_list_shortcuts().
582 // gtk_places_sidebar_get_nth_bookmark().
583 // enum GtkPlacesOpenFlags
584
585 /*
520586 * GtkRevealer
521587 */
522588
541607 }
542608
543609 func wrapRevealer(obj *glib.Object) *Revealer {
610 if obj == nil {
611 return nil
612 }
613
544614 return &Revealer{Bin{Container{Widget{glib.InitiallyUnowned{obj}}}}}
545615 }
546616
618688 }
619689
620690 func wrapSearchBar(obj *glib.Object) *SearchBar {
691 if obj == nil {
692 return nil
693 }
694
621695 return &SearchBar{Bin{Container{Widget{glib.InitiallyUnowned{obj}}}}}
622696 }
623697
688762 }
689763
690764 func wrapStack(obj *glib.Object) *Stack {
765 if obj == nil {
766 return nil
767 }
768
691769 return &Stack{Container{Widget{glib.InitiallyUnowned{obj}}}}
692770 }
693771
723801 }
724802
725803 // GetVisibleChild is a wrapper around gtk_stack_get_visible_child().
726 func (v *Stack) GetVisibleChild() *Widget {
804 func (v *Stack) GetVisibleChild() (IWidget, error) {
727805 c := C.gtk_stack_get_visible_child(v.native())
728806 if c == nil {
729 return nil
730 }
731 return wrapWidget(glib.Take(unsafe.Pointer(c)))
807 return nil, nil
808 }
809 return castWidget(c)
732810 }
733811
734812 // SetVisibleChildName is a wrapper around gtk_stack_set_visible_child_name().
784862 c := C.gtk_stack_get_transition_type(v.native())
785863 return StackTransitionType(c)
786864 }
865
866 /*
867 * GtkBuilder
868 */
869
870 // BuilderNewFromFile is a wrapper around gtk_builder_new_from_file().
871 func BuilderNewFromFile(filePath string) (*Builder, error) {
872 cstr := C.CString(filePath)
873 defer C.free(unsafe.Pointer(cstr))
874
875 c := C.gtk_builder_new_from_file((*C.gchar)(cstr))
876 if c == nil {
877 return nil, nilPtrErr
878 }
879
880 obj := glib.Take(unsafe.Pointer(c))
881 return &Builder{obj}, nil
882 }
883
884 // BuilderNewFromResource is a wrapper around gtk_builder_new_from_resource().
885 func BuilderNewFromResource(resourcePath string) (*Builder, error) {
886 cstr := C.CString(resourcePath)
887 defer C.free(unsafe.Pointer(cstr))
888
889 c := C.gtk_builder_new_from_resource((*C.gchar)(cstr))
890 if c == nil {
891 return nil, nilPtrErr
892 }
893
894 obj := glib.Take(unsafe.Pointer(c))
895 return &Builder{obj}, nil
896 }
897
898 // BuilderNewFromString is a wrapper around gtk_builder_new_from_string().
899 func BuilderNewFromString(resource string) (*Builder, error) {
900 cstr := C.CString(resource)
901 defer C.free(unsafe.Pointer(cstr))
902
903 c := C.gtk_builder_new_from_string((*C.gchar)(cstr), C.gssize(len(resource)))
904 if c == nil {
905 return nil, nilPtrErr
906 }
907
908 obj := glib.Take(unsafe.Pointer(c))
909 return &Builder{obj}, nil
910 }
911
912 // TODO:
913 // gtk_builder_add_callback_symbol
914 // gtk_builder_add_callback_symbols
915 // gtk_builder_lookup_callback_symbol
916 // gtk_builder_set_application
917 // gtk_builder_get_application
1515 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1616 */
1717
18 static GtkHeaderBar *
19 toGtkHeaderBar(void *p)
20 {
21 return (GTK_HEADER_BAR(p));
18 #include "gtk.go.h" // for gotk3_callbackDelete
19 #include <stdlib.h>
20
21 static GtkHeaderBar *toGtkHeaderBar(void *p) { return (GTK_HEADER_BAR(p)); }
22
23 static GtkListBox *toGtkListBox(void *p) { return (GTK_LIST_BOX(p)); }
24
25 static GtkListBoxRow *toGtkListBoxRow(void *p) { return (GTK_LIST_BOX_ROW(p)); }
26
27 static GtkRevealer *toGtkRevealer(void *p) { return (GTK_REVEALER(p)); }
28
29 static GtkSearchBar *toGtkSearchBar(void *p) { return (GTK_SEARCH_BAR(p)); }
30
31 static GtkStack *toGtkStack(void *p) { return (GTK_STACK(p)); }
32
33 static GtkStackSwitcher *toGtkStackSwitcher(void *p) {
34 return (GTK_STACK_SWITCHER(p));
2235 }
2336
24 static GtkListBox *
25 toGtkListBox(void *p)
26 {
27 return (GTK_LIST_BOX(p));
37 extern gboolean goListBoxFilterFuncs(GtkListBoxRow *row, gpointer user_data);
38
39 static inline void _gtk_list_box_set_filter_func(GtkListBox *box,
40 gpointer user_data) {
41 gtk_list_box_set_filter_func(box,
42 (GtkListBoxFilterFunc)(goListBoxFilterFuncs),
43 user_data, (GDestroyNotify)(gotk3_callbackDelete));
2844 }
2945
30 static GtkListBoxRow *
31 toGtkListBoxRow(void *p)
32 {
33 return (GTK_LIST_BOX_ROW(p));
46 extern void goListBoxHeaderFuncs(GtkListBoxRow *row, GtkListBoxRow *before,
47 gpointer user_data);
48
49 static inline void _gtk_list_box_set_header_func(GtkListBox *box,
50 gpointer user_data) {
51 gtk_list_box_set_header_func(
52 box, (GtkListBoxUpdateHeaderFunc)(goListBoxHeaderFuncs), user_data,
53 (GDestroyNotify)(gotk3_callbackDelete));
3454 }
3555
36 static GtkRevealer *
37 toGtkRevealer(void *p)
38 {
39 return (GTK_REVEALER(p));
56 extern gint goListBoxSortFuncs(GtkListBoxRow *row1, GtkListBoxRow *row2,
57 gpointer user_data);
58
59 static inline void _gtk_list_box_set_sort_func(GtkListBox *box,
60 gpointer user_data) {
61 gtk_list_box_set_sort_func(box, (GtkListBoxSortFunc)(goListBoxSortFuncs),
62 user_data, (GDestroyNotify)(gotk3_callbackDelete));
4063 }
41
42 static GtkSearchBar *
43 toGtkSearchBar(void *p)
44 {
45 return (GTK_SEARCH_BAR(p));
46 }
47
48 static GtkStack *
49 toGtkStack(void *p)
50 {
51 return (GTK_STACK(p));
52 }
53
54 static GtkStackSwitcher *
55 toGtkStackSwitcher(void *p)
56 {
57 return (GTK_STACK_SWITCHER(p));
58 }
59
60 extern gboolean goListBoxFilterFuncs (GtkListBoxRow *row,
61 gpointer user_data);
62
63 static inline void _gtk_list_box_set_filter_func(GtkListBox *box, gpointer user_data) {
64 gtk_list_box_set_filter_func(box, (GtkListBoxFilterFunc)(goListBoxFilterFuncs), user_data, NULL);
65 }
66
67 extern void goListBoxHeaderFuncs (GtkListBoxRow *row,
68 GtkListBoxRow *before,
69 gpointer user_data);
70
71 static inline void _gtk_list_box_set_header_func(GtkListBox *box, gpointer user_data) {
72 gtk_list_box_set_header_func(box, (GtkListBoxUpdateHeaderFunc)(goListBoxHeaderFuncs), user_data, NULL);
73 }
74
75 extern gint goListBoxSortFuncs (GtkListBoxRow *row1,
76 GtkListBoxRow *row2,
77 gpointer user_data);
78
79 static inline void _gtk_list_box_set_sort_func(GtkListBox *box, gpointer user_data) {
80 gtk_list_box_set_sort_func(box, (GtkListBoxSortFunc)(goListBoxSortFuncs), user_data, NULL);
81 }
3232 "github.com/gotk3/gotk3/glib"
3333 )
3434
35 /*
36 * Constants
37 */
38
39 const (
40 DIALOG_USE_HEADER_BAR DialogFlags = C.GTK_DIALOG_USE_HEADER_BAR
41 )
42
43 const (
44 STATE_FLAG_LINK StateFlags = C.GTK_STATE_FLAG_LINK
45 STATE_FLAG_VISITED StateFlags = C.GTK_STATE_FLAG_VISITED
46 )
47
3548 const (
3649 BUTTONBOX_EXPAND ButtonBoxStyle = C.GTK_BUTTONBOX_EXPAND
3750 )
5568 }
5669 }
5770
58 // GetLocaleDirection() is a wrapper around gtk_get_locale_direction().
71 // GetLocaleDirection is a wrapper around gtk_get_locale_direction().
5972 func GetLocaleDirection() TextDirection {
6073 c := C.gtk_get_locale_direction()
6174 return TextDirection(c)
6275 }
6376
6477 /*
78 * GtkStack
79 */
80
81 const (
82 STACK_TRANSITION_TYPE_OVER_UP StackTransitionType = C.GTK_STACK_TRANSITION_TYPE_OVER_UP
83 STACK_TRANSITION_TYPE_OVER_DOWN = C.GTK_STACK_TRANSITION_TYPE_OVER_DOWN
84 STACK_TRANSITION_TYPE_OVER_LEFT = C.GTK_STACK_TRANSITION_TYPE_OVER_LEFT
85 STACK_TRANSITION_TYPE_OVER_RIGHT = C.GTK_STACK_TRANSITION_TYPE_OVER_RIGHT
86 STACK_TRANSITION_TYPE_UNDER_UP = C.GTK_STACK_TRANSITION_TYPE_UNDER_UP
87 STACK_TRANSITION_TYPE_UNDER_DOWN = C.GTK_STACK_TRANSITION_TYPE_UNDER_DOWN
88 STACK_TRANSITION_TYPE_UNDER_LEFT = C.GTK_STACK_TRANSITION_TYPE_UNDER_LEFT
89 STACK_TRANSITION_TYPE_UNDER_RIGHT = C.GTK_STACK_TRANSITION_TYPE_UNDER_RIGHT
90 STACK_TRANSITION_TYPE_OVER_UP_DOWN = C.GTK_STACK_TRANSITION_TYPE_OVER_UP_DOWN
91 )
92
93 /*
6594 * Dialog
6695 */
6796
6897 // GetHeaderBar is a wrapper around gtk_dialog_get_header_bar().
69 func (v *Dialog) GetHeaderBar() *Widget {
98 func (v *Dialog) GetHeaderBar() (IWidget, error) {
7099 c := C.gtk_dialog_get_header_bar(v.native())
71100 if c == nil {
72 return nil
73 }
74 return wrapWidget(glib.Take(unsafe.Pointer(c)))
101 return nil, nil
102 }
103 return castWidget(c)
75104 }
76105
77106 /*
78107 * Entry
79108 */
80109
81 // SetMaxWidthChars() is a wrapper around gtk_entry_set_max_width_chars().
110 // SetMaxWidthChars is a wrapper around gtk_entry_set_max_width_chars().
82111 func (v *Entry) SetMaxWidthChars(nChars int) {
83112 C.gtk_entry_set_max_width_chars(v.native(), C.gint(nChars))
84113 }
85114
86 // GetMaxWidthChars() is a wrapper around gtk_entry_get_max_width_chars().
115 // GetMaxWidthChars is a wrapper around gtk_entry_get_max_width_chars().
87116 func (v *Entry) GetMaxWidthChars() int {
88117 c := C.gtk_entry_get_max_width_chars(v.native())
89118 return int(c)
149178 /*
150179 * FlowBox
151180 */
181
182 // FlowBox is a representation of GtkFlowBox
152183 type FlowBox struct {
153184 Container
154185 }
168199 }
169200
170201 func wrapFlowBox(obj *glib.Object) *FlowBox {
202 if obj == nil {
203 return nil
204 }
205
171206 return &FlowBox{Container{Widget{glib.InitiallyUnowned{obj}}}}
172207 }
173208
331366 /*
332367 * FlowBoxChild
333368 */
369
370 // FlowBoxChild is a representation of GtkFlowBoxChild
334371 type FlowBoxChild struct {
335372 Bin
336373 }
350387 }
351388
352389 func wrapFlowBoxChild(obj *glib.Object) *FlowBoxChild {
390 if obj == nil {
391 return nil
392 }
393
353394 return &FlowBoxChild{Bin{Container{Widget{glib.InitiallyUnowned{obj}}}}}
354395 }
355396
380421 }
381422
382423 /*
383 * GtkPopover
424 * GtkPlacesSidebar
425 */
426
427 // TODO:
428 // gtk_places_sidebar_get_local_only().
429 // gtk_places_sidebar_set_local_only().
430
431 /*
432 * GtkPopover
384433 */
385434
386435 // Popover is a representation of GTK's GtkPopover.
403452 }
404453
405454 func wrapPopover(obj *glib.Object) *Popover {
455 if obj == nil {
456 return nil
457 }
458
406459 return &Popover{Bin{Container{Widget{glib.InitiallyUnowned{obj}}}}}
407460 }
408461
421474 return wrapPopover(glib.Take(unsafe.Pointer(c))), nil
422475 }
423476
477 // PopoverNewFromModel is a wrapper around gtk_popover_new_from_model().
478 func PopoverNewFromModel(relative IWidget, model *glib.MenuModel) (*Popover, error) {
479 //Takes relative to widget
480 var c *C.struct__GtkWidget
481
482 mptr := C.toGMenuModel(unsafe.Pointer(model.Native()))
483
484 if relative == nil {
485 c = C.gtk_popover_new_from_model(nil, mptr)
486 } else {
487 c = C.gtk_popover_new_from_model(relative.toWidget(), mptr)
488 }
489 if c == nil {
490 return nil, nilPtrErr
491 }
492 return wrapPopover(glib.Take(unsafe.Pointer(c))), nil
493 }
494
495 // BindModel is a wrapper around gtk_popover_bind_model().
496 func (v *Popover) BindModel(menuModel *glib.MenuModel, actionNamespace string) {
497 cstr := C.CString(actionNamespace)
498 defer C.free(unsafe.Pointer(cstr))
499 C.gtk_popover_bind_model(v.native(), C.toGMenuModel(unsafe.Pointer(menuModel.Native())), (*C.gchar)(cstr))
500 }
501
424502 // SetRelativeTo is a wrapper around gtk_popover_set_relative_to().
425503 func (v *Popover) SetRelativeTo(relative IWidget) {
426504 C.gtk_popover_set_relative_to(v.native(), relative.toWidget())
427505 }
428506
429507 // GetRelativeTo is a wrapper around gtk_popover_get_relative_to().
430 func (v *Popover) GetRelativeTo() *Widget {
508 func (v *Popover) GetRelativeTo() (IWidget, error) {
431509 c := C.gtk_popover_get_relative_to(v.native())
432510 if c == nil {
433 return nil
434 }
435 return wrapWidget(glib.Take(unsafe.Pointer(c)))
511 return nil, nil
512 }
513 return castWidget(c)
436514 }
437515
438516 // SetPointingTo is a wrapper around gtk_popover_set_pointing_to().
441519 }
442520
443521 // GetPointingTo is a wrapper around gtk_popover_get_pointing_to().
444 func (v *Popover) GetPointingTo(rect *gdk.Rectangle) bool {
445 var crect C.GdkRectangle
446 isSet := C.gtk_popover_get_pointing_to(v.native(), &crect)
447 *rect = *gdk.WrapRectangle(uintptr(unsafe.Pointer(&crect)))
448 return gobool(isSet)
522 func (v *Popover) GetPointingTo() (*gdk.Rectangle, bool) {
523 var cRect *C.GdkRectangle
524 isSet := C.gtk_popover_get_pointing_to(v.native(), cRect)
525 rect := gdk.WrapRectangle(uintptr(unsafe.Pointer(cRect)))
526 return rect, gobool(isSet)
449527 }
450528
451529 // SetPosition is a wrapper around gtk_popover_set_position().
459537 return PositionType(c)
460538 }
461539
540 // SetModal is a wrapper around gtk_popover_set_modal().
541 func (v *Popover) SetModal(modal bool) {
542 C.gtk_popover_set_modal(v.native(), gbool(modal))
543 }
544
545 // GetModal is a wrapper around gtk_popover_get_modal().
546 func (v *Popover) GetModal() bool {
547 return gobool(C.gtk_popover_get_modal(v.native()))
548 }
549
462550 /*
463551 * TreePath
464552 */
465553
466 // TreePathNewFromIndicesv() is a wrapper around gtk_tree_path_new_from_indicesv().
554 // TreePathNewFromIndicesv is a wrapper around gtk_tree_path_new_from_indicesv().
467555 func TreePathNewFromIndicesv(indices []int) (*TreePath, error) {
468556 if len(indices) == 0 {
469557 return nil, errors.New("no indice")
1515 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1616 */
1717
18 static GtkFlowBox *
19 toGtkFlowBox(void *p)
20 {
21 return (GTK_FLOW_BOX(p));
18 static GtkFlowBox *toGtkFlowBox(void *p) { return (GTK_FLOW_BOX(p)); }
19
20 static GtkFlowBoxChild *toGtkFlowBoxChild(void *p) {
21 return (GTK_FLOW_BOX_CHILD(p));
2222 }
2323
24 static GtkFlowBoxChild *
25 toGtkFlowBoxChild(void *p)
26 {
27 return (GTK_FLOW_BOX_CHILD(p));
28 }
24 static GMenuModel *toGMenuModel(void *p) { return (G_MENU_MODEL(p)); }
2925
30 static GtkPopover *
31 toGtkPopover(void *p)
32 {
33 return (GTK_POPOVER(p));
34 }
26 static GtkPopover *toGtkPopover(void *p) { return (GTK_POPOVER(p)); }
0 // Same copyright and license as the rest of the files in this project
01 // +build !gtk_3_6,!gtk_3_8,!gtk_3_10,!gtk_3_12
12
23 package gtk
34
45 // #include <stdlib.h>
56 // #include <gtk/gtk.h>
7 // #include "gtk_since_3_14.go.h"
68 import "C"
79 import (
810 "unsafe"
11
12 "github.com/gotk3/gotk3/internal/callback"
913 "github.com/gotk3/gotk3/glib"
14 )
15
16 /*
17 * Constants
18 */
19
20 const (
21 STATE_FLAG_CHECKED StateFlags = C.GTK_STATE_FLAG_CHECKED
22 )
23
24 // IconLookupFlags is a representation of GTK's GtkIconLookupFlags.
25 const (
26 ICON_LOOKUP_FORCE_REGULAR IconLookupFlags = C.GTK_ICON_LOOKUP_FORCE_REGULAR
27 ICON_LOOKUP_FORCE_SYMBOLIC = C.GTK_ICON_LOOKUP_FORCE_SYMBOLIC
28 ICON_LOOKUP_DIR_LTR = C.GTK_ICON_LOOKUP_DIR_LTR
29 ICON_LOOKUP_DIR_RTL = C.GTK_ICON_LOOKUP_DIR_RTL
30 )
31
32 /*
33 * GtkStack
34 */
35
36 const (
37 STACK_TRANSITION_TYPE_OVER_DOWN_UP StackTransitionType = C.GTK_STACK_TRANSITION_TYPE_OVER_DOWN_UP
38 STACK_TRANSITION_TYPE_OVER_LEFT_RIGHT = C.GTK_STACK_TRANSITION_TYPE_OVER_LEFT_RIGHT
39 STACK_TRANSITION_TYPE_OVER_RIGHT_LEFT = C.GTK_STACK_TRANSITION_TYPE_OVER_RIGHT_LEFT
1040 )
1141
1242 /*
2858 C.gtk_list_box_unselect_all(v.native())
2959 }
3060
31 // TODO: gtk_list_box_selected_foreach()
61 // ListBoxForeachFunc is a representation of GtkListBoxForeachFunc
62 type ListBoxForeachFunc func(box *ListBox, row *ListBoxRow) int
63
64 // SelectedForeach is a wrapper around gtk_list_box_selected_foreach().
65 func (v *ListBox) SelectedForeach(fn ListBoxForeachFunc) {
66 id := callback.Assign(fn)
67 defer callback.Delete(id)
68
69 C._gtk_list_box_selected_foreach(v.native(), C.gpointer(id))
70 }
3271
3372 // GetSelectedRows is a wrapper around gtk_list_box_get_selected_rows().
3473 func (v *ListBox) GetSelectedRows() *glib.List {
76115 c := C.gtk_list_box_row_get_selectable(v.native())
77116 return gobool(c)
78117 }
118
119 /*
120 * GtkPlacesSidebar
121 */
122
123 // TODO:
124 // gtk_places_sidebar_get_show_enter_location().
125 // gtk_places_sidebar_set_show_enter_location().
126
127 /*
128 * GtkSwitch
129 */
130
131 // TODO:
132 // gtk_switch_set_state().
133 // gtk_switch_get_state().
0 // Same copyright and license as the rest of the files in this project
1
2 extern void goListBoxForEachFuncs(GtkListBox *box, GtkListBoxRow *row,
3 gpointer user_data);
4
5 static inline void _gtk_list_box_selected_foreach(GtkListBox *box,
6 gpointer user_data) {
7 gtk_list_box_selected_foreach(
8 box, (GtkListBoxForeachFunc)(goListBoxForEachFuncs), user_data);
9 }
33
44 package gtk
55
6 // #include <stdlib.h>
76 // #include <gtk/gtk.h>
87 // #include "gtk_since_3_16.go.h"
98 import "C"
109 import (
1110 "unsafe"
1211
12 "github.com/gotk3/gotk3/gdk"
1313 "github.com/gotk3/gotk3/glib"
1414 )
1515
16 const(
17 POLICY_EXTERNAL PolicyType = C.GTK_POLICY_EXTERNAL
16 const (
17 POLICY_EXTERNAL PolicyType = C.GTK_POLICY_EXTERNAL
1818 )
1919
2020 func init() {
2121 tm := []glib.TypeMarshaler{
2222
2323 // Objects/Interfaces
24 {glib.Type(C.gtk_button_role_get_type()), marshalButtonRole},
2425 {glib.Type(C.gtk_popover_menu_get_type()), marshalPopoverMenu},
2526 {glib.Type(C.gtk_model_button_get_type()), marshalModelButton},
2627 {glib.Type(C.gtk_stack_sidebar_get_type()), marshalStackSidebar},
28 {glib.Type(C.gtk_text_extend_selection_get_type()), marshalTextExtendSelection},
2729 }
2830 glib.RegisterGValueMarshalers(tm)
2931
3739 }
3840 }
3941
42 /*
43 * Constants
44 */
45
46 // ButtonRole is a representation of GTK's GtkButtonRole.
47 type ButtonRole int
48
49 const (
50 BUTTON_ROLE_NORMAL ButtonRole = C.GTK_BUTTON_ROLE_NORMAL
51 BUTTON_ROLE_CHECK ButtonRole = C.GTK_BUTTON_ROLE_CHECK
52 BUTTON_ROLE_RADIO ButtonRole = C.GTK_BUTTON_ROLE_RADIO
53 )
54
55 func marshalButtonRole(p uintptr) (interface{}, error) {
56 c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
57 return ButtonRole(c), nil
58 }
59
60 /*
61 * TextView
62 */
63
64 // TextExtendSelection is a representation of GTK's GtkTextExtendSelection.
65 type TextExtendSelection int
66
67 const (
68 TEXT_EXTEND_SELECTION_WORD TextExtendSelection = C.GTK_TEXT_EXTEND_SELECTION_WORD
69 TEXT_EXTEND_SELECTION_LINE TextExtendSelection = C.GTK_TEXT_EXTEND_SELECTION_LINE
70 )
71
72 func marshalTextExtendSelection(p uintptr) (interface{}, error) {
73 c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
74 return TextExtendSelection(c), nil
75 }
76
77 /*
78 * GtkStack
79 */
80
81 // SetHHomogeneous is a wrapper around gtk_stack_set_hhomogeneous().
82 func (v *Stack) SetHHomogeneous(hhomogeneous bool) {
83 C.gtk_stack_set_hhomogeneous(v.native(), gbool(hhomogeneous))
84 }
85
86 // GetHHomogeneous is a wrapper around gtk_stack_get_hhomogeneous().
87 func (v *Stack) GetHHomogeneous() bool {
88 return gobool(C.gtk_stack_get_hhomogeneous(v.native()))
89 }
90
91 // SetVHomogeneous is a wrapper around gtk_stack_set_vhomogeneous().
92 func (v *Stack) SetVHomogeneous(vhomogeneous bool) {
93 C.gtk_stack_set_vhomogeneous(v.native(), gbool(vhomogeneous))
94 }
95
96 // GetVHomogeneous is a wrapper around gtk_stack_get_vhomogeneous().
97 func (v *Stack) GetVHomogeneous() bool {
98 return gobool(C.gtk_stack_get_vhomogeneous(v.native()))
99 }
100
101 /*
102 * GtkNotebook
103 */
104
105 // DetachTab is a wrapper around gtk_notebook_detach_tab().
106 func (v *Notebook) DetachTab(child IWidget) {
107 C.gtk_notebook_detach_tab(v.native(), child.toWidget())
108 }
109
110 /*
111 * GtkListBox
112 */
113
114 // ListBoxCreateWidgetFunc is a representation of GtkListBoxCreateWidgetFunc.
115 type ListBoxCreateWidgetFunc func(item interface{}) int
116
117 /*
118 * GtkScrolledWindow
119 */
120
40121 // SetOverlayScrolling is a wrapper around gtk_scrolled_window_set_overlay_scrolling().
41122 func (v *ScrolledWindow) SetOverlayScrolling(scrolling bool) {
42123 C.gtk_scrolled_window_set_overlay_scrolling(v.native(), gbool(scrolling))
47128 return gobool(C.gtk_scrolled_window_get_overlay_scrolling(v.native()))
48129 }
49130
131 /*
132 * GtkPaned
133 */
134
50135 // SetWideHandle is a wrapper around gtk_paned_set_wide_handle().
51136 func (v *Paned) SetWideHandle(wide bool) {
52137 C.gtk_paned_set_wide_handle(v.native(), gbool(wide))
56141 func (v *Paned) GetWideHandle() bool {
57142 return gobool(C.gtk_paned_get_wide_handle(v.native()))
58143 }
144
145 /*
146 * GtkLabel
147 */
59148
60149 // GetXAlign is a wrapper around gtk_label_get_xalign().
61150 func (v *Label) GetXAlign() float64 {
81170
82171 /*
83172 * GtkModelButton
84 */
173 */
85174
86175 // ModelButton is a representation of GTK's GtkModelButton.
87176 type ModelButton struct {
88177 Button
89 }
90
91 func (v *ModelButton) native() *C.GtkModelButton {
92 if v == nil || v.GObject == nil {
93 return nil
94 }
95
96 p := unsafe.Pointer(v.GObject)
97 return C.toGtkModelButton(p)
98 }
99
100 func marshalModelButton(p uintptr) (interface{}, error) {
101 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
102 return wrapModelButton(glib.Take(unsafe.Pointer(c))), nil
103 }
104
105 func wrapModelButton(obj *glib.Object) *ModelButton {
106 actionable := wrapActionable(obj)
107 return &ModelButton{Button{Bin{Container{Widget{glib.InitiallyUnowned{obj}}}}, actionable}}
108 }
109
110 // ModelButtonNew is a wrapper around gtk_model_button_new
111 func ModelButtonNew() (*ModelButton, error) {
112 c := C.gtk_model_button_new()
113 if c == nil {
114 return nil, nilPtrErr
115 }
116 return wrapModelButton(glib.Take(unsafe.Pointer(c))), nil
117 }
178 }
179
180 func (v *ModelButton) native() *C.GtkModelButton {
181 if v == nil || v.GObject == nil {
182 return nil
183 }
184
185 p := unsafe.Pointer(v.GObject)
186 return C.toGtkModelButton(p)
187 }
188
189 func marshalModelButton(p uintptr) (interface{}, error) {
190 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
191 return wrapModelButton(glib.Take(unsafe.Pointer(c))), nil
192 }
193
194 func wrapModelButton(obj *glib.Object) *ModelButton {
195 if obj == nil {
196 return nil
197 }
198
199 actionable := wrapActionable(obj)
200 return &ModelButton{Button{Bin{Container{Widget{glib.InitiallyUnowned{obj}}}}, actionable}}
201 }
202
203 // ModelButtonNew is a wrapper around gtk_model_button_new
204 func ModelButtonNew() (*ModelButton, error) {
205 c := C.gtk_model_button_new()
206 if c == nil {
207 return nil, nilPtrErr
208 }
209 return wrapModelButton(glib.Take(unsafe.Pointer(c))), nil
210 }
118211
119212 /*
120213 * GtkPopoverMenu
140233 }
141234
142235 func wrapPopoverMenu(obj *glib.Object) *PopoverMenu {
236 if obj == nil {
237 return nil
238 }
239
143240 return &PopoverMenu{Popover{Bin{Container{Widget{glib.InitiallyUnowned{obj}}}}}}
144241 }
145242
185282 }
186283
187284 func wrapStackSidebar(obj *glib.Object) *StackSidebar {
285 if obj == nil {
286 return nil
287 }
288
188289 return &StackSidebar{Bin{Container{Widget{glib.InitiallyUnowned{obj}}}}}
189290 }
190291
197298 return wrapStackSidebar(glib.Take(unsafe.Pointer(c))), nil
198299 }
199300
301 // SetStack is a wrapper around gtk_stack_sidebar_set_stack().
200302 func (v *StackSidebar) SetStack(stack *Stack) {
201303 C.gtk_stack_sidebar_set_stack(v.native(), stack.native())
202304 }
203305
306 // GetStack is a wrapper around gtk_stack_sidebar_get_stack().
204307 func (v *StackSidebar) GetStack() *Stack {
205308 c := C.gtk_stack_sidebar_get_stack(v.native())
206309 if c == nil {
209312 return wrapStack(glib.Take(unsafe.Pointer(c)))
210313 }
211314
315 /*
316 * GtkEntry
317 */
318
212319 // GrabFocusWithoutSelecting is a wrapper for gtk_entry_grab_focus_without_selecting()
213320 func (v *Entry) GrabFocusWithoutSelecting() {
214321 C.gtk_entry_grab_focus_without_selecting(v.native())
215322 }
216323
217 // InsertMarkup() is a wrapper around gtk_text_buffer_insert_markup()
324 /*
325 * GtkSearchEntry
326 */
327
328 // HandleEvent is a wrapper around gtk_search_entry_handle_event().
329 func (v *SearchEntry) HandleEvent(event *gdk.Event) {
330 e := (*C.GdkEvent)(unsafe.Pointer(event.Native()))
331 C.gtk_search_entry_handle_event(v.native(), e)
332 }
333
334 /*
335 * GtkTextBuffer
336 */
337
338 // InsertMarkup is a wrapper around gtk_text_buffer_insert_markup()
218339 func (v *TextBuffer) InsertMarkup(start *TextIter, text string) {
219340 cstr := C.CString(text)
220341 defer C.free(unsafe.Pointer(cstr))
221342 C.gtk_text_buffer_insert_markup(v.native(), (*C.GtkTextIter)(start), (*C.gchar)(cstr), C.gint(len(text)))
222343 }
344
345 /*
346 * CssProvider
347 */
348
349 // LoadFromResource is a wrapper around gtk_css_provider_load_from_resource().
350 //
351 // See: https://developer.gnome.org/gtk3/stable/GtkCssProvider.html#gtk-css-provider-load-from-resource
352 func (v *CssProvider) LoadFromResource(path string) {
353 cpath := C.CString(path)
354 defer C.free(unsafe.Pointer(cpath))
355 C.gtk_css_provider_load_from_resource(v.native(), (*C.gchar)(cpath))
356 }
357
358 /*
359 * GtkTextView
360 */
361
362 // SetMonospace is a wrapper around gtk_text_view_set_monospace()
363 func (v *TextView) SetMonospace(monospace bool) {
364 C.gtk_text_view_set_monospace(v.native(), gbool(monospace))
365 }
366
367 // GetMonospace is a wrapper around gtk_text_view_get_monospace()
368 func (v *TextView) GetMonospace() bool {
369 return gobool(C.gtk_text_view_get_monospace(v.native()))
370 }
1515 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1616 */
1717
18 static GtkModelButton *
19 toGtkModelButton(void *mb)
20 {
21 return (GTK_MODEL_BUTTON(mb));
18 #pragma once
19
20 #include "gtk.go.h"
21 #include <stdlib.h> // for gotk3_callbackDelete
22
23 static GListModel *toGListModel(void *p) { return (G_LIST_MODEL(p)); }
24
25 static GtkModelButton *toGtkModelButton(void *mb) {
26 return (GTK_MODEL_BUTTON(mb));
2227 }
2328
24 static GtkPopoverMenu *
25 toGtkPopoverMenu(void *p)
26 {
27 return (GTK_POPOVER_MENU(p));
29 static GtkPopoverMenu *toGtkPopoverMenu(void *p) {
30 return (GTK_POPOVER_MENU(p));
2831 }
2932
30 static GtkStackSidebar *
31 toGtkStackSidebar(void *p)
32 {
33 return (GTK_STACK_SIDEBAR(p));
33 static GtkStackSidebar *toGtkStackSidebar(void *p) {
34 return (GTK_STACK_SIDEBAR(p));
3435 }
3536
36 static GtkGLArea *
37 toGtkGLArea(void *p)
38 {
39 return (GTK_GL_AREA(p));
40 }
37 static GtkGLArea *toGtkGLArea(void *p) { return (GTK_GL_AREA(p)); }
38
39 extern void goListBoxCreateWidgetFuncs(gpointer item, gpointer user_data);
40
41 static inline void _gtk_list_box_bind_model(GtkListBox *box, GListModel *model,
42 gpointer user_data) {
43 gtk_list_box_bind_model(
44 box, model, (GtkListBoxCreateWidgetFunc)(goListBoxCreateWidgetFuncs),
45 user_data, (GDestroyNotify)(gotk3_callbackDelete));
46 }
0 // Same copyright and license as the rest of the files in this project.
1 // This file is normally only compiled for GTK 3.16 and 3.18.
2 // +build !gtk_3_6,!gtk_3_8,!gtk_3_10,!gtk_3_12,!gtk_3_14,gtk_deprecated gtk_3_16 gtk_3_18
3
4 package gtk
5
6 // #include <gtk/gtk.h>
7 import "C"
8
9 /*
10 * GtkPopover
11 */
12
13 // SetTransitionsEnabled is a wrapper gtk_popover_set_transitions_enabled().
14 func (v *Popover) SetTransitionsEnabled(transitionsEnabled bool) {
15 C.gtk_popover_set_transitions_enabled(v.native(), gbool(transitionsEnabled))
16 }
17
18 // GetTransitionsEnabled is a wrapper gtk_popover_get_transitions_enabled().
19 func (v *Popover) GetTransitionsEnabled() bool {
20 return gobool(C.gtk_popover_get_transitions_enabled(v.native()))
21 }
0 // Same copyright and license as the rest of the files in this project
1 // The code in this file is only for GTK+ version 3.16+, as well as Glib version 2.44+
2
3 // +build !gtk_3_6,!gtk_3_8,!gtk_3_10,!gtk_3_12,!gtk_3_14,!glib_2_40,!glib_2_42
4
5 package gtk
6
7 // #include <gtk/gtk.h>
8 // #include "gtk_since_3_16.go.h"
9 import "C"
10 import (
11 "unsafe"
12
13 "github.com/gotk3/gotk3/internal/callback"
14 "github.com/gotk3/gotk3/glib"
15 )
16
17 // BindModel is a wrapper around gtk_list_box_bind_model().
18 func (v *ListBox) BindModel(listModel *glib.ListModel, createWidgetFunc ListBoxCreateWidgetFunc) {
19 C._gtk_list_box_bind_model(
20 v.native(),
21 C.toGListModel(unsafe.Pointer(listModel.Native())),
22 C.gpointer(callback.Assign(createWidgetFunc)),
23 )
24 }
0 // +build !gtk_3_6,!gtk_3_8,!gtk_3_10,!gtk_3_12,!gtk_3_14,!gtk_3_16,gtk_3_18
0 // +build !gtk_3_6,!gtk_3_8,!gtk_3_10,!gtk_3_12,!gtk_3_14,!gtk_3_16
11
22 // See: https://developer.gnome.org/gtk3/3.18/api-index-3-18.html
33
88
99 // #include <gtk/gtk.h>
1010 import "C"
11 import (
12 "unsafe"
1311
14 "github.com/gotk3/gotk3/glib"
15 )
12 /*
13 * GtkStack
14 */
15
16 // TODO:
17 // gtk_stack_get_interpolate_size().
18 // gtk_stack_set_interpolate_size().
19
20 /*
21 * GtkRadioMenuItem
22 */
23
24 // JoinGroup is a wrapper around gtk_radio_menu_item_join_group().
25 func (v *RadioMenuItem) JoinGroup(group_source *RadioMenuItem) {
26 C.gtk_radio_menu_item_join_group(v.native(), group_source.native())
27 }
28
29 /*
30 * GtkOverlay
31 */
1632
1733 // ReorderOverlay() is a wrapper around gtk_overlay_reorder_overlay().
1834 func (v *Overlay) ReorderOverlay(child IWidget, position int) {
19 C.gtk_overlay_reorder_overlay(v.native(), child.toWidget(), C.gint(position))
35 C.gtk_overlay_reorder_overlay(v.native(), child.toWidget(), C.int(position))
2036 }
2137
2238 // GetOverlayPassThrough() is a wrapper around gtk_overlay_get_overlay_pass_through().
3046 C.gtk_overlay_set_overlay_pass_through(v.native(), widget.toWidget(), gbool(passThrough))
3147 }
3248
49 /*
50 * GtkPlacesSidebar
51 */
52
53 // TODO:
54 // gtk_places_sidebar_set_show_recent().
55 // gtk_places_sidebar_get_show_recent().
56 // gtk_places_sidebar_get_show_trash().
57 // gtk_places_sidebar_set_show_trash().
58 // gtk_places_sidebar_get_show_other_locations().
59 // gtk_places_sidebar_set_show_other_locations().
60 // gtk_places_sidebar_set_drop_targets_visible().
61
62 /*
63 * GtkPopover
64 */
65
3366 // SetDefaultWidget is a wrapper around gtk_popover_set_default_widget().
3467 func (p *Popover) SetDefaultWidget(widget IWidget) {
3568 C.gtk_popover_set_default_widget(p.native(), widget.toWidget())
3669 }
3770
3871 // GetDefaultWidget is a wrapper around gtk_popover_get_default_widget().
39 func (p *Popover) GetDefaultWidget() *Widget {
72 func (p *Popover) GetDefaultWidget() (IWidget, error) {
4073 w := C.gtk_popover_get_default_widget(p.native())
4174 if w == nil {
42 return nil
75 return nil, nil
4376 }
44 return &Widget{glib.InitiallyUnowned{glib.Take(unsafe.Pointer(w))}}
77 return castWidget(w)
4578 }
79
80 /*
81 * GtkTextView
82 */
83
84 // SetTopMargin is a wrapper around gtk_text_view_set_top_margin().
85 func (v *TextView) SetTopMargin(topMargin int) {
86 C.gtk_text_view_set_top_margin(v.native(), C.gint(topMargin))
87 }
88
89 // GetTopMargin is a wrapper around gtk_text_view_get_top_margin().
90 func (v *TextView) GetTopMargin() int {
91 return int(C.gtk_text_view_get_top_margin(v.native()))
92 }
93
94 // SetBottomMargin is a wrapper around gtk_text_view_set_bottom_margin().
95 func (v *TextView) SetBottomMargin(bottomMargin int) {
96 C.gtk_text_view_set_bottom_margin(v.native(), C.gint(bottomMargin))
97 }
98
99 // GetBottomMargin is a wrapper around gtk_text_view_get_bottom_margin().
100 func (v *TextView) GetBottomMargin() int {
101 return int(C.gtk_text_view_get_bottom_margin(v.native()))
102 }
1313 "github.com/gotk3/gotk3/glib"
1414 )
1515
16 func init() {
17 tm := []glib.TypeMarshaler{
18 // Enums
19 {glib.Type(C.gtk_popover_constraint_get_type()), marshalPopoverConstraint},
20 }
21 glib.RegisterGValueMarshalers(tm)
22 }
23
24 /*
25 * Constants
26 */
27
28 // PopoverConstraint is a representation of GTK's GtkPopoverConstraint.
29 type PopoverConstraint int
30
31 const (
32 POPOVER_CONSTRAINT_NONE PopoverConstraint = C.GTK_POPOVER_CONSTRAINT_NONE
33 POPOVER_CONSTRAINT_WINDOW PopoverConstraint = C.GTK_POPOVER_CONSTRAINT_WINDOW
34 )
35
36 func marshalPopoverConstraint(p uintptr) (interface{}, error) {
37 c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
38 return PopoverConstraint(c), nil
39 }
40
41 const (
42 STATE_FLAG_DROP_ACTIVE StateFlags = C.GTK_STATE_FLAG_DROP_ACTIVE
43 )
44
1645 /*
1746 * GtkNativeDialog
1847 */
3261 }
3362
3463 func wrapNativeDialog(obj *glib.Object) *NativeDialog {
64 if obj == nil {
65 return nil
66 }
67
3568 return &NativeDialog{glib.InitiallyUnowned{obj}}
3669 }
3770
5184 C.gtk_native_dialog_set_modal(v.native(), gbool(modal))
5285 }
5386
54 // GetModal() is a wrapper around gtk_native_dialog_get_modal().
87 // GetModal is a wrapper around gtk_native_dialog_get_modal().
5588 func (v *NativeDialog) GetModal() bool {
5689 c := C.gtk_native_dialog_get_modal(v.native())
5790 return gobool(c)
6497 C.gtk_native_dialog_set_title(v.native(), (*C.char)(cstr))
6598 }
6699
67 // GetTitle() is a wrapper around gtk_native_dialog_get_title().
100 // GetTitle is a wrapper around gtk_native_dialog_get_title().
68101 func (v *NativeDialog) GetTitle() (string, error) {
69102 return stringReturn((*C.gchar)(C.gtk_native_dialog_get_title(v.native())))
70103 }
71104
72 // SetTransientFor() is a wrapper around gtk_native_dialog_set_transient_for().
105 // SetTransientFor is a wrapper around gtk_native_dialog_set_transient_for().
73106 func (v *NativeDialog) SetTransientFor(parent IWindow) {
74107 var pw *C.GtkWindow = nil
75108 if parent != nil {
78111 C.gtk_native_dialog_set_transient_for(v.native(), pw)
79112 }
80113
81 // GetTransientFor() is a wrapper around gtk_native_dialog_get_transient_for().
114 // GetTransientFor is a wrapper around gtk_native_dialog_get_transient_for().
82115 func (v *NativeDialog) GetTransientFor() (*Window, error) {
83116 c := C.gtk_native_dialog_get_transient_for(v.native())
84117 if c == nil {
125158 }
126159
127160 func wrapFileChooserNativeDialog(obj *glib.Object) *FileChooserNativeDialog {
161 if obj == nil {
162 return nil
163 }
164
128165 fc := wrapFileChooser(obj)
129166 return &FileChooserNativeDialog{NativeDialog{glib.InitiallyUnowned{obj}}, *fc}
130167 }
131168
132169 // FileChooserNativeDialogNew is a wrapper around gtk_file_chooser_native_new().
133 func FileChooserNativeDialogNew(
134 title string,
135 parent IWindow,
136 action FileChooserAction,
137 accept_label string,
138 cancel_label string) (*FileChooserNativeDialog, error) {
170 func FileChooserNativeDialogNew(title string, parent IWindow, action FileChooserAction,
171 accept_label string, cancel_label string) (*FileChooserNativeDialog, error) {
172
139173 c_title := C.CString(title)
140174 defer C.free(unsafe.Pointer(c_title))
175
141176 c_accept_label := C.CString(accept_label)
142177 defer C.free(unsafe.Pointer(c_accept_label))
178
143179 c_cancel_label := C.CString(cancel_label)
144180 defer C.free(unsafe.Pointer(c_cancel_label))
181
182 var w *C.GtkWindow = nil
183 if parent != nil {
184 w = parent.toWindow()
185 }
186
145187 c := C.gtk_file_chooser_native_new(
146 (*C.gchar)(c_title), parent.toWindow(), C.GtkFileChooserAction(action),
188 (*C.gchar)(c_title), w, C.GtkFileChooserAction(action),
147189 (*C.gchar)(c_accept_label), (*C.gchar)(c_cancel_label))
148190 if c == nil {
149191 return nil, nilPtrErr
155197 /*
156198 * FileChooserNative
157199 */
158 func OpenFileChooserNative(title string, parent_window IWindow) *string {
200 func OpenFileChooserNative(title string, parent IWindow) *string {
159201 c_title := C.CString(title)
160202
161203 var native *C.GtkFileChooserNative
162204
205 var w *C.GtkWindow = nil
206 if parent != nil {
207 w = parent.toWindow()
208 }
209
163210 native = C.gtk_file_chooser_native_new((*C.gchar)(c_title),
164 parent_window.toWindow(),
211 w,
165212 C.GtkFileChooserAction(FILE_CHOOSER_ACTION_OPEN),
166213 (*C.gchar)(C.CString("_Open")),
167214 (*C.gchar)(C.CString("_Cancel")))
188235 C.gtk_file_chooser_native_set_accept_label(v.native(), (*C.char)(cstr))
189236 }
190237
191 // GetAcceptLabel() is a wrapper around gtk_file_chooser_native_get_accept_label().
238 // GetAcceptLabel is a wrapper around gtk_file_chooser_native_get_accept_label().
192239 func (v *FileChooserNativeDialog) GetAcceptLabel() (string, error) {
193240 return stringReturn((*C.gchar)(C.gtk_file_chooser_native_get_accept_label(v.native())))
194241 }
200247 C.gtk_file_chooser_native_set_cancel_label(v.native(), (*C.char)(cstr))
201248 }
202249
203 // GetCancelLabel() is a wrapper around gtk_file_chooser_native_get_cancel_label().
250 // GetCancelLabel is a wrapper around gtk_file_chooser_native_get_cancel_label().
204251 func (v *FileChooserNativeDialog) GetCancelLabel() (string, error) {
205252 return stringReturn((*C.gchar)(C.gtk_file_chooser_native_get_cancel_label(v.native())))
206253 }
254
255 /*
256 * GtkTextView
257 */
258
259 // TODO:
260 // gtk_text_view_reset_cursor_blink().
261
262 /*
263 * GtkExpander
264 */
265
266 // TODO:
267 // gtk_expander_set_spacing().
268 // gtk_expander_get_spacing().
269
270 /*
271 * GtkPopover
272 */
273
274 // SetConstrainTo is a wrapper gtk_popover_set_constrain_to().
275 func (v *Popover) SetConstrainTo(constrain PopoverConstraint) {
276 C.gtk_popover_set_constrain_to(v.native(), C.GtkPopoverConstraint(constrain))
277 }
278
279 // GetConstrainTo is a wrapper gtk_popover_get_constrain_to().
280 func (v *Popover) GetConstrainTo() PopoverConstraint {
281 return PopoverConstraint(C.gtk_popover_get_constrain_to(v.native()))
282 }
1919
2020 #include <stdlib.h>
2121
22 static GtkFileChooser *
23 toGtkFileChooser(void *p)
24 {
25 return (GTK_FILE_CHOOSER(p));
22 static GtkFileChooser *toGtkFileChooser(void *p) {
23 return (GTK_FILE_CHOOSER(p));
2624 }
2725
28 static GtkFileChooserNative *
29 toGtkFileChooserNative(void *p)
30 {
31 return (GTK_FILE_CHOOSER_NATIVE(p));
26 static GtkFileChooserNative *toGtkFileChooserNative(void *p) {
27 return (GTK_FILE_CHOOSER_NATIVE(p));
3228 }
3329
34 static GtkNativeDialog *
35 toGtkNativeDialog(void *p)
36 {
37 return (GTK_NATIVE_DIALOG(p));
30 static GtkNativeDialog *toGtkNativeDialog(void *p) {
31 return (GTK_NATIVE_DIALOG(p));
3832 }
0 // +build !gtk_3_6,!gtk_3_8,!gtk_3_10,!gtk_3_12,!gtk_3_14,!gtk_3_16,!gtk_3_18,!gtk_3_20
1
2 // See: https://developer.gnome.org/gtk3/3.22/api-index-3-22.html
3
4 package gtk
5
6 // #include <gtk/gtk.h>
7 import "C"
8
9 // Popup is a wrapper around gtk_popover_popup().
10 func (v *Popover) Popup() {
11 C.gtk_popover_popup(v.native())
12 }
13
14 // Popdown is a wrapper around gtk_popover_popdown().
15 func (v *Popover) Popdown() {
16 C.gtk_popover_popdown(v.native())
17 }
18
19 /*
20 * GtkScrolledWindow
21 */
22
23 // GetMaxContentWidth is a wrapper around gtk_scrolled_window_get_max_content_width().
24 func (v *ScrolledWindow) GetMaxContentWidth() int {
25 c := C.gtk_scrolled_window_get_max_content_width(v.native())
26 return int(c)
27 }
28
29 // SetMaxContentWidth is a wrapper around gtk_scrolled_window_set_max_content_width().
30 func (v *ScrolledWindow) SetMaxContentWidth(width int) {
31 C.gtk_scrolled_window_set_max_content_width(v.native(), C.gint(width))
32 }
33
34 // GetMaxContentHeight is a wrapper around gtk_scrolled_window_get_max_content_height().
35 func (v *ScrolledWindow) GetMaxContentHeight() int {
36 c := C.gtk_scrolled_window_get_max_content_height(v.native())
37 return int(c)
38 }
39
40 // SetMaxContentHeight is a wrapper around gtk_scrolled_window_set_max_content_height().
41 func (v *ScrolledWindow) SetMaxContentHeight(width int) {
42 C.gtk_scrolled_window_set_max_content_height(v.native(), C.gint(width))
43 }
44
45 // GetPropagateNaturalWidth is a wrapper around gtk_scrolled_window_get_propagate_natural_width().
46 func (v *ScrolledWindow) GetPropagateNaturalWidth() bool {
47 c := C.gtk_scrolled_window_get_propagate_natural_width(v.native())
48 return gobool(c)
49 }
50
51 // SetPropagateNaturalWidth is a wrapper around gtk_scrolled_window_set_propagate_natural_width().
52 func (v *ScrolledWindow) SetPropagateNaturalWidth(propagate bool) {
53 C.gtk_scrolled_window_set_propagate_natural_width(v.native(), gbool(propagate))
54 }
55
56 // GetPropagateNaturalHeight is a wrapper around gtk_scrolled_window_get_propagate_natural_height().
57 func (v *ScrolledWindow) GetPropagateNaturalHeight() bool {
58 c := C.gtk_scrolled_window_get_propagate_natural_height(v.native())
59 return gobool(c)
60 }
61
62 // SetPropagateNaturalHeight is a wrapper around gtk_scrolled_window_set_propagate_natural_height().
63 func (v *ScrolledWindow) SetPropagateNaturalHeight(propagate bool) {
64 C.gtk_scrolled_window_set_propagate_natural_height(v.native(), gbool(propagate))
65 }
0 // +build !gtk_3_6,!gtk_3_8,!gtk_3_10,!gtk_3_12,!gtk_3_14,!gtk_3_16,!gtk_3_18,!gtk_3_20,!gtk_3_22
1
2 package gtk
3
4 // #include <gtk/gtk.h>
5 import "C"
6
7 /*
8 * GtkInputPurpose
9 */
10
11 const (
12 INPUT_PURPOSE_TERMINAL InputPurpose = C.GTK_INPUT_PURPOSE_TERMINAL
13 )
2424
2525 // #include <gtk/gtk.h>
2626 import "C"
27 import (
28 "sync"
2927
30 "github.com/gotk3/gotk3/gdk"
31 )
3228 /*
3329 * Constants
3430 */
3733 STATE_FLAG_DIR_LTR StateFlags = C.GTK_STATE_FLAG_DIR_LTR
3834 STATE_FLAG_DIR_RTL StateFlags = C.GTK_STATE_FLAG_DIR_RTL
3935 )
40
41 /*
42 * GtkTickCallback
43 */
44
45 type TickCallback func(widget *Widget, frameClock *gdk.FrameClock, userData uintptr) bool
46
47 type tickCallbackData struct {
48 fn TickCallback
49 userData uintptr
50 }
51
52 var (
53 tickCallbackRegistry = struct {
54 sync.RWMutex
55 next int
56 m map[int]tickCallbackData
57 }{
58 next: 1,
59 m: make(map[int]tickCallbackData),
60 }
61 )
518518 }
519519 }
520520
521 func TestCellRendererAccel_AccelModeMarshaling(t *testing.T) {
522 // CellRendererAccel has no getters/setters, everything is handled via properties, so marshaling has to work
523 renderer, err := CellRendererAccelNew()
524 if err != nil {
525 t.Error(err)
526 }
527
528 err = renderer.SetProperty("accel-mode", CELL_RENDERER_ACCEL_MODE_OTHER)
529 if err != nil {
530 t.Error(err)
531 }
532
533 value, err := renderer.GetProperty("accel-mode")
534 if err != nil {
535 t.Error(err)
536 }
537
538 if CELL_RENDERER_ACCEL_MODE_OTHER != value {
539 t.Errorf("Expected %v, got %v", CELL_RENDERER_ACCEL_MODE_OTHER, value)
540 }
541 }
542
543 func TestCellRendererAccel_ModifierTypeMarshaling(t *testing.T) {
544 // CellRendererAccel has no getters/setters, everything is handled via properties, so marshaling has to work
545 renderer, err := CellRendererAccelNew()
546 if err != nil {
547 t.Error(err)
548 }
549
550 err = renderer.SetProperty("accel-mods", gdk.META_MASK)
551 if err != nil {
552 t.Error(err)
553 }
554
555 value, err := renderer.GetProperty("accel-mods")
556 if err != nil {
557 t.Error(err)
558 }
559
560 if gdk.META_MASK != value.(gdk.ModifierType) {
561 t.Errorf("Expected %v, got %v", gdk.META_MASK, value.(gdk.ModifierType))
562 }
563 }
564
521565 func setupListStore() *ListStore {
522566 ls, err := ListStoreNew(glib.TYPE_STRING)
523567 if err != nil {
636680
637681 if *first != *newIter {
638682 t.Fatal("Expected the new iter was prepended to liststore")
683 }
684 }
685
686 // Test storing and fetching a non-empty string value in a ListStore
687 func TestListStoreGetValue_NonEmptyString(t *testing.T) {
688 ls := setupListStore()
689
690 // Add a string
691 err := ls.InsertWithValues(nil, -1, []int{0}, []interface{}{"foo"})
692 if err != nil {
693 t.Fatal("Failed to insert row", err)
694 }
695
696 // Fetch the first iter
697 first, listIsntEmpty := ls.GetIterFirst()
698 if !listIsntEmpty {
699 t.Fatal("Unexpected: liststore is empty")
700 }
701
702 // Obtain a value
703 v, err := ls.GetValue(first, 0)
704 if err != nil {
705 t.Fatal("Failed GetValue()", err)
706 }
707
708 s, err := v.GetString()
709 if err != nil {
710 t.Fatal("Failed GetString()", err)
711 }
712
713 if s != "foo" {
714 t.Errorf("Expected 'foo'; Got %v", s)
715 }
716 }
717
718 // Test storing and fetching an empty string value in a ListStore
719 func TestListStoreGetValue_EmptyString(t *testing.T) {
720 ls := setupListStore()
721
722 // Add a string
723 err := ls.InsertWithValues(nil, -1, []int{0}, []interface{}{""})
724 if err != nil {
725 t.Fatal("Failed to insert row", err)
726 }
727
728 // Fetch the first iter
729 first, listIsntEmpty := ls.GetIterFirst()
730 if !listIsntEmpty {
731 t.Fatal("Unexpected: liststore is empty")
732 }
733
734 // Obtain a value
735 v, err := ls.GetValue(first, 0)
736 if err != nil {
737 t.Fatal("Failed GetValue()", err)
738 }
739
740 s, err := v.GetString()
741 if err != nil {
742 t.Fatal("Failed GetString()", err)
743 }
744
745 if s != "" {
746 t.Errorf("Expected an empty string; Got %v", s)
747 }
748 }
749
750 // Test storing and fetching a missing string value in a ListStore
751 func TestListStoreGetValue_MissingString(t *testing.T) {
752 ls := setupListStore()
753
754 // Add a string
755 err := ls.InsertWithValues(nil, -1, nil, nil)
756 if err != nil {
757 t.Fatal("Failed to insert row", err)
758 }
759
760 // Fetch the first iter
761 first, listIsntEmpty := ls.GetIterFirst()
762 if !listIsntEmpty {
763 t.Fatal("Unexpected: liststore is empty")
764 }
765
766 // Obtain a value
767 v, err := ls.GetValue(first, 0)
768 if err != nil {
769 t.Fatal("Failed GetValue()", err)
770 }
771
772 _, err = v.GetString()
773 if err == nil {
774 t.Fatal("Unexpected success: error expected from GetString()", err)
639775 }
640776 }
641777
3535 }
3636
3737 func wrapIconView(obj *glib.Object) *IconView {
38 if obj == nil {
39 return nil
40 }
41
3842 return &IconView{Container{Widget{glib.InitiallyUnowned{obj}}}}
3943 }
4044
4852 return wrapIconView(glib.Take(unsafe.Pointer(c))), nil
4953 }
5054
55 // TODO:
56 // gtk_icon_view_new_with_area().
57
5158 // IconViewNewWithModel is a wrapper around gtk_icon_view_new_with_model().
5259 func IconViewNewWithModel(model ITreeModel) (*IconView, error) {
5360 c := C.gtk_icon_view_new_with_model(model.toTreeModel())
6875 }
6976
7077 // GetModel is a wrapper around gtk_icon_view_get_model().
71 func (v *IconView) GetModel() (*TreeModel, error) {
78 func (v *IconView) GetModel() (ITreeModel, error) {
7279 c := C.gtk_icon_view_get_model(v.native())
7380 if c == nil {
7481 return nil, nilPtrErr
7582 }
76 obj := glib.Take(unsafe.Pointer(c))
77 return wrapTreeModel(obj), nil
83 return castTreeModel(c)
7884 }
7985
8086 // SetTextColumn is a wrapper around gtk_icon_view_set_text_column().
156162 return int(bx), int(by)
157163 }
158164
159 // SetCursor is a wrapper around gtk_icon_view_set_selection_mode().
165 // SetCursor is a wrapper around gtk_icon_view_set_cursor().
160166 func (v *IconView) SetCursor(path *TreePath, cell *CellRenderer, startEditing bool) {
161167 C.gtk_icon_view_set_cursor(v.native(), path.native(), cell.native(), gbool(startEditing))
162168 }
184190 return path, cell
185191 }
186192
193 // TODO:
194 // gtk_icon_view_selected_foreach().
187195 // func (v *IconView) SelectedForeach() {}
188196
189197 // SetSelectionMode is a wrapper around gtk_icon_view_set_selection_mode().
281289 C.gtk_icon_view_set_activate_on_single_click(v.native(), gbool(single))
282290 }
283291
284 // ActivateOnSingleClick is a wrapper around gtk_icon_view_get_activate_on_single_click().
285 func (v *IconView) ActivateOnSingleClick() bool {
292 // GetActivateOnSingleClick is a wrapper around gtk_icon_view_get_activate_on_single_click().
293 func (v *IconView) GetActivateOnSingleClick() bool {
286294 return gobool(C.gtk_icon_view_get_activate_on_single_click(v.native()))
287295 }
288296
310318 return gobool(C.gtk_icon_view_path_is_selected(v.native(), path.native()))
311319 }
312320
313 // GetSelectedItems is a wrapper around gtk_icon_view_unselect_path().
321 // GetSelectedItems is a wrapper around gtk_icon_view_get_selected_items().
314322 func (v *IconView) GetSelectedItems() *glib.List {
315323 clist := C.gtk_icon_view_get_selected_items(v.native())
316324 if clist == nil {
440448 return int(C.gtk_icon_view_get_item_row(v.native(), path.native()))
441449 }
442450
443 /*
444 func (v *IconView) EnableModelDragSource() {}
445
446 func (v *IconView) EnableModelDragDest() {}
447
448 func (v *IconView) UnsetModelDragSource() {}
449
450 func (v *IconView) UnsetModelDragDest() {}
451 */
451 // TODO:
452 // gtk_icon_view_get_item_column().
453 // gtk_icon_view_enable_model_drag_source().
454 // func (v *IconView) EnableModelDragSource() {}
455 // gtk_icon_view_enable_model_drag_dest().
456 // func (v *IconView) EnableModelDragDest() {}
457 // gtk_icon_view_unset_model_drag_source().
458 // func (v *IconView) UnsetModelDragSource() {}
459 // gtk_icon_view_unset_model_drag_dest().
460 // func (v *IconView) UnsetModelDragDest() {}
452461
453462 // SetReorderable is a wrapper around gtk_icon_view_set_reorderable().
454463 func (v *IconView) SetReorderable(reorderable bool) {
460469 return gobool(C.gtk_icon_view_get_reorderable(v.native()))
461470 }
462471
463 /*
464 func (v *IconView) SetDragDestItem() {}
465
466 func (v *IconView) GetDragDestItem() {}
467
468 func (v *IconView) GetDestItemAtPos() {}
469
470 func (v *IconView) CreateDragIcon() {}
471 */
472 // TODO:
473 // gtk_icon_view_set_drag_dest_item().
474 // func (v *IconView) SetDragDestItem() {}
475 // gtk_icon_view_get_drag_dest_item().
476 // func (v *IconView) GetDragDestItem() {}
477 // gtk_icon_view_get_dest_item_at_pos().
478 // func (v *IconView) GetDestItemAtPos() {}
479 // gtk_icon_view_create_drag_icon().
480 // func (v *IconView) CreateDragIcon() {}
3737 }
3838
3939 func wrapInfoBar(obj *glib.Object) *InfoBar {
40 if obj == nil {
41 return nil
42 }
43
4044 return &InfoBar{Box{Container{Widget{glib.InitiallyUnowned{obj}}}}}
4145 }
4246
47 // InfoBarNew is a wrapper around gtk_info_bar_new().
4348 func InfoBarNew() (*InfoBar, error) {
4449 c := C.gtk_info_bar_new()
4550 if c == nil {
4954 return wrapInfoBar(glib.Take(unsafe.Pointer(c))), nil
5055 }
5156
57 // TODO:
58 // gtk_info_bar_new_with_buttons().
59
60 // AddActionWidget is a wrapper around gtk_info_bar_add_action_widget().
5261 func (v *InfoBar) AddActionWidget(w IWidget, responseId ResponseType) {
5362 C.gtk_info_bar_add_action_widget(v.native(), w.toWidget(), C.gint(responseId))
5463 }
5564
65 // AddButton is a wrapper around gtk_info_bar_add_button().
5666 func (v *InfoBar) AddButton(buttonText string, responseId ResponseType) {
5767 cstr := C.CString(buttonText)
5868 defer C.free(unsafe.Pointer(cstr))
6070 C.gtk_info_bar_add_button(v.native(), (*C.gchar)(cstr), C.gint(responseId))
6171 }
6272
73 // TODO:
74 // gtk_info_bar_add_buttons().
75
76 // SetResponseSensitive is a wrapper around gtk_info_bar_set_response_sensitive().
6377 func (v *InfoBar) SetResponseSensitive(responseId ResponseType, setting bool) {
6478 C.gtk_info_bar_set_response_sensitive(v.native(), C.gint(responseId), gbool(setting))
6579 }
6680
81 // SetDefaultResponse is a wrapper around gtk_info_bar_set_default_response().
6782 func (v *InfoBar) SetDefaultResponse(responseId ResponseType) {
6883 C.gtk_info_bar_set_default_response(v.native(), C.gint(responseId))
6984 }
7085
86 // TODO:
87 // gtk_info_bar_response().
88
89 // SetMessageType is a wrapper around gtk_info_bar_set_message_type().
7190 func (v *InfoBar) SetMessageType(messageType MessageType) {
7291 C.gtk_info_bar_set_message_type(v.native(), C.GtkMessageType(messageType))
7392 }
7493
94 // GetMessageType is a wrapper around gtk_info_bar_get_message_type().
7595 func (v *InfoBar) GetMessageType() MessageType {
7696 messageType := C.gtk_info_bar_get_message_type(v.native())
7797 return MessageType(messageType)
7898 }
7999
80 func (v *InfoBar) GetActionArea() (*Widget, error) {
100 // GetActionArea is a wrapper around gtk_info_bar_get_action_area().
101 func (v *InfoBar) GetActionArea() (IWidget, error) {
81102 c := C.gtk_info_bar_get_action_area(v.native())
82103 if c == nil {
83104 return nil, nilPtrErr
84105 }
85
86 return wrapWidget(glib.Take(unsafe.Pointer(c))), nil
106 return castWidget(c)
87107 }
88108
109 // GetContentArea is a wrapper around gtk_info_bar_get_content_area().
89110 func (v *InfoBar) GetContentArea() (*Box, error) {
90111 c := C.gtk_info_bar_get_content_area(v.native())
91112 if c == nil {
95116 return wrapBox(glib.Take(unsafe.Pointer(c))), nil
96117 }
97118
119 // GetShowCloseButton is a wrapper around gtk_info_bar_get_show_close_button().
98120 func (v *InfoBar) GetShowCloseButton() bool {
99121 b := C.gtk_info_bar_get_show_close_button(v.native())
100122 return gobool(b)
101123 }
102124
125 // SetShowCloseButton is a wrapper around gtk_info_bar_set_show_close_button().
103126 func (v *InfoBar) SetShowCloseButton(setting bool) {
104127 C.gtk_info_bar_set_show_close_button(v.native(), gbool(setting))
105128 }
129
130 // TODO: for GTK+ 3.22.29
131 // gtk_info_bar_get_revealed().
132 // gtk_info_bar_set_revealed().
3838 }
3939
4040 func wrapLabel(obj *glib.Object) *Label {
41 if obj == nil {
42 return nil
43 }
44
4145 return &Label{Widget{glib.InitiallyUnowned{obj}}}
4246 }
4347
44 func WidgetToLabel(widget *Widget) (interface{}, error) {
48 // WidgetToLabel is a convience func that casts the given *Widget into a *Label.
49 func WidgetToLabel(widget *Widget) (*Label, error) {
4550 obj := glib.Take(unsafe.Pointer(widget.GObject))
4651 return wrapLabel(obj), nil
4752 }
6368 cstr := C.CString(str)
6469 defer C.free(unsafe.Pointer(cstr))
6570 C.gtk_label_set_text(v.native(), (*C.gchar)(cstr))
71 }
72
73 // TODO:
74 // gtk_label_set_text_with_mnemonic().
75 // gtk_label_get_attributes().
76 func (v *Label) SetAttributes(attributes *pango.AttrList) {
77 C.gtk_label_set_attributes(v.native(), (*C.PangoAttrList)(unsafe.Pointer(attributes.Native())))
6678 }
6779
6880 // SetMarkup is a wrapper around gtk_label_set_markup().
134146 func (v *Label) SetLineWrapMode(wrapMode pango.WrapMode) {
135147 C.gtk_label_set_line_wrap_mode(v.native(), C.PangoWrapMode(wrapMode))
136148 }
149
150 // TODO:
151 // gtk_label_get_line_wrap_mode().
152 // gtk_label_get_layout_offsets().
153 // gtk_label_get_layout().
154 // gtk_label_get_mnemonic_widget().
137155
138156 // GetSelectable is a wrapper around gtk_label_get_selectable().
139157 func (v *Label) GetSelectable() bool {
0 // Supports building with gtk 3.6+
1
02 package gtk
13
24 // #include <gtk/gtk.h>
2830 LEVEL_BAR_MODE_DISCRETE LevelBarMode = C.GTK_LEVEL_BAR_MODE_DISCRETE
2931 )
3032
33 // stock offset macro values of GtkLevelBar
34 const (
35 LEVEL_BAR_OFFSET_LOW string = C.GTK_LEVEL_BAR_OFFSET_LOW
36 LEVEL_BAR_OFFSET_HIGH string = C.GTK_LEVEL_BAR_OFFSET_HIGH
37 )
38
3139 func marshalLevelBarMode(p uintptr) (interface{}, error) {
3240 c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
3341 return LevelBarMode(c), nil
5765 }
5866
5967 func wrapLevelBar(obj *glib.Object) *LevelBar {
68 if obj == nil {
69 return nil
70 }
71
6072 return &LevelBar{Widget{glib.InitiallyUnowned{obj}}}
6173 }
6274
63 // LevelBarNew() is a wrapper around gtk_level_bar_new().
75 // LevelBarNew is a wrapper around gtk_level_bar_new().
6476 func LevelBarNew() (*LevelBar, error) {
6577 c := C.gtk_level_bar_new()
6678 if c == nil {
6981 return wrapLevelBar(glib.Take(unsafe.Pointer(c))), nil
7082 }
7183
72 // LevelBarNewForInterval() is a wrapper around gtk_level_bar_new_for_interval().
84 // LevelBarNewForInterval is a wrapper around gtk_level_bar_new_for_interval().
7385 func LevelBarNewForInterval(min_value, max_value float64) (*LevelBar, error) {
7486 c := C.gtk_level_bar_new_for_interval(C.gdouble(min_value), C.gdouble(max_value))
7587 if c == nil {
7890 return wrapLevelBar(glib.Take(unsafe.Pointer(c))), nil
7991 }
8092
81 // SetMode() is a wrapper around gtk_level_bar_set_mode().
93 // SetMode is a wrapper around gtk_level_bar_set_mode().
8294 func (v *LevelBar) SetMode(m LevelBarMode) {
8395 C.gtk_level_bar_set_mode(v.native(), C.GtkLevelBarMode(m))
8496 }
8597
86 // GetMode() is a wrapper around gtk_level_bar_get_mode().
98 // GetMode is a wrapper around gtk_level_bar_get_mode().
8799 func (v *LevelBar) GetMode() LevelBarMode {
88100 return LevelBarMode(C.gtk_level_bar_get_mode(v.native()))
89101 }
90102
91 // SetValue() is a wrapper around gtk_level_bar_set_value().
103 // SetValue is a wrapper around gtk_level_bar_set_value().
92104 func (v *LevelBar) SetValue(value float64) {
93105 C.gtk_level_bar_set_value(v.native(), C.gdouble(value))
94106 }
95107
96 // GetValue() is a wrapper around gtk_level_bar_get_value().
108 // GetValue is a wrapper around gtk_level_bar_get_value().
97109 func (v *LevelBar) GetValue() float64 {
98110 c := C.gtk_level_bar_get_value(v.native())
99111 return float64(c)
100112 }
101113
102 // SetMinValue() is a wrapper around gtk_level_bar_set_min_value().
114 // SetMinValue is a wrapper around gtk_level_bar_set_min_value().
103115 func (v *LevelBar) SetMinValue(value float64) {
104116 C.gtk_level_bar_set_min_value(v.native(), C.gdouble(value))
105117 }
106118
107 // GetMinValue() is a wrapper around gtk_level_bar_get_min_value().
119 // GetMinValue is a wrapper around gtk_level_bar_get_min_value().
108120 func (v *LevelBar) GetMinValue() float64 {
109121 c := C.gtk_level_bar_get_min_value(v.native())
110122 return float64(c)
111123 }
112124
113 // SetMaxValue() is a wrapper around gtk_level_bar_set_max_value().
125 // SetMaxValue is a wrapper around gtk_level_bar_set_max_value().
114126 func (v *LevelBar) SetMaxValue(value float64) {
115127 C.gtk_level_bar_set_max_value(v.native(), C.gdouble(value))
116128 }
117129
118 // GetMaxValue() is a wrapper around gtk_level_bar_get_max_value().
130 // GetMaxValue is a wrapper around gtk_level_bar_get_max_value().
119131 func (v *LevelBar) GetMaxValue() float64 {
120132 c := C.gtk_level_bar_get_max_value(v.native())
121133 return float64(c)
122134 }
123135
124 const (
125 LEVEL_BAR_OFFSET_LOW string = C.GTK_LEVEL_BAR_OFFSET_LOW
126 LEVEL_BAR_OFFSET_HIGH string = C.GTK_LEVEL_BAR_OFFSET_HIGH
127 )
128
129 // AddOffsetValue() is a wrapper around gtk_level_bar_add_offset_value().
136 // AddOffsetValue is a wrapper around gtk_level_bar_add_offset_value().
130137 func (v *LevelBar) AddOffsetValue(name string, value float64) {
131138 cstr := C.CString(name)
132139 defer C.free(unsafe.Pointer(cstr))
133140 C.gtk_level_bar_add_offset_value(v.native(), (*C.gchar)(cstr), C.gdouble(value))
134141 }
135142
136 // RemoveOffsetValue() is a wrapper around gtk_level_bar_remove_offset_value().
143 // RemoveOffsetValue is a wrapper around gtk_level_bar_remove_offset_value().
137144 func (v *LevelBar) RemoveOffsetValue(name string) {
138145 cstr := C.CString(name)
139146 defer C.free(unsafe.Pointer(cstr))
140147 C.gtk_level_bar_remove_offset_value(v.native(), (*C.gchar)(cstr))
141148 }
142149
143 // GetOffsetValue() is a wrapper around gtk_level_bar_get_offset_value().
150 // GetOffsetValue is a wrapper around gtk_level_bar_get_offset_value().
144151 func (v *LevelBar) GetOffsetValue(name string) (float64, bool) {
145152 cstr := C.CString(name)
146153 defer C.free(unsafe.Pointer(cstr))
0 // +build !gtk_3_6,!gtk_3_8,!gtk_3_10,!gtk_3_12,!gtk_3_14,!gtk_3_16,!gtk_3_18
1
2 package gtk
3
4 // #include <gtk/gtk.h>
5 // #include "gtk.go.h"
6 import "C"
7
8 /*
9 * Constants
10 */
11
12 const (
13 LEVEL_BAR_OFFSET_FULL string = C.GTK_LEVEL_BAR_OFFSET_FULL
14 )
77 import "C"
88 import (
99 "unsafe"
10
11 "github.com/gotk3/gotk3/gdk"
1012
1113 "github.com/gotk3/gotk3/glib"
1214 )
5254 }
5355
5456 func wrapMenu(obj *glib.Object) *Menu {
57 if obj == nil {
58 return nil
59 }
60
5561 return &Menu{MenuShell{Container{Widget{glib.InitiallyUnowned{obj}}}}}
5662 }
5763
6470 return wrapMenu(glib.Take(unsafe.Pointer(c))), nil
6571 }
6672
67 // Popdown() is a wrapper around gtk_menu_popdown().
68 func (v *Menu) Popdown() {
69 C.gtk_menu_popdown(v.native())
73 // GtkMenuNewFromModel is a wrapper around gtk_menu_new_from_model().
74 func GtkMenuNewFromModel(model *glib.MenuModel) (*Menu, error) {
75 c := C.gtk_menu_new_from_model(C.toGMenuModel(unsafe.Pointer(model.Native())))
76 if c == nil {
77 return nil, nilPtrErr
78 }
79 return wrapMenu(glib.Take(unsafe.Pointer(c))), nil
80 }
81
82 // SetScreen is a wrapper around gtk_menu_set_screen().
83 func (v *Menu) SetScreen(screen *gdk.Screen) {
84 C.gtk_menu_set_screen(v.native(), (*C.GdkScreen)(unsafe.Pointer(screen.Native())))
85 }
86
87 // Attach is a wrapper around gtk_menu_attach().
88 func (v *Menu) Attach(child IWidget, l, r, t, b uint) {
89 C.gtk_menu_attach(
90 v.native(),
91 child.toWidget(),
92 C.guint(l),
93 C.guint(r),
94 C.guint(t),
95 C.guint(b))
96 }
97
98 // SetMonitor() is a wrapper around gtk_menu_set_monitor().
99 func (v *Menu) SetMonitor(monitor_num int) {
100 C.gtk_menu_set_monitor(v.native(), C.gint(monitor_num))
101 }
102
103 // GetMonitor() is a wrapper around gtk_menu_get_monitor().
104 func (v *Menu) GetMonitor() int {
105 return int(C.gtk_menu_get_monitor(v.native()))
70106 }
71107
72108 // ReorderChild() is a wrapper around gtk_menu_reorder_child().
73109 func (v *Menu) ReorderChild(child IWidget, position int) {
74110 C.gtk_menu_reorder_child(v.native(), child.toWidget(), C.gint(position))
75111 }
112
113 // SetReserveToggleSize() is a wrapper around gtk_menu_set_reserve_toggle_size().
114 func (v *Menu) SetReserveToggleSize(reserve bool) {
115 C.gtk_menu_set_reserve_toggle_size(v.native(), gbool(reserve))
116 }
117
118 // GetReserveToggleSize() is a wrapper around gtk_menu_get_reserve_toggle_size().
119 func (v *Menu) GetReserveToggleSize() bool {
120 return gobool(C.gtk_menu_get_reserve_toggle_size(v.native()))
121 }
122
123 // Popdown() is a wrapper around gtk_menu_popdown().
124 func (v *Menu) Popdown() {
125 C.gtk_menu_popdown(v.native())
126 }
127
128 // TODO
129 /*
130 gtk_menu_reposition () require 'GtkMenuPositionFunc' (according to its position function.)
131 */
132
133 // GetActive() is a wrapper around gtk_menu_get_active().
134 func (v *Menu) GetActive() (*Menu, error) {
135 c := C.gtk_menu_get_active(v.native())
136 if c == nil {
137 return nil, nilPtrErr
138 }
139 return wrapMenu(glib.Take(unsafe.Pointer(c))), nil
140 }
141
142 // SetActive() is a wrapper around gtk_menu_set_active().
143 func (v *Menu) SetActive(index uint) {
144 C.gtk_menu_set_active(v.native(), C.guint(index))
145 }
146
147 // TODO
148 /*
149 void
150 gtk_menu_attach_to_widget (GtkMenu *menu,
151 GtkWidget *attach_widget,
152 GtkMenuDetachFunc detacher);
153
154 void
155 gtk_menu_detach (GtkMenu *menu);
156 */
157
158 // GetAttachWidget() is a wrapper around gtk_menu_get_attach_widget().
159 func (v *Menu) GetAttachWidget() (IWidget, error) {
160 c := C.gtk_menu_get_attach_widget(v.native())
161 if c == nil {
162 return nil, nilPtrErr
163 }
164 return castWidget(c)
165 }
166
167 // TODO
168 /*
169 GList *
170 gtk_menu_get_for_attach_widget (GtkWidget *widget);
171 */
1010
1111 "github.com/gotk3/gotk3/glib"
1212 )
13
14 func init() {
15 tm := []glib.TypeMarshaler{
16 {glib.Type(C.gtk_menu_direction_type_get_type()), marshalMenuDirectionType},
17 }
18
19 glib.RegisterGValueMarshalers(tm)
20 }
21
22 // MenuDirectionType is a representation of GTK's GtkMenuDirectionType.
23 type MenuDirectionType int
24
25 const (
26 MENU_DIR_PARENT MenuDirectionType = C.GTK_MENU_DIR_PARENT
27 MENU_DIR_CHILD MenuDirectionType = C.GTK_MENU_DIR_CHILD
28 MENU_DIR_NEXT MenuDirectionType = C.GTK_MENU_DIR_NEXT
29 MENU_DIR_PREV MenuDirectionType = C.GTK_MENU_DIR_PREV
30 )
31
32 func marshalMenuDirectionType(p uintptr) (interface{}, error) {
33 c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
34 return MenuDirectionType(c), nil
35 }
1336
1437 /*
1538 * GtkMenuShell
3659 }
3760
3861 func wrapMenuShell(obj *glib.Object) *MenuShell {
62 if obj == nil {
63 return nil
64 }
65
3966 return &MenuShell{Container{Widget{glib.InitiallyUnowned{obj}}}}
4067 }
4168
89116 C.gtk_menu_shell_set_take_focus(v.native(), gbool(takeFocus))
90117 }
91118
92 // gboolean gtk_menu_shell_get_take_focus ()
93 // GtkWidget * gtk_menu_shell_get_selected_item ()
94 // GtkWidget * gtk_menu_shell_get_parent_shell ()
95 // void gtk_menu_shell_bind_model ()
119 // GetTakeFocus is a wrapper around gtk_menu_shell_get_take_focus().
120 func (v *MenuShell) GetTakeFocus() bool {
121 return gobool(C.gtk_menu_shell_get_take_focus(v.native()))
122 }
123
124 // GetSelectedItem is a wrapper around gtk_menu_shell_get_selected_item().
125 func (v *MenuShell) GetSelectedItem() (IMenuItem, error) {
126 c := C.gtk_menu_shell_get_selected_item(v.native())
127 if c == nil {
128 return nil, nilPtrErr
129 }
130 obj := glib.Take(unsafe.Pointer(c))
131 return wrapMenuItem(obj), nil
132 }
133
134 // GetParentShell is a wrapper around gtk_menu_shell_get_parent_shell().
135 func (v *MenuShell) GetParentShell() (*MenuShell, error) {
136 c := C.gtk_menu_shell_get_parent_shell(v.native())
137 if c == nil {
138 return nil, nilPtrErr
139 }
140 obj := glib.Take(unsafe.Pointer(c))
141 return wrapMenuShell(obj), nil
142 }
143
144 // BindModel is a wrapper around gtk_menu_shell_bind_model().
145 func (v *MenuShell) BindModel(model *glib.MenuModel,
146 action_namespace string, with_separators bool) {
147
148 cstr := C.CString(action_namespace)
149 defer C.free(unsafe.Pointer(cstr))
150
151 C.gtk_menu_shell_bind_model(
152 v.native(),
153 (*C.GMenuModel)(unsafe.Pointer(model.Native())),
154 cstr,
155 gbool(with_separators))
156 }
1010 "github.com/gotk3/gotk3/gdk"
1111 )
1212
13 // PopupAtRect is a wrapper around gtk_menu_popup_at_rect().
14 func (v *Menu) PopupAtRect(rect_window *gdk.Window,
15 rect *gdk.Rectangle, rect_anchor, menu_anchor gdk.Gravity,
16 trigger_event *gdk.Event) {
17
18 C.gtk_menu_popup_at_rect(
19 v.native(),
20 (*C.GdkWindow)(unsafe.Pointer(rect_window.Native())),
21 (*C.GdkRectangle)(unsafe.Pointer(&rect.GdkRectangle)),
22 C.GdkGravity(rect_anchor),
23 C.GdkGravity(menu_anchor),
24 (*C.GdkEvent)(unsafe.Pointer(trigger_event.Native())))
25 }
26
27 // PopupAtWidget() is a wrapper for gtk_menu_popup_at_widget()
28 func (v *Menu) PopupAtWidget(widget IWidget, widgetAnchor gdk.Gravity, menuAnchor gdk.Gravity, triggerEvent *gdk.Event) {
29 e := (*C.GdkEvent)(unsafe.Pointer(triggerEvent.Native()))
30 C.gtk_menu_popup_at_widget(v.native(), widget.toWidget(), C.GdkGravity(widgetAnchor), C.GdkGravity(menuAnchor), e)
31 }
32
1333 // PopupAtPointer() is a wrapper for gtk_menu_popup_at_pointer(), on older versions it uses PopupAtMouseCursor
1434 func (v *Menu) PopupAtPointer(triggerEvent *gdk.Event) {
1535 e := (*C.GdkEvent)(unsafe.Pointer(triggerEvent.Native()))
1636 C.gtk_menu_popup_at_pointer(v.native(), e)
1737 }
1838
19 // PopupAtWidget() is a wrapper for gtk_menu_popup_at_widget()
20 func (v *Menu) PopupAtWidget(widget IWidget, widgetAnchor gdk.GdkGravity, menuAnchor gdk.GdkGravity, triggerEvent *gdk.Event) {
21 e := (*C.GdkEvent)(unsafe.Pointer(triggerEvent.Native()))
22 C.gtk_menu_popup_at_widget(v.native(), widget.toWidget(), C.GdkGravity(widgetAnchor), C.GdkGravity(menuAnchor), e)
39 // PlaceOnMonitor() is a wrapper around gtk_menu_place_on_monitor().
40 func (v *Menu) PlaceOnMonitor(monitor *gdk.Monitor) {
41 C.gtk_menu_place_on_monitor(
42 v.native(),
43 (*C.GdkMonitor)(unsafe.Pointer(monitor.Native())))
2344 }
11
22 // #include <gtk/gtk.h>
33 // #include "gtk.go.h"
4 // #include "print.go.h"
45 import "C"
56 import (
67 "errors"
78 "runtime"
8 "sync"
99 "unsafe"
1010
1111 "github.com/gotk3/gotk3/cairo"
1212 "github.com/gotk3/gotk3/glib"
13 "github.com/gotk3/gotk3/internal/callback"
1314 "github.com/gotk3/gotk3/pango"
1415 )
1516
247248 }
248249
249250 func wrapPageSetup(obj *glib.Object) *PageSetup {
251 if obj == nil {
252 return nil
253 }
254
250255 return &PageSetup{obj}
251256 }
252257
647652 }
648653
649654 func wrapPrintContext(obj *glib.Object) *PrintContext {
655 if obj == nil {
656 return nil
657 }
658
650659 return &PrintContext{obj}
651660 }
652661
754763 }
755764
756765 func wrapPrintOperation(obj *glib.Object) *PrintOperation {
766 if obj == nil {
767 return nil
768 }
769
757770 pop := wrapPrintOperationPreview(obj)
758771 return &PrintOperation{obj, *pop}
759772 }
871884 // Run() is a wrapper around gtk_print_operation_run().
872885 func (po *PrintOperation) Run(action PrintOperationAction, parent IWindow) (PrintOperationResult, error) {
873886 var err *C.GError = nil
874 c := C.gtk_print_operation_run(po.native(), C.GtkPrintOperationAction(action), parent.toWindow(), &err)
887
888 var w *C.GtkWindow = nil
889 if parent != nil {
890 w = parent.toWindow()
891 }
892
893 c := C.gtk_print_operation_run(po.native(), C.GtkPrintOperationAction(action), w, &err)
875894 res := PrintOperationResult(c)
876895 if res == PRINT_OPERATION_RESULT_ERROR {
877896 defer C.g_error_free(err)
948967
949968 // PrintRunPageSetupDialog() is a wrapper around gtk_print_run_page_setup_dialog().
950969 func PrintRunPageSetupDialog(parent IWindow, pageSetup *PageSetup, settings *PrintSettings) *PageSetup {
951 c := C.gtk_print_run_page_setup_dialog(parent.toWindow(), pageSetup.native(), settings.native())
970
971 var w *C.GtkWindow = nil
972 if parent != nil {
973 w = parent.toWindow()
974 }
975
976 c := C.gtk_print_run_page_setup_dialog(w, pageSetup.native(), settings.native())
952977 obj := glib.Take(unsafe.Pointer(c))
953978 return wrapPageSetup(obj)
954979 }
955980
956 type PageSetupDoneCallback func(setup *PageSetup, userData uintptr)
957
958 type pageSetupDoneCallbackData struct {
959 fn PageSetupDoneCallback
960 data uintptr
961 }
962
963 var (
964 pageSetupDoneCallbackRegistry = struct {
965 sync.RWMutex
966 next int
967 m map[int]pageSetupDoneCallbackData
968 }{
969 next: 1,
970 m: make(map[int]pageSetupDoneCallbackData),
971 }
972 )
981 type PageSetupDoneCallback func(setup *PageSetup)
973982
974983 // PrintRunPageSetupDialogAsync() is a wrapper around gtk_print_run_page_setup_dialog_async().
975984 func PrintRunPageSetupDialogAsync(parent IWindow, setup *PageSetup,
976 settings *PrintSettings, cb PageSetupDoneCallback, data uintptr) {
977
978 pageSetupDoneCallbackRegistry.Lock()
979 id := pageSetupDoneCallbackRegistry.next
980 pageSetupDoneCallbackRegistry.next++
981 pageSetupDoneCallbackRegistry.m[id] =
982 pageSetupDoneCallbackData{fn: cb, data: data}
983 pageSetupDoneCallbackRegistry.Unlock()
984
985 C._gtk_print_run_page_setup_dialog_async(parent.toWindow(), setup.native(),
986 settings.native(), C.gpointer(uintptr(id)))
985 settings *PrintSettings, cb PageSetupDoneCallback) {
986
987 var w *C.GtkWindow = nil
988 if parent != nil {
989 w = parent.toWindow()
990 }
991
992 C._gtk_print_run_page_setup_dialog_async(w, setup.native(),
993 settings.native(), C.gpointer(callback.Assign(cb)))
987994 }
988995
989996 /*
10191026 }
10201027
10211028 func wrapPrintOperationPreview(obj *glib.Object) *PrintOperationPreview {
1029 if obj == nil {
1030 return nil
1031 }
1032
10221033 return &PrintOperationPreview{obj}
10231034 }
10241035
10681079 }
10691080
10701081 func wrapPrintSettings(obj *glib.Object) *PrintSettings {
1082 if obj == nil {
1083 return nil
1084 }
1085
10711086 return &PrintSettings{obj}
10721087 }
10731088
11591174 C.gtk_print_settings_unset(ps.native(), (*C.gchar)(cstr))
11601175 }
11611176
1162 type PrintSettingsCallback func(key, value string, userData uintptr)
1163
1164 type printSettingsCallbackData struct {
1165 fn PrintSettingsCallback
1166 userData uintptr
1167 }
1168
1169 var (
1170 printSettingsCallbackRegistry = struct {
1171 sync.RWMutex
1172 next int
1173 m map[int]printSettingsCallbackData
1174 }{
1175 next: 1,
1176 m: make(map[int]printSettingsCallbackData),
1177 }
1178 )
1177 type PrintSettingsCallback func(key, value string)
11791178
11801179 // Foreach() is a wrapper around gtk_print_settings_foreach().
1181 func (ps *PrintSettings) ForEach(cb PrintSettingsCallback, userData uintptr) {
1182 printSettingsCallbackRegistry.Lock()
1183 id := printSettingsCallbackRegistry.next
1184 printSettingsCallbackRegistry.next++
1185 printSettingsCallbackRegistry.m[id] =
1186 printSettingsCallbackData{fn: cb, userData: userData}
1187 printSettingsCallbackRegistry.Unlock()
1188
1189 C._gtk_print_settings_foreach(ps.native(), C.gpointer(uintptr(id)))
1180 func (ps *PrintSettings) ForEach(cb PrintSettingsCallback) {
1181 // Clean up callback immediately as we only need it for the duration of this Foreach call
1182 id := callback.Assign(cb)
1183 defer callback.Delete(id)
1184
1185 C._gtk_print_settings_foreach(ps.native(), C.gpointer(id))
11901186 }
11911187
11921188 // GetBool() is a wrapper around gtk_print_settings_get_bool().
0 #pragma once
1
2 #include <stdint.h>
3 #include <stdlib.h>
4 #include <string.h>
5
6 extern void goPrintSettings(gchar *key, gchar *value, gpointer user_data);
7
8 static inline void _gtk_print_settings_foreach(GtkPrintSettings *ps,
9 gpointer user_data) {
10 gtk_print_settings_foreach(ps, (GtkPrintSettingsFunc)(goPrintSettings),
11 user_data);
12 }
13
14 extern void goPageSetupDone(GtkPageSetup *setup, gpointer data);
15
16 static inline void
17 _gtk_print_run_page_setup_dialog_async(GtkWindow *parent, GtkPageSetup *setup,
18 GtkPrintSettings *settings,
19 gpointer data) {
20 gtk_print_run_page_setup_dialog_async(
21 parent, setup, settings, (GtkPageSetupDoneFunc)(goPageSetupDone), data);
22 }
0 package gtk
1
2 // #include <gtk/gtk.h>
3 import "C"
4 import (
5 "unsafe"
6
7 "github.com/gotk3/gotk3/glib"
8 "github.com/gotk3/gotk3/internal/callback"
9 )
10
11 //export goPageSetupDone
12 func goPageSetupDone(setup *C.GtkPageSetup, data C.gpointer) {
13 // This callback is only used once, so we can clean up immediately
14 fn := callback.GetAndDelete(uintptr(data)).(PageSetupDoneCallback)
15 fn(wrapPageSetup(glib.Take(unsafe.Pointer(setup))))
16 }
17
18 //export goPrintSettings
19 func goPrintSettings(key *C.gchar, value *C.gchar, userData C.gpointer) {
20 fn := callback.Get(uintptr(userData)).(PrintSettingsCallback)
21 fn(C.GoString((*C.char)(key)), C.GoString((*C.char)(value)))
22 }
4747 settings.Set("Key3", "String2")
4848 settings.SetInt("Key4", 2)
4949
50 settings.ForEach(func(key, value string, ptr uintptr) {
50 settings.ForEach(func(key, value string) {
5151 }, 0)
5252 }
5353
3838 }
3939
4040 func wrapSettings(obj *glib.Object) *Settings {
41 if obj == nil {
42 return nil
43 }
44
4145 return &Settings{obj}
4246 }
4347
0 static GtkSettings *
1 toGtkSettings(void *p)
2 {
3 return (GTK_SETTINGS(p));
4 }
0 static GtkSettings *toGtkSettings(void *p) { return (GTK_SETTINGS(p)); }
0 // +build !gtk_3_6,!gtk_3_8,!gtk_3_10,!gtk_3_12,!gtk_3_14,!gtk_3_16,!gtk_3_18
1
2 package gtk
3
4 // #include <gtk/gtk.h>
5 // #include "gtk.go.h"
6 // #include "shortcutswindow_since_3_20.go.h"
7 import "C"
8 import (
9 "unsafe"
10
11 "github.com/gotk3/gotk3/glib"
12 )
13
14 func init() {
15 tm := []glib.TypeMarshaler{
16 {glib.Type(C.gtk_shortcuts_window_get_type()), marshalShortcutsWindow},
17 {glib.Type(C.gtk_shortcuts_section_get_type()), marshalShortcutsSection},
18 {glib.Type(C.gtk_shortcuts_group_get_type()), marshalShortcutsGroup},
19 {glib.Type(C.gtk_shortcuts_shortcut_get_type()), marshalShortcutsShortcut},
20 }
21
22 glib.RegisterGValueMarshalers(tm)
23
24 WrapMap["GtkShortcutsWindow"] = wrapShortcutsWindow
25 WrapMap["GtkShortcutsSection"] = wrapShortcutsSection
26 WrapMap["GtkShortcutsGroup"] = wrapShortcutsGroup
27 WrapMap["GtkShortcutsShortcut"] = wrapShortcutsShortcut
28 }
29
30 /*
31 * GtkShortcutsWindow
32 */
33
34 // ShortcutsWindow is a representation of GTK's GtkShortcutsWindow.
35 type ShortcutsWindow struct {
36 Window
37 }
38
39 func (v *ShortcutsWindow) native() *C.GtkShortcutsWindow {
40 if v == nil || v.GObject == nil {
41 return nil
42 }
43 p := unsafe.Pointer(v.GObject)
44 return C.toGtkShortcutsWindow(p)
45 }
46
47 func marshalShortcutsWindow(p uintptr) (interface{}, error) {
48 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
49 obj := glib.Take(unsafe.Pointer(c))
50 return wrapShortcutsWindow(obj), nil
51 }
52
53 func wrapShortcutsWindow(obj *glib.Object) *ShortcutsWindow {
54 if obj == nil {
55 return nil
56 }
57
58 return &ShortcutsWindow{Window{Bin{Container{Widget{glib.InitiallyUnowned{obj}}}}}}
59 }
60
61 /*
62 * GtkShortcutsSection
63 */
64
65 // ShortcutsSection is a representation of GTK's GtkShortcutsSection.
66 type ShortcutsSection struct {
67 Box
68 }
69
70 // native returns a pointer to the underlying GtkShortcutsSection.
71 func (v *ShortcutsSection) native() *C.GtkShortcutsSection {
72 if v == nil || v.GObject == nil {
73 return nil
74 }
75 p := unsafe.Pointer(v.GObject)
76 return C.toGtkShortcutsSection(p)
77 }
78
79 func marshalShortcutsSection(p uintptr) (interface{}, error) {
80 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
81 obj := glib.Take(unsafe.Pointer(c))
82 return wrapShortcutsSection(obj), nil
83 }
84
85 func wrapShortcutsSection(obj *glib.Object) *ShortcutsSection {
86 if obj == nil {
87 return nil
88 }
89
90 return &ShortcutsSection{Box{Container{Widget{glib.InitiallyUnowned{obj}}}}}
91 }
92
93 /*
94 * GtkShortcutsGroup
95 */
96
97 // ShortcutsGroup is a representation of GTK's GtkShortcutsGroup.
98 type ShortcutsGroup struct {
99 Box
100 }
101
102 // native returns a pointer to the underlying GtkShortcutsGroup.
103 func (v *ShortcutsGroup) native() *C.GtkShortcutsGroup {
104 if v == nil || v.GObject == nil {
105 return nil
106 }
107 p := unsafe.Pointer(v.GObject)
108 return C.toGtkShortcutsGroup(p)
109 }
110
111 func marshalShortcutsGroup(p uintptr) (interface{}, error) {
112 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
113 obj := glib.Take(unsafe.Pointer(c))
114 return wrapShortcutsGroup(obj), nil
115 }
116
117 func wrapShortcutsGroup(obj *glib.Object) *ShortcutsGroup {
118 if obj == nil {
119 return nil
120 }
121
122 return &ShortcutsGroup{Box{Container{Widget{glib.InitiallyUnowned{obj}}}}}
123 }
124
125 /*
126 * GtkShortcutsShortcut
127 */
128
129 // ShortcutsShortcut is a representation of GTK's GtkShortcutsShortcut.
130 type ShortcutsShortcut struct {
131 Box
132 }
133
134 // native returns a pointer to the underlying GtkShortcutsShortcut.
135 func (v *ShortcutsShortcut) native() *C.GtkShortcutsShortcut {
136 if v == nil || v.GObject == nil {
137 return nil
138 }
139 p := unsafe.Pointer(v.GObject)
140 return C.toGtkShortcutsShortcut(p)
141 }
142
143 func marshalShortcutsShortcut(p uintptr) (interface{}, error) {
144 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
145 obj := glib.Take(unsafe.Pointer(c))
146 return wrapShortcutsShortcut(obj), nil
147 }
148
149 func wrapShortcutsShortcut(obj *glib.Object) *ShortcutsShortcut {
150 if obj == nil {
151 return nil
152 }
153
154 return &ShortcutsShortcut{Box{Container{Widget{glib.InitiallyUnowned{obj}}}}}
155 }
0 /*
1 * Copyright (c) 2013-2014 Conformal Systems <info@conformal.com>
2 *
3 * This file originated from: http://opensource.conformal.com/
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18 static GtkShortcutsWindow *toGtkShortcutsWindow(void *p) {
19 return (GTK_SHORTCUTS_WINDOW(p));
20 }
21
22 static GtkShortcutsSection *toGtkShortcutsSection(void *p) {
23 return (GTK_SHORTCUTS_SECTION(p));
24 }
25
26 static GtkShortcutsGroup *toGtkShortcutsGroup(void *p) {
27 return (GTK_SHORTCUTS_GROUP(p));
28 }
29
30 static GtkShortcutsShortcut *toGtkShortcutsShortcut(void *p) {
31 return (GTK_SHORTCUTS_SHORTCUT(p));
32 }
+0
-140
gtk/shortcutswindow_since_3_22.go less more
0 // +build !gtk_3_6,!gtk_3_8,!gtk_3_10,!gtk_3_12,!gtk_3_14,!gtk_3_16,!gtk_3_18,!gtk_3_20
1
2 package gtk
3
4 // #include <gtk/gtk.h>
5 // #include "gtk.go.h"
6 // #include "shortcutswindow_since_3_22.go.h"
7 import "C"
8 import (
9 "unsafe"
10
11 "github.com/gotk3/gotk3/glib"
12 )
13
14 func init() {
15 tm := []glib.TypeMarshaler{
16 {glib.Type(C.gtk_shortcuts_window_get_type()), marshalShortcutsWindow},
17 {glib.Type(C.gtk_shortcuts_section_get_type()), marshalShortcutsSection},
18 {glib.Type(C.gtk_shortcuts_group_get_type()), marshalShortcutsGroup},
19 {glib.Type(C.gtk_shortcuts_shortcut_get_type()), marshalShortcutsShortcut},
20 }
21
22 glib.RegisterGValueMarshalers(tm)
23
24 WrapMap["GtkShortcutsWindow"] = wrapShortcutsWindow
25 WrapMap["GtkShortcutsSection"] = wrapShortcutsSection
26 WrapMap["GtkShortcutsGroup"] = wrapShortcutsGroup
27 WrapMap["GtkShortcutsShortcut"] = wrapShortcutsShortcut
28 }
29
30 /*
31 * GtkShortcutsWindow
32 */
33
34 // ShortcutsWindow is a representation of GTK's GtkShortcutsWindow.
35 type ShortcutsWindow struct {
36 Window
37 }
38
39 func (v *ShortcutsWindow) native() *C.GtkShortcutsWindow {
40 if v == nil || v.GObject == nil {
41 return nil
42 }
43 p := unsafe.Pointer(v.GObject)
44 return C.toGtkShortcutsWindow(p)
45 }
46
47 func marshalShortcutsWindow(p uintptr) (interface{}, error) {
48 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
49 obj := glib.Take(unsafe.Pointer(c))
50 return wrapShortcutsWindow(obj), nil
51 }
52
53 func wrapShortcutsWindow(obj *glib.Object) *ShortcutsWindow {
54 return &ShortcutsWindow{Window{Bin{Container{Widget{glib.InitiallyUnowned{obj}}}}}}
55 }
56
57 /*
58 * GtkShortcutsSection
59 */
60
61 // ShortcutsWindow is a representation of GTK's GtkShortcutsSection.
62 type ShortcutsSection struct {
63 Box
64 }
65
66 // native returns a pointer to the underlying GtkShortcutsSection.
67 func (v *ShortcutsSection) native() *C.GtkShortcutsSection {
68 if v == nil || v.GObject == nil {
69 return nil
70 }
71 p := unsafe.Pointer(v.GObject)
72 return C.toGtkShortcutsSection(p)
73 }
74
75 func marshalShortcutsSection(p uintptr) (interface{}, error) {
76 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
77 obj := glib.Take(unsafe.Pointer(c))
78 return wrapShortcutsSection(obj), nil
79 }
80
81 func wrapShortcutsSection(obj *glib.Object) *ShortcutsSection {
82 return &ShortcutsSection{Box{Container{Widget{glib.InitiallyUnowned{obj}}}}}
83 }
84
85 /*
86 * GtkShortcutsSection
87 */
88
89 // ShortcutsWindow is a representation of GTK's GtkShortcutsGroup.
90 type ShortcutsGroup struct {
91 Box
92 }
93
94 // native returns a pointer to the underlying GtkShortcutsGroup.
95 func (v *ShortcutsGroup) native() *C.GtkShortcutsGroup {
96 if v == nil || v.GObject == nil {
97 return nil
98 }
99 p := unsafe.Pointer(v.GObject)
100 return C.toGtkShortcutsGroup(p)
101 }
102
103 func marshalShortcutsGroup(p uintptr) (interface{}, error) {
104 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
105 obj := glib.Take(unsafe.Pointer(c))
106 return wrapShortcutsGroup(obj), nil
107 }
108
109 func wrapShortcutsGroup(obj *glib.Object) *ShortcutsGroup {
110 return &ShortcutsGroup{Box{Container{Widget{glib.InitiallyUnowned{obj}}}}}
111 }
112
113 /*
114 * GtkShortcutsShortcut
115 */
116
117 // ShortcutsWindow is a representation of GTK's GtkShortcutsShortcut.
118 type ShortcutsShortcut struct {
119 Box
120 }
121
122 // native returns a pointer to the underlying GtkShortcutsShortcut.
123 func (v *ShortcutsShortcut) native() *C.GtkShortcutsShortcut {
124 if v == nil || v.GObject == nil {
125 return nil
126 }
127 p := unsafe.Pointer(v.GObject)
128 return C.toGtkShortcutsShortcut(p)
129 }
130
131 func marshalShortcutsShortcut(p uintptr) (interface{}, error) {
132 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
133 obj := glib.Take(unsafe.Pointer(c))
134 return wrapShortcutsShortcut(obj), nil
135 }
136
137 func wrapShortcutsShortcut(obj *glib.Object) *ShortcutsShortcut {
138 return &ShortcutsShortcut{Box{Container{Widget{glib.InitiallyUnowned{obj}}}}}
139 }
+0
-41
gtk/shortcutswindow_since_3_22.go.h less more
0 /*
1 * Copyright (c) 2013-2014 Conformal Systems <info@conformal.com>
2 *
3 * This file originated from: http://opensource.conformal.com/
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18 static GtkShortcutsWindow *
19 toGtkShortcutsWindow(void *p)
20 {
21 return (GTK_SHORTCUTS_WINDOW(p));
22 }
23
24 static GtkShortcutsSection *
25 toGtkShortcutsSection(void *p)
26 {
27 return (GTK_SHORTCUTS_SECTION(p));
28 }
29
30 static GtkShortcutsGroup *
31 toGtkShortcutsGroup(void *p)
32 {
33 return (GTK_SHORTCUTS_GROUP(p));
34 }
35
36 static GtkShortcutsShortcut *
37 toGtkShortcutsShortcut(void *p)
38 {
39 return (GTK_SHORTCUTS_SHORTCUT(p));
40 }
0 // +build linux
1
02 package gtk
13
24 // #include <gtk/gtkx.h>
68 // #include "socket_plug.go.h"
79 import "C"
810 import (
11 "unsafe"
12
913 "github.com/gotk3/gotk3/gdk"
1014 "github.com/gotk3/gotk3/glib"
11 "unsafe"
1215 )
1316
1417 func init() {
4851 }
4952
5053 func wrapSocket(obj *glib.Object) *Socket {
54 if obj == nil {
55 return nil
56 }
57
5158 return &Socket{Container{Widget{glib.InitiallyUnowned{obj}}}}
5259 }
5360
127134 }
128135
129136 func wrapPlug(obj *glib.Object) *Plug {
137 if obj == nil {
138 return nil
139 }
140
130141 return &Plug{Window{Bin{Container{Widget{glib.InitiallyUnowned{obj}}}}}}
131142 }
132143
00
1 static GtkSocket *
2 toGtkSocket(void *p)
3 {
4 return (GTK_SOCKET(p));
5 }
1 static GtkSocket *toGtkSocket(void *p) { return (GTK_SOCKET(p)); }
62
7 static GtkPlug *
8 toGtkPlug(void *p)
9 {
10 return (GTK_PLUG(p));
11 }
3 static GtkPlug *toGtkPlug(void *p) { return (GTK_PLUG(p)); }
124
13 static GdkDisplay *
14 toGdkDisplay(void *p)
15 {
16 return (GDK_DISPLAY(p));
17 }
5 static GdkDisplay *toGdkDisplay(void *p) { return (GDK_DISPLAY(p)); }
1111 import "C"
1212 import (
1313 "unsafe"
14
15 "github.com/gotk3/gotk3/glib"
1614 )
1715
1816 // GetChildByName is a wrapper around gtk_stack_get_child_by_name().
19 func (v *Stack) GetChildByName(name string) *Widget {
17 func (v *Stack) GetChildByName(name string) (IWidget, error) {
2018 cstr := C.CString(name)
2119 defer C.free(unsafe.Pointer(cstr))
2220 c := C.gtk_stack_get_child_by_name(v.native(), (*C.gchar)(cstr))
2321 if c == nil {
24 return nil
22 return nil, nilPtrErr
2523 }
26 return wrapWidget(glib.Take(unsafe.Pointer(c)))
24 return castWidget(c)
2725 }
2826
2927 // GetTransitionRunning is a wrapper around gtk_stack_get_transition_running().
4949 }
5050
5151 func wrapStackSwitcher(obj *glib.Object) *StackSwitcher {
52 if obj == nil {
53 return nil
54 }
55
5256 return &StackSwitcher{Box{Container{Widget{glib.InitiallyUnowned{obj}}}}}
5357 }
5458
4141 }
4242
4343 func wrapStyleContext(obj *glib.Object) *StyleContext {
44 if obj == nil {
45 return nil
46 }
47
4448 return &StyleContext{obj}
4549 }
4650
0 package gtk
1
2 // #include <gtk/gtk.h>
3 // #include "gtk.go.h"
4 import "C"
5 import (
6 "errors"
7 "os"
8 "unsafe"
9
10 "github.com/gotk3/gotk3/gdk"
11
12 "github.com/gotk3/gotk3/glib"
13 )
14
15 // TestFindLabel is a wrapper around gtk_test_find_label().
16 // This function will search widget and all its descendants for a GtkLabel widget with a text string matching label_pattern.
17 // The labelPattern may contain asterisks “*” and question marks “?” as placeholders, g_pattern_match() is used for the matching.
18 func TestFindLabel(widget IWidget, labelPattern string) (IWidget, error) {
19 cstr := C.CString(labelPattern)
20 defer C.free(unsafe.Pointer(cstr))
21 c := C.gtk_test_find_label(widget.toWidget(), (*C.gchar)(cstr))
22 if c == nil {
23 return nil, errors.New("no label with pattern '" + labelPattern + "' found")
24 }
25 obj, err := castWidget(c)
26 if err != nil {
27 return nil, err
28 }
29 return obj, nil
30 }
31
32 // TestFindSibling is a wrapper around gtk_test_find_sibling().
33 // This function will search siblings of base_widget and siblings of its ancestors for all widgets matching widgetType.
34 // Of the matching widgets, the one that is geometrically closest to base_widget will be returned.
35 func TestFindSibling(baseWidget IWidget, widgetType glib.Type) (IWidget, error) {
36 c := C.gtk_test_find_sibling(baseWidget.toWidget(), C.GType(widgetType))
37 if c == nil {
38 return nil, errors.New("no widget of type '" + widgetType.Name() + "' found")
39 }
40 obj, err := castWidget(c)
41 if err != nil {
42 return nil, err
43 }
44 return obj, nil
45 }
46
47 // TestFindWidget is a wrapper around gtk_test_find_widget().
48 // This function will search the descendants of widget for a widget of type widget_type that has a label matching labelPattern next to it.
49 // This is most useful for automated GUI testing, e.g. to find the “OK” button in a dialog and synthesize clicks on it.
50 // However see TestFindLabel(), TestFindSibling() and TestWidgetClick() (and their GTK documentation)
51 // for possible caveats involving the search of such widgets and synthesizing widget events.
52 func TestFindWidget(widget IWidget, labelPattern string, widgetType glib.Type) (IWidget, error) {
53 cstr := C.CString(labelPattern)
54 defer C.free(unsafe.Pointer(cstr))
55 c := C.gtk_test_find_widget(widget.toWidget(), (*C.gchar)(cstr), C.GType(widgetType))
56 if c == nil {
57 return nil, errors.New("no widget with label pattern '" + labelPattern + "' and type '" + widgetType.Name() + "' found")
58 }
59 obj, err := castWidget(c)
60 if err != nil {
61 return nil, err
62 }
63 return obj, nil
64 }
65
66 /*
67 TestInit is a wrapper around gtk_test_init().
68 This function is used to initialize a GTK+ test program.
69 It will in turn call g_test_init() and gtk_init() to properly initialize the testing framework and graphical toolkit.
70 It’ll also set the program’s locale to “C” and prevent loading of rc files and Gtk+ modules.
71 This is done to make tets program environments as deterministic as possible.
72
73 Like gtk_init() and g_test_init(), any known arguments will be processed and stripped from argc and argv.
74 */
75 func TestInit(args *[]string) {
76 if args != nil {
77 argc := C.int(len(*args))
78 argv := C.make_strings(argc)
79 defer C.destroy_strings(argv)
80
81 for i, arg := range *args {
82 cstr := C.CString(arg)
83 C.set_string(argv, C.int(i), (*C.gchar)(cstr))
84 }
85
86 C._gtk_test_init((*C.int)(unsafe.Pointer(&argc)),
87 (***C.char)(unsafe.Pointer(&argv)))
88
89 unhandled := make([]string, argc)
90 for i := 0; i < int(argc); i++ {
91 cstr := C.get_string(argv, C.int(i))
92 unhandled[i] = goString(cstr)
93 C.free(unsafe.Pointer(cstr))
94 }
95 *args = unhandled
96 } else {
97 // gtk_test_init does not take nil, we have to use an empty argument list
98 // (only containing the first arg, which is the executable name)
99 argc := C.int(1)
100 argv := C.make_strings(argc)
101 defer C.destroy_strings(argv)
102
103 // Add first argument
104 cstr := C.CString(os.Args[0])
105 C.set_string(argv, C.int(0), (*C.gchar)(cstr))
106
107 C._gtk_test_init((*C.int)(unsafe.Pointer(&argc)),
108 (***C.char)(unsafe.Pointer(&argv)))
109 }
110 }
111
112 // TestListAllTypes is a wrapper around gtk_test_list_all_types().
113 // Return the type ids that have been registered after calling TestRegisterAllTypes().
114 func TestListAllTypes() []glib.Type {
115 var types *C.GType
116 var clen C.guint
117
118 types = C.gtk_test_list_all_types(&clen)
119 defer C.free(unsafe.Pointer(types))
120
121 length := uint(clen)
122
123 typeReturn := make([]glib.Type, length)
124 for i := uint(0); i < length; i++ {
125 current := (*C.GType)(pointerAtOffset(unsafe.Pointer(types), unsafe.Sizeof(*types), i))
126 typeReturn[i] = glib.Type(*current)
127 }
128 return typeReturn
129 }
130
131 // pointerAtOffset adjusts `arrayPointer` (pointer to the first element of a C array)
132 // to point at the offset `i`,
133 // to be able to read the value there without having to go through cgo.
134 func pointerAtOffset(arrayPointer unsafe.Pointer, elementSize uintptr, offset uint) unsafe.Pointer {
135 return unsafe.Pointer(uintptr(arrayPointer) + elementSize*uintptr(offset))
136 }
137
138 // TestRegisterAllTypes is a wrapper around gtk_test_register_all_types().
139 // Force registration of all core Gtk+ and Gdk object types.
140 // This allowes to refer to any of those object types via g_type_from_name() after calling this function.
141 func TestRegisterAllTypes() {
142 C.gtk_test_register_all_types()
143 }
144
145 // TestWidgetSendKey is a wrapper around gtk_test_widget_send_key()
146 //
147 // This function will generate keyboard press and release events
148 // in the middle of the first GdkWindow found that belongs to widget.
149 // For windowless widgets like GtkButton (which returns FALSE from gtk_widget_get_has_window()),
150 // this will often be an input-only event window.
151 // For other widgets, this is usually widget->window.
152 //
153 // widget: Widget to generate a key press and release on.
154 // keyval: A Gdk keyboard value.
155 // modifiers: Keyboard modifiers the event is setup with.
156 //
157 // returns: whether all actions neccessary for the key event simulation were carried out successfully.
158 func TestWidgetSendKey(widget IWidget, keyval uint, modifiers gdk.ModifierType) bool {
159 return gobool(C.gtk_test_widget_send_key(widget.toWidget(), C.guint(keyval), C.GdkModifierType(modifiers)))
160 }
0 //+build gtk_3_6 gtk_3_8 gtk_3_10 gtk_3_12 gtk_3_14 gtk_3_16 gtk_3_18 gtk_deprecated
1
2 package gtk
3
4 // #include <gtk/gtk.h>
5 import "C"
6 import (
7 "github.com/gotk3/gotk3/gdk"
8 )
9
10 /*
11 GtkWidget *
12 gtk_test_create_simple_window (const gchar *window_title,
13 const gchar *dialog_text);
14
15 GtkWidget *
16 gtk_test_create_widget (GType widget_type,
17 const gchar *first_property_name,
18 ...);
19
20 GtkWidget *
21 gtk_test_display_button_window (const gchar *window_title,
22 const gchar *dialog_text,
23 ...);
24
25 double
26 gtk_test_slider_get_value (GtkWidget *widget);
27
28 void
29 gtk_test_slider_set_perc (GtkWidget *widget,
30 double percentage);
31
32 gboolean
33 gtk_test_spin_button_click (GtkSpinButton *spinner,
34 guint button,
35 gboolean upwards);
36
37 gchar *
38 gtk_test_text_get (GtkWidget *widget);
39
40 void
41 gtk_test_text_set (GtkWidget *widget,
42 const gchar *string);
43 */
44
45 // TestWidgetClick is a wrapper around gtk_test_widget_click()
46 // Deprecated since 3.20
47 //
48 // This function will generate a button click (button press and button release event)
49 // in the middle of the first GdkWindow found that belongs to widget.
50 // For windowless widgets like GtkButton (which returns FALSE from gtk_widget_get_has_window()),
51 // this will often be an input-only event window.
52 // For other widgets, this is usually widget->window.
53 //
54 // widget: Widget to generate a button click on.
55 // button: Number of the pointer button for the event, usually 1, 2 or 3.
56 // modifiers: Keyboard modifiers the event is setup with.
57 //
58 // returns: whether all actions neccessary for the button click simulation were carried out successfully.
59 func TestWidgetClick(widget IWidget, button gdk.Button, modifiers gdk.ModifierType) bool {
60 return gobool(C.gtk_test_widget_click(widget.toWidget(), C.guint(button), C.GdkModifierType(modifiers)))
61 }
0 // +build !gtk_3_6,!gtk_3_8
1
2 package gtk
3
4 // #include <gtk/gtk.h>
5 import "C"
6
7 // TestWidgetWaitForDraw is a wrapper around gtk_test_widget_wait_for_draw().
8 // Enters the main loop and waits for widget to be “drawn”. In this context that means it waits for the frame clock of widget to have run a full styling, layout and drawing cycle.
9 // This function is intended to be used for syncing with actions that depend on widget relayouting or on interaction with the display server.
10 func TestWidgetWaitForDraw(widget IWidget) {
11 C.gtk_test_widget_wait_for_draw(widget.toWidget())
12 }
0 package gtk
1
2 import (
3 "reflect"
4 "testing"
5 "unsafe"
6
7 "github.com/gotk3/gotk3/glib"
8 )
9
10 func TestTestRegisterAllTypes(t *testing.T) {
11 TestRegisterAllTypes()
12 types := TestListAllTypes()
13
14 if len(types) == 0 {
15 t.Error("Expected at least one type to be registered")
16 }
17 }
18
19 func TestPointerAtOffset(t *testing.T) {
20 // Simulate a C array by using a pointer to the first element
21 intArray := []int{4, 8, 2, 5, 9}
22 arrayPointer := unsafe.Pointer(&intArray[0])
23 elementSize := unsafe.Sizeof(intArray[0])
24
25 for i, val := range intArray {
26 intAtOffset := (*int)(pointerAtOffset(arrayPointer, elementSize, uint(i)))
27 if val != *intAtOffset {
28 t.Errorf("Expected %d at offset %d, got %d", val, i, *intAtOffset)
29 }
30 }
31 }
32
33 func TestTestFindLabel(t *testing.T) {
34 // Build a dummy widget
35 box, _ := BoxNew(ORIENTATION_HORIZONTAL, 0)
36 label1, _ := LabelNew("First")
37 label2, _ := LabelNew("Second")
38
39 box.PackStart(label1, true, true, 0)
40 box.PackStart(label2, true, true, 0)
41
42 // Find a label in the box with text matching Fir*
43 found, err := TestFindLabel(box, "Fir*")
44 if err != nil {
45 t.Error("Unexpected error:", err.Error())
46 }
47
48 // Should return the label1
49 if found == nil {
50 t.Error("Return value is nil")
51 }
52 foundAsLabel, ok := found.(*Label)
53 if !ok {
54 t.Error("Did not return a label. Received type:", reflect.TypeOf(found))
55 }
56
57 text, _ := foundAsLabel.GetText()
58 if text != "First" {
59 t.Error("Expected: First, Got:", text)
60 }
61
62 }
63
64 func TestTestFindSibling(t *testing.T) {
65 // Build a dummy widget
66 box, _ := BoxNew(ORIENTATION_HORIZONTAL, 0)
67 label1, _ := LabelNew("First")
68 label2, _ := LabelNew("Second")
69
70 box.PackStart(label1, true, true, 0)
71 box.PackStart(label2, true, true, 0)
72
73 // Finx a sibling to label1, of type label
74 found, err := TestFindSibling(label1, glib.TypeFromName("GtkLabel"))
75 if err != nil {
76 t.Error("Unexpected error:", err.Error())
77 }
78
79 // Should return the label2
80 if found == nil {
81 t.Error("Return value is nil")
82 }
83 foundAsLabel, ok := found.(*Label)
84 if !ok {
85 t.Error("Did not return a label. Received type:", reflect.TypeOf(found))
86 }
87
88 text, _ := foundAsLabel.GetText()
89 if text != "Second" {
90 t.Error("Expected: First, Got:", text)
91 }
92
93 }
94
95 func TestTestFindWidget(t *testing.T) {
96 // Build a dummy widget
97 box, _ := BoxNew(ORIENTATION_HORIZONTAL, 0)
98 button1, _ := ButtonNewWithLabel("First")
99 button2, _ := ButtonNewWithLabel("Second")
100
101 box.PackStart(button1, true, true, 0)
102 box.PackStart(button2, true, true, 0)
103
104 // Find a label in the box with text matching Fir*
105 found, err := TestFindWidget(box, "Sec*", glib.TypeFromName("GtkButton"))
106 if err != nil {
107 t.Error("Unexpected error:", err.Error())
108 }
109
110 // Should return the button2
111 if found == nil {
112 t.Error("Return value is nil")
113 }
114 foundAsButton, ok := found.(*Button)
115 if !ok {
116 t.Error("Did not return a button. Received type:", reflect.TypeOf(found))
117 }
118
119 text, _ := foundAsButton.GetLabel()
120 if text != "Second" {
121 t.Error("Expected: Second, Got:", text)
122 }
123
124 }
22 package gtk
33
44 // #include <gtk/gtk.h>
5 // #include "gtk.go.h"
5 // #include "text_child_anchor.go.h"
66 import "C"
7 import (
8 "unsafe"
9
10 "github.com/gotk3/gotk3/glib"
11 )
12
13 func init() {
14 tm := []glib.TypeMarshaler{
15 // Objects/Interfaces
16 {glib.Type(C.gtk_text_child_anchor_get_type()), marshalTextChildAnchor},
17 }
18 glib.RegisterGValueMarshalers(tm)
19 }
720
821 /*
922 * GtkTextChildAnchor
1023 */
1124
1225 // TextChildAnchor is a representation of GTK's GtkTextChildAnchor
13 type TextChildAnchor C.GtkTextChildAnchor
26 type TextChildAnchor struct {
27 glib.InitiallyUnowned
28 }
1429
1530 // native returns a pointer to the underlying GtkTextChildAnchor.
1631 func (v *TextChildAnchor) native() *C.GtkTextChildAnchor {
17 return (*C.GtkTextChildAnchor)(v)
32 if v == nil || v.GObject == nil {
33 return nil
34 }
35 p := unsafe.Pointer(v.GObject)
36 return C.toGtkTextChildAnchor(p)
1837 }
38
39 func marshalTextChildAnchor(p uintptr) (interface{}, error) {
40 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
41 obj := glib.Take(unsafe.Pointer(c))
42 return wrapTextChildAnchor(obj), nil
43 }
44
45 func wrapTextChildAnchor(obj *glib.Object) *TextChildAnchor {
46 if obj == nil {
47 return nil
48 }
49
50 return &TextChildAnchor{glib.InitiallyUnowned{obj}}
51 }
52
53 // TextChildAnchorNew is a wrapper around gtk_text_child_anchor_new ()
54 func TextChildAnchorNew() (*TextChildAnchor, error) {
55 c := C.gtk_text_child_anchor_new()
56 if c == nil {
57 return nil, nilPtrErr
58 }
59 return wrapTextChildAnchor(glib.Take(unsafe.Pointer(c))), nil
60 }
61
62 // GetWidgets is a wrapper around gtk_text_child_anchor_get_widgets ().
63 func (v *TextChildAnchor) GetWidgets() *glib.List {
64 clist := C.gtk_text_child_anchor_get_widgets(v.native())
65 if clist == nil {
66 return nil
67 }
68
69 glist := glib.WrapList(uintptr(unsafe.Pointer(clist)))
70 glist.DataWrapper(func(ptr unsafe.Pointer) interface{} {
71 return wrapWidget(glib.Take(ptr))
72 })
73
74 return glist
75 }
76
77 // GetDeleted is a wrapper around gtk_text_child_anchor_get_deleted().
78 func (v *TextChildAnchor) GetDeleted() bool {
79 return gobool(C.gtk_text_child_anchor_get_deleted(v.native()))
80 }
0 /*
1 * Copyright (c) 2013-2014 Conformal Systems <info@conformal.com>
2 *
3 * This file originated from: http://opensource.conformal.com/
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18 static GtkTextChildAnchor *
19 toGtkTextChildAnchor(void *p)
20 {
21 return (GTK_TEXT_CHILD_ANCHOR(p));
22 }
55 // #include "gtk.go.h"
66 import "C"
77
8 import "unsafe"
8 import (
9 "unsafe"
10
11 "github.com/gotk3/gotk3/glib"
12 )
13
14 func init() {
15
16 WrapMap["GtkTextMark"] = wrapTextMark
17 }
918
1019 /*
1120 * GtkTextMark
1221 */
1322
14 // TextMark is a representation of GTK's GtkTextMark
15 type TextMark C.GtkTextMark
23 // TextMark is a representation of GTK's GtkTextMark.
24 // A position in the buffer preserved across buffer modifications
25 type TextMark struct {
26 *glib.Object
27 }
1628
1729 // native returns a pointer to the underlying GtkTextMark.
1830 func (v *TextMark) native() *C.GtkTextMark {
19 if v == nil {
31 if v == nil || v.GObject == nil {
2032 return nil
2133 }
22 return (*C.GtkTextMark)(v)
34 p := unsafe.Pointer(v.GObject)
35 return C.toGtkTextMark(p)
2336 }
2437
2538 func marshalTextMark(p uintptr) (interface{}, error) {
26 c := C.g_value_get_boxed((*C.GValue)(unsafe.Pointer(p)))
27 return (*TextMark)(unsafe.Pointer(c)), nil
39 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
40 obj := glib.Take(unsafe.Pointer(c))
41 return wrapTextMark(obj), nil
2842 }
43
44 func wrapTextMark(obj *glib.Object) *TextMark {
45 if obj == nil {
46 return nil
47 }
48
49 return &TextMark{obj}
50 }
51
52 // TextMarkNew is a wrapper around gtk_text_mark_new().
53 func TextMarkNew(name string, leftGravity bool) (*TextMark, error) {
54 cstr := C.CString(name)
55 defer C.free(unsafe.Pointer(cstr))
56
57 c := C.gtk_text_mark_new((*C.gchar)(cstr), gbool(leftGravity))
58 if c == nil {
59 return nil, nilPtrErr
60 }
61 return wrapTextMark(glib.Take(unsafe.Pointer(c))), nil
62 }
63
64 // SetVisible is a wrapper around gtk_text_mark_set_visible().
65 func (v *TextMark) SetVisible(setting bool) {
66 C.gtk_text_mark_set_visible(v.native(), gbool(setting))
67 }
68
69 // GetVisible is a wrapper around gtk_text_mark_get_visible().
70 func (v *TextMark) GetVisible() bool {
71 return gobool(C.gtk_text_mark_get_visible(v.native()))
72 }
73
74 // GetDeleted is a wrapper around gtk_text_mark_get_deleted().
75 func (v *TextMark) GetDeleted() bool {
76 return gobool(C.gtk_text_mark_get_deleted(v.native()))
77 }
78
79 // GetName is a wrapper around gtk_text_mark_get_name().
80 func (v *TextMark) GetName() string {
81 return goString(C.gtk_text_mark_get_name(v.native()))
82 }
83
84 // GetBuffer is a wrapper around gtk_text_mark_get_buffer().
85 func (v *TextMark) GetBuffer() (*TextBuffer, error) {
86 c := C.gtk_text_mark_get_buffer(v.native())
87 if c == nil {
88 return nil, nilPtrErr
89 }
90 return wrapTextBuffer(glib.Take(unsafe.Pointer(c))), nil
91 }
92
93 // GetLeftGravity is a wrapper around gtk_text_mark_get_left_gravity().
94 func (v *TextMark) GetLeftGravity() bool {
95 return gobool(C.gtk_text_mark_get_left_gravity(v.native()))
96 }
55 // #include "gtk.go.h"
66 import "C"
77 import (
8 "runtime"
89 "unsafe"
910
1011 "github.com/gotk3/gotk3/gdk"
1112 "github.com/gotk3/gotk3/glib"
13 "github.com/gotk3/gotk3/pango"
1214 )
15
16 func init() {
17
18 tm := []glib.TypeMarshaler{
19 {glib.Type(C.gtk_text_window_type_get_type()), marshalTextWindowType},
20 }
21
22 glib.RegisterGValueMarshalers(tm)
23 }
1324
1425 // TextWindowType is a representation of GTK's GtkTextWindowType.
1526 type TextWindowType int
1627
1728 const (
18 TEXT_WINDOW_WIDGET TextWindowType = C.GTK_TEXT_WINDOW_WIDGET
19 TEXT_WINDOW_TEXT TextWindowType = C.GTK_TEXT_WINDOW_TEXT
20 TEXT_WINDOW_LEFT TextWindowType = C.GTK_TEXT_WINDOW_LEFT
21 TEXT_WINDOW_RIGHT TextWindowType = C.GTK_TEXT_WINDOW_RIGHT
22 TEXT_WINDOW_TOP TextWindowType = C.GTK_TEXT_WINDOW_TOP
23 TEXT_WINDOW_BOTTOM TextWindowType = C.GTK_TEXT_WINDOW_BOTTOM
29 TEXT_WINDOW_PRIVATE TextWindowType = C.GTK_TEXT_WINDOW_PRIVATE
30 TEXT_WINDOW_WIDGET TextWindowType = C.GTK_TEXT_WINDOW_WIDGET
31 TEXT_WINDOW_TEXT TextWindowType = C.GTK_TEXT_WINDOW_TEXT
32 TEXT_WINDOW_LEFT TextWindowType = C.GTK_TEXT_WINDOW_LEFT
33 TEXT_WINDOW_RIGHT TextWindowType = C.GTK_TEXT_WINDOW_RIGHT
34 TEXT_WINDOW_TOP TextWindowType = C.GTK_TEXT_WINDOW_TOP
35 TEXT_WINDOW_BOTTOM TextWindowType = C.GTK_TEXT_WINDOW_BOTTOM
2436 )
37
38 func marshalTextWindowType(p uintptr) (interface{}, error) {
39 c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
40 return TextWindowType(c), nil
41 }
2542
2643 /*
2744 * GtkTextView
4865 }
4966
5067 func wrapTextView(obj *glib.Object) *TextView {
68 if obj == nil {
69 return nil
70 }
71
5172 return &TextView{Container{Widget{glib.InitiallyUnowned{obj}}}}
5273 }
5374
210231 func (v *TextView) GetIndent() int {
211232 c := C.gtk_text_view_get_indent(v.native())
212233 return int(c)
234 }
235
236 // SetTabs is a wrapper around gtk_text_view_set_tabs().
237 func (v *TextView) SetTabs(tabs *pango.TabArray) {
238 C.gtk_text_view_set_tabs(v.native(), (*C.PangoTabArray)(unsafe.Pointer(tabs.Native())))
239 }
240
241 // GetTabs is a wrapper around gtk_text_view_get_tabs().
242 func (v *TextView) GetTabs() (*pango.TabArray, error) {
243 c := C.gtk_text_view_get_tabs(v.native())
244 if c == nil {
245 return nil, nilPtrErr
246 }
247 ta := pango.WrapTabArray(uintptr(unsafe.Pointer(c)))
248 runtime.SetFinalizer(ta, (*pango.TabArray).Free)
249 return ta, nil
213250 }
214251
215252 // SetInputHints is a wrapper around gtk_text_view_set_input_hints().
405442 C.gtk_text_view_add_child_at_anchor(v.native(), child.toWidget(), anchor.native())
406443 }
407444
408 // GtkAdjustment * gtk_text_view_get_hadjustment () -- DEPRECATED
409 // GtkAdjustment * gtk_text_view_get_vadjustment () -- DEPRECATED
410 // void gtk_text_view_add_child_at_anchor ()
411 // GtkTextChildAnchor * gtk_text_child_anchor_new ()
412 // GList * gtk_text_child_anchor_get_widgets ()
413 // gboolean gtk_text_child_anchor_get_deleted ()
414 // void gtk_text_view_set_top_margin () -- SINCE 3.18
415 // gint gtk_text_view_get_top_margin () -- SINCE 3.18
416 // void gtk_text_view_set_bottom_margin () -- SINCE 3.18
417 // gint gtk_text_view_get_bottom_margin () -- SINCE 3.18
418 // void gtk_text_view_set_tabs () -- PangoTabArray
419 // PangoTabArray * gtk_text_view_get_tabs () -- PangoTabArray
445 // TODO:
420446 // GtkTextAttributes * gtk_text_view_get_default_attributes () -- GtkTextAttributes
421 // void gtk_text_view_set_monospace () -- SINCE 3.16
422 // gboolean gtk_text_view_get_monospace () -- SINCE 3.16
447 // GtkTextViewLayer
0 package gtk
1
2 // TODO:
3 // GtkToolShellIface
4 // gtk_tool_shell_get_ellipsize_mode().
5 // gtk_tool_shell_get_icon_size().
6 // gtk_tool_shell_get_orientation().
7 // gtk_tool_shell_get_relief_style().
8 // gtk_tool_shell_get_style().
9 // gtk_tool_shell_get_text_alignment().
10 // gtk_tool_shell_get_text_orientation().
11 // gtk_tool_shell_rebuild_menu().
12 // gtk_tool_shell_get_text_size_group().
3333 }
3434
3535 func wrapTooltip(obj *glib.Object) *Tooltip {
36 if obj == nil {
37 return nil
38 }
39
3640 return &Tooltip{Widget{glib.InitiallyUnowned{obj}}}
3741 }
3842
77 import "C"
88 import (
99 "runtime"
10 "strings"
1011 "unsafe"
1112
1213 "github.com/gotk3/gotk3/gdk"
1314 "github.com/gotk3/gotk3/glib"
15 "github.com/gotk3/gotk3/internal/callback"
1416 )
1517
1618 /*
3840 }
3941
4042 func wrapTreeView(obj *glib.Object) *TreeView {
43 if obj == nil {
44 return nil
45 }
46
4147 return &TreeView{Container{Widget{glib.InitiallyUnowned{obj}}}}
4248 }
4349
6066 }
6167
6268 // GetModel is a wrapper around gtk_tree_view_get_model().
63 func (v *TreeView) GetModel() (*TreeModel, error) {
69 func (v *TreeView) GetModel() (ITreeModel, error) {
6470 c := C.gtk_tree_view_get_model(v.native())
6571 if c == nil {
66 return nil, nil
67 }
68 return wrapTreeModel(glib.Take(unsafe.Pointer(c))), nil
72 return nil, nilPtrErr
73 }
74 return castTreeModel(c)
6975 }
7076
7177 // SetModel is a wrapper around gtk_tree_view_set_model().
225231 if clist == nil {
226232 return nil
227233 }
228
234
229235 list := glib.WrapList(uintptr(unsafe.Pointer(clist)))
230236 list.DataWrapper(func(ptr unsafe.Pointer) interface{} {
231237 return wrapTreeViewColumn(glib.Take(unsafe.Pointer(ptr)))
233239 runtime.SetFinalizer(list, func(glist *glib.List) {
234240 glist.Free()
235241 })
236
242
237243 return list
238244 }
239245
346352 return w
347353 }
348354
349 // ConvertWidgetToBinWindowCoords is a rapper around
350 // gtk_tree_view_convert_widget_to_bin_window_coords().
355 // ConvertWidgetToBinWindowCoords is a rapper around gtk_tree_view_convert_widget_to_bin_window_coords().
351356 func (v *TreeView) ConvertWidgetToBinWindowCoords(wx, wy int, bx, by *int) {
352357 C.gtk_tree_view_convert_widget_to_bin_window_coords(
353358 v.native(),
357362 (*C.gint)(unsafe.Pointer(by)))
358363 }
359364
360 // ConvertBinWindowToWidgetCoords is a rapper around
361 // gtk_tree_view_convert_bin_window_to_widget_coords().
365 // ConvertBinWindowToWidgetCoords is a rapper around gtk_tree_view_convert_bin_window_to_widget_coords().
362366 func (v *TreeView) ConvertBinWindowToWidgetCoords(bx, by int, wx, wy *int) {
363367 C.gtk_tree_view_convert_bin_window_to_widget_coords(v.native(),
364368 (C.gint)(bx),
367371 (*C.gint)(unsafe.Pointer(wy)))
368372 }
369373
374 // ConvertBinWindowToTreeCoords is a wrapper around gtk_tree_view_convert_bin_window_to_tree_coords().
375 func (v *TreeView) ConvertBinWindowToTreeCoords(bx, by int, tx, ty *int) {
376 C.gtk_tree_view_convert_bin_window_to_tree_coords(v.native(),
377 (C.gint)(bx),
378 (C.gint)(by),
379 (*C.gint)(unsafe.Pointer(tx)),
380 (*C.gint)(unsafe.Pointer(ty)))
381 }
382
370383 // SetEnableSearch is a wrapper around gtk_tree_view_set_enable_search().
371384 func (v *TreeView) SetEnableSearch(b bool) {
372385 C.gtk_tree_view_set_enable_search(v.native(), gbool(b))
401414 C.gtk_tree_view_set_search_entry(v.native(), e.native())
402415 }
403416
404 // SetSearchEqualSubstringMatch sets TreeView to search by substring match.
417 // TreeViewSearchEqualFunc is the callback type for TreeView's
418 // SetSearchEqualFunc. It is worth noting that the returned boolean should be
419 // false if the row matches.
420 type TreeViewSearchEqualFunc func(model *TreeModel, column int, key string, iter *TreeIter) (notMatch bool)
421
422 // SetSearchEqualFunc is a wrapper around gtk_tree_view_set_search_equal_func().
423 func (v *TreeView) SetSearchEqualFunc(f TreeViewSearchEqualFunc) {
424 C._gtk_tree_view_set_search_equal_func(v.native(), C.gpointer(callback.Assign(f)))
425 }
426
427 // SetSearchEqualSubstringMatch calls SetSearchEqualFunc with a strings.Contains
428 // adapter.
405429 func (v *TreeView) SetSearchEqualSubstringMatch() {
406 C.gtk_tree_view_set_search_equal_func(
407 v.native(),
408 (C.GtkTreeViewSearchEqualFunc)(unsafe.Pointer(C.substring_match_equal_func)),
409 nil,
410 nil)
430 v.SetSearchEqualFunc(func(model *TreeModel, column int, key string, iter *TreeIter) bool {
431 return !strings.Contains(model.GetStringFromIter(iter), key)
432 })
411433 }
412434
413435 // SetFixedHeightMode is a wrapper around gtk_tree_view_set_fixed_height_mode().
536558 C.gtk_tree_view_set_tooltip_row(v.native(), tooltip.native(), path.native())
537559 }
538560
561 // TreeViewDropPosition describes GtkTreeViewDropPosition.
562 type TreeViewDropPosition int
563
564 const (
565 TREE_VIEW_DROP_BEFORE TreeViewDropPosition = C.GTK_TREE_VIEW_DROP_BEFORE
566 TREE_VIEW_DROP_AFTER TreeViewDropPosition = C.GTK_TREE_VIEW_DROP_AFTER
567 TREE_VIEW_DROP_INTO_OR_BEFORE TreeViewDropPosition = C.GTK_TREE_VIEW_DROP_INTO_OR_BEFORE
568 TREE_VIEW_DROP_INTO_OR_AFTER TreeViewDropPosition = C.GTK_TREE_VIEW_DROP_INTO_OR_AFTER
569 )
570
571 // TODO:
572 // GtkTreeViewDropPosition
539573 // gboolean gtk_tree_view_get_tooltip_context ()
540574 // void (*GtkTreeDestroyCountFunc) ()
541 // void gtk_tree_view_set_destroy_count_func ()
542575 // gboolean (*GtkTreeViewRowSeparatorFunc) ()
543576 // GtkTreeViewRowSeparatorFunc gtk_tree_view_get_row_separator_func ()
544577 // void gtk_tree_view_set_row_separator_func ()
545578 // void (*GtkTreeViewSearchPositionFunc) ()
546579 // GtkTreeViewSearchPositionFunc gtk_tree_view_get_search_position_func ()
547580 // void gtk_tree_view_set_search_position_func ()
548 // void gtk_tree_view_set_search_equal_func ()
549581 // GtkTreeViewSearchEqualFunc gtk_tree_view_get_search_equal_func ()
550582 // void gtk_tree_view_map_expanded_rows ()
551583 // gint gtk_tree_view_insert_column_with_attributes ()
554586 // void gtk_tree_view_get_background_area ()
555587 // void gtk_tree_view_get_visible_rect ()
556588 // gboolean gtk_tree_view_get_visible_range ()
557 // void gtk_tree_view_convert_bin_window_to_tree_coords ()
558589 // void gtk_tree_view_convert_tree_to_bin_window_coords ()
559590 // void gtk_tree_view_convert_tree_to_widget_coords ()
560591 // void gtk_tree_view_convert_widget_to_tree_coords ()
561 // void gtk_tree_view_enable_model_drag_dest ()
562 // void gtk_tree_view_enable_model_drag_source ()
563 // void gtk_tree_view_unset_rows_drag_source ()
564 // void gtk_tree_view_unset_rows_drag_dest ()
565 // void gtk_tree_view_set_drag_dest_row ()
566 // void gtk_tree_view_get_drag_dest_row ()
567 // gboolean gtk_tree_view_get_dest_row_at_pos ()
568592 // cairo_surface_t * gtk_tree_view_create_row_drag_icon ()
593
594 // EnableModelDragDest is a wrapper around gtk_tree_view_enable_model_drag_dest().
595 func (v *TreeView) EnableModelDragDest(targets []TargetEntry, actions gdk.DragAction) {
596 C.gtk_tree_view_enable_model_drag_dest(v.native(), (*C.GtkTargetEntry)(&targets[0]), C.gint(len(targets)), C.GdkDragAction(actions))
597 }
598
599 // EnableModelDragSource is a wrapper around gtk_tree_view_enable_model_drag_source().
600 func (v *TreeView) EnableModelDragSource(startButtonMask gdk.ModifierType, targets []TargetEntry, actions gdk.DragAction) {
601 C.gtk_tree_view_enable_model_drag_source(v.native(), C.GdkModifierType(startButtonMask), (*C.GtkTargetEntry)(&targets[0]), C.gint(len(targets)), C.GdkDragAction(actions))
602 }
603
604 // UnsetRowsDragSource is a wrapper around gtk_tree_view_unset_rows_drag_source().
605 func (v *TreeView) UnsetRowsDragSource() {
606 C.gtk_tree_view_unset_rows_drag_source(v.native())
607 }
608
609 // UnsetRowsDragDest is a wrapper around gtk_tree_view_unset_rows_drag_dest().
610 func (v *TreeView) UnsetRowsDragDest() {
611 C.gtk_tree_view_unset_rows_drag_dest(v.native())
612 }
613
614 // SetDragDestRow is a wrapper around gtk_tree_view_set_drag_dest_row().
615 func (v *TreeView) SetDragDestRow(path *TreePath, pos TreeViewDropPosition) {
616 C.gtk_tree_view_set_drag_dest_row(v.native(), path.native(), C.GtkTreeViewDropPosition(pos))
617 }
618
619 // GetDragDestRow is a wrapper around gtk_tree_view_get_drag_dest_row().
620 func (v *TreeView) GetDragDestRow() (path *TreePath, pos TreeViewDropPosition) {
621 var (
622 cpath *C.GtkTreePath
623 cpos C.GtkTreeViewDropPosition
624 )
625
626 C.gtk_tree_view_get_drag_dest_row(v.native(), &cpath, &cpos)
627
628 pos = TreeViewDropPosition(cpos)
629
630 if cpath != nil {
631 path = &TreePath{cpath}
632 runtime.SetFinalizer(path, (*TreePath).free)
633 }
634
635 return
636 }
637
638 // GetDestRowAtPos is a wrapper around gtk_tree_view_get_dest_row_at_pos().
639 func (v *TreeView) GetDestRowAtPos(dragX, dragY int) (path *TreePath, pos TreeViewDropPosition, ok bool) {
640 var (
641 cpath *C.GtkTreePath
642 cpos C.GtkTreeViewDropPosition
643 )
644
645 cbool := C.gtk_tree_view_get_dest_row_at_pos(v.native(), C.gint(dragX), C.gint(dragY), &cpath, &cpos)
646
647 ok = gobool(cbool)
648 pos = TreeViewDropPosition(cpos)
649
650 if cpath != nil {
651 path = &TreePath{cpath}
652 runtime.SetFinalizer(path, (*TreePath).free)
653 }
654
655 return
656 }
3636 }
3737
3838 func wrapTreeViewColumn(obj *glib.Object) *TreeViewColumn {
39 if obj == nil {
40 return nil
41 }
42
3943 return &TreeViewColumn{glib.InitiallyUnowned{obj}}
4044 }
4145
4246 // TreeViewColumnNew() is a wrapper around gtk_tree_view_column_new().
4347 func TreeViewColumnNew() (*TreeViewColumn, error) {
4448 c := C.gtk_tree_view_column_new()
49 if c == nil {
50 return nil, nilPtrErr
51 }
52 return wrapTreeViewColumn(glib.Take(unsafe.Pointer(c))), nil
53 }
54
55 // TreeViewColumnNewWithArea is a wrapper around gtk_tree_view_column_new_with_area().
56 func TreeViewColumnNewWithArea(area ICellArea) (*TreeViewColumn, error) {
57 c := C.gtk_tree_view_column_new_with_area(area.toCellArea())
4558 if c == nil {
4659 return nil, nilPtrErr
4760 }
246259 return int(C.gtk_tree_view_column_get_x_offset(v.native()))
247260 }
248261
249 // GtkTreeViewColumn * gtk_tree_view_column_new_with_area ()
250262 // void gtk_tree_view_column_set_attributes ()
251263 // void gtk_tree_view_column_set_cell_data_func ()
252264
274286 }
275287
276288 // GetButton() is a wrapper around gtk_tree_view_column_get_button().
277 func (v *TreeViewColumn) GetButton() (*Widget, error) {
289 func (v *TreeViewColumn) GetButton() (IWidget, error) {
278290 widget := C.gtk_tree_view_column_get_button(v.native())
279291 if widget == nil {
280292 return nil, nilPtrErr
281293 }
282 obj := glib.Take(unsafe.Pointer(widget))
283 return wrapWidget(obj), nil
294 return castWidget(widget)
284295 }
285296
286297 // GetWidget() is a wrapper around gtk_tree_view_column_get_widget().
287 func (v *TreeViewColumn) GetWidget() (*Widget, error) {
298 func (v *TreeViewColumn) GetWidget() (IWidget, error) {
288299 widget := C.gtk_tree_view_column_get_widget(v.native())
289300 if widget == nil {
290 return nil, nilPtrErr
291 }
292 obj := glib.Take(unsafe.Pointer(widget))
293 return wrapWidget(obj), nil
301 return nil, nil
302 }
303 return castWidget(widget)
294304 }
295305
296306 // void gtk_tree_view_column_set_alignment ()
77 import "C"
88 import (
99 "errors"
10 "runtime"
1011 "unsafe"
1112
13 "github.com/gotk3/gotk3/cairo"
1214 "github.com/gotk3/gotk3/gdk"
1315 "github.com/gotk3/gotk3/glib"
1416 )
1618 /*
1719 * GtkWidget
1820 */
21
22 func init() {
23 tm := []glib.TypeMarshaler{
24 // Enums
25 {glib.Type(C.gtk_size_request_mode_get_type()), marshalSizeRequestMode},
26
27 // Boxed
28 {glib.Type(C.gtk_requisition_get_type()), marshalRequisition},
29 }
30 glib.RegisterGValueMarshalers(tm)
31
32 WrapMap["GtkRequisition"] = wrapRequisition
33 }
34
35 // SizeRequestMode is a representation of GTK's GtkSizeRequestMode.
36 type SizeRequestMode int
37
38 const (
39 SIZE_REQUEST_HEIGHT_FOR_WIDTH SizeRequestMode = C.GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH
40 SIZE_REQUEST_WIDTH_FOR_HEIGHT SizeRequestMode = C.GTK_SIZE_REQUEST_WIDTH_FOR_HEIGHT
41 SIZE_REQUEST_CONSTANT_SIZE SizeRequestMode = C.GTK_SIZE_REQUEST_CONSTANT_SIZE
42 )
43
44 func marshalSizeRequestMode(p uintptr) (interface{}, error) {
45 c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
46 return SizeRequestMode(c), nil
47 }
1948
2049 // Widget is a representation of GTK's GtkWidget.
2150 type Widget struct {
2857 // GtkWidget.
2958 type IWidget interface {
3059 toWidget() *C.GtkWidget
60 ToWidget() *Widget
3161 Set(string, interface{}) error
3262 }
3363
5989 return v.native()
6090 }
6191
92 // ToWidget is a helper getter, e.g.: it returns *gtk.Label as a *gtk.Widget.
93 // In other cases, where you have a gtk.IWidget, use the type assertion.
94 func (v *Widget) ToWidget() *Widget {
95 return v
96 }
97
98 // Cast changes the widget to an object of interface type IWidget.
99 // This is only useful if you don't already have an object of type IWidget at hand (see example below).
100 // This func is similar to gtk.Builder.GetObject():
101 // The returned value needs to be type-asserted, before it can be used.
102 //
103 // Example:
104 // // you know that the parent is an object of type *gtk.ApplicationWindow,
105 // // or you want to check just in case
106 // parentWindow, _ := myWindow.GetTransientFor()
107 // intermediate, _ := parentWindow.Cast()
108 // appWindow, typeAssertSuccessful := intermediate.(*gtk.ApplicationWindow)
109 func (v *Widget) Cast() (IWidget, error) {
110 return castWidget(v.native())
111 }
112
62113 func marshalWidget(p uintptr) (interface{}, error) {
63114 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
64115 obj := glib.Take(unsafe.Pointer(c))
66117 }
67118
68119 func wrapWidget(obj *glib.Object) *Widget {
120 if obj == nil {
121 return nil
122 }
123
69124 return &Widget{glib.InitiallyUnowned{obj}}
70125 }
126
127 // TODO:
128 // GtkCallback().
129 // gtk_widget_new().
71130
72131 // Destroy is a wrapper around gtk_widget_destroy().
73132 func (v *Widget) Destroy() {
74133 C.gtk_widget_destroy(v.native())
75134 }
76135
136 // HideOnDelete is a wrapper around gtk_widget_hide_on_delete().
137 // Calling this func adds gtk_widget_hide_on_delete to the widget's "delete-event" signal.
77138 func (v *Widget) HideOnDelete() {
78139 C._gtk_widget_hide_on_delete(v.native())
79140 }
80141
142 // TODO:
143 // gtk_widget_set_direction().
144 // gtk_widget_get_direction().
145 // gtk_widget_set_default_direction().
146 // gtk_widget_get_default_direction().
147 // gtk_widget_input_shape_combine_region().
148 // gtk_widget_create_pango_context().
149 // gtk_widget_create_pango_context().
150 // gtk_widget_get_pango_context().
151 // gtk_widget_create_pango_layout().
152
153 // QueueDrawArea is a wrapper aroung gtk_widget_queue_draw_area().
154 func (v *Widget) QueueDrawArea(x, y, w, h int) {
155 C.gtk_widget_queue_draw_area(v.native(), C.gint(x), C.gint(y), C.gint(w), C.gint(h))
156 }
157
158 // QueueDrawRegion is a wrapper aroung gtk_widget_queue_draw_region().
159 func (v *Widget) QueueDrawRegion(region *cairo.Region) {
160 C.gtk_widget_queue_draw_region(v.native(), (*C.cairo_region_t)(unsafe.Pointer(region.Native())))
161 }
162
163 // TODO:
164 // gtk_widget_set_redraw_on_allocate().
165 // gtk_widget_mnemonic_activate().
166 // gtk_widget_class_install_style_property().
167 // gtk_widget_class_install_style_property_parser().
168 // gtk_widget_class_find_style_property().
169 // gtk_widget_class_list_style_properties().
170 // gtk_widget_send_focus_change().
171 // gtk_widget_style_get().
172 // gtk_widget_style_get_property().
173 // gtk_widget_style_get_valist().
174 // gtk_widget_class_set_accessible_type().
175 // gtk_widget_get_accessible().
176 // gtk_widget_child_focus().
177 // gtk_widget_child_notify().
178 // gtk_widget_get_child_visible().
179 // gtk_widget_get_settings().
180 // gtk_widget_get_clipboard().
181
182 // GetDisplay is a wrapper around gtk_widget_get_display().
183 func (v *Widget) GetDisplay() (*gdk.Display, error) {
184 c := C.gtk_widget_get_display(v.native())
185 if c == nil {
186 return nil, nilPtrErr
187 }
188 s := &gdk.Display{glib.Take(unsafe.Pointer(c))}
189 return s, nil
190 }
191
192 // GetScreen is a wrapper around gtk_widget_get_screen().
193 func (v *Widget) GetScreen() (*gdk.Screen, error) {
194 c := C.gtk_widget_get_screen(v.native())
195 if c == nil {
196 return nil, nilPtrErr
197 }
198 s := &gdk.Screen{glib.Take(unsafe.Pointer(c))}
199 return s, nil
200 }
201
202 // TODO:
203 // gtk_widget_has_screen().
204 // gtk_widget_get_size_request().
205 // gtk_widget_set_child_visible().
206 // gtk_widget_list_mnemonic_labels().
207 // gtk_widget_add_mnemonic_label().
208 // gtk_widget_remove_mnemonic_label().
209 // gtk_widget_error_bell().
210 // gtk_widget_keynav_failed().
211 // gtk_widget_get_tooltip_window().
212 // gtk_widget_get_has_tooltip().
213 // gtk_widget_set_has_tooltip().
214 // gtk_widget_trigger_tooltip_query().
215 // gtk_cairo_should_draw_window().
216 // gtk_cairo_transform_to_window().
217
218 // DragDestSet is a wrapper around gtk_drag_dest_set().
81219 func (v *Widget) DragDestSet(flags DestDefaults, targets []TargetEntry, actions gdk.DragAction) {
82220 C.gtk_drag_dest_set(v.native(), C.GtkDestDefaults(flags), (*C.GtkTargetEntry)(&targets[0]), C.gint(len(targets)), C.GdkDragAction(actions))
83221 }
84222
85 func (v *Widget) DragSourceSet(start_button_mask gdk.ModifierType, targets []TargetEntry, actions gdk.DragAction) {
86 C.gtk_drag_source_set(v.native(), C.GdkModifierType(start_button_mask), (*C.GtkTargetEntry)(&targets[0]), C.gint(len(targets)), C.GdkDragAction(actions))
223 // DragSourceSet is a wrapper around gtk_drag_source_set().
224 func (v *Widget) DragSourceSet(startButtonMask gdk.ModifierType, targets []TargetEntry, actions gdk.DragAction) {
225 C.gtk_drag_source_set(v.native(), C.GdkModifierType(startButtonMask), (*C.GtkTargetEntry)(&targets[0]), C.gint(len(targets)), C.GdkDragAction(actions))
87226 }
88227
89228 // ResetStyle is a wrapper around gtk_widget_reset_style().
98237
99238 // TODO(jrick) this may require some rethinking
100239 /*
240 // Destroyed is a wrapper around gtk_widget_destroyed().
101241 func (v *Widget) Destroyed(widgetPointer **Widget) {
102242 }
103243 */
139279 C.gtk_widget_set_can_default(v.native(), gbool(canDefault))
140280 }
141281
282 // SetMapped is a wrapper around gtk_widget_set_mapped().
283 func (v *Widget) SetMapped(mapped bool) {
284 C.gtk_widget_set_mapped(v.native(), gbool(mapped))
285 }
286
142287 // GetMapped is a wrapper around gtk_widget_get_mapped().
143288 func (v *Widget) GetMapped() bool {
144289 c := C.gtk_widget_get_mapped(v.native())
145290 return gobool(c)
146291 }
147292
148 // SetMapped is a wrapper around gtk_widget_set_mapped().
149 func (v *Widget) SetMapped(mapped bool) {
150 C.gtk_widget_set_can_focus(v.native(), gbool(mapped))
151 }
293 // TODO:
294 // gtk_widget_device_is_shadowed().
295 // gtk_widget_get_modifier_mask().
296
297 // InsertActionGroup is a wrapper around gtk_widget_insert_action_group().
298 func (v *Widget) InsertActionGroup(name string, group glib.IActionGroup) {
299 C.gtk_widget_insert_action_group(v.native(), (*C.gchar)(C.CString(name)), C.toGActionGroup(unsafe.Pointer(group.Native())))
300 }
301
302 // TODO:
303 // gtk_widget_get_path().
304
305 // GetPreferredHeight is a wrapper around gtk_widget_get_preferred_height().
306 func (v *Widget) GetPreferredHeight() (int, int) {
307 var minimum, natural C.gint
308 C.gtk_widget_get_preferred_height(v.native(), &minimum, &natural)
309 return int(minimum), int(natural)
310 }
311
312 // GetPreferredWidth is a wrapper around gtk_widget_get_preferred_width().
313 func (v *Widget) GetPreferredWidth() (int, int) {
314 var minimum, natural C.gint
315 C.gtk_widget_get_preferred_width(v.native(), &minimum, &natural)
316 return int(minimum), int(natural)
317 }
318
319 // GetPreferredHeightForWidth is a wrapper around gtk_widget_get_preferred_height_for_width().
320 func (v *Widget) GetPreferredHeightForWidth(width int) (int, int) {
321
322 var minimum, natural C.gint
323
324 C.gtk_widget_get_preferred_height_for_width(
325 v.native(),
326 C.gint(width),
327 &minimum,
328 &natural)
329 return int(minimum), int(natural)
330 }
331
332 // GetPreferredWidthForHeight is a wrapper around gtk_widget_get_preferred_width_for_height().
333 func (v *Widget) GetPreferredWidthForHeight(height int) (int, int) {
334
335 var minimum, natural C.gint
336
337 C.gtk_widget_get_preferred_width_for_height(
338 v.native(),
339 C.gint(height),
340 &minimum,
341 &natural)
342 return int(minimum), int(natural)
343 }
344
345 // GetRequestMode is a wrapper around gtk_widget_get_request_mode().
346 func (v *Widget) GetRequestMode() SizeRequestMode {
347 return SizeRequestMode(C.gtk_widget_get_request_mode(v.native()))
348 }
349
350 // GetPreferredSize is a wrapper around gtk_widget_get_preferred_size().
351 func (v *Widget) GetPreferredSize() (*Requisition, *Requisition) {
352
353 minimum_size := new(C.GtkRequisition)
354 natural_size := new(C.GtkRequisition)
355
356 C.gtk_widget_get_preferred_size(v.native(), minimum_size, natural_size)
357
358 minR, err := requisitionFromNative(minimum_size)
359 if err != nil {
360 minR = nil
361 }
362 natR, err := requisitionFromNative(natural_size)
363 if err != nil {
364 natR = nil
365 }
366
367 return minR, natR
368 }
369
370 // TODO:
371 /*
372 gint
373 gtk_distribute_natural_allocation (gint extra_space,
374 guint n_requested_sizes,
375 GtkRequestedSize *sizes);
376 */
377
378 // GetHAlign is a wrapper around gtk_widget_get_halign().
379 func (v *Widget) GetHAlign() Align {
380 c := C.gtk_widget_get_halign(v.native())
381 return Align(c)
382 }
383
384 // SetHAlign is a wrapper around gtk_widget_set_halign().
385 func (v *Widget) SetHAlign(align Align) {
386 C.gtk_widget_set_halign(v.native(), C.GtkAlign(align))
387 }
388
389 // GetVAlign is a wrapper around gtk_widget_get_valign().
390 func (v *Widget) GetVAlign() Align {
391 c := C.gtk_widget_get_valign(v.native())
392 return Align(c)
393 }
394
395 // SetVAlign is a wrapper around gtk_widget_set_valign().
396 func (v *Widget) SetVAlign(align Align) {
397 C.gtk_widget_set_valign(v.native(), C.GtkAlign(align))
398 }
399
400 // GetMarginTop is a wrapper around gtk_widget_get_margin_top().
401 func (v *Widget) GetMarginTop() int {
402 c := C.gtk_widget_get_margin_top(v.native())
403 return int(c)
404 }
405
406 // SetMarginTop is a wrapper around gtk_widget_set_margin_top().
407 func (v *Widget) SetMarginTop(margin int) {
408 C.gtk_widget_set_margin_top(v.native(), C.gint(margin))
409 }
410
411 // GetMarginBottom is a wrapper around gtk_widget_get_margin_bottom().
412 func (v *Widget) GetMarginBottom() int {
413 c := C.gtk_widget_get_margin_bottom(v.native())
414 return int(c)
415 }
416
417 // SetMarginBottom is a wrapper around gtk_widget_set_margin_bottom().
418 func (v *Widget) SetMarginBottom(margin int) {
419 C.gtk_widget_set_margin_bottom(v.native(), C.gint(margin))
420 }
421
422 // GetHExpand is a wrapper around gtk_widget_get_hexpand().
423 func (v *Widget) GetHExpand() bool {
424 c := C.gtk_widget_get_hexpand(v.native())
425 return gobool(c)
426 }
427
428 // SetHExpand is a wrapper around gtk_widget_set_hexpand().
429 func (v *Widget) SetHExpand(expand bool) {
430 C.gtk_widget_set_hexpand(v.native(), gbool(expand))
431 }
432
433 // TODO:
434 // gtk_widget_get_hexpand_set().
435 // gtk_widget_set_hexpand_set().
436
437 // GetVExpand is a wrapper around gtk_widget_get_vexpand().
438 func (v *Widget) GetVExpand() bool {
439 c := C.gtk_widget_get_vexpand(v.native())
440 return gobool(c)
441 }
442
443 // SetVExpand is a wrapper around gtk_widget_set_vexpand().
444 func (v *Widget) SetVExpand(expand bool) {
445 C.gtk_widget_set_vexpand(v.native(), gbool(expand))
446 }
447
448 // TODO:
449 // gtk_widget_get_vexpand_set().
450 // gtk_widget_set_vexpand_set().
451 // gtk_widget_queue_compute_expand().
452 // gtk_widget_compute_expand().
152453
153454 // GetRealized is a wrapper around gtk_widget_get_realized().
154455 func (v *Widget) GetRealized() bool {
203504 C.gtk_widget_unmap(v.native())
204505 }
205506
206 // QueueDrawArea is a wrapper aroung gtk_widget_queue_draw_area().
207 func (v *Widget) QueueDrawArea(x, y, w, h int) {
208 C.gtk_widget_queue_draw_area(v.native(), C.gint(x), C.gint(y), C.gint(w), C.gint(h))
209 }
210
507 // TODO:
211508 //void gtk_widget_realize(GtkWidget *widget);
212509 //void gtk_widget_unrealize(GtkWidget *widget);
213510 //void gtk_widget_draw(GtkWidget *widget, cairo_t *cr);
214511 //void gtk_widget_queue_resize(GtkWidget *widget);
215512 //void gtk_widget_queue_resize_no_redraw(GtkWidget *widget);
216 //GdkFrameClock *gtk_widget_get_frame_clock(GtkWidget *widget);
217 //guint gtk_widget_add_tick_callback (GtkWidget *widget,
218 // GtkTickCallback callback,
219 // gpointer user_data,
220 // GDestroyNotify notify);
221 //void gtk_widget_remove_tick_callback(GtkWidget *widget, guint id);
222
223 // TODO(jrick) GtkAllocation
224 /*
225 func (v *Widget) SizeAllocate() {
226 }
227 */
228
229 // Allocation is a representation of GTK's GtkAllocation type.
230 type Allocation struct {
231 gdk.Rectangle
232 }
233
234 // Native returns a pointer to the underlying GtkAllocation.
235 func (v *Allocation) native() *C.GtkAllocation {
236 return (*C.GtkAllocation)(unsafe.Pointer(&v.GdkRectangle))
237 }
238
239 // GetAllocatedWidth() is a wrapper around gtk_widget_get_allocated_width().
240 func (v *Widget) GetAllocatedWidth() int {
241 return int(C.gtk_widget_get_allocated_width(v.native()))
242 }
243
244 // GetAllocatedHeight() is a wrapper around gtk_widget_get_allocated_height().
245 func (v *Widget) GetAllocatedHeight() int {
246 return int(C.gtk_widget_get_allocated_height(v.native()))
247 }
513 // gtk_widget_queue_allocate().
248514
249515 // Event() is a wrapper around gtk_widget_event().
250516 func (v *Widget) Event(event *gdk.Event) bool {
258524 return gobool(C.gtk_widget_activate(v.native()))
259525 }
260526
261 // TODO(jrick) GdkRectangle
262 /*
263 func (v *Widget) Intersect() {
264 }
265 */
527 // Intersect is a wrapper around gtk_widget_intersect().
528 func (v *Widget) Intersect(area gdk.Rectangle) (*gdk.Rectangle, bool) {
529 var cRect *C.GdkRectangle
530 hadIntersection := C.gtk_widget_intersect(v.native(), nativeGdkRectangle(area), cRect)
531 intersection := gdk.WrapRectangle(uintptr(unsafe.Pointer(cRect)))
532 return intersection, gobool(hadIntersection)
533 }
266534
267535 // IsFocus() is a wrapper around gtk_widget_is_focus().
268536 func (v *Widget) IsFocus() bool {
331599 }
332600
333601 // GetParent is a wrapper around gtk_widget_get_parent().
334 func (v *Widget) GetParent() (*Widget, error) {
602 func (v *Widget) GetParent() (IWidget, error) {
335603 c := C.gtk_widget_get_parent(v.native())
336604 if c == nil {
337 return nil, nilPtrErr
338 }
339 return wrapWidget(glib.Take(unsafe.Pointer(c))), nil
605 return nil, nil
606 }
607 return castWidget(c)
340608 }
341609
342610 // SetSizeRequest is a wrapper around gtk_widget_set_size_request().
383651 C.gtk_widget_add_events(v.native(), C.gint(events))
384652 }
385653
654 // TODO:
655 /*
656 // gtk_widget_set_device_events().
657 func (v *Widget) SetDeviceEvents() {
658 }
659 */
660
661 /*
662 // gtk_widget_get_device_events().
663 func (v *Widget) GetDeviceEvents() {
664 }
665 */
666
667 /*
668 // gtk_widget_add_device_events().
669 func (v *Widget) AddDeviceEvents() {
670 }
671 */
672
386673 // FreezeChildNotify is a wrapper around gtk_widget_freeze_child_notify().
387674 func (v *Widget) FreezeChildNotify() {
388675 C.gtk_widget_freeze_child_notify(v.native())
429716 return gobool(c)
430717 }
431718
432 // TODO(jrick) GdkEventMask
433 /*
434 func (v *Widget) SetDeviceEvents() {
435 }
436 */
437
438 // TODO(jrick) GdkEventMask
439 /*
440 func (v *Widget) GetDeviceEvents() {
441 }
442 */
443
444 // TODO(jrick) GdkEventMask
445 /*
446 func (v *Widget) AddDeviceEvents() {
447 }
448 */
719 // FIXME:
720 // gtk_widget_set_window().
721 // gtk_widget_set_receives_default().
722 // gtk_widget_get_receives_default().
723 // gtk_widget_set_support_multidevice().
724 // gtk_widget_get_support_multidevice().
449725
450726 // SetDeviceEnabled is a wrapper around gtk_widget_set_device_enabled().
451727 func (v *Widget) SetDeviceEnabled(device *gdk.Device, enabled bool) {
461737 }
462738
463739 // GetToplevel is a wrapper around gtk_widget_get_toplevel().
464 func (v *Widget) GetToplevel() (*Widget, error) {
740 func (v *Widget) GetToplevel() (IWidget, error) {
465741 c := C.gtk_widget_get_toplevel(v.native())
466742 if c == nil {
467743 return nil, nilPtrErr
468744 }
469 return wrapWidget(glib.Take(unsafe.Pointer(c))), nil
745 return castWidget(c)
746 }
747
748 // TODO:
749 // gtk_widget_get_ancestor().
750 // gtk_widget_get_visual().
751 // gtk_widget_is_ancestor().
752
753 // GetTooltipMarkup is a wrapper around gtk_widget_get_tooltip_markup().
754 // A non-nil error is returned in the case that gtk_widget_get_tooltip_markup
755 // returns NULL to differentiate between NULL and an empty string.
756 func (v *Widget) GetTooltipMarkup() (string, error) {
757 c := C.gtk_widget_get_tooltip_markup(v.native())
758 if c == nil {
759 return "", nilPtrErr
760 }
761 return C.GoString((*C.char)(c)), nil
762 }
763
764 // SetTooltipMarkup is a wrapper around gtk_widget_set_tooltip_markup().
765 func (v *Widget) SetTooltipMarkup(text string) {
766 cstr := C.CString(text)
767 defer C.free(unsafe.Pointer(cstr))
768 C.gtk_widget_set_tooltip_markup(v.native(), (*C.gchar)(cstr))
470769 }
471770
472771 // GetTooltipText is a wrapper around gtk_widget_get_tooltip_text().
488787 C.gtk_widget_set_tooltip_text(v.native(), (*C.gchar)(cstr))
489788 }
490789
491 // GetHAlign is a wrapper around gtk_widget_get_halign().
492 func (v *Widget) GetHAlign() Align {
493 c := C.gtk_widget_get_halign(v.native())
494 return Align(c)
495 }
496
497 // SetHAlign is a wrapper around gtk_widget_set_halign().
498 func (v *Widget) SetHAlign(align Align) {
499 C.gtk_widget_set_halign(v.native(), C.GtkAlign(align))
500 }
501
502 // GetVAlign is a wrapper around gtk_widget_get_valign().
503 func (v *Widget) GetVAlign() Align {
504 c := C.gtk_widget_get_valign(v.native())
505 return Align(c)
506 }
507
508 // SetVAlign is a wrapper around gtk_widget_set_valign().
509 func (v *Widget) SetVAlign(align Align) {
510 C.gtk_widget_set_valign(v.native(), C.GtkAlign(align))
511 }
512
513 // GetMarginTop is a wrapper around gtk_widget_get_margin_top().
514 func (v *Widget) GetMarginTop() int {
515 c := C.gtk_widget_get_margin_top(v.native())
516 return int(c)
517 }
518
519 // SetMarginTop is a wrapper around gtk_widget_set_margin_top().
520 func (v *Widget) SetMarginTop(margin int) {
521 C.gtk_widget_set_margin_top(v.native(), C.gint(margin))
522 }
523
524 // GetMarginBottom is a wrapper around gtk_widget_get_margin_bottom().
525 func (v *Widget) GetMarginBottom() int {
526 c := C.gtk_widget_get_margin_bottom(v.native())
527 return int(c)
528 }
529
530 // SetMarginBottom is a wrapper around gtk_widget_set_margin_bottom().
531 func (v *Widget) SetMarginBottom(margin int) {
532 C.gtk_widget_set_margin_bottom(v.native(), C.gint(margin))
533 }
534
535 // GetHExpand is a wrapper around gtk_widget_get_hexpand().
536 func (v *Widget) GetHExpand() bool {
537 c := C.gtk_widget_get_hexpand(v.native())
538 return gobool(c)
539 }
540
541 // SetHExpand is a wrapper around gtk_widget_set_hexpand().
542 func (v *Widget) SetHExpand(expand bool) {
543 C.gtk_widget_set_hexpand(v.native(), gbool(expand))
544 }
545
546 // GetVExpand is a wrapper around gtk_widget_get_vexpand().
547 func (v *Widget) GetVExpand() bool {
548 c := C.gtk_widget_get_vexpand(v.native())
549 return gobool(c)
550 }
551
552 // SetVExpand is a wrapper around gtk_widget_set_vexpand().
553 func (v *Widget) SetVExpand(expand bool) {
554 C.gtk_widget_set_vexpand(v.native(), gbool(expand))
555 }
556
557790 // TranslateCoordinates is a wrapper around gtk_widget_translate_coordinates().
558791 func (v *Widget) TranslateCoordinates(dest IWidget, srcX, srcY int) (destX, destY int, e error) {
559792 cdest := nullableWidget(dest)
605838 C.gtk_widget_size_allocate(v.native(), allocation.native())
606839 }
607840
841 // TODO:
842 // gtk_widget_size_allocate_with_baseline().
843
608844 // SetStateFlags is a wrapper around gtk_widget_set_state_flags().
609845 func (v *Widget) SetStateFlags(stateFlags StateFlags, clear bool) {
610846 C.gtk_widget_set_state_flags(v.native(), C.GtkStateFlags(stateFlags), gbool(clear))
611847 }
848
849 // TODO:
850 // gtk_widget_unset_state_flags().
851 // gtk_widget_get_state_flags().
612852
613853 // GetWindow is a wrapper around gtk_widget_get_window().
614854 func (v *Widget) GetWindow() (*gdk.Window, error) {
621861 return w, nil
622862 }
623863
624 // GetPreferredHeight is a wrapper around gtk_widget_get_preferred_height().
625 func (v *Widget) GetPreferredHeight() (int, int) {
626 var minimum, natural C.gint
627 C.gtk_widget_get_preferred_height(v.native(), &minimum, &natural)
628 return int(minimum), int(natural)
629 }
630
631 // GetPreferredWidth is a wrapper around gtk_widget_get_preferred_width().
632 func (v *Widget) GetPreferredWidth() (int, int) {
633 var minimum, natural C.gint
634 C.gtk_widget_get_preferred_width(v.native(), &minimum, &natural)
635 return int(minimum), int(natural)
636 }
637
638 func (v *Widget) InsertActionGroup(name string, group glib.IActionGroup) {
639 C.gtk_widget_insert_action_group(v.native(), (*C.gchar)(C.CString(name)), C.toGActionGroup(unsafe.Pointer(group.Native())))
640 }
641
642 // GetScreen is a wrapper around gtk_widget_get_screen().
643 func (v *Widget) GetScreen() (*gdk.Screen, error) {
644 c := C.gtk_widget_get_screen(v.native())
864 /*
865 * GtkRequisition
866 */
867
868 // Requisition is a representation of GTK's GtkRequisition
869 type Requisition struct {
870 requisition *C.GtkRequisition
871 Width,
872 Height int
873 }
874
875 func (v *Requisition) native() *C.GtkRequisition {
876 if v == nil {
877 return nil
878 }
879 v.requisition.width = C.int(v.Width)
880 v.requisition.height = C.int(v.Height)
881 return v.requisition
882 }
883
884 // Native returns a pointer to the underlying GtkRequisition.
885 func (v *Requisition) Native() uintptr {
886 return uintptr(unsafe.Pointer(v.native()))
887 }
888
889 func marshalRequisition(p uintptr) (interface{}, error) {
890 c := C.g_value_get_boxed((*C.GValue)(unsafe.Pointer(p)))
891 requisition := (*C.GtkRequisition)(unsafe.Pointer(c))
892 return wrapRequisition(requisition), nil
893 }
894
895 func wrapRequisition(requisition *C.GtkRequisition) *Requisition {
896 if requisition == nil {
897 return nil
898 }
899 return &Requisition{requisition, int(requisition.width), int(requisition.height)}
900 }
901
902 // requisitionFromNative that handle finalizer.
903 func requisitionFromNative(requisitionNative *C.GtkRequisition) (*Requisition, error) {
904 requisition := wrapRequisition(requisitionNative)
905 if requisition == nil {
906 return nil, nilPtrErr
907 }
908 runtime.SetFinalizer(requisition, (*Requisition).free)
909 return requisition, nil
910 }
911
912 // RequisitionNew is a wrapper around gtk_requisition_new().
913 func RequisitionNew() (*Requisition, error) {
914 c := C.gtk_requisition_new()
645915 if c == nil {
646916 return nil, nilPtrErr
647917 }
648 s := &gdk.Screen{glib.Take(unsafe.Pointer(c))}
649 return s, nil
650 }
918 return requisitionFromNative(c)
919 }
920
921 // free is a wrapper around gtk_requisition_free().
922 func (v *Requisition) free() {
923 C.gtk_requisition_free(v.native())
924 }
925
926 // Copy is a wrapper around gtk_requisition_copy().
927 func (v *Requisition) Copy() (*Requisition, error) {
928 c := C.gtk_requisition_copy(v.native())
929 if c == nil {
930 return nil, nilPtrErr
931 }
932 return requisitionFromNative(c)
933 }
934
935 /*
936 * GtkAllocation
937 */
938
939 // Allocation is a representation of GTK's GtkAllocation type.
940 type Allocation struct {
941 gdk.Rectangle
942 }
943
944 // Native returns a pointer to the underlying GtkAllocation.
945 func (v *Allocation) native() *C.GtkAllocation {
946 return (*C.GtkAllocation)(unsafe.Pointer(&v.GdkRectangle))
947 }
948
949 // GetAllocatedWidth() is a wrapper around gtk_widget_get_allocated_width().
950 func (v *Widget) GetAllocatedWidth() int {
951 return int(C.gtk_widget_get_allocated_width(v.native()))
952 }
953
954 // GetAllocatedHeight() is a wrapper around gtk_widget_get_allocated_height().
955 func (v *Widget) GetAllocatedHeight() int {
956 return int(C.gtk_widget_get_allocated_height(v.native()))
957 }
958
959 // TODO:
960 // gtk_widget_get_allocated_baseline().
961 // gtk_widget_get_allocated_size().
99
1010 "github.com/gotk3/gotk3/gdk"
1111 "github.com/gotk3/gotk3/glib"
12 "github.com/gotk3/gotk3/internal/callback"
1213 )
1314
1415 //export goTickCallbacks
15 func goTickCallbacks (widget *C.GtkWidget, frameClock *C.GdkFrameClock, userData C.gpointer) C.gboolean {
16 id := int(uintptr(userData))
17
18 tickCallbackRegistry.Lock()
19 r := tickCallbackRegistry.m[id]
20 tickCallbackRegistry.Unlock()
21
22 return gbool(r.fn(
23 wrapWidget(glib.Take(unsafe.Pointer(widget))),
16 func goTickCallbacks(widget *C.GtkWidget, frameClock *C.GdkFrameClock, userData C.gpointer) C.gboolean {
17 fn := callback.Get(uintptr(userData)).(TickCallback)
18 return gbool(fn(
19 wrapWidget(glib.Take(unsafe.Pointer(widget))),
2420 gdk.WrapFrameClock(unsafe.Pointer(frameClock)),
25 r.userData,
2621 ))
2722 }
0 // +build !gtk_3_6,!gtk_3_8
1
2 package gtk
3
4 // #include <gtk/gtk.h>
5 import "C"
6
7 // GetPreferredHeightAndBaselineForWidth is a wrapper around gtk_widget_get_preferred_height_and_baseline_for_width().
8 func (v *Widget) GetPreferredHeightAndBaselineForWidth(height int) (int, int, int, int) {
9
10 var minimum, natural, minimum_baseline, natural_baseline C.gint
11
12 C.gtk_widget_get_preferred_height_and_baseline_for_width(
13 v.native(),
14 C.gint(height),
15 &minimum,
16 &natural,
17 &minimum_baseline,
18 &natural_baseline)
19 return int(minimum),
20 int(natural),
21 int(minimum_baseline),
22 int(natural_baseline)
23 }
24
25 // TODO:
26 // gtk_widget_get_valign_with_baseline().
27 // gtk_widget_init_template().
28 // gtk_widget_class_set_template().
29 // gtk_widget_class_set_template_from_resource().
30 // gtk_widget_get_template_child().
31 // gtk_widget_class_bind_template_child().
32 // gtk_widget_class_bind_template_child_internal().
33 // gtk_widget_class_bind_template_child_private().
34 // gtk_widget_class_bind_template_child_internal_private().
35 // gtk_widget_class_bind_template_child_full().
36 // gtk_widget_class_bind_template_callback().
37 // gtk_widget_class_bind_template_callback_full().
38 // gtk_widget_class_set_connect_func().
39
40 // GetScaleFactor is a wrapper around gtk_widget_get_scale_factor().
41 func (v *Widget) GetScaleFactor() int {
42 return int(C.gtk_widget_get_scale_factor(v.native()))
43 }
2525 // #include <gtk/gtk.h>
2626 import "C"
2727
28 // SetMarginStart is a wrapper around gtk_widget_set_margin_start().
2829 func (v *Widget) SetMarginStart(margin int) {
2930 C.gtk_widget_set_margin_start(v.native(), C.gint(margin))
3031 }
3132
33 // GetMarginStart is a wrapper around gtk_widget_get_margin_start().
3234 func (v *Widget) GetMarginStart() int {
3335 c := C.gtk_widget_get_margin_start(v.native())
3436 return int(c)
3537 }
3638
39 // SetMarginEnd is a wrapper around gtk_widget_set_margin_end().
3740 func (v *Widget) SetMarginEnd(margin int) {
3841 C.gtk_widget_set_margin_end(v.native(), C.gint(margin))
3942 }
4043
44 // GetMarginEnd is a wrapper around gtk_widget_get_margin_end().
4145 func (v *Widget) GetMarginEnd() int {
4246 c := C.gtk_widget_get_margin_end(v.native())
4347 return int(c)
0 // +build !gtk_3_6,!gtk_3_8,!gtk_3_10,!gtk_3_12,!gtk_3_14
1
2 package gtk
3
4 // #include <gtk/gtk.h>
5 import "C"
6
7 // TODO:
8 // gtk_widget_list_action_prefixes().
9 // gtk_widget_get_action_group().
0 // +build !gtk_3_6,!gtk_3_8,!gtk_3_10,!gtk_3_12,!gtk_3_14,!gtk_3_16
1
2 package gtk
3
4 // #include <gtk/gtk.h>
5 import "C"
6
7 // TODO:
8 // gtk_widget_set_font_options().
9 // gtk_widget_get_font_options().
10 // gtk_widget_set_font_map().
11 // gtk_widget_get_font_map().
1414 func (v *Widget) SetFocusOnClick(focusOnClick bool) {
1515 C.gtk_widget_set_focus_on_click(v.native(), gbool(focusOnClick))
1616 }
17
18 // TODO:
19 // gtk_widget_class_get_css_name().
20 // gtk_widget_class_set_css_name().
2626 // #include "widget_since_3_8.go.h"
2727 import "C"
2828
29 import (
29 import (
3030 "unsafe"
3131
3232 "github.com/gotk3/gotk3/gdk"
33 "github.com/gotk3/gotk3/internal/callback"
3334 )
35
36 /*
37 * GtkTickCallback
38 */
39
40 // TickCallback is a representation of GtkTickCallback
41 type TickCallback func(widget *Widget, frameClock *gdk.FrameClock) bool
3442
3543 /*
3644 * GtkWidget
6068 }
6169
6270 // AddTickCallback is a wrapper around gtk_widget_add_tick_callback().
63 func (v *Widget) AddTickCallback(fn TickCallback, userData uintptr) int {
64 tickCallbackRegistry.Lock()
65 id := tickCallbackRegistry.next
66 tickCallbackRegistry.next++
67 tickCallbackRegistry.m[id] = tickCallbackData{fn: fn, userData: userData}
68 tickCallbackRegistry.Unlock()
69
70 return int(C._gtk_widget_add_tick_callback(v.native(), C.gpointer(uintptr(id))))
71 func (v *Widget) AddTickCallback(fn TickCallback) int {
72 return int(C._gtk_widget_add_tick_callback(v.native(), C.gpointer(callback.Assign(fn))))
7173 }
7274
7375 // RemoveTickCallback is a wrapper around gtk_widget_remove_tick_callback().
7476 func (v *Widget) RemoveTickCallback(id int) {
7577 C.gtk_widget_remove_tick_callback(v.native(), C.guint(id))
76 }
78 }
79
80 // TODO:
81 // gtk_widget_register_window().
82 // gtk_widget_unregister_window().
1515 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1616 */
1717
18 #include "gtk.go.h" // for gotk3_callbackDelete
1819 #include <stdlib.h>
1920
20 extern gboolean goTickCallbacks (GtkWidget *widget, GdkFrameClock *frame_clock, gpointer user_data);
21 extern gboolean goTickCallbacks(GtkWidget *widget, GdkFrameClock *frame_clock,
22 gpointer user_data);
2123
22 static inline guint _gtk_widget_add_tick_callback(GtkWidget *widget, gpointer user_data) {
23 return gtk_widget_add_tick_callback(widget, (GtkTickCallback)(goTickCallbacks), user_data, NULL);
24 }
24 static inline guint _gtk_widget_add_tick_callback(GtkWidget *widget,
25 gpointer user_data) {
26 return gtk_widget_add_tick_callback(
27 widget, (GtkTickCallback)(goTickCallbacks), user_data,
28 (GDestroyNotify)(gotk3_callbackDelete));
29 }
00 // Same copyright and license as the rest of the files in this project
1 // This file contains accelerator related functions and structures
21
32 package gtk
43
76 import "C"
87 import (
98 "errors"
9 "runtime"
1010 "unsafe"
1111
1212 "github.com/gotk3/gotk3/gdk"
1616 /*
1717 * GtkWindow
1818 */
19
20 // gtk_window_set_has_user_ref_count is NOT included, see GTK documentation for why that is.
1921
2022 // Window is a representation of GTK's GtkWindow.
2123 type Window struct {
2729 // functions that wrap around a C GTK function taking a GtkWindow.
2830 type IWindow interface {
2931 toWindow() *C.GtkWindow
32 ToWindow() *Window
3033 }
3134
3235 // native returns a pointer to the underlying GtkWindow.
4548 return v.native()
4649 }
4750
51 // ToWindow is a helper getter, e.g.: it returns *gtk.ApplicationWindow as a *gtk.Window.
52 // In other cases, where you have a gtk.IWindow, use the type assertion.
53 func (v *Window) ToWindow() *Window {
54 return v
55 }
56
4857 func marshalWindow(p uintptr) (interface{}, error) {
4958 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
5059 obj := glib.Take(unsafe.Pointer(c))
5261 }
5362
5463 func wrapWindow(obj *glib.Object) *Window {
64 if obj == nil {
65 return nil
66 }
67
5568 return &Window{Bin{Container{Widget{glib.InitiallyUnowned{obj}}}}}
5669 }
5770
116129 C.gtk_window_set_default_icon(iconPtr)
117130 }
118131
119 // TODO(jrick) GdkGeometry GdkWindowHints.
120 /*
121 func (v *Window) SetGeometryHints() {
122 }
123 */
132 // SetGeometryHints is a wrapper around gtk_window_set_geometry_hints().
133 func (v *Window) SetGeometryHints(geometryWidget IWidget, geometry gdk.Geometry, geometryMask gdk.WindowHints) {
134 var gW *C.GtkWidget = nil
135 if geometryWidget != nil {
136 gW = geometryWidget.toWidget()
137 }
138 C.gtk_window_set_geometry_hints(v.native(), gW, nativeGdkGeometry(geometry), C.GdkWindowHints(geometryMask))
139 }
124140
125141 // SetGravity is a wrapper around gtk_window_set_gravity().
126 func (v *Window) SetGravity(gravity gdk.GdkGravity) {
142 func (v *Window) SetGravity(gravity gdk.Gravity) {
127143 C.gtk_window_set_gravity(v.native(), C.GdkGravity(gravity))
128144 }
129145
130 // TODO(jrick) GdkGravity.
131 /*
132 func (v *Window) GetGravity() {
133 }
134 */
146 // GetGravity is a wrapper around gtk_window_get_gravity().
147 func (v *Window) GetGravity() gdk.Gravity {
148 c := C.gtk_window_get_gravity(v.native())
149 return gdk.Gravity(c)
150 }
135151
136152 // SetPosition is a wrapper around gtk_window_set_position().
137153 func (v *Window) SetPosition(position WindowPosition) {
147163 C.gtk_window_set_transient_for(v.native(), pw)
148164 }
149165
166 // SetAttachedTo is a wrapper around gtk_window_set_attached_to().
167 func (v *Window) SetAttachedTo(attachWidget IWidget) {
168 var aW *C.GtkWidget = nil
169 if attachWidget != nil {
170 aW = attachWidget.toWidget()
171 }
172 C.gtk_window_set_attached_to(v.native(), aW)
173 }
174
150175 // SetDestroyWithParent is a wrapper around
151176 // gtk_window_set_destroy_with_parent().
152177 func (v *Window) SetDestroyWithParent(setting bool) {
173198 }
174199
175200 // GetFocus is a wrapper around gtk_window_get_focus().
176 func (v *Window) GetFocus() (*Widget, error) {
201 func (v *Window) GetFocus() (IWidget, error) {
177202 c := C.gtk_window_get_focus(v.native())
178203 if c == nil {
179 return nil, nilPtrErr
180 }
181 return wrapWidget(glib.Take(unsafe.Pointer(c))), nil
204 return nil, nil
205 }
206 return castWidget(c)
182207 }
183208
184209 // SetFocus is a wrapper around gtk_window_set_focus().
187212 }
188213
189214 // GetDefaultWidget is a wrapper around gtk_window_get_default_widget().
190 func (v *Window) GetDefaultWidget() *Widget {
215 // See SetDefault() for the setter.
216 func (v *Window) GetDefaultWidget() (IWidget, error) {
191217 c := C.gtk_window_get_default_widget(v.native())
192218 if c == nil {
193 return nil
194 }
195 obj := glib.Take(unsafe.Pointer(c))
196 return wrapWidget(obj)
219 return nil, nil
220 }
221 return castWidget(c)
197222 }
198223
199224 // SetDefault is a wrapper around gtk_window_set_default().
225 // See GetDefaultWidget() for the getter.
200226 func (v *Window) SetDefault(widget IWidget) {
201227 C.gtk_window_set_default(v.native(), widget.toWidget())
202228 }
357383 func (v *Window) GetIcon() (*gdk.Pixbuf, error) {
358384 c := C.gtk_window_get_icon(v.native())
359385 if c == nil {
360 return nil, nilPtrErr
361 }
362
363 p := &gdk.Pixbuf{glib.Take(unsafe.Pointer(c))}
364 return p, nil
386 return nil, nil
387 }
388 return &gdk.Pixbuf{glib.Take(unsafe.Pointer(c))}, nil
365389 }
366390
367391 // GetIconName is a wrapper around gtk_window_get_icon_name().
376400 }
377401
378402 // GetPosition is a wrapper around gtk_window_get_position().
379 func (v *Window) GetPosition() (root_x, root_y int) {
403 func (v *Window) GetPosition() (int, int) {
380404 var x, y C.gint
381405 C.gtk_window_get_position(v.native(), &x, &y)
382406 return int(x), int(y)
410434 func (v *Window) GetTransientFor() (*Window, error) {
411435 c := C.gtk_window_get_transient_for(v.native())
412436 if c == nil {
413 return nil, nilPtrErr
437 return nil, nil
414438 }
415439 return wrapWindow(glib.Take(unsafe.Pointer(c))), nil
416440 }
417441
418442 // GetAttachedTo is a wrapper around gtk_window_get_attached_to().
419 func (v *Window) GetAttachedTo() (*Widget, error) {
443 func (v *Window) GetAttachedTo() (IWidget, error) {
420444 c := C.gtk_window_get_attached_to(v.native())
421445 if c == nil {
422 return nil, nilPtrErr
423 }
424 return wrapWidget(glib.Take(unsafe.Pointer(c))), nil
446 return nil, nil
447 }
448 return castWidget(c)
425449 }
426450
427451 // GetTypeHint is a wrapper around gtk_window_get_type_hint().
438462
439463 // GetSkipPagerHint is a wrapper around gtk_window_get_skip_pager_hint().
440464 func (v *Window) GetSkipPagerHint() bool {
441 c := C.gtk_window_get_skip_taskbar_hint(v.native())
465 c := C.gtk_window_get_skip_pager_hint(v.native())
442466 return gobool(c)
443467 }
444468
458482 func (v *Window) GetFocusOnMap() bool {
459483 c := C.gtk_window_get_focus_on_map(v.native())
460484 return gobool(c)
485 }
486
487 // GetWindowType is a wrapper around gtk_window_get_window_type().
488 func (v *Window) GetWindowType() WindowType {
489 c := C.gtk_window_get_window_type(v.native())
490 return WindowType(c)
461491 }
462492
463493 // HasGroup is a wrapper around gtk_window_has_group().
516546 C.gtk_window_set_icon_name(v.native(), (*C.gchar)(cstr))
517547 }
518548
519 // SetAutoStartupNotification is a wrapper around
549 // WindowSetAutoStartupNotification is a wrapper around
520550 // gtk_window_set_auto_startup_notification().
521 // This doesn't seem write. Might need to rethink?
522 /*
523 func (v *Window) SetAutoStartupNotification(setting bool) {
551 func WindowSetAutoStartupNotification(setting bool) {
524552 C.gtk_window_set_auto_startup_notification(gbool(setting))
525553 }
526 */
527554
528555 // GetMnemonicsVisible is a wrapper around
529556 // gtk_window_get_mnemonics_visible().
533560 }
534561
535562 // SetMnemonicsVisible is a wrapper around
536 // gtk_window_get_mnemonics_visible().
563 // gtk_window_set_mnemonics_visible().
537564 func (v *Window) SetMnemonicsVisible(setting bool) {
538565 C.gtk_window_set_mnemonics_visible(v.native(), gbool(setting))
539566 }
553580 func (v *Window) GetApplication() (*Application, error) {
554581 c := C.gtk_window_get_application(v.native())
555582 if c == nil {
556 return nil, nilPtrErr
557 }
558
583 return nil, nil
584 }
559585 return wrapApplication(glib.Take(unsafe.Pointer(c))), nil
560586 }
561587
597623 C.gtk_window_set_mnemonic_modifier(v.native(), C.GdkModifierType(mods))
598624 }
599625
600 // TODO gtk_window_begin_move_drag().
601 // TODO gtk_window_begin_resize_drag().
602 // TODO gtk_window_get_default_icon_list().
603 // TODO gtk_window_get_group().
604 // TODO gtk_window_get_icon_list().
605 // TODO gtk_window_get_window_type().
606 // TODO gtk_window_list_toplevels().
607 // TODO gtk_window_parse_geometry().
608 // TODO gtk_window_propagate_key_event().
609 // TODO gtk_window_set_attached_to().
610 // TODO gtk_window_set_default_icon_list().
611 // TODO gtk_window_set_icon_list().
612 // TODO gtk_window_set_screen().
613 // TODO gtk_window_get_resize_grip_area().
626 // SetScreen is a wrapper around gtk_window_set_screen().
627 func (v *Window) SetScreen(screen *gdk.Screen) {
628 C.gtk_window_set_screen(v.native(), C.toGdkScreen(unsafe.Pointer(screen.Native())))
629 }
630
631 // GetScreen is a wrapper around gtk_window_get_screen().
632 func (v *Window) GetScreen() *gdk.Screen {
633 c := C.gtk_window_get_screen(v.native())
634 return &gdk.Screen{glib.Take(unsafe.Pointer(c))}
635 }
636
637 // PropagateKeyEvent is a wrapper around gtk_window_propagate_key_event().
638 func (v *Window) PropagateKeyEvent(event *gdk.EventKey) bool {
639 c := C.gtk_window_propagate_key_event(v.native(), (*C.GdkEventKey)(unsafe.Pointer(event.Native())))
640 return gobool(c)
641 }
642
643 // WindowListToplevels is a wrapper around gtk_window_list_toplevels().
644 // Returned list is wrapped to return *gtk.Window elements.
645 // TODO: Use IWindow and wrap to correct type
646 func WindowListToplevels() *glib.List {
647 clist := C.gtk_window_list_toplevels()
648 if clist == nil {
649 return nil
650 }
651 glist := glib.WrapList(uintptr(unsafe.Pointer(clist)))
652 glist.DataWrapper(func(ptr unsafe.Pointer) interface{} {
653 return wrapWindow(glib.Take(ptr))
654 })
655 runtime.SetFinalizer(glist, func(l *glib.List) {
656 l.Free()
657 })
658 return glist
659 }
660
661 // WindowGetDefaultIconList is a wrapper around gtk_window_get_default_icon_list().
662 // Returned list is wrapped to return *gdk.Pixbuf elements.
663 func WindowGetDefaultIconList() *glib.List {
664 clist := C.gtk_window_get_default_icon_list()
665 if clist == nil {
666 return nil
667 }
668 glist := glib.WrapList(uintptr(unsafe.Pointer(clist)))
669 glist.DataWrapper(func(ptr unsafe.Pointer) interface{} {
670 return &gdk.Pixbuf{glib.Take(ptr)}
671 })
672 runtime.SetFinalizer(glist, func(l *glib.List) {
673 l.Free()
674 })
675 return glist
676 }
677
678 // GetIconList is a wrapper around gtk_window_get_icon_list().
679 // Returned list is wrapped to return *gdk.Pixbuf elements.
680 func (v *Window) GetIconList() *glib.List {
681 clist := C.gtk_window_get_icon_list(v.native())
682 if clist == nil {
683 return nil
684 }
685 glist := glib.WrapList(uintptr(unsafe.Pointer(clist)))
686 glist.DataWrapper(func(ptr unsafe.Pointer) interface{} {
687 return &gdk.Pixbuf{glib.Take(ptr)}
688 })
689 runtime.SetFinalizer(glist, func(l *glib.List) {
690 l.Free()
691 })
692 return glist
693 }
694
695 // WindowSetDefaultIconList is a wrapper around gtk_window_set_default_icon_list().
696 // List should only contain *gdk.Pixbuf elements!
697 func WindowSetDefaultIconList(list *glib.List) {
698 native := (*C.struct__GList)(unsafe.Pointer(list.Native()))
699 C.gtk_window_set_default_icon_list(native)
700 }
701
702 // SetIconList is a wrapper around gtk_window_set_icon_list().
703 // List should only contain *gdk.Pixbuf elements!
704 func (v *Window) SetIconList(list *glib.List) {
705 native := (*C.struct__GList)(unsafe.Pointer(list.Native()))
706 C.gtk_window_set_icon_list(v.native(), native)
707 }
708
709 // BeginResizeDrag is a wrapper around gtk_window_begin_resize_drag().
710 func (v *Window) BeginResizeDrag(edge gdk.WindowEdge, button gdk.Button, rootX, rootY int, timestamp uint32) {
711 C.gtk_window_begin_resize_drag(v.native(), C.GdkWindowEdge(edge), C.gint(button), C.gint(rootX), C.gint(rootY), C.guint32(timestamp))
712 }
713
714 // BeginMoveDrag is a wrapper around gtk_window_begin_move_drag().
715 func (v *Window) BeginMoveDrag(button gdk.Button, rootX, rootY int, timestamp uint32) {
716 C.gtk_window_begin_move_drag(v.native(), C.gint(button), C.gint(rootX), C.gint(rootY), C.guint32(timestamp))
717 }
718
719 // GetGroup is a wrapper around gtk_window_get_group().
720 func (v *Window) GetGroup() *WindowGroup {
721 c := C.gtk_window_get_group(v.native())
722 if c == nil {
723 return nil
724 }
725 return wrapWindowGroup(glib.Take(unsafe.Pointer(c)))
726 }
00 // Same copyright and license as the rest of the files in this project
1 // This file contains accelerator related functions and structures
21
32 // +build !gtk_3_6,!gtk_3_8
43 // not use this: go build -tags gtk_3_8'. Otherwise, if no build tags are used, GTK 3.10
0 // Same copyright and license as the rest of the files in this project
1
02 // +build !gtk_3_6,!gtk_3_8,!gtk_3_10
13
24 package gtk
0 // Same copyright and license as the rest of the files in this project
1
2 // +build !gtk_3_6,!gtk_3_8,!gtk_3_10,!gtk_3_12
3
4 package gtk
5
6 // #include <gtk/gtk.h>
7 import "C"
8
9 // SetInteractiveDebugging is a wrapper around gtk_window_set_interactive_debugging().
10 func SetInteractiveDebugging(enable bool) {
11 C.gtk_window_set_interactive_debugging(gbool(enable))
12 }
0 // Same copyright and license as the rest of the files in this project
1
2 // +build !gtk_3_6,!gtk_3_8,!gtk_3_10,!gtk_3_12,!gtk_3_14
3
4 package gtk
5
6 // #include <gtk/gtk.h>
7 import "C"
8
9 // GetTitlebar is a wrapper around gtk_window_get_titlebar().
10 func (v *Window) GetTitlebar() (IWidget, error) {
11 c := C.gtk_window_get_titlebar(v.native())
12 if c == nil {
13 return nil, nil
14 }
15 return castWidget(c)
16 }
0 // Same copyright and license as the rest of the files in this project
1
2 // +build !gtk_3_6,!gtk_3_8,!gtk_3_10,!gtk_3_12,!gtk_3_14
3
4 // Package gtk_test is a separate package for unit tests.
5 // Doing this actually utilizes the go build cache
6 // for package gtk when changing unit test code.
7 package gtk_test
8
9 import (
10 "testing"
11
12 "github.com/gotk3/gotk3/gtk"
13 )
14
15 func TestWindowGetSetTitlebar(t *testing.T) {
16 win := createTestWindow(t)
17
18 // Create test button, SetCanDefault is required for SetDefault to work
19 expected, err := gtk.ButtonNew()
20 if err != nil {
21 t.Error("unexpected error:", err.Error())
22 }
23 win.SetTitlebar(expected)
24
25 a, err := win.GetTitlebar()
26 if err != nil {
27 t.Error("unexpected cast failure:", err.Error())
28 }
29 actual := a.ToWidget()
30 if expected.Native() != actual.Native() {
31 t.Errorf("Expected '0x%x'; Got '0x%x'", expected.Native(), actual.Native())
32 }
33 }
0 // Same copyright and license as the rest of the files in this project
1
2 // +build !gtk_3_6,!gtk_3_8,!gtk_3_10,!gtk_3_12,!gtk_3_14,!gtk_3_16
3
4 package gtk
5
6 // #include <gtk/gtk.h>
7 // #include "gtk.go.h"
8 import "C"
9 import (
10 "unsafe"
11
12 "github.com/gotk3/gotk3/gdk"
13 )
14
15 // FullscreenOnMonitor is a wrapper around gtk_window_fullscreen_on_monitor().
16 func (v *Window) FullscreenOnMonitor(screen *gdk.Screen, monitor int) {
17 C.gtk_window_fullscreen_on_monitor(v.native(), C.toGdkScreen(unsafe.Pointer(screen.Native())), C.gint(monitor))
18 }
0 // Same copyright and license as the rest of the files in this project
1
2 // Package gtk_test is a separate package for unit tests.
3 // Doing this actually utilizes the go build cache
4 // for package gtk when changing unit test code.
5 package gtk_test
6
7 import (
8 "testing"
9
10 "github.com/gotk3/gotk3/gdk"
11 "github.com/gotk3/gotk3/gtk"
12 )
13
14 func TestWindowNew(t *testing.T) {
15 cut, err := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
16 if err != nil {
17 t.Error("unexpected error:", err.Error())
18 }
19
20 actual := cut.GetWindowType()
21 if gtk.WINDOW_TOPLEVEL != actual {
22 t.Errorf("Expected WindowType '%d'; Got '%d'", gtk.WINDOW_TOPLEVEL, actual)
23 }
24 }
25
26 func createTestWindow(t *testing.T) *gtk.Window {
27 win, err := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
28 if err != nil {
29 t.Error("unexpected error:", err.Error())
30 }
31
32 return win
33 }
34
35 func TestWindowGetSetTitle(t *testing.T) {
36 win := createTestWindow(t)
37
38 expected := "Unit Test Window"
39 win.SetTitle(expected)
40
41 actual, err := win.GetTitle()
42 if err != nil {
43 t.Error("unexpected error:", err.Error())
44 }
45 if expected != actual {
46 t.Errorf("Expected '%s'; Got '%s'", expected, actual)
47 }
48 }
49
50 func TestWindowGetSetIconName(t *testing.T) {
51 win := createTestWindow(t)
52
53 expected := "unit-icon-symbolic"
54 win.SetIconName(expected)
55
56 actual, err := win.GetIconName()
57 if err != nil {
58 t.Error("unexpected error:", err.Error())
59 }
60 if expected != actual {
61 t.Errorf("Expected '%s'; Got '%s'", expected, actual)
62 }
63 }
64
65 func TestWindowGetSetDefaultIconName(t *testing.T) {
66 expected := "unit-icon-symbolic"
67 gtk.WindowSetDefaultIconName(expected)
68
69 actual, err := gtk.WindowGetDefaultIconName()
70 if err != nil {
71 t.Error("unexpected error:", err.Error())
72 }
73 if expected != actual {
74 t.Errorf("Expected '%s'; Got '%s'", expected, actual)
75 }
76 }
77
78 func TestWindowGetSetRole(t *testing.T) {
79 win := createTestWindow(t)
80
81 expected := "Unit Test Role"
82 win.SetRole(expected)
83
84 actual, err := win.GetRole()
85 if err != nil {
86 t.Error("unexpected error:", err.Error())
87 }
88 if expected != actual {
89 t.Errorf("Expected '%s'; Got '%s'", expected, actual)
90 }
91 }
92
93 func TestWindowGetSetTransientFor(t *testing.T) {
94 win := createTestWindow(t)
95
96 expected := createTestWindow(t)
97 win.SetTransientFor(expected)
98
99 actual, err := win.GetTransientFor()
100 if err != nil {
101 t.Error("unexpected error:", err.Error())
102 }
103 if expected.Native() != actual.Native() {
104 t.Errorf("Expected '0x%x'; Got '0x%x'", expected.Native(), actual.Native())
105 }
106 }
107
108 func TestWindowGetSetAttachedTo(t *testing.T) {
109 win := createTestWindow(t)
110
111 expected := createTestWindow(t)
112 win.SetAttachedTo(expected)
113
114 a, err := win.GetAttachedTo()
115 if err != nil {
116 t.Error("unexpected error:", err.Error())
117 }
118 actual := a.ToWidget()
119 if expected.Native() != actual.Native() {
120 t.Errorf("Expected '0x%x'; Got '0x%x'", expected.Native(), actual.Native())
121 }
122 }
123
124 func TestWindowGetSetDefaultSize(t *testing.T) {
125 win := createTestWindow(t)
126
127 expectedW, expectedH := 123, 345
128 win.SetDefaultSize(expectedW, expectedH)
129
130 actualW, actualH := win.GetDefaultSize()
131
132 if expectedW != actualW || expectedH != actualH {
133 t.Errorf("Expected %dx%d; Got %dx%d", expectedW, expectedH, actualW, actualH)
134 }
135 }
136
137 func TestWindowGetSetGravity(t *testing.T) {
138 win := createTestWindow(t)
139
140 var expected gdk.Gravity
141 expected = gdk.GDK_GRAVITY_EAST
142 win.SetGravity(expected)
143
144 actual := win.GetGravity()
145 if expected != actual {
146 t.Errorf("Expected '%d'; Got '%d'", expected, actual)
147 }
148 }
149
150 func TestWindowGetSetDefaultWidget(t *testing.T) {
151 win := createTestWindow(t)
152
153 // Create test button, SetCanDefault is required for SetDefault to work
154 expected, err := gtk.ButtonNew()
155 if err != nil {
156 t.Error("unexpected error:", err.Error())
157 }
158 expected.SetCanDefault(true)
159
160 win.SetDefault(expected)
161
162 a, err := win.GetDefaultWidget()
163 if err != nil {
164 t.Error("unexpected error:", err.Error())
165 }
166 actual := a.ToWidget()
167 if expected.Native() != actual.Native() {
168 t.Errorf("Expected '0x%x'; Got '0x%x'", expected.Native(), actual.Native())
169 }
170 }
171
172 func TestWindowGetSetDestroyWithParent(t *testing.T) {
173 win := createTestWindow(t)
174
175 testCases := []struct {
176 desc string
177 value bool
178 }{
179 {
180 desc: "true",
181 value: true,
182 },
183 {
184 desc: "true",
185 value: false,
186 },
187 }
188 for _, tC := range testCases {
189 t.Run(tC.desc, func(t *testing.T) {
190 win.SetDestroyWithParent(tC.value)
191
192 actual := win.GetDestroyWithParent()
193 if tC.value != actual {
194 t.Errorf("Expected '%t'; Got '%t'", tC.value, actual)
195 }
196 })
197 }
198 }
199
200 func TestWindowGetSetHideTitlebarWhenMaximized(t *testing.T) {
201 win := createTestWindow(t)
202
203 testCases := []struct {
204 desc string
205 value bool
206 }{
207 {
208 desc: "true",
209 value: true,
210 },
211 {
212 desc: "true",
213 value: false,
214 },
215 }
216 for _, tC := range testCases {
217 t.Run(tC.desc, func(t *testing.T) {
218 win.SetHideTitlebarWhenMaximized(tC.value)
219
220 actual := win.GetHideTitlebarWhenMaximized()
221 if tC.value != actual {
222 t.Errorf("Expected '%t'; Got '%t'", tC.value, actual)
223 }
224 })
225 }
226 }
227
228 func TestWindowGetSetResizable(t *testing.T) {
229 win := createTestWindow(t)
230
231 testCases := []struct {
232 desc string
233 value bool
234 }{
235 {
236 desc: "true",
237 value: true,
238 },
239 {
240 desc: "true",
241 value: false,
242 },
243 }
244 for _, tC := range testCases {
245 t.Run(tC.desc, func(t *testing.T) {
246 win.SetResizable(tC.value)
247
248 actual := win.GetResizable()
249 if tC.value != actual {
250 t.Errorf("Expected '%t'; Got '%t'", tC.value, actual)
251 }
252 })
253 }
254 }
255
256 func TestWindowGetSetModal(t *testing.T) {
257 win := createTestWindow(t)
258
259 testCases := []struct {
260 desc string
261 value bool
262 }{
263 {
264 desc: "true",
265 value: true,
266 },
267 {
268 desc: "true",
269 value: false,
270 },
271 }
272 for _, tC := range testCases {
273 t.Run(tC.desc, func(t *testing.T) {
274 win.SetModal(tC.value)
275
276 actual := win.GetModal()
277 if tC.value != actual {
278 t.Errorf("Expected '%t'; Got '%t'", tC.value, actual)
279 }
280 })
281 }
282 }
283
284 func TestWindowGetSetDecorated(t *testing.T) {
285 win := createTestWindow(t)
286
287 testCases := []struct {
288 desc string
289 value bool
290 }{
291 {
292 desc: "true",
293 value: true,
294 },
295 {
296 desc: "true",
297 value: false,
298 },
299 }
300 for _, tC := range testCases {
301 t.Run(tC.desc, func(t *testing.T) {
302 win.SetDecorated(tC.value)
303
304 actual := win.GetDecorated()
305 if tC.value != actual {
306 t.Errorf("Expected '%t'; Got '%t'", tC.value, actual)
307 }
308 })
309 }
310 }
311
312 func TestWindowGetSetDeletable(t *testing.T) {
313 win := createTestWindow(t)
314
315 testCases := []struct {
316 desc string
317 value bool
318 }{
319 {
320 desc: "true",
321 value: true,
322 },
323 {
324 desc: "true",
325 value: false,
326 },
327 }
328 for _, tC := range testCases {
329 t.Run(tC.desc, func(t *testing.T) {
330 win.SetDeletable(tC.value)
331
332 actual := win.GetDeletable()
333 if tC.value != actual {
334 t.Errorf("Expected '%t'; Got '%t'", tC.value, actual)
335 }
336 })
337 }
338 }
339
340 func TestWindowGetSetSkipTaskbarHint(t *testing.T) {
341 win := createTestWindow(t)
342
343 testCases := []struct {
344 desc string
345 value bool
346 }{
347 {
348 desc: "true",
349 value: true,
350 },
351 {
352 desc: "true",
353 value: false,
354 },
355 }
356 for _, tC := range testCases {
357 t.Run(tC.desc, func(t *testing.T) {
358 win.SetSkipTaskbarHint(tC.value)
359
360 actual := win.GetSkipTaskbarHint()
361 if tC.value != actual {
362 t.Errorf("Expected '%t'; Got '%t'", tC.value, actual)
363 }
364 })
365 }
366 }
367
368 func TestWindowGetSetSkipPagerHint(t *testing.T) {
369 win := createTestWindow(t)
370
371 testCases := []struct {
372 desc string
373 value bool
374 }{
375 {
376 desc: "true",
377 value: true,
378 },
379 {
380 desc: "true",
381 value: false,
382 },
383 }
384 for _, tC := range testCases {
385 t.Run(tC.desc, func(t *testing.T) {
386 win.SetSkipPagerHint(tC.value)
387
388 actual := win.GetSkipPagerHint()
389 if tC.value != actual {
390 t.Errorf("Expected '%t'; Got '%t'", tC.value, actual)
391 }
392 })
393 }
394 }
395
396 func TestWindowGetSetUrgencyHint(t *testing.T) {
397 win := createTestWindow(t)
398
399 testCases := []struct {
400 desc string
401 value bool
402 }{
403 {
404 desc: "true",
405 value: true,
406 },
407 {
408 desc: "true",
409 value: false,
410 },
411 }
412 for _, tC := range testCases {
413 t.Run(tC.desc, func(t *testing.T) {
414 win.SetUrgencyHint(tC.value)
415
416 actual := win.GetUrgencyHint()
417 if tC.value != actual {
418 t.Errorf("Expected '%t'; Got '%t'", tC.value, actual)
419 }
420 })
421 }
422 }
423
424 func TestWindowGetSetAcceptFocus(t *testing.T) {
425 win := createTestWindow(t)
426
427 testCases := []struct {
428 desc string
429 value bool
430 }{
431 {
432 desc: "true",
433 value: true,
434 },
435 {
436 desc: "true",
437 value: false,
438 },
439 }
440 for _, tC := range testCases {
441 t.Run(tC.desc, func(t *testing.T) {
442 win.SetAcceptFocus(tC.value)
443
444 actual := win.GetAcceptFocus()
445 if tC.value != actual {
446 t.Errorf("Expected '%t'; Got '%t'", tC.value, actual)
447 }
448 })
449 }
450 }
451
452 func TestWindowGetSetFocusOnMap(t *testing.T) {
453 win := createTestWindow(t)
454
455 testCases := []struct {
456 desc string
457 value bool
458 }{
459 {
460 desc: "true",
461 value: true,
462 },
463 {
464 desc: "true",
465 value: false,
466 },
467 }
468 for _, tC := range testCases {
469 t.Run(tC.desc, func(t *testing.T) {
470 win.SetFocusOnMap(tC.value)
471
472 actual := win.GetFocusOnMap()
473 if tC.value != actual {
474 t.Errorf("Expected '%t'; Got '%t'", tC.value, actual)
475 }
476 })
477 }
478 }
479
480 func TestWindowGetSetMnemonicsVisible(t *testing.T) {
481 win := createTestWindow(t)
482
483 testCases := []struct {
484 desc string
485 value bool
486 }{
487 {
488 desc: "true",
489 value: true,
490 },
491 {
492 desc: "true",
493 value: false,
494 },
495 }
496 for _, tC := range testCases {
497 t.Run(tC.desc, func(t *testing.T) {
498 win.SetMnemonicsVisible(tC.value)
499
500 actual := win.GetMnemonicsVisible()
501 if tC.value != actual {
502 t.Errorf("Expected '%t'; Got '%t'", tC.value, actual)
503 }
504 })
505 }
506 }
507
508 func TestWindowGetSetFocusVisible(t *testing.T) {
509 win := createTestWindow(t)
510
511 testCases := []struct {
512 desc string
513 value bool
514 }{
515 {
516 desc: "true",
517 value: true,
518 },
519 {
520 desc: "true",
521 value: false,
522 },
523 }
524 for _, tC := range testCases {
525 t.Run(tC.desc, func(t *testing.T) {
526 win.SetFocusVisible(tC.value)
527
528 actual := win.GetFocusVisible()
529 if tC.value != actual {
530 t.Errorf("Expected '%t'; Got '%t'", tC.value, actual)
531 }
532 })
533 }
534 }
535
536 func TestWindowGetSetTypeHint(t *testing.T) {
537 win := createTestWindow(t)
538
539 var expected gdk.WindowTypeHint
540 expected = gdk.WINDOW_TYPE_HINT_UTILITY
541 win.SetTypeHint(expected)
542
543 actual := win.GetTypeHint()
544 if expected != actual {
545 t.Errorf("Expected '%d'; Got '%d'", expected, actual)
546 }
547 }
0 // Same copyright and license as the rest of the files in this project
1
2 package gtk
3
4 // #include <gtk/gtk.h>
5 // #include "gtk.go.h"
6 import "C"
7 import (
8 "runtime"
9 "unsafe"
10
11 "github.com/gotk3/gotk3/gdk"
12 "github.com/gotk3/gotk3/glib"
13 )
14
15 /*
16 * GtkWindowGroup
17 */
18
19 type WindowGroup struct {
20 *glib.Object
21 }
22
23 // native returns a pointer to the underlying GtkWindowGroup.
24 func (v *WindowGroup) native() *C.GtkWindowGroup {
25 if v == nil || v.GObject == nil {
26 return nil
27 }
28 p := unsafe.Pointer(v.GObject)
29 return C.toGtkWindowGroup(p)
30 }
31
32 func marshalWindowGroup(p uintptr) (interface{}, error) {
33 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
34 obj := glib.Take(unsafe.Pointer(c))
35 return wrapWindowGroup(obj), nil
36 }
37
38 func wrapWindowGroup(obj *glib.Object) *WindowGroup {
39 if obj == nil {
40 return nil
41 }
42
43 return &WindowGroup{obj}
44 }
45
46 // WindowGroupNew is a wrapper around gtk_window_group_new().
47 func WindowGroupNew() (*WindowGroup, error) {
48 c := C.gtk_window_group_new()
49 if c == nil {
50 return nil, nilPtrErr
51 }
52 return wrapWindowGroup(glib.Take(unsafe.Pointer(c))), nil
53 }
54
55 // AddWindow is a wrapper around gtk_window_group_add_window().
56 func (v *WindowGroup) AddWindow(window IWindow) {
57 var pw *C.GtkWindow = nil
58 if window != nil {
59 pw = window.toWindow()
60 }
61 C.gtk_window_group_add_window(v.native(), pw)
62 }
63
64 // RemoveWindow is a wrapper around gtk_window_group_remove_window().
65 func (v *WindowGroup) RemoveWindow(window IWindow) {
66 var pw *C.GtkWindow = nil
67 if window != nil {
68 pw = window.toWindow()
69 }
70 C.gtk_window_group_remove_window(v.native(), pw)
71 }
72
73 // ListWindows is a wrapper around gtk_window_group_list_windows().
74 // Returned list is wrapped to return *gtk.Window elements.
75 // TODO: Use IWindow and wrap to correct type
76 func (v *WindowGroup) ListWindows() *glib.List {
77 clist := C.gtk_window_group_list_windows(v.native())
78 if clist == nil {
79 return nil
80 }
81 glist := glib.WrapList(uintptr(unsafe.Pointer(clist)))
82 glist.DataWrapper(func(ptr unsafe.Pointer) interface{} {
83 return wrapWindow(glib.Take(ptr))
84 })
85 runtime.SetFinalizer(glist, func(l *glib.List) {
86 l.Free()
87 })
88 return glist
89 }
90
91 // GetCurrentGrab is a wrapper around gtk_window_group_get_current_grab().
92 func (v *WindowGroup) GetCurrentGrab() (IWidget, error) {
93 c := C.gtk_window_group_get_current_grab(v.native())
94 if c == nil {
95 return nil, nil
96 }
97 return castWidget(c)
98 }
99
100 // GetCurrentDeviceGrab is a wrapper around gtk_window_group_get_current_device_grab().
101 func (v *WindowGroup) GetCurrentDeviceGrab(device *gdk.Device) (IWidget, error) {
102 c := C.gtk_window_group_get_current_device_grab(v.native(), C.toGdkDevice(unsafe.Pointer(device.Native())))
103 if c == nil {
104 return nil, nil
105 }
106 return castWidget(c)
107 }
0 package callback
1
2 import (
3 "sync"
4
5 "github.com/gotk3/gotk3/internal/slab"
6 )
7
8 var (
9 mutex sync.RWMutex
10 registry slab.Slab
11 )
12
13 func Assign(callback interface{}) uintptr {
14 mutex.Lock()
15 defer mutex.Unlock()
16
17 return registry.Put(callback)
18 }
19
20 func Get(ptr uintptr) interface{} {
21 mutex.RLock()
22 defer mutex.RUnlock()
23
24 return registry.Get(ptr)
25 }
26
27 func Delete(ptr uintptr) {
28 GetAndDelete(ptr)
29 }
30
31 func GetAndDelete(ptr uintptr) interface{} {
32 mutex.Lock()
33 defer mutex.Unlock()
34
35 return registry.Pop(ptr)
36 }
0 package closure
1
2 import (
3 "sync"
4 "unsafe"
5 )
6
7 var (
8 closures = sync.Map{} // unsafe.Pointer(*GClosure) -> reflect.Value
9
10 // use a bi-directional map to allow lookup of the closure value from both
11 // the SourceHandle and the closure ID in constant time.
12 signalMu sync.Mutex
13 signalClosures = map[uint]unsafe.Pointer{} // uint(SourceHandle) -> uintptr (closure key, callbackID)
14 closureSignals = map[unsafe.Pointer]uint{} // unsafe.Pointer(*GClosure) -> uint(SourceHandle)
15 )
16
17 // RegisterSignal registers the given signal handle to be associated with the
18 // closure pointer. This association allows the closure to be removed as well
19 // when the signal removal is requested from the user using DisconnectSignal.
20 func RegisterSignal(handle uint, closure unsafe.Pointer) {
21 // Safety check omitted until the race condition in glib/connect.go is
22 // fixed. Check that file for more info.
23
24 signalMu.Lock()
25 defer signalMu.Unlock()
26
27 signalClosures[handle] = closure
28 closureSignals[closure] = handle
29 }
30
31 // DisconnectSignal removes both the signal and the closure associated with it
32 // from the internal registry. Since this function will also remove the closure
33 // itself from the internal registry, Gtk's disconnect functions should be
34 // called first.
35 func DisconnectSignal(handle uint) {
36 signalMu.Lock()
37 defer signalMu.Unlock()
38
39 closure, ok := signalClosures[handle]
40 if ok {
41 closures.Delete(closure)
42 delete(closureSignals, closure)
43 delete(signalClosures, handle)
44 }
45 }
46
47 // Assign assigns the given FuncStack to the given closure.
48 func Assign(closure unsafe.Pointer, fs FuncStack) {
49 closures.Store(closure, fs)
50 }
51
52 // Get gets the reflect-value callback from the closure pointer.
53 func Get(closure unsafe.Pointer) FuncStack {
54 v, ok := closures.Load(closure)
55 if ok {
56 return v.(FuncStack)
57 }
58 return zeroFuncStack
59 }
60
61 // Delete deletes the closure pointer from the registry while also checking for
62 // any existing signal handler associated with the given callback ID. If a
63 // signal handler is found, then its behavior is similar to DisconnectSignal.
64 func Delete(closure unsafe.Pointer) {
65 funcStack := getAndDeleteClosure(closure)
66 if !funcStack.IsValid() {
67 return
68 }
69
70 signalMu.Lock()
71 defer signalMu.Unlock()
72
73 handle, ok := closureSignals[closure]
74 if ok {
75 delete(closureSignals, closure)
76 delete(signalClosures, handle)
77 }
78 }
0 // +build !go1.15
1
2 package closure
3
4 import "unsafe"
5
6 func getAndDeleteClosure(closure unsafe.Pointer) FuncStack {
7 v, ok := closures.Load(closure)
8 if ok {
9 closures.Delete(closure)
10 return v.(FuncStack)
11 }
12 return zeroFuncStack
13 }
0 // +build go1.15
1
2 package closure
3
4 import "unsafe"
5
6 func getAndDeleteClosure(closure unsafe.Pointer) FuncStack {
7 v, ok := closures.LoadAndDelete(closure)
8 if ok {
9 return v.(FuncStack)
10 }
11 return zeroFuncStack
12 }
0 package closure
1
2 import (
3 "fmt"
4 "reflect"
5 "runtime"
6 "strconv"
7 "strings"
8 "sync"
9 )
10
11 // FrameSize is the number of frames that FuncStack should trace back from.
12 const FrameSize = 3
13
14 // FuncStack wraps a function value and provides function frames containing the
15 // caller trace for debugging.
16 type FuncStack struct {
17 Func reflect.Value
18 Frames []uintptr
19 }
20
21 var zeroFuncStack = FuncStack{}
22
23 // NewFuncStack creates a new FuncStack. It panics if fn is not a function. The
24 // given frameSkip is added 2, meaning the first frame from 0 will start from
25 // the caller of NewFuncStack.
26 func NewFuncStack(fn interface{}, frameSkip int) FuncStack {
27 // Create a reflect.Value from f. This is called when the returned
28 // GClosure runs.
29 rf := reflect.ValueOf(fn)
30
31 // Closures can only be created from funcs.
32 if rf.Type().Kind() != reflect.Func {
33 panic("closure value is not a func")
34 }
35
36 frames := make([]uintptr, FrameSize)
37 frames = frames[:runtime.Callers(frameSkip+2, frames)]
38
39 return FuncStack{
40 Func: rf,
41 Frames: frames,
42 }
43 }
44
45 var (
46 idleTypeCache sync.Map
47 idleTypeSentinel = struct{}{}
48 )
49
50 // NewIdleFuncStack works akin to NewFuncStack, but it also validates the given
51 // function type for the correct acceptable signatures for SourceFunc while also
52 // caching the checks.
53 func NewIdleFuncStack(fn interface{}, frameSkip int) FuncStack {
54 fs := NewFuncStack(fn, frameSkip+1)
55 funcType := fs.Func.Type()
56
57 // LoadOrStore will actually ensure that only 1 check is done at a time, but
58 // future checks on failed functions may trigger a late panic.
59 _, checked := idleTypeCache.LoadOrStore(funcType, idleTypeSentinel)
60 if checked {
61 return fs
62 }
63
64 // Ensure no parameters prematurely.
65 if funcType.NumIn() > 0 {
66 fs.Panicf("timeout source should have no parameters")
67 }
68
69 // Ensure proper return types.
70 switch out := funcType.NumOut(); out {
71 case 0:
72 break
73 case 1:
74 out0 := funcType.Out(0)
75 if out0.Kind() != reflect.Bool {
76 fs.Panicf("expected bool in return type, got %v", out0.Kind())
77 }
78 default:
79 fs.Panicf("unexpected return count (expecting 0 or 1): %d", out)
80 }
81
82 return fs
83 }
84
85 // IsValid returns true if the given FuncStack is not a zero-value i.e. valid.
86 func (fs FuncStack) IsValid() bool {
87 return fs.Frames != nil
88 }
89
90 const headerSignature = "closure error: "
91
92 // Panicf panics with the given FuncStack printed to standard error.
93 func (fs FuncStack) Panicf(msgf string, v ...interface{}) {
94 msg := strings.Builder{}
95 msg.WriteString(headerSignature)
96 fmt.Fprintf(&msg, msgf, v...)
97
98 msg.WriteString("\n\nClosure added at:")
99
100 frames := runtime.CallersFrames(fs.Frames)
101 for {
102 frame, more := frames.Next()
103 msg.WriteString("\n\t")
104 msg.WriteString(frame.Function)
105 msg.WriteString(" at ")
106 msg.WriteString(frame.File)
107 msg.WriteByte(':')
108 msg.WriteString(strconv.Itoa(frame.Line))
109
110 if !more {
111 break
112 }
113 }
114
115 panic(msg.String())
116 }
117
118 // TryRepanic attempts to recover a panic. If successful, it will re-panic with
119 // the trace, or none if there is already one.
120 func (fs FuncStack) TryRepanic() {
121 panicking := recover()
122 if panicking == nil {
123 return
124 }
125
126 if msg, ok := panicking.(string); ok {
127 if strings.HasPrefix(msg, headerSignature) {
128 // We can just repanic as-is.
129 panic(msg)
130 }
131 }
132
133 fs.Panicf("unexpected panic caught: %v", panicking)
134 }
0 package slab
1
2 type slabEntry struct {
3 Value interface{}
4 Index uintptr
5 }
6
7 func (entry slabEntry) IsValid() bool {
8 return entry.Value != nil
9 }
10
11 // Slab is an implementation of the internal registry free list. A zero-value
12 // instance is a valid instance. This data structure is not thread-safe.
13 type Slab struct {
14 entries []slabEntry
15 free uintptr
16 }
17
18 func (s *Slab) Put(entry interface{}) uintptr {
19 if s.free == uintptr(len(s.entries)) {
20 index := uintptr(len(s.entries))
21 s.entries = append(s.entries, slabEntry{entry, 0})
22 s.free++
23 return index
24 }
25
26 index := s.free
27
28 s.free = s.entries[index].Index
29 s.entries[index] = slabEntry{entry, 0}
30
31 return index
32 }
33
34 func (s *Slab) Get(i uintptr) interface{} {
35 // Perform bound check.
36 if i >= uintptr(len(s.entries)) {
37 return nil
38 }
39 // Perform validity check in case of invalid ID.
40 if entry := s.entries[i]; entry.IsValid() {
41 return entry.Value
42 }
43 return nil
44 }
45
46 func (s *Slab) Pop(i uintptr) interface{} {
47 popped := s.entries[i].Value
48 s.entries[i] = slabEntry{nil, s.free}
49 s.free = i
50 return popped
51 }
00
11 #include <fontconfig/fontconfig.h>
22
3 static int addFont(unsigned char* font) {
4 FcBool fontAddStatus = FcConfigAppFontAddFile(FcConfigGetCurrent(), font);
5 return fontAddStatus;
3 static int addFont(unsigned char *font) {
4 FcBool fontAddStatus = FcConfigAppFontAddFile(FcConfigGetCurrent(), font);
5 return fontAddStatus;
66 }
102102
103103 func (v *AttrList) native() *C.PangoAttrList {
104104 return (*C.PangoAttrList)(unsafe.Pointer(v.pangoAttrList))
105 }
106
107 func (v *AttrList) Insert(attribute *Attribute) {
108 C.pango_attr_list_insert(v.pangoAttrList, attribute.native())
109 }
110
111 func AttrListNew() *AttrList {
112 c := C.pango_attr_list_new()
113 attrList := new(AttrList)
114 attrList.pangoAttrList = c
115 return attrList
105116 }
106117
107118 // AttrType is a representation of Pango's PangoAttrType.
1919 #include <stdlib.h>
2020 #include <string.h>
2121
22 static PangoColor* toPangoColor(void *p)
23 {
24 return ( (PangoColor*) (p) );
25 }
26
22 static PangoColor *toPangoColor(void *p) { return ((PangoColor *)(p)); }
0 // +build !pango_1_42
1
2 package pango
3
4 // #include <pango/pango.h>
5 // #include "pango.go.h"
6 import "C"
7
8 var (
9 ATTR_INSERT_HYPHENS AttrType = C.PANGO_ATTR_INSERT_HYPHENS
10 )
11
12 func AttrInsertHyphensNew(insertHyphens bool) *Attribute {
13 c := C.pango_attr_insert_hyphens_new(gbool(insertHyphens))
14 attr := new(Attribute)
15 attr.pangoAttribute = c
16 return attr
17 }
245245
246246 //void pango_font_description_set_variant (PangoFontDescription *desc,
247247 // PangoVariant variant);
248 func (v *FontDescription) SetVariant(variant Variant) {
249 C.pango_font_description_set_variant(v.native(), (C.PangoVariant)(variant))
250 }
251
248252 //PangoVariant pango_font_description_get_variant (const PangoFontDescription *desc) G_GNUC_PURE;
253 func (v *FontDescription) GetVariant() Variant {
254 c := C.pango_font_description_get_variant(v.native())
255 return Variant(c)
256 }
249257
250258 //void pango_font_description_set_weight (PangoFontDescription *desc,
251259 // PangoWeight weight);
2121 // #include "pango.go.h"
2222 import "C"
2323 import (
24 "runtime"
2425 "unsafe"
2526
2627 "github.com/gotk3/gotk3/glib"
3233 {glib.Type(C.pango_alignment_get_type()), marshalAlignment},
3334 {glib.Type(C.pango_ellipsize_mode_get_type()), marshalEllipsizeMode},
3435 {glib.Type(C.pango_wrap_mode_get_type()), marshalWrapMode},
36 {glib.Type(C.pango_tab_align_get_type()), marshalTabAlign},
3537
3638 // Objects/Interfaces
3739 // {glib.Type(C.pango_layout_get_type()), marshalLayout},
5052 }
5153
5254 func (v *Layout) native() *C.PangoLayout {
55 if v == nil {
56 return nil
57 }
5358 return (*C.PangoLayout)(unsafe.Pointer(v.pangoLayout))
5459 }
5560
7075 }
7176
7277 func (v *LayoutLine) native() *C.PangoLayoutLine {
78 if v == nil {
79 return nil
80 }
7381 return (*C.PangoLayoutLine)(unsafe.Pointer(v.pangoLayoutLine))
7482 }
7583
120128 return EllipsizeMode(c), nil
121129 }
122130
131 type TabAlign int
132
133 const (
134 TAB_LEFT TabAlign = C.PANGO_TAB_LEFT
135 )
136
137 func marshalTabAlign(p uintptr) (interface{}, error) {
138 c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
139 return TabAlign(c), nil
140 }
141
123142 /*
124143 func marshalLayout(p uintptr) (interface{}, error) {
125144 c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
132151 }
133152 */
134153
135 //PangoLayout *pango_layout_new (PangoContext *context);
154 // LayoutNew is a wrapper around pango_layout_new().
136155 func LayoutNew(context *Context) *Layout {
137156 c := C.pango_layout_new(context.native())
138157
141160 return layout
142161 }
143162
144 //PangoLayout *pango_layout_copy (PangoLayout *src);
163 // Copy is a wrapper around pango_layout_copy().
145164 func (v *Layout) Copy() *Layout {
146165 c := C.pango_layout_copy(v.native())
147166
150169 return layout
151170 }
152171
153 //PangoContext *pango_layout_get_context (PangoLayout *layout);
172 // GetContext is a wrapper around pango_layout_get_context().
154173 func (v *Layout) GetContext() *Context {
155174 c := C.pango_layout_get_context(v.native())
156175
160179 return context
161180 }
162181
163 //void pango_layout_set_attributes (PangoLayout *layout,
164 // PangoAttrList *attrs);
182 // SetAttributes is a wrapper around pango_layout_set_attributes().
165183 func (v *Layout) SetAttributes(attrs *AttrList) {
166184 C.pango_layout_set_attributes(v.native(), attrs.native())
167185 }
168186
169 //PangoAttrList *pango_layout_get_attributes (PangoLayout *layout);
187 // GetAttributes is a wrapper around pango_layout_get_attributes().
170188 func (v *Layout) GetAttributes() *AttrList {
171189 c := C.pango_layout_get_attributes(v.native())
172190
176194 return attrList
177195 }
178196
179 //void pango_layout_set_text (PangoLayout *layout,
180 // const char *text,
181 // int length);
197 // SetText is a wrapper around pango_layout_set_text().
182198 func (v *Layout) SetText(text string, length int) {
183199 cstr := C.CString(text)
184200 defer C.free(unsafe.Pointer(cstr))
185201 C.pango_layout_set_text(v.native(), (*C.char)(cstr), (C.int)(length))
186202 }
187203
188 //const char *pango_layout_get_text (PangoLayout *layout);
204 // GetText is a wrapper around pango_layout_get_text().
189205 func (v *Layout) GetText() string {
190206 c := C.pango_layout_get_text(v.native())
191207 return C.GoString((*C.char)(c))
192208 }
193209
194 //gint pango_layout_get_character_count (PangoLayout *layout);
210 // GetCharacterCount is a wrapper around pango_layout_get_character_count().
195211 func (v *Layout) GetCharacterCount() int {
196212 c := C.pango_layout_get_character_count(v.native())
197213 return int(c)
198214 }
199215
200 //void pango_layout_set_markup (PangoLayout *layout,
201 // const char *markup,
202 // int length);
216 // SetMarkup is a wrapper around pango_layout_set_markup().
203217 func (v *Layout) SetMarkup(text string, length int) {
204218 cstr := C.CString(text)
205219 defer C.free(unsafe.Pointer(cstr))
213227 // gunichar *accel_char);
214228
215229 /*
216 func (v *Layout)SetMarkupWithAccel (text string, length int, accel_marker, accel_char rune){
230 func (v *Layout) SetMarkupWithAccel (text string, length int, accel_marker, accel_char rune){
217231 cstr := C.CString(text)
218232 defer C.free(unsafe.Pointer(cstr))
219233 C.pango_layout_set_markup_with_accel (v.native(), (*C.char)(cstr), (C.int)(length), (C.gunichar)(accel_marker), (C.gunichar)(accel_char) )
220234 }
221235 */
222236
223 //void pango_layout_set_font_description (PangoLayout *layout,
224 // const PangoFontDescription *desc);
225
237 // SetFontDescription is a wrapper around pango_layout_set_font_description().
226238 func (v *Layout) SetFontDescription(desc *FontDescription) {
227239 C.pango_layout_set_font_description(v.native(), desc.native())
228240 }
229241
230 //const PangoFontDescription *pango_layout_get_font_description (PangoLayout *layout);
231
242 // GetFontDescription is a wrapper around pango_layout_get_font_description().
232243 func (v *Layout) GetFontDescription() *FontDescription {
233244 c := C.pango_layout_get_font_description(v.native())
234245
238249 return desc
239250 }
240251
241 //void pango_layout_set_width (PangoLayout *layout,
242 // int width);
243
252 // SetWidth is a wrapper around pango_layout_set_width().
244253 func (v *Layout) SetWidth(width int) {
245254 C.pango_layout_set_width(v.native(), C.int(width))
246255 }
247256
248 //int pango_layout_get_width (PangoLayout *layout);
249
257 // GetWidth is a wrapper around pango_layout_get_width().
250258 func (v *Layout) GetWidth() int {
251259 c := C.pango_layout_get_width(v.native())
252260 return int(c)
253261 }
254262
255 //void pango_layout_set_height (PangoLayout *layout,
256 // int height);
257
263 // SetHeight is a wrapper around pango_layout_set_height().
258264 func (v *Layout) SetHeight(width int) {
259265 C.pango_layout_set_height(v.native(), C.int(width))
260266 }
261267
262 //int pango_layout_get_height (PangoLayout *layout);
263
268 // GetHeight is a wrapper around pango_layout_get_height().
264269 func (v *Layout) GetHeight() int {
265270 c := C.pango_layout_get_height(v.native())
266271 return int(c)
267272 }
268273
269 //void pango_layout_set_wrap (PangoLayout *layout,
270 // PangoWrapMode wrap);
271
274 // SetWrap is a wrapper around pango_layout_set_wrap().
272275 func (v *Layout) SetWrap(wrap WrapMode) {
273276 C.pango_layout_set_wrap(v.native(), C.PangoWrapMode(wrap))
274277 }
275278
276 //PangoWrapMode pango_layout_get_wrap (PangoLayout *layout);
277
279 // WrapMode is a wrapper around pango_layout_get_wrap().
278280 func (v *Layout) GetWrap() WrapMode {
279281 c := C.pango_layout_get_wrap(v.native())
280282 return WrapMode(c)
281283 }
282284
283 //gboolean pango_layout_is_wrapped (PangoLayout *layout);
284
285 // IsWrapped is a wrapper around pango_layout_is_wrapped().
285286 func (v *Layout) IsWrapped() bool {
286287 c := C.pango_layout_is_wrapped(v.native())
287288 return gobool(c)
288289 }
289290
290 //void pango_layout_set_indent (PangoLayout *layout,
291 // int indent);
292
291 // SetIndent is a wrapper around pango_layout_set_indent().
293292 func (v *Layout) SetIndent(indent int) {
294293 C.pango_layout_set_indent(v.native(), C.int(indent))
295294 }
296295
297 //int pango_layout_get_indent (PangoLayout *layout);
298
296 // GetIndent is a wrapper around pango_layout_get_indent().
299297 func (v *Layout) GetIndent() int {
300298 c := C.pango_layout_get_indent(v.native())
301299 return int(c)
300 }
301
302 // SetTabs is a wrapper around pango_layout_set_tabs().
303 func (v *Layout) SetTabs(tabs *TabArray) {
304 C.pango_layout_set_tabs(v.native(), tabs.native())
305 }
306
307 // GetTabs is a wrapper around pango_layout_get_tabs().
308 func (v *Layout) GetTabs() (*TabArray, error) {
309 c := C.pango_layout_get_tabs(v.native())
310 if c == nil {
311 return nil, nilPtrErr
312 }
313 ta := wrapTabArray(c)
314 runtime.SetFinalizer(ta, (*TabArray).free)
315 return ta, nil
316 }
317
318 // GetSize is a wrapper around pango_layout_get_size().
319 func (v *Layout) GetSize() (int, int) {
320 var w, h C.int
321 C.pango_layout_get_size(v.native(), &w, &h)
322 return int(w), int(h)
323 }
324
325 /*
326 * TabArray
327 */
328
329 // TabArray is a representation of PangoTabArray.
330 type TabArray struct {
331 pangoTabArray *C.PangoTabArray
332 }
333
334 // Native returns a pointer to the underlying PangoTabArray.
335 func (v *TabArray) Native() uintptr {
336 return uintptr(unsafe.Pointer(v.native()))
337 }
338
339 func (v *TabArray) native() *C.PangoTabArray {
340 if v == nil {
341 return nil
342 }
343 return (*C.PangoTabArray)(unsafe.Pointer(v.pangoTabArray))
344 }
345
346 func wrapTabArray(tabArray *C.PangoTabArray) *TabArray {
347 return &TabArray{tabArray}
348 }
349
350 func WrapTabArray(p uintptr) *TabArray {
351 tabArray := new(TabArray)
352 tabArray.pangoTabArray = (*C.PangoTabArray)(unsafe.Pointer(p))
353 return tabArray
354 }
355
356 // TabArrayNew is a wrapper around pango_tab_array_new().
357 func TabArrayNew(initialSize int, positionsInPixels bool) *TabArray {
358 c := C.pango_tab_array_new(C.gint(initialSize), gbool(positionsInPixels))
359
360 tabArray := new(TabArray)
361 runtime.SetFinalizer(tabArray, (*TabArray).free)
362 tabArray.pangoTabArray = (*C.PangoTabArray)(c)
363 return tabArray
364 }
365
366 // TabArrayNewWithPositions is a wrapper around pango_tab_array_new_with_positions().
367 // func TabArrayNewWithPositions(size int, positionsInPixels bool, ...) *TabArray {
368 // c := C.pango_tab_array_new_with_positions(C.gint(size), gbool(positionsInPixels), ...)
369
370 // tabArray := new(TabArray)
371 // runtime.SetFinalizer(e, (*TabArray).free)
372 // tabArray.pangoTabArray = (*C.PangoTabArray)(c)
373 // return tabArray
374 // }
375
376 // Copy is a wrapper around pango_tab_array_copy().
377 func (v *TabArray) Copy() (*TabArray, error) {
378 c := C.pango_tab_array_copy(v.native())
379 if c == nil {
380 return nil, nilPtrErr
381 }
382 ta := wrapTabArray(c)
383 runtime.SetFinalizer(ta, (*TabArray).free)
384 return ta, nil
385 }
386
387 // free is a wrapper around pango_tab_array_free().
388 func (v *TabArray) free() {
389 C.pango_tab_array_free(v.native())
390 }
391
392 // free is a wrapper around pango_tab_array_free().
393 // This is only to enable other packages within gotk. Should not be used outside the gotk library.
394 func (v *TabArray) Free() {
395 C.pango_tab_array_free(v.native())
396 }
397
398 // GetSize is a wrapper around pango_tab_array_get_size().
399 func (v *TabArray) GetSize() int {
400 return int(C.pango_tab_array_get_size(v.native()))
401 }
402
403 // Resize is a wrapper around pango_tab_array_resize().
404 func (v *TabArray) Resize(newSize int) {
405 C.pango_tab_array_resize(v.native(), C.gint(newSize))
406 }
407
408 // SetTab is a wrapper around pango_tab_array_set_tab().
409 func (v *TabArray) SetTab(tabIndex int, alignment TabAlign, location int) {
410 C.pango_tab_array_set_tab(v.native(), C.gint(tabIndex), C.PangoTabAlign(alignment), C.gint(location))
411 }
412
413 // GetTab is a wrapper around pango_tab_array_get_tab().
414 func (v *TabArray) GetTab(tabIndex int) (TabAlign, int) {
415 var alignment C.PangoTabAlign
416 var location C.gint
417 C.pango_tab_array_get_tab(v.native(), C.gint(tabIndex), &alignment, &location)
418 return TabAlign(alignment), int(location)
419 }
420
421 // GetTabs is a wrapper around pango_tab_array_get_tabs().
422 // func (v *TabArray) GetTabs() ([]TabAlign, []int) {
423 // var alignment *C.PangoTabAlign
424 // var location *C.gint
425
426 // C.pango_tab_array_get_tabs(v.native(), &alignment, &location)
427
428 // size := v.GetSize()
429
430 // var goAlignments []TabAlign
431 // var goLocations []int
432
433 // if &alignment != nil {
434 // var ginthelp C.gint
435 // sizeOf := unsafe.Sizeof(ginthelp)
436 // for i := 0; i < int(size); i++ {
437 // goAlignmentElement := TabAlign(*((*C.gint)(unsafe.Pointer(location))))
438 // goAlignments = append(goAlignments, goAlignmentElement)
439 // location += sizeOf
440 // }
441 // }
442
443 // if &location != nil {
444 // var ginthelp C.gint
445 // sizeOf := unsafe.Sizeof(ginthelp)
446 // for i := 0; i < int(size); i++ {
447 // goLocationElement := int(*((*C.gint)(unsafe.Pointer(location))))
448 // goLocations = append(goLocations, goLocationElement)
449 // location += sizeOf
450 // }
451
452 // // TODO: free locations
453 // }
454
455 // return goAlignments, goLocations
456 // }
457
458 // GetPositionsInPixels is a wrapper around pango_tab_array_get_positions_in_pixels().
459 func (v *TabArray) GetPositionsInPixels() bool {
460 return gobool(C.pango_tab_array_get_positions_in_pixels(v.native()))
302461 }
303462
304463 //void pango_layout_set_spacing (PangoLayout *layout,
313472 //void pango_layout_set_alignment (PangoLayout *layout,
314473 // PangoAlignment alignment);
315474 //PangoAlignment pango_layout_get_alignment (PangoLayout *layout);
316 //
317 //void pango_layout_set_tabs (PangoLayout *layout,
318 // PangoTabArray *tabs);
319 //
320 //PangoTabArray* pango_layout_get_tabs (PangoLayout *layout);
321475 //
322476 //void pango_layout_set_single_paragraph_mode (PangoLayout *layout,
323477 // gboolean setting);
370524 //void pango_layout_get_pixel_extents (PangoLayout *layout,
371525 // PangoRectangle *ink_rect,
372526 // PangoRectangle *logical_rect);
373
374 //void pango_layout_get_size (PangoLayout *layout,
375 // int *width,
376 // int *height);
377 func (v *Layout) GetSize() (int, int) {
378 var w, h C.int
379 C.pango_layout_get_size(v.native(), &w, &h)
380 return int(w), int(h)
381 }
382
383527 //void pango_layout_get_pixel_size (PangoLayout *layout,
384528 // int *width,
385529 // int *height);
1919 #include <stdlib.h>
2020 #include <string.h>
2121
22 static PangoLayout* toPangoLayout(void *p)
23 {
24 return ( (PangoLayout*) (p) );
25 }
26
22 static PangoLayout *toPangoLayout(void *p) { return ((PangoLayout *)(p)); }
2020 // #include <pango/pango.h>
2121 // #include "pango.go.h"
2222 import "C"
23 import "errors"
2324
2425 // "github.com/andre-hub/gotk3/glib"
2526 // "unsafe"
4647 }
4748
4849 /*
50 * Unexported vars
51 */
52
53 var nilPtrErr = errors.New("cgo returned unexpected nil pointer")
54
55 /*
4956 * Constantes
5057 */
5158
2424
2525 #include "pangocairo.go.h"
2626
27
28 static PangoRectangle *
29 createPangoRectangle(int x, int y, int width, int height)
30 {
31 PangoRectangle *r = (PangoRectangle *)malloc(sizeof(PangoRectangle));
32 r->x = x;
33 r->y = y;
34 r->width = width;
35 r->height = height;
36 return r;
27 static PangoRectangle *createPangoRectangle(int x, int y, int width,
28 int height) {
29 PangoRectangle *r = (PangoRectangle *)malloc(sizeof(PangoRectangle));
30 r->x = x;
31 r->y = y;
32 r->width = width;
33 r->height = height;
34 return r;
3735 }