Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 3465 → Rev 3466

/programs/cmm/browser/TWB.h
8,7 → 8,7
 
char download_path[]="/rd/1/.download";
char search_path[]="http://nigma.ru/index.php?s=";
char version[]=" Text-based Browser 0.98.2";
char version[]=" Text-based Browser 0.99";
 
 
struct TWebBrowser {
23,13 → 23,11
void DrawPage();
void DrawScroller();
};
TWebBrowser WB1;
 
byte rez, b_text, i_text, u_text, s_text, pre_text, blq_text, li_text,
link, ignor_text, li_tab, first_line_drawed, cur_encoding;
link, ignor_text, li_tab, cur_encoding;
TWebBrowser WB1;
 
 
dword text_colors[300],
text_color_index,
link_color,
37,24 → 35,113
 
int stroka,
stolbec,
tab_len;
tab_len,
anchor_line_num;
 
char anchor[256];
int anchor_line_num;
char line[500],
tag[100],
tagparam[10000],
parametr[1200],
options[4096];
options[4096],
anchor[256];
 
#include "include\history.h"
#include "include\colors.h"
#include "include\unicode_tags.h"
#include "include\img_cache.h"
#include "include\some_code.h"
#include "include\parce_tag.h"
 
//=======================================================================
dword drawbuf;
void DrawBufInit()
{
free(drawbuf);
drawbuf = malloc(WB1.width * WB1.line_h +4 * 4 + 8); //+1 for good luck
ESDWORD[drawbuf] = WB1.width;
ESDWORD[drawbuf+4] = WB1.line_h;
DrawBufFill();
}
void DrawBufFill()
{
int i;
for (i=0; i<WB1.width* WB1.line_h +4 * 4; i+=4) ESDWORD[drawbuf+i+8] = bg_color;
}
void DrawBufBar(dword x, y, w, h, color)
{
int i, j;
for (j=0; j<h; j++)
{
for (i = y+j*WB1.width+x*4; i<y+j*WB1.width+x+w*4 ; i+=4) ESDWORD[drawbuf+i+8] = color;
}
}
 
char shift[]={8,8,4,4};
void DrawBufSkew(dword x, y, w, h)
{
int i, j;
stolbec++;
for (j=0; j<=3; j++)
{
for (i = y+j*WB1.width+x+w+h*4; i>y+j*WB1.width+x+h-12*4 ; i-=4)
ESDWORD[drawbuf+i+8] = ESDWORD[-shift[j]+drawbuf+i+8];
}
}
 
void TextGoDown(int left1, top1, width1)
{
if (!stroka) DrawBar(WB1.left, WB1.top, WB1.width, 5, bg_color); //çàêðàøèâàåì ôîí íàä ïåðâîé ñòðîêîé
stroka++;
if (blq_text) stolbec = 8; else stolbec = 0;
if (li_text) stolbec = li_tab * 5;
if (top1>=WB1.top) && ( top1 < WB1.height+WB1.top-10) && (!anchor)
{
PutPaletteImage(drawbuf+8, WB1.width, WB1.line_h, left1-5, top1, 32,0);
DrawBufFill();
}
}
 
void TWebBrowser::DrawPage()
{
int start_x, start_y, line_length, magrin_left=5;
if (!header)
{
strcpy(#header, #line);
strcat(#header, " -");
strcat(#header, #version);
line = 0;
return;
}
if (stroka >= 0) && (stroka - 2 < lines.visible) && (line) && (!anchor)
{
start_x = stolbec * 6 + left + magrin_left;
start_y = stroka * 10 + top + magrin_left;
line_length = strlen(#line) * 6;
 
if (use_truetype == 1)
{
//line_length = get_length stdcall (#line,-1,16,line_length);
text_out stdcall (#line, #fontlol, 17, text_colors[text_color_index], start_x, start_y-3);
}
else
{
WriteBufText(start_x, 0, 0x88, text_colors[text_color_index], #line, drawbuf);
}
IF (b_text) WriteBufText(start_x+1, 0, 0x88, text_colors[text_color_index], #line, drawbuf);
IF (i_text) DrawBufSkew(start_x, 0, line_length, line_h);
IF (s_text) DrawBufBar(start_x, 4, line_length, 1, text_colors[text_color_index]);
IF (u_text) DrawBufBar(start_x, 8, line_length, 1, text_colors[text_color_index]);
IF (link) {
UnsafeDefineButton(start_x-2, start_y, line_length + 3, 9, blink + BT_HIDE, 0xB5BFC9);
DrawBufBar(start_x, 8, line_length, 1, text_colors[text_color_index]);
}
stolbec += strlen(#line);
}
}
//=======================================================================
 
void TWebBrowser::Scan(int id)
{
if (id >= 400)
138,11 → 225,14
if (!BrowserHistory.GoForward()) return;
OpenPage();
return;
case 052: //Íàæàòà F3
//case 255: //F12
// RunProgram("/rd/1/HTMLv_old", #URL);
// return;
case 052: //F3
if (strcmp(get_URL_part(5),"http:")<>0) RunProgram("/rd/1/tinypad", #URL); else RunProgram("/rd/1/tinypad", #download_path);
return;
case 054: //F5
IF(edit1.flags & 0b10) break;
IF(address_box.flags & 0b10) break;
case REFRESH:
if (GetProcessSlot(downloader_id)<>0)
{
210,7 → 300,6
 
 
char *ABSOLUTE_LINKS[]={ "http:", "mailto:", "ftp:", "/sys/", "/rd/", "/fd/", "/bd/", "/hd/", "/cd/", "/tmp/", 0};
 
//dword TWebBrowser::GetNewUrl(dword CUR_URL, NEW_URL){
void TWebBrowser::GetNewUrl(){
int i, len;
307,13 → 396,13
 
void TWebBrowser::ShowPage()
{
edit1.size = edit1.pos = strlen(#editURL);
edit1.offset=0;
edit_box_draw stdcall(#edit1); //ðèñóåì ñòðîêó àäðåñà
address_box.size = address_box.pos = strlen(#editURL);
address_box.offset=0;
edit_box_draw stdcall(#address_box);
 
if (!filesize)
{
DrawBar(left, top, width+4, height, 0xFFFFFF); //çàêðàøèâàåì âñ¸ äîíèçó
DrawBar(left, top, width+scroll1.size_x+1, height, 0xFFFFFF); //fill all
if (GetProcessSlot(downloader_id)<>0) WriteText(left + 10, top + 18, 0x80, 0, "Loading...");
else
{
343,7 → 432,7
for (j = 400; j < blink + 1; j++;) DeleteButton(j);
blink = 400;
 
b_text = i_text = u_text = s_text = blq_text = first_line_drawed =
b_text = i_text = u_text = s_text = blq_text =
li_text = link = ignor_text = text_color_index = text_colors[0] = li_tab = 0; //îáíóëÿåì òåãè
link_color = 0x0000FF;
bg_color = 0xFFFFFF;
350,6 → 439,7
line = NULL;
strcpy(#page_links,"|");
strcpy(#header, #version);
DrawBufInit();
 
if (pre_text<>2)
{
449,16 → 539,15
if (tag[strlen(#tag)-1]=='/') tag[strlen(#tag)-1]=NULL; //for br/
if (tagparam) && (strlen(#tagparam) < 4000) GetNextParam();
 
if (stolbec + strlen(#line) > lines.column_max)
if (stolbec + strlen(#line) > lines.column_max) //============the same as NEXT_MARK
{
perenos_num = strrchr(#line, ' ');
if (!perenos_num) && (strlen(#line)>lines.column_max) perenos_num=lines.column_max;
strcpy(#temp, #line + perenos_num); //ïåðåíîñ ïî ñëîâàì
line[perenos_num] = 0x00;
if (stroka >= lines.visible) && (lines.first <>0) break 1; //óõîäèì...
if (stroka-1 > lines.visible) && (lines.first <>0) break 1; //óõîäèì...
DrawPage();
strcpy(#line, #temp);
TextGoDown(left + 5, stroka * 10 + top + 5, width - 20); //çàêðàøèâàåì ñëåäóùóþ ñòðîêó
}
DrawPage();
484,10 → 573,9
if (!perenos_num) && (strlen(#line)>lines.column_max) perenos_num=lines.column_max;
strcpy(#temp, #line + perenos_num); //ïåðåíîñ ïî ñëîâàì
line[perenos_num] = 0x00;
if (stroka >= lines.visible) && (lines.first <>0) break 1; //óõîäèì...
if (stroka-1 > lines.visible) && (lines.first <>0) break 1; //óõîäèì...
DrawPage();
strcpy(#line, #temp);
TextGoDown(left + 5, stroka * 10 + top + 5, width - 20); //çàêðàøèâàåì ñëåäóùóþ ñòðîêó
}
}
494,10 → 582,12
}
 
DrawPage(); //ðèñóåò ïîñëåäíþþ ñòðîêó, ïîòîì ýòî íàäî óáðàòü, îïòèìèçèðîâàâ êîä
TextGoDown(left + 5, stroka * 10 + top + 5, width - 20); //çàêðàøèâàåì ñëåäóùóþ ñòðîêó
 
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); //çàêðàøèâàåì âñ¸ äî êîíöà
DrawBar(left, lines.visible * 10 + top + 25, width, -lines.visible * 10 + height - 25, bg_color);
if (stroka * 10 + 5 <= height)
DrawBar(left, stroka * 10 + top + 5, width, -stroka * 10 + height - 5, bg_color); //çàêðàøèâàåì âñ¸ äî êîíöà
if (lines.first == 0) lines.all = stroka;
if (anchor) //åñëè ïîñðåäè òåêñòà ïîÿâèòñÿ íîâûé ÿêîðü - áóäåò áåñêîíå÷íûé öèêë
{
510,53 → 600,6
 
 
 
void TWebBrowser::DrawPage()
{
int start_x, start_y, line_length;
if (!header)
{
strcpy(#header, #line);
strcat(#header, " -");
strcat(#header, #version);
line = 0;
return;
}
if (stroka >= 0) && (stroka - 2 < lines.visible) && (line) && (!anchor)
{
if (!stroka) && (!stolbec)
{
DrawBar(left, top, width-15, 15, bg_color); //first line
first_line_drawed=1;
}
start_x = stolbec * 6 + left + 5;
start_y = stroka * 10 + top + 5;
line_length = strlen(#line) * 6;
 
if (use_truetype == 1)
{
//line_length = get_length stdcall (#line,-1,16,line_length);
text_out stdcall (#line, #fontlol, 17, text_colors[text_color_index], start_x, start_y-3);
}
else
{
WriteText(start_x, start_y, 0x80, text_colors[text_color_index], #line);
IF (b_text) { $add ebx, 1<<16 $int 0x40 }
}
IF (i_text) Skew(start_x, start_y, line_length+6, 10);
IF (s_text) DrawBar(start_x, start_y + 4, line_length, 1, text_colors[text_color_index]);
IF (u_text) DrawBar(start_x, start_y + 8, line_length, 1, text_colors[text_color_index]);
IF (link) {
UnsafeDefineButton(start_x-2, start_y, line_length + 3, 9, blink + BT_HIDE, 0xB5BFC9);
DrawBar(start_x, start_y + 8, line_length, 1, text_colors[text_color_index]);
}
stolbec += strlen(#line);
}
}
 
 
char oldtag[100];
void TWebBrowser::WhatTextStyle(int left1, top1, width1) {
dword hr_color;
600,7 → 643,11
do{
if (!strcmp(#parametr, "link=")) link_color = GetColor(#options);
if (!strcmp(#parametr, "text=")) text_colors[0]=GetColor(#options);
if (!strcmp(#parametr, "bgcolor=")) bg_color=GetColor(#options);
if (!strcmp(#parametr, "bgcolor="))
{
bg_color=GetColor(#options);
DrawBufFill();
}
} while(GetNextParam());
return;
}
701,9 → 748,11
if(!chTag("li")) || (!chTag("dt")) //íàäî ñäåëàòü âëîæåííûå ñïèñêè
{
li_text = rez;
IF(rez == 0) return;
if (rez)
{
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) DrawBufBar(li_tab * 5 * 6 + left1 - 5, line_h/2-3, 2, 2, 0x555555);
}
return;
}
if (!chTag("u")) || (!chTag("ins")) u_text = rez;
719,33 → 768,41
if (!chTag("pre")) pre_text = rez;
if (!chTag("hr"))
{
if (anchor) || (stroka < -1)
{
stroka+=2;
return;
}
if (strcmp(#parametr, "color=") == 0) hr_color = GetColor(#options); else hr_color = 0x999999;
TextGoDown(left1, top1, width1);
TextGoDown(left1, top1 + 10, width1);
if (anchor) return;
IF(strcmp(#parametr, "color=") == 0) hr_color = GetColor(#options);
ELSE hr_color = 0x999999;
IF(stroka > 0) DrawBar(left1, top1 + 14, width1 - 8, 1, hr_color);
DrawBufBar(5, WB1.line_h/2, WB1.width-10, 1, hr_color);
TextGoDown(left1, top1+WB1.line_h, width1);
}
/*
if (!chTag("input"))
{
do{
if (!strcmp(#parametr, "type=")) if ((!strcmp(#options, "radio")) || (!strcmp(#options, "checkbox")))
if (!strcmp(#parametr, "type="))
{
if ((!strcmp(#options, "radio")) || (!strcmp(#options, "checkbox")))
{
if (!anchor) && (stroka > 0) CheckBox(stolbec*6 + left1,top1-2,10,10, 0, "\0", 0x888888, text_colors[text_color_index], 0);
stolbec+=2;
}
if (!strcmp(#parametr, "type=")) if ((!strcmp(#options, "text")) || (!strcmp(#options, "password")))
if ((!strcmp(#options, "text")) || (!strcmp(#options, "password")))
{
if (!anchor) && (stroka > 0) CheckBox(stolbec*6 + left1,top1-2,90,10, 0, "\0", 0x555555, 0, 0);
stolbec+=16;
}
if (!strcmp(#parametr, "type=")) if ((!strcmp(#options, "button")) || (!strcmp(#options, "file")) || (!strcmp(#options, "submit")))
if ((!strcmp(#options, "button")) || (!strcmp(#options, "file")) || (!strcmp(#options, "submit")))
{
if (!anchor) && (stroka > 0) DrawCaptButton(stolbec*6 + left1,top1-2,60,10, 0, 0xCCCccc, 0, "Button");
stolbec+=21;
}
}
} while(GetNextParam());
}
*/
if (!chTag("img"))
{
Images( left1, top1, width1);
767,120 → 824,7
}
 
 
void TextGoDown(int left1, top1, width1)
{
if (!stroka) && (!stolbec) && (!first_line_drawed)
{
DrawBar(WB1.left, WB1.top, WB1.width-15, 15, bg_color); //çàêðàøèâàåì ïåðâóþ ñòðîêó
first_line_drawed=1;
}
stroka++;
if (blq_text) stolbec = 8;
ELSE stolbec = 0;
if (li_text) stolbec = li_tab * 5;
IF(stroka >= 0) && (stroka - 2 < lines.visible) && (!anchor) DrawBar(left1 - 5, top1 + 10, width1 + 5, 10, bg_color);
}
 
 
struct s_image
{
dword *image;
char path[4096];
};
s_image pics[100]; //pics = mem_Alloc( 100*sizeof(s_image) );
int num_of_pics;
 
int GetOrSetPicNum(dword i_path)
{
int i;
for (i=0; i<num_of_pics; i++)
{
if (!strcmp(#pics[i].path, i_path)) return i;
}
num_of_pics++;
return num_of_pics;
}
 
void FreeImgCache()
{
int i;
for (i=0; i<=num_of_pics; i++)
{
img_destroy stdcall (pics[num_of_pics].image);
pics[num_of_pics].path = NULL;
}
num_of_pics=0;
}
 
 
void Images(int left1, top1, width1)
{
dword image;
char img_path[4096], alt[4096];
int w=0, h=0, img_lines_first=0, cur_pic=0;
do{
if (!strcmp(#parametr,"src=")) //íàäî îáúåäèíèòü ñ GetNewUrl()
{
if (downloader_id) strcpy(#img_path, #history_list[history_current-1].Item);
else strcpy(#img_path, BrowserHistory.CurrentUrl()); //äîñòà¸ì àäðåñ òåêóùåé ñòðàíèöû
if (strcmpn(#img_path, "http:", 5)!=0) || (strcmpn(#options, "http:", 5)!=0)
{
img_path[strrchr(#img_path, '/')] = '\0'; //îáðåçàåì å¸ óðë äî ïîñëåäíåãî /
strcat(#img_path, #options);
cur_pic=GetOrSetPicNum(#img_path);
if (!pics[cur_pic].path)
{
pics[cur_pic].image=load_image(#img_path);
strcpy(#pics[cur_pic].path, #img_path);
}
}
}
if (!strcmp(#parametr,"alt="))
{
strcpy(#alt, "[");
strcat(#alt, #options);
strcat(#alt, "]");
}
 
} while(GetNextParam());
if (!pics[cur_pic].image)
{
if (alt) && (link) strcat(#line, #alt);
return;
}
w=DSWORD[pics[cur_pic].image+4];
h=DSWORD[pics[cur_pic].image+8];
if (w>width1) w=width1;
if (stroka==0) DrawBar(WB1.left, WB1.top, WB1.width-15, 15, bg_color); //çàêðàøèâàåì ïåðâóþ ñòðîêó
stroka+=h/10;
if (top1+h<WB1.top) || (top1>WB1.top+WB1.height-10) return; //åñëè ÂѨ èçîáðàæåíèå óøëî ÂÅÐÕ èëè ÂÍÈÇ
if (top1<WB1.top) //åñëè ÷àñòü èçîáðàæåíèÿ ñâåðõó
{
DrawBar(WB1.left, WB1.top, WB1.width-15, 10, bg_color); //çàêðàøèâàåì ïåðâóþ ñòðîêó
img_lines_first=WB1.top-top1;
h=h-img_lines_first;
top1=WB1.top;
}
if (top1>WB1.top+WB1.height-h-15) //åñëè ÷àñòü èçîáðàæåíèÿ ñíèçó
{
h=WB1.top+WB1.height-top1-15;
}
if (h<=0) return;
if (anchor) return;
img_draw stdcall (pics[cur_pic].image,left1-5,top1+10,w, h,0,img_lines_first);
DrawBar(left1+w - 5, top1 + 10, width1-w + 5, h, bg_color);
IF (link) UnsafeDefineButton(left1 - 5, top1+10, w, h, blink + BT_HIDE, 0xB5BFC9);
}
 
 
//ñêðîëë
void TWebBrowser::DrawScroller() //íå îïòèìàëüíàÿ îòðèñîâêà, íî çàòî â îäíîì ìåñòå
{
scroll1.max_area = lines.all;
888,8 → 832,9
scroll1.position = lines.first;
 
scroll1.all_redraw=1;
scroll1.start_x=Form.width-28; //left + width - 15
scroll1.start_x = WB1.left + WB1.width;
scroll1.size_y=WB1.height;
 
scrollbar_v_draw(#scroll1);
}