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