Adding a common menu example and a window menu example. Fixing the problem with menu...
authorMichael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
Thu, 8 Feb 2007 12:55:14 +0000 (12:55 +0000)
committerMichael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
Thu, 8 Feb 2007 12:55:14 +0000 (12:55 +0000)
ChangeLog.2
examples/Makefile.am
examples/hildon-window-cmn-menu-example.c [new file with mode: 0644]
examples/hildon-window-menu-example.c [new file with mode: 0644]
src/hildon-program.c
src/hildon-window.c

index 01029f2..001b9b5 100644 (file)
@@ -1,3 +1,18 @@
+2007-02-08  Michael Dominic Kostrzewa  <michael.kostrzewa@nokia.com> 
+
+       * examples/Makefile.am:
+       * examples/hildon-window-cmn-menu-example.c:
+       * examples/hildon-window-menu-example.c: Adding a common menu example
+       and a window menu example.
+
+       * src/hildon-program.c: Adding a note to the documentation about
+       HildonProgram reffing. Fixes MB#867. 
+
+       * src/hildon-window.c: Fixing the menu ref counting problem. Now
+       applications are NOT supposed to take care about menu destroying since
+       the HildonWindow handles that. Adding this to the documentation. Fixes
+       NB#46434.
+
 2007-02-07  Michael Dominic Kostrzewa  <michael.kostrzewa@nokia.com> 
 
        * src/hildon-program.c:
index 1cc760b..3bbeadc 100644 (file)
@@ -16,7 +16,9 @@ noinst_PROGRAMS                               = hildon-window-example                 \
                                          hildon-icon-sizes-example             \
                                          hildon-insensitive-example            \
                                          hildon-get-password-dialog-example    \
-                                         hildon-set-password-dialog-example
+                                         hildon-set-password-dialog-example    \
+                                         hildon-window-menu-example            \
+                                         hildon-window-cmn-menu-example
 
 # HIldon window
 hildon_window_example_LDADD            = $(HILDON_OBJ_LIBS)
@@ -98,4 +100,14 @@ hildon_set_password_dialog_example_LDADD    = $(HILDON_OBJ_LIBS)
 hildon_set_password_dialog_example_CFLAGS      = $(HILDON_OBJ_CFLAGS)
 hildon_set_password_dialog_example_SOURCES     = hildon-set-password-dialog-example.c
 
+# HIldon window menu example
+hildon_window_menu_example_LDADD       = $(HILDON_OBJ_LIBS)
+hildon_window_menu_example_CFLAGS      = $(HILDON_OBJ_CFLAGS)
+hildon_window_menu__example_SOURCES    = hildon-window-menu-example.c
+
+# HIldon window common menu example
+hildon_window_cmn_menu_example_LDADD   = $(HILDON_OBJ_LIBS)
+hildon_window_cmn_menu_example_CFLAGS  = $(HILDON_OBJ_CFLAGS)
+hildon_window_cmn_menu_example_SOURCES = hildon-window-cmn-menu-example.c
+
 endif
diff --git a/examples/hildon-window-cmn-menu-example.c b/examples/hildon-window-cmn-menu-example.c
new file mode 100644 (file)
index 0000000..7825a33
--- /dev/null
@@ -0,0 +1,56 @@
+/*
+ * This file is a part of hildon examples
+ *
+ * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved.
+ *
+ * Author: Michael Dominic Kostrzewa <michael.kostrzewa@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
+ * the License.
+ *
+ * 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                                        <stdio.h>
+#include                                        <stdlib.h>
+#include                                        <glib.h>
+#include                                        <gtk/gtk.h>
+#include                                        "hildon.h"
+
+int
+main                                            (int argc, 
+                                                 char **args)
+{
+    gtk_init (&argc, &args);
+    
+    HildonProgram *program = hildon_program_get_instance ();
+
+    GtkWidget *window = hildon_window_new ();
+    hildon_program_add_window (program, HILDON_WINDOW (window));
+
+    GtkMenu *menu = GTK_MENU (gtk_menu_new ());
+    GtkWidget *menu_item = gtk_menu_item_new_with_label ("Test common item");
+    gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
+
+    hildon_program_set_common_menu (program, menu);
+
+    g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (gtk_main_quit), NULL);
+    gtk_widget_show_all (GTK_WIDGET (window));
+    
+    gtk_main ();
+
+    return 0;
+}
+
+
diff --git a/examples/hildon-window-menu-example.c b/examples/hildon-window-menu-example.c
new file mode 100644 (file)
index 0000000..2cc68b2
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * This file is a part of hildon examples
+ *
+ * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved.
+ *
+ * Author: Michael Dominic Kostrzewa <michael.kostrzewa@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
+ * the License.
+ *
+ * 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                                        <stdio.h>
+#include                                        <stdlib.h>
+#include                                        <glib.h>
+#include                                        <gtk/gtk.h>
+#include                                        "hildon.h"
+
+int
+main                                            (int argc, 
+                                                 char **args)
+{
+    gtk_init (&argc, &args);
+    
+    HildonProgram *program = hildon_program_get_instance ();
+
+    GtkWidget *window = hildon_window_new ();
+    hildon_program_add_window (program, HILDON_WINDOW (window));
+
+    GtkMenu *menu = GTK_MENU (gtk_menu_new ());
+    GtkWidget *menu_item = gtk_menu_item_new_with_label ("Test item");
+    gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item);
+
+    hildon_window_set_menu (HILDON_WINDOW (window), menu);
+
+    g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (gtk_main_quit), NULL);
+    gtk_widget_show_all (GTK_WIDGET (window));
+    
+    gtk_main ();
+
+    return 0;
+}
index 5fdc689..b7ea2d3 100644 (file)
@@ -381,7 +381,8 @@ hildon_program_common_toolbar_topmost_window    (gpointer window,
  * hildon_program_get_instance:
  *
  * Return value: Returns the #HildonProgram for the current process.
- * The object is created on the first call.
+ * The object is created on the first call. Note that you're not supposed 
+ * to unref the returned object since it's not reffed in the first place.
  **/
 HildonProgram*
 hildon_program_get_instance                     (void)
index bbd16b0..bb63e57 100644 (file)
@@ -783,7 +783,7 @@ hildon_window_destroy                           (GtkObject *obj)
 
     while (menu_list)
     {
-        if (GTK_IS_MENU(menu_list->data))
+        if (GTK_IS_MENU (menu_list->data))
         {
             if (GTK_WIDGET_VISIBLE (GTK_WIDGET (menu_list->data)))
             {
@@ -791,6 +791,13 @@ hildon_window_destroy                           (GtkObject *obj)
                 gtk_menu_shell_deactivate (GTK_MENU_SHELL (menu_list->data));
             }
             gtk_menu_detach (GTK_MENU (menu_list->data));
+
+            /* Destroy it, but only if it's not a common menu */
+            if (priv->program && 
+                hildon_program_get_common_menu (priv->program) != menu_list->data) {
+                    g_object_unref (menu_list->data);
+                    gtk_object_destroy (GTK_OBJECT (menu_list->data));
+            }
         }
         menu_list = menu_list->next;
     }
@@ -1708,9 +1715,10 @@ hildon_window_remove_toolbar                    (HildonWindow *self,
  * hildon_window_get_menu:
  * @self : #HildonWindow
  * 
- * Gets the #GtMenu assigned to the #HildonAppview.
+ * Gets the #GtMenu assigned to the #HildonAppview. Note that the 
+ * window is still the owner of the menu.
  * 
- * Return value: The #GtkMenu assigned to this application view.
+ * Return value: The #GtkMenu assigned to this application view. 
  **/
 GtkMenu*
 hildon_window_get_menu                          (HildonWindow * self)
@@ -1731,7 +1739,8 @@ hildon_window_get_menu                          (HildonWindow * self)
  * Sets the menu to be used for this window. This menu overrides
  * a program-wide menu that may have been set with
  * hildon_program_set_common_menu. Pass NULL to remove the current
- * menu.
+ * menu. HildonWindow takes ownership of the passed menu and you're
+ * not supposed to free it yourself anymore.
  **/ 
 void
 hildon_window_set_menu                          (HildonWindow *self,