Changeset 7cf5ddb in mainline


Ignore:
Timestamp:
2023-03-08T18:21:22Z (14 months ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
master, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
42c2e65, 72ac106
Parents:
bea6233
Message:

Generic UI list control

Derived from file list, now file list is based on UI list.
Whew!

Location:
uspace
Files:
5 added
9 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/nav/panel.c

    rbea6233 r7cf5ddb  
    11/*
    2  * Copyright (c) 2022 Jiri Svoboda
     2 * Copyright (c) 2023 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    6060};
    6161
     62static void panel_flist_activate_req(ui_file_list_t *, void *);
    6263static void panel_flist_selected(ui_file_list_t *, void *, const char *);
    6364
    6465/** Panel file list callbacks */
    6566static ui_file_list_cb_t panel_flist_cb = {
    66         .selected = panel_flist_selected
     67        .activate_req = panel_flist_activate_req,
     68        .selected = panel_flist_selected,
    6769};
    6870
     
    216218        gfx_coord2_t pos;
    217219        ui_control_t *ctl;
     220        ui_evclaim_t claim;
    218221
    219222        pos.x = event->hpos;
     
    222225                return ui_unclaimed;
    223226
     227        ctl = ui_file_list_ctl(panel->flist);
     228        claim = ui_control_pos_event(ctl, event);
     229        if (claim == ui_claimed)
     230                return ui_claimed;
     231
    224232        if (!panel->active && event->type == POS_PRESS)
    225233                panel_activate_req(panel);
    226234
    227         ctl = ui_file_list_ctl(panel->flist);
    228         return ui_control_pos_event(ctl, event);
     235        return ui_claimed;
    229236}
    230237
     
    416423}
    417424
     425/** File list in panel requests activation.
     426 *
     427 * @param flist File list
     428 * @param arg Argument (panel_t *)
     429 */
     430static void panel_flist_activate_req(ui_file_list_t *flist, void *arg)
     431{
     432        panel_t *panel = (panel_t *)arg;
     433
     434        panel_activate_req(panel);
     435}
     436
    418437/** File in panel file list was selected.
    419438 *
  • uspace/app/uidemo/uidemo.c

    rbea6233 r7cf5ddb  
    4444#include <ui/image.h>
    4545#include <ui/label.h>
     46#include <ui/list.h>
    4647#include <ui/menubar.h>
    4748#include <ui/menuentry.h>
     
    598599        ui_menu_entry_t *mmodify;
    599600        ui_menu_entry_t *mabout;
     601        ui_list_entry_attr_t eattr;
    600602        errno_t rc;
    601603
     
    11831185
    11841186        ui_tab_add(demo.tbasic, ui_fixed_ctl(demo.bfixed));
     1187
     1188        rc = ui_fixed_create(&demo.lfixed);
     1189        if (rc != EOK) {
     1190                printf("Error creating fixed layout.\n");
     1191                return rc;
     1192        }
     1193
     1194        rc = ui_list_create(window, false, &demo.list);
     1195        if (rc != EOK) {
     1196                printf("Error creating list.\n");
     1197                return rc;
     1198        }
     1199
     1200        ui_list_entry_attr_init(&eattr);
     1201
     1202        eattr.caption = "One";
     1203        rc = ui_list_entry_append(demo.list, &eattr, NULL);
     1204        if (rc != EOK) {
     1205                printf("Error adding list entry.\n");
     1206                return rc;
     1207        }
     1208
     1209        eattr.caption = "Two";
     1210        rc = ui_list_entry_append(demo.list, &eattr, NULL);
     1211        if (rc != EOK) {
     1212                printf("Error adding list entry.\n");
     1213                return rc;
     1214        }
     1215
     1216        eattr.caption = "Three";
     1217        rc = ui_list_entry_append(demo.list, &eattr, NULL);
     1218        if (rc != EOK) {
     1219                printf("Error adding list entry.\n");
     1220                return rc;
     1221        }
     1222
     1223        eattr.caption = "Four";
     1224        rc = ui_list_entry_append(demo.list, &eattr, NULL);
     1225        if (rc != EOK) {
     1226                printf("Error adding list entry.\n");
     1227                return rc;
     1228        }
     1229
     1230        eattr.caption = "Five";
     1231        rc = ui_list_entry_append(demo.list, &eattr, NULL);
     1232        if (rc != EOK) {
     1233                printf("Error adding list entry.\n");
     1234                return rc;
     1235        }
     1236
     1237        eattr.caption = "Six";
     1238        rc = ui_list_entry_append(demo.list, &eattr, NULL);
     1239        if (rc != EOK) {
     1240                printf("Error adding list entry.\n");
     1241                return rc;
     1242        }
     1243
     1244        /* FIXME: Auto layout */
     1245        if (ui_is_textmode(ui)) {
     1246                rect.p0.x = 4;
     1247                rect.p0.y = 5;
     1248                rect.p1.x = 41;
     1249                rect.p1.y = 10;
     1250        } else {
     1251                rect.p0.x = 15;
     1252                rect.p0.y = 88;
     1253                rect.p1.x = 245;
     1254                rect.p1.y = 173;
     1255        }
     1256
     1257        ui_list_set_rect(demo.list, &rect);
     1258
     1259        rc = ui_fixed_add(demo.lfixed, ui_list_ctl(demo.list));
     1260        if (rc != EOK) {
     1261                printf("Error adding control to layout.\n");
     1262                return rc;
     1263        }
     1264
     1265        ui_tab_add(demo.tlists, ui_fixed_ctl(demo.lfixed));
    11851266
    11861267        ui_window_add(window, ui_fixed_ctl(demo.fixed));
  • uspace/app/uidemo/uidemo.h

    rbea6233 r7cf5ddb  
    4242#include <ui/fixed.h>
    4343#include <ui/label.h>
     44#include <ui/list.h>
    4445#include <ui/menu.h>
    4546#include <ui/menubar.h>
     
    5960        ui_fixed_t *fixed;
    6061        ui_fixed_t *bfixed;
     62        ui_fixed_t *lfixed;
    6163        ui_menu_bar_t *mbar;
    6264        ui_menu_t *mfile;
     
    8082        ui_scrollbar_t *hscrollbar;
    8183        ui_scrollbar_t *vscrollbar;
     84        ui_list_t *list;
    8285} ui_demo_t;
    8386
  • uspace/lib/ui/include/ui/filelist.h

    rbea6233 r7cf5ddb  
    11/*
    2  * Copyright (c) 2022 Jiri Svoboda
     2 * Copyright (c) 2023 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3939#include <errno.h>
    4040#include <gfx/coord.h>
    41 #include <io/kbd_event.h>
    42 #include <io/pos_event.h>
    4341#include <ui/control.h>
    4442#include <ui/window.h>
  • uspace/lib/ui/meson.build

    rbea6233 r7cf5ddb  
    4040        'src/image.c',
    4141        'src/label.c',
     42        'src/list.c',
    4243        'src/menu.c',
    4344        'src/menubar.c',
     
    7172        'test/image.c',
    7273        'test/label.c',
     74        'test/list.c',
    7375        'test/main.c',
    7476        'test/menu.c',
  • uspace/lib/ui/private/filelist.h

    rbea6233 r7cf5ddb  
    11/*
    2  * Copyright (c) 2022 Jiri Svoboda
     2 * Copyright (c) 2023 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3737#define _UI_PRIVATE_FILELIST_H
    3838
    39 #include <adt/list.h>
    4039#include <gfx/color.h>
    41 #include <gfx/coord.h>
    4240#include <ipc/loc.h>
     41#include <ui/list.h>
    4342#include <ui/window.h>
    4443#include <stdint.h>
     
    6160        /** Containing file list */
    6261        struct ui_file_list *flist;
    63         /** Link to @c flist->entries */
    64         link_t lentries;
     62        /** List entry */
     63        ui_list_entry_t *entry;
    6564        /** File name */
    6665        char *name;
     
    8281
    8382        /** Containing window */
    84         ui_window_t *window;
     83        struct ui_window *window;
     84
     85        /** UI list */
     86        ui_list_t *list;
    8587
    8688        /** Callbacks */
     
    9092        void *cb_arg;
    9193
    92         /** File list rectangle */
    93         gfx_rect_t rect;
    94 
    95         /** Scrollbar */
    96         struct ui_scrollbar *scrollbar;
    97 
    9894        /** Directory-type entry color */
    9995        gfx_color_t *dir_color;
     
    10298        gfx_color_t *svc_color;
    10399
    104         /** File list entries (list of ui_file_list_entry_t) */
    105         list_t entries;
    106 
    107         /** Number of entries */
    108         size_t entries_cnt;
    109 
    110         /** First entry of current page */
    111         ui_file_list_entry_t *page;
    112 
    113         /** Index of first entry of current page */
    114         size_t page_idx;
    115 
    116         /** Cursor position */
    117         ui_file_list_entry_t *cursor;
    118 
    119         /** Index of entry under cursor */
    120         size_t cursor_idx;
    121 
    122         /** @c true iff the file list is active */
    123         bool active;
    124 
    125100        /** Directory */
    126101        char *dir;
    127102} ui_file_list_t;
    128103
    129 extern gfx_coord_t ui_file_list_entry_height(ui_file_list_t *);
    130 extern errno_t ui_file_list_entry_paint(ui_file_list_entry_t *, size_t);
    131 extern errno_t ui_file_list_paint(ui_file_list_t *);
    132 extern ui_evclaim_t ui_file_list_kbd_event(ui_file_list_t *, kbd_event_t *);
    133 extern ui_evclaim_t ui_file_list_pos_event(ui_file_list_t *, pos_event_t *);
    134 extern unsigned ui_file_list_page_size(ui_file_list_t *);
    135 extern void ui_file_list_inside_rect(ui_file_list_t *, gfx_rect_t *);
    136 extern void ui_file_list_scrollbar_rect(ui_file_list_t *, gfx_rect_t *);
    137 extern gfx_coord_t ui_file_list_scrollbar_pos(ui_file_list_t *);
    138 extern void ui_file_list_scrollbar_update(ui_file_list_t *);
    139104extern bool ui_file_list_is_active(ui_file_list_t *);
    140105extern void ui_file_list_entry_delete(ui_file_list_entry_t *);
     
    142107extern errno_t ui_file_list_sort(ui_file_list_t *);
    143108extern int ui_file_list_entry_ptr_cmp(const void *, const void *);
     109extern void ui_file_list_entry_attr_init(ui_file_list_entry_attr_t *);
     110extern errno_t ui_file_list_entry_append(ui_file_list_t *,
     111    ui_file_list_entry_attr_t *);
    144112extern ui_file_list_entry_t *ui_file_list_first(ui_file_list_t *);
    145113extern ui_file_list_entry_t *ui_file_list_last(ui_file_list_t *);
    146114extern ui_file_list_entry_t *ui_file_list_next(ui_file_list_entry_t *);
    147115extern ui_file_list_entry_t *ui_file_list_prev(ui_file_list_entry_t *);
    148 extern ui_file_list_entry_t *ui_file_list_page_nth_entry(ui_file_list_t *,
    149     size_t, size_t *);
    150 extern void ui_file_list_entry_attr_init(ui_file_list_entry_attr_t *);
    151 extern errno_t ui_file_list_entry_append(ui_file_list_t *,
    152     ui_file_list_entry_attr_t *);
    153 extern void ui_file_list_cursor_move(ui_file_list_t *, ui_file_list_entry_t *,
    154     size_t);
    155 extern void ui_file_list_cursor_up(ui_file_list_t *);
    156 extern void ui_file_list_cursor_down(ui_file_list_t *);
    157 extern void ui_file_list_cursor_top(ui_file_list_t *);
    158 extern void ui_file_list_cursor_bottom(ui_file_list_t *);
    159 extern void ui_file_list_page_up(ui_file_list_t *);
    160 extern void ui_file_list_page_down(ui_file_list_t *);
    161 extern void ui_file_list_scroll_up(ui_file_list_t *);
    162 extern void ui_file_list_scroll_down(ui_file_list_t *);
    163 extern void ui_file_list_scroll_page_up(ui_file_list_t *);
    164 extern void ui_file_list_scroll_page_down(ui_file_list_t *);
    165 extern void ui_file_list_scroll_pos(ui_file_list_t *, size_t);
    166116extern errno_t ui_file_list_open_dir(ui_file_list_t *, ui_file_list_entry_t *);
    167117extern errno_t ui_file_list_open_file(ui_file_list_t *, ui_file_list_entry_t *);
    168118extern void ui_file_list_activate_req(ui_file_list_t *);
    169119extern void ui_file_list_selected(ui_file_list_t *, const char *);
     120extern errno_t ui_file_list_paint(ui_file_list_t *);
     121extern int ui_file_list_list_compare(ui_list_entry_t *, ui_list_entry_t *);
    170122
    171123#endif
  • uspace/lib/ui/src/filelist.c

    rbea6233 r7cf5ddb  
    11/*
    2  * Copyright (c) 2022 Jiri Svoboda
     2 * Copyright (c) 2023 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3030 * @{
    3131 */
    32 /** @file File list.
     32/** @file File list control.
    3333 *
    3434 * Displays a file listing.
     
    3737#include <dirent.h>
    3838#include <errno.h>
    39 #include <gfx/render.h>
    40 #include <gfx/text.h>
    4139#include <stdlib.h>
    4240#include <str.h>
    4341#include <ui/control.h>
    4442#include <ui/filelist.h>
    45 #include <ui/paint.h>
     43#include <ui/list.h>
    4644#include <ui/resource.h>
    47 #include <ui/scrollbar.h>
    4845#include <vfs/vfs.h>
    4946#include <qsort.h>
     
    5653static ui_evclaim_t ui_file_list_ctl_pos_event(void *, pos_event_t *);
    5754
    58 /** File list control ops */
     55/** List control ops */
    5956ui_control_ops_t ui_file_list_ctl_ops = {
    6057        .destroy = ui_file_list_ctl_destroy,
     
    6461};
    6562
    66 enum {
    67         file_list_entry_hpad = 2,
    68         file_list_entry_vpad = 2,
    69         file_list_entry_hpad_text = 1,
    70         file_list_entry_vpad_text = 0,
    71 };
    72 
    73 static void ui_file_list_scrollbar_up(ui_scrollbar_t *, void *);
    74 static void ui_file_list_scrollbar_down(ui_scrollbar_t *, void *);
    75 static void ui_file_list_scrollbar_page_up(ui_scrollbar_t *, void *);
    76 static void ui_file_list_scrollbar_page_down(ui_scrollbar_t *, void *);
    77 static void ui_file_list_scrollbar_moved(ui_scrollbar_t *, void *, gfx_coord_t);
    78 
    79 /** File list scrollbar callbacks */
    80 static ui_scrollbar_cb_t ui_file_list_scrollbar_cb = {
    81         .up = ui_file_list_scrollbar_up,
    82         .down = ui_file_list_scrollbar_down,
    83         .page_up = ui_file_list_scrollbar_page_up,
    84         .page_down = ui_file_list_scrollbar_page_down,
    85         .moved = ui_file_list_scrollbar_moved
     63static void ui_file_list_list_activate_req(ui_list_t *, void *);
     64static void ui_file_list_list_selected(ui_list_entry_t *, void *);
     65
     66/** List callbacks */
     67ui_list_cb_t ui_file_list_list_cb = {
     68        .activate_req = ui_file_list_list_activate_req,
     69        .selected = ui_file_list_list_selected,
     70        .compare = ui_file_list_list_compare,
    8671};
    8772
     
    10590        rc = ui_control_new(&ui_file_list_ctl_ops, (void *)flist,
    10691            &flist->control);
    107         if (rc != EOK) {
    108                 free(flist);
    109                 return rc;
    110         }
     92        if (rc != EOK)
     93                goto error;
    11194
    11295        rc = gfx_color_new_ega(0x0f, &flist->dir_color);
     
    118101                goto error;
    119102
    120         rc = ui_scrollbar_create(ui_window_get_ui(window), window,
    121             ui_sbd_vert, &flist->scrollbar);
     103        rc = ui_list_create(window, active, &flist->list);
    122104        if (rc != EOK)
    123105                goto error;
    124106
    125         ui_scrollbar_set_cb(flist->scrollbar, &ui_file_list_scrollbar_cb,
    126             (void *) flist);
     107        ui_list_set_cb(flist->list, &ui_file_list_list_cb, (void *)flist);
    127108
    128109        flist->window = window;
    129         list_initialize(&flist->entries);
    130         flist->entries_cnt = 0;
    131         flist->active = active;
    132 
    133110        *rflist = flist;
    134111        return EOK;
    135112error:
     113        ui_control_delete(flist->control);
    136114        if (flist->dir_color != NULL)
    137115                gfx_color_delete(flist->dir_color);
    138116        if (flist->svc_color != NULL)
    139117                gfx_color_delete(flist->svc_color);
     118        free(flist);
     119        return rc;
     120}
     121
     122/** Destroy file list.
     123 *
     124 * @param flist File list
     125 */
     126void ui_file_list_destroy(ui_file_list_t *flist)
     127{
     128        ui_file_list_clear_entries(flist);
     129        ui_list_destroy(flist->list);
    140130        ui_control_delete(flist->control);
    141131        free(flist);
    142         return rc;
    143 }
    144 
    145 /** Destroy file list.
    146  *
    147  * @param flist File list
    148  */
    149 void ui_file_list_destroy(ui_file_list_t *flist)
    150 {
    151         ui_file_list_clear_entries(flist);
    152         ui_control_delete(flist->control);
    153         free(flist);
    154132}
    155133
     
    166144}
    167145
    168 /** Get height of file list entry.
    169  *
    170  * @param flist File list
    171  * @return Entry height in pixels
    172  */
    173 gfx_coord_t ui_file_list_entry_height(ui_file_list_t *flist)
    174 {
    175         ui_resource_t *res;
    176         gfx_font_metrics_t metrics;
    177         gfx_coord_t height;
    178         gfx_coord_t vpad;
    179 
    180         res = ui_window_get_res(flist->window);
    181 
    182         if (res->textmode) {
    183                 vpad = file_list_entry_vpad_text;
    184         } else {
    185                 vpad = file_list_entry_vpad;
    186         }
    187 
    188         /* Normal menu entry */
    189         gfx_font_get_metrics(res->font, &metrics);
    190         height = metrics.ascent + metrics.descent + 1;
    191 
    192         return height + 2 * vpad;
    193 }
    194 
    195 /** Paint file list entry.
    196  *
    197  * @param entry File list entry
    198  * @param entry_idx Entry index (within list of entries)
    199  * @return EOK on success or an error code
    200  */
    201 errno_t ui_file_list_entry_paint(ui_file_list_entry_t *entry, size_t entry_idx)
    202 {
    203         ui_file_list_t *flist = entry->flist;
    204         gfx_context_t *gc = ui_window_get_gc(flist->window);
    205         ui_resource_t *res = ui_window_get_res(flist->window);
    206         gfx_font_t *font = ui_resource_get_font(res);
    207         gfx_text_fmt_t fmt;
    208         gfx_coord2_t pos;
    209         gfx_rect_t rect;
    210         gfx_rect_t lrect;
    211         gfx_rect_t crect;
    212         gfx_color_t *bgcolor;
    213         char *caption;
    214         gfx_coord_t hpad, vpad;
    215         gfx_coord_t line_height;
    216         size_t rows;
    217         errno_t rc;
    218         int rv;
    219 
    220         line_height = ui_file_list_entry_height(flist);
    221         ui_file_list_inside_rect(entry->flist, &lrect);
    222 
    223         gfx_text_fmt_init(&fmt);
    224         fmt.font = font;
    225         rows = ui_file_list_page_size(flist) + 1;
    226 
    227         /* Do not display entry outside of current page */
    228         if (entry_idx < flist->page_idx ||
    229             entry_idx >= flist->page_idx + rows)
    230                 return EOK;
    231 
    232         if (res->textmode) {
    233                 hpad = file_list_entry_hpad_text;
    234                 vpad = file_list_entry_vpad_text;
    235         } else {
    236                 hpad = file_list_entry_hpad;
    237                 vpad = file_list_entry_vpad;
    238         }
    239 
    240         pos.x = lrect.p0.x;
    241         pos.y = lrect.p0.y + line_height * (entry_idx - flist->page_idx);
    242 
    243         if (entry == flist->cursor && flist->active) {
    244                 fmt.color = res->entry_sel_text_fg_color;
    245                 bgcolor = res->entry_sel_text_bg_color;
    246         } else if (entry->isdir) {
    247                 if (res->textmode) {
    248                         fmt.color = flist->dir_color;
    249                         bgcolor = flist->dir_color;
    250                 } else {
    251                         fmt.color = res->entry_fg_color;
    252                         bgcolor = res->entry_bg_color;
    253                 }
    254         } else if (entry->svc != 0) {
    255                 if (res->textmode) {
    256                         fmt.color = flist->svc_color;
    257                         bgcolor = flist->svc_color;
    258                 } else {
    259                         fmt.color = res->entry_fg_color;
    260                         bgcolor = res->entry_bg_color;
    261                 }
    262         } else {
    263                 fmt.color = res->entry_fg_color;
    264                 bgcolor = res->entry_bg_color;
    265         }
    266 
    267         /* Draw entry background */
    268         rect.p0 = pos;
    269         rect.p1.x = lrect.p1.x;
    270         rect.p1.y = rect.p0.y + line_height;
    271 
    272         /* Clip to file list interior */
    273         gfx_rect_clip(&rect, &lrect, &crect);
    274 
    275         rc = gfx_set_color(gc, bgcolor);
    276         if (rc != EOK)
    277                 return rc;
    278 
    279         rc = gfx_fill_rect(gc, &crect);
    280         if (rc != EOK)
    281                 return rc;
    282 
    283         /*
    284          * Make sure name does not overflow the entry rectangle.
    285          *
    286          * XXX We probably want to measure the text width, and,
    287          * if it's too long, use gfx_text_find_pos() to find where
    288          * it should be cut off (and append some sort of overflow
    289          * marker.
    290          */
    291         rc = gfx_set_clip_rect(gc, &crect);
    292         if (rc != EOK)
    293                 return rc;
    294 
    295         pos.x += hpad;
    296         pos.y += vpad;
    297 
    298         if (res->textmode || !entry->isdir) {
    299                 rc = gfx_puttext(&pos, &fmt, entry->name);
    300                 if (rc != EOK) {
    301                         (void) gfx_set_clip_rect(gc, NULL);
    302                         return rc;
    303                 }
    304         } else {
    305                 /*
    306                  * XXX This is mostly a hack to distinguish directories
    307                  * util a better solution is available. (E.g. a Size
    308                  * column where we can put <dir>, an icon.)
    309                  */
    310                 rv = asprintf(&caption, "[%s]", entry->name);
    311                 if (rv < 0) {
    312                         (void) gfx_set_clip_rect(gc, NULL);
    313                         return rc;
    314                 }
    315 
    316                 rc = gfx_puttext(&pos, &fmt, caption);
    317                 if (rc != EOK) {
    318                         free(caption);
    319                         (void) gfx_set_clip_rect(gc, NULL);
    320                         return rc;
    321                 }
    322 
    323                 free(caption);
    324         }
    325 
    326         return gfx_set_clip_rect(gc, NULL);
    327 }
    328 
    329 /** Paint file list.
    330  *
    331  * @param flist File list
    332  */
    333 errno_t ui_file_list_paint(ui_file_list_t *flist)
    334 {
    335         gfx_context_t *gc = ui_window_get_gc(flist->window);
    336         ui_resource_t *res = ui_window_get_res(flist->window);
    337         ui_file_list_entry_t *entry;
    338         int i, lines;
    339         errno_t rc;
    340 
    341         rc = gfx_set_color(gc, res->entry_bg_color);
    342         if (rc != EOK)
    343                 return rc;
    344 
    345         rc = gfx_fill_rect(gc, &flist->rect);
    346         if (rc != EOK)
    347                 return rc;
    348 
    349         if (!res->textmode) {
    350                 rc = ui_paint_inset_frame(res, &flist->rect, NULL);
    351                 if (rc != EOK)
    352                         return rc;
    353         }
    354 
    355         lines = ui_file_list_page_size(flist) + 1;
    356         i = 0;
    357 
    358         entry = flist->page;
    359         while (entry != NULL && i < lines) {
    360                 rc = ui_file_list_entry_paint(entry, flist->page_idx + i);
    361                 if (rc != EOK)
    362                         return rc;
    363 
    364                 ++i;
    365                 entry = ui_file_list_next(entry);
    366         }
    367 
    368         rc = ui_scrollbar_paint(flist->scrollbar);
    369         if (rc != EOK)
    370                 return rc;
    371 
    372         rc = gfx_update(gc);
    373         if (rc != EOK)
    374                 return rc;
    375 
    376         return EOK;
    377 }
    378 
    379 /** Handle file list keyboard event.
    380  *
    381  * @param flist File list
    382  * @param event Keyboard event
    383  * @return ui_claimed iff event was claimed
    384  */
    385 ui_evclaim_t ui_file_list_kbd_event(ui_file_list_t *flist, kbd_event_t *event)
    386 {
    387         if (!flist->active)
    388                 return ui_unclaimed;
    389 
    390         if (event->type == KEY_PRESS) {
    391                 if ((event->mods & (KM_CTRL | KM_ALT | KM_SHIFT)) == 0) {
    392                         switch (event->key) {
    393                         case KC_UP:
    394                                 ui_file_list_cursor_up(flist);
    395                                 break;
    396                         case KC_DOWN:
    397                                 ui_file_list_cursor_down(flist);
    398                                 break;
    399                         case KC_HOME:
    400                                 ui_file_list_cursor_top(flist);
    401                                 break;
    402                         case KC_END:
    403                                 ui_file_list_cursor_bottom(flist);
    404                                 break;
    405                         case KC_PAGE_UP:
    406                                 ui_file_list_page_up(flist);
    407                                 break;
    408                         case KC_PAGE_DOWN:
    409                                 ui_file_list_page_down(flist);
    410                                 break;
    411                         case KC_ENTER:
    412                                 ui_file_list_open(flist, flist->cursor);
    413                                 break;
    414                         default:
    415                                 break;
    416                         }
    417                 }
    418         }
    419 
    420         return ui_claimed;
    421 }
    422 
    423 /** Handle file list position event.
    424  *
    425  * @param flist File list
    426  * @param event Position event
    427  * @return ui_claimed iff event was claimed
    428  */
    429 ui_evclaim_t ui_file_list_pos_event(ui_file_list_t *flist, pos_event_t *event)
    430 {
    431         gfx_coord2_t pos;
    432         gfx_rect_t irect;
    433         ui_file_list_entry_t *entry;
    434         gfx_coord_t line_height;
    435         size_t entry_idx;
    436         ui_evclaim_t claim;
    437         int n;
    438 
    439         claim = ui_scrollbar_pos_event(flist->scrollbar, event);
    440         if (claim == ui_claimed)
    441                 return ui_claimed;
    442 
    443         line_height = ui_file_list_entry_height(flist);
    444 
    445         pos.x = event->hpos;
    446         pos.y = event->vpos;
    447         if (!gfx_pix_inside_rect(&pos, &flist->rect))
    448                 return ui_unclaimed;
    449 
    450         if (!flist->active && event->type == POS_PRESS)
    451                 ui_file_list_activate_req(flist);
    452 
    453         if (event->type == POS_PRESS || event->type == POS_DCLICK) {
    454                 ui_file_list_inside_rect(flist, &irect);
    455 
    456                 /* Did we click on one of the entries? */
    457                 if (gfx_pix_inside_rect(&pos, &irect)) {
    458                         /* Index within page */
    459                         n = (pos.y - irect.p0.y) / line_height;
    460 
    461                         /* Entry and its index within entire listing */
    462                         entry = ui_file_list_page_nth_entry(flist, n, &entry_idx);
    463                         if (entry == NULL)
    464                                 return ui_claimed;
    465 
    466                         if (event->type == POS_PRESS) {
    467                                 /* Move to the entry found */
    468                                 ui_file_list_cursor_move(flist, entry, entry_idx);
    469                         } else {
    470                                 /* event->type == POS_DCLICK */
    471                                 ui_file_list_open(flist, entry);
    472                         }
    473                 } else {
    474                         /* It's in the border. */
    475                         if (event->type == POS_PRESS) {
    476                                 /* Top or bottom half? */
    477                                 if (pos.y >= (irect.p0.y + irect.p1.y) / 2)
    478                                         ui_file_list_page_down(flist);
    479                                 else
    480                                         ui_file_list_page_up(flist);
    481                         }
    482                 }
    483         }
    484 
    485         return ui_claimed;
    486 }
    487 
    488146/** Get base control for file list.
    489147 *
     
    503161void ui_file_list_set_rect(ui_file_list_t *flist, gfx_rect_t *rect)
    504162{
    505         gfx_rect_t srect;
    506 
    507         flist->rect = *rect;
    508 
    509         ui_file_list_scrollbar_rect(flist, &srect);
    510         ui_scrollbar_set_rect(flist->scrollbar, &srect);
    511 }
    512 
    513 /** Get file list page size.
    514  *
    515  * @param flist File list
    516  * @return Number of entries that fit in flist at the same time.
    517  */
    518 unsigned ui_file_list_page_size(ui_file_list_t *flist)
    519 {
    520         gfx_coord_t line_height;
    521         gfx_rect_t irect;
    522 
    523         line_height = ui_file_list_entry_height(flist);
    524         ui_file_list_inside_rect(flist, &irect);
    525         return (irect.p1.y - irect.p0.y) / line_height;
    526 }
    527 
    528 /** Get file list interior rectangle.
    529  *
    530  * @param flist File list
    531  * @param irect Place to store interior rectangle
    532  */
    533 void ui_file_list_inside_rect(ui_file_list_t *flist, gfx_rect_t *irect)
    534 {
    535         ui_resource_t *res = ui_window_get_res(flist->window);
    536         gfx_rect_t rect;
    537         gfx_coord_t width;
    538 
    539         if (res->textmode) {
    540                 rect = flist->rect;
    541         } else {
    542                 ui_paint_get_inset_frame_inside(res, &flist->rect, &rect);
    543         }
    544 
    545         if (res->textmode) {
    546                 width = 1;
    547         } else {
    548                 width = 23;
    549         }
    550 
    551         irect->p0 = rect.p0;
    552         irect->p1.x = rect.p1.x - width;
    553         irect->p1.y = rect.p1.y;
    554 }
    555 
    556 /** Get file list scrollbar rectangle.
    557  *
    558  * @param flist File list
    559  * @param irect Place to store interior rectangle
    560  */
    561 void ui_file_list_scrollbar_rect(ui_file_list_t *flist, gfx_rect_t *srect)
    562 {
    563         ui_resource_t *res = ui_window_get_res(flist->window);
    564         gfx_rect_t rect;
    565         gfx_coord_t width;
    566 
    567         if (res->textmode) {
    568                 rect = flist->rect;
    569         } else {
    570                 ui_paint_get_inset_frame_inside(res, &flist->rect, &rect);
    571         }
    572 
    573         if (res->textmode) {
    574                 width = 1;
    575         } else {
    576                 width = 23;
    577         }
    578 
    579         srect->p0.x = rect.p1.x - width;
    580         srect->p0.y = rect.p0.y;
    581         srect->p1 = rect.p1;
    582 }
    583 
    584 /** Compute new position for file list scrollbar thumb.
    585  *
    586  * @param flist File list
    587  * @return New position
    588  */
    589 gfx_coord_t ui_file_list_scrollbar_pos(ui_file_list_t *flist)
    590 {
    591         size_t entries;
    592         size_t pglen;
    593         size_t sbar_len;
    594 
    595         entries = list_count(&flist->entries);
    596         pglen = ui_file_list_page_size(flist);
    597         sbar_len = ui_scrollbar_move_length(flist->scrollbar);
    598 
    599         if (entries > pglen)
    600                 return sbar_len * flist->page_idx / (entries - pglen);
    601         else
    602                 return 0;
    603 }
    604 
    605 /** Update file list scrollbar position.
    606  *
    607  * @param flist File list
    608  */
    609 void ui_file_list_scrollbar_update(ui_file_list_t *flist)
    610 {
    611         ui_scrollbar_set_pos(flist->scrollbar,
    612             ui_file_list_scrollbar_pos(flist));
     163        ui_list_set_rect(flist->list, rect);
    613164}
    614165
     
    620171bool ui_file_list_is_active(ui_file_list_t *flist)
    621172{
    622         return flist->active;
     173        return ui_list_is_active(flist->list);
    623174}
    624175
     
    639190        }
    640191
    641         flist->active = true;
    642         (void) ui_file_list_paint(flist);
    643         return EOK;
     192        return ui_list_activate(flist->list);
    644193}
    645194
     
    650199void ui_file_list_deactivate(ui_file_list_t *flist)
    651200{
    652         flist->active = false;
    653         (void) ui_file_list_paint(flist);
     201        ui_list_deactivate(flist->list);
    654202}
    655203
     
    661209{
    662210        memset(attr, 0, sizeof(*attr));
    663 }
    664 
    665 /** Destroy file list control.
    666  *
    667  * @param arg Argument (ui_file_list_t *)
    668  */
    669 void ui_file_list_ctl_destroy(void *arg)
    670 {
    671         ui_file_list_t *flist = (ui_file_list_t *) arg;
    672 
    673         ui_file_list_destroy(flist);
    674 }
    675 
    676 /** Paint file list control.
    677  *
    678  * @param arg Argument (ui_file_list_t *)
    679  * @return EOK on success or an error code
    680  */
    681 errno_t ui_file_list_ctl_paint(void *arg)
    682 {
    683         ui_file_list_t *flist = (ui_file_list_t *) arg;
    684 
    685         return ui_file_list_paint(flist);
    686 }
    687 
    688 /** Handle file list control keyboard event.
    689  *
    690  * @param arg Argument (ui_file_list_t *)
    691  * @param kbd_event Keyboard event
    692  * @return @c ui_claimed iff the event is claimed
    693  */
    694 ui_evclaim_t ui_file_list_ctl_kbd_event(void *arg, kbd_event_t *event)
    695 {
    696         ui_file_list_t *flist = (ui_file_list_t *) arg;
    697 
    698         return ui_file_list_kbd_event(flist, event);
    699 }
    700 
    701 /** Handle file list control position event.
    702  *
    703  * @param arg Argument (ui_file_list_t *)
    704  * @param pos_event Position event
    705  * @return @c ui_claimed iff the event is claimed
    706  */
    707 ui_evclaim_t ui_file_list_ctl_pos_event(void *arg, pos_event_t *event)
    708 {
    709         ui_file_list_t *flist = (ui_file_list_t *) arg;
    710 
    711         return ui_file_list_pos_event(flist, event);
    712211}
    713212
     
    721220{
    722221        ui_file_list_entry_t *entry;
     222        ui_list_entry_attr_t lattr;
     223        ui_list_entry_t *lentry;
     224        ui_resource_t *res;
     225        char *caption;
     226        errno_t rc;
     227        int rv;
     228
     229        res = ui_window_get_res(flist->window);
    723230
    724231        entry = calloc(1, sizeof(ui_file_list_entry_t));
     
    736243        entry->isdir = attr->isdir;
    737244        entry->svc = attr->svc;
    738         link_initialize(&entry->lentries);
    739         list_append(&entry->lentries, &flist->entries);
    740         ++flist->entries_cnt;
     245
     246        if (attr->isdir && !res->textmode) {
     247                rv = asprintf(&caption, "[%s]", attr->name);
     248                if (rv < 0)
     249                        caption = NULL;
     250        } else {
     251                caption = str_dup(attr->name);
     252        }
     253
     254        if (caption == NULL) {
     255                free(entry->name);
     256                free(entry);
     257                return ENOMEM;
     258        }
     259
     260        lattr.caption = caption;
     261        lattr.arg = (void *)entry;
     262        lattr.color = NULL;
     263        lattr.bgcolor = NULL;
     264
     265        if (res->textmode) {
     266                if (attr->isdir) {
     267                        lattr.color = flist->dir_color;
     268                        lattr.bgcolor = flist->dir_color;
     269                } else if (attr->svc != 0) {
     270                        lattr.color = flist->svc_color;
     271                        lattr.bgcolor = flist->svc_color;
     272                }
     273        }
     274
     275        rc = ui_list_entry_append(flist->list, &lattr, &lentry);
     276        if (rc != EOK) {
     277                free(caption);
     278                free(entry->name);
     279                free(entry);
     280                return rc;
     281        }
     282
     283        free(caption);
     284        entry->entry = lentry;
    741285        return EOK;
    742286}
     
    748292void ui_file_list_entry_delete(ui_file_list_entry_t *entry)
    749293{
    750         if (entry->flist->cursor == entry)
    751                 entry->flist->cursor = NULL;
    752         if (entry->flist->page == entry)
    753                 entry->flist->page = NULL;
    754 
    755         list_remove(&entry->lentries);
    756         --entry->flist->entries_cnt;
    757         free((char *) entry->name);
     294        ui_list_entry_delete(entry->entry);
     295        free(entry->name);
    758296        free(entry);
    759297}
     
    788326        char *ndir = NULL;
    789327        ui_file_list_entry_attr_t attr;
     328        ui_file_list_entry_t *cur;
    790329        ui_file_list_entry_t *next;
    791         ui_file_list_entry_t *prev;
    792330        char *olddn;
    793         size_t pg_size;
    794         size_t max_idx;
    795         size_t i;
    796331        errno_t rc;
    797332
     
    853388                goto error;
    854389
    855         flist->cursor = ui_file_list_first(flist);
    856         flist->cursor_idx = 0;
    857         flist->page = ui_file_list_first(flist);
    858         flist->page_idx = 0;
    859 
    860390        /* Moving up? */
    861391        if (str_cmp(dirname, "..") == 0) {
     
    865395                        /* Find corresponding entry */
    866396                        ++olddn;
    867                         next = ui_file_list_next(flist->cursor);
     397                        cur = ui_file_list_first(flist);
     398                        next = ui_file_list_next(cur);
    868399                        while (next != NULL && str_cmp(next->name, olddn) <= 0 &&
    869400                            next->isdir) {
    870                                 flist->cursor = next;
    871                                 ++flist->cursor_idx;
    872                                 next = ui_file_list_next(flist->cursor);
     401                                cur = next;
     402                                next = ui_file_list_next(cur);
    873403                        }
    874404
    875                         /* Move page so that cursor is in the center */
    876                         flist->page = flist->cursor;
    877                         flist->page_idx = flist->cursor_idx;
    878 
    879                         pg_size = ui_file_list_page_size(flist);
    880 
    881                         for (i = 0; i < pg_size / 2; i++) {
    882                                 prev = ui_file_list_prev(flist->page);
    883                                 if (prev == NULL)
    884                                         break;
    885 
    886                                 flist->page = prev;
    887                                 --flist->page_idx;
    888                         }
    889 
    890                         /* Make sure page is not beyond the end if possible */
    891                         if (flist->entries_cnt > pg_size)
    892                                 max_idx = flist->entries_cnt - pg_size;
    893                         else
    894                                 max_idx = 0;
    895 
    896                         while (flist->page_idx > 0 && flist->page_idx > max_idx) {
    897                                 prev = ui_file_list_prev(flist->page);
    898                                 if (prev == NULL)
    899                                         break;
    900 
    901                                 flist->page = prev;
    902                                 --flist->page_idx;
    903                         }
     405                        /* Center on the entry */
     406                        ui_list_cursor_center(flist->list, cur->entry);
    904407                }
    905408        }
     
    925428errno_t ui_file_list_sort(ui_file_list_t *flist)
    926429{
    927         ui_file_list_entry_t **emap;
    928         ui_file_list_entry_t *entry;
    929         size_t i;
    930 
    931         /* Create an array to hold pointer to each entry */
    932         emap = calloc(flist->entries_cnt, sizeof(ui_file_list_entry_t *));
    933         if (emap == NULL)
    934                 return ENOMEM;
    935 
    936         /* Write entry pointers to array */
    937         entry = ui_file_list_first(flist);
    938         i = 0;
    939         while (entry != NULL) {
    940                 assert(i < flist->entries_cnt);
    941                 emap[i++] = entry;
    942                 entry = ui_file_list_next(entry);
    943         }
    944 
    945         /* Sort the array of pointers */
    946         qsort(emap, flist->entries_cnt, sizeof(ui_file_list_entry_t *),
    947             ui_file_list_entry_ptr_cmp);
    948 
    949         /* Unlink entries from entry list */
    950         entry = ui_file_list_first(flist);
    951         while (entry != NULL) {
    952                 list_remove(&entry->lentries);
    953                 entry = ui_file_list_first(flist);
    954         }
    955 
    956         /* Add entries back to entry list sorted */
    957         for (i = 0; i < flist->entries_cnt; i++)
    958                 list_append(&emap[i]->lentries, &flist->entries);
    959 
    960         free(emap);
    961         return EOK;
    962 }
    963 
    964 /** Compare two file list entries indirectly referenced by pointers.
    965  *
    966  * @param pa Pointer to pointer to first entry
    967  * @param pb Pointer to pointer to second entry
    968  * @return <0, =0, >=0 if pa < b, pa == pb, pa > pb, resp.
    969  */
    970 int ui_file_list_entry_ptr_cmp(const void *pa, const void *pb)
    971 {
    972         ui_file_list_entry_t *a = *(ui_file_list_entry_t **)pa;
    973         ui_file_list_entry_t *b = *(ui_file_list_entry_t **)pb;
     430        return ui_list_sort(flist->list);
     431}
     432
     433/** Compare two list entries within file list entries.
     434 *
     435 * @param ea First UI list entry
     436 * @param eb Second UI list entry
     437 * @return <0, =0, >=0 if a < b, a == b, a > b, resp.
     438 */
     439int ui_file_list_list_compare(ui_list_entry_t *ea, ui_list_entry_t *eb)
     440{
     441        ui_file_list_entry_t *a;
     442        ui_file_list_entry_t *b;
    974443        int dcmp;
     444
     445        a = (ui_file_list_entry_t *)ui_list_entry_get_arg(ea);
     446        b = (ui_file_list_entry_t *)ui_list_entry_get_arg(eb);
    975447
    976448        /* Sort directories first */
     
    989461ui_file_list_entry_t *ui_file_list_first(ui_file_list_t *flist)
    990462{
    991         link_t *link;
    992 
    993         link = list_first(&flist->entries);
    994         if (link == NULL)
     463        ui_list_entry_t *lentry;
     464
     465        lentry = ui_list_first(flist->list);
     466        if (lentry == NULL)
    995467                return NULL;
    996468
    997         return list_get_instance(link, ui_file_list_entry_t, lentries);
     469        return (ui_file_list_entry_t *)ui_list_entry_get_arg(lentry);
    998470}
    999471
     
    1005477ui_file_list_entry_t *ui_file_list_last(ui_file_list_t *flist)
    1006478{
    1007         link_t *link;
    1008 
    1009         link = list_last(&flist->entries);
    1010         if (link == NULL)
     479        ui_list_entry_t *lentry;
     480
     481        lentry = ui_list_last(flist->list);
     482        if (lentry == NULL)
    1011483                return NULL;
    1012484
    1013         return list_get_instance(link, ui_file_list_entry_t, lentries);
     485        return (ui_file_list_entry_t *)ui_list_entry_get_arg(lentry);
    1014486}
    1015487
     
    1021493ui_file_list_entry_t *ui_file_list_next(ui_file_list_entry_t *cur)
    1022494{
    1023         link_t *link;
    1024 
    1025         link = list_next(&cur->lentries, &cur->flist->entries);
    1026         if (link == NULL)
     495        ui_list_entry_t *lentry;
     496
     497        lentry = ui_list_next(cur->entry);
     498        if (lentry == NULL)
    1027499                return NULL;
    1028500
    1029         return list_get_instance(link, ui_file_list_entry_t, lentries);
     501        return (ui_file_list_entry_t *)ui_list_entry_get_arg(lentry);
    1030502}
    1031503
     
    1037509ui_file_list_entry_t *ui_file_list_prev(ui_file_list_entry_t *cur)
    1038510{
    1039         link_t *link;
    1040 
    1041         link = list_prev(&cur->lentries, &cur->flist->entries);
    1042         if (link == NULL)
     511        ui_list_entry_t *lentry;
     512
     513        lentry = ui_list_prev(cur->entry);
     514        if (lentry == NULL)
    1043515                return NULL;
    1044516
    1045         return list_get_instance(link, ui_file_list_entry_t, lentries);
    1046 }
    1047 
    1048 /** Find the n-th entry of the current file list page.
    1049  *
    1050  * @param flist File list
    1051  * @param n Which entry to get (starting from 0)
    1052  * @param ridx Place to store index (within listing) of the entry
    1053  * @return n-th entry of the page
    1054  */
    1055 ui_file_list_entry_t *ui_file_list_page_nth_entry(ui_file_list_t *flist,
    1056     size_t n, size_t *ridx)
    1057 {
    1058         ui_file_list_entry_t *entry;
    1059         size_t i;
    1060         size_t idx;
    1061 
    1062         assert(n <= ui_file_list_page_size(flist));
    1063 
    1064         entry = flist->page;
     517        return (ui_file_list_entry_t *)ui_list_entry_get_arg(lentry);
     518}
     519
     520/** Get entry under cursor.
     521 *
     522 * @param flist File list
     523 * @return Current cursor
     524 */
     525ui_file_list_entry_t *ui_file_list_get_cursor(ui_file_list_t *flist)
     526{
     527        ui_list_entry_t *entry;
     528
     529        entry = ui_list_get_cursor(flist->list);
    1065530        if (entry == NULL)
    1066531                return NULL;
    1067532
    1068         idx = flist->page_idx;
    1069         for (i = 0; i < n; i++) {
    1070                 entry = ui_file_list_next(entry);
    1071                 if (entry == NULL)
    1072                         return NULL;
    1073 
    1074                 ++idx;
    1075         }
    1076 
    1077         *ridx = idx;
    1078         return entry;
    1079 }
    1080 
    1081 /** Get entry under cursor.
    1082  *
    1083  * @param flist File list
    1084  * @return Current cursor
    1085  */
    1086 ui_file_list_entry_t *ui_file_list_get_cursor(ui_file_list_t *flist)
    1087 {
    1088         return flist->cursor;
    1089 }
    1090 
    1091 /** Move cursor to a new position, possibly scrolling.
    1092  *
    1093  * @param flist File list
    1094  * @param entry New entry under cursor
    1095  * @param entry_idx Index of new entry under cursor
    1096  */
    1097 void ui_file_list_cursor_move(ui_file_list_t *flist,
    1098     ui_file_list_entry_t *entry, size_t entry_idx)
    1099 {
    1100         gfx_context_t *gc = ui_window_get_gc(flist->window);
    1101         ui_file_list_entry_t *old_cursor;
    1102         size_t old_idx;
    1103         size_t rows;
    1104         ui_file_list_entry_t *e;
    1105         size_t i;
    1106 
    1107         rows = ui_file_list_page_size(flist);
    1108 
    1109         old_cursor = flist->cursor;
    1110         old_idx = flist->cursor_idx;
    1111 
    1112         flist->cursor = entry;
    1113         flist->cursor_idx = entry_idx;
    1114 
    1115         if (entry_idx >= flist->page_idx &&
    1116             entry_idx < flist->page_idx + rows) {
    1117                 /*
    1118                  * If cursor is still on the current page, we're not
    1119                  * scrolling. Just unpaint old cursor and paint new
    1120                  * cursor.
    1121                  */
    1122                 ui_file_list_entry_paint(old_cursor, old_idx);
    1123                 ui_file_list_entry_paint(flist->cursor, flist->cursor_idx);
    1124 
    1125                 (void) gfx_update(gc);
    1126         } else {
    1127                 /*
    1128                  * Need to scroll and update all rows.
    1129                  */
    1130 
    1131                 /* Scrolling up */
    1132                 if (entry_idx < flist->page_idx) {
    1133                         flist->page = entry;
    1134                         flist->page_idx = entry_idx;
    1135                 }
    1136 
    1137                 /* Scrolling down */
    1138                 if (entry_idx >= flist->page_idx + rows) {
    1139                         if (entry_idx >= rows) {
    1140                                 flist->page_idx = entry_idx - rows + 1;
    1141                                 /* Find first page entry (go back rows - 1) */
    1142                                 e = entry;
    1143                                 for (i = 0; i < rows - 1; i++) {
    1144                                         e = ui_file_list_prev(e);
    1145                                 }
    1146 
    1147                                 /* Should be valid */
    1148                                 assert(e != NULL);
    1149                                 flist->page = e;
    1150                         } else {
    1151                                 flist->page = ui_file_list_first(flist);
    1152                                 flist->page_idx = 0;
    1153                         }
    1154                 }
    1155 
    1156                 ui_file_list_scrollbar_update(flist);
    1157                 (void) ui_file_list_paint(flist);
    1158         }
    1159 }
    1160 
    1161 /** Move cursor one entry up.
    1162  *
    1163  * @param flist File list
    1164  */
    1165 void ui_file_list_cursor_up(ui_file_list_t *flist)
    1166 {
    1167         ui_file_list_entry_t *prev;
    1168         size_t prev_idx;
    1169 
    1170         prev = ui_file_list_prev(flist->cursor);
    1171         prev_idx = flist->cursor_idx - 1;
    1172         if (prev != NULL)
    1173                 ui_file_list_cursor_move(flist, prev, prev_idx);
    1174 }
    1175 
    1176 /** Move cursor one entry down.
    1177  *
    1178  * @param flist File list
    1179  */
    1180 void ui_file_list_cursor_down(ui_file_list_t *flist)
    1181 {
    1182         ui_file_list_entry_t *next;
    1183         size_t next_idx;
    1184 
    1185         next = ui_file_list_next(flist->cursor);
    1186         next_idx = flist->cursor_idx + 1;
    1187         if (next != NULL)
    1188                 ui_file_list_cursor_move(flist, next, next_idx);
    1189 }
    1190 
    1191 /** Move cursor to top.
    1192  *
    1193  * @param flist File list
    1194  */
    1195 void ui_file_list_cursor_top(ui_file_list_t *flist)
    1196 {
    1197         ui_file_list_cursor_move(flist, ui_file_list_first(flist), 0);
    1198 }
    1199 
    1200 /** Move cursor to bottom.
    1201  *
    1202  * @param flist File list
    1203  */
    1204 void ui_file_list_cursor_bottom(ui_file_list_t *flist)
    1205 {
    1206         ui_file_list_cursor_move(flist, ui_file_list_last(flist),
    1207             flist->entries_cnt - 1);
    1208 }
    1209 
    1210 /** Move cursor one page up.
    1211  *
    1212  * @param flist File list
    1213  */
    1214 void ui_file_list_page_up(ui_file_list_t *flist)
    1215 {
    1216         gfx_context_t *gc = ui_window_get_gc(flist->window);
    1217         ui_file_list_entry_t *old_page;
    1218         ui_file_list_entry_t *old_cursor;
    1219         size_t old_idx;
    1220         size_t rows;
    1221         ui_file_list_entry_t *entry;
    1222         size_t i;
    1223 
    1224         rows = ui_file_list_page_size(flist);
    1225 
    1226         old_page = flist->page;
    1227         old_cursor = flist->cursor;
    1228         old_idx = flist->cursor_idx;
    1229 
    1230         /* Move page by rows entries up (if possible) */
    1231         for (i = 0; i < rows; i++) {
    1232                 entry = ui_file_list_prev(flist->page);
    1233                 if (entry != NULL) {
    1234                         flist->page = entry;
    1235                         --flist->page_idx;
    1236                 }
    1237         }
    1238 
    1239         /* Move cursor by rows entries up (if possible) */
    1240 
    1241         for (i = 0; i < rows; i++) {
    1242                 entry = ui_file_list_prev(flist->cursor);
    1243                 if (entry != NULL) {
    1244                         flist->cursor = entry;
    1245                         --flist->cursor_idx;
    1246                 }
    1247         }
    1248 
    1249         if (flist->page != old_page) {
    1250                 /* We have scrolled. Need to repaint all entries */
    1251                 ui_file_list_scrollbar_update(flist);
    1252                 (void) ui_file_list_paint(flist);
    1253         } else if (flist->cursor != old_cursor) {
    1254                 /* No scrolling, but cursor has moved */
    1255                 ui_file_list_entry_paint(old_cursor, old_idx);
    1256                 ui_file_list_entry_paint(flist->cursor, flist->cursor_idx);
    1257 
    1258                 (void) gfx_update(gc);
    1259         }
    1260 }
    1261 
    1262 /** Move cursor one page down.
    1263  *
    1264  * @param flist File list
    1265  */
    1266 void ui_file_list_page_down(ui_file_list_t *flist)
    1267 {
    1268         gfx_context_t *gc = ui_window_get_gc(flist->window);
    1269         ui_file_list_entry_t *old_page;
    1270         ui_file_list_entry_t *old_cursor;
    1271         size_t old_idx;
    1272         size_t max_idx;
    1273         size_t rows;
    1274         ui_file_list_entry_t *entry;
    1275         size_t i;
    1276 
    1277         rows = ui_file_list_page_size(flist);
    1278 
    1279         old_page = flist->page;
    1280         old_cursor = flist->cursor;
    1281         old_idx = flist->cursor_idx;
    1282 
    1283         if (flist->entries_cnt > rows)
    1284                 max_idx = flist->entries_cnt - rows;
    1285         else
    1286                 max_idx = 0;
    1287 
    1288         /* Move page by rows entries down (if possible) */
    1289         for (i = 0; i < rows; i++) {
    1290                 entry = ui_file_list_next(flist->page);
    1291                 /* Do not scroll that results in a short page */
    1292                 if (entry != NULL && flist->page_idx < max_idx) {
    1293                         flist->page = entry;
    1294                         ++flist->page_idx;
    1295                 }
    1296         }
    1297 
    1298         /* Move cursor by rows entries down (if possible) */
    1299 
    1300         for (i = 0; i < rows; i++) {
    1301                 entry = ui_file_list_next(flist->cursor);
    1302                 if (entry != NULL) {
    1303                         flist->cursor = entry;
    1304                         ++flist->cursor_idx;
    1305                 }
    1306         }
    1307 
    1308         if (flist->page != old_page) {
    1309                 /* We have scrolled. Need to repaint all entries */
    1310                 ui_file_list_scrollbar_update(flist);
    1311                 (void) ui_file_list_paint(flist);
    1312         } else if (flist->cursor != old_cursor) {
    1313                 /* No scrolling, but cursor has moved */
    1314                 ui_file_list_entry_paint(old_cursor, old_idx);
    1315                 ui_file_list_entry_paint(flist->cursor, flist->cursor_idx);
    1316 
    1317                 (void) gfx_update(gc);
    1318         }
    1319 }
    1320 
    1321 /** Scroll one entry up.
    1322  *
    1323  * @param flist File list
    1324  */
    1325 void ui_file_list_scroll_up(ui_file_list_t *flist)
    1326 {
    1327         ui_file_list_entry_t *prev;
    1328 
    1329         prev = ui_file_list_prev(flist->page);
    1330         if (prev == NULL)
    1331                 return;
    1332 
    1333         flist->page = prev;
    1334         assert(flist->page_idx > 0);
    1335         --flist->page_idx;
    1336 
    1337         ui_file_list_scrollbar_update(flist);
    1338         (void) ui_file_list_paint(flist);
    1339 }
    1340 
    1341 /** Scroll one entry down.
    1342  *
    1343  * @param flist File list
    1344  */
    1345 void ui_file_list_scroll_down(ui_file_list_t *flist)
    1346 {
    1347         ui_file_list_entry_t *next;
    1348         ui_file_list_entry_t *pgend;
    1349         size_t i;
    1350         size_t rows;
    1351 
    1352         next = ui_file_list_next(flist->page);
    1353         if (next == NULL)
    1354                 return;
    1355 
    1356         rows = ui_file_list_page_size(flist);
    1357 
    1358         /* Find last page entry */
    1359         pgend = flist->page;
    1360         for (i = 0; i < rows && pgend != NULL; i++) {
    1361                 pgend = ui_file_list_next(pgend);
    1362         }
    1363 
    1364         /* Scroll down by one entry, if the page remains full */
    1365         if (pgend != NULL) {
    1366                 flist->page = next;
    1367                 ++flist->page_idx;
    1368         }
    1369 
    1370         ui_file_list_scrollbar_update(flist);
    1371         (void) ui_file_list_paint(flist);
    1372 }
    1373 
    1374 /** Scroll one page up.
    1375  *
    1376  * @param flist File list
    1377  */
    1378 void ui_file_list_scroll_page_up(ui_file_list_t *flist)
    1379 {
    1380         ui_file_list_entry_t *prev;
    1381         size_t i;
    1382         size_t rows;
    1383 
    1384         prev = ui_file_list_prev(flist->page);
    1385         if (prev == NULL)
    1386                 return;
    1387 
    1388         rows = ui_file_list_page_size(flist);
    1389 
    1390         for (i = 0; i < rows && prev != NULL; i++) {
    1391                 flist->page = prev;
    1392                 assert(flist->page_idx > 0);
    1393                 --flist->page_idx;
    1394                 prev = ui_file_list_prev(prev);
    1395         }
    1396 
    1397         ui_file_list_scrollbar_update(flist);
    1398         (void) ui_file_list_paint(flist);
    1399 }
    1400 
    1401 /** Scroll one page down.
    1402  *
    1403  * @param flist File list
    1404  */
    1405 void ui_file_list_scroll_page_down(ui_file_list_t *flist)
    1406 {
    1407         ui_file_list_entry_t *next;
    1408         ui_file_list_entry_t *pgend;
    1409         size_t i;
    1410         size_t rows;
    1411 
    1412         next = ui_file_list_next(flist->page);
    1413         if (next == NULL)
    1414                 return;
    1415 
    1416         rows = ui_file_list_page_size(flist);
    1417 
    1418         /* Find last page entry */
    1419         pgend = flist->page;
    1420         for (i = 0; i < rows && pgend != NULL; i++) {
    1421                 pgend = ui_file_list_next(pgend);
    1422         }
    1423 
    1424         /* Scroll by up to 'rows' entries, keeping the page full */
    1425         for (i = 0; i < rows && pgend != NULL; i++) {
    1426                 flist->page = next;
    1427                 ++flist->page_idx;
    1428                 next = ui_file_list_next(next);
    1429                 pgend = ui_file_list_next(pgend);
    1430         }
    1431 
    1432         ui_file_list_scrollbar_update(flist);
    1433         (void) ui_file_list_paint(flist);
    1434 }
    1435 
    1436 /** Scroll to a specific entry
    1437  *
    1438  * @param flist File list
    1439  * @param page_idx New index of first entry on the page
    1440  */
    1441 void ui_file_list_scroll_pos(ui_file_list_t *flist, size_t page_idx)
    1442 {
    1443         ui_file_list_entry_t *entry;
    1444         size_t i;
    1445 
    1446         entry = ui_file_list_first(flist);
    1447         for (i = 0; i < page_idx; i++) {
    1448                 entry = ui_file_list_next(entry);
    1449                 assert(entry != NULL);
    1450         }
    1451 
    1452         flist->page = entry;
    1453         flist->page_idx = page_idx;
    1454 
    1455         (void) ui_file_list_paint(flist);
     533        return (ui_file_list_entry_t *)ui_list_entry_get_arg(entry);
    1456534}
    1457535
     
    1487565    ui_file_list_entry_t *entry)
    1488566{
    1489         gfx_context_t *gc = ui_window_get_gc(flist->window);
    1490567        char *dirname;
    1491568        errno_t rc;
     
    1515592                return rc;
    1516593
    1517         return gfx_update(gc);
     594        return EOK;
    1518595}
    1519596
     
    1557634}
    1558635
    1559 /** File list scrollbar up button pressed.
    1560  *
    1561  * @param scrollbar Scrollbar
     636/** Paint file list.
     637 *
     638 * @param flist File list
     639 * @return EOK on success or an error code.
     640 */
     641errno_t ui_file_list_paint(ui_file_list_t *flist)
     642{
     643        return ui_control_paint(ui_list_ctl(flist->list));
     644}
     645
     646/** Destroy file list control.
     647 *
     648 * @param arg Argument (ui_list_t *)
     649 */
     650void ui_file_list_ctl_destroy(void *arg)
     651{
     652        ui_file_list_t *flist = (ui_file_list_t *) arg;
     653
     654        ui_file_list_destroy(flist);
     655}
     656
     657/** Paint file list control.
     658 *
    1562659 * @param arg Argument (ui_file_list_t *)
    1563  */
    1564 static void ui_file_list_scrollbar_up(ui_scrollbar_t *scrollbar, void *arg)
     660 * @return EOK on success or an error code
     661 */
     662errno_t ui_file_list_ctl_paint(void *arg)
     663{
     664        ui_file_list_t *flist = (ui_file_list_t *) arg;
     665
     666        return ui_file_list_paint(flist);
     667}
     668
     669/** Handle file list control keyboard event.
     670 *
     671 * @param arg Argument (ui_file_list_t *)
     672 * @param kbd_event Keyboard event
     673 * @return @c ui_claimed iff the event is claimed
     674 */
     675ui_evclaim_t ui_file_list_ctl_kbd_event(void *arg, kbd_event_t *event)
     676{
     677        ui_file_list_t *flist = (ui_file_list_t *) arg;
     678
     679        return ui_control_kbd_event(ui_list_ctl(flist->list), event);
     680}
     681
     682/** Handle file list control position event.
     683 *
     684 * @param arg Argument (ui_file_list_t *)
     685 * @param pos_event Position event
     686 * @return @c ui_claimed iff the event is claimed
     687 */
     688ui_evclaim_t ui_file_list_ctl_pos_event(void *arg, pos_event_t *event)
     689{
     690        ui_file_list_t *flist = (ui_file_list_t *) arg;
     691
     692        return ui_control_pos_event(ui_list_ctl(flist->list), event);
     693}
     694
     695/** Activate request callback handler for UI list within file list.
     696 *
     697 * @param list UI list
     698 * @param arg Argument (File list)
     699 */
     700static void ui_file_list_list_activate_req(ui_list_t *list, void *arg)
    1565701{
    1566702        ui_file_list_t *flist = (ui_file_list_t *)arg;
    1567         ui_file_list_scroll_up(flist);
    1568 }
    1569 
    1570 /** File list scrollbar down button pressed.
    1571  *
    1572  * @param scrollbar Scrollbar
    1573  * @param arg Argument (ui_file_list_t *)
    1574  */
    1575 static void ui_file_list_scrollbar_down(ui_scrollbar_t *scrollbar, void *arg)
    1576 {
    1577         ui_file_list_t *flist = (ui_file_list_t *)arg;
    1578         ui_file_list_scroll_down(flist);
    1579 }
    1580 
    1581 /** File list scrollbar page up pressed.
    1582  *
    1583  * @param scrollbar Scrollbar
    1584  * @param arg Argument (ui_file_list_t *)
    1585  */
    1586 static void ui_file_list_scrollbar_page_up(ui_scrollbar_t *scrollbar, void *arg)
    1587 {
    1588         ui_file_list_t *flist = (ui_file_list_t *)arg;
    1589         ui_file_list_scroll_page_up(flist);
    1590 }
    1591 
    1592 /** File list scrollbar page down pressed.
    1593  *
    1594  * @param scrollbar Scrollbar
    1595  * @param arg Argument (ui_file_list_t *)
    1596  */
    1597 static void ui_file_list_scrollbar_page_down(ui_scrollbar_t *scrollbar,
    1598     void *arg)
    1599 {
    1600         ui_file_list_t *flist = (ui_file_list_t *)arg;
    1601         ui_file_list_scroll_page_down(flist);
    1602 }
    1603 
    1604 /** File list scrollbar moved.
    1605  *
    1606  * @param scrollbar Scrollbar
    1607  * @param arg Argument (ui_file_list_t *)
    1608  */
    1609 static void ui_file_list_scrollbar_moved(ui_scrollbar_t *scrollbar, void *arg,
    1610     gfx_coord_t pos)
    1611 {
    1612         ui_file_list_t *flist = (ui_file_list_t *)arg;
    1613         size_t entries;
    1614         size_t pglen;
    1615         size_t sbar_len;
    1616         size_t pgstart;
    1617 
    1618         entries = list_count(&flist->entries);
    1619         pglen = ui_file_list_page_size(flist);
    1620         sbar_len = ui_scrollbar_move_length(flist->scrollbar);
    1621 
    1622         if (entries > pglen)
    1623                 pgstart = (entries - pglen) * pos / (sbar_len - 1);
    1624         else
    1625                 pgstart = 0;
    1626 
    1627         ui_file_list_scroll_pos(flist, pgstart);
     703
     704        ui_file_list_activate_req(flist);
     705}
     706
     707/** Entry selected callback handler for UI list within file list.
     708 *
     709 * @param entr Activated UI list entry
     710 * @param arg Argument (File list entry)
     711 */
     712static void ui_file_list_list_selected(ui_list_entry_t *entry, void *arg)
     713{
     714        ui_file_list_entry_t *fentry = (void *)arg;
     715
     716        (void) ui_file_list_open(fentry->flist, fentry);
    1628717}
    1629718
  • uspace/lib/ui/test/filelist.c

    rbea6233 r7cf5ddb  
    11/*
    2  * Copyright (c) 2022 Jiri Svoboda
     2 * Copyright (c) 2023 Jiri Svoboda
    33 * All rights reserved.
    44 *
     
    3737#include <vfs/vfs.h>
    3838#include "../private/filelist.h"
     39#include "../private/list.h"
    3940
    4041PCUT_INIT;
     
    117118}
    118119
    119 /** ui_file_list_entry_height() gives the correct height */
    120 PCUT_TEST(entry_height)
    121 {
    122         ui_t *ui;
    123         ui_window_t *window;
    124         ui_wnd_params_t params;
    125         ui_file_list_t *flist;
    126         errno_t rc;
    127         gfx_coord_t height;
    128 
    129         rc = ui_create_disp(NULL, &ui);
    130         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    131 
    132         ui_wnd_params_init(&params);
    133         params.caption = "Test";
    134 
    135         rc = ui_window_create(ui, &params, &window);
    136         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    137 
    138         rc = ui_file_list_create(window, true, &flist);
    139         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    140 
    141         /* Font height is 13, padding: 2 (top) + 2 (bottom) */
    142         height = ui_file_list_entry_height(flist);
    143         PCUT_ASSERT_INT_EQUALS(17, height);
    144 
    145         ui_file_list_destroy(flist);
    146         ui_window_destroy(window);
    147         ui_destroy(ui);
    148 }
    149 
    150 /** Test ui_file_list_entry_paint() */
    151 PCUT_TEST(entry_paint)
    152 {
    153         ui_t *ui;
    154         ui_window_t *window;
    155         ui_wnd_params_t params;
    156         ui_file_list_t *flist;
    157         ui_file_list_entry_attr_t attr;
    158         errno_t rc;
    159 
    160         rc = ui_create_disp(NULL, &ui);
    161         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    162 
    163         ui_wnd_params_init(&params);
    164         params.caption = "Test";
    165 
    166         rc = ui_window_create(ui, &params, &window);
    167         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    168 
    169         rc = ui_file_list_create(window, true, &flist);
    170         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    171 
    172         ui_file_list_entry_attr_init(&attr);
    173         attr.name = "a";
    174         attr.size = 1;
    175 
    176         rc = ui_file_list_entry_append(flist, &attr);
    177         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    178 
    179         rc = ui_file_list_entry_paint(ui_file_list_first(flist), 0);
    180         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    181 
    182         ui_file_list_destroy(flist);
    183         ui_window_destroy(window);
    184         ui_destroy(ui);
    185 }
    186 
    187120/** Test ui_file_list_paint() */
    188121PCUT_TEST(paint)
     
    238171        control = ui_file_list_ctl(flist);
    239172        PCUT_ASSERT_NOT_NULL(control);
    240 
    241         ui_file_list_destroy(flist);
    242         ui_window_destroy(window);
    243         ui_destroy(ui);
    244 }
    245 
    246 /** Test ui_file_list_kbd_event() */
    247 PCUT_TEST(kbd_event)
    248 {
    249         ui_t *ui;
    250         ui_window_t *window;
    251         ui_wnd_params_t params;
    252         ui_file_list_t *flist;
    253         ui_evclaim_t claimed;
    254         kbd_event_t event;
    255         errno_t rc;
    256 
    257         /* Active file list should claim events */
    258 
    259         rc = ui_create_disp(NULL, &ui);
    260         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    261 
    262         ui_wnd_params_init(&params);
    263         params.caption = "Test";
    264 
    265         rc = ui_window_create(ui, &params, &window);
    266         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    267 
    268         rc = ui_file_list_create(window, true, &flist);
    269         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    270 
    271         event.type = KEY_PRESS;
    272         event.key = KC_ESCAPE;
    273         event.mods = 0;
    274         event.c = '\0';
    275 
    276         claimed = ui_file_list_kbd_event(flist, &event);
    277         PCUT_ASSERT_EQUALS(ui_claimed, claimed);
    278 
    279         ui_file_list_destroy(flist);
    280 
    281         /* Inactive file list should not claim events */
    282 
    283         rc = ui_create_disp(NULL, &ui);
    284         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    285 
    286         ui_wnd_params_init(&params);
    287         params.caption = "Test";
    288 
    289         rc = ui_window_create(ui, &params, &window);
    290         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    291 
    292         rc = ui_file_list_create(window, false, &flist);
    293         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    294 
    295         event.type = KEY_PRESS;
    296         event.key = KC_ESCAPE;
    297         event.mods = 0;
    298         event.c = '\0';
    299 
    300         claimed = ui_file_list_kbd_event(flist, &event);
    301         PCUT_ASSERT_EQUALS(ui_unclaimed, claimed);
    302 
    303         ui_file_list_destroy(flist);
    304         ui_window_destroy(window);
    305         ui_destroy(ui);
    306 }
    307 
    308 /** Test ui_file_list_pos_event() */
    309 PCUT_TEST(pos_event)
    310 {
    311         ui_t *ui;
    312         ui_window_t *window;
    313         ui_wnd_params_t params;
    314         ui_file_list_t *flist;
    315         ui_evclaim_t claimed;
    316         pos_event_t event;
    317         gfx_rect_t rect;
    318         ui_file_list_entry_attr_t attr;
    319         errno_t rc;
    320 
    321         rc = ui_create_disp(NULL, &ui);
    322         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    323 
    324         ui_wnd_params_init(&params);
    325         params.caption = "Test";
    326 
    327         rc = ui_window_create(ui, &params, &window);
    328         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    329 
    330         rc = ui_file_list_create(window, true, &flist);
    331         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    332 
    333         rect.p0.x = 10;
    334         rect.p0.y = 20;
    335         rect.p1.x = 50;
    336         rect.p1.y = 220;
    337 
    338         ui_file_list_set_rect(flist, &rect);
    339 
    340         ui_file_list_entry_attr_init(&attr);
    341         attr.name = "a";
    342         attr.size = 1;
    343         rc = ui_file_list_entry_append(flist, &attr);
    344         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    345 
    346         attr.name = "b";
    347         attr.size = 2;
    348         rc = ui_file_list_entry_append(flist, &attr);
    349         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    350 
    351         attr.name = "c";
    352         attr.size = 3;
    353         rc = ui_file_list_entry_append(flist, &attr);
    354         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    355 
    356         flist->cursor = ui_file_list_first(flist);
    357         flist->cursor_idx = 0;
    358         flist->page = ui_file_list_first(flist);
    359         flist->page_idx = 0;
    360 
    361         event.pos_id = 0;
    362         event.type = POS_PRESS;
    363         event.btn_num = 1;
    364 
    365         /* Clicking on the middle entry should select it */
    366         event.hpos = 20;
    367         event.vpos = 40;
    368 
    369         claimed = ui_file_list_pos_event(flist, &event);
    370         PCUT_ASSERT_EQUALS(ui_claimed, claimed);
    371 
    372         PCUT_ASSERT_NOT_NULL(flist->cursor);
    373         PCUT_ASSERT_STR_EQUALS("b", flist->cursor->name);
    374         PCUT_ASSERT_INT_EQUALS(2, flist->cursor->size);
    375 
    376         /* Clicking on the top edge should do a page-up */
    377         event.hpos = 20;
    378         event.vpos = 20;
    379         claimed = ui_file_list_pos_event(flist, &event);
    380         PCUT_ASSERT_EQUALS(ui_claimed, claimed);
    381 
    382         PCUT_ASSERT_NOT_NULL(flist->cursor);
    383         PCUT_ASSERT_STR_EQUALS("a", flist->cursor->name);
    384         PCUT_ASSERT_INT_EQUALS(1, flist->cursor->size);
    385173
    386174        ui_file_list_destroy(flist);
     
    417205
    418206        ui_file_list_set_rect(flist, &rect);
    419         PCUT_ASSERT_INT_EQUALS(rect.p0.x, flist->rect.p0.x);
    420         PCUT_ASSERT_INT_EQUALS(rect.p0.y, flist->rect.p0.y);
    421         PCUT_ASSERT_INT_EQUALS(rect.p1.x, flist->rect.p1.x);
    422         PCUT_ASSERT_INT_EQUALS(rect.p1.y, flist->rect.p1.y);
    423 
    424         ui_file_list_destroy(flist);
    425         ui_window_destroy(window);
    426         ui_destroy(ui);
    427 }
    428 
    429 /** ui_file_list_page_size() returns correct size */
    430 PCUT_TEST(page_size)
    431 {
    432         ui_t *ui;
    433         ui_window_t *window;
    434         ui_wnd_params_t params;
    435         ui_file_list_t *flist;
    436         gfx_rect_t rect;
    437         errno_t rc;
    438 
    439         rc = ui_create_disp(NULL, &ui);
    440         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    441 
    442         ui_wnd_params_init(&params);
    443         params.caption = "Test";
    444 
    445         rc = ui_window_create(ui, &params, &window);
    446         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    447 
    448         rc = ui_file_list_create(window, true, &flist);
    449         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    450 
    451         rect.p0.x = 10;
    452         rect.p0.y = 20;
    453         rect.p1.x = 50;
    454         rect.p1.y = 220;
    455 
    456         ui_file_list_set_rect(flist, &rect);
    457 
    458         /* NOTE If page size changes, we have problems elsewhere in the tests */
    459         PCUT_ASSERT_INT_EQUALS(11, ui_file_list_page_size(flist));
    460 
    461         ui_file_list_destroy(flist);
    462         ui_window_destroy(window);
    463         ui_destroy(ui);
    464 }
    465 
    466 /** ui_file_list_inside_rect() gives correct interior rectangle */
    467 PCUT_TEST(inside_rect)
    468 {
    469         ui_t *ui;
    470         ui_window_t *window;
    471         ui_wnd_params_t params;
    472         ui_file_list_t *flist;
    473         gfx_rect_t rect;
    474         gfx_rect_t irect;
    475         errno_t rc;
    476 
    477         rc = ui_create_disp(NULL, &ui);
    478         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    479 
    480         ui_wnd_params_init(&params);
    481         params.caption = "Test";
    482 
    483         rc = ui_window_create(ui, &params, &window);
    484         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    485 
    486         rc = ui_file_list_create(window, true, &flist);
    487         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    488 
    489         rect.p0.x = 10;
    490         rect.p0.y = 20;
    491         rect.p1.x = 50;
    492         rect.p1.y = 220;
    493 
    494         ui_file_list_set_rect(flist, &rect);
    495 
    496         ui_file_list_inside_rect(flist, &irect);
    497         PCUT_ASSERT_INT_EQUALS(10 + 2, irect.p0.x);
    498         PCUT_ASSERT_INT_EQUALS(20 + 2, irect.p0.y);
    499         PCUT_ASSERT_INT_EQUALS(50 - 2 - 23, irect.p1.x);
    500         PCUT_ASSERT_INT_EQUALS(220 - 2, irect.p1.y);
    501 
    502         ui_file_list_destroy(flist);
    503         ui_window_destroy(window);
    504         ui_destroy(ui);
    505 }
    506 
    507 /** ui_file_list_scrollbar_rect() gives correct scrollbar rectangle */
    508 PCUT_TEST(scrollbar_rect)
    509 {
    510         ui_t *ui;
    511         ui_window_t *window;
    512         ui_wnd_params_t params;
    513         ui_file_list_t *flist;
    514         gfx_rect_t rect;
    515         gfx_rect_t srect;
    516         errno_t rc;
    517 
    518         rc = ui_create_disp(NULL, &ui);
    519         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    520 
    521         ui_wnd_params_init(&params);
    522         params.caption = "Test";
    523 
    524         rc = ui_window_create(ui, &params, &window);
    525         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    526 
    527         rc = ui_file_list_create(window, true, &flist);
    528         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    529 
    530         rect.p0.x = 10;
    531         rect.p0.y = 20;
    532         rect.p1.x = 50;
    533         rect.p1.y = 220;
    534 
    535         ui_file_list_set_rect(flist, &rect);
    536 
    537         ui_file_list_scrollbar_rect(flist, &srect);
    538         PCUT_ASSERT_INT_EQUALS(50 - 2 - 23, srect.p0.x);
    539         PCUT_ASSERT_INT_EQUALS(20 + 2, srect.p0.y);
    540         PCUT_ASSERT_INT_EQUALS(50 - 2, srect.p1.x);
    541         PCUT_ASSERT_INT_EQUALS(220 - 2, srect.p1.y);
    542 
    543         ui_file_list_destroy(flist);
    544         ui_window_destroy(window);
    545         ui_destroy(ui);
    546 }
    547 
    548 /** ui_file_list_scrollbar_update() updates scrollbar position */
    549 PCUT_TEST(scrollbar_update)
    550 {
    551         ui_t *ui;
    552         ui_window_t *window;
    553         ui_wnd_params_t params;
    554         ui_file_list_t *flist;
    555         gfx_rect_t rect;
     207        PCUT_ASSERT_INT_EQUALS(rect.p0.x, flist->list->rect.p0.x);
     208        PCUT_ASSERT_INT_EQUALS(rect.p0.y, flist->list->rect.p0.y);
     209        PCUT_ASSERT_INT_EQUALS(rect.p1.x, flist->list->rect.p1.x);
     210        PCUT_ASSERT_INT_EQUALS(rect.p1.y, flist->list->rect.p1.y);
     211
     212        ui_file_list_destroy(flist);
     213        ui_window_destroy(window);
     214        ui_destroy(ui);
     215}
     216
     217/** ui_file_list_is_active() returns file list activity state */
     218PCUT_TEST(is_active)
     219{
     220        ui_t *ui;
     221        ui_window_t *window;
     222        ui_wnd_params_t params;
     223        ui_file_list_t *flist;
     224        errno_t rc;
     225
     226        rc = ui_create_disp(NULL, &ui);
     227        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     228
     229        ui_wnd_params_init(&params);
     230        params.caption = "Test";
     231
     232        rc = ui_window_create(ui, &params, &window);
     233        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     234
     235        rc = ui_file_list_create(window, true, &flist);
     236        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     237        PCUT_ASSERT_TRUE(ui_file_list_is_active(flist));
     238        ui_file_list_destroy(flist);
     239
     240        rc = ui_file_list_create(window, false, &flist);
     241        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     242        PCUT_ASSERT_FALSE(ui_file_list_is_active(flist));
     243        ui_file_list_destroy(flist);
     244        ui_window_destroy(window);
     245        ui_destroy(ui);
     246}
     247
     248/** ui_file_list_activate() activates file list */
     249PCUT_TEST(activate)
     250{
     251        ui_t *ui;
     252        ui_window_t *window;
     253        ui_wnd_params_t params;
     254        ui_file_list_t *flist;
     255        errno_t rc;
     256
     257        rc = ui_create_disp(NULL, &ui);
     258        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     259
     260        ui_wnd_params_init(&params);
     261        params.caption = "Test";
     262
     263        rc = ui_window_create(ui, &params, &window);
     264        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     265
     266        rc = ui_file_list_create(window, false, &flist);
     267        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     268
     269        PCUT_ASSERT_FALSE(ui_file_list_is_active(flist));
     270        rc = ui_file_list_activate(flist);
     271        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     272        PCUT_ASSERT_TRUE(ui_file_list_is_active(flist));
     273
     274        ui_file_list_destroy(flist);
     275        ui_window_destroy(window);
     276        ui_destroy(ui);
     277}
     278
     279/** ui_file_list_deactivate() deactivates file list */
     280PCUT_TEST(deactivate)
     281{
     282        ui_t *ui;
     283        ui_window_t *window;
     284        ui_wnd_params_t params;
     285        ui_file_list_t *flist;
     286        errno_t rc;
     287
     288        rc = ui_create_disp(NULL, &ui);
     289        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     290
     291        ui_wnd_params_init(&params);
     292        params.caption = "Test";
     293
     294        rc = ui_window_create(ui, &params, &window);
     295        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     296
     297        rc = ui_file_list_create(window, true, &flist);
     298        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     299
     300        PCUT_ASSERT_TRUE(ui_file_list_is_active(flist));
     301        ui_file_list_deactivate(flist);
     302        PCUT_ASSERT_FALSE(ui_file_list_is_active(flist));
     303
     304        ui_file_list_destroy(flist);
     305        ui_window_destroy(window);
     306        ui_destroy(ui);
     307}
     308
     309/** ui_file_list_entry_append() appends new entry */
     310PCUT_TEST(entry_append)
     311{
     312        ui_t *ui;
     313        ui_window_t *window;
     314        ui_wnd_params_t params;
     315        ui_file_list_t *flist;
    556316        ui_file_list_entry_attr_t attr;
     317        errno_t rc;
     318
     319        rc = ui_create_disp(NULL, &ui);
     320        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     321
     322        ui_wnd_params_init(&params);
     323        params.caption = "Test";
     324
     325        rc = ui_window_create(ui, &params, &window);
     326        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     327
     328        rc = ui_file_list_create(window, true, &flist);
     329        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     330
     331        ui_file_list_entry_attr_init(&attr);
     332
     333        attr.name = "a";
     334        attr.size = 1;
     335        rc = ui_file_list_entry_append(flist, &attr);
     336        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     337
     338        PCUT_ASSERT_INT_EQUALS(1, ui_list_entries_cnt(flist->list));
     339
     340        attr.name = "b";
     341        attr.size = 2;
     342        rc = ui_file_list_entry_append(flist, &attr);
     343        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     344
     345        PCUT_ASSERT_INT_EQUALS(2, ui_list_entries_cnt(flist->list));
     346
     347        ui_file_list_destroy(flist);
     348        ui_window_destroy(window);
     349        ui_destroy(ui);
     350}
     351
     352/** ui_file_list_entry_delete() deletes entry */
     353PCUT_TEST(entry_delete)
     354{
     355        ui_t *ui;
     356        ui_window_t *window;
     357        ui_wnd_params_t params;
     358        ui_file_list_t *flist;
    557359        ui_file_list_entry_t *entry;
    558         gfx_coord_t pos;
    559         gfx_coord_t move_len;
    560         errno_t rc;
    561 
    562         rc = ui_create_disp(NULL, &ui);
    563         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    564 
    565         ui_wnd_params_init(&params);
    566         params.caption = "Test";
    567 
    568         rc = ui_window_create(ui, &params, &window);
    569         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    570 
    571         rc = ui_file_list_create(window, true, &flist);
    572         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    573 
    574         rect.p0.x = 0;
    575         rect.p0.y = 0;
    576         rect.p1.x = 50;
    577         rect.p1.y = 38;
    578 
    579         ui_file_list_set_rect(flist, &rect);
     360        ui_file_list_entry_attr_t attr;
     361        errno_t rc;
     362
     363        rc = ui_create_disp(NULL, &ui);
     364        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     365
     366        ui_wnd_params_init(&params);
     367        params.caption = "Test";
     368
     369        rc = ui_window_create(ui, &params, &window);
     370        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     371
     372        rc = ui_file_list_create(window, true, &flist);
     373        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     374
     375        attr.name = "a";
     376        attr.size = 1;
     377        rc = ui_file_list_entry_append(flist, &attr);
     378        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     379
     380        attr.name = "b";
     381        attr.size = 2;
     382        rc = ui_file_list_entry_append(flist, &attr);
     383        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     384
     385        PCUT_ASSERT_INT_EQUALS(2, ui_list_entries_cnt(flist->list));
     386
     387        entry = ui_file_list_first(flist);
     388        ui_file_list_entry_delete(entry);
     389
     390        PCUT_ASSERT_INT_EQUALS(1, ui_list_entries_cnt(flist->list));
     391
     392        entry = ui_file_list_first(flist);
     393        ui_file_list_entry_delete(entry);
     394
     395        PCUT_ASSERT_INT_EQUALS(0, ui_list_entries_cnt(flist->list));
     396
     397        ui_file_list_destroy(flist);
     398        ui_window_destroy(window);
     399        ui_destroy(ui);
     400}
     401
     402/** ui_file_list_clear_entries() removes all entries from file list */
     403PCUT_TEST(clear_entries)
     404{
     405        ui_t *ui;
     406        ui_window_t *window;
     407        ui_wnd_params_t params;
     408        ui_file_list_t *flist;
     409        ui_file_list_entry_attr_t attr;
     410        errno_t rc;
     411
     412        rc = ui_create_disp(NULL, &ui);
     413        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     414
     415        ui_wnd_params_init(&params);
     416        params.caption = "Test";
     417
     418        rc = ui_window_create(ui, &params, &window);
     419        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     420
     421        rc = ui_file_list_create(window, true, &flist);
     422        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    580423
    581424        ui_file_list_entry_attr_init(&attr);
     
    585428        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    586429
    587         attr.name = "b";
    588         attr.size = 2;
    589         rc = ui_file_list_entry_append(flist, &attr);
    590         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    591 
    592         attr.name = "c";
    593         attr.size = 3;
    594         rc = ui_file_list_entry_append(flist, &attr);
    595         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    596 
    597         entry = ui_file_list_next(ui_file_list_first(flist));
    598 
    599         flist->cursor = entry;
    600         flist->cursor_idx = 1;
    601         flist->page = entry;
    602         flist->page_idx = 1;
    603 
    604         ui_file_list_scrollbar_update(flist);
    605 
    606         /* Now scrollbar thumb should be all the way down */
    607         move_len = ui_scrollbar_move_length(flist->scrollbar);
    608         pos = ui_scrollbar_get_pos(flist->scrollbar);
    609         PCUT_ASSERT_INT_EQUALS(move_len, pos);
    610 
    611         ui_file_list_destroy(flist);
    612         ui_window_destroy(window);
    613         ui_destroy(ui);
    614 }
    615 
    616 /** ui_file_list_is_active() returns file list activity state */
    617 PCUT_TEST(is_active)
    618 {
    619         ui_t *ui;
    620         ui_window_t *window;
    621         ui_wnd_params_t params;
    622         ui_file_list_t *flist;
    623         errno_t rc;
    624 
    625         rc = ui_create_disp(NULL, &ui);
    626         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    627 
    628         ui_wnd_params_init(&params);
    629         params.caption = "Test";
    630 
    631         rc = ui_window_create(ui, &params, &window);
    632         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    633 
    634         rc = ui_file_list_create(window, true, &flist);
    635         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    636         PCUT_ASSERT_TRUE(ui_file_list_is_active(flist));
    637         ui_file_list_destroy(flist);
    638 
    639         rc = ui_file_list_create(window, false, &flist);
    640         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    641         PCUT_ASSERT_FALSE(ui_file_list_is_active(flist));
    642         ui_file_list_destroy(flist);
    643         ui_window_destroy(window);
    644         ui_destroy(ui);
    645 }
    646 
    647 /** ui_file_list_activate() activates file list */
    648 PCUT_TEST(activate)
    649 {
    650         ui_t *ui;
    651         ui_window_t *window;
    652         ui_wnd_params_t params;
    653         ui_file_list_t *flist;
    654         errno_t rc;
    655 
    656         rc = ui_create_disp(NULL, &ui);
    657         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    658 
    659         ui_wnd_params_init(&params);
    660         params.caption = "Test";
    661 
    662         rc = ui_window_create(ui, &params, &window);
    663         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    664 
    665         rc = ui_file_list_create(window, false, &flist);
    666         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    667 
    668         PCUT_ASSERT_FALSE(ui_file_list_is_active(flist));
    669         rc = ui_file_list_activate(flist);
    670         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    671         PCUT_ASSERT_TRUE(ui_file_list_is_active(flist));
    672 
    673         ui_file_list_destroy(flist);
    674         ui_window_destroy(window);
    675         ui_destroy(ui);
    676 }
    677 
    678 /** ui_file_list_deactivate() deactivates file list */
    679 PCUT_TEST(deactivate)
    680 {
    681         ui_t *ui;
    682         ui_window_t *window;
    683         ui_wnd_params_t params;
    684         ui_file_list_t *flist;
    685         errno_t rc;
    686 
    687         rc = ui_create_disp(NULL, &ui);
    688         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    689 
    690         ui_wnd_params_init(&params);
    691         params.caption = "Test";
    692 
    693         rc = ui_window_create(ui, &params, &window);
    694         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    695 
    696         rc = ui_file_list_create(window, true, &flist);
    697         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    698 
    699         PCUT_ASSERT_TRUE(ui_file_list_is_active(flist));
    700         ui_file_list_deactivate(flist);
    701         PCUT_ASSERT_FALSE(ui_file_list_is_active(flist));
    702 
    703         ui_file_list_destroy(flist);
    704         ui_window_destroy(window);
    705         ui_destroy(ui);
    706 }
    707 
    708 /** ui_file_list_entry_append() appends new entry */
    709 PCUT_TEST(entry_append)
    710 {
    711         ui_t *ui;
    712         ui_window_t *window;
    713         ui_wnd_params_t params;
    714         ui_file_list_t *flist;
    715         ui_file_list_entry_attr_t attr;
    716         errno_t rc;
    717 
    718         rc = ui_create_disp(NULL, &ui);
    719         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    720 
    721         ui_wnd_params_init(&params);
    722         params.caption = "Test";
    723 
    724         rc = ui_window_create(ui, &params, &window);
    725         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    726 
    727         rc = ui_file_list_create(window, true, &flist);
    728         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    729 
    730         ui_file_list_entry_attr_init(&attr);
    731 
    732         attr.name = "a";
    733         attr.size = 1;
    734         rc = ui_file_list_entry_append(flist, &attr);
    735         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    736 
    737         PCUT_ASSERT_INT_EQUALS(1, list_count(&flist->entries));
    738 
    739         attr.name = "b";
    740         attr.size = 2;
    741         rc = ui_file_list_entry_append(flist, &attr);
    742         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    743 
    744         PCUT_ASSERT_INT_EQUALS(2, list_count(&flist->entries));
    745 
    746         ui_file_list_destroy(flist);
    747         ui_window_destroy(window);
    748         ui_destroy(ui);
    749 }
    750 
    751 /** ui_file_list_entry_delete() deletes entry */
    752 PCUT_TEST(entry_delete)
    753 {
    754         ui_t *ui;
    755         ui_window_t *window;
    756         ui_wnd_params_t params;
    757         ui_file_list_t *flist;
    758         ui_file_list_entry_t *entry;
    759         ui_file_list_entry_attr_t attr;
    760         errno_t rc;
    761 
    762         rc = ui_create_disp(NULL, &ui);
    763         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    764 
    765         ui_wnd_params_init(&params);
    766         params.caption = "Test";
    767 
    768         rc = ui_window_create(ui, &params, &window);
    769         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    770 
    771         rc = ui_file_list_create(window, true, &flist);
    772         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    773 
    774         attr.name = "a";
    775         attr.size = 1;
    776         rc = ui_file_list_entry_append(flist, &attr);
    777         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    778 
    779         attr.name = "b";
    780         attr.size = 2;
    781         rc = ui_file_list_entry_append(flist, &attr);
    782         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    783 
    784         PCUT_ASSERT_INT_EQUALS(2, list_count(&flist->entries));
    785 
    786         entry = ui_file_list_first(flist);
    787         ui_file_list_entry_delete(entry);
    788 
    789         PCUT_ASSERT_INT_EQUALS(1, list_count(&flist->entries));
    790 
    791         entry = ui_file_list_first(flist);
    792         ui_file_list_entry_delete(entry);
    793 
    794         PCUT_ASSERT_INT_EQUALS(0, list_count(&flist->entries));
    795 
    796         ui_file_list_destroy(flist);
    797         ui_window_destroy(window);
    798         ui_destroy(ui);
    799 }
    800 
    801 /** ui_file_list_clear_entries() removes all entries from file list */
    802 PCUT_TEST(clear_entries)
    803 {
    804         ui_t *ui;
    805         ui_window_t *window;
    806         ui_wnd_params_t params;
    807         ui_file_list_t *flist;
    808         ui_file_list_entry_attr_t attr;
    809         errno_t rc;
    810 
    811         rc = ui_create_disp(NULL, &ui);
    812         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    813 
    814         ui_wnd_params_init(&params);
    815         params.caption = "Test";
    816 
    817         rc = ui_window_create(ui, &params, &window);
    818         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    819 
    820         rc = ui_file_list_create(window, true, &flist);
    821         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    822 
    823         ui_file_list_entry_attr_init(&attr);
    824         attr.name = "a";
    825         attr.size = 1;
    826         rc = ui_file_list_entry_append(flist, &attr);
    827         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    828 
    829430        attr.name = "a";
    830431        attr.size = 2;
     
    832433        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    833434
    834         PCUT_ASSERT_INT_EQUALS(2, list_count(&flist->entries));
     435        PCUT_ASSERT_INT_EQUALS(2, ui_list_entries_cnt(flist->list));
    835436
    836437        ui_file_list_clear_entries(flist);
    837         PCUT_ASSERT_INT_EQUALS(0, list_count(&flist->entries));
     438        PCUT_ASSERT_INT_EQUALS(0, ui_list_entries_cnt(flist->list));
    838439
    839440        ui_file_list_destroy(flist);
     
    892493        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    893494
    894         PCUT_ASSERT_INT_EQUALS(2, list_count(&flist->entries));
     495        PCUT_ASSERT_INT_EQUALS(2, ui_list_entries_cnt(flist->list));
    895496
    896497        entry = ui_file_list_first(flist);
     
    979580        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    980581
    981         PCUT_ASSERT_NOT_NULL(flist->cursor);
    982         PCUT_ASSERT_STR_EQUALS("b", flist->cursor->name);
     582        PCUT_ASSERT_NOT_NULL(ui_file_list_get_cursor(flist));
     583        PCUT_ASSERT_STR_EQUALS("b", ui_file_list_get_cursor(flist)->name);
    983584
    984585        ui_file_list_destroy(flist);
     
    1064665}
    1065666
    1066 /** ui_file_list_entry_ptr_cmp compares two indirectly referenced entries */
    1067 PCUT_TEST(entry_ptr_cmp)
     667/** ui_file_list_list_compare compares two file list entries */
     668PCUT_TEST(list_compare)
    1068669{
    1069670        ui_t *ui;
     
    1106707
    1107708        /* a < b */
    1108         rel = ui_file_list_entry_ptr_cmp(&a, &b);
     709        rel = ui_file_list_list_compare(a->entry, b->entry);
    1109710        PCUT_ASSERT_TRUE(rel < 0);
    1110711
    1111712        /* b > a */
    1112         rel = ui_file_list_entry_ptr_cmp(&b, &a);
     713        rel = ui_file_list_list_compare(b->entry, a->entry);
    1113714        PCUT_ASSERT_TRUE(rel > 0);
    1114715
    1115716        /* a == a */
    1116         rel = ui_file_list_entry_ptr_cmp(&a, &a);
     717        rel = ui_file_list_list_compare(a->entry, a->entry);
    1117718        PCUT_ASSERT_INT_EQUALS(0, rel);
    1118719
     
    1120721        ui_window_destroy(window);
    1121722        ui_destroy(ui);
     723}
     724
     725/** ui_file_list_entry_attr_init() initializes file list attribute structure */
     726PCUT_TEST(entry_attr_init)
     727{
     728        ui_file_list_entry_attr_t attr;
     729
     730        ui_file_list_entry_attr_init(&attr);
     731        PCUT_ASSERT_NULL(attr.name);
     732        PCUT_ASSERT_INT_EQUALS(0, attr.size);
     733        PCUT_ASSERT_EQUALS(false, attr.isdir);
     734        PCUT_ASSERT_INT_EQUALS(0, attr.svc);
    1122735}
    1123736
     
    1354967}
    1355968
    1356 /** ui_file_list_page_nth_entry() .. */
    1357 PCUT_TEST(page_nth_entry)
    1358 {
    1359         ui_t *ui;
    1360         ui_window_t *window;
    1361         ui_wnd_params_t params;
    1362         ui_file_list_t *flist;
    1363         ui_file_list_entry_t *entry;
    1364         ui_file_list_entry_attr_t attr;
    1365         gfx_rect_t rect;
    1366         size_t idx;
    1367         errno_t rc;
    1368 
    1369         rc = ui_create_disp(NULL, &ui);
    1370         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1371 
    1372         ui_wnd_params_init(&params);
    1373         params.caption = "Test";
    1374 
    1375         rc = ui_window_create(ui, &params, &window);
    1376         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1377 
    1378         rc = ui_file_list_create(window, true, &flist);
    1379         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1380 
    1381         ui_file_list_entry_attr_init(&attr);
    1382 
    1383         /* Add some entries */
    1384         attr.name = "a";
    1385         attr.size = 1;
    1386         rc = ui_file_list_entry_append(flist, &attr);
    1387         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1388 
    1389         attr.name = "b";
    1390         attr.size = 2;
    1391         rc = ui_file_list_entry_append(flist, &attr);
    1392         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1393 
    1394         attr.name = "c";
    1395         attr.size = 3;
    1396         rc = ui_file_list_entry_append(flist, &attr);
    1397         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1398 
    1399         flist->page = ui_file_list_next(ui_file_list_first(flist));
    1400         flist->page_idx = 1;
    1401 
    1402         rect.p0.x = 0;
    1403         rect.p0.y = 0;
    1404         rect.p1.x = 100;
    1405         rect.p1.y = 100;
    1406         ui_file_list_set_rect(flist, &rect);
    1407 
    1408         entry = ui_file_list_page_nth_entry(flist, 0, &idx);
    1409         PCUT_ASSERT_NOT_NULL(entry);
    1410         PCUT_ASSERT_STR_EQUALS("b", entry->name);
    1411         PCUT_ASSERT_INT_EQUALS(1, idx);
    1412 
    1413         entry = ui_file_list_page_nth_entry(flist, 1, &idx);
    1414         PCUT_ASSERT_NOT_NULL(entry);
    1415         PCUT_ASSERT_STR_EQUALS("c", entry->name);
    1416         PCUT_ASSERT_INT_EQUALS(2, idx);
    1417 
    1418         entry = ui_file_list_page_nth_entry(flist, 2, &idx);
    1419         PCUT_ASSERT_NULL(entry);
    1420 
    1421         ui_file_list_destroy(flist);
    1422         ui_window_destroy(window);
    1423         ui_destroy(ui);
    1424 }
    1425 
    1426 /** ui_file_list_cursor_move() moves cursor and scrolls */
    1427 PCUT_TEST(cursor_move)
    1428 {
    1429         ui_t *ui;
    1430         ui_window_t *window;
    1431         ui_wnd_params_t params;
    1432         ui_file_list_t *flist;
    1433         ui_file_list_entry_attr_t attr;
    1434         gfx_rect_t rect;
    1435         errno_t rc;
    1436         rc = ui_create_disp(NULL, &ui);
    1437         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1438 
    1439         ui_wnd_params_init(&params);
    1440         params.caption = "Test";
    1441 
    1442         rc = ui_window_create(ui, &params, &window);
    1443         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1444 
    1445         rc = ui_file_list_create(window, true, &flist);
    1446         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1447 
    1448         rect.p0.x = 0;
    1449         rect.p0.y = 0;
    1450         rect.p1.x = 10;
    1451         rect.p1.y = 38; /* Assuming this makes page size 2 */
    1452         ui_file_list_set_rect(flist, &rect);
    1453 
    1454         PCUT_ASSERT_INT_EQUALS(2, ui_file_list_page_size(flist));
    1455 
    1456         /* Add tree entries (more than page size, which is 2) */
    1457 
    1458         ui_file_list_entry_attr_init(&attr);
    1459 
    1460         attr.name = "a";
    1461         attr.size = 1;
    1462         rc = ui_file_list_entry_append(flist, &attr);
    1463         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1464 
    1465         attr.name = "b";
    1466         attr.size = 2;
    1467         rc = ui_file_list_entry_append(flist, &attr);
    1468         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1469 
    1470         attr.name = "c";
    1471         attr.size = 3;
    1472         rc = ui_file_list_entry_append(flist, &attr);
    1473         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1474 
    1475         /* Cursor to the last entry and page start to the next-to-last entry */
    1476         flist->cursor = ui_file_list_last(flist);
    1477         flist->cursor_idx = 2;
    1478         flist->page = ui_file_list_prev(flist->cursor);
    1479         flist->page_idx = 1;
    1480 
    1481         /* Move cursor one entry up */
    1482         ui_file_list_cursor_move(flist, ui_file_list_prev(flist->cursor),
    1483             flist->cursor_idx - 1);
    1484 
    1485         /* Cursor and page start should now both be at the second entry */
    1486         PCUT_ASSERT_STR_EQUALS("b", flist->cursor->name);
    1487         PCUT_ASSERT_INT_EQUALS(2, flist->cursor->size);
    1488         PCUT_ASSERT_INT_EQUALS(1, flist->cursor_idx);
    1489         PCUT_ASSERT_EQUALS(flist->cursor, flist->page);
    1490         PCUT_ASSERT_INT_EQUALS(1, flist->page_idx);
    1491 
    1492         /* Move cursor to the first entry. This should scroll up. */
    1493         ui_file_list_cursor_move(flist, ui_file_list_first(flist), 0);
    1494 
    1495         /* Cursor and page start should now both be at the first entry */
    1496         PCUT_ASSERT_STR_EQUALS("a", flist->cursor->name);
    1497         PCUT_ASSERT_INT_EQUALS(1, flist->cursor->size);
    1498         PCUT_ASSERT_INT_EQUALS(0, flist->cursor_idx);
    1499         PCUT_ASSERT_EQUALS(flist->cursor, flist->page);
    1500         PCUT_ASSERT_INT_EQUALS(0, flist->page_idx);
    1501 
    1502         /* Move cursor to the last entry. */
    1503         ui_file_list_cursor_move(flist, ui_file_list_last(flist), 2);
    1504 
    1505         /* Cursor should be on the last entry and page on the next to last */
    1506         PCUT_ASSERT_STR_EQUALS("c", flist->cursor->name);
    1507         PCUT_ASSERT_INT_EQUALS(3, flist->cursor->size);
    1508         PCUT_ASSERT_INT_EQUALS(2, flist->cursor_idx);
    1509         PCUT_ASSERT_STR_EQUALS("b", flist->page->name);
    1510         PCUT_ASSERT_INT_EQUALS(2, flist->page->size);
    1511         PCUT_ASSERT_INT_EQUALS(1, flist->page_idx);
    1512 
    1513         ui_file_list_destroy(flist);
    1514         ui_window_destroy(window);
    1515         ui_destroy(ui);
    1516 }
    1517 
    1518 /** ui_file_list_cursor_up() moves cursor one entry up */
    1519 PCUT_TEST(cursor_up)
    1520 {
    1521         ui_t *ui;
    1522         ui_window_t *window;
    1523         ui_wnd_params_t params;
    1524         ui_file_list_t *flist;
    1525         ui_file_list_entry_attr_t attr;
    1526         gfx_rect_t rect;
    1527         errno_t rc;
    1528         rc = ui_create_disp(NULL, &ui);
    1529         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1530 
    1531         ui_wnd_params_init(&params);
    1532         params.caption = "Test";
    1533 
    1534         rc = ui_window_create(ui, &params, &window);
    1535         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1536 
    1537         rc = ui_file_list_create(window, true, &flist);
    1538         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1539 
    1540         rect.p0.x = 0;
    1541         rect.p0.y = 0;
    1542         rect.p1.x = 10;
    1543         rect.p1.y = 38; /* Assuming this makes page size 2 */
    1544         ui_file_list_set_rect(flist, &rect);
    1545 
    1546         PCUT_ASSERT_INT_EQUALS(2, ui_file_list_page_size(flist));
    1547 
    1548         /* Add tree entries (more than page size, which is 2) */
    1549 
    1550         ui_file_list_entry_attr_init(&attr);
    1551 
    1552         attr.name = "a";
    1553         attr.size = 1;
    1554         rc = ui_file_list_entry_append(flist, &attr);
    1555         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1556 
    1557         attr.name = "b";
    1558         attr.size = 2;
    1559         rc = ui_file_list_entry_append(flist, &attr);
    1560         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1561 
    1562         attr.name = "c";
    1563         attr.size = 3;
    1564         rc = ui_file_list_entry_append(flist, &attr);
    1565         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1566 
    1567         /* Cursor to the last entry and page start to the next-to-last entry */
    1568         flist->cursor = ui_file_list_last(flist);
    1569         flist->cursor_idx = 2;
    1570         flist->page = ui_file_list_prev(flist->cursor);
    1571         flist->page_idx = 1;
    1572 
    1573         /* Move cursor one entry up */
    1574         ui_file_list_cursor_up(flist);
    1575 
    1576         /* Cursor and page start should now both be at the second entry */
    1577         PCUT_ASSERT_STR_EQUALS("b", flist->cursor->name);
    1578         PCUT_ASSERT_INT_EQUALS(2, flist->cursor->size);
    1579         PCUT_ASSERT_INT_EQUALS(1, flist->cursor_idx);
    1580         PCUT_ASSERT_EQUALS(flist->cursor, flist->page);
    1581         PCUT_ASSERT_INT_EQUALS(1, flist->page_idx);
    1582 
    1583         /* Move cursor one entry up. This should scroll up. */
    1584         ui_file_list_cursor_up(flist);
    1585 
    1586         /* Cursor and page start should now both be at the first entry */
    1587         PCUT_ASSERT_STR_EQUALS("a", flist->cursor->name);
    1588         PCUT_ASSERT_INT_EQUALS(1, flist->cursor->size);
    1589         PCUT_ASSERT_INT_EQUALS(0, flist->cursor_idx);
    1590         PCUT_ASSERT_EQUALS(flist->cursor, flist->page);
    1591         PCUT_ASSERT_INT_EQUALS(0, flist->page_idx);
    1592 
    1593         /* Moving further up should do nothing (we are at the top). */
    1594         ui_file_list_cursor_up(flist);
    1595 
    1596         /* Cursor and page start should still be at the first entry */
    1597         PCUT_ASSERT_STR_EQUALS("a", flist->cursor->name);
    1598         PCUT_ASSERT_INT_EQUALS(1, flist->cursor->size);
    1599         PCUT_ASSERT_INT_EQUALS(0, flist->cursor_idx);
    1600         PCUT_ASSERT_EQUALS(flist->cursor, flist->page);
    1601         PCUT_ASSERT_INT_EQUALS(0, flist->page_idx);
    1602 
    1603         ui_file_list_destroy(flist);
    1604         ui_window_destroy(window);
    1605         ui_destroy(ui);
    1606 }
    1607 
    1608 /** ui_file_list_cursor_down() moves cursor one entry down */
    1609 PCUT_TEST(cursor_down)
    1610 {
    1611         ui_t *ui;
    1612         ui_window_t *window;
    1613         ui_wnd_params_t params;
    1614         ui_file_list_t *flist;
    1615         ui_file_list_entry_attr_t attr;
    1616         gfx_rect_t rect;
    1617         errno_t rc;
    1618 
    1619         rc = ui_create_disp(NULL, &ui);
    1620         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1621 
    1622         ui_wnd_params_init(&params);
    1623         params.caption = "Test";
    1624 
    1625         rc = ui_window_create(ui, &params, &window);
    1626         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1627 
    1628         rc = ui_file_list_create(window, true, &flist);
    1629         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1630 
    1631         rect.p0.x = 0;
    1632         rect.p0.y = 0;
    1633         rect.p1.x = 10;
    1634         rect.p1.y = 38; /* Assuming this makes page size 2 */
    1635         ui_file_list_set_rect(flist, &rect);
    1636 
    1637         PCUT_ASSERT_INT_EQUALS(2, ui_file_list_page_size(flist));
    1638 
    1639         /* Add tree entries (more than page size, which is 2) */
    1640 
    1641         ui_file_list_entry_attr_init(&attr);
    1642 
    1643         attr.name = "a";
    1644         attr.size = 1;
    1645         rc = ui_file_list_entry_append(flist, &attr);
    1646         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1647 
    1648         attr.name = "b";
    1649         attr.size = 2;
    1650         rc = ui_file_list_entry_append(flist, &attr);
    1651         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1652 
    1653         attr.name = "c";
    1654         attr.size = 3;
    1655         rc = ui_file_list_entry_append(flist, &attr);
    1656         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1657 
    1658         /* Cursor and page start to the first entry */
    1659         flist->cursor = ui_file_list_first(flist);
    1660         flist->cursor_idx = 0;
    1661         flist->page = flist->cursor;
    1662         flist->page_idx = 0;
    1663 
    1664         /* Move cursor one entry down */
    1665         ui_file_list_cursor_down(flist);
    1666 
    1667         /* Cursor should now be at the second entry, page stays the same */
    1668         PCUT_ASSERT_STR_EQUALS("b", flist->cursor->name);
    1669         PCUT_ASSERT_INT_EQUALS(2, flist->cursor->size);
    1670         PCUT_ASSERT_INT_EQUALS(1, flist->cursor_idx);
    1671         PCUT_ASSERT_EQUALS(ui_file_list_first(flist), flist->page);
    1672         PCUT_ASSERT_INT_EQUALS(0, flist->page_idx);
    1673 
    1674         /* Move cursor one entry down. This should scroll down. */
    1675         ui_file_list_cursor_down(flist);
    1676 
    1677         /* Cursor should now be at the third and page at the second entry. */
    1678         PCUT_ASSERT_STR_EQUALS("c", flist->cursor->name);
    1679         PCUT_ASSERT_INT_EQUALS(3, flist->cursor->size);
    1680         PCUT_ASSERT_INT_EQUALS(2, flist->cursor_idx);
    1681         PCUT_ASSERT_STR_EQUALS("b", flist->page->name);
    1682         PCUT_ASSERT_INT_EQUALS(2, flist->page->size);
    1683         PCUT_ASSERT_INT_EQUALS(1, flist->page_idx);
    1684 
    1685         /* Moving further down should do nothing (we are at the bottom). */
    1686         ui_file_list_cursor_down(flist);
    1687 
    1688         /* Cursor should still be at the third and page at the second entry. */
    1689         PCUT_ASSERT_STR_EQUALS("c", flist->cursor->name);
    1690         PCUT_ASSERT_INT_EQUALS(3, flist->cursor->size);
    1691         PCUT_ASSERT_INT_EQUALS(2, flist->cursor_idx);
    1692         PCUT_ASSERT_STR_EQUALS("b", flist->page->name);
    1693         PCUT_ASSERT_INT_EQUALS(2, flist->page->size);
    1694         PCUT_ASSERT_INT_EQUALS(1, flist->page_idx);
    1695 
    1696         ui_file_list_destroy(flist);
    1697         ui_window_destroy(window);
    1698         ui_destroy(ui);
    1699 }
    1700 
    1701 /** ui_file_list_cursor_top() moves cursor to the first entry */
    1702 PCUT_TEST(cursor_top)
    1703 {
    1704         ui_t *ui;
    1705         ui_window_t *window;
    1706         ui_wnd_params_t params;
    1707         ui_file_list_t *flist;
    1708         ui_file_list_entry_attr_t attr;
    1709         gfx_rect_t rect;
    1710         errno_t rc;
    1711 
    1712         rc = ui_create_disp(NULL, &ui);
    1713         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1714 
    1715         ui_wnd_params_init(&params);
    1716         params.caption = "Test";
    1717 
    1718         rc = ui_window_create(ui, &params, &window);
    1719         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1720 
    1721         rc = ui_file_list_create(window, true, &flist);
    1722         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1723 
    1724         rect.p0.x = 0;
    1725         rect.p0.y = 0;
    1726         rect.p1.x = 10;
    1727         rect.p1.y = 38; /* Assuming this makes page size 2 */
    1728         ui_file_list_set_rect(flist, &rect);
    1729 
    1730         PCUT_ASSERT_INT_EQUALS(2, ui_file_list_page_size(flist));
    1731 
    1732         /* Add tree entries (more than page size, which is 2) */
    1733 
    1734         ui_file_list_entry_attr_init(&attr);
    1735 
    1736         attr.name = "a";
    1737         attr.size = 1;
    1738         rc = ui_file_list_entry_append(flist, &attr);
    1739         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1740 
    1741         attr.name = "b";
    1742         attr.size = 2;
    1743         rc = ui_file_list_entry_append(flist, &attr);
    1744         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1745 
    1746         attr.name = "c";
    1747         attr.size = 3;
    1748         rc = ui_file_list_entry_append(flist, &attr);
    1749         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1750 
    1751         /* Cursor to the last entry and page start to the next-to-last entry */
    1752         flist->cursor = ui_file_list_last(flist);
    1753         flist->cursor_idx = 2;
    1754         flist->page = ui_file_list_prev(flist->cursor);
    1755         flist->page_idx = 1;
    1756 
    1757         /* Move cursor to the top. This should scroll up. */
    1758         ui_file_list_cursor_top(flist);
    1759 
    1760         /* Cursor and page start should now both be at the first entry */
    1761         PCUT_ASSERT_STR_EQUALS("a", flist->cursor->name);
    1762         PCUT_ASSERT_INT_EQUALS(1, flist->cursor->size);
    1763         PCUT_ASSERT_INT_EQUALS(0, flist->cursor_idx);
    1764         PCUT_ASSERT_EQUALS(flist->cursor, flist->page);
    1765         PCUT_ASSERT_INT_EQUALS(0, flist->page_idx);
    1766 
    1767         ui_file_list_destroy(flist);
    1768         ui_window_destroy(window);
    1769         ui_destroy(ui);
    1770 }
    1771 
    1772 /** ui_file_list_cursor_bottom() moves cursor to the last entry */
    1773 PCUT_TEST(cursor_bottom)
    1774 {
    1775         ui_t *ui;
    1776         ui_window_t *window;
    1777         ui_wnd_params_t params;
    1778         ui_file_list_t *flist;
    1779         ui_file_list_entry_attr_t attr;
    1780         gfx_rect_t rect;
    1781         errno_t rc;
    1782 
    1783         rc = ui_create_disp(NULL, &ui);
    1784         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1785 
    1786         ui_wnd_params_init(&params);
    1787         params.caption = "Test";
    1788 
    1789         rc = ui_window_create(ui, &params, &window);
    1790         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1791 
    1792         rc = ui_file_list_create(window, true, &flist);
    1793         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1794 
    1795         rect.p0.x = 0;
    1796         rect.p0.y = 0;
    1797         rect.p1.x = 10;
    1798         rect.p1.y = 38; /* Assuming this makes page size 2 */
    1799         ui_file_list_set_rect(flist, &rect);
    1800 
    1801         PCUT_ASSERT_INT_EQUALS(2, ui_file_list_page_size(flist));
    1802 
    1803         /* Add tree entries (more than page size, which is 2) */
    1804 
    1805         ui_file_list_entry_attr_init(&attr);
    1806 
    1807         attr.name = "a";
    1808         attr.size = 1;
    1809         rc = ui_file_list_entry_append(flist, &attr);
    1810         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1811 
    1812         attr.name = "b";
    1813         attr.size = 2;
    1814         rc = ui_file_list_entry_append(flist, &attr);
    1815         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1816 
    1817         attr.name = "c";
    1818         attr.size = 3;
    1819         rc = ui_file_list_entry_append(flist, &attr);
    1820         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1821 
    1822         /* Cursor and page start to the first entry */
    1823         flist->cursor = ui_file_list_first(flist);
    1824         flist->cursor_idx = 0;
    1825         flist->page = flist->cursor;
    1826         flist->page_idx = 0;
    1827 
    1828         /* Move cursor to the bottom. This should scroll down. */
    1829         ui_file_list_cursor_bottom(flist);
    1830 
    1831         /* Cursor should now be at the third and page at the second entry. */
    1832         PCUT_ASSERT_STR_EQUALS("c", flist->cursor->name);
    1833         PCUT_ASSERT_INT_EQUALS(3, flist->cursor->size);
    1834         PCUT_ASSERT_INT_EQUALS(2, flist->cursor_idx);
    1835         PCUT_ASSERT_STR_EQUALS("b", flist->page->name);
    1836         PCUT_ASSERT_INT_EQUALS(2, flist->page->size);
    1837         PCUT_ASSERT_INT_EQUALS(1, flist->page_idx);
    1838 
    1839         ui_file_list_destroy(flist);
    1840         ui_window_destroy(window);
    1841         ui_destroy(ui);
    1842 }
    1843 
    1844 /** ui_file_list_page_up() moves one page up */
    1845 PCUT_TEST(page_up)
    1846 {
    1847         ui_t *ui;
    1848         ui_window_t *window;
    1849         ui_wnd_params_t params;
    1850         ui_file_list_t *flist;
    1851         ui_file_list_entry_attr_t attr;
    1852         gfx_rect_t rect;
    1853         errno_t rc;
    1854 
    1855         rc = ui_create_disp(NULL, &ui);
    1856         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1857 
    1858         ui_wnd_params_init(&params);
    1859         params.caption = "Test";
    1860 
    1861         rc = ui_window_create(ui, &params, &window);
    1862         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1863 
    1864         rc = ui_file_list_create(window, true, &flist);
    1865         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1866 
    1867         rect.p0.x = 0;
    1868         rect.p0.y = 0;
    1869         rect.p1.x = 10;
    1870         rect.p1.y = 38; /* Assuming this makes page size 2 */
    1871         ui_file_list_set_rect(flist, &rect);
    1872 
    1873         PCUT_ASSERT_INT_EQUALS(2, ui_file_list_page_size(flist));
    1874 
    1875         /* Add five entries (2 full pages, one partial) */
    1876 
    1877         ui_file_list_entry_attr_init(&attr);
    1878 
    1879         attr.name = "a";
    1880         attr.size = 1;
    1881         rc = ui_file_list_entry_append(flist, &attr);
    1882         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1883 
    1884         attr.name = "b";
    1885         attr.size = 2;
    1886         rc = ui_file_list_entry_append(flist, &attr);
    1887         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1888 
    1889         attr.name = "c";
    1890         attr.size = 3;
    1891         rc = ui_file_list_entry_append(flist, &attr);
    1892         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1893 
    1894         attr.name = "d";
    1895         attr.size = 4;
    1896         rc = ui_file_list_entry_append(flist, &attr);
    1897         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1898 
    1899         attr.name = "e";
    1900         attr.size = 5;
    1901         rc = ui_file_list_entry_append(flist, &attr);
    1902         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1903 
    1904         /* Cursor to the last entry and page start to the next-to-last entry */
    1905         flist->cursor = ui_file_list_last(flist);
    1906         flist->cursor_idx = 4;
    1907         flist->page = ui_file_list_prev(flist->cursor);
    1908         flist->page_idx = 3;
    1909 
    1910         /* Move one page up */
    1911         ui_file_list_page_up(flist);
    1912 
    1913         /* Page should now start at second entry and cursor at third */
    1914         PCUT_ASSERT_STR_EQUALS("c", flist->cursor->name);
    1915         PCUT_ASSERT_INT_EQUALS(3, flist->cursor->size);
    1916         PCUT_ASSERT_INT_EQUALS(2, flist->cursor_idx);
    1917         PCUT_ASSERT_STR_EQUALS("b", flist->page->name);
    1918         PCUT_ASSERT_INT_EQUALS(2, flist->page->size);
    1919         PCUT_ASSERT_INT_EQUALS(1, flist->page_idx);
    1920 
    1921         /* Move one page up again. */
    1922         ui_file_list_page_up(flist);
    1923 
    1924         /* Cursor and page start should now both be at the first entry */
    1925         PCUT_ASSERT_STR_EQUALS("a", flist->cursor->name);
    1926         PCUT_ASSERT_INT_EQUALS(1, flist->cursor->size);
    1927         PCUT_ASSERT_INT_EQUALS(0, flist->cursor_idx);
    1928         PCUT_ASSERT_EQUALS(flist->cursor, flist->page);
    1929         PCUT_ASSERT_INT_EQUALS(0, flist->page_idx);
    1930 
    1931         /* Moving further up should do nothing (we are at the top). */
    1932         ui_file_list_page_up(flist);
    1933 
    1934         /* Cursor and page start should still be at the first entry */
    1935         PCUT_ASSERT_STR_EQUALS("a", flist->cursor->name);
    1936         PCUT_ASSERT_INT_EQUALS(1, flist->cursor->size);
    1937         PCUT_ASSERT_INT_EQUALS(0, flist->cursor_idx);
    1938         PCUT_ASSERT_EQUALS(flist->cursor, flist->page);
    1939         PCUT_ASSERT_INT_EQUALS(0, flist->page_idx);
    1940 
    1941         ui_file_list_destroy(flist);
    1942         ui_window_destroy(window);
    1943         ui_destroy(ui);
    1944 }
    1945 
    1946 /** ui_file_list_page_up() moves one page down */
    1947 PCUT_TEST(page_down)
    1948 {
    1949         ui_t *ui;
    1950         ui_window_t *window;
    1951         ui_wnd_params_t params;
    1952         ui_file_list_t *flist;
    1953         ui_file_list_entry_attr_t attr;
    1954         gfx_rect_t rect;
    1955         errno_t rc;
    1956 
    1957         rc = ui_create_disp(NULL, &ui);
    1958         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1959 
    1960         ui_wnd_params_init(&params);
    1961         params.caption = "Test";
    1962 
    1963         rc = ui_window_create(ui, &params, &window);
    1964         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1965 
    1966         rc = ui_file_list_create(window, true, &flist);
    1967         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1968 
    1969         rect.p0.x = 0;
    1970         rect.p0.y = 0;
    1971         rect.p1.x = 10;
    1972         rect.p1.y = 38; /* Assuming this makes page size 2 */
    1973         ui_file_list_set_rect(flist, &rect);
    1974 
    1975         PCUT_ASSERT_INT_EQUALS(2, ui_file_list_page_size(flist));
    1976 
    1977         /* Add five entries (2 full pages, one partial) */
    1978 
    1979         ui_file_list_entry_attr_init(&attr);
    1980 
    1981         attr.name = "a";
    1982         attr.size = 1;
    1983         rc = ui_file_list_entry_append(flist, &attr);
    1984         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1985 
    1986         attr.name = "b";
    1987         attr.size = 2;
    1988         rc = ui_file_list_entry_append(flist, &attr);
    1989         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1990 
    1991         attr.name = "c";
    1992         attr.size = 3;
    1993         rc = ui_file_list_entry_append(flist, &attr);
    1994         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    1995 
    1996         attr.name = "d";
    1997         attr.size = 4;
    1998         rc = ui_file_list_entry_append(flist, &attr);
    1999         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    2000 
    2001         attr.name = "e";
    2002         attr.size = 5;
    2003         rc = ui_file_list_entry_append(flist, &attr);
    2004         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    2005 
    2006         /* Cursor and page to the first entry */
    2007         flist->cursor = ui_file_list_first(flist);
    2008         flist->cursor_idx = 0;
    2009         flist->page = flist->cursor;
    2010         flist->page_idx = 0;
    2011 
    2012         /* Move one page down */
    2013         ui_file_list_page_down(flist);
    2014 
    2015         /* Page and cursor should point to the third entry */
    2016         PCUT_ASSERT_STR_EQUALS("c", flist->cursor->name);
    2017         PCUT_ASSERT_INT_EQUALS(3, flist->cursor->size);
    2018         PCUT_ASSERT_INT_EQUALS(2, flist->cursor_idx);
    2019         PCUT_ASSERT_STR_EQUALS("c", flist->page->name);
    2020         PCUT_ASSERT_INT_EQUALS(3, flist->page->size);
    2021         PCUT_ASSERT_INT_EQUALS(2, flist->page_idx);
    2022 
    2023         /* Move one page down again. */
    2024         ui_file_list_page_down(flist);
    2025 
    2026         /* Cursor should point to last and page to next-to-last entry */
    2027         PCUT_ASSERT_STR_EQUALS("e", flist->cursor->name);
    2028         PCUT_ASSERT_INT_EQUALS(5, flist->cursor->size);
    2029         PCUT_ASSERT_INT_EQUALS(4, flist->cursor_idx);
    2030         PCUT_ASSERT_STR_EQUALS("d", flist->page->name);
    2031         PCUT_ASSERT_INT_EQUALS(4, flist->page->size);
    2032         PCUT_ASSERT_INT_EQUALS(3, flist->page_idx);
    2033 
    2034         /* Moving further down should do nothing (we are at the bottom). */
    2035         ui_file_list_page_down(flist);
    2036 
    2037         /* Cursor should still point to last and page to next-to-last entry */
    2038         PCUT_ASSERT_STR_EQUALS("e", flist->cursor->name);
    2039         PCUT_ASSERT_INT_EQUALS(5, flist->cursor->size);
    2040         PCUT_ASSERT_INT_EQUALS(4, flist->cursor_idx);
    2041         PCUT_ASSERT_STR_EQUALS("d", flist->page->name);
    2042         PCUT_ASSERT_INT_EQUALS(4, flist->page->size);
    2043         PCUT_ASSERT_INT_EQUALS(3, flist->page_idx);
    2044 
    2045         ui_file_list_destroy(flist);
    2046         ui_window_destroy(window);
    2047         ui_destroy(ui);
    2048 }
    2049 
    2050 /** ui_file_list_scroll_up() scrolls up by one row */
    2051 PCUT_TEST(scroll_up)
    2052 {
    2053         ui_t *ui;
    2054         ui_window_t *window;
    2055         ui_wnd_params_t params;
    2056         ui_file_list_t *flist;
    2057         ui_file_list_entry_attr_t attr;
    2058         gfx_rect_t rect;
    2059         errno_t rc;
    2060 
    2061         rc = ui_create_disp(NULL, &ui);
    2062         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    2063 
    2064         ui_wnd_params_init(&params);
    2065         params.caption = "Test";
    2066 
    2067         rc = ui_window_create(ui, &params, &window);
    2068         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    2069 
    2070         rc = ui_file_list_create(window, true, &flist);
    2071         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    2072 
    2073         rect.p0.x = 0;
    2074         rect.p0.y = 0;
    2075         rect.p1.x = 10;
    2076         rect.p1.y = 38; /* Assuming this makes page size 2 */
    2077         ui_file_list_set_rect(flist, &rect);
    2078 
    2079         PCUT_ASSERT_INT_EQUALS(2, ui_file_list_page_size(flist));
    2080 
    2081         /* Add tree entries (more than page size, which is 2) */
    2082 
    2083         ui_file_list_entry_attr_init(&attr);
    2084 
    2085         attr.name = "a";
    2086         attr.size = 1;
    2087         rc = ui_file_list_entry_append(flist, &attr);
    2088         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    2089 
    2090         attr.name = "b";
    2091         attr.size = 2;
    2092         rc = ui_file_list_entry_append(flist, &attr);
    2093         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    2094 
    2095         attr.name = "c";
    2096         attr.size = 3;
    2097         rc = ui_file_list_entry_append(flist, &attr);
    2098         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    2099 
    2100         /* Cursor to the last entry, page to the second */
    2101         flist->cursor = ui_file_list_last(flist);
    2102         flist->cursor_idx = 2;
    2103         flist->page = ui_file_list_prev(flist->cursor);
    2104         flist->page_idx = 1;
    2105 
    2106         /* Scroll one entry up */
    2107         ui_file_list_scroll_up(flist);
    2108 
    2109         /* Page should start on the first entry, cursor unchanged */
    2110         PCUT_ASSERT_STR_EQUALS("c", flist->cursor->name);
    2111         PCUT_ASSERT_INT_EQUALS(3, flist->cursor->size);
    2112         PCUT_ASSERT_INT_EQUALS(2, flist->cursor_idx);
    2113         PCUT_ASSERT_STR_EQUALS("a", flist->page->name);
    2114         PCUT_ASSERT_INT_EQUALS(1, flist->page->size);
    2115         PCUT_ASSERT_INT_EQUALS(0, flist->page_idx);
    2116 
    2117         /* Try scrolling one more entry up */
    2118         ui_file_list_scroll_up(flist);
    2119 
    2120         /* We were at the beginning, so nothing should have changed  */
    2121         PCUT_ASSERT_STR_EQUALS("c", flist->cursor->name);
    2122         PCUT_ASSERT_INT_EQUALS(3, flist->cursor->size);
    2123         PCUT_ASSERT_INT_EQUALS(2, flist->cursor_idx);
    2124         PCUT_ASSERT_STR_EQUALS("a", flist->page->name);
    2125         PCUT_ASSERT_INT_EQUALS(1, flist->page->size);
    2126         PCUT_ASSERT_INT_EQUALS(0, flist->page_idx);
    2127 
    2128         ui_file_list_destroy(flist);
    2129         ui_window_destroy(window);
    2130         ui_destroy(ui);
    2131 }
    2132 
    2133 /** ui_file_list_scroll_down() scrolls down by one row */
    2134 PCUT_TEST(scroll_down)
    2135 {
    2136         ui_t *ui;
    2137         ui_window_t *window;
    2138         ui_wnd_params_t params;
    2139         ui_file_list_t *flist;
    2140         ui_file_list_entry_attr_t attr;
    2141         gfx_rect_t rect;
    2142         errno_t rc;
    2143 
    2144         rc = ui_create_disp(NULL, &ui);
    2145         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    2146 
    2147         ui_wnd_params_init(&params);
    2148         params.caption = "Test";
    2149 
    2150         rc = ui_window_create(ui, &params, &window);
    2151         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    2152 
    2153         rc = ui_file_list_create(window, true, &flist);
    2154         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    2155 
    2156         rect.p0.x = 0;
    2157         rect.p0.y = 0;
    2158         rect.p1.x = 10;
    2159         rect.p1.y = 38; /* Assuming this makes page size 2 */
    2160         ui_file_list_set_rect(flist, &rect);
    2161 
    2162         PCUT_ASSERT_INT_EQUALS(2, ui_file_list_page_size(flist));
    2163 
    2164         /* Add tree entries (more than page size, which is 2) */
    2165 
    2166         ui_file_list_entry_attr_init(&attr);
    2167 
    2168         attr.name = "a";
    2169         attr.size = 1;
    2170         rc = ui_file_list_entry_append(flist, &attr);
    2171         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    2172 
    2173         attr.name = "b";
    2174         attr.size = 2;
    2175         rc = ui_file_list_entry_append(flist, &attr);
    2176         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    2177 
    2178         attr.name = "c";
    2179         attr.size = 3;
    2180         rc = ui_file_list_entry_append(flist, &attr);
    2181         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    2182 
    2183         /* Cursor and page start to the first entry */
    2184         flist->cursor = ui_file_list_first(flist);
    2185         flist->cursor_idx = 0;
    2186         flist->page = flist->cursor;
    2187         flist->page_idx = 0;
    2188 
    2189         /* Scroll one entry down */
    2190         ui_file_list_scroll_down(flist);
    2191 
    2192         /* Page should start on the second entry, cursor unchanged */
    2193         PCUT_ASSERT_STR_EQUALS("a", flist->cursor->name);
    2194         PCUT_ASSERT_INT_EQUALS(1, flist->cursor->size);
    2195         PCUT_ASSERT_INT_EQUALS(0, flist->cursor_idx);
    2196         PCUT_ASSERT_STR_EQUALS("b", flist->page->name);
    2197         PCUT_ASSERT_INT_EQUALS(2, flist->page->size);
    2198         PCUT_ASSERT_INT_EQUALS(1, flist->page_idx);
    2199 
    2200         /* Try scrolling one more entry down */
    2201         ui_file_list_scroll_down(flist);
    2202 
    2203         /* We were at the end, so nothing should have changed  */
    2204         PCUT_ASSERT_STR_EQUALS("a", flist->cursor->name);
    2205         PCUT_ASSERT_INT_EQUALS(1, flist->cursor->size);
    2206         PCUT_ASSERT_INT_EQUALS(0, flist->cursor_idx);
    2207         PCUT_ASSERT_STR_EQUALS("b", flist->page->name);
    2208         PCUT_ASSERT_INT_EQUALS(2, flist->page->size);
    2209         PCUT_ASSERT_INT_EQUALS(1, flist->page_idx);
    2210 
    2211         ui_file_list_destroy(flist);
    2212         ui_window_destroy(window);
    2213         ui_destroy(ui);
    2214 }
    2215 
    2216 /** ui_file_list_scroll_page_up() scrolls up by one page */
    2217 PCUT_TEST(scroll_page_up)
    2218 {
    2219         ui_t *ui;
    2220         ui_window_t *window;
    2221         ui_wnd_params_t params;
    2222         ui_file_list_t *flist;
    2223         ui_file_list_entry_attr_t attr;
    2224         gfx_rect_t rect;
    2225         errno_t rc;
    2226 
    2227         rc = ui_create_disp(NULL, &ui);
    2228         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    2229 
    2230         ui_wnd_params_init(&params);
    2231         params.caption = "Test";
    2232 
    2233         rc = ui_window_create(ui, &params, &window);
    2234         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    2235 
    2236         rc = ui_file_list_create(window, true, &flist);
    2237         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    2238 
    2239         rect.p0.x = 0;
    2240         rect.p0.y = 0;
    2241         rect.p1.x = 10;
    2242         rect.p1.y = 38; /* Assuming this makes page size 2 */
    2243         ui_file_list_set_rect(flist, &rect);
    2244 
    2245         PCUT_ASSERT_INT_EQUALS(2, ui_file_list_page_size(flist));
    2246 
    2247         /* Add five entries (more than twice the page size, which is 2) */
    2248 
    2249         ui_file_list_entry_attr_init(&attr);
    2250 
    2251         attr.name = "a";
    2252         attr.size = 1;
    2253         rc = ui_file_list_entry_append(flist, &attr);
    2254         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    2255 
    2256         attr.name = "b";
    2257         attr.size = 2;
    2258         rc = ui_file_list_entry_append(flist, &attr);
    2259         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    2260 
    2261         attr.name = "c";
    2262         attr.size = 3;
    2263         rc = ui_file_list_entry_append(flist, &attr);
    2264         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    2265 
    2266         attr.name = "d";
    2267         attr.size = 4;
    2268         rc = ui_file_list_entry_append(flist, &attr);
    2269         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    2270 
    2271         attr.name = "e";
    2272         attr.size = 5;
    2273         rc = ui_file_list_entry_append(flist, &attr);
    2274         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    2275 
    2276         /* Cursor to the last entry, page to the second last */
    2277         flist->cursor = ui_file_list_last(flist);
    2278         flist->cursor_idx = 4;
    2279         flist->page = ui_file_list_prev(flist->cursor);
    2280         flist->page_idx = 3;
    2281 
    2282         /* Scroll one page up */
    2283         ui_file_list_scroll_page_up(flist);
    2284 
    2285         /* Page should start on 'b', cursor unchanged */
    2286         PCUT_ASSERT_STR_EQUALS("e", flist->cursor->name);
    2287         PCUT_ASSERT_INT_EQUALS(5, flist->cursor->size);
    2288         PCUT_ASSERT_INT_EQUALS(4, flist->cursor_idx);
    2289         PCUT_ASSERT_STR_EQUALS("b", flist->page->name);
    2290         PCUT_ASSERT_INT_EQUALS(2, flist->page->size);
    2291         PCUT_ASSERT_INT_EQUALS(1, flist->page_idx);
    2292 
    2293         /* Page up again */
    2294         ui_file_list_scroll_page_up(flist);
    2295 
    2296         /* Page should now be at the beginning, cursor unchanged */
    2297         PCUT_ASSERT_STR_EQUALS("e", flist->cursor->name);
    2298         PCUT_ASSERT_INT_EQUALS(5, flist->cursor->size);
    2299         PCUT_ASSERT_INT_EQUALS(4, flist->cursor_idx);
    2300         PCUT_ASSERT_STR_EQUALS("a", flist->page->name);
    2301         PCUT_ASSERT_INT_EQUALS(1, flist->page->size);
    2302         PCUT_ASSERT_INT_EQUALS(0, flist->page_idx);
    2303 
    2304         /* Page up again */
    2305         ui_file_list_scroll_page_up(flist);
    2306 
    2307         /* We were at the beginning, nothing should have changed */
    2308         PCUT_ASSERT_STR_EQUALS("e", flist->cursor->name);
    2309         PCUT_ASSERT_INT_EQUALS(5, flist->cursor->size);
    2310         PCUT_ASSERT_INT_EQUALS(4, flist->cursor_idx);
    2311         PCUT_ASSERT_STR_EQUALS("a", flist->page->name);
    2312         PCUT_ASSERT_INT_EQUALS(1, flist->page->size);
    2313         PCUT_ASSERT_INT_EQUALS(0, flist->page_idx);
    2314 
    2315         ui_file_list_destroy(flist);
    2316         ui_window_destroy(window);
    2317         ui_destroy(ui);
    2318 }
    2319 
    2320 /** ui_file_list_scroll_page_up() scrolls down by one page */
    2321 PCUT_TEST(scroll_page_down)
    2322 {
    2323         ui_t *ui;
    2324         ui_window_t *window;
    2325         ui_wnd_params_t params;
    2326         ui_file_list_t *flist;
    2327         ui_file_list_entry_attr_t attr;
    2328         gfx_rect_t rect;
    2329         errno_t rc;
    2330 
    2331         rc = ui_create_disp(NULL, &ui);
    2332         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    2333 
    2334         ui_wnd_params_init(&params);
    2335         params.caption = "Test";
    2336 
    2337         rc = ui_window_create(ui, &params, &window);
    2338         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    2339 
    2340         rc = ui_file_list_create(window, true, &flist);
    2341         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    2342 
    2343         rect.p0.x = 0;
    2344         rect.p0.y = 0;
    2345         rect.p1.x = 10;
    2346         rect.p1.y = 38; /* Assuming this makes page size 2 */
    2347         ui_file_list_set_rect(flist, &rect);
    2348 
    2349         PCUT_ASSERT_INT_EQUALS(2, ui_file_list_page_size(flist));
    2350 
    2351         /* Add five entries (more than twice the page size, which is 2) */
    2352 
    2353         ui_file_list_entry_attr_init(&attr);
    2354 
    2355         attr.name = "a";
    2356         attr.size = 1;
    2357         rc = ui_file_list_entry_append(flist, &attr);
    2358         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    2359 
    2360         attr.name = "b";
    2361         attr.size = 2;
    2362         rc = ui_file_list_entry_append(flist, &attr);
    2363         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    2364 
    2365         attr.name = "c";
    2366         attr.size = 3;
    2367         rc = ui_file_list_entry_append(flist, &attr);
    2368         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    2369 
    2370         attr.name = "d";
    2371         attr.size = 4;
    2372         rc = ui_file_list_entry_append(flist, &attr);
    2373         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    2374 
    2375         attr.name = "e";
    2376         attr.size = 5;
    2377         rc = ui_file_list_entry_append(flist, &attr);
    2378         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    2379 
    2380         /* Cursor and page to the first entry */
    2381         flist->cursor = ui_file_list_first(flist);
    2382         flist->cursor_idx = 0;
    2383         flist->page = ui_file_list_first(flist);
    2384         flist->page_idx = 0;
    2385 
    2386         /* Scroll one page down */
    2387         ui_file_list_scroll_page_down(flist);
    2388 
    2389         /* Page should start on 'c', cursor unchanged */
    2390         PCUT_ASSERT_STR_EQUALS("a", flist->cursor->name);
    2391         PCUT_ASSERT_INT_EQUALS(1, flist->cursor->size);
    2392         PCUT_ASSERT_INT_EQUALS(0, flist->cursor_idx);
    2393         PCUT_ASSERT_STR_EQUALS("c", flist->page->name);
    2394         PCUT_ASSERT_INT_EQUALS(3, flist->page->size);
    2395         PCUT_ASSERT_INT_EQUALS(2, flist->page_idx);
    2396 
    2397         /* Page down again */
    2398         ui_file_list_scroll_page_down(flist);
    2399 
    2400         /* Page should now start at 'd', cursor unchanged */
    2401         PCUT_ASSERT_STR_EQUALS("a", flist->cursor->name);
    2402         PCUT_ASSERT_INT_EQUALS(1, flist->cursor->size);
    2403         PCUT_ASSERT_INT_EQUALS(0, flist->cursor_idx);
    2404         PCUT_ASSERT_STR_EQUALS("d", flist->page->name);
    2405         PCUT_ASSERT_INT_EQUALS(4, flist->page->size);
    2406         PCUT_ASSERT_INT_EQUALS(3, flist->page_idx);
    2407 
    2408         /* Page down again */
    2409         ui_file_list_scroll_page_down(flist);
    2410 
    2411         /* We were at the end, nothing should have changed */
    2412         PCUT_ASSERT_STR_EQUALS("a", flist->cursor->name);
    2413         PCUT_ASSERT_INT_EQUALS(1, flist->cursor->size);
    2414         PCUT_ASSERT_INT_EQUALS(0, flist->cursor_idx);
    2415         PCUT_ASSERT_STR_EQUALS("d", flist->page->name);
    2416         PCUT_ASSERT_INT_EQUALS(4, flist->page->size);
    2417         PCUT_ASSERT_INT_EQUALS(3, flist->page_idx);
    2418 
    2419         ui_file_list_destroy(flist);
    2420         ui_window_destroy(window);
    2421         ui_destroy(ui);
    2422 }
    2423 
    2424 PCUT_TEST(scroll_pos)
    2425 {
    2426         ui_t *ui;
    2427         ui_window_t *window;
    2428         ui_wnd_params_t params;
    2429         ui_file_list_t *flist;
    2430         ui_file_list_entry_attr_t attr;
    2431         gfx_rect_t rect;
    2432         errno_t rc;
    2433 
    2434         rc = ui_create_disp(NULL, &ui);
    2435         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    2436 
    2437         ui_wnd_params_init(&params);
    2438         params.caption = "Test";
    2439 
    2440         rc = ui_window_create(ui, &params, &window);
    2441         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    2442 
    2443         rc = ui_file_list_create(window, true, &flist);
    2444         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    2445 
    2446         rect.p0.x = 0;
    2447         rect.p0.y = 0;
    2448         rect.p1.x = 10;
    2449         rect.p1.y = 38; /* Assuming this makes page size 2 */
    2450         ui_file_list_set_rect(flist, &rect);
    2451 
    2452         PCUT_ASSERT_INT_EQUALS(2, ui_file_list_page_size(flist));
    2453 
    2454         /* Add five entries (more than twice the page size, which is 2) */
    2455 
    2456         ui_file_list_entry_attr_init(&attr);
    2457 
    2458         attr.name = "a";
    2459         attr.size = 1;
    2460         rc = ui_file_list_entry_append(flist, &attr);
    2461         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    2462 
    2463         attr.name = "b";
    2464         attr.size = 2;
    2465         rc = ui_file_list_entry_append(flist, &attr);
    2466         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    2467 
    2468         attr.name = "c";
    2469         attr.size = 3;
    2470         rc = ui_file_list_entry_append(flist, &attr);
    2471         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    2472 
    2473         attr.name = "d";
    2474         attr.size = 4;
    2475         rc = ui_file_list_entry_append(flist, &attr);
    2476         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    2477 
    2478         attr.name = "e";
    2479         attr.size = 5;
    2480         rc = ui_file_list_entry_append(flist, &attr);
    2481         PCUT_ASSERT_ERRNO_VAL(EOK, rc);
    2482 
    2483         /* Cursor and page to the first entry */
    2484         flist->cursor = ui_file_list_first(flist);
    2485         flist->cursor_idx = 0;
    2486         flist->page = ui_file_list_first(flist);
    2487         flist->page_idx = 0;
    2488 
    2489         /* Scroll to entry 1 (one down) */
    2490         ui_file_list_scroll_pos(flist, 1);
    2491 
    2492         /* Page should start on 'b', cursor unchanged */
    2493         PCUT_ASSERT_STR_EQUALS("a", flist->cursor->name);
    2494         PCUT_ASSERT_INT_EQUALS(1, flist->cursor->size);
    2495         PCUT_ASSERT_INT_EQUALS(0, flist->cursor_idx);
    2496         PCUT_ASSERT_STR_EQUALS("b", flist->page->name);
    2497         PCUT_ASSERT_INT_EQUALS(2, flist->page->size);
    2498         PCUT_ASSERT_INT_EQUALS(1, flist->page_idx);
    2499 
    2500         /* Scroll to entry 3 (i.e. the end) */
    2501         ui_file_list_scroll_pos(flist, 3);
    2502 
    2503         /* Page should now start at 'd', cursor unchanged */
    2504         PCUT_ASSERT_STR_EQUALS("a", flist->cursor->name);
    2505         PCUT_ASSERT_INT_EQUALS(1, flist->cursor->size);
    2506         PCUT_ASSERT_INT_EQUALS(0, flist->cursor_idx);
    2507         PCUT_ASSERT_STR_EQUALS("d", flist->page->name);
    2508         PCUT_ASSERT_INT_EQUALS(4, flist->page->size);
    2509         PCUT_ASSERT_INT_EQUALS(3, flist->page_idx);
    2510 
    2511         ui_file_list_destroy(flist);
    2512         ui_window_destroy(window);
    2513         ui_destroy(ui);
    2514 }
    2515 
    2516969/** ui_file_list_open_dir() opens a directory entry */
    2517970PCUT_TEST(open_dir)
     
    25591012        PCUT_ASSERT_STR_EQUALS(p, flist->dir);
    25601013
    2561         PCUT_ASSERT_INT_EQUALS(2, list_count(&flist->entries));
     1014        PCUT_ASSERT_INT_EQUALS(2, ui_list_entries_cnt(flist->list));
    25621015
    25631016        entry = ui_file_list_first(flist);
     
    27061159}
    27071160
     1161/** ui_file_list_get_cursor() returns the current cursor position */
     1162PCUT_TEST(get_cursor)
     1163{
     1164        ui_t *ui;
     1165        ui_window_t *window;
     1166        ui_wnd_params_t params;
     1167        ui_file_list_t *flist;
     1168        ui_file_list_entry_attr_t attr;
     1169        ui_file_list_entry_t *entry;
     1170        ui_file_list_entry_t *cursor;
     1171        errno_t rc;
     1172
     1173        rc = ui_create_disp(NULL, &ui);
     1174        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     1175
     1176        ui_wnd_params_init(&params);
     1177        params.caption = "Test";
     1178
     1179        rc = ui_window_create(ui, &params, &window);
     1180        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     1181
     1182        rc = ui_file_list_create(window, true, &flist);
     1183        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     1184
     1185        ui_file_list_entry_attr_init(&attr);
     1186
     1187        /* Append entry */
     1188        attr.name = "a";
     1189        attr.size = 1;
     1190        rc = ui_file_list_entry_append(flist, &attr);
     1191        PCUT_ASSERT_ERRNO_VAL(EOK, rc);
     1192
     1193        entry = ui_file_list_first(flist);
     1194        PCUT_ASSERT_NOT_NULL(entry);
     1195
     1196        /* Cursor should be at the only entry */
     1197        cursor = ui_file_list_get_cursor(flist);
     1198        PCUT_ASSERT_EQUALS(entry, cursor);
     1199
     1200        ui_file_list_destroy(flist);
     1201        ui_window_destroy(window);
     1202        ui_destroy(ui);
     1203}
     1204
    27081205static void test_file_list_activate_req(ui_file_list_t *flist, void *arg)
    27091206{
  • uspace/lib/ui/test/main.c

    rbea6233 r7cf5ddb  
    4141PCUT_IMPORT(image);
    4242PCUT_IMPORT(label);
     43PCUT_IMPORT(list);
    4344PCUT_IMPORT(menu);
    4445PCUT_IMPORT(menubar);
Note: See TracChangeset for help on using the changeset viewer.