1 /* 2 * 3 * Copyright (C) 2003-2009 by the gtk2-perl team (see the file AUTHORS for the 4 * full list) 5 * 6 * This library is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU Library General Public License as published by 8 * the Free Software Foundation; either version 2.1 of the License, or (at your 9 * option) any later version. 10 * 11 * This library is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 14 * License for more details. 15 * 16 * You should have received a copy of the GNU Library General Public License 17 * along with this library; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * 21 * $Id$ 22 */ 23 24 #ifndef _GTK2PERL_H_ 25 #define _GTK2PERL_H_ 26 27 #include <gperl.h> 28 #include <pango-perl.h> 29 #include <gtk/gtk.h> 30 31 #include "gtk2perl-versions.h" 32 33 /* custom GType for GtkBindingSet */ 34 #ifndef GTK_TYPE_BINDING_SET 35 # define GTK_TYPE_BINDING_SET (gtk2perl_binding_set_get_type ()) 36 GType gtk2perl_binding_set_get_type (void) G_GNUC_CONST; 37 #endif 38 39 /* custom GType for GdkRegion */ 40 #ifndef GDK_TYPE_REGION 41 # define GDK_TYPE_REGION (gtk2perl_gdk_region_get_type ()) 42 GType gtk2perl_gdk_region_get_type (void) G_GNUC_CONST; 43 #endif 44 45 #include "gtk2perl-autogen.h" 46 47 /* no plug/socket on non-X11 despite patches exist for years. */ 48 #ifndef GDK_WINDOWING_X11 49 # undef GTK_TYPE_PLUG 50 # undef GTK_TYPE_SOCKET 51 #endif 52 53 /** 54 * gtk2perl_new_gtkobject: 55 * @object: object to wrap. 56 * 57 * convenient wrapper around gperl_new_object() which always passes %TRUE 58 * for gperl_new_object()'s "own" parameter. for #GtkObjects, that parameter 59 * merely results in gtk_object_sink() being called; if the object was not 60 * floating, this does nothing. thus, everything just works out. 61 * 62 * returns: scalar wrapper for @object. 63 * 64 * in xs/GtkObject.xs 65 */ 66 SV * gtk2perl_new_gtkobject (GtkObject * object); 67 68 69 /* 70 custom handling for GdkBitmaps, since there are no typemacros for them. 71 */ 72 /* GObject derivative GdkBitmap */ 73 #define SvGdkBitmap(sv) ((GdkBitmap*)gperl_get_object_check (sv, GDK_TYPE_DRAWABLE)) 74 typedef GdkBitmap GdkBitmap_ornull; 75 #define SvGdkBitmap_ornull(sv) (gperl_sv_is_defined (sv) ? SvGdkBitmap(sv) : NULL) 76 typedef GdkBitmap GdkBitmap_noinc; 77 /* these are real functions, rather than macros, because there's some extra 78 * work involved in making sure it's blessed into Gtk2::Gdk::Bitmap when no 79 * GType exists for GdkBitmap. */ 80 SV * newSVGdkBitmap (GdkBitmap * bitmap); 81 SV * newSVGdkBitmap_noinc (GdkBitmap * bitmap); 82 #define newSVGdkBitmap_ornull(b) (b ? newSVGdkBitmap (b) : Nullsv) 83 84 /* exported for GtkGC */ 85 SV * newSVGdkGCValues (GdkGCValues * v); 86 void SvGdkGCValues (SV * data, GdkGCValues * v, GdkGCValuesMask * m); 87 88 /* exported for various other parts of pango */ 89 SV * newSVPangoRectangle (PangoRectangle * rectangle); 90 PangoRectangle * SvPangoRectangle (SV * sv); 91 92 /* 93 * GdkAtom, an opaque pointer 94 */ 95 SV * newSVGdkAtom (GdkAtom atom); 96 GdkAtom SvGdkAtom (SV * sv); 97 98 SV * newSVGtkTargetEntry (GtkTargetEntry * target_entry); 99 /* do not store GtkTargetEntry objects returned from this function -- 100 * they are only good for the block of code in which they are created */ 101 GtkTargetEntry * SvGtkTargetEntry (SV * sv); 102 void gtk2perl_read_gtk_target_entry (SV * sv, GtkTargetEntry * entry); 103 104 #define GTK2PERL_STACK_ITEMS_TO_TARGET_ENTRY_ARRAY(first, targets, ntargets) \ 105 { \ 106 guint i; \ 107 if (items <= first) { \ 108 ntargets = 0; \ 109 targets = NULL; \ 110 } else { \ 111 ntargets = items - first; \ 112 targets = gperl_alloc_temp (sizeof (GtkTargetEntry) * ntargets); \ 113 for (i = 0 ; i < ntargets ; i++) \ 114 gtk2perl_read_gtk_target_entry (ST (i + first), \ 115 targets + i); \ 116 } \ 117 } 118 119 /* 120 * get a list of GTypes from the xsub argument stack 121 * used to collect column types for creating and initializing GtkTreeStores 122 * and GtkListStores. 123 */ 124 #define GTK2PERL_STACK_ITEMS_TO_GTYPE_ARRAY(arrayvar, first, last) \ 125 (arrayvar) = g_array_new (FALSE, FALSE, sizeof (GType)); \ 126 g_array_set_size ((arrayvar), (last) - (first) + 1); \ 127 { \ 128 int i; \ 129 for (i = (first) ; i <= (last) ; i++) { \ 130 char * package = SvPV_nolen (ST (i)); \ 131 /* look up GType by package name. */ \ 132 GType t = gperl_type_from_package (package); \ 133 if (t == 0) { \ 134 g_array_free ((arrayvar), TRUE); \ 135 croak ("package %s is not registered with GPerl", \ 136 package); \ 137 g_assert ("not reached"); \ 138 } \ 139 g_array_index ((arrayvar), GType, i-(first)) = t; \ 140 } \ 141 } 142 143 144 /* 145 * some custom opaque object handling for private gtk structures needed 146 * for doing drag and drop. 147 */ 148 149 /* gtk+ 2.10 introduces a boxed type for GtkTargetList and we use it for 150 * property marshalling, etc. But we also need to keep backwards compatability 151 * with the old wrappers so we overwrite the macros. */ 152 #if GTK_CHECK_VERSION (2, 10, 0) 153 # undef newSVGtkTargetList 154 # undef newSVGtkTargetList_ornull 155 # undef SvGtkTargetList 156 # undef SvGtkTargetList_ornull 157 #else 158 typedef GtkTargetList GtkTargetList_ornull; 159 #endif 160 SV * newSVGtkTargetList (GtkTargetList * list); 161 #define newSVGtkTargetList_ornull(list) ((list) ? newSVGtkTargetList (list) : &PL_sv_undef) 162 GtkTargetList * SvGtkTargetList (SV * sv); 163 #define SvGtkTargetList_ornull(sv) (gperl_sv_is_defined (sv) ? SvGtkTargetList (sv) : NULL) 164 165 /* 166 * exported so Gnome2 can reuse it in wrappers. other modules might want to 167 * do the same. the callback for it needn't worry about param_types or 168 * return type, as this does all the marshaling by hand (the C function writes 169 * through the params, so we have to handle the stack specially). 170 */ 171 void gtk2perl_menu_position_func (GtkMenu * menu, 172 gint * x, 173 gint * y, 174 gboolean * push_in, 175 GPerlCallback * callback); 176 177 178 #if ! GTK_CHECK_VERSION (2, 4, 0) 179 /* in versions prior to 2.4.0, GtkTreeSearchFlags was declared such that 180 * glib-mkenums interpreted and registered it as a GEnum type. sometime 181 * before 2.3.0, this was corrected, and the type is registered as a GFlags. 182 * The maps file has GFlags (since that's correct), but we have to mangle 183 * things somewhat for the bindings to work properly with older libraries. */ 184 # undef SvGtkTextSearchFlags 185 # undef newSVGtkTextSearchFlags 186 # define SvGtkTextSearchFlags(sv) (gperl_convert_enum (GTK_TYPE_TEXT_SEARCH_FLAGS, sv)) 187 # define newSVGtkTextSearchFlags(val) (gperl_convert_back_enum (GTK_TYPE_TEXT_SEARCH_FLAGS, val)) 188 #endif 189 190 /* object handling for GdkGeometry */ 191 SV * newSVGdkGeometry (GdkGeometry *geometry); 192 GdkGeometry * SvGdkGeometry (SV *object); 193 GdkGeometry * SvGdkGeometryReal (SV *object, GdkWindowHints *hints); 194 195 /* special handling for GdkPixbufFormat, which was introduced in gtk+ 2.2.0 */ 196 #if GTK_CHECK_VERSION (2, 2, 0) 197 SV * newSVGdkPixbufFormat (GdkPixbufFormat * format); 198 GdkPixbufFormat * SvGdkPixbufFormat (SV * sv); 199 #endif 200 201 #endif /* _GTK2PERL_H_ */ 202