+/**
+ * hildon_program_pop_window_stack:
+ * @self: A #HildonProgram
+ *
+ * The #HildonProgram object maintains a list of stackable
+ * windows. Each time a #HildonStackableWindow is shown, it is
+ * automatically added to the top of the stack. Windows are removed
+ * from the stack when they are destroyed.
+ *
+ * This function removes the #HildonStackableWindow from the top of
+ * the stack and returns it. The window is automatically hidden, but
+ * not destroyed. If that window was visible and there are more
+ * windows left in the stack, the next one will be shown
+ * automatically.
+ *
+ * If the stack is empty, %NULL is returned.
+ *
+ * Returns: A #HildonStackableWindow, or %NULL.
+ */
+HildonStackableWindow *
+hildon_program_pop_window_stack (HildonProgram *self)
+{
+ HildonStackableWindow *top;
+
+ top = hildon_program_peek_window_stack (self);
+
+ if (top)
+ {
+ HildonStackableWindow *next;
+
+ /* Remove the window from the stack and get the next one */
+ _hildon_program_remove_from_stack (self, top);
+ next = hildon_program_peek_window_stack (self);
+
+ /* Hide the window just removed and show the next one if necessary */
+ if (GTK_WIDGET_VISIBLE (GTK_WIDGET (top)) && next != NULL);
+ gtk_widget_show (GTK_WIDGET (next));
+
+ gtk_widget_hide (GTK_WIDGET (top));
+ }
+
+ return top;
+}
+
+/**
+ * hildon_program_peek_window_stack:
+ * @self: A #HildonProgram
+ *
+ * The #HildonProgram object maintains a list of stackable
+ * windows. Each time a #HildonStackableWindow is shown, it is
+ * automatically added to the top of the stack. Windows are removed
+ * from the stack when they are destroyed.
+ *
+ * This function returns the #HildonStackableWindow from the top of
+ * the stack or %NULL if the stack is empty. The stack is never modified.
+ *
+ * Returns: A #HildonStackableWindow, or %NULL.
+ */
+HildonStackableWindow *
+hildon_program_peek_window_stack (HildonProgram *self)
+{
+ HildonStackableWindow *top = NULL;
+ HildonProgramPrivate *priv;
+
+ g_return_val_if_fail (HILDON_IS_PROGRAM (self), NULL);
+
+ priv = HILDON_PROGRAM_GET_PRIVATE (self);
+ g_assert (priv);
+
+ if (priv->window_stack != NULL)
+ top = HILDON_STACKABLE_WINDOW (priv->window_stack->data);
+
+ return top;
+}
+
+void G_GNUC_INTERNAL
+_hildon_program_add_to_stack (HildonProgram *self,
+ HildonStackableWindow *win)
+{
+ HildonProgramPrivate *priv;
+
+ g_return_if_fail (HILDON_IS_PROGRAM (self));
+ g_return_if_fail (HILDON_IS_STACKABLE_WINDOW (win));
+
+ priv = HILDON_PROGRAM_GET_PRIVATE (self);
+ g_assert (priv);
+
+ if (g_slist_find (priv->window_stack, win) == NULL)
+ {
+ priv->window_stack = g_slist_prepend (priv->window_stack, win);
+ }
+ else
+ {
+ g_critical ("%s: window already in the stack!", __FUNCTION__);
+ }
+
+}
+
+gboolean G_GNUC_INTERNAL
+_hildon_program_remove_from_stack (HildonProgram *self,
+ HildonStackableWindow *win)
+{
+ GSList *pos;
+ HildonProgramPrivate *priv;
+
+ g_return_val_if_fail (HILDON_IS_PROGRAM (self), FALSE);
+ g_return_val_if_fail (HILDON_IS_STACKABLE_WINDOW (win), FALSE);
+
+ priv = HILDON_PROGRAM_GET_PRIVATE (self);
+ g_assert (priv);
+
+ pos = g_slist_find (priv->window_stack, win);
+
+ if (pos != NULL)
+ priv->window_stack = g_slist_delete_link (priv->window_stack, pos);
+
+ return (pos != NULL);
+}
+