Changeset 46bd63c9 in mainline for uspace/lib/ui/src/menubar.c
- Timestamp:
- 2023-09-08T08:47:30Z (13 months ago)
- Branches:
- master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 1af103e
- Parents:
- 0b6fad9
- git-author:
- Jiri Svoboda <jiri@…> (2023-09-07 18:47:09)
- git-committer:
- Jiri Svoboda <jiri@…> (2023-09-08 08:47:30)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/src/menubar.c
r0b6fad9 r46bd63c9 45 45 #include <ui/control.h> 46 46 #include <ui/paint.h> 47 #include <ui/menu.h>48 47 #include <ui/menubar.h> 48 #include <ui/menudd.h> 49 49 #include <ui/window.h> 50 50 #include "../private/menubar.h" … … 95 95 mbar->ui = ui; 96 96 mbar->window = window; 97 list_initialize(&mbar->menu s);97 list_initialize(&mbar->menudds); 98 98 *rmbar = mbar; 99 99 return EOK; … … 106 106 void ui_menu_bar_destroy(ui_menu_bar_t *mbar) 107 107 { 108 ui_menu_ t *menu;108 ui_menu_dd_t *mdd; 109 109 110 110 if (mbar == NULL) 111 111 return; 112 112 113 /* Destroy menu s */114 m enu = ui_menu_first(mbar);115 while (m enu!= NULL) {116 ui_menu_d estroy(menu);117 m enu = ui_menu_first(mbar);113 /* Destroy menu drop-downs */ 114 mdd = ui_menu_dd_first(mbar); 115 while (mdd != NULL) { 116 ui_menu_dd_destroy(mdd); 117 mdd = ui_menu_dd_first(mbar); 118 118 } 119 119 … … 155 155 gfx_rect_t rect; 156 156 gfx_color_t *bg_color; 157 ui_menu_ t *menu;157 ui_menu_dd_t *mdd; 158 158 const char *caption; 159 159 gfx_coord_t width; … … 189 189 fmt.valign = gfx_valign_top; 190 190 191 m enu = ui_menu_first(mbar);192 while (m enu!= NULL) {193 caption = ui_menu_ caption(menu);191 mdd = ui_menu_dd_first(mbar); 192 while (mdd != NULL) { 193 caption = ui_menu_dd_caption(mdd); 194 194 width = ui_text_width(res->font, caption) + 2 * hpad; 195 195 tpos.x = pos.x + hpad; … … 200 200 rect.p1.y = mbar->rect.p1.y; 201 201 202 if (m enu== mbar->selected) {202 if (mdd == mbar->selected) { 203 203 fmt.color = res->wnd_sel_text_color; 204 204 fmt.hgl_color = res->wnd_sel_text_hgl_color; … … 223 223 224 224 pos.x += width; 225 m enu = ui_menu_next(menu);225 mdd = ui_menu_dd_next(mdd); 226 226 } 227 227 … … 241 241 * 242 242 * @param mbar Menu bar 243 * @param m enu Menuto select (or deselect if selected) or @c NULL243 * @param mdd Menu drop-down to select (or deselect if selected) or @c NULL 244 244 * @param openup Open menu even if not currently open 245 245 * @param idev_id Input device ID associated with the selecting seat 246 246 */ 247 void ui_menu_bar_select(ui_menu_bar_t *mbar, ui_menu_ t *menu, bool openup,247 void ui_menu_bar_select(ui_menu_bar_t *mbar, ui_menu_dd_t *mdd, bool openup, 248 248 sysarg_t idev_id) 249 249 { 250 ui_menu_ t *old_menu;250 ui_menu_dd_t *old_mdd; 251 251 gfx_rect_t rect; 252 252 bool was_open; 253 253 254 old_m enu= mbar->selected;255 256 mbar->selected = m enu;257 258 /* Close previously open menu */259 if (old_m enu != NULL && ui_menu_is_open(old_menu)) {254 old_mdd = mbar->selected; 255 256 mbar->selected = mdd; 257 258 /* Close previously open menu drop-down */ 259 if (old_mdd != NULL && ui_menu_dd_is_open(old_mdd)) { 260 260 was_open = true; 261 (void) ui_menu_ close(old_menu);261 (void) ui_menu_dd_close(old_mdd); 262 262 } else { 263 263 was_open = false; … … 270 270 if (openup || was_open) { 271 271 /* 272 * Open the newly selected menu if either273 * the old menu was open or @a openup was272 * Open the newly selected menu drop-down if either 273 * the old menu drop-down was open or @a openup was 274 274 * specified. 275 275 */ 276 (void) ui_menu_ open(mbar->selected, &rect, idev_id);276 (void) ui_menu_dd_open(mbar->selected, &rect, idev_id); 277 277 } 278 278 } … … 289 289 void ui_menu_bar_left(ui_menu_bar_t *mbar, sysarg_t idev_id) 290 290 { 291 ui_menu_ t *nmenu;291 ui_menu_dd_t *nmdd; 292 292 293 293 if (mbar->selected == NULL) 294 294 return; 295 295 296 nm enu = ui_menu_prev(mbar->selected);297 if (nm enu== NULL)298 nm enu = ui_menu_last(mbar);299 300 if (nm enu!= mbar->selected)301 ui_menu_bar_select(mbar, nm enu, false, idev_id);296 nmdd = ui_menu_dd_prev(mbar->selected); 297 if (nmdd == NULL) 298 nmdd = ui_menu_dd_last(mbar); 299 300 if (nmdd != mbar->selected) 301 ui_menu_bar_select(mbar, nmdd, false, idev_id); 302 302 } 303 303 … … 312 312 void ui_menu_bar_right(ui_menu_bar_t *mbar, sysarg_t idev_id) 313 313 { 314 ui_menu_ t *nmenu;314 ui_menu_dd_t *nmdd; 315 315 316 316 if (mbar->selected == NULL) 317 317 return; 318 318 319 nm enu = ui_menu_next(mbar->selected);320 if (nm enu== NULL)321 nm enu = ui_menu_first(mbar);322 323 if (nm enu!= mbar->selected)324 ui_menu_bar_select(mbar, nm enu, false, idev_id);319 nmdd = ui_menu_dd_next(mbar->selected); 320 if (nmdd == NULL) 321 nmdd = ui_menu_dd_first(mbar); 322 323 if (nmdd != mbar->selected) 324 ui_menu_bar_select(mbar, nmdd, false, idev_id); 325 325 } 326 326 … … 355 355 356 356 if (event->key == KC_ENTER || event->key == KC_DOWN) { 357 if (mbar->selected != NULL && !ui_menu_is_open(mbar->selected)) { 357 if (mbar->selected != NULL && 358 !ui_menu_dd_is_open(mbar->selected)) { 358 359 ui_menu_bar_entry_rect(mbar, mbar->selected, 359 360 &rect); 360 ui_menu_ open(mbar->selected, &rect, event->kbd_id);361 ui_menu_dd_open(mbar->selected, &rect, event->kbd_id); 361 362 } 362 363 … … 364 365 } 365 366 366 if (event->c != '\0' && !ui_menu_ is_open(mbar->selected)) {367 if (event->c != '\0' && !ui_menu_dd_is_open(mbar->selected)) { 367 368 /* Check if it is an accelerator. */ 368 369 ui_menu_bar_press_accel(mbar, event->c, event->kbd_id); … … 407 408 void ui_menu_bar_press_accel(ui_menu_bar_t *mbar, char32_t c, sysarg_t kbd_id) 408 409 { 409 ui_menu_ t *menu;410 ui_menu_dd_t *mdd; 410 411 char32_t maccel; 411 412 412 m enu = ui_menu_first(mbar);413 while (m enu!= NULL) {414 maccel = ui_menu_ get_accel(menu);413 mdd = ui_menu_dd_first(mbar); 414 while (mdd != NULL) { 415 maccel = ui_menu_dd_get_accel(mdd); 415 416 if (c == maccel) { 416 ui_menu_bar_select(mbar, m enu, true, kbd_id);417 ui_menu_bar_select(mbar, mdd, true, kbd_id); 417 418 return; 418 419 } 419 420 420 m enu = ui_menu_next(menu);421 mdd = ui_menu_dd_next(mdd); 421 422 } 422 423 } … … 433 434 gfx_coord2_t pos; 434 435 gfx_rect_t rect; 435 ui_menu_ t *menu;436 ui_menu_dd_t *mdd; 436 437 const char *caption; 437 438 gfx_coord_t width; … … 454 455 pos_id = event->pos_id; 455 456 456 m enu = ui_menu_first(mbar);457 while (m enu!= NULL) {458 caption = ui_menu_ caption(menu);457 mdd = ui_menu_dd_first(mbar); 458 while (mdd != NULL) { 459 caption = ui_menu_dd_caption(mdd); 459 460 width = ui_text_width(res->font, caption) + 2 * hpad; 460 461 … … 469 470 470 471 /* Open the menu, close if already open. */ 471 if (m enu== mbar->selected)472 if (mdd == mbar->selected) 472 473 ui_menu_bar_select(mbar, NULL, false, pos_id); 473 474 else 474 ui_menu_bar_select(mbar, m enu, true, pos_id);475 ui_menu_bar_select(mbar, mdd, true, pos_id); 475 476 476 477 return ui_claimed; … … 478 479 479 480 pos.x += width; 480 m enu = ui_menu_next(menu);481 mdd = ui_menu_dd_next(mdd); 481 482 } 482 483 … … 487 488 * 488 489 * @param mbar Menu bar 489 * @param m enu Menuwhose entry's rectangle is to be returned490 * @param mdd Menu drop-down whose entry's rectangle is to be returned 490 491 * @param rrect Place to store entry rectangle 491 492 */ 492 void ui_menu_bar_entry_rect(ui_menu_bar_t *mbar, ui_menu_ t *menu,493 void ui_menu_bar_entry_rect(ui_menu_bar_t *mbar, ui_menu_dd_t *mdd, 493 494 gfx_rect_t *rrect) 494 495 { … … 496 497 gfx_coord2_t pos; 497 498 gfx_rect_t rect; 498 ui_menu_ t *cur;499 ui_menu_dd_t *cur; 499 500 const char *caption; 500 501 gfx_coord_t width; … … 511 512 pos = mbar->rect.p0; 512 513 513 cur = ui_menu_ first(mbar);514 cur = ui_menu_dd_first(mbar); 514 515 while (cur != NULL) { 515 caption = ui_menu_ caption(cur);516 caption = ui_menu_dd_caption(cur); 516 517 width = ui_text_width(res->font, caption) + 2 * hpad; 517 518 … … 520 521 rect.p1.y = mbar->rect.p1.y; 521 522 522 if (cur == m enu) {523 if (cur == mdd) { 523 524 *rrect = rect; 524 525 return; … … 526 527 527 528 pos.x += width; 528 cur = ui_menu_ next(cur);529 cur = ui_menu_dd_next(cur); 529 530 } 530 531 … … 544 545 mbar->active = true; 545 546 if (mbar->selected == NULL) 546 mbar->selected = ui_menu_ first(mbar);547 mbar->selected = ui_menu_dd_first(mbar); 547 548 548 549 (void) ui_menu_bar_paint(mbar);
Note:
See TracChangeset
for help on using the changeset viewer.