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// Go bindings for GDK 3.  Supports version 3.6 and later.
18package gdk
19
20// #cgo pkg-config: gdk-3.0 glib-2.0 gobject-2.0
21// #include <gdk/gdk.h>
22// #include "gdk.go.h"
23import "C"
24import (
25	"errors"
26	"reflect"
27	"runtime"
28	"strconv"
29	"unsafe"
30
31	"github.com/gotk3/gotk3/glib"
32)
33
34func init() {
35	tm := []glib.TypeMarshaler{
36		// Enums
37		{glib.Type(C.gdk_drag_action_get_type()), marshalDragAction},
38		{glib.Type(C.gdk_colorspace_get_type()), marshalColorspace},
39		{glib.Type(C.gdk_event_type_get_type()), marshalEventType},
40		{glib.Type(C.gdk_interp_type_get_type()), marshalInterpType},
41		{glib.Type(C.gdk_modifier_type_get_type()), marshalModifierType},
42		{glib.Type(C.gdk_pixbuf_alpha_mode_get_type()), marshalPixbufAlphaMode},
43		{glib.Type(C.gdk_event_mask_get_type()), marshalEventMask},
44
45		// Objects/Interfaces
46		{glib.Type(C.gdk_device_get_type()), marshalDevice},
47		{glib.Type(C.gdk_cursor_get_type()), marshalCursor},
48		{glib.Type(C.gdk_device_manager_get_type()), marshalDeviceManager},
49		{glib.Type(C.gdk_display_get_type()), marshalDisplay},
50		{glib.Type(C.gdk_drag_context_get_type()), marshalDragContext},
51		{glib.Type(C.gdk_pixbuf_get_type()), marshalPixbuf},
52		{glib.Type(C.gdk_rgba_get_type()), marshalRGBA},
53		{glib.Type(C.gdk_screen_get_type()), marshalScreen},
54		{glib.Type(C.gdk_visual_get_type()), marshalVisual},
55		{glib.Type(C.gdk_window_get_type()), marshalWindow},
56
57		// Boxed
58		{glib.Type(C.gdk_event_get_type()), marshalEvent},
59	}
60	glib.RegisterGValueMarshalers(tm)
61}
62
63/*
64 * Type conversions
65 */
66
67func gbool(b bool) C.gboolean {
68	if b {
69		return C.gboolean(1)
70	}
71	return C.gboolean(0)
72}
73func gobool(b C.gboolean) bool {
74	if b != 0 {
75		return true
76	}
77	return false
78}
79
80/*
81 * Unexported vars
82 */
83
84var nilPtrErr = errors.New("cgo returned unexpected nil pointer")
85
86/*
87 * Constants
88 */
89
90// DragAction is a representation of GDK's GdkDragAction.
91type DragAction int
92
93const (
94	ACTION_DEFAULT DragAction = C.GDK_ACTION_DEFAULT
95	ACTION_COPY    DragAction = C.GDK_ACTION_COPY
96	ACTION_MOVE    DragAction = C.GDK_ACTION_MOVE
97	ACTION_LINK    DragAction = C.GDK_ACTION_LINK
98	ACTION_PRIVATE DragAction = C.GDK_ACTION_PRIVATE
99	ACTION_ASK     DragAction = C.GDK_ACTION_ASK
100)
101
102func marshalDragAction(p uintptr) (interface{}, error) {
103	c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
104	return DragAction(c), nil
105}
106
107// Colorspace is a representation of GDK's GdkColorspace.
108type Colorspace int
109
110const (
111	COLORSPACE_RGB Colorspace = C.GDK_COLORSPACE_RGB
112)
113
114func marshalColorspace(p uintptr) (interface{}, error) {
115	c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
116	return Colorspace(c), nil
117}
118
119// InterpType is a representation of GDK's GdkInterpType.
120type InterpType int
121
122const (
123	INTERP_NEAREST  InterpType = C.GDK_INTERP_NEAREST
124	INTERP_TILES    InterpType = C.GDK_INTERP_TILES
125	INTERP_BILINEAR InterpType = C.GDK_INTERP_BILINEAR
126	INTERP_HYPER    InterpType = C.GDK_INTERP_HYPER
127)
128
129// PixbufRotation is a representation of GDK's GdkPixbufRotation.
130type PixbufRotation int
131
132const (
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
139func marshalInterpType(p uintptr) (interface{}, error) {
140	c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
141	return InterpType(c), nil
142}
143
144// ModifierType is a representation of GDK's GdkModifierType.
145type ModifierType uint
146
147const (
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
166)
167
168func marshalModifierType(p uintptr) (interface{}, error) {
169	c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
170	return ModifierType(c), nil
171}
172
173// PixbufAlphaMode is a representation of GDK's GdkPixbufAlphaMode.
174type PixbufAlphaMode int
175
176const (
177	GDK_PIXBUF_ALPHA_BILEVEL PixbufAlphaMode = C.GDK_PIXBUF_ALPHA_BILEVEL
178	GDK_PIXBUF_ALPHA_FULL    PixbufAlphaMode = C.GDK_PIXBUF_ALPHA_FULL
179)
180
181func marshalPixbufAlphaMode(p uintptr) (interface{}, error) {
182	c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
183	return PixbufAlphaMode(c), nil
184}
185
186// Selections
187const (
188	SELECTION_PRIMARY       Atom = 1
189	SELECTION_SECONDARY     Atom = 2
190	SELECTION_CLIPBOARD     Atom = 69
191	TARGET_BITMAP           Atom = 5
192	TARGET_COLORMAP         Atom = 7
193	TARGET_DRAWABLE         Atom = 17
194	TARGET_PIXMAP           Atom = 20
195	TARGET_STRING           Atom = 31
196	SELECTION_TYPE_ATOM     Atom = 4
197	SELECTION_TYPE_BITMAP   Atom = 5
198	SELECTION_TYPE_COLORMAP Atom = 7
199	SELECTION_TYPE_DRAWABLE Atom = 17
200	SELECTION_TYPE_INTEGER  Atom = 19
201	SELECTION_TYPE_PIXMAP   Atom = 20
202	SELECTION_TYPE_WINDOW   Atom = 33
203	SELECTION_TYPE_STRING   Atom = 31
204)
205
206// added by terrak
207// EventMask is a representation of GDK's GdkEventMask.
208type EventMask int
209
210const (
211	EXPOSURE_MASK            EventMask = C.GDK_EXPOSURE_MASK
212	POINTER_MOTION_MASK      EventMask = C.GDK_POINTER_MOTION_MASK
213	POINTER_MOTION_HINT_MASK EventMask = C.GDK_POINTER_MOTION_HINT_MASK
214	BUTTON_MOTION_MASK       EventMask = C.GDK_BUTTON_MOTION_MASK
215	BUTTON1_MOTION_MASK      EventMask = C.GDK_BUTTON1_MOTION_MASK
216	BUTTON2_MOTION_MASK      EventMask = C.GDK_BUTTON2_MOTION_MASK
217	BUTTON3_MOTION_MASK      EventMask = C.GDK_BUTTON3_MOTION_MASK
218	BUTTON_PRESS_MASK        EventMask = C.GDK_BUTTON_PRESS_MASK
219	BUTTON_RELEASE_MASK      EventMask = C.GDK_BUTTON_RELEASE_MASK
220	KEY_PRESS_MASK           EventMask = C.GDK_KEY_PRESS_MASK
221	KEY_RELEASE_MASK         EventMask = C.GDK_KEY_RELEASE_MASK
222	ENTER_NOTIFY_MASK        EventMask = C.GDK_ENTER_NOTIFY_MASK
223	LEAVE_NOTIFY_MASK        EventMask = C.GDK_LEAVE_NOTIFY_MASK
224	FOCUS_CHANGE_MASK        EventMask = C.GDK_FOCUS_CHANGE_MASK
225	STRUCTURE_MASK           EventMask = C.GDK_STRUCTURE_MASK
226	PROPERTY_CHANGE_MASK     EventMask = C.GDK_PROPERTY_CHANGE_MASK
227	VISIBILITY_NOTIFY_MASK   EventMask = C.GDK_VISIBILITY_NOTIFY_MASK
228	PROXIMITY_IN_MASK        EventMask = C.GDK_PROXIMITY_IN_MASK
229	PROXIMITY_OUT_MASK       EventMask = C.GDK_PROXIMITY_OUT_MASK
230	SUBSTRUCTURE_MASK        EventMask = C.GDK_SUBSTRUCTURE_MASK
231	SCROLL_MASK              EventMask = C.GDK_SCROLL_MASK
232	TOUCH_MASK               EventMask = C.GDK_TOUCH_MASK
233	SMOOTH_SCROLL_MASK       EventMask = C.GDK_SMOOTH_SCROLL_MASK
234	ALL_EVENTS_MASK          EventMask = C.GDK_ALL_EVENTS_MASK
235)
236
237func marshalEventMask(p uintptr) (interface{}, error) {
238	c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
239	return EventMask(c), nil
240}
241
242// added by lazyshot
243// ScrollDirection is a representation of GDK's GdkScrollDirection
244
245type ScrollDirection int
246
247const (
248	SCROLL_UP     ScrollDirection = C.GDK_SCROLL_UP
249	SCROLL_DOWN   ScrollDirection = C.GDK_SCROLL_DOWN
250	SCROLL_LEFT   ScrollDirection = C.GDK_SCROLL_LEFT
251	SCROLL_RIGHT  ScrollDirection = C.GDK_SCROLL_RIGHT
252	SCROLL_SMOOTH ScrollDirection = C.GDK_SCROLL_SMOOTH
253)
254
255// WindowState is a representation of GDK's GdkWindowState
256type WindowState int
257
258const (
259	WINDOW_STATE_WITHDRAWN  WindowState = C.GDK_WINDOW_STATE_WITHDRAWN
260	WINDOW_STATE_ICONIFIED  WindowState = C.GDK_WINDOW_STATE_ICONIFIED
261	WINDOW_STATE_MAXIMIZED  WindowState = C.GDK_WINDOW_STATE_MAXIMIZED
262	WINDOW_STATE_STICKY     WindowState = C.GDK_WINDOW_STATE_STICKY
263	WINDOW_STATE_FULLSCREEN WindowState = C.GDK_WINDOW_STATE_FULLSCREEN
264	WINDOW_STATE_ABOVE      WindowState = C.GDK_WINDOW_STATE_ABOVE
265	WINDOW_STATE_BELOW      WindowState = C.GDK_WINDOW_STATE_BELOW
266	WINDOW_STATE_FOCUSED    WindowState = C.GDK_WINDOW_STATE_FOCUSED
267	WINDOW_STATE_TILED      WindowState = C.GDK_WINDOW_STATE_TILED
268)
269
270// WindowTypeHint is a representation of GDK's GdkWindowTypeHint
271type WindowTypeHint int
272
273const (
274	WINDOW_TYPE_HINT_NORMAL        WindowTypeHint = C.GDK_WINDOW_TYPE_HINT_NORMAL
275	WINDOW_TYPE_HINT_DIALOG        WindowTypeHint = C.GDK_WINDOW_TYPE_HINT_DIALOG
276	WINDOW_TYPE_HINT_MENU          WindowTypeHint = C.GDK_WINDOW_TYPE_HINT_MENU
277	WINDOW_TYPE_HINT_TOOLBAR       WindowTypeHint = C.GDK_WINDOW_TYPE_HINT_TOOLBAR
278	WINDOW_TYPE_HINT_SPLASHSCREEN  WindowTypeHint = C.GDK_WINDOW_TYPE_HINT_SPLASHSCREEN
279	WINDOW_TYPE_HINT_UTILITY       WindowTypeHint = C.GDK_WINDOW_TYPE_HINT_UTILITY
280	WINDOW_TYPE_HINT_DOCK          WindowTypeHint = C.GDK_WINDOW_TYPE_HINT_DOCK
281	WINDOW_TYPE_HINT_DESKTOP       WindowTypeHint = C.GDK_WINDOW_TYPE_HINT_DESKTOP
282	WINDOW_TYPE_HINT_DROPDOWN_MENU WindowTypeHint = C.GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU
283	WINDOW_TYPE_HINT_POPUP_MENU    WindowTypeHint = C.GDK_WINDOW_TYPE_HINT_POPUP_MENU
284	WINDOW_TYPE_HINT_TOOLTIP       WindowTypeHint = C.GDK_WINDOW_TYPE_HINT_TOOLTIP
285	WINDOW_TYPE_HINT_NOTIFICATION  WindowTypeHint = C.GDK_WINDOW_TYPE_HINT_NOTIFICATION
286	WINDOW_TYPE_HINT_COMBO         WindowTypeHint = C.GDK_WINDOW_TYPE_HINT_COMBO
287	WINDOW_TYPE_HINT_DND           WindowTypeHint = C.GDK_WINDOW_TYPE_HINT_DND
288)
289
290// CURRENT_TIME is a representation of GDK_CURRENT_TIME
291
292const CURRENT_TIME = C.GDK_CURRENT_TIME
293
294// GrabStatus is a representation of GdkGrabStatus
295
296type GrabStatus int
297
298const (
299	GRAB_SUCCESS         GrabStatus = C.GDK_GRAB_SUCCESS
300	GRAB_ALREADY_GRABBED GrabStatus = C.GDK_GRAB_ALREADY_GRABBED
301	GRAB_INVALID_TIME    GrabStatus = C.GDK_GRAB_INVALID_TIME
302	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
306)
307
308// GrabOwnership is a representation of GdkGrabOwnership
309
310type GrabOwnership int
311
312const (
313	OWNERSHIP_NONE        GrabOwnership = C.GDK_OWNERSHIP_NONE
314	OWNERSHIP_WINDOW      GrabOwnership = C.GDK_OWNERSHIP_WINDOW
315	OWNERSHIP_APPLICATION GrabOwnership = C.GDK_OWNERSHIP_APPLICATION
316)
317
318// DeviceType is a representation of GdkDeviceType
319
320type DeviceType int
321
322const (
323	DEVICE_TYPE_MASTER   DeviceType = C.GDK_DEVICE_TYPE_MASTER
324	DEVICE_TYPE_SLAVE    DeviceType = C.GDK_DEVICE_TYPE_SLAVE
325	DEVICE_TYPE_FLOATING DeviceType = C.GDK_DEVICE_TYPE_FLOATING
326)
327
328// EventPropagation constants
329
330const (
331	GDK_EVENT_PROPAGATE bool = C.GDK_EVENT_PROPAGATE != 0
332	GDK_EVENT_STOP      bool = C.GDK_EVENT_STOP != 0
333)
334
335/*
336 * GdkAtom
337 */
338
339// Atom is a representation of GDK's GdkAtom.
340type Atom uintptr
341
342// native returns the underlying GdkAtom.
343func (v Atom) native() C.GdkAtom {
344	return C.toGdkAtom(unsafe.Pointer(uintptr(v)))
345}
346
347func (v Atom) Name() string {
348	c := C.gdk_atom_name(v.native())
349	defer C.g_free(C.gpointer(c))
350	return C.GoString((*C.char)(c))
351}
352
353// GdkAtomIntern is a wrapper around gdk_atom_intern
354func GdkAtomIntern(atomName string, onlyIfExists bool) Atom {
355	cstr := C.CString(atomName)
356	defer C.free(unsafe.Pointer(cstr))
357	c := C.gdk_atom_intern((*C.gchar)(cstr), gbool(onlyIfExists))
358	return Atom(uintptr(unsafe.Pointer(c)))
359}
360
361/*
362 * GdkDevice
363 */
364
365// Device is a representation of GDK's GdkDevice.
366type Device struct {
367	*glib.Object
368}
369
370// native returns a pointer to the underlying GdkDevice.
371func (v *Device) native() *C.GdkDevice {
372	if v == nil || v.GObject == nil {
373		return nil
374	}
375	p := unsafe.Pointer(v.GObject)
376	return C.toGdkDevice(p)
377}
378
379// Native returns a pointer to the underlying GdkDevice.
380func (v *Device) Native() uintptr {
381	return uintptr(unsafe.Pointer(v.native()))
382}
383
384func marshalDevice(p uintptr) (interface{}, error) {
385	c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
386	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
387	return &Device{obj}, nil
388}
389
390/*
391 * GdkCursor
392 */
393
394// Cursor is a representation of GdkCursor.
395type Cursor struct {
396	*glib.Object
397}
398
399// CursorNewFromName is a wrapper around gdk_cursor_new_from_name().
400func CursorNewFromName(display *Display, name string) (*Cursor, error) {
401	cstr := C.CString(name)
402	defer C.free(unsafe.Pointer(cstr))
403	c := C.gdk_cursor_new_from_name(display.native(), (*C.gchar)(cstr))
404	if c == nil {
405		return nil, nilPtrErr
406	}
407
408	return &Cursor{glib.Take(unsafe.Pointer(c))}, nil
409}
410
411// native returns a pointer to the underlying GdkCursor.
412func (v *Cursor) native() *C.GdkCursor {
413	if v == nil || v.GObject == nil {
414		return nil
415	}
416	p := unsafe.Pointer(v.GObject)
417	return C.toGdkCursor(p)
418}
419
420// Native returns a pointer to the underlying GdkCursor.
421func (v *Cursor) Native() uintptr {
422	return uintptr(unsafe.Pointer(v.native()))
423}
424
425func marshalCursor(p uintptr) (interface{}, error) {
426	c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
427	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
428	return &Cursor{obj}, nil
429}
430
431/*
432 * GdkDeviceManager
433 */
434
435// DeviceManager is a representation of GDK's GdkDeviceManager.
436type DeviceManager struct {
437	*glib.Object
438}
439
440// native returns a pointer to the underlying GdkDeviceManager.
441func (v *DeviceManager) native() *C.GdkDeviceManager {
442	if v == nil || v.GObject == nil {
443		return nil
444	}
445	p := unsafe.Pointer(v.GObject)
446	return C.toGdkDeviceManager(p)
447}
448
449// Native returns a pointer to the underlying GdkDeviceManager.
450func (v *DeviceManager) Native() uintptr {
451	return uintptr(unsafe.Pointer(v.native()))
452}
453
454func marshalDeviceManager(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 &DeviceManager{obj}, nil
458}
459
460// GetDisplay() is a wrapper around gdk_device_manager_get_display().
461func (v *DeviceManager) GetDisplay() (*Display, error) {
462	c := C.gdk_device_manager_get_display(v.native())
463	if c == nil {
464		return nil, nilPtrErr
465	}
466
467	return &Display{glib.Take(unsafe.Pointer(c))}, nil
468}
469
470/*
471 * GdkDisplay
472 */
473
474// Display is a representation of GDK's GdkDisplay.
475type Display struct {
476	*glib.Object
477}
478
479// native returns a pointer to the underlying GdkDisplay.
480func (v *Display) native() *C.GdkDisplay {
481	if v == nil || v.GObject == nil {
482		return nil
483	}
484	p := unsafe.Pointer(v.GObject)
485	return C.toGdkDisplay(p)
486}
487
488// Native returns a pointer to the underlying GdkDisplay.
489func (v *Display) Native() uintptr {
490	return uintptr(unsafe.Pointer(v.native()))
491}
492
493func marshalDisplay(p uintptr) (interface{}, error) {
494	c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
495	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
496	return &Display{obj}, nil
497}
498
499func toDisplay(s *C.GdkDisplay) (*Display, error) {
500	if s == nil {
501		return nil, nilPtrErr
502	}
503	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(s))}
504	return &Display{obj}, nil
505}
506
507// DisplayOpen() is a wrapper around gdk_display_open().
508func DisplayOpen(displayName string) (*Display, error) {
509	cstr := C.CString(displayName)
510	defer C.free(unsafe.Pointer(cstr))
511	c := C.gdk_display_open((*C.gchar)(cstr))
512	if c == nil {
513		return nil, nilPtrErr
514	}
515
516	return &Display{glib.Take(unsafe.Pointer(c))}, nil
517}
518
519// DisplayGetDefault() is a wrapper around gdk_display_get_default().
520func DisplayGetDefault() (*Display, error) {
521	c := C.gdk_display_get_default()
522	if c == nil {
523		return nil, nilPtrErr
524	}
525
526	return &Display{glib.Take(unsafe.Pointer(c))}, nil
527}
528
529// GetName() is a wrapper around gdk_display_get_name().
530func (v *Display) GetName() (string, error) {
531	c := C.gdk_display_get_name(v.native())
532	if c == nil {
533		return "", nilPtrErr
534	}
535	return C.GoString((*C.char)(c)), nil
536}
537
538// GetDefaultScreen() is a wrapper around gdk_display_get_default_screen().
539func (v *Display) GetDefaultScreen() (*Screen, error) {
540	c := C.gdk_display_get_default_screen(v.native())
541	if c == nil {
542		return nil, nilPtrErr
543	}
544
545	return &Screen{glib.Take(unsafe.Pointer(c))}, nil
546}
547
548// DeviceIsGrabbed() is a wrapper around gdk_display_device_is_grabbed().
549func (v *Display) DeviceIsGrabbed(device *Device) bool {
550	c := C.gdk_display_device_is_grabbed(v.native(), device.native())
551	return gobool(c)
552}
553
554// Beep() is a wrapper around gdk_display_beep().
555func (v *Display) Beep() {
556	C.gdk_display_beep(v.native())
557}
558
559// Sync() is a wrapper around gdk_display_sync().
560func (v *Display) Sync() {
561	C.gdk_display_sync(v.native())
562}
563
564// Flush() is a wrapper around gdk_display_flush().
565func (v *Display) Flush() {
566	C.gdk_display_flush(v.native())
567}
568
569// Close() is a wrapper around gdk_display_close().
570func (v *Display) Close() {
571	C.gdk_display_close(v.native())
572}
573
574// IsClosed() is a wrapper around gdk_display_is_closed().
575func (v *Display) IsClosed() bool {
576	c := C.gdk_display_is_closed(v.native())
577	return gobool(c)
578}
579
580// GetEvent() is a wrapper around gdk_display_get_event().
581func (v *Display) GetEvent() (*Event, error) {
582	c := C.gdk_display_get_event(v.native())
583	if c == nil {
584		return nil, nilPtrErr
585	}
586
587	//The finalizer is not on the glib.Object but on the event.
588	e := &Event{c}
589	runtime.SetFinalizer(e, (*Event).free)
590	return e, nil
591}
592
593// PeekEvent() is a wrapper around gdk_display_peek_event().
594func (v *Display) PeekEvent() (*Event, error) {
595	c := C.gdk_display_peek_event(v.native())
596	if c == nil {
597		return nil, nilPtrErr
598	}
599
600	//The finalizer is not on the glib.Object but on the event.
601	e := &Event{c}
602	runtime.SetFinalizer(e, (*Event).free)
603	return e, nil
604}
605
606// PutEvent() is a wrapper around gdk_display_put_event().
607func (v *Display) PutEvent(event *Event) {
608	C.gdk_display_put_event(v.native(), event.native())
609}
610
611// HasPending() is a wrapper around gdk_display_has_pending().
612func (v *Display) HasPending() bool {
613	c := C.gdk_display_has_pending(v.native())
614	return gobool(c)
615}
616
617// SetDoubleClickTime() is a wrapper around gdk_display_set_double_click_time().
618func (v *Display) SetDoubleClickTime(msec uint) {
619	C.gdk_display_set_double_click_time(v.native(), C.guint(msec))
620}
621
622// SetDoubleClickDistance() is a wrapper around gdk_display_set_double_click_distance().
623func (v *Display) SetDoubleClickDistance(distance uint) {
624	C.gdk_display_set_double_click_distance(v.native(), C.guint(distance))
625}
626
627// SupportsColorCursor() is a wrapper around gdk_display_supports_cursor_color().
628func (v *Display) SupportsColorCursor() bool {
629	c := C.gdk_display_supports_cursor_color(v.native())
630	return gobool(c)
631}
632
633// SupportsCursorAlpha() is a wrapper around gdk_display_supports_cursor_alpha().
634func (v *Display) SupportsCursorAlpha() bool {
635	c := C.gdk_display_supports_cursor_alpha(v.native())
636	return gobool(c)
637}
638
639// GetDefaultCursorSize() is a wrapper around gdk_display_get_default_cursor_size().
640func (v *Display) GetDefaultCursorSize() uint {
641	c := C.gdk_display_get_default_cursor_size(v.native())
642	return uint(c)
643}
644
645// GetMaximalCursorSize() is a wrapper around gdk_display_get_maximal_cursor_size().
646func (v *Display) GetMaximalCursorSize() (width, height uint) {
647	var w, h C.guint
648	C.gdk_display_get_maximal_cursor_size(v.native(), &w, &h)
649	return uint(w), uint(h)
650}
651
652// GetDefaultGroup() is a wrapper around gdk_display_get_default_group().
653func (v *Display) GetDefaultGroup() (*Window, error) {
654	c := C.gdk_display_get_default_group(v.native())
655	if c == nil {
656		return nil, nilPtrErr
657	}
658
659	return &Window{glib.Take(unsafe.Pointer(c))}, nil
660}
661
662// SupportsSelectionNotification() is a wrapper around
663// gdk_display_supports_selection_notification().
664func (v *Display) SupportsSelectionNotification() bool {
665	c := C.gdk_display_supports_selection_notification(v.native())
666	return gobool(c)
667}
668
669// RequestSelectionNotification() is a wrapper around
670// gdk_display_request_selection_notification().
671func (v *Display) RequestSelectionNotification(selection Atom) bool {
672	c := C.gdk_display_request_selection_notification(v.native(),
673		selection.native())
674	return gobool(c)
675}
676
677// SupportsClipboardPersistence() is a wrapper around
678// gdk_display_supports_clipboard_persistence().
679func (v *Display) SupportsClipboardPersistence() bool {
680	c := C.gdk_display_supports_clipboard_persistence(v.native())
681	return gobool(c)
682}
683
684// TODO(jrick)
685func (v *Display) StoreClipboard(clipboardWindow *Window, time uint32, targets ...Atom) {
686	panic("Not implemented")
687}
688
689// SupportsShapes() is a wrapper around gdk_display_supports_shapes().
690func (v *Display) SupportsShapes() bool {
691	c := C.gdk_display_supports_shapes(v.native())
692	return gobool(c)
693}
694
695// SupportsInputShapes() is a wrapper around gdk_display_supports_input_shapes().
696func (v *Display) SupportsInputShapes() bool {
697	c := C.gdk_display_supports_input_shapes(v.native())
698	return gobool(c)
699}
700
701// TODO(jrick) glib.AppLaunchContext GdkAppLaunchContext
702func (v *Display) GetAppLaunchContext() {
703	panic("Not implemented")
704}
705
706// NotifyStartupComplete() is a wrapper around gdk_display_notify_startup_complete().
707func (v *Display) NotifyStartupComplete(startupID string) {
708	cstr := C.CString(startupID)
709	defer C.free(unsafe.Pointer(cstr))
710	C.gdk_display_notify_startup_complete(v.native(), (*C.gchar)(cstr))
711}
712
713// EventType is a representation of GDK's GdkEventType.
714// Do not confuse these event types with the signals that GTK+ widgets emit
715type EventType int
716
717func marshalEventType(p uintptr) (interface{}, error) {
718	c := C.g_value_get_enum((*C.GValue)(unsafe.Pointer(p)))
719	return EventType(c), nil
720}
721
722const (
723	EVENT_NOTHING             EventType = C.GDK_NOTHING
724	EVENT_DELETE              EventType = C.GDK_DELETE
725	EVENT_DESTROY             EventType = C.GDK_DESTROY
726	EVENT_EXPOSE              EventType = C.GDK_EXPOSE
727	EVENT_MOTION_NOTIFY       EventType = C.GDK_MOTION_NOTIFY
728	EVENT_BUTTON_PRESS        EventType = C.GDK_BUTTON_PRESS
729	EVENT_2BUTTON_PRESS       EventType = C.GDK_2BUTTON_PRESS
730	EVENT_DOUBLE_BUTTON_PRESS EventType = C.GDK_DOUBLE_BUTTON_PRESS
731	EVENT_3BUTTON_PRESS       EventType = C.GDK_3BUTTON_PRESS
732	EVENT_TRIPLE_BUTTON_PRESS EventType = C.GDK_TRIPLE_BUTTON_PRESS
733	EVENT_BUTTON_RELEASE      EventType = C.GDK_BUTTON_RELEASE
734	EVENT_KEY_PRESS           EventType = C.GDK_KEY_PRESS
735	EVENT_KEY_RELEASE         EventType = C.GDK_KEY_RELEASE
736	EVENT_LEAVE_NOTIFY        EventType = C.GDK_ENTER_NOTIFY
737	EVENT_FOCUS_CHANGE        EventType = C.GDK_FOCUS_CHANGE
738	EVENT_CONFIGURE           EventType = C.GDK_CONFIGURE
739	EVENT_MAP                 EventType = C.GDK_MAP
740	EVENT_UNMAP               EventType = C.GDK_UNMAP
741	EVENT_PROPERTY_NOTIFY     EventType = C.GDK_PROPERTY_NOTIFY
742	EVENT_SELECTION_CLEAR     EventType = C.GDK_SELECTION_CLEAR
743	EVENT_SELECTION_REQUEST   EventType = C.GDK_SELECTION_REQUEST
744	EVENT_SELECTION_NOTIFY    EventType = C.GDK_SELECTION_NOTIFY
745	EVENT_PROXIMITY_IN        EventType = C.GDK_PROXIMITY_IN
746	EVENT_PROXIMITY_OUT       EventType = C.GDK_PROXIMITY_OUT
747	EVENT_DRAG_ENTER          EventType = C.GDK_DRAG_ENTER
748	EVENT_DRAG_LEAVE          EventType = C.GDK_DRAG_LEAVE
749	EVENT_DRAG_MOTION         EventType = C.GDK_DRAG_MOTION
750	EVENT_DRAG_STATUS         EventType = C.GDK_DRAG_STATUS
751	EVENT_DROP_START          EventType = C.GDK_DROP_START
752	EVENT_DROP_FINISHED       EventType = C.GDK_DROP_FINISHED
753	EVENT_CLIENT_EVENT        EventType = C.GDK_CLIENT_EVENT
754	EVENT_VISIBILITY_NOTIFY   EventType = C.GDK_VISIBILITY_NOTIFY
755	EVENT_SCROLL              EventType = C.GDK_SCROLL
756	EVENT_WINDOW_STATE        EventType = C.GDK_WINDOW_STATE
757	EVENT_SETTING             EventType = C.GDK_SETTING
758	EVENT_OWNER_CHANGE        EventType = C.GDK_OWNER_CHANGE
759	EVENT_GRAB_BROKEN         EventType = C.GDK_GRAB_BROKEN
760	EVENT_DAMAGE              EventType = C.GDK_DAMAGE
761	EVENT_TOUCH_BEGIN         EventType = C.GDK_TOUCH_BEGIN
762	EVENT_TOUCH_UPDATE        EventType = C.GDK_TOUCH_UPDATE
763	EVENT_TOUCH_END           EventType = C.GDK_TOUCH_END
764	EVENT_TOUCH_CANCEL        EventType = C.GDK_TOUCH_CANCEL
765	EVENT_LAST                EventType = C.GDK_EVENT_LAST
766)
767
768/*
769 * GDK Keyval
770 */
771
772// KeyvalFromName() is a wrapper around gdk_keyval_from_name().
773func KeyvalFromName(keyvalName string) uint {
774	str := (*C.gchar)(C.CString(keyvalName))
775	defer C.free(unsafe.Pointer(str))
776	return uint(C.gdk_keyval_from_name(str))
777}
778
779func KeyvalConvertCase(v uint) (lower, upper uint) {
780	var l, u C.guint
781	l = 0
782	u = 0
783	C.gdk_keyval_convert_case(C.guint(v), &l, &u)
784	return uint(l), uint(u)
785}
786
787func KeyvalIsLower(v uint) bool {
788	return gobool(C.gdk_keyval_is_lower(C.guint(v)))
789}
790
791func KeyvalIsUpper(v uint) bool {
792	return gobool(C.gdk_keyval_is_upper(C.guint(v)))
793}
794
795func KeyvalToLower(v uint) uint {
796	return uint(C.gdk_keyval_to_lower(C.guint(v)))
797}
798
799func KeyvalToUpper(v uint) uint {
800	return uint(C.gdk_keyval_to_upper(C.guint(v)))
801}
802
803func KeyvalToUnicode(v uint) rune {
804	return rune(C.gdk_keyval_to_unicode(C.guint(v)))
805}
806
807func UnicodeToKeyval(v rune) uint {
808	return uint(C.gdk_unicode_to_keyval(C.guint32(v)))
809}
810
811/*
812 * GdkDragContext
813 */
814
815// DragContext is a representation of GDK's GdkDragContext.
816type DragContext struct {
817	*glib.Object
818}
819
820// native returns a pointer to the underlying GdkDragContext.
821func (v *DragContext) native() *C.GdkDragContext {
822	if v == nil || v.GObject == nil {
823		return nil
824	}
825	p := unsafe.Pointer(v.GObject)
826	return C.toGdkDragContext(p)
827}
828
829// Native returns a pointer to the underlying GdkDragContext.
830func (v *DragContext) Native() uintptr {
831	return uintptr(unsafe.Pointer(v.native()))
832}
833
834func marshalDragContext(p uintptr) (interface{}, error) {
835	c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
836	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
837	return &DragContext{obj}, nil
838}
839
840func (v *DragContext) ListTargets() *glib.List {
841	c := C.gdk_drag_context_list_targets(v.native())
842	return glib.WrapList(uintptr(unsafe.Pointer(c)))
843}
844
845/*
846 * GdkEvent
847 */
848
849// Event is a representation of GDK's GdkEvent.
850type Event struct {
851	GdkEvent *C.GdkEvent
852}
853
854// native returns a pointer to the underlying GdkEvent.
855func (v *Event) native() *C.GdkEvent {
856	if v == nil {
857		return nil
858	}
859	return v.GdkEvent
860}
861
862// Native returns a pointer to the underlying GdkEvent.
863func (v *Event) Native() uintptr {
864	return uintptr(unsafe.Pointer(v.native()))
865}
866
867func marshalEvent(p uintptr) (interface{}, error) {
868	c := C.g_value_get_boxed((*C.GValue)(unsafe.Pointer(p)))
869	return &Event{(*C.GdkEvent)(unsafe.Pointer(c))}, nil
870}
871
872func (v *Event) free() {
873	C.gdk_event_free(v.native())
874}
875
876/*
877 * GdkEventButton
878 */
879
880// EventButton is a representation of GDK's GdkEventButton.
881type EventButton struct {
882	*Event
883}
884
885func EventButtonNew() *EventButton {
886	ee := (*C.GdkEvent)(unsafe.Pointer(&C.GdkEventButton{}))
887	ev := Event{ee}
888	return &EventButton{&ev}
889}
890
891// EventButtonNewFromEvent returns an EventButton from an Event.
892//
893// Using widget.Connect() for a key related signal such as
894// "button-press-event" results in a *Event being passed as
895// the callback's second argument. The argument is actually a
896// *EventButton. EventButtonNewFromEvent provides a means of creating
897// an EventKey from the Event.
898func EventButtonNewFromEvent(event *Event) *EventButton {
899	ee := (*C.GdkEvent)(unsafe.Pointer(event.native()))
900	ev := Event{ee}
901	return &EventButton{&ev}
902}
903
904// Native returns a pointer to the underlying GdkEventButton.
905func (v *EventButton) Native() uintptr {
906	return uintptr(unsafe.Pointer(v.native()))
907}
908
909func (v *EventButton) native() *C.GdkEventButton {
910	return (*C.GdkEventButton)(unsafe.Pointer(v.Event.native()))
911}
912
913func (v *EventButton) X() float64 {
914	c := v.native().x
915	return float64(c)
916}
917
918func (v *EventButton) Y() float64 {
919	c := v.native().y
920	return float64(c)
921}
922
923// XRoot returns the x coordinate of the pointer relative to the root of the screen.
924func (v *EventButton) XRoot() float64 {
925	c := v.native().x_root
926	return float64(c)
927}
928
929// YRoot returns the y coordinate of the pointer relative to the root of the screen.
930func (v *EventButton) YRoot() float64 {
931	c := v.native().y_root
932	return float64(c)
933}
934
935func (v *EventButton) Button() uint {
936	c := v.native().button
937	return uint(c)
938}
939
940func (v *EventButton) State() uint {
941	c := v.native().state
942	return uint(c)
943}
944
945// Time returns the time of the event in milliseconds.
946func (v *EventButton) Time() uint32 {
947	c := v.native().time
948	return uint32(c)
949}
950
951func (v *EventButton) Type() EventType {
952	c := v.native()._type
953	return EventType(c)
954}
955
956func (v *EventButton) MotionVal() (float64, float64) {
957	x := v.native().x
958	y := v.native().y
959	return float64(x), float64(y)
960}
961
962func (v *EventButton) MotionValRoot() (float64, float64) {
963	x := v.native().x_root
964	y := v.native().y_root
965	return float64(x), float64(y)
966}
967
968func (v *EventButton) ButtonVal() uint {
969	c := v.native().button
970	return uint(c)
971}
972
973/*
974 * GdkEventKey
975 */
976
977// EventKey is a representation of GDK's GdkEventKey.
978type EventKey struct {
979	*Event
980}
981
982func EventKeyNew() *EventKey {
983	ee := (*C.GdkEvent)(unsafe.Pointer(&C.GdkEventKey{}))
984	ev := Event{ee}
985	return &EventKey{&ev}
986}
987
988// EventKeyNewFromEvent returns an EventKey from an Event.
989//
990// Using widget.Connect() for a key related signal such as
991// "key-press-event" results in a *Event being passed as
992// the callback's second argument. The argument is actually a
993// *EventKey. EventKeyNewFromEvent provides a means of creating
994// an EventKey from the Event.
995func EventKeyNewFromEvent(event *Event) *EventKey {
996	ee := (*C.GdkEvent)(unsafe.Pointer(event.native()))
997	ev := Event{ee}
998	return &EventKey{&ev}
999}
1000
1001// Native returns a pointer to the underlying GdkEventKey.
1002func (v *EventKey) Native() uintptr {
1003	return uintptr(unsafe.Pointer(v.native()))
1004}
1005
1006func (v *EventKey) native() *C.GdkEventKey {
1007	return (*C.GdkEventKey)(unsafe.Pointer(v.Event.native()))
1008}
1009
1010func (v *EventKey) KeyVal() uint {
1011	c := v.native().keyval
1012	return uint(c)
1013}
1014
1015func (v *EventKey) Type() EventType {
1016	c := v.native()._type
1017	return EventType(c)
1018}
1019
1020func (v *EventKey) State() uint {
1021	c := v.native().state
1022	return uint(c)
1023}
1024
1025/*
1026 * GdkEventMotion
1027 */
1028
1029type EventMotion struct {
1030	*Event
1031}
1032
1033func EventMotionNew() *EventMotion {
1034	ee := (*C.GdkEvent)(unsafe.Pointer(&C.GdkEventMotion{}))
1035	ev := Event{ee}
1036	return &EventMotion{&ev}
1037}
1038
1039// EventMotionNewFromEvent returns an EventMotion from an Event.
1040//
1041// Using widget.Connect() for a key related signal such as
1042// "button-press-event" results in a *Event being passed as
1043// the callback's second argument. The argument is actually a
1044// *EventMotion. EventMotionNewFromEvent provides a means of creating
1045// an EventKey from the Event.
1046func EventMotionNewFromEvent(event *Event) *EventMotion {
1047	ee := (*C.GdkEvent)(unsafe.Pointer(event.native()))
1048	ev := Event{ee}
1049	return &EventMotion{&ev}
1050}
1051
1052// Native returns a pointer to the underlying GdkEventMotion.
1053func (v *EventMotion) Native() uintptr {
1054	return uintptr(unsafe.Pointer(v.native()))
1055}
1056
1057func (v *EventMotion) native() *C.GdkEventMotion {
1058	return (*C.GdkEventMotion)(unsafe.Pointer(v.Event.native()))
1059}
1060
1061func (v *EventMotion) MotionVal() (float64, float64) {
1062	x := v.native().x
1063	y := v.native().y
1064	return float64(x), float64(y)
1065}
1066
1067func (v *EventMotion) MotionValRoot() (float64, float64) {
1068	x := v.native().x_root
1069	y := v.native().y_root
1070	return float64(x), float64(y)
1071}
1072
1073// Time returns the time of the event in milliseconds.
1074func (v *EventMotion) Time() uint32 {
1075	c := v.native().time
1076	return uint32(c)
1077}
1078
1079func (v *EventMotion) Type() EventType {
1080	c := v.native()._type
1081	return EventType(c)
1082}
1083
1084// A bit-mask representing the state of the modifier keys (e.g. Control, Shift
1085// and Alt) and the pointer buttons. See gdk.ModifierType constants.
1086func (v *EventMotion) State() ModifierType {
1087	c := v.native().state
1088	return ModifierType(c)
1089}
1090
1091/*
1092 * GdkEventScroll
1093 */
1094
1095// EventScroll is a representation of GDK's GdkEventScroll.
1096type EventScroll struct {
1097	*Event
1098}
1099
1100func EventScrollNew() *EventScroll {
1101	ee := (*C.GdkEvent)(unsafe.Pointer(&C.GdkEventScroll{}))
1102	ev := Event{ee}
1103	return &EventScroll{&ev}
1104}
1105
1106// EventScrollNewFromEvent returns an EventScroll from an Event.
1107//
1108// Using widget.Connect() for a key related signal such as
1109// "button-press-event" results in a *Event being passed as
1110// the callback's second argument. The argument is actually a
1111// *EventScroll. EventScrollNewFromEvent provides a means of creating
1112// an EventKey from the Event.
1113func EventScrollNewFromEvent(event *Event) *EventScroll {
1114	ee := (*C.GdkEvent)(unsafe.Pointer(event.native()))
1115	ev := Event{ee}
1116	return &EventScroll{&ev}
1117}
1118
1119// Native returns a pointer to the underlying GdkEventScroll.
1120func (v *EventScroll) Native() uintptr {
1121	return uintptr(unsafe.Pointer(v.native()))
1122}
1123
1124func (v *EventScroll) native() *C.GdkEventScroll {
1125	return (*C.GdkEventScroll)(unsafe.Pointer(v.Event.native()))
1126}
1127
1128func (v *EventScroll) DeltaX() float64 {
1129	return float64(v.native().delta_x)
1130}
1131
1132func (v *EventScroll) DeltaY() float64 {
1133	return float64(v.native().delta_y)
1134}
1135
1136func (v *EventScroll) X() float64 {
1137	return float64(v.native().x)
1138}
1139
1140func (v *EventScroll) Y() float64 {
1141	return float64(v.native().y)
1142}
1143
1144func (v *EventScroll) Type() EventType {
1145	c := v.native()._type
1146	return EventType(c)
1147}
1148
1149func (v *EventScroll) Direction() ScrollDirection {
1150	c := v.native().direction
1151	return ScrollDirection(c)
1152}
1153
1154/*
1155 * GdkEventWindowState
1156 */
1157
1158// EventWindowState is a representation of GDK's GdkEventWindowState.
1159type EventWindowState struct {
1160	*Event
1161}
1162
1163func EventWindowStateNew() *EventWindowState {
1164	ee := (*C.GdkEvent)(unsafe.Pointer(&C.GdkEventWindowState{}))
1165	ev := Event{ee}
1166	return &EventWindowState{&ev}
1167}
1168
1169// EventWindowStateNewFromEvent returns an EventWindowState from an Event.
1170//
1171// Using widget.Connect() for the
1172// "window-state-event" signal results in a *Event being passed as
1173// the callback's second argument. The argument is actually a
1174// *EventWindowState. EventWindowStateNewFromEvent provides a means of creating
1175// an EventWindowState from the Event.
1176func EventWindowStateNewFromEvent(event *Event) *EventWindowState {
1177	ee := (*C.GdkEvent)(unsafe.Pointer(event.native()))
1178	ev := Event{ee}
1179	return &EventWindowState{&ev}
1180}
1181
1182// Native returns a pointer to the underlying GdkEventWindowState.
1183func (v *EventWindowState) Native() uintptr {
1184	return uintptr(unsafe.Pointer(v.native()))
1185}
1186
1187func (v *EventWindowState) native() *C.GdkEventWindowState {
1188	return (*C.GdkEventWindowState)(unsafe.Pointer(v.Event.native()))
1189}
1190
1191func (v *EventWindowState) Type() EventType {
1192	c := v.native()._type
1193	return EventType(c)
1194}
1195
1196func (v *EventWindowState) ChangedMask() WindowState {
1197	c := v.native().changed_mask
1198	return WindowState(c)
1199}
1200
1201func (v *EventWindowState) NewWindowState() WindowState {
1202	c := v.native().new_window_state
1203	return WindowState(c)
1204}
1205
1206/*
1207 * GdkGravity
1208 */
1209type GdkGravity int
1210
1211const (
1212	GDK_GRAVITY_NORTH_WEST = C.GDK_GRAVITY_NORTH_WEST
1213	GDK_GRAVITY_NORTH      = C.GDK_GRAVITY_NORTH
1214	GDK_GRAVITY_NORTH_EAST = C.GDK_GRAVITY_NORTH_EAST
1215	GDK_GRAVITY_WEST       = C.GDK_GRAVITY_WEST
1216	GDK_GRAVITY_CENTER     = C.GDK_GRAVITY_CENTER
1217	GDK_GRAVITY_EAST       = C.GDK_GRAVITY_EAST
1218	GDK_GRAVITY_SOUTH_WEST = C.GDK_GRAVITY_SOUTH_WEST
1219	GDK_GRAVITY_SOUTH      = C.GDK_GRAVITY_SOUTH
1220	GDK_GRAVITY_SOUTH_EAST = C.GDK_GRAVITY_SOUTH_EAST
1221	GDK_GRAVITY_STATIC     = C.GDK_GRAVITY_STATIC
1222)
1223
1224/*
1225 * GdkPixbuf
1226 */
1227
1228// Pixbuf is a representation of GDK's GdkPixbuf.
1229type Pixbuf struct {
1230	*glib.Object
1231}
1232
1233// native returns a pointer to the underlying GdkPixbuf.
1234func (v *Pixbuf) native() *C.GdkPixbuf {
1235	if v == nil || v.GObject == nil {
1236		return nil
1237	}
1238	p := unsafe.Pointer(v.GObject)
1239	return C.toGdkPixbuf(p)
1240}
1241
1242// Native returns a pointer to the underlying GdkPixbuf.
1243func (v *Pixbuf) Native() uintptr {
1244	return uintptr(unsafe.Pointer(v.native()))
1245}
1246
1247func (v *Pixbuf) NativePrivate() *C.GdkPixbuf {
1248	if v == nil || v.GObject == nil {
1249		return nil
1250	}
1251	p := unsafe.Pointer(v.GObject)
1252	return C.toGdkPixbuf(p)
1253}
1254
1255func marshalPixbuf(p uintptr) (interface{}, error) {
1256	c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
1257	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
1258	return &Pixbuf{obj}, nil
1259}
1260
1261// GetColorspace is a wrapper around gdk_pixbuf_get_colorspace().
1262func (v *Pixbuf) GetColorspace() Colorspace {
1263	c := C.gdk_pixbuf_get_colorspace(v.native())
1264	return Colorspace(c)
1265}
1266
1267// GetNChannels is a wrapper around gdk_pixbuf_get_n_channels().
1268func (v *Pixbuf) GetNChannels() int {
1269	c := C.gdk_pixbuf_get_n_channels(v.native())
1270	return int(c)
1271}
1272
1273// GetHasAlpha is a wrapper around gdk_pixbuf_get_has_alpha().
1274func (v *Pixbuf) GetHasAlpha() bool {
1275	c := C.gdk_pixbuf_get_has_alpha(v.native())
1276	return gobool(c)
1277}
1278
1279// GetBitsPerSample is a wrapper around gdk_pixbuf_get_bits_per_sample().
1280func (v *Pixbuf) GetBitsPerSample() int {
1281	c := C.gdk_pixbuf_get_bits_per_sample(v.native())
1282	return int(c)
1283}
1284
1285// GetPixels is a wrapper around gdk_pixbuf_get_pixels_with_length().
1286// A Go slice is used to represent the underlying Pixbuf data array, one
1287// byte per channel.
1288func (v *Pixbuf) GetPixels() (channels []byte) {
1289	var length C.guint
1290	c := C.gdk_pixbuf_get_pixels_with_length(v.native(), &length)
1291	sliceHeader := (*reflect.SliceHeader)(unsafe.Pointer(&channels))
1292	sliceHeader.Data = uintptr(unsafe.Pointer(c))
1293	sliceHeader.Len = int(length)
1294	sliceHeader.Cap = int(length)
1295
1296	// To make sure the slice doesn't outlive the Pixbuf, add a reference
1297	v.Ref()
1298	runtime.SetFinalizer(&channels, func(_ *[]byte) {
1299		v.Unref()
1300	})
1301	return
1302}
1303
1304// GetWidth is a wrapper around gdk_pixbuf_get_width().
1305func (v *Pixbuf) GetWidth() int {
1306	c := C.gdk_pixbuf_get_width(v.native())
1307	return int(c)
1308}
1309
1310// GetHeight is a wrapper around gdk_pixbuf_get_height().
1311func (v *Pixbuf) GetHeight() int {
1312	c := C.gdk_pixbuf_get_height(v.native())
1313	return int(c)
1314}
1315
1316// GetRowstride is a wrapper around gdk_pixbuf_get_rowstride().
1317func (v *Pixbuf) GetRowstride() int {
1318	c := C.gdk_pixbuf_get_rowstride(v.native())
1319	return int(c)
1320}
1321
1322// GetByteLength is a wrapper around gdk_pixbuf_get_byte_length().
1323func (v *Pixbuf) GetByteLength() int {
1324	c := C.gdk_pixbuf_get_byte_length(v.native())
1325	return int(c)
1326}
1327
1328// GetOption is a wrapper around gdk_pixbuf_get_option().  ok is true if
1329// the key has an associated value.
1330func (v *Pixbuf) GetOption(key string) (value string, ok bool) {
1331	cstr := C.CString(key)
1332	defer C.free(unsafe.Pointer(cstr))
1333	c := C.gdk_pixbuf_get_option(v.native(), (*C.gchar)(cstr))
1334	if c == nil {
1335		return "", false
1336	}
1337	return C.GoString((*C.char)(c)), true
1338}
1339
1340// PixbufNew is a wrapper around gdk_pixbuf_new().
1341func PixbufNew(colorspace Colorspace, hasAlpha bool, bitsPerSample, width, height int) (*Pixbuf, error) {
1342	c := C.gdk_pixbuf_new(C.GdkColorspace(colorspace), gbool(hasAlpha),
1343		C.int(bitsPerSample), C.int(width), C.int(height))
1344	if c == nil {
1345		return nil, nilPtrErr
1346	}
1347
1348	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
1349	p := &Pixbuf{obj}
1350	//obj.Ref()
1351	runtime.SetFinalizer(p, func(_ interface{}) { obj.Unref() })
1352	return p, nil
1353}
1354
1355// PixbufCopy is a wrapper around gdk_pixbuf_copy().
1356func PixbufCopy(v *Pixbuf) (*Pixbuf, error) {
1357	c := C.gdk_pixbuf_copy(v.native())
1358	if c == nil {
1359		return nil, nilPtrErr
1360	}
1361
1362	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
1363	p := &Pixbuf{obj}
1364	//obj.Ref()
1365	runtime.SetFinalizer(p, func(_ interface{}) { obj.Unref() })
1366	return p, nil
1367}
1368
1369// PixbufNewFromFile is a wrapper around gdk_pixbuf_new_from_file().
1370func PixbufNewFromFile(filename string) (*Pixbuf, error) {
1371	cstr := C.CString(filename)
1372	defer C.free(unsafe.Pointer(cstr))
1373
1374	var err *C.GError
1375	c := C.gdk_pixbuf_new_from_file((*C.char)(cstr), &err)
1376	if c == nil {
1377		defer C.g_error_free(err)
1378		return nil, errors.New(C.GoString((*C.char)(err.message)))
1379	}
1380
1381	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
1382	p := &Pixbuf{obj}
1383	//obj.Ref()
1384	runtime.SetFinalizer(p, func(_ interface{}) { obj.Unref() })
1385	return p, nil
1386}
1387
1388// PixbufNewFromFileAtSize is a wrapper around gdk_pixbuf_new_from_file_at_size().
1389func PixbufNewFromFileAtSize(filename string, width, height int) (*Pixbuf, error) {
1390	cstr := C.CString(filename)
1391	defer C.free(unsafe.Pointer(cstr))
1392
1393	var err *C.GError = nil
1394	c := C.gdk_pixbuf_new_from_file_at_size(cstr, C.int(width), C.int(height), &err)
1395	if err != nil {
1396		defer C.g_error_free(err)
1397		return nil, errors.New(C.GoString((*C.char)(err.message)))
1398	}
1399
1400	if c == nil {
1401		return nil, nilPtrErr
1402	}
1403
1404	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
1405	p := &Pixbuf{obj}
1406	//obj.Ref()
1407	runtime.SetFinalizer(p, func(_ interface{}) { obj.Unref() })
1408	return p, nil
1409}
1410
1411// PixbufNewFromFileAtScale is a wrapper around gdk_pixbuf_new_from_file_at_scale().
1412func PixbufNewFromFileAtScale(filename string, width, height int, preserveAspectRatio bool) (*Pixbuf, error) {
1413	cstr := C.CString(filename)
1414	defer C.free(unsafe.Pointer(cstr))
1415
1416	var err *C.GError = nil
1417	c := C.gdk_pixbuf_new_from_file_at_scale(cstr, C.int(width), C.int(height),
1418		gbool(preserveAspectRatio), &err)
1419	if err != nil {
1420		defer C.g_error_free(err)
1421		return nil, errors.New(C.GoString((*C.char)(err.message)))
1422	}
1423
1424	if c == nil {
1425		return nil, nilPtrErr
1426	}
1427
1428	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
1429	p := &Pixbuf{obj}
1430	//obj.Ref()
1431	runtime.SetFinalizer(p, func(_ interface{}) { obj.Unref() })
1432	return p, nil
1433}
1434
1435// ScaleSimple is a wrapper around gdk_pixbuf_scale_simple().
1436func (v *Pixbuf) ScaleSimple(destWidth, destHeight int, interpType InterpType) (*Pixbuf, error) {
1437	c := C.gdk_pixbuf_scale_simple(v.native(), C.int(destWidth),
1438		C.int(destHeight), C.GdkInterpType(interpType))
1439	if c == nil {
1440		return nil, nilPtrErr
1441	}
1442
1443	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
1444	p := &Pixbuf{obj}
1445	//obj.Ref()
1446	runtime.SetFinalizer(p, func(_ interface{}) { obj.Unref() })
1447	return p, nil
1448}
1449
1450// RotateSimple is a wrapper around gdk_pixbuf_rotate_simple().
1451func (v *Pixbuf) RotateSimple(angle PixbufRotation) (*Pixbuf, error) {
1452	c := C.gdk_pixbuf_rotate_simple(v.native(), C.GdkPixbufRotation(angle))
1453	if c == nil {
1454		return nil, nilPtrErr
1455	}
1456
1457	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
1458	p := &Pixbuf{obj}
1459	//obj.Ref()
1460	runtime.SetFinalizer(p, func(_ interface{}) { obj.Unref() })
1461	return p, nil
1462}
1463
1464// ApplyEmbeddedOrientation is a wrapper around gdk_pixbuf_apply_embedded_orientation().
1465func (v *Pixbuf) ApplyEmbeddedOrientation() (*Pixbuf, error) {
1466	c := C.gdk_pixbuf_apply_embedded_orientation(v.native())
1467	if c == nil {
1468		return nil, nilPtrErr
1469	}
1470
1471	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
1472	p := &Pixbuf{obj}
1473	//obj.Ref()
1474	runtime.SetFinalizer(p, func(_ interface{}) { obj.Unref() })
1475	return p, nil
1476}
1477
1478// Flip is a wrapper around gdk_pixbuf_flip().
1479func (v *Pixbuf) Flip(horizontal bool) (*Pixbuf, error) {
1480	c := C.gdk_pixbuf_flip(v.native(), gbool(horizontal))
1481	if c == nil {
1482		return nil, nilPtrErr
1483	}
1484
1485	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
1486	p := &Pixbuf{obj}
1487	//obj.Ref()
1488	runtime.SetFinalizer(p, func(_ interface{}) { obj.Unref() })
1489	return p, nil
1490}
1491
1492// SaveJPEG is a wrapper around gdk_pixbuf_save().
1493// Quality is a number between 0...100
1494func (v *Pixbuf) SaveJPEG(path string, quality int) error {
1495	cpath := C.CString(path)
1496	cquality := C.CString(strconv.Itoa(quality))
1497	defer C.free(unsafe.Pointer(cpath))
1498	defer C.free(unsafe.Pointer(cquality))
1499
1500	var err *C.GError
1501	c := C._gdk_pixbuf_save_jpeg(v.native(), cpath, &err, cquality)
1502	if !gobool(c) {
1503		defer C.g_error_free(err)
1504		return errors.New(C.GoString((*C.char)(err.message)))
1505	}
1506
1507	return nil
1508}
1509
1510// SavePNG is a wrapper around gdk_pixbuf_save().
1511// Compression is a number between 0...9
1512func (v *Pixbuf) SavePNG(path string, compression int) error {
1513	cpath := C.CString(path)
1514	ccompression := C.CString(strconv.Itoa(compression))
1515	defer C.free(unsafe.Pointer(cpath))
1516	defer C.free(unsafe.Pointer(ccompression))
1517
1518	var err *C.GError
1519	c := C._gdk_pixbuf_save_png(v.native(), cpath, &err, ccompression)
1520	if !gobool(c) {
1521		defer C.g_error_free(err)
1522		return errors.New(C.GoString((*C.char)(err.message)))
1523	}
1524	return nil
1525}
1526
1527// PixbufGetFileInfo is a wrapper around gdk_pixbuf_get_file_info().
1528// TODO: need to wrap the returned format to GdkPixbufFormat.
1529func PixbufGetFileInfo(filename string) (format interface{}, width, height int) {
1530	cstr := C.CString(filename)
1531	defer C.free(unsafe.Pointer(cstr))
1532	var cw, ch C.gint
1533	format = C.gdk_pixbuf_get_file_info((*C.gchar)(cstr), &cw, &ch)
1534	// TODO: need to wrap the returned format to GdkPixbufFormat.
1535	return format, int(cw), int(ch)
1536}
1537
1538/*
1539 * GdkPixbufLoader
1540 */
1541
1542// PixbufLoader is a representation of GDK's GdkPixbufLoader.
1543// Users of PixbufLoader are expected to call Close() when they are finished.
1544type PixbufLoader struct {
1545	*glib.Object
1546}
1547
1548// native() returns a pointer to the underlying GdkPixbufLoader.
1549func (v *PixbufLoader) native() *C.GdkPixbufLoader {
1550	if v == nil || v.GObject == nil {
1551		return nil
1552	}
1553	p := unsafe.Pointer(v.GObject)
1554	return C.toGdkPixbufLoader(p)
1555}
1556
1557// PixbufLoaderNew() is a wrapper around gdk_pixbuf_loader_new().
1558func PixbufLoaderNew() (*PixbufLoader, error) {
1559	c := C.gdk_pixbuf_loader_new()
1560	if c == nil {
1561		return nil, nilPtrErr
1562	}
1563
1564	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
1565	p := &PixbufLoader{obj}
1566	obj.Ref()
1567	runtime.SetFinalizer(p, func(_ interface{}) { obj.Unref() })
1568	return p, nil
1569}
1570
1571// PixbufLoaderNewWithType() is a wrapper around gdk_pixbuf_loader_new_with_type().
1572func PixbufLoaderNewWithType(t string) (*PixbufLoader, error) {
1573	var err *C.GError
1574
1575	cstr := C.CString(t)
1576	defer C.free(unsafe.Pointer(cstr))
1577
1578	c := C.gdk_pixbuf_loader_new_with_type((*C.char)(cstr), &err)
1579	if err != nil {
1580		defer C.g_error_free(err)
1581		return nil, errors.New(C.GoString((*C.char)(err.message)))
1582	}
1583
1584	if c == nil {
1585		return nil, nilPtrErr
1586	}
1587
1588	return &PixbufLoader{glib.Take(unsafe.Pointer(c))}, nil
1589}
1590
1591// Write() is a wrapper around gdk_pixbuf_loader_write().  The
1592// function signature differs from the C equivalent to satisify the
1593// io.Writer interface.
1594func (v *PixbufLoader) Write(data []byte) (int, error) {
1595	// n is set to 0 on error, and set to len(data) otherwise.
1596	// This is a tiny hacky to satisfy io.Writer and io.WriteCloser,
1597	// which would allow access to all io and ioutil goodies,
1598	// and play along nice with go environment.
1599
1600	if len(data) == 0 {
1601		return 0, nil
1602	}
1603
1604	var err *C.GError
1605	c := C.gdk_pixbuf_loader_write(v.native(),
1606		(*C.guchar)(unsafe.Pointer(&data[0])), C.gsize(len(data)),
1607		&err)
1608
1609	if !gobool(c) {
1610		defer C.g_error_free(err)
1611		return 0, errors.New(C.GoString((*C.char)(err.message)))
1612	}
1613
1614	return len(data), nil
1615}
1616
1617func (v *PixbufLoader) WriteAndReturnPixbuf(data []byte) (*Pixbuf, error) {
1618
1619	if len(data) == 0 {
1620		return nil, errors.New("no data")
1621	}
1622
1623	var err *C.GError
1624	c := C.gdk_pixbuf_loader_write(v.native(), (*C.guchar)(unsafe.Pointer(&data[0])), C.gsize(len(data)), &err)
1625
1626	if !gobool(c) {
1627		defer C.g_error_free(err)
1628		return nil, errors.New(C.GoString((*C.char)(err.message)))
1629	}
1630
1631	v.Close()
1632
1633	c2 := C.gdk_pixbuf_loader_get_pixbuf(v.native())
1634	if c2 == nil {
1635		return nil, nilPtrErr
1636	}
1637
1638	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c2))}
1639	p := &Pixbuf{obj}
1640	//obj.Ref() // Don't call Ref here, gdk_pixbuf_loader_get_pixbuf already did that for us.
1641	runtime.SetFinalizer(p, func(_ interface{}) { obj.Unref() })
1642
1643	return p, nil
1644}
1645
1646// Close is a wrapper around gdk_pixbuf_loader_close().  An error is
1647// returned instead of a bool like the native C function to support the
1648// io.Closer interface.
1649func (v *PixbufLoader) Close() error {
1650	var err *C.GError
1651
1652	if ok := gobool(C.gdk_pixbuf_loader_close(v.native(), &err)); !ok {
1653		defer C.g_error_free(err)
1654		return errors.New(C.GoString((*C.char)(err.message)))
1655	}
1656	return nil
1657}
1658
1659// SetSize is a wrapper around gdk_pixbuf_loader_set_size().
1660func (v *PixbufLoader) SetSize(width, height int) {
1661	C.gdk_pixbuf_loader_set_size(v.native(), C.int(width), C.int(height))
1662}
1663
1664// GetPixbuf is a wrapper around gdk_pixbuf_loader_get_pixbuf().
1665func (v *PixbufLoader) GetPixbuf() (*Pixbuf, error) {
1666	c := C.gdk_pixbuf_loader_get_pixbuf(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() // Don't call Ref here, gdk_pixbuf_loader_get_pixbuf already did that for us.
1674	runtime.SetFinalizer(p, func(_ interface{}) { obj.Unref() })
1675	return p, nil
1676}
1677
1678type RGBA struct {
1679	rgba *C.GdkRGBA
1680}
1681
1682func marshalRGBA(p uintptr) (interface{}, error) {
1683	c := C.g_value_get_boxed((*C.GValue)(unsafe.Pointer(p)))
1684	return WrapRGBA(unsafe.Pointer(c)), nil
1685}
1686
1687func WrapRGBA(p unsafe.Pointer) *RGBA {
1688	return wrapRGBA((*C.GdkRGBA)(p))
1689}
1690
1691func wrapRGBA(obj *C.GdkRGBA) *RGBA {
1692	return &RGBA{obj}
1693}
1694
1695func NewRGBA(values ...float64) *RGBA {
1696	cval := C.GdkRGBA{}
1697	c := &RGBA{&cval}
1698	if len(values) > 0 {
1699		c.rgba.red = C.gdouble(values[0])
1700	}
1701	if len(values) > 1 {
1702		c.rgba.green = C.gdouble(values[1])
1703	}
1704	if len(values) > 2 {
1705		c.rgba.blue = C.gdouble(values[2])
1706	}
1707	if len(values) > 3 {
1708		c.rgba.alpha = C.gdouble(values[3])
1709	}
1710	return c
1711}
1712
1713func (c *RGBA) Floats() []float64 {
1714	return []float64{float64(c.rgba.red), float64(c.rgba.green), float64(c.rgba.blue), float64(c.rgba.alpha)}
1715}
1716
1717// SetColors sets all colors values in the RGBA.
1718func (c *RGBA) SetColors(r, g, b, a float64) {
1719	c.rgba.red = C.gdouble(r)
1720	c.rgba.green = C.gdouble(g)
1721	c.rgba.blue = C.gdouble(b)
1722	c.rgba.alpha = C.gdouble(a)
1723}
1724
1725func (v *RGBA) Native() uintptr {
1726	return uintptr(unsafe.Pointer(v.rgba))
1727}
1728
1729// Parse is a representation of gdk_rgba_parse().
1730func (v *RGBA) Parse(spec string) bool {
1731	cstr := (*C.gchar)(C.CString(spec))
1732	defer C.free(unsafe.Pointer(cstr))
1733
1734	return gobool(C.gdk_rgba_parse(v.rgba, cstr))
1735}
1736
1737// String is a representation of gdk_rgba_to_string().
1738func (v *RGBA) String() string {
1739	return C.GoString((*C.char)(C.gdk_rgba_to_string(v.rgba)))
1740}
1741
1742// GdkRGBA * 	gdk_rgba_copy ()
1743// void 	gdk_rgba_free ()
1744// gboolean 	gdk_rgba_equal ()
1745// guint 	gdk_rgba_hash ()
1746
1747// PixbufGetType is a wrapper around gdk_pixbuf_get_type().
1748func PixbufGetType() glib.Type {
1749	return glib.Type(C.gdk_pixbuf_get_type())
1750}
1751
1752/*
1753 * GdkRectangle
1754 */
1755
1756// Rectangle is a representation of GDK's GdkRectangle type.
1757type Rectangle struct {
1758	GdkRectangle C.GdkRectangle
1759}
1760
1761func WrapRectangle(p uintptr) *Rectangle {
1762	return wrapRectangle((*C.GdkRectangle)(unsafe.Pointer(p)))
1763}
1764
1765func wrapRectangle(obj *C.GdkRectangle) *Rectangle {
1766	if obj == nil {
1767		return nil
1768	}
1769	return &Rectangle{*obj}
1770}
1771
1772// Native() returns a pointer to the underlying GdkRectangle.
1773func (r *Rectangle) native() *C.GdkRectangle {
1774	return &r.GdkRectangle
1775}
1776
1777// GetX returns x field of the underlying GdkRectangle.
1778func (r *Rectangle) GetX() int {
1779	return int(r.native().x)
1780}
1781
1782// GetY returns y field of the underlying GdkRectangle.
1783func (r *Rectangle) GetY() int {
1784	return int(r.native().y)
1785}
1786
1787// GetWidth returns width field of the underlying GdkRectangle.
1788func (r *Rectangle) GetWidth() int {
1789	return int(r.native().width)
1790}
1791
1792// GetHeight returns height field of the underlying GdkRectangle.
1793func (r *Rectangle) GetHeight() int {
1794	return int(r.native().height)
1795}
1796
1797/*
1798 * GdkVisual
1799 */
1800
1801// Visual is a representation of GDK's GdkVisual.
1802type Visual struct {
1803	*glib.Object
1804}
1805
1806func (v *Visual) native() *C.GdkVisual {
1807	if v == nil || v.GObject == nil {
1808		return nil
1809	}
1810	p := unsafe.Pointer(v.GObject)
1811	return C.toGdkVisual(p)
1812}
1813
1814func (v *Visual) Native() uintptr {
1815	return uintptr(unsafe.Pointer(v.native()))
1816}
1817
1818func marshalVisual(p uintptr) (interface{}, error) {
1819	c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
1820	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
1821	return &Visual{obj}, nil
1822}
1823
1824/*
1825 * GdkWindow
1826 */
1827
1828// Window is a representation of GDK's GdkWindow.
1829type Window struct {
1830	*glib.Object
1831}
1832
1833// SetCursor is a wrapper around gdk_window_set_cursor().
1834func (v *Window) SetCursor(cursor *Cursor) {
1835	C.gdk_window_set_cursor(v.native(), cursor.native())
1836}
1837
1838// native returns a pointer to the underlying GdkWindow.
1839func (v *Window) native() *C.GdkWindow {
1840	if v == nil || v.GObject == nil {
1841		return nil
1842	}
1843	p := unsafe.Pointer(v.GObject)
1844	return C.toGdkWindow(p)
1845}
1846
1847// Native returns a pointer to the underlying GdkWindow.
1848func (v *Window) Native() uintptr {
1849	return uintptr(unsafe.Pointer(v.native()))
1850}
1851
1852func marshalWindow(p uintptr) (interface{}, error) {
1853	c := C.g_value_get_object((*C.GValue)(unsafe.Pointer(p)))
1854	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(c))}
1855	return &Window{obj}, nil
1856}
1857
1858func toWindow(s *C.GdkWindow) (*Window, error) {
1859	if s == nil {
1860		return nil, nilPtrErr
1861	}
1862	obj := &glib.Object{glib.ToGObject(unsafe.Pointer(s))}
1863	return &Window{obj}, nil
1864}
1865