From cb9906f10d6208d30b6c3206f3955bae3f4349f1 Mon Sep 17 00:00:00 2001 From: "Kirill Lipatov (Leency)" Date: Sun, 30 Mar 2014 11:57:13 +0000 Subject: [PATCH] WebView 1.0 Beta 4: fixes, view page source git-svn-id: svn://kolibrios.org@4718 a494cfbc-eb01-0410-851d-a64ba20cac60 --- programs/cmm/TWB/TWB.c | 66 ++++++++++++++----------------- programs/cmm/TWB/history.h | 14 +++++-- programs/cmm/TWB/img_cache.h | 22 ++++------- programs/cmm/TWB/links.h | 14 +++---- programs/cmm/browser/WebView.c | 67 ++++++++++++++++++++++---------- programs/cmm/browser/history.h | 5 ++- programs/cmm/browser/menu_rmb.h | 24 ++++++------ programs/cmm/browser/show_src.h | 69 +++++++++++++++++++++++++++++++++ programs/cmm/example/example.c | 21 ++++++++++ 9 files changed, 209 insertions(+), 93 deletions(-) create mode 100644 programs/cmm/browser/show_src.h diff --git a/programs/cmm/TWB/TWB.c b/programs/cmm/TWB/TWB.c index 27334cb7b9..4214df1c36 100644 --- a/programs/cmm/TWB/TWB.c +++ b/programs/cmm/TWB/TWB.c @@ -17,6 +17,8 @@ struct TWebBrowser { void DrawPage(); void DrawScroller(); void NewLine(); + void Perenos(); + byte end_parsing; } WB1; byte b_text, i_text, u_text, s_text, pre_text, blq_text, li_text, li_tab, @@ -54,13 +56,12 @@ char anchor[256]; #include "..\TWB\table.h" - //======================================================================= void TWebBrowser::DrawPage() { - int start_x, start_y, line_length, magrin_left=5; + int start_x, start_y, line_length, stolbec_len, magrin_left=5; if (!header) { @@ -75,8 +76,9 @@ void TWebBrowser::DrawPage() if (stroka >= 0) && (stroka - 2 < list.visible) && (line) && (!anchor) { start_x = stolbec * 6 + list.x + magrin_left; - start_y = stroka * 10 + list.y + magrin_left; - line_length = strlen(#line) * 6; + start_y = stroka * list.line_h + list.y + magrin_left; + stolbec_len = strlen(#line); + line_length = stolbec_len * 6; WriteBufText(start_x, 0, 0x88, text_colors[text_color_index], #line, buf_data); IF (b_text) WriteBufText(start_x+1, 0, 0x88, text_colors[text_color_index], #line, buf_data); @@ -84,11 +86,11 @@ void TWebBrowser::DrawPage() IF (s_text) DrawBuf.DrawBar(start_x, 4, line_length, 1, text_colors[text_color_index]); IF (u_text) DrawBuf.DrawBar(start_x, 8, line_length, 1, text_colors[text_color_index]); IF (link) { - UnsafeDefineButton(start_x-2, start_y, line_length + 3, 9, PageLinks.count + 400 + BT_HIDE, 0xB5BFC9); + UnsafeDefineButton(start_x-2, start_y-1, line_length + 3, 10, PageLinks.count + 400 + BT_HIDE, 0xB5BFC9); DrawBuf.DrawBar(start_x, 8, line_length, 1, text_colors[text_color_index]); PageLinks.AddText(#line, line_length, list.line_h, UNDERLINE); } - stolbec += strlen(#line); + stolbec += stolbec_len; } } //======================================================================= @@ -121,7 +123,7 @@ void TWebBrowser::Prepare(dword bufpos, in_filesize){ void TWebBrowser::Parse(){ word bukva[2]; - int j, perenos_num; + int j; byte ignor_param; char temp[768]; dword bufpos = bufpointer; @@ -129,6 +131,7 @@ void TWebBrowser::Parse(){ b_text = i_text = u_text = s_text = blq_text = t_html = t_body = li_text = link = ignor_text = text_color_index = text_colors[0] = li_tab = condition_text_val = condition_text_active = 0; //обнуляем теги + end_parsing = false; condition_max = 255; text_align = ALIGN_LEFT; link_color_inactive = 0x0000FF; @@ -148,8 +151,9 @@ void TWebBrowser::Parse(){ if (!strcmp(#URL + strlen(#URL) - 4, ".mht")) ignor_text = 1; } - for ( ; bufpointer+bufsize > bufpos; bufpos++;) + for ( ; (bufpointer+bufsize > bufpos) && (ESBYTE[bufpos]!=0); bufpos++;) { + if (end_parsing) break; bukva = ESBYTE[bufpos]; if (ignor_text) && (bukva!='<') continue; if (condition_text_active) && (condition_text_val != condition_href) && (bukva!='<') continue; @@ -160,7 +164,7 @@ void TWebBrowser::Parse(){ { chrcat(#line, ' '); bukva = temp = NULL; - goto NEXT_MARK; + Perenos(); } case '\9': if (pre_text) //иначе идём на 0x0d @@ -239,17 +243,7 @@ void TWebBrowser::Parse(){ if (tag[strlen(#tag)-1]=='/') tag[strlen(#tag)-1]=NULL; //for br/ if (tagparam) && (strlen(#tagparam) < 4000) GetNextParam(); - if (stolbec + strlen(#line) > list.column_max) //============the same as NEXT_MARK - { - perenos_num = strrchr(#line, ' '); - if (!perenos_num) && (strlen(#line)>list.column_max) perenos_num=list.column_max; - strcpy(#temp, #line + perenos_num); //перенос по словам - line[perenos_num] = 0x00; - if (stroka-1 > list.visible) && (list.first <>0) break 1; //уходим... - DrawPage(); - strcpy(#line, #temp); - NewLine(); //закрашиваем следущую строку - } + if (stolbec + strlen(#line) > list.column_max) Perenos(); DrawPage(); line = NULL; if (tag) SetTextStyle(list.x + 5, stroka * list.line_h + list.y + 5); //обработка тегов @@ -264,22 +258,9 @@ void TWebBrowser::Parse(){ if (!stolbec) && (!line) break; //строка не может начинаться с пробела } if (strlen(#line) list.column_max) - { - NEXT_MARK: - perenos_num = strrchr(#line, ' '); - if (!perenos_num) && (strlen(#line)>list.column_max) perenos_num=list.column_max; - strcpy(#temp, #line + perenos_num); - line[perenos_num] = 0x00; - if (stroka-1 > list.visible) && (list.first <>0) break 1; - DrawPage(); - strcpy(#line, #temp); - NewLine(); - } + if (stolbec + strlen(#line) > list.column_max) Perenos(); } } - DrawPage(); NewLine(); DrawBar(list.x, stroka * list.line_h + list.y + 5, list.w, -stroka * list.line_h + list.h - 5, bg_color); @@ -294,6 +275,19 @@ void TWebBrowser::Parse(){ DrawScroller(); } +void TWebBrowser::Perenos() +{ + int perenos_num; + char new_line_text[4096]; + perenos_num = strrchr(#line, ' '); + if (!perenos_num) && (strlen(#line)>list.column_max) perenos_num=list.column_max; + strcpy(#new_line_text, #line + perenos_num); + line[perenos_num] = 0x00; + if (stroka-1 > list.visible) && (list.first <>0) end_parsing=true; + DrawPage(); + strcpy(#line, #new_line_text); + NewLine(); +} char oldtag[100]; @@ -384,7 +378,7 @@ void TWebBrowser::SetTextStyle(int left1, top1) { link = 1; text_colors[text_color_index] = link_color_inactive; - PageLinks.AddLink(#options, stolbec*6+left1, top1); + PageLinks.AddLink(#options, stolbec*6+left1, top1-2); } if (anchor) && (!strcmp(#parametr, "name=")) { @@ -547,7 +541,7 @@ void TWebBrowser::SetTextStyle(int left1, top1) { if (opened) { NewLine(); - if (stroka > -1) && (stroka - 2 < list.visible) DrawBuf.DrawBar(li_tab * 5 * 6 + left1 - 5, list.line_h/2-3, 2, 2, 0x555555); + if (stroka > -1) && (stroka - 2 < list.visible) DrawBuf.DrawBar(li_tab * 5 * 6 + left1 - 5, list.line_h/2-2, 2, 2, 0x555555); } return; } diff --git a/programs/cmm/TWB/history.h b/programs/cmm/TWB/history.h index aa23cde5eb..916a5dd451 100644 --- a/programs/cmm/TWB/history.h +++ b/programs/cmm/TWB/history.h @@ -1,5 +1,6 @@ struct path_string { -char Item[4096]; + char Item[sizeof(URL)]; + int was_first; }; #define MAX_HISTORY_NUM 40 @@ -10,6 +11,7 @@ struct UrlsHistory { int current; dword CurrentUrl(); dword GetUrl(); + dword GetFirstLine(); void AddUrl(); byte GoBack(); byte GoForward(); @@ -23,6 +25,10 @@ dword UrlsHistory::GetUrl(int id) { return #history_list[id].Item; } +dword UrlsHistory::GetFirstLine(int id) { + return history_list[id].was_first; +} + void UrlsHistory::AddUrl() { int i; if (links_count>0) && (!strcmp(#URL,#history_list[current].Item)) return; @@ -32,11 +38,12 @@ void UrlsHistory::AddUrl() { current/=2; for (i=0; iVisited pages

"); for (i=1; i"); strcat(history_pointer, BrowserHistory.GetUrl(i)); diff --git a/programs/cmm/browser/menu_rmb.h b/programs/cmm/browser/menu_rmb.h index ee540911d3..24e3eb1eac 100644 --- a/programs/cmm/browser/menu_rmb.h +++ b/programs/cmm/browser/menu_rmb.h @@ -1,18 +1,20 @@ //Leency - 2012-2013 char *ITEMS_LIST[]={ -"WIN Ctrl+E",05, -"DOS Ctrl+D",04, -"KOI Ctrl+K",11, -"UTF Ctrl+U",21, +"WIN Ctrl+E",05, +"DOS Ctrl+D",04, +"KOI Ctrl+K",11, +"UTF Ctrl+U",21, #ifdef LANG_RUS -"€б室­ЁЄ бва ­Ёжл F3",52, -"ЋзЁбвЁвм Єни Є авЁ­®Є" ,02, -"€бв®аЁп" ,03, +"Џ®б¬®ваҐвм Ёб室­ЁЄ F3",52, +"ђҐ¤ ЄвЁа®ў вм Ёб室­ЁЄ F4",53, +"ЋзЁбвЁвм Єни Є авЁ­®Є" ,02, +"€бв®аЁп" ,03, #else -"View source F3",52, -"Free image cache" ,09, -"History" ,03, +"View source F3",52, +"Edit source F4",53, +"Free image cache" ,09, +"History" ,03, #endif 0}; @@ -26,7 +28,7 @@ void menu_rmb() menu.first = menu.current = 0; while (ITEMS_LIST[menu.count*2]) menu.count++; - menu.SetSizes(2,2,165,menu.count*19,0,19); + menu.SetSizes(2,2,177,menu.count*19,0,19); SetEventMask(100111b); loop() switch(WaitEvent()) diff --git a/programs/cmm/browser/show_src.h b/programs/cmm/browser/show_src.h new file mode 100644 index 0000000000..8fde215e28 --- /dev/null +++ b/programs/cmm/browser/show_src.h @@ -0,0 +1,69 @@ +//you are butifull, you are butifull +dword ShowSource() +{ + dword new_buf, new_buf_start, i; + byte ww, param, comment; + + if (souce_mode) return; + souce_mode = true; + new_buf_start = new_buf = malloc(bufsize*5); + strcat(new_buf, "
");
+	for (i=bufpointer; i<");
+					new_buf+=20;
+				}
+				else
+				{
+					strcat(new_buf, "<");
+					new_buf+=20;					
+				}
+				break;
+			case '>':
+				if (!param) //fix non-closed quote
+				{
+					param = 1;
+					strcat(new_buf, """);
+					new_buf+=12;					
+				}
+				if (ESBYTE[i-1]=='-') && (ESBYTE[i-2]=='-')
+				{
+					strcat(new_buf, ">");
+					new_buf+=10;
+				}
+				else
+				{
+					strcat(new_buf, ">");
+					new_buf+=10;					
+				}
+				break;
+			case '\"':
+			case '\'':
+				if (param)
+				{
+					param = 0;
+					strcat(new_buf, """);
+					new_buf+=22;
+				}
+				else
+				{
+					param = 1;
+					strcat(new_buf, """);
+					new_buf+=12;
+				}
+				break;
+			default:
+				chrcat(new_buf, ww);
+		}
+	}
+	bufsize = new_buf;
+	free(bufpointer);
+	bufpointer = new_buf_start;
+}
\ No newline at end of file
diff --git a/programs/cmm/example/example.c b/programs/cmm/example/example.c
index 0d52ebf9de..c87a7ff767 100644
--- a/programs/cmm/example/example.c
+++ b/programs/cmm/example/example.c
@@ -1,12 +1,32 @@
 #define MEMSIZE 0x3E80
 #include "..\lib\kolibri.h" 
 #include "..\lib\strings.h" 
+#include "..\lib\mem.h" 
 #include "..\lib\file_system.h"
 
+void str_replace(dword buf_in, what_replace, to_what_replace) {
+	dword start_pos=0;
+	dword buf_from;
+
+	buf_from = malloc(strlen(buf_in));
+	loop() {
+		strcpy(buf_from, buf_in);
+		start_pos = strstr(buf_from, what_replace);
+		if (start_pos == 0) break;
+		strlcpy(buf_in, buf_from, start_pos-buf_from);
+		strcat(buf_in, to_what_replace);
+		start_pos += strlen(what_replace);
+		strcat(buf_in, start_pos);
+	}
+	free(buf_from);
+}
 
 void main()
 {   
 	int id, key;
+	strcpy(#param, " lorem");
+	str_replace(#param, "<", "<");
+	str_replace(#param, ">", ">");
 	
 	loop()
    {
@@ -38,6 +58,7 @@ void draw_window()
 	DefineAndDrawWindow(215,100,250,200,0x34,0xFFFFFF,"Window header");
 	GetProcessInfo(#Form, SelfInfo);
 	WriteText(50,80,0x80,0,"Press Enter");
+	WriteText(10,110,0x80,0,#param);
 }