From ac0309d8c47b27d8fd13571be3394f722ab6eae0 Mon Sep 17 00:00:00 2001 From: "Kirill Lipatov (Leency)" Date: Tue, 5 May 2020 22:38:26 +0000 Subject: [PATCH] Eskin: if skin file was not defined then no skin set. Default system skin will be used in this case. Probably a bit speedup system boot. TxtRead: autodetect encoding, fix about encoding git-svn-id: svn://kolibrios.org@7872 a494cfbc-eb01-0410-851d-a64ba20cac60 --- data/common/settings/system.ini | 1 - programs/cmm/lib/obj/iconv.h | 4 ++-- programs/cmm/txtread/data.h | 4 ++-- programs/cmm/txtread/ini.h | 2 +- programs/cmm/txtread/search.h | 21 +++++++++++---------- programs/cmm/txtread/txtread.c | 16 ++++++++++++---- programs/system/eskin/trunk/eskin.asm | 2 +- 7 files changed, 29 insertions(+), 21 deletions(-) diff --git a/data/common/settings/system.ini b/data/common/settings/system.ini index 112f5fcec7..51d8c0a647 100644 --- a/data/common/settings/system.ini +++ b/data/common/settings/system.ini @@ -20,6 +20,5 @@ program=/sys/demos/spiral [style] buttons_gradient=1 -skin=/rd1/1/default.skn bg_program=/rd/1/media/kiv bg_param=\T__/rd/1/home.png diff --git a/programs/cmm/lib/obj/iconv.h b/programs/cmm/lib/obj/iconv.h index 410f3bd50b..a5664340de 100644 --- a/programs/cmm/lib/obj/iconv.h +++ b/programs/cmm/lib/obj/iconv.h @@ -16,8 +16,8 @@ $DD 2 dup 0 char aIconv_open[] = "iconv_open"; char aIconv[] = "iconv"; -char charsets[] = "UTF-8\0 KOI8-RU\0 CP1251\0 CP1252\0 ISO8859-5\0CP866"; -enum { CH_UTF8, CH_KOI8, CH_CP1251, CH_CP1252, CH_ISO8859_5, CH_CP866, CH_NULL }; +char charsets[] = "UTF-8\0 KOI8-RU\0 CP1251\0 CP1252\0 ISO8859-5\0CP866 \0AUTO"; +enum { CH_UTF8, CH_KOI8, CH_CP1251, CH_CP1252, CH_ISO8859_5, CH_CP866, CH_AUTO }; dword ChangeCharset(dword from_chs, to_chs, conv_buf) { diff --git a/programs/cmm/txtread/data.h b/programs/cmm/txtread/data.h index 4dd3878f74..75423ff1f3 100644 --- a/programs/cmm/txtread/data.h +++ b/programs/cmm/txtread/data.h @@ -7,7 +7,7 @@ #ifdef LANG_RUS #define INTRO_TEXT "Это простой просмотрщик текста.\nПопробуйте открыть какой-нибудь текстовый файл." -#define VERSION "Text Reader v1.4" +#define VERSION "Text Reader v1.41" #define ABOUT "Идея: Leency, punk_joker Код: Leency, Veliant, KolibriOS Team @@ -38,7 +38,7 @@ char color_scheme_names[] = #else #define INTRO_TEXT "This is a plain Text Reader.\nTry to open some text file." -#define VERSION "Text Reader v1.4" +#define VERSION "Text Reader v1.41" #define ABOUT "Idea: Leency, punk_joker Code: Leency, Veliant, KolibriOS Team diff --git a/programs/cmm/txtread/ini.h b/programs/cmm/txtread/ini.h index 5c03bd42bb..b5c61f9076 100644 --- a/programs/cmm/txtread/ini.h +++ b/programs/cmm/txtread/ini.h @@ -3,7 +3,7 @@ _ini ini = { "/sys/settings/app.ini", "Txtread" }; void LoadIniSettings() { kfont.size.pt = ini.GetInt("FontSize", 14); - encoding = ini.GetInt("Encoding", CH_CP866); + encoding = ini.GetInt("Encoding", CH_AUTO); curcol_scheme = ini.GetInt("ColorScheme", 2); Form.left = ini.GetInt("WinX", 150); Form.top = ini.GetInt("WinY", 50); diff --git a/programs/cmm/txtread/search.h b/programs/cmm/txtread/search.h index c663aad571..40b3f3abbe 100644 --- a/programs/cmm/txtread/search.h +++ b/programs/cmm/txtread/search.h @@ -68,19 +68,20 @@ bool SEARCH::edit_mouse() 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); + char matches[30]; + strcpy(#matches, "Matches: "); + strcat(#matches, itoa(found_count)); + strcat(#matches, " "); + WriteTextWithBg(search_box.left+search_box.width+14+110, search_box.top+3, 0xD0, sc.work_text, #matches, sc.work); } -bool SEARCH::draw(dword _btn_find, _btn_hide) +bool SEARCH::draw(dword _btn_find, _btn_hide, _y) { 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); + DrawBar(0, _y, Form.cwidth, 1, sc.work_graph); + DrawBar(0, _y+1, Form.cwidth, SEARCH_H-1, sc.work); - search_box.top = Form.cheight - SEARCH_H + 6; + search_box.top = _y + 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); @@ -144,10 +145,10 @@ int SEARCH::highlight(dword _color, _bg_color) } } -void draw_bar(dword _x, _y, _w, _h, _color) +: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) + for (i = _y*list.w+_x*4+kfont.raw ; i<_y*list.w+_x+_w*4+kfont.raw ; i+=4) { ESDWORD[i] = _color; } diff --git a/programs/cmm/txtread/txtread.c b/programs/cmm/txtread/txtread.c index bda83dcbb3..ce7045803c 100644 --- a/programs/cmm/txtread/txtread.c +++ b/programs/cmm/txtread/txtread.c @@ -312,7 +312,7 @@ void EventShowCharsetsList() { menu_id = CHANGE_CHARSET; 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\nAUTO"); } void EventShowReopenMenu() @@ -342,7 +342,7 @@ void EventShowInfo() { help_opened = true; DrawBar(list.x, list.y, list.w, list.h, bg_color); WriteText(list.x + 10, list.y + 10, 10000001b, text_color, VERSION); - WriteTextLines(list.x + 10, list.y+40, 10110000b, text_color, ABOUT, 20); + WriteTextLines(list.x + 10, list.y+40, 10010000b, text_color, ABOUT, 20); } void EventChangeCharset(dword id) @@ -417,7 +417,15 @@ void LoadFile(dword f_path) io.buffer_data = INTRO_TEXT; strcpy(#title, "Text Reader"); } - if (encoding!=CH_CP866) ChangeCharset(encoding, "CP866", io.buffer_data); + + // Autodetecting encoding + if (encoding==CH_AUTO) { + if (strstr(io.buffer_data, "\208\190")) ChangeCharset(CH_UTF8, "CP866", io.buffer_data); + else if (chrnum(io.buffer_data, '\246')>5) || (strstr(io.buffer_data, "яЁ")) ChangeCharset(CH_CP1251, "CP866", io.buffer_data); + } else { + if (encoding!=CH_CP866) ChangeCharset(encoding, "CP866", io.buffer_data); + } + list.ClearList(); } @@ -468,7 +476,7 @@ void draw_window() DrawToolbarButton(SHOW_INFO, x.n); colscheme_mx = DrawToolbarButton(COLOR_SCHEME, x.inc(-TOOLBAR_BUTTON_WIDTH - BUTTONS_GAP)); - if (search.draw(BTN_FIND_NEXT+10, BTN_FIND_CLOSE+10)) { + if (search.draw(BTN_FIND_NEXT+10, BTN_FIND_CLOSE+10, Form.cheight - SEARCH_H)) { DrawRectangle3D(search_mx+1, 6, TOOLBAR_ICON_WIDTH-1, TOOLBAR_ICON_HEIGHT-1, 0xCCCccc, 0xF8FCF8); } diff --git a/programs/system/eskin/trunk/eskin.asm b/programs/system/eskin/trunk/eskin.asm index 707731be71..fbbbddf146 100644 --- a/programs/system/eskin/trunk/eskin.asm +++ b/programs/system/eskin/trunk/eskin.asm @@ -1 +1 @@ - use32 org 0x0 db 'MENUET01' ; 8 byte id dd 38 ; required os dd STARTAPP ; program start dd I_END ; program image size dd 0x1000000 ; required amount of memory dd 0x1000000 ; stack heap dd 0x0 dd 0x0 include '../../../proc32.inc' include '../../../macros.inc' include '../../../dll.inc' PATH_MAX equ 255 STARTAPP: ; Initialize memory mcall 68, 11 ; Import libraries stdcall dll.Load,importTable ; Set button style: flat or gradient (3D) invoke ini_get_int, aIni, aSection, aButtonStyle, 0 mov ecx, eax mcall 48, 1 set_bg: invoke ini_get_str, aIni, aSection, aBgProgram, sz_buffer, PATH_MAX, 0 invoke ini_get_str, aIni, aSection, aBgParam, sz_param, PATH_MAX, 0 m2m dword [InfoStructure+8], sz_param ; pointer to the parametrs m2m dword [InfoStructure+21], sz_buffer ; pointer to the file name mcall 70, InfoStructure set_skin: invoke ini_get_str, aIni, aSection, aSkinPath, sz_param, PATH_MAX, 0 mcall 48, 8, sz_param mcall -1 proc RunProgram stdcall, app_path:dword, app_param:dword m2m dword [InfoStructure+8], [app_param] ; pointer to the parametrs m2m dword [InfoStructure+21], [app_path] ; pointer to the file name mcall 70, InfoStructure ret endp importTable: library \ libini, 'libini.obj' import libini, \ ini_get_str ,'ini_get_str', \ ini_get_int ,'ini_get_int' InfoStructure: dd 7 ; subfunction number dd 0 ; position in the file in bytes dd ? ; upper part of the position address dd 0 ; number of bytes to read dd 0 ; pointer to the buffer to write data db 0 dd ? ; pointer to the filename aIni db '/sys/settings/system.ini',0 aSection db 'style',0 aBgProgram db 'bg_program',0 aBgParam db 'bg_param',0 aButtonStyle db 'buttons_gradient',0 aSkinPath db 'skin',0 sz_buffer: rb PATH_MAX sz_param: rb PATH_MAX I_END: ; End of application code and data marker \ No newline at end of file + use32 org 0x0 db 'MENUET01' ; 8 byte id dd 38 ; required os dd STARTAPP ; program start dd I_END ; program image size dd 0x1000000 ; required amount of memory dd 0x1000000 ; stack heap dd 0x0 dd 0x0 include '../../../proc32.inc' include '../../../macros.inc' include '../../../dll.inc' PATH_MAX equ 255 STARTAPP: ; Initialize memory mcall 68, 11 ; Import libraries stdcall dll.Load,importTable ; Set button style: flat or gradient (3D) invoke ini_get_int, aIni, aSection, aButtonStyle, 0 mov ecx, eax mcall 48, 1 set_bg: invoke ini_get_str, aIni, aSection, aBgProgram, sz_buffer, PATH_MAX, 0 invoke ini_get_str, aIni, aSection, aBgParam, sz_param, PATH_MAX, 0 m2m dword [InfoStructure+8], sz_param ; pointer to the parametrs m2m dword [InfoStructure+21], sz_buffer ; pointer to the file name mcall 70, InfoStructure set_skin: invoke ini_get_str, aIni, aSection, aSkinPath, sz_param, PATH_MAX, 0 cmp byte [sz_param], 0 ;no need to set skin it was not specified je @f ;mcall 63, 1, '0' ;debug mcall 48, 8, sz_param @@: mcall -1 proc RunProgram stdcall, app_path:dword, app_param:dword m2m dword [InfoStructure+8], [app_param] ; pointer to the parametrs m2m dword [InfoStructure+21], [app_path] ; pointer to the file name mcall 70, InfoStructure ret endp importTable: library \ libini, 'libini.obj' import libini, \ ini_get_str ,'ini_get_str', \ ini_get_int ,'ini_get_int' InfoStructure: dd 7 ; subfunction number dd 0 ; position in the file in bytes dd ? ; upper part of the position address dd 0 ; number of bytes to read dd 0 ; pointer to the buffer to write data db 0 dd ? ; pointer to the filename aIni db '/sys/settings/system.ini',0 aSection db 'style',0 aBgProgram db 'bg_program',0 aBgParam db 'bg_param',0 aButtonStyle db 'buttons_gradient',0 aSkinPath db 'skin',0 sz_buffer: rb PATH_MAX sz_param: rb PATH_MAX I_END: ; End of application code and data marker \ No newline at end of file