Changeset 28ca31ed in mainline for uspace/app/taskbar-cfg/startmenu.c


Ignore:
Timestamp:
2024-02-13T20:13:48Z (16 months ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master
Children:
10657856
Parents:
242e3c3
Message:

Moving start menu entry up and down

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/taskbar-cfg/startmenu.c

    r242e3c3 r28ca31ed  
    11/*
    2  * Copyright (c) 2023 Jiri Svoboda
     2 * Copyright (c) 2024 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    5454static void startmenu_delete_entry_clicked(ui_pbutton_t *, void *);
    5555static void startmenu_edit_entry_clicked(ui_pbutton_t *, void *);
     56static void startmenu_up_entry_clicked(ui_pbutton_t *, void *);
     57static void startmenu_down_entry_clicked(ui_pbutton_t *, void *);
    5658
    5759/** Entry list callbacks */
     
    7375ui_pbutton_cb_t startmenu_edit_entry_button_cb = {
    7476        .clicked = startmenu_edit_entry_clicked
     77};
     78
     79/** Move entry up button callbacks */
     80ui_pbutton_cb_t startmenu_up_entry_button_cb = {
     81        .clicked = startmenu_up_entry_clicked
     82};
     83
     84/** Move entry down button callbacks */
     85ui_pbutton_cb_t startmenu_down_entry_button_cb = {
     86        .clicked = startmenu_down_entry_clicked
    7587};
    7688
     
    151163                rect.p0.y = 5;
    152164                rect.p1.x = 56;
    153                 rect.p1.y = 10;
     165                rect.p1.y = 20;
    154166        } else {
    155167                rect.p0.x = 20;
    156168                rect.p0.y = 80;
    157169                rect.p1.x = 360;
    158                 rect.p1.y = 180;
     170                rect.p1.y = 330;
    159171        }
    160172
     
    263275            &startmenu_edit_entry_button_cb, (void *)smenu);
    264276
     277        /* Move entry up button */
     278
     279        rc = ui_pbutton_create(ui_res, "Up", &smenu->up_entry);
     280        if (rc != EOK) {
     281                printf("Error creating button.\n");
     282                goto error;
     283        }
     284
     285        if (ui_resource_is_textmode(ui_res)) {
     286                rect.p0.x = 58;
     287                rect.p0.y = 12;
     288                rect.p1.x = 68;
     289                rect.p1.y = 13;
     290        } else {
     291                rect.p0.x = 370;
     292                rect.p0.y = 190;
     293                rect.p1.x = 450;
     294                rect.p1.y = 215;
     295        }
     296
     297        ui_pbutton_set_rect(smenu->up_entry, &rect);
     298
     299        rc = ui_fixed_add(smenu->fixed, ui_pbutton_ctl(smenu->up_entry));
     300        if (rc != EOK) {
     301                printf("Error adding control to layout.\n");
     302                goto error;
     303        }
     304
     305        ui_pbutton_set_cb(smenu->up_entry,
     306            &startmenu_up_entry_button_cb, (void *)smenu);
     307
     308        /* Move entry down button */
     309
     310        rc = ui_pbutton_create(ui_res, "Down", &smenu->down_entry);
     311        if (rc != EOK) {
     312                printf("Error creating button.\n");
     313                goto error;
     314        }
     315
     316        if (ui_resource_is_textmode(ui_res)) {
     317                rect.p0.x = 58;
     318                rect.p0.y = 14;
     319                rect.p1.x = 68;
     320                rect.p1.y = 15;
     321        } else {
     322                rect.p0.x = 370;
     323                rect.p0.y = 220;
     324                rect.p1.x = 450;
     325                rect.p1.y = 245;
     326        }
     327
     328        ui_pbutton_set_rect(smenu->down_entry, &rect);
     329
     330        rc = ui_fixed_add(smenu->fixed, ui_pbutton_ctl(smenu->down_entry));
     331        if (rc != EOK) {
     332                printf("Error adding control to layout.\n");
     333                goto error;
     334        }
     335
     336        ui_pbutton_set_cb(smenu->down_entry,
     337            &startmenu_down_entry_button_cb, (void *)smenu);
     338
    265339        ui_tab_add(smenu->tab, ui_fixed_ctl(smenu->fixed));
    266340
     
    268342        return EOK;
    269343error:
     344        if (smenu->down_entry != NULL)
     345                ui_pbutton_destroy(smenu->down_entry);
     346        if (smenu->up_entry != NULL)
     347                ui_pbutton_destroy(smenu->up_entry);
    270348        if (smenu->delete_entry != NULL)
    271349                ui_pbutton_destroy(smenu->delete_entry);
     
    488566        ui_list_entry_delete(smentry->lentry);
    489567        free(smentry);
    490         (void) ui_control_paint(ui_list_ctl(smenu->entries_list));
     568        (void)ui_control_paint(ui_list_ctl(smenu->entries_list));
    491569}
    492570
     
    504582}
    505583
     584/** Up entry button clicked.
     585 *
     586 * @param pbutton Push button
     587 * @param arg Argument (startmenu_t *)
     588 */
     589static void startmenu_up_entry_clicked(ui_pbutton_t *pbutton, void *arg)
     590{
     591        startmenu_t *smenu = (startmenu_t *)arg;
     592        startmenu_entry_t *smentry;
     593        errno_t rc;
     594
     595        (void)pbutton;
     596
     597        smentry = startmenu_get_selected(smenu);
     598        if (smentry == NULL)
     599                return;
     600
     601        rc = smenu_entry_move_up(smentry->entry);
     602        if (rc != EOK)
     603                return;
     604
     605        ui_list_entry_move_up(smentry->lentry);
     606
     607        (void)ui_control_paint(ui_list_ctl(smenu->entries_list));
     608}
     609
     610/** Down entry button clicked.
     611 *
     612 * @param pbutton Push button
     613 * @param arg Argument (startmenu_t *)
     614 */
     615static void startmenu_down_entry_clicked(ui_pbutton_t *pbutton, void *arg)
     616{
     617        startmenu_t *smenu = (startmenu_t *)arg;
     618        startmenu_entry_t *smentry;
     619        errno_t rc;
     620
     621        (void)pbutton;
     622
     623        smentry = startmenu_get_selected(smenu);
     624        if (smentry == NULL)
     625                return;
     626
     627        rc = smenu_entry_move_up(smentry->entry);
     628        if (rc != EOK)
     629                return;
     630
     631        ui_list_entry_move_down(smentry->lentry);
     632
     633        (void)ui_control_paint(ui_list_ctl(smenu->entries_list));
     634}
     635
    506636/** @}
    507637 */
Note: See TracChangeset for help on using the changeset viewer.