source: mainline/uspace/lib/ui/private/filelist.h@ 11662bd

ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 11662bd was 11662bd, checked in by Jiri Svoboda <jiri@…>, 3 years ago

File list control

File dialogs now allow browsing files/directories using the new
file list control. This is essentialy a copy of the Panel class
from Navigator, modified and extended to work in graphics mode as well.
Later Panel should be re-implemented using file list to prevent
duplication.

Note that this is not 100% done, it needs, for example, a scrollbar
(instead of scrolling by clicking the edges).

  • Property mode set to 100644
File size: 5.3 KB
RevLine 
[11662bd]1/*
2 * Copyright (c) 2022 Jiri Svoboda
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup libui
30 * @{
31 */
32/**
33 * @file File list
34 */
35
36#ifndef _UI_PRIVATE_FILELIST_H
37#define _UI_PRIVATE_FILELIST_H
38
39#include <adt/list.h>
40#include <gfx/color.h>
41#include <gfx/coord.h>
42#include <ipc/loc.h>
43#include <ui/window.h>
44#include <stdint.h>
45#include <types/ui/filelist.h>
46
47/** File list entry attributes */
48struct ui_file_list_entry_attr {
49 /** File name */
50 const char *name;
51 /** File size */
52 uint64_t size;
53 /** @c true iff entry is a directory */
54 bool isdir;
55 /** Service number for service special entries */
56 service_id_t svc;
57};
58
59/** File list entry */
60struct ui_file_list_entry {
61 /** Containing file list */
62 struct ui_file_list *flist;
63 /** Link to @c flist->entries */
64 link_t lentries;
65 /** File name */
66 char *name;
67 /** File size */
68 uint64_t size;
69 /** @c true iff entry is a directory */
70 bool isdir;
71 /** Service number for service special entries */
72 service_id_t svc;
73};
74
75/** File list.
76 *
77 * Allows browsing files and directories.
78 */
79typedef struct ui_file_list {
80 /** Base control object */
81 struct ui_control *control;
82
83 /** Containing window */
84 ui_window_t *window;
85
86 /** Callbacks */
87 struct ui_file_list_cb *cb;
88
89 /** Callback argument */
90 void *cb_arg;
91
92 /** File list rectangle */
93 gfx_rect_t rect;
94
95 /** Directory-type entry color */
96 gfx_color_t *dir_color;
97
98 /** Service-type entry color */
99 gfx_color_t *svc_color;
100
101 /** File list entries (list of ui_file_list_entry_t) */
102 list_t entries;
103
104 /** Number of entries */
105 size_t entries_cnt;
106
107 /** First entry of current page */
108 ui_file_list_entry_t *page;
109
110 /** Index of first entry of current page */
111 size_t page_idx;
112
113 /** Cursor position */
114 ui_file_list_entry_t *cursor;
115
116 /** Index of entry under cursor */
117 size_t cursor_idx;
118
119 /** @c true iff the file list is active */
120 bool active;
121
122 /** Directory */
123 char *dir;
124} ui_file_list_t;
125
126extern gfx_coord_t ui_file_list_entry_height(ui_file_list_t *);
127extern errno_t ui_file_list_entry_paint(ui_file_list_entry_t *, size_t);
128extern errno_t ui_file_list_paint(ui_file_list_t *);
129extern ui_evclaim_t ui_file_list_kbd_event(ui_file_list_t *, kbd_event_t *);
130extern ui_evclaim_t ui_file_list_pos_event(ui_file_list_t *, pos_event_t *);
131extern unsigned ui_file_list_page_size(ui_file_list_t *);
132extern void ui_file_list_inside_rect(ui_file_list_t *, gfx_rect_t *);
133extern bool ui_file_list_is_active(ui_file_list_t *);
134extern void ui_file_list_entry_delete(ui_file_list_entry_t *);
135extern void ui_file_list_clear_entries(ui_file_list_t *);
136extern errno_t ui_file_list_sort(ui_file_list_t *);
137extern int ui_file_list_entry_ptr_cmp(const void *, const void *);
138extern ui_file_list_entry_t *ui_file_list_first(ui_file_list_t *);
139extern ui_file_list_entry_t *ui_file_list_last(ui_file_list_t *);
140extern ui_file_list_entry_t *ui_file_list_next(ui_file_list_entry_t *);
141extern ui_file_list_entry_t *ui_file_list_prev(ui_file_list_entry_t *);
142extern ui_file_list_entry_t *ui_file_list_page_nth_entry(ui_file_list_t *,
143 size_t, size_t *);
144extern void ui_file_list_entry_attr_init(ui_file_list_entry_attr_t *);
145extern errno_t ui_file_list_entry_append(ui_file_list_t *,
146 ui_file_list_entry_attr_t *);
147extern void ui_file_list_cursor_move(ui_file_list_t *, ui_file_list_entry_t *,
148 size_t);
149extern void ui_file_list_cursor_up(ui_file_list_t *);
150extern void ui_file_list_cursor_down(ui_file_list_t *);
151extern void ui_file_list_cursor_top(ui_file_list_t *);
152extern void ui_file_list_cursor_bottom(ui_file_list_t *);
153extern void ui_file_list_page_up(ui_file_list_t *);
154extern void ui_file_list_page_down(ui_file_list_t *);
155extern errno_t ui_file_list_open(ui_file_list_t *, ui_file_list_entry_t *);
156extern errno_t ui_file_list_open_dir(ui_file_list_t *, ui_file_list_entry_t *);
157extern errno_t ui_file_list_open_file(ui_file_list_t *, ui_file_list_entry_t *);
158extern void ui_file_list_activate_req(ui_file_list_t *);
159extern void ui_file_list_selected(ui_file_list_t *, const char *);
160
161#endif
162
163/** @}
164 */
Note: See TracBrowser for help on using the repository browser.