[gnome-panel/wip/user-menu: 6/11] panel: Create a generic PanelMenuBarObject widget



commit bd44cc8ee221249689f4a243ce30d43c98108608
Author: Vincent Untz <vuntz gnome org>
Date:   Thu Mar 31 17:13:36 2011 +0530

    panel: Create a generic PanelMenuBarObject widget
    
    PanelMenuBar is based on it, and we'll be able to easily add
    PanelUserMenu.

 gnome-panel/Makefile.am             |    2 +
 gnome-panel/panel-menu-bar-object.c |  349 +++++++++++++++++++++++++++++++++++
 gnome-panel/panel-menu-bar-object.h |   68 +++++++
 gnome-panel/panel-menu-bar.c        |  289 +----------------------------
 gnome-panel/panel-menu-bar.h        |   12 +-
 gnome-panel/panel.c                 |    4 +-
 6 files changed, 431 insertions(+), 293 deletions(-)
---
diff --git a/gnome-panel/Makefile.am b/gnome-panel/Makefile.am
index 2102e4f..11485ff 100644
--- a/gnome-panel/Makefile.am
+++ b/gnome-panel/Makefile.am
@@ -48,6 +48,7 @@ panel_sources =			\
 	panel-stock-icons.c	\
 	panel-action-button.c	\
 	panel-menu-bar.c	\
+	panel-menu-bar-object.c	\
 	panel-menu-button.c	\
 	panel-menu-items.c	\
 	panel-separator.c	\
@@ -94,6 +95,7 @@ panel_headers =			\
 	panel-stock-icons.h	\
 	panel-action-button.h	\
 	panel-menu-bar.h	\
+	panel-menu-bar-object.h	\
 	panel-menu-button.h	\
 	panel-menu-items.h	\
 	panel-separator.h	\
diff --git a/gnome-panel/panel-menu-bar-object.c b/gnome-panel/panel-menu-bar-object.c
new file mode 100644
index 0000000..fe0fd64
--- /dev/null
+++ b/gnome-panel/panel-menu-bar-object.c
@@ -0,0 +1,349 @@
+/*
+ * panel-menu-bar-object.c: a base class for menu bar objects
+ *
+ * Copyright (C) 2003 Sun Microsystems, Inc.
+ * Copyright (C) 2004 Vincent Untz
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Authors:
+ *	Mark McLoughlin <mark skynet ie>
+ *	Vincent Untz <vincent vuntz net>
+ */
+
+#include <config.h>
+
+#include "panel-background.h"
+#include "panel-typebuiltins.h"
+
+#include "panel-menu-bar-object.h"
+
+G_DEFINE_TYPE (PanelMenuBarObject, panel_menu_bar_object, GTK_TYPE_MENU_BAR)
+
+#define PANEL_MENU_BAR_OBJECT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PANEL_TYPE_MENU_BAR_OBJECT, PanelMenuBarObjectPrivate))
+
+struct _PanelMenuBarObjectPrivate {
+	PanelWidget *panel;
+
+	PanelOrientation orientation;
+};
+
+enum {
+	PROP_0,
+	PROP_ORIENTATION,
+};
+
+static void panel_menu_bar_object_update_text_gravity (PanelMenuBarObject *menubar);
+static void panel_menu_bar_object_update_orientation (PanelMenuBarObject *menubar);
+
+static void
+panel_menu_bar_object_init (PanelMenuBarObject *menubar)
+{
+        GtkStyleContext *context;
+        GtkCssProvider *provider;
+
+	menubar->priv = PANEL_MENU_BAR_OBJECT_GET_PRIVATE (menubar);
+
+        provider = gtk_css_provider_new ();
+        gtk_css_provider_load_from_data (provider,
+                                         "PanelMenuBarObject {\n"
+                                         " border-width: 0px;\n"
+                                         "}",
+                                         -1, NULL);
+        context = gtk_widget_get_style_context (GTK_WIDGET (menubar));
+        gtk_style_context_add_provider (context,
+                                        GTK_STYLE_PROVIDER (provider),
+                                        GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
+        g_object_unref (provider);
+	gtk_style_context_add_class (context, "gnome-panel-menu-bar");
+
+	menubar->priv->panel = NULL;
+}
+
+static void
+panel_menu_bar_object_get_property (GObject	*object,
+				    guint	 prop_id,
+				    GValue	*value,
+				    GParamSpec	*pspec)
+{
+	PanelMenuBarObject *menubar;
+
+	g_return_if_fail (PANEL_IS_MENU_BAR_OBJECT (object));
+
+	menubar = PANEL_MENU_BAR_OBJECT (object);
+
+	switch (prop_id) {
+	case PROP_ORIENTATION:
+		g_value_set_enum (value, menubar->priv->orientation);
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+		break;
+	}
+}
+
+static void
+panel_menu_bar_object_set_property (GObject	  *object,
+				    guint	   prop_id,
+				    const GValue *value,
+				    GParamSpec	  *pspec)
+{
+	PanelMenuBarObject *menubar;
+
+	g_return_if_fail (PANEL_IS_MENU_BAR_OBJECT (object));
+
+	menubar = PANEL_MENU_BAR_OBJECT (object);
+
+	switch (prop_id) {
+	case PROP_ORIENTATION:
+		panel_menu_bar_object_set_orientation (menubar,
+						       g_value_get_enum (value));
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+		break;
+	}
+}
+
+static void
+panel_menu_bar_object_size_allocate (GtkWidget     *widget,
+				     GtkAllocation *allocation)
+{
+	GtkAllocation    old_allocation;
+	GtkAllocation    widget_allocation;
+	PanelBackground *background;
+
+	gtk_widget_get_allocation (widget, &widget_allocation);
+
+	old_allocation.x      = widget_allocation.x;
+	old_allocation.y      = widget_allocation.y;
+	old_allocation.width  = widget_allocation.width;
+	old_allocation.height = widget_allocation.height;
+
+	GTK_WIDGET_CLASS (panel_menu_bar_object_parent_class)->size_allocate (widget, allocation);
+
+	if (old_allocation.x      == allocation->x &&
+	    old_allocation.y      == allocation->y &&
+	    old_allocation.width  == allocation->width &&
+	    old_allocation.height == allocation->height)
+		return;
+
+	background = &PANEL_MENU_BAR_OBJECT (widget)->priv->panel->background;
+
+	if (background->type == PANEL_BACK_NONE ||
+	   (background->type == PANEL_BACK_COLOR && !background->has_alpha))
+		return;
+
+	panel_menu_bar_object_change_background (PANEL_MENU_BAR_OBJECT (widget));
+}
+
+static void
+panel_menu_bar_object_class_init (PanelMenuBarObjectClass *klass)
+{
+	GObjectClass   *gobject_class = (GObjectClass   *) klass;
+	GtkWidgetClass *widget_class  = (GtkWidgetClass *) klass;
+
+	gobject_class->get_property = panel_menu_bar_object_get_property;
+        gobject_class->set_property = panel_menu_bar_object_set_property;
+
+	widget_class->size_allocate = panel_menu_bar_object_size_allocate;
+
+	g_type_class_add_private (klass, sizeof (PanelMenuBarObjectPrivate));
+
+	g_object_class_install_property (
+		gobject_class,
+		PROP_ORIENTATION,
+		g_param_spec_enum ("orientation",
+				   "Orientation",
+				   "The PanelMenuBarObject orientation",
+				   PANEL_TYPE_ORIENTATION,
+				   PANEL_ORIENTATION_TOP,
+				   G_PARAM_READWRITE));
+}
+
+static gboolean
+panel_menu_bar_object_on_draw (GtkWidget *widget,
+			       cairo_t   *cr,
+			       gpointer   data)
+{
+	PanelMenuBarObject *menubar = data;
+
+	if (gtk_widget_has_focus (GTK_WIDGET (menubar))) {
+                GtkStyleContext *context;
+
+                context = gtk_widget_get_style_context (widget);
+                gtk_style_context_save (context);
+                gtk_style_context_set_state (context,
+					     gtk_widget_get_state_flags (widget));
+
+                cairo_save (cr);
+		gtk_render_focus (context, cr,
+                                  0, 0,
+                                  gtk_widget_get_allocated_width (widget),
+                                  gtk_widget_get_allocated_height (widget));
+                cairo_restore (cr);
+
+                gtk_style_context_restore (context);
+        }
+
+	return FALSE;
+}
+
+void
+panel_menu_bar_object_object_load_finish (PanelMenuBarObject *menubar,
+					  PanelWidget        *panel)
+{
+	menubar->priv->panel = panel;
+
+	/* we didn't do this on "applet-added" since we didn't have the panel yet */
+	panel_menu_bar_object_change_background (menubar);
+        panel_menu_bar_object_update_orientation (menubar);
+	panel_menu_bar_object_update_text_gravity (menubar);
+
+	g_signal_connect (menubar, "screen-changed",
+			  G_CALLBACK (panel_menu_bar_object_update_text_gravity),
+			  NULL);
+
+	g_signal_connect_after (menubar, "focus-in-event",
+				G_CALLBACK (gtk_widget_queue_draw), menubar);
+	g_signal_connect_after (menubar, "focus-out-event",
+				G_CALLBACK (gtk_widget_queue_draw), menubar);
+	g_signal_connect_after (menubar, "draw",
+				G_CALLBACK (panel_menu_bar_object_on_draw), menubar);
+	gtk_widget_set_can_focus (GTK_WIDGET (menubar), TRUE);
+
+	panel_widget_set_applet_expandable (panel, GTK_WIDGET (menubar), FALSE, TRUE);
+}
+
+void
+panel_menu_bar_object_change_background (PanelMenuBarObject *menubar)
+{
+	if (!menubar->priv->panel)
+		return;
+
+	panel_background_change_background_on_widget (&menubar->priv->panel->background,
+						      GTK_WIDGET (menubar));
+}
+
+static void
+set_item_text_gravity (GtkWidget *item)
+{
+	GtkWidget    *label;
+	PangoLayout  *layout;
+	PangoContext *context;
+
+	label = gtk_bin_get_child (GTK_BIN (item));
+	layout = gtk_label_get_layout (GTK_LABEL (label));
+	context = pango_layout_get_context (layout);
+	pango_context_set_base_gravity (context, PANGO_GRAVITY_AUTO);
+}
+
+static void
+panel_menu_bar_object_update_text_gravity (PanelMenuBarObject *menubar)
+{
+	GList *children, *l;
+
+	children = gtk_container_get_children (GTK_CONTAINER (menubar));
+	for (l = children; l != NULL; l = l->next)
+		set_item_text_gravity (GTK_WIDGET (l->data));
+	g_list_free (children);
+}
+
+static void
+set_item_text_angle_and_alignment (GtkWidget *item,
+				   double     text_angle,
+				   float      xalign,
+				   float      yalign)
+{
+	GtkWidget *label;
+
+	label = gtk_bin_get_child (GTK_BIN (item));
+
+	gtk_label_set_angle (GTK_LABEL (label), text_angle);
+
+	gtk_misc_set_alignment (GTK_MISC (label), xalign, yalign);
+}
+
+static void
+panel_menu_bar_object_update_orientation (PanelMenuBarObject *menubar)
+{
+	GtkPackDirection pack_direction;
+	double           text_angle;
+	float            text_xalign;
+	float            text_yalign;
+	GList           *children, *l;
+
+	pack_direction = GTK_PACK_DIRECTION_LTR;
+	text_angle = 0.0;
+	text_xalign = 0.0;
+	text_yalign = 0.5;
+
+	switch (menubar->priv->orientation) {
+	case PANEL_ORIENTATION_TOP:
+	case PANEL_ORIENTATION_BOTTOM:
+		break;
+	case PANEL_ORIENTATION_LEFT:
+		pack_direction = GTK_PACK_DIRECTION_BTT;
+		text_angle = 90.0;
+		text_xalign = 0.5;
+		text_yalign = 0.0;
+		break;
+	case PANEL_ORIENTATION_RIGHT:
+		pack_direction = GTK_PACK_DIRECTION_TTB;
+		text_angle = 270.0;
+		text_xalign = 0.5;
+		text_yalign = 0.0;
+		break;
+	default:
+		g_assert_not_reached ();
+		break;
+	}
+
+	gtk_menu_bar_set_pack_direction (GTK_MENU_BAR (menubar), pack_direction);
+	gtk_menu_bar_set_child_pack_direction (GTK_MENU_BAR (menubar), pack_direction);
+
+	children = gtk_container_get_children (GTK_CONTAINER (menubar));
+	for (l = children; l != NULL; l = l->next)
+		set_item_text_angle_and_alignment (GTK_WIDGET (l->data),
+						   text_angle,
+						   text_xalign,
+						   text_yalign);
+	g_list_free (children);
+}
+
+void
+panel_menu_bar_object_set_orientation (PanelMenuBarObject *menubar,
+				       PanelOrientation    orientation)
+{
+        g_return_if_fail (PANEL_IS_MENU_BAR_OBJECT (menubar));
+
+        if (menubar->priv->orientation == orientation)
+                return;
+
+        menubar->priv->orientation = orientation;
+
+        panel_menu_bar_object_update_orientation (menubar);
+
+        g_object_notify (G_OBJECT (menubar), "orientation");
+}
+
+PanelOrientation
+panel_menu_bar_object_get_orientation (PanelMenuBarObject *menubar)
+{
+        g_return_val_if_fail (PANEL_IS_MENU_BAR_OBJECT (menubar), 0);
+
+        return menubar->priv->orientation;
+}
diff --git a/gnome-panel/panel-menu-bar-object.h b/gnome-panel/panel-menu-bar-object.h
new file mode 100644
index 0000000..9091164
--- /dev/null
+++ b/gnome-panel/panel-menu-bar-object.h
@@ -0,0 +1,68 @@
+/*
+ * panel-menu-bar-object.h: a base class for menu bar objects
+ *
+ * Copyright (C) 2003 Sun Microsystems, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program 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
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Authors:
+ *	Mark McLoughlin <mark skynet ie>
+ */
+
+#ifndef __PANEL_MENU_BAR_OBJECT_H__
+#define __PANEL_MENU_BAR_OBJECT_H__
+
+#include <gtk/gtk.h>
+
+#include "panel-widget.h"
+
+G_BEGIN_DECLS
+
+#define PANEL_TYPE_MENU_BAR_OBJECT         (panel_menu_bar_object_get_type ())
+#define PANEL_MENU_BAR_OBJECT(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), PANEL_TYPE_MENU_BAR_OBJECT, PanelMenuBarObject))
+#define PANEL_MENU_BAR_OBJECT_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), PANEL_TYPE_MENU_BAR_OBJECT, PanelMenuBarObjectClass))
+#define PANEL_IS_MENU_BAR_OBJECT(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), PANEL_TYPE_MENU_BAR_OBJECT))
+#define PANEL_IS_MENU_BAR_OBJECT_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), PANEL_TYPE_MENU_BAR_OBJECT))
+#define PANEL_MENU_BAR_OBJECT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), PANEL_TYPE_MENU_BAR_OBJECT, PanelMenuBarObjectClass))
+
+typedef struct _PanelMenuBarObject        PanelMenuBarObject;
+typedef struct _PanelMenuBarObjectClass   PanelMenuBarObjectClass;
+typedef struct _PanelMenuBarObjectPrivate PanelMenuBarObjectPrivate;
+
+struct _PanelMenuBarObject{
+	GtkMenuBar                  menubar;
+
+	PanelMenuBarObjectPrivate  *priv;
+};
+
+struct _PanelMenuBarObjectClass {
+	GtkMenuBarClass             menubar_class;
+};
+
+GType      panel_menu_bar_object_get_type  (void) G_GNUC_CONST;
+
+void panel_menu_bar_object_object_load_finish (PanelMenuBarObject *menubar,
+					       PanelWidget        *panel);
+
+void       panel_menu_bar_object_change_background (PanelMenuBarObject *menubar);
+
+void             panel_menu_bar_object_set_orientation (PanelMenuBarObject     *menubar,
+							PanelOrientation        orientation);
+PanelOrientation panel_menu_bar_object_get_orientation (PanelMenuBarObject     *menubar);
+
+G_END_DECLS
+
+#endif /* __PANEL_MENU_BAR_OBJECT_H__ */
diff --git a/gnome-panel/panel-menu-bar.c b/gnome-panel/panel-menu-bar.c
index b18d447..76be70b 100644
--- a/gnome-panel/panel-menu-bar.c
+++ b/gnome-panel/panel-menu-bar.c
@@ -35,20 +35,16 @@
 #include <libpanel-util/panel-launch.h>
 #include <libpanel-util/panel-show.h>
 
-#include "panel-util.h"
-#include "panel-background.h"
-#include "panel-action-button.h"
 #include "applet.h"
 #include "menu.h"
-#include "panel-menu-items.h"
-#include "panel-globals.h"
 #include "panel-layout.h"
 #include "panel-lockdown.h"
-#include "panel-stock-icons.h"
-#include "panel-typebuiltins.h"
 #include "panel-icon-names.h"
+#include "panel-menu-bar-object.h"
+#include "panel-menu-items.h"
+#include "panel-util.h"
 
-G_DEFINE_TYPE (PanelMenuBar, panel_menu_bar, GTK_TYPE_MENU_BAR)
+G_DEFINE_TYPE (PanelMenuBar, panel_menu_bar, PANEL_TYPE_MENU_BAR_OBJECT)
 
 #define PANEL_MENU_BAR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PANEL_TYPE_MENU_BAR, PanelMenuBarPrivate))
 
@@ -61,17 +57,8 @@ struct _PanelMenuBarPrivate {
 	GtkWidget   *applications_item;
 	GtkWidget   *places_item;
 	GtkWidget   *desktop_item;
-
-	PanelOrientation orientation;
-};
-
-enum {
-	PROP_0,
-	PROP_ORIENTATION,
 };
 
-static void panel_menu_bar_update_text_gravity (PanelMenuBar *menubar);
-
 /* themeable size - "panel-foobar" -- This is only used for the icon of the
  * Applications item in the menu bar */
 #define PANEL_DEFAULT_MENU_BAR_ICON_SIZE       24
@@ -147,24 +134,8 @@ panel_menu_bar_setup_tooltip (PanelMenuBar *menubar)
 static void
 panel_menu_bar_init (PanelMenuBar *menubar)
 {
-        GtkStyleContext *context;
-        GtkCssProvider *provider;
-
 	menubar->priv = PANEL_MENU_BAR_GET_PRIVATE (menubar);
 
-        provider = gtk_css_provider_new ();
-        gtk_css_provider_load_from_data (provider,
-                                         "PanelMenuBar {\n"
-                                         " border-width: 0px;\n"
-                                         "}",
-                                         -1, NULL);
-        context = gtk_widget_get_style_context (GTK_WIDGET (menubar));
-        gtk_style_context_add_provider (context,
-                                        GTK_STYLE_PROVIDER (provider),
-                                        GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
-        g_object_unref (provider);
-	gtk_style_context_add_class (context, "gnome-panel-menu-bar");
-
 	menubar->priv->info = NULL;
 
 	menubar->priv->applications_menu = create_applications_menu ("applications.menu", NULL, TRUE);
@@ -192,55 +163,6 @@ panel_menu_bar_init (PanelMenuBar *menubar)
 	gtk_widget_show (menubar->priv->desktop_item);
 
 	panel_menu_bar_setup_tooltip (menubar);
-
-	panel_menu_bar_update_text_gravity (menubar);
-	g_signal_connect (menubar, "screen-changed",
-			  G_CALLBACK (panel_menu_bar_update_text_gravity),
-			  NULL);
-}
-
-static void
-panel_menu_bar_get_property (GObject	*object,
-			     guint	 prop_id,
-			     GValue	*value,
-			     GParamSpec *pspec)
-{
-	PanelMenuBar *menubar;
-
-	g_return_if_fail (PANEL_IS_MENU_BAR (object));
-
-	menubar = PANEL_MENU_BAR (object);
-
-	switch (prop_id) {
-	case PROP_ORIENTATION:
-		g_value_set_enum (value, menubar->priv->orientation);
-		break;
-	default:
-		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
-		break;
-	}
-}
-
-static void
-panel_menu_bar_set_property (GObject	  *object,
-			     guint	   prop_id,
-			     const GValue *value,
-			     GParamSpec	  *pspec)
-{
-	PanelMenuBar *menubar;
-
-	g_return_if_fail (PANEL_IS_MENU_BAR (object));
-
-	menubar = PANEL_MENU_BAR (object);
-
-	switch (prop_id) {
-	case PROP_ORIENTATION:
-		panel_menu_bar_set_orientation (menubar, g_value_get_enum (value));
-		break;
-	default:
-		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
-		break;
-	}
 }
 
 static void
@@ -268,38 +190,6 @@ panel_menu_bar_parent_set (GtkWidget *widget,
 }
 
 static void
-panel_menu_bar_size_allocate (GtkWidget     *widget,
-			      GtkAllocation *allocation)
-{
-	GtkAllocation    old_allocation;
-	GtkAllocation    widget_allocation;
-	PanelBackground *background;
-
-	gtk_widget_get_allocation (widget, &widget_allocation);
-
-	old_allocation.x      = widget_allocation.x;
-	old_allocation.y      = widget_allocation.y;
-	old_allocation.width  = widget_allocation.width;
-	old_allocation.height = widget_allocation.height;
-
-	GTK_WIDGET_CLASS (panel_menu_bar_parent_class)->size_allocate (widget, allocation);
-
-	if (old_allocation.x      == allocation->x &&
-	    old_allocation.y      == allocation->y &&
-	    old_allocation.width  == allocation->width &&
-	    old_allocation.height == allocation->height)
-		return;
-
-	background = &PANEL_MENU_BAR (widget)->priv->panel->background;
-
-	if (background->type == PANEL_BACK_NONE ||
-	   (background->type == PANEL_BACK_COLOR && !background->has_alpha))
-		return;
-
-	panel_menu_bar_change_background (PANEL_MENU_BAR (widget));
-}
-
-static void
 panel_menu_bar_style_updated (GtkWidget *widget)
 {
 	PanelMenuBar *menubar = PANEL_MENU_BAR (widget);
@@ -320,28 +210,13 @@ panel_menu_bar_style_updated (GtkWidget *widget)
 static void
 panel_menu_bar_class_init (PanelMenuBarClass *klass)
 {
-	GObjectClass   *gobject_class = (GObjectClass   *) klass;
 	GtkWidgetClass *widget_class  = (GtkWidgetClass *) klass;
 
-	gobject_class->get_property = panel_menu_bar_get_property;
-        gobject_class->set_property = panel_menu_bar_set_property;
-
 	widget_class->parent_set = panel_menu_bar_parent_set;
-	widget_class->size_allocate = panel_menu_bar_size_allocate;
 	widget_class->style_updated = panel_menu_bar_style_updated;
 
 	g_type_class_add_private (klass, sizeof (PanelMenuBarPrivate));
 
-	g_object_class_install_property (
-		gobject_class,
-		PROP_ORIENTATION,
-		g_param_spec_enum ("orientation",
-				   "Orientation",
-				   "The PanelMenuBar orientation",
-				   PANEL_TYPE_ORIENTATION,
-				   PANEL_ORIENTATION_TOP,
-				   G_PARAM_READWRITE));
-
 	gtk_widget_class_install_style_property (
 		widget_class,
 		g_param_spec_boolean ("icon-visible",
@@ -356,33 +231,6 @@ panel_menu_bar_class_init (PanelMenuBarClass *klass)
 								   PANEL_DEFAULT_MENU_BAR_ICON_SIZE);
 }
 
-static gboolean
-panel_menu_bar_on_draw (GtkWidget *widget,
-			cairo_t   *cr,
-			gpointer   data)
-{
-	PanelMenuBar *menubar = data;
-
-	if (gtk_widget_has_focus (GTK_WIDGET (menubar))) {
-                GtkStyleContext *context;
-
-                context = gtk_widget_get_style_context (widget);
-                gtk_style_context_save (context);
-                gtk_style_context_set_state (context, gtk_widget_get_state_flags (widget));
-
-                cairo_save (cr);
-		gtk_render_focus (context, cr,
-                                  0, 0,
-                                  gtk_widget_get_allocated_width (widget),
-                                  gtk_widget_get_allocated_height (widget));
-                cairo_restore (cr);
-
-                gtk_style_context_restore (context);
-        }
-
-	return FALSE;
-}
-
 void
 panel_menu_bar_load (PanelWidget *panel,
 		     const char  *id,
@@ -419,15 +267,8 @@ panel_menu_bar_load (PanelWidget *panel,
 				   _("_Help"),
 				   NULL);
 
-	g_signal_connect_after (menubar, "focus-in-event",
-				G_CALLBACK (gtk_widget_queue_draw), menubar);
-	g_signal_connect_after (menubar, "focus-out-event",
-				G_CALLBACK (gtk_widget_queue_draw), menubar);
-	g_signal_connect_after (menubar, "draw",
-				G_CALLBACK (panel_menu_bar_on_draw), menubar);
-	gtk_widget_set_can_focus (GTK_WIDGET (menubar), TRUE);
-
-	panel_widget_set_applet_expandable (panel, GTK_WIDGET (menubar), FALSE, TRUE);
+	panel_menu_bar_object_object_load_finish (PANEL_MENU_BAR_OBJECT (menubar),
+						  panel);
 }
 
 void
@@ -501,121 +342,3 @@ panel_menu_bar_popup_menu (PanelMenuBar *menubar,
 	gtk_menu_shell_select_item (menu_shell,
 				    gtk_menu_get_attach_widget (menu));
 }
-
-void
-panel_menu_bar_change_background (PanelMenuBar *menubar)
-{
-	panel_background_change_background_on_widget (&menubar->priv->panel->background,
-						      GTK_WIDGET (menubar));
-}
-
-static void
-set_item_text_gravity (GtkWidget *item)
-{
-	GtkWidget    *label;
-	PangoLayout  *layout;
-	PangoContext *context;
-
-	label = gtk_bin_get_child (GTK_BIN (item));
-	layout = gtk_label_get_layout (GTK_LABEL (label));
-	context = pango_layout_get_context (layout);
-	pango_context_set_base_gravity (context, PANGO_GRAVITY_AUTO);
-}
-
-static void
-panel_menu_bar_update_text_gravity (PanelMenuBar *menubar)
-{
-	set_item_text_gravity (menubar->priv->applications_item);
-	set_item_text_gravity (menubar->priv->places_item);
-	set_item_text_gravity (menubar->priv->desktop_item);
-}
-
-static void
-set_item_text_angle_and_alignment (GtkWidget *item,
-				   double     text_angle,
-				   float      xalign,
-				   float      yalign)
-{
-	GtkWidget *label;
-
-	label = gtk_bin_get_child (GTK_BIN (item));
-
-	gtk_label_set_angle (GTK_LABEL (label), text_angle);
-
-	gtk_misc_set_alignment (GTK_MISC (label), xalign, yalign);
-}
-
-static void
-panel_menu_bar_update_orientation (PanelMenuBar *menubar)
-{
-	GtkPackDirection pack_direction;
-	double           text_angle;
-	float            text_xalign;
-	float            text_yalign;
-
-	pack_direction = GTK_PACK_DIRECTION_LTR;
-	text_angle = 0.0;
-	text_xalign = 0.0;
-	text_yalign = 0.5;
-
-	switch (menubar->priv->orientation) {
-	case PANEL_ORIENTATION_TOP:
-	case PANEL_ORIENTATION_BOTTOM:
-		break;
-	case PANEL_ORIENTATION_LEFT:
-		pack_direction = GTK_PACK_DIRECTION_BTT;
-		text_angle = 90.0;
-		text_xalign = 0.5;
-		text_yalign = 0.0;
-		break;
-	case PANEL_ORIENTATION_RIGHT:
-		pack_direction = GTK_PACK_DIRECTION_TTB;
-		text_angle = 270.0;
-		text_xalign = 0.5;
-		text_yalign = 0.0;
-		break;
-	default:
-		g_assert_not_reached ();
-		break;
-	}
-
-	gtk_menu_bar_set_pack_direction (GTK_MENU_BAR (menubar), pack_direction);
-	gtk_menu_bar_set_child_pack_direction (GTK_MENU_BAR (menubar), pack_direction);
-
-	set_item_text_angle_and_alignment (menubar->priv->applications_item,
-					   text_angle,
-					   text_xalign,
-					   text_yalign);
-	set_item_text_angle_and_alignment (menubar->priv->places_item,
-					   text_angle,
-					   text_xalign,
-					   text_yalign);
-	set_item_text_angle_and_alignment (menubar->priv->desktop_item,
-					   text_angle,
-					   text_xalign,
-					   text_yalign);
-}
-
-void
-panel_menu_bar_set_orientation (PanelMenuBar     *menubar,
-				PanelOrientation  orientation)
-{
-        g_return_if_fail (PANEL_IS_MENU_BAR (menubar));
-
-        if (menubar->priv->orientation == orientation)
-                return;
-
-        menubar->priv->orientation = orientation;
-
-        panel_menu_bar_update_orientation (menubar);
-
-        g_object_notify (G_OBJECT (menubar), "orientation");
-}
-
-PanelOrientation
-panel_menu_bar_get_orientation (PanelMenuBar *menubar)
-{
-        g_return_val_if_fail (PANEL_IS_MENU_BAR (menubar), 0);
-
-        return menubar->priv->orientation;
-}
diff --git a/gnome-panel/panel-menu-bar.h b/gnome-panel/panel-menu-bar.h
index 25f6d6f..98f1a25 100644
--- a/gnome-panel/panel-menu-bar.h
+++ b/gnome-panel/panel-menu-bar.h
@@ -26,6 +26,8 @@
 #define __PANEL_MENU_BAR_H__
 
 #include <gtk/gtk.h>
+
+#include "panel-menu-bar-object.h"
 #include "panel-widget.h"
 
 G_BEGIN_DECLS
@@ -42,13 +44,13 @@ typedef struct _PanelMenuBarClass   PanelMenuBarClass;
 typedef struct _PanelMenuBarPrivate PanelMenuBarPrivate;
 
 struct _PanelMenuBar{
-	GtkMenuBar            menubar;
+	PanelMenuBarObject    menubar;
 
 	PanelMenuBarPrivate  *priv;
 };
 
 struct _PanelMenuBarClass {
-	GtkMenuBarClass       menubar_class;
+	PanelMenuBarObjectClass menubar_class;
 };
 
 GType      panel_menu_bar_get_type  (void) G_GNUC_CONST;
@@ -67,12 +69,6 @@ void       panel_menu_bar_invoke_menu      (PanelMenuBar *menubar,
 void       panel_menu_bar_popup_menu       (PanelMenuBar *menubar,
 					    guint32       activate_time);
 
-void       panel_menu_bar_change_background (PanelMenuBar *menubar);
-
-void             panel_menu_bar_set_orientation (PanelMenuBar     *menubar,
-						 PanelOrientation  orientation);
-PanelOrientation panel_menu_bar_get_orientation (PanelMenuBar     *menubar);
-
 G_END_DECLS
 
 #endif /* __PANEL_MENU_BAR_H__ */
diff --git a/gnome-panel/panel.c b/gnome-panel/panel.c
index 80a6126..f21f73f 100644
--- a/gnome-panel/panel.c
+++ b/gnome-panel/panel.c
@@ -77,7 +77,7 @@ orientation_change (AppletInfo  *info,
 		button_widget_set_orientation (BUTTON_WIDGET (info->widget), orientation);
 		break;
 	case PANEL_OBJECT_MENU_BAR:
-		panel_menu_bar_set_orientation (PANEL_MENU_BAR (info->widget), orientation);
+		panel_menu_bar_object_set_orientation (PANEL_MENU_BAR_OBJECT (info->widget), orientation);
 		break;
 	case PANEL_OBJECT_SEPARATOR:
 		panel_separator_set_orientation (PANEL_SEPARATOR (info->widget),
@@ -145,7 +145,7 @@ back_change (AppletInfo  *info,
 			PANEL_APPLET_FRAME (info->widget), panel->background.type);
 		break;
 	case PANEL_OBJECT_MENU_BAR:
-		panel_menu_bar_change_background (PANEL_MENU_BAR (info->widget));
+		panel_menu_bar_object_change_background (PANEL_MENU_BAR_OBJECT (info->widget));
 		break;
 	case PANEL_OBJECT_SEPARATOR:
 		panel_separator_change_background (PANEL_SEPARATOR (info->widget));



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]