Subversion Repositories Kolibri OS

Rev

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

  1. #ifndef KOLIBRI_FILEBROWSE_H
  2. #define KOLIBRI_FILEBROWSE_H
  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.  
  94.  
  95. typedef struct __attribute__ ((__packed__)) {
  96.         uint32_t type;  // unused
  97.         uint32_t x_w;  // 10, 400
  98.         uint32_t y_h; // 45, 550
  99.         uint32_t icon_size_xy;  // x_y (16, 16)
  100.         uint16_t line_size_x;  // not used
  101.         uint16_t line_size_y;  // 18 or 17  - âûñîòà ëèíèè - ñòðîêè ñ ôàéëîì
  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
  108.         uint32_t icon_resolution_raw;  // ...
  109.         void* icon_palette_raw;      // ...
  110.         uint32_t directory_path_area;  // not used
  111.         uint32_t file_name_area;  // not used
  112.         uint32_t select_flag;  // widget have focus, set auto on mouseclick, but need to reset before mouse()
  113.         color_t background_color;  // self explained, 0xffffff
  114.         color_t select_color; // self explained, 0xbbddff
  115.     color_t select_text_color; // self explained - have a bug - never really used
  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
  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
  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
  132.     char* ini_file_end;     // start + filesize
  133.     uint32_t draw_scroll_bar;  // 1 = need redraw sb after key(), user - resetted
  134.     uint32_t font_size_xy;  // x_y      (6, 9)
  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
  139.     uint32_t mouse_key_delay; // 50
  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
  144.     uint16_t key_action;   // fill before key(), 1..12, wiki
  145.     uint16_t key_action_num; // fill before key()  fn2 >> 8
  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
  153.  
  154. } filebrowser;
  155.  
  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] = "<DIR> 1023b 00.00.00 00:00     temp1.asm";
  163.  
  164.     memset(fb, 0, sizeof(filebrowser));
  165.     fb->x_w = x_w;
  166.     fb->y_h = y_h;
  167.     fb->font_size_xy = font_size_xy;
  168.  
  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;
  173.  
  174.     fb->line_size_y = (icon_size_xy & 0xFFFF) + 2;
  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
  184.     fb->background_color = bgcolor;  // self explained, 0xffffff
  185.         fb->select_color = bk_select; // self explained, 0xbbddff
  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;
  196. }
  197.  
  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)
  201. {
  202.     filebrowser *new_fb = (filebrowser *)malloc(sizeof(filebrowser));
  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,
  204.                                          font_select, bk_select, font_color, bgcolor, reduct_color);
  205. }
  206.  
  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)
  209. {
  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,
  216.                                          0x000000, 0xbbddff, kolibri_color_table.color_work_text, kolibri_color_table.color_work_area, 0xff0000);
  217. }
  218. */
  219.  
  220. inline void gui_add_filebrowser(kolibri_window *wnd, filebrowser* f)
  221. {
  222.     kolibri_window_add_element(wnd, KOLIBRI_FILEBROWSE, f);
  223. }
  224.  
  225. extern void (*filebrowse_draw)(filebrowser *) __attribute__((__stdcall__));
  226. extern void (*filebrowse_key)(filebrowser *) __attribute__((__stdcall__));
  227. extern void (*filebrowse_mouse)(filebrowser *) __attribute__((__stdcall__));
  228.  
  229. #endif /* KOLIBRI_FILEBROWSE_H */
  230.