~ubuntu-branches/ubuntu/oneiric/gnome-panel/oneiric

« back to all changes in this revision

Viewing changes to bonobo/libpanel-applet/panel-applet.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher, Sebastien Bacher, Jeremy Bicha
  • Date: 2011-05-30 11:04:49 UTC
  • mfrom: (1.13.10 upstream) (2.2.5 experimental)
  • Revision ID: james.westby@ubuntu.com-20110530110449-hinl17kxkcefjw6x
Tags: 1:3.0.2-0ubuntu1
[ Sebastien Bacher ]
* New upstream version
* debian/control.in:
  - the new libgweather version is in oneiric, use it
  - drop the python and python-gconf depends, 
    they were added for gnome-panel-add which is still using gconf and buggy
* debian/gnome-panel-data.install:
  - don't install the apport hook, it's only getting gconf datas which 
    doesn't work since gnome-panel uses gsettings
* debian/patches/90_build_fixes.patch:
  - restore build fix from git not applied in the new serie
* debian/patches/01_panel_submenus.patch:
  - don't take that Debian diff, the .menus use the upstream naming in Ubuntu
* debian/patches/06_no_resize_grip.patch:
  - dropped, the issue is fixed in the new version
* debian/patches/50_fix-potfiles.patch:
  - dropped, the issue is fixed in the new version
* debian/watch:
  - track unstable series as well

Drop those delta, since gnome-panel is not the default Ubuntu session now we
can go back to an experience closer to the upstream one: 
* debian/control.in:
  - drop the indicators recommends, unity-2d is the ubuntu fallback session
    so we can get back to use an upstream config for gnome-panel and reduce
    the delta we carry
* debian/patches/04_default_panel_config.patch:
  - don't modify the upstream layout
* debian/patches/05_no_session_delay.patch:
  - no need to tweak the upstream session to optimize it
* debian/patches/16_compiz_workspace_switcher.patch:
  - go back to the upstream switcher behaviour    
* debian/patches/25_dynamic_fusa_detection.patch:
  - not needed since we use the upstream layout, could be ported if someone
    is wanting to do the work though
* debian/patches/30_disable-initial-animation.patch, debian/rules:
  - drop the --disable-initial-animation, that was some login optimization
    but since it's not the default desktop you should go back to the 
    upstream behaviour

[ Jeremy Bicha ]   
* New upstream version
* Merge from Debian experimental, remaining Ubuntu changes:
* debian/control:
  - Recommends gnome-settings-daemon which has the timezone polkit service
* debian/rules:
  - Update translations template.
* debian/gnome-panel-data.install:
  - Install apport hook
  - Install the "About Ubuntu" menu item.
* debian/patches/01_layout.patch:
  - Disabled, Help & About Ubuntu don't fit as well in Gnome Panel 3
* debian/patches/01_panel_submenus.patch.
  - Dropped
* debian/patches/03_dnd_places_link.patch:
  - Disabled, when using Drag'n'Drop from Places menu, install a link launcher
    (.desktop file) instead of copying the entire directory.
* debian/patches/17_about-ubuntu-translation.patch:
  - List ubuntu-about.desktop for translation.
* debian/patches/40_unset_menuproxy.patch:
  - Make sure gnome-panel and the applets don't pick up menu proxies.
* debian/patches/50_fix-potfiles.patch
  - Fix i18n
* debian/patches/85_disable_shutdown_on_ltsp.patch:
  - Suppress the shutdown option in the panel if LTSP_CLIENT is set.
* debian/patches/71_change_bookmark_submenu_limit_value.patch
  - Dropped, picked up by Debian
* debian/patches/18_lockdown_lock_editor.patch:
* debian/patches/90_git_wnck_show_realize.patch:
* debian/patches/90_fix_linking_DSO_link.patch:
* debian/patches/91_gir_annotations.patch
* debian/patches/92_git_calendar_day.patch
* debian/patches/92_git_fix_applets_in_multiscreen.patch:
  - Dropped, applied upstream
* debian/watch:
  - watch unstable versions

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * panel-applet.c: panel applet writing library.
3
 
 *
4
 
 * Copyright (C) 2001 Sun Microsystems, Inc.
5
 
 *
6
 
 * This library is free software; you can redistribute it and/or
7
 
 * modify it under the terms of the GNU Library General Public
8
 
 * License as published by the Free Software Foundation; either
9
 
 * version 2 of the License, or (at your option) any later version.
10
 
 *
11
 
 * This library is distributed in the hope that it will be useful,
12
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
 
 * Library General Public License for more details.
15
 
 *
16
 
 * You should have received a copy of the GNU Library General Public
17
 
 * License along with this library; if not, write to the
18
 
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19
 
 * Boston, MA 02111-1307, USA.
20
 
 *
21
 
 * Authors:
22
 
 *     Mark McLoughlin <mark@skynet.ie>
23
 
 */
24
 
 
25
 
#ifdef HAVE_CONFIG_H
26
 
#include <config.h>
27
 
#endif
28
 
 
29
 
#include <unistd.h>
30
 
#include <stdlib.h>
31
 
#include <string.h>
32
 
 
33
 
#include <cairo.h>
34
 
#include <gdk/gdk.h>
35
 
#include <gdk/gdkx.h>
36
 
#include <gdk/gdkkeysyms.h>
37
 
#include <gtk/gtk.h>
38
 
#include <bonobo/bonobo-ui-util.h>
39
 
#include <bonobo/bonobo-main.h>
40
 
#include <bonobo/bonobo-types.h>
41
 
#include <bonobo/bonobo-property-bag.h>
42
 
#include <bonobo/bonobo-item-handler.h>
43
 
#include <bonobo/bonobo-shlib-factory.h>
44
 
#include <bonobo/bonobo-property-bag-client.h>
45
 
#include <gconf/gconf.h>
46
 
#include <gconf/gconf-client.h>
47
 
#include <X11/Xatom.h>
48
 
 
49
 
#include "panel-applet.h"
50
 
#include "panel-applet-private.h"
51
 
#include "panel-applet-shell.h"
52
 
#include "panel-applet-marshal.h"
53
 
#include "panel-applet-enums.h"
54
 
 
55
 
#define PANEL_APPLET_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), PANEL_TYPE_APPLET, PanelAppletPrivate))
56
 
 
57
 
struct _PanelAppletPrivate {
58
 
        PanelAppletShell           *shell;
59
 
        BonoboControl              *control;
60
 
        BonoboPropertyBag          *prop_sack;
61
 
        BonoboItemHandler          *item_handler;
62
 
        GConfClient                *client;
63
 
 
64
 
        char                       *iid;
65
 
        GClosure                   *closure;
66
 
        gboolean                    bound;
67
 
        char                       *prefs_key;
68
 
 
69
 
        PanelAppletFlags            flags;
70
 
        PanelAppletOrient           orient;
71
 
        guint                       size;
72
 
        char                       *background;
73
 
        GtkWidget                  *background_widget;
74
 
 
75
 
        int                         previous_width;
76
 
        int                         previous_height;
77
 
 
78
 
        int                        *size_hints;
79
 
        int                         size_hints_len;
80
 
 
81
 
        gboolean                    moving_focus_out;
82
 
 
83
 
        gboolean                    locked_down;
84
 
};
85
 
 
86
 
enum {
87
 
        CHANGE_ORIENT,
88
 
        CHANGE_SIZE,
89
 
        CHANGE_BACKGROUND,
90
 
        MOVE_FOCUS_OUT_OF_APPLET,
91
 
        SAVE_YOURSELF,
92
 
        LAST_SIGNAL
93
 
};
94
 
 
95
 
static guint panel_applet_signals [LAST_SIGNAL];
96
 
 
97
 
#define PROPERTY_ORIENT     "panel-applet-orient"
98
 
#define PROPERTY_SIZE       "panel-applet-size"
99
 
#define PROPERTY_BACKGROUND "panel-applet-background"
100
 
#define PROPERTY_FLAGS      "panel-applet-flags"
101
 
#define PROPERTY_SIZE_HINTS "panel-applet-size-hints"
102
 
#define PROPERTY_LOCKED_DOWN "panel-applet-locked-down"
103
 
 
104
 
enum {
105
 
        PROPERTY_ORIENT_IDX,
106
 
        PROPERTY_SIZE_IDX,
107
 
        PROPERTY_BACKGROUND_IDX,
108
 
        PROPERTY_FLAGS_IDX,
109
 
        PROPERTY_SIZE_HINTS_IDX,
110
 
        PROPERTY_LOCKED_DOWN_IDX
111
 
};
112
 
 
113
 
G_DEFINE_TYPE (PanelApplet, panel_applet, GTK_TYPE_EVENT_BOX)
114
 
 
115
 
static void panel_applet_handle_background (PanelApplet *applet);
116
 
static void panel_applet_setup             (PanelApplet *applet);
117
 
 
118
 
static void
119
 
panel_applet_associate_schemas_in_dir (GConfClient  *client,
120
 
                                       const gchar  *prefs_key,
121
 
                                       const gchar  *schema_dir,
122
 
                                       GError      **error)
123
 
{
124
 
        GSList *list, *l;
125
 
 
126
 
        list = gconf_client_all_entries (client, schema_dir, error);
127
 
 
128
 
        if (*error != NULL)
129
 
                return;
130
 
 
131
 
        for (l = list; l; l = l->next) {
132
 
                GConfEntry  *entry = l->data;
133
 
                const gchar *schema_key;
134
 
                GConfEntry  *applet_entry;
135
 
                const gchar *applet_schema_key;
136
 
                gchar       *key;
137
 
                gchar       *tmp;
138
 
 
139
 
                schema_key = gconf_entry_get_key (entry);
140
 
                tmp = g_path_get_basename (schema_key);
141
 
 
142
 
                if (strchr (tmp, '-'))
143
 
                        g_warning ("Applet key '%s' contains a hyphen. Please "
144
 
                                   "use underscores in gconf keys\n", tmp);
145
 
 
146
 
                key = g_strdup_printf ("%s/%s", prefs_key, tmp);
147
 
                g_free (tmp);
148
 
 
149
 
                /* Associating a schema is potentially expensive, so let's try
150
 
                 * to avoid this by doing it only when needed. So we check if
151
 
                 * the key is already correctly associated. */
152
 
 
153
 
                applet_entry = gconf_client_get_entry (client, key,
154
 
                                                       NULL, TRUE, NULL);
155
 
                if (applet_entry)
156
 
                        applet_schema_key = gconf_entry_get_schema_name (applet_entry);
157
 
                else
158
 
                        applet_schema_key = NULL;
159
 
 
160
 
                if (g_strcmp0 (schema_key, applet_schema_key) != 0) {
161
 
                        gconf_engine_associate_schema (client->engine,
162
 
                                                       key, schema_key, error);
163
 
 
164
 
                        if (applet_entry == NULL ||
165
 
                            gconf_entry_get_value (applet_entry) == NULL ||
166
 
                            gconf_entry_get_is_default (applet_entry)) {
167
 
                                /* unset the key: gconf_client_get_entry()
168
 
                                 * brought an invalid entry in the client
169
 
                                 * cache, and we want to fix this */
170
 
                                gconf_client_unset (client, key, NULL);
171
 
                        }
172
 
                }
173
 
 
174
 
                g_free (key);
175
 
 
176
 
                if (applet_entry)
177
 
                        gconf_entry_unref (applet_entry);
178
 
                gconf_entry_unref (entry);
179
 
 
180
 
                if (*error) {
181
 
                        g_slist_free (list);
182
 
                        return;
183
 
                }
184
 
        }
185
 
 
186
 
        g_slist_free (list);
187
 
 
188
 
        list = gconf_client_all_dirs (client, schema_dir, error);
189
 
 
190
 
        for (l = list; l; l = l->next) {
191
 
                gchar *subdir = l->data;
192
 
                gchar *prefs_subdir;
193
 
                gchar *schema_subdir;
194
 
                gchar *tmp;
195
 
 
196
 
                tmp = g_path_get_basename (subdir);
197
 
 
198
 
                prefs_subdir  = g_strdup_printf ("%s/%s", prefs_key, tmp);
199
 
                schema_subdir = g_strdup_printf ("%s/%s", schema_dir, tmp);
200
 
 
201
 
                panel_applet_associate_schemas_in_dir (client,
202
 
                                                       prefs_subdir,
203
 
                                                       schema_subdir,
204
 
                                                       error);
205
 
 
206
 
                g_free (prefs_subdir);
207
 
                g_free (schema_subdir);
208
 
                g_free (subdir);
209
 
                g_free (tmp);
210
 
 
211
 
                if (*error) {
212
 
                        g_slist_free (list);
213
 
                        return;
214
 
                }
215
 
        }
216
 
 
217
 
        g_slist_free (list);
218
 
}
219
 
 
220
 
void
221
 
panel_applet_add_preferences (PanelApplet  *applet,
222
 
                              const gchar  *schema_dir,
223
 
                              GError      **opt_error)
224
 
{
225
 
        GError **error = NULL;
226
 
        GError  *our_error = NULL;
227
 
 
228
 
        g_return_if_fail (PANEL_IS_APPLET (applet));
229
 
        g_return_if_fail (schema_dir != NULL);
230
 
 
231
 
        if (!applet->priv->prefs_key)
232
 
                return;
233
 
 
234
 
        if (opt_error)
235
 
                error = opt_error;
236
 
        else
237
 
                error = &our_error;
238
 
 
239
 
        panel_applet_associate_schemas_in_dir (applet->priv->client,
240
 
                                               applet->priv->prefs_key,
241
 
                                               schema_dir,
242
 
                                               error);
243
 
 
244
 
        if (!opt_error && our_error) {
245
 
                g_warning (G_STRLOC ": failed to add preferences from '%s' : '%s'",
246
 
                           schema_dir, our_error->message);
247
 
                g_error_free (our_error);
248
 
        }
249
 
}
250
 
 
251
 
char *
252
 
panel_applet_get_preferences_key (PanelApplet *applet)
253
 
{
254
 
        g_return_val_if_fail (PANEL_IS_APPLET (applet), NULL);
255
 
 
256
 
        if (!applet->priv->prefs_key)
257
 
                return NULL;
258
 
 
259
 
        return g_strdup (applet->priv->prefs_key);
260
 
}
261
 
 
262
 
static void
263
 
panel_applet_set_preferences_key (PanelApplet *applet,
264
 
                                  const char  *prefs_key)
265
 
{
266
 
        g_return_if_fail (PANEL_IS_APPLET (applet));
267
 
 
268
 
        if (applet->priv->prefs_key) {
269
 
                gconf_client_remove_dir (applet->priv->client,
270
 
                                         applet->priv->prefs_key,
271
 
                                         NULL);
272
 
 
273
 
                g_free (applet->priv->prefs_key);
274
 
                applet->priv->prefs_key = NULL;
275
 
        }
276
 
 
277
 
        if (prefs_key) {
278
 
                applet->priv->prefs_key = g_strdup (prefs_key);
279
 
 
280
 
                gconf_client_add_dir (applet->priv->client,
281
 
                                      applet->priv->prefs_key,
282
 
                                      GCONF_CLIENT_PRELOAD_RECURSIVE,
283
 
                                      NULL);
284
 
        }
285
 
}
286
 
 
287
 
PanelAppletFlags
288
 
panel_applet_get_flags (PanelApplet *applet)
289
 
{
290
 
        g_return_val_if_fail (PANEL_IS_APPLET (applet), PANEL_APPLET_FLAGS_NONE);
291
 
 
292
 
        return applet->priv->flags;
293
 
}
294
 
 
295
 
void
296
 
panel_applet_set_flags (PanelApplet      *applet,
297
 
                        PanelAppletFlags  flags)
298
 
{
299
 
        g_return_if_fail (PANEL_IS_APPLET (applet));
300
 
 
301
 
        if (applet->priv->prop_sack != NULL)
302
 
                bonobo_pbclient_set_short (BONOBO_OBJREF (applet->priv->prop_sack), PROPERTY_FLAGS, flags, NULL);
303
 
        else
304
 
                applet->priv->flags = flags;
305
 
}
306
 
 
307
 
void
308
 
panel_applet_set_size_hints (PanelApplet      *applet,
309
 
                             const int        *size_hints,
310
 
                             int               n_elements,
311
 
                             int               base_size)
312
 
{
313
 
        CORBA_sequence_CORBA_long *seq;
314
 
        CORBA_Environment          env;
315
 
        CORBA_any                  any;
316
 
        int                        i;
317
 
 
318
 
        CORBA_exception_init (&env);
319
 
 
320
 
        seq = CORBA_sequence_CORBA_long__alloc ();
321
 
        seq->_length = seq->_maximum = n_elements;
322
 
        seq->_release = CORBA_TRUE;
323
 
        seq->_buffer  = CORBA_sequence_CORBA_long_allocbuf (seq->_length);
324
 
 
325
 
        for (i = 0; i < n_elements; i++)
326
 
                seq->_buffer [i] = size_hints [i] + base_size;
327
 
 
328
 
        any._type    = TC_CORBA_sequence_CORBA_long;
329
 
        any._release = CORBA_FALSE;
330
 
        any._value   = seq;
331
 
 
332
 
        Bonobo_PropertyBag_setValue (BONOBO_OBJREF (applet->priv->prop_sack),
333
 
                                     PROPERTY_SIZE_HINTS,
334
 
                                     &any,
335
 
                                     &env);
336
 
 
337
 
        CORBA_free (seq);
338
 
 
339
 
        CORBA_exception_free (&env);
340
 
}
341
 
 
342
 
guint
343
 
panel_applet_get_size (PanelApplet *applet)
344
 
{
345
 
        g_return_val_if_fail (PANEL_IS_APPLET (applet), 0);
346
 
 
347
 
        return applet->priv->size;
348
 
}
349
 
 
350
 
PanelAppletOrient
351
 
panel_applet_get_orient (PanelApplet *applet)
352
 
{
353
 
        g_return_val_if_fail (PANEL_IS_APPLET (applet), 0);
354
 
 
355
 
        return applet->priv->orient;
356
 
}
357
 
 
358
 
gboolean
359
 
panel_applet_get_locked_down (PanelApplet *applet)
360
 
{
361
 
        g_return_val_if_fail (PANEL_IS_APPLET (applet), FALSE);
362
 
 
363
 
        return applet->priv->locked_down;
364
 
}
365
 
 
366
 
static Atom _net_wm_window_type = None;
367
 
static Atom _net_wm_window_type_dock = None;
368
 
static Atom _net_active_window = None;
369
 
 
370
 
static void
371
 
panel_applet_init_atoms (Display *xdisplay)
372
 
{
373
 
        if (_net_wm_window_type == None)
374
 
                _net_wm_window_type = XInternAtom (xdisplay,
375
 
                                                   "_NET_WM_WINDOW_TYPE",
376
 
                                                   False);
377
 
 
378
 
        if (_net_wm_window_type_dock == None)
379
 
                _net_wm_window_type_dock = XInternAtom (xdisplay,
380
 
                                                        "_NET_WM_WINDOW_TYPE_DOCK",
381
 
                                                        False);
382
 
 
383
 
        if (_net_active_window == None)
384
 
                _net_active_window = XInternAtom (xdisplay,
385
 
                                                  "_NET_ACTIVE_WINDOW",
386
 
                                                  False);
387
 
}
388
 
 
389
 
static Window
390
 
panel_applet_find_toplevel_dock_window (PanelApplet *applet,
391
 
                                        Display     *xdisplay)
392
 
{
393
 
        GtkWidget  *toplevel;
394
 
        Window      xwin;
395
 
        Window      root, parent, *child;
396
 
        int         num_children;
397
 
 
398
 
        toplevel = gtk_widget_get_toplevel (GTK_WIDGET (applet));
399
 
        if (!gtk_widget_get_realized (toplevel))
400
 
                return None;
401
 
 
402
 
        xwin = GDK_WINDOW_XID (gtk_widget_get_window (toplevel));
403
 
 
404
 
        child = NULL;
405
 
        parent = root = None;
406
 
        do {
407
 
                Atom    type_return;
408
 
                Atom    window_type;
409
 
                int     format_return;
410
 
                gulong  number_return, bytes_after_return;
411
 
                guchar *data_return;
412
 
 
413
 
                XGetWindowProperty (xdisplay,
414
 
                                    xwin,
415
 
                                    _net_wm_window_type,
416
 
                                    0, 1, False,
417
 
                                    XA_ATOM,
418
 
                                    &type_return, &format_return,
419
 
                                    &number_return,
420
 
                                    &bytes_after_return,
421
 
                                    &data_return);
422
 
 
423
 
                if (type_return == XA_ATOM) {
424
 
                        window_type = *(Atom *) data_return;
425
 
 
426
 
                        XFree (data_return);
427
 
                        data_return = NULL;
428
 
 
429
 
                        if (window_type == _net_wm_window_type_dock)
430
 
                                return xwin;
431
 
                }
432
 
 
433
 
                if (!XQueryTree (xdisplay,
434
 
                           xwin,
435
 
                           &root, &parent, &child,
436
 
                           (guint *) &num_children)) {
437
 
                           return None;
438
 
                }
439
 
 
440
 
                if (child && num_children > 0)
441
 
                        XFree (child);
442
 
 
443
 
                xwin = parent;
444
 
 
445
 
        } while (xwin != None && xwin != root);
446
 
 
447
 
        return None;
448
 
}
449
 
 
450
 
/* This function
451
 
 *   1) Gets the window id of the panel that contains the applet
452
 
 *      using XQueryTree and XGetWindowProperty to find an ancestor
453
 
 *      window with the _NET_WM_WINDOW_TYPE_DOCK window type.
454
 
 *   2) Sends a _NET_ACTIVE_WINDOW message to get that panel focused
455
 
 */
456
 
void
457
 
panel_applet_request_focus (PanelApplet  *applet,
458
 
                            guint32       timestamp)
459
 
{
460
 
        GdkScreen  *screen;
461
 
        GdkWindow  *root;
462
 
        GdkDisplay *display;
463
 
        Display    *xdisplay;
464
 
        Window      dock_xwindow;
465
 
        Window      xroot;
466
 
        XEvent      xev;
467
 
 
468
 
        g_return_if_fail (PANEL_IS_APPLET (applet));
469
 
 
470
 
        screen  = gtk_widget_get_screen (GTK_WIDGET (applet));
471
 
        root    = gdk_screen_get_root_window (screen);
472
 
        display = gdk_screen_get_display (screen);
473
 
 
474
 
        xdisplay = GDK_DISPLAY_XDISPLAY (display);
475
 
        xroot    = GDK_WINDOW_XWINDOW (root);
476
 
 
477
 
        panel_applet_init_atoms (xdisplay);
478
 
 
479
 
        dock_xwindow = panel_applet_find_toplevel_dock_window (applet, xdisplay);
480
 
        if (dock_xwindow == None)
481
 
                return;
482
 
 
483
 
        xev.xclient.type         = ClientMessage;
484
 
        xev.xclient.serial       = 0;
485
 
        xev.xclient.send_event   = True;
486
 
        xev.xclient.window       = dock_xwindow;
487
 
        xev.xclient.message_type = _net_active_window;
488
 
        xev.xclient.format       = 32;
489
 
        xev.xclient.data.l[0]    = 1; /* requestor type; we're an app, I guess */
490
 
        xev.xclient.data.l[1]    = timestamp;
491
 
        xev.xclient.data.l[2]    = None; /* "currently active window", supposedly */
492
 
        xev.xclient.data.l[3]    = 0;
493
 
        xev.xclient.data.l[4]    = 0;
494
 
 
495
 
        XSendEvent (xdisplay,
496
 
                    xroot, False,
497
 
                    SubstructureRedirectMask | SubstructureNotifyMask,
498
 
                    &xev);
499
 
}
500
 
 
501
 
void
502
 
panel_applet_setup_menu (PanelApplet        *applet,
503
 
                         const gchar        *xml,
504
 
                         const BonoboUIVerb *verb_list,
505
 
                         gpointer            user_data)
506
 
{
507
 
        BonoboUIComponent *popup_component;
508
 
 
509
 
        g_return_if_fail (PANEL_IS_APPLET (applet));
510
 
        g_return_if_fail (xml != NULL && verb_list != NULL);
511
 
 
512
 
        popup_component = panel_applet_get_popup_component (applet);
513
 
 
514
 
        bonobo_ui_component_set (popup_component, "/", "<popups/>", NULL);
515
 
 
516
 
        bonobo_ui_component_set_translate (popup_component, "/popups", xml, NULL);
517
 
 
518
 
        bonobo_ui_component_add_verb_list_with_data (popup_component, verb_list, user_data);
519
 
}
520
 
 
521
 
void
522
 
panel_applet_setup_menu_from_file (PanelApplet        *applet,
523
 
                                   const gchar        *opt_datadir,
524
 
                                   const gchar        *file,
525
 
                                   const gchar        *opt_app_name,
526
 
                                   const BonoboUIVerb *verb_list,
527
 
                                   gpointer            user_data)
528
 
{
529
 
        BonoboUIComponent *popup_component;
530
 
        gchar             *app_name = NULL;
531
 
 
532
 
        g_return_if_fail (PANEL_IS_APPLET (applet));
533
 
        g_return_if_fail (file != NULL && verb_list != NULL);
534
 
 
535
 
        if (!opt_datadir)
536
 
                opt_datadir = PANEL_APPLET_DATADIR;
537
 
 
538
 
        if (!opt_app_name)
539
 
                opt_app_name = app_name = g_strdup_printf ("%lu",
540
 
                                                           (unsigned long) getpid ());
541
 
 
542
 
        popup_component = panel_applet_get_popup_component (applet);
543
 
 
544
 
        bonobo_ui_util_set_ui (popup_component, opt_datadir, file, opt_app_name, NULL);
545
 
 
546
 
        bonobo_ui_component_add_verb_list_with_data (popup_component, verb_list, user_data);
547
 
 
548
 
        if (app_name)
549
 
                g_free (app_name);
550
 
}
551
 
 
552
 
BonoboControl *
553
 
panel_applet_get_control (PanelApplet *applet)
554
 
{
555
 
        g_return_val_if_fail (PANEL_IS_APPLET (applet), NULL);
556
 
 
557
 
        return applet->priv->control;
558
 
}
559
 
 
560
 
BonoboUIComponent *
561
 
panel_applet_get_popup_component (PanelApplet *applet)
562
 
{
563
 
        g_return_val_if_fail (PANEL_IS_APPLET (applet), NULL);
564
 
 
565
 
        return bonobo_control_get_popup_ui_component (applet->priv->control);
566
 
}
567
 
 
568
 
static void
569
 
panel_applet_finalize (GObject *object)
570
 
{
571
 
        PanelApplet *applet = PANEL_APPLET (object);
572
 
 
573
 
        panel_applet_set_preferences_key (applet, NULL);
574
 
 
575
 
        if (applet->priv->client)
576
 
                g_object_unref (applet->priv->client);
577
 
        applet->priv->client = NULL;
578
 
 
579
 
        if (applet->priv->prop_sack)
580
 
                bonobo_object_unref (
581
 
                        BONOBO_OBJECT (applet->priv->prop_sack));
582
 
        applet->priv->prop_sack = NULL;
583
 
 
584
 
        g_free (applet->priv->size_hints);
585
 
        g_free (applet->priv->prefs_key);
586
 
        g_free (applet->priv->background);
587
 
        g_free (applet->priv->iid);
588
 
 
589
 
        if (applet->priv->closure)
590
 
                g_closure_unref (applet->priv->closure);
591
 
        applet->priv->closure = NULL;
592
 
 
593
 
        G_OBJECT_CLASS (panel_applet_parent_class)->finalize (object);
594
 
}
595
 
 
596
 
static gboolean
597
 
container_has_focusable_child (GtkContainer *container)
598
 
{
599
 
        GtkWidget *child;
600
 
        GList *list;
601
 
        GList *t;
602
 
        gboolean retval = FALSE;
603
 
 
604
 
        list = gtk_container_get_children (container);
605
 
 
606
 
        for (t = list; t; t = t->next) {
607
 
                child = GTK_WIDGET (t->data);
608
 
                if (gtk_widget_get_can_focus (child)) {
609
 
                        retval = TRUE;
610
 
                        break;
611
 
                } else if (GTK_IS_CONTAINER (child)) {
612
 
                        retval = container_has_focusable_child (GTK_CONTAINER (child));
613
 
                        if (retval)
614
 
                                break;
615
 
                }
616
 
        }
617
 
        g_list_free (list);
618
 
        return retval;
619
 
}
620
 
 
621
 
static void
622
 
panel_applet_position_menu (GtkMenu   *menu,
623
 
                            int       *x,
624
 
                            int       *y,
625
 
                            gboolean  *push_in,
626
 
                            GtkWidget *widget)
627
 
{
628
 
        PanelApplet    *applet;
629
 
        GtkAllocation   allocation;
630
 
        GtkRequisition  requisition;
631
 
        GdkScreen      *screen;
632
 
        int             menu_x = 0;
633
 
        int             menu_y = 0;
634
 
        int             pointer_x;
635
 
        int             pointer_y;
636
 
 
637
 
        g_return_if_fail (PANEL_IS_APPLET (widget));
638
 
 
639
 
        applet = PANEL_APPLET (widget);
640
 
 
641
 
        screen = gtk_widget_get_screen (widget);
642
 
 
643
 
        gtk_widget_size_request (GTK_WIDGET (menu), &requisition);
644
 
 
645
 
        gdk_window_get_origin (gtk_widget_get_window (widget),
646
 
                               &menu_x, &menu_y);
647
 
        gtk_widget_get_pointer (widget, &pointer_x, &pointer_y);
648
 
 
649
 
        gtk_widget_get_allocation (widget, &allocation);
650
 
 
651
 
        menu_x += allocation.x;
652
 
        menu_y += allocation.y;
653
 
 
654
 
        if (applet->priv->orient == PANEL_APPLET_ORIENT_UP ||
655
 
            applet->priv->orient == PANEL_APPLET_ORIENT_DOWN) {
656
 
                if (gtk_widget_get_direction (GTK_WIDGET (menu)) != GTK_TEXT_DIR_RTL) {
657
 
                        if (pointer_x < allocation.width &&
658
 
                            requisition.width < pointer_x)
659
 
                                menu_x += MIN (pointer_x,
660
 
                                               allocation.width - requisition.width);
661
 
                } else {
662
 
                        menu_x += allocation.width - requisition.width;
663
 
                        if (pointer_x > 0 && pointer_x < allocation.width &&
664
 
                            pointer_x < allocation.width - requisition.width) {
665
 
                                menu_x -= MIN (allocation.width - pointer_x,
666
 
                                               allocation.width - requisition.width);
667
 
                        }
668
 
                }
669
 
                menu_x = MIN (menu_x, gdk_screen_get_width (screen) - requisition.width);
670
 
 
671
 
                if (menu_y > gdk_screen_get_height (screen) / 2)
672
 
                        menu_y -= requisition.height;
673
 
                else
674
 
                        menu_y += allocation.height;
675
 
        } else  {
676
 
                if (pointer_y < allocation.height &&
677
 
                    requisition.height < pointer_y)
678
 
                        menu_y += MIN (pointer_y, allocation.height - requisition.height);
679
 
                menu_y = MIN (menu_y, gdk_screen_get_height (screen) - requisition.height);
680
 
 
681
 
                if (menu_x > gdk_screen_get_width (screen) / 2)
682
 
                        menu_x -= requisition.width;
683
 
                else
684
 
                        menu_x += allocation.width;
685
 
 
686
 
        }
687
 
 
688
 
        *x = menu_x;
689
 
        *y = menu_y;
690
 
        *push_in = TRUE;
691
 
}
692
 
 
693
 
static gboolean
694
 
panel_applet_can_focus (GtkWidget *widget)
695
 
{
696
 
        /*
697
 
         * A PanelApplet widget can focus if it has a tooltip or it does
698
 
         * not have any focusable children.
699
 
         */
700
 
        if (gtk_widget_get_has_tooltip (widget))
701
 
                return TRUE;
702
 
 
703
 
        if (!PANEL_IS_APPLET (widget))
704
 
                return FALSE;
705
 
 
706
 
        return !container_has_focusable_child (GTK_CONTAINER (widget));
707
 
}
708
 
 
709
 
static gboolean
710
 
panel_applet_button_press (GtkWidget      *widget,
711
 
                           GdkEventButton *event)
712
 
{
713
 
        PanelApplet *applet = PANEL_APPLET (widget);
714
 
 
715
 
        if (!container_has_focusable_child (GTK_CONTAINER (applet))) {
716
 
                if (!gtk_widget_has_focus (widget)) {
717
 
                        gtk_widget_set_can_focus (widget, TRUE);
718
 
                        gtk_widget_grab_focus (widget);
719
 
                }
720
 
        }
721
 
 
722
 
        if (event->button == 1)
723
 
                return TRUE;
724
 
        else if (event->button == 3) {
725
 
                bonobo_control_do_popup_full (
726
 
                                applet->priv->control,
727
 
                                NULL, NULL,
728
 
                                (GtkMenuPositionFunc) panel_applet_position_menu,
729
 
                                applet,
730
 
                                event->button,
731
 
                                event->time);
732
 
                return TRUE;
733
 
        }
734
 
 
735
 
        return FALSE;
736
 
}
737
 
 
738
 
gboolean
739
 
_panel_applet_popup_menu (PanelApplet *applet,
740
 
                          guint button,
741
 
                          guint32 time)
742
 
{
743
 
        bonobo_control_do_popup_full (applet->priv->control, NULL, NULL,
744
 
                                      (GtkMenuPositionFunc) panel_applet_position_menu,
745
 
                                      applet, button, time);
746
 
        return TRUE;
747
 
}
748
 
 
749
 
static gboolean
750
 
panel_applet_popup_menu (PanelApplet *applet)
751
 
{
752
 
        return _panel_applet_popup_menu (applet, 3, GDK_CURRENT_TIME);
753
 
}
754
 
 
755
 
static void
756
 
panel_applet_size_request (GtkWidget *widget, GtkRequisition *requisition)
757
 
{
758
 
        int focus_width = 0;
759
 
 
760
 
        GTK_WIDGET_CLASS (panel_applet_parent_class)->size_request (widget,
761
 
                                                                    requisition);
762
 
 
763
 
        if (!panel_applet_can_focus (widget))
764
 
                return;
765
 
 
766
 
        /*
767
 
         * We are deliberately ignoring focus-padding here to
768
 
         * save valuable panel real estate.
769
 
         */
770
 
        gtk_widget_style_get (widget,
771
 
                              "focus-line-width", &focus_width,
772
 
                              NULL);
773
 
 
774
 
        requisition->width  += 2 * focus_width;
775
 
        requisition->height += 2 * focus_width;
776
 
}
777
 
 
778
 
static void
779
 
panel_applet_size_allocate (GtkWidget     *widget,
780
 
                            GtkAllocation *allocation)
781
 
{
782
 
        GtkAllocation  child_allocation;
783
 
        GtkBin        *bin;
784
 
        GtkWidget     *child;
785
 
        int            border_width;
786
 
        int            focus_width = 0;
787
 
        PanelApplet   *applet;
788
 
 
789
 
        if (!panel_applet_can_focus (widget)) {
790
 
                GTK_WIDGET_CLASS (panel_applet_parent_class)->size_allocate (widget, allocation);
791
 
        } else {
792
 
                /*
793
 
                 * We are deliberately ignoring focus-padding here to
794
 
                 * save valuable panel real estate.
795
 
                 */
796
 
                gtk_widget_style_get (widget,
797
 
                                      "focus-line-width", &focus_width,
798
 
                                      NULL);
799
 
 
800
 
                border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
801
 
 
802
 
                gtk_widget_set_allocation (widget, allocation);
803
 
                bin = GTK_BIN (widget);
804
 
 
805
 
                child_allocation.x = focus_width;
806
 
                child_allocation.y = focus_width;
807
 
 
808
 
                child_allocation.width  = MAX (allocation->width  - border_width * 2, 0);
809
 
                child_allocation.height = MAX (allocation->height - border_width * 2, 0);
810
 
 
811
 
                if (gtk_widget_get_realized (widget))
812
 
                        gdk_window_move_resize (gtk_widget_get_window (widget),
813
 
                                                allocation->x + border_width,
814
 
                                                allocation->y + border_width,
815
 
                                                child_allocation.width,
816
 
                                                child_allocation.height);
817
 
 
818
 
                child_allocation.width  = MAX (child_allocation.width  - 2 * focus_width, 0);
819
 
                child_allocation.height = MAX (child_allocation.height - 2 * focus_width, 0);
820
 
 
821
 
                child = gtk_bin_get_child (bin);
822
 
                if (child)
823
 
                        gtk_widget_size_allocate (child, &child_allocation);
824
 
        }
825
 
 
826
 
        applet = PANEL_APPLET (widget);
827
 
 
828
 
        if (applet->priv->previous_height != allocation->height ||
829
 
            applet->priv->previous_width  != allocation->width) {
830
 
                applet->priv->previous_height = allocation->height;
831
 
                applet->priv->previous_width = allocation->width;
832
 
 
833
 
                panel_applet_handle_background (applet);
834
 
        }
835
 
}
836
 
 
837
 
static gboolean
838
 
panel_applet_expose (GtkWidget      *widget,
839
 
                     GdkEventExpose *event)
840
 
{
841
 
        GtkAllocation allocation;
842
 
        int border_width;
843
 
        int focus_width = 0;
844
 
        int x, y, width, height;
845
 
 
846
 
        g_return_val_if_fail (PANEL_IS_APPLET (widget), FALSE);
847
 
        g_return_val_if_fail (event != NULL, FALSE);
848
 
 
849
 
        GTK_WIDGET_CLASS (panel_applet_parent_class)->expose_event (widget,
850
 
                                                                    event);
851
 
 
852
 
        if (!gtk_widget_has_focus (widget))
853
 
                return FALSE;
854
 
 
855
 
        gtk_widget_get_allocation (widget, &allocation);
856
 
 
857
 
        /*
858
 
         * We are deliberately ignoring focus-padding here to
859
 
         * save valuable panel real estate.
860
 
         */
861
 
        gtk_widget_style_get (widget,
862
 
                              "focus-line-width", &focus_width,
863
 
                              NULL);
864
 
 
865
 
        border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
866
 
 
867
 
        x = allocation.x;
868
 
        y = allocation.y;
869
 
 
870
 
        width  = allocation.width  - 2 * border_width;
871
 
        height = allocation.height - 2 * border_width;
872
 
 
873
 
        gtk_paint_focus (gtk_widget_get_style (widget),
874
 
                         gtk_widget_get_window (widget),
875
 
                         gtk_widget_get_state (widget),
876
 
                         &event->area, widget, "panel_applet",
877
 
                         x, y, width, height);
878
 
 
879
 
        return FALSE;
880
 
}
881
 
 
882
 
static gboolean
883
 
panel_applet_focus (GtkWidget        *widget,
884
 
                    GtkDirectionType  dir)
885
 
{
886
 
        gboolean ret;
887
 
        GtkWidget *previous_focus_child;
888
 
        PanelApplet *applet;
889
 
 
890
 
        g_return_val_if_fail (PANEL_IS_APPLET (widget), FALSE);
891
 
 
892
 
        applet = PANEL_APPLET (widget);
893
 
        if (applet->priv->moving_focus_out) {
894
 
                /*
895
 
                 * Applet will retain focus if there is nothing else on the
896
 
                 * panel to get focus
897
 
                 */
898
 
                applet->priv->moving_focus_out = FALSE;
899
 
                return FALSE;
900
 
        }
901
 
 
902
 
        previous_focus_child = gtk_container_get_focus_child (GTK_CONTAINER (widget));
903
 
        if (!previous_focus_child && !gtk_widget_has_focus (widget)) {
904
 
                if (gtk_widget_get_has_tooltip (widget)) {
905
 
                        gtk_widget_set_can_focus (widget, TRUE);
906
 
                        gtk_widget_grab_focus (widget);
907
 
                        gtk_widget_set_can_focus (widget, FALSE);
908
 
                        return TRUE;
909
 
                }
910
 
        }
911
 
        ret = GTK_WIDGET_CLASS (panel_applet_parent_class)->focus (widget, dir);
912
 
 
913
 
        if (!ret && !previous_focus_child) {
914
 
                if (!gtk_widget_has_focus (widget))  {
915
 
                        /*
916
 
                         * Applet does not have a widget which can focus so set
917
 
                         * the focus on the applet unless it already had focus
918
 
                         * because it had a tooltip.
919
 
                         */
920
 
                        gtk_widget_set_can_focus (widget, TRUE);
921
 
                        gtk_widget_grab_focus (widget);
922
 
                        gtk_widget_set_can_focus (widget, FALSE);
923
 
                        ret = TRUE;
924
 
                }
925
 
        }
926
 
 
927
 
        return ret;
928
 
}
929
 
 
930
 
static gboolean
931
 
panel_applet_parse_color (const gchar *color_str,
932
 
                          GdkColor    *color)
933
 
{
934
 
        int r, g, b;
935
 
 
936
 
        g_assert (color_str && color);
937
 
 
938
 
        if (sscanf (color_str, "%4x%4x%4x", &r, &g, &b) != 3)
939
 
                return FALSE;
940
 
 
941
 
        color->red   = r;
942
 
        color->green = g;
943
 
        color->blue  = b;
944
 
 
945
 
        return TRUE;
946
 
}
947
 
 
948
 
static gboolean
949
 
panel_applet_parse_pixmap_str (const char *str,
950
 
                               GdkNativeWindow *xid,
951
 
                               int             *x,
952
 
                               int             *y)
953
 
{
954
 
        char **elements;
955
 
        char  *tmp;
956
 
 
957
 
        g_return_val_if_fail (str != NULL, FALSE);
958
 
        g_return_val_if_fail (xid != NULL, FALSE);
959
 
        g_return_val_if_fail (x != NULL, FALSE);
960
 
        g_return_val_if_fail (y != NULL, FALSE);
961
 
 
962
 
        elements = g_strsplit (str, ",", -1);
963
 
 
964
 
        if (!elements)
965
 
                return FALSE;
966
 
 
967
 
        if (!elements [0] || !*elements [0] ||
968
 
            !elements [1] || !*elements [1] ||
969
 
            !elements [2] || !*elements [2])
970
 
                goto ERROR_AND_FREE;
971
 
 
972
 
        *xid = strtol (elements [0], &tmp, 10);
973
 
        if (tmp == elements [0])
974
 
                goto ERROR_AND_FREE;
975
 
 
976
 
        *x   = strtol (elements [1], &tmp, 10);
977
 
        if (tmp == elements [1])
978
 
                goto ERROR_AND_FREE;
979
 
 
980
 
        *y   = strtol (elements [2], &tmp, 10);
981
 
        if (tmp == elements [2])
982
 
                goto ERROR_AND_FREE;
983
 
 
984
 
        g_strfreev (elements);
985
 
        return TRUE;
986
 
 
987
 
 ERROR_AND_FREE:
988
 
        g_strfreev (elements);
989
 
        return FALSE;
990
 
}
991
 
 
992
 
static GdkPixmap *
993
 
panel_applet_get_pixmap (PanelApplet     *applet,
994
 
                         GdkNativeWindow  xid,
995
 
                         int              x,
996
 
                         int              y)
997
 
{
998
 
        gboolean         display_grabbed;
999
 
        GdkPixmap       *pixmap;
1000
 
        GdkDisplay      *display;
1001
 
        GdkPixmap       *retval;
1002
 
        GdkWindow       *window;
1003
 
        int              width;
1004
 
        int              height;
1005
 
        cairo_t         *cr;
1006
 
        cairo_pattern_t *pattern;
1007
 
 
1008
 
        g_return_val_if_fail (PANEL_IS_APPLET (applet), NULL);
1009
 
 
1010
 
        if (!gtk_widget_get_realized (GTK_WIDGET (applet)))
1011
 
                return NULL;
1012
 
 
1013
 
        display = gdk_display_get_default ();
1014
 
        display_grabbed = FALSE;
1015
 
 
1016
 
        window = gtk_widget_get_window (GTK_WIDGET (applet));
1017
 
 
1018
 
        pixmap = gdk_pixmap_lookup_for_display (display, xid);
1019
 
        if (pixmap)
1020
 
                g_object_ref (pixmap);
1021
 
        else {
1022
 
                display_grabbed = TRUE;
1023
 
                gdk_x11_display_grab (display);
1024
 
                pixmap = gdk_pixmap_foreign_new_for_display (display, xid);
1025
 
        }
1026
 
 
1027
 
        /* This can happen if the user changes the background very fast.
1028
 
         * We'll get the next update, so it's not a big deal. */
1029
 
        if (pixmap == NULL) {
1030
 
                if (display_grabbed)
1031
 
                        gdk_x11_display_ungrab (display);
1032
 
                return NULL;
1033
 
        }
1034
 
 
1035
 
        gdk_drawable_get_size (GDK_DRAWABLE (window),
1036
 
                               &width, &height);
1037
 
        retval = gdk_pixmap_new (window,
1038
 
                                 width, height, -1);
1039
 
 
1040
 
        /* the pixmap has no colormap, and we need one */
1041
 
        gdk_drawable_set_colormap (GDK_DRAWABLE (pixmap),
1042
 
                                   gdk_drawable_get_colormap (window));
1043
 
 
1044
 
        cr = gdk_cairo_create (GDK_DRAWABLE (retval));
1045
 
        gdk_cairo_set_source_pixmap (cr, pixmap, -x, -y);
1046
 
        pattern = cairo_get_source (cr);
1047
 
        cairo_pattern_set_extend (pattern, CAIRO_EXTEND_REPEAT);
1048
 
 
1049
 
        cairo_rectangle (cr, 0, 0, width, height);
1050
 
        cairo_fill (cr);
1051
 
 
1052
 
        cairo_destroy (cr);
1053
 
 
1054
 
        g_object_unref (pixmap);
1055
 
 
1056
 
        if (display_grabbed)
1057
 
                gdk_x11_display_ungrab (display);
1058
 
 
1059
 
        return retval;
1060
 
}
1061
 
 
1062
 
static PanelAppletBackgroundType
1063
 
panel_applet_handle_background_string (PanelApplet  *applet,
1064
 
                                       GdkColor     *color,
1065
 
                                       GdkPixmap   **pixmap)
1066
 
{
1067
 
        PanelAppletBackgroundType   retval;
1068
 
        char                      **elements;
1069
 
 
1070
 
        retval = PANEL_NO_BACKGROUND;
1071
 
 
1072
 
        if (!gtk_widget_get_realized (GTK_WIDGET (applet)) || !applet->priv->background)
1073
 
                return retval;
1074
 
 
1075
 
        elements = g_strsplit (applet->priv->background, ":", -1);
1076
 
 
1077
 
        if (elements [0] && !strcmp (elements [0], "none" )) {
1078
 
                retval = PANEL_NO_BACKGROUND;
1079
 
 
1080
 
        } else if (elements [0] && !strcmp (elements [0], "color")) {
1081
 
                g_return_val_if_fail (color != NULL, PANEL_NO_BACKGROUND);
1082
 
 
1083
 
                if (!elements [1] || !panel_applet_parse_color (elements [1], color)) {
1084
 
 
1085
 
                        g_warning ("Incomplete '%s' background type received", elements [0]);
1086
 
                        g_strfreev (elements);
1087
 
                        return PANEL_NO_BACKGROUND;
1088
 
                }
1089
 
 
1090
 
                retval = PANEL_COLOR_BACKGROUND;
1091
 
 
1092
 
        } else if (elements [0] && !strcmp (elements [0], "pixmap")) {
1093
 
                GdkNativeWindow pixmap_id;
1094
 
                int             x, y;
1095
 
 
1096
 
                g_return_val_if_fail (pixmap != NULL, PANEL_NO_BACKGROUND);
1097
 
 
1098
 
                if (!panel_applet_parse_pixmap_str (elements [1], &pixmap_id, &x, &y)) {
1099
 
                        g_warning ("Incomplete '%s' background type received: %s",
1100
 
                                   elements [0], elements [1]);
1101
 
 
1102
 
                        g_strfreev (elements);
1103
 
                        return PANEL_NO_BACKGROUND;
1104
 
                }
1105
 
 
1106
 
                *pixmap = panel_applet_get_pixmap (applet, pixmap_id, x, y);
1107
 
                if (!*pixmap) {
1108
 
                        g_warning ("Failed to get pixmap %s", elements [1]);
1109
 
                        g_strfreev (elements);
1110
 
                        return PANEL_NO_BACKGROUND;
1111
 
                }
1112
 
 
1113
 
                retval = PANEL_PIXMAP_BACKGROUND;
1114
 
        } else
1115
 
                g_warning ("Unknown background type received");
1116
 
 
1117
 
        g_strfreev (elements);
1118
 
 
1119
 
        return retval;
1120
 
}
1121
 
 
1122
 
PanelAppletBackgroundType
1123
 
panel_applet_get_background (PanelApplet *applet,
1124
 
                             GdkColor *color,
1125
 
                             GdkPixmap **pixmap)
1126
 
{
1127
 
        g_return_val_if_fail (PANEL_IS_APPLET (applet), PANEL_NO_BACKGROUND);
1128
 
 
1129
 
        /* initial sanity */
1130
 
        if (pixmap != NULL)
1131
 
                *pixmap = NULL;
1132
 
        if (color != NULL)
1133
 
                memset (color, 0, sizeof (GdkColor));
1134
 
 
1135
 
        return panel_applet_handle_background_string (applet, color, pixmap);
1136
 
}
1137
 
 
1138
 
static void
1139
 
panel_applet_get_prop (BonoboPropertyBag *sack,
1140
 
                       BonoboArg         *arg,
1141
 
                       guint              arg_id,
1142
 
                       CORBA_Environment *ev,
1143
 
                       gpointer           user_data)
1144
 
{
1145
 
        PanelApplet *applet = PANEL_APPLET (user_data);
1146
 
 
1147
 
        switch (arg_id) {
1148
 
        case PROPERTY_ORIENT_IDX:
1149
 
                BONOBO_ARG_SET_SHORT (arg, applet->priv->orient);
1150
 
                break;
1151
 
        case PROPERTY_SIZE_IDX:
1152
 
                BONOBO_ARG_SET_SHORT (arg, applet->priv->size);
1153
 
                break;
1154
 
        case PROPERTY_BACKGROUND_IDX:
1155
 
                BONOBO_ARG_SET_STRING (arg, applet->priv->background);
1156
 
                break;
1157
 
        case PROPERTY_FLAGS_IDX:
1158
 
                BONOBO_ARG_SET_SHORT (arg, applet->priv->flags);
1159
 
                break;
1160
 
        case PROPERTY_SIZE_HINTS_IDX: {
1161
 
                CORBA_sequence_CORBA_long *seq;
1162
 
                int                        i;
1163
 
 
1164
 
                seq = arg->_value;
1165
 
 
1166
 
                seq->_length  = seq->_maximum = applet->priv->size_hints_len;
1167
 
                seq->_buffer  = CORBA_sequence_CORBA_long_allocbuf (seq->_length);
1168
 
                seq->_release = CORBA_TRUE;
1169
 
 
1170
 
                for (i = 0; i < applet->priv->size_hints_len; i++)
1171
 
                        seq->_buffer [i] = applet->priv->size_hints [i];
1172
 
        }
1173
 
                break;
1174
 
        case PROPERTY_LOCKED_DOWN_IDX:
1175
 
                BONOBO_ARG_SET_BOOLEAN (arg, applet->priv->locked_down);
1176
 
                break;
1177
 
        default:
1178
 
                g_assert_not_reached ();
1179
 
                break;
1180
 
        }
1181
 
}
1182
 
 
1183
 
static void
1184
 
panel_applet_update_background_for_widget (GtkWidget                 *widget,
1185
 
                                           PanelAppletBackgroundType  type,
1186
 
                                           GdkColor                  *color,
1187
 
                                           GdkPixmap                 *pixmap)
1188
 
{
1189
 
        GtkRcStyle *rc_style;
1190
 
        GtkStyle   *style;
1191
 
 
1192
 
        /* reset style */
1193
 
        gtk_widget_set_style (widget, NULL);
1194
 
        rc_style = gtk_rc_style_new ();
1195
 
        gtk_widget_modify_style (widget, rc_style);
1196
 
        g_object_unref (rc_style);
1197
 
 
1198
 
        switch (type) {
1199
 
        case PANEL_NO_BACKGROUND:
1200
 
                break;
1201
 
        case PANEL_COLOR_BACKGROUND:
1202
 
                gtk_widget_modify_bg (widget, GTK_STATE_NORMAL, color);
1203
 
                break;
1204
 
        case PANEL_PIXMAP_BACKGROUND:
1205
 
                style = gtk_style_copy (gtk_widget_get_style (widget));
1206
 
                if (style->bg_pixmap[GTK_STATE_NORMAL])
1207
 
                        g_object_unref (style->bg_pixmap[GTK_STATE_NORMAL]);
1208
 
                style->bg_pixmap[GTK_STATE_NORMAL] = g_object_ref (pixmap);
1209
 
                gtk_widget_set_style (widget, style);
1210
 
                g_object_unref (style);
1211
 
                break;
1212
 
        default:
1213
 
                g_assert_not_reached ();
1214
 
                break;
1215
 
        }
1216
 
}
1217
 
 
1218
 
static void
1219
 
panel_applet_handle_background (PanelApplet *applet)
1220
 
{
1221
 
        PanelAppletBackgroundType  type;
1222
 
        GdkColor                   color;
1223
 
        GdkPixmap                 *pixmap;
1224
 
 
1225
 
        type = panel_applet_get_background (applet, &color, &pixmap);
1226
 
 
1227
 
        if (applet->priv->background_widget)
1228
 
                panel_applet_update_background_for_widget (applet->priv->background_widget,
1229
 
                                                           type, &color, pixmap);
1230
 
 
1231
 
        switch (type) {
1232
 
        case PANEL_NO_BACKGROUND:
1233
 
                g_signal_emit (G_OBJECT (applet),
1234
 
                               panel_applet_signals [CHANGE_BACKGROUND],
1235
 
                               0, PANEL_NO_BACKGROUND, NULL, NULL);
1236
 
                break;
1237
 
        case PANEL_COLOR_BACKGROUND:
1238
 
                g_signal_emit (G_OBJECT (applet),
1239
 
                               panel_applet_signals [CHANGE_BACKGROUND],
1240
 
                               0, PANEL_COLOR_BACKGROUND, &color, NULL);
1241
 
                break;
1242
 
        case PANEL_PIXMAP_BACKGROUND:
1243
 
                g_signal_emit (G_OBJECT (applet),
1244
 
                               panel_applet_signals [CHANGE_BACKGROUND],
1245
 
                               0, PANEL_PIXMAP_BACKGROUND, NULL, pixmap);
1246
 
 
1247
 
                g_object_unref (pixmap);
1248
 
                break;
1249
 
        default:
1250
 
                g_assert_not_reached ();
1251
 
                break;
1252
 
        }
1253
 
}
1254
 
 
1255
 
static void
1256
 
panel_applet_set_prop (BonoboPropertyBag *sack,
1257
 
                       const BonoboArg   *arg,
1258
 
                       guint              arg_id,
1259
 
                       CORBA_Environment *ev,
1260
 
                       gpointer           user_data)
1261
 
{
1262
 
        PanelApplet *applet = PANEL_APPLET (user_data);
1263
 
 
1264
 
        switch (arg_id) {
1265
 
        case PROPERTY_ORIENT_IDX: {
1266
 
                PanelAppletOrient orient;
1267
 
 
1268
 
                orient = BONOBO_ARG_GET_SHORT (arg);
1269
 
 
1270
 
                if (applet->priv->orient != orient) {
1271
 
                        applet->priv->orient = orient;
1272
 
 
1273
 
                        g_signal_emit (G_OBJECT (applet),
1274
 
                                       panel_applet_signals [CHANGE_ORIENT],
1275
 
                                       0, orient);
1276
 
                }
1277
 
        }
1278
 
                break;
1279
 
        case PROPERTY_SIZE_IDX: {
1280
 
                guint size;
1281
 
 
1282
 
                size = BONOBO_ARG_GET_SHORT (arg);
1283
 
 
1284
 
                if (applet->priv->size != size) {
1285
 
                        applet->priv->size = size;
1286
 
 
1287
 
                        g_signal_emit (G_OBJECT (applet),
1288
 
                                       panel_applet_signals [CHANGE_SIZE],
1289
 
                                       0, size);
1290
 
                }
1291
 
        }
1292
 
                break;
1293
 
        case PROPERTY_BACKGROUND_IDX:
1294
 
                if (applet->priv->background)
1295
 
                        g_free (applet->priv->background);
1296
 
 
1297
 
                applet->priv->background = g_strdup (BONOBO_ARG_GET_STRING (arg));
1298
 
 
1299
 
                panel_applet_handle_background (applet);
1300
 
                break;
1301
 
        case PROPERTY_FLAGS_IDX:
1302
 
                applet->priv->flags = BONOBO_ARG_GET_SHORT (arg);
1303
 
                break;
1304
 
        case PROPERTY_SIZE_HINTS_IDX: {
1305
 
                CORBA_sequence_CORBA_long *seq = arg->_value;
1306
 
                int                        i;
1307
 
 
1308
 
                applet->priv->size_hints = g_realloc (applet->priv->size_hints,
1309
 
                                                      seq->_length * sizeof (int));
1310
 
                for (i = 0; i < seq->_length; i++)
1311
 
                        applet->priv->size_hints [i] = seq->_buffer [i];
1312
 
 
1313
 
                applet->priv->size_hints_len = seq->_length;;
1314
 
        }
1315
 
                break;
1316
 
        case PROPERTY_LOCKED_DOWN_IDX:
1317
 
                applet->priv->locked_down = BONOBO_ARG_GET_BOOLEAN (arg);
1318
 
                break;
1319
 
        default:
1320
 
                g_assert_not_reached ();
1321
 
                break;
1322
 
        }
1323
 
}
1324
 
 
1325
 
static BonoboPropertyBag *
1326
 
panel_applet_property_bag (PanelApplet *applet)
1327
 
{
1328
 
        BonoboPropertyBag *sack;
1329
 
 
1330
 
        sack = bonobo_property_bag_new (panel_applet_get_prop,
1331
 
                                        panel_applet_set_prop,
1332
 
                                        applet);
1333
 
 
1334
 
        bonobo_property_bag_add (sack,
1335
 
                                 PROPERTY_ORIENT,
1336
 
                                 PROPERTY_ORIENT_IDX,
1337
 
                                 BONOBO_ARG_SHORT,
1338
 
                                 NULL,
1339
 
                                 "The Applet's containing Panel's orientation",
1340
 
                                 Bonobo_PROPERTY_READABLE | Bonobo_PROPERTY_WRITEABLE);
1341
 
 
1342
 
        bonobo_property_bag_add (sack,
1343
 
                                 PROPERTY_SIZE,
1344
 
                                 PROPERTY_SIZE_IDX,
1345
 
                                 BONOBO_ARG_SHORT,
1346
 
                                 NULL,
1347
 
                                 "The Applet's containing Panel's size in pixels",
1348
 
                                 Bonobo_PROPERTY_READABLE | Bonobo_PROPERTY_WRITEABLE);
1349
 
 
1350
 
        bonobo_property_bag_add (sack,
1351
 
                                 PROPERTY_BACKGROUND,
1352
 
                                 PROPERTY_BACKGROUND_IDX,
1353
 
                                 BONOBO_ARG_STRING,
1354
 
                                 NULL,
1355
 
                                 "The Applet's containing Panel's background color or pixmap",
1356
 
                                 Bonobo_PROPERTY_READABLE | Bonobo_PROPERTY_WRITEABLE);
1357
 
 
1358
 
        bonobo_property_bag_add (sack,
1359
 
                                 PROPERTY_FLAGS,
1360
 
                                 PROPERTY_FLAGS_IDX,
1361
 
                                 BONOBO_ARG_SHORT,
1362
 
                                 NULL,
1363
 
                                 "The Applet's flags",
1364
 
                                 Bonobo_PROPERTY_READABLE);
1365
 
 
1366
 
        bonobo_property_bag_add (sack,
1367
 
                                 PROPERTY_SIZE_HINTS,
1368
 
                                 PROPERTY_SIZE_HINTS_IDX,
1369
 
                                 TC_CORBA_sequence_CORBA_long,
1370
 
                                 NULL,
1371
 
                                 "Ranges that hint what sizes are acceptable for the applet",
1372
 
                                 Bonobo_PROPERTY_READABLE);
1373
 
 
1374
 
        bonobo_property_bag_add (sack,
1375
 
                                 PROPERTY_LOCKED_DOWN,
1376
 
                                 PROPERTY_LOCKED_DOWN_IDX,
1377
 
                                 BONOBO_ARG_BOOLEAN,
1378
 
                                 NULL,
1379
 
                                 "The Applet's containing Panel is locked down",
1380
 
                                 Bonobo_PROPERTY_READABLE | Bonobo_PROPERTY_WRITEABLE);
1381
 
 
1382
 
        return sack;
1383
 
}
1384
 
 
1385
 
static void
1386
 
panel_applet_realize (GtkWidget *widget)
1387
 
{
1388
 
        GTK_WIDGET_CLASS (panel_applet_parent_class)->realize (widget);
1389
 
 
1390
 
        if (PANEL_APPLET (widget)->priv->background)
1391
 
                panel_applet_handle_background (PANEL_APPLET (widget));
1392
 
}
1393
 
 
1394
 
static void
1395
 
panel_applet_control_bound (BonoboControl *control,
1396
 
                            PanelApplet   *applet)
1397
 
{
1398
 
        gboolean ret;
1399
 
 
1400
 
        g_return_if_fail (PANEL_IS_APPLET (applet));
1401
 
        g_return_if_fail (applet->priv->iid != NULL &&
1402
 
                          applet->priv->closure != NULL);
1403
 
 
1404
 
        if (applet->priv->bound)
1405
 
                return;
1406
 
 
1407
 
        bonobo_closure_invoke (applet->priv->closure,
1408
 
                               G_TYPE_BOOLEAN, &ret,
1409
 
                               PANEL_TYPE_APPLET, applet,
1410
 
                               G_TYPE_STRING, applet->priv->iid,
1411
 
                               NULL);
1412
 
 
1413
 
 
1414
 
        if (!ret) { /* FIXME */
1415
 
                g_warning ("need to free the control here");
1416
 
 
1417
 
                return;
1418
 
        }
1419
 
 
1420
 
        applet->priv->bound = TRUE;
1421
 
}
1422
 
 
1423
 
static Bonobo_Unknown
1424
 
panel_applet_item_handler_get_object (BonoboItemHandler *handler,
1425
 
                                      const char        *item_name,
1426
 
                                      gboolean           only_if_exists,
1427
 
                                      gpointer           user_data,
1428
 
                                      CORBA_Environment *ev)
1429
 
{
1430
 
        PanelApplet *applet = user_data;
1431
 
        GSList      *options;
1432
 
        GSList      *l;
1433
 
 
1434
 
        g_return_val_if_fail (PANEL_IS_APPLET (applet), CORBA_OBJECT_NIL);
1435
 
 
1436
 
        options = bonobo_item_option_parse (item_name);
1437
 
 
1438
 
        for (l = options; l; l = l->next) {
1439
 
                BonoboItemOption *option = l->data;
1440
 
 
1441
 
                if (!option->value || !option->value [0])
1442
 
                        continue;
1443
 
 
1444
 
                if (!strcmp (option->key, "prefs_key") && !applet->priv->prefs_key)
1445
 
                        panel_applet_set_preferences_key (applet, option->value);
1446
 
 
1447
 
                else if (!strcmp (option->key, "background"))
1448
 
                        bonobo_pbclient_set_string (BONOBO_OBJREF (applet->priv->prop_sack),
1449
 
                                                    PROPERTY_BACKGROUND, option->value, NULL);
1450
 
 
1451
 
                else if (!strcmp (option->key, "orient")) {
1452
 
                        if (!strcmp (option->value, "up"))
1453
 
                                bonobo_pbclient_set_short (
1454
 
                                        BONOBO_OBJREF (applet->priv->prop_sack), PROPERTY_ORIENT,
1455
 
                                        PANEL_APPLET_ORIENT_UP, NULL);
1456
 
 
1457
 
                        else if (!strcmp (option->value, "down"))
1458
 
                                bonobo_pbclient_set_short (
1459
 
                                        BONOBO_OBJREF (applet->priv->prop_sack), PROPERTY_ORIENT,
1460
 
                                        PANEL_APPLET_ORIENT_DOWN, NULL);
1461
 
 
1462
 
                        else if (!strcmp (option->value, "left"))
1463
 
                                bonobo_pbclient_set_short (
1464
 
                                        BONOBO_OBJREF (applet->priv->prop_sack), PROPERTY_ORIENT,
1465
 
                                        PANEL_APPLET_ORIENT_LEFT, NULL);
1466
 
 
1467
 
                        else if (!strcmp (option->value, "right"))
1468
 
                                bonobo_pbclient_set_short (
1469
 
                                        BONOBO_OBJREF (applet->priv->prop_sack), PROPERTY_ORIENT,
1470
 
                                        PANEL_APPLET_ORIENT_RIGHT, NULL);
1471
 
 
1472
 
                } else if (!strcmp (option->key, "size")) {
1473
 
                        if (!strcmp (option->value, "xx-small"))
1474
 
                                bonobo_pbclient_set_short (
1475
 
                                        BONOBO_OBJREF (applet->priv->prop_sack), PROPERTY_SIZE,
1476
 
                                        GNOME_Vertigo_PANEL_XX_SMALL, NULL);
1477
 
 
1478
 
                        else if (!strcmp (option->value, "x-small"))
1479
 
                                bonobo_pbclient_set_short (
1480
 
                                        BONOBO_OBJREF (applet->priv->prop_sack), PROPERTY_SIZE,
1481
 
                                        GNOME_Vertigo_PANEL_X_SMALL, NULL);
1482
 
 
1483
 
                        else if (!strcmp (option->value, "small"))
1484
 
                                bonobo_pbclient_set_short (
1485
 
                                        BONOBO_OBJREF (applet->priv->prop_sack), PROPERTY_SIZE,
1486
 
                                        GNOME_Vertigo_PANEL_SMALL, NULL);
1487
 
 
1488
 
                        else if (!strcmp (option->value, "medium"))
1489
 
                                bonobo_pbclient_set_short (
1490
 
                                        BONOBO_OBJREF (applet->priv->prop_sack), PROPERTY_SIZE,
1491
 
                                        GNOME_Vertigo_PANEL_MEDIUM, NULL);
1492
 
 
1493
 
                        else if (!strcmp (option->value, "large"))
1494
 
                                bonobo_pbclient_set_short (
1495
 
                                        BONOBO_OBJREF (applet->priv->prop_sack), PROPERTY_SIZE,
1496
 
                                        GNOME_Vertigo_PANEL_LARGE, NULL);
1497
 
 
1498
 
                        else if (!strcmp (option->value, "x-large"))
1499
 
                                bonobo_pbclient_set_short (
1500
 
                                        BONOBO_OBJREF (applet->priv->prop_sack), PROPERTY_SIZE,
1501
 
                                        GNOME_Vertigo_PANEL_X_LARGE, NULL);
1502
 
 
1503
 
                        else if (!strcmp (option->value, "xx-large"))
1504
 
                                bonobo_pbclient_set_short (
1505
 
                                        BONOBO_OBJREF (applet->priv->prop_sack), PROPERTY_SIZE,
1506
 
                                        GNOME_Vertigo_PANEL_XX_LARGE, NULL);
1507
 
                } else if (!strcmp (option->key, "locked_down")) {
1508
 
                        gboolean val = FALSE;
1509
 
                        if (option->value[0] == 'T' ||
1510
 
                            option->value[0] == 't' ||
1511
 
                            option->value[0] == 'Y' ||
1512
 
                            option->value[0] == 'y' ||
1513
 
                            atoi (option->value) != 0)
1514
 
                                val = TRUE;
1515
 
                        bonobo_pbclient_set_boolean (BONOBO_OBJREF (applet->priv->prop_sack),
1516
 
                                                     PROPERTY_LOCKED_DOWN, val, NULL);
1517
 
                }
1518
 
        }
1519
 
 
1520
 
        bonobo_item_options_free (options);
1521
 
 
1522
 
        return bonobo_object_dup_ref (BONOBO_OBJREF (applet->priv->control), ev);
1523
 
}
1524
 
 
1525
 
static void
1526
 
panel_applet_move_focus_out_of_applet (PanelApplet      *applet,
1527
 
                                       GtkDirectionType  dir)
1528
 
{
1529
 
        GtkWidget *toplevel;
1530
 
 
1531
 
        applet->priv->moving_focus_out = TRUE;
1532
 
        toplevel = gtk_widget_get_toplevel (GTK_WIDGET (applet));
1533
 
        g_return_if_fail (toplevel);
1534
 
 
1535
 
        gtk_widget_child_focus (toplevel, dir);
1536
 
        applet->priv->moving_focus_out = FALSE;
1537
 
}
1538
 
 
1539
 
static void
1540
 
add_tab_bindings (GtkBindingSet   *binding_set,
1541
 
                  GdkModifierType  modifiers,
1542
 
                  GtkDirectionType direction)
1543
 
{
1544
 
        gtk_binding_entry_add_signal (binding_set, GDK_Tab, modifiers,
1545
 
                                      "move_focus_out_of_applet", 1,
1546
 
                                      GTK_TYPE_DIRECTION_TYPE, direction);
1547
 
        gtk_binding_entry_add_signal (binding_set, GDK_KP_Tab, modifiers,
1548
 
                                      "move_focus_out_of_applet", 1,
1549
 
                                      GTK_TYPE_DIRECTION_TYPE, direction);
1550
 
}
1551
 
 
1552
 
static GObject *
1553
 
panel_applet_constructor (GType                  type,
1554
 
                          guint                  n_construct_properties,
1555
 
                          GObjectConstructParam *construct_properties)
1556
 
{
1557
 
        GObject     *obj;
1558
 
        PanelApplet *applet;
1559
 
 
1560
 
        obj = G_OBJECT_CLASS (panel_applet_parent_class)->constructor (type,
1561
 
                                                                       n_construct_properties,
1562
 
                                                                       construct_properties);
1563
 
 
1564
 
        applet = PANEL_APPLET (obj);
1565
 
 
1566
 
        panel_applet_setup (applet);
1567
 
 
1568
 
        return obj;
1569
 
}
1570
 
 
1571
 
static void
1572
 
panel_applet_class_init (PanelAppletClass *klass)
1573
 
{
1574
 
        GObjectClass   *gobject_class = (GObjectClass *) klass;
1575
 
        GtkObjectClass *object_class = (GtkObjectClass *) klass;
1576
 
        GtkWidgetClass *widget_class = (GtkWidgetClass *) klass;
1577
 
        GtkBindingSet *binding_set;
1578
 
 
1579
 
        gobject_class->constructor = panel_applet_constructor;
1580
 
        klass->move_focus_out_of_applet = panel_applet_move_focus_out_of_applet;
1581
 
 
1582
 
        widget_class->button_press_event = panel_applet_button_press;
1583
 
        widget_class->size_request = panel_applet_size_request;
1584
 
        widget_class->size_allocate = panel_applet_size_allocate;
1585
 
        widget_class->expose_event = panel_applet_expose;
1586
 
        widget_class->focus = panel_applet_focus;
1587
 
        widget_class->realize = panel_applet_realize;
1588
 
 
1589
 
        gobject_class->finalize = panel_applet_finalize;
1590
 
 
1591
 
        g_type_class_add_private (klass, sizeof (PanelAppletPrivate));
1592
 
 
1593
 
        panel_applet_signals [CHANGE_ORIENT] =
1594
 
                g_signal_new ("change_orient",
1595
 
                              G_TYPE_FROM_CLASS (klass),
1596
 
                              G_SIGNAL_RUN_LAST,
1597
 
                              G_STRUCT_OFFSET (PanelAppletClass, change_orient),
1598
 
                              NULL,
1599
 
                              NULL,
1600
 
                              panel_applet_marshal_VOID__UINT,
1601
 
                              G_TYPE_NONE,
1602
 
                              1,
1603
 
                              G_TYPE_UINT);
1604
 
 
1605
 
        panel_applet_signals [CHANGE_SIZE] =
1606
 
                g_signal_new ("change_size",
1607
 
                              G_TYPE_FROM_CLASS (klass),
1608
 
                              G_SIGNAL_RUN_LAST,
1609
 
                              G_STRUCT_OFFSET (PanelAppletClass, change_size),
1610
 
                              NULL,
1611
 
                              NULL,
1612
 
                              panel_applet_marshal_VOID__INT,
1613
 
                              G_TYPE_NONE,
1614
 
                              1,
1615
 
                              G_TYPE_INT);
1616
 
 
1617
 
        panel_applet_signals [CHANGE_BACKGROUND] =
1618
 
                g_signal_new ("change_background",
1619
 
                              G_TYPE_FROM_CLASS (klass),
1620
 
                              G_SIGNAL_RUN_LAST,
1621
 
                              G_STRUCT_OFFSET (PanelAppletClass, change_background),
1622
 
                              NULL,
1623
 
                              NULL,
1624
 
                              panel_applet_marshal_VOID__ENUM_BOXED_OBJECT,
1625
 
                              G_TYPE_NONE,
1626
 
                              3,
1627
 
                              PANEL_TYPE_PANEL_APPLET_BACKGROUND_TYPE,
1628
 
                              GDK_TYPE_COLOR,
1629
 
                              GDK_TYPE_PIXMAP);
1630
 
 
1631
 
        panel_applet_signals [MOVE_FOCUS_OUT_OF_APPLET] =
1632
 
                g_signal_new ("move_focus_out_of_applet",
1633
 
                              G_TYPE_FROM_CLASS (klass),
1634
 
                              G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1635
 
                              G_STRUCT_OFFSET (PanelAppletClass, move_focus_out_of_applet),
1636
 
                              NULL,
1637
 
                              NULL,
1638
 
                              panel_applet_marshal_VOID__ENUM,
1639
 
                              G_TYPE_NONE,
1640
 
                              1,
1641
 
                              GTK_TYPE_DIRECTION_TYPE);
1642
 
 
1643
 
        binding_set = gtk_binding_set_by_class (object_class);
1644
 
        add_tab_bindings (binding_set, 0, GTK_DIR_TAB_FORWARD);
1645
 
        add_tab_bindings (binding_set, GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
1646
 
        add_tab_bindings (binding_set, GDK_CONTROL_MASK, GTK_DIR_TAB_FORWARD);
1647
 
        add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD);
1648
 
}
1649
 
 
1650
 
static void
1651
 
panel_applet_init (PanelApplet *applet)
1652
 
{
1653
 
        applet->priv = PANEL_APPLET_GET_PRIVATE (applet);
1654
 
 
1655
 
        applet->priv->client = gconf_client_get_default ();
1656
 
 
1657
 
        applet->priv->bound  = FALSE;
1658
 
        applet->priv->flags  = PANEL_APPLET_FLAGS_NONE;
1659
 
        applet->priv->orient = PANEL_APPLET_ORIENT_UP;
1660
 
        applet->priv->size   = GNOME_Vertigo_PANEL_MEDIUM;
1661
 
 
1662
 
        applet->priv->moving_focus_out = FALSE;
1663
 
 
1664
 
        gtk_widget_set_events (GTK_WIDGET (applet),
1665
 
                               GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK);
1666
 
}
1667
 
 
1668
 
static void
1669
 
panel_applet_setup (PanelApplet *applet)
1670
 
{
1671
 
        PanelAppletPrivate *priv;
1672
 
 
1673
 
        priv = applet->priv;
1674
 
 
1675
 
        priv->control = bonobo_control_new (GTK_WIDGET (applet));
1676
 
 
1677
 
        g_signal_connect (priv->control, "set_frame",
1678
 
                          G_CALLBACK (panel_applet_control_bound),
1679
 
                          applet);
1680
 
 
1681
 
        priv->prop_sack = panel_applet_property_bag (applet);
1682
 
 
1683
 
        bonobo_control_set_properties (
1684
 
                        priv->control, BONOBO_OBJREF (priv->prop_sack), NULL);
1685
 
 
1686
 
        priv->shell = panel_applet_shell_new (applet);
1687
 
 
1688
 
        bonobo_object_add_interface (BONOBO_OBJECT (priv->control),
1689
 
                                     BONOBO_OBJECT (priv->shell));
1690
 
 
1691
 
        priv->item_handler =
1692
 
                bonobo_item_handler_new (
1693
 
                        NULL, panel_applet_item_handler_get_object, applet);
1694
 
 
1695
 
        bonobo_object_add_interface (BONOBO_OBJECT (priv->control),
1696
 
                                     BONOBO_OBJECT (priv->item_handler));
1697
 
 
1698
 
        g_signal_connect (applet, "popup_menu",
1699
 
                          G_CALLBACK (panel_applet_popup_menu), NULL);
1700
 
}
1701
 
 
1702
 
GtkWidget *
1703
 
panel_applet_new (void)
1704
 
{
1705
 
        PanelApplet *applet;
1706
 
 
1707
 
        applet = g_object_new (PANEL_TYPE_APPLET, NULL);
1708
 
 
1709
 
        return GTK_WIDGET (applet);
1710
 
}
1711
 
 
1712
 
typedef struct {
1713
 
        GType     applet_type;
1714
 
        GClosure *closure;
1715
 
} PanelAppletCallBackData;
1716
 
 
1717
 
static PanelAppletCallBackData *
1718
 
panel_applet_callback_data_new (GType     applet_type,
1719
 
                                GClosure *closure)
1720
 
{
1721
 
        PanelAppletCallBackData *retval;
1722
 
 
1723
 
        retval = g_new0 (PanelAppletCallBackData, 1);
1724
 
 
1725
 
        retval->applet_type = applet_type;
1726
 
        retval->closure     = closure;
1727
 
 
1728
 
        return retval;
1729
 
}
1730
 
 
1731
 
static void
1732
 
panel_applet_callback_data_free (PanelAppletCallBackData *data)
1733
 
{
1734
 
        g_closure_unref (data->closure);
1735
 
        g_free (data);
1736
 
}
1737
 
 
1738
 
static BonoboObject *
1739
 
panel_applet_factory_callback (BonoboGenericFactory    *factory,
1740
 
                               const char              *iid,
1741
 
                               PanelAppletCallBackData *data)
1742
 
{
1743
 
        PanelApplet *applet;
1744
 
 
1745
 
        applet = g_object_new (data->applet_type, NULL);
1746
 
 
1747
 
        applet->priv->iid     = g_strdup (iid);
1748
 
        applet->priv->closure = g_closure_ref (data->closure);
1749
 
 
1750
 
        bonobo_control_life_instrument (applet->priv->control);
1751
 
 
1752
 
        return BONOBO_OBJECT (applet->priv->control);
1753
 
}
1754
 
 
1755
 
static void
1756
 
panel_applet_all_controls_dead (void)
1757
 
{
1758
 
        if (!bonobo_control_life_get_count())
1759
 
                bonobo_main_quit ();
1760
 
}
1761
 
 
1762
 
int
1763
 
panel_applet_factory_main_closure (const gchar *iid,
1764
 
                                   GType        applet_type,
1765
 
                                   GClosure    *closure)
1766
 
{
1767
 
        int                      retval;
1768
 
        char                    *display_iid;
1769
 
        PanelAppletCallBackData *data;
1770
 
 
1771
 
        g_return_val_if_fail (iid != NULL, 1);
1772
 
        g_return_val_if_fail (closure != NULL, 1);
1773
 
 
1774
 
        g_assert (g_type_is_a (applet_type, PANEL_TYPE_APPLET));
1775
 
 
1776
 
        bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
1777
 
        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
1778
 
 
1779
 
        bonobo_control_life_set_callback (panel_applet_all_controls_dead);
1780
 
 
1781
 
        closure = bonobo_closure_store (closure, panel_applet_marshal_BOOLEAN__STRING);
1782
 
 
1783
 
        data = panel_applet_callback_data_new (applet_type, closure);
1784
 
 
1785
 
        display_iid = bonobo_activation_make_registration_id (
1786
 
                iid, DisplayString (gdk_display_get_default ()));
1787
 
        retval = bonobo_generic_factory_main (
1788
 
                display_iid,
1789
 
                (BonoboFactoryCallback) panel_applet_factory_callback,
1790
 
                data);
1791
 
        g_free (display_iid);
1792
 
 
1793
 
        panel_applet_callback_data_free (data);
1794
 
 
1795
 
        return retval;
1796
 
}
1797
 
 
1798
 
int
1799
 
panel_applet_factory_main (const gchar                 *iid,
1800
 
                           GType                        applet_type,
1801
 
                           PanelAppletFactoryCallback   callback,
1802
 
                           gpointer                     data)
1803
 
{
1804
 
        GClosure *closure;
1805
 
 
1806
 
        g_return_val_if_fail (iid != NULL, 1);
1807
 
        g_return_val_if_fail (callback != NULL, 1);
1808
 
 
1809
 
        closure = g_cclosure_new (G_CALLBACK (callback), data, NULL);
1810
 
 
1811
 
        return panel_applet_factory_main_closure (iid, applet_type, closure);
1812
 
}
1813
 
 
1814
 
Bonobo_Unknown
1815
 
panel_applet_shlib_factory_closure (const char         *iid,
1816
 
                                    GType               applet_type,
1817
 
                                    PortableServer_POA  poa,
1818
 
                                    gpointer            impl_ptr,
1819
 
                                    GClosure           *closure,
1820
 
                                    CORBA_Environment  *ev)
1821
 
{
1822
 
        BonoboShlibFactory *factory;
1823
 
 
1824
 
        g_return_val_if_fail (iid != NULL, CORBA_OBJECT_NIL);
1825
 
        g_return_val_if_fail (closure != NULL, CORBA_OBJECT_NIL);
1826
 
 
1827
 
        g_assert (g_type_is_a (applet_type, PANEL_TYPE_APPLET));
1828
 
 
1829
 
        bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
1830
 
        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
1831
 
 
1832
 
        closure = bonobo_closure_store (closure, panel_applet_marshal_BOOLEAN__STRING);
1833
 
 
1834
 
        factory = bonobo_shlib_factory_new_closure (
1835
 
                        iid, poa, impl_ptr,
1836
 
                        g_cclosure_new (G_CALLBACK (panel_applet_factory_callback),
1837
 
                                        panel_applet_callback_data_new (applet_type, closure),
1838
 
                                        (GClosureNotify) panel_applet_callback_data_free));
1839
 
 
1840
 
        return CORBA_Object_duplicate (BONOBO_OBJREF (factory), ev);
1841
 
}
1842
 
 
1843
 
Bonobo_Unknown
1844
 
panel_applet_shlib_factory (const char                 *iid,
1845
 
                            GType                       applet_type,
1846
 
                            PortableServer_POA          poa,
1847
 
                            gpointer                    impl_ptr,
1848
 
                            PanelAppletFactoryCallback  callback,
1849
 
                            gpointer                    user_data,
1850
 
                            CORBA_Environment          *ev)
1851
 
{
1852
 
        g_return_val_if_fail (iid != NULL, CORBA_OBJECT_NIL);
1853
 
        g_return_val_if_fail (callback != NULL, CORBA_OBJECT_NIL);
1854
 
 
1855
 
        return panel_applet_shlib_factory_closure (
1856
 
                        iid, applet_type, poa, impl_ptr,
1857
 
                        g_cclosure_new (G_CALLBACK (callback),
1858
 
                                        user_data, NULL),
1859
 
                        ev);
1860
 
}
1861
 
 
1862
 
void
1863
 
panel_applet_set_background_widget (PanelApplet *applet,
1864
 
                                    GtkWidget   *widget)
1865
 
{
1866
 
        applet->priv->background_widget = widget;
1867
 
 
1868
 
        if (widget) {
1869
 
                PanelAppletBackgroundType  type;
1870
 
                GdkColor                   color;
1871
 
                GdkPixmap                 *pixmap;
1872
 
 
1873
 
                type = panel_applet_get_background (applet, &color, &pixmap);
1874
 
                panel_applet_update_background_for_widget (widget, type,
1875
 
                                                           &color, pixmap);
1876
 
                if (type == PANEL_PIXMAP_BACKGROUND)
1877
 
                        g_object_unref (pixmap);
1878
 
        }
1879
 
}