1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551
|
/*
* Copyright (c) 2003-2006 by the gtk2-perl team (see the file AUTHORS)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307 USA.
*
* $Header: /cvsroot/gtk2-perl/gtk2-perl-xs/Gtk2/xs/GtkSelection.xs,v 1.28 2006/08/07 18:36:10 kaffeetisch Exp $
*/
#include "gtk2perl.h"
SV *
newSVGtkTargetEntry (GtkTargetEntry * e)
{
HV * h;
SV * r;
if (!e)
return &PL_sv_undef;
h = newHV ();
r = newRV_noinc ((SV*)h);
hv_store (h, "target", 6, e->target ? newSVpv (e->target, 0) : newSVsv (&PL_sv_undef), 0);
hv_store (h, "flags", 5, newSVGtkTargetFlags (e->flags), 0);
hv_store (h, "info", 4, newSViv (e->info), 0);
return r;
}
GtkTargetEntry *
SvGtkTargetEntry (SV * sv)
{
GtkTargetEntry * entry = gperl_alloc_temp (sizeof (GtkTargetEntry));
gtk2perl_read_gtk_target_entry (sv, entry);
return entry;
}
void
gtk2perl_read_gtk_target_entry (SV * sv,
GtkTargetEntry * e)
{
HV * h;
AV * a;
SV ** s;
STRLEN len;
if ((!sv) || (!SvOK (sv)) || (!SvRV (sv)) ||
(SvTYPE (SvRV (sv)) != SVt_PVHV && SvTYPE (SvRV(sv)) != SVt_PVAV))
croak ("a target entry must be a reference to a hash "
"containing the keys 'target', 'flags', and 'info', "
"or a reference to a three-element list containing "
"the information in the order target, flags, info");
if (SvTYPE (SvRV (sv)) == SVt_PVHV) {
h = (HV*) SvRV (sv);
if ((s=hv_fetch (h, "target", 6, 0)) && SvOK (*s))
e->target = SvPV (*s, len);
if ((s=hv_fetch (h, "flags", 5, 0)) && SvOK (*s))
e->flags = SvGtkTargetFlags (*s);
if ((s=hv_fetch (h, "info", 4, 0)) && SvOK (*s))
e->info = SvUV (*s);
} else {
a = (AV*)SvRV (sv);
if ((s=av_fetch (a, 0, 0)) && SvOK (*s))
e->target = SvPV (*s, len);
if ((s=av_fetch (a, 1, 0)) && SvOK (*s))
e->flags = SvGtkTargetFlags (*s);
if ((s=av_fetch (a, 2, 0)) && SvOK (*s))
e->info = SvUV (*s);
}
}
/* gtk+ 2.10 introduces a boxed type for GtkTargetList. */
#if GTK_CHECK_VERSION (2, 10, 0)
static GPerlBoxedWrapperClass *default_wrapper_class;
static GPerlBoxedWrapperClass gtk_target_list_wrapper_class;
static SV *
gtk_target_list_wrap (GType gtype,
const char *package,
gpointer boxed,
gboolean own)
{
/* To keep compatibility with the old wrappers, we always assume
* ownership of the list. */
gtk_target_list_ref ((GtkTargetList *) boxed);
return default_wrapper_class->wrap (gtype, package, boxed, TRUE);
}
#endif /* 2.10 */
SV *
newSVGtkTargetList (GtkTargetList * list)
{
#if GTK_CHECK_VERSION (2, 9, 0)
return gperl_new_boxed (list, GTK_TYPE_TARGET_LIST, TRUE);
#else
gtk_target_list_ref (list);
return sv_setref_pv (newSV (0), "Gtk2::TargetList", list);
#endif
}
GtkTargetList *
SvGtkTargetList (SV * sv)
{
#if GTK_CHECK_VERSION (2, 9, 0)
return gperl_get_boxed_check (sv, GTK_TYPE_TARGET_LIST);
#else
if (!sv || !SvROK (sv) ||
!sv_derived_from (sv, "Gtk2::TargetList"))
croak ("variable is not of type Gtk2::TargetList");
return INT2PTR (GtkTargetList*, SvUV (SvRV (sv)));
#endif
}
MODULE = Gtk2::Selection PACKAGE = Gtk2::TargetEntry
=for position SYNOPSIS
=head1 SYNOPSIS
# as a HASH
$target_entry = {
target => 'text/plain', # some string representing the drag type
flags => [], # Gtk2::TargetFlags
info => 42, # some app-defined integer identifier
};
# as an ARRAY, for compactness
$target_entry = [ $target, $flags, $info ];
=cut
=for position DESCRIPTION
=head1 DESCRIPTION
A Gtk2::TargetEntry data structure represents a single type of data than can
be supplied for by a widget for a selection or for supplied or received during
drag-and-drop. It contains a string representing the drag type, a flags field
(used only for drag and drop - see Gtk2::TargetFlags), and an application
assigned integer ID. The integer ID will later be passed as a signal parameter
for signals like "selection_get". It allows the application to identify the
target type without extensive string compares.
=cut
=for flags GtkTargetFlags
=cut
=for see_also Gtk2::TargetList
=cut
MODULE = Gtk2::Selection PACKAGE = Gtk2::TargetList PREFIX = gtk_target_list_
BOOT:
#if GTK_CHECK_VERSION (2, 9, 0)
default_wrapper_class = gperl_default_boxed_wrapper_class ();
gtk_target_list_wrapper_class = *default_wrapper_class;
gtk_target_list_wrapper_class.wrap = gtk_target_list_wrap;
gperl_register_boxed (GTK_TYPE_TARGET_LIST, "Gtk2::TargetList",
>k_target_list_wrapper_class);
#endif
=for see_also Gtk2::TargetEntry
=cut
#if !GTK_CHECK_VERSION (2, 10, 0)
void
DESTROY (SV * list)
CODE:
gtk_target_list_unref (SvGtkTargetList (list));
#endif /* !2.10 */
## GtkTargetList *gtk_target_list_new (const GtkTargetEntry *targets, guint ntargets)
=for apidoc
=for arg ... of Gtk2::TargetEntry's
=cut
GtkTargetList *
gtk_target_list_new (class, ...)
PREINIT:
GtkTargetEntry *targets;
guint ntargets;
CODE:
GTK2PERL_STACK_ITEMS_TO_TARGET_ENTRY_ARRAY (1, targets, ntargets);
RETVAL = gtk_target_list_new (targets, ntargets);
OUTPUT:
RETVAL
CLEANUP:
gtk_target_list_unref (RETVAL);
## void gtk_target_list_add (GtkTargetList *list, GdkAtom target, guint flags, guint info)
void
gtk_target_list_add (list, target, flags, info)
GtkTargetList *list
GdkAtom target
guint flags
guint info
## void gtk_target_list_add_table (GtkTargetList *list, const GtkTargetEntry *targets, guint ntargets)
=for apidoc
=for arg ... of Gtk2::TargetEntry's
=cut
void
gtk_target_list_add_table (GtkTargetList * list, ...)
PREINIT:
GtkTargetEntry *targets;
guint ntargets;
CODE:
GTK2PERL_STACK_ITEMS_TO_TARGET_ENTRY_ARRAY (1, targets, ntargets);
gtk_target_list_add_table (list, targets, ntargets);
## void gtk_target_list_remove (GtkTargetList *list, GdkAtom target)
void
gtk_target_list_remove (list, target)
GtkTargetList *list
GdkAtom target
## gboolean gtk_target_list_find (GtkTargetList *list, GdkAtom target, guint *info)
guint
gtk_target_list_find (list, target)
GtkTargetList *list
GdkAtom target
CODE:
if (!gtk_target_list_find (list, target, &RETVAL))
XSRETURN_UNDEF;
OUTPUT:
RETVAL
#if GTK_CHECK_VERSION (2, 6, 0)
void gtk_target_list_add_text_targets (GtkTargetList *list, guint info);
void gtk_target_list_add_image_targets (GtkTargetList *list, guint info, gboolean writable);
void gtk_target_list_add_uri_targets (GtkTargetList *list, guint info);
#endif
#if GTK_CHECK_VERSION (2, 10, 0)
void gtk_target_list_add_rich_text_targets (GtkTargetList *list, guint info, gboolean deserializable, GtkTextBuffer * buffer);
#endif
MODULE = Gtk2::Selection PACKAGE = Gtk2::Selection PREFIX = gtk_selection_
## gboolean gtk_selection_owner_set (GtkWidget *widget, GdkAtom selection, guint32 time_)
gboolean
gtk_selection_owner_set (class, widget, selection, time_)
GtkWidget_ornull *widget
GdkAtom selection
guint32 time_
C_ARGS:
widget, selection, time_
#if GTK_CHECK_VERSION(2,2,0)
## gboolean gtk_selection_owner_set_for_display (GdkDisplay *display, GtkWidget *widget, GdkAtom selection, guint32 time_)
gboolean
gtk_selection_owner_set_for_display (class, display, widget, selection, time_)
GdkDisplay *display
GtkWidget_ornull *widget
GdkAtom selection
guint32 time_
C_ARGS:
display, widget, selection, time_
#endif /* >= 2.2.0 */
MODULE = Gtk2::Selection PACKAGE = Gtk2::Widget PREFIX = gtk_
=for see_also Gtk2::TargetEntry
=cut
## void gtk_selection_add_target (GtkWidget *widget, GdkAtom selection, GdkAtom target, guint info)
void
gtk_selection_add_target (widget, selection, target, info)
GtkWidget *widget
GdkAtom selection
GdkAtom target
guint info
## void gtk_selection_add_targets (GtkWidget *widget, GdkAtom selection, const GtkTargetEntry *targets, guint ntargets)
=for apidoc
=for arg ... of Gtk2::TargetEntry's
=cut
void
gtk_selection_add_targets (widget, selection, ...)
GtkWidget *widget
GdkAtom selection
PREINIT:
GtkTargetEntry *targets;
guint ntargets;
CODE:
GTK2PERL_STACK_ITEMS_TO_TARGET_ENTRY_ARRAY (2, targets, ntargets);
gtk_selection_add_targets (widget, selection, targets, ntargets);
## void gtk_selection_clear_targets (GtkWidget *widget, GdkAtom selection)
void
gtk_selection_clear_targets (widget, selection)
GtkWidget *widget
GdkAtom selection
## gboolean gtk_selection_convert (GtkWidget *widget, GdkAtom selection, GdkAtom target, guint32 time_)
gboolean
gtk_selection_convert (widget, selection, target, time_)
GtkWidget *widget
GdkAtom selection
GdkAtom target
guint32 time_
## void gtk_selection_remove_all (GtkWidget *widget)
void
gtk_selection_remove_all (widget)
GtkWidget *widget
#if GTK_CHECK_VERSION (2, 10, 0)
MODULE = Gtk2::Selection PACKAGE = Gtk2 PREFIX = gtk_
gboolean gtk_targets_include_text (class, first_target_atom, ...)
ALIAS:
targets_include_uri = 1
PREINIT:
GdkAtom * targets;
gint n_targets;
gint i;
CODE:
n_targets = items - 1;
targets = g_new (GdkAtom, n_targets);
for (i = 1; i < items ; i++)
targets[i-1] = SvGdkAtom (ST (i));
if (ix == 1)
RETVAL = gtk_targets_include_uri (targets, n_targets);
else
RETVAL = gtk_targets_include_text (targets, n_targets);
g_free (targets);
OUTPUT:
RETVAL
gboolean gtk_targets_include_rich_text (class, GtkTextBuffer * buffer, first_target_atom, ...)
PREINIT:
GdkAtom * targets;
gint n_targets;
gint i;
CODE:
n_targets = items - 2;
targets = g_new (GdkAtom, n_targets);
for (i = 2; i < items ; i++)
targets[i-2] = SvGdkAtom (ST (i));
RETVAL = gtk_targets_include_rich_text (targets, n_targets, buffer);
g_free (targets);
OUTPUT:
RETVAL
gboolean gtk_targets_include_image (class, gboolean writable, first_target_atom, ...)
PREINIT:
GdkAtom * targets;
gint n_targets;
gint i;
CODE:
n_targets = items - 2;
targets = g_new (GdkAtom, n_targets);
for (i = 2; i < items ; i++)
targets[i-2] = SvGdkAtom (ST (i));
RETVAL = gtk_targets_include_image (targets, n_targets, writable);
g_free (targets);
OUTPUT:
RETVAL
#endif /* 2.10 */
MODULE = Gtk2::Selection PACKAGE = Gtk2::SelectionData PREFIX = gtk_selection_data_
SV *
selection (d)
GtkSelectionData * d
ALIAS:
Gtk2::SelectionData::target = 1
Gtk2::SelectionData::type = 2
Gtk2::SelectionData::format = 3
Gtk2::SelectionData::data = 4
Gtk2::SelectionData::length = 5
Gtk2::SelectionData::display = 6
CODE:
switch (ix) {
case 0: RETVAL = newSVGdkAtom (d->selection); break;
case 1: RETVAL = newSVGdkAtom (d->target); break;
case 2: RETVAL = newSVGdkAtom (d->type); break;
case 3: RETVAL = newSViv (d->format); break;
case 4: RETVAL = newSVpv ((char*)d->data, d->length); break;
case 5: RETVAL = newSViv (d->length); break;
#if GTK_CHECK_VERSION(2,2,0)
case 6: RETVAL = newSVGdkDisplay (d->display); break;
#endif
default:
RETVAL = NULL;
g_assert_not_reached ();
}
OUTPUT:
RETVAL
## void gtk_selection_data_set (GtkSelectionData *selection_data, GdkAtom type, gint format, const guchar *data, gint length)
void
gtk_selection_data_set (selection_data, type, format, data)
GtkSelectionData *selection_data
GdkAtom type
gint format
const guchar *data
C_ARGS:
selection_data, type, format, data, sv_len (ST (3))
## gboolean gtk_selection_data_set_text (GtkSelectionData *selection_data, const gchar *str, gint len)
gboolean
gtk_selection_data_set_text (selection_data, str, len=-1)
GtkSelectionData *selection_data
const gchar *str
gint len
## guchar * gtk_selection_data_get_text (GtkSelectionData *selection_data)
#guchar *
gchar_own *
gtk_selection_data_get_text (selection_data)
GtkSelectionData *selection_data
CODE:
/* the C function returns guchar*, but the docs say it will return
* a UTF-8 string or NULL. for our code to do the UTF-8 upgrade,
* we need to use a gchar* typemap, so we'll cast to keep the compiler
* happy. */
RETVAL = (gchar*) gtk_selection_data_get_text (selection_data);
/* the docs say get_text will return NULL if there is no text or it
* the text can't be converted to UTF-8. (why don't we have a
* gchar_own_ornull typemap?) */
if (!RETVAL)
XSRETURN_UNDEF;
OUTPUT:
RETVAL
## gboolean gtk_selection_data_get_targets (GtkSelectionData *selection_data, GdkAtom **targets, gint *n_atoms)
=for apidoc
Gets the contents of selection_data as an array of targets. This can be used to
interpret the results of getting the standard TARGETS target that is always
supplied for any selection.
Returns a list of GdkAtoms, the targets.
=cut
void
gtk_selection_data_get_targets (selection_data)
GtkSelectionData *selection_data
PREINIT:
GdkAtom *targets;
gint n_atoms, i;
PPCODE:
if (!gtk_selection_data_get_targets (selection_data,
&targets, &n_atoms))
XSRETURN_EMPTY;
EXTEND (SP, n_atoms);
for (i = 0 ; i < n_atoms ; i++)
PUSHs (sv_2mortal (newSVGdkAtom (targets[i])));
g_free (targets);
## gboolean gtk_selection_data_targets_include_text (GtkSelectionData *selection_data)
gboolean
gtk_selection_data_targets_include_text (selection_data)
GtkSelectionData *selection_data
# FIXME: This method is completely misbound, it can only be used as
# Gtk2::SelectionData::gtk_selection_clear ($widget, $event). Additionally, it
# has been deprecated since 31-Jan-03. So remove this whenever we get the
# chance to break API.
## gboolean gtk_selection_clear (GtkWidget *widget, GdkEventSelection *event)
=for apidoc __hide__
=cut
gboolean
gtk_selection_clear (widget, event)
GtkWidget *widget
GdkEvent *event
C_ARGS:
widget, (GdkEventSelection*)event
#if GTK_CHECK_VERSION (2, 6, 0)
gboolean gtk_selection_data_set_pixbuf (GtkSelectionData *selection_data, GdkPixbuf *pixbuf);
GdkPixbuf_noinc_ornull * gtk_selection_data_get_pixbuf (GtkSelectionData *selection_data);
## gboolean gtk_selection_data_set_uris (GtkSelectionData *selection_data, gchar **uris);
=for apidoc
=for arg ... of strings
=cut
gboolean
gtk_selection_data_set_uris (selection_data, ...);
GtkSelectionData *selection_data
PREINIT:
gchar **uris = NULL;
int i;
CODE:
/* uris is NULL-terminated. */
uris = g_new0 (gchar *, items);
for (i = 1; i < items; i++)
uris[i - 1] = SvGChar (ST (i));
RETVAL = gtk_selection_data_set_uris (selection_data, uris);
g_free (uris);
OUTPUT:
RETVAL
## gchar ** gtk_selection_data_get_uris (GtkSelectionData *selection_data);
void
gtk_selection_data_get_uris (selection_data)
GtkSelectionData *selection_data
PREINIT:
gchar **uris = NULL;
int i;
PPCODE:
uris = gtk_selection_data_get_uris (selection_data);
if (!uris)
XSRETURN_EMPTY;
for (i = 0; uris[i]; i++)
XPUSHs (sv_2mortal (newSVGChar (uris[i])));
g_strfreev (uris);
gboolean gtk_selection_data_targets_include_image (GtkSelectionData *selection_data, gboolean writable);
#endif /* 2.6 */
#if GTK_CHECK_VERSION (2, 10, 0)
gboolean gtk_selection_data_targets_include_rich_text (GtkSelectionData *selection_data, GtkTextBuffer * buffer)
gboolean gtk_selection_data_targets_include_uri (GtkSelectionData *selection_data)
#endif /* 2.10 */
|