Changes in uspace/lib/ui/src/menuentry.c [c68c18b9:ee3b28a9] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/src/menuentry.c
rc68c18b9 ree3b28a9 1 1 /* 2 * Copyright (c) 202 1Jiri Svoboda2 * Copyright (c) 2024 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 43 43 #include <stdlib.h> 44 44 #include <str.h> 45 #include <ui/accel.h> 45 46 #include <ui/control.h> 46 47 #include <ui/paint.h> 48 #include <ui/menubar.h> 47 49 #include <ui/menuentry.h> 48 50 #include <ui/window.h> … … 143 145 return; 144 146 147 mentry->menu->total_h -= ui_menu_entry_height(mentry); 148 /* NOTE: max_caption_w/max_shortcut_w not updated (speed) */ 149 145 150 list_remove(&mentry->lentries); 151 152 /* 153 * If we emptied the menu, reset accumulated dims so they 154 * can be correctly calculated when (if) the menu is 155 * re-populated. 156 */ 157 if (list_empty(&mentry->menu->entries)) { 158 mentry->menu->total_h = 0; 159 mentry->menu->max_caption_w = 0; 160 mentry->menu->max_shortcut_w = 0; 161 } 162 146 163 free(mentry->caption); 147 164 free(mentry); … … 159 176 mentry->cb = cb; 160 177 mentry->arg = arg; 178 } 179 180 /** Set menu entry disabled flag. 181 * 182 * @param mentry Menu entry 183 * @param disabled @c true iff entry is to be disabled, @c false otherwise 184 */ 185 void ui_menu_entry_set_disabled(ui_menu_entry_t *mentry, bool disabled) 186 { 187 mentry->disabled = disabled; 188 } 189 190 /** Get menu entry disabled flag. 191 * 192 * @param mentry Menu entry 193 * @return disabled @c true iff entry is disabled, @c false otherwise 194 */ 195 bool ui_menu_entry_is_disabled(ui_menu_entry_t *mentry) 196 { 197 return mentry->disabled; 161 198 } 162 199 … … 177 214 } 178 215 216 /** Get last menu entry in menu. 217 * 218 * @param menu Menu 219 * @return Last menu entry or @c NULL if there is none 220 */ 221 ui_menu_entry_t *ui_menu_entry_last(ui_menu_t *menu) 222 { 223 link_t *link; 224 225 link = list_last(&menu->entries); 226 if (link == NULL) 227 return NULL; 228 229 return list_get_instance(link, ui_menu_entry_t, lentries); 230 } 231 179 232 /** Get next menu entry in menu. 180 233 * … … 193 246 } 194 247 248 /** Get previous menu entry in menu. 249 * 250 * @param cur Current menu entry 251 * @return Next menu entry or @c NULL if @a cur is the last one 252 */ 253 ui_menu_entry_t *ui_menu_entry_prev(ui_menu_entry_t *cur) 254 { 255 link_t *link; 256 257 link = list_prev(&cur->lentries, &cur->menu->entries); 258 if (link == NULL) 259 return NULL; 260 261 return list_get_instance(link, ui_menu_entry_t, lentries); 262 } 263 195 264 /** Get width of menu entry. 196 265 * … … 207 276 * This needs to work even if the menu is not open, so we cannot 208 277 * use the menu's resource, which is only created after the menu 209 * is open (and its window is created). Use the menu bar's278 * is open (and its window is created). Use the parent window's 210 279 * resource instead. 211 280 */ 212 res = ui_window_get_res(mentry->menu-> mbar->window);213 214 *caption_w = gfx_text_width(res->font, mentry->caption);215 *shortcut_w = gfx_text_width(res->font, mentry->shortcut);281 res = ui_window_get_res(mentry->menu->parent); 282 283 *caption_w = ui_text_width(res->font, mentry->caption); 284 *shortcut_w = ui_text_width(res->font, mentry->shortcut); 216 285 } 217 286 … … 233 302 * This needs to work even if the menu is not open, so we cannot 234 303 * use the menu's resource, which is only created after the menu 235 * is open (and its window is created). Use the menu bar's304 * is open (and its window is created). Use the parent window's 236 305 * resource instead. 237 306 */ 238 res = ui_window_get_res(menu-> mbar->window);307 res = ui_window_get_res(menu->parent); 239 308 240 309 if (res->textmode) … … 272 341 * This needs to work even if the menu is not open, so we cannot 273 342 * use the menu's resource, which is only created after the menu 274 * is open (and its window is created). Use the menu bar's343 * is open (and its window is created). Use the parent window's 275 344 * resource instead. 276 345 */ 277 res = ui_window_get_res(mentry->menu-> mbar->window);346 res = ui_window_get_res(mentry->menu->parent); 278 347 279 348 if (res->textmode) { … … 298 367 } 299 368 369 /** Get menu entry accelerator character. 370 * 371 * @param mentry Menu entry 372 * @return Accelerator character (lowercase) or the null character if 373 * the menu entry has no accelerator. 374 */ 375 char32_t ui_menu_entry_get_accel(ui_menu_entry_t *mentry) 376 { 377 return ui_accel_get(mentry->caption); 378 } 379 300 380 /** Paint menu entry. 301 381 * … … 307 387 { 308 388 ui_resource_t *res; 309 gfx_text_fmt_t fmt;389 ui_text_fmt_t fmt; 310 390 gfx_color_t *bg_color; 311 391 ui_menu_entry_geom_t geom; … … 317 397 ui_menu_entry_get_geom(mentry, pos, &geom); 318 398 319 gfx_text_fmt_init(&fmt); 399 ui_text_fmt_init(&fmt); 400 fmt.font = res->font; 320 401 fmt.halign = gfx_halign_left; 321 402 fmt.valign = gfx_valign_top; … … 324 405 mentry == mentry->menu->selected) { 325 406 fmt.color = res->wnd_sel_text_color; 407 fmt.hgl_color = res->wnd_sel_text_hgl_color; 326 408 bg_color = res->wnd_sel_text_bg_color; 409 } else if (mentry->disabled) { 410 fmt.color = res->wnd_dis_text_color; 411 fmt.hgl_color = res->wnd_dis_text_color; 412 bg_color = res->wnd_face_color; 327 413 } else { 328 414 fmt.color = res->wnd_text_color; 415 fmt.hgl_color = res->wnd_text_hgl_color; 329 416 bg_color = res->wnd_face_color; 330 417 } … … 338 425 goto error; 339 426 340 rc = gfx_puttext(res->font,&geom.caption_pos, &fmt, mentry->caption);427 rc = ui_paint_text(&geom.caption_pos, &fmt, mentry->caption); 341 428 if (rc != EOK) 342 429 goto error; … … 344 431 fmt.halign = gfx_halign_right; 345 432 346 rc = gfx_puttext(res->font,&geom.shortcut_pos, &fmt, mentry->shortcut);433 rc = ui_paint_text(&geom.shortcut_pos, &fmt, mentry->shortcut); 347 434 if (rc != EOK) 348 435 goto error; 349 436 350 437 if (mentry->separator) { 351 rect.p0 = geom.caption_pos; 352 rect.p1.x = geom.shortcut_pos.x; 353 rect.p1.y = rect.p0.y + 2; 354 rc = ui_paint_bevel(res->gc, &rect, res->wnd_shadow_color, 355 res->wnd_highlight_color, 1, NULL); 356 if (rc != EOK) 357 goto error; 438 if (res->textmode) { 439 rect = geom.outer_rect; 440 rect.p0.x -= 1; 441 rect.p1.x += 1; 442 443 rc = ui_paint_text_hbrace(res, &rect, ui_box_single, 444 res->wnd_face_color); 445 if (rc != EOK) 446 goto error; 447 } else { 448 rect.p0 = geom.caption_pos; 449 rect.p1.x = geom.shortcut_pos.x; 450 rect.p1.y = rect.p0.y + 2; 451 rc = ui_paint_bevel(res->gc, &rect, res->wnd_shadow_color, 452 res->wnd_highlight_color, 1, NULL); 453 if (rc != EOK) 454 goto error; 455 } 358 456 } 359 457 … … 367 465 } 368 466 467 /** Determine if entry is selectable. 468 * 469 * @return @c true iff entry is selectable 470 */ 471 bool ui_menu_entry_selectable(ui_menu_entry_t *mentry) 472 { 473 return !mentry->separator; 474 } 475 369 476 /** Handle button press in menu entry. 370 477 * … … 377 484 return; 378 485 379 if (mentry->separator )486 if (mentry->separator || mentry->disabled) 380 487 return; 381 488 … … 396 503 mentry->held = false; 397 504 398 if (mentry->inside) { 399 /* Close menu */ 400 ui_menu_bar_select(mentry->menu->mbar, NULL, NULL); 401 402 /* Call back */ 403 ui_menu_entry_cb(mentry); 404 } 505 if (mentry->inside) 506 ui_menu_entry_activate(mentry); 507 } 508 509 /** Activate menu entry. 510 * 511 * @param mentry Menu entry 512 */ 513 void ui_menu_entry_activate(ui_menu_entry_t *mentry) 514 { 515 /* Close menu */ 516 ui_menu_close_req(mentry->menu); 517 518 /* Call back */ 519 ui_menu_entry_cb(mentry); 405 520 } 406 521 … … 486 601 } 487 602 break; 603 case POS_DCLICK: 604 break; 488 605 } 489 606
Note:
See TracChangeset
for help on using the changeset viewer.