2
* panel-menu-bar-object.c: a base class for menu bar objects
4
* Copyright (C) 2003 Sun Microsystems, Inc.
5
* Copyright (C) 2004 Vincent Untz
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU General Public License as
9
* published by the Free Software Foundation; either version 2 of the
10
* License, or (at your option) any later version.
12
* This program is distributed in the hope that it will be useful, but
13
* WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23
* Mark McLoughlin <mark@skynet.ie>
24
* Vincent Untz <vincent@vuntz.net>
29
#include "panel-background.h"
30
#include "panel-typebuiltins.h"
32
#include "panel-menu-bar-object.h"
34
G_DEFINE_TYPE (PanelMenuBarObject, panel_menu_bar_object, GTK_TYPE_MENU_BAR)
36
#define PANEL_MENU_BAR_OBJECT_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PANEL_TYPE_MENU_BAR_OBJECT, PanelMenuBarObjectPrivate))
38
struct _PanelMenuBarObjectPrivate {
41
PanelOrientation orientation;
49
static void panel_menu_bar_object_update_text_gravity (PanelMenuBarObject *menubar);
50
static void panel_menu_bar_object_update_orientation (PanelMenuBarObject *menubar);
53
panel_menu_bar_object_init (PanelMenuBarObject *menubar)
55
GtkStyleContext *context;
56
GtkCssProvider *provider;
58
menubar->priv = PANEL_MENU_BAR_OBJECT_GET_PRIVATE (menubar);
60
provider = gtk_css_provider_new ();
61
gtk_css_provider_load_from_data (provider,
62
"PanelMenuBarObject {\n"
63
" border-width: 0px;\n"
66
context = gtk_widget_get_style_context (GTK_WIDGET (menubar));
67
gtk_style_context_add_provider (context,
68
GTK_STYLE_PROVIDER (provider),
69
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
70
g_object_unref (provider);
71
gtk_style_context_add_class (context, "gnome-panel-menu-bar");
73
menubar->priv->panel = NULL;
77
panel_menu_bar_object_get_property (GObject *object,
82
PanelMenuBarObject *menubar;
84
g_return_if_fail (PANEL_IS_MENU_BAR_OBJECT (object));
86
menubar = PANEL_MENU_BAR_OBJECT (object);
89
case PROP_ORIENTATION:
90
g_value_set_enum (value, menubar->priv->orientation);
93
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
99
panel_menu_bar_object_set_property (GObject *object,
104
PanelMenuBarObject *menubar;
106
g_return_if_fail (PANEL_IS_MENU_BAR_OBJECT (object));
108
menubar = PANEL_MENU_BAR_OBJECT (object);
111
case PROP_ORIENTATION:
112
panel_menu_bar_object_set_orientation (menubar,
113
g_value_get_enum (value));
116
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
122
panel_menu_bar_object_size_allocate (GtkWidget *widget,
123
GtkAllocation *allocation)
125
GtkAllocation old_allocation;
126
GtkAllocation widget_allocation;
127
PanelBackground *background;
129
gtk_widget_get_allocation (widget, &widget_allocation);
131
old_allocation.x = widget_allocation.x;
132
old_allocation.y = widget_allocation.y;
133
old_allocation.width = widget_allocation.width;
134
old_allocation.height = widget_allocation.height;
136
GTK_WIDGET_CLASS (panel_menu_bar_object_parent_class)->size_allocate (widget, allocation);
138
if (old_allocation.x == allocation->x &&
139
old_allocation.y == allocation->y &&
140
old_allocation.width == allocation->width &&
141
old_allocation.height == allocation->height)
144
background = &PANEL_MENU_BAR_OBJECT (widget)->priv->panel->background;
146
if (background->type == PANEL_BACK_NONE ||
147
(background->type == PANEL_BACK_COLOR && !background->has_alpha))
150
panel_menu_bar_object_change_background (PANEL_MENU_BAR_OBJECT (widget));
154
panel_menu_bar_object_class_init (PanelMenuBarObjectClass *klass)
156
GObjectClass *gobject_class = (GObjectClass *) klass;
157
GtkWidgetClass *widget_class = (GtkWidgetClass *) klass;
159
gobject_class->get_property = panel_menu_bar_object_get_property;
160
gobject_class->set_property = panel_menu_bar_object_set_property;
162
widget_class->size_allocate = panel_menu_bar_object_size_allocate;
164
g_type_class_add_private (klass, sizeof (PanelMenuBarObjectPrivate));
166
g_object_class_install_property (
169
g_param_spec_enum ("orientation",
171
"The PanelMenuBarObject orientation",
172
PANEL_TYPE_ORIENTATION,
173
PANEL_ORIENTATION_TOP,
178
panel_menu_bar_object_on_draw (GtkWidget *widget,
182
PanelMenuBarObject *menubar = data;
184
if (gtk_widget_has_focus (GTK_WIDGET (menubar))) {
185
GtkStyleContext *context;
187
context = gtk_widget_get_style_context (widget);
188
gtk_style_context_save (context);
189
gtk_style_context_set_state (context,
190
gtk_widget_get_state_flags (widget));
193
gtk_render_focus (context, cr,
195
gtk_widget_get_allocated_width (widget),
196
gtk_widget_get_allocated_height (widget));
199
gtk_style_context_restore (context);
206
panel_menu_bar_object_object_load_finish (PanelMenuBarObject *menubar,
209
menubar->priv->panel = panel;
211
/* we didn't do this on "applet-added" since we didn't have the panel yet */
212
panel_menu_bar_object_change_background (menubar);
213
panel_menu_bar_object_update_orientation (menubar);
214
panel_menu_bar_object_update_text_gravity (menubar);
216
g_signal_connect (menubar, "screen-changed",
217
G_CALLBACK (panel_menu_bar_object_update_text_gravity),
220
g_signal_connect_after (menubar, "focus-in-event",
221
G_CALLBACK (gtk_widget_queue_draw), menubar);
222
g_signal_connect_after (menubar, "focus-out-event",
223
G_CALLBACK (gtk_widget_queue_draw), menubar);
224
g_signal_connect_after (menubar, "draw",
225
G_CALLBACK (panel_menu_bar_object_on_draw), menubar);
226
gtk_widget_set_can_focus (GTK_WIDGET (menubar), TRUE);
228
panel_widget_set_applet_expandable (panel, GTK_WIDGET (menubar), FALSE, TRUE);
232
panel_menu_bar_object_change_background (PanelMenuBarObject *menubar)
234
if (!menubar->priv->panel)
237
panel_background_change_background_on_widget (&menubar->priv->panel->background,
238
GTK_WIDGET (menubar));
242
set_item_text_gravity (GtkWidget *item)
246
PangoContext *context;
248
label = gtk_bin_get_child (GTK_BIN (item));
249
layout = gtk_label_get_layout (GTK_LABEL (label));
250
context = pango_layout_get_context (layout);
251
pango_context_set_base_gravity (context, PANGO_GRAVITY_AUTO);
255
panel_menu_bar_object_update_text_gravity (PanelMenuBarObject *menubar)
259
children = gtk_container_get_children (GTK_CONTAINER (menubar));
260
for (l = children; l != NULL; l = l->next)
261
set_item_text_gravity (GTK_WIDGET (l->data));
262
g_list_free (children);
266
set_item_text_angle_and_alignment (GtkWidget *item,
273
label = gtk_bin_get_child (GTK_BIN (item));
275
gtk_label_set_angle (GTK_LABEL (label), text_angle);
277
gtk_misc_set_alignment (GTK_MISC (label), xalign, yalign);
281
panel_menu_bar_object_update_orientation (PanelMenuBarObject *menubar)
283
GtkPackDirection pack_direction;
289
pack_direction = GTK_PACK_DIRECTION_LTR;
294
switch (menubar->priv->orientation) {
295
case PANEL_ORIENTATION_TOP:
296
case PANEL_ORIENTATION_BOTTOM:
298
case PANEL_ORIENTATION_LEFT:
299
pack_direction = GTK_PACK_DIRECTION_BTT;
304
case PANEL_ORIENTATION_RIGHT:
305
pack_direction = GTK_PACK_DIRECTION_TTB;
311
g_assert_not_reached ();
315
gtk_menu_bar_set_pack_direction (GTK_MENU_BAR (menubar), pack_direction);
316
gtk_menu_bar_set_child_pack_direction (GTK_MENU_BAR (menubar), pack_direction);
318
children = gtk_container_get_children (GTK_CONTAINER (menubar));
319
for (l = children; l != NULL; l = l->next)
320
set_item_text_angle_and_alignment (GTK_WIDGET (l->data),
324
g_list_free (children);
328
panel_menu_bar_object_set_orientation (PanelMenuBarObject *menubar,
329
PanelOrientation orientation)
331
g_return_if_fail (PANEL_IS_MENU_BAR_OBJECT (menubar));
333
if (menubar->priv->orientation == orientation)
336
menubar->priv->orientation = orientation;
338
panel_menu_bar_object_update_orientation (menubar);
340
g_object_notify (G_OBJECT (menubar), "orientation");
344
panel_menu_bar_object_get_orientation (PanelMenuBarObject *menubar)
346
g_return_val_if_fail (PANEL_IS_MENU_BAR_OBJECT (menubar), 0);
348
return menubar->priv->orientation;