TxtRead 1.4: add search

git-svn-id: svn://kolibrios.org@7818 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2020-04-21 20:49:38 +00:00
parent 27e32a883f
commit f3e196d8aa
5 changed files with 485 additions and 198 deletions

View File

@ -0,0 +1,88 @@
//===================================================//
// //
// TRANSLATIONS //
// //
//===================================================//
#ifdef LANG_RUS
#define INTRO_TEXT "<22>â® ¯à®á⮩ ¯à®á¬®âà騪 ⥪áâ .\n<>®¯à®¡ã©â¥ ®âªàëâì ª ª®©-­¨¡ã¤ì ⥪áâ®¢ë© ä ©«."
#define VERSION "Text Reader v1.4"
#define ABOUT "ˆ¤¥ï: Leency, punk_joker
Š®¤: Leency, Veliant, KolibriOS Team
ƒ®àï稥 ª« ¢¨è¨:
Ctrl+O - ®âªàëâì ä ©«
Ctrl+I - ¯®ª § âì ¨­ä®à¬ æ¨î ® ä ©«¥
Ctrl+<EFBFBD>«îá - 㢥«¨ç¨âì èà¨äâ
Ctrl+Œ¨­ãá - 㬥­ìè¨âì èà¨äâ
Ctrl+Tab - ¢ë¡à âì ª®¤¨à®¢ªã ⥪áâ 
Ctrl+E - ®âªàëâì ä ©« ¢ ¤à㣮© ¯à®£à ¬¬¥
<EFBFBD>®¨áª:
Ctrl+F - ®âªàëâì ¯ ­¥«ì ¯®¨áª 
F3 - ¨áª âì ¤ «¥¥
Esc - áªàëâì ¯ ­¥«ì ¯®¨áª 
<EFBFBD> ¦¬¨â¥ «î¡ãî ª« ¢¨èã..."
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" };

View File

@ -1,11 +1,22 @@
enum { void ParseAndPaint()
COUNT_BUF_HEIGHT, {
DRAW_BUF 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 #define DRAW_PADDING 12
void Parse(byte mode) void Parse()
{ {
dword bufoff, buflen; dword bufoff, buflen;
byte ch; byte ch;
@ -15,6 +26,7 @@ dword stroka_y=DRAW_PADDING-3;
dword line_length=30; dword line_length=30;
dword line_start=io.buffer_data; dword line_start=io.buffer_data;
list.count=0;
buflen = strlen(io.buffer_data) + io.buffer_data; buflen = strlen(io.buffer_data) + io.buffer_data;
for (bufoff=io.buffer_data; bufoff<buflen; bufoff++) for (bufoff=io.buffer_data; bufoff<buflen; bufoff++)
{ {
@ -28,39 +40,47 @@ dword line_start=io.buffer_data;
if (srch_pos == line_start) break; //no white space found in whole line if (srch_pos == line_start) break; //no white space found in whole line
srch_pos--; srch_pos--;
} }
if (mode==COUNT_BUF_HEIGHT) {
line_start = bufoff;
line_length = 30;
list.count++; list.count++;
}
if (mode==DRAW_BUF) {
strlcpy(#line, line_start, bufoff-line_start); strlcpy(#line, line_start, bufoff-line_start);
kfont.WriteIntoBuffer(DRAW_PADDING,stroka_y,list.w,kfont.size.height, bg_color, text_color, kfont.size.pt, #line); search.add(stroka_y, #line);
stroka_y += list.item_h; stroka_y += list.item_h;
line_start = bufoff; line_start = bufoff;
line_length = 30; line_length = 30;
} }
} }
} list.count+=2;
if (mode==COUNT_BUF_HEIGHT) list.count+=2; list.visible = list.h / list.item_h;
if (mode==DRAW_BUF) kfont.WriteIntoBuffer(DRAW_PADDING,stroka_y,list.w,kfont.size.height, bg_color, text_color, kfont.size.pt, line_start);
}
void PreparePage()
{
list.w = Form.cwidth-scroll.size_x-1;
list.count=0;
Parse(COUNT_BUF_HEIGHT);
//draw text in buffer
list.SetSizes(0, TOOLBAR_H, list.w, Form.cheight-TOOLBAR_H, kfont.size.pt+8);
if (list.count < list.visible) list.count = list.visible; if (list.count < list.visible) list.count = list.visible;
kfont.size.height = list.count+1*list.item_h; kfont.size.height = list.count+1*list.item_h;
kfont.raw_size = 0; kfont.raw_size = 0;
Parse(DRAW_BUF); search.add(stroka_y, line_start);
}
if (list.count > list.visible * 10) DrawPage();
//draw result void Paint()
kfont.ApplySmooth(); {
DrawPage(); 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();
} }

View File

@ -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; i<pos.count; i++) {
if (strstri(lines.get(i),#search_text)!=-1) return atoi(pos.get(i));
}
return false;
}
int SEARCH::highlight(dword _color, _bg_color)
{
int i;
dword col;
found_count = 0;
for (i=0; i<pos.count; i++) {
if (strstri(lines.get(i),#search_text)==-1) {
col=_bg_color;
} else {
col=_color;
found_count++;
}
draw_bar(0, atoi(pos.get(i)), 3, list.item_h, col);
}
}
void draw_bar(dword _x, _y, _w, _h, _color)
{
int i;
for (i = _y*list.w+_x*KFONT_BPP+kfont.raw ; i<_y*list.w+_x+_w*KFONT_BPP+kfont.raw ; i+=KFONT_BPP)
{
ESDWORD[i] = _color;
}
if (_h>0) draw_bar(dword _x, _y+1, _w, _h-1, _color);
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 504 B

After

Width:  |  Height:  |  Size: 666 B

View File

@ -1,4 +1,4 @@
#define MEMSIZE 4096*25 #define MEMSIZE 1024*80
//===================================================// //===================================================//
// // // //
@ -21,93 +21,62 @@
//===================================================// //===================================================//
// // // //
// DATA // // INTERNAL INCLUDES //
// // // //
//===================================================// //===================================================//
proc_info Form;
llist list;
#define TOOLBAR_H 34 #define TOOLBAR_H 34
#define TOOLBAR_ICON_WIDTH 24 #define TOOLBAR_ICON_WIDTH 24
#define TOOLBAR_ICON_HEIGHT 22 #define TOOLBAR_ICON_HEIGHT 22
#define DEFAULT_EDITOR "/sys/tinypad" dword bg_color;
dword text_color;
#define INTRO_TEXT "This is a plain Text Reader.\nTry to open some text file." #include "search.h"
#define VERSION "Text Reader v1.3" #include "prepare_page.h"
#define ABOUT "Idea: Leency, punk_joker #include "data.h"
Code: Leency, Veliant, KolibriOS Team
Hotkeys: int encoding;
Ctrl+O - open file int curcol_scheme;
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
Press any key..." #include "ini.h"
dword color_schemes[] = { //===================================================//
0xFFFfff, 0, // //
0xF0F0F0, 0, // DATA //
0xFDF6E3, 0x101A21, // //
0xFCF0DA, 0x171501, //===================================================//
0xF0F0C7, 0,
0x282C34, 0xABB2BF,
0x282923, 0xD8D8D2
};
char color_scheme_names[] =
"White & Black
Grey & Black RtfRead
Linen & Black Horst
Antique & Black Pocket
Lemon & Black Fb2Read
DarkGrey & Grey Godot
DarkGrey & Grey Monokai";
char default_dir[] = "/rd/1";
od_filter filter2 = { 8, "TXT\0\0" };
scroll_bar scroll = { 15,200,398,44,0,2,115,15,0,0xeeeeee,0xBBBbbb,0xeeeeee,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1}; scroll_bar scroll = { 15,200,398,44,0,2,115,15,0,0xeeeeee,0xBBBbbb,0xeeeeee,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1};
llist list;
proc_info Form;
char title[4196]; char title[4196];
bool help_opened = false; bool help_opened = false;
int charsets_mx;
int reopenin_mx;
int colscheme_mx;
int curcol_scheme; int charsets_mx,
reopenin_mx,
colscheme_mx,
search_mx;
enum { enum {
OPEN_FILE, OPEN_FILE,
MAGNIFY_MINUS, MAGNIFY_MINUS,
MAGNIFY_PLUS, MAGNIFY_PLUS,
CHANGE_ENCODING, CHANGE_CHARSET,
RUN_EDIT, REOPEN_IN_APP,
SHOW_INFO, SHOW_INFO,
SHOW_FILE_PROPERTIES, SHOW_FILE_PROPERTIES,
COLOR_SCHEME COLOR_SCHEME,
SEARCH_BTN,
BTN_FIND_NEXT,
BTN_FIND_CLOSE
}; };
int encoding;
dword bg_color;
dword text_color;
dword menu_id; dword menu_id;
//===================================================//
// //
// INTERNAL INCLUDES //
// //
//===================================================//
#include "ini.h"
#include "prepare_page.h"
//===================================================// //===================================================//
// // // //
// CODE // // CODE //
@ -133,7 +102,7 @@ void main()
EventSetColorScheme(curcol_scheme); EventSetColorScheme(curcol_scheme);
kfont.init(DEFAULT_FONT); kfont.init(DEFAULT_FONT);
Libimg_LoadImage(#skin, abspath("toolbar.png")); Libimg_LoadImage(#skin, abspath("toolbar.png"));
OpenFile(#param); LoadFile(#param);
list.no_selection = true; list.no_selection = true;
SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER); SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
loop() loop()
@ -158,23 +127,21 @@ void main()
//===================================================// //===================================================//
// // // //
// EVENTS // // EVENT HANDLERS //
// // // //
//===================================================// //===================================================//
void HandleButtonEvent() void HandleButtonEvent()
{ {
int btn = GetButtonID();
byte btn = GetButtonID();
if (btn==1) { if (btn==1) {
SaveIniSettings(); SaveIniSettings();
ExitProcess(); ExitProcess();
} }
btn-=10; switch(btn-10)
switch(btn)
{ {
case OPEN_FILE: case OPEN_FILE:
EventOpenFile(); EventOpenDialog();
break; break;
case SHOW_FILE_PROPERTIES: case SHOW_FILE_PROPERTIES:
EventShowFileProperties(); EventShowFileProperties();
@ -185,10 +152,10 @@ void HandleButtonEvent()
case MAGNIFY_MINUS: case MAGNIFY_MINUS:
EventMagnifyMinus(); EventMagnifyMinus();
break; break;
case CHANGE_ENCODING: case CHANGE_CHARSET:
EventShowEncodingList(); EventShowCharsetsList();
break; break;
case RUN_EDIT: case REOPEN_IN_APP:
EventShowReopenMenu(); EventShowReopenMenu();
break; break;
case COLOR_SCHEME: case COLOR_SCHEME:
@ -197,53 +164,81 @@ void HandleButtonEvent()
case SHOW_INFO: case SHOW_INFO:
EventShowInfo(); EventShowInfo();
break; break;
case SEARCH_BTN:
if (search.visible) {
search.hide();
} else {
search.show();
}
break;
case BTN_FIND_NEXT:
EventSearchNext();
break;
case BTN_FIND_CLOSE:
search.hide();
break;
} }
} }
void HandleKeyEvent() void HandleKeyEvent()
{ {
int new_y;
if (help_opened) { if (help_opened) {
help_opened = false; help_opened = false;
DrawPage(); DrawPage();
return; return;
} }
GetKeys(); GetKeys();
if (key_scancode == SCAN_CODE_F1) {
EventShowInfo();
return;
}
if (key_modifier & KEY_LCTRL) || (key_modifier & KEY_RCTRL) { if (key_modifier & KEY_LCTRL) || (key_modifier & KEY_RCTRL) {
switch (key_scancode) switch (key_scancode)
{ {
case SCAN_CODE_KEY_O: case SCAN_CODE_KEY_O:
EventOpenFile(); EventOpenDialog();
break; return;
case SCAN_CODE_KEY_I: case SCAN_CODE_KEY_I:
EventShowFileProperties(); EventShowFileProperties();
break; return;
case SCAN_CODE_PLUS: case SCAN_CODE_PLUS:
case SCAN_CODE_UP: case SCAN_CODE_UP:
EventMagnifyPlus(); EventMagnifyPlus();
break; return;
case SCAN_CODE_DOWN: case SCAN_CODE_DOWN:
case SCAN_CODE_MINUS: case SCAN_CODE_MINUS:
EventMagnifyMinus(); EventMagnifyMinus();
break; return;
case SCAN_CODE_KEY_E: case SCAN_CODE_KEY_E:
EventShowReopenMenu(); EventShowReopenMenu();
break; return;
case SCAN_CODE_TAB: case SCAN_CODE_TAB:
EventChangeEncoding(); EventShowCharsetsList();
break; return;
case SCAN_CODE_KEY_F:
search.show();
return;
case SCAN_CODE_HOME:
list.KeyHome();
DrawPage();
} }
}
switch (key_scancode)
{
case SCAN_CODE_F1:
EventShowInfo();
return;
case SCAN_CODE_ESC:
search.hide();
return;
case SCAN_CODE_ENTER:
if (! search_box.flags & ed_focus) return;
case SCAN_CODE_F3:
EventSearchNext();
return; return;
} }
if (list.ProcessKey(key_scancode)) if (!search.edit_key()) {
DrawPage(); if (list.ProcessKey(key_scancode)) DrawPage();
}
} }
void HandleMouseEvent() void HandleMouseEvent()
{ {
mouse.get(); mouse.get();
@ -257,16 +252,32 @@ void HandleMouseEvent()
list.first = scroll.position; list.first = scroll.position;
DrawPage(); DrawPage();
} }
search.edit_mouse();
} }
/* ----------------------------------------------------- */ //===================================================//
// //
// EVENTS //
// //
//===================================================//
void EventOpenFile() bool EventSearchNext()
{
int new_y = search.find_next(list.first, bg_color);
if (new_y) {
list.first = new_y / list.item_h;
list.CheckDoesValuesOkey();
DrawPage();
}
}
void EventOpenDialog()
{ {
OpenDialog_start stdcall (#o_dialog); OpenDialog_start stdcall (#o_dialog);
if (o_dialog.status) { if (o_dialog.status) {
OpenFile(#openfile_path); LoadFile(#openfile_path);
PreparePage(); search.clear();
ParseAndPaint();
} }
} }
@ -285,7 +296,7 @@ void EventMagnifyPlus()
if(!kfont.changeSIZE()) if(!kfont.changeSIZE())
kfont.size.pt--; kfont.size.pt--;
else else
PreparePage(); ParseAndPaint();
} }
void EventMagnifyMinus() void EventMagnifyMinus()
@ -294,28 +305,29 @@ void EventMagnifyMinus()
if(!kfont.changeSIZE()) if(!kfont.changeSIZE())
kfont.size.pt++; kfont.size.pt++;
else else
PreparePage(); ParseAndPaint();
} }
void EventShowEncodingList() void EventShowCharsetsList()
{ {
menu_id = CHANGE_CHARSET;
open_lmenu(Form.left+5 + charsets_mx, Form.top+29+skin_height, MENU_ALIGN_TOP_LEFT, open_lmenu(Form.left+5 + charsets_mx, Form.top+29+skin_height, MENU_ALIGN_TOP_LEFT,
encoding+1, "UTF-8\nKOI8-RU\nCP1251\nCP1252\nISO8859-5\nCP866"); encoding+1, "UTF-8\nKOI8-RU\nCP1251\nCP1252\nISO8859-5\nCP866");
menu_id = 10;
} }
void EventShowReopenMenu() void EventShowReopenMenu()
{ {
menu_id = REOPEN_IN_APP;
open_lmenu(Form.left+5 + reopenin_mx, Form.top+29+skin_height, MENU_ALIGN_TOP_LEFT, 0, open_lmenu(Form.left+5 + reopenin_mx, Form.top+29+skin_height, MENU_ALIGN_TOP_LEFT, 0,
"Tinypad\nTextEdit\nWebView\nFB2Read\nHexView\nOther"); "Tinypad\nTextEdit\nWebView\nFB2Read\nHexView\nOther");
menu_id = 20;
} }
void EventShowColorSchemesList() void EventShowColorSchemesList()
{ {
open_lmenu(Form.left+5 + colscheme_mx, Form.top+29+skin_height, MENU_ALIGN_TOP_LEFT, menu_id = COLOR_SCHEME;
open_lmenu(Form.left+2 + colscheme_mx + 26,
Form.top+29+skin_height, MENU_ALIGN_TOP_RIGHT,
curcol_scheme+1, #color_scheme_names); curcol_scheme+1, #color_scheme_names);
menu_id = 30;
} }
void EventSetColorScheme(dword _setn) void EventSetColorScheme(dword _setn)
@ -323,65 +335,65 @@ void EventSetColorScheme(dword _setn)
curcol_scheme = _setn; curcol_scheme = _setn;
bg_color = color_schemes[curcol_scheme*2]; bg_color = color_schemes[curcol_scheme*2];
text_color = color_schemes[curcol_scheme*2+1]; text_color = color_schemes[curcol_scheme*2+1];
if (list.count) ParseAndPaint();
} }
void EventShowInfo() { void EventShowInfo() {
help_opened = true; help_opened = true;
DrawBar(list.x, list.y, list.w, list.h, 0xFFFfff); DrawBar(list.x, list.y, list.w, list.h, bg_color);
WriteText(list.x + 10, list.y + 10, 10000001b, 0x555555, VERSION); WriteText(list.x + 10, list.y + 10, 10000001b, text_color, VERSION);
WriteTextLines(list.x + 10, list.y+40, 10110000b, 0, ABOUT, 20); WriteTextLines(list.x + 10, list.y+40, 10110000b, text_color, ABOUT, 20);
} }
void EventChangeEncoding(dword id) void EventChangeCharset(dword id)
{ {
encoding = id; encoding = id;
OpenFile(#openfile_path); LoadFile(#openfile_path);
PreparePage(); ParseAndPaint();
draw_window(); draw_window();
} }
void EventOpenFileInAnotherProgram(dword _app) void EventOpenFileInAnotherProgram(dword _id)
{
RunProgram(_app, #param);
}
void EventMenuClick()
{ {
dword app;
byte open_param[4096]; byte open_param[4096];
dword click_id = get_menu_click(); switch(_id) {
if (click_id) switch(click_id + menu_id - 1) case 0:
{ app = "/sys/tinypad";
//Encoding
case 10...15:
EventChangeEncoding(click_id-1);
break; break;
//Reopen case 1:
case 20: app = "/sys/develop/t_edit";
EventOpenFileInAnotherProgram("/sys/tinypad");
break; break;
case 21: case 2:
EventOpenFileInAnotherProgram("/sys/develop/t_edit"); app = "/sys/network/webview";
break; break;
case 22: case 3:
EventOpenFileInAnotherProgram("/sys/network/webview"); app = "/sys/fb2read";
break; break;
case 23: case 4:
EventOpenFileInAnotherProgram("/sys/fb2read"); app = "/sys/develop/heed";
break; break;
case 24: case 5:
EventOpenFileInAnotherProgram("/sys/develop/heed");
break;
case 25:
open_param[0]='~'; open_param[0]='~';
strcpy(#open_param+1,#param); strcpy(#open_param+1,#param);
RunProgram("/sys/@open", #open_param); RunProgram("/sys/@open", #open_param);
break; break;
//ColorSchemes
case 30...38:
EventSetColorScheme(click_id-1);
PreparePage();
break;
} }
RunProgram(app, #param);
}
void EventMenuClick()
{
dword click_id = get_menu_click();
if (click_id) && (menu_id)
{
if (menu_id == CHANGE_CHARSET) EventChangeCharset(click_id-1);
else if (menu_id == REOPEN_IN_APP) EventOpenFileInAnotherProgram(click_id-1);
else if (menu_id == COLOR_SCHEME) EventSetColorScheme(click_id-1);
else notify("'Error: wrong menu number'E");
}
menu_id = NULL;
} }
//===================================================// //===================================================//
@ -390,37 +402,52 @@ void EventMenuClick()
// // // //
//===================================================// //===================================================//
void OpenFile(dword f_path) void LoadFile(dword f_path)
{ {
int tmp; int tmp;
if (ESBYTE[f_path]) { if (ESBYTE[f_path]) {
strcpy(#param, f_path); strcpy(#param, f_path);
io.read(#param); if (!io.read(#param)) goto NO_DATA;
strcpy(#title, #param); strcpy(#title, #param);
strcat(#title, " - Text Reader"); strcat(#title, " - Text Reader");
} }
else { else {
NO_DATA:
if (list.count) return; if (list.count) return;
io.buffer_data = INTRO_TEXT; io.buffer_data = INTRO_TEXT;
strcpy(#title, "Text Reader"); strcpy(#title, "Text Reader");
} }
if (encoding!=CH_CP866) ChangeCharset(encoding, "CP866", io.buffer_data); if (encoding!=CH_CP866) ChangeCharset(encoding, "CP866", io.buffer_data);
list.KeyHome();
list.ClearList(); list.ClearList();
} }
int DrawToolbarButton(char image_id, int x)
{
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);
if (menu_id) && (menu_id == image_id) {
DrawRectangle3D(x+1, 6, TOOLBAR_ICON_WIDTH-1, TOOLBAR_ICON_HEIGHT-1, 0xCCCccc, 0xF8FCF8);
PutShadow(x+1, 6, TOOLBAR_ICON_WIDTH, TOOLBAR_ICON_HEIGHT, true, 2);
}
DefineHiddenButton(x+1, 6, TOOLBAR_ICON_WIDTH, TOOLBAR_ICON_HEIGHT, 10+image_id);
return x;
}
void draw_window() void draw_window()
{ {
#define BUTTONS_GAP 6 #define BUTTONS_GAP 5
#define BLOCKS_GAP 15 #define BLOCKS_GAP 18
#define TOOLBAR_BUTTON_WIDTH 26 #define TOOLBAR_BUTTON_WIDTH 26
incn x; incn x;
int old_w;
DefineAndDrawWindow(Form.left,Form.top,Form.width,Form.height,0x73,0,#title,0); DefineAndDrawWindow(Form.left,Form.top,Form.width,Form.height,0x73,0,#title,0);
GetProcessInfo(#Form, SelfInfo); GetProcessInfo(#Form, SelfInfo);
sc.get(); sc.get();
if (Form.status_window>2) return; if (Form.status_window>2) 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; } if (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); return; }
DrawBar(0, 0, Form.cwidth, TOOLBAR_H - 1, sc.work); 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_MINUS, x.inc(TOOLBAR_BUTTON_WIDTH + BLOCKS_GAP));
DrawToolbarButton(MAGNIFY_PLUS, x.inc(TOOLBAR_BUTTON_WIDTH - 1)); 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; search_mx = DrawToolbarButton(SEARCH_BTN, x.inc(TOOLBAR_BUTTON_WIDTH + BLOCKS_GAP));
DrawToolbarButton(RUN_EDIT, x.inc(TOOLBAR_BUTTON_WIDTH + BLOCKS_GAP)); reopenin_mx = x.n; charsets_mx = DrawToolbarButton(CHANGE_CHARSET, x.inc(TOOLBAR_BUTTON_WIDTH + BUTTONS_GAP));
DrawToolbarButton(SHOW_INFO, Form.cwidth - 34); reopenin_mx = DrawToolbarButton(REOPEN_IN_APP, x.inc(TOOLBAR_BUTTON_WIDTH + BUTTONS_GAP));
if ((Form.cwidth-scroll.size_x-1 == list.w) && x.n = Form.cwidth - 34;
(Form.cheight-TOOLBAR_H == list.h) && DrawToolbarButton(SHOW_INFO, x.n);
(list.count) 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(); DrawPage();
} else { } else {
PreparePage(); ParseAndPaint();
} }
DrawRectangle(scroll.start_x, scroll.start_y, scroll.size_x, scroll.size_y-1, scroll.bckg_col); 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() void DrawPage()
{ {
kfont.ShowBufferPart(list.x, list.y, list.w, list.h, list.first*list.item_h*list.w); 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.max_area = list.count;
scroll.cur_area = list.visible; scroll.cur_area = list.visible;
scroll.position = list.first; scroll.position = list.first;