HTMLv 0.94b: general code update #2

git-svn-id: svn://kolibrios.org@2811 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2012-06-20 19:58:55 +00:00
parent e50cde95f6
commit 424ffe7057
16 changed files with 181 additions and 124 deletions

View File

@ -3,17 +3,17 @@
//Asper, lev, Lrz, Barsuk, Nable.
//home icon - rachel fu, GPL licence
#include "..\lib\kolibri.h--"
#include "..\lib\encoding.h--"
#include "..\lib\file_system.h--"
#include "..\lib\kolibri.h"
#include "..\lib\encoding.h"
#include "..\lib\file_system.h"
#include "img\toolbar_icons.c"
#include "img\URLgoto.txt";
#include "..\lib\mem.h--"
#include "..\lib\libio_lib.h--"
#include "..\lib\libimg_lib.h--"
#include "..\lib\edit_box_lib.h--"
#include "..\lib\dll.h--"
#include "..\lib\scroll_bar\scroll_lib.h--"
#include "..\lib\mem.h"
#include "..\lib\libio_lib.h"
#include "..\lib\libimg_lib.h"
#include "..\lib\edit_box_lib.h"
#include "..\lib\dll.h"
#include "..\lib\scroll_bar\scroll_lib.h"
//ïåðåìåííûå
char URL[4096],
@ -21,12 +21,11 @@ char URL[4096],
page_links[12000],
header[512];
int lines_visible,
lines_all,
lines_first,
lines_column_max,
mouse_dd;
struct lines{
int visible, all, first, column_max;
};
int mouse_dd;
edit_box edit1= {250,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,248,#editURL,#mouse_dd,2,19,19};
scroll_bar scroll1 = { 18,200,398, 44,18,0,115,15,0,0xeeeeee,0xD2CED0,0x555555,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1}; //details in scroll_lib.h--
@ -54,7 +53,7 @@ void main()
else strcpy(#URL, "/sys/index.htm");
strcpy(#editURL, #URL);
OpenPage();
WB1.OpenPage();
SetEventMask(0x27);
loop()
@ -64,9 +63,9 @@ void main()
{
CASE evMouse:
/*scrollbar_v_mouse (#scroll1); //êîí÷åíûé ñêðîëë ïðèòîðìàæèìàåò, èä¸ì "ñâîèì ïóò¸ì"
if (lines_first <> scroll1.position)
if (lines.first <> scroll1.position)
{
lines_first = scroll1.position;
lines.first = scroll1.position;
WB1.ParseHTML(buf, filesize);
//break;
};*/
@ -85,32 +84,32 @@ void main()
IF (m.vert==65535) //ïðîêðóòêà êîë¸ñèêîì
{
IF (lines_first==0) break;
IF (lines_first>3) lines_first-=2; ELSE lines_first=1;
IF (lines.first==0) break;
IF (lines.first>3) lines.first-=2; ELSE lines.first=1;
WB1.Scan(ID1);
break;
}
IF (m.vert==1)
{
IF(lines_visible+lines_first+3>=lines_all) WB1.Scan(181);
IF(lines.visible+lines.first+3>=lines.all) WB1.Scan(181);
ELSE {
lines_first+=2;
lines.first+=2;
WB1.Scan(ID2);
}
break;
}
IF (lines_all<lines_visible) break;
half_scroll_size = WB1.height - 16 * lines_visible / lines_all - 3 /2;
IF (lines.all<lines.visible) break;
half_scroll_size = WB1.height - 16 * lines.visible / lines.all - 3 /2;
if (m.x>=WB1.width-14) && (m.x<=WB1.width+6)
&& (m.y>WB1.top+16) && (m.y<WB1.top+WB1.height-16)
&& (lines_all>lines_visible) while (m.lkm)
&& (lines.all>lines.visible) while (m.lkm)
{
IF (half_scroll_size/2+WB1.top>m.y) || (m.y<0) || (m.y>4000) m.y=half_scroll_size/2+WB1.top; //åñëè êóðñîð íàä îêíîì
btn=lines_first; //ñîõðàíÿåì ñòàðîå êîëè÷åñòâî
lines_first = m.y -half_scroll_size -WB1.top * lines_all / WB1.height;
IF (lines_visible+lines_first>lines_all) lines_first=lines_all-lines_visible;
IF (btn<>lines_first) WB1.ParseHTML(buf, filesize); //÷òîá ëèøíèé ðàç íå ïåðåðèñîâûâàòü
btn=lines.first; //ñîõðàíÿåì ñòàðîå êîëè÷åñòâî
lines.first = m.y -half_scroll_size -WB1.top * lines.all / WB1.height;
IF (lines.visible+lines.first>lines.all) lines.first=lines.all-lines.visible;
IF (btn<>lines.first) WB1.ParseHTML(buf, filesize); //÷òîá ëèøíèé ðàç íå ïåðåðèñîâûâàòü
m.get();
}
@ -146,9 +145,8 @@ void main()
{
if (GetProcessSlot(downloader_id)<>0) break;
downloader_id=0;
lines_first = lines_all = 0;
ReadHtml();
if (filesize) wintodos(buf);
lines.first = lines.all = 0;
WB1.ReadHtml(_WIN);
Draw_Window();
}
}
@ -187,10 +185,10 @@ void Draw_Window()
WB1.top=44;
WB1.width=Form.width-13;
WB1.height=onTop(43,5);
lines_column_max = WB1.width - 30 / 6;
lines_visible = WB1.height - 3 / 10 - 2;
lines.column_max = WB1.width - 30 / 6;
lines.visible = WB1.height - 3 / 10 - 2;
WB1.ShowPage(#URL);
WB1.ShowPage();
}
int onLeft(dword right,left) {return Form.width-right-left;}

View File

@ -5,20 +5,22 @@ dword
buf,
filesize,
blink;
int i;
int i;
char download_path[]="/rd/1/.download";
char search_path[]="http://nigma.ru/index.php?s=";
char version[]=" Text-based Browser 0.94";
char version[]=" Text-based Browser 0.94b";
struct TWebBrowser {
int left, top, width, height;
void DrawScroller();
void Scan(int);
void OpenPage();
void ReadHtml(byte);
void ShowPage();
void ParseHTML(dword, dword);
void Scan(int);
void WhatTextStyle(int left1, top1, width1);
void DrawScroller();
};
TWebBrowser WB1;
@ -64,8 +66,8 @@ void TWebBrowser::Scan(int id)
strcpy(#URL, BrowserHistory.CurrentUrl());
lines_first=lines_all-lines_visible;
ShowPage(#URL);
lines.first=lines.all-lines.visible;
ShowPage();
return;
}
//liner.ru#1
@ -88,18 +90,16 @@ void TWebBrowser::Scan(int id)
return;
}
IF(lines_all < lines_visible) SWITCH(id) //åñëè ìàëî ñòðîê èãíîðèðóåì íåêîòîðûå êíîïêè
IF(lines.all < lines.visible) SWITCH(id) //åñëè ìàëî ñòðîê èãíîðèðóåì íåêîòîðûå êíîïêè
{ CASE 183: CASE 184: CASE 180: CASE 181: return; }
switch (id)
{
case 011: //Ctrk+K
ReadHtml();
koitodos(buf);
ReadHtml(_KOI);
break;
case 021: //Ctrl+U
ReadHtml();
utf8rutodos(buf);
ReadHtml(_UTF);
break;
case BACK:
if (!BrowserHistory.GoBack()) return;
@ -125,7 +125,7 @@ void TWebBrowser::Scan(int id)
Draw_Window();
return;
}
anchor_line_num=lines_first; //âåñ¸ëûé êîñòûëü :Ð
anchor_line_num=lines.first; //âåñ¸ëûé êîñòûëü :Ð
anchor[0]='|';
OpenPage();
return;
@ -151,30 +151,30 @@ void TWebBrowser::Scan(int id)
return;
case ID1: //ìîòàåì ââåðõ
IF(lines_first <= 0) return;
lines_first--;
IF(lines.first <= 0) return;
lines.first--;
break;
case ID2: //ìîòàåì âíèç
IF(lines_visible + lines_first >= lines_all) return;
lines_first++;
IF(lines.visible + lines.first >= lines.all) return;
lines.first++;
break;
case 183: //PgDown
IF(lines_first == lines_all - lines_visible) return;
lines_first += lines_visible + 2;
IF(lines_visible + lines_first > lines_all) lines_first = lines_all - lines_visible;
IF(lines.first == lines.all - lines.visible) return;
lines.first += lines.visible + 2;
IF(lines.visible + lines.first > lines.all) lines.first = lines.all - lines.visible;
BREAK;
case 184: //PgUp
IF(lines_first == 0) RETURN;
lines_first -= lines_visible - 2;
IF(lines_first < 0) lines_first = 0;
IF(lines.first == 0) RETURN;
lines.first -= lines.visible - 2;
IF(lines.first < 0) lines.first = 0;
BREAK;
case 180: //home
IF(lines_first == 0) RETURN;
lines_first = 0;
IF(lines.first == 0) RETURN;
lines.first = 0;
BREAK;
case 181: //end
IF (lines_first == lines_all - lines_visible) RETURN;
lines_first = lines_all - lines_visible;
IF (lines.first == lines.all - lines.visible) RETURN;
lines.first = lines.all - lines.visible;
BREAK;
default:
RETURN;
@ -214,7 +214,7 @@ void GetNewUrl(){
void ReadHtml()
void TWebBrowser::ReadHtml(byte dest)
{
if (!strcmp(get_URL_part(5),"http:")))
file_size stdcall (#download_path);
@ -230,10 +230,14 @@ void ReadHtml()
ReadFile(0, filesize, buf, #download_path);
else
ReadFile(0, filesize, buf, #URL);
if (dest==_WIN) wintodos(buf);
if (dest==_UTF) utf8rutodos(buf);
if (dest==_KOI) koitodos(buf);
}
void OpenPage()
void TWebBrowser::OpenPage()
{
if (GetProcessSlot(downloader_id)<>0) PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal);
KillProcess(downloader_id);
@ -258,14 +262,13 @@ void OpenPage()
Draw_Window();
return;
}
lines_first = lines_all = 0;
ReadHtml();
if (filesize) wintodos(buf);
WB1.ShowPage(#URL);
lines.first = lines.all = 0;
ReadHtml(_WIN);
WB1.ShowPage();
}
void TWebBrowser::ShowPage(dword adress)
void TWebBrowser::ShowPage()
{
edit1.size = edit1.pos = strlen(#editURL);
edit_box_draw stdcall(#edit1); //ðèñóåì ñòðîêó àäðåñà
@ -295,7 +298,7 @@ void TWebBrowser::ParseHTML(dword bword, fsize){
byte ignor_param = 0;
char temp[768];
stroka = -lines_first;
stroka = -lines.first;
stolbec = 0;
for (j = 400; j < blink + 1; j++;) DeleteButton(j);
@ -420,12 +423,12 @@ void TWebBrowser::ParseHTML(dword bword, fsize){
IF(ignor_text) break;
IF(!pre_text) && (bukva == ' ') && (!strcmp(#line + strlen(#line) - 1, " ")) continue;
//
if (stolbec + strlen(#line) >lines_column_max)
if (stolbec + strlen(#line) >lines.column_max)
{
strcpy(#temp, #line + find_symbol(#line, ' ')); //ïåðåíîñ ïî ñëîâàì
line[find_symbol(#line, ' ')] = 0x00;
NEXT_MARK:
IF(stroka - 1 > lines_visible) && (lines_first <>0) break 1; //óõîäèì...
IF(stroka - 1 > lines.visible) && (lines.first <>0) break 1; //óõîäèì...
WhatTextStyle(left + 5, stroka * 10 + top + 5, width - 20); //âûâîä ñòðîêè
TextGoDown(left + 5, stroka * 10 + top + 5, width - 20); //çàêðàøèâàåì ñëåäóùóþ ñòðîêó
strcpy(#line, #temp);
@ -437,16 +440,16 @@ void TWebBrowser::ParseHTML(dword bword, fsize){
if (strcmp(#URL + strlen(#URL) - 4, ".txt")<>0) && (!body_present)
DrawBar(left, top, width-15, 15, bg_color); //çàêðàøèâàåì ïåðâóþ ñòðîêó åñëè êàêîé-òî ðàõèò íå ñîçäàë òåã áîäè
if (lines_visible * 10 + 25 <= height)
DrawBar(left, lines_visible * 10 + top + 25, width - 15, -lines_visible * 10 + height - 25, bg_color);
if (lines.visible * 10 + 25 <= height)
DrawBar(left, lines.visible * 10 + top + 25, width - 15, -lines.visible * 10 + height - 25, bg_color);
if (stroka * 10 + 15 <= height)
DrawBar(left, stroka * 10 + top + 15, width - 15, -stroka * 10 + height - 15, bg_color); //çàêðàøèâàåì âñ¸ äî êîíöà
if (lines_first == 0) lines_all = stroka;
if (lines.first == 0) lines.all = stroka;
if (anchor)
{
anchor='';
lines_first=anchor_line_num;
lines.first=anchor_line_num;
ParseHTML(buf, filesize);
}
@ -536,7 +539,7 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
IF(!chTag("q")) strcat(#line, "\"");
//âûâîä íà ýêðàí
if (stroka >= 0) && (stroka - 2 < lines_visible) && (line) && (!anchor)
if (stroka >= 0) && (stroka - 2 < lines.visible) && (line) && (!anchor)
{
WriteText(stolbec * 6 + left1, top1, 0x80, text_colors[text_color_index], #line, 0); //ìîæåò òóò ðèñîâàòü áåëóþ ñòðîêó?
IF (b_text) { $add ebx, 1<<16 $int 0x40 }
@ -556,7 +559,7 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
{
if (!strcmp(#anchor, #options))
{
anchor_line_num=lines_first+stroka;
anchor_line_num=lines.first+stroka;
}
}
@ -595,7 +598,7 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
_A_MARK:
if (!strcmp(#parametr, "href="))
{
if (stroka - 1 > lines_visible) || (stroka < -2) return;
if (stroka - 1 > lines.visible) || (stroka < -2) return;
if (link == 1) text_color_index--; //åñëè êàêîé-òî äîëáî¸á íå çàêðûë òýã
link = 1;
blink++;
@ -608,7 +611,7 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
{
if (!strcmp(#anchor, #options))
{
anchor_line_num=lines_first+stroka;
anchor_line_num=lines.first+stroka;
}
}
if (tagparam)
@ -626,7 +629,7 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
/////////////////////////
if (!chTag("font"))
{
IF (stroka - 1 > lines_visible) return;
IF (stroka - 1 > lines.visible) return;
COL_MARK:
if (strcmp(#parametr, "color=") == 0) //&& (parametr[1] == '#')
{
@ -689,7 +692,7 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
li_text = rez;
IF(rez == 0) return;
TextGoDown(left1, top1, width1);
IF(stroka > -1) && (stroka - 2 < lines_visible) DrawBar(li_tab * 5 * 6 + left1 - 5, top1 + 12, 2, 2, 0);
IF(stroka > -1) && (stroka - 2 < lines.visible) DrawBar(li_tab * 5 * 6 + left1 - 5, top1 + 12, 2, 2, 0);
return;
}
////////////////////////////
@ -746,7 +749,7 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
top1=WB1.top;
}
if (top1>WB1.top+WB1.height-h-15) //åñëè ÷àñòü èçîáðàæåíèÿ ñíèçó IF (stroka - 2 < lines_visible)
if (top1>WB1.top+WB1.height-h-15) //åñëè ÷àñòü èçîáðàæåíèÿ ñíèçó IF (stroka - 2 < lines.visible)
{
h=WB1.top+WB1.height-top1-15;
}
@ -775,20 +778,9 @@ void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
{
strcpy(#options, #options[find_symbol(#options, '=')]); //ïîèñê â content=
IF (!strcmp(#options,"utf-8")) || (!strcmp(#options,"utf8"))
{
ReadHtml();
utf8rutodos(buf);
}
IF(!strcmp(#options, "koi8-r")) || (!strcmp(#options, "koi8-u"))
{
ReadHtml();
koitodos(buf);
}
IF(!strcmp(#options, "dos")) || (!strcmp(#options, "cp-866"))
{
ReadHtml();
}
if (!strcmp(#options,"utf-8")) || (!strcmp(#options,"utf8")) ReadHtml(_UTF);
if (!strcmp(#options, "koi8-r")) || (!strcmp(#options, "koi8-u")) ReadHtml(_KOI);
if (!strcmp(#options, "dos")) || (!strcmp(#options, "cp-866")) ReadHtml(_DOS);
}
if (tagparam)
{
@ -806,16 +798,16 @@ void TextGoDown(int left1, top1, width1)
IF(blq_text == 1) stolbec = 8;
ELSE stolbec = 0;
IF(li_text == 1) stolbec = li_tab * 5;
IF(stroka >= 0) && (stroka - 2 < lines_visible) && (!anchor) DrawBar(left1 - 5, top1 + 10, width1 + 5, 10, bg_color);
IF(stroka >= 0) && (stroka - 2 < lines.visible) && (!anchor) DrawBar(left1 - 5, top1 + 10, width1 + 5, 10, bg_color);
}
//ñêðîëë
void TWebBrowser::DrawScroller() //íå îïòèìàëüíàÿ îòðèñîâêà, íî çàòî â îäíîì ìåñòå
{
scroll1.max_area = lines_all;
scroll1.cur_area = lines_visible;
scroll1.position = lines_first;
scroll1.max_area = lines.all;
scroll1.cur_area = lines.visible;
scroll1.position = lines.first;
scroll1.all_redraw=1;
scroll1.start_x=Form.width-28; //left + width - 15

View File

@ -1,6 +1,6 @@
..\C--\c-- HTMLv.c--
..\C--\c-- HTMLv.c
del HTMLv
rename HTMLv.com HTMLv
rem ..\C--\kpack HTMLv
del warning.txt
pause
del warning.txt

View File

@ -9,10 +9,10 @@
#define ID1 178
#define ID2 177
#define WINDOWS 0
#define DOS 1
#define KOI 2
#define UTF 3
#define _WIN 0
#define _DOS 1
#define _KOI 2
#define _UTF 3
dword get_URL_part(byte len) {

View File

@ -20,14 +20,15 @@ char program_path[4096];
#define evKey 2
#define evReDraw 1
#define OLD -1
#define true 1
#define false 0
//Button options
#define BT_DEL 0x80000000
#define BT_HIDE 0x40000000
#define BT_NOFRAME 0x20000000
#define OLD -1
#define true 1
#define false 0
//-------------------------------------------------------------------------
struct mouse

View File

@ -0,0 +1,66 @@
#code32 TRUE
inline fastcall dword malloc(dword ECX){
dword size, heap;
#speed
size = ECX;
EAX = 68;
EBX = 11;
$int 0x40;
heap = EAX;
IF (size<=heap)
{
EAX = 68;
EBX = 12;
ECX = size;
$int 0x40;
}
ELSE EAX=-1;
#codesize
}
inline fastcall dword free(dword ECX){
#speed
EAX = 68;
EBX = 13;
$int 0x40;
#codesize
}
inline fastcall dword realloc(dword ECX, EDX){
#speed
EAX = 68;
EBX = 20;
$int 0x40;
#codesize
}
inline fastcall memmov( EDI, ESI, ECX)
{
asm {
MOV EAX, ECX
CMP EDI, ESI
JG L1
JE L2
SAR ECX, 2
JS L2
REP MOVSD
MOV ECX, EAX
AND ECX, 3
REP MOVSB
JMP SHORT L2
L1: LEA ESI, DSDWORD[ ESI+ECX-4]
LEA EDI, DSDWORD[ EDI+ECX-4]
SAR ECX, 2
JS L2
STD
REP MOVSD
MOV ECX, EAX
AND ECX, 3
ADD ESI, 3
ADD EDI, 3
REP MOVSB
CLD
L2:
}
}