XtAddCallback (widget, XtNselect, pick_hook, (XtPointer)instance);
XtAddCallback (widget, XtNhighlightCallback, highlight_hook,
(XtPointer)instance);
+
return popup_shell;
}
Widget widget;
XEvent *event;
{
- XButtonPressedEvent dummy;
XlwMenuWidget mw;
if (!XtIsShell (widget))
mw = (XlwMenuWidget)((CompositeWidget)widget)->composite.children [0];
if (event)
- pop_up_menu (mw, (XButtonPressedEvent*) event);
+ XtCallActionProc ((Widget) mw, "start", event, NULL, 0);
else
{
- dummy.type = ButtonPress;
- dummy.serial = 0;
- dummy.send_event = 0;
- dummy.display = XtDisplay (widget);
- dummy.window = XtWindow (XtParent (widget));
- dummy.time = CurrentTime;
- dummy.button = 0;
- XQueryPointer (dummy.display, dummy.window, &dummy.root,
- &dummy.subwindow, &dummy.x_root, &dummy.y_root,
- &dummy.x, &dummy.y, &dummy.state);
-
- pop_up_menu (mw, &dummy);
+ XEvent dummy;
+ XButtonPressedEvent *bd = &dummy.xbutton;
+
+ bd->type = ButtonPress;
+ bd->serial = 0;
+ bd->send_event = 0;
+ bd->display = XtDisplay (widget);
+ bd->window = XtWindow (XtParent (widget));
+ bd->time = CurrentTime;
+ bd->button = 0;
+ XQueryPointer (bd->display, bd->window, &bd->root,
+ &bd->subwindow, &bd->x_root, &bd->y_root,
+ &bd->x, &bd->y, &bd->state);
+
+ XtCallActionProc ((Widget) mw, "start", &dummy, NULL, 0);
}
}
/* creation functions */
+/* Called for key press in dialogs. Used to pop down dialog on ESC. */
+static void
+dialog_key_cb (widget, closure, event, continue_to_dispatch)
+ Widget widget;
+ XtPointer closure;
+ XEvent *event;
+ Boolean *continue_to_dispatch;
+{
+ KeySym sym = 0;
+ Modifiers modif_ret;
+
+ XtTranslateKeycode (event->xkey.display, event->xkey.keycode, 0,
+ &modif_ret, &sym);
+
+ if (sym == osfXK_Cancel)
+ {
+ Widget w = *((Widget *) closure);
+
+ while (w && ! XtIsShell (w))
+ w = XtParent (w);
+
+ if (XtIsShell (w)) XtPopdown (w);
+ }
+
+ *continue_to_dispatch = TRUE;
+}
+
/* dialogs */
static Widget
make_dialog (name, parent, pop_up_p, shell_title, icon_name, text_input_slot,
XtSetArg(al[ac], XmNmarginWidth, 10); ac++;
XtSetArg(al[ac], XmNnavigationType, XmTAB_GROUP); ac++;
children [n_children] = XmCreatePushButton (row, button_name, al, ac);
+ XtAddEventHandler (children [n_children],
+ KeyPressMask, False, dialog_key_cb, result);
if (i == 0)
{
XtSetArg(al[ac], XmNmarginWidth, 10); ac++;
XtSetArg(al[ac], XmNnavigationType, XmTAB_GROUP); ac++;
children [n_children] = XmCreatePushButton (row, button_name, al, ac);
+ XtAddEventHandler (children [n_children],
+ KeyPressMask, False, dialog_key_cb, result);
+
if (! button) button = children [n_children];
n_children++;
}
XtAddCallback (widget, XmNpopdownCallback, xm_nosel_callback,
(XtPointer) instance);
+
return widget;
}
static void Key();
static void Nothing();
static int separator_height __P ((enum menu_separator));
+static void pop_up_menu __P ((XlwMenuWidget, XButtonPressedEvent *));
+
static XtActionsRec
xlwMenuActionsList [] =
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_no_call_data)
XlwMenuWidget mw;
widget_value *item;
+ int skip_no_call_data;
{
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_no_call_data && !current->call_data))
if (current->next)
current=current->next;
else
return current;
}
-widget_value *
-find_next_selectable (mw, item)
+static widget_value *
+find_next_selectable (mw, item, skip_no_call_data)
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_no_call_data && !current->call_data)))
;
if (current == item)
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_no_call_data && !current->call_data))
{
if (current->next)
current=current->next;
return current;
}
-widget_value *
-find_prev_selectable (mw, item)
+static widget_value *
+find_prev_selectable (mw, item, skip_no_call_data)
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_no_call_data))
+ != 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 items with zero call data (title 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 items with zero call data (title 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))
- 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);
}
-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