Changeset b3b48f4 in mainline
- Timestamp:
- 2022-03-11T17:28:10Z (3 years ago)
- Branches:
- master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- bd16113
- Parents:
- b987eb4
- Location:
- uspace/lib/ui
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/include/ui/menubar.h
rb987eb4 rb3b48f4 46 46 #include <types/ui/ui.h> 47 47 #include <types/ui/window.h> 48 #include <uchar.h> 48 49 49 50 extern errno_t ui_menu_bar_create(ui_t *, ui_window_t *, … … 55 56 extern ui_evclaim_t ui_menu_bar_kbd_event(ui_menu_bar_t *, kbd_event_t *); 56 57 extern ui_evclaim_t ui_menu_bar_pos_event(ui_menu_bar_t *, pos_event_t *); 58 extern void ui_menu_bar_press_accel(ui_menu_bar_t *, char32_t); 57 59 extern void ui_menu_bar_unfocus(ui_menu_bar_t *); 58 60 extern void ui_menu_bar_activate(ui_menu_bar_t *); -
uspace/lib/ui/src/menu.c
rb987eb4 rb3b48f4 519 519 ui_menu_key_press_unmod(menu, event); 520 520 } 521 522 if (event->type == KEY_PRESS && (event->mods & KM_ALT) != 0 && 523 (event->mods & (KM_CTRL | KM_SHIFT)) == 0 && event->c != '\0') 524 ui_menu_bar_press_accel(menu->mbar, event->c); 521 525 522 526 return ui_claimed; -
uspace/lib/ui/src/menubar.c
rb987eb4 rb3b48f4 330 330 { 331 331 gfx_rect_t rect; 332 ui_menu_t *menu;333 char32_t maccel;334 332 335 333 if (event->key == KC_F10) { … … 364 362 if (event->c != '\0' && !ui_menu_is_open(mbar->selected)) { 365 363 /* Check if it is an accelerator. */ 366 367 menu = ui_menu_first(mbar); 368 while (menu != NULL) { 369 maccel = ui_menu_get_accel(menu); 370 if (event->c == maccel) { 371 ui_menu_bar_select(mbar, menu, true); 372 return ui_claimed; 373 } 374 375 menu = ui_menu_next(menu); 376 } 364 ui_menu_bar_press_accel(mbar, event->c); 377 365 } 378 366 … … 388 376 ui_evclaim_t ui_menu_bar_kbd_event(ui_menu_bar_t *mbar, kbd_event_t *event) 389 377 { 378 if ((event->mods & KM_ALT) != 0 && 379 (event->mods & (KM_CTRL | KM_SHIFT)) == 0 && event->c != '\0') { 380 /* Check if it is an accelerator. */ 381 ui_menu_bar_press_accel(mbar, event->c); 382 } 383 390 384 if (event->type == KEY_PRESS && (event->mods & 391 385 (KM_CTRL | KM_ALT | KM_SHIFT)) == 0) { … … 397 391 398 392 return ui_unclaimed; 393 } 394 395 /** Accelerator key press. 396 * 397 * If @a c matches an accelerator key, open the respective menu. 398 * 399 * @param mbar Menu bar 400 * @param c Character 401 */ 402 void ui_menu_bar_press_accel(ui_menu_bar_t *mbar, char32_t c) 403 { 404 ui_menu_t *menu; 405 char32_t maccel; 406 407 menu = ui_menu_first(mbar); 408 while (menu != NULL) { 409 maccel = ui_menu_get_accel(menu); 410 if (c == maccel) { 411 ui_menu_bar_select(mbar, menu, true); 412 return; 413 } 414 415 menu = ui_menu_next(menu); 416 } 399 417 } 400 418 -
uspace/lib/ui/test/menubar.c
rb987eb4 rb3b48f4 198 198 } 199 199 200 /** Press event on menu bar entry selectsmenu */201 PCUT_TEST(p os_event_select)200 /** ui_menu_bar_press_accel() opens the corresponding menu */ 201 PCUT_TEST(press_accel) 202 202 { 203 203 ui_t *ui = NULL; … … 206 206 ui_menu_bar_t *mbar = NULL; 207 207 ui_menu_t *menu = NULL; 208 ui_evclaim_t claimed;209 pos_event_t event;210 208 gfx_rect_t rect; 211 209 errno_t rc; … … 231 229 ui_menu_bar_set_rect(mbar, &rect); 232 230 231 rc = ui_menu_create(mbar, "~T~est", &menu); 232 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 233 PCUT_ASSERT_NOT_NULL(menu); 234 235 PCUT_ASSERT_FALSE(ui_menu_is_open(menu)); 236 237 ui_menu_bar_press_accel(mbar, 't'); 238 239 PCUT_ASSERT_TRUE(ui_menu_is_open(menu)); 240 241 ui_menu_bar_destroy(mbar); 242 ui_window_destroy(window); 243 ui_destroy(ui); 244 } 245 246 /** Press event on menu bar entry selects menu */ 247 PCUT_TEST(pos_event_select) 248 { 249 ui_t *ui = NULL; 250 ui_window_t *window = NULL; 251 ui_wnd_params_t params; 252 ui_menu_bar_t *mbar = NULL; 253 ui_menu_t *menu = NULL; 254 ui_evclaim_t claimed; 255 pos_event_t event; 256 gfx_rect_t rect; 257 errno_t rc; 258 259 rc = ui_create_disp(NULL, &ui); 260 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 261 262 ui_wnd_params_init(¶ms); 263 params.caption = "Hello"; 264 265 rc = ui_window_create(ui, ¶ms, &window); 266 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 267 PCUT_ASSERT_NOT_NULL(window); 268 269 rc = ui_menu_bar_create(ui, window, &mbar); 270 PCUT_ASSERT_ERRNO_VAL(EOK, rc); 271 PCUT_ASSERT_NOT_NULL(mbar); 272 273 rect.p0.x = 0; 274 rect.p0.y = 0; 275 rect.p1.x = 50; 276 rect.p1.y = 25; 277 ui_menu_bar_set_rect(mbar, &rect); 278 233 279 rc = ui_menu_create(mbar, "Test", &menu); 234 280 PCUT_ASSERT_ERRNO_VAL(EOK, rc);
Note:
See TracChangeset
for help on using the changeset viewer.