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