diff options
Diffstat (limited to 'src/FbTk/Menu.cc')
-rw-r--r-- | src/FbTk/Menu.cc | 58 |
1 files changed, 37 insertions, 21 deletions
diff --git a/src/FbTk/Menu.cc b/src/FbTk/Menu.cc index 40f81c8..7128152 100644 --- a/src/FbTk/Menu.cc +++ b/src/FbTk/Menu.cc | |||
@@ -109,7 +109,8 @@ Menu::Menu(FbTk::ThemeProxy<MenuTheme> &tm, ImageControl &imgctrl): | |||
109 | m_alignment(ALIGNDONTCARE), | 109 | m_alignment(ALIGNDONTCARE), |
110 | m_active_index(-1), | 110 | m_active_index(-1), |
111 | m_shape(0), | 111 | m_shape(0), |
112 | m_need_update(true) { | 112 | m_need_update(true), |
113 | m_single_trigger(false) { | ||
113 | // setup timers | 114 | // setup timers |
114 | 115 | ||
115 | RefCount<Command<void> > show_cmd(new SimpleCommand<Menu>(*this, &Menu::openSubmenu)); | 116 | RefCount<Command<void> > show_cmd(new SimpleCommand<Menu>(*this, &Menu::openSubmenu)); |
@@ -861,6 +862,10 @@ bool Menu::isItemSelectable(unsigned int index) const { | |||
861 | return (!item || !item->isEnabled()) ? false : true; | 862 | return (!item || !item->isEnabled()) ? false : true; |
862 | } | 863 | } |
863 | 864 | ||
865 | bool Menu::isSingleTrigger() const { | ||
866 | |||
867 | return m_single_trigger || (parent() && parent()->isSingleTrigger()); | ||
868 | } | ||
864 | 869 | ||
865 | void Menu::handleEvent(XEvent &event) { | 870 | void Menu::handleEvent(XEvent &event) { |
866 | if (event.type == FocusOut) { | 871 | if (event.type == FocusOut) { |
@@ -1123,19 +1128,7 @@ void Menu::keyPressEvent(XKeyEvent &event) { | |||
1123 | break; | 1128 | break; |
1124 | case XK_KP_Enter: | 1129 | case XK_KP_Enter: |
1125 | case XK_Return: | 1130 | case XK_Return: |
1126 | resetTypeAhead(); | 1131 | goto click_on_item; |
1127 | if (validIndex(m_active_index) && | ||
1128 | isItemEnabled(m_active_index)) { | ||
1129 | // send fake button click | ||
1130 | int button = (event.state & ShiftMask) ? 3 : 1; | ||
1131 | if (menuitems[m_active_index]->submenu() != 0 && button == 1) | ||
1132 | enterSubmenu(); | ||
1133 | else { | ||
1134 | find(m_active_index)->click(button, event.time, event.state); | ||
1135 | m_need_update = true; | ||
1136 | updateMenu(); | ||
1137 | } | ||
1138 | } | ||
1139 | break; | 1132 | break; |
1140 | case XK_Tab: | 1133 | case XK_Tab: |
1141 | case XK_ISO_Left_Tab: | 1134 | case XK_ISO_Left_Tab: |
@@ -1150,15 +1143,38 @@ void Menu::keyPressEvent(XKeyEvent &event) { | |||
1150 | drawTypeAheadItems(); | 1143 | drawTypeAheadItems(); |
1151 | break; | 1144 | break; |
1152 | default: | 1145 | default: |
1153 | m_type_ahead.putCharacter(keychar[0]); | 1146 | { |
1154 | // if current item doesn't match new search string, find the next one | 1147 | m_type_ahead.putCharacter(keychar[0]); |
1155 | drawTypeAheadItems(); | 1148 | drawTypeAheadItems(); |
1156 | if (!m_matches.empty() && (!validIndex(m_active_index) || | 1149 | // if current item doesn't match new search string, find the next one |
1157 | std::find(m_matches.begin(), m_matches.end(), | 1150 | if (!m_matches.empty() && (!validIndex(m_active_index) || |
1158 | find(m_active_index)) == m_matches.end())) | 1151 | std::find(m_matches.begin(), m_matches.end(), |
1159 | cycleItems(false); | 1152 | find(m_active_index)) == m_matches.end())) |
1153 | cycleItems(false); | ||
1154 | |||
1155 | if (isSingleTrigger() && m_matches.size() == 1) { | ||
1156 | goto click_on_item; | ||
1157 | } | ||
1158 | } | ||
1160 | break; | 1159 | break; |
1161 | } | 1160 | } |
1161 | return; | ||
1162 | |||
1163 | // TODO: 'goto' is just the temporary solution to this code sharing | ||
1164 | click_on_item: | ||
1165 | resetTypeAhead(); | ||
1166 | if (validIndex(m_active_index) && | ||
1167 | isItemEnabled(m_active_index)) { | ||
1168 | // send fake button click | ||
1169 | int button = (event.state & ShiftMask) ? 3 : 1; | ||
1170 | if (menuitems[m_active_index]->submenu() != 0 && button == 1) | ||
1171 | enterSubmenu(); | ||
1172 | else { | ||
1173 | find(m_active_index)->click(button, event.time, event.state); | ||
1174 | m_need_update = true; | ||
1175 | updateMenu(); | ||
1176 | } | ||
1177 | } | ||
1162 | } | 1178 | } |
1163 | 1179 | ||
1164 | void Menu::leaveNotifyEvent(XCrossingEvent &ce) { | 1180 | void Menu::leaveNotifyEvent(XCrossingEvent &ce) { |