Subversion Repositories Kolibri OS

Compare Revisions

No changes between revisions

Regard whitespace Rev 6753 → Rev 6759

/programs/cmm/txtread/Tupfile.lua
0,0 → 1,6
if tup.getconfig("NO_CMM") ~= "" then return end
if tup.getconfig("LANG") == "ru"
then C_LANG = "LANG_RUS"
else C_LANG = "LANG_ENG" -- this includes default case without config
end
tup.rule("txtread.c", "c-- /D=AUTOBUILD /D=$(C_LANG) %f" .. tup.getconfig("KPACK_CMD"), "txtread.com")
/programs/cmm/txtread/ini.h
0,0 → 1,24
char ini_path[4096];
char config_section[] = "Config";
int encoding;
 
void LoadIniSettings()
{
strcpy(#ini_path, "/sys/settings/txtread.ini");
ini_get_int stdcall (#ini_path, #config_section, "FontSize", 14); label.size.pt = EAX;
ini_get_int stdcall (#ini_path, #config_section, "Encoding", CH_CP866); encoding = EAX;
ini_get_int stdcall (#ini_path, #config_section, "WinX", 150); Form.left = EAX;
ini_get_int stdcall (#ini_path, #config_section, "WinY", 50); Form.top = EAX;
ini_get_int stdcall (#ini_path, #config_section, "WinW", 640); Form.width = EAX;
ini_get_int stdcall (#ini_path, #config_section, "WinH", 560); Form.height = EAX;
}
 
void SaveIniSettings()
{
ini_set_int stdcall (#ini_path, #config_section, "FontSize", label.size.pt);
ini_set_int stdcall (#ini_path, #config_section, "Encoding", encoding);
ini_set_int stdcall (#ini_path, #config_section, "WinX", Form.left);
ini_set_int stdcall (#ini_path, #config_section, "WinY", Form.top);
ini_set_int stdcall (#ini_path, #config_section, "WinW", Form.width);
ini_set_int stdcall (#ini_path, #config_section, "WinH", Form.height);
}
/programs/cmm/txtread/txtread.c
0,0 → 1,296
#define MEMSIZE 4096*25
 
#include "../lib/font.h"
#include "../lib/io.h"
#include "../lib/gui.h"
#include "../lib/list_box.h"
#include "../lib/menu.h"
#include "../lib/obj/box_lib.h"
#include "../lib/obj/libini.h"
#include "../lib/obj/iconv.h"
#include "../lib/obj/proc_lib.h"
#include "../lib/patterns/libimg_load_skin.h"
#include "../lib/patterns/simple_open_dialog.h"
 
#define TOOLBAR_H 34
#define TOOLBAR_ICON_WIDTH 26
#define TOOLBAR_ICON_HEIGHT 24
 
#define DEFAULT_EDITOR "/sys/tinypad"
 
#define INTRO_TEXT "This is a plain Text Reader.\nTry to open some text file."
#define VERSION "Text Reader v1.2"
#define ABOUT "Idea: Leency, punk_joker
Code: Leency, Veliant, KolibriOS Team
 
Hotkeys:
Ctrl+O - open file
Ctrl+Up - bigger font
Ctrl+Down - smaller font
Ctrl+Tab - select charset
Ctrl+E - edit current document
Press any key..."
 
char default_dir[] = "/rd/1";
od_filter filter2 = {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};
llist list;
 
proc_info Form;
char title[4196];
 
byte help_opened = false;
 
enum {
OPEN_FILE,
MAGNIFY_MINUS,
MAGNIFY_PLUS,
CHANGE_ENCODING,
RUN_EDIT,
SHOW_INFO,
};
 
#include "ini.h"
#include "gui.h"
#include "prepare_page.h"
 
 
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);
}
 
 
void main()
{
InitDlls();
OpenDialog_init stdcall (#o_dialog);
label.init(DEFAULT_FONT);
Libimg_LoadImage(#skin, abspath("toolbar.png"));
LoadIniSettings();
OpenFile(#param);
list.no_selection = true;
SetEventMask(10000000000000000000000001100111b);
loop()
{
switch(WaitEvent())
{
case evMouse:
HandleMouseEvent();
break;
case evKey:
HandleKeyEvent();
break;
case evButton:
HandleButtonEvent();
break;
case evReDraw:
if (menu.list.cur_y) {
encoding = menu.list.cur_y - 10;
OpenFile(#param);
PreparePage();
menu.list.cur_y = NULL;
};
draw_window();
}
}
}
 
 
void HandleButtonEvent()
{
byte btn = GetButtonID();
if (btn==1) {
SaveIniSettings();
ExitProcess();
}
btn-=10;
switch(btn)
{
case OPEN_FILE:
EventOpenFile();
break;
case MAGNIFY_PLUS:
EventMagnifyPlus();
break;
case MAGNIFY_MINUS:
EventMagnifyMinus();
break;
case CHANGE_ENCODING:
EventChangeEncoding();
break;
case RUN_EDIT:
EventRunEdit();
break;
case SHOW_INFO:
EventShowInfo();
break;
}
}
 
 
void HandleKeyEvent()
{
if (help_opened) {
help_opened = false;
DrawPage();
return;
}
GetKeys();
if (key_scancode==059) {
EventShowInfo();
return;
}
if (key_modifier & KEY_LCTRL) || (key_modifier & KEY_RCTRL) {
switch (key_scancode)
{
case 024:
EventOpenFile();
break;
case SCAN_CODE_UP:
EventMagnifyPlus();
break;
case SCAN_CODE_DOWN:
EventMagnifyMinus();
break;
case 018:
EventRunEdit();
break;
case SCAN_CODE_TAB:
EventChangeEncoding();
break;
}
return;
}
if (list.ProcessKey(key_scancode))
DrawPage();
}
 
 
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();
}
}
 
 
/* ----------------------------------------------------- */
 
void EventOpenFile()
{
OpenDialog_start stdcall (#o_dialog);
OpenFile(#openfile_path);
PreparePage();
}
 
void EventMagnifyPlus()
{
label.size.pt++;
if(!label.changeSIZE())
label.size.pt--;
else
PreparePage();
}
 
void EventMagnifyMinus()
{
label.size.pt--;
if(!label.changeSIZE())
label.size.pt++;
else
PreparePage();
}
 
void EventRunEdit()
{
io.run(DEFAULT_EDITOR, #param);
}
 
void EventChangeEncoding()
{
menu.selected = encoding + 1;
menu.show(Form.left+104, Form.top+29+skin_height, 130, "UTF-8\nKOI8-RU\nCP1251\nCP1252\nISO8859-5\nCP866", 10);
}
 
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);
}
 
/* ------------------------------------------- */
 
 
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;
io.buffer_data = INTRO_TEXT;
strcpy(#title, "Text Reader");
}
if (encoding!=CH_CP866) ChangeCharset(charsets[encoding], "CP866", io.buffer_data);
list.KeyHome();
list.ClearList();
}
 
void draw_window()
{
DefineAndDrawWindow(Form.left,Form.top,Form.width,Form.height,0x73,0,#title,0);
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);
DrawToolbarButton(OPEN_FILE, 8);
DrawToolbarButton(MAGNIFY_PLUS, 42);
DrawToolbarButton(MAGNIFY_MINUS, 67);
DrawToolbarButton(CHANGE_ENCODING, 101);
DrawToolbarButton(RUN_EDIT, 135);
DrawToolbarButton(SHOW_INFO, Form.cwidth - 34);
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);
}
 
void DrawPage()
{
_PutImage(list.x,list.y,list.w,list.h,list.first*list.item_h*list.w*3 + label.raw);
DrawScroller();
}
/programs/cmm/txtread/gui.h
0,0 → 1,19
void DrawToolbarButton(char image_id, int x)
{
DefineButton(x+1, 7, TOOLBAR_ICON_WIDTH-2, TOOLBAR_ICON_HEIGHT-2, 10+image_id + BT_HIDE, 0);
img_draw stdcall(skin.image, x, 6, TOOLBAR_ICON_WIDTH, TOOLBAR_ICON_HEIGHT, 0, image_id*TOOLBAR_ICON_HEIGHT);
}
 
 
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;
scroll.start_x = list.x + list.w;
scrollbar_v_draw(#scroll);
}
/programs/cmm/txtread/prepare_page.h
0,0 → 1,73
char char_width[255];
 
enum {
COUNT_BUF_HEIGHT,
DRAW_BUF
};
 
void Parcer(byte mode)
{
dword bufoff, buflen;
byte ch;
char line[4096]=0;
int srch_pos;
dword stroka=0;
dword stroka_y=5;
dword line_length=30;
dword line_start=io.buffer_data;
 
buflen = strlen(io.buffer_data) + io.buffer_data;
for (bufoff=io.buffer_data; bufoff<buflen; bufoff++)
{
ch = ESBYTE[bufoff];
line_length += char_width[ch];
if (line_length>=list.w) || (ch==10) {
srch_pos = bufoff;
loop()
{
if (__isWhite(ESBYTE[srch_pos])) { bufoff=srch_pos+1; break; } //normal word-break
if (srch_pos == line_start) break; //no white space found in whole line
srch_pos--;
}
if (mode==COUNT_BUF_HEIGHT) {
line_start = bufoff;
line_length = 30;
list.count++;
}
if (mode==DRAW_BUF) {
EBX = bufoff-line_start;
strlcpy(#line, line_start, EBX);
label.write_buf(8,stroka_y,list.w,label.size.height, 0xFFFFFF, 0, label.size.pt, #line);
stroka_y += list.item_h;
line_start = bufoff;
line_length = 30;
}
}
}
if (mode==COUNT_BUF_HEIGHT) list.count+=2;
if (mode==DRAW_BUF) label.write_buf(8,stroka_y,list.w,label.size.height, 0xFFFFFF, 0, label.size.pt, line_start);
}
 
void PreparePage()
{
//get font chars width, need to increase performance
int i;
label.changeSIZE();
for (i=0; i<256; i++) char_width[i] = label.symbol_size(i);
 
//get font buffer height
list.w = Form.cwidth-scroll.size_x-1;
list.count=0;
Parcer(COUNT_BUF_HEIGHT);
//draw text in buffer
list.SetSizes(0, TOOLBAR_H, list.w, Form.cheight-TOOLBAR_H, label.size.pt+3);
if (list.count < list.visible) list.count = list.visible;
label.size.height = list.count+1*list.item_h;
label.raw_size = 0;
Parcer(DRAW_BUF);
 
//draw result
label.apply_smooth();
DrawPage();
}
/programs/cmm/txtread/toolbar.png
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/programs/cmm/txtread/compile.bat
0,0 → 1,5
@C-- "textreader.c"
@del "textreader"
@rename "textreader.com" "textreader"
@del warning.txt
@pause
/programs/cmm/txtread/.
Property changes:
Added: tsvn:logminsize
+5
\ No newline at end of property