2008-08-29 Alberto Garcia <agarcia@igalia.com>
authorAlberto Garcia <agarcia@igalia.com>
Fri, 29 Aug 2008 14:43:04 +0000 (14:43 +0000)
committerAlberto Garcia <agarcia@igalia.com>
Fri, 29 Aug 2008 14:43:04 +0000 (14:43 +0000)
* examples/Makefile.am
* examples/hildon-edit-toolbar-example.c: Example of the
HildonEditToolbar widget.

ChangeLog
examples/Makefile.am
examples/hildon-edit-toolbar-example.c [new file with mode: 0644]

index 34ba304..c518866 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2008-08-29  Alberto Garcia  <agarcia@igalia.com>
+
+       * examples/Makefile.am
+       * examples/hildon-edit-toolbar-example.c: Example of the
+       HildonEditToolbar widget.
+
 2008-08-29  Claudio Saavedra  <csaavedra@igalia.com>
 
        * configure.ac: postrelease version bump.
index 8593819..081c16f 100644 (file)
@@ -36,6 +36,7 @@ noinst_PROGRAMS                               = hildon-window-example                         \
                                          hildon-finger-example                         \
                                          hildon-seekbar-example                        \
                                          hildon-find-toolbar-example                   \
+                                         hildon-edit-toolbar-example                   \
                                          hildon-wizard-dialog-example                  \
                                          hildon-hvolumebar-timer-example               \
                                          hildon-toolbar-seekbar-example                \
@@ -83,6 +84,11 @@ hildon_find_toolbar_example_LDADD    = $(HILDON_OBJ_LIBS)
 hildon_find_toolbar_example_CFLAGS     = $(HILDON_OBJ_CFLAGS)
 hildon_find_toolbar_example_SOURCES    = hildon-find-toolbar-example.c
 
+# Hildon edit toolbar
+hildon_edit_toolbar_example_LDADD      = $(HILDON_OBJ_LIBS)
+hildon_edit_toolbar_example_CFLAGS     = $(HILDON_OBJ_CFLAGS)
+hildon_edit_toolbar_example_SOURCES    = hildon-edit-toolbar-example.c
+
 # Hildon seekbar
 hildon_seekbar_example_LDADD           = $(HILDON_OBJ_LIBS)
 hildon_seekbar_example_CFLAGS          = $(HILDON_OBJ_CFLAGS)
diff --git a/examples/hildon-edit-toolbar-example.c b/examples/hildon-edit-toolbar-example.c
new file mode 100644 (file)
index 0000000..58e6886
--- /dev/null
@@ -0,0 +1,199 @@
+/*
+ * This file is a part of hildon examples
+ *
+ * Copyright (C) 2008 Nokia Corporation, all rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * as published by the Free Software Foundation; 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ *
+ */
+
+#include <gtk/gtk.h>
+#include <hildon.h>
+
+typedef enum
+{
+  NORMAL_MODE,
+  EDIT_MODE
+} TreeViewMode;
+
+
+static GtkTreeModel *
+get_model                                       (void)
+{
+  int i;
+  static GtkListStore *store = NULL;
+
+  if (store != NULL)
+    return GTK_TREE_MODEL (store);
+
+  store = gtk_list_store_new (1, G_TYPE_STRING);
+
+  for (i = 0; i < 50; i++)
+    {
+      gchar *str;
+
+      str = g_strdup_printf ("\nRow %d\n", i);
+      gtk_list_store_insert_with_values (store, NULL, i, 0, str, -1);
+      g_free (str);
+    }
+
+  return GTK_TREE_MODEL (store);
+}
+
+static GtkWidget *
+create_icon_view                                (TreeViewMode  tvmode)
+{
+  GtkWidget *icon_view;
+  GtkTreeModel *model;
+  GtkCellRenderer *renderer;
+
+  if (tvmode == NORMAL_MODE)
+    {
+      icon_view = hildon_gtk_icon_view_new (HILDON_UI_MODE_NORMAL);
+    }
+  else
+    {
+      icon_view = hildon_gtk_icon_view_new (HILDON_UI_MODE_EDIT);
+      gtk_icon_view_set_selection_mode (GTK_ICON_VIEW (icon_view),
+                                        GTK_SELECTION_MULTIPLE);
+    }
+
+  model = get_model ();
+  gtk_icon_view_set_model (GTK_ICON_VIEW (icon_view), model);
+
+  renderer = gtk_cell_renderer_pixbuf_new ();
+  g_object_set (renderer, "stock-id", GTK_STOCK_NEW, NULL);
+  gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), renderer, TRUE);
+
+  renderer = gtk_cell_renderer_text_new ();
+  gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (icon_view), renderer, FALSE);
+  gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (icon_view), renderer, "text", 0, NULL);
+
+  return icon_view;
+}
+
+static void
+delete_button_clicked                           (GtkButton   *button,
+                                                 GtkIconView *iconview)
+{
+  GtkTreeModel *model;
+  GList *items, *iter, *refs;
+  GtkWidget *window;
+
+  items = gtk_icon_view_get_selected_items (iconview);
+  model = gtk_icon_view_get_model (iconview);
+  refs = NULL;
+
+  /* Get row references for all selected items */
+  for (iter = items; iter != NULL; iter = iter->next)
+    {
+      GtkTreePath *path = (GtkTreePath *) iter->data;
+      GtkTreeRowReference *ref = gtk_tree_row_reference_new (model, path);
+      refs = g_list_prepend (refs, gtk_tree_row_reference_copy (ref));
+      gtk_tree_row_reference_free (ref);
+    }
+
+  g_list_foreach (items, (GFunc) gtk_tree_path_free, NULL);
+  g_list_free (items);
+
+  /* Remove all selected items from the model */
+  for (iter = refs; iter != NULL; iter = iter->next)
+    {
+      GtkTreeIter treeiter;
+      GtkTreeRowReference *ref = (GtkTreeRowReference *) iter->data;
+      GtkTreePath *path = gtk_tree_row_reference_get_path (ref);
+      gtk_tree_model_get_iter (model, &treeiter, path);
+      gtk_list_store_remove (GTK_LIST_STORE (model), &treeiter);
+    }
+
+  g_list_foreach (refs, (GFunc) gtk_tree_row_reference_free, NULL);
+  g_list_free (refs);
+
+  /* After removing the items, close the window */
+  window = gtk_widget_get_toplevel (GTK_WIDGET (iconview));
+  gtk_widget_destroy (window);
+}
+
+static void
+edit_window                                     (void)
+{
+  GtkWidget *window;
+  GtkWidget *iconview;
+  GtkWidget *vbox;
+  GtkWidget *toolbar;
+  GtkWidget *area;
+
+  window = hildon_stackable_window_new ();
+  gtk_container_set_border_width (GTK_CONTAINER (window), 6);
+
+  vbox = gtk_vbox_new (FALSE, 10);
+  toolbar = hildon_edit_toolbar_new_with_text ("Choose items to delete", "Delete");
+  area = hildon_pannable_area_new ();
+  iconview = create_icon_view (EDIT_MODE);
+
+  gtk_container_add (GTK_CONTAINER (area), iconview);
+  gtk_box_pack_start (GTK_BOX (vbox), toolbar, FALSE, FALSE, 0);
+  gtk_box_pack_start (GTK_BOX (vbox), area, TRUE, TRUE, 0);
+
+  gtk_container_add (GTK_CONTAINER (window), vbox);
+
+  g_signal_connect (toolbar, "button-clicked", G_CALLBACK (delete_button_clicked), iconview);
+  g_signal_connect_swapped (toolbar, "arrow-clicked", G_CALLBACK (gtk_widget_destroy), window);
+
+  gtk_widget_show_all (window);
+  gtk_window_fullscreen (GTK_WINDOW (window));
+}
+
+int
+main                                            (int    argc,
+                                                 char **argv)
+{
+  GtkWidget *window;
+  GtkWidget *iconview;
+  GtkWidget *vbox;
+  GtkWidget *button;
+  GtkWidget *area;
+
+  gtk_init (&argc, &argv);
+
+  gtk_rc_parse_string ("style \"fremantle-widget\" {\n"
+                       "  GtkWidget::hildon-mode = 1\n"
+                       "} class \"GtkIconView\" style \"fremantle-widget\"");
+
+  window = hildon_stackable_window_new ();
+  g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
+  gtk_container_set_border_width (GTK_CONTAINER (window), 6);
+
+  vbox = gtk_vbox_new (FALSE, 10);
+  area = hildon_pannable_area_new ();
+  iconview = create_icon_view (NORMAL_MODE);
+  button = hildon_gtk_button_new (HILDON_SIZE_AUTO_WIDTH | HILDON_SIZE_FINGER_HEIGHT);
+  gtk_button_set_label (GTK_BUTTON (button), "Delete some items");
+
+  gtk_container_add (GTK_CONTAINER (area), iconview);
+  gtk_box_pack_start (GTK_BOX (vbox), area, TRUE, TRUE, 0);
+  gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
+
+  gtk_container_add (GTK_CONTAINER (window), vbox);
+
+  g_signal_connect (button, "clicked", G_CALLBACK (edit_window), NULL);
+
+  gtk_widget_show_all (window);
+
+  gtk_main ();
+
+  return 0;
+}