From 1116fef55c2d711e857b3fceb893969c44d2b580 Mon Sep 17 00:00:00 2001 From: siemargl Date: Sun, 2 Oct 2016 18:46:15 +0000 Subject: [PATCH] filebrowser demo almost fixed git-svn-id: svn://kolibrios.org@6559 a494cfbc-eb01-0410-851d-a64ba20cac60 --- contrib/C_Layer/EXAMPLE/kmenu/Makefile | 4 +- contrib/C_Layer/EXAMPLE/kmenu/kmenu_example.c | 22 +-- .../C_Layer/EXAMPLE/libguic_kolibri/Makefile | 2 +- .../EXAMPLE/libguic_kolibri/dbutton_files.c | 166 +++++++++++++++--- .../EXAMPLE/libguic_kolibri/option_menu.c | 2 +- .../libguic_kolibri/reload_16x16_8b.png | Bin 0 -> 1458 bytes 6 files changed, 159 insertions(+), 37 deletions(-) create mode 100644 contrib/C_Layer/EXAMPLE/libguic_kolibri/reload_16x16_8b.png diff --git a/contrib/C_Layer/EXAMPLE/kmenu/Makefile b/contrib/C_Layer/EXAMPLE/kmenu/Makefile index cf14da06b2..c4f17c453d 100644 --- a/contrib/C_Layer/EXAMPLE/kmenu/Makefile +++ b/contrib/C_Layer/EXAMPLE/kmenu/Makefile @@ -6,9 +6,9 @@ SDK_DIR:= $(abspath ../../../sdk) CLAYER:= $(abspath ../../) LDFLAGS = -static -S -nostdlib -T $(SDK_DIR)/sources/newlib/app.lds \ - --image-base 0 -lgcc -ldll -lc.dll -lapp + --image-base 0 -lgcc -ldll -lc.dll -CFLAGS = -g -U_Win32 -U_WIN32 -U__MINGW32__ +CFLAGS = -g -U_Win32 -U_WIN32 -U__MINGW32__ -std=gnu90 INCLUDES= -I. -I$(SDK_DIR)/sources/newlib/libc/include -I$(CLAYER)/INCLUDE LIBPATH:= -L $(SDK_DIR)/lib -L /home/autobuild/tools/win32/mingw32/lib diff --git a/contrib/C_Layer/EXAMPLE/kmenu/kmenu_example.c b/contrib/C_Layer/EXAMPLE/kmenu/kmenu_example.c index 314ae884f3..15ebcb516a 100644 --- a/contrib/C_Layer/EXAMPLE/kmenu/kmenu_example.c +++ b/contrib/C_Layer/EXAMPLE/kmenu/kmenu_example.c @@ -23,23 +23,23 @@ int main() kmenu_init(NULL); ksubmenu_t *sub_menu1 = ksubmenu_new(); - ksubmenu_add(sub_menu1, kmenuitem_new(0, "Open", 101)); - ksubmenu_add(sub_menu1, kmenuitem_new(0, "Save", 102)); - ksubmenu_add(sub_menu1, kmenuitem_new(2, "", 0)); - ksubmenu_add(sub_menu1, kmenuitem_new(0, "Exit", 103)); + ksubmenu_add(sub_menu1, kmenuitem_new(KMENUITEM_NORMAL, "Open", 101)); + ksubmenu_add(sub_menu1, kmenuitem_new(KMENUITEM_NORMAL, "Save", 102)); + ksubmenu_add(sub_menu1, kmenuitem_new(KMENUITEM_SEPARATOR, NULL, 0)); + ksubmenu_add(sub_menu1, kmenuitem_new(KMENUITEM_NORMAL, "Exit", 103)); ksubmenu_t *sub_menu2 = ksubmenu_new(); - ksubmenu_add(sub_menu2, kmenuitem_new(0, "Find", 201)); - ksubmenu_add(sub_menu2, kmenuitem_new(0, "Replace", 202)); + ksubmenu_add(sub_menu2, kmenuitem_new(KMENUITEM_NORMAL, "Find", 201)); + ksubmenu_add(sub_menu2, kmenuitem_new(KMENUITEM_NORMAL, "Replace", 202)); ksubmenu_t *sub_menu22 = ksubmenu_new(); - ksubmenu_add(sub_menu22, kmenuitem_new(0, "cp1251", 211)); - ksubmenu_add(sub_menu22, kmenuitem_new(0, "UTF-8", 212)); - ksubmenu_add(sub_menu2, kmenuitem__submenu_new(1, "Encoding", sub_menu22)); + ksubmenu_add(sub_menu22, kmenuitem_new(KMENUITEM_NORMAL, "CP1251", 211)); + ksubmenu_add(sub_menu22, kmenuitem_new(KMENUITEM_NORMAL, "UTF-8", 212)); + ksubmenu_add(sub_menu2, kmenuitem__submenu_new(KMENUITEM_SUBMENU, "Encoding", sub_menu22)); ksubmenu_t *main_menu = ksubmenu_new(); - ksubmenu_add(main_menu, kmenuitem__submenu_new(1, "File", sub_menu1)); - ksubmenu_add(main_menu, kmenuitem__submenu_new(1, "Edit", sub_menu2)); + ksubmenu_add(main_menu, kmenuitem__submenu_new(KMENUITEM_SUBMENU, "File", sub_menu1)); + ksubmenu_add(main_menu, kmenuitem__submenu_new(KMENUITEM_SUBMENU, "Edit", sub_menu2)); extern volatile unsigned press_key; diff --git a/contrib/C_Layer/EXAMPLE/libguic_kolibri/Makefile b/contrib/C_Layer/EXAMPLE/libguic_kolibri/Makefile index 58cbb60161..34edc08f22 100644 --- a/contrib/C_Layer/EXAMPLE/libguic_kolibri/Makefile +++ b/contrib/C_Layer/EXAMPLE/libguic_kolibri/Makefile @@ -8,7 +8,7 @@ CLAYER:= $(abspath ../../) LDFLAGS = -static -S -nostdlib -T $(SDK_DIR)/lib/app-dynamic.lds \ --image-base 0 -lgcc -ldll -lc.dll -CFLAGS = -g -U_Win32 -U_WIN32 -U__MINGW32__ -std=gnu90 +CFLAGS = -g -U_Win32 -U_WIN32 -U__MINGW32__ -std=gnu90 -mno-ms-bitfields INCLUDES= -I. -I$(SDK_DIR)/sources/newlib/libc/include -I$(CLAYER)/INCLUDE LIBPATH:= -L $(SDK_DIR)/lib diff --git a/contrib/C_Layer/EXAMPLE/libguic_kolibri/dbutton_files.c b/contrib/C_Layer/EXAMPLE/libguic_kolibri/dbutton_files.c index 6d759dec95..b8e0923d5b 100644 --- a/contrib/C_Layer/EXAMPLE/libguic_kolibri/dbutton_files.c +++ b/contrib/C_Layer/EXAMPLE/libguic_kolibri/dbutton_files.c @@ -3,7 +3,8 @@ -Picture Button -StaticText -File Open/Save Dialog - -Filebrowser (planned) + -Filebrowser + -Controlling minimal window size Free for all @@ -16,6 +17,7 @@ #include #include #include +#include #include "kos32sys.h" #include "kolibri_gui.h" #include "kolibri_opendialog.h" @@ -24,6 +26,10 @@ char temp_path[4096]; char** sys_path = (char**)0x20; // hack - get path from KOS header. analog argv[0] +char* load_file_inmem(char* fname, int32_t* read_sz); // see below +void* read_folderdata(char* name); +void control_minimal_window_size(int wmin, int hmin); + int main(int argc, char **argv) { /* Load all libraries, initialize global tables like system color table and @@ -44,37 +50,29 @@ int main(int argc, char **argv) // load image for buttons const int icon_rgb_size = 16*16*3; // every icons 16x16 24bpp - char *image_data_rgb = malloc(icon_rgb_size * 3), - *image_data, *pc; + char *image_data_rgb, + *image_data, + *filedata; // make full path + argv strcpy(temp_path, *sys_path); - pc = strrchr(temp_path, '/'); // this fails if has params with '/' within. use argv[0] instead + char *pc = strrchr(temp_path, '/'); // this fails if has params with '/' within. use argv[0] instead if (pc) pc[1] = 0; strcat(temp_path, "reload_16x16_8b.png"); - debug_board_write_str(temp_path); - FILE *ficon = fopen(temp_path, "rb"); - if (!ficon) - { - debug_board_write_str("no icons file reload_16x16_8b.png "); - return 1; - } - int ficon_size = fread(image_data_rgb, 1, icon_rgb_size * 3, ficon); - if (ferror(ficon)) - { - debug_board_write_str("error reading file reload_16x16_8b.png "); - return 1; - } - fclose(ficon); +// debug_board_write_str(temp_path); + int32_t read_bytes; + filedata = load_file_inmem(temp_path, &read_bytes); + image_data_rgb = malloc(icon_rgb_size * 3); // we know size // определяем вид изображения и переводим его во временный буфер image_data - image_data = (*img_decode)(image_data_rgb, ficon_size, 0); + image_data = (*img_decode)(filedata, read_bytes, 0); // преобразуем изображение к формату rgb (*img_to_rgb2)(image_data, image_data_rgb); // удаляем временный буфер image_data (*img_destroy)(image_data); + free(filedata); // creating GUI using library functions - kolibri_window *main_window = kolibri_new_window(50, 40, 400, 160, "PictureButton and File dialog demo"); + kolibri_window *main_window = kolibri_new_window(50, 40, 430, 500, "PictureButton and File dialog demo"); pict_button tbar[3]; gui_add_pict_button(main_window, kolibri_pict_button(&tbar[0], X_Y(10, 16), X_Y(10, 16), image_data_rgb, image_data_rgb + icon_rgb_size, image_data_rgb + icon_rgb_size * 2, 24, NULL, 0)); @@ -84,7 +82,7 @@ int main(int argc, char **argv) statictext labels[3]; // tips gui_add_statictext(main_window, kolibri_statictext_def(&labels[0], X_Y(5, 28), "Open")); gui_add_statictext(main_window, kolibri_statictext_def(&labels[1], X_Y(35, 28), "Save")); - gui_add_statictext(main_window, kolibri_statictext_def(&labels[2], X_Y(65, 28), "Select Dir")); + gui_add_statictext(main_window, kolibri_statictext_def(&labels[2], X_Y(65, 28), "Select Dir & browse")); open_dialog *dlg_opensave = kolibri_new_open_dialog(OPEN, 10, 10, 420, 320); (*OpenDialog_init)(dlg_opensave); @@ -92,12 +90,37 @@ int main(int argc, char **argv) pathview pview; gui_add_pathview(main_window, kolibri_pathview(&pview, X_Y(10, 50), 330, 1, 0, dlg_opensave->openfile_path, temp_path, 0, 0)); // black font, no background, font 1 + filebrowser brows; + filedata = load_file_inmem("/rd/1/File managers/z_icons.png", &read_bytes); + image_data_rgb = malloc(icon_rgb_size * 20); // we know size + // определяем вид изображения и переводим его во временный буфер image_data + image_data = (*img_decode)(filedata, read_bytes, 0); + // преобразуем изображение к формату rgb + (*img_to_rgb2)(image_data, image_data_rgb); + // удаляем временный буфер image_data + (*img_destroy)(image_data); + free(filedata); + + filedata = load_file_inmem("/rd/1/File managers/icons.ini", &read_bytes); + gui_add_filebrowser(main_window, kolibri_filebrowser(&brows, X_Y(10, 400), X_Y(80, 300), X_Y(6, 9), X_Y(16, 16), image_data_rgb, NULL, 24, + filedata, filedata + read_bytes, + 0x00FF00, 0xbbddff, 0x000000, 0xFFFFFF, 0xFF0000)); + + // try devices "/" - good + brows.folder_data = read_folderdata("/rd/1"); + brows.select_panel_counter = 1; + do /* Start of main activity loop */ { switch(gui_event) { case KOLIBRI_EVENT_REDRAW: +//???? start red +//brows.marked_file = 1; + control_minimal_window_size(430, 500); + brows.all_redraw = 1; kolibri_handle_event_redraw(main_window); + brows.all_redraw = 0; break; case KOLIBRI_EVENT_NONE: break; @@ -117,8 +140,16 @@ int main(int argc, char **argv) case KOLIBRI_EVENT_MOUSE: // mouse_pos = get_mouse_pos(POS_WINDOW); // window relative // mouse_button = get_mouse_eventstate(); +//brows.all_redraw = 1; kolibri_handle_event_mouse(main_window); + + if (brows.mouse_keys_delta == 3) // double clicked in browser + { + debug_board_printf("mouse_keys_delta == 3, name %s\n", brows.selected_BDVK_adress->fname); + brows.mouse_keys_delta = 0; + } + if(tbar[0].click) // open { tbar[0].click = 0; @@ -138,7 +169,9 @@ int main(int argc, char **argv) (*OpenDialog_start)(dlg_opensave); if (dlg_opensave->status != 2 && dlg_opensave->status != 0) // fail or cancel (*path_show_prepare)(&pview); - kolibri_handle_event_redraw(main_window); + + // just calling line below draws incomplete + // kolibri_handle_event_redraw(main_window); } if(tbar[2].click) // select { @@ -146,8 +179,15 @@ int main(int argc, char **argv) dlg_opensave->mode = SELECT; (*OpenDialog_start)(dlg_opensave); if (dlg_opensave->status != 2 && dlg_opensave->status != 0) // fail or cancel + { (*path_show_prepare)(&pview); + free(brows.folder_data); + brows.folder_data = read_folderdata(dlg_opensave->openfile_path); + } + // we may redraw here, or just wait next redraw event + brows.all_redraw = 1; kolibri_handle_event_redraw(main_window); + brows.all_redraw = 0; } break; @@ -159,3 +199,85 @@ int main(int argc, char **argv) return 0; } + +char* load_file_inmem(char* fname, int32_t* read_sz) +{ + FILE *f = fopen(fname, "rb"); + if (!f) { + debug_board_printf("Can't open file: %s", fname); + exit(1); + } + if (fseek(f, 0, SEEK_END)) { + debug_board_printf("Can't SEEK_END file: %s", fname); + exit(1); + } + int filesize = ftell(f); + rewind(f); + char* fdata = malloc(filesize); + if(!fdata) { + debug_board_printf("No memory for file %s", fname); + exit(1); + } + *read_sz = fread(fdata, 1, filesize, f); + if (ferror(f)) { + debug_board_printf("Error reading file %s", fname); + exit(1); + } + fclose(f); + + return fdata; +} + +void* read_folderdata(char* name) +{ + struct fs_dirinfo di; + struct fs_dirheader dhead; + assert(sizeof di == 25); + memset(&di, 0, sizeof di); + di.ppath = name; + di.retval = (uint32_t)&dhead; + int rc = sf_file(1, &di); // read dir size + if(rc) { + debug_board_printf("Error reading dir size %s", name); + exit(1); + } + di.size = dhead.totl_blocks; + + char *retdir = malloc(sizeof dhead + dhead.totl_blocks * sizeof(struct fsBDFE)); + if(!retdir) { + debug_board_printf("No memory for dir %s", name); + exit(1); + } + di.retval = (uint32_t)retdir; + rc = sf_file(1, &di); // read dir size + if(rc) { + debug_board_printf("Error 2 reading dir size %s", name); + exit(1); + } + + debug_board_printf("Loaded dir [%s] etnries %d,\n first file [%s]\n", name, ((struct fs_dirheader*)(retdir))->curn_blocks, ((struct fsBDFE*)(retdir+32))->fname); + + return retdir; +} + + + +void control_minimal_window_size(int wmin, int hmin) +{ + char pinfo[1024]; + get_proc_info(pinfo); + + int win_hight = *(int*)(pinfo + 46), + win_width = *(int*)(pinfo + 42); + char win_status = pinfo[70]; + + if (win_status & 7) return; // maximized, minimized or titlebar mode + + if (win_width < wmin) + __asm__ __volatile__("int $0x40" ::"a"(67), "b"(-1), "c"(-1), "d"(wmin), "S"(-1)); // SF_CHANGE_WINDOW x,y,w,h + if (win_hight < hmin) + __asm__ __volatile__("int $0x40" ::"a"(67), "b"(-1), "c"(-1), "d"(-1), "S"(hmin)); // x,y,w,h + +} + + diff --git a/contrib/C_Layer/EXAMPLE/libguic_kolibri/option_menu.c b/contrib/C_Layer/EXAMPLE/libguic_kolibri/option_menu.c index 773ebccc66..26724e8505 100644 --- a/contrib/C_Layer/EXAMPLE/libguic_kolibri/option_menu.c +++ b/contrib/C_Layer/EXAMPLE/libguic_kolibri/option_menu.c @@ -137,7 +137,7 @@ int main() kolibri_handle_event_key(main_window); // ??????? if(keypress.code == SCAN_CODE_ALTM && get_os_keyb_modifiers() & (KEY_LALT | KEY_RALT)) - (*menu_bar_activate)(menu1); // wont work, immediately redraw command closes menu ( + (*menu_bar_activate)(menu1); // wont work, immediately redraw command closes menu ( . but Alt+F1 worked in opendial.asm:463 break; case KOLIBRI_EVENT_BUTTON: diff --git a/contrib/C_Layer/EXAMPLE/libguic_kolibri/reload_16x16_8b.png b/contrib/C_Layer/EXAMPLE/libguic_kolibri/reload_16x16_8b.png new file mode 100644 index 0000000000000000000000000000000000000000..db09b0519d789e5b301e1d5e59476b305980b03e GIT binary patch literal 1458 zcmV;j1x@;iP)Px&08mU+MF0Q*|NsB<_4x@hazNo0;rYL!fAkXd)6Pim4?Z$k*1~<>l$`2R3+hALS{Qvg&`uY0%5sm*5ivJRh{}PS=6N~>8j{g{r{~MA2Ba{Cnl>a7`|1FsRJD>kP zp#MUm|463)O{o7*tN%}_|52*{RIC4Iwf}Ir|8>0ocD(<7!2g26|A)l?jmiI)%>S|4 z|HI<{(&_)$?Em2K|K{`m5|sZFk^dBt|2n1rR0qg++{{jN=0t5F01MC9?@&p9z z1O@*E2mc2L><0<$2@CNH4DAdN{}B}K6c+9l80{Dt?inBMA0z)GBJLt9{3|Z+E-~;i zH1ISx@HadEJ3Rk9Jn%e1_d-GOK|}FFMe#*S`btUhNl*VzO!7=s|5Z}*QeFRDTk~6C z|6yJ8U19TKX#Z$t^k!`IY;*K;b@g?6_IiBve1G+Sh53b%|B;aQkgWf#tNg30`Kz({ zvA6%Xz52bw|HHugz{dN=&->5Q{L|I^)!qKx5UR*^V5jE%L5hsq@Xn1Y+pxY0 z7+KB5rBZntW>-dlVw{YqQMR0QMP_T~#zFTYQrx-%Ys^?jN=nvgGn$hjH6>|4E5=+& z@4C$r#T`pqX=o`)av<$$_cFy=HuOJF0B#NJ|1H^x|xM6t!EKa=ICmdBNL zXw6t#M=NTcFBBQHV3rviJg{$1bOcOLKPxYd**}7W{~^o$$4E8zE(hvUZ>M(k7DX? z0se6ES+CVf%Fzmba=C_RI>$i1XT=5G0j&&m4}XY&=1g_ubUr|^~R^Dg1(JVMhE z(?l@+aTW0cFJ`=pcrh*O<6}g8S}3*@yhT|VMtR(?^c#pbGYsPWA7eJ-V{YIqoB#j- M07*qoM6N<$f=wR)RR910 literal 0 HcmV?d00001