File: GtkGC.xs

package info (click to toggle)
libgtk2-perl 2:1.2499-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,668 kB
  • ctags: 594
  • sloc: perl: 22,100; ansic: 122; makefile: 17
file content (137 lines) | stat: -rw-r--r-- 3,092 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
 * Copyright (c) 2003 by the gtk2-perl team (see the file AUTHORS)
 *
 * Licensed under the LGPL, see LICENSE file for more information.
 *
 * $Id$
 */

#include "gtk2perl.h"

static GQuark release_count_quark (void) G_GNUC_CONST;

static GQuark
release_count_quark (void)
{
	static GQuark q = 0;

	if (!q)
		q = g_quark_from_static_string ("gtk2perl_gc_release_count");

	return q;
}

static gint
modify_count (GdkGC * gc,
	      gint diff)
{
	gint count;

	count = GPOINTER_TO_INT (g_object_get_qdata (G_OBJECT (gc),
						     release_count_quark ()));

	count += diff;

	g_object_set_qdata (G_OBJECT (gc),
			    release_count_quark (),
			    GINT_TO_POINTER (count));

	return count;
}

MODULE = Gtk2::GC	PACKAGE = Gtk2::GC	PREFIX = gtk_gc_

BOOT:
	gperl_set_isa ("Gtk2::GC", "Gtk2::Gdk::GC");

=for position post_hierarchy

=head1 HIERARCHY

  Glib::Object
  +----Gtk2::Gdk::GC
       +----Gtk2::GC

=cut

=for position DESCRIPTION

=head1 DESCRIPTION

These functions provide access to a shared pool of L<Gtk2::Gdk::GC>
objects. When a new L<Gtk2::Gdk::GC> is needed, I<Gtk2::Gdk::GC::get> is called
with the required depth, colormap and I<Gtk2::Gdk::GCValues>. If a
L<Gtk2::Gdk::GC> with the required properties already exists then that is
returned. If not, a new L<Gtk2::Gdk::GC> is created.

[From: L<http://developer.gnome.org/doc/API/2.0/gtk/gtk-Graphics-Contexts.html>]

=cut

## GdkGC * gtk_gc_get (gint depth, GdkColormap *colormap, GdkGCValues *values, GdkGCValuesMask values_mask)
=for apidoc
=for signature gc = Gtk2::GC->get ($depth, $colormap, $values)
=for arg values (Gtk2::Gdk::GCValues) Values to match
C<$values> is a hashref with keys and values as per
C<< Gtk2::Gdk::GC->new >> (see L<Gtk2::Gdk::GC>).
=cut
SV *
gtk_gc_get (class, depth, colormap, values)
	gint depth
	GdkColormap *colormap
	SV *values
    PREINIT:
	GdkGC * gc;
	GdkGCValues v;
	GdkGCValuesMask m;
    CODE:
	SvGdkGCValues (values, &v, &m);
	gc = gtk_gc_get (depth, colormap, &v, m);
	modify_count (gc, 1);
	/* Rebless to Gtk2::GC, so that we get our DESTROY called */
	RETVAL = sv_bless (newSVGdkGC (gc), gv_stashpv ("Gtk2::GC", 1));
    OUTPUT:
	RETVAL

=for apidoc __hide__
=cut
## void gtk_gc_release (GdkGC *gc)
void
gtk_gc_release (class, gc)
	GdkGC *gc
    CODE:
	modify_count (gc, -1);
	gtk_gc_release (gc);

=for apidoc __hide__
=cut
void
DESTROY (SV * sv)
    PREINIT:
	GdkGC * gc;
    CODE:
	gc = SvGdkGC (sv);

	/* Release all live references */
	while (modify_count (gc, -1) >= 0)
		gtk_gc_release (gc);

	/* You must never fail to chain up to DESTROY on a Glib::Object. */
	PUSHMARK (SP);
	EXTEND (SP, 1);
	PUSHs (sv);
	PUTBACK;
	call_method ("Gtk2::Gdk::GC::DESTROY", G_VOID|G_DISCARD);
	SPAGAIN;

=for position post_methods

=head2 Compatibility

Before version 1.200 of the Gtk2 perl module, it was necessary to call
C<Gtk2::GC::release()> on GCs obtained from C<Gtk2::GC::get()>.  As of
version 1.200, this is no longer necessary; a GC will be released when
the last perl reference goes away.  Old-style code continues to work,
but C<Gtk2::GC::release()> is deprecated.

=cut