X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=examples%2Fhildon-stackable-window-example.c;h=5991d975bb82d4fa6da6041e801f1c673f108b85;hb=76647632fc1c5e345216bec8a314c49c7a4dc1fe;hp=09367f26695eae9ec15b176914d2ba99eacb6ac0;hpb=8a95e38835d478bf3d24ee0b6e8dcd6b5175580f;p=hildon diff --git a/examples/hildon-stackable-window-example.c b/examples/hildon-stackable-window-example.c index 09367f2..5991d97 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 - * * 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,108 +20,189 @@ * */ -#include -#include -#include -#include -#include "hildon.h" +#include -#include -#include -#include +static gint global_stack_count = 1; static void -add_window (GtkWidget* w); +add_window (GtkWidget *button, + HildonStackableWindow *parent); static void -detach_window (GtkWidget* w) -{ - HildonProgram *program = hildon_program_get_instance (); - hildon_program_remove_window (program, HILDON_WINDOW (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++; + /* Marked up window title */ + text = g_strdup_printf ("Stack number %d - window %d", stack_number, win_number); + hildon_window_set_markup (HILDON_WINDOW (window), text); + g_free (text); - 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); - - if (!ismain) - { - GtkWidget *detach, *back; - detach = GTK_WIDGET (gtk_button_new_with_label ("Detach")); - gtk_box_pack_end (GTK_BOX (hbbox), detach, FALSE, FALSE, 0); + gtk_container_set_border_width (GTK_CONTAINER (window), 6); + gtk_container_add (GTK_CONTAINER (window), vbox); + gtk_widget_show_all (vbox); - g_signal_connect_swapped (G_OBJECT (detach), "clicked", - G_CALLBACK (detach_window), - HILDON_STACKABLE_WINDOW (window)); + return window; +} - back = GTK_WIDGET (gtk_button_new_with_label ("Back to root")); - gtk_box_pack_end (GTK_BOX (hbbox), back, FALSE, FALSE, 0); +static void +add_window (GtkWidget *button, + HildonStackableWindow *parent) +{ + HildonWindowStack *stack = NULL; + GtkWidget *window; - g_signal_connect_swapped (G_OBJECT (back), "clicked", - G_CALLBACK (hildon_program_go_to_root_window), - hildon_program_get_instance ()); + if (parent) { + stack = hildon_stackable_window_get_stack (parent); + } else { + stack = hildon_window_stack_new (); } - return window; + window = new_window (parent); + + if (!stack) { + stack = hildon_window_stack_get_default (); + } + hildon_window_stack_push_1 (stack, HILDON_STACKABLE_WINDOW (window)); } static void -add_window (GtkWidget *w) +push_windows (GtkWidget *button, + GtkSpinButton *spin) { - GtkWidget *window = new_window (FALSE); - HildonProgram *program = hildon_program_get_instance (); + 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); +} - hildon_program_add_window (program, HILDON_WINDOW (window)); +static void +pop_windows (GtkWidget *button, + GtkSpinButton *spin) +{ + HildonWindowStack *stack = NULL; + HildonStackableWindow *win; + gint nwindows = gtk_spin_button_get_value_as_int (spin); - gtk_widget_show_all (window); + win = HILDON_STACKABLE_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (spin))); + stack = hildon_stackable_window_get_stack (win); - return; + hildon_window_stack_pop (stack, nwindows, NULL); } int -main (int argc, - char **args) +main (int argc, + char **argv) { - HildonProgram *program; GtkWidget *window; - gtk_init (&argc, &args); + hildon_gtk_init (&argc, &argv); - g_set_application_name ("stack"); + g_set_application_name ("hildon-stackable-window-example"); - program = hildon_program_get_instance (); - window = new_window (TRUE); - hildon_program_add_window (program, HILDON_WINDOW (window)); + 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 ();