Fix OpenDialog filter (VERY big thanks to IgorA), rename libimg_lib.h to libimg.h and libio_lib.h to libio.h, Calypte uses string collection

git-svn-id: svn://kolibrios.org@7049 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2017-10-04 22:59:57 +00:00
parent 478054d8c2
commit 9be11fb14a
18 changed files with 172 additions and 151 deletions

View File

@ -1,13 +1,12 @@
//Calypte 0.35 - Leency
//Calypte 0.15 - Punk Joker
#define MEMSIZE 1024*100
#define MEMSIZE 1024*200
#ifndef AUTOBUILD
#include "lang.h--"
#endif
//===================================================//
// //
// LIB //
@ -19,26 +18,25 @@
#include "../lib/gui.h"
#include "../lib/list_box.h"
#include "../lib/menu.h"
//#include "../lib/collection.h"
#include "../lib/collection.h"
#include "../lib/obj/iconv.h"
#include "../lib/obj/box_lib.h"
#include "../lib/obj/libio_lib.h" //TO CHECK: why opendial is a peace of shit!
#include "../lib/obj/libio.h"
#include "../lib/obj/proc_lib.h"
//#include "../lib/obj/libini.h"
#include "../lib/patterns/simple_open_dialog.h"
char default_dir[] = "/rd/1";
od_filter filter2 = { "TXT",0};
//===================================================//
// //
// DATA //
// //
//===================================================//
char default_dir[] = "/rd/1";
od_filter filter2 = { 8, "TXT\0\0" };
/*========= MENU ==========*/
?define MENU1 "File"
?define MENU2 "Encoding"
@ -89,7 +87,7 @@ int menu_encoding_x = NULL;
int menu_reopen_x = NULL;
/*======== MENU END ==========*/
#define TITLE "Calypte v0.3"
#define TITLE "Calypte v0.37"
char win_title[4096] = TITLE;
#define TOPPANELH 23
@ -107,12 +105,11 @@ dword old_width,old_height;
dword bufpointer;
dword bufsize;
dword draw_sruct;
scroll_bar scroll_v = { SCROLL_SIZE,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_h = { SCROLL_SIZE,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};
//collection s;
collection s;
//===================================================//
// //
@ -120,22 +117,27 @@ scroll_bar scroll_h = { SCROLL_SIZE,200,398,44,0,2,115,15,0,0xeeeeee,0xBBBbbb,0x
// //
//===================================================//
void InitDlls()
{
load_dll(boxlib, #box_lib_init, 0);
load_dll(libio, #libio_init, 1);
load_dll(iconv_lib, #iconv_open, 0);
load_dll(Proc_lib, #OpenDialog_init,0);
OpenDialog_init stdcall (#o_dialog);
}
void main()
{
int id;
InitDlls();
load_dll(boxlib, #box_lib_init, 0);
load_dll(libio, #libio_init, 1);
//load_dll(libini, #lib_init, 1);
load_dll(iconv_lib, #iconv_open, 0);
load_dll(Proc_lib, #OpenDialog_init,0);
OpenDialog_init stdcall (#o_dialog);
if (param)
{
draw_window();
OpenFile(#param);
Prepare();
DrawText();
}
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()
{
switch(WaitEvent())
@ -171,80 +173,13 @@ void main()
break;
case evReDraw:
if (menu.list.cur_y) {
if (menu.list.cur_y == FILE_SUBMENU_ID_OPEN) EventOpenFile();
if (menu.list.cur_y == FILE_SUBMENU_ID_CLOSE) EventCloseFile();
if (menu.list.cur_y == FILE_SUBMENU_ID_PROPERTIES) EventShowFileProperties();
if (menu.list.cur_y == FILE_SUBMENU_ID_EXIT) ExitProcess();
if (menu.list.cur_y > MENU_ID_ENCODING) && (menu.list.cur_y < MENU_ID_ENCODING + 10)
EventChangeEncoding(menu.list.cur_y - MENU_ID_ENCODING);
if (menu.list.cur_y == FILE_SUBMENU_ID_TINYPAD) ReopenFileIn("/sys/tinypad");
if (menu.list.cur_y == FILE_SUBMENU_ID_TEXTEDIT) ReopenFileIn("/sys/develop/t_edit");
if (menu.list.cur_y == FILE_SUBMENU_ID_TEXTREAD) ReopenFileIn("/sys/txtread");
if (menu.list.cur_y == FILE_SUBMENU_ID_WEBVIEW) ReopenFileIn("/sys/network/webview");
if (menu.list.cur_y == FILE_SUBMENU_ID_FB2READ) ReopenFileIn("/sys/fb2read");
if (menu.list.cur_y == FILE_SUBMENU_ID_HEXVIEW) ReopenFileIn("/sys/develop/heed");
menu.list.cur_y = 0;
};
if (menu.list.cur_y) EventMenuClick();
draw_window();
break;
}
}
}
void ReopenFileIn(dword _app)
{
RunProgram(_app, #param);
}
void EventShowMenu(dword _menu_item_x, _menu_list, _id, _selected)
{
menu.selected = _selected;
menu.show(
Form.left+5 + _menu_item_x,
Form.top+skin_height + TOPPANELH,
140,
_menu_list,
_id);
}
void EventOpenFile()
{
OpenDialog_start stdcall (#o_dialog);
if (!o_dialog.status) return;
OpenFile(#openfile_path);
Prepare();
draw_window();
}
void EventCloseFile()
{
if (!bufpointer) return;
strcpy(#win_title, TITLE);
FreeBuf();
draw_window();
}
void EventShowFileProperties()
{
char ss_param[4096];
if (!bufpointer) return;
sprintf(#ss_param, "-p %s", #param);
RunProgram("/sys/File managers/Eolite", #ss_param);
}
void EventChangeEncoding(dword id)
{
encoding = id;
OpenFile(#openfile_path);
Prepare();
draw_window();
}
int DrawMenuButton(dword x,y,id,text)
{
int textlen = strlen(text)*8;
@ -257,7 +192,7 @@ int DrawMenuButton(dword x,y,id,text)
void draw_window()
{
system.color.get();
DefineAndDrawWindow(GetScreenWidth()-WIN_W/2,GetScreenHeight()-WIN_H/2,WIN_W,WIN_H,0x73,0xFFFFFF,#win_title,0);
DefineAndDrawWindow(screen.width-WIN_W/2,screen.height-WIN_H/2,WIN_W,WIN_H,0x73,0xFFFFFF,#win_title,0);
GetProcessInfo(#Form, SelfInfo);
DrawBar(0, 0, Form.cwidth, TOPPANELH-1, system.color.work);
DrawBar(0, TOPPANELH-1, Form.cwidth, 1, system.color.work_dark);
@ -298,23 +233,12 @@ void OpenFile(dword _path)
if (ReadFile(0, bufsize, bufpointer, #param) != 0) {
bufpointer = 0;
notify("'Error opening file'-E");
return;
}
}
if (encoding!=CH_CP866) ChangeCharset(charsets[encoding], "CP866", bufpointer);
}
void FreeBuf()
{
int i;
if (!bufpointer) return;
for (i=0; i<rows.count; i++)
{
mem_Free(DSDWORD[i*4+draw_sruct]);
}
draw_sruct = mem_Free(draw_sruct);
bufpointer = mem_Free(bufpointer);
}
enum {
PARSE_CALCULATE_ROWS_COUNT,
PARSE_DRAW_PREPARE,
@ -342,20 +266,12 @@ void Parse(int mode)
}
if (len_str<=rows.column_max)
{
if (mode==PARSE_DRAW_PREPARE)
{
ESDWORD[sub_pos*4+draw_sruct] = mem_Alloc(len_str+1);
strlcpy(DSDWORD[sub_pos*4+draw_sruct], bufpointer+pos, len_str); //-1 to do not show \n symbol
}
if (mode==PARSE_DRAW_PREPARE) s.addn(bufpointer+pos, len_str);
pos += len_str+1;
}
else
{
if (mode==PARSE_DRAW_PREPARE)
{
ESDWORD[sub_pos*4+draw_sruct] = mem_Alloc(len_str+1);
strlcpy(DSDWORD[sub_pos*4+draw_sruct], bufpointer+pos, rows.column_max);
}
if (mode==PARSE_DRAW_PREPARE) s.addn(bufpointer+pos, rows.column_max);
pos += rows.column_max;
}
sub_pos++;
@ -366,10 +282,7 @@ void Parse(int mode)
if (mode == PARSE_CALCULATE_ROWS_COUNT)
{
rows.count = sub_pos;
draw_sruct = mem_Free(draw_sruct);
draw_sruct = mem_Alloc(rows.count*4);
Parse(PARSE_DRAW_PREPARE);
}
}
@ -392,7 +305,7 @@ void DrawText()
if (bufpointer) for (i=0; i<top; i++)
{
DrawBar(0, i*rows.item_h+TOPPANELH, rows.w, rows.item_h, 0xFFFFFF);
WriteText(2, i*rows.item_h+TOPPANELH, 0x90, 0x000000, DSDWORD[i+rows.first*4+draw_sruct]);
WriteText(2, i*rows.item_h+TOPPANELH, 0x90, 0x000000, s.get(i+rows.first));
}
DrawBar(0, i*rows.item_h+rows.y, rows.w, -i*rows.item_h + rows.h, 0xFFFfff);
DrawVerticalScroll();
@ -410,4 +323,84 @@ void DrawVerticalScroll()
scrollbar_v_draw(#scroll_v);
}
//===================================================//
// //
// EVENTS //
// //
//===================================================//
void EventMenuClick()
{
switch(menu.list.cur_y)
{
//File
case FILE_SUBMENU_ID_OPEN: EventOpenFile(); break;
case FILE_SUBMENU_ID_CLOSE: EventCloseFile(); break;
case FILE_SUBMENU_ID_PROPERTIES: EventShowFileProperties(); break;
case FILE_SUBMENU_ID_EXIT: ExitProcess(); break;
//Encoding
case MENU_ID_ENCODING...MENU_ID_ENCODING+9: EventChangeEncoding(menu.list.cur_y-MENU_ID_ENCODING); break;
//Reopen
case FILE_SUBMENU_ID_TINYPAD: EventOpenFileInAnotherProgram("/sys/tinypad"); break;
case FILE_SUBMENU_ID_TEXTEDIT: EventOpenFileInAnotherProgram("/sys/develop/t_edit"); break;
case FILE_SUBMENU_ID_TEXTREAD: EventOpenFileInAnotherProgram("/sys/txtread"); break;
case FILE_SUBMENU_ID_WEBVIEW: EventOpenFileInAnotherProgram("/sys/network/webview"); break;
case FILE_SUBMENU_ID_FB2READ: EventOpenFileInAnotherProgram("/sys/fb2read"); break;
case FILE_SUBMENU_ID_HEXVIEW: EventOpenFileInAnotherProgram("/sys/develop/heed"); break;
}
menu.list.cur_y = 0;
}
void EventShowMenu(dword _menu_item_x, _menu_list, _id, _selected)
{
menu.selected = _selected;
menu.show(
Form.left+5 + _menu_item_x,
Form.top+skin_height + TOPPANELH,
140,
_menu_list,
_id);
}
void EventOpenFile()
{
OpenDialog_start stdcall (#o_dialog);
if (!o_dialog.status) return;
OpenFile(#openfile_path);
Prepare();
draw_window();
}
void EventCloseFile()
{
if (!bufpointer) return;
s.drop();
bufpointer = mem_Free(bufpointer);
strcpy(#win_title, TITLE);
draw_window();
}
void EventShowFileProperties()
{
char ss_param[4096];
if (!bufpointer) return;
sprintf(#ss_param, "-p %s", #param);
RunProgram("/sys/File managers/Eolite", #ss_param);
}
void EventChangeEncoding(dword id)
{
encoding = id;
OpenFile(#openfile_path);
Prepare();
draw_window();
}
void EventOpenFileInAnotherProgram(dword _app)
{
RunProgram(_app, #param);
}
stop:

View File

@ -19,8 +19,8 @@
//*.obj libraries
#include "..\lib\obj\box_lib.h"
#include "..\lib\obj\libio_lib.h"
#include "..\lib\obj\libimg_lib.h"
#include "..\lib\obj\libio.h"
#include "..\lib\obj\libimg.h"
#include "..\lib\obj\http.h"
#include "..\lib\obj\iconv.h"
//useful patterns

View File

@ -13,7 +13,7 @@
#include "../lib/gui.h"
#include "../lib/list_box.h"
#include "../lib/obj/box_lib.h"
#include "../lib/obj/libio_lib.h"
#include "../lib/obj/libio.h"
#include "../lib/obj/libini.h"
#include "../lib/collection.h"
#include "../lib/io.h"

View File

@ -13,8 +13,9 @@ struct collection
int realloc_size, count;
dword data_start;
dword data_size;
dword element_offset[4090];
dword element_offset[4000];
int add();
int addn();
dword get();
void drop();
void increase_data_size();
@ -34,15 +35,19 @@ void collection::increase_data_size() {
}
int collection::add(dword in) {
if (count >= 4090) return 0;
if (element_offset[count]+strlen(in)+2 > data_size) {
return addn(in, strlen(in));
}
int collection::addn(dword in, len) {
if (count >= 4000) return 0;
if (element_offset[count]+len+2 > data_size) {
increase_data_size();
add(in);
return;
addn(in, len);
return 1;
}
strcpy(data_start+element_offset[count], in);
strncpy(data_start+element_offset[count], in, len);
count++;
element_offset[count] = element_offset[count-1] + strlen(in) + 1;
element_offset[count] = element_offset[count-1] + len + 1;
return 1;
}

View File

@ -15,7 +15,7 @@
#endif
#ifndef INCLUDE_LIBIO_H
#include "../lib/obj/libio_lib.h"
#include "../lib/obj/libio.h"
#endif
:byte init_imglib_check;

View File

@ -2,7 +2,7 @@
#define INCLUDE_LIBIMG_LOAD_SKIN_H
#ifndef INCLUDE_LIBIMG_H
#include "../lib/obj/libimg_lib.h"
#include "../lib/obj/libimg.h"
#endif
:struct libimg_image {

View File

@ -1,15 +1,17 @@
struct od_filter
{
dword size;
byte end;
};
{
dword size; //size = len(#ext) + sizeof(dword)
char ext[16];
};
proc_info pr_inf;
char communication_area_name[] = "FFFFFFFF_open_dialog";
char opendir_path[4096];
char opendir_path[3072];
char open_dialog_path[] = "/rd/1/File managers/opendial";
char openfile_path[4096];
char filename_area[256];
char filename_area[1024];
opendialog o_dialog = {
0,

View File

@ -233,6 +233,18 @@ inline fastcall int strlcpy(dword ESI, EDI, EBX)
return 0;
}
:void strncpy(dword dst, src, len)
{
while (len)
{
ESBYTE[dst] = ESBYTE[src];
dst++;
src++;
len--;
}
ESBYTE[dst]=0;
}
/*
inline fastcall void strtrim( ESI)
{
@ -889,6 +901,15 @@ inline signed strcoll(dword text1,text2)
return 0;
}
replace_char(dword in_str, char from_char, to_char, int length) {
int i;
for (i=0; i<length; i++) {
if (ESBYTE[in_str+i] == from_char) ESBYTE[in_str+i] = to_char;
}
ESBYTE[in_str+length]=0;
}
#define strnmov strmovn
#define stricmp strcmpi
#define strcmpn strncmp

View File

@ -16,8 +16,8 @@
//*.obj libraries
#include "../lib/obj/box_lib.h"
#include "../lib/obj/network.h"
#include "../lib/obj/libio_lib.h"
#include "../lib/obj/libimg_lib.h"
#include "../lib/obj/libio.h"
#include "../lib/obj/libimg.h"
#include "../lib/obj/netcode.h"
#include "../lib/obj/iconv.h"
//patternts

View File

@ -8,8 +8,8 @@
#include "..\lib\gui.h"
#include "..\lib\random.h"
#include "..\lib\obj\libio_lib.h"
#include "..\lib\obj\libimg_lib.h"
#include "..\lib\obj\libio.h"
#include "..\lib\obj\libimg.h"
#include "..\lib\patterns\libimg_load_skin.h"
proc_info Form;

View File

@ -9,7 +9,7 @@
#include "..\lib\mem.h"
#include "..\lib\file_system.h"
#include "..\lib\gui.h"
#include "..\lib\obj\libio_lib.h"
#include "..\lib\obj\libio.h"
#include "..\lib\obj\box_lib.h"
#include "..\lib\obj\libini.h"
#include "..\lib\patterns\restart_process.h"

View File

@ -10,7 +10,7 @@
#include "..\lib\dll.h"
#include "..\lib\gui.h"
#include "..\lib\obj\libio_lib.h"
#include "..\lib\obj\libio.h"
#include "..\lib\obj\libini.h"
#include "..\lib\obj\box_lib.h"

View File

@ -14,8 +14,8 @@ od_filter filter2 = { "MP3", 0 };
#include "..\lib\gui.h"
#include "..\lib\obj\box_lib.h"
#include "..\lib\obj\libio_lib.h"
#include "..\lib\obj\libimg_lib.h"
#include "..\lib\obj\libio.h"
#include "..\lib\obj\libimg.h"
#include "..\lib\obj\libini.h"
#include "..\lib\patterns\libimg_load_skin.h"

View File

@ -15,8 +15,8 @@
#include "../lib/gui.h"
#include "../lib/obj/box_lib.h"
#include "../lib/obj/libio_lib.h"
#include "../lib/obj/libimg_lib.h"
#include "../lib/obj/libio.h"
#include "../lib/obj/libimg.h"
#include "../lib/obj/libini.h"
#include "../lib/patterns/libimg_load_skin.h"

View File

@ -8,8 +8,8 @@ SOFTWARE CENTER v2.8
#include "..\lib\io.h"
#include "..\lib\gui.h"
#include "..\lib\obj\libio_lib.h"
#include "..\lib\obj\libimg_lib.h"
#include "..\lib\obj\libio.h"
#include "..\lib\obj\libimg.h"
#include "..\lib\obj\libini.h"
#include "..\lib\kfont.h"
#include "..\lib\list_box.h"

View File

@ -15,8 +15,8 @@ Copyright (C) 2008 O.Bogomaz
#include "..\lib\kolibri.h"
#include "..\lib\random.h"
#include "..\lib\obj\libio_lib.h"
#include "..\lib\obj\libimg_lib.h"
#include "..\lib\obj\libio.h"
#include "..\lib\obj\libimg.h"
#include "..\lib\patterns\libimg_load_skin.h"
libimg_image menu;

View File

@ -5,7 +5,7 @@
#include "..\lib\file_system.h"
#include "..\lib\dll.h"
#include "..\lib\obj\libio_lib.h"
#include "..\lib\obj\libio.h"
#include "..\lib\obj\libini.h"
#ifndef AUTOBUILD