Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ui/src/menuentry.c

    ree3b28a9 r81ec7e1  
    11/*
    2  * Copyright (c) 2024 Jiri Svoboda
     2 * Copyright (c) 2021 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    4343#include <stdlib.h>
    4444#include <str.h>
    45 #include <ui/accel.h>
    4645#include <ui/control.h>
    4746#include <ui/paint.h>
    48 #include <ui/menubar.h>
    4947#include <ui/menuentry.h>
    5048#include <ui/window.h>
     
    145143                return;
    146144
    147         mentry->menu->total_h -= ui_menu_entry_height(mentry);
    148         /* NOTE: max_caption_w/max_shortcut_w not updated (speed) */
    149 
    150145        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 
    163146        free(mentry->caption);
    164147        free(mentry);
     
    176159        mentry->cb = cb;
    177160        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;
    198161}
    199162
     
    214177}
    215178
    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 
    232179/** Get next menu entry in menu.
    233180 *
     
    246193}
    247194
    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 
    264195/** Get width of menu entry.
    265196 *
     
    276207         * This needs to work even if the menu is not open, so we cannot
    277208         * use the menu's resource, which is only created after the menu
    278          * is open (and its window is created). Use the parent window's
     209         * is open (and its window is created). Use the menu bar's
    279210         * resource instead.
    280211         */
    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);
    285216}
    286217
     
    302233         * This needs to work even if the menu is not open, so we cannot
    303234         * use the menu's resource, which is only created after the menu
    304          * is open (and its window is created). Use the parent window's
     235         * is open (and its window is created). Use the menu bar's
    305236         * resource instead.
    306237         */
    307         res = ui_window_get_res(menu->parent);
     238        res = ui_window_get_res(menu->mbar->window);
    308239
    309240        if (res->textmode)
     
    341272         * This needs to work even if the menu is not open, so we cannot
    342273         * use the menu's resource, which is only created after the menu
    343          * is open (and its window is created). Use the parent window's
     274         * is open (and its window is created). Use the menu bar's
    344275         * resource instead.
    345276         */
    346         res = ui_window_get_res(mentry->menu->parent);
     277        res = ui_window_get_res(mentry->menu->mbar->window);
    347278
    348279        if (res->textmode) {
     
    367298}
    368299
    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 
    380300/** Paint menu entry.
    381301 *
     
    387307{
    388308        ui_resource_t *res;
    389         ui_text_fmt_t fmt;
     309        gfx_text_fmt_t fmt;
    390310        gfx_color_t *bg_color;
    391311        ui_menu_entry_geom_t geom;
     
    397317        ui_menu_entry_get_geom(mentry, pos, &geom);
    398318
    399         ui_text_fmt_init(&fmt);
    400         fmt.font = res->font;
     319        gfx_text_fmt_init(&fmt);
    401320        fmt.halign = gfx_halign_left;
    402321        fmt.valign = gfx_valign_top;
     
    405324            mentry == mentry->menu->selected) {
    406325                fmt.color = res->wnd_sel_text_color;
    407                 fmt.hgl_color = res->wnd_sel_text_hgl_color;
    408326                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;
    413327        } else {
    414328                fmt.color = res->wnd_text_color;
    415                 fmt.hgl_color = res->wnd_text_hgl_color;
    416329                bg_color = res->wnd_face_color;
    417330        }
     
    425338                goto error;
    426339
    427         rc = ui_paint_text(&geom.caption_pos, &fmt, mentry->caption);
     340        rc = gfx_puttext(res->font, &geom.caption_pos, &fmt, mentry->caption);
    428341        if (rc != EOK)
    429342                goto error;
     
    431344        fmt.halign = gfx_halign_right;
    432345
    433         rc = ui_paint_text(&geom.shortcut_pos, &fmt, mentry->shortcut);
     346        rc = gfx_puttext(res->font, &geom.shortcut_pos, &fmt, mentry->shortcut);
    434347        if (rc != EOK)
    435348                goto error;
     
    465378}
    466379
    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 
    476380/** Handle button press in menu entry.
    477381 *
     
    484388                return;
    485389
    486         if (mentry->separator || mentry->disabled)
     390        if (mentry->separator)
    487391                return;
    488392
     
    503407        mentry->held = false;
    504408
    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        }
    520416}
    521417
     
    601497                }
    602498                break;
    603         case POS_DCLICK:
    604                 break;
    605499        }
    606500
Note: See TracChangeset for help on using the changeset viewer.