diff options
author | Alberto Garcia <agarcia@igalia.com> | 2008-11-25 14:31:06 +0000 |
---|---|---|
committer | Alberto Garcia <agarcia@igalia.com> | 2008-11-25 14:31:06 +0000 |
commit | 8c908e27d527aa6feed0b15b5f2a3b8487d10033 (patch) | |
tree | 058aa6355fe96861e52b127a8e86b91e8a3166b5 /examples | |
parent | db9685e21af93630b100473c49d066de0ad3691f (diff) |
2008-11-25 Alberto Garcia <agarcia@igalia.com>
* doc/hildon-docs.sgml
* doc/hildon.types
* src/Makefile.am
* src/hildon.h
* src/hildon-window-stack-private.h
* src/hildon-window-stack.h
* src/hildon-window-stack.c:
New HildonWindowStack object, that adds support for multiple
stacks of windows per process.
* src/hildon-stackable-window-private.h
* src/hildon-stackable-window.h
* src/hildon-stackable-window.c (hildon_stackable_window_set_stack)
(hildon_stackable_window_get_stack, hildon_stackable_window_map)
(hildon_stackable_window_show, hildon_stackable_window_hide)
(hildon_stackable_window_class_init)
(hildon_stackable_window_init):
Use HildonWindowStack for stack management.
* src/hildon-program.c (hildon_program_pop_window_stack)
(hildon_program_peek_window_stack)
(hildon_program_go_to_root_window):
Add a fallback implementation to the deprecated functions using
HildonWindowStack.
* examples/hildon-stackable-window-example.c:
Use the new HildonWindowStack API.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/hildon-stackable-window-example.c | 188 |
1 files changed, 139 insertions, 49 deletions
diff --git a/examples/hildon-stackable-window-example.c b/examples/hildon-stackable-window-example.c index a6ac028..83aed2d 100644 --- a/examples/hildon-stackable-window-example.c +++ b/examples/hildon-stackable-window-example.c @@ -3,8 +3,6 @@ * * Copyright (C) 2008 Nokia Corporation, all rights reserved. * - * Author: Karl Lattimer <karl.lattimer@nokia.com> - * * 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 @@ -22,94 +20,186 @@ * */ -#include <stdio.h> -#include <stdlib.h> -#include <glib.h> -#include <gtk/gtk.h> #include "hildon.h" -#include <X11/X.h> -#include <X11/Xlib.h> -#include <X11/Xatom.h> +static gint global_stack_count = 1; + +static void +add_window (GtkWidget *button, + HildonStackableWindow *parent); static void -add_window (GtkWidget* w); +push_windows (GtkWidget *button, + GtkSpinButton *spin); + +static void +pop_windows (GtkWidget *button, + GtkSpinButton *spin); static GtkWidget* -new_window (gboolean ismain) +new_window (HildonStackableWindow *parent) { - GtkWidget *window, *hbbox, *add; - static int count = 0; - gchar* title; + GtkWidget *window, *hbbox, *vbox, *label, *add, *new; + GtkWidget *spin1hbox, *spin1label1, *spin1, *spin1label2, *pushbtn, *align1; + GtkWidget *spin2hbox, *spin2label1, *spin2, *spin2label2, *popbtn, *align2; + gint stack_number, win_number; + gchar *text; window = hildon_stackable_window_new (); - if (count == 0) - title = g_strdup ("main window"); - else - title = g_strdup_printf ("win%d", count); + if (parent) { + stack_number = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (parent), "stack-number")); + win_number = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (parent), "win-number")) + 1; + } else { + stack_number = global_stack_count++; + win_number = 1; + } + g_object_set_data (G_OBJECT (window), "stack-number", GINT_TO_POINTER (stack_number)); + g_object_set_data (G_OBJECT (window), "win-number", GINT_TO_POINTER (win_number)); - gtk_window_set_title (GTK_WINDOW (window), title); - g_free (title); + /* Window title */ + text = g_strdup_printf ("Stack number %d - window %d", stack_number, win_number); + gtk_window_set_title (GTK_WINDOW (window), text); + g_free (text); - count++; - - gtk_container_set_border_width (GTK_CONTAINER (window), 6); + /* Main label */ + text = g_strdup_printf ("Stack number %d\nWindow number %d", stack_number, win_number); + label = gtk_label_new (text); + g_free (text); hbbox = gtk_hbutton_box_new (); - gtk_container_add (GTK_CONTAINER (window), hbbox); - add = gtk_button_new_with_label ("Add a window"); + /* Button to push a window to the current stack */ + add = hildon_gtk_button_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH); + gtk_button_set_label (GTK_BUTTON (add), "Add a window to this stack"); gtk_box_pack_start (GTK_BOX (hbbox), add, FALSE, FALSE, 0); + g_signal_connect (G_OBJECT (add), "clicked", G_CALLBACK (add_window), window); + + /* Button to create a new stack */ + new = hildon_gtk_button_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH); + gtk_button_set_label (GTK_BUTTON (new), "Add a window to a new stack"); + gtk_box_pack_start (GTK_BOX (hbbox), new, FALSE, FALSE, 0); + g_signal_connect (G_OBJECT (new), "clicked", G_CALLBACK (add_window), NULL); + + /* Spinbox and button to push many windows */ + spin1hbox = gtk_hbox_new (FALSE, 0); + spin1label1 = gtk_label_new ("Push"); + spin1 = gtk_spin_button_new (GTK_ADJUSTMENT (gtk_adjustment_new (2, 2, 5, 1, 1, 1)), 1, 0); + gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spin1), TRUE); + spin1label2 = gtk_label_new ("windows"); + pushbtn = hildon_gtk_button_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH); + gtk_button_set_label (GTK_BUTTON (pushbtn), "Push windows"); + gtk_box_pack_start (GTK_BOX (spin1hbox), spin1label1, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (spin1hbox), spin1, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (spin1hbox), spin1label2, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (spin1hbox), pushbtn, FALSE, FALSE, 10); + align1 = gtk_alignment_new (0.5, 0.5, 0, 0); + gtk_container_add (GTK_CONTAINER (align1), spin1hbox); + g_signal_connect (G_OBJECT (pushbtn), "clicked", G_CALLBACK (push_windows), spin1); + + /* Spinbox and button to pop many windows */ + spin2hbox = gtk_hbox_new (FALSE, 0); + spin2label1 = gtk_label_new ("Pop"); + spin2 = gtk_spin_button_new (GTK_ADJUSTMENT (gtk_adjustment_new (2, 2, 5, 1, 1, 1)), 1, 0); + gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spin2), TRUE); + spin2label2 = gtk_label_new ("windows"); + popbtn = hildon_gtk_button_new (HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH); + gtk_button_set_label (GTK_BUTTON (popbtn), "Pop windows"); + gtk_box_pack_start (GTK_BOX (spin2hbox), spin2label1, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (spin2hbox), spin2, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (spin2hbox), spin2label2, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX (spin2hbox), popbtn, FALSE, FALSE, 10); + align2 = gtk_alignment_new (0.5, 0.5, 0, 0); + gtk_container_add (GTK_CONTAINER (align2), spin2hbox); + g_signal_connect (G_OBJECT (popbtn), "clicked", G_CALLBACK (pop_windows), spin2); + + vbox = gtk_vbox_new (FALSE, 0); + gtk_box_pack_start (GTK_BOX (vbox), label, TRUE, TRUE, 0); + gtk_box_pack_start (GTK_BOX (vbox), hbbox, FALSE, FALSE, 10); + gtk_box_pack_start (GTK_BOX (vbox), align1, FALSE, FALSE, 10); + gtk_box_pack_start (GTK_BOX (vbox), align2, FALSE, FALSE, 10); - g_signal_connect (G_OBJECT (add), "clicked", G_CALLBACK (add_window), NULL); + gtk_container_set_border_width (GTK_CONTAINER (window), 6); + gtk_container_add (GTK_CONTAINER (window), vbox); + gtk_widget_show_all (vbox); - if (!ismain) - { - GtkWidget *detach, *back; - detach = GTK_WIDGET (gtk_button_new_with_label ("Destroy")); - gtk_box_pack_end (GTK_BOX (hbbox), detach, FALSE, FALSE, 0); + return window; +} - g_signal_connect_swapped (G_OBJECT (detach), "clicked", - G_CALLBACK (gtk_widget_destroy), - HILDON_STACKABLE_WINDOW (window)); +static void +add_window (GtkWidget *button, + HildonStackableWindow *parent) +{ + HildonWindowStack *stack = NULL; + GtkWidget *window; + + if (parent) { + stack = hildon_stackable_window_get_stack (parent); + } else { + stack = hildon_window_stack_new (); + } - back = GTK_WIDGET (gtk_button_new_with_label ("Back to root")); - gtk_box_pack_end (GTK_BOX (hbbox), back, FALSE, FALSE, 0); + window = new_window (parent); - g_signal_connect_swapped (G_OBJECT (back), "clicked", - G_CALLBACK (hildon_program_go_to_root_window), - hildon_program_get_instance ()); + if (!stack) { + stack = hildon_window_stack_get_default (); } + hildon_window_stack_push_1 (stack, HILDON_STACKABLE_WINDOW (window)); - return window; + return; +} + +static void +push_windows (GtkWidget *button, + GtkSpinButton *spin) +{ + GList *l = NULL; + HildonWindowStack *stack = NULL; + HildonStackableWindow *parent; + gint nwindows = gtk_spin_button_get_value_as_int (spin); + + parent = HILDON_STACKABLE_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (spin))); + stack = hildon_stackable_window_get_stack (parent); + + while (nwindows > 0) { + parent = HILDON_STACKABLE_WINDOW (new_window (parent)); + l = g_list_append (l, parent); + nwindows--; + } + hildon_window_stack_push_list (stack, l); + g_list_free (l); } static void -add_window (GtkWidget *w) +pop_windows (GtkWidget *button, + GtkSpinButton *spin) { - GtkWidget *window = new_window (FALSE); - gtk_widget_show_all (window); + HildonWindowStack *stack = NULL; + HildonStackableWindow *win; + gint nwindows = gtk_spin_button_get_value_as_int (spin); - return; + win = HILDON_STACKABLE_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (spin))); + stack = hildon_stackable_window_get_stack (win); + + hildon_window_stack_pop (stack, nwindows, NULL); } int -main (int argc, +main (int argc, char **argv) { GtkWidget *window; hildon_gtk_init (&argc, &argv); - g_set_application_name ("stack"); + g_set_application_name ("hildon-stackable-window-example"); - window = new_window (TRUE); + window = new_window (NULL); - g_signal_connect (G_OBJECT (window), "delete_event", + g_signal_connect (G_OBJECT (window), "destroy", G_CALLBACK (gtk_main_quit), NULL); - gtk_widget_show_all (GTK_WIDGET (window)); + gtk_widget_show (window); gtk_main (); |