/* Implements a lightweight menubar widget.
Copyright (C) 1992 Lucid, Inc.
- Copyright (C) 2002 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
This file is part of the Lucid Widget Library.
You should have received a copy of the GNU General Public License
along with GNU Emacs; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA. */
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
/* Created by devin@lucid.com */
unsigned long *,
double, int));
extern int x_catch_errors __P ((Display*));
-extern int x_uncatch_errors __P ((Display*, int));
+extern void x_uncatch_errors P_ ((Display *, int));
extern int x_had_errors_p __P ((Display*));
-extern int x_clear_errors __P ((Display*));
+extern void x_clear_errors __P ((Display*));
extern unsigned long x_copy_dpy_color __P ((Display *, Colormap,
unsigned long));
static XtResource
xlwMenuResources[] =
{
+#ifdef HAVE_X_I18N
+ {XtNfontSet, XtCFontSet, XtRFontSet, sizeof(XFontSet),
+ offset(menu.fontSet), XtRFontSet, NULL},
+#endif
{XtNfont, XtCFont, XtRFontStruct, sizeof(XFontStruct *),
- offset(menu.font),XtRString, "XtDefaultFont"},
+ offset(menu.font), XtRString, "XtDefaultFont"},
{XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel),
offset(menu.foreground), XtRString, "XtDefaultForeground"},
{XtNdisabledForeground, XtCDisabledForeground, XtRPixel, sizeof(Pixel),
{"right", Right},
{"select", Select},
{"key", Key},
+ {"MenuGadgetEscape", Key}, /* Compatibility with Lesstif/Motif. */
{"nothing", Nothing},
};
XtNumber(xlwMenuResources), /* resource_count */
NULLQUARK, /* xrm_class */
TRUE, /* compress_motion */
- TRUE, /* compress_exposure */
+ XtExposeCompressMaximal, /* compress_exposure */
TRUE, /* compress_enterleave */
FALSE, /* visible_interest */
XlwMenuDestroy, /* destroy */
{
XCharStruct xcs;
int drop;
+#ifdef HAVE_X_I18N
+ XRectangle ink, logical;
+ if (mw->menu.fontSet)
+ {
+ XmbTextExtents (mw->menu.fontSet, s, strlen (s), &ink, &logical);
+ return logical.width;
+ }
+#endif
XTextExtents (mw->menu.font, s, strlen (s), &drop, &drop, &drop, &xcs);
return xcs.width;
+
}
+#ifdef HAVE_X_I18N
+#define MENU_FONT_HEIGHT(mw) \
+ ((mw)->menu.fontSet != NULL \
+ ? (mw)->menu.font_extents->max_logical_extent.height \
+ : (mw)->menu.font->ascent + (mw)->menu.font->descent)
+#define MENU_FONT_ASCENT(mw) \
+ ((mw)->menu.fontSet != NULL \
+ ? - (mw)->menu.font_extents->max_logical_extent.y \
+ : (mw)->menu.font->ascent)
+#else
+#define MENU_FONT_HEIGHT(mw) \
+ ((mw)->menu.font->ascent + (mw)->menu.font->descent)
+#define MENU_FONT_ASCENT(mw) ((mw)->menu.font->ascent)
+#endif
+
static int
arrow_width (mw)
XlwMenuWidget mw;
{
- return (mw->menu.font->ascent * 3/4) | 1;
+ return (MENU_FONT_ASCENT (mw) * 3/4) | 1;
}
/* Return the width of toggle buttons of widget MW. */
toggle_button_width (mw)
XlwMenuWidget mw;
{
- return ((mw->menu.font->ascent + mw->menu.font->descent) * 2 / 3) | 1;
+ return (MENU_FONT_HEIGHT (mw) * 2 / 3) | 1;
}
}
else
{
- *height =
- mw->menu.font->ascent + mw->menu.font->descent
- + 2 * mw->menu.vertical_spacing + 2 * mw->menu.shadow_thickness;
+ *height = MENU_FONT_HEIGHT (mw)
+ + 2 * mw->menu.vertical_spacing + 2 * mw->menu.shadow_thickness;
*label_width =
string_width (mw, resource_widget_value (mw, val))
double factor = 1.62;
int thickness2 = thickness * factor;
- y += (mw->menu.font->ascent + mw->menu.font->descent - height) / 2;
+ y += (MENU_FONT_HEIGHT (mw) - height) / 2;
if (down_p)
{
width = toggle_button_width (mw);
height = width;
x += mw->menu.horizontal_spacing;
- y += (mw->menu.font->ascent - height) / 2;
+ y += (MENU_FONT_ASCENT (mw) - height) / 2;
draw_shadow_rectangle (mw, window, x, y, width, height, False, selected_p);
}
width = radio_button_width (mw);
height = width;
x += mw->menu.horizontal_spacing;
- y += (mw->menu.font->ascent - height) / 2;
+ y += (MENU_FONT_ASCENT (mw) - height) / 2;
draw_shadow_rhombus (mw, window, x, y, width, height, False, selected_p);
}
{
GC deco_gc;
GC text_gc;
- int font_ascent = mw->menu.font->ascent;
- int font_descent = mw->menu.font->descent;
+ int font_height = MENU_FONT_HEIGHT (mw);
+ int font_ascent = MENU_FONT_ASCENT (mw);
int shadow = mw->menu.shadow_thickness;
int margin = mw->menu.margin;
int h_spacing = mw->menu.horizontal_spacing;
x_offset += ws->button_width;
- XDrawString (XtDisplay (mw), ws->window, text_gc, x_offset,
+#ifdef HAVE_X_I18N
+ if (mw->menu.fontSet)
+ XmbDrawString (XtDisplay (mw), ws->window, mw->menu.fontSet,
+ text_gc, x_offset,
+ y + v_spacing + shadow + font_ascent,
+ display_string, strlen (display_string));
+ else
+#endif
+ XDrawString (XtDisplay (mw), ws->window,
+ text_gc, x_offset,
y + v_spacing + shadow + font_ascent,
display_string, strlen (display_string));
}
else if (val->key)
{
- XDrawString (XtDisplay (mw), ws->window, text_gc,
+#ifdef HAVE_X_I18N
+ if (mw->menu.fontSet)
+ XmbDrawString (XtDisplay (mw), ws->window,
+ mw->menu.fontSet,
+ text_gc,
+ x + label_width + mw->menu.arrow_spacing,
+ y + v_spacing + shadow + font_ascent,
+ val->key, strlen (val->key));
+ else
+#endif
+ XDrawString (XtDisplay (mw), ws->window,
+ text_gc,
x + label_width + mw->menu.arrow_spacing,
y + v_spacing + shadow + font_ascent,
val->key, strlen (val->key));
mw->menu.background_gc,
x + shadow, y + shadow,
label_width + h_spacing - 1,
- font_ascent + font_descent + 2 * v_spacing - 1);
+ font_height + 2 * v_spacing - 1);
draw_shadow_rectangle (mw, ws->window, x, y, width, height,
True, False);
}
{
XGCValues xgcv;
float scale;
+ XtGCMask mask = GCForeground | GCBackground;
+#ifdef HAVE_X_I18N
+ if (!mw->menu.fontSet)
+ {
+ xgcv.font = mw->menu.font->fid;
+ mask |= GCFont;
+ }
+#else
xgcv.font = mw->menu.font->fid;
+ mask |= GCFont;
+#endif
xgcv.foreground = mw->menu.foreground;
xgcv.background = mw->core.background_pixel;
- mw->menu.foreground_gc = XtGetGC ((Widget)mw,
- GCFont | GCForeground | GCBackground,
- &xgcv);
+ mw->menu.foreground_gc = XtGetGC ((Widget)mw, mask, &xgcv);
- xgcv.font = mw->menu.font->fid;
xgcv.foreground = mw->menu.button_foreground;
- xgcv.background = mw->core.background_pixel;
- mw->menu.button_gc = XtGetGC ((Widget)mw,
- GCFont | GCForeground | GCBackground,
- &xgcv);
+ mw->menu.button_gc = XtGetGC ((Widget)mw, mask, &xgcv);
- xgcv.font = mw->menu.font->fid;
xgcv.background = mw->core.background_pixel;
#define BRIGHTNESS(color) (((color) & 0xff) + (((color) >> 8) & 0xff) + (((color) >> 16) & 0xff))
xgcv.foreground = mw->menu.foreground;
xgcv.fill_style = FillStippled;
xgcv.stipple = mw->menu.gray_pixmap;
- mw->menu.disabled_gc = XtGetGC ((Widget)mw,
- (GCFont | GCForeground | GCBackground
- | GCFillStyle | GCStipple), &xgcv);
+ mw->menu.disabled_gc = XtGetGC ((Widget)mw, mask
+ | GCFillStyle | GCStipple, &xgcv);
}
else
{
/* Many colors available, use disabled pixel. */
xgcv.foreground = mw->menu.disabled_foreground;
- mw->menu.disabled_gc = XtGetGC ((Widget)mw,
- (GCFont | GCForeground | GCBackground), &xgcv);
+ mw->menu.disabled_gc = XtGetGC ((Widget)mw, mask, &xgcv);
}
- xgcv.font = mw->menu.font->fid;
xgcv.foreground = mw->menu.button_foreground;
xgcv.background = mw->core.background_pixel;
xgcv.fill_style = FillStippled;
xgcv.stipple = mw->menu.gray_pixmap;
- mw->menu.inactive_button_gc = XtGetGC ((Widget)mw,
- (GCFont | GCForeground | GCBackground
- | GCFillStyle | GCStipple), &xgcv);
+ mw->menu.inactive_button_gc = XtGetGC ((Widget)mw, mask
+ | GCFillStyle | GCStipple, &xgcv);
- xgcv.font = mw->menu.font->fid;
xgcv.foreground = mw->core.background_pixel;
xgcv.background = mw->menu.foreground;
- mw->menu.background_gc = XtGetGC ((Widget)mw,
- GCFont | GCForeground | GCBackground,
- &xgcv);
+ mw->menu.background_gc = XtGetGC ((Widget)mw, mask, &xgcv);
}
static void
Can anyone find a real fix? -- rms. */
if (mw->menu.font == 0)
mw->menu.font = xlwmenu_default_font;
-
+#ifdef HAVE_X_I18N
+ if (mw->menu.fontSet)
+ mw->menu.font_extents = XExtentsOfFontSet (mw->menu.fontSet);
+#endif
+
make_drawing_gcs (mw);
make_shadow_gcs (mw);
XlwMenuWidget mw = (XlwMenuWidget)w;
XSetWindowAttributes xswa;
int mask;
+ int count;
(*xlwMenuWidgetClass->core_class.superclass->core_class.realize)
(w, valueMask, attributes);
xswa.save_under = True;
xswa.cursor = mw->menu.cursor_shape;
mask = CWSaveUnder | CWCursor;
+ /* I sometimes get random BadCursor errors while creating the first
+ frame on a display. I can not find their reason, but they are
+ annoying so for now let's ignore any errors here. -- lorentey */
+#ifdef emacs
+ count = x_catch_errors (XtDisplay (w));
+#endif
XChangeWindowAttributes (XtDisplay (w), XtWindow (w), mask, &xswa);
+#ifdef emacs
+ x_uncatch_errors (XtDisplay (w), count);
+#endif
mw->menu.windows [0].window = XtWindow (w);
mw->menu.windows [0].x = w->core.x;
if (newmw->core.background_pixel != oldmw->core.background_pixel
|| newmw->menu.foreground != oldmw->menu.foreground
- || newmw->menu.font != oldmw->menu.font)
+#ifdef HAVE_X_I18N
+ || newmw->menu.fontSet != oldmw->menu.fontSet
+ || (newmw->menu.fontSet == NULL && newmw->menu.font != oldmw->menu.font)
+#else
+ || newmw->menu.font != oldmw->menu.font
+#endif
+ )
{
release_drawing_gcs (newmw);
make_drawing_gcs (newmw);
}
}
+#ifdef HAVE_X_I18N
+ if (newmw->menu.fontSet != oldmw->menu.fontSet && newmw->menu.fontSet != NULL)
+ {
+ redisplay = True;
+ newmw->menu.font_extents = XExtentsOfFontSet (newmw->menu.fontSet);
+ }
+#endif
+
return redisplay;
}
}
static widget_value *
-find_first_selectable (mw, item, skip_no_call_data)
+find_first_selectable (mw, item, skip_titles)
XlwMenuWidget mw;
widget_value *item;
- int skip_no_call_data;
+ int skip_titles;
{
widget_value *current = item;
enum menu_separator separator;
while (lw_separator_p (current->name, &separator, 0) || !current->enabled
- || (skip_no_call_data && !current->call_data))
+ || (skip_titles && !current->call_data && !current->contents))
if (current->next)
current=current->next;
else
- return NULL;
+ return NULL;
return current;
}
static widget_value *
-find_next_selectable (mw, item, skip_no_call_data)
+find_next_selectable (mw, item, skip_titles)
XlwMenuWidget mw;
widget_value *item;
+ int skip_titles;
{
widget_value *current = item;
enum menu_separator separator;
while (current->next && (current=current->next) &&
(lw_separator_p (current->name, &separator, 0) || !current->enabled
- || (skip_no_call_data && !current->call_data)))
+ || (skip_titles && !current->call_data && !current->contents)))
;
if (current == item)
while (lw_separator_p (current->name, &separator, 0)
|| !current->enabled
- || (skip_no_call_data && !current->call_data))
+ || (skip_titles && !current->call_data
+ && !current->contents))
{
if (current->next)
current=current->next;
}
static widget_value *
-find_prev_selectable (mw, item, skip_no_call_data)
+find_prev_selectable (mw, item, skip_titles)
XlwMenuWidget mw;
widget_value *item;
+ int skip_titles;
{
widget_value *current = item;
widget_value *prev = item;
- while ((current=find_next_selectable (mw, current, skip_no_call_data))
+ while ((current=find_next_selectable (mw, current, skip_titles))
!= item)
{
if (prev == current)
if (mw->menu.old_depth == mw->menu.top_depth)
/* When <down> in the menu-bar is pressed, display the corresponding
sub-menu and select the first selectable menu item there.
- If this is a popup menu, skip items with zero call data (title of
- the popup). */
+ If this is a popup menu, skip title item of the popup. */
set_new_state (mw,
find_first_selectable (mw,
selected_item->contents,
last selectable item in the list. So we select the first
selectable one and find the previous selectable item. Is there
a better way? */
- /* If this is a popup menu, skip items with zero call data (title of
- the popup). */
+ /* If this is a popup menu, skip title item of the popup. */
set_new_state (mw,
find_first_selectable (mw,
selected_item->contents,