From f3e196d8aaaae27dba1fce3831fb580277c16133 Mon Sep 17 00:00:00 2001 From: "Kirill Lipatov (Leency)" Date: Tue, 21 Apr 2020 20:49:38 +0000 Subject: [PATCH] TxtRead 1.4: add search git-svn-id: svn://kolibrios.org@7818 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/cmm/txtread/data.h | 88 +++++++ programs/cmm/txtread/prepare_page.h | 90 ++++--- programs/cmm/txtread/search.h | 155 ++++++++++++ programs/cmm/txtread/toolbar.png | Bin 504 -> 666 bytes programs/cmm/txtread/txtread.c | 350 +++++++++++++++------------- 5 files changed, 485 insertions(+), 198 deletions(-) create mode 100644 programs/cmm/txtread/data.h create mode 100644 programs/cmm/txtread/search.h diff --git a/programs/cmm/txtread/data.h b/programs/cmm/txtread/data.h new file mode 100644 index 0000000000..4dd3878f74 --- /dev/null +++ b/programs/cmm/txtread/data.h @@ -0,0 +1,88 @@ +//===================================================// +// // +// TRANSLATIONS // +// // +//===================================================// + +#ifdef LANG_RUS + +#define INTRO_TEXT "Это простой просмотрщик текста.\nПопробуйте открыть какой-нибудь текстовый файл." +#define VERSION "Text Reader v1.4" +#define ABOUT "Идея: Leency, punk_joker +Код: Leency, Veliant, KolibriOS Team + +Горячие клавиши: +Ctrl+O - открыть файл +Ctrl+I - показать информацию о файле +Ctrl+Плюс - увеличить шрифт +Ctrl+Минус - уменьшить шрифт +Ctrl+Tab - выбрать кодировку текста +Ctrl+E - открыть файл в другой программе + +Поиск: +Ctrl+F - открыть панель поиска +F3 - искать далее +Esc - скрыть панель поиска + +Нажмите любую клавишу..." + +char color_scheme_names[] = +"Черный на белом +Черный на сером |RtfRead +Черный на льне |Horst +Черный на холсте |Pocket +Черный на желтом |Fb2Read +Серый на темном1 |Godot +Серый на темном2 |Monokai"; + +#else + +#define INTRO_TEXT "This is a plain Text Reader.\nTry to open some text file." +#define VERSION "Text Reader v1.4" +#define ABOUT "Idea: Leency, punk_joker +Code: Leency, Veliant, KolibriOS Team + +Hotkeys: +Ctrl+O - open file +Ctrl+I - show file properties +Ctrl+Up - bigger font +Ctrl+Down - smaller font +Ctrl+Tab - select charset +Ctrl+E - reopen current file in another app + +Search: +Ctrl+F - open search +F3 - search next +Esc - hide search bar + +Press any key..." + +char color_scheme_names[] = +"Black & White +Black & Grey |RtfRead +Black & Linen |Horst +Black & Antique |Pocket +Black & Lemon |Fb2Read +Grey & DarkGrey |Godot +Grey & DarkGrey |Monokai"; + +#endif + +//===================================================// +// // +// DATA // +// // +//===================================================// + +dword color_schemes[] = { +0xFFFfff, 0, +0xF0F0F0, 0, +0xFDF6E3, 0x101A21, +0xFCF0DA, 0x171501, +0xF0F0C7, 0, +0x282C34, 0xABB2BF, +0x282923, 0xD8D8D2 +}; + +char default_dir[] = "/rd/1"; +od_filter filter2 = { 8, "TXT\0\0" }; \ No newline at end of file diff --git a/programs/cmm/txtread/prepare_page.h b/programs/cmm/txtread/prepare_page.h index b1cf8d465e..b1f3024307 100644 --- a/programs/cmm/txtread/prepare_page.h +++ b/programs/cmm/txtread/prepare_page.h @@ -1,11 +1,22 @@ -enum { - COUNT_BUF_HEIGHT, - DRAW_BUF -}; +void ParseAndPaint() +{ + dword start_time = GetStartTime(); + search.clear(); + Parse(); + Paint(); + debugln("\nTextRead statistics in miliseconds..."); + debugval("Page generate time", GetStartTime() - start_time); + if (list.count > list.visible * 10) DrawPage(); + start_time = GetStartTime(); + kfont.ApplySmooth(); + debugval("Smooth", GetStartTime() - start_time); + DrawPage(); +} + #define DRAW_PADDING 12 -void Parse(byte mode) +void Parse() { dword bufoff, buflen; byte ch; @@ -15,6 +26,7 @@ dword stroka_y=DRAW_PADDING-3; dword line_length=30; dword line_start=io.buffer_data; + list.count=0; buflen = strlen(io.buffer_data) + io.buffer_data; for (bufoff=io.buffer_data; bufoff list.visible * 10) DrawPage(); - //draw result - kfont.ApplySmooth(); - DrawPage(); + search.add(stroka_y, line_start); } + +void Paint() +{ + int i; + int cur_pos; + dword cur_line; + for ( i=0; i < search.lines.count; i++) + { + cur_pos = atoi(search.pos.get(i)); + cur_line = search.lines.get(i); + kfont.WriteIntoBuffer(DRAW_PADDING, cur_pos, list.w, + kfont.size.height, bg_color, text_color, kfont.size.pt, cur_line); + } +} + +:void PaintVisible() +{ + int i; + dword cur_pos; + dword cur_line; + for ( i=0; i < list.visible; i++) + { + cur_pos = atoi(search.pos.get(i + list.first)); + cur_line = search.lines.get(i + list.first); + kfont.WriteIntoBuffer(DRAW_PADDING, cur_pos, list.w, + kfont.size.height, bg_color, text_color, kfont.size.pt, cur_line); + } + kfont.ApplySmooth(); +} \ No newline at end of file diff --git a/programs/cmm/txtread/search.h b/programs/cmm/txtread/search.h new file mode 100644 index 0000000000..c663aad571 --- /dev/null +++ b/programs/cmm/txtread/search.h @@ -0,0 +1,155 @@ + +#include "../lib/collection.h" + +#define SEARCH_H 34 + + +struct SEARCH +{ + bool visible; + int found_count; + collection lines; + collection pos; + void show(); + void hide(); + bool draw(); + void draw_found(); + int height(); + bool edit_key(); + bool edit_mouse(); + void add(); + void clear(); + int find_next(); + int highlight(); +} search; + +char search_text[64]; +char found_text[64]; +edit_box search_box = {250, 10, NULL, 0xffffff, +0x94AECE, 0xffffff, 0xffffff,0x10000000,sizeof(search_text)-1,#search_text}; + + +void SEARCH::show() +{ + visible = true; + search_box.flags = ed_focus; + draw_window(); +} + +void SEARCH::hide() +{ + visible = false; + draw_window(); +} + +int SEARCH::height() +{ + return visible * SEARCH_H; +} + +bool SEARCH::edit_key() +{ + if (visible) && (search_box.flags & ed_focus) { + EAX = key_editbox; + edit_box_key stdcall(#search_box); + return true; + } + return false; +} + +bool SEARCH::edit_mouse() +{ + if (visible) { + edit_box_mouse stdcall(#search_box); + if (search_box.flags & ed_focus) return true; + } + return false; +} + +void SEARCH::draw_found() +{ + strcpy(#param, "Matches: "); + strcat(#param, itoa(found_count)); + strcat(#param, " "); + WriteTextWithBg(search_box.left+search_box.width+14+110, search_box.top+3, 0xD0, sc.work_text, #param, sc.work); +} + +bool SEARCH::draw(dword _btn_find, _btn_hide) +{ + if (!visible) return false; + DrawBar(0,Form.cheight - SEARCH_H, Form.cwidth, 1, sc.work_graph); + DrawBar(0,Form.cheight - SEARCH_H+1, Form.cwidth, SEARCH_H-1, sc.work); + + search_box.top = Form.cheight - SEARCH_H + 6; + search_box.width = math.min(Form.width - 200, 250); + + DrawRectangle(search_box.left-1, search_box.top-1, search_box.width+2, 23,sc.work_graph); + + edit_box_draw stdcall(#search_box); + + DrawCaptButton(search_box.left+search_box.width+14, search_box.top-1, 90, + TOOLBAR_ICON_HEIGHT+1, _btn_find, sc.work_light, sc.work_text, "Find next"); + + draw_found(); + + DefineHiddenButton(Form.cwidth-26, search_box.top-1, TOOLBAR_ICON_HEIGHT+1, + TOOLBAR_ICON_HEIGHT+1, _btn_hide); + WriteText(Form.cwidth-26+7, search_box.top+2, 0x81, sc.work_graph, "x"); + return true; +} + +void SEARCH::clear() +{ + pos.drop(); + lines.drop(); + visible = false; + found_text[0] = '\0'; + found_count = 0; +} + +void SEARCH::add(dword _pos, _line) +{ + pos.add(itoa(_pos)); + lines.add(_line); +} + +int SEARCH::find_next(int _cur_pos, _bg_color) +{ + int i; + if (!search_text[0]) return false; + + strcpy(#found_text, #search_text); + highlight(0xFF0000, _bg_color); + draw_found(); + + for (i=_cur_pos+1; i0) draw_bar(dword _x, _y+1, _w, _h-1, _color); +} \ No newline at end of file diff --git a/programs/cmm/txtread/toolbar.png b/programs/cmm/txtread/toolbar.png index 678a26a60388692d810f0c77c101223d54f91e09..ee255f9b7e56d4304c5e9b4075994ccd0e749945 100644 GIT binary patch literal 666 zcmV;L0%iS)P)Px#9#BkFMfCLaWMpLA+}!;9{EUo@%goDrdwZ;{tm^RU zmYJ7Ja*Xl-00J6GL_t(o!|j*Za^x@wMFnAz|Nn=B7RwS|WGCIJ>YCA82nLS9=ynKS zhbMf#JsckVbo;*x#sqeV@7gDc3FvomPW)rC6UPxuAs;;mWQ8cRuJugq6ELpFdt=mK%~AJ7P(`efC(ltn#TcfHLd>Hw)01T1!KgeytN%z7ppu# zf~`WK;OsfWU=O5MU_!`T3cHRUz>`&fSiuJWXiY2wxwIE?1lAHWa6d)t>?K2IPZQA% z9Xl}N5->7yafp1J;HqiT6=K~HmnnS#@TCz&7Nkx{%y$w2C&LS-M4WX=LBr%VP6kyqYuj+Fz)_k z4WHT5D`iV)EwGu(jc8yaSBukuG0aAB1ncU7xP1X{0fV%LZB;Y6ZRWXdf?alO^MCs& z8jj6hN`vd#S=Y4VdhIA$o8r1#_Zgj9sB>H4R*oYvTm$Y~80VFN&z?{w`$KU{5dTlu9+JHcgsNw-H69f$Qc4?ZD11 z=%&GnFhQ>s_sZi%l8V!7R5?&2b4fLTok^;!g6);Yq8aa~`gi0|j8KPbUH&1qASWz6%`Fqp{hqs$sVAsZs1-Sq7lphn8RG0ifr*z_q+L zkYy(^)!;CB$sam}Oc?>J{x#C{JOK3kJq7w71W~OZ28Y2bjUK1@k>7|w!$+DvHPZC_ zL4sHdNOedW98NxufUBB!ek?O;_+-}f=^$4H)cDu@RsgR!Q;%HC?FDqMvo5R8*roeo?$wvm uQsiU(_xX2up}GA2-u&l{Ebmr)7XCMd)>&{-+B91L00002) return; - if (Form.width < 200) { MoveSize(OLD,OLD,200,OLD); return; } + if (Form.width < 340) { MoveSize(OLD,OLD,340,OLD); return; } if (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); return; } DrawBar(0, 0, Form.cwidth, TOOLBAR_H - 1, sc.work); @@ -432,19 +459,29 @@ void draw_window() DrawToolbarButton(MAGNIFY_MINUS, x.inc(TOOLBAR_BUTTON_WIDTH + BLOCKS_GAP)); DrawToolbarButton(MAGNIFY_PLUS, x.inc(TOOLBAR_BUTTON_WIDTH - 1)); - DrawToolbarButton(COLOR_SCHEME, x.inc(TOOLBAR_BUTTON_WIDTH + BUTTONS_GAP)); colscheme_mx = x.n; - DrawToolbarButton(CHANGE_ENCODING, x.inc(TOOLBAR_BUTTON_WIDTH + BLOCKS_GAP)); charsets_mx = x.n; - DrawToolbarButton(RUN_EDIT, x.inc(TOOLBAR_BUTTON_WIDTH + BLOCKS_GAP)); reopenin_mx = x.n; - DrawToolbarButton(SHOW_INFO, Form.cwidth - 34); - - if ((Form.cwidth-scroll.size_x-1 == list.w) && - (Form.cheight-TOOLBAR_H == list.h) && - (list.count) - ) { + search_mx = DrawToolbarButton(SEARCH_BTN, x.inc(TOOLBAR_BUTTON_WIDTH + BLOCKS_GAP)); + charsets_mx = DrawToolbarButton(CHANGE_CHARSET, x.inc(TOOLBAR_BUTTON_WIDTH + BUTTONS_GAP)); + reopenin_mx = DrawToolbarButton(REOPEN_IN_APP, x.inc(TOOLBAR_BUTTON_WIDTH + BUTTONS_GAP)); + + x.n = Form.cwidth - 34; + DrawToolbarButton(SHOW_INFO, x.n); + colscheme_mx = DrawToolbarButton(COLOR_SCHEME, x.inc(-TOOLBAR_BUTTON_WIDTH - BUTTONS_GAP)); + + if (search.draw(BTN_FIND_NEXT+10, BTN_FIND_CLOSE+10)) { + DrawRectangle3D(search_mx+1, 6, TOOLBAR_ICON_WIDTH-1, + TOOLBAR_ICON_HEIGHT-1, 0xCCCccc, 0xF8FCF8); + } + + old_w = list.w; + + list.SetSizes(0, TOOLBAR_H, Form.cwidth-scroll.size_x-1, + Form.cheight-TOOLBAR_H-search.height(), math.round(kfont.size.pt * 1.4)); + + if ((Form.cwidth-scroll.size_x-1 == old_w) && (list.count)) { DrawPage(); } else { - PreparePage(); + ParseAndPaint(); } DrawRectangle(scroll.start_x, scroll.start_y, scroll.size_x, scroll.size_y-1, scroll.bckg_col); @@ -453,20 +490,7 @@ void draw_window() void DrawPage() { kfont.ShowBufferPart(list.x, list.y, list.w, list.h, list.first*list.item_h*list.w); - DrawScroller(); -} -void DrawToolbarButton(char image_id, int x) -{ - DefineButton(x+1, 6, TOOLBAR_ICON_WIDTH, TOOLBAR_ICON_HEIGHT, 10+image_id + BT_HIDE, 0); - //img_draw stdcall(skin.image, x, 5, TOOLBAR_ICON_WIDTH, TOOLBAR_ICON_HEIGHT, TOOLBAR_ICON_WIDTH-1*image_id, 0); - DrawOvalBorder(x, 5, TOOLBAR_ICON_WIDTH, TOOLBAR_ICON_HEIGHT, sc.work_graph, - sc.work_graph,sc.work_graph, sc.work_dark); - img_draw stdcall(skin.image, x+1, 5+1, TOOLBAR_ICON_WIDTH, TOOLBAR_ICON_HEIGHT, TOOLBAR_ICON_WIDTH*image_id, 0); -} - -void DrawScroller() -{ scroll.max_area = list.count; scroll.cur_area = list.visible; scroll.position = list.first; @@ -475,4 +499,4 @@ void DrawScroller() scroll.start_y = list.y; scroll.size_y = list.h; scrollbar_v_draw(#scroll); -} \ No newline at end of file +}