diff lwlib/xlwmenu.c @ 80:1ce6082ce73f r20-0b90

Import from CVS: tag r20-0b90
author cvs
date Mon, 13 Aug 2007 09:06:37 +0200
parents c7528f8e288d
children ac0620f6398e
line wrap: on
line diff
--- a/lwlib/xlwmenu.c	Mon Aug 13 09:05:44 2007 +0200
+++ b/lwlib/xlwmenu.c	Mon Aug 13 09:06:37 2007 +0200
@@ -105,7 +105,7 @@
   {XtNmenu, XtCMenu, XtRPointer, sizeof(XtPointer),
      offset(menu.contents), XtRImmediate, (XtPointer)NULL},
   {XtNcursor, XtCCursor, XtRCursor, sizeof(Cursor),
-     offset(menu.cursor_shape), XtRString, (XtPointer)"right_ptr"},
+     offset(menu.cursor_shape), XtRString, (XtPointer) "right_ptr"},
   {XtNhorizontal, XtCHorizontal, XtRInt, sizeof(int),
      offset(menu.horizontal), XtRImmediate, (XtPointer)True},
   {XtNuseBackingStore, XtCUseBackingStore, XtRBoolean, sizeof (Boolean),
@@ -128,9 +128,8 @@
 static void XlwMenuDestroy (Widget w);
 static void XlwMenuClassInitialize (void);
 static void Start (Widget w, XEvent *ev, String *params, Cardinal *num_params);
-static void Drag (Widget w, XEvent *ev, String *params, Cardinal *num_params);
-static void Select (Widget w, XEvent *ev, String *params,
- Cardinal *num_params);
+static void Drag  (Widget w, XEvent *ev, String *params, Cardinal *num_params);
+static void Select(Widget w, XEvent *ev, String *params, Cardinal *num_params);
 
 #ifdef NEED_MOTIF
 static XFontStruct *default_font_of_font_list (XmFontList);
@@ -174,8 +173,7 @@
     NULL,				/* set_values_hook	  */
     XtInheritSetValuesAlmost,		/* set_values_almost	  */
     NULL,				/* get_values_hook	  */
-    NULL,				/* #### - should this be set for */
-			    		/* grabs? accept_focus */
+    NULL, /* #### - should this be set for grabs? accept_focus	  */
     XtVersion,				/* version		  */
     NULL,				/* callback_private	  */
     xlwMenuTranslations,		/* tm_table		  */
@@ -220,7 +218,7 @@
 
     {
       /* If we got to this point, the colormap is full, so we're
-	 going to try and get the next closest color.
+	 going to try to get the next closest color.
 	 The algorithm used is a least-squares matching, which is
 	 what X uses for closest color matching with StaticColor visuals.  */
 
@@ -250,10 +248,9 @@
 	      nearest_delta = delta;
 	    }
 	}
-      color_def->red = cells[nearest].red;
+      color_def->red   = cells[nearest].red;
       color_def->green = cells[nearest].green;
-      color_def->blue = cells[nearest].blue;
-
+      color_def->blue  = cells[nearest].blue;
       free (cells);
       return XAllocColor (display, screen_colormap, color_def);
     }
@@ -273,7 +270,7 @@
     {
       mw->menu.new_stack_length *= 2;
       mw->menu.new_stack =
-	(widget_value**)XtRealloc ((char*)mw->menu.new_stack,
+	(widget_value**)XtRealloc ((char *)mw->menu.new_stack,
 				   mw->menu.new_stack_length *
 				   sizeof (widget_value*));
     }
@@ -283,13 +280,9 @@
 static void
 pop_new_stack_if_no_contents (XlwMenuWidget mw)
 {
-  if (mw->menu.new_depth)
-    {
-      if (!mw->menu.new_stack [mw->menu.new_depth - 1]->contents)
-	{
-	  mw->menu.new_depth -= 1;
-	}
-    }
+  if (mw->menu.new_depth &&
+      !mw->menu.new_stack [mw->menu.new_depth - 1]->contents)
+    mw->menu.new_depth -= 1;
 }
 
 static void
@@ -306,7 +299,7 @@
     {
       mw->menu.old_stack_length *= 2;
       mw->menu.old_stack =
-	(widget_value**)XtRealloc ((char*)mw->menu.old_stack,
+	(widget_value**)XtRealloc ((char *)mw->menu.old_stack,
 				   mw->menu.old_stack_length *
 				   sizeof (widget_value*));
     }
@@ -315,9 +308,9 @@
 static Boolean
 close_to_reference_time(Widget w, Time reference_time, XEvent *ev)
 {
-  return (reference_time &&
-	  (ev->xbutton.time - reference_time
-	      < XtGetMultiClickTime (XtDisplay (w))));
+  return
+    reference_time &&
+    (ev->xbutton.time - reference_time < XtGetMultiClickTime (XtDisplay (w)));
 }
 
 /* Size code */
@@ -446,7 +439,7 @@
        ntimes++)
     result = &percent[1];
   
-  result = XtMalloc((ntimes * strlen(value)) + strlen(string) + 4);
+  result = XtMalloc ((ntimes * strlen(value)) + strlen(string) + 4);
   result[0] = '\0';
 
   while ((percent = strchr(string, '%')))
@@ -583,7 +576,7 @@
       val->toolkit_data = complete_name;
       val->free_toolkit_data = True;
     }
-  return ((XmString) val->toolkit_data);
+  return (XmString) val->toolkit_data;
 }
 
 /* Unused */
@@ -608,8 +601,7 @@
 		     name,
 		     name,
 		     nameResource, 1,
-		     NULL, 0
-		     );
+		     NULL, 0);
 
   if (!string)
     string = name;
@@ -664,7 +656,7 @@
 	}
       val->free_toolkit_data = True;
     }
-  return (char*)val->toolkit_data;
+  return (char *) val->toolkit_data;
 }
 
 #endif /* !Motif */
@@ -673,8 +665,7 @@
  *    Code for drawing strings.
  */
 static void
-string_draw(
-	    XlwMenuWidget mw,
+string_draw(XlwMenuWidget mw,
 	    Window window,
 	    int x, int y,
 	    GC gc,
@@ -683,7 +674,8 @@
 #else
 	    char *string
 #endif
-) {
+)
+{
 #ifdef NEED_MOTIF
   XmStringDraw (XtDisplay (mw), window,
 		mw->menu.font_list,
@@ -716,14 +708,12 @@
  *    Low level code for drawing 3-D edges.
  */
 static void
-shadow_rectangle_draw (
-		       Display *dpy,
+shadow_rectangle_draw (Display *dpy,
 		       Window window,
 		       GC top_gc,
 		       GC bottom_gc,
 		       int x, int y, unsigned width, unsigned height,
-		       unsigned thickness
-		       )
+		       unsigned thickness)
 {
   XPoint points [4];
 
@@ -794,8 +784,7 @@
 shadow_draw (XlwMenuWidget mw,
 	     Window window,
 	     int x, int y, unsigned width, unsigned height,
-	     shadow_type type
-	     )
+	     shadow_type type)
 {
   Display *dpy = XtDisplay (mw);
   GC top_gc;
@@ -835,47 +824,39 @@
   if (etched)
     {
       unsigned half = thickness/2;
-      shadow_rectangle_draw (
-			     dpy,
+      shadow_rectangle_draw (dpy,
 			     window,
 			     top_gc,
 			     top_gc,
 			     x, y,
 			     width - half, height - half,
-			     thickness - half
-			     );
-      shadow_rectangle_draw (
-			     dpy,
+			     thickness - half);
+      shadow_rectangle_draw (dpy,
 			     window,
 			     bottom_gc,
 			     bottom_gc,
 			     x + half, y + half,
 			     width - half , height - half,
-			     half
-			     );
+			     half);
     }
   else
     {
-      shadow_rectangle_draw (
-			     dpy,
+      shadow_rectangle_draw (dpy,
 			     window,
 			     top_gc,
 			     bottom_gc,
 			     x, y,
 			     width, height,
-			     thickness
-			     );
+			     thickness);
     }
 }
 
 static void 
-arrow_decoration_draw (
-		       XlwMenuWidget mw,
+arrow_decoration_draw (XlwMenuWidget mw,
 		       Window window,
 		       int x, int y,
 		       unsigned width,
-		       Boolean raised
-		       )
+		       Boolean raised)
 {
   Display *dpy = XtDisplay (mw);
   GC top_gc;
@@ -896,12 +877,12 @@
   
   if (raised)
     {
-      top_gc = mw->menu.shadow_bottom_gc;
+      top_gc    = mw->menu.shadow_bottom_gc;
       bottom_gc = mw->menu.shadow_top_gc;
     }
   else
     {
-      top_gc = mw->menu.shadow_top_gc;
+      top_gc    = mw->menu.shadow_top_gc;
       bottom_gc = mw->menu.shadow_bottom_gc;
     }
 
@@ -918,15 +899,13 @@
   points [3].x = x + thickness;
   points [3].y = y + width - thickness;
     
-  XFillPolygon (
-		dpy,
+  XFillPolygon (dpy,
 		window,
 		select_gc,
 		points,
 		4, 
 		Convex,
-		CoordModeOrigin
-		);
+		CoordModeOrigin);
 
   /* left border */
   points [0].x = x;
@@ -966,13 +945,11 @@
 }
 
 static void
-toggle_decoration_draw (
-			XlwMenuWidget mw,
+toggle_decoration_draw (XlwMenuWidget mw,
 			Window window,
 			int x, int y,
 			unsigned width,
-			Boolean set
-			)
+			Boolean set)
 {
   Display *dpy = XtDisplay (mw);
   int thickness = mw->menu.shadow_thickness;
@@ -988,27 +965,23 @@
    *    Fill internal area.
    */
   if (set) 
-    XFillRectangle (
-		    dpy,
+    XFillRectangle (dpy,
 		    window,
 		    select_gc,
 		    x + thickness,
 		    y + thickness,
 		    width - (2*thickness),
-		    width - (2*thickness)
-		    );
+		    width - (2*thickness));
   
   shadow_draw(mw, window, x, y, width, width, type);
 }
 
 static void
-radio_decoration_draw (
-		       XlwMenuWidget mw,
+radio_decoration_draw (XlwMenuWidget mw,
 		       Window window,
 		       int x, int y,
 		       unsigned width,
-		       Boolean enabled
-		       )
+		       Boolean enabled)
 {
   Display *dpy = XtDisplay (mw);
   GC top_gc;
@@ -1028,12 +1001,12 @@
 
   if (enabled)
     {
-      top_gc = mw->menu.shadow_bottom_gc;
+      top_gc    = mw->menu.shadow_bottom_gc;
       bottom_gc = mw->menu.shadow_top_gc;
     }
   else
     {
-      top_gc = mw->menu.shadow_top_gc;
+      top_gc    = mw->menu.shadow_top_gc;
       bottom_gc = mw->menu.shadow_bottom_gc;
     }
 
@@ -1146,20 +1119,17 @@
 		    points,
 		    4, 
 		    Convex,
-		    CoordModeOrigin
-		    );
+		    CoordModeOrigin);
     }
 }
 
 static void
-separator_decoration_draw (
-			   XlwMenuWidget mw,
+separator_decoration_draw (XlwMenuWidget mw,
 			   Window window,
 			   int x, int y,
 			   unsigned width,
 			   Boolean vertical,
-			   shadow_type type
-			   )
+			   shadow_type type)
 {
   Display *dpy = XtDisplay (mw);
   GC top_gc;
@@ -1241,11 +1211,9 @@
 	XDrawLine (dpy, window, top_gc, x, y + i, x + width, y + i);
       
       for (i = 0; i < bottom_line_thickness; i++)
-	XDrawLine (
-		   dpy, window, bottom_gc, 
+	XDrawLine (dpy, window, bottom_gc, 
 		   x, y + top_line_thickness + offset + i,
-		   x + width, y + top_line_thickness + offset + i
-		   );
+		   x + width, y + top_line_thickness + offset + i);
       y += (top_line_thickness + offset + bottom_line_thickness + 1);
     }
 
@@ -1350,15 +1318,13 @@
 }
 
 static void
-label_button_size (
-		   XlwMenuWidget mw,
+label_button_size (XlwMenuWidget mw,
 		   widget_value *val,
 		   Boolean in_menubar,
 		   unsigned *toggle_width,
 		   unsigned *label_width,
 		   unsigned *bindings_width,
-		   unsigned *height
-		   )
+		   unsigned *height)
 {
   *height = (mw->menu.font_ascent + mw->menu.font_descent +
 	     2 * mw->menu.vertical_margin +
@@ -1371,8 +1337,7 @@
 }
 
 static void
-label_button_draw (
-		   XlwMenuWidget mw,
+label_button_draw (XlwMenuWidget mw,
 		   widget_value *val,
 		   Boolean       in_menubar,
 		   Boolean       highlighted,
@@ -1381,8 +1346,7 @@
 		   unsigned width,
 		   unsigned height,
 		   unsigned label_offset,
-		   unsigned binding_tab
-		   )
+		   unsigned binding_tab)
 {
   int y_offset = mw->menu.shadow_thickness + mw->menu.vertical_margin;
   
@@ -1392,32 +1356,26 @@
   /*
    *    Draw the label string.
    */
-  string_draw (
-	       mw,
+  string_draw (mw,
 	       window,
 	       x + label_offset, y + y_offset, 
 	       mw->menu.foreground_gc,
-	       resource_widget_value (mw, val)
-	       );
+	       resource_widget_value (mw, val));
 }
 
 static void
-push_button_size (
-		  XlwMenuWidget mw,
+push_button_size (XlwMenuWidget mw,
 		  widget_value *val,
 		  Boolean in_menubar,
 		  unsigned *toggle_width,
 		  unsigned *label_width,
 		  unsigned *bindings_width,
-		  unsigned *height
-		  )
+		  unsigned *height)
 {
   /* inherit */
-  label_button_size (
-		     mw, val, in_menubar,
+  label_button_size (mw, val, in_menubar,
 		     toggle_width, label_width, bindings_width,
-		     height
-		     );
+		     height);
   
   /* key bindings to display? */
   if (!in_menubar && val->key)
@@ -1436,8 +1394,7 @@
 }
 
 static void
-push_button_draw (
-		  XlwMenuWidget mw, 
+push_button_draw (XlwMenuWidget mw,
 		  widget_value *val,
 		  Boolean       in_menubar,
 		  Boolean       highlighted,
@@ -1445,8 +1402,7 @@
 		  int x, int y, 
 		  unsigned width, unsigned height,
 		  unsigned      label_offset,
-		  unsigned      binding_offset
-		  )
+		  unsigned      binding_offset)
 {
   int y_offset = mw->menu.shadow_thickness + mw->menu.vertical_margin;
   GC gc;
@@ -1474,13 +1430,11 @@
 	gc = mw->menu.inactive_gc;
     }
 
-  string_draw (
-	       mw,
+  string_draw (mw,
 	       window,
 	       x + label_offset, y + y_offset, 
 	       gc,
-	       resource_widget_value(mw, val)
-	       );
+	       resource_widget_value(mw, val));
   
   /*
    *    Draw the keybindings
@@ -1533,22 +1487,18 @@
 }
 
 static void
-cascade_button_size (
-		     XlwMenuWidget mw,
+cascade_button_size (XlwMenuWidget mw,
 		     widget_value *val,
 		     Boolean in_menubar,
 		     unsigned *toggle_width,
 		     unsigned *label_width,
 		     unsigned *arrow_width,
-		     unsigned *height
-		     )
+		     unsigned *height)
 {
   /* inherit */
-  label_button_size (
-		     mw, val, in_menubar,
+  label_button_size (mw, val, in_menubar,
 		     toggle_width, label_width, arrow_width,
-		     height
-		     );
+		     height);
   /* we have a pull aside arrow */
   if (!in_menubar)
     {
@@ -1557,8 +1507,7 @@
 }
 
 static void
-cascade_button_draw (
-		     XlwMenuWidget mw, 
+cascade_button_draw (XlwMenuWidget mw, 
 		     widget_value *val,
 		     Boolean       in_menubar,
 		     Boolean       highlighted,
@@ -1566,8 +1515,7 @@
 		     int x, int y, 
 		     unsigned width, unsigned height,
 		     unsigned      label_offset,
-		     unsigned      binding_offset
-		     )
+		     unsigned      binding_offset)
 {
   shadow_type type;
 
@@ -1600,14 +1548,12 @@
 	  binding_offset = label_offset + s_width +  mw->menu.shadow_thickness;
 	}
       
-      arrow_decoration_draw (
-			     mw,
+      arrow_decoration_draw (mw,
 			     window,
 			     x + binding_offset + mw->menu.column_spacing,
 			     y + y_offset,
 			     arrow_height,
-			     highlighted
-			     );
+			     highlighted);
     }
   
   /*
@@ -1637,29 +1583,24 @@
 }
 
 static void
-toggle_button_size (
-		    XlwMenuWidget mw,
+toggle_button_size (XlwMenuWidget mw,
 		    widget_value *val,
 		    Boolean in_menubar,
 		    unsigned *toggle_width,
 		    unsigned *label_width,
 		    unsigned *bindings_width,
-		    unsigned *height
-		    )
+		    unsigned *height)
 {
   /* inherit */
-  push_button_size (
-		    mw, val, in_menubar,
+  push_button_size (mw, val, in_menubar,
 		    toggle_width, label_width, bindings_width,
-		    height
-		    );
+		    height);
   /* we have a toggle */
   *toggle_width += toggle_decoration_height(mw) + mw->menu.column_spacing;
 }
 
 static void
-toggle_button_draw (
-		    XlwMenuWidget mw, 
+toggle_button_draw (XlwMenuWidget mw,
 		    widget_value *val,
 		    Boolean       in_menubar,
 		    Boolean highlighted,
@@ -1667,8 +1608,7 @@
 		    int x, int y, 
 		    unsigned width, unsigned height,
 		    unsigned      label_tab,
-		    unsigned      binding_tab
-		    )
+		    unsigned      binding_tab)
 {
   int x_offset;
   int y_offset;
@@ -1698,8 +1638,7 @@
 }
 
 static void
-radio_button_draw (
-		   XlwMenuWidget mw, 
+radio_button_draw (XlwMenuWidget mw, 
 		   widget_value *val,
 		   Boolean       in_menubar,
 		   Boolean       highlighted,
@@ -1707,8 +1646,7 @@
 		   int x, int y, 
 		   unsigned width, unsigned height,
 		   unsigned      label_tab,
-		   unsigned      binding_tab
-		   )
+		   unsigned      binding_tab)
 {
   int x_offset;
   int y_offset;
@@ -1802,8 +1740,7 @@
 		unsigned *toggle_width,
 		unsigned *label_width,
 		unsigned *rest_width,
-		unsigned *height
-		)
+		unsigned *height)
 {
   *height = separator_decoration_height (mw, val);
   *label_width = 1;
@@ -1819,8 +1756,7 @@
 		int x, int y, 
 		unsigned width, unsigned height,
 		unsigned      label_tab,
-		unsigned      binding_tab
-		)
+		unsigned      binding_tab)
 {
   unsigned sep_width;
 
@@ -1835,8 +1771,7 @@
 			     y,
 			     sep_width,
 			     in_menubar,
-			     separator_type(val->value)
-			     );
+			     separator_type(val->value));
 }
 
 static void
@@ -1862,16 +1797,14 @@
 		unsigned *height
 )
 {
-
-  void (*function_ptr) (
-			XlwMenuWidget _mw,
+  void (*function_ptr) (XlwMenuWidget _mw,
 			widget_value *_val,
 			Boolean _in_menubar,
 			unsigned *_toggle_width,
 			unsigned *_label_width,
 			unsigned *_rest_width,
-			unsigned *_height
-			);
+			unsigned *_height);
+
   switch (menu_item_type (val))
     {
     case TOGGLE_TYPE:
@@ -1897,27 +1830,23 @@
       break;
     }
 
-  (*function_ptr) (
-		   mw,
+  (*function_ptr) (mw,
 		   val,
 		   horizontal,
 		   toggle_width,
 		   label_width,
 		   rest_width,
-		   height
-		   );
+		   height);
 }
 
 static void
-display_menu_item (
-		   XlwMenuWidget mw,
+display_menu_item (XlwMenuWidget mw,
 		   widget_value *val,
 		   window_state *ws,
 		   XPoint *where,
 		   Boolean highlighted,
 		   Boolean horizontal,
-		   Boolean just_compute
-		   )
+		   Boolean just_compute)
 {
   
   int x = where->x /* + mw->menu.shadow_thickness */ ;
@@ -1929,8 +1858,7 @@
   unsigned height;
   unsigned label_tab;
   unsigned binding_tab;
-  void (*function_ptr) (
-			XlwMenuWidget _mw,
+  void (*function_ptr) (XlwMenuWidget _mw,
 			widget_value *_val,
 			Boolean _in_menubar,
 			Boolean _highlighted,
@@ -1938,13 +1866,10 @@
 			int _x, int _y, 
 			unsigned _width, unsigned _height,
 			unsigned      _label_tab,
-			unsigned      _binding_tab
-			);
+			unsigned      _binding_tab);
 
-  size_menu_item (
-		  mw, val, horizontal,
-		  &toggle_width, &label_width, &binding_width, &height
-		  );
+  size_menu_item (mw, val, horizontal,
+		  &toggle_width, &label_width, &binding_width, &height);
 
   if (horizontal)
     {
@@ -1992,8 +1917,7 @@
       return;
     }
 
-  (*function_ptr) (
-		   mw,
+  (*function_ptr) (mw,
 		   val,
 		   horizontal,
 		   highlighted,
@@ -2001,8 +1925,7 @@
 		   x, y, 
 		   width, height,
 		   label_tab,
-		   binding_tab
-		   );
+		   binding_tab);
 }
 
 static void
@@ -2013,8 +1936,8 @@
   unsigned	rest_width;
   unsigned	height;
   unsigned	max_toggle_width = 0;
-  unsigned	max_label_width = 0;
-  unsigned	max_rest_width = 0;
+  unsigned	max_label_width  = 0;
+  unsigned	max_rest_width   = 0;
   unsigned	max_height = 0;
   int		horizontal_p = mw->menu.horizontal && (level == 0);
   widget_value*	val;
@@ -2027,15 +1950,13 @@
 
   for (val = mw->menu.old_stack [level]->contents; val; val = val->next)
     {
-      size_menu_item (
-		      mw,
+      size_menu_item (mw,
 		      val,
 		      horizontal_p,
 		      &toggle_width,
 		      &label_width,
 		      &rest_width,
-		      &height
-		      );
+		      &height);
       if (horizontal_p)
 	{
 	  max_label_width += toggle_width + label_width + rest_width;
@@ -2044,12 +1965,12 @@
 	}
       else
 	{
-	  if (toggle_width > max_toggle_width)
-	    max_toggle_width = toggle_width;
-	  if (label_width > max_label_width)
-	    max_label_width = label_width;
-	  if (rest_width > max_rest_width)
-	    max_rest_width = rest_width;
+	  if (max_toggle_width < toggle_width)
+	      max_toggle_width = toggle_width;
+	  if (max_label_width < label_width)
+	      max_label_width = label_width;
+	  if (max_rest_width < rest_width)
+	      max_rest_width = rest_width;
 	  max_height += height;
 	}
     }
@@ -2057,9 +1978,9 @@
   ws->height = max_height;
   ws->width = max_label_width + max_rest_width + max_toggle_width;
   ws->toggle_width = max_toggle_width;
-  ws->label_width = max_label_width;
+  ws->label_width  = max_label_width;
 
-  ws->width += 2 * mw->menu.shadow_thickness;
+  ws->width  += 2 * mw->menu.shadow_thickness;
   ws->height += 2 * mw->menu.shadow_thickness;
 }
 
@@ -2235,7 +2156,7 @@
   else
     {
       mw->menu.windows =
-	(window_state *) XtRealloc ((char*)mw->menu.windows,
+	(window_state *) XtRealloc ((char *) mw->menu.windows,
 				    n * sizeof (window_state));
       start_at = mw->menu.windows_length;
     }
@@ -2400,8 +2321,8 @@
   int y = level == 0 ? ws->y : ws->y + mw->menu.shadow_thickness;
   relative_pos->x = ev->x_root - x;
   relative_pos->y = ev->y_root - y;
-  return (x < ev->x_root && ev->x_root < (int) (x + ws->width)
-	  && y < ev->y_root && ev->y_root < (int) (y + ws->height));
+  return (x < ev->x_root && ev->x_root < (int) (x + ws->width) &&
+	  y < ev->y_root && ev->y_root < (int) (y + ws->height));
 }
 
 static Boolean
@@ -2509,7 +2430,7 @@
   xgcv.fill_style = FillStippled;
   xgcv.stipple = mw->menu.gray_pixmap;
   mw->menu.inactive_button_gc = XtGetGC ((Widget)mw,
-				  (flags | GCFillStyle | GCStipple),
+					 (flags | GCFillStyle | GCStipple),
 					 &xgcv);
 }
 
@@ -2523,12 +2444,12 @@
   XtReleaseGC ((Widget) mw, mw->menu.background_gc);
   XtReleaseGC ((Widget) mw, mw->menu.select_gc);
   /* let's get some segvs if we try to use these... */
-  mw->menu.foreground_gc = (GC) -1;
-  mw->menu.button_gc = (GC) -1;
-  mw->menu.inactive_gc = (GC) -1;
+  mw->menu.foreground_gc      = (GC) -1;
+  mw->menu.button_gc          = (GC) -1;
+  mw->menu.inactive_gc        = (GC) -1;
   mw->menu.inactive_button_gc = (GC) -1;
-  mw->menu.background_gc = (GC) -1;
-  mw->menu.select_gc = (GC) -1;
+  mw->menu.background_gc      = (GC) -1;
+  mw->menu.select_gc          = (GC) -1;
 }
 
 #define MINL(x,y) ((((unsigned long) (x)) < ((unsigned long) (y))) \
@@ -2545,9 +2466,9 @@
   int top_frobbed = 0, bottom_frobbed = 0;
 
   if (mw->menu.top_shadow_color == -1)
-    mw->menu.top_shadow_color = mw->core.background_pixel;
+      mw->menu.top_shadow_color = mw->core.background_pixel;
   if (mw->menu.bottom_shadow_color == -1)
-    mw->menu.bottom_shadow_color = mw->menu.foreground;
+      mw->menu.bottom_shadow_color = mw->menu.foreground;
 
   if (mw->menu.top_shadow_color == mw->core.background_pixel ||
       mw->menu.top_shadow_color == mw->menu.foreground)
@@ -2810,10 +2731,9 @@
 /*  mw->menu.cursor = XCreateFontCursor (display, mw->menu.cursor_shape); */
   mw->menu.cursor = mw->menu.cursor_shape;
   
-  mw->menu.gray_pixmap = XCreatePixmapFromBitmapData (display, window,
-						      (char *) gray_bits,
-						      gray_width,
-						      gray_height, 1, 0, 1);
+  mw->menu.gray_pixmap =
+    XCreatePixmapFromBitmapData (display, window, (char *) gray_bits,
+				 gray_width, gray_height, 1, 0, 1);
   
 #ifdef NEED_MOTIF
   /* The menu.font_list slot came from the *fontList resource (Motif standard.)
@@ -2932,7 +2852,7 @@
     }
   
   release_drawing_gcs (mw);
-  release_shadow_gcs (mw);
+  release_shadow_gcs  (mw);
 
   /* this doesn't come from the resource db but is created explicitly
      so we must free it ourselves. */
@@ -2982,8 +2902,8 @@
       || newmw->menu.foreground != oldmw->menu.foreground
       /* For the XEditResource protocol, which may want to change the font. */
 #ifdef NEED_MOTIF
-      || newmw->menu.font_list != oldmw->menu.font_list
-      || newmw->menu.font_list_2 != oldmw->menu.font_list_2
+      || newmw->menu.font_list          != oldmw->menu.font_list
+      || newmw->menu.font_list_2        != oldmw->menu.font_list_2
       || newmw->menu.fallback_font_list != oldmw->menu.fallback_font_list
 #else
       || newmw->menu.font != oldmw->menu.font
@@ -3013,7 +2933,7 @@
 {
   XlwMenuWidget mw = (XlwMenuWidget)w;
 
-  mw->menu.windows [0].width = mw->core.width;
+  mw->menu.windows [0].width  = mw->core.width;
   mw->menu.windows [0].height = mw->core.height;
 }
 
@@ -3175,7 +3095,7 @@
     }
   
   /* callback */
-  XtCallCallbackList ((Widget)mw, mw->menu.select, (XtPointer)selected_item);
+  XtCallCallbackList ((Widget) mw, mw->menu.select, (XtPointer) selected_item);
 }
 
 
@@ -3195,7 +3115,7 @@
   mw->menu.next_release_must_exit = True;
   mw->menu.last_selected_val = NULL;
 
-  XtCallCallbackList ((Widget)mw, mw->menu.open, NULL);
+  XtCallCallbackList ((Widget) mw, mw->menu.open, NULL);
 
   size_menu (mw, 0);
 
@@ -3204,14 +3124,18 @@
 
   x -= borderwidth;
   y -= borderwidth;
+  
   if (x < borderwidth)
-    x = borderwidth;
-  if (x + w + 2 * borderwidth > WidthOfScreen (screen))
-    x = WidthOfScreen (screen) - w - 2 * borderwidth;
+      x = borderwidth;
+  
+  if (x > WidthOfScreen (screen) - w - 2 * borderwidth)
+      x = WidthOfScreen (screen) - w - 2 * borderwidth;
+  
   if (y < borderwidth)
-    y = borderwidth;
-  if (y + h + 2 * borderwidth> HeightOfScreen (screen))
-    y = HeightOfScreen (screen) - h - 2 * borderwidth;
+      y = borderwidth;
+  
+  if (y > HeightOfScreen (screen) - h - 2 * borderwidth)
+      y = HeightOfScreen (screen) - h - 2 * borderwidth;
 
   mw->menu.popped_up = True;
   XtConfigureWidget (XtParent (mw), x, y, w, h,
@@ -3245,7 +3169,7 @@
 xlw_unmunge_class_resize (Widget w)
 {
   if (w->core.widget_class->core_class.resize != XlwMenuResize)
-    w->core.widget_class->core_class.resize = XlwMenuResize;
+      w->core.widget_class->core_class.resize  = XlwMenuResize;
 }
 #endif /* 0 */