]> Pileus Git - ~andy/gtk/blobdiff - tests/testiconview.c
stylecontext: Do invalidation on first resize container
[~andy/gtk] / tests / testiconview.c
index 1ef1464cfef832072b8b89fbd691e245398571a6..ea1af1a1d81b349a4ed9d4be49d21a7f0db80782 100644 (file)
@@ -12,9 +12,7 @@
  * 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.
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
  */
 
 #include <gtk/gtk.h>
@@ -34,6 +32,7 @@ fill_model (GtkTreeModel *model)
   char *str, *str2;
   GtkTreeIter iter;
   GtkListStore *store = GTK_LIST_STORE (model);
+  gint32 size;
   
   pixbuf = gdk_pixbuf_new_from_file ("gnome-textfile.png", NULL);
 
@@ -51,11 +50,15 @@ fill_model (GtkTreeModel *model)
 
   while (i < NUMBER_OF_ITEMS - 1)
     {
+      GdkPixbuf *pb;
+      size = g_random_int_range (20, 70);
+      pb = gdk_pixbuf_scale_simple (pixbuf, size, size, GDK_INTERP_NEAREST);
+
       str = g_strdup_printf ("Icon %d", i);
       str2 = g_strdup_printf ("Icon <b>%d</b>", i);    
       gtk_list_store_prepend (store, &iter);
       gtk_list_store_set (store, &iter,
-                         0, pixbuf,
+                         0, pb,
                          1, str,
                          2, i,
                          3, str2,
@@ -329,14 +332,26 @@ static void
 do_popup_menu (GtkWidget      *icon_list, 
               GdkEventButton *event)
 {
+  GtkIconView *icon_view = GTK_ICON_VIEW (icon_list); 
   GtkWidget *menu;
   GtkWidget *menuitem;
-  GtkTreePath *path;
+  GtkTreePath *path = NULL;
   int button, event_time;
   ItemData *data;
+  GList *list;
 
-  path = gtk_icon_view_get_path_at_pos (GTK_ICON_VIEW (icon_list), 
-                                        event->x, event->y);
+  if (event)
+    path = gtk_icon_view_get_path_at_pos (icon_view, event->x, event->y);
+  else
+    {
+      list = gtk_icon_view_get_selected_items (icon_view);
+
+      if (list)
+        {
+          path = (GtkTreePath*)list->data;
+          g_list_free_full (list, (GDestroyNotify) gtk_tree_path_free);
+        }
+    }
 
   if (!path)
     return;
@@ -344,7 +359,7 @@ do_popup_menu (GtkWidget      *icon_list,
   menu = gtk_menu_new ();
 
   data = g_new0 (ItemData, 1);
-  data->icon_list = GTK_ICON_VIEW (icon_list);
+  data->icon_list = icon_view;
   data->path = path;
   g_object_set_data_full (G_OBJECT (menu), "item-path", data, (GDestroyNotify)free_item_data);
 
@@ -374,7 +389,8 @@ button_press_event_handler (GtkWidget      *widget,
                            GdkEventButton *event)
 {
   /* Ignore double-clicks and triple-clicks */
-  if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
+  if (gdk_event_triggers_context_menu ((GdkEvent *) event) &&
+      event->type == GDK_BUTTON_PRESS)
     {
       do_popup_menu (widget, event);
       return TRUE;
@@ -415,10 +431,10 @@ main (gint argc, gchar **argv)
   window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
   gtk_window_set_default_size (GTK_WINDOW (window), 700, 400);
 
-  vbox = gtk_vbox_new (FALSE, 0);
+  vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
   gtk_container_add (GTK_CONTAINER (window), vbox);
 
-  paned = gtk_hpaned_new ();
+  paned = gtk_paned_new (GTK_ORIENTATION_HORIZONTAL);
   gtk_box_pack_start (GTK_BOX (vbox), paned, TRUE, TRUE, 0);
 
   icon_list = gtk_icon_view_new ();
@@ -540,48 +556,48 @@ main (gint argc, gchar **argv)
 
   gtk_paned_add2 (GTK_PANED (paned), scrolled_window);
 
-  bbox = gtk_hbutton_box_new ();
+  bbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
   gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_START);
   gtk_box_pack_start (GTK_BOX (vbox), bbox, FALSE, FALSE, 0);
 
   button = gtk_button_new_with_label ("Add some");
   g_signal_connect (button, "clicked", G_CALLBACK (add_some), icon_list);
-  gtk_box_pack_start_defaults (GTK_BOX (bbox), button);
+  gtk_box_pack_start (GTK_BOX (bbox), button, TRUE, TRUE, 0);
 
   button = gtk_button_new_with_label ("Add many");
   g_signal_connect (button, "clicked", G_CALLBACK (add_many), icon_list);
-  gtk_box_pack_start_defaults (GTK_BOX (bbox), button);
+  gtk_box_pack_start (GTK_BOX (bbox), button, TRUE, TRUE, 0);
 
   button = gtk_button_new_with_label ("Add large");
   g_signal_connect (button, "clicked", G_CALLBACK (add_large), icon_list);
-  gtk_box_pack_start_defaults (GTK_BOX (bbox), button);
+  gtk_box_pack_start (GTK_BOX (bbox), button, TRUE, TRUE, 0);
 
   button = gtk_button_new_with_label ("Remove selected");
   g_signal_connect (button, "clicked", G_CALLBACK (foreach_selected_remove), icon_list);
-  gtk_box_pack_start_defaults (GTK_BOX (bbox), button);
+  gtk_box_pack_start (GTK_BOX (bbox), button, TRUE, TRUE, 0);
 
   button = gtk_button_new_with_label ("Swap");
   g_signal_connect (button, "clicked", G_CALLBACK (swap_rows), icon_list);
-  gtk_box_pack_start_defaults (GTK_BOX (bbox), button);
+  gtk_box_pack_start (GTK_BOX (bbox), button, TRUE, TRUE, 0);
 
-  bbox = gtk_hbutton_box_new ();
+  bbox = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
   gtk_button_box_set_layout (GTK_BUTTON_BOX (bbox), GTK_BUTTONBOX_START);
   gtk_box_pack_start (GTK_BOX (vbox), bbox, FALSE, FALSE, 0);
 
   button = gtk_button_new_with_label ("Select all");
   g_signal_connect (button, "clicked", G_CALLBACK (select_all), icon_list);
-  gtk_box_pack_start_defaults (GTK_BOX (bbox), button);
+  gtk_box_pack_start (GTK_BOX (bbox), button, TRUE, TRUE, 0);
 
   button = gtk_button_new_with_label ("Unselect all");
   g_signal_connect (button, "clicked", G_CALLBACK (unselect_all), icon_list);
-  gtk_box_pack_start_defaults (GTK_BOX (bbox), button);
-  
+  gtk_box_pack_start (GTK_BOX (bbox), button, TRUE, TRUE, 0);
+
   button = gtk_button_new_with_label ("Select nonexisting");
   g_signal_connect (button, "clicked", G_CALLBACK (select_nonexisting), icon_list);
-  gtk_box_pack_start_defaults (GTK_BOX (bbox), button);
+  gtk_box_pack_start (GTK_BOX (bbox), button, TRUE, TRUE, 0);
 
   icon_list = gtk_icon_view_new ();
-  
+
   scrolled_window = gtk_scrolled_window_new (NULL, NULL);
   gtk_container_add (GTK_CONTAINER (scrolled_window), icon_list);
   gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),