Rev 4571 | Rev 4643 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4571 | Rev 4636 | ||
---|---|---|---|
1 | //HTML Viewer in C-- |
1 | //HTML Viewer in C-- |
2 | //Copyright 2007-2013 by Veliant & Leency |
2 | //Copyright 2007-2013 by Veliant & Leency |
3 | //Asper, lev, Lrz, Barsuk, Nable... |
3 | //Asper, lev, Lrz, Barsuk, Nable... |
4 | //home icon - rachel fu, GPL licence |
4 | //home icon - rachel fu, GPL licence |
5 | 5 | ||
6 | #ifndef AUTOBUILD |
6 | #ifndef AUTOBUILD |
7 | #include "lang.h--" |
7 | #include "lang.h--" |
8 | #endif |
8 | #endif |
9 | 9 | ||
10 | //libraries |
10 | //libraries |
11 | #define MEMSIZE 0x100000 |
11 | #define MEMSIZE 0x100000 |
12 | #include "..\lib\kolibri.h" |
12 | #include "..\lib\kolibri.h" |
13 | #include "..\lib\strings.h" |
13 | #include "..\lib\strings.h" |
14 | #include "..\lib\figures.h" |
14 | #include "..\lib\figures.h" |
15 | #include "..\lib\encoding.h" |
15 | #include "..\lib\encoding.h" |
16 | #include "..\lib\file_system.h" |
16 | #include "..\lib\file_system.h" |
17 | #include "..\lib\mem.h" |
17 | #include "..\lib\mem.h" |
18 | #include "..\lib\dll.h" |
18 | #include "..\lib\dll.h" |
19 | #include "..\lib\draw_buf.h" |
19 | #include "..\lib\draw_buf.h" |
20 | #include "..\lib\list_box.h" |
20 | #include "..\lib\list_box.h" |
21 | #include "..\lib\cursor.h" |
21 | #include "..\lib\cursor.h" |
22 | 22 | ||
23 | //*.obj libraries |
23 | //*.obj libraries |
24 | #include "..\lib\lib.obj\box_lib.h" |
24 | #include "..\lib\lib.obj\box_lib.h" |
25 | #include "..\lib\lib.obj\libio_lib.h" |
25 | #include "..\lib\lib.obj\libio_lib.h" |
26 | #include "..\lib\lib.obj\libimg_lib.h" |
26 | #include "..\lib\lib.obj\libimg_lib.h" |
27 | #include "..\lib\lib.obj\http.h" |
27 | #include "..\lib\lib.obj\http.h" |
28 | //images |
28 | //images |
29 | #include "img\toolbar_icons.c" |
29 | #include "img\toolbar_icons.c" |
30 | #include "img\URLgoto.txt"; |
30 | #include "img\URLgoto.txt"; |
31 | 31 | ||
32 | #ifdef LANG_RUS |
32 | #ifdef LANG_RUS |
33 | char version[]=" ¥ªáâ®¢ë© ¡à 㧥à 0.99.67"; |
33 | char version[]=" ¥ªáâ®¢ë© ¡à 㧥à 0.99.69"; |
34 | ?define IMAGES_CACHE_CLEARED "íè ª à⨮ª ®ç¨é¥" |
34 | ?define IMAGES_CACHE_CLEARED "íè ª à⨮ª ®ç¨é¥" |
35 | ?define T_LAST_SLIDE "â® ¯®á«¥¤¨© á« ©¤" |
35 | ?define T_LAST_SLIDE "â® ¯®á«¥¤¨© á« ©¤" |
36 | char loading[] = " £à㧪 áâà ¨æë... |
36 | char loading[] = " £à㧪 áâà ¨æë... |
37 | unsigned char page_not_found[] = FROM "html\page_not_found_ru.htm"; |
37 | unsigned char page_not_found[] = FROM "html\page_not_found_ru.htm"; |
38 | char accept_language[]= "Accept-Language: ru\n\0"; |
38 | char accept_language[]= "Accept-Language: ru\n\0"; |
39 | #else |
39 | #else |
40 | char version[]=" Text-based Browser 0.99.67"; |
40 | char version[]=" Text-based Browser 0.99.69"; |
41 | ?define IMAGES_CACHE_CLEARED "Images cache cleared" |
41 | ?define IMAGES_CACHE_CLEARED "Images cache cleared" |
42 | ?define T_LAST_SLIDE "This slide is the last" |
42 | ?define T_LAST_SLIDE "This slide is the last" |
43 | char loading[] = "Loading... |
43 | char loading[] = "Loading... |
44 | unsigned char page_not_found[] = FROM "html\page_not_found_en.htm"; |
44 | unsigned char page_not_found[] = FROM "html\page_not_found_en.htm"; |
45 | char accept_language[]= "Accept-Language: en\n\0"; |
45 | char accept_language[]= "Accept-Language: en\n\0"; |
46 | #endif |
46 | #endif |
47 | - | ||
48 | byte native_http=1; |
- | |
49 | 47 | ||
50 | proc_info Form; |
48 | proc_info Form; |
51 | #define WIN_W 640 |
49 | #define WIN_W 640 |
52 | #define WIN_H 480 |
50 | #define WIN_H 480 |
53 | 51 | ||
54 | char search_path[]="http://nigma.ru/index.php?s="; |
52 | char search_path[]="http://nigma.ru/index.php?s="; |
55 | char str_location[]="location\0"; |
53 | char str_location[]="location\0"; |
56 | int redirected = 0; |
54 | int redirected = 0; |
57 | 55 | ||
58 | char stak[4096]; |
56 | char stak[4096]; |
59 | mouse m; |
57 | mouse m; |
60 | int action_buf; |
58 | int action_buf; |
61 | 59 | ||
62 | dword http_transfer = 0; |
60 | dword http_transfer = 0; |
63 | dword http_buffer; |
61 | dword http_buffer; |
64 | - | ||
65 | int downloader_id; |
- | |
66 | 62 | ||
67 | #include "..\TWB\TWB.c" |
63 | #include "..\TWB\TWB.c" |
- | 64 | #include "menu_rmb.h" |
|
68 | #include "menu_rmb.h" |
65 | #include "history.h" |
69 | 66 | ||
70 | char editURL[sizeof(URL)]; |
67 | char editURL[sizeof(URL)]; |
71 | int mouse_twb; |
68 | int mouse_twb; |
72 | edit_box address_box= {250,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(URL),#editURL,#mouse_twb,2,19,19}; |
69 | edit_box address_box= {250,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(URL),#editURL,#mouse_twb,2,19,19}; |
73 | 70 | ||
74 | #define URL_HISTORY "WebView://history" |
71 | #define URL_HISTORY "WebView://history" |
75 | 72 | ||
76 | enum { BACK=300, FORWARD, REFRESH, HOME, NEWTAB, GOTOURL, SEARCHWEB, INPUT_CH, INPUT_BT, BTN_UP, BTN_DOWN }; |
73 | enum { BACK=300, FORWARD, REFRESH, HOME, NEWTAB, GOTOURL, SEARCHWEB, INPUT_CH, INPUT_BT, BTN_UP, BTN_DOWN }; |
77 | 74 | ||
78 | 75 | ||
79 | void main() |
76 | void main() |
80 | { |
77 | { |
81 | int key, btn; |
78 | int key, btn; |
82 | int half_scroll_size; |
79 | int half_scroll_size; |
83 | int scroll_used=0, show_menu; |
80 | int scroll_used=0, show_menu; |
84 | 81 | ||
85 | mem_Init(); |
82 | mem_Init(); |
86 | CursorPointer.Load(#CursorFile); |
83 | CursorPointer.Load(#CursorFile); |
87 | if (load_dll2(boxlib, #box_lib_init,0)!=0) {notify("System Error: library doesn't exists /rd/1/lib/box_lib.obj"); ExitProcess();} |
84 | if (load_dll2(boxlib, #box_lib_init,0)!=0) {notify("System Error: library doesn't exists /rd/1/lib/box_lib.obj"); ExitProcess();} |
88 | if (load_dll2(libio, #libio_init,1)!=0) notify("Error: library doesn't exists - libio"); |
85 | if (load_dll2(libio, #libio_init,1)!=0) notify("Error: library doesn't exists - libio"); |
89 | if (load_dll2(libimg, #libimg_init,1)!=0) notify("Error: library doesn't exists - libimg"); |
86 | if (load_dll2(libimg, #libimg_init,1)!=0) notify("Error: library doesn't exists - libimg"); |
90 | if (load_dll2(libHTTP, #http_lib_init,1)!=0) notify("Error: library doesn't exists - http"); |
87 | if (load_dll2(libHTTP, #http_lib_init,1)!=0) notify("Error: library doesn't exists - http"); |
91 | 88 | ||
92 | if (!URL) strcpy(#URL, "/sys/index.htm"); |
89 | if (!URL) strcpy(#URL, "/sys/index.htm"); |
93 | Form.width=WIN_W; |
90 | Form.width=WIN_W; |
94 | Form.height=WIN_H; |
91 | Form.height=WIN_H; |
95 | SetElementSizes(); |
92 | SetElementSizes(); |
96 | OpenPage(); |
93 | OpenPage(); |
97 | 94 | ||
98 | SetEventMask(0xa7); |
95 | SetEventMask(0xa7); |
99 | loop() |
96 | loop() |
100 | { |
97 | { |
101 | WaitEventTimeout(2); |
98 | WaitEventTimeout(2); |
102 | switch(EAX & 0xFF) |
99 | switch(EAX & 0xFF) |
103 | { |
100 | { |
104 | CASE evMouse: |
101 | CASE evMouse: |
105 | if (!CheckActiveProcess(Form.ID)) break; |
102 | if (!CheckActiveProcess(Form.ID)) break; |
106 | 103 | //Edit URL |
|
107 | edit_box_mouse stdcall (#address_box); |
104 | edit_box_mouse stdcall (#address_box); |
108 | - | ||
109 | m.get(); |
105 | m.get(); |
- | 106 | //Links hover |
|
110 | if (m.y>WB1.list.y) PageLinks.Hover(m.x, m.y, link_color_inactive, link_color_active, bg_color); |
107 | if (m.y>WB1.list.y) PageLinks.Hover(m.x, m.y, link_color_inactive, link_color_active, bg_color); |
111 | 108 | //Menu |
|
112 | if (m.y>WB1.list.y) && (m.y |
109 | if (m.y>WB1.list.y) && (m.y |
113 | { |
110 | { |
114 | if (m.pkm) |
111 | if (m.pkm) |
115 | { |
112 | { |
116 | show_menu = 1; |
113 | show_menu = 1; |
117 | } |
114 | } |
118 | if (!m.pkm) && (show_menu) |
115 | if (!m.pkm) && (show_menu) |
119 | { |
116 | { |
120 | show_menu = 0; |
117 | show_menu = 0; |
121 | SwitchToAnotherThread(); |
118 | SwitchToAnotherThread(); |
122 | CreateThread(#menu_rmb,#stak+4092); |
119 | CreateThread(#menu_rmb,#stak+4092); |
123 | break; |
120 | break; |
124 | } |
121 | } |
125 | } |
122 | } |
126 | - | ||
- | 123 | //Mouse scroll |
|
127 | if (m.vert) |
124 | if (m.vert) |
128 | { |
125 | { |
129 | if (WB1.list.MouseScroll(m.vert)) WB1.Parse(bufpointer, bufsize); |
126 | if (WB1.list.MouseScroll(m.vert)) WB1.Parse(); |
130 | } |
127 | } |
131 | - | ||
- | 128 | //Drag scroller |
|
132 | if (!m.lkm) scroll_used=0; |
129 | if (!m.lkm) scroll_used=0; |
133 | if (m.x>=scroll_wv.start_x) && (m.x<=scroll_wv.start_x+scroll_wv.size_x) |
130 | if (m.x>=scroll_wv.start_x) && (m.x<=scroll_wv.start_x+scroll_wv.size_x) |
134 | && (m.y>=scroll_wv.start_y+scroll_wv.btn_height) && (-scroll_wv.btn_height+scroll_wv.start_y+scroll_wv.size_y>m.y) |
131 | && (m.y>=scroll_wv.start_y+scroll_wv.btn_height) && (-scroll_wv.btn_height+scroll_wv.start_y+scroll_wv.size_y>m.y) |
135 | && (WB1.list.count>WB1.list.visible) && (m.lkm) |
132 | && (WB1.list.count>WB1.list.visible) && (m.lkm) |
136 | { |
133 | { |
137 | scroll_used=1; |
134 | scroll_used=1; |
138 | } |
135 | } |
139 | - | ||
140 | if (scroll_used) |
136 | if (scroll_used) |
141 | { |
137 | { |
142 | half_scroll_size = WB1.list.h - 16 * WB1.list.visible / WB1.list.count - 3 /2; |
138 | half_scroll_size = WB1.list.h - 16 * WB1.list.visible / WB1.list.count - 3 /2; |
143 | if (half_scroll_size+WB1.list.y>m.y) || (m.y<0) || (m.y>4000) m.y=half_scroll_size+WB1.list.y; |
139 | if (half_scroll_size+WB1.list.y>m.y) || (m.y<0) || (m.y>4000) m.y=half_scroll_size+WB1.list.y; |
144 | btn=WB1.list.first; |
140 | btn=WB1.list.first; |
145 | WB1.list.first = m.y -half_scroll_size -WB1.list.y * WB1.list.count / WB1.list.h; |
141 | WB1.list.first = m.y -half_scroll_size -WB1.list.y * WB1.list.count / WB1.list.h; |
146 | if (WB1.list.visible+WB1.list.first>WB1.list.count) WB1.list.first=WB1.list.count-WB1.list.visible; |
142 | if (WB1.list.visible+WB1.list.first>WB1.list.count) WB1.list.first=WB1.list.count-WB1.list.visible; |
147 | if (btn<>WB1.list.first) WB1.Parse(bufpointer, bufsize); |
143 | if (btn<>WB1.list.first) WB1.Parse(); |
148 | } |
144 | } |
149 | - | ||
150 | break; |
145 | break; |
151 | case evButton: |
146 | case evButton: |
152 | btn=GetButtonID(); |
147 | btn=GetButtonID(); |
153 | if (btn==1) |
- | |
154 | { |
- | |
155 | KillProcess(downloader_id); |
- | |
156 | ExitProcess(); |
148 | if (btn==1) ExitProcess(); |
157 | } |
- | |
158 | ELSE |
- | |
159 | { |
- | |
160 | Scan(btn); |
149 | Scan(btn); |
161 | } |
- | |
162 | break; |
150 | break; |
163 | case evKey: |
151 | case evKey: |
164 | key = GetKey(); |
152 | key = GetKey(); |
165 | 153 | ||
166 | if (address_box.flags & 0b10) SWITCH(key) |
154 | if (address_box.flags & 0b10) SWITCH(key) |
167 | { CASE 52: CASE 53: CASE 54: goto _EDIT_MARK; } |
155 | { CASE 52: CASE 53: CASE 54: goto _EDIT_MARK; } |
168 | 156 | ||
169 | Scan(key); |
157 | Scan(key); |
170 | 158 | ||
171 | _EDIT_MARK: |
159 | _EDIT_MARK: |
172 | if (key<>0x0d) && (key<>183) && (key<>184) {EAX=key<<8; edit_box_key stdcall(#address_box);} |
160 | if (key<>0x0d) && (key<>183) && (key<>184) {EAX=key<<8; edit_box_key stdcall(#address_box);} |
173 | break; |
161 | break; |
174 | case evReDraw: |
162 | case evReDraw: |
175 | if (action_buf) { Scan(action_buf); action_buf=0;} |
163 | if (action_buf) Scan(action_buf); |
176 | Draw_Window(); |
164 | Draw_Window(); |
177 | break; |
165 | break; |
178 | 166 | ||
179 | case evNetwork: |
167 | case evNetwork: |
180 | if (http_transfer > 0) { |
168 | if (http_transfer > 0) { |
181 | http_process stdcall (http_transfer); |
169 | http_process stdcall (http_transfer); |
182 | $push EAX |
170 | $push EAX |
183 | ESI = http_transfer; |
171 | ESI = http_transfer; |
- | 172 | if (o_bufpointer) o_bufpointer = free(o_bufpointer); |
|
184 | bufpointer = ESI.http_msg.content_ptr; |
173 | bufpointer = ESI.http_msg.content_ptr; |
185 | bufsize = ESI.http_msg.content_received; |
174 | bufsize = ESI.http_msg.content_received; |
186 | WB1.Parse(bufpointer, bufsize); |
175 | WB1.Parse(); |
187 | 176 | ||
188 | $pop EAX |
177 | $pop EAX |
189 | if (EAX == 0) { |
178 | if (EAX == 0) { |
190 | ESI = http_transfer; |
179 | ESI = http_transfer; |
191 | // Handle redirects |
180 | // Handle redirects |
192 | if (ESI.http_msg.status >= 300) && (ESI.http_msg.status < 400) |
181 | if (ESI.http_msg.status >= 300) && (ESI.http_msg.status < 400) |
193 | { |
182 | { |
194 | redirected++; |
183 | redirected++; |
195 | if (redirected<=5) |
184 | if (redirected<=5) |
196 | { |
185 | { |
197 | http_find_header_field stdcall (http_transfer, #str_location); |
186 | http_find_header_field stdcall (http_transfer, #str_location); |
198 | if (EAX!=0) { |
187 | if (EAX!=0) { |
199 | ESI = EAX; |
188 | ESI = EAX; |
200 | EDI = #URL; |
189 | EDI = #URL; |
201 | do { |
190 | do { |
202 | $lodsb; |
191 | $lodsb; |
203 | $stosb; |
192 | $stosb; |
204 | } while (AL != 0) && (AL != 13) && (AL != 10)); |
193 | } while (AL != 0) && (AL != 13) && (AL != 10)); |
205 | DSBYTE[EDI-1]='\0'; |
194 | DSBYTE[EDI-1]='\0'; |
206 | } |
195 | } |
207 | } |
196 | } |
208 | else |
197 | else |
209 | { |
198 | { |
210 | //TODO: display error (too many redirects) |
199 | //TODO: display error (too many redirects) |
211 | } |
200 | } |
212 | } |
201 | } |
213 | else |
202 | else |
214 | { |
203 | { |
215 | redirected = 0; |
204 | redirected = 0; |
216 | } |
205 | } |
217 | // Loading the page is complete, free resources |
206 | // Loading the page is complete, free resources |
218 | http_free stdcall (http_transfer); |
207 | http_free stdcall (http_transfer); |
219 | http_transfer=0; |
208 | http_transfer=0; |
220 | if (redirected>0) |
209 | if (redirected>0) |
221 | { |
210 | { |
222 | WB1.GetNewUrl(); |
211 | WB1.GetNewUrl(); |
223 | strcpy(#editURL, #URL); |
212 | strcpy(#editURL, #URL); |
224 | BrowserHistory.current--; |
213 | BrowserHistory.current--; |
225 | OpenPage(); |
214 | OpenPage(); |
226 | } |
215 | } |
227 | else |
216 | else |
228 | { |
217 | { |
229 | Draw_Window(); // stop button => refresh button |
218 | Draw_Window(); // stop button => refresh button |
230 | } |
219 | } |
231 | } |
220 | } |
232 | } |
221 | } |
233 | default: |
- | |
234 | if (downloader_id<>0) |
- | |
235 | { |
- | |
236 | if (GetProcessSlot(downloader_id)<>0) break; |
- | |
237 | downloader_id=0; |
- | |
238 | WB1.list.first = WB1.list.count = 0; |
- | |
239 | WB1.ReadHtml(_WIN); |
- | |
240 | Draw_Window(); |
- | |
241 | } |
- | |
242 | } |
222 | } |
243 | } |
223 | } |
244 | } |
224 | } |
245 | 225 | ||
246 | void SetElementSizes() |
226 | void SetElementSizes() |
247 | { |
227 | { |
248 | address_box.width = Form.width - 266; |
228 | address_box.width = Form.width - 266; |
249 | WB1.list.SetSizes(0, 44, Form.width - 10 - scroll_wv.size_x, Form.cheight - 44, 0, 10); |
229 | WB1.list.SetSizes(0, 44, Form.width - 10 - scroll_wv.size_x, Form.cheight - 44, 0, 10); |
250 | WB1.list.column_max = WB1.list.w - 30 / 6; |
230 | WB1.list.column_max = WB1.list.w - 30 / 6; |
251 | WB1.list.visible = WB1.list.h - 3 / WB1.list.line_h - 2; |
231 | WB1.list.visible = WB1.list.h - 3 / WB1.list.line_h - 2; |
252 | WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, WB1.list.h, WB1.list.line_h); |
232 | WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, WB1.list.h, WB1.list.line_h); |
253 | } |
233 | } |
254 | 234 | ||
255 | 235 | ||
256 | void Draw_Window() |
236 | void Draw_Window() |
257 | { |
237 | { |
258 | int j; |
238 | int j; |
259 | DefineAndDrawWindow(215,100,WIN_W,WIN_H,0x73,0xE4DFE1,0,0); |
239 | DefineAndDrawWindow(215,100,WIN_W,WIN_H,0x73,0xE4DFE1,0,0); |
260 | 240 | ||
261 | GetProcessInfo(#Form, SelfInfo); |
241 | GetProcessInfo(#Form, SelfInfo); |
262 | if (Form.status_window>2) |
242 | if (Form.status_window>2) |
263 | { |
243 | { |
264 | DrawTitle(#header); |
244 | DrawTitle(#header); |
265 | return; |
245 | return; |
266 | } |
246 | } |
267 | if (Form.height<120) MoveSize(OLD,OLD,OLD,120); |
247 | if (Form.height<120) MoveSize(OLD,OLD,OLD,120); |
268 | if (Form.width<280) MoveSize(OLD,OLD,280,OLD); |
248 | if (Form.width<280) MoveSize(OLD,OLD,280,OLD); |
269 | 249 | ||
270 | PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal); |
250 | PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal); |
271 | if (GetProcessSlot(downloader_id)<>0) || (http_transfer > 0) _PutImage(88,10, 24,24, #stop_btn); |
251 | if (http_transfer > 0) _PutImage(88,10, 24,24, #stop_btn); |
272 | 252 | ||
273 | DrawBar(200,0,Form.cwidth-200,43,0xE4DFE1); |
253 | DrawBar(200,0,Form.cwidth-200,43,0xE4DFE1); |
274 | DrawBar(0,42,Form.cwidth,1,0xE2DBDC); |
254 | DrawBar(0,42,Form.cwidth,1,0xE2DBDC); |
275 | DrawBar(0,43,Form.cwidth,1,0xD2CED0); |
255 | DrawBar(0,43,Form.cwidth,1,0xD2CED0); |
276 | for (j=0; j<5; j++) DefineButton(j*37+11, 7, 29, 29, 300+j+BT_HIDE, 0xE4DFE1); |
256 | for (j=0; j<5; j++) DefineButton(j*37+11, 7, 29, 29, 300+j+BT_HIDE, 0xE4DFE1); |
277 | _PutImage(Form.cwidth-48,14, 40,19, #URLgoto); |
257 | _PutImage(Form.cwidth-48,14, 40,19, #URLgoto); |
278 | DefineButton(Form.cwidth-28,15, 18, 16, GOTOURL+BT_HIDE, 0xE4DFE1); |
258 | DefineButton(Form.cwidth-28,15, 18, 16, GOTOURL+BT_HIDE, 0xE4DFE1); |
279 | DefineButton(Form.cwidth-47,15, 17, 16, SEARCHWEB+BT_HIDE, 0xE4DFE1); |
259 | DefineButton(Form.cwidth-47,15, 17, 16, SEARCHWEB+BT_HIDE, 0xE4DFE1); |
280 | DrawRectangle(205,14,Form.cwidth-205-49,18,0x94AECE); //around adress bar |
260 | DrawRectangle(205,14,Form.cwidth-205-49,18,0x94AECE); //around adress bar |
281 | DrawRectangle(206,15,Form.cwidth-205-50,16,0xE4ECF3); |
261 | DrawRectangle(206,15,Form.cwidth-205-50,16,0xE4ECF3); |
282 | 262 | ||
283 | SetElementSizes(); |
263 | SetElementSizes(); |
284 | ShowPage(); |
264 | ShowPage(); |
285 | 265 | ||
286 | DefineButton(scroll_wv.start_x+1, scroll_wv.start_y+1, 16, 16, BTN_UP+BT_HIDE, 0xE4DFE1); |
266 | DefineButton(scroll_wv.start_x+1, scroll_wv.start_y+1, 16, 16, BTN_UP+BT_HIDE, 0xE4DFE1); |
287 | DefineButton(scroll_wv.start_x+1, scroll_wv.start_y+scroll_wv.size_y-18, 16, 16, BTN_DOWN+BT_HIDE, 0xE4DFE1); |
267 | DefineButton(scroll_wv.start_x+1, scroll_wv.start_y+scroll_wv.size_y-18, 16, 16, BTN_DOWN+BT_HIDE, 0xE4DFE1); |
288 | } |
268 | } |
289 | 269 | ||
290 | 270 | ||
291 | void Scan(int id) |
271 | void ChangeCharset(byte new_charset) |
292 | { |
272 | { |
- | 273 | BufEncode(new_charset); |
|
- | 274 | WB1.Parse(); |
|
- | 275 | } |
|
- | 276 | ||
- | 277 | void Scan(int id) |
|
- | 278 | { |
|
- | 279 | action_buf=0; |
|
- | 280 | if (id >= 400) |
|
- | 281 | { |
|
- | 282 | ProcessLinks(id); |
|
293 | if (id >= 400) ProcessLinks(id); |
283 | return; |
294 | 284 | } |
|
295 | switch (id) |
285 | switch (id) |
296 | { |
286 | { |
297 | case 011: //Ctrk+K |
287 | case 011: //Ctrk+K |
298 | WB1.ReadHtml(_KOI); |
288 | ChangeCharset(_KOI); |
299 | WB1.Parse(bufpointer, bufsize); |
- | |
300 | return; |
289 | return; |
301 | 290 | ||
302 | case 021: //Ctrl+U |
291 | case 021: //Ctrl+U |
303 | WB1.ReadHtml(_UTF); |
292 | ChangeCharset(_UTF); |
304 | WB1.Parse(bufpointer, bufsize); |
- | |
305 | return; |
293 | return; |
306 | 294 | ||
307 | case 004: //Ctrl+D |
295 | case 004: //Ctrl+D |
308 | WB1.ReadHtml(_DOS); |
296 | ChangeCharset(_DOS); |
309 | WB1.Parse(bufpointer, bufsize); |
- | |
310 | return; |
297 | return; |
311 | 298 | ||
312 | case 005: //Win encoding |
299 | case 005: //Win encoding |
313 | WB1.ReadHtml(_WIN); |
300 | ChangeCharset(_WIN); |
314 | WB1.Parse(bufpointer, bufsize); |
- | |
315 | return; |
301 | return; |
316 | 302 | ||
317 | case 009: //free img cache |
303 | case 009: //free img cache |
318 | ImgCache.Free(); |
304 | ImgCache.Free(); |
319 | notify(IMAGES_CACHE_CLEARED); |
305 | notify(IMAGES_CACHE_CLEARED); |
320 | WB1.Parse(bufpointer, bufsize); |
306 | WB1.Parse(); |
321 | return; |
307 | return; |
322 | 308 | ||
323 | case 003: //history |
309 | case 003: //history |
324 | strcpy(#URL, URL_HISTORY); |
310 | strcpy(#URL, URL_HISTORY); |
325 | OpenPage(); |
311 | OpenPage(); |
326 | return; |
312 | return; |
327 | 313 | ||
328 | case BACK: |
314 | case BACK: |
329 | if (!BrowserHistory.GoBack()) return; |
315 | if (!BrowserHistory.GoBack()) return; |
330 | OpenPage(); |
316 | OpenPage(); |
331 | return; |
317 | return; |
332 | case FORWARD: |
318 | case FORWARD: |
333 | if (!BrowserHistory.GoForward()) return; |
319 | if (!BrowserHistory.GoForward()) return; |
334 | OpenPage(); |
320 | OpenPage(); |
335 | return; |
321 | return; |
336 | case 052: //F3 |
322 | case 052: //F3 |
- | 323 | if (strncmp(#URL,"http:",5)==0) |
|
- | 324 | { |
|
- | 325 | WriteFile(bufsize, bufpointer, "/tmp0/1/webview.tmp"); |
|
337 | if (strncmp(#URL,"http:",5)<>0) RunProgram("/rd/1/tinypad", #URL); |
326 | if (EAX==0) RunProgram("/rd/1/tinypad", "/tmp0/1/webview.tmp"); |
- | 327 | } |
|
- | 328 | else |
|
- | 329 | { |
|
338 | else RunProgram("/rd/1/tinypad", #download_path); |
330 | RunProgram("/rd/1/tinypad", #URL); |
- | 331 | } |
|
339 | return; |
332 | return; |
340 | case 054: //F5 |
333 | case 054: //F5 |
341 | IF(address_box.flags & 0b10) WB1.Parse(bufpointer, bufsize); |
334 | IF(address_box.flags & 0b10) WB1.Parse(); |
342 | return; |
335 | return; |
343 | 336 | ||
344 | case REFRESH: |
337 | case REFRESH: |
345 | if (http_transfer<>0) |
338 | if (http_transfer > 0) StopLoading(); |
346 | { |
- | |
347 | EAX = http_transfer; |
- | |
348 | EAX = EAX.http_msg.content_ptr; // get pointer to data |
- | |
349 | $push EAX // save it on the stack |
- | |
350 | http_free stdcall (http_transfer); // abort connection |
- | |
351 | $pop EAX |
- | |
352 | mem_Free(EAX); // free data |
- | |
353 | http_transfer=0; |
- | |
354 | bufsize = 0; |
- | |
355 | } |
- | |
356 | if (GetProcessSlot(downloader_id)<>0) |
- | |
357 | { |
- | |
358 | KillProcess(downloader_id); |
- | |
359 | pause(20); |
- | |
360 | Draw_Window(); |
- | |
361 | return; |
- | |
362 | } |
- | |
363 | anchor_line_num=WB1.list.first; |
- | |
364 | anchor[0]='|'; |
- | |
365 | OpenPage(); |
339 | else OpenPage(); |
366 | return; |
340 | return; |
367 | case 014: |
341 | case 014: |
368 | case 020: |
342 | case 020: |
369 | case NEWTAB: |
343 | case NEWTAB: |
370 | MoveSize(190,80,OLD,OLD); |
344 | MoveSize(190,80,OLD,OLD); |
371 | RunProgram(#program_path, #URL); |
345 | RunProgram(#program_path, #URL); |
372 | return; |
346 | return; |
373 | 347 | ||
374 | case HOME: |
348 | case HOME: |
375 | strcpy(#editURL, "http://kolibrios.org/"); |
349 | strcpy(#editURL, "http://kolibrios.org/"); |
376 | case GOTOURL: |
350 | case GOTOURL: |
377 | case 0x0D: //enter |
351 | case 0x0D: //enter |
378 | if ((strstr(#editURL,"ttp://")==0) && (editURL[0]!='/')) strcpy(#URL,"http://"); else URL[0] = 0; |
352 | if ((strstr(#editURL,"ttp://")==0) && (editURL[0]!='/')) strcpy(#URL,"http://"); else URL[0] = 0; |
379 | strcat(#URL, #editURL); |
353 | strcat(#URL, #editURL); |
380 | OpenPage(); |
354 | OpenPage(); |
381 | return; |
355 | return; |
382 | case SEARCHWEB: |
356 | case SEARCHWEB: |
383 | strcpy(#URL, #search_path); |
357 | strcpy(#URL, #search_path); |
384 | strcat(#URL, #editURL); |
358 | strcat(#URL, #editURL); |
385 | OpenPage(); |
359 | OpenPage(); |
386 | return; |
360 | return; |
387 | 361 | ||
388 | case 183: //PgDown |
362 | case 183: //PgDown |
389 | if (WB1.list.count < WB1.list.visible) return; |
363 | if (WB1.list.count < WB1.list.visible) return; |
390 | IF(WB1.list.first == WB1.list.count - WB1.list.visible) return; |
364 | IF(WB1.list.first == WB1.list.count - WB1.list.visible) return; |
391 | WB1.list.first += WB1.list.visible + 2; |
365 | WB1.list.first += WB1.list.visible + 2; |
392 | IF(WB1.list.visible + WB1.list.first > WB1.list.count) WB1.list.first = WB1.list.count - WB1.list.visible; |
366 | IF(WB1.list.visible + WB1.list.first > WB1.list.count) WB1.list.first = WB1.list.count - WB1.list.visible; |
393 | WB1.Parse(bufpointer, bufsize); |
367 | WB1.Parse(); |
394 | return; |
368 | return; |
395 | 369 | ||
396 | case 184: //PgUp |
370 | case 184: //PgUp |
397 | if (WB1.list.count < WB1.list.visible) return; |
371 | if (WB1.list.count < WB1.list.visible) return; |
398 | IF(WB1.list.first == 0) return; |
372 | IF(WB1.list.first == 0) return; |
399 | WB1.list.first -= WB1.list.visible - 2; |
373 | WB1.list.first -= WB1.list.visible - 2; |
400 | IF(WB1.list.first < 0) WB1.list.first = 0; |
374 | IF(WB1.list.first < 0) WB1.list.first = 0; |
401 | WB1.Parse(bufpointer, bufsize); |
375 | WB1.Parse(); |
402 | return; |
376 | return; |
403 | 377 | ||
404 | case 178: |
378 | case 178: |
405 | case BTN_UP: |
379 | case BTN_UP: |
406 | if (WB1.list.first <= 0) return; |
380 | if (WB1.list.first <= 0) return; |
407 | WB1.list.first--; |
381 | WB1.list.first--; |
408 | WB1.Parse(bufpointer, bufsize); |
382 | WB1.Parse(); |
409 | return; |
383 | return; |
410 | 384 | ||
411 | case 177: |
385 | case 177: |
412 | case BTN_DOWN: |
386 | case BTN_DOWN: |
413 | if (WB1.list.visible + WB1.list.first >= WB1.list.count) return; |
387 | if (WB1.list.visible + WB1.list.first >= WB1.list.count) return; |
414 | WB1.list.first++; |
388 | WB1.list.first++; |
415 | WB1.Parse(bufpointer, bufsize); |
389 | WB1.Parse(); |
416 | return; |
390 | return; |
417 | 391 | ||
418 | case 180: //home |
392 | case 180: //home |
419 | if (WB1.list.KeyHome()) WB1.Parse(bufpointer, bufsize); |
393 | if (WB1.list.KeyHome()) WB1.Parse(); |
420 | return; |
394 | return; |
421 | 395 | ||
422 | case 181: //end |
396 | case 181: //end |
423 | if (WB1.list.count < WB1.list.visible) return; |
397 | if (WB1.list.count < WB1.list.visible) return; |
424 | if (WB1.list.KeyEnd()) WB1.Parse(bufpointer, bufsize); |
398 | if (WB1.list.KeyEnd()) WB1.Parse(); |
425 | return; |
399 | return; |
426 | } |
400 | } |
427 | } |
401 | } |
428 | 402 | ||
429 | 403 | ||
430 | 404 | ||
431 | void ProcessLinks(int id) |
405 | void ProcessLinks(int id) |
432 | { |
406 | { |
433 | strcpy(#URL, PageLinks.GetURL(id-401)); |
407 | strcpy(#URL, PageLinks.GetURL(id-401)); |
434 | //$1 - Condition Script |
408 | //$1 - Condition Script |
435 | if (URL[0] == '$') |
409 | if (URL[0] == '$') |
436 | { |
410 | { |
437 | if (URL[1]=='-') && (condition_href) condition_href--; |
411 | if (URL[1]=='-') && (condition_href) condition_href--; |
438 | if (URL[1]=='+') |
412 | if (URL[1]=='+') |
439 | { |
413 | { |
440 | if (condition_href |
414 | if (condition_href |
441 | } |
415 | } |
442 | if (URL[1]!='-') && (URL[1]!='+') condition_href = atoi(#URL+1); |
416 | if (URL[1]!='-') && (URL[1]!='+') condition_href = atoi(#URL+1); |
443 | strcpy(#URL, BrowserHistory.CurrentUrl()); |
417 | strcpy(#URL, BrowserHistory.CurrentUrl()); |
444 | ShowPage(); |
418 | ShowPage(); |
445 | return; |
419 | return; |
446 | } |
420 | } |
447 | //#1 |
421 | //#1 |
448 | if (URL[0] == '#') |
422 | if (URL[0] == '#') |
449 | { |
423 | { |
450 | strcpy(#anchor, #URL+strrchr(#URL, '#')); |
424 | strcpy(#anchor, #URL+strrchr(#URL, '#')); |
451 | strcpy(#URL, BrowserHistory.CurrentUrl()); |
425 | strcpy(#URL, BrowserHistory.CurrentUrl()); |
452 | WB1.list.first=WB1.list.count-WB1.list.visible; |
426 | WB1.list.first=WB1.list.count-WB1.list.visible; |
453 | ShowPage(); |
427 | ShowPage(); |
454 | return; |
428 | return; |
455 | } |
429 | } |
456 | //liner.ru#1 |
430 | //liner.ru#1 |
457 | if (strrchr(#URL, '#')!=-1) |
431 | if (strrchr(#URL, '#')!=-1) |
458 | { |
432 | { |
459 | strcpy(#anchor, #URL+strrchr(#URL, '#')); |
433 | strcpy(#anchor, #URL+strrchr(#URL, '#')); |
460 | URL[strrchr(#URL, '#')-1] = 0x00; |
434 | URL[strrchr(#URL, '#')-1] = 0x00; |
461 | } |
435 | } |
462 | 436 | ||
463 | WB1.GetNewUrl(); |
437 | WB1.GetNewUrl(); |
464 | 438 | ||
465 | if (!strcmp(#URL + strlen(#URL) - 4, ".gif")) || (!strcmp(#URL + strlen(#URL) - 4, ".png")) || (!strcmp(#URL + strlen(#URL) - 4, ".jpg")) |
439 | if (!strcmp(#URL + strlen(#URL) - 4, ".gif")) || (!strcmp(#URL + strlen(#URL) - 4, ".png")) || (!strcmp(#URL + strlen(#URL) - 4, ".jpg")) |
466 | { |
440 | { |
467 | //if (strstr(#URL,"http:")) |
441 | //if (strstr(#URL,"http:")) |
468 | RunProgram("/sys/media/kiv", #URL); |
442 | RunProgram("/sys/media/kiv", #URL); |
469 | strcpy(#editURL, BrowserHistory.CurrentUrl()); |
443 | strcpy(#editURL, BrowserHistory.CurrentUrl()); |
470 | strcpy(#URL, BrowserHistory.CurrentUrl()); |
444 | strcpy(#URL, BrowserHistory.CurrentUrl()); |
471 | return; |
445 | return; |
472 | } |
446 | } |
473 | if (!strcmpn(#URL,"mailto:", 7)) |
447 | if (!strcmpn(#URL,"mailto:", 7)) |
474 | { |
448 | { |
475 | notify(#URL); |
449 | notify(#URL); |
476 | strcpy(#editURL, BrowserHistory.CurrentUrl()); |
450 | strcpy(#editURL, BrowserHistory.CurrentUrl()); |
477 | strcpy(#URL, BrowserHistory.CurrentUrl()); |
451 | strcpy(#URL, BrowserHistory.CurrentUrl()); |
478 | return; |
452 | return; |
479 | } |
453 | } |
480 | - | ||
481 | OpenPage(); |
454 | OpenPage(); |
482 | return; |
455 | return; |
483 | } |
456 | } |
- | 457 | ||
- | 458 | void StopLoading() |
|
- | 459 | { |
|
- | 460 | if (http_transfer<>0) |
|
- | 461 | { |
|
- | 462 | EAX = http_transfer; |
|
- | 463 | EAX = EAX.http_msg.content_ptr; // get pointer to data |
|
- | 464 | $push EAX // save it on the stack |
|
- | 465 | http_free stdcall (http_transfer); // abort connection |
|
- | 466 | $pop EAX |
|
- | 467 | mem_Free(EAX); // free data |
|
- | 468 | http_transfer=0; |
|
- | 469 | bufsize = 0; |
|
- | 470 | } |
|
- | 471 | anchor_line_num=WB1.list.first; |
|
- | 472 | anchor[0]='|'; |
|
- | 473 | } |
|
484 | 474 | ||
485 | void OpenPage() |
475 | void OpenPage() |
486 | { |
476 | { |
487 | if (GetProcessSlot(downloader_id)<>0) PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal); |
477 | if (http_transfer<>0) PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal); |
488 | KillProcess(downloader_id); |
478 | StopLoading(); |
489 | strcpy(#editURL, #URL); |
479 | strcpy(#editURL, #URL); |
490 | BrowserHistory.AddUrl(); |
480 | BrowserHistory.AddUrl(); |
491 | strcpy(#header, #version); |
481 | strcpy(#header, #version); |
492 | pre_text =0; |
482 | pre_text =0; |
493 | if (!strncmp(#URL,"http:",5)) |
483 | WB1.list.ClearList(); |
494 | { |
- | |
495 | if (native_http) |
484 | if (strncmp(#URL,"http:",5)==0) |
496 | { |
485 | { |
497 | http_get stdcall (#URL, #accept_language); |
486 | http_get stdcall (#URL, #accept_language); |
498 | http_transfer = EAX; |
487 | http_transfer = EAX; |
- | 488 | cur_encoding = _DEFAULT; |
|
499 | IF (http_transfer < 0) notify("Error from HTTP lib"); |
489 | IF (http_transfer < 0) notify("Error from HTTP lib"); |
- | 490 | Draw_Window(); |
|
- | 491 | return; |
|
500 | } |
492 | } |
501 | else |
493 | else |
502 | { |
494 | { |
503 | KillProcess(downloader_id); |
495 | file_size stdcall (#URL); |
- | 496 | bufsize = EBX; |
|
- | 497 | if (!bufsize) return; |
|
504 | DeleteFile(#download_path); |
498 | mem_Free(bufpointer); |
- | 499 | cur_encoding = _DEFAULT; |
|
505 | downloader_id = RunProgram("/sys/network/downloader", #URL); |
500 | if (o_bufpointer) o_bufpointer = free(o_bufpointer); |
- | 501 | bufpointer = mem_Alloc(bufsize); |
|
506 | IF (downloader_id<0) notify("Error running Downloader. Internet unavilable."); |
502 | ReadFile(0, bufsize, bufpointer, #URL); |
507 | } |
503 | } |
508 | Draw_Window(); |
- | |
509 | return; |
- | |
510 | } |
- | |
511 | WB1.list.first = WB1.list.count =0; |
- | |
512 | WB1.ReadHtml(_WIN); |
- | |
513 | ShowPage(); |
504 | ShowPage(); |
514 | } |
505 | } |
515 | 506 | ||
516 | void ShowPage() |
507 | void ShowPage() |
517 | { |
508 | { |
518 | address_box.size = address_box.pos = strlen(#editURL); |
509 | address_box.size = address_box.pos = strlen(#editURL); |
519 | address_box.offset=0; |
510 | address_box.offset=0; |
520 | edit_box_draw stdcall(#address_box); |
511 | edit_box_draw stdcall(#address_box); |
521 | 512 | ||
522 | if (strcmp(#URL, URL_HISTORY)==0) ShowHistory(); else |
513 | if (strcmp(#URL, URL_HISTORY)==0) ShowHistory(); else |
523 | if (!bufsize) |
514 | if (!bufsize) |
524 | { |
515 | { |
525 | PageLinks.Clear(); |
516 | PageLinks.Clear(); |
526 | if (GetProcessSlot(downloader_id)<>0) |
517 | if (http_transfer<>0) |
- | 518 | { |
|
527 | WB1.Parse(#loading, sizeof(loading)); |
519 | WB1.Prepare(#loading, sizeof(loading)); |
- | 520 | } |
|
528 | else |
521 | else |
529 | WB1.Parse(#page_not_found, sizeof(page_not_found)); |
522 | WB1.Prepare(#page_not_found, sizeof(page_not_found)); |
530 | } |
523 | } |
531 | else |
524 | else |
532 | WB1.Parse(bufpointer, bufsize); |
525 | WB1.Parse(); |
533 | 526 | ||
534 | if (!header) strcpy(#header, #version); |
527 | if (!header) strcpy(#header, #version); |
535 | if (!strcmp(#version, #header)) DrawTitle(#header); |
528 | if (!strcmp(#version, #header)) DrawTitle(#header); |
536 | } |
529 | } |
537 | - | ||
538 | ShowHistory() |
- | |
539 | { |
- | |
540 | int i; |
- | |
541 | static int history_pointer; |
- | |
542 | - | ||
543 | free(history_pointer); |
- | |
544 | history_pointer = malloc(64000); |
- | |
545 | strcat(history_pointer, " |
- | |
546 | strcat(history_pointer, " |
- | |
547 | for (i=1; i |
- | |
548 | { |
- | |
549 | strcat(history_pointer, ""); |
- | |
552 | strcat(history_pointer, BrowserHistory.GetUrl(i)); |
- | |
553 | strcat(history_pointer, " |
- | |
554 | } |
- | |
555 | strcat(history_pointer, " |
- | |
556 | for (i=1; i |
- | |
557 | { |
- | |
558 | strcat(history_pointer, " |
- | |
561 | strcat(history_pointer, #pics[i].path); |
- | |
562 | } |
- | |
563 | bufpointer = history_pointer; |
- | |
564 | WB1.Parse(history_pointer, strlen(history_pointer)); |
530 | |
565 | } |
531 | |
566 | 532 | ||
567 | 533 | ||
568 | stop:>0)>>>>=>>>>>>>5;>>280)>120)>>>=5) |
534 | stop:>>>>>=>>>>5;>280)>120)>=5) |
569 | >>8;><8;>>>>>0)>=scroll_wv.start_x+scroll_wv.size_x)> |
535 | >>8;><8;>>>>>0)>=scroll_wv.start_x+scroll_wv.size_x)> |