[maemo-commits] [maemo-commits] r11204 - in projects/haf/trunk/hildon-desktop: . libhildondesktop
From: subversion at stage.maemo.org subversion at stage.maemo.orgDate: Mon Apr 23 19:46:46 EEST 2007
- Previous message: [maemo-commits] r11203 - in projects/haf/trunk/hildon-desktop: . libhildondesktop
- Next message: [maemo-commits] r11205 - in projects/haf/trunk/hildon-desktop: . libhildondesktop
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Author: moimart Date: 2007-04-23 19:46:42 +0300 (Mon, 23 Apr 2007) New Revision: 11204 Added: projects/haf/trunk/hildon-desktop/libhildondesktop/hildon-desktop-popup-menu.c projects/haf/trunk/hildon-desktop/libhildondesktop/hildon-desktop-popup-menu.h Modified: projects/haf/trunk/hildon-desktop/ChangeLog projects/haf/trunk/hildon-desktop/libhildondesktop/Makefile.am Log: * libhildondesktop/hildon-desktop-popup-menu.[ch]: - Added basic implementation of new menu. * Makefile.am: - Added HildonDesktopPopupMenu to building batch * ChangeLog updated. Modified: projects/haf/trunk/hildon-desktop/ChangeLog =================================================================== --- projects/haf/trunk/hildon-desktop/ChangeLog 2007-04-23 15:18:17 UTC (rev 11203) +++ projects/haf/trunk/hildon-desktop/ChangeLog 2007-04-23 16:46:42 UTC (rev 11204) @@ -1,3 +1,10 @@ +2007-04-23 Moises Martinez <moises.martinez at nokia.com> + + * libhildondesktop/hildon-desktop-popup-menu.[ch]: + - Added basic implementation of new menu. + * Makefile.am: + - Added HildonDesktopPopupMenu to building batch + 2007-04-23 Lucas Rocha <lucas.rocha at nokia.com> * libhildondesktop/notification-manager.xml: renamed Modified: projects/haf/trunk/hildon-desktop/libhildondesktop/Makefile.am =================================================================== --- projects/haf/trunk/hildon-desktop/libhildondesktop/Makefile.am 2007-04-23 15:18:17 UTC (rev 11203) +++ projects/haf/trunk/hildon-desktop/libhildondesktop/Makefile.am 2007-04-23 16:46:42 UTC (rev 11204) @@ -14,6 +14,7 @@ hildon-desktop-panel-window.h \ hildon-desktop-panel-window-dialog.h \ hildon-desktop-popup-window.h \ + hildon-desktop-popup-menu.h \ hildon-desktop-panel.h \ hildon-desktop-multiscreen.h \ hildon-desktop-panel-expandable.h \ @@ -92,6 +93,8 @@ hildon-desktop-panel-window-dialog.c \ hildon-desktop-popup-window.h \ hildon-desktop-popup-window.c \ + hildon-desktop-popup-menu.h \ + hildon-desktop-popup-menu.c \ hildon-desktop-panel-expandable.h \ hildon-desktop-panel-expandable.c \ hildon-desktop-multiscreen.h \ Added: projects/haf/trunk/hildon-desktop/libhildondesktop/hildon-desktop-popup-menu.c =================================================================== --- projects/haf/trunk/hildon-desktop/libhildondesktop/hildon-desktop-popup-menu.c 2007-04-23 15:18:17 UTC (rev 11203) +++ projects/haf/trunk/hildon-desktop/libhildondesktop/hildon-desktop-popup-menu.c 2007-04-23 16:46:42 UTC (rev 11204) @@ -0,0 +1,203 @@ +/* + * This file is part of maemo-af-desktop + * + * Copyright (C) 2007 Nokia Corporation. + * + * Author: Moises Martinez <moises.martinez at nokia.com> + * Contact: Karoliina Salminen <karoliina.t.salminen at 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; either 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 "hildon-desktop-popup-menu.h" + +#include <gtk/gtkvbox.h> +#include <gtk/gtkwindow.h> + +#define HILDON_DESKTOP_POPUP_MENU_GET_PRIVATE(object) \ + (G_TYPE_INSTANCE_GET_PRIVATE ((object), HILDON_DESKTOP_TYPE_POPUP_MENU, HildonDesktopPopupMenuPrivate)) + +G_DEFINE_TYPE (HildonDesktopPopupMenu, hildon_desktop_popup_menu, GTK_TYPE_SCROLLED_WINDOW); + +struct _HildonDesktopPopupMenuPrivate +{ + GtkWidget *box; + GtkWidget *box_items; + + guint n_menu_items; +}; + +static GObject *hildon_desktop_popup_menu_constructor (GType gtype, + guint n_params, + GObjectConstructParam *params); + +static gboolean hildon_desktop_popup_menu_motion_notify (GtkWidget *widget, GdkEventMotion *event); + +static void +hildon_desktop_popup_menu_init (HildonDesktopPopupMenu *menu) +{ + menu->priv = HILDON_DESKTOP_POPUP_MENU_GET_PRIVATE (menu); + + menu->priv->n_menu_items = 0; +} + +static void +hildon_desktop_popup_menu_class_init (HildonDesktopPopupMenuClass *menu_class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (menu_class); + GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (menu_class); + + object_class->constructor = hildon_desktop_popup_menu_constructor; + + widget_class->motion_notify_event = hildon_desktop_popup_menu_motion_notify; + + g_type_class_add_private (object_class, sizeof (HildonDesktopPopupMenuPrivate)); +} + +static GObject * +hildon_desktop_popup_menu_constructor (GType gtype, + guint n_params, + GObjectConstructParam *params) +{ + GObject *object; + HildonDesktopPopupMenu *menu; + + object = G_OBJECT_CLASS (hildon_desktop_popup_menu_parent_class)->constructor (gtype, + n_params, + params); + + menu = HILDON_DESKTOP_POPUP_MENU (object); + + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (menu), + GTK_POLICY_NEVER, + GTK_POLICY_NEVER); + + gtk_widget_push_composite_child (); + + menu->priv->box = gtk_vbox_new (FALSE,0); + + gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (menu), menu->priv->box); + gtk_widget_show (menu->priv->box); + + menu->priv->box_items = gtk_vbox_new (FALSE, 0); /* FIXME: add spacing decoration */ + + gtk_container_add (GTK_CONTAINER (menu->priv->box), + menu->priv->box_items); + gtk_widget_show (menu->priv->box_items); + + gtk_widget_pop_composite_child (); + + return object; +} + +static gboolean +hildon_desktop_popup_menu_motion_notify (GtkWidget *widget, + GdkEventMotion *event) +{ + HildonDesktopPopupMenu *menu = HILDON_DESKTOP_POPUP_MENU (widget); + GList *menu_items = NULL, *l; + gint w,h,x,y; + + menu_items = + gtk_container_get_children (GTK_CONTAINER (menu->priv->box_items)); + + for (l = menu_items; l != NULL; l = g_list_next (l)) + { + gtk_widget_get_pointer (GTK_WIDGET (l->data), &x, &y); + + w = GTK_WIDGET (l->data)->allocation.width; + h = GTK_WIDGET (l->data)->allocation.height; + + if ((x >= 0) && (x <= w) && (y >= 0) && (y <= h)) + { + if (GTK_IS_ITEM (l->data)) + gtk_item_select (GTK_ITEM (l->data)); + } + else + { + if (GTK_IS_ITEM (l->data)) + gtk_item_deselect (GTK_ITEM (l->data)); + } + } + + return TRUE; +} + +void +hildon_desktop_popup_menu_add_item (HildonDesktopPopupMenu *menu, GtkMenuItem *item) +{ + GList *children = NULL, *l; + gint d_height = 0; + GtkRequisition req; + + g_assert (HILDON_DESKTOP_IS_POPUP_MENU (menu)); + g_return_if_fail (GTK_IS_MENU_ITEM (item)); + + gtk_box_pack_start (GTK_BOX (menu->priv->box_items), + GTK_WIDGET (item), + FALSE, FALSE, 0); + + gtk_widget_show (GTK_WIDGET (item)); + + children = gtk_container_get_children (GTK_CONTAINER (menu->priv->box_items)); + + for (l = children; l != NULL; l = g_list_next (l)) + { + gtk_widget_size_request (GTK_WIDGET (l->data), &req); + + d_height += req.height; + } + + GtkWidget *parent = gtk_widget_get_parent (GTK_WIDGET (menu)); + + if (GTK_IS_WINDOW (parent)) + { + gtk_widget_size_request (parent, &req); + gtk_widget_set_size_request (parent, req.width, d_height); + } +} + +void +hildon_desktop_popup_menu_remove_item (HildonDesktopPopupMenu *menu, GtkMenuItem *item) +{ + GList *children = NULL, *l; + + g_assert (HILDON_DESKTOP_IS_POPUP_MENU (menu)); + g_return_if_fail (GTK_IS_MENU_ITEM (item)); + + children = gtk_container_get_children (GTK_CONTAINER (menu->priv->box_items)); + + for (l = children; l != NULL; l = g_list_next (l)) + { + if (l->data == item) + { + gtk_container_remove (GTK_CONTAINER (menu->priv->box_items), GTK_WIDGET (item)); + break; + } + } +} + +GList * +hildon_desktop_popup_menu_get_children (HildonDesktopPopupMenu *menu) +{ + g_assert (HILDON_DESKTOP_IS_POPUP_MENU (menu)); + + GList *list = gtk_container_get_children (GTK_CONTAINER (menu->priv->box_items)); + + return list; +} + Added: projects/haf/trunk/hildon-desktop/libhildondesktop/hildon-desktop-popup-menu.h =================================================================== --- projects/haf/trunk/hildon-desktop/libhildondesktop/hildon-desktop-popup-menu.h 2007-04-23 15:18:17 UTC (rev 11203) +++ projects/haf/trunk/hildon-desktop/libhildondesktop/hildon-desktop-popup-menu.h 2007-04-23 16:46:42 UTC (rev 11204) @@ -0,0 +1,74 @@ +/* + * This file is part of maemo-af-desktop + * + * Copyright (C) 2007 Nokia Corporation. + * + * Author: Moises Martinez <moises.martinez at nokia.com> + * Contact: Karoliina Salminen <karoliina.t.salminen at 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; either 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 + * + */ + +#ifndef __HILDON_DESKTOP_POPUP_MENU_H__ +#define __HILDON_DESKTOP_POPUP_MENU_H__ + +#include <gtk/gtkscrolledwindow.h> +#include <gtk/gtkmenuitem.h> + +G_BEGIN_DECLS + +typedef struct _HildonDesktopPopupMenu HildonDesktopPopupMenu; +typedef struct _HildonDesktopPopupMenuClass HildonDesktopPopupMenuClass; +typedef struct _HildonDesktopPopupMenuPrivate HildonDesktopPopupMenuPrivate; + + +#define HILDON_DESKTOP_TYPE_POPUP_MENU ( hildon_desktop_popup_menu_get_type() ) +#define HILDON_DESKTOP_POPUP_MENU(obj) (GTK_CHECK_CAST (obj, HILDON_DESKTOP_TYPE_POPUP_MENU, HildonDesktopPopupMenu)) +#define HILDON_DESKTOP_POPUP_MENU_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), HILDON_DESKTOP_TYPE_POPUP_MENU, HildonDesktopPopupMenuClass)) +#define HILDON_DESKTOP_IS_POPUP_MENU(obj) (GTK_CHECK_TYPE (obj, HILDON_DESKTOP_TYPE_POPUP_MENU)) +#define HILDON_DESKTOP_IS_POPUP_MENU_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), HILDON_DESKTOP_TYPE_POPUP_MENU)) + +struct _HildonDesktopPopupMenu +{ + GtkScrolledWindow parent; + + HildonDesktopPopupMenuPrivate *priv; +}; + +struct _HildonDesktopPopupMenuClass +{ + GtkScrolledWindowClass parent_class; + /* */ +}; + +GType +hildon_desktop_popup_menu_get_type (void); + +void +hildon_desktop_popup_menu_add_item (HildonDesktopPopupMenu *menu, + GtkMenuItem *item); + +void +hildon_desktop_popup_menu_remove_item (HildonDesktopPopupMenu *menu, + GtkMenuItem *item); + +GList * +hildon_desktop_popup_menu_get_children (HildonDesktopPopupMenu *menu); +G_BEGIN_DECLS + +#endif/*__HILDON_DESKTOP_POPUP_MENU_H__*/ +
- Previous message: [maemo-commits] r11203 - in projects/haf/trunk/hildon-desktop: . libhildondesktop
- Next message: [maemo-commits] r11205 - in projects/haf/trunk/hildon-desktop: . libhildondesktop
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]