]> git.pld-linux.org Git - packages/gnome-panel.git/blob - gnome-panel-menu-stripe.patch
- BR: libpng-devel
[packages/gnome-panel.git] / gnome-panel-menu-stripe.patch
1 diff -Nuard gnome-panel-2.4.1.orig/gnome-panel/Makefile.am gnome-panel-2.4.1/gnome-panel/Makefile.am
2 --- gnome-panel-2.4.1.orig/gnome-panel/Makefile.am      2003-09-05 14:35:53.000000000 +0200
3 +++ gnome-panel-2.4.1/gnome-panel/Makefile.am   2003-12-02 22:42:53.000000000 +0100
4 @@ -98,6 +98,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 -Nuard gnome-panel-2.4.1.orig/gnome-panel/menu.c gnome-panel-2.4.1/gnome-panel/menu.c
14 --- gnome-panel-2.4.1.orig/gnome-panel/menu.c   2003-10-14 12:46:30.000000000 +0200
15 +++ gnome-panel-2.4.1/gnome-panel/menu.c        2003-12-02 22:42:53.000000000 +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-run-dialog.h"
26  
27  #undef MENU_DEBUG
28 +#define MENU_SNAP_LENGTH 10
29  
30  static char *gnome_folder = NULL;
31  
32 @@ -610,6 +612,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 @@ -705,8 +710,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 @@ -718,8 +723,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 @@ -735,12 +739,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 @@ -748,6 +758,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 @@ -3316,7 +3333,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 -Nuard gnome-panel-2.4.1.orig/gnome-panel/panel-config-global.c gnome-panel-2.4.1/gnome-panel/panel-config-global.c
108 --- gnome-panel-2.4.1.orig/gnome-panel/panel-config-global.c    2003-03-05 02:11:34.000000000 +0100
109 +++ gnome-panel-2.4.1/gnome-panel/panel-config-global.c 2003-12-02 22:42:53.000000000 +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 @@ -152,6 +160,9 @@
133                 global_config.highlight_when_over =
134                         gconf_value_get_bool (value);
135  
136 +       else if (strcmp (key, "show_menu_stripe") == 0)
137 +               global_config.menu_stripe =
138 +                               gconf_value_get_bool (value);
139  #if 0
140         else
141                 g_warning ("%s not handled", key);
142 diff -Nuard gnome-panel-2.4.1.orig/gnome-panel/panel-config-global.h gnome-panel-2.4.1/gnome-panel/panel-config-global.h
143 --- gnome-panel-2.4.1.orig/gnome-panel/panel-config-global.h    2003-03-05 02:11:34.000000000 +0100
144 +++ gnome-panel-2.4.1/gnome-panel/panel-config-global.h 2003-12-02 22:42:53.000000000 +0100
145 @@ -37,6 +37,7 @@
146  gboolean panel_global_config_get_drawer_auto_close    (void);
147  gboolean panel_global_config_get_tooltips_enabled     (void);
148  gboolean panel_global_config_get_confirm_panel_remove (void);
149 +gboolean panel_global_config_get_menu_stripe         (void);
150  
151  G_END_DECLS
152  
153 diff -Nuard gnome-panel-2.4.1.orig/gnome-panel/panel-global.schemas.in gnome-panel-2.4.1/gnome-panel/panel-global.schemas.in
154 --- gnome-panel-2.4.1.orig/gnome-panel/panel-global.schemas.in  2003-07-07 15:27:58.000000000 +0200
155 +++ gnome-panel-2.4.1/gnome-panel/panel-global.schemas.in       2003-12-02 22:42:53.000000000 +0100
156 @@ -93,6 +93,18 @@
157        </schema>
158  
159        <schema>
160 +        <key>/schemas/apps/panel/global/show_menu_stripe</key>
161 +        <applyto>/apps/panel/global/show_menu_stripe</applyto>
162 +        <owner>panel</owner>
163 +        <type>bool</type>
164 +        <default>true</default>
165 +        <locale name="C">
166 +          <short></short>
167 +          <long></long>
168 +        </locale>
169 +      </schema>
170 +
171 +      <schema>
172          <key>/schemas/apps/panel/global/enable_key_bindings</key>
173          <applyto>/apps/panel/global/enable_key_bindings</applyto>
174          <owner>panel</owner>
175 diff -Nuard gnome-panel-2.4.1.orig/gnome-panel/panel-menu.c gnome-panel-2.4.1/gnome-panel/panel-menu.c
176 --- gnome-panel-2.4.1.orig/gnome-panel/panel-menu.c     1970-01-01 01:00:00.000000000 +0100
177 +++ gnome-panel-2.4.1/gnome-panel/panel-menu.c  2003-12-03 01:30:49.228495360 +0100
178 @@ -0,0 +1,773 @@
179 +/*
180 + * To set this up insert something like this in your ~/.gtkrc-2.0
181 + *
182 + * Copyright (C) 2003 Marcin Krzy¿anowski
183 + * Copyright (C) 2002 Ximian, Inc. 
184 + * Copyright (C) 2001 Havoc Pennington
185 + * Copyright (C) 1997-2000 Dan Pascu and Alfredo Kojima
186 + * 
187 + * style "default"
188 + * {
189 + *   PanelMenu::default_side_image = "/tmp/stripelogo.png"
190 + *   PanelMenu::gradient_bg = true
191 + * }
192 + * class "PanelMenu" style "default"
193 + *
194 + * Authors:
195 + *       Thomas, Michael Meeks
196 + *       GtkMenu code by the GTK+ team
197 + *       Gradient code from WindowMaker by Dan Pascu and Alfredo Kojima, by way of metacity by Havoc Pennington.
198 + *      Marcin Krzy¿anowski
199 + */
200 +#include <config.h>
201 +#include <string.h>
202 +#include <libgnome/gnome-macros.h>
203 +#include <libgnome/gnome-program.h>
204 +#include <libgnome/gnome-i18n.h>
205 +#include <gtk/gtkgc.h>
206 +#include <gtk/gtkimagemenuitem.h>
207 +#include <gtk/gtkseparatormenuitem.h>
208 +#include <gtk/gtkmenu.h>
209 +#include <gtk/gtkwidget.h>
210 +#include <gtk/gtkwindow.h>
211 +#include <gtk/gtkmain.h>
212 +#include <gdk/gdkwindow.h>
213 +#include <panel-menu.h>
214 +
215 +#include "panel-config-global.h"
216 +
217 +#define dprintf(a) g_warning a
218 +/*#define dprintf(a) G_STMT_START { (void) 0; } G_STMT_END*/
219 +
220 +GNOME_CLASS_BOILERPLATE (PanelMenu, panel_menu,
221 +                        GtkMenu, GTK_TYPE_MENU)
222 +
223 +
224 +
225 +static void
226 +panel_menu_size_request  (GtkWidget *widget,
227 +                         GtkRequisition *requisition)
228 +{
229 +       PanelMenu *pm = PANEL_MENU (widget);
230 +
231 +       GTK_WIDGET_CLASS (parent_class)->size_request (widget, requisition);
232 +
233 +       if (panel_global_config_get_menu_stripe () && pm->side_image != NULL)
234 +               requisition->width += gdk_pixbuf_get_width (pm->side_image)
235 +                      + gtk_widget_get_style (widget)->xthickness;
236 +}
237 +
238 +static GdkColor *
239 +get_light_stripe_color (PanelMenu *pm)
240 +{
241 +       GdkColor *color;
242 +       
243 +       gtk_widget_style_get (GTK_WIDGET (pm),
244 +                             "stripe-color-light", &color,
245 +                             NULL);
246 +
247 +       if (!color) {
248 +               color = gdk_color_copy (&GTK_WIDGET (pm)->style->bg[GTK_STATE_NORMAL]);
249 +       }
250 +       
251 +       return color;
252 +}
253 +
254 +static GdkColor *
255 +get_stripe_color (PanelMenu *pm)
256 +{
257 +       GdkColor *color;
258 +       
259 +       gtk_widget_style_get (GTK_WIDGET (pm),
260 +                             "stripe-color", &color,
261 +                             NULL);
262 +
263 +       if (!color) {
264 +               color = gdk_color_copy (&GTK_WIDGET (pm)->style->bg[GTK_STATE_SELECTED]);
265 +       }
266 +       
267 +       return color;
268 +}
269 +
270 +static GdkGC *
271 +get_stripe_gc (PanelMenu *pm) 
272 +{
273 +       GdkGCValues gc_values;
274 +       GdkGCValuesMask gc_values_mask;
275 +       GdkColor *color;
276 +       
277 +       color = get_stripe_color (pm);
278 +       gc_values.foreground = *color;
279 +       gdk_color_free (color);
280 +       gc_values_mask = GDK_GC_FOREGROUND;
281 +       
282 +       gdk_rgb_find_color (GTK_WIDGET (pm)->style->colormap, &gc_values.foreground);
283 +
284 +       return gtk_gc_get (GTK_WIDGET (pm)->style->depth,
285 +                          GTK_WIDGET (pm)->style->colormap,
286 +                          &gc_values, gc_values_mask);
287 +}
288 +
289 +static gboolean
290 +panel_menu_expose_event (GtkWidget      *widget,
291 +                        GdkEventExpose *event)
292 +{
293 +       GdkRectangle exposed;
294 +       GdkRectangle position;
295 +       GdkWindow   *window;
296 +       int bin_height;
297 +       GdkGC *stripe_gc;
298 +       PanelMenu *pm = PANEL_MENU (widget);
299 +
300 +       GTK_WIDGET_CLASS (parent_class)->expose_event (widget, event);
301 +
302 +       if (!panel_global_config_get_menu_stripe () || !pm->side_image) {
303 +              return TRUE;
304 +       }
305 +       window = GTK_MENU (widget)->bin_window;
306 +
307 +       stripe_gc = get_stripe_gc (pm);
308 +
309 +       gdk_gc_set_clip_rectangle (stripe_gc, &event->area);       
310 +       gdk_draw_rectangle (window,
311 +                          stripe_gc,
312 +                          TRUE,
313 +                          widget->allocation.x,
314 +                          widget->allocation.y,
315 +                          gdk_pixbuf_get_width (pm->side_image),
316 +                          widget->allocation.height);
317 +       gdk_gc_set_clip_rectangle (stripe_gc, NULL);
318 +
319 +       bin_height = widget->allocation.height - 2 * (GTK_CONTAINER (widget)->border_width + widget->style->ythickness);
320 +
321 +       position = widget->allocation;
322 +       position.y += bin_height - gdk_pixbuf_get_height (pm->side_image);
323 +       position.width = gdk_pixbuf_get_width (pm->side_image);
324 +       position.height = gdk_pixbuf_get_height (pm->side_image);
325 +
326 +       if (widget->allocation.height >= gdk_pixbuf_get_height (pm->side_image)) {
327 +              if (gdk_rectangle_intersect (&event->area,
328 +                                           &position,
329 +                                           &exposed)) {
330 +                      gdk_pixbuf_render_to_drawable (
331 +                              pm->side_image, window,
332 +                              widget->style->black_gc,
333 +                              exposed.x - position.x,
334 +                              exposed.y - position.y,
335 +                              exposed.x, exposed.y,
336 +                              exposed.width, exposed.height,
337 +                              GDK_RGB_DITHER_NORMAL,
338 +                              exposed.x, exposed.y);
339 +              }
340 +       }
341 +               
342 +       position = widget->allocation;
343 +       if (position.height != gdk_pixbuf_get_height (pm->side_image)) {
344 +               position.width = gdk_pixbuf_get_width (pm->side_image);
345 +              if (position.height > gdk_pixbuf_get_height (pm->side_image)) {
346 +                      position.height = bin_height - gdk_pixbuf_get_height (pm->side_image);
347 +              } else {
348 +                      position.height = bin_height;
349 +              }
350 +              
351 +               if (pm->scaled_image && gdk_rectangle_intersect (&event->area,
352 +                                                               &position,
353 +                                                               &exposed)) {
354 +      
355 +                       gdk_pixbuf_render_to_drawable (
356 +                               pm->scaled_image, window,
357 +                               widget->style->black_gc,
358 +                               exposed.x - position.x,
359 +                               exposed.y - position.y,
360 +                               exposed.x, exposed.y,
361 +                               exposed.width, exposed.height,
362 +                               GDK_RGB_DITHER_NORMAL,
363 +                               exposed.x, exposed.y);
364 +               }
365 +       }
366 +
367 +       return TRUE;
368 +}
369 +
370 +/* begin metacity cut and paste */
371 +static void
372 +free_buffer (guchar *pixels, gpointer data)
373 +{
374 +  g_free (pixels);
375 +}
376 +
377 +static GdkPixbuf*
378 +blank_pixbuf (int width, int height, gboolean no_padding)
379 +{
380 +  guchar *buf;
381 +  int rowstride;
382 +
383 +  g_return_val_if_fail (width > 0, NULL);
384 +  g_return_val_if_fail (height > 0, NULL);
385 +
386 +  if (no_padding)
387 +    rowstride = width * 3;
388 +  else
389 +    /* Always align rows to 32-bit boundaries */  
390 +    rowstride = 4 * ((3 * width + 3) / 4);
391 +
392 +  buf = g_try_malloc (height * rowstride);
393 +  if (!buf)
394 +    return NULL;
395 +
396 +  return gdk_pixbuf_new_from_data (buf, GDK_COLORSPACE_RGB,
397 +                                   FALSE, 8,
398 +                                   width, height, rowstride,
399 +                                   free_buffer, NULL);
400 +}
401 +
402 +static GdkPixbuf*
403 +meta_gradient_create_vertical (int width, int height,
404 +                               const GdkColor *from,
405 +                               const GdkColor *to)
406 +{
407 +  int i, j;
408 +  long r, g, b, dr, dg, db;
409 +  GdkPixbuf *pixbuf;
410 +  unsigned char *ptr;
411 +  unsigned char rr, gg, bb;
412 +  int r0, g0, b0;
413 +  int rf, gf, bf;
414 +  int rowstride;
415 +  unsigned char *pixels;
416 +  
417 +  pixbuf = blank_pixbuf (width, height, FALSE);
418 +  if (pixbuf == NULL)
419 +    return NULL;
420 +    
421 +  pixels = gdk_pixbuf_get_pixels (pixbuf);
422 +  rowstride = gdk_pixbuf_get_rowstride (pixbuf);
423 +  
424 +  r0 = (guchar) (from->red / 256.0);
425 +  g0 = (guchar) (from->green / 256.0);
426 +  b0 = (guchar) (from->blue / 256.0);
427 +  rf = (guchar) (to->red / 256.0);
428 +  gf = (guchar) (to->green / 256.0);
429 +  bf = (guchar) (to->blue / 256.0);
430 +  
431 +  r = r0<<16;
432 +  g = g0<<16;
433 +  b = b0<<16;
434 +
435 +  dr = ((rf-r0)<<16)/(int)height;
436 +  dg = ((gf-g0)<<16)/(int)height;
437 +  db = ((bf-b0)<<16)/(int)height;
438 +
439 +  for (i=0; i<height; i++)
440 +    {
441 +      ptr = pixels + i * rowstride;
442 +      
443 +      rr = r>>16;
444 +      gg = g>>16;
445 +      bb = b>>16;
446 +      for (j=0; j<width/8; j++)
447 +        {
448 +          *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
449 +          *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
450 +          *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
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 +       }
457 +      switch (width%8)
458 +        {
459 +        case 7: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
460 +        case 6: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
461 +        case 5: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
462 +        case 4: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
463 +        case 3: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
464 +        case 2: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
465 +        case 1: *(ptr++) = rr; *(ptr++) = gg; *(ptr++) = bb;
466 +       }
467 +      r+=dr;
468 +      g+=dg;
469 +      b+=db;
470 +    }
471 +  return pixbuf;
472 +}
473 +
474 +/* end metacity cut and paste */
475 +
476 +/* begin gtkmenu.c cut and paste */
477 +
478 +#define MENU_SCROLL_ARROW_HEIGHT 16
479 +
480 +static void
481 +gtk_menu_stop_scrolling (GtkMenu *menu)
482 +{
483 +  if (menu->timeout_id)
484 +    {
485 +      g_source_remove (menu->timeout_id);
486 +      menu->timeout_id = 0;
487 +    }
488 +}
489 +
490 +static void
491 +gtk_menu_scroll_to (GtkMenu *menu,
492 +                   gint    offset)
493 +{
494 +  GtkWidget *widget;
495 +  gint x, y;
496 +  gint view_width, view_height;
497 +  gint border_width;
498 +  gboolean last_visible;
499 +  gint menu_height;
500 +
501 +  widget = GTK_WIDGET (menu);
502 +
503 +  if (menu->tearoff_active &&
504 +      menu->tearoff_adjustment &&
505 +      (menu->tearoff_adjustment->value != offset))
506 +    {
507 +      menu->tearoff_adjustment->value = offset;
508 +      gtk_adjustment_value_changed (menu->tearoff_adjustment);
509 +    }
510 +  
511 +  /* Move/resize the viewport according to arrows: */
512 +  view_width = widget->allocation.width;
513 +  view_height = widget->allocation.height;
514 +
515 +  border_width = GTK_CONTAINER (menu)->border_width;
516 +  view_width -= (border_width + widget->style->xthickness) * 2;
517 +  view_height -= (border_width + widget->style->ythickness) * 2;
518 +  menu_height = widget->requisition.height - (border_width + widget->style->ythickness) * 2;
519 +
520 +  offset = CLAMP (offset, 0, menu_height - view_height);
521 +
522 +  /* Scroll the menu: */
523 +  if (GTK_WIDGET_REALIZED (menu))
524 +    gdk_window_move (menu->bin_window, 0, -offset);
525 +
526 +  x = border_width + widget->style->xthickness;
527 +  y = border_width + widget->style->ythickness;
528 +  
529 +  if (!menu->tearoff_active)
530 +    {
531 +      last_visible = menu->upper_arrow_visible;
532 +      menu->upper_arrow_visible = (offset > 0);
533 +      
534 +      if (menu->upper_arrow_visible)
535 +       view_height -= MENU_SCROLL_ARROW_HEIGHT;
536 +      
537 +      if ( (last_visible != menu->upper_arrow_visible) &&
538 +          !menu->upper_arrow_visible)
539 +       {
540 +         menu->upper_arrow_prelight = FALSE;
541 +         
542 +         /* If we hid the upper arrow, possibly remove timeout */
543 +         if (menu->scroll_step < 0)
544 +           gtk_menu_stop_scrolling (menu);
545 +       }
546 +      
547 +      last_visible = menu->lower_arrow_visible;
548 +      menu->lower_arrow_visible = (view_height + offset < menu_height);
549 +      
550 +      if (menu->lower_arrow_visible)
551 +       view_height -= MENU_SCROLL_ARROW_HEIGHT;
552 +      
553 +      if ( (last_visible != menu->lower_arrow_visible) &&
554 +          !menu->lower_arrow_visible)
555 +       {
556 +         menu->lower_arrow_prelight = FALSE;
557 +         
558 +         /* If we hid the lower arrow, possibly remove timeout */
559 +         if (menu->scroll_step > 0)
560 +           gtk_menu_stop_scrolling (menu);
561 +       }
562 +      
563 +      if (menu->upper_arrow_visible)
564 +       y += MENU_SCROLL_ARROW_HEIGHT;
565 +    }
566 +
567 +  if (GTK_WIDGET_REALIZED (menu))
568 +    gdk_window_move_resize (menu->view_window,
569 +                           x,
570 +                           y,
571 +                           view_width,
572 +                           view_height);
573 +
574 +  menu->scroll_offset = offset;
575 +}
576 +
577 +static void
578 +gtk_menu_set_tearoff_hints (GtkMenu *menu,
579 +                            gint     width)
580 +{
581 +  GdkGeometry geometry_hints;
582 +
583 +  if (!menu->tearoff_window)
584 +    return;
585 +
586 +  if (GTK_WIDGET_VISIBLE (menu->tearoff_scrollbar))
587 +    {
588 +      gtk_widget_size_request (menu->tearoff_scrollbar, NULL);
589 +      width += menu->tearoff_scrollbar->requisition.width;
590 +    }
591 +
592 +  geometry_hints.min_width = width;
593 +  geometry_hints.max_width = width;
594 +
595 +  geometry_hints.min_height = 0;
596 +  geometry_hints.max_height = GTK_WIDGET (menu)->requisition.height;
597 +
598 +  gtk_window_set_geometry_hints (GTK_WINDOW (menu->tearoff_window),
599 +                                 NULL,
600 +                                 &geometry_hints,
601 +                                 GDK_HINT_MAX_SIZE|GDK_HINT_MIN_SIZE);
602 +}
603 +
604 +static void
605 +gtk_menu_size_allocate (GtkWidget     *widget,
606 +                       GtkAllocation *allocation)
607 +{
608 +  GtkMenu *menu;
609 +  GtkMenuShell *menu_shell;
610 +  GtkWidget *child;
611 +  GtkAllocation child_allocation;
612 +  GList *children;
613 +  gint x, y;
614 +  gint width, height;
615 +
616 +  g_return_if_fail (GTK_IS_MENU (widget));
617 +  g_return_if_fail (allocation != NULL);
618 +  
619 +  menu = GTK_MENU (widget);
620 +  menu_shell = GTK_MENU_SHELL (widget);
621 +
622 +  widget->allocation = *allocation;
623 +
624 +  x = GTK_CONTAINER (menu)->border_width + widget->style->xthickness;
625 +  y = GTK_CONTAINER (menu)->border_width + widget->style->ythickness;
626 +  
627 +  width = MAX (1, allocation->width - x * 2);
628 +  height = MAX (1, allocation->height - y * 2);
629 +  
630 +  if (menu->upper_arrow_visible && !menu->tearoff_active)
631 +    {
632 +      y += MENU_SCROLL_ARROW_HEIGHT;
633 +      height -= MENU_SCROLL_ARROW_HEIGHT;
634 +    }
635 +  
636 +  if (menu->lower_arrow_visible && !menu->tearoff_active)
637 +    height -= MENU_SCROLL_ARROW_HEIGHT;
638 +  
639 +  if (GTK_WIDGET_REALIZED (widget))
640 +    {
641 +      gdk_window_move_resize (widget->window,
642 +                             allocation->x, allocation->y,
643 +                             allocation->width, allocation->height);
644 +
645 +      gdk_window_move_resize (menu->view_window,
646 +                             x,
647 +                             y,
648 +                             width,
649 +                             height);
650 +    }
651 +
652 +  if (menu_shell->children)
653 +    {
654 +      child_allocation.x = 0;
655 +      child_allocation.y = 0;
656 +      child_allocation.width = width;
657 +
658 +/* inserted for panel-menu.c */
659 +      if (panel_global_config_get_menu_stripe () && PANEL_MENU (widget)->side_image) 
660 +       {
661 +         child_allocation.x = gdk_pixbuf_get_width (PANEL_MENU (widget)->side_image) + gtk_widget_get_style (widget)->xthickness;
662 +       }
663 +
664 +      child_allocation.width = width - child_allocation.x;
665 +/* end panel-menu.c */
666 +      
667 +      children = menu_shell->children;
668 +      while (children)
669 +       {
670 +         child = children->data;
671 +         children = children->next;
672 +         
673 +         if (GTK_WIDGET_VISIBLE (child))
674 +           {
675 +             GtkRequisition child_requisition;
676 +             gtk_widget_get_child_requisition (child, &child_requisition);
677 +             
678 +             child_allocation.height = child_requisition.height;
679 +
680 +             gtk_menu_item_toggle_size_allocate (GTK_MENU_ITEM (child),
681 +                                                 menu->toggle_size);
682 +
683 +/* inserted for panel-menu.c */
684 +             if (PANEL_MENU (widget)->side_image && g_type_is_a (G_OBJECT_TYPE (child), GTK_TYPE_SEPARATOR_MENU_ITEM)) 
685 +               {
686 +                 /* this is dumb, gtkmenuitem.c uses allocation.width as an absolute point */
687 +                 child_allocation.width += gdk_pixbuf_get_width (PANEL_MENU (widget)->side_image);
688 +               }
689 +
690 +             gtk_widget_size_allocate (child, &child_allocation);
691 +
692 +             if (PANEL_MENU(widget)->side_image && g_type_is_a (G_OBJECT_TYPE (child), GTK_TYPE_SEPARATOR_MENU_ITEM)) 
693 +               {
694 +                 child_allocation.width -= gdk_pixbuf_get_width (PANEL_MENU (widget)->side_image);
695 +               }
696 +
697 +             /* Hack to handle events on the stripe area */
698 +             if (GTK_WIDGET_REALIZED (child)) 
699 +               { 
700 +                 gdk_window_move_resize (GTK_MENU_ITEM (child)->event_window,
701 +                                         0, child_allocation.y,
702 +                                         allocation->width, 
703 +                                         child_allocation.height);
704 +               }
705 +/* end panel-menu.c */
706 +
707 +             gtk_widget_queue_draw (child);
708 +             
709 +             child_allocation.y += child_allocation.height;
710 +           }
711 +       }
712 +      
713 +      /* Resize the item window */
714 +      if (GTK_WIDGET_REALIZED (widget))
715 +       {
716 +/* inserted for panel-menu.c */
717 +         gdk_window_resize (menu->bin_window,
718 +#if 0
719 +                            child_allocation.width,
720 +#else
721 +                            allocation->width,
722 +#endif
723 +                            child_allocation.y);
724 +/* end panel-menu.c */
725 +       }
726 +
727 +
728 +      if (menu->tearoff_active)
729 +       {
730 +         if (allocation->height >= widget->requisition.height)
731 +           {
732 +             if (GTK_WIDGET_VISIBLE (menu->tearoff_scrollbar))
733 +               {
734 +                 gtk_widget_hide (menu->tearoff_scrollbar);
735 +                 gtk_menu_set_tearoff_hints (menu, allocation->width);
736 +                 gtk_widget_set_size_request (menu->tearoff_window, -1, allocation->height);
737 +
738 +                 gtk_menu_scroll_to (menu, 0);
739 +               }
740 +           }
741 +         else
742 +           {
743 +             menu->tearoff_adjustment->upper = widget->requisition.height;
744 +             menu->tearoff_adjustment->page_size = allocation->height;
745 +             
746 +             if (menu->tearoff_adjustment->value + menu->tearoff_adjustment->page_size >
747 +                 menu->tearoff_adjustment->upper)
748 +               {
749 +                 gint value;
750 +                 value = menu->tearoff_adjustment->upper - menu->tearoff_adjustment->page_size;
751 +                 if (value < 0)
752 +                   value = 0;
753 +                 gtk_menu_scroll_to (menu, value);
754 +               }
755 +             
756 +             gtk_adjustment_changed (menu->tearoff_adjustment);
757 +             
758 +             if (!GTK_WIDGET_VISIBLE (menu->tearoff_scrollbar))
759 +               {
760 +                 gtk_widget_show (menu->tearoff_scrollbar);
761 +                 gtk_menu_set_tearoff_hints (menu, allocation->width);
762 +                 gtk_widget_set_size_request (menu->tearoff_window, -1, allocation->height);
763 +               }
764 +           }
765 +       }
766 +    }
767 +/* inserted for panel-menu.c */
768 +
769 +  {
770 +    PanelMenu *pm = PANEL_MENU (widget);
771 +    
772 +    gint scaled_height = height;
773 +    
774 +    if (pm->side_image && widget->allocation.height > gdk_pixbuf_get_height (pm->side_image)) 
775 +      {
776 +       scaled_height -= gdk_pixbuf_get_height (pm->side_image);
777 +      } 
778 +
779 +    if (pm->side_image && widget->allocation.height < gdk_pixbuf_get_height (pm->side_image))
780 +      {
781 +       gint scaled_width = ((scaled_height * gdk_pixbuf_get_width (pm->side_image)) / gdk_pixbuf_get_height (pm->side_image));
782 +       
783 +       pm->scaled_image = gdk_pixbuf_scale_simple (pm->side_image,
784 +                                                   scaled_width,
785 +                                                   scaled_height,
786 +                                                   GDK_INTERP_BILINEAR); /* maybe HYPER ? */
787 +      } 
788 +    else
789 +      {
790 +       gboolean draw_gradient;
791 +       gtk_widget_style_get (GTK_WIDGET (pm),
792 +                             "gradient_bg", &draw_gradient, 
793 +                             NULL);
794 +       
795 +       if (pm->side_image && draw_gradient) 
796 +         {
797 +           GdkColor *stripe_color;
798 +           GdkColor *light_color;
799 +           
800 +           stripe_color = get_stripe_color (pm);
801 +           light_color = get_light_stripe_color (pm);
802 +           pm->scaled_image = meta_gradient_create_vertical 
803 +             (gdk_pixbuf_get_width (pm->side_image),
804 +              scaled_height,
805 +              light_color,
806 +              stripe_color);
807 +           gdk_color_free (light_color);
808 +           gdk_color_free (stripe_color);
809 +         }
810 +      }
811 +  }
812 +/* end panel-menu.c */
813 +}
814 +
815 +/* end gtkmenu cut and paste */
816 +
817 +static void
818 +unload_images (PanelMenu *pm)
819 +{
820 +       if (pm->side_image) {
821 +               g_object_unref (pm->side_image);
822 +               pm->side_image = NULL;
823 +       }
824 +
825 +       if (pm->scaled_image) {
826 +               g_object_unref (pm->scaled_image);
827 +               pm->scaled_image = NULL;
828 +       }
829 +
830 +}
831 +
832 +static GdkPixbuf *
833 +get_stripe_image (PanelMenu *pm,
834 +                 const char *name,
835 +                 const char *default_filename)
836 +{      
837 +       GdkPixbuf *image = NULL;
838 +       char *file_src;
839 +       
840 +       gtk_widget_style_get (GTK_WIDGET (pm), name, &file_src, NULL);
841 +
842 +       if (!file_src) {
843 +               file_src = gnome_program_locate_file (NULL,
844 +                                                     GNOME_FILE_DOMAIN_PIXMAP,
845 +                                                     default_filename,
846 +                                                     TRUE,
847 +                                                     NULL);
848 +       }
849 +
850 +       if (file_src) 
851 +               image = gdk_pixbuf_new_from_file (file_src, NULL);
852 +       
853 +       g_free (file_src);
854 +       
855 +       return image;
856 +}
857 +
858 +static void
859 +load_images (PanelMenu *pm)
860 +{
861 +       GdkPixbuf *image;
862 +
863 +       unload_images (pm);
864 +       
865 +       pm->side_image = get_stripe_image (pm, "default_side_image",
866 +                                 "pld-desktop-stripe.png");
867 +
868 +}
869 +
870 +static void
871 +panel_menu_style_set (GtkWidget *widget,
872 +                     GtkStyle *old_style)
873 +{
874 +       load_images (PANEL_MENU (widget));
875 +       GNOME_CALL_PARENT (GTK_WIDGET_CLASS, style_set, (widget, old_style));
876 +}
877 +
878 +static void
879 +panel_menu_destroy (GtkObject *object)
880 +{
881 +       PanelMenu *pm = PANEL_MENU (object);
882 +       
883 +       unload_images (pm);
884 +       
885 +       GNOME_CALL_PARENT (GTK_OBJECT_CLASS, destroy, (object));
886 +}
887 +
888 +static void
889 +panel_menu_finalize (GObject *object)
890 +{
891 +       GNOME_CALL_PARENT (G_OBJECT_CLASS, finalize, (object));
892 +}
893 +
894 +static void
895 +panel_menu_class_init (PanelMenuClass *klass)
896 +{      
897 +       GtkWidgetClass *widget_class = (GtkWidgetClass *) klass;
898 +       GtkObjectClass *gtk_object_class = (GtkObjectClass *)klass;
899 +       GObjectClass *object_class = (GObjectClass *) klass;
900 +
901 +       gtk_widget_class_install_style_property (
902 +               widget_class,
903 +               g_param_spec_string ("default_side_image",
904 +                                    _("Default Side Image"),
905 +                                    _("Filename of logo down the side of applications menu"),
906 +                                    NULL,
907 +                                    G_PARAM_READWRITE));
908 +
909 +       gtk_widget_class_install_style_property (
910 +               widget_class,
911 +               g_param_spec_boolean ("gradient_bg",
912 +                                    _("Gradient Background"),
913 +                                    _("Draw a gradient in the menu stripe"),
914 +                                    FALSE,
915 +                                    G_PARAM_READWRITE));
916 +       gtk_widget_class_install_style_property (
917 +              widget_class,
918 +              g_param_spec_boxed ("stripe_color",
919 +                                  _("Stripe Color"),
920 +                                  _("Color of the panel menu stripe"),
921 +                                  GDK_TYPE_COLOR,
922 +                                  G_PARAM_READABLE));
923 +
924 +       gtk_widget_class_install_style_property (
925 +              widget_class,
926 +              g_param_spec_boxed ("stripe_color_light",
927 +                                  _("Light Stripe Color"),
928 +                                  _("Light color of the panel menu stripe, for gradients"),
929 +                                  GDK_TYPE_COLOR,
930 +                                  G_PARAM_READABLE));       
931 +
932 +       object_class->finalize = panel_menu_finalize;
933 +       gtk_object_class->destroy = panel_menu_destroy;
934 +       widget_class->size_request = panel_menu_size_request;
935 +       widget_class->size_allocate = gtk_menu_size_allocate;
936 +       widget_class->expose_event = panel_menu_expose_event;
937 +       widget_class->style_set = panel_menu_style_set;
938 +}
939 +
940 +static void
941 +panel_menu_instance_init (PanelMenu *pm)
942 +{
943 +       gtk_widget_ensure_style (GTK_WIDGET (pm));
944 +
945 +       load_images (pm);
946 +       
947 +       gtk_widget_add_events (
948 +               GTK_WIDGET (pm),
949 +               GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK |
950 +               GDK_POINTER_MOTION_MASK);
951 +}
952 diff -Nuard gnome-panel-2.4.1.orig/gnome-panel/panel-menu.h gnome-panel-2.4.1/gnome-panel/panel-menu.h
953 --- gnome-panel-2.4.1.orig/gnome-panel/panel-menu.h     1970-01-01 01:00:00.000000000 +0100
954 +++ gnome-panel-2.4.1/gnome-panel/panel-menu.h  2003-12-03 01:22:39.710913344 +0100
955 @@ -0,0 +1,31 @@
956 +#include <gtk/gtkmenu.h>
957 +#include <gtk/gtkimage.h>
958 +
959 +typedef struct _PanelMenu PanelMenu;
960 +typedef struct _PanelMenuClass PanelMenuClass;
961 +
962 +#define PANEL_MENU(obj) \
963 +        GTK_CHECK_CAST (obj, panel_menu_get_type (), PanelMenu)
964 +#define PANEL_MENU_CLASS(k) \
965 +       GTK_CHECK_CLASS_CAST (k, panel_menu_get_type (), PanelMenuClass)
966 +#define PANEL_IS_MENU(obj) \
967 +       GTK_CHECK_TYPE (obj, panel_menu_get_type ())
968 +
969 +
970 +struct _PanelMenu
971 +{
972 +       GtkMenu parent;
973 +
974 +       GdkPixbuf *side_image;
975 +       GdkPixbuf *scaled_image; 
976 +
977 +       GdkRegion *navigation_region;
978 +};
979 +
980 +struct _PanelMenuClass
981 +{
982 +       GtkMenuClass parent_class;
983 +};
984 +
985 +GType      panel_menu_get_type (void);
986 +GtkWidget *panel_menu_evolve   (void);
This page took 0.098872 seconds and 3 git commands to generate.