30
30
#include <glib/gi18n.h>
32
#include <gconf/gconf.h>
33
32
#include <gdk/gdk.h>
34
33
#include <gdk/gdkx.h>
36
35
#include "panel-applets-manager.h"
37
#include "panel-profile.h"
36
#include "panel-bindings.h"
39
38
#include "applet.h"
40
39
#include "panel-marshal.h"
41
40
#include "panel-background.h"
41
#include "panel-layout.h"
42
42
#include "panel-lockdown.h"
43
#include "panel-object-loader.h"
44
#include "panel-schemas.h"
43
45
#include "panel-stock-icons.h"
44
46
#include "xstuff.h"
45
47
#include "panel-compatibility.h"
90
87
guint has_handle : 1;
94
panel_applet_frame_paint (GtkWidget *widget,
91
panel_applet_frame_draw (GtkWidget *widget,
97
PanelAppletFrame *frame;
94
PanelAppletFrame *frame = PANEL_APPLET_FRAME (widget);
95
GtkStyleContext *context;
99
frame = PANEL_APPLET_FRAME (widget);
97
if (GTK_WIDGET_CLASS (panel_applet_frame_parent_class)->draw)
98
GTK_WIDGET_CLASS (panel_applet_frame_parent_class)->draw (widget, cr);
101
100
if (!frame->priv->has_handle)
104
if (gtk_widget_is_drawable (widget)) {
105
GtkOrientation orientation = GTK_ORIENTATION_HORIZONTAL;
107
switch (frame->priv->orientation) {
108
case PANEL_ORIENTATION_TOP:
109
case PANEL_ORIENTATION_BOTTOM:
110
orientation = GTK_ORIENTATION_VERTICAL;
112
case PANEL_ORIENTATION_LEFT:
113
case PANEL_ORIENTATION_RIGHT:
114
orientation = GTK_ORIENTATION_HORIZONTAL;
117
g_assert_not_reached ();
122
gtk_widget_get_style (widget), gtk_widget_get_window (widget),
123
gtk_widget_get_state (widget),
125
area, widget, "handlebox",
126
frame->priv->handle_rect.x,
127
frame->priv->handle_rect.y,
128
frame->priv->handle_rect.width,
129
frame->priv->handle_rect.height,
135
panel_applet_frame_expose (GtkWidget *widget,
136
GdkEventExpose *event)
138
if (gtk_widget_is_drawable (widget)) {
139
GTK_WIDGET_CLASS (panel_applet_frame_parent_class)->expose_event (widget, event);
141
panel_applet_frame_paint (widget, &event->area);
103
context = gtk_widget_get_style_context (widget);
104
gtk_style_context_save (context);
105
gtk_style_context_set_state (context, gtk_widget_get_state_flags (widget));
109
frame->priv->handle_rect.x,
110
frame->priv->handle_rect.y,
111
frame->priv->handle_rect.width,
112
frame->priv->handle_rect.height);
114
gtk_render_handle (context, cr,
116
gtk_widget_get_allocated_width (widget),
117
gtk_widget_get_allocated_height (widget));
120
gtk_style_context_restore (context);
170
panel_applet_frame_size_request (GtkWidget *widget,
171
GtkRequisition *requisition)
173
PanelAppletFrame *frame;
176
GtkRequisition child_requisition;
179
frame = PANEL_APPLET_FRAME (widget);
180
bin = GTK_BIN (widget);
182
if (!frame->priv->has_handle) {
183
GTK_WIDGET_CLASS (panel_applet_frame_parent_class)->size_request (widget, requisition);
187
child = gtk_bin_get_child (bin);
188
if (child && gtk_widget_get_visible (child)) {
189
gtk_widget_size_request (child, &child_requisition);
191
requisition->width = child_requisition.width;
192
requisition->height = child_requisition.height;
195
border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
196
requisition->width += border_width;
197
requisition->height += border_width;
199
switch (frame->priv->orientation) {
200
case PANEL_ORIENTATION_TOP:
201
case PANEL_ORIENTATION_BOTTOM:
202
requisition->width += HANDLE_SIZE;
204
case PANEL_ORIENTATION_LEFT:
205
case PANEL_ORIENTATION_RIGHT:
206
requisition->height += HANDLE_SIZE;
148
panel_applet_frame_get_preferred_width(GtkWidget *widget, gint *minimal_width, gint *natural_width)
150
PanelAppletFrame *frame;
155
frame = PANEL_APPLET_FRAME (widget);
156
bin = GTK_BIN (widget);
158
if (!frame->priv->has_handle) {
159
GTK_WIDGET_CLASS (panel_applet_frame_parent_class)->get_preferred_width (widget, minimal_width, natural_width);
163
child = gtk_bin_get_child (bin);
164
if (child && gtk_widget_get_visible (child))
165
gtk_widget_get_preferred_width (child, minimal_width, natural_width);
167
border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
168
*minimal_width += border_width;
169
*natural_width += border_width;
171
switch (frame->priv->orientation) {
172
case PANEL_ORIENTATION_TOP:
173
case PANEL_ORIENTATION_BOTTOM:
174
*minimal_width += HANDLE_SIZE;
175
*natural_width += HANDLE_SIZE;
177
case PANEL_ORIENTATION_LEFT:
178
case PANEL_ORIENTATION_RIGHT:
181
g_assert_not_reached ();
187
panel_applet_frame_get_preferred_height(GtkWidget *widget, gint *minimal_height, gint *natural_height)
189
PanelAppletFrame *frame;
194
frame = PANEL_APPLET_FRAME (widget);
195
bin = GTK_BIN (widget);
197
if (!frame->priv->has_handle) {
198
GTK_WIDGET_CLASS (panel_applet_frame_parent_class)->get_preferred_height (widget, minimal_height, natural_height);
202
child = gtk_bin_get_child (bin);
203
if (child && gtk_widget_get_visible (child))
204
gtk_widget_get_preferred_height (child, minimal_height, natural_height);
206
border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
207
*minimal_height += border_width;
208
*natural_height += border_width;
210
switch (frame->priv->orientation) {
211
case PANEL_ORIENTATION_LEFT:
212
case PANEL_ORIENTATION_RIGHT:
213
*minimal_height += HANDLE_SIZE;
214
*natural_height += HANDLE_SIZE;
216
case PANEL_ORIENTATION_TOP:
217
case PANEL_ORIENTATION_BOTTOM:
209
220
g_assert_not_reached ();
345
360
if (event->window != gtk_widget_get_window (widget))
363
modifiers = event->state & gtk_accelerator_get_default_mod_mask ();
348
365
switch (event->button) {
351
368
if (button_event_in_rect (event, &frame->priv->handle_rect)) {
352
if (event->type == GDK_BUTTON_PRESS ||
353
event->type == GDK_2BUTTON_PRESS) {
369
if ((event->type == GDK_BUTTON_PRESS ||
370
event->type == GDK_2BUTTON_PRESS) &&
371
modifiers == panel_bindings_get_mouse_button_modifier_keymask ()){
354
372
panel_widget_applet_drag_start (
355
373
frame->priv->panel, GTK_WIDGET (frame),
356
PW_DRAG_OFF_CURSOR, event->time);
358
376
} else if (event->type == GDK_BUTTON_RELEASE) {
359
377
panel_widget_applet_drag_end (frame->priv->panel);
365
383
if (event->type == GDK_BUTTON_PRESS ||
366
384
event->type == GDK_2BUTTON_PRESS) {
367
gdk_pointer_ungrab (GDK_CURRENT_TIME);
385
display = gtk_widget_get_display (widget);
386
device_manager = gdk_display_get_device_manager (display);
387
pointer = gdk_device_manager_get_client_pointer (device_manager);
388
gdk_device_ungrab (pointer, GDK_CURRENT_TIME);
369
PANEL_APPLET_FRAME_GET_CLASS (frame)->popup_menu (frame,
390
if (modifiers == panel_bindings_get_mouse_button_modifier_keymask ())
391
PANEL_APPLET_FRAME_GET_CLASS (frame)->popup_edit_menu (frame,
395
PANEL_APPLET_FRAME_GET_CLASS (frame)->popup_menu (frame,
374
400
} else if (event->type == GDK_BUTTON_RELEASE)
406
429
gobject_class->finalize = panel_applet_frame_finalize;
408
widget_class->expose_event = panel_applet_frame_expose;
409
widget_class->size_request = panel_applet_frame_size_request;
431
widget_class->draw = panel_applet_frame_draw;
432
widget_class->get_preferred_width = panel_applet_frame_get_preferred_width;
433
widget_class->get_preferred_height = panel_applet_frame_get_preferred_height;
410
434
widget_class->size_allocate = panel_applet_frame_size_allocate;
411
435
widget_class->button_press_event = panel_applet_frame_button_changed;
412
436
widget_class->button_release_event = panel_applet_frame_button_changed;
431
455
PANEL_APPLET_FRAME_GET_CLASS (frame)->init_properties (frame);
435
panel_applet_frame_sync_menu_state (PanelAppletFrame *frame)
459
panel_applet_frame_sync_menu_state (PanelLockdown *lockdown,
437
PanelWidget *panel_widget;
438
gboolean locked_down;
462
PanelAppletFrame *frame = PANEL_APPLET_FRAME (user_data);
463
PanelWidget *panel_widget;
464
gboolean locked_down;
444
468
panel_widget = PANEL_WIDGET (gtk_widget_get_parent (GTK_WIDGET (frame)));
446
470
movable = panel_applet_can_freely_move (frame->priv->applet_info);
447
removable = panel_profile_id_lists_are_writable ();
448
lockable = panel_applet_lockable (frame->priv->applet_info);
450
locked = panel_widget_get_applet_locked (panel_widget, GTK_WIDGET (frame));
451
locked_down = panel_lockdown_get_locked_down ();
453
PANEL_APPLET_FRAME_GET_CLASS (frame)->sync_menu_state (frame, movable, removable, lockable, locked, locked_down);
471
removable = panel_layout_is_writable ();
472
locked_down = panel_lockdown_get_panels_locked_down_s ();
474
PANEL_APPLET_FRAME_GET_CLASS (frame)->sync_menu_state (frame, movable, removable, locked_down);
539
560
frame->priv->panel = frame_act->panel;
540
561
gtk_widget_show_all (GTK_WIDGET (frame));
542
info = panel_applet_register (GTK_WIDGET (frame), GTK_WIDGET (frame),
543
NULL, frame->priv->panel,
544
frame_act->locked, frame_act->position,
545
frame_act->exactpos, PANEL_OBJECT_APPLET,
563
info = panel_applet_register (GTK_WIDGET (frame), frame->priv->panel,
564
PANEL_OBJECT_APPLET, frame_act->id,
566
GTK_WIDGET (frame), NULL);
547
567
frame->priv->applet_info = info;
549
569
panel_widget_set_applet_size_constrained (frame->priv->panel,
550
570
GTK_WIDGET (frame), TRUE);
552
panel_applet_frame_sync_menu_state (frame);
573
panel_lockdown_on_notify (panel_lockdown_get (),
576
panel_applet_frame_sync_menu_state,
578
panel_applet_frame_sync_menu_state (panel_lockdown_get (), frame);
553
580
panel_applet_frame_init_properties (frame);
555
panel_lockdown_notify_add (G_CALLBACK (panel_applet_frame_sync_menu_state),
558
panel_applet_stop_loading (frame_act->id);
582
panel_object_loader_stop_loading (frame_act->id);
559
583
panel_applet_frame_activating_free (frame_act);
659
683
PanelWidget *panel;
663
gboolean locked = FALSE;
686
GSettings *settings = NULL;
665
688
panel = frame->priv->panel;
666
689
iid = g_strdup (frame->priv->iid);
669
692
id = g_strdup (info->id);
670
position = panel_applet_get_position (info);
671
locked = panel_widget_get_applet_locked (panel, info->widget);
693
settings = panel_applet_get_settings (info);
694
g_object_ref (settings);
672
695
panel_applet_clean (info);
675
panel_applet_frame_load (iid, panel, locked,
698
panel_applet_frame_load_helper (iid, panel, id, settings);
703
g_object_unref (settings);
681
705
} else if (info) {
682
706
/* if we can't write to applets list we can't really delete
683
707
it, so we'll just ignore this. FIXME: handle this
684
708
more correctly I suppose. */
685
if (panel_profile_id_lists_are_writable ())
686
panel_profile_delete_object (info);
709
if (panel_layout_is_writable ())
710
panel_layout_delete_object (panel_applet_get_id (info));
689
713
g_object_unref (frame);
827
panel_applet_frame_activating_get_locked (PanelAppletFrameActivating *frame_act)
829
return frame_act->locked;
833
839
panel_applet_frame_activating_get_locked_down (PanelAppletFrameActivating *frame_act)
835
return panel_lockdown_get_locked_down ();
841
return panel_lockdown_get_panels_locked_down_s ();
845
panel_applet_frame_activating_get_settings_path (PanelAppletFrameActivating *frame_act)
850
g_object_get (frame_act->settings, "path", &path, NULL);
851
path_instance = g_strdup_printf ("%s%s", path,
852
PANEL_LAYOUT_OBJECT_CONFIG_SUFFIX);
855
return path_instance;
839
859
panel_applet_frame_activating_get_conf_path (PanelAppletFrameActivating *frame_act)
841
return g_strdup_printf (PANEL_APPLET_PREFS_KEY, frame_act->id);
861
return panel_layout_object_get_gconf_path (frame_act->id);
944
962
if (g_slist_find_custom (no_reload_applets, id,
945
963
(GCompareFunc) strcmp)) {
946
panel_applet_stop_loading (id);
964
panel_object_loader_stop_loading (id);
950
if (panel_lockdown_is_applet_disabled (iid)) {
951
panel_applet_stop_loading (id);
968
if (panel_lockdown_is_applet_disabled (panel_lockdown_get (), iid)) {
969
panel_object_loader_stop_loading (id);
955
973
frame_act = g_slice_new0 (PanelAppletFrameActivating);
956
frame_act->locked = locked;
957
974
frame_act->panel = panel;
958
frame_act->position = position;
959
frame_act->exactpos = exactpos;
960
975
frame_act->id = g_strdup (id);
976
frame_act->settings = g_object_ref (settings);
962
978
if (!panel_applets_manager_load_applet (iid, frame_act)) {
963
979
panel_applet_frame_loading_failed (iid, panel, id);
969
panel_applet_frame_load_from_gconf (PanelWidget *panel_widget,
985
panel_applet_frame_load (PanelWidget *panel_widget,
974
989
gchar *applet_iid;
976
991
g_return_if_fail (panel_widget != NULL);
977
992
g_return_if_fail (id != NULL);
979
applet_iid = panel_compatibility_get_applet_iid (id);
994
applet_iid = panel_compatibility_get_applet_iid (settings, id);
980
995
if (!applet_iid) {
981
panel_applet_stop_loading (id);
996
panel_object_loader_stop_loading (id);
985
panel_applet_frame_load (applet_iid, panel_widget,
986
locked, position, TRUE, id);
1000
panel_applet_frame_load_helper (applet_iid, panel_widget, id, settings);
988
1002
g_free (applet_iid);
992
panel_applet_frame_create (PanelToplevel *toplevel,
1006
panel_applet_frame_create (PanelToplevel *toplevel,
1007
PanelObjectPackType pack_type,
1000
1011
g_return_if_fail (iid != NULL);
1002
client = panel_gconf_get_client ();
1004
id = panel_profile_prepare_object (PANEL_OBJECT_APPLET, toplevel, position, FALSE);
1006
key = panel_gconf_full_key (PANEL_GCONF_APPLETS, id, "applet_iid");
1007
gconf_client_set_string (client, key, iid, NULL);
1009
panel_profile_add_to_list (PANEL_GCONF_APPLETS, id);
1014
/** \brief Gets the IID for a panel applet frame
1015
\param frame Applet frame
1016
\return The IID of the applet or NULL on error
1019
panel_applet_frame_get_iid (PanelAppletFrame * frame)
1021
g_return_val_if_fail (PANEL_IS_APPLET_FRAME (frame), NULL);
1023
return frame->priv->iid;
1013
panel_layout_object_create (PANEL_OBJECT_APPLET,
1015
panel_toplevel_get_id (toplevel),
1016
pack_type, pack_index);