#include <config.h>
#endif
-#include "../src/lisp.h"
+#include "lisp.h"
#include <stdio.h>
/* FIXME: Should ESC close one level of menu structure or the complete menu? */
-/* FIXME: Should F10 enter to menu? Which one? File? */
+/* FIXME: F10 should enter the menu, the first one in the menu-bar. */
#define offset(field) XtOffset(XlwMenuWidget, field)
static XtResource
offset(menu.font),XtRString, "XtDefaultFont"},
{XtNforeground, XtCForeground, XtRPixel, sizeof(Pixel),
offset(menu.foreground), XtRString, "XtDefaultForeground"},
+ {XtNdisabledForeground, XtCDisabledForeground, XtRPixel, sizeof(Pixel),
+ offset(menu.disabled_foreground), XtRString, (XtPointer)NULL},
{XtNbuttonForeground, XtCButtonForeground, XtRPixel, sizeof(Pixel),
offset(menu.button_foreground), XtRString, "XtDefaultForeground"},
{XtNmargin, XtCMargin, XtRDimension, sizeof(Dimension),
- offset(menu.margin), XtRImmediate, (XtPointer) 4},
+ offset(menu.margin), XtRImmediate, (XtPointer)1},
{XtNhorizontalSpacing, XtCMargin, XtRDimension, sizeof(Dimension),
offset(menu.horizontal_spacing), XtRImmediate, (XtPointer)3},
{XtNverticalSpacing, XtCMargin, XtRDimension, sizeof(Dimension),
- offset(menu.vertical_spacing), XtRImmediate, (XtPointer)1},
+ offset(menu.vertical_spacing), XtRImmediate, (XtPointer)2},
{XtNarrowSpacing, XtCMargin, XtRDimension, sizeof(Dimension),
offset(menu.arrow_spacing), XtRImmediate, (XtPointer)10},
{XmNshadowThickness, XmCShadowThickness, XtRDimension,
sizeof (Dimension), offset (menu.shadow_thickness),
- XtRImmediate, (XtPointer) 2},
+ XtRImmediate, (XtPointer)1},
{XmNtopShadowColor, XmCTopShadowColor, XtRPixel, sizeof (Pixel),
offset (menu.top_shadow_color), XtRImmediate, (XtPointer)-1},
{XmNbottomShadowColor, XmCBottomShadowColor, XtRPixel, sizeof (Pixel),
static void Select();
static void Key();
static void Nothing();
-static int separator_height ();
+static int separator_height __P ((enum menu_separator));
+static void pop_up_menu __P ((XlwMenuWidget, XButtonPressedEvent *));
+
static XtActionsRec
xlwMenuActionsList [] =
{"right", Right},
{"select", Select},
{"key", Key},
+ {"MenuGadgetEscape", Key}, /* Compatibility with Lesstif/Motif. */
{"nothing", Nothing},
};
int submenu_destroyed;
-/* For debug, set this to 0 to not grab the keyboard on menu popup */
-int x_menu_grab_keyboard = 1;
+/* For debug, if installation-directory is non-nil this is not an installed
+ Emacs. In that case we do not grab the keyboard to make it easier to
+ debug. */
+#define GRAB_KEYBOARD (EQ (Vinstallation_directory, Qnil))
static int next_release_must_exit;
Time ungrabtime;
{
XtUngrabPointer (w, ungrabtime);
- if (x_menu_grab_keyboard) XtUngrabKeyboard (w, ungrabtime);
+ if (GRAB_KEYBOARD) XtUngrabKeyboard (w, ungrabtime);
}
/* Like abort, but remove grabs from widget W before. */
pop_new_stack_if_no_contents (mw)
XlwMenuWidget mw;
{
- if (mw->menu.new_depth)
+ if (mw->menu.new_depth > 1)
{
if (!mw->menu.new_stack [mw->menu.new_depth - 1]->contents)
mw->menu.new_depth -= 1;
if (val->enabled)
text_gc = mw->menu.foreground_gc;
else
- text_gc = mw->menu.inactive_gc;
+ text_gc = mw->menu.disabled_gc;
deco_gc = mw->menu.foreground_gc;
if (separator_p)
{
XlwMenuWidget mw = (XlwMenuWidget) w;
int i;
-
+
for (i = 0; i < mw->menu.windows_length; ++i)
if (window == mw->menu.windows[i].window)
break;
/* unmap the menus that popped down */
for (i = new_depth - 1; i < old_depth; i++)
- if (i >= new_depth || !new_stack[i]->contents)
+ if (i >= new_depth || (i > 0 && !new_stack[i]->contents))
XUnmapWindow (XtDisplay (mw), windows[i].window);
}
XlwMenuWidget mw;
{
XGCValues xgcv;
+ float scale;
xgcv.font = mw->menu.font->fid;
xgcv.foreground = mw->menu.foreground;
&xgcv);
xgcv.font = mw->menu.font->fid;
- xgcv.foreground = mw->menu.foreground;
xgcv.background = mw->core.background_pixel;
- xgcv.fill_style = FillStippled;
- xgcv.stipple = mw->menu.gray_pixmap;
- mw->menu.inactive_gc = XtGetGC ((Widget)mw,
- (GCFont | GCForeground | GCBackground
- | GCFillStyle | GCStipple), &xgcv);
+
+#define BRIGHTNESS(color) (((color) & 0xff) + (((color) >> 8) & 0xff) + (((color) >> 16) & 0xff))
+
+ /* Allocate color for disabled menu-items. */
+ mw->menu.disabled_foreground = mw->menu.foreground;
+ if (BRIGHTNESS(mw->menu.foreground) < BRIGHTNESS(mw->core.background_pixel))
+ scale = 2.3;
+ else
+ scale = 0.55;
+
+ x_alloc_lighter_color_for_widget ((Widget) mw, XtDisplay ((Widget) mw),
+ mw->core.colormap,
+ &mw->menu.disabled_foreground,
+ scale,
+ 0x8000);
+
+ if (mw->menu.foreground == mw->menu.disabled_foreground
+ || mw->core.background_pixel == mw->menu.disabled_foreground)
+ {
+ /* Too few colors, use stipple. */
+ 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);
+ }
+ else
+ {
+ /* Many colors available, use disabled pixel. */
+ xgcv.foreground = mw->menu.disabled_foreground;
+ mw->menu.disabled_gc = XtGetGC ((Widget)mw,
+ (GCFont | GCForeground | GCBackground), &xgcv);
+ }
xgcv.font = mw->menu.font->fid;
xgcv.foreground = mw->menu.button_foreground;
{
XtReleaseGC ((Widget) mw, mw->menu.foreground_gc);
XtReleaseGC ((Widget) mw, mw->menu.button_gc);
- XtReleaseGC ((Widget) mw, mw->menu.inactive_gc);
+ XtReleaseGC ((Widget) mw, mw->menu.disabled_gc);
XtReleaseGC ((Widget) mw, mw->menu.inactive_button_gc);
XtReleaseGC ((Widget) mw, mw->menu.background_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.disabled_gc = (GC) -1;
mw->menu.inactive_button_gc = (GC) -1;
mw->menu.background_gc = (GC) -1;
}
Cardinal *num_args;
{
/* Get the GCs and the widget size */
- XSetWindowAttributes xswa;
- int mask;
Window window = RootWindowOfScreen (DefaultScreenOfDisplay (XtDisplay (mw)));
Display* display = XtDisplay (mw);
make_drawing_gcs (mw);
make_shadow_gcs (mw);
- xswa.background_pixel = mw->core.background_pixel;
- xswa.border_pixel = mw->core.border_pixel;
- mask = CWBackPixel | CWBorderPixel;
-
mw->menu.popped_up = False;
mw->menu.old_depth = 1;
if (!mw->menu.popped_up)
{
menu_post_event = *ev;
+ /* If event is set to CurrentTime, get the last known time stamp.
+ This is for calculating if (popup) menus should stay up after
+ a fast click. */
+ if (menu_post_event.xbutton.time == CurrentTime)
+ menu_post_event.xbutton.time
+ = XtLastTimestampProcessed (XtDisplay (w));
+
pop_up_menu (mw, (XButtonPressedEvent*) ev);
}
else
{
}
-widget_value *
-find_first_selectable (mw, item)
+static widget_value *
+find_first_selectable (mw, item, skip_titles)
XlwMenuWidget mw;
widget_value *item;
+ int skip_titles;
{
widget_value *current = item;
enum menu_separator separator;
- while (lw_separator_p (current->name, &separator, 0) || !current->enabled)
+ while (lw_separator_p (current->name, &separator, 0) || !current->enabled
+ || (skip_titles && !current->call_data && !current->contents))
if (current->next)
current=current->next;
else
- return NULL;
+ return NULL;
return current;
}
-widget_value *
-find_next_selectable (mw, item)
+static widget_value *
+find_next_selectable (mw, item, skip_titles)
XlwMenuWidget mw;
widget_value *item;
{
enum menu_separator separator;
while (current->next && (current=current->next) &&
- (lw_separator_p (current->name, &separator, 0) || !current->enabled))
+ (lw_separator_p (current->name, &separator, 0) || !current->enabled
+ || (skip_titles && !current->call_data && !current->contents)))
;
if (current == item)
{
+ if (mw->menu.old_depth < 2)
+ return current;
current = mw->menu.old_stack [mw->menu.old_depth - 2]->contents;
- while (lw_separator_p (current->name, &separator, 0) || !current->enabled)
+ while (lw_separator_p (current->name, &separator, 0)
+ || !current->enabled
+ || (skip_titles && !current->call_data
+ && !current->contents))
{
if (current->next)
current=current->next;
return current;
}
-widget_value *
-find_prev_selectable (mw, item)
+static widget_value *
+find_prev_selectable (mw, item, skip_titles)
XlwMenuWidget mw;
widget_value *item;
{
widget_value *current = item;
widget_value *prev = item;
- while ((current=find_next_selectable (mw, current)) != item)
+ while ((current=find_next_selectable (mw, current, skip_titles))
+ != item)
{
if (prev == current)
break;
{
XlwMenuWidget mw = (XlwMenuWidget) w;
widget_value* selected_item = mw->menu.old_stack [mw->menu.old_depth - 1];
+ int popup_menu_p = mw->menu.top_depth == 1;
/* Inside top-level menu-bar? */
- if (mw->menu.old_depth == 2)
+ 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. */
- set_new_state (mw, find_first_selectable (mw, selected_item->contents), mw->menu.old_depth);
+ sub-menu and select the first selectable menu item there.
+ If this is a popup menu, skip title item of the popup. */
+ set_new_state (mw,
+ find_first_selectable (mw,
+ selected_item->contents,
+ popup_menu_p),
+ mw->menu.old_depth);
else
/* Highlight next possible (enabled and not separator) menu item. */
- set_new_state (mw, find_next_selectable (mw, selected_item), mw->menu.old_depth - 1);
+ set_new_state (mw, find_next_selectable (mw, selected_item, popup_menu_p),
+ mw->menu.old_depth - 1);
remap_menubar (mw);
}
{
XlwMenuWidget mw = (XlwMenuWidget) w;
widget_value* selected_item = mw->menu.old_stack [mw->menu.old_depth - 1];
+ int popup_menu_p = mw->menu.top_depth == 1;
/* Inside top-level menu-bar? */
- if (mw->menu.old_depth == 2)
+ if (mw->menu.old_depth == mw->menu.top_depth)
{
/* FIXME: this is tricky. <up> in the menu-bar should select the
last selectable item in the list. So we select the first
selectable one and find the previous selectable item. Is there
a better way? */
- set_new_state (mw, find_first_selectable (mw, selected_item->contents), mw->menu.old_depth);
+ /* If this is a popup menu, skip title item of the popup. */
+ set_new_state (mw,
+ find_first_selectable (mw,
+ selected_item->contents,
+ popup_menu_p),
+ mw->menu.old_depth);
remap_menubar (mw);
selected_item = mw->menu.old_stack [mw->menu.old_depth - 1];
- set_new_state (mw, find_prev_selectable (mw, selected_item), mw->menu.old_depth - 1);
+ set_new_state (mw,
+ find_prev_selectable (mw,
+ selected_item,
+ popup_menu_p),
+ mw->menu.old_depth - 1);
}
else
/* Highlight previous (enabled and not separator) menu item. */
- set_new_state (mw, find_prev_selectable (mw, selected_item), mw->menu.old_depth - 1);
+ set_new_state (mw, find_prev_selectable (mw, selected_item, popup_menu_p),
+ mw->menu.old_depth - 1);
remap_menubar (mw);
}
-static void
+void
Left (w, ev, params, num_params)
Widget w;
XEvent *ev;
widget_value* selected_item = mw->menu.old_stack [mw->menu.old_depth - 1];
/* Inside top-level menu-bar? */
- if (mw->menu.old_depth == 2)
+ if (mw->menu.old_depth == mw->menu.top_depth)
/* When <left> in the menu-bar is pressed, display the previous item on
the menu-bar. If the current item is the first one, highlight the
last item in the menubar (probably Help). */
- set_new_state (mw, find_prev_selectable (mw, selected_item), mw->menu.old_depth - 1);
+ set_new_state (mw, find_prev_selectable (mw, selected_item, 0),
+ mw->menu.old_depth - 1);
+ else if (mw->menu.old_depth == 1
+ && selected_item->contents) /* Is this menu item expandable? */
+ {
+ set_new_state (mw, selected_item->contents, mw->menu.old_depth);
+ remap_menubar (mw);
+ selected_item = mw->menu.old_stack [mw->menu.old_depth - 1];
+ if (!selected_item->enabled && find_first_selectable (mw,
+ selected_item,
+ 0))
+ set_new_state (mw, find_first_selectable (mw, selected_item, 0),
+ mw->menu.old_depth - 1);
+ }
+
else
{
pop_new_stack_if_no_contents (mw);
- set_new_state (mw, mw->menu.old_stack [mw->menu.old_depth - 2], mw->menu.old_depth - 2);
+ set_new_state (mw, mw->menu.old_stack [mw->menu.old_depth - 2],
+ mw->menu.old_depth - 2);
}
remap_menubar (mw);
}
-static void
+void
Right (w, ev, params, num_params)
Widget w;
XEvent *ev;
widget_value* selected_item = mw->menu.old_stack [mw->menu.old_depth - 1];
/* Inside top-level menu-bar? */
- if (mw->menu.old_depth == 2)
+ if (mw->menu.old_depth == mw->menu.top_depth)
/* When <right> in the menu-bar is pressed, display the next item on
the menu-bar. If the current item is the last one, highlight the
first item (probably File). */
- set_new_state (mw, find_next_selectable (mw, selected_item), mw->menu.old_depth - 1);
+ set_new_state (mw, find_next_selectable (mw, selected_item, 0),
+ mw->menu.old_depth - 1);
else if (selected_item->contents) /* Is this menu item expandable? */
{
set_new_state (mw, selected_item->contents, mw->menu.old_depth);
remap_menubar (mw);
selected_item = mw->menu.old_stack [mw->menu.old_depth - 1];
- if (!selected_item->enabled && find_first_selectable (mw, selected_item))
- set_new_state (mw, find_first_selectable (mw, selected_item), mw->menu.old_depth - 1);
+ if (!selected_item->enabled && find_first_selectable (mw,
+ selected_item,
+ 0))
+ set_new_state (mw, find_first_selectable (mw, selected_item, 0),
+ mw->menu.old_depth - 1);
}
else
{
pop_new_stack_if_no_contents (mw);
- set_new_state (mw, mw->menu.old_stack [mw->menu.old_depth - 2], mw->menu.old_depth - 2);
+ set_new_state (mw, mw->menu.old_stack [mw->menu.old_depth - 2],
+ mw->menu.old_depth - 2);
}
remap_menubar (mw);
\f/* Special code to pop-up a menu */
-void
+static void
pop_up_menu (mw, event)
XlwMenuWidget mw;
XButtonPressedEvent* event;
display_menu (mw, 0, False, NULL, NULL, NULL, NULL, NULL);
mw->menu.windows [0].x = x + borderwidth;
mw->menu.windows [0].y = y + borderwidth;
+ mw->menu.top_depth = 1; /* Popup menus don't have a bar so top is 1 */
}
else
{
/* notes the absolute position of the menubar window */
mw->menu.windows [0].x = ev->xmotion.x_root - ev->xmotion.x;
mw->menu.windows [0].y = ev->xmotion.y_root - ev->xmotion.y;
+ mw->menu.top_depth = 2;
}
#ifdef emacs
mw->menu.cursor_shape,
event->time) == Success)
{
- if (! x_menu_grab_keyboard
+ if (! GRAB_KEYBOARD
|| XtGrabKeyboard ((Widget)mw, False, GrabModeAsync,
GrabModeAsync, event->time) == Success)
{
handle_motion_event (mw, (XMotionEvent*)event);
}
+
+/* arch-tag: 657f43dd-dfd0-4cc9-910c-52935f01176e
+ (do not change this comment) */