Subversion Repositories Kolibri OS

Rev

Rev 6612 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
8581 rgimad 1
#ifndef KOLIBRI_FILEBROWSE_H
2
#define KOLIBRI_FILEBROWSE_H
6560 siemargl 3
 
4
struct  __attribute__ ((__packed__)) fs_dirinfo {
5
    uint32_t    subfn; // 1 read dir
6
    uint32_t    start;
7
    uint32_t    flags;
8
    uint32_t    size;
9
    uint32_t    retval;
10
    union {
11
        struct __attribute__ ((__packed__)) {
12
            uint8_t zero;  // 0
13
            char*   ppath;
14
        };
15
        char path[5];  // up to 4096
16
    } ;
17
};
18
 
19
static inline
20
uint32_t sf_file(int subfn, struct fs_dirinfo* dinfo)
21
// retval 0 if ok
22
{
23
    uint32_t retval;
24
    dinfo->subfn = subfn;
25
 
26
    __asm__ __volatile__(
27
    "int $0x40 "
28
    :"=a"(retval)
29
    :"a"(70),"b"(dinfo)
30
    :);
31
 
32
    return retval;
33
};
34
 
35
 
36
struct fs_dirheader {
37
    uint32_t     version; // 1
38
    uint32_t     curn_blocks;  // number of read dir items (BDFE)
39
    uint32_t     totl_blocks;  // directory full size
40
    char         other[20]; // reserved 0
41
};
42
 
43
enum filetype
44
{
45
    fs_readonly = 1,
46
    fs_hidden = 2,
47
    fs_system = 4,
48
    fs_volumelabel = 8,
49
    fs_folder = 0x10,
50
    fs_nonarchived = 0x20
51
};
52
 
53
struct __attribute__ ((__packed__)) fs_filetime {
54
    uint8_t    sec;
55
    uint8_t    mm;
56
    uint8_t    hour;
57
    uint8_t    zero;
58
};
59
 
60
struct __attribute__ ((__packed__)) fs_filedate {
61
    uint8_t    day;
62
    uint8_t    month;
63
    uint16_t   year;
64
};
65
 
66
/// directory entry cp866
67
struct fsBDFE {
68
    uint32_t filetype;
69
    uint32_t encoding; // 0 - cp866, 1 - utf16le
70
    struct fs_filetime tm_created;
71
    struct fs_filedate dt_created;
72
    struct fs_filetime tm_accessed;
73
    struct fs_filedate dt_accessed;
74
    struct fs_filetime tm_modified;
75
    struct fs_filedate dt_modified;
76
    uint64_t size;
77
    char   fname[264];
78
}; // must be sized 304
79
 
80
/// directory entry UTF16LE
81
struct fsBDFE_16 {
82
    uint32_t filetype;
83
    uint32_t encoding; // 0 - cp866, 1 - utf16le
84
    struct fs_filetime tm_created;
85
    struct fs_filedate dt_created;
86
    struct fs_filetime tm_accessed;
87
    struct fs_filedate dt_accessed;
88
    struct fs_filetime tm_modified;
89
    struct fs_filedate dt_modified;
90
    uint64_t size;
91
    wchar_t   fname[260];
92
}; // must be sized 560
93
 
8581 rgimad 94
 
95
typedef struct __attribute__ ((__packed__)) {
96
	uint32_t type;  // unused
97
	uint32_t x_w;  // 10, 400
6535 siemargl 98
	uint32_t y_h; // 45, 550
8581 rgimad 99
	uint32_t icon_size_xy;  // x_y (16, 16)
6560 siemargl 100
	uint16_t line_size_x;  // not used
8581 rgimad 101
	uint16_t line_size_y;  // 18 or 17  - ������ ����� - ������ � ������
6560 siemargl 102
	uint16_t type_size_x;  // not used
103
	uint16_t size_size_x;  // not used
104
	uint16_t date_size_x;  // not used
105
	uint16_t attributes_size_x; // not used
106
	uint32_t icon_assoc_area;  // not used
107
	void* icon_raw_area;   // z_icons.png
6535 siemargl 108
	uint32_t icon_resolution_raw;  // ...
6560 siemargl 109
	void* icon_palette_raw;      // ...
110
	uint32_t directory_path_area;  // not used
111
	uint32_t file_name_area;  // not used
6561 siemargl 112
	uint32_t select_flag;  // widget have focus, set auto on mouseclick, but need to reset before mouse()
8581 rgimad 113
	color_t background_color;  // self explained, 0xffffff
114
	color_t select_color; // self explained, 0xbbddff
6589 siemargl 115
    color_t select_text_color; // self explained - have a bug - never really used
6560 siemargl 116
    color_t text_color; // self explained
117
    color_t reduct_text_color; // 0xff0000  - spec color for cutted filenames
118
    color_t marked_text_color; // not used
8581 rgimad 119
    uint32_t max_panel_line;    // moved to scrollbar->cur_area, - ������������ ����� ����� � ����, �����������������
120
	uint32_t select_panel_counter;  // !=0 if want to draw multiselection ???
121
	uint32_t folder_block;   // auto formed, ���������� ������ ������ ����� �������� (����) ????? format BDVK == bdfe,, // moved to scrollbar->max_area
122
	uint32_t start_draw_line;    // internal - top showed file n. moved to scrollbar->position and back
123
	uint16_t start_draw_cursor_line;  //internal
6560 siemargl 124
    void* folder_data;      // 32 byte - dir_header, +4 = number, +32 - bdvk[], size of rec(bdvk cp866) = 304byte
125
    uint32_t temp_counter; //internal
126
    uint32_t file_name_length; //internal
127
    uint32_t marked_file;  // have a mark 0/1 ?
128
    uint32_t extension_size;  //internal
129
    uint32_t extension_start;  //internal
130
    void* type_table; // type buffer
131
    char* ini_file_start;   // icons.ini contens - file<>icon association
6535 siemargl 132
    char* ini_file_end;     // start + filesize
6560 siemargl 133
    uint32_t draw_scroll_bar;  // 1 = need redraw sb after key(), user - resetted
6535 siemargl 134
    uint32_t font_size_xy;  // x_y	(6, 9)
6560 siemargl 135
    uint32_t mouse_keys;  // saved internal
136
    uint32_t mouse_keys_old; // saved internal
137
    uint32_t mouse_pos; // saved internal
138
    uint32_t mouse_keys_delta; // saved internal
6535 siemargl 139
    uint32_t mouse_key_delay; // 50
6560 siemargl 140
    uint32_t mouse_keys_tick; // internal timer
141
    uint16_t start_draw_cursor_line_2;  // internal cursor line
142
    uint32_t all_redraw;         // 0 - skip draw contens, 1 - force draw, 2 - no draw selection (but draw icons), used when scroll
143
    struct fsBDFE* selected_BDVK_adress;  // pointer to selected
6535 siemargl 144
    uint16_t key_action;   // fill before key(), 1..12, wiki
145
    uint16_t key_action_num; // fill before key()  fn2 >> 8
6560 siemargl 146
    char* name_temp_area;       // temporary string format buffer
147
    uint32_t max_name_temp_size;  // sizeof ^
148
    uint32_t display_name_max_length;  // autocounted
149
    uint32_t draw_panel_selection_flag;  // flag internal showing selected item
150
    uint32_t mouse_pos_old;  // saved internal
151
    uint32_t marked_counter;  // number of marked files
152
    char* keymap_pointer;  // keyboard layout map
6535 siemargl 153
 
8581 rgimad 154
} filebrowser;
155
 
6560 siemargl 156
static inline filebrowser* kolibri_filebrowser(filebrowser* fb, uint32_t x_w, uint32_t y_h, uint32_t font_size_xy, uint32_t icon_size_xy, void* icon_raw_area, void* icon_palette_raw, uint32_t icon_res,
157
                                         char* ini_file_start, char* ini_file_end,
158
                                         color_t font_select, color_t bk_select, color_t font_color, color_t bgcolor, color_t reduct_color)
159
{
160
    static char name_temp_area[256];
161
    static char keymap_area[128];
162
    static char type_table[128] = " 1023b 00.00.00 00:00     temp1.asm";
6535 siemargl 163
 
6560 siemargl 164
    memset(fb, 0, sizeof(filebrowser));
8581 rgimad 165
    fb->x_w = x_w;
6560 siemargl 166
    fb->y_h = y_h;
167
    fb->font_size_xy = font_size_xy;
6535 siemargl 168
 
6560 siemargl 169
    fb->icon_size_xy = icon_size_xy;
170
    fb->icon_raw_area = icon_raw_area;
171
    fb->icon_palette_raw = icon_palette_raw;
172
    fb->icon_resolution_raw = icon_res;
6535 siemargl 173
 
8581 rgimad 174
    fb->line_size_y = (icon_size_xy & 0xFFFF) + 2;
6560 siemargl 175
 
176
    // constants
177
    fb->type_table = type_table;
178
    fb->mouse_key_delay = 50;
179
    fb->name_temp_area = name_temp_area;
180
//    fb->max_name_temp_size = sizeof name_temp_area - 1;
181
    fb->keymap_pointer = keymap_area;
182
 
183
    // careful - font sizes may be encoded in colors as SysFn4
8581 rgimad 184
    fb->background_color = bgcolor;  // self explained, 0xffffff
185
	fb->select_color = bk_select; // self explained, 0xbbddff
6560 siemargl 186
    fb->select_text_color = font_select; // self explained
187
    fb->text_color = font_color; // self explained
188
    fb->reduct_text_color = reduct_color; // 0xff0000  - spec color for cutted filenames
189
 
190
    fb->ini_file_start = ini_file_start;
191
    fb->ini_file_end = ini_file_end;
192
/*
193
    void* folder_data;      // 32 byte - dir_header, +4 = number, +32 - bdvk[], size of rec(bdvk cp866) = 304byte
194
*/
195
    return fb;
8581 rgimad 196
}
197
 
6560 siemargl 198
static inline filebrowser* kolibri_new_filebrowser(uint32_t x_w, uint32_t y_h, uint32_t font_size_xy, uint32_t icon_size_xy, void* icon_raw_area, void* icon_palette_raw, uint32_t icon_bpp,
199
                                         char* ini_file_start, char* ini_file_end,
200
                                         color_t font_select, color_t bk_select, color_t font_color, color_t bgcolor, color_t reduct_color)
8581 rgimad 201
{
202
    filebrowser *new_fb = (filebrowser *)malloc(sizeof(filebrowser));
6560 siemargl 203
    return kolibri_filebrowser(new_fb, x_w, y_h, font_size_xy, icon_size_xy, icon_raw_area, icon_palette_raw, icon_bpp, ini_file_start, ini_file_end,
8581 rgimad 204
                                         font_select, bk_select, font_color, bgcolor, reduct_color);
6535 siemargl 205
}
206
 
6560 siemargl 207
/* loading files leads to link functions even if no using filebrowser
208
inline filebrowser* kolibri_filebrowser_def(filebrowser* fb, uint32_t x_w, uint32_t y_h)
6535 siemargl 209
{
6560 siemargl 210
    // load default icons and icon association
211
    char icons_ini[]       = "/rd/1/File managers/icons.ini";
212
    char icons16img[]       = "/rd/1/File managers/z_icons.png";
213
 
214
    return kolibri_filebrowser(fb, x_w, y_h, X_Y(9, 16), X_Y(16, 16), icon_raw_area, icon_palette_raw, icon_res,
215
                                         ini_file_start, ini_file_end,
8581 rgimad 216
                                         0x000000, 0xbbddff, kolibri_color_table.color_work_text, kolibri_color_table.color_work_area, 0xff0000);
6535 siemargl 217
}
6560 siemargl 218
*/
6589 siemargl 219
 
8581 rgimad 220
static inline void gui_add_filebrowser(kolibri_window *wnd, filebrowser* f)
6535 siemargl 221
{
8581 rgimad 222
    kolibri_window_add_element(wnd, KOLIBRI_FILEBROWSE, f);
6535 siemargl 223
}
6612 siemargl 224
 
8581 rgimad 225
extern void (*filebrowse_draw)(filebrowser *) __attribute__((__stdcall__));
226
extern void (*filebrowse_key)(filebrowser *) __attribute__((__stdcall__));
227
extern void (*filebrowse_mouse)(filebrowser *) __attribute__((__stdcall__));
6612 siemargl 228
 
229
__attribute__((__stdcall__)) static inline void filebrowser_key(filebrowser *fb, oskey_t keypress)
230
/// wrapper for key, translate keypress (ASCII mode) to action for browser
231
{
232
//    if (!fb->select_flag) return;  // same reaction as other controls
233
 
234
    int extended_key = 0, act = 0;
235
 
236
    if(keypress.state) return;
237
    if (keypress.code == 0xE0){ extended_key = 1; return; }
238
 
239
    act = 0;
240
    switch(keypress.ctrl_key)  // ascii scancode
241
    {
242
    case 80: // arrow down
243
        act = 1; break;
244
    case 72: // arrow up
245
        act = 2; break;
246
    case 81: // PageDown
247
        act = 3; break;
248
    case 73: // PageUp
249
        act = 4; break;
250
    case 71: // Home
251
        act = 5; break;
252
    case 79: // End
253
        act = 6; break;
254
    case 28: // Enter
255
        act = 7; break;
256
    case 82: // Insert
257
        act = 8; break;
258
    case 78: // NumPad+   select all
259
        act = 9; break;
260
    case 74: // NumPad-   deselct
261
        act = 10; break;
262
    case 55: // NumPad*  invert selection
263
        act = 11; break;
264
    default:
265
        act = 12; // search by letter
266
    }
267
    fb->key_action = act;
268
    fb->key_action_num = keypress.ctrl_key;
269
 
270
//    debug_board_printf("key pressed [%X] %d, action %d, ext_flag = %d\n", keypress.val, brows.key_action_num, act, extended_key);
271
 
272
    if (extended_key) extended_key = 0;
273
    (*filebrowse_key)(fb);
274
}
275
 
8581 rgimad 276
 
277
#endif /* KOLIBRI_FILEBROWSE_H */