[perl-Gtk3] Add more overrides for Gtk3::TreeView and friends



commit 3ee0664467da85b81516760ae8dd5c7f1e4b3b59
Author: Torsten SchÃnfeld <kaffeetisch gmx de>
Date:   Wed Jan 30 00:23:51 2013 +0100

    Add more overrides for Gtk3::TreeView and friends

 NEWS                      |    1 +
 lib/Gtk3.pm               |   47 +++++++++++++++++++++++++++++--
 t/overrides.t             |   67 +++++++++++++++++++++++++++++++++++++++++++-
 t/zz-GtkCellLayoutIface.t |    3 +-
 4 files changed, 112 insertions(+), 6 deletions(-)
---
diff --git a/NEWS b/NEWS
index 1427cd5..59d5d06 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,7 @@
 * Add overrides for Gtk3::TextBuffer.
 * Add overrides for Gtk3::ListStore's and Gtk3::TreeStore's
   insert_with_values().
+* Add more overrides for Gtk3::TreeView and friends.
 * Add overrides for various button constructors.
 * Add an override for Gtk3::main_level.
 * Add overrides for Gtk3::Gdk::RGBA.
diff --git a/lib/Gtk3.pm b/lib/Gtk3.pm
index 36f5e0b..a7baa74 100644
--- a/lib/Gtk3.pm
+++ b/lib/Gtk3.pm
@@ -41,6 +41,7 @@ my @_GTK_FLATTEN_ARRAY_REF_RETURN_FOR = qw/
   Gtk3::Container::get_children
   Gtk3::Stock::list_ids
   Gtk3::TreePath::get_indices
+  Gtk3::TreeView::get_columns
   Gtk3::UIManager::get_action_groups
   Gtk3::UIManager::get_toplevels
   Gtk3::Window::list_toplevels
@@ -57,6 +58,11 @@ my @_GTK_HANDLE_SENTINEL_BOOLEAN_FOR = qw/
   Gtk3::TreeModelFilter::convert_child_iter_to_iter
   Gtk3::TreeModelSort::convert_child_iter_to_iter
   Gtk3::TreeSelection::get_selected
+  Gtk3::TreeView::get_dest_row_at_pos
+  Gtk3::TreeView::get_path_at_pos
+  Gtk3::TreeView::get_tooltip_context
+  Gtk3::TreeView::get_visible_range
+  Gtk3::TreeViewColumn::cell_get_position
 /;
 my @_GTK_USE_GENERIC_SIGNAL_MARSHALLER_FOR = (
   ['Gtk3::Editable', 'insert-text'],
@@ -1107,17 +1113,52 @@ sub Gtk3::TreeView::new {
     $_GTK_BASENAME, 'TreeView', $method, @_);
 }
 
+sub Gtk3::TreeView::insert_column_with_attributes {
+  my ($tree_view, $position, $title, $cell, @rest) = @_;
+  if (@rest % 2) {
+    croak ('Usage: $tree_view->insert_column_with_attributes (position, title, cell_renderer, attr1 => col1, ...)');
+  }
+  my $column = Gtk3::TreeViewColumn->new;
+  my $n = $tree_view->insert_column ($column, $position);
+  $column->set_title ($title);
+  $column->pack_start ($cell, Glib::TRUE);
+  for (my $i = 0; $i < @rest; $i += 2) {
+    $column->add_attribute ($cell, $rest[$i], $rest[$i+1]);
+  }
+  return $n;
+}
+
 sub Gtk3::TreeViewColumn::new_with_attributes {
-  my ($class, $title, $cell, %attr_to_column) = @_;
+  my ($class, $title, $cell, @rest) = @_;
+  if (@rest % 2) {
+    croak ('Usage: Gtk3::TreeViewColumn->new_with_attributes (title, cell_renderer, attr1 => col1, ...)');
+  }
   my $object = $class->new;
   $object->set_title ($title);
   $object->pack_start ($cell, Glib::TRUE);
-  foreach my $attr (keys %attr_to_column) {
-    $object->add_attribute ($cell, $attr, $attr_to_column{$attr});
+  for (my $i = 0; $i < @rest; $i += 2) {
+    $object->add_attribute ($cell, $rest[$i], $rest[$i+1]);
   }
   return $object;
 }
 
+# Gtk3::TreeViewColumn::set_attributes and Gtk3::CellLayout::set_attributes
+{
+  no strict 'refs';
+  foreach my $package (qw/TreeViewColumn CellLayout/) {
+    *{'Gtk3::' . $package . '::set_attributes'} = sub {
+      my ($object, $cell, @rest) = @_;
+      if (@rest % 2) {
+        croak ('Usage: $object->set_attributes (cell_renderer, attr1 => col1, ...)');
+      }
+      $object->clear_attributes ($cell);
+      for (my $i = 0; $i < @rest; $i += 2) {
+        $object->add_attribute ($cell, $rest[$i], $rest[$i+1]);
+      }
+    }
+  }
+}
+
 sub Gtk3::UIManager::add_ui_from_string {
   my ($manager, $string) = @_;
   return Glib::Object::Introspection->invoke (
diff --git a/t/overrides.t b/t/overrides.t
index 06d26d1..e9d018c 100644
--- a/t/overrides.t
+++ b/t/overrides.t
@@ -7,7 +7,7 @@ use warnings;
 use utf8;
 use Encode;
 
-plan tests => 131;
+plan tests => 139;
 
 # Gtk3::CHECK_VERSION and check_version
 {
@@ -381,7 +381,7 @@ SKIP: {
 
 # Gtk3::TreeSelection::get_selected
 SKIP: {
-  skip 'tree model ctors not properly supported', 2
+  skip 'tree model ctors not properly supported', 3
     unless check_gi_version(1, 29, 17);
 
   my $model = Gtk3::ListStore->new ('Glib::String');
@@ -392,6 +392,69 @@ SKIP: {
   my ($sel_model, $sel_iter) = $selection->get_selected;
   is ($sel_model, $model);
   isa_ok ($sel_iter, 'Gtk3::TreeIter');
+  $sel_iter = $selection->get_selected;
+  isa_ok ($sel_iter, 'Gtk3::TreeIter');
+}
+
+# Gtk3::TreeView::insert_column_with_attributes, get_dest_row_at_pos,
+# get_path_at_pos, get_tooltip_context, get_visible_range
+SKIP: {
+  skip 'tree model ctors not properly supported', 5
+    unless check_gi_version(1, 29, 17);
+
+  my $model = Gtk3::ListStore->new ('Glib::String');
+  $model->insert_with_values (-1, 0 => 'Test string');
+
+  my $view = Gtk3::TreeView->new ($model);
+  $view->insert_column_with_attributes (-1, 'String',
+                                        Gtk3::CellRendererText->new,
+                                        text => 0);
+  my $column = $view->get_column (0);
+  is ($column->get_title, 'String');
+  is_deeply ([$view->get_columns], [$column]);
+
+  my $window = Gtk3::Window->new;
+  $window->add ($view);
+  $window->show_all;
+
+  my @bin_pos = (0, 0);
+  my @widget_pos = $view->convert_bin_window_to_widget_coords (@bin_pos);
+  my @dest_stuff = $view->get_dest_row_at_pos (@widget_pos);
+  is (@dest_stuff, 2);
+  my @pos_stuff = $view->get_path_at_pos (@bin_pos);
+  is (@pos_stuff, 4);
+
+  my @tooltip_stuff = $view->get_tooltip_context (@widget_pos, Glib::TRUE);
+  is (@tooltip_stuff, 5);
+
+  # Nondeterministic:
+  my @vis_paths = $view->get_visible_range;
+  # is (@vis_paths, 2); # or sometimes 0
+}
+
+# Gtk3::TreeViewColumn::new_with_attributes, set_attributes, cell_get_position
+{
+  skip 'tree model ctors not properly supported', 2
+    unless check_gi_version(1, 29, 17);
+
+  my $model = Gtk3::ListStore->new ('Glib::String');
+  $model->insert_with_values (-1, 0 => 'Test string');
+
+  my $renderer = Gtk3::CellRendererText->new;
+  my $column = Gtk3::TreeViewColumn->new_with_attributes (
+    'String', $renderer, text => 0);
+  is ($column->get_title, 'String');
+  $column->set_attributes ($renderer, text => 0);
+
+  my $view = Gtk3::TreeView->new ($model);
+  $view->insert_column ($column, -1);
+
+  my $window = Gtk3::Window->new;
+  $window->add ($view);
+  $window->show_all;
+
+  my @cell_stuff = $column->cell_get_position ($renderer);
+  is (@cell_stuff, 2);
 }
 
 # Gtk3::UIManager
diff --git a/t/zz-GtkCellLayoutIface.t b/t/zz-GtkCellLayoutIface.t
index d445fc2..d073df1 100644
--- a/t/zz-GtkCellLayoutIface.t
+++ b/t/zz-GtkCellLayoutIface.t
@@ -6,7 +6,7 @@ use strict;
 use warnings;
 use Glib ':constants';
 
-plan tests => 29;
+plan tests => 35;
 
 my $cell = Gtk3::CellRendererText->new ();
 
@@ -16,6 +16,7 @@ $layout->pack_end ($cell, FALSE);
 $layout->clear ();
 $layout->add_attribute ($cell, text => 42);
 $layout->clear_attributes ($cell);
+$layout->set_attributes ($cell, text => 42);
 $layout->reorder ($cell, 42);
 
 my @cells = $layout->get_cells ();



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]