2015-12-14 15:50:28 +01:00
|
|
|
#define MEMSIZE 4096*25
|
2015-09-07 17:07:51 +02:00
|
|
|
|
2015-11-06 15:55:25 +01:00
|
|
|
#include "../lib/io.h"
|
2018-05-22 14:08:24 +02:00
|
|
|
#include "../lib/gui.h"
|
2015-09-07 17:07:51 +02:00
|
|
|
#include "../lib/list_box.h"
|
2018-05-22 14:04:44 +02:00
|
|
|
#include "../lib/kfont.h"
|
2018-04-16 11:33:37 +02:00
|
|
|
|
2015-09-07 17:07:51 +02:00
|
|
|
#include "../lib/obj/box_lib.h"
|
|
|
|
#include "../lib/obj/libini.h"
|
2018-04-16 11:33:37 +02:00
|
|
|
#include "../lib/obj/libimg.h"
|
2015-09-07 17:07:51 +02:00
|
|
|
#include "../lib/obj/iconv.h"
|
|
|
|
#include "../lib/obj/proc_lib.h"
|
2018-04-16 11:33:37 +02:00
|
|
|
|
2015-09-07 17:07:51 +02:00
|
|
|
#include "../lib/patterns/simple_open_dialog.h"
|
|
|
|
|
|
|
|
#define TOOLBAR_H 34
|
2015-11-21 22:12:38 +01:00
|
|
|
#define TOOLBAR_ICON_WIDTH 26
|
|
|
|
#define TOOLBAR_ICON_HEIGHT 24
|
|
|
|
|
|
|
|
#define DEFAULT_EDITOR "/sys/tinypad"
|
|
|
|
|
2015-12-17 16:48:28 +01:00
|
|
|
#define INTRO_TEXT "This is a plain Text Reader.\nTry to open some text file."
|
2018-10-14 12:47:23 +02:00
|
|
|
#define VERSION "Text Reader v1.22"
|
2015-12-14 15:50:28 +01:00
|
|
|
#define ABOUT "Idea: Leency, punk_joker
|
|
|
|
Code: Leency, Veliant, KolibriOS Team
|
|
|
|
|
|
|
|
Hotkeys:
|
|
|
|
Ctrl+O - open file
|
2018-04-03 14:45:08 +02:00
|
|
|
Ctrl+I - show file properties
|
2015-12-14 15:50:28 +01:00
|
|
|
Ctrl+Up - bigger font
|
|
|
|
Ctrl+Down - smaller font
|
|
|
|
Ctrl+Tab - select charset
|
2018-10-14 12:47:23 +02:00
|
|
|
Ctrl+E - reopen current file in another app
|
2015-12-14 15:50:28 +01:00
|
|
|
|
|
|
|
Press any key..."
|
2015-09-07 17:07:51 +02:00
|
|
|
|
|
|
|
char default_dir[] = "/rd/1";
|
2018-05-22 14:04:44 +02:00
|
|
|
od_filter filter2 = { 8, "TXT\0\0" };
|
2015-09-07 17:07:51 +02:00
|
|
|
|
|
|
|
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];
|
|
|
|
|
2018-04-03 14:45:08 +02:00
|
|
|
bool help_opened = false;
|
|
|
|
int charsets_menu_left = 0;
|
2018-10-14 12:47:23 +02:00
|
|
|
int reopenin_menu_left = 0;
|
2015-09-07 17:07:51 +02:00
|
|
|
|
|
|
|
enum {
|
2015-12-14 15:50:28 +01:00
|
|
|
OPEN_FILE,
|
2015-09-07 17:07:51 +02:00
|
|
|
MAGNIFY_MINUS,
|
|
|
|
MAGNIFY_PLUS,
|
|
|
|
CHANGE_ENCODING,
|
|
|
|
RUN_EDIT,
|
|
|
|
SHOW_INFO,
|
2018-04-03 14:45:08 +02:00
|
|
|
SHOW_FILE_PROPERTIES
|
2015-09-07 17:07:51 +02:00
|
|
|
};
|
|
|
|
|
2017-10-05 11:37:50 +02:00
|
|
|
int encoding;
|
|
|
|
|
2018-10-14 12:47:23 +02:00
|
|
|
dword bg_color = 0xF0F0F0;
|
|
|
|
dword text_color = 0;
|
|
|
|
|
2015-09-07 17:07:51 +02:00
|
|
|
#include "ini.h"
|
2015-12-17 16:48:28 +01:00
|
|
|
#include "prepare_page.h"
|
|
|
|
|
2015-11-21 22:12:38 +01:00
|
|
|
void InitDlls()
|
|
|
|
{
|
|
|
|
load_dll(boxlib, #box_lib_init, 0);
|
|
|
|
load_dll(libio, #libio_init, 1);
|
|
|
|
load_dll(libimg, #libimg_init, 1);
|
|
|
|
load_dll(libini, #lib_init, 1);
|
|
|
|
load_dll(iconv_lib, #iconv_open, 0);
|
|
|
|
load_dll(Proc_lib, #OpenDialog_init,0);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-09-07 17:07:51 +02:00
|
|
|
void main()
|
2015-11-21 22:12:38 +01:00
|
|
|
{
|
2015-12-18 22:10:45 +01:00
|
|
|
InitDlls();
|
2015-09-07 17:07:51 +02:00
|
|
|
OpenDialog_init stdcall (#o_dialog);
|
2018-05-22 14:04:44 +02:00
|
|
|
LoadIniSettings();
|
2016-12-21 20:50:13 +01:00
|
|
|
kfont.init(DEFAULT_FONT);
|
2015-09-07 17:07:51 +02:00
|
|
|
Libimg_LoadImage(#skin, abspath("toolbar.png"));
|
|
|
|
OpenFile(#param);
|
|
|
|
list.no_selection = true;
|
2018-04-16 00:44:36 +02:00
|
|
|
SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
|
2015-09-07 17:07:51 +02:00
|
|
|
loop()
|
|
|
|
{
|
2015-11-21 22:12:38 +01:00
|
|
|
switch(WaitEvent())
|
|
|
|
{
|
|
|
|
case evMouse:
|
|
|
|
HandleMouseEvent();
|
2015-09-07 17:07:51 +02:00
|
|
|
break;
|
2015-11-21 22:12:38 +01:00
|
|
|
case evKey:
|
|
|
|
HandleKeyEvent();
|
|
|
|
break;
|
|
|
|
case evButton:
|
|
|
|
HandleButtonEvent();
|
|
|
|
break;
|
|
|
|
case evReDraw:
|
2018-10-14 12:47:23 +02:00
|
|
|
EventMenuClick();
|
2015-11-21 22:12:38 +01:00
|
|
|
draw_window();
|
|
|
|
}
|
2015-09-07 17:07:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-21 22:12:38 +01:00
|
|
|
|
2015-12-17 16:48:28 +01:00
|
|
|
void HandleButtonEvent()
|
|
|
|
{
|
2015-11-21 22:12:38 +01:00
|
|
|
|
2015-12-17 16:48:28 +01:00
|
|
|
byte btn = GetButtonID();
|
|
|
|
if (btn==1) {
|
|
|
|
SaveIniSettings();
|
|
|
|
ExitProcess();
|
|
|
|
}
|
|
|
|
btn-=10;
|
|
|
|
switch(btn)
|
2015-11-21 22:12:38 +01:00
|
|
|
{
|
2015-12-17 16:48:28 +01:00
|
|
|
case OPEN_FILE:
|
|
|
|
EventOpenFile();
|
|
|
|
break;
|
2018-04-03 14:45:08 +02:00
|
|
|
case SHOW_FILE_PROPERTIES:
|
|
|
|
EventShowFileProperties();
|
|
|
|
break;
|
2015-12-17 16:48:28 +01:00
|
|
|
case MAGNIFY_PLUS:
|
|
|
|
EventMagnifyPlus();
|
|
|
|
break;
|
|
|
|
case MAGNIFY_MINUS:
|
|
|
|
EventMagnifyMinus();
|
|
|
|
break;
|
|
|
|
case CHANGE_ENCODING:
|
2018-10-14 12:47:23 +02:00
|
|
|
EventShowEncodingList();
|
2015-12-17 16:48:28 +01:00
|
|
|
break;
|
|
|
|
case RUN_EDIT:
|
2018-10-14 12:47:23 +02:00
|
|
|
EventShowEdit();
|
2015-12-17 16:48:28 +01:00
|
|
|
break;
|
|
|
|
case SHOW_INFO:
|
|
|
|
EventShowInfo();
|
|
|
|
break;
|
2015-11-21 22:12:38 +01:00
|
|
|
}
|
2015-09-07 17:07:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-12-17 16:48:28 +01:00
|
|
|
void HandleKeyEvent()
|
2015-09-07 17:07:51 +02:00
|
|
|
{
|
2015-12-17 16:48:28 +01:00
|
|
|
if (help_opened) {
|
|
|
|
help_opened = false;
|
|
|
|
DrawPage();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
GetKeys();
|
2018-04-03 14:45:08 +02:00
|
|
|
if (key_scancode == SCAN_CODE_F1) {
|
2015-12-17 16:48:28 +01:00
|
|
|
EventShowInfo();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (key_modifier & KEY_LCTRL) || (key_modifier & KEY_RCTRL) {
|
|
|
|
switch (key_scancode)
|
|
|
|
{
|
2018-04-03 14:45:08 +02:00
|
|
|
case SCAN_CODE_KEY_O:
|
2015-12-17 16:48:28 +01:00
|
|
|
EventOpenFile();
|
|
|
|
break;
|
2018-04-03 14:45:08 +02:00
|
|
|
case SCAN_CODE_KEY_I:
|
|
|
|
EventShowFileProperties();
|
|
|
|
break;
|
2015-12-17 16:48:28 +01:00
|
|
|
case SCAN_CODE_UP:
|
|
|
|
EventMagnifyPlus();
|
|
|
|
break;
|
|
|
|
case SCAN_CODE_DOWN:
|
|
|
|
EventMagnifyMinus();
|
|
|
|
break;
|
2018-04-03 14:45:08 +02:00
|
|
|
case SCAN_CODE_KEY_E:
|
2018-10-14 12:47:23 +02:00
|
|
|
EventShowEdit();
|
2015-12-17 16:48:28 +01:00
|
|
|
break;
|
|
|
|
case SCAN_CODE_TAB:
|
|
|
|
EventChangeEncoding();
|
|
|
|
break;
|
2015-09-07 17:07:51 +02:00
|
|
|
}
|
2015-12-17 16:48:28 +01:00
|
|
|
return;
|
2015-09-07 17:07:51 +02:00
|
|
|
}
|
2015-12-17 16:48:28 +01:00
|
|
|
if (list.ProcessKey(key_scancode))
|
|
|
|
DrawPage();
|
|
|
|
}
|
2015-09-07 17:07:51 +02:00
|
|
|
|
|
|
|
|
2015-12-17 16:48:28 +01:00
|
|
|
void HandleMouseEvent()
|
|
|
|
{
|
|
|
|
mouse.get();
|
|
|
|
list.wheel_size = 7;
|
|
|
|
if (list.MouseScroll(mouse.vert)) {
|
|
|
|
DrawPage();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
scrollbar_v_mouse (#scroll);
|
|
|
|
if (list.first != scroll.position) {
|
|
|
|
list.first = scroll.position;
|
|
|
|
DrawPage();
|
2015-09-07 17:07:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-17 16:48:28 +01:00
|
|
|
|
|
|
|
/* ----------------------------------------------------- */
|
|
|
|
|
|
|
|
void EventOpenFile()
|
2015-09-07 17:07:51 +02:00
|
|
|
{
|
2015-12-17 16:48:28 +01:00
|
|
|
OpenDialog_start stdcall (#o_dialog);
|
2018-05-22 14:04:44 +02:00
|
|
|
if (o_dialog.status) {
|
|
|
|
OpenFile(#openfile_path);
|
|
|
|
PreparePage();
|
|
|
|
}
|
2015-09-07 17:07:51 +02:00
|
|
|
}
|
|
|
|
|
2018-04-03 14:45:08 +02:00
|
|
|
void EventShowFileProperties()
|
|
|
|
{
|
|
|
|
char ss_param[4096];
|
|
|
|
if (!param) return;
|
|
|
|
sprintf(#ss_param, "-p %s", #param);
|
2018-10-14 12:47:23 +02:00
|
|
|
RunProgram("/sys/File managers/Eolite", #ss_param);
|
2018-04-03 14:45:08 +02:00
|
|
|
}
|
|
|
|
|
2015-12-17 16:48:28 +01:00
|
|
|
void EventMagnifyPlus()
|
2015-09-07 17:07:51 +02:00
|
|
|
{
|
2016-12-21 20:50:13 +01:00
|
|
|
kfont.size.pt++;
|
|
|
|
if(!kfont.changeSIZE())
|
|
|
|
kfont.size.pt--;
|
2015-12-17 16:48:28 +01:00
|
|
|
else
|
|
|
|
PreparePage();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EventMagnifyMinus()
|
|
|
|
{
|
2016-12-21 20:50:13 +01:00
|
|
|
kfont.size.pt--;
|
|
|
|
if(!kfont.changeSIZE())
|
|
|
|
kfont.size.pt++;
|
2015-12-17 16:48:28 +01:00
|
|
|
else
|
|
|
|
PreparePage();
|
|
|
|
}
|
|
|
|
|
2018-10-14 12:47:23 +02:00
|
|
|
void EventShowEdit()
|
2015-12-17 16:48:28 +01:00
|
|
|
{
|
2018-10-14 12:47:23 +02:00
|
|
|
menu.selected = 0;
|
|
|
|
menu.show(Form.left+5 + reopenin_menu_left, Form.top+29+skin_height, 130,
|
|
|
|
"Tinypad\nTextEdit\nWebView\nFB2Read\nHexView", 20);
|
2015-12-17 16:48:28 +01:00
|
|
|
}
|
|
|
|
|
2018-10-14 12:47:23 +02:00
|
|
|
void EventShowEncodingList()
|
2015-12-17 16:48:28 +01:00
|
|
|
{
|
2016-01-07 16:43:03 +01:00
|
|
|
menu.selected = encoding + 1;
|
2018-04-03 14:45:08 +02:00
|
|
|
menu.show(Form.left+5 + charsets_menu_left, Form.top+29+skin_height, 130,
|
|
|
|
"UTF-8\nKOI8-RU\nCP1251\nCP1252\nISO8859-5\nCP866", 10);
|
2015-12-17 16:48:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void EventShowInfo() {
|
|
|
|
help_opened = true;
|
|
|
|
DrawBar(list.x, list.y, list.w, list.h, 0xFFFfff);
|
|
|
|
WriteText(list.x + 10, list.y + 10, 10000001b, 0x555555, VERSION);
|
|
|
|
WriteTextLines(list.x + 10, list.y+40, 10110000b, 0, ABOUT, 20);
|
2015-09-07 17:07:51 +02:00
|
|
|
}
|
|
|
|
|
2018-10-14 12:47:23 +02:00
|
|
|
void EventChangeEncoding(dword id)
|
|
|
|
{
|
|
|
|
encoding = id;
|
|
|
|
OpenFile(#openfile_path);
|
|
|
|
PreparePage();
|
|
|
|
draw_window();
|
|
|
|
}
|
|
|
|
|
|
|
|
void EventOpenFileInAnotherProgram(dword _app)
|
|
|
|
{
|
|
|
|
RunProgram(_app, #param);
|
|
|
|
}
|
|
|
|
|
|
|
|
void EventMenuClick()
|
|
|
|
{
|
|
|
|
switch(menu.cur_y)
|
|
|
|
{
|
|
|
|
//Encoding
|
|
|
|
case 10...15:
|
|
|
|
EventChangeEncoding(menu.cur_y-10);
|
|
|
|
break;
|
|
|
|
//Reopen
|
|
|
|
case 20:
|
|
|
|
EventOpenFileInAnotherProgram("/sys/tinypad");
|
|
|
|
break;
|
|
|
|
case 21:
|
|
|
|
EventOpenFileInAnotherProgram("/sys/develop/t_edit");
|
|
|
|
break;
|
|
|
|
case 22:
|
|
|
|
EventOpenFileInAnotherProgram("/sys/network/webview");
|
|
|
|
break;
|
|
|
|
case 23:
|
|
|
|
EventOpenFileInAnotherProgram("/sys/fb2read");
|
|
|
|
break;
|
|
|
|
case 24:
|
|
|
|
EventOpenFileInAnotherProgram("/sys/develop/heed");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
menu.cur_y = 0;
|
|
|
|
}
|
|
|
|
|
2015-12-17 16:48:28 +01:00
|
|
|
/* ------------------------------------------- */
|
|
|
|
|
|
|
|
|
2015-09-07 17:07:51 +02:00
|
|
|
void OpenFile(dword f_path)
|
|
|
|
{
|
|
|
|
int tmp;
|
|
|
|
if (ESBYTE[f_path]) {
|
|
|
|
strcpy(#param, f_path);
|
|
|
|
io.read(#param);
|
|
|
|
strcpy(#title, #param);
|
|
|
|
strcat(#title, " - Text Reader");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (list.count) return;
|
2015-11-21 22:12:38 +01:00
|
|
|
io.buffer_data = INTRO_TEXT;
|
2015-09-07 17:07:51 +02:00
|
|
|
strcpy(#title, "Text Reader");
|
|
|
|
}
|
|
|
|
if (encoding!=CH_CP866) ChangeCharset(charsets[encoding], "CP866", io.buffer_data);
|
|
|
|
list.KeyHome();
|
|
|
|
list.ClearList();
|
|
|
|
}
|
|
|
|
|
2015-12-17 16:48:28 +01:00
|
|
|
void draw_window()
|
|
|
|
{
|
2018-04-03 14:45:08 +02:00
|
|
|
#define PADDING 6
|
|
|
|
#define TOOLBAR_BUTTON_WIDTH 26
|
|
|
|
incn x;
|
2016-11-23 12:37:13 +01:00
|
|
|
DefineAndDrawWindow(Form.left,Form.top,Form.width,Form.height,0x73,0,#title,0);
|
2015-12-17 16:48:28 +01:00
|
|
|
GetProcessInfo(#Form, SelfInfo);
|
|
|
|
if (Form.status_window>2) return;
|
|
|
|
|
|
|
|
if (Form.width < 200) { MoveSize(OLD,OLD,200,OLD); return; }
|
|
|
|
if (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); return; }
|
|
|
|
|
|
|
|
DrawBar(0, 0, Form.cwidth, TOOLBAR_H - 1, 0xe1e1e1);
|
|
|
|
DrawBar(0, TOOLBAR_H - 1, Form.cwidth, 1, 0x7F7F7F);
|
|
|
|
|
2018-04-03 14:45:08 +02:00
|
|
|
x.n = 0;
|
|
|
|
DrawToolbarButton(OPEN_FILE, x.inc(8));
|
|
|
|
DrawToolbarButton(SHOW_FILE_PROPERTIES, x.inc(TOOLBAR_BUTTON_WIDTH + PADDING));
|
2018-10-02 22:13:25 +02:00
|
|
|
DrawToolbarButton(MAGNIFY_MINUS, x.inc(TOOLBAR_BUTTON_WIDTH + PADDING + PADDING));
|
|
|
|
DrawToolbarButton(MAGNIFY_PLUS, x.inc(TOOLBAR_BUTTON_WIDTH - 1));
|
2018-04-03 14:45:08 +02:00
|
|
|
DrawToolbarButton(CHANGE_ENCODING, x.inc(TOOLBAR_BUTTON_WIDTH + PADDING + PADDING));
|
|
|
|
charsets_menu_left = x.n;
|
2018-10-14 12:47:23 +02:00
|
|
|
DrawToolbarButton(RUN_EDIT, x.inc(TOOLBAR_BUTTON_WIDTH + PADDING + PADDING));
|
|
|
|
reopenin_menu_left = x.n;
|
2015-12-17 16:48:28 +01:00
|
|
|
DrawToolbarButton(SHOW_INFO, Form.cwidth - 34);
|
|
|
|
|
2017-10-03 16:55:12 +02:00
|
|
|
|
2015-12-17 16:48:28 +01:00
|
|
|
if ((Form.cwidth-scroll.size_x-1 == list.w) &&
|
|
|
|
(Form.cheight-TOOLBAR_H == list.h) &&
|
|
|
|
(list.count)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
DrawPage();
|
|
|
|
} else {
|
|
|
|
PreparePage();
|
|
|
|
}
|
|
|
|
DrawRectangle(scroll.start_x, scroll.start_y, scroll.size_x, scroll.size_y-1, scroll.bckg_col);
|
2015-11-21 22:12:38 +01:00
|
|
|
}
|
2015-12-17 16:48:28 +01:00
|
|
|
|
|
|
|
void DrawPage()
|
|
|
|
{
|
2016-12-23 01:27:00 +01:00
|
|
|
kfont.ShowBufferPart(list.x, list.y, list.w, list.h, list.first*list.item_h*list.w);
|
2015-12-17 16:48:28 +01:00
|
|
|
DrawScroller();
|
2018-05-22 14:04:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void DrawToolbarButton(char image_id, int x)
|
|
|
|
{
|
|
|
|
DefineButton(x+1, 6, TOOLBAR_ICON_WIDTH-2, TOOLBAR_ICON_HEIGHT-2, 10+image_id + BT_HIDE, 0);
|
2018-10-02 22:13:25 +02:00
|
|
|
img_draw stdcall(skin.image, x, 5, TOOLBAR_ICON_WIDTH, TOOLBAR_ICON_HEIGHT, TOOLBAR_ICON_WIDTH-1*image_id, 0);
|
2018-05-22 14:04:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void DrawScroller()
|
|
|
|
{
|
|
|
|
scroll.max_area = list.count;
|
|
|
|
scroll.cur_area = list.visible;
|
|
|
|
scroll.position = list.first;
|
|
|
|
scroll.all_redraw = 0;
|
|
|
|
scroll.start_x = list.x + list.w;
|
|
|
|
scroll.start_y = list.y;
|
|
|
|
scroll.size_y = list.h;
|
|
|
|
scrollbar_v_draw(#scroll);
|
2015-12-17 16:48:28 +01:00
|
|
|
}
|