]> git.pld-linux.org Git - packages/gnome-panel.git/blob - gnome-panel-menu-stripe.patch
- merged from DEVEL, but it doesn't work for now
[packages/gnome-panel.git] / gnome-panel-menu-stripe.patch
1 diff -urN aa/gnome-panel-2.5.92/gnome-panel/Makefile.am gnome-panel-2.5.92/gnome-panel/Makefile.am
2 --- aa/gnome-panel-2.5.92/gnome-panel/Makefile.am       2004-02-06 17:04:50.000000000 +0100
3 +++ gnome-panel-2.5.92/gnome-panel/Makefile.am  2004-03-12 14:24:21.791325944 +0100
4 @@ -80,6 +80,8 @@
5         panel-typebuiltins.h    \
6         panel-marshal.c         \
7         panel-marshal.h         \
8 +       panel-menu.c            \
9 +       panel-menu.h            \
10         main.c                  \
11         panel-widget.c          \
12         button-widget.c         \
13 diff -urN aa/gnome-panel-2.5.92/gnome-panel/menu.c gnome-panel-2.5.92/gnome-panel/menu.c
14 --- aa/gnome-panel-2.5.92/gnome-panel/menu.c    2004-03-09 11:08:47.000000000 +0100
15 +++ gnome-panel-2.5.92/gnome-panel/menu.c       2004-03-12 14:24:21.795325336 +0100
16 @@ -44,6 +44,7 @@
17  #include "menu-fentry.h"
18  #include "menu-util.h"
19  #include "menu-ditem.h"
20 +#include "panel-menu.h"
21  #include "panel-util.h"
22  #include "panel-gconf.h"
23  #include "panel.h"
24 @@ -67,6 +68,7 @@
25  #include "panel-lockdown.h"
26  
27  #undef MENU_DEBUG
28 +#define MENU_SNAP_LENGTH 10
29  
30  static char *gnome_folder = NULL;
31  
32 @@ -614,6 +616,9 @@
33         if (repo->orig_func != NULL) {
34                 repo->orig_func (menu, x, y, push_in, repo->orig_data);
35  
36 +               if (*x < MENU_SNAP_LENGTH)
37 +                 *x = 0;
38 +
39                 if (menu->parent_menu_item != NULL) {
40                         /* This is a submenu so behave submenuish */
41                         if (*x < monitor_basex ||
42 @@ -709,8 +714,8 @@
43         reload_image_menu_items ();
44  }
45  
46 -GtkWidget *
47 -panel_create_menu (void)
48 +static GtkWidget *
49 +panel_create_menu_of_type (GType menu_type)
50  {
51         GtkWidget       *retval;
52         static gboolean  registered_icon_theme_changer = FALSE;
53 @@ -722,8 +727,7 @@
54                                   G_CALLBACK (icon_theme_changed), NULL);
55         }
56         
57 -       retval = gtk_menu_new ();
58 -       
59 +       retval = g_object_new (menu_type, NULL);
60         panel_gconf_notify_add_while_alive ("/desktop/gnome/interface/menus_have_icons",
61                                             (GConfClientNotifyFunc) menus_have_icons_changed,
62                                             G_OBJECT (retval));
63 @@ -739,12 +743,18 @@
64         return retval;
65  }
66  
67 +GtkWidget *
68 +panel_create_menu (void)
69 +{
70 +        return panel_create_menu_of_type (gtk_menu_get_type());
71 +}
72 +
73  static GtkWidget *
74 -menu_new (void)
75 +menu_new_of_type (GType menu_type)
76  {
77         GtkWidget *retval;
78  
79 -       retval = panel_create_menu ();
80 +       retval = panel_create_menu_of_type (menu_type);
81  
82         g_signal_connect (
83                 retval, "show", G_CALLBACK (setup_menu_panel), NULL);
84 @@ -752,6 +762,13 @@
85         return retval;
86  }
87  
88 +static GtkWidget *
89 +menu_new (void)
90 +{
91 +       return menu_new_of_type (gtk_menu_get_type ());
92 +}
93 +
94 +
95  static void
96  icon_to_load_free (IconToLoad *icon)
97  {
98 @@ -3314,7 +3331,7 @@
99         }
100  
101         if (!root_menu)
102 -               root_menu = menu_new ();
103 +               root_menu = menu_new_of_type (panel_menu_get_type ());
104  
105         g_object_set_data (G_OBJECT (root_menu), "menu_panel", panel);
106  
107 diff -urN aa/gnome-panel-2.5.92/gnome-panel/panel-config-global.c gnome-panel-2.5.92/gnome-panel/panel-config-global.c
108 --- aa/gnome-panel-2.5.92/gnome-panel/panel-config-global.c     2004-01-18 15:35:47.000000000 +0100
109 +++ gnome-panel-2.5.92/gnome-panel/panel-config-global.c        2004-03-12 14:24:21.795325336 +0100
110 @@ -45,6 +45,7 @@
111         guint               drawer_auto_close : 1;
112         guint               confirm_panel_remove : 1;
113         guint               highlight_when_over : 1;
114 +       guint               menu_stripe : 1;
115  } GlobalConfig;
116  
117  static GlobalConfig global_config = { 0, };
118 @@ -94,6 +95,13 @@
119  
120         return global_config.confirm_panel_remove;
121  }
122 +gboolean
123 +panel_global_config_get_menu_stripe (void)
124 +{
125 +       g_assert (global_config_initialised == TRUE);
126 +
127 +       return global_config.menu_stripe;
128 +}
129  
130  static void
131  panel_global_config_set_entry (GConfEntry *entry)
132 @@ -151,6 +159,11 @@
133         else if (strcmp (key, "highlight_launchers_on_mouseover") == 0)
134                 global_config.highlight_when_over =
135                         gconf_value_get_bool (value);
136 +
137 +  else if (strcmp (key, "show_menu_stripe") == 0)
138 +    global_config.menu_stripe =
139 +        gconf_value_get_bool (value);
140 +
141  }
142  
143  static void
144 diff -urN aa/gnome-panel-2.5.92/gnome-panel/panel-config-global.h gnome-panel-2.5.92/gnome-panel/panel-config-global.h
145 --- aa/gnome-panel-2.5.92/gnome-panel/panel-config-global.h     2004-01-18 15:32:28.000000000 +0100
146 +++ gnome-panel-2.5.92/gnome-panel/panel-config-global.h        2004-03-12 14:24:21.796325184 +0100
147 @@ -37,6 +37,7 @@
148  gboolean panel_global_config_get_drawer_auto_close    (void);
149  gboolean panel_global_config_get_tooltips_enabled     (void);
150  gboolean panel_global_config_get_confirm_panel_remove (void);
151 +gboolean panel_global_config_get_menu_stripe         (void);
152  
153  G_END_DECLS
154  
155 diff -urN aa/gnome-panel-2.5.92/gnome-panel/panel-global.schemas.in gnome-panel-2.5.92/gnome-panel/panel-global.schemas.in
156 --- aa/gnome-panel-2.5.92/gnome-panel/panel-global.schemas.in   2004-01-18 16:10:23.000000000 +0100
157 +++ gnome-panel-2.5.92/gnome-panel/panel-global.schemas.in      2004-03-12 14:24:21.797325032 +0100
158 @@ -93,6 +93,18 @@
159        </schema>
160  
161        <schema>
162 +        <key>/schemas/apps/panel/global/show_menu_stripe</key>
163 +        <applyto>/apps/panel/global/show_menu_stripe</applyto>
164 +        <owner>panel</owner>
165 +        <type>bool</type>
166 +        <default>true</default>
167 +        <locale name="C">
168 +          <short></short>
169 +          <long></long>
170 +        </locale>
171 +      </schema>
172 +
173 +      <schema>
174          <key>/schemas/apps/panel/global/enable_key_bindings</key>
175          <applyto>/apps/panel/global/enable_key_bindings</applyto>
176          <owner>panel</owner>
177 diff -urN aa/gnome-panel-2.5.92/gnome-panel/panel-menu.c gnome-panel-2.5.92/gnome-panel/panel-menu.c
178 --- aa/gnome-panel-2.5.92/gnome-panel/panel-menu.c      1970-01-01 01:00:00.000000000 +0100
179 +++ gnome-panel-2.5.92/gnome-panel/panel-menu.c 2004-03-12 14:39:15.063527928 +0100
180 @@ -0,0 +1,916 @@
181 +/*
182 + * To set this up insert something like this in your ~/.gtkrc-2.0
183 + *
184 + * Copyright (C) 2002 Ximian, Inc. 
185 + * Copyright (C) 2001 Havoc Pennington
186 + * Copyright (C) 1997-2000 Dan Pascu and Alfredo Kojima
187 + * Copyright (C) 2003 Marcin Krzy¿anowski
188 + * 
189 + * style "default"
190 + * {
191 + *   PanelMenu::default_side_image = "/tmp/stripelogo.png"
192 + *   PanelMenu::gradient_bg = true
193 + * }
194 + * class "PanelMenu" style "default"
195 + *
196 + * Authors:
197 + *       Thomas, Michael Meeks
198 + *       GtkMenu code by the GTK+ team
199 + *       Gradient code from WindowMaker by Dan Pascu and Alfredo Kojima, 
200 + *         by way of metacity by Havoc Pennington.
201 + *       Marcin Krzy¿anowski
202 + */
203 +#include <config.h>
204 +#include <string.h>
205 +#include <libgnome/gnome-macros.h>
206 +#include <libgnome/gnome-program.h>
207 +#include <libgnome/gnome-i18n.h>
208 +#include <gtk/gtkgc.h>
209 +#include <gtk/gtkimagemenuitem.h>
210 +#include <gtk/gtkseparatormenuitem.h>
211 +#include <gtk/gtkmenu.h>
212 +#include <gtk/gtkwidget.h>
213 +#include <gtk/gtkwindow.h>
214 +#include <gtk/gtkmain.h>
215 +#include <gdk/gdkwindow.h>
216 +#include <panel-menu.h>
217 +
218 +#include "panel-config-global.h"
219 +
220 +#define dprintf(a) g_warning a
221 +/*#define dprintf(a) G_STMT_START { (void) 0; } G_STMT_END*/
222 +
223 +GNOME_CLASS_BOILERPLATE (PanelMenu, panel_menu,
224 +                        GtkMenu, GTK_TYPE_MENU)
225 +
226 +
227 +
228 +static void
229 +panel_menu_size_request  (GtkWidget *widget,
230 +                         GtkRequisition *requisition)
231 +{
232 +       PanelMenu *pm = PANEL_MENU (widget);
233 +
234 +       GTK_WIDGET_CLASS (parent_class)->size_request (widget, requisition);
235 +
236 +       if (panel_global_config_get_menu_stripe () && pm->side_image != NULL)
237 +               requisition->width += gdk_pixbuf_get_width (pm->side_image)
238 +                      + gtk_widget_get_style (widget)->xthickness;
239 +}
240 +
241 +static GdkColor *
242 +get_light_stripe_color (PanelMenu *pm)
243 +{
244 +       GdkColor *color;
245 +       
246 +       gtk_widget_style_get (GTK_WIDGET (pm),
247 +                             "stripe-color-light", &color,
248 +                             NULL);
249 +
250 +       if (!color) {
251 +               color = gdk_color_copy (&GTK_WIDGET (pm)->style->bg[GTK_STATE_NORMAL]);
252 +       }
253 +       
254 +       return color;
255 +}
256 +
257 +static GdkColor *
258 +get_stripe_color (PanelMenu *pm)
259 +{
260 +       GdkColor *color;
261 +       
262 +       gtk_widget_style_get (GTK_WIDGET (pm),
263 +                             "stripe-color", &color,
264 +                             NULL);
265 +
266 +       if (!color) {
267 +               color = gdk_color_copy (&GTK_WIDGET (pm)->style->bg[GTK_STATE_SELECTED]);
268 +       }
269 +       
270 +       return color;
271 +}
272 +
273 +static GdkGC *
274 +get_stripe_gc (PanelMenu *pm) 
275 +{
276 +       GdkGCValues gc_values;
277 +       GdkGCValuesMask gc_values_mask;
278 +       GdkColor *color;
279 +       
280 +       color = get_stripe_color (pm);
281 +       gc_values.foreground = *color;
282 +       gdk_color_free (color);
283 +       gc_values_mask = GDK_GC_FOREGROUND;
284 +       
285 +       gdk_rgb_find_color (GTK_WIDGET (pm)->style->colormap, &gc_values.foreground);
286 +
287 +       return gtk_gc_get (GTK_WIDGET (pm)->style->depth,
288 +                          GTK_WIDGET (pm)->style->colormap,
289 +                          &gc_values, gc_values_mask);
290 +}
291 +
292 +static gboolean
293 +panel_menu_expose_event (GtkWidget      *widget,
294 +                        GdkEventExpose *event)
295 +{
296 +       GdkRectangle exposed;
297 +       GdkRectangle position;
298 +       GdkWindow   *window;
299 +       int bin_height;
300 +       GdkGC *stripe_gc;
301 +       PanelMenu *pm = PANEL_MENU (widget);
302 +
303 +       GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event);
304 +
305 +       if (!panel_global_config_get_menu_stripe () || !pm->side_image) {
306 +              return TRUE;
307 +       }
308 +       window = GTK_MENU (widget)->bin_window;
309 +
310 +       stripe_gc = get_stripe_gc (pm);
311 +
312 +       gdk_gc_set_clip_rectangle (stripe_gc, &event->area);       
313 +       gdk_draw_rectangle (window,
314 +                          stripe_gc,
315 +                          TRUE,
316 +                          widget->allocation.x,
317 +                          widget->allocation.y,
318 +                          gdk_pixbuf_get_width (pm->side_image),
319 +                          widget->allocation.height);
320 +       gdk_gc_set_clip_rectangle (stripe_gc, NULL);
321 +
322 +       bin_height = widget->allocation.height - 2 * (GTK_CONTAINER (widget)->border_width + widget->style->ythickness);
323 +
324 +       position = widget->allocation;
325 +       position.y += bin_height - gdk_pixbuf_get_height (pm->side_image);
326 +       position.width = gdk_pixbuf_get_width (pm->side_image);
327 +       position.height = gdk_pixbuf_get_height (pm->side_image);
328 +
329 +       if (widget->allocation.height >= gdk_pixbuf_get_height (pm->side_image)) {
330 +              if (gdk_rectangle_intersect (&event->area,
331 +                                           &position,
332 +                                           &exposed)) {
333 +                      gdk_pixbuf_render_to_drawable (
334 +                              pm->side_image, window,
335 +                              widget->style->black_gc,
336 +                              exposed.x - position.x,
337 +                              exposed.y - position.y,
338 +                              exposed.x, exposed.y,
339 +                              exposed.width, exposed.height,
340 +                              GDK_RGB_DITHER_NORMAL,
341 +                              exposed.x, exposed.y);
342 +              }
343 +       }
344 +               
345 +       position = widget->allocation;
346 +       if (position.height != gdk_pixbuf_get_height (pm->side_image)) {
347 +               position.width = gdk_pixbuf_get_width (pm->side_image);
348 +              if (position.height > gdk_pixbuf_get_height (pm->side_image)) {
349 +                      position.height = bin_height - gdk_pixbuf_get_height (pm->side_image);
350 +              } else {
351 +                      position.height = bin_height;
352 +              }
353 +              
354 +               if (pm->scaled_image && gdk_rectangle_intersect (&event->area,
355 +                                                               &position,
356 +                                                               &exposed)) {
357 +      
358 +                       gdk_pixbuf_render_to_drawable (
359 +                               pm->scaled_image, window,
360 +                               widget->style->black_gc,
361 +                               exposed.x - position.x,
362 +                               exposed.y - position.y,
363 +                               exposed.x, exposed.y,
364 +                               exposed.width, exposed.height,
365 +                               GDK_RGB_DITHER_NORMAL,
366 +                               exposed.x, exposed.y);
367 +               }
368 +       }
369 +
370 +       return TRUE;
371 +}
372 +
373 +/* begin metacity cut and paste */
374 +static void
375 +free_buffer (guchar *pixels, gpointer data)
376 +{
377 +  g_free (pixels);
378 +}
379 +
380 +static GdkPixbuf*
381 +blank_pixbuf (int width, int height, gboolean no_padding)
382 +{
383 +  guchar *buf;
384 +  int rowstride;
385 +
386 +  g_return_val_if_fail (width > 0, NULL);
387 +  g_return_val_if_fail (height > 0, NULL);
388 +
389 +  if (no_padding)
390 +    rowstride = width * 3;
391 +  else
392 +    /* Always align rows to 32-bit boundaries */  
393 +    rowstride = 4 * ((3 * width + 3) / 4);
394 +
395 +  buf = g_try_malloc (height * rowstride);
396 +  if (!buf)
397 +    return NULL;
398 +
399 +  return gdk_pixbuf_new_from_data (buf, GDK_COLORSPACE_RGB,
400 +                                   FALSE, 8,
401 +                                   width, height, rowstride,
402 +                                   free_buffer, NULL);
403 +}
404 +
405 +static GdkPixbuf*
406 +meta_gradient_create_vertical (int width, int height,
407 +                               const GdkColor *from,
408 +                               const GdkColor *to)
409 +{
410 +  int i, j;
411 +  long r, g, b, dr, dg, db;
412 +  GdkPixbuf *pixbuf;
413 +  unsigned char *ptr;
414 +  unsigned char rr, gg, bb;
415 +  int r0, g0, b0;
416 +  int rf, gf, bf;
417 +  int rowstride;
418 +  unsigned char *pixels;
419 +  
420 +  pixbuf = blank_pixbuf (width, height, FALSE);
421 +  if (pixbuf == NULL)
422 +    return NULL;
423 +    
424 +  pixels = gdk_pixbuf_get_pixels (pixbuf);
425 +  rowstride = gdk_pixbuf_get_rowstride (pixbuf);
426 +  
427 +  r0 = (guchar) (from->red / 256.0);
428 +  g0 = (guchar) (from->green / 256.0);
429 +  b0 = (guchar) (from->blue / 256.0);
430 +  rf = (guchar) (to->red / 256.0);
431 +  gf = (guchar) (to->green / 256.0);
432 +  bf = (guchar) (to->blue / 256.0);
433 +  
434 +  r = r0<<16;
435 +  g = g0<<16;
436 +  b = b0<<16;
437 +
438 +  dr = ((rf-r0)<<16)/(int)height;
439 +  dg = ((gf-g0)<<16)/(int)height;
440 +  db = ((bf-b0)<<16)/(int)height;
441 +
442 +  for (i=0; i<height; i++)
443 +    {
444 +      ptr = pixels + i * rowstride;
445 +      
446 +      rr = r>>16;
447 +      gg = g>>16;
448 +      bb = b>>16;
449 +      for (j=0; j<width/8; j++)
450 +        {
451 +          *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
452 +          *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
453 +          *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
454 +          *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
455 +          *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
456 +          *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
457 +          *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
458 +          *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
459 +       }
460 +      switch (width%8)
461 +        {
462 +        case 7: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
463 +        case 6: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
464 +        case 5: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
465 +        case 4: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
466 +        case 3: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
467 +        case 2: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
468 +        case 1: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
469 +       }
470 +      r+=dr;
471 +      g+=dg;
472 +      b+=db;
473 +    }
474 +  return pixbuf;
475 +}
476 +
477 +/* end metacity cut and paste */
478 +
479 +/* begin gtkmenu.c cut and paste */
480 +
481 +#define MENU_SCROLL_ARROW_HEIGHT 16
482 +
483 +typedef struct _GtkMenuPrivate         GtkMenuPrivate;
484 +struct _GtkMenuPrivate 
485 +{
486 +  gboolean have_position;
487 +  gint x;
488 +  gint y;
489 +
490 +  /* info used for the table */
491 +  guint rows;
492 +  guint columns;
493 +
494 +  guint *heights;
495 +  gint heights_length;
496 +
497 +  gint monitor_num;
498 +};
499 +
500 +static void
501 +gtk_menu_free_private (gpointer data)
502 +{
503 +  GtkMenuPrivate *priv = (GtkMenuPrivate *)data;
504 +
505 +  g_free (priv->heights);
506 +
507 +  g_free (priv);
508 +}
509 +
510 +static GtkMenuPrivate *
511 +gtk_menu_get_private (GtkMenu *menu)
512 +{
513 +  GtkMenuPrivate *private;
514 +  static GQuark private_quark = 0;
515 +
516 +  if (!private_quark)
517 +    private_quark = g_quark_from_static_string ("gtk-menu-private");
518 +
519 +  private = g_object_get_qdata (G_OBJECT (menu), private_quark);
520 +
521 +  if (!private)
522 +    {
523 +      private = g_new0 (GtkMenuPrivate, 1);
524 +      private->have_position = FALSE;
525 +      
526 +      g_object_set_qdata_full (G_OBJECT (menu), private_quark,
527 +                              private, gtk_menu_free_private);
528 +    }
529 +
530 +  return private;
531 +}
532 +
533 +static void
534 +gtk_menu_remove_scroll_timeout (GtkMenu *menu)
535 +{
536 +  if (menu->timeout_id)
537 +    {
538 +      g_source_remove (menu->timeout_id);
539 +      menu->timeout_id = 0;
540 +    }
541 +}
542 +
543 +static void
544 +gtk_menu_stop_scrolling (GtkMenu *menu)
545 +{
546 +  gtk_menu_remove_scroll_timeout (menu);
547 +
548 +  menu->upper_arrow_prelight = FALSE;
549 +  menu->lower_arrow_prelight = FALSE;
550 +}
551 +
552 +static void
553 +gtk_menu_scroll_to (GtkMenu *menu,
554 +                   gint    offset)
555 +{
556 +  GtkWidget *widget;
557 +  gint x, y;
558 +  gint view_width, view_height;
559 +  gint border_width;
560 +  gboolean last_visible;
561 +  gint menu_height;
562 +  guint vertical_padding;
563 +
564 +  widget = GTK_WIDGET (menu);
565 +
566 +  if (menu->tearoff_active &&
567 +      menu->tearoff_adjustment &&
568 +      (menu->tearoff_adjustment->value != offset))
569 +    {
570 +      menu->tearoff_adjustment->value =
571 +       CLAMP (offset,
572 +              0, menu->tearoff_adjustment->upper - menu->tearoff_adjustment->page_size);
573 +      gtk_adjustment_value_changed (menu->tearoff_adjustment);
574 +    }
575 +  
576 +  /* Move/resize the viewport according to arrows: */
577 +  view_width = widget->allocation.width;
578 +  view_height = widget->allocation.height;
579 +
580 +  gtk_widget_style_get (GTK_WIDGET (menu),
581 +                       "vertical-padding", &vertical_padding,
582 +                       NULL);
583 +  
584 +  border_width = GTK_CONTAINER (menu)->border_width;
585 +  view_width -= (border_width + widget->style->xthickness) * 2;
586 +  view_height -= (border_width + widget->style->ythickness + vertical_padding) * 2;
587 +  menu_height = widget->requisition.height -
588 +      (border_width + widget->style->ythickness + vertical_padding) * 2;
589 +
590 +  x = border_width + widget->style->xthickness;
591 +  y = border_width + widget->style->ythickness + vertical_padding;
592 +
593 +  if (!menu->tearoff_active)
594 +    {
595 +      last_visible = menu->upper_arrow_visible;
596 +      menu->upper_arrow_visible = offset > 0;
597 +      
598 +      if (menu->upper_arrow_visible)
599 +       view_height -= MENU_SCROLL_ARROW_HEIGHT;
600 +      
601 +      if ( (last_visible != menu->upper_arrow_visible) &&
602 +          !menu->upper_arrow_visible)
603 +       {
604 +         menu->upper_arrow_prelight = FALSE;
605 +         
606 +         /* If we hid the upper arrow, possibly remove timeout */
607 +         if (menu->scroll_step < 0)
608 +           {
609 +             gtk_menu_stop_scrolling (menu);
610 +             gtk_widget_queue_draw (GTK_WIDGET (menu));
611 +           }
612 +       }
613 +
614 +      last_visible = menu->lower_arrow_visible;
615 +      menu->lower_arrow_visible = offset < menu_height - view_height;
616 +      
617 +      if (menu->lower_arrow_visible)
618 +       view_height -= MENU_SCROLL_ARROW_HEIGHT;
619 +      
620 +      if ( (last_visible != menu->lower_arrow_visible) &&
621 +          !menu->lower_arrow_visible)
622 +       {
623 +         menu->lower_arrow_prelight = FALSE;
624 +         
625 +         /* If we hid the lower arrow, possibly remove timeout */
626 +         if (menu->scroll_step > 0)
627 +           {
628 +             gtk_menu_stop_scrolling (menu);
629 +             gtk_widget_queue_draw (GTK_WIDGET (menu));
630 +           }
631 +       }
632 +      
633 +      if (menu->upper_arrow_visible)
634 +       y += MENU_SCROLL_ARROW_HEIGHT;
635 +    }
636 +
637 +  /* Scroll the menu: */
638 +  if (GTK_WIDGET_REALIZED (menu))
639 +    gdk_window_move (menu->bin_window, 0, -offset);
640 +
641 +  if (GTK_WIDGET_REALIZED (menu))
642 +    gdk_window_move_resize (menu->view_window,
643 +                           x,
644 +                           y,
645 +                           view_width,
646 +                           view_height);
647 +
648 +  menu->scroll_offset = offset;
649 +}
650 +
651 +static void
652 +gtk_menu_set_tearoff_hints (GtkMenu *menu,
653 +                           gint     width)
654 +{
655 +  GdkGeometry geometry_hints;
656 +  
657 +  if (!menu->tearoff_window)
658 +    return;
659 +
660 +  if (GTK_WIDGET_VISIBLE (menu->tearoff_scrollbar))
661 +    {
662 +      gtk_widget_size_request (menu->tearoff_scrollbar, NULL);
663 +      width += menu->tearoff_scrollbar->requisition.width;
664 +    }
665 +
666 +  geometry_hints.min_width = width;
667 +  geometry_hints.max_width = width;
668 +    
669 +  geometry_hints.min_height = 0;
670 +  geometry_hints.max_height = GTK_WIDGET (menu)->requisition.height;
671 +
672 +  gtk_window_set_geometry_hints (GTK_WINDOW (menu->tearoff_window),
673 +                                NULL,
674 +                                &geometry_hints,
675 +                                GDK_HINT_MAX_SIZE|GDK_HINT_MIN_SIZE);
676 +}
677 +
678 +static void
679 +get_child_attach (GtkWidget *child,
680 +                  gint      *l,
681 +                  gint      *r,
682 +                  gint      *t,
683 +                  gint      *b)
684 +{
685 +  gtk_container_child_get (GTK_CONTAINER (child->parent), child,
686 +                           "left_attach", l,
687 +                           "right_attach", r,
688 +                           "top_attach", t,
689 +                           "bottom_attach", b,
690 +                           NULL);
691 +}
692 +
693 +static void
694 +gtk_menu_size_allocate (GtkWidget     *widget,
695 +                       GtkAllocation *allocation)
696 +{
697 +  GtkMenu *menu;
698 +  GtkMenuShell *menu_shell;
699 +  GtkWidget *child;
700 +  GtkAllocation child_allocation;
701 +  GtkRequisition child_requisition;
702 +  GtkMenuPrivate *priv;
703 +  GList *children;
704 +  gint x, y;
705 +  gint width, height;
706 +  guint vertical_padding;
707 +  guint menu_stripe_width;
708 +
709 +  g_return_if_fail (GTK_IS_MENU (widget));
710 +  g_return_if_fail (allocation != NULL);
711 +  
712 +  menu = GTK_MENU (widget);
713 +  menu_shell = GTK_MENU_SHELL (widget);
714 +  priv = gtk_menu_get_private (menu);
715
716 +  widget->allocation = *allocation;
717 +  gtk_widget_get_child_requisition (GTK_WIDGET (menu), &child_requisition);
718 +
719 +  gtk_widget_style_get (GTK_WIDGET (menu),
720 +                       "vertical-padding", &vertical_padding,
721 +                       NULL);
722 +  
723 +  x = GTK_CONTAINER (menu)->border_width + widget->style->xthickness;
724 +  y = GTK_CONTAINER (menu)->border_width + widget->style->ythickness + vertical_padding;
725 +
726 +  width = MAX (1, allocation->width - x * 2);
727 +  height = MAX (1, allocation->height - y * 2);
728 +
729 +  child_requisition.width -= x * 2;
730 +  child_requisition.height -= y * 2;
731 +
732 +  if (menu_shell->active)
733 +    gtk_menu_scroll_to (menu, menu->scroll_offset);
734 +  
735 +  if (menu->upper_arrow_visible && !menu->tearoff_active)
736 +    {
737 +      y += MENU_SCROLL_ARROW_HEIGHT;
738 +      height -= MENU_SCROLL_ARROW_HEIGHT;
739 +    }
740 +  
741 +  if (menu->lower_arrow_visible && !menu->tearoff_active)
742 +    height -= MENU_SCROLL_ARROW_HEIGHT;
743 +  
744 +  if (GTK_WIDGET_REALIZED (widget))
745 +    {
746 +      gdk_window_move_resize (widget->window,
747 +                             allocation->x, allocation->y,
748 +                             allocation->width, allocation->height);
749 +
750 +      gdk_window_move_resize (menu->view_window,
751 +                             x,
752 +                             y,
753 +                             width,
754 +                             height);
755 +    }
756 +
757 +/* inserted for panel-menu.c */
758 +  if (panel_global_config_get_menu_stripe () && PANEL_MENU (widget)->side_image) {
759 +    menu_stripe_width = gdk_pixbuf_get_width (PANEL_MENU (widget)->side_image) + gtk_widget_get_style (widget)->xthickness;
760 +  } else {
761 +    menu_stripe_width = 0;
762 +  }
763 +/* end panel-menu.c */
764 +
765 +  if (menu_shell->children)
766 +    {
767 +/* inserted for panel-menu.c */
768 +#if 0
769 +      gint base_width = width / priv->columns;
770 +#else
771 +      gint base_width = (width - menu_stripe_width) / priv->columns;
772 +#endif
773 +/* end panel-menu.c */
774 +
775 +      children = menu_shell->children;
776 +      while (children)
777 +       {
778 +         child = children->data;
779 +         children = children->next;
780 +
781 +         if (GTK_WIDGET_VISIBLE (child))
782 +           {
783 +              gint i;
784 +             guint l, r, t, b;
785 +
786 +              get_child_attach (child, &l, &r, &t, &b);
787 +
788 +              if (gtk_widget_get_direction (GTK_WIDGET (menu)) == GTK_TEXT_DIR_RTL)
789 +                {
790 +                  guint tmp;
791 +                  tmp = priv->columns - l;
792 +                  l = priv->columns - r;
793 +                  r = tmp;
794 +                }
795 +
796 +              child_allocation.width = (r - l) * base_width;
797 +              child_allocation.height = 0;
798 +/* inserted for panel-menu.c */
799 +#if 0
800 +              child_allocation.x = l * base_width;
801 +#else
802 +              child_allocation.x = l * base_width + menu_stripe_width;
803 +#endif
804 +              child_allocation.y = 0;
805 +
806 +              for (i = 0; i < b; i++)
807 +                {
808 +                  if (i < t)
809 +                    child_allocation.y += priv->heights[i];
810 +                  else
811 +                    child_allocation.height += priv->heights[i];
812 +                }
813 +
814 +
815 +             gtk_menu_item_toggle_size_allocate (GTK_MENU_ITEM (child),
816 +                                                 menu->toggle_size);
817 +
818 +             gtk_widget_size_allocate (child, &child_allocation);
819 +
820 +#if 0
821 +
822 +/* inserted for panel-menu.c */
823 +             if (use_menu_stripe && g_type_is_a (G_OBJECT_TYPE (child), GTK_TYPE_SEPARATOR_MENU_ITEM)) 
824 +               {
825 +                 /* this is dumb, gtkmenuitem.c uses allocation.width as an absolute point */
826 +                 child_allocation.width += gdk_pixbuf_get_width (PANEL_MENU (widget)->side_image);
827 +               }
828 +
829 +             gtk_widget_size_allocate (child, &child_allocation);
830 +
831 +             if (use_menu_stripe && g_type_is_a (G_OBJECT_TYPE (child), GTK_TYPE_SEPARATOR_MENU_ITEM)) 
832 +               {
833 +                 child_allocation.width -= gdk_pixbuf_get_width (PANEL_MENU (widget)->side_image);
834 +               }
835 +#endif
836 +
837 +             /* Hack to handle events on the stripe area */
838 +             if (GTK_WIDGET_REALIZED (child) && l == 0) 
839 +               { 
840 +                 gdk_window_move_resize (GTK_MENU_ITEM (child)->event_window,
841 +                                         0, child_allocation.y,
842 +                                         child_allocation.width + child_allocation.x, 
843 +                                         child_allocation.height);
844 +               }
845 +/* end panel-menu.c */
846 +
847 +             gtk_widget_queue_draw (child);
848 +           }
849 +       }
850 +      
851 +      /* Resize the item window */
852 +      if (GTK_WIDGET_REALIZED (widget))
853 +       {
854 +          gint i;
855 +          gint width, height;
856 +
857 +          height = 0;
858 +          for (i = 0; i < priv->rows; i++)
859 +            height += priv->heights[i];
860 +
861 +/* inserted for panel-menu.c */
862 +#if 0
863 +          width = priv->columns * base_width;
864 +#else
865 +          width = priv->columns * base_width + menu_stripe_width;
866 +#endif
867 +/* end panel-menu.c */
868 +
869 +         gdk_window_resize (menu->bin_window, width, height);
870 +       }
871 +
872 +      if (menu->tearoff_active)
873 +       {
874 +         if (allocation->height >= widget->requisition.height)
875 +           {
876 +             if (GTK_WIDGET_VISIBLE (menu->tearoff_scrollbar))
877 +               {
878 +                 gtk_widget_hide (menu->tearoff_scrollbar);
879 +                 gtk_menu_set_tearoff_hints (menu, allocation->width);
880 +
881 +                 gtk_menu_scroll_to (menu, 0);
882 +               }
883 +           }
884 +         else
885 +           {
886 +             menu->tearoff_adjustment->upper = widget->requisition.height;
887 +             menu->tearoff_adjustment->page_size = allocation->height;
888 +             
889 +             if (menu->tearoff_adjustment->value + menu->tearoff_adjustment->page_size >
890 +                 menu->tearoff_adjustment->upper)
891 +               {
892 +                 gint value;
893 +                 value = menu->tearoff_adjustment->upper - menu->tearoff_adjustment->page_size;
894 +                 if (value < 0)
895 +                   value = 0;
896 +                 gtk_menu_scroll_to (menu, value);
897 +               }
898 +             
899 +             gtk_adjustment_changed (menu->tearoff_adjustment);
900 +             
901 +             if (!GTK_WIDGET_VISIBLE (menu->tearoff_scrollbar))
902 +               {
903 +                 gtk_widget_show (menu->tearoff_scrollbar);
904 +                 gtk_menu_set_tearoff_hints (menu, allocation->width);
905 +               }
906 +           }
907 +       }
908 +    }
909 +/* inserted for panel-menu.c */
910 +
911 +  {
912 +    PanelMenu *pm = PANEL_MENU (widget);
913 +               
914 +    gint scaled_height = height;
915 +               
916 +    if (pm->side_image && widget->allocation.height > gdk_pixbuf_get_height (pm->side_image)) 
917 +      {
918 +       scaled_height -= gdk_pixbuf_get_height (pm->side_image);
919 +      }
920 +    
921 +    if (pm->side_image && widget->allocation.height < gdk_pixbuf_get_height (pm->side_image)) 
922 +      {
923 +       gint scaled_width = ((scaled_height * gdk_pixbuf_get_width (pm->side_image)) / gdk_pixbuf_get_height (pm->side_image));
924 +
925 +       if (pm->scaled_image)
926 +               gdk_pixbuf_unref(pm->scaled_image);
927 +
928 +       pm->scaled_image = gdk_pixbuf_scale_simple (pm->side_image,
929 +                                                   scaled_width,
930 +                                                   scaled_height,
931 +                                                   GDK_INTERP_BILINEAR); /* maybe HYPER ? */
932 +       gdk_pixbuf_unref(pm->side_image);
933 +       pm->side_image = pm->scaled_image;
934 +      } 
935 +    else 
936 +      {
937 +       gboolean draw_gradient;
938 +       gtk_widget_style_get (GTK_WIDGET (pm),
939 +                             "gradient_bg", &draw_gradient, 
940 +                             NULL);
941 +       
942 +       if (pm->side_image && draw_gradient) 
943 +         {
944 +           GdkColor *stripe_color;
945 +           GdkColor *light_color;
946 +           
947 +           stripe_color = get_stripe_color (pm);
948 +           light_color = get_light_stripe_color (pm);
949 +           pm->scaled_image = meta_gradient_create_vertical 
950 +             (gdk_pixbuf_get_width (pm->side_image),
951 +              scaled_height,
952 +              light_color,
953 +              stripe_color);
954 +           gdk_color_free (light_color);
955 +           gdk_color_free (stripe_color);
956 +         }
957 +      }
958 +  }
959 +/* end panel-menu.c */
960 +}
961 +
962 +/* end gtkmenu cut and paste */
963 +
964 +static void
965 +unload_images (PanelMenu *pm)
966 +{
967 +       if (pm->side_image) {
968 +               g_object_unref (pm->side_image);
969 +               pm->side_image = NULL;
970 +       }
971 +
972 +       if (pm->scaled_image) {
973 +               g_object_unref (pm->scaled_image);
974 +               pm->scaled_image = NULL;
975 +       }
976 +}
977 +
978 +static GdkPixbuf *
979 +get_stripe_image (PanelMenu *pm,
980 +                 const char *name,
981 +                 const char *default_filename)
982 +{      
983 +       GdkPixbuf *image = NULL;
984 +       char *file_src;
985 +       
986 +       gtk_widget_style_get (GTK_WIDGET (pm), name, &file_src, NULL);
987 +
988 +       if (!file_src) {
989 +               file_src = gnome_program_locate_file (NULL,
990 +                                                     GNOME_FILE_DOMAIN_PIXMAP,
991 +                                                     default_filename,
992 +                                                     TRUE,
993 +                                                     NULL);
994 +       }
995 +
996 +       if (file_src) 
997 +               image = gdk_pixbuf_new_from_file (file_src, NULL);
998 +       
999 +       g_free (file_src);
1000 +       
1001 +       return image;
1002 +}
1003 +
1004 +static void
1005 +load_images (PanelMenu *pm)
1006 +{
1007 +       GdkPixbuf *image;
1008 +
1009 +       unload_images (pm);
1010 +       
1011 +       pm->side_image = get_stripe_image (pm, "default_side_image",
1012 +                                 "pld-desktop-stripe.png");
1013 +}
1014 +
1015 +static void
1016 +panel_menu_style_set (GtkWidget *widget,
1017 +                     GtkStyle *old_style)
1018 +{
1019 +       load_images (PANEL_MENU (widget));
1020 +       GNOME_CALL_PARENT (GTK_WIDGET_CLASS, style_set, (widget, old_style));
1021 +}
1022 +
1023 +static void
1024 +panel_menu_destroy (GtkObject *object)
1025 +{
1026 +       PanelMenu *pm = PANEL_MENU (object);
1027 +       
1028 +       unload_images (pm);
1029 +       
1030 +       GNOME_CALL_PARENT (GTK_OBJECT_CLASS, destroy, (object));
1031 +}
1032 +
1033 +static void
1034 +panel_menu_finalize (GObject *object)
1035 +{
1036 +       GNOME_CALL_PARENT (G_OBJECT_CLASS, finalize, (object));
1037 +}
1038 +
1039 +static void
1040 +panel_menu_class_init (PanelMenuClass *klass)
1041 +{      
1042 +       GtkWidgetClass *widget_class = (GtkWidgetClass *) klass;
1043 +       GtkObjectClass *gtk_object_class = (GtkObjectClass *)klass;
1044 +       GObjectClass *object_class = (GObjectClass *) klass;
1045 +
1046 +       gtk_widget_class_install_style_property (
1047 +               widget_class,
1048 +               g_param_spec_string ("default_side_image",
1049 +                                    _("Default Side Image"),
1050 +                                    _("Filename of logo down the side of applications menu"),
1051 +                                    NULL,
1052 +                                    G_PARAM_READWRITE));
1053 +
1054 +       gtk_widget_class_install_style_property (
1055 +               widget_class,
1056 +               g_param_spec_boolean ("gradient_bg",
1057 +                                    _("Gradient Background"),
1058 +                                    _("Draw a gradient in the menu stripe"),
1059 +                                    FALSE,
1060 +                                    G_PARAM_READWRITE));
1061 +       gtk_widget_class_install_style_property (
1062 +              widget_class,
1063 +              g_param_spec_boxed ("stripe_color",
1064 +                                  _("Stripe Color"),
1065 +                                  _("Color of the panel menu stripe"),
1066 +                                  GDK_TYPE_COLOR,
1067 +                                  G_PARAM_READABLE));
1068 +
1069 +       gtk_widget_class_install_style_property (
1070 +              widget_class,
1071 +              g_param_spec_boxed ("stripe_color_light",
1072 +                                  _("Light Stripe Color"),
1073 +                                  _("Light color of the panel menu stripe, for gradients"),
1074 +                                  GDK_TYPE_COLOR,
1075 +                                  G_PARAM_READABLE));       
1076 +
1077 +       object_class->finalize = panel_menu_finalize;
1078 +       gtk_object_class->destroy = panel_menu_destroy;
1079 +       widget_class->size_request = panel_menu_size_request;
1080 +       widget_class->size_allocate = gtk_menu_size_allocate;
1081 +       widget_class->expose_event = panel_menu_expose_event;
1082 +       widget_class->style_set = panel_menu_style_set;
1083 +}
1084 +
1085 +static void
1086 +panel_menu_instance_init (PanelMenu *pm)
1087 +{
1088 +       gtk_widget_ensure_style (GTK_WIDGET (pm));
1089 +
1090 +       load_images (pm);
1091 +       
1092 +       gtk_widget_add_events (
1093 +               GTK_WIDGET (pm),
1094 +               GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK |
1095 +               GDK_POINTER_MOTION_MASK);
1096 +}
1097 diff -urN aa/gnome-panel-2.5.92/gnome-panel/panel-menu.h gnome-panel-2.5.92/gnome-panel/panel-menu.h
1098 --- aa/gnome-panel-2.5.92/gnome-panel/panel-menu.h      1970-01-01 01:00:00.000000000 +0100
1099 +++ gnome-panel-2.5.92/gnome-panel/panel-menu.h 2004-03-12 14:41:46.122563464 +0100
1100 @@ -0,0 +1,31 @@
1101 +#include <gtk/gtkmenu.h>
1102 +#include <gtk/gtkimage.h>
1103 +
1104 +typedef struct _PanelMenu PanelMenu;
1105 +typedef struct _PanelMenuClass PanelMenuClass;
1106 +
1107 +#define PANEL_MENU(obj) \
1108 +        GTK_CHECK_CAST (obj, panel_menu_get_type (), PanelMenu)
1109 +#define PANEL_MENU_CLASS(k) \
1110 +       GTK_CHECK_CLASS_CAST (k, panel_menu_get_type (), PanelMenuClass)
1111 +#define PANEL_IS_MENU(obj) \
1112 +       GTK_CHECK_TYPE (obj, panel_menu_get_type ())
1113 +
1114 +
1115 +struct _PanelMenu
1116 +{
1117 +       GtkMenu parent;
1118 +
1119 +       GdkPixbuf *side_image;
1120 +       GdkPixbuf *scaled_image;
1121 +
1122 +       GdkRegion *navigation_region;
1123 +};
1124 +
1125 +struct _PanelMenuClass
1126 +{
1127 +       GtkMenuClass parent_class;
1128 +};
1129 +
1130 +GType      panel_menu_get_type (void);
1131 +GtkWidget *panel_menu_evolve   (void);
This page took 0.16971 seconds and 4 git commands to generate.