aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Janík2002-04-20 13:39:57 +0000
committerPavel Janík2002-04-20 13:39:57 +0000
commit1b8d91abb3b7e4b2c4128bbc11cde1af4f3d4de9 (patch)
tree8f388301a8825b82786835b584e7563348ea1633
parent436fa78bc1cb8b588a1ce14e3abfd91fb916b467 (diff)
downloademacs-1b8d91abb3b7e4b2c4128bbc11cde1af4f3d4de9.tar.gz
emacs-1b8d91abb3b7e4b2c4128bbc11cde1af4f3d4de9.zip
(find_next_selectable): New function.
(Down, Up, Right): Use it. (find_next_selectable): Prevent endless loops when only one item is enabled in the menu.
-rw-r--r--lwlib/xlwmenu.c51
1 files changed, 43 insertions, 8 deletions
diff --git a/lwlib/xlwmenu.c b/lwlib/xlwmenu.c
index 2d879722823..c63422bacc6 100644
--- a/lwlib/xlwmenu.c
+++ b/lwlib/xlwmenu.c
@@ -129,6 +129,7 @@ xlwMenuTranslations [] =
129 129
130/* FIXME: Should ESC close one level of menu structure or the complete menu? */ 130/* FIXME: Should ESC close one level of menu structure or the complete menu? */
131 131
132/* FIXME: Should F10 enter to menu? Which one? File? */
132 133
133#define offset(field) XtOffset(XlwMenuWidget, field) 134#define offset(field) XtOffset(XlwMenuWidget, field)
134static XtResource 135static XtResource
@@ -2005,6 +2006,23 @@ Nothing (w, ev, params, num_params)
2005} 2006}
2006 2007
2007widget_value * 2008widget_value *
2009find_first_selectable (mw, item)
2010 XlwMenuWidget mw;
2011 widget_value *item;
2012{
2013 widget_value *current = item;
2014 enum menu_separator separator;
2015
2016 while (lw_separator_p (current->name, &separator, 0) || !current->enabled)
2017 if (current->next)
2018 current=current->next;
2019 else
2020 return NULL;
2021
2022 return current;
2023}
2024
2025widget_value *
2008find_next_selectable (mw, item) 2026find_next_selectable (mw, item)
2009 XlwMenuWidget mw; 2027 XlwMenuWidget mw;
2010 widget_value *item; 2028 widget_value *item;
@@ -2021,8 +2039,14 @@ find_next_selectable (mw, item)
2021 current = mw->menu.old_stack [mw->menu.old_depth - 2]->contents; 2039 current = mw->menu.old_stack [mw->menu.old_depth - 2]->contents;
2022 2040
2023 while (lw_separator_p (current->name, &separator, 0) || !current->enabled) 2041 while (lw_separator_p (current->name, &separator, 0) || !current->enabled)
2024 if (current->next) 2042 {
2025 current=current->next; 2043 if (current->next)
2044 current=current->next;
2045
2046 if (current == item)
2047 break;
2048 }
2049
2026 } 2050 }
2027 2051
2028 return current; 2052 return current;
@@ -2037,7 +2061,11 @@ find_prev_selectable (mw, item)
2037 widget_value *prev = item; 2061 widget_value *prev = item;
2038 2062
2039 while ((current=find_next_selectable (mw, current)) != item) 2063 while ((current=find_next_selectable (mw, current)) != item)
2064 {
2065 if (prev == current)
2066 break;
2040 prev=current; 2067 prev=current;
2068 }
2041 2069
2042 return prev; 2070 return prev;
2043} 2071}
@@ -2055,8 +2083,8 @@ Down (w, ev, params, num_params)
2055 /* Inside top-level menu-bar? */ 2083 /* Inside top-level menu-bar? */
2056 if (mw->menu.old_depth == 2) 2084 if (mw->menu.old_depth == 2)
2057 /* When <down> in the menu-bar is pressed, display the corresponding 2085 /* When <down> in the menu-bar is pressed, display the corresponding
2058 sub-menu and select the first menu item there. */ 2086 sub-menu and select the first selectable menu item there. */
2059 set_new_state (mw, selected_item->contents, mw->menu.old_depth); 2087 set_new_state (mw, find_first_selectable (mw, selected_item->contents), mw->menu.old_depth);
2060 else 2088 else
2061 /* Highlight next possible (enabled and not separator) menu item. */ 2089 /* Highlight next possible (enabled and not separator) menu item. */
2062 set_new_state (mw, find_next_selectable (mw, selected_item), mw->menu.old_depth - 1); 2090 set_new_state (mw, find_next_selectable (mw, selected_item), mw->menu.old_depth - 1);
@@ -2078,9 +2106,10 @@ Up (w, ev, params, num_params)
2078 if (mw->menu.old_depth == 2) 2106 if (mw->menu.old_depth == 2)
2079 { 2107 {
2080 /* FIXME: this is tricky. <up> in the menu-bar should select the 2108 /* FIXME: this is tricky. <up> in the menu-bar should select the
2081 last selectable item in the list. So we select the first one and 2109 last selectable item in the list. So we select the first
2082 find the previous selectable item. Is there a better way? */ 2110 selectable one and find the previous selectable item. Is there
2083 set_new_state (mw, selected_item->contents, mw->menu.old_depth); 2111 a better way? */
2112 set_new_state (mw, find_first_selectable (mw, selected_item->contents), mw->menu.old_depth);
2084 remap_menubar (mw); 2113 remap_menubar (mw);
2085 selected_item = mw->menu.old_stack [mw->menu.old_depth - 1]; 2114 selected_item = mw->menu.old_stack [mw->menu.old_depth - 1];
2086 set_new_state (mw, find_prev_selectable (mw, selected_item), mw->menu.old_depth - 1); 2115 set_new_state (mw, find_prev_selectable (mw, selected_item), mw->menu.old_depth - 1);
@@ -2134,7 +2163,13 @@ Right (w, ev, params, num_params)
2134 first item (probably File). */ 2163 first item (probably File). */
2135 set_new_state (mw, find_next_selectable (mw, selected_item), mw->menu.old_depth - 1); 2164 set_new_state (mw, find_next_selectable (mw, selected_item), mw->menu.old_depth - 1);
2136 else if (selected_item->contents) /* Is this menu item expandable? */ 2165 else if (selected_item->contents) /* Is this menu item expandable? */
2137 set_new_state (mw, selected_item->contents, mw->menu.old_depth); 2166 {
2167 set_new_state (mw, selected_item->contents, mw->menu.old_depth);
2168 remap_menubar (mw);
2169 selected_item = mw->menu.old_stack [mw->menu.old_depth - 1];
2170 if (!selected_item->enabled && find_first_selectable (mw, selected_item))
2171 set_new_state (mw, find_first_selectable (mw, selected_item), mw->menu.old_depth - 1);
2172 }
2138 else 2173 else
2139 { 2174 {
2140 pop_new_stack_if_no_contents (mw); 2175 pop_new_stack_if_no_contents (mw);