35
35
#include <libpanel-util/panel-launch.h>
36
36
#include <libpanel-util/panel-show.h>
38
#include "panel-util.h"
39
#include "panel-background.h"
40
#include "panel-action-button.h"
41
38
#include "applet.h"
43
#include "panel-menu-items.h"
44
#include "panel-globals.h"
45
#include "panel-profile.h"
40
#include "panel-layout.h"
46
41
#include "panel-lockdown.h"
47
#include "panel-stock-icons.h"
48
#include "panel-typebuiltins.h"
49
42
#include "panel-icon-names.h"
50
#include "applet-signaler.h"
43
#include "panel-menu-bar-object.h"
44
#include "panel-menu-items.h"
45
#include "panel-util.h"
52
G_DEFINE_TYPE (PanelMenuBar, panel_menu_bar, GTK_TYPE_MENU_BAR)
47
G_DEFINE_TYPE (PanelMenuBar, panel_menu_bar, PANEL_TYPE_MENU_BAR_OBJECT)
54
49
#define PANEL_MENU_BAR_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PANEL_TYPE_MENU_BAR, PanelMenuBarPrivate))
58
53
PanelWidget *panel;
60
56
GtkWidget *applications_menu;
61
57
GtkWidget *applications_item;
62
58
GtkWidget *places_item;
63
GtkWidget *desktop_item;
65
PanelOrientation orientation;
73
static void panel_menu_bar_update_text_gravity (PanelMenuBar *menubar);
61
/* themeable size - "panel-foobar" -- This is only used for the icon of the
62
* Applications item in the menu bar */
63
#define PANEL_DEFAULT_MENU_BAR_ICON_SIZE 24
65
static GtkIconSize panel_menu_bar_icon_size = 0;
68
panel_menu_bar_icon_get_size (void)
70
return panel_menu_bar_icon_size;
76
74
panel_menu_bar_reinit_tooltip (GtkWidget *widget,
103
#define FUSA_APPLET_IID "OAFIID:GNOME_FastUserSwitchApplet"
104
#define INDICATOR_APPLET_COMPLETE_IID "OAFIID:GNOME_IndicatorAppletComplete"
107
panel_menu_bar_set_tooltip_remove (PanelAppletSignaler * pas, AppletInfo * info, GtkWidget * widget)
109
const char * iid = panel_applet_get_iid(info);
113
if (g_strcmp0(iid, FUSA_APPLET_IID) == 0 ||
114
g_strcmp0(iid, INDICATOR_APPLET_COMPLETE_IID) == 0)
115
panel_util_set_tooltip_text (widget,
116
_("Change desktop appearance and behavior, get help, or log out"));
122
panel_menu_bar_set_tooltip_add (PanelAppletSignaler * pas, AppletInfo * info, GtkWidget * widget)
124
const char * iid = panel_applet_get_iid(info);
128
if (g_strcmp0(iid, FUSA_APPLET_IID) == 0 ||
129
g_strcmp0(iid, INDICATOR_APPLET_COMPLETE_IID) == 0)
130
panel_util_set_tooltip_text (widget,
131
_("Change system appearance and behavior, or get help"));
137
disconnect_signalers (PanelAppletSignaler *signaler,
140
g_signal_handlers_disconnect_by_func (signaler,
141
panel_menu_bar_set_tooltip_add,
143
g_signal_handlers_disconnect_by_func (signaler,
144
panel_menu_bar_set_tooltip_remove,
149
100
panel_menu_bar_setup_tooltip (PanelMenuBar *menubar)
151
PanelAppletSignaler *signaler = panel_applet_signaler_get_default ();
153
102
panel_util_set_tooltip_text (menubar->priv->applications_item,
154
103
_("Browse and run installed applications"));
155
104
panel_util_set_tooltip_text (menubar->priv->places_item,
156
105
_("Access documents, folders and network places"));
157
panel_util_set_tooltip_text (menubar->priv->desktop_item,
158
_("Change desktop appearance and behavior, get help, or log out"));
160
g_object_weak_ref (G_OBJECT (menubar->priv->desktop_item),
161
(GWeakNotify) disconnect_signalers,
164
g_signal_connect(signaler, PANEL_APPLET_SIGNALER_SIGNAL_APPLET_ADDED,
165
G_CALLBACK(panel_menu_bar_set_tooltip_add), menubar->priv->desktop_item);
166
g_signal_connect(signaler, PANEL_APPLET_SIGNALER_SIGNAL_APPLET_REMOVED,
167
G_CALLBACK(panel_menu_bar_set_tooltip_remove), menubar->priv->desktop_item);
170
107
//FIXME: this doesn't handle the right-click case. Sigh.
171
108
/* Hide tooltip if a menu is activated */
203
134
menubar->priv->applications_item = panel_image_menu_item_new ();
204
135
gtk_menu_item_set_label (GTK_MENU_ITEM (menubar->priv->applications_item),
205
136
_("Applications"));
206
image = gtk_image_new_from_icon_name (PANEL_ICON_MAIN_MENU,
207
panel_menu_bar_icon_get_size ());
208
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menubar->priv->applications_item),
137
menubar->priv->image = gtk_image_new_from_icon_name (PANEL_ICON_MAIN_MENU,
138
panel_menu_bar_icon_get_size ());
211
140
gtk_menu_item_set_submenu (GTK_MENU_ITEM (menubar->priv->applications_item),
212
141
menubar->priv->applications_menu);
213
142
gtk_menu_shell_append (GTK_MENU_SHELL (menubar),
214
143
menubar->priv->applications_item);
144
gtk_widget_show (menubar->priv->applications_item);
216
146
menubar->priv->places_item = panel_place_menu_item_new (FALSE);
217
147
gtk_menu_shell_append (GTK_MENU_SHELL (menubar),
218
148
menubar->priv->places_item);
220
menubar->priv->desktop_item = panel_desktop_menu_item_new (FALSE, TRUE);
221
gtk_menu_shell_append (GTK_MENU_SHELL (menubar),
222
menubar->priv->desktop_item);
149
gtk_widget_show (menubar->priv->places_item);
224
151
panel_menu_bar_setup_tooltip (menubar);
226
panel_menu_bar_update_text_gravity (menubar);
227
g_signal_connect (menubar, "screen-changed",
228
G_CALLBACK (panel_menu_bar_update_text_gravity),
233
panel_menu_bar_get_property (GObject *object,
238
PanelMenuBar *menubar;
240
g_return_if_fail (PANEL_IS_MENU_BAR (object));
242
menubar = PANEL_MENU_BAR (object);
245
case PROP_ORIENTATION:
246
g_value_set_enum (value, menubar->priv->orientation);
249
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
255
panel_menu_bar_set_property (GObject *object,
260
PanelMenuBar *menubar;
262
g_return_if_fail (PANEL_IS_MENU_BAR (object));
264
menubar = PANEL_MENU_BAR (object);
267
case PROP_ORIENTATION:
268
panel_menu_bar_set_orientation (menubar, g_value_get_enum (value));
271
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
292
170
if (menubar->priv->places_item)
293
171
panel_place_menu_item_set_panel (menubar->priv->places_item,
294
172
menubar->priv->panel);
295
if (menubar->priv->desktop_item)
296
panel_desktop_menu_item_set_panel (menubar->priv->desktop_item,
297
menubar->priv->panel);
301
panel_menu_bar_size_allocate (GtkWidget *widget,
302
GtkAllocation *allocation)
176
panel_menu_bar_style_updated (GtkWidget *widget)
304
GtkAllocation old_allocation;
305
GtkAllocation widget_allocation;
306
PanelBackground *background;
308
gtk_widget_get_allocation (widget, &widget_allocation);
310
old_allocation.x = widget_allocation.x;
311
old_allocation.y = widget_allocation.y;
312
old_allocation.width = widget_allocation.width;
313
old_allocation.height = widget_allocation.height;
315
GTK_WIDGET_CLASS (panel_menu_bar_parent_class)->size_allocate (widget, allocation);
317
if (old_allocation.x == allocation->x &&
318
old_allocation.y == allocation->y &&
319
old_allocation.width == allocation->width &&
320
old_allocation.height == allocation->height)
323
background = &PANEL_MENU_BAR (widget)->priv->panel->background;
325
if (background->type == PANEL_BACK_NONE ||
326
(background->type == PANEL_BACK_COLOR && !background->has_alpha))
329
panel_menu_bar_change_background (PANEL_MENU_BAR (widget));
178
PanelMenuBar *menubar = PANEL_MENU_BAR (widget);
181
GTK_WIDGET_CLASS (panel_menu_bar_parent_class)->style_updated (widget);
183
gtk_widget_style_get (widget, "icon-visible", &visible, NULL);
186
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menubar->priv->applications_item),
187
menubar->priv->image);
189
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menubar->priv->applications_item),
333
194
panel_menu_bar_class_init (PanelMenuBarClass *klass)
335
GObjectClass *gobject_class = (GObjectClass *) klass;
336
196
GtkWidgetClass *widget_class = (GtkWidgetClass *) klass;
338
gobject_class->get_property = panel_menu_bar_get_property;
339
gobject_class->set_property = panel_menu_bar_set_property;
341
198
widget_class->parent_set = panel_menu_bar_parent_set;
342
widget_class->size_allocate = panel_menu_bar_size_allocate;
199
widget_class->style_updated = panel_menu_bar_style_updated;
344
201
g_type_class_add_private (klass, sizeof (PanelMenuBarPrivate));
346
g_object_class_install_property (
349
g_param_spec_enum ("orientation",
351
"The PanelMenuBar orientation",
352
PANEL_TYPE_ORIENTATION,
353
PANEL_ORIENTATION_TOP,
356
gtk_rc_parse_string (
357
"style \"panel-menubar-style\"\n"
359
" GtkMenuBar::shadow-type = none\n"
360
" GtkMenuBar::internal-padding = 0\n"
362
"class \"PanelMenuBar\" style \"panel-menubar-style\"");
366
panel_menu_bar_on_expose (GtkWidget *widget,
367
GdkEventExpose *event,
370
PanelMenuBar *menubar = data;
372
if (gtk_widget_has_focus (GTK_WIDGET (menubar)))
373
gtk_paint_focus (gtk_widget_get_style (widget),
374
gtk_widget_get_window (widget),
375
gtk_widget_get_state (GTK_WIDGET (menubar)),
203
gtk_widget_class_install_style_property (
205
g_param_spec_boolean ("icon-visible",
207
"Whether the menubar icon is visible",
209
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
211
if (panel_menu_bar_icon_size == 0)
212
panel_menu_bar_icon_size = gtk_icon_size_register ("panel-foobar",
213
PANEL_DEFAULT_MENU_BAR_ICON_SIZE,
214
PANEL_DEFAULT_MENU_BAR_ICON_SIZE);
384
218
panel_menu_bar_load (PanelWidget *panel,
390
222
PanelMenuBar *menubar;
394
226
menubar = g_object_new (PANEL_TYPE_MENU_BAR, NULL);
396
228
menubar->priv->info = panel_applet_register (
397
GTK_WIDGET (menubar), NULL, NULL,
398
panel, locked, position, exactpos,
399
PANEL_OBJECT_MENU_BAR, id);
229
GTK_WIDGET (menubar), panel,
230
PANEL_OBJECT_MENU_BAR, id,
400
233
if (!menubar->priv->info) {
401
234
gtk_widget_destroy (GTK_WIDGET (menubar));
238
if (panel_is_program_in_path ("alacarte") ||
239
panel_is_program_in_path ("gmenu-simple-editor")) {
240
panel_applet_add_callback (menubar->priv->info,
244
panel_lockdown_get_not_panels_locked_down_s);
405
247
panel_applet_add_callback (menubar->priv->info,
411
if (!panel_lockdown_get_locked_down () &&
412
(panel_is_program_in_path ("alacarte") ||
413
panel_is_program_in_path ("gmenu-simple-editor"))) {
414
panel_applet_add_callback (menubar->priv->info,
421
g_signal_connect_after (menubar, "focus-in-event",
422
G_CALLBACK (gtk_widget_queue_draw), menubar);
423
g_signal_connect_after (menubar, "focus-out-event",
424
G_CALLBACK (gtk_widget_queue_draw), menubar);
425
g_signal_connect_after (menubar, "expose-event",
426
G_CALLBACK (panel_menu_bar_on_expose), menubar);
427
gtk_widget_set_can_focus (GTK_WIDGET (menubar), TRUE);
429
panel_widget_set_applet_expandable (panel, GTK_WIDGET (menubar), FALSE, TRUE);
433
panel_menu_bar_load_from_gconf (PanelWidget *panel,
439
panel_menu_bar_load (panel, locked, position, exactpos, id);
443
panel_menu_bar_create (PanelToplevel *toplevel,
448
id = panel_profile_prepare_object (PANEL_OBJECT_MENU_BAR, toplevel, position, FALSE);
449
panel_profile_add_to_list (PANEL_GCONF_OBJECTS, id);
253
panel_menu_bar_object_object_load_finish (PANEL_MENU_BAR_OBJECT (menubar),
258
panel_menu_bar_create (PanelToplevel *toplevel,
259
PanelObjectPackType pack_type,
262
panel_layout_object_create (PANEL_OBJECT_MENU_BAR, NULL,
263
panel_toplevel_get_id (toplevel),
264
pack_type, pack_index);
484
298
panel_menu_bar_popup_menu (PanelMenuBar *menubar,
485
299
guint32 activate_time)
488
GtkMenuShell *menu_shell;
490
301
g_return_if_fail (PANEL_IS_MENU_BAR (menubar));
492
menu = GTK_MENU (menubar->priv->applications_menu);
495
* We need to call _gtk_menu_shell_activate() here as is done in
496
* window_key_press_handler in gtkmenubar.c which pops up menu
497
* when F10 is pressed.
499
* As that function is private its code is replicated here.
501
menu_shell = GTK_MENU_SHELL (menubar);
502
if (!menu_shell->active) {
503
gtk_grab_add (GTK_WIDGET (menu_shell));
504
menu_shell->have_grab = TRUE;
505
menu_shell->active = TRUE;
507
gtk_menu_shell_select_item (menu_shell,
508
gtk_menu_get_attach_widget (menu));
512
panel_menu_bar_change_background (PanelMenuBar *menubar)
514
panel_background_change_background_on_widget (&menubar->priv->panel->background,
515
GTK_WIDGET (menubar));
519
set_item_text_gravity (GtkWidget *item)
523
PangoContext *context;
525
label = gtk_bin_get_child (GTK_BIN (item));
526
layout = gtk_label_get_layout (GTK_LABEL (label));
527
context = pango_layout_get_context (layout);
528
pango_context_set_base_gravity (context, PANGO_GRAVITY_AUTO);
532
panel_menu_bar_update_text_gravity (PanelMenuBar *menubar)
534
set_item_text_gravity (menubar->priv->applications_item);
535
set_item_text_gravity (menubar->priv->places_item);
536
set_item_text_gravity (menubar->priv->desktop_item);
540
set_item_text_angle_and_alignment (GtkWidget *item,
547
label = gtk_bin_get_child (GTK_BIN (item));
549
gtk_label_set_angle (GTK_LABEL (label), text_angle);
551
gtk_misc_set_alignment (GTK_MISC (label), xalign, yalign);
555
panel_menu_bar_update_orientation (PanelMenuBar *menubar)
557
GtkPackDirection pack_direction;
562
pack_direction = GTK_PACK_DIRECTION_LTR;
567
switch (menubar->priv->orientation) {
568
case PANEL_ORIENTATION_TOP:
569
case PANEL_ORIENTATION_BOTTOM:
571
case PANEL_ORIENTATION_LEFT:
572
pack_direction = GTK_PACK_DIRECTION_BTT;
577
case PANEL_ORIENTATION_RIGHT:
578
pack_direction = GTK_PACK_DIRECTION_TTB;
584
g_assert_not_reached ();
588
gtk_menu_bar_set_pack_direction (GTK_MENU_BAR (menubar), pack_direction);
589
gtk_menu_bar_set_child_pack_direction (GTK_MENU_BAR (menubar), pack_direction);
591
set_item_text_angle_and_alignment (menubar->priv->applications_item,
595
set_item_text_angle_and_alignment (menubar->priv->places_item,
599
set_item_text_angle_and_alignment (menubar->priv->desktop_item,
606
panel_menu_bar_set_orientation (PanelMenuBar *menubar,
607
PanelOrientation orientation)
609
g_return_if_fail (PANEL_IS_MENU_BAR (menubar));
611
if (menubar->priv->orientation == orientation)
614
menubar->priv->orientation = orientation;
616
panel_menu_bar_update_orientation (menubar);
618
g_object_notify (G_OBJECT (menubar), "orientation");
622
panel_menu_bar_get_orientation (PanelMenuBar *menubar)
624
g_return_val_if_fail (PANEL_IS_MENU_BAR (menubar), 0);
626
return menubar->priv->orientation;
303
gtk_menu_shell_select_item (GTK_MENU_SHELL (menubar),
304
menubar->priv->applications_item);