Calypte: new program for read text book
git-svn-id: svn://kolibrios.org@5612 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
404f097a41
commit
0dab2e078d
|
@ -0,0 +1,389 @@
|
|||
#define MEMSIZE 0x100000
|
||||
#include "..\lib\kolibri.h"
|
||||
#include "..\lib\strings.h"
|
||||
#include "..\lib\mem.h"
|
||||
#include "..\lib\file_system.h"
|
||||
#include "..\lib\dll.h"
|
||||
#include "..\lib\gui.h"
|
||||
#include "..\lib\obj\box_lib.h"
|
||||
#include "..\lib\obj\proc_lib.h"
|
||||
#include "..\lib\obj\libio_lib.h"
|
||||
|
||||
#include "lang.h--"
|
||||
|
||||
#ifdef LANG_RUS
|
||||
?define T_FILE "” ©«"
|
||||
?define T_TYPE "’¨¯"
|
||||
?define T_SIZE "<EFBFBD> §¬¥à"
|
||||
?define MENU1 "” ©«"
|
||||
?define MENU1_SUBMENU1 "Žâªàëâì"
|
||||
?define MENU1_SUBMENU2 "‡ ªàëâì"
|
||||
?define MENU1_SUBMENU3 "‘¢®©á⢠"
|
||||
?define MENU1_SUBMENU4 "‚ë室"
|
||||
?define ERROR_LOAD_BOX_LIB "Žè¨¡ª ¯à¨ § £à㧪¥ ¡¨¡«¨®â¥ª¨ - box_lib.obj"
|
||||
?define ERROR_LOAD_LIBIO "Žè¨¡ª ¯à¨ § £à㧪¥ ¡¨¡«¨®â¥ª¨ - libio.obj"
|
||||
?define ERROR_LOAD_PROC_LIB "Žè¨¡ª ¯à¨ § £à㧪¥ ¡¨¡«¨®â¥ª¨ - proc_lib.obj"
|
||||
#else
|
||||
?define T_FILE "File"
|
||||
?define T_TYPE "Type"
|
||||
?define T_SIZE "Size"
|
||||
?define MENU1 "File"
|
||||
?define MENU1_SUBMENU1 "Open"
|
||||
?define MENU1_SUBMENU2 "Close"
|
||||
?define MENU1_SUBMENU3 "Properties"
|
||||
?define MENU1_SUBMENU4 "Exit"
|
||||
?define ERROR_LOAD_BOX_LIB "Error while loading library - box_lib.obj"
|
||||
?define ERROR_LOAD_LIBIO "Error while loading library - libio.obj"
|
||||
?define ERROR_LOAD_PROC_LIB "Error while loading library - proc_lib.obj"
|
||||
#endif
|
||||
|
||||
#ifdef LANG_RUS
|
||||
struct menu_text_struct
|
||||
{
|
||||
char menu[5];
|
||||
char sub_menu1[8];
|
||||
char sub_menu2[8];
|
||||
//char sub_menu3[9];
|
||||
char sub_menu4[6];
|
||||
byte end;
|
||||
};
|
||||
#else
|
||||
struct menu_text_struct
|
||||
{
|
||||
char menu[5];
|
||||
char sub_menu1[5];
|
||||
char sub_menu2[6];
|
||||
//char sub_menu3[11];
|
||||
char sub_menu4[5];
|
||||
byte end;
|
||||
};
|
||||
#endif
|
||||
|
||||
#define TITLE "Calypte v0.1"
|
||||
|
||||
#define TOPPANELH 19
|
||||
#define BOTPANELH 10
|
||||
#define WIN_W 600
|
||||
#define WIN_H 400
|
||||
|
||||
proc_info Form;
|
||||
system_colors sc;
|
||||
|
||||
byte active_properties = 0;
|
||||
dword properties_window;
|
||||
|
||||
#include "include\gui.h"
|
||||
#include "include\properties.h"
|
||||
|
||||
struct filter
|
||||
{
|
||||
dword size;
|
||||
char ext1[4];
|
||||
//char ext2[4];
|
||||
//char ext3[4];
|
||||
//char ext4[4];
|
||||
byte end;
|
||||
};
|
||||
|
||||
filter filter2;
|
||||
menu_text_struct menu_text_area1;
|
||||
|
||||
char win_title[4096] = "Calypte v0.1";
|
||||
|
||||
int
|
||||
cur_row=0,
|
||||
read=0,
|
||||
pos=0,
|
||||
row_num=0,
|
||||
col_count=0,
|
||||
row_count=0;
|
||||
|
||||
dword old_width,old_height;
|
||||
|
||||
proc_info pr_inf;
|
||||
char communication_area_name[] = "FFFFFFFF_open_dialog";
|
||||
byte plugin_path[4096];
|
||||
char default_dir[] = "/rd/1";
|
||||
char open_dialog_path[] = "/rd/1/File managers/opendial"; //opendial
|
||||
byte openfile_path[2048];
|
||||
byte filename_area[4096];
|
||||
|
||||
opendialog o_dialog = {0, #pr_inf, #communication_area_name, 0, #plugin_path, #default_dir, #open_dialog_path, #draw_window, 0, #openfile_path, #filename_area, #filter2, 420, 200, 320, 120};
|
||||
|
||||
dword bufpointer;
|
||||
dword bufsize;
|
||||
dword draw_sruct;
|
||||
|
||||
menu_data menudata1 = {0, 40, 2, 15, 2, #menu_text_area1.menu, #menu_text_area1.sub_menu1, #menu_text_area1.end, 0, 0, 80, 2, 100, 18, 0xEEEEEE, 0xFF, 0xEEEEEE, 0, 0, 0, #Form, 0, 0, 0, 16, 0, 0, 0x00CC00, 0, 0xFFFFFF, 0, 8, 0, 0};
|
||||
|
||||
void main()
|
||||
{
|
||||
int id, key;
|
||||
|
||||
strcpy(#filter2.ext1, "TXT");
|
||||
//strcpy(#filter2.ext2, "ASM");
|
||||
//strcpy(#filter2.ext3, "INC\0");
|
||||
//strcpy(#filter2.ext4, "\0");
|
||||
filter2.size = 8;
|
||||
filter2.end = 0;
|
||||
|
||||
strcpy(#menu_text_area1.menu, MENU1);
|
||||
strcpy(#menu_text_area1.sub_menu1, MENU1_SUBMENU1);
|
||||
strcpy(#menu_text_area1.sub_menu2, MENU1_SUBMENU2);
|
||||
//strcpy(#menu_text_area1.sub_menu3, MENU1_SUBMENU3);
|
||||
strcpy(#menu_text_area1.sub_menu4, MENU1_SUBMENU4);
|
||||
menu_text_area1.end = 0;
|
||||
|
||||
mem_Init();
|
||||
if (load_dll2(boxlib, #box_lib_init,0)!=0) notify(ERROR_LOAD_BOX_LIB);
|
||||
if (load_dll2(libio, #libio_init,1)!=0) notify(ERROR_LOAD_LIBIO);
|
||||
if (load_dll2(Proc_lib, #OpenDialog_init,0)!=0) notify(ERROR_LOAD_PROC_LIB);
|
||||
OpenDialog_init stdcall (#o_dialog);
|
||||
SetEventMask(0x27);
|
||||
loop()
|
||||
{
|
||||
switch(WaitEvent())
|
||||
{
|
||||
case evMouse:
|
||||
menu_bar_mouse stdcall (#menudata1);
|
||||
if (menudata1.click==1)
|
||||
{
|
||||
switch(menudata1.cursor_out)
|
||||
{
|
||||
case 1:
|
||||
OpenDialog_start stdcall (#o_dialog);
|
||||
OpenFile(#openfile_path);
|
||||
Prepare();
|
||||
draw_window();
|
||||
break;
|
||||
case 2:
|
||||
read = 0;
|
||||
strcpy(#win_title, TITLE);
|
||||
FreeBuf();
|
||||
draw_window();
|
||||
break;
|
||||
case 3:
|
||||
if (!active_properties)
|
||||
{
|
||||
SwitchToAnotherThread();
|
||||
properties_window = CreateThread(#properties_dialog, #properties_stak+4092);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
ActivateWindow(GetProcessSlot(properties_window));
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
ExitProcess();
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case evButton:
|
||||
id=GetButtonID();
|
||||
if (id==1) || (id==10) ExitProcess();
|
||||
break;
|
||||
|
||||
case evKey:
|
||||
key = GetKey();
|
||||
switch (key)
|
||||
{
|
||||
if (Form.status_window>2) break;
|
||||
case 015: //Ctrl+O
|
||||
OpenDialog_start stdcall (#o_dialog);
|
||||
OpenFile(#openfile_path);
|
||||
Prepare();
|
||||
draw_window();
|
||||
break;
|
||||
case ASCII_KEY_HOME:
|
||||
cur_row = 0;
|
||||
DrawText();
|
||||
break;
|
||||
case ASCII_KEY_END:
|
||||
cur_row = row_num - row_count - 1;
|
||||
DrawText();
|
||||
break;
|
||||
case ASCII_KEY_UP:
|
||||
if (!cur_row) break;
|
||||
else cur_row = cur_row-1;
|
||||
DrawText();
|
||||
break;
|
||||
case ASCII_KEY_DOWN:
|
||||
if (cur_row+row_count>=row_num) break;
|
||||
cur_row = cur_row+1;
|
||||
DrawText();
|
||||
break;
|
||||
case ASCII_KEY_PGUP:
|
||||
if (!cur_row) break;
|
||||
if (cur_row<row_count) cur_row = 0;
|
||||
else cur_row = cur_row-row_count;
|
||||
DrawText();
|
||||
break;
|
||||
case ASCII_KEY_PGDN:
|
||||
if (cur_row+row_count>row_num) break;
|
||||
cur_row = cur_row+row_count;
|
||||
DrawText();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case evReDraw:
|
||||
draw_window();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void draw_window()
|
||||
{
|
||||
sc.get();
|
||||
DefineAndDrawWindow(GetScreenWidth()-WIN_W/2,GetScreenHeight()-WIN_H/2,WIN_W,WIN_H,0x73,0xFFFFFF,#win_title);
|
||||
GetProcessInfo(#Form, SelfInfo);
|
||||
DrawBar(0, 0, Form.cwidth, TOPPANELH, sc.work);
|
||||
DrawBar(0, Form.cheight-BOTPANELH, Form.cwidth, BOTPANELH, sc.work);
|
||||
|
||||
menudata1.bckg_col = sc.work;
|
||||
menu_bar_draw stdcall (#menudata1);
|
||||
|
||||
if (old_width!=Form.width) || (old_height!=Form.height)
|
||||
{
|
||||
old_width = Form.width;
|
||||
old_height = Form.height;
|
||||
|
||||
col_count = Form.cwidth/6;
|
||||
row_count = Form.cheight-BOTPANELH-TOPPANELH-2;
|
||||
row_count = row_count/10;
|
||||
|
||||
if (read==1) Prepare();
|
||||
}
|
||||
if (read==1)
|
||||
{
|
||||
DrawText();
|
||||
}
|
||||
else DrawBar(0, TOPPANELH, Form.cwidth, Form.cheight-BOTPANELH-TOPPANELH, 0xFFFFFF);
|
||||
}
|
||||
|
||||
void OpenFile(dword path)
|
||||
{
|
||||
strcpy(#win_title, TITLE);
|
||||
strcat(#win_title, " - ");
|
||||
strcat(#win_title, path);
|
||||
file_size stdcall (path);
|
||||
bufsize = EBX;
|
||||
if (bufsize)
|
||||
{
|
||||
mem_Free(bufpointer);
|
||||
bufpointer = mem_Alloc(bufsize);
|
||||
ReadFile(0, bufsize, bufpointer, path);
|
||||
read=1;
|
||||
}
|
||||
}
|
||||
|
||||
void FreeBuf()
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<row_num; i++)
|
||||
{
|
||||
mem_Free(DSDWORD[i*4+draw_sruct]);
|
||||
}
|
||||
mem_Free(draw_sruct);
|
||||
mem_Free(bufpointer);
|
||||
}
|
||||
|
||||
void Prepare()
|
||||
{
|
||||
int i, sub_pos;
|
||||
int len_str = 0;
|
||||
byte do_eof = 0;
|
||||
word bukva[2];
|
||||
dword address;
|
||||
row_num = 0;
|
||||
while(1)
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
bukva = DSBYTE[bufpointer+pos+len_str];
|
||||
if (bukva=='\0')
|
||||
{
|
||||
do_eof = 1;
|
||||
break;
|
||||
}
|
||||
if (bukva==0x0a) break;
|
||||
else len_str++;
|
||||
}
|
||||
if (len_str<=col_count)
|
||||
{
|
||||
pos=pos+len_str+1;
|
||||
row_num++;
|
||||
}
|
||||
else
|
||||
{
|
||||
pos=pos+col_count;
|
||||
row_num++;
|
||||
}
|
||||
len_str = 0;
|
||||
if (do_eof) break;
|
||||
}
|
||||
mem_Free(draw_sruct);
|
||||
draw_sruct = mem_Alloc(row_num*4);
|
||||
pos=0;
|
||||
sub_pos=0;
|
||||
len_str = 0;
|
||||
do_eof = 0;
|
||||
while(1)
|
||||
{
|
||||
while(1)
|
||||
{
|
||||
bukva = DSBYTE[bufpointer+pos+len_str];
|
||||
if (bukva=='\0')
|
||||
{
|
||||
do_eof = 1;
|
||||
break;
|
||||
}
|
||||
if (bukva==0x0a) break;
|
||||
else len_str++;
|
||||
}
|
||||
if (len_str<=col_count)
|
||||
{
|
||||
address = mem_Alloc(len_str+1);
|
||||
ESDWORD[sub_pos*4+draw_sruct] = address;
|
||||
strlcpy(DSDWORD[sub_pos*4+draw_sruct], bufpointer+pos, len_str);
|
||||
pos=pos+len_str+1;
|
||||
sub_pos++;
|
||||
}
|
||||
else
|
||||
{
|
||||
address = mem_Alloc(len_str+1);
|
||||
ESDWORD[sub_pos*4+draw_sruct] = address;
|
||||
strlcpy(DSDWORD[sub_pos*4+draw_sruct], bufpointer+pos, col_count);
|
||||
pos=pos+col_count;
|
||||
sub_pos++;
|
||||
}
|
||||
len_str = 0;
|
||||
if (pos>=bufsize-1) break;
|
||||
}
|
||||
pos=0;
|
||||
}
|
||||
|
||||
void DrawText()
|
||||
{
|
||||
int i, top, num_line;
|
||||
if (row_num<row_count) top = row_num;
|
||||
else
|
||||
{
|
||||
if (row_num-cur_row<=row_count) top = row_num-cur_row-1;
|
||||
else top = row_count;
|
||||
}
|
||||
DrawBar(0, TOPPANELH, Form.cwidth, 3, 0xFFFFFF);
|
||||
for (i=0, num_line = cur_row; i<top; i++, num_line++)
|
||||
{
|
||||
DrawBar(0, i*10+TOPPANELH+3, Form.cwidth, 10, 0xFFFFFF);
|
||||
WriteText(2, i*10+TOPPANELH+3, 0x80, 0x000000, DSDWORD[num_line*4+draw_sruct]);
|
||||
}
|
||||
DrawBar(0, i*10+TOPPANELH+3, Form.cwidth, -i*10-TOPPANELH-BOTPANELH+Form.cheight, 0xFFFFFF);
|
||||
}
|
||||
|
||||
stop:
|
||||
char properties_stak[4096];
|
|
@ -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("Ready.c", "c-- /D=AUTOBUILD /D=$(C_LANG) %f" .. tup.getconfig("KPACK_CMD"), "Ready.com")
|
|
@ -0,0 +1,11 @@
|
|||
@del lang.h--
|
||||
@echo #define LANG_ENG 1 >lang.h--
|
||||
|
||||
@del Calypte
|
||||
cls
|
||||
c-- Calypte.c
|
||||
@kpack Calypte.com
|
||||
@rename Calypte.com Calypte
|
||||
@del warning.txt
|
||||
@del lang.h--
|
||||
@pause
|
|
@ -0,0 +1,11 @@
|
|||
@del lang.h--
|
||||
@echo #define LANG_RUS 1 >lang.h--
|
||||
|
||||
@del Calypte
|
||||
cls
|
||||
c-- Calypte.c
|
||||
@kpack Calypte.com
|
||||
@rename Calypte.com Calypte
|
||||
@del warning.txt
|
||||
@del lang.h--
|
||||
@pause
|
|
@ -0,0 +1,23 @@
|
|||
#define COL_PADDING 0xC8C9C9
|
||||
|
||||
dword col_palette[14] = {0xD2D3D3,0xD4D4D4,0xD6D5D6,0xD8D7D8,0xDAD8D9,0xDCDADB,
|
||||
0xDFDCDD,0xE1DDDE,0xE2DEE0,0xE4DFE1,0xE3DFE1,0xE3DFE1,0xE3DFE1,0xE3DFE1,0xE3DFE1};
|
||||
|
||||
void DrawFlatButton(dword x,y,width,height,id,color,text)
|
||||
{
|
||||
int fill_h;
|
||||
DrawRectangle(x,y,width,height,sc.work_graph);
|
||||
DrawRectangle3D(x+1,y+1,width-2,height-2,0xFEFEFE,COL_PADDING);
|
||||
PutPixel(x+width-1, y+1, COL_PADDING);
|
||||
if (color!=-1) DrawFilledBar(x+2, y+2, width-3, height-3);
|
||||
IF (id<>0) DefineButton(x+1,y+1,width-2,height-2,id+BT_HIDE,0xEFEBEF);
|
||||
WriteText(-strlen(text)*6+width/2+x+1,height/2-3+y,0x80,sc.work_text,text);
|
||||
}
|
||||
|
||||
void DrawFilledBar(dword x, y, w, h)
|
||||
{
|
||||
int i, fill_h;
|
||||
if (h <= 14) fill_h = h; else fill_h = 14;
|
||||
for (i=0; i<fill_h; i++) DrawBar(x, y+i, w, 1, col_palette[14-i]);
|
||||
DrawBar(x, y+i, w, h-fill_h, col_palette[14-i]);
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
#ifdef LANG_RUS
|
||||
?define WINDOW_TITLE_PROPERTIES "‘¢®©á⢠"
|
||||
?define BTN_CLOSE "‡ ªàëâì"
|
||||
?define PR_T_NAME "ˆ¬ï:"
|
||||
?define PR_T_DEST "<EFBFBD> ᯮ«®¦¥¨¥:"
|
||||
?define PR_T_SIZE "<EFBFBD> §¬¥à:"
|
||||
?define SET_3 "‘®§¤ :"
|
||||
?define SET_4 "Žâªàëâ:"
|
||||
?define SET_5 "ˆ§¬¥¥:"
|
||||
?define SET_6 "” ©«®¢: "
|
||||
?define SET_7 " <20> ¯®ª: "
|
||||
?define PR_T_CONTAINS "‘®¤¥à¦¨â: "
|
||||
?define FLAGS " €ââਡãâë "
|
||||
?define PR_T_HIDDEN "‘ªàëâë©"
|
||||
?define PR_T_SYSTEM "‘¨á⥬ë©"
|
||||
?define PR_T_ONLY_READ "’®«ìª® ç⥨¥"
|
||||
#else
|
||||
?define WINDOW_TITLE_PROPERTIES "Properties"
|
||||
?define BTN_CLOSE "Close"
|
||||
?define PR_T_NAME "Name:"
|
||||
?define PR_T_DEST "Destination:"
|
||||
?define PR_T_SIZE "Size:"
|
||||
?define SET_3 "Created:"
|
||||
?define SET_4 "Opened:"
|
||||
?define SET_5 "Modified:"
|
||||
?define SET_6 "Files: "
|
||||
?define SET_7 " Folders: "
|
||||
?define PR_T_CONTAINS "Contains: "
|
||||
?define FLAGS " Attributes "
|
||||
?define PR_T_HIDDEN "Hidden"
|
||||
?define PR_T_SYSTEM "System"
|
||||
?define PR_T_ONLY_READ "Read-only"
|
||||
#endif
|
||||
|
||||
dword mouse_ddd2;
|
||||
char path_to_file[4096]="\0";
|
||||
char file_name2[4096]="\0";
|
||||
edit_box file_name_ed = {195,50,25,0xffffff,0x94AECE,0x000000,0xffffff,2,4098,#file_name2,#mouse_ddd2, 1000000000000000b,2,2};
|
||||
edit_box path_to_file_ed = {145,100,46,0xffffff,0x94AECE,0x000000,0xffffff,2,4098,#path_to_file,#mouse_ddd2, 1000000000000000b,2,2};
|
||||
frame flags_frame = { 0, 280, 10, 83, 151, 0x000111, 0xFFFfff, 1, FLAGS, 0, 0, 6, 0x000111, 0xCCCccc };
|
||||
|
||||
int file_count, dir_count, size_dir;
|
||||
char folder_info[200];
|
||||
BDVK file_info_general;
|
||||
BDVK file_info_dirsize;
|
||||
|
||||
byte readonly, hidden, system;
|
||||
|
||||
void properties_dialog()
|
||||
{
|
||||
byte id;
|
||||
byte key;
|
||||
dword file_name_off;
|
||||
dword element_size;
|
||||
dword selected_offset2;
|
||||
char element_size_label[32];
|
||||
proc_info settings_form;
|
||||
|
||||
IF (active_properties) ExitProcess();
|
||||
active_properties=1;
|
||||
|
||||
SetEventMask(0x27);
|
||||
loop() switch(WaitEvent())
|
||||
{
|
||||
case evButton:
|
||||
id=GetButtonID();
|
||||
IF (id==1) || (id==10)
|
||||
{
|
||||
active_properties=0;
|
||||
ExitProcess();
|
||||
}
|
||||
break;
|
||||
|
||||
case evMouse:
|
||||
break;
|
||||
|
||||
case evKey:
|
||||
key = GetKey();
|
||||
IF (key==27)
|
||||
{
|
||||
active_properties=0;
|
||||
ExitProcess();
|
||||
}
|
||||
EAX=key<<8;
|
||||
break;
|
||||
|
||||
case evReDraw:
|
||||
DefineAndDrawWindow(Form.left + 150,150,270,285+GetSkinHeight(),0x34,sc.work,WINDOW_TITLE_PROPERTIES);
|
||||
GetProcessInfo(#settings_form, SelfInfo);
|
||||
DrawFlatButton(settings_form.cwidth - 70 - 13, settings_form.cheight - 34, 70, 22, 10, 0xE4DFE1, BTN_CLOSE);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue