From 7bf14f7dc96d774f1d4a0a9738e25b3fafeefd01 Mon Sep 17 00:00:00 2001 From: siemargl Date: Sun, 16 Oct 2016 22:29:26 +0000 Subject: [PATCH] editor, treelist, msgbox demo runs git-svn-id: svn://kolibrios.org@6601 a494cfbc-eb01-0410-851d-a64ba20cac60 --- contrib/C_Layer/ASM/loadboxlib.asm | 26 + .../C_Layer/EXAMPLE/libguic_kolibri/Makefile | 9 +- .../libguic_kolibri/editor_tree_msgbox.c | 122 +++-- .../EXAMPLE/libguic_kolibri/tl_nod_16.png | Bin 0 -> 699 bytes .../EXAMPLE/libguic_kolibri/tl_sys_16.png | Bin 0 -> 1367 bytes contrib/C_Layer/INCLUDE/kolibri_editor.h | 78 +-- .../C_Layer/INCLUDE/kolibri_gui_elements.h | 7 + contrib/C_Layer/INCLUDE/kolibri_msgbox.h | 7 +- contrib/C_Layer/INCLUDE/kolibri_treelist.h | 506 +++++++++++++++--- 9 files changed, 604 insertions(+), 151 deletions(-) create mode 100644 contrib/C_Layer/EXAMPLE/libguic_kolibri/tl_nod_16.png create mode 100644 contrib/C_Layer/EXAMPLE/libguic_kolibri/tl_sys_16.png diff --git a/contrib/C_Layer/ASM/loadboxlib.asm b/contrib/C_Layer/ASM/loadboxlib.asm index 4be627eedc..5096e884af 100644 --- a/contrib/C_Layer/ASM/loadboxlib.asm +++ b/contrib/C_Layer/ASM/loadboxlib.asm @@ -183,3 +183,29 @@ public ted_but_reverse as '_ted_but_reverse_asm' public ted_but_find_next as '_ted_but_find_next' public ted_text_colored as 'ted_text_colored_asm' +public tl_data_init as '_tl_data_init_asm' +public tl_data_clear as '_tl_data_clear_asm' +public tl_info_clear as '_tl_info_clear_asm' +public tl_key as '_tl_key_asm' +public tl_mouse as '_tl_mouse' +public tl_draw as '_tl_draw' +public tl_info_undo as '_tl_info_undo_asm' +public tl_info_redo as '_tl_info_redo_asm' +public tl_node_add as '_tl_node_add_asm' +public tl_node_set_data as '_tl_node_set_data_asm' +public tl_node_get_data as '_tl_node_get_data_asm' +public tl_node_delete as '_tl_node_delete_asm' +public tl_cur_beg as '_tl_cur_beg_asm' +public tl_cur_next as '_tl_cur_next_asm' +public tl_cur_perv as '_tl_cur_perv_asm' +public tl_node_close_open as '_tl_node_close_open_asm' +public tl_node_lev_inc as '_tl_node_lev_inc_asm' +public tl_node_lev_dec as '_tl_node_lev_dec_asm' +public tl_node_move_up as '_tl_node_move_up' +public tl_node_move_down as '_tl_node_move_down' +public tl_node_poi_get_info as '_tl_node_poi_get_info_asm' +public tl_node_poi_get_next_info as '_tl_node_poi_get_next_info_asm' +public tl_node_poi_get_data as '_tl_node_poi_get_data_asm' +public tl_save_mem as '_tl_save_mem_asm' +public tl_load_mem as '_tl_load_mem_asm' +public tl_get_mem_size as '_tl_get_mem_size_asm' diff --git a/contrib/C_Layer/EXAMPLE/libguic_kolibri/Makefile b/contrib/C_Layer/EXAMPLE/libguic_kolibri/Makefile index 34edc08f22..5e5ad2aa0c 100644 --- a/contrib/C_Layer/EXAMPLE/libguic_kolibri/Makefile +++ b/contrib/C_Layer/EXAMPLE/libguic_kolibri/Makefile @@ -19,10 +19,13 @@ SOURCES = boardmsg.c option_menu.c OBJECTS = $(patsubst %.c, %.o, $(SOURCES)) -all: boardmsg option_menu scroll_progress dbutton_files +all: boardmsg option_menu scroll_progress dbutton_files editor_tree_msgbox + +editor_tree_msgbox: editor_tree_msgbox.o + $(LD) $(LIBPATH) --subsystem windows -o $@ $^ $(OBJPATH)/loadboxlib.obj $(OBJPATH)/loadlibimg.obj $(OBJPATH)/loadmsgbox.obj $(LDFLAGS) -Map=editor_tree_msgbox.map + kos32-objcopy $@ -O binary scroll_progress: scroll_progress.o -# $(LD) $(LIBPATH) --subsystem native -o $@ $^ $(OBJPATH)/loadboxlib.obj $(LDFLAGS) $(LD) $(LIBPATH) --subsystem windows -o $@ $^ $(OBJPATH)/loadboxlib.obj $(LDFLAGS) kos32-objcopy $@ -O binary @@ -36,7 +39,7 @@ boardmsg: boardmsg.o kos32-objcopy $@ -O binary dbutton_files: dbutton_files.o - $(LD) $(LIBPATH) --subsystem native -o $@ $^ $(OBJPATH)/loadboxlib.obj $(OBJPATH)/loadproclib.obj $(OBJPATH)/loadlibimg.obj $(LDFLAGS) -Map=dbutton_files.map + $(LD) $(LIBPATH) --subsystem native -o $@ $^ $(OBJPATH)/loadboxlib.obj $(OBJPATH)/loadproclib.obj $(OBJPATH)/loadlibimg.obj $(LDFLAGS) kos32-objcopy $@ -O binary %.o : %.c Makefile diff --git a/contrib/C_Layer/EXAMPLE/libguic_kolibri/editor_tree_msgbox.c b/contrib/C_Layer/EXAMPLE/libguic_kolibri/editor_tree_msgbox.c index a69678995f..d092d49009 100644 --- a/contrib/C_Layer/EXAMPLE/libguic_kolibri/editor_tree_msgbox.c +++ b/contrib/C_Layer/EXAMPLE/libguic_kolibri/editor_tree_msgbox.c @@ -22,9 +22,11 @@ #include "kolibri_libimg.h" #include "kolibri_msgbox.h" -char temp_path[4096]; +char run_path[4096]; +char fname[4096]; char* load_file_inmem(char* fname, int32_t* read_sz); // see below +char* load_image_file(char* fname); // see below int main(int argc, char **argv) { @@ -34,7 +36,7 @@ int main(int argc, char **argv) elements can be used after a successful call to this function */ kolibri_gui_init(); - kolibri_proclib_init(); // opensave && color dialogs +// kolibri_proclib_init(); // opensave && color dialogs kolibri_libimg_init(); // png handling int gui_event = KOLIBRI_EVENT_REDRAW; @@ -43,53 +45,46 @@ int main(int argc, char **argv) // pos_t mouse_pos; oskey_t keypress; - // load image for buttons - const int icon_rgb_size = 16*16*3; // every icons 16x16 24bpp - char *image_data_rgb, - *image_data, - *filedata; // make full path + argv - strcpy(temp_path, argv[0]); - char *pc = strrchr(temp_path, '/'); // this fails if has params with '/' within. use argv[0] instead + strcpy(run_path, argv[0]); + char *pc = strrchr(run_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); - 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)(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, 470, 500, "Editor, TreeView and MsgBox demo"); + kolibri_window *main_window = kolibri_new_window(50, 40, 490, 500, "Editor, TreeView and MsgBox demo"); editor *ed; editor *ed_lock; - gui_add_editor(main_window, ed = kolibri_new_editor(X_Y(10, 440), X_Y(20, 150), 0x1001, 2048, &ed_lock)); + gui_add_editor(main_window, ed = kolibri_new_editor(X_Y(0, 440), X_Y(20, 150), 0x1001, 2048, &ed_lock)); ed_lock = ed; + treelist *tl = kolibri_new_treelist(X_Y(0, 440), X_Y(200, 200), 16, X_Y(16, 16), 100, 50, 0, 0, TL_KEY_NO_EDIT | TL_DRAW_PAR_LINE, &ed_lock, 0x8080ff, 0x0000ff, 0xffffff); + treelist_data_init(tl); - 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); + // читаем файл с курсорами и линиями + strcpy(fname, run_path); + strcat(fname, "tl_sys_16.png"); + tl->data_img_sys = load_image_file(fname); - filedata = load_file_inmem("/rd/1/File managers/icons.ini", &read_bytes); + // читаем файл с иконками узлов + strcpy(fname, run_path); + strcat(fname, "tl_nod_16.png"); + tl->data_img = load_image_file(fname); + treelist_node_add(tl, "node1", 1, 0, 0); // где 1 номер иконки с книгой + treelist_cursor_next(tl); + + treelist_node_add(tl, "node2", 1, 0, 0); + treelist_cursor_next(tl); + + treelist_node_add(tl, "node3", 1, 0, 0); + treelist_cursor_next(tl); + + treelist_cursor_begin(tl); //;ставим курсор на начало списка + gui_add_treelist(main_window, tl); - int extended_key = 0, act = 0; msgbox* box = kolibri_new_msgbox("Exit", "Are\rYOU\rSure?", 3, "YES", "Absolute", "Not Yet", NULL); // default NOT do /* Start of main activity loop */ @@ -97,7 +92,7 @@ int main(int argc, char **argv) switch(gui_event) { case KOLIBRI_EVENT_REDRAW: - if (box->retval == 1 || box->retval == 2) return 0; // msgbox closes + if (box->retval == 1 || box->retval == 2) goto clearing; // msgbox closes kolibri_handle_event_redraw(main_window); break; @@ -115,8 +110,7 @@ int main(int argc, char **argv) { case BTN_QUIT: if (box->retval == 3 || box->retval == 0) // not started or cancelled, analyze when redraw after closing msgbox - kolibri_start_msgbox(box, NULL); - return 0; + kolibri_start_msgbox(box, NULL); break; } break; @@ -127,6 +121,60 @@ int main(int argc, char **argv) gui_event = get_os_event(); } while(1) ; /* End of main activity loop */ + +clearing: + editor_delete(ed); + treelist_data_clear(tl); 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; +} + +char* load_image_file(char* fname) +{ + int32_t read_bytes = -1, w, h; + char *image_data = 0, *image_data_rgb = 0, *filedata = 0; + + filedata = load_file_inmem(fname, &read_bytes); + // определяем вид изображения и переводим его во временный буфер image_data + image_data = (*img_decode)(filedata, read_bytes, 0); + w = *(int*)(image_data +4); + h = *(int*)(image_data +8); + image_data_rgb = malloc(w * h * 3); + // преобразуем изображение к формату rgb + (*img_to_rgb2)(image_data, image_data_rgb); + // удаляем временный буфер image_data + (*img_destroy)(image_data); + free(filedata); + + return image_data_rgb; +} + diff --git a/contrib/C_Layer/EXAMPLE/libguic_kolibri/tl_nod_16.png b/contrib/C_Layer/EXAMPLE/libguic_kolibri/tl_nod_16.png new file mode 100644 index 0000000000000000000000000000000000000000..08505dc95e4ebbfec4550667fd04b5aaa5bc299a GIT binary patch literal 699 zcmV;s0!00ZP)Px#1ZP1_K>z@;j|==^1poj5AY({UO#lFTCIA3{ga82g0001h=l}q9FaQARU;qF* zm;eA5aGbhPJOBU!IY~r8R5(v#Y-sq;!0`XqulGQb0RynI3NSJ_xn3m4ukSg>W$qHQ%by_J`}Sk6j##hPt|c(Q)sLt?!nX|Hd>6MMHi4 zzqItvDpq%yqTe!<{gSu7TTy|o2dbgI;eUR?cU_x%%)u`iYX35T(*1v+9t8|NAPqn_ zIC(r_^M1-u`3I^Lq5-T&(fV#>CBhz%26w+_OhAL(9x>GYL)QS*Q~FC8qz9U_8LF%Q z2$|mosZ096;EF>}$xjvQyH!;nJq$of(CGm~J=g&$9~qn?Kai!QQPx#1ZP1_K>z@;j|==^1poj532;bRa{vGh)&Kwv)&Y=jd7J&jG7(Kc{K)Jgeq>scjF-r&xO-UG zjUbEQvX{MxDENhncu+ieRT1%^qKF>E=<~gru1-yLbyu~TXtW8B87BRH^Xlu>zg`V< zU4Tz9_9@QfYXt1reGh7z3$U{72y_+R2BI|r$eC?t@WZb0P_toG0AdH|XTSy!vS&g7 z;sf^Ve+BiqJ|3=Y)lLQ&0q9Qy@d1mQH^Z1;D@qTm_SgeRklEQaygz(ELt@NLVc^2TW;N0PLzI;12f3iV5X_pSS%FW9!Fpa=^|=V05ndF$JwVuapDACKMk= z(TR$))kN|E8fPnjv$dZ$iP|i}mZLRJB-2{?8Uff|oL}5rZ?Z%+BiMulz&kGK#H0_B zd4OW$v#$lz2QKanF6slvTyPZxp^GXV7g z0Vqf4Ad!G`Cuei#=co@vk`a(o`zMBMu2LV|zn}3P1wce1QhsCvVSop?(Ynhgnx0j}77S|MJQEXu z@i;ULorw9sRjutPW~TS%#dPhzDxMEi`@MNI^tQB{0WV(6)aHYiPZ;#9vPdXlfIH_I z6o0BVM{sOoMQI@^R$PM%tMi5#kSNtJrq*ND6NdiClg~c{$N3GKn*N4DVIY3}fSl9m zG%Q`3f!f-(0L0h?0yvHXU0q#}$t({*e8Aqluc5K=Padvp>GXOIaB(-$L3}_%!#-HH zEW;mGEuYVGfDEat+fu%m=FM9Kot>TjgTg`gN|97oE6aJwlC_Y_<*Weh?d>pY*8K7a za=G(RQ!|H?Rm*0xKA4>6&Rqx{9XIXj2VxYcDXO#G@!uOpowF4noBfwJiP|i}{^sik zUtK;JiA9*g8$8||E**2itm71}gLnG1(A}~F{@ON9s|$oq_@gZaJ)2tffZm2l@a*BB zI+xE0;{D5~47%$p&AYSCnLfLF8TElP!wl$a#Bb5*gLTtTcwaID5`FN+^g(ju8G;gs zE+=%HwmUD-p<8!eINp*9KQA1p8wCSz4f!DIyl`m!Vz_-a8W4S6z;%9*vW+GWh|h}7 z^oa99vNIWvy6RqOl)58vb5-X-?0TXK@al;t@V>DZ?;FkaL=8aH6R9AnLV}~9>I0>o zs6qk&ojy?Oi3BOC_l;t_ZS(;ZC9Ud-VfugybKUBFqd()MjYa4KwVqhS`^Jy1C(6!t zaSR^Fhe{f_**+DNNG>vdaf5AZ|X8FKL86h?Ng) z^g(1ku+az6`9Px&;^l*otW4QSx1`N`W9)pOMi4t6Bob#ZX*hH_gXd>5dLPm^;ls#K zCwu1N>qh|q9m$3XAh(&??R~o+f#?sVPX_xyYBRO{mIR>pqCe>~aG?w+0Dvw8sk!J>r?2_QB3I<8)9hK13y=6ql|AI$pTJDQ26Izia~ ZKLEyLIYFLsfvx}m002ovPDHLkV1mS7irD}F literal 0 HcmV?d00001 diff --git a/contrib/C_Layer/INCLUDE/kolibri_editor.h b/contrib/C_Layer/INCLUDE/kolibri_editor.h index bf8f3a9e4e..3a8c38e642 100644 --- a/contrib/C_Layer/INCLUDE/kolibri_editor.h +++ b/contrib/C_Layer/INCLUDE/kolibri_editor.h @@ -120,7 +120,7 @@ struct editor_syntax_file static struct editor_syntax_file default_syntax = { 10, //count_colors_text - 0, // count_key_words dd (f1-text)/48 + 1, // count_key_words dd (f1-text)/48, minimum 1 0xf1fcd0, //color_cursor dd 0xf1fcd0 0x080808, //color_wnd_capt dd 0x080808 0x1C1C1C, //color_wnd_work dd 0x1C1C1C @@ -165,28 +165,28 @@ extern void (*ted_but_sumb_upper_asm)(editor *) __attribute__((__stdcall__)); static inline void editor_selected_toupper(editor *ed) { __asm__ __volatile__ ( - "push edi \n\t" - "push esi \n\t":::); + "push %%edi \n\t" + "push %%esi \n\t":::); (*ted_but_sumb_upper_asm)(ed); __asm__ __volatile__ ( - "pop esi \n\t" - "pop edi \n\t":::); + "pop %%esi \n\t" + "pop %%edi \n\t":::); } extern void (*ted_but_sumb_lover_asm)(editor *) __attribute__((__stdcall__)); static inline void editor_selected_tolower(editor *ed) { __asm__ __volatile__ ( - "push edi \n\t" - "push esi \n\t":::); + "push %%edi \n\t" + "push %%esi \n\t":::); (*ted_but_sumb_lover_asm)(ed); __asm__ __volatile__ ( - "pop esi \n\t" - "pop edi \n\t":::); + "pop %%esi \n\t" + "pop %%edi \n\t":::); } @@ -194,28 +194,28 @@ extern void (*ted_but_convert_by_table_asm)(editor *, char* table) __attribute__ static inline void editor_convert_by_table(editor *ed, char* table) { __asm__ __volatile__ ( - "push edi \n\t" - "push esi \n\t":::); + "push %%edi \n\t" + "push %%esi \n\t":::); (*ted_but_convert_by_table_asm)(ed, table); __asm__ __volatile__ ( - "pop esi \n\t" - "pop edi \n\t":::); + "pop %%esi \n\t" + "pop %%edi \n\t":::); } extern int (*ted_can_save_asm)(editor *) __attribute__((__stdcall__)); static inline int editor_can_save(editor *ed) -/// return 1 if can be saved +/// return 1 if need to be saved (has changes), 0 otherwise { int ret; __asm__ __volatile__ ( - "push edi \n\t":::); + "push %%edi \n\t":::); (*ted_can_save_asm)(ed); __asm__ __volatile__ ( - "pop edi \n\t":"=a"(ret)::); + "pop %%edi \n\t":"=a"(ret)::); return ret; } @@ -224,12 +224,12 @@ static inline void editor_clear(editor *ed, int all) /// all==1 - clear all memory { __asm__ __volatile__ ( - "push edi \n\t":::); + "push %%edi \n\t":::); (*ted_clear_asm)(ed, all); __asm__ __volatile__ ( - "pop edi \n\t":::); + "pop %%edi \n\t":::); } extern void (*ted_delete_asm)(editor *) __attribute__((__stdcall__)); @@ -237,12 +237,12 @@ static inline void editor_delete(editor *ed) /// frees all memory (destroy) { __asm__ __volatile__ ( - "push edi \n\t":::); + "push %%edi \n\t":::); (*ted_delete_asm)(ed); __asm__ __volatile__ ( - "pop edi \n\t":::); + "pop %%edi \n\t":::); free(ed->scr_w); free(ed->scr_h); free(ed->buffer); @@ -254,12 +254,12 @@ static inline void editor_init(editor *ed) /// allocate memory { __asm__ __volatile__ ( - "push edi \n\t":::); + "push %%edi \n\t":::); (*ted_init_asm)(ed); __asm__ __volatile__ ( - "pop edi \n\t":::); + "pop %%edi \n\t":::); } extern int (*ted_is_select)(editor *) __attribute__((__stdcall__)); @@ -268,12 +268,12 @@ static inline int editor_is_select(editor *ed) { int ret; __asm__ __volatile__ ( - "push ebx \n\t":::); + "push %%ebx \n\t":::); (*ted_is_select)(ed); __asm__ __volatile__ ( - "pop ebx \n\t":"=a"(ret)::); + "pop %%ebx \n\t":"=a"(ret)::); return ret; } @@ -303,12 +303,12 @@ static inline int editor_openfile(editor *ed, char *fname, int *readbytes) int ret; struct fs_dirinfo di; __asm__ __volatile__ ( - "push edi \n\t":::); + "push %%edi \n\t":::); (*ted_open_file_asm)(ed, &di, fname); __asm__ __volatile__ ( - "pop edi \n\t":"=b"(*readbytes), "=a"(ret)::); + "pop %%edi \n\t":"=b"(*readbytes), "=a"(ret)::); return ret; } @@ -327,50 +327,50 @@ extern void (*ted_but_cut)(editor *) __attribute__((__stdcall__)); static inline void editor_cut(editor *ed) { __asm__ __volatile__ ( - "push edi \n\t":::); + "push %%edi \n\t":::); (*ted_but_cut)(ed); __asm__ __volatile__ ( - "pop edi \n\t":::); + "pop %%edi \n\t":::); } extern void (*ted_but_undo)(editor *) __attribute__((__stdcall__)); static inline void editor_undo(editor *ed) { __asm__ __volatile__ ( - "push edi \n\t":::); + "push %%edi \n\t":::); (*ted_but_undo)(ed); __asm__ __volatile__ ( - "pop edi \n\t":::); + "pop %%edi \n\t":::); } extern void (*ted_but_redo)(editor *) __attribute__((__stdcall__)); static inline void editor_redo(editor *ed) { __asm__ __volatile__ ( - "push edi \n\t":::); + "push %%edi \n\t":::); (*ted_but_redo)(ed); __asm__ __volatile__ ( - "pop edi \n\t":::); + "pop %%edi \n\t":::); } extern void (*ted_but_reverse)(editor *) __attribute__((__stdcall__)); static inline void editor_reverse(editor *ed) { __asm__ __volatile__ ( - "push edi \n\t" - "push ebx\n\t":::); + "push %%edi \n\t" + "push %%ebx\n\t":::); (*ted_but_reverse)(ed); __asm__ __volatile__ ( - "pop ebx \n\t" - "pop edi \n\t":::); + "pop %%ebx \n\t" + "pop %%edi \n\t":::); } extern void (*ted_text_colored_asm)() __attribute__((__stdcall__)); @@ -428,7 +428,7 @@ static void editor_key(editor* ed) editor_keyboard(ed, conv_table, ed_ctrl, get_key().val); } -inline void gui_add_editor(kolibri_window *wnd, editor* e) +static inline void gui_add_editor(kolibri_window *wnd, editor* e) { kolibri_window_add_element(wnd, KOLIBRI_EDITOR, e); } @@ -472,8 +472,8 @@ static inline editor* kolibri_new_editor(uint32_t x_w, uint32_t y_h, uint32_t fo */ ed->symbol_new_line = 20; // ascii(20) - ed->scr_w = kolibri_new_scrollbar_def(0, 0, 100, 30, 0); - ed->scr_h = kolibri_new_scrollbar_def(0, 0, 100, 30, 0); + ed->scr_w = kolibri_new_scrollbar_def(X_Y(50, 16), X_Y(50, 300), 100, 30, 0); + ed->scr_h = kolibri_new_scrollbar_def(X_Y(0, 150), X_Y(50, 16), 100, 30, 0); ed->buffer_size = TE_BUF_SIZE; ed->buffer = malloc(TE_BUF_SIZE); diff --git a/contrib/C_Layer/INCLUDE/kolibri_gui_elements.h b/contrib/C_Layer/INCLUDE/kolibri_gui_elements.h index ee10205f45..65c11302d3 100644 --- a/contrib/C_Layer/INCLUDE/kolibri_gui_elements.h +++ b/contrib/C_Layer/INCLUDE/kolibri_gui_elements.h @@ -26,6 +26,7 @@ enum KOLIBRI_GUI_ELEMENT_TYPE { KOLIBRI_PATHSHOW, KOLIBRI_FILEBROWSE, KOLIBRI_EDITOR, + KOLIBRI_TREELIST, /* Add elements above this element in order to let KOLIBRI_NUM_GUI_ELEMENTS */ /* stay at correct value */ @@ -81,6 +82,7 @@ void kolibri_window_add_element(kolibri_window *some_window, enum KOLIBRI_GUI_EL #include "kolibri_statictext.h" #include "kolibri_filebrowse.h" #include "kolibri_editor.h" +#include "kolibri_treelist.h" /*---------------------Define various functions for initializing GUI-------*/ @@ -156,6 +158,11 @@ kolibri_gui_op_table[KOLIBRI_EDITOR].redraw_fn = (cb_elem_boxlib)ted_draw; kolibri_gui_op_table[KOLIBRI_EDITOR].mouse_fn = (cb_elem_boxlib)ted_mouse; kolibri_gui_op_table[KOLIBRI_EDITOR].key_fn = (cb_elem_boxlib)editor_key; debug_board_printf("KOLIBRI_EDITOR (%x,%x,%x)\n", ted_draw, ted_mouse, editor_key); + +kolibri_gui_op_table[KOLIBRI_TREELIST].redraw_fn = (cb_elem_boxlib)tl_draw; +kolibri_gui_op_table[KOLIBRI_TREELIST].mouse_fn = (cb_elem_boxlib)tl_mouse; +kolibri_gui_op_table[KOLIBRI_TREELIST].key_fn = (cb_elem_boxlib)treelist_key; +debug_board_printf("KOLIBRI_TREELIST (%x,%x,%x)\n", tl_draw, tl_mouse, treelist_key); } /* Create a new main GUI window for KolibriOS */ diff --git a/contrib/C_Layer/INCLUDE/kolibri_msgbox.h b/contrib/C_Layer/INCLUDE/kolibri_msgbox.h index 918de6988c..7c6db9db48 100644 --- a/contrib/C_Layer/INCLUDE/kolibri_msgbox.h +++ b/contrib/C_Layer/INCLUDE/kolibri_msgbox.h @@ -29,16 +29,19 @@ static inline msgbox* kolibri_new_msgbox(char* title, char* text, int def_but, . msgbox* box = calloc(sizeof(msgbox), 1); box->retval = (uint8_t)def_but; - char *pc = box->texts, - *but_text = va_arg(vl, char*); + char *pc = box->texts; strcpy(pc, title); pc += strlen(title) + 1; + strcpy(pc, text); + pc += strlen(text) + 1; + char *but_text = va_arg(vl, char*); while (but_text) { strcpy(pc, but_text); pc += strlen(but_text) + 1; // assert(pc - box->texts < sizeof box->texts); + but_text = va_arg(vl, char*); } va_end(vl); diff --git a/contrib/C_Layer/INCLUDE/kolibri_treelist.h b/contrib/C_Layer/INCLUDE/kolibri_treelist.h index c36ba90877..0aaebefe51 100644 --- a/contrib/C_Layer/INCLUDE/kolibri_treelist.h +++ b/contrib/C_Layer/INCLUDE/kolibri_treelist.h @@ -1,71 +1,32 @@ #ifndef KOLIBRI_TREELIST_H #define KOLIBRI_TREELIST_H -/* -el_focus dd tedit0 -mouse_dd dd 0 -tree1 tree_list 264,count_of_dir_list_files+2, tl_key_no_edit+tl_draw_par_line+tl_list_box_mode,\ - 16,16, 0x8080ff,0x0000ff,0xffffff, 0,70,TED_PANEL_WIDTH-17,120, 0,0,0, el_focus,\ - ws_dir_lbox,0 -tree3 tree_list MAX_COLOR_WORD_LEN,3,tl_key_no_edit,\ - 16,16, 0x8080ff,0x0000ff,0xffffff, 5,30,300,160, 16, 0,0, el_focus, w_scr_t3,0 - -tree_file_struct: - dd 1 - dd 0,0,count_of_dir_list_files - dd dir_mem - db 0 - dd file_name ;sys_path -*/ -/* -;struct TreeList -; type dw ? ;+ 0 тип элемента, или индекс иконки для узла -; lev db ? ;+ 2 уровень элемента -; clo db ? ;+ 3 флаг закрытия, или открытия (имеет смысл для родительского узла) -; perv dd ? ;+ 4 индекс предыдущего элемента -; next dd ? ;+ 8 индекс последующего элемента -; tc dd ? ;+12 врем. создания -; td dd ? ;+16 врем. удаления -;ends - -struc tree_list info_size,info_max_count,style, img_cx,img_cy,\ - col_bkg,col_zag,col_txt, box_l,box_t,box_w,box_h, capt_cy,info_capt_offs,\ - info_capt_len,el_focus, p_scroll,on_press { -.box_left dd box_l -.box_top dd box_t -.box_width dd box_w -.box_height dd box_h -.data_info dd 0 -.info_size dw info_size -.info_max_count dd info_max_count -.style dd style -.data_nodes dd 0 -.data_img dd 0 -.img_cx dw img_cx -.img_cy dw img_cy -.data_img_sys dd 0 -.ch_tim dd 0 -.tim_undo dd 0 -.cur_pos dd 0 -.col_bkg dd col_bkg -.col_zag dd col_zag -.col_txt dd col_txt -.capt_cy dw capt_cy -.info_capt_offs dw info_capt_offs -.info_capt_len dw info_capt_len -.el_focus dd el_focus -.p_scroll dd p_scroll -.on_press dd on_press -} -*/ -// константы стиля +/// константы стиля enum tl_style { TL_KEY_NO_EDIT = 1, // элемент нельзя редактировать на клавиатуре (изменять уровни, удалять) TL_DRAW_PAR_LINE = 2, // рисовать линии к родительскому узлу TL_LISTBOX_MODE = 4 //стиль не отображает уровни (как в ListBox все одного уровня) }; +/// константы для функций +enum tl_err { + TL_ERR_LOAD_CAPTION = 1, //в памяти нет заголовка 'tree' + TL_ERR_SAVE_MEMOTY_SIZE = 2, //не хватает памяти для сохранения элемента + TL_ERR_LOAD_INFO_SIZE = 4, //не совпадает размер информационной структуры при открытии +}; + +typedef struct __attribute__ ((__packed__)) { + uint16_t type; //тип элемента, или индекс иконки для узла + uint8_t lev; //уровень элемента + uint8_t clo; //флаг закрытия, или открытия (имеет смысл для родительского узла) + uint32_t prev; //индекс предыдущего элемента + uint32_t next; //индекс последующего элемента + uint32_t tcreat; //врем. создания + uint32_t tdel; //врем. удаления +} treelist_node; + + typedef struct __attribute__ ((__packed__)) { uint32_t left; uint32_t top; @@ -75,7 +36,7 @@ typedef struct __attribute__ ((__packed__)) { uint16_t info_size; // размер данных выделяемых для каждого узла (пользовательськие данные + текст для подписи) uint32_t info_max_count; // максимальное количество узлов, которые можно добавить в элемент uint32_t style; // стили элемента - void *data_nodes; // указатель на структуры узлов + treelist_node *data_nodes; // указатель на структуры узлов void *data_img; // указатель на изображения с иконками узлов uint16_t img_cx; // ширина иконок uint16_t img_cy; // высота иконок @@ -84,23 +45,428 @@ typedef struct __attribute__ ((__packed__)) { uint32_t tim_undo; // количество отмененных действий uint32_t cur_pos; // позиция курсора color_t col_bkg; // цвет фона - color_t tl_col_zag; // цвет заголовка - color_t tl_col_txt; // цвет текста + color_t col_zag; // цвет заголовка + color_t col_txt; // цвет текста uint16_t capt_cy; // высота подписи uint16_t info_capt_offs;//сдвиг для начала текста (подписи узла) uint16_t info_capt_len;//длина текста подписи узла (если = 0 то до конца структуры) void *el_focus; // указатель на структуру элемента в фокусе - void *p_scroll; // указатель на структуру скроллинга + scrollbar *p_scroll; // указатель на структуру скроллинга void *on_press; // +84 указатель на функцию, которая вызывается при нажатии Enter } treelist; -/* -;константы для функций -tl_err_save_memory_size equ 10b ;не хватает памяти для сохранения элемента -tl_err_load_caption equ 1b ;в памяти нет заголовка 'tree' -tl_err_load_info_size equ 100b ;не совпадает размер информационной структуры при открытии -tl_load_mode_add equ 0x20000 ;опция считывания в режиме добавления информации -tl_save_load_heder_size equ 26 ;размер заголовка для записи/чтения элементов -*/ +static inline treelist* kolibri_new_treelist( uint32_t x_w, uint32_t y_h, uint16_t capt_cy, uint32_t icon_size_xy, uint16_t info_size, uint32_t info_max_count, + uint16_t info_capt_len, uint16_t info_capt_offs, enum tl_style style, void *el_focus, color_t back, color_t title, color_t txt) +{ + treelist *tl = (treelist *)calloc(1, sizeof(treelist)); + tl->left= x_w >> 16; + tl->width = x_w & 0xFFFF; + tl->top = y_h >> 16; + tl->height = y_h & 0xFFFF; + tl->info_size = info_size; + tl->info_max_count = info_max_count; + tl->style = style; + tl->img_cx = icon_size_xy >> 16; + tl->img_cy = icon_size_xy & 0xFFFF; + tl->col_bkg = back; + tl->col_zag = title; + tl->col_txt = txt; + tl->info_capt_len = info_capt_len; + tl->info_capt_offs = info_capt_offs; + tl->el_focus = el_focus; + tl->p_scroll = kolibri_new_scrollbar_def(X_Y(0, 16), X_Y(70, 30), 100, 30, 0); + return tl; +} + +static inline void gui_add_treelist(kolibri_window *wnd, treelist* tl) +{ + kolibri_window_add_element(wnd, KOLIBRI_TREELIST, tl); +} + + +///реакция на мышь +extern void (*tl_mouse)(treelist *) __attribute__((__stdcall__)); + +///вывод списка на экран +extern void (*tl_draw)(treelist *) __attribute__((__stdcall__)); + +///перемещаем узел вверх +extern void (*tl_node_move_up)(treelist *) __attribute__((__stdcall__)); + +///перемещаем узел вниз +extern void (*tl_node_move_down)(treelist *) __attribute__((__stdcall__)); + +extern void (*tl_data_init_asm)(treelist *) __attribute__((__stdcall__)); +///выделение памяти для структур списка и основной информации (конструктор) +static inline void treelist_data_init(treelist *tl) +{ + __asm__ __volatile__ ( + "push %%edi \n\t":::); + + (*tl_data_init_asm)(tl); + + __asm__ __volatile__ ( + "pop %%edi \n\t":::); +} + +extern void (*tl_data_clear_asm)(treelist *) __attribute__((__stdcall__)); +///очистка памяти элемента (деструктор) +static inline void treelist_data_clear(treelist *tl) +{ + __asm__ __volatile__ ( + "push %%edi \n\t":::); + + (*tl_data_clear_asm)(tl); + + __asm__ __volatile__ ( + "pop %%edi \n\t":::); +} + +extern void (*tl_info_clear_asm)(treelist *) __attribute__((__stdcall__)); +///очистка списка (информации) +static inline void treelist_info_clear(treelist *tl) +{ + __asm__ __volatile__ ( + "push %%edi \n\t":::); + + (*tl_info_clear_asm)(tl); + + __asm__ __volatile__ ( + "pop %%edi \n\t":::); +} + +extern void (*tl_key_asm)(treelist *) __attribute__((__stdcall__)); +///реакция на клавиатуру +static inline void treelist_key(treelist *tl) +{ + __asm__ __volatile__ ( + "push %%ebx \n\t" + "push %%edi \n\t":::); + + (*tl_key_asm)(tl); + + __asm__ __volatile__ ( + "pop %%edi \n\t" + "pop %%ebx \n\t":::); +} + +extern void (*tl_info_undo_asm)(treelist *) __attribute__((__stdcall__)); +///отмена действия +static inline void treelist_undo(treelist *tl) +{ + __asm__ __volatile__ ( + "push %%edi \n\t":::); + + (*tl_info_undo_asm)(tl); + + __asm__ __volatile__ ( + "pop %%edi \n\t":::); +} + +extern void (*tl_info_redo_asm)(treelist *) __attribute__((__stdcall__)); +///повтор действия +static inline void treelist_redo(treelist *tl) +{ + __asm__ __volatile__ ( + "push %%edi \n\t":::); + + (*tl_info_redo_asm)(tl); + + __asm__ __volatile__ ( + "pop %%edi \n\t":::); +} + +extern void (*tl_node_add_asm)(treelist *, uint32_t n_opt, void *n_info) __attribute__((__stdcall__)); +///добавить узел +///input: +/// tlist - указатель на структуру листа +/// n_opt - опции добавления +/// n_info - указатель на добавляемые данные +static inline void treelist_node_add(treelist *tl, void *n_info, uint16_t type, uint8_t clos, uint8_t lev) +{ + __asm__ __volatile__ ( + "push %%ebx \n\t" + "push %%edi \n\t":::); + + uint32_t n_opt = (type << 16) | (clos << 8) | lev; + (*tl_node_add_asm)(tl, n_opt, n_info); + + __asm__ __volatile__ ( + "pop %%edi \n\t" + "pop %%ebx \n\t":::); +} + +extern void (*tl_node_set_data_asm)(treelist *, void *n_info) __attribute__((__stdcall__)); +///записать в текущий узел +///input: +/// tlist - указатель на структуру листа +/// n_info - указатель на данные +static inline void treelist_node_setdata(treelist *tl, void *n_info) +{ + __asm__ __volatile__ ( + "push %%esi \n\t" + "push %%edi \n\t":::); + + (*tl_node_set_data_asm)(tl, n_info); + + __asm__ __volatile__ ( + "pop %%edi \n\t" + "pop %%esi \n\t":::); +} + +extern void* (*tl_node_get_data_asm)(treelist *) __attribute__((__stdcall__)); +///взять указатель на данные узла под курсором +static inline void* treelist_getdata(treelist *tl) +{ + __asm__ __volatile__ ( + "push %%edi \n\t":::); + + void *res = + (*tl_node_get_data_asm)(tl); + + __asm__ __volatile__ ( + "pop %%edi \n\t":::); + return res; +} + +extern void (*tl_node_delete_asm)(treelist *) __attribute__((__stdcall__)); +///удалить узел под курсором +static inline void treelist_node_delete(treelist *tl) +{ + __asm__ __volatile__ ( + "push %%edi \n\t":::); + + (*tl_node_delete_asm)(tl); + + __asm__ __volatile__ ( + "pop %%edi \n\t":::); +} + +extern void (*tl_cur_beg_asm)(treelist *) __attribute__((__stdcall__)); +///поставить курсор на первый узел +static inline void treelist_cursor_begin(treelist *tl) +{ + __asm__ __volatile__ ( + "push %%edi \n\t":::); + + (*tl_cur_beg_asm)(tl); + + __asm__ __volatile__ ( + "pop %%edi \n\t":::); +} + +extern void (*tl_cur_next_asm)(treelist *) __attribute__((__stdcall__)); +///перенести курсор на 1 позицию ниже +static inline void treelist_cursor_next(treelist *tl) +{ + __asm__ __volatile__ ( + "push %%ebx \n\t" + "push %%esi \n\t" + "push %%edi \n\t":::); + + (*tl_cur_next_asm)(tl); + + __asm__ __volatile__ ( + "pop %%edi \n\t" + "pop %%esi \n\t" + "pop %%ebx \n\t":::); +} + +extern void (*tl_cur_perv_asm)(treelist *) __attribute__((__stdcall__)); +///перенести курсор на 1 позицию выше +static inline void treelist_cursor_prev(treelist *tl) +{ + __asm__ __volatile__ ( + "push %%ebx \n\t" + "push %%esi \n\t" + "push %%edi \n\t":::); + + (*tl_cur_perv_asm)(tl); + + __asm__ __volatile__ ( + "pop %%edi \n\t" + "pop %%esi \n\t" + "pop %%ebx \n\t":::); +} + +extern void (*tl_node_close_open_asm)(treelist *) __attribute__((__stdcall__)); +///открыть/закрыть узел (работает с узлами которые имеют дочерние узлы) +static inline void treelist_close_open(treelist *tl) +{ + __asm__ __volatile__ ( + "push %%edi \n\t":::); + + (*tl_node_close_open_asm)(tl); + + __asm__ __volatile__ ( + "pop %%edi \n\t":::); +} + +extern void (*tl_node_lev_inc_asm)(treelist *) __attribute__((__stdcall__)); +///увеличить уровень +static inline void treelist_level_inc(treelist *tl) +{ + __asm__ __volatile__ ( + "push %%edi \n\t":::); + + (*tl_node_lev_inc_asm)(tl); + + __asm__ __volatile__ ( + "pop %%edi \n\t":::); +} + +extern void (*tl_node_lev_dec_asm)(treelist *) __attribute__((__stdcall__)); +///уменьшить уровень +static inline void treelist_level_dec(treelist *tl) +{ + __asm__ __volatile__ ( + "push %%edi \n\t":::); + + (*tl_node_lev_dec_asm)(tl); + + __asm__ __volatile__ ( + "pop %%edi \n\t":::); +} + +extern treelist_node* (*tl_node_poi_get_info_asm)(treelist *, int node_ind) __attribute__((__stdcall__)); +///взять указатель на структуру узла в указанной позиции +///input: +/// tlist - pointer to 'TreeList' struct +/// node_ind - node index +///output - pointer to node info or NULL +static inline treelist_node* treelist_getnode(treelist *tl, int node_ind) +{ + __asm__ __volatile__ ( + "push %%ebx \n\t" + "push %%edi \n\t":::); + + treelist_node *ret = + (*tl_node_poi_get_info_asm)(tl, node_ind); + + __asm__ __volatile__ ( + "pop %%edi \n\t" + "pop %%ebx \n\t":::); + return ret; +} + +extern treelist_node* (*tl_node_poi_get_next_info_asm)(treelist *, treelist_node*) __attribute__((__stdcall__)); +///взять указатель на следущую структуру узла +///input: +/// tlist - pointer to 'TreeList' struct +/// node_p - node param struct +///output - pointer to next node struct or NULL +static inline treelist_node* treelist_getnode_next(treelist *tl, treelist_node* node) +{ + __asm__ __volatile__ ( + "push %%ebx \n\t" + "push %%edi \n\t":::); + + treelist_node *ret = + (*tl_node_poi_get_next_info_asm)(tl, node); + + __asm__ __volatile__ ( + "pop %%edi \n\t" + "pop %%ebx \n\t":::); + return ret; +} + +extern void* (*_tl_node_poi_get_data_asm)(treelist *, treelist_node*) __attribute__((__stdcall__)); +///;взять указатель на данные узла +///input: +/// tlist - pointer to 'TreeList' struct +/// node_p - node param struct +///output - pointer +static inline void* treelist_getnode_data(treelist *tl, treelist_node *node) +{ + __asm__ __volatile__ ( + "push %%edi \n\t":::); + + void *ret = + (*_tl_node_poi_get_data_asm)(tl, node); + + __asm__ __volatile__ ( + "pop %%edi \n\t":::); + return ret; +} + +extern int (*tl_save_mem_asm)(treelist *, int opt, void *h_mem, int mem_size) __attribute__((__stdcall__)); +/// tlist - pointer to 'TreeList' struct +/// opt - options: 0 - first element, 1 - add next element +/// h_mem - pointer to memory +/// mem_size - memory size +///output - error code +static inline int treelist_save2mem(treelist *tl, int opt, void *h_mem, int mem_size) +{ + __asm__ __volatile__ ( + "push %%ebx \n\t" + "push %%esi \n\t" + "push %%edi \n\t":::); + + int ret = + (*tl_save_mem_asm)(tl, opt, h_mem, mem_size); + + __asm__ __volatile__ ( + "pop %%edi \n\t" + "pop %%esi \n\t" + "pop %%ebx \n\t":::); + return ret; +} + +extern int (*_tl_load_mem_asm)(treelist *, int opt, void *h_mem, int mem_size) __attribute__((__stdcall__)); +/**input: +; tlist - pointer to 'TreeList' struct +; opt - options: element index + (2*(add mode)+(init mode)) shl 16, tl_load_mode_add equ 0x20000 ;опция считывания в режиме добавления информации +; h_mem - pointer to memory +; mem_size - memory size +; размер памяти, пока не используется (назначался для контроля) +; для его использования нужно доработать функцию +;output: +; eax - error code +;memory header format: +; +0 - (4) 'tree' +; +4 - (2) info size +; +6 - (4) count nodes +; +10 - (4) tlist style +; +14 - (4) cursor pos +; +18 - (2) info capt offs +; +20 - (2) info capt len +; +22 - (4) scroll pos +;memory data format: +; +26 - (info size + 8) * count nodes */ +static inline int treelist_load4mem(treelist *tl, int opt, void *h_mem, int mem_size) +{ + __asm__ __volatile__ ( + "push %%ebx \n\t" + "push %%esi \n\t" + "push %%edi \n\t":::); + + int ret = + (*_tl_load_mem_asm)(tl, opt, h_mem, mem_size); + + __asm__ __volatile__ ( + "pop %%edi \n\t" + "pop %%esi \n\t" + "pop %%ebx \n\t":::); + return ret; +} + +extern int (*tl_get_mem_size_asm)(treelist *, void *h_mem) __attribute__((__stdcall__)); +/// ;берет размер памяти занятой функцией tl_save_mem при сохранении элементов +/// tlist - pointer to 'TreeList' struct +/// h_mem - pointer to saved memory +static inline int treelist_get_memsize(treelist *tl, void *h_mem) +{ + __asm__ __volatile__ ( + "push %%ebx \n\t" + "push %%edi \n\t":::); + + int ret = + (*tl_get_mem_size_asm)(tl, h_mem); + + __asm__ __volatile__ ( + "pop %%edi \n\t" + "pop %%ebx \n\t":::); + return ret; +} #endif //KOLIBRI_TREELIST_H