home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / perl5 / Gtk2.pm < prev    next >
Encoding:
Perl POD Document  |  2008-11-28  |  10.5 KB  |  365 lines

  1. #
  2. # Copyright (C) 2003-2008 by the gtk2-perl team (see the file AUTHORS for
  3. # the full list)
  4. #
  5. # This library is free software; you can redistribute it and/or modify it under
  6. # the terms of the GNU Library General Public License as published by the Free
  7. # Software Foundation; either version 2.1 of the License, or (at your option)
  8. # any later version.
  9. #
  10. # This library is distributed in the hope that it will be useful, but WITHOUT
  11. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  12. # FOR A PARTICULAR PURPOSE.  See the GNU Library General Public License for
  13. # more details.
  14. #
  15. # You should have received a copy of the GNU Library General Public License
  16. # along with this library; if not, write to the Free Software Foundation, Inc.,
  17. # 59 Temple Place - Suite 330, Boston, MA  02111-1307  USA.
  18. #
  19. # $Header: /cvsroot/gtk2-perl/gtk2-perl-xs/Gtk2/Gtk2.pm,v 1.125 2008/06/22 17:26:54 kaffeetisch Exp $
  20. #
  21.  
  22. package Gtk2;
  23.  
  24. # Gtk uses unicode strings; thus we require perl>=5.8.x,
  25. # which is unicode internally.
  26. use 5.008;
  27. use strict;
  28. use warnings;
  29.  
  30. use Glib;
  31.  
  32. # if the gtk+ we've been compiled against is at 2.8.0 or newer or if pango is
  33. # at 1.10.0 or newer, we need to import the Cairo module for the cairo glue in
  34. # gtk+ and pango.
  35. eval "use Cairo;";
  36.  
  37. use Exporter;
  38. require DynaLoader;
  39.  
  40. our $VERSION = '1.190';
  41.  
  42. our @ISA = qw(DynaLoader Exporter);
  43.  
  44. # this is critical -- tell dynaloader to load the module so that its
  45. # symbols are available to all other modules.  without this, nobody
  46. # else can use important functions like gtk2perl_new_object!
  47. #
  48. # hrm.  win32 doesn't really use this, because we have to link the whole
  49. # thing at compile time to ensure all the symbols are defined.
  50. #
  51. # on darwin, at least with the particular 5.8.0 binary i'm using, perl
  52. # complains "Can't make loaded symbols global on this platform" when this
  53. # is set to 0x01, but goes on to work fine.  returning 0 here avoids the
  54. # warning and doesn't appear to break anything.
  55. sub dl_load_flags { $^O eq 'darwin' ? 0x00 : 0x01 }
  56.  
  57. # now load the XS code.
  58. Gtk2->bootstrap ($VERSION);
  59.  
  60. # %Gtk2::EXPORT_TAGS is filled from the constants-x.y files by the generated XS
  61. # code in build/constants.xs
  62. our @EXPORT_OK = map { @$_ } values %Gtk2::EXPORT_TAGS;
  63. $Gtk2::EXPORT_TAGS{all} = \@EXPORT_OK;
  64.  
  65. sub import {
  66.     my $class = shift;
  67.  
  68.     # threads' init needs to be called before the main init and we don't
  69.     # want to force the order those options are passed to us so we need to
  70.     # cache the choices in booleans and (optionally) do them in the corect
  71.     # order afterwards
  72.     my $init = 0;
  73.     my $threads_init = 0;
  74.  
  75.     my @unknown_args = ($class);
  76.     foreach (@_) {
  77.         if (/^-?init$/) {
  78.             $init = 1;
  79.         } elsif (/-?threads-init$/) {
  80.             $threads_init = 1;
  81.         } else {
  82.             push @unknown_args, $_;
  83.         }
  84.     }
  85.  
  86.     Gtk2::Gdk::Threads->init if ($threads_init);
  87.     Gtk2->init if ($init);
  88.  
  89.     # call into Exporter for the unrecognized arguments; handles exporting
  90.     # and version checking
  91.     Gtk2->export_to_level (1, @unknown_args);
  92. }
  93.  
  94. # Preloaded methods go here.
  95.  
  96. package Gtk2::Gdk;
  97.  
  98. sub CHARS { 8 };
  99. sub SHORTS { 16 };
  100. sub LONGS { 32 };
  101.  
  102. sub USHORTS { 16 };
  103. sub ULONGS { 32 };
  104.  
  105. package Gtk2::Gdk::Atom;
  106.  
  107. use overload
  108.     '==' => \&Gtk2::Gdk::Atom::eq,
  109.     '!=' => \&Gtk2::Gdk::Atom::ne,
  110.     fallback => 1;
  111.  
  112. package Gtk2::CellLayout::DataFunc;
  113.  
  114. use overload
  115.     '&{}' => sub { \&Gtk2::CellLayout::DataFunc::invoke },
  116.     fallback => 1;
  117.  
  118. package Gtk2::TreeSortable::IterCompareFunc;
  119.  
  120. use overload
  121.     '&{}' => sub { \&Gtk2::TreeSortable::IterCompareFunc::invoke },
  122.     fallback => 1;
  123.  
  124. package Gtk2::TreeModelSort;
  125.  
  126. # We forgot to prepend Gtk2::TreeModel to @Gtk2::TreeModelSort::ISA.  So this
  127. # hack is here to make sure that $model_sort->get resolves to
  128. # Gtk2::TreeModel::get when appropriate and to Glib::Object::get otherwise, so
  129. # we stay backwards compatible.
  130. sub get {
  131.     if (@_ > 1 and ref $_[1] eq 'Gtk2::TreeIter') {
  132.         # called as $model->get ($iter, columns...);
  133.         return Gtk2::TreeModel::get (@_);
  134.     } else {
  135.         # called as $model->get (names...);
  136.         return Glib::Object::get (@_);
  137.     }
  138. }
  139.  
  140. package Gtk2::Builder;
  141.  
  142. sub _do_connect {
  143.   my ($object,
  144.       $signal_name,
  145.       $user_data,
  146.       $connect_object,
  147.       $flags,
  148.       $handler) = @_;
  149.  
  150.   my $func = ($flags & 'after') ? 'signal_connect_after' : 'signal_connect';
  151.  
  152.   # we get connect_object when we're supposed to call
  153.   # signal_connect_object, which ensures that the data (an object)
  154.   # lives as long as the signal is connected.  the bindings take
  155.   # care of that for us in all cases, so we only have signal_connect.
  156.   # if we get a connect_object, just use that instead of user_data.
  157.   $object->$func($signal_name => $handler,
  158.                  $connect_object ? $connect_object : $user_data);
  159. }
  160.  
  161. sub connect_signals {
  162.   my $builder = shift;
  163.   my $user_data = shift;
  164.  
  165.   # $builder->connect_signals ($user_data)
  166.   # $builder->connect_signals ($user_data, $package)
  167.   if ($#_ <= 0) {
  168.     my $package = shift;
  169.     $package = caller unless defined $package;
  170.  
  171.     $builder->connect_signals_full(sub {
  172.       my ($builder,
  173.           $object,
  174.           $signal_name,
  175.           $handler_name,
  176.           $connect_object,
  177.           $flags) = @_;
  178.  
  179.       no strict qw/refs/;
  180.  
  181.       my $handler = $handler_name;
  182.       if (ref $package) {
  183.         $handler = sub { $package->$handler_name(@_) };
  184.       } else {
  185.         if ($package && $handler !~ /::/) {
  186.           $handler = $package.'::'.$handler_name;
  187.         }
  188.       }
  189.  
  190.       _do_connect ($object, $signal_name, $user_data, $connect_object,
  191.                    $flags, $handler);
  192.     });
  193.   }
  194.  
  195.   # $builder->connect_signals ($user_data, %handlers)
  196.   else {
  197.     my %handlers = @_;
  198.  
  199.     $builder->connect_signals_full(sub {
  200.       my ($builder,
  201.           $object,
  202.           $signal_name,
  203.           $handler_name,
  204.           $connect_object,
  205.           $flags) = @_;
  206.  
  207.       return unless exists $handlers{$handler_name};
  208.  
  209.       _do_connect ($object, $signal_name, $user_data, $connect_object,
  210.                    $flags, $handlers{$handler_name});
  211.     });
  212.   }
  213. }
  214.  
  215. package Gtk2;
  216.  
  217. 1;
  218. __END__
  219. # documentation is a good thing.
  220.  
  221. =head1 NAME
  222.  
  223. Gtk2 - Perl interface to the 2.x series of the Gimp Toolkit library
  224.  
  225. =head1 SYNOPSIS
  226.  
  227.   use Gtk2 -init;
  228.   # Gtk2->init; works if you didn't use -init on use
  229.   my $window = Gtk2::Window->new ('toplevel');
  230.   my $button = Gtk2::Button->new ('Quit');
  231.   $button->signal_connect (clicked => sub { Gtk2->main_quit });
  232.   $window->add ($button);
  233.   $window->show_all;
  234.   Gtk2->main;
  235.  
  236. =head1 ABSTRACT
  237.  
  238. Perl bindings to the 2.x series of the Gtk+ widget set.  This module
  239. allows you to write graphical user interfaces in a Perlish and
  240. object-oriented way, freeing you from the casting and memory management
  241. in C, yet remaining very close in spirit to original API.
  242.  
  243. =head1 DESCRIPTION
  244.  
  245. The Gtk2 module allows a Perl developer to use the Gtk+ graphical user
  246. interface library.  Find out more about Gtk+ at http://www.gtk.org.
  247.  
  248. The GTK+ Reference Manual is also a handy companion when writing Gtk
  249. programs in any language.  http://developer.gnome.org/doc/API/2.0/gtk/
  250. The Perl bindings follow the C API very closely, and the C reference
  251. documentation should be considered the canonical source.
  252.  
  253. To discuss gtk2-perl, ask questions and flame/praise the authors,
  254. join gtk-perl-list@gnome.org at lists.gnome.org.
  255.  
  256. Also have a look at the gtk2-perl website and sourceforge project page,
  257. http://gtk2-perl.sourceforge.net
  258.  
  259. =head1 INITIALIZATION
  260.  
  261.   use Gtk2 qw/-init/;
  262.   use Gtk2 qw/-init -threads-init/;
  263.  
  264. =over
  265.  
  266. =item -init
  267.  
  268. Equivalent to Gtk2->init, called to initialize GLIB and GTK+. Just about every
  269. Gtk2-Perl script should do "use Gtk2 -init"; This initialization should take
  270. place before using any other Gtk2 functions in your GUI applications. It will
  271. initialize everything needed to operate the toolkit and parses some standard
  272. command line options. @ARGV is adjusted accordingly so your own code will never
  273. see those standard arguments.
  274.  
  275. =item -threads-init
  276.  
  277. Equivalent to Gtk2::Gdk::Threads->init, called to initialze/enable gdk's thread
  278. safety mechanisms so that gdk can be accessed from multiple threads when used
  279. in conjunction with Gtk2::Gdk::Threads->enter and Gtk2::Gdk::Threads->leave. If
  280. invoked as Gtk2::Gdk::Threads->init it should be done before Gtk2->init is
  281. called, if done by "use Gtk2 -init -threads-init" order does not matter.
  282.  
  283. =back
  284.  
  285. =head1 EXPORTS
  286.  
  287. Gtk2 exports nothing by default, but some constants are available upon request.
  288.  
  289. =over
  290.  
  291. =item Tag: constants
  292.  
  293.   GTK_PRIORITY_RESIZE
  294.   GDK_PRIORITY_EVENTS
  295.   GDK_PRIORITY_REDRAW
  296.   GDK_CURRENT_TIME
  297.  
  298. =back
  299.  
  300. See L<Glib> for other standard priority levels.
  301.  
  302. =head1 SEE ALSO
  303.  
  304. L<perl>(1), L<Glib>(3pm).
  305.  
  306. L<Gtk2::Gdk::Keysyms>(3pm) contains a hash of key codes, culled from
  307. gdk/gdkkeysyms.h
  308.  
  309. L<Gtk2::api>(3pm) describes how to map the C API into Perl, and some of the
  310. important differences in the Perl bindings.
  311.  
  312. L<Gtk2::Helper>(3pm) contains stuff that makes writing Gtk2 programs
  313. a little easier.
  314.  
  315. L<Gtk2::SimpleList>(3pm) makes the GtkListStore and GtkTreeModel a I<lot>
  316. easier to use.
  317.  
  318. L<Gtk2::Pango>(3pm) exports various little-used but important constants you
  319. may need to work with pango directly.
  320.  
  321. L<Gtk2::index>(3pm) lists the autogenerated api documentation pod files
  322. for Gtk2.
  323.  
  324. Gtk2 also provides code to make it relatively painless to create Perl
  325. wrappers for other GLib/Gtk-based libraries.  See L<Gtk2::CodeGen>,
  326. L<ExtUtils::PkgConfig>, and L<ExtUtils::Depends>.  If you're writing bindings,
  327. you'll probably also be interested in L<Gtk2::devel>, which is a supplement
  328. to L<Glib::devel> and L<Glib::xsapi>.  The Binding Howto, at
  329. http://gtk2-perl.sourceforge.net/doc/binding_howto.pod.html, ties it all
  330. together.
  331.  
  332. =head1 AUTHORS
  333.  
  334. The gtk2-perl team:
  335.  
  336.  muppet <scott at asofyet dot org>
  337.  Ross McFarland <rwmcfa1 at neces dot com>
  338.  Torsten Schoenfeld <kaffeetisch at web dot de>
  339.  Marc Lehmann <pcg at goof dot com>
  340.  Goeran Thyni <gthyni at kirra dot net>
  341.  Joern Reder <joern at zyn dot de>
  342.  Chas Owens <alas at wilma dot widomaker dot com>
  343.  Guillaume Cottenceau <gc at mandrakesoft dot com>
  344.  
  345. =head1 COPYRIGHT AND LICENSE
  346.  
  347. Copyright 2003-2008 by the gtk2-perl team.
  348.  
  349. This library is free software; you can redistribute it and/or
  350. modify it under the terms of the GNU Library General Public
  351. License as published by the Free Software Foundation; either
  352. version 2 of the License, or (at your option) any later version.
  353.  
  354. This library is distributed in the hope that it will be useful,
  355. but WITHOUT ANY WARRANTY; without even the implied warranty of
  356. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  357. Library General Public License for more details.
  358.  
  359. You should have received a copy of the GNU Library General Public
  360. License along with this library; if not, write to the
  361. Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  362. Boston, MA  02111-1307  USA.
  363.  
  364. =cut
  365.