Ignore:
File:
1 edited

Legend:

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

    r5e758e4 r7cf5ddb  
    149149        list->cb = cb;
    150150        list->cb_arg = arg;
    151 }
    152 
    153 /** Get UI list callback argument.
    154  *
    155  * @param list UI list
    156  * @return Callback argument
    157  */
    158 void *ui_list_get_cb_arg(ui_list_t *list)
    159 {
    160         return list->cb_arg;
    161151}
    162152
     
    711701}
    712702
    713 /** Destroy UI list entry.
    714  *
    715  * This is the quick way, but does not update cursor or page position.
     703/** Delete UI list entry.
    716704 *
    717705 * @param entry UI list entry
    718706 */
    719 void ui_list_entry_destroy(ui_list_entry_t *entry)
     707void ui_list_entry_delete(ui_list_entry_t *entry)
    720708{
    721709        if (entry->list->cursor == entry)
     
    730718}
    731719
    732 /** Delete UI list entry.
    733  *
    734  * If required, update cursor and page position and repaint.
    735  *
    736  * @param entry UI list entry
    737  */
    738 void ui_list_entry_delete(ui_list_entry_t *entry)
    739 {
    740         ui_list_t *list = entry->list;
    741 
    742         /* Try to make sure entry does not disappear under cursor or page */
    743         if (entry->list->cursor == entry)
    744                 ui_list_cursor_up(entry->list);
    745         if (entry->list->cursor == entry)
    746                 ui_list_cursor_down(entry->list);
    747         if (entry->list->page == entry)
    748                 ui_list_scroll_up(entry->list);
    749         if (entry->list->page == entry)
    750                 ui_list_scroll_down(entry->list);
    751 
    752         ui_list_entry_destroy(entry);
    753 
    754         /*
    755          * But it could still happen if there are not enough entries.
    756          * In that case just move page and/or cursor to the first
    757          * entry.
    758          */
    759         if (list->page == NULL) {
    760                 list->page = ui_list_first(list);
    761                 list->page_idx = 0;
    762         } else {
    763                 /*
    764                  * Entry index might have changed if earlier entry
    765                  * was deleted.
    766                  */
    767                 list->page_idx = ui_list_entry_get_idx(list->page);
    768         }
    769 
    770         if (list->cursor == NULL) {
    771                 list->cursor = ui_list_first(list);
    772                 list->cursor_idx = 0;
    773         } else {
    774                 /*
    775                  * Entry index might have changed if earlier entry
    776                  * was deleted.
    777                  */
    778                 list->cursor_idx = ui_list_entry_get_idx(list->cursor);
    779         }
    780 }
    781 
    782720/** Get entry argument.
    783721 *
     
    790728}
    791729
    792 /** Get containing list.
    793  *
    794  * @param entry UI list entry
    795  * @return Containing list
    796  */
    797 ui_list_t *ui_list_entry_get_list(ui_list_entry_t *entry)
    798 {
    799         return entry->list;
    800 }
    801 
    802 /** Change list entry caption.
    803  *
    804  * @param entry UI list entry
    805  * @param caption New caption
    806  *
    807  * @return EOK on success, ENOMEM if out of memory
    808  */
    809 errno_t ui_list_entry_set_caption(ui_list_entry_t *entry, const char *caption)
    810 {
    811         char *dcaption;
    812 
    813         dcaption = str_dup(caption);
    814         if (dcaption == NULL)
    815                 return ENOMEM;
    816 
    817         free(entry->caption);
    818         entry->caption = dcaption;
    819 
    820         (void)ui_list_entry_paint(entry, ui_list_entry_get_idx(entry));
    821         return EOK;
    822 }
    823 
    824730/** Clear UI list entry list.
    825731 *
     
    832738        entry = ui_list_first(list);
    833739        while (entry != NULL) {
    834                 ui_list_entry_destroy(entry);
     740                ui_list_entry_delete(entry);
    835741                entry = ui_list_first(list);
    836742        }
     
    952858{
    953859        return list->cursor;
    954 }
    955 
    956 /** Set new cursor position.
    957  *
    958  * O(N) in list size, use with caution.
    959  *
    960  * @param list UI list
    961  * @param entry New cursor position
    962  */
    963 void ui_list_set_cursor(ui_list_t *list, ui_list_entry_t *entry)
    964 {
    965         size_t idx;
    966 
    967         idx = ui_list_entry_get_idx(entry);
    968         ui_list_cursor_move(list, entry, idx);
    969860}
    970861
     
    1021912                                /* Find first page entry (go back rows - 1) */
    1022913                                e = entry;
    1023                                 for (i = 0; i + 1 < rows; i++) {
     914                                for (i = 0; i < rows - 1; i++) {
    1024915                                        e = ui_list_prev(e);
    1025916                                }
     
    12071098        ui_list_entry_t *prev;
    12081099
    1209         if (list->page == NULL)
    1210                 return;
    1211 
    12121100        prev = ui_list_prev(list->page);
    12131101        if (prev == NULL)
     
    12321120        size_t i;
    12331121        size_t rows;
    1234 
    1235         if (list->page == NULL)
    1236                 return;
    12371122
    12381123        next = ui_list_next(list->page);
Note: See TracChangeset for help on using the changeset viewer.