Changes in uspace/lib/ui/src/menuentry.c [ee3b28a9:81ec7e1] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/ui/src/menuentry.c
ree3b28a9 r81ec7e1 1 1 /* 2 * Copyright (c) 202 4Jiri Svoboda2 * Copyright (c) 2021 Jiri Svoboda 3 3 * All rights reserved. 4 4 * … … 43 43 #include <stdlib.h> 44 44 #include <str.h> 45 #include <ui/accel.h>46 45 #include <ui/control.h> 47 46 #include <ui/paint.h> 48 #include <ui/menubar.h>49 47 #include <ui/menuentry.h> 50 48 #include <ui/window.h> … … 145 143 return; 146 144 147 mentry->menu->total_h -= ui_menu_entry_height(mentry);148 /* NOTE: max_caption_w/max_shortcut_w not updated (speed) */149 150 145 list_remove(&mentry->lentries); 151 152 /*153 * If we emptied the menu, reset accumulated dims so they154 * can be correctly calculated when (if) the menu is155 * 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 163 146 free(mentry->caption); 164 147 free(mentry); … … 176 159 mentry->cb = cb; 177 160 mentry->arg = arg; 178 }179 180 /** Set menu entry disabled flag.181 *182 * @param mentry Menu entry183 * @param disabled @c true iff entry is to be disabled, @c false otherwise184 */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 entry193 * @return disabled @c true iff entry is disabled, @c false otherwise194 */195 bool ui_menu_entry_is_disabled(ui_menu_entry_t *mentry)196 {197 return mentry->disabled;198 161 } 199 162 … … 214 177 } 215 178 216 /** Get last menu entry in menu.217 *218 * @param menu Menu219 * @return Last menu entry or @c NULL if there is none220 */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 232 179 /** Get next menu entry in menu. 233 180 * … … 246 193 } 247 194 248 /** Get previous menu entry in menu.249 *250 * @param cur Current menu entry251 * @return Next menu entry or @c NULL if @a cur is the last one252 */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 264 195 /** Get width of menu entry. 265 196 * … … 276 207 * This needs to work even if the menu is not open, so we cannot 277 208 * use the menu's resource, which is only created after the menu 278 * is open (and its window is created). Use the parent window's209 * is open (and its window is created). Use the menu bar's 279 210 * resource instead. 280 211 */ 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);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); 285 216 } 286 217 … … 302 233 * This needs to work even if the menu is not open, so we cannot 303 234 * use the menu's resource, which is only created after the menu 304 * is open (and its window is created). Use the parent window's235 * is open (and its window is created). Use the menu bar's 305 236 * resource instead. 306 237 */ 307 res = ui_window_get_res(menu-> parent);238 res = ui_window_get_res(menu->mbar->window); 308 239 309 240 if (res->textmode) … … 341 272 * This needs to work even if the menu is not open, so we cannot 342 273 * use the menu's resource, which is only created after the menu 343 * is open (and its window is created). Use the parent window's274 * is open (and its window is created). Use the menu bar's 344 275 * resource instead. 345 276 */ 346 res = ui_window_get_res(mentry->menu-> parent);277 res = ui_window_get_res(mentry->menu->mbar->window); 347 278 348 279 if (res->textmode) { … … 367 298 } 368 299 369 /** Get menu entry accelerator character.370 *371 * @param mentry Menu entry372 * @return Accelerator character (lowercase) or the null character if373 * 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 380 300 /** Paint menu entry. 381 301 * … … 387 307 { 388 308 ui_resource_t *res; 389 ui_text_fmt_t fmt;309 gfx_text_fmt_t fmt; 390 310 gfx_color_t *bg_color; 391 311 ui_menu_entry_geom_t geom; … … 397 317 ui_menu_entry_get_geom(mentry, pos, &geom); 398 318 399 ui_text_fmt_init(&fmt); 400 fmt.font = res->font; 319 gfx_text_fmt_init(&fmt); 401 320 fmt.halign = gfx_halign_left; 402 321 fmt.valign = gfx_valign_top; … … 405 324 mentry == mentry->menu->selected) { 406 325 fmt.color = res->wnd_sel_text_color; 407 fmt.hgl_color = res->wnd_sel_text_hgl_color;408 326 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;413 327 } else { 414 328 fmt.color = res->wnd_text_color; 415 fmt.hgl_color = res->wnd_text_hgl_color;416 329 bg_color = res->wnd_face_color; 417 330 } … … 425 338 goto error; 426 339 427 rc = ui_paint_text(&geom.caption_pos, &fmt, mentry->caption);340 rc = gfx_puttext(res->font, &geom.caption_pos, &fmt, mentry->caption); 428 341 if (rc != EOK) 429 342 goto error; … … 431 344 fmt.halign = gfx_halign_right; 432 345 433 rc = ui_paint_text(&geom.shortcut_pos, &fmt, mentry->shortcut);346 rc = gfx_puttext(res->font, &geom.shortcut_pos, &fmt, mentry->shortcut); 434 347 if (rc != EOK) 435 348 goto error; … … 465 378 } 466 379 467 /** Determine if entry is selectable.468 *469 * @return @c true iff entry is selectable470 */471 bool ui_menu_entry_selectable(ui_menu_entry_t *mentry)472 {473 return !mentry->separator;474 }475 476 380 /** Handle button press in menu entry. 477 381 * … … 484 388 return; 485 389 486 if (mentry->separator || mentry->disabled)390 if (mentry->separator) 487 391 return; 488 392 … … 503 407 mentry->held = false; 504 408 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); 409 if (mentry->inside) { 410 /* Close menu */ 411 ui_menu_bar_select(mentry->menu->mbar, NULL, NULL); 412 413 /* Call back */ 414 ui_menu_entry_cb(mentry); 415 } 520 416 } 521 417 … … 601 497 } 602 498 break; 603 case POS_DCLICK:604 break;605 499 } 606 500
Note:
See TracChangeset
for help on using the changeset viewer.