Changeset f2416ec3 in mainline for uspace/lib/ui/src/menubar.c


Ignore:
Timestamp:
2021-05-26T07:40:59Z (3 years ago)
Author:
Jiri Svoboda <jiri@…>
Children:
6baab83
Parents:
344f8b9
git-author:
Jiri Svoboda <jiri@…> (2021-05-25 18:40:50)
git-committer:
Jiri Svoboda <jiri@…> (2021-05-26 07:40:59)
Message:

Specify parent window when creating popup

This will be used in conjunction with ui_wnd_popup_params_t.place
(a rectangle relative to the parent window) to determine where on
the screen the popup window should appear.

File:
1 edited

Legend:

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

    r344f8b9 rf2416ec3  
    4747#include <ui/menu.h>
    4848#include <ui/menubar.h>
     49#include <ui/window.h>
    4950#include "../private/menubar.h"
    5051#include "../private/resource.h"
     
    7374 *
    7475 * @param ui UI
    75  * @param res UI resource
     76 * @param window Window that will contain the menu bar
    7677 * @param rmbar Place to store pointer to new menu bar
    7778 * @return EOK on success, ENOMEM if out of memory
    7879 */
    79 errno_t ui_menu_bar_create(ui_t *ui, ui_resource_t *res,
    80     ui_menu_bar_t **rmbar)
     80errno_t ui_menu_bar_create(ui_t *ui, ui_window_t *window, ui_menu_bar_t **rmbar)
    8181{
    8282        ui_menu_bar_t *mbar;
     
    9494
    9595        mbar->ui = ui;
    96         mbar->res = res;
     96        mbar->window = window;
    9797        list_initialize(&mbar->menus);
    9898        *rmbar = mbar;
     
    149149errno_t ui_menu_bar_paint(ui_menu_bar_t *mbar)
    150150{
     151        ui_resource_t *res;
    151152        gfx_text_fmt_t fmt;
    152153        gfx_coord2_t pos;
     
    161162        errno_t rc;
    162163
     164        res = ui_window_get_res(mbar->window);
     165
    163166        /* Paint menu bar background */
    164167
    165         rc = gfx_set_color(mbar->res->gc, mbar->res->wnd_face_color);
     168        rc = gfx_set_color(res->gc, res->wnd_face_color);
    166169        if (rc != EOK)
    167170                goto error;
    168171
    169         rc = gfx_fill_rect(mbar->res->gc, &mbar->rect);
     172        rc = gfx_fill_rect(res->gc, &mbar->rect);
    170173        if (rc != EOK)
    171174                goto error;
    172175
    173         if (mbar->res->textmode) {
     176        if (res->textmode) {
    174177                hpad = menubar_hpad_text;
    175178                vpad = menubar_vpad_text;
     
    188191        while (menu != NULL) {
    189192                caption = ui_menu_caption(menu);
    190                 width = gfx_text_width(mbar->res->font, caption) + 2 * hpad;
     193                width = gfx_text_width(res->font, caption) + 2 * hpad;
    191194                tpos.x = pos.x + hpad;
    192195                tpos.y = pos.y + vpad;
     
    197200
    198201                if (menu == mbar->selected) {
    199                         fmt.color = mbar->res->wnd_sel_text_color;
    200                         bg_color = mbar->res->wnd_sel_text_bg_color;
     202                        fmt.color = res->wnd_sel_text_color;
     203                        bg_color = res->wnd_sel_text_bg_color;
    201204                } else {
    202                         fmt.color = mbar->res->wnd_text_color;
    203                         bg_color = mbar->res->wnd_face_color;
     205                        fmt.color = res->wnd_text_color;
     206                        bg_color = res->wnd_face_color;
    204207                }
    205208
    206                 rc = gfx_set_color(mbar->res->gc, bg_color);
     209                rc = gfx_set_color(res->gc, bg_color);
    207210                if (rc != EOK)
    208211                        goto error;
    209212
    210                 rc = gfx_fill_rect(mbar->res->gc, &rect);
     213                rc = gfx_fill_rect(res->gc, &rect);
    211214                if (rc != EOK)
    212215                        goto error;
    213216
    214                 rc = gfx_puttext(mbar->res->font, &tpos, &fmt, caption);
     217                rc = gfx_puttext(res->font, &tpos, &fmt, caption);
    215218                if (rc != EOK)
    216219                        goto error;
     
    220223        }
    221224
    222         rc = gfx_update(mbar->res->gc);
     225        rc = gfx_update(res->gc);
    223226        if (rc != EOK)
    224227                goto error;
     
    269272ui_evclaim_t ui_menu_bar_pos_event(ui_menu_bar_t *mbar, pos_event_t *event)
    270273{
     274        ui_resource_t *res;
    271275        gfx_coord2_t pos;
    272276        gfx_rect_t rect;
     
    277281        gfx_coord2_t ppos;
    278282
     283        res = ui_window_get_res(mbar->window);
     284
    279285        ppos.x = event->hpos;
    280286        ppos.y = event->vpos;
    281287
    282         if (mbar->res->textmode) {
     288        if (res->textmode) {
    283289                hpad = menubar_hpad_text;
    284290        } else {
     
    291297        while (menu != NULL) {
    292298                caption = ui_menu_caption(menu);
    293                 width = gfx_text_width(mbar->res->font, caption) + 2 * hpad;
     299                width = gfx_text_width(res->font, caption) + 2 * hpad;
    294300
    295301                rect.p0 = pos;
Note: See TracChangeset for help on using the changeset viewer.