Rev 4693 | Rev 4719 | 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 |
4718 | leency | 32 | char version[]=" Текстовый браузер 1.0 Beta 4"; |
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 |
4718 | leency | 39 | char version[]=" Text-based Browser 1.0 Beta 4"; |
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 | |
4692 | leency | 62 | dword TAB_H = false; //19; |
4677 | leency | 63 | dword TAB_W = 150; |
4692 | leency | 64 | dword TOOLBAR_H = 31; //50; |
4718 | leency | 65 | dword STATUSBAR_H =15; |
66 | dword col_bg; |
||
67 | dword panel_color; |
||
68 | dword border_color; |
||
4677 | leency | 69 | |
4686 | leency | 70 | pb progress_bar = {0, 10, 83, 150, 12, 0, 0, 100, 0xeeeEEE, 8072B7EBh, 0x9F9F9F}; |
4718 | leency | 71 | byte souce_mode = false; |
4677 | leency | 72 | |
4411 | leency | 73 | #include "..\TWB\TWB.c" |
74 | #include "menu_rmb.h" |
||
4636 | leency | 75 | #include "history.h" |
4718 | leency | 76 | #include "show_src.h" |
3067 | leency | 77 | |
4534 | leency | 78 | char editURL[sizeof(URL)]; |
79 | int mouse_twb; |
||
4677 | leency | 80 | edit_box address_box = {250,55,34,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(URL),#editURL,#mouse_twb,2,19,19}; |
4534 | leency | 81 | |
4677 | leency | 82 | #define URL_SERVICE_HISTORY "WebView://history" |
83 | #define URL_SERVICE_HOME "WebView://home" |
||
4718 | leency | 84 | #define URL_SERVICE_SOURCE "WebView://source:" |
4534 | leency | 85 | |
4488 | leency | 86 | enum { BACK=300, FORWARD, REFRESH, HOME, NEWTAB, GOTOURL, SEARCHWEB, INPUT_CH, INPUT_BT, BTN_UP, BTN_DOWN }; |
3067 | leency | 87 | |
4718 | leency | 88 | struct struct_skin { |
4677 | leency | 89 | dword image, w, h; |
4718 | leency | 90 | int Load(); |
4677 | leency | 91 | } skin; |
4488 | leency | 92 | |
4718 | leency | 93 | int struct_skin::Load() |
4677 | leency | 94 | { |
4718 | leency | 95 | dword image_data; |
4677 | leency | 96 | skin.image = load_image(abspath("wv_skin.png")); |
4686 | leency | 97 | if (!skin.image) notify("WebView skin file 'wv_skin.png' not found, program will terminate"); |
4677 | leency | 98 | skin.w = DSWORD[skin.image+4]; |
99 | skin.h = DSWORD[skin.image+8]; |
||
4718 | leency | 100 | image_data = DSDWORD[skin.image+24]; |
101 | |||
102 | col_bg = DSDWORD[DSDWORD[skin.image+24]]; |
||
103 | panel_color = DSDWORD[skin.w*4*4 + image_data]; |
||
104 | border_color = DSDWORD[skin.w*4*7 + image_data]; |
||
105 | progress_bar.progress_color = DSDWORD[skin.w*4*10 + image_data]; |
||
106 | $and col_bg, 0x00ffffff |
||
107 | $and panel_color, 0x00ffffff |
||
108 | $and border_color, 0x00ffffff |
||
109 | $and progress_bar.progress_color, 0x00ffffff |
||
4677 | leency | 110 | } |
111 | |||
4686 | leency | 112 | void DrawProgress() |
113 | { |
||
114 | unsigned long btn; |
||
115 | //progressbar_draw stdcall(#progress_bar); |
||
116 | progress_bar.width = progress_bar.left = 0; |
||
117 | if (http_transfer == 0) return; |
||
118 | if (progress_bar.max) btn = address_box.width*progress_bar.value/progress_bar.max; else btn = 30; |
||
119 | DrawBar(address_box.left-1, address_box.top+14, btn, 2, progress_bar.progress_color); |
||
120 | } |
||
121 | |||
4718 | leency | 122 | |
3067 | leency | 123 | void main() |
124 | { |
||
4686 | leency | 125 | unsigned long key, btn; |
3067 | leency | 126 | int half_scroll_size; |
4026 | leency | 127 | int scroll_used=0, show_menu; |
3067 | leency | 128 | |
129 | mem_Init(); |
||
4536 | leency | 130 | CursorPointer.Load(#CursorFile); |
4686 | leency | 131 | if (load_dll2(boxlib, #box_lib_init,0)!=0) notify("System Error: library doesn't exists /rd/1/lib/box_lib.obj"); |
4536 | leency | 132 | if (load_dll2(libio, #libio_init,1)!=0) notify("Error: library doesn't exists - libio"); |
133 | if (load_dll2(libimg, #libimg_init,1)!=0) notify("Error: library doesn't exists - libimg"); |
||
4540 | leency | 134 | if (load_dll2(libHTTP, #http_lib_init,1)!=0) notify("Error: library doesn't exists - http"); |
4718 | leency | 135 | skin.Load(); |
3067 | leency | 136 | |
137 | Form.width=WIN_W; |
||
138 | Form.height=WIN_H; |
||
139 | SetElementSizes(); |
||
4677 | leency | 140 | if (!URL) strcpy(#URL, URL_SERVICE_HOME); |
4416 | leency | 141 | OpenPage(); |
3067 | leency | 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 | { |
||
4415 | leency | 187 | half_scroll_size = WB1.list.h - 16 * WB1.list.visible / WB1.list.count - 3 /2; |
4416 | leency | 188 | if (half_scroll_size+WB1.list.y>m.y) || (m.y<0) || (m.y>4000) m.y=half_scroll_size+WB1.list.y; |
189 | btn=WB1.list.first; |
||
4415 | leency | 190 | WB1.list.first = m.y -half_scroll_size -WB1.list.y * WB1.list.count / WB1.list.h; |
191 | if (WB1.list.visible+WB1.list.first>WB1.list.count) WB1.list.first=WB1.list.count-WB1.list.visible; |
||
4636 | leency | 192 | if (btn<>WB1.list.first) WB1.Parse(); |
3067 | leency | 193 | } |
194 | break; |
||
195 | case evButton: |
||
196 | btn=GetButtonID(); |
||
4636 | leency | 197 | if (btn==1) ExitProcess(); |
198 | Scan(btn); |
||
3067 | leency | 199 | break; |
200 | case evKey: |
||
201 | key = GetKey(); |
||
202 | |||
4416 | leency | 203 | if (address_box.flags & 0b10) SWITCH(key) |
4718 | leency | 204 | { CASE 52: CASE 53: CASE 54: CASE 180: CASE 181: goto _EDIT_MARK; } |
3067 | leency | 205 | |
4413 | leency | 206 | Scan(key); |
3067 | leency | 207 | |
208 | _EDIT_MARK: |
||
4416 | leency | 209 | if (key<>0x0d) && (key<>183) && (key<>184) {EAX=key<<8; edit_box_key stdcall(#address_box);} |
3067 | leency | 210 | break; |
211 | case evReDraw: |
||
4636 | leency | 212 | if (action_buf) Scan(action_buf); |
3067 | leency | 213 | Draw_Window(); |
214 | break; |
||
4540 | leency | 215 | |
4536 | leency | 216 | case evNetwork: |
4540 | leency | 217 | if (http_transfer > 0) { |
4536 | leency | 218 | http_process stdcall (http_transfer); |
4677 | leency | 219 | $push EAX |
220 | ESI = http_transfer; |
||
221 | progress_bar.max = ESI.http_msg.content_length; |
||
4686 | leency | 222 | if (progress_bar.value != ESI.http_msg.content_received) |
223 | { |
||
224 | progress_bar.value = ESI.http_msg.content_received; |
||
225 | DrawProgress(); |
||
226 | } |
||
4677 | leency | 227 | $pop EAX |
228 | if (EAX == 0) { |
||
4558 | hidnplayr | 229 | ESI = http_transfer; |
230 | // Handle redirects |
||
4563 | leency | 231 | if (ESI.http_msg.status >= 300) && (ESI.http_msg.status < 400) |
232 | { |
||
4558 | hidnplayr | 233 | redirected++; |
4563 | leency | 234 | if (redirected<=5) |
235 | { |
||
4558 | hidnplayr | 236 | http_find_header_field stdcall (http_transfer, #str_location); |
237 | if (EAX!=0) { |
||
238 | ESI = EAX; |
||
239 | EDI = #URL; |
||
240 | do { |
||
241 | $lodsb; |
||
242 | $stosb; |
||
243 | } while (AL != 0) && (AL != 13) && (AL != 10)); |
||
244 | DSBYTE[EDI-1]='\0'; |
||
245 | } |
||
4563 | leency | 246 | } |
247 | else |
||
248 | { |
||
4558 | hidnplayr | 249 | //TODO: display error (too many redirects) |
250 | } |
||
4563 | leency | 251 | } |
252 | else |
||
253 | { |
||
4558 | hidnplayr | 254 | redirected = 0; |
255 | } |
||
4554 | leency | 256 | // Loading the page is complete, free resources |
4563 | leency | 257 | if (redirected>0) |
258 | { |
||
4643 | leency | 259 | http_free stdcall (http_transfer); |
260 | http_transfer=0; |
||
4686 | leency | 261 | PageLinks.GetAbsoluteURL(#URL); |
4687 | leency | 262 | BrowserHistory.current--; |
4558 | hidnplayr | 263 | strcpy(#editURL, #URL); |
264 | OpenPage(); |
||
4563 | leency | 265 | } |
266 | else |
||
267 | { |
||
4686 | leency | 268 | BrowserHistory.AddUrl(); |
4643 | leency | 269 | ESI = http_transfer; |
270 | bufpointer = ESI.http_msg.content_ptr; |
||
271 | bufsize = ESI.http_msg.content_received; |
||
272 | http_free stdcall (http_transfer); |
||
273 | http_transfer=0; |
||
4645 | leency | 274 | SetPageDefaults(); |
4558 | hidnplayr | 275 | Draw_Window(); // stop button => refresh button |
276 | } |
||
4536 | leency | 277 | } |
278 | } |
||
3067 | leency | 279 | } |
280 | } |
||
281 | } |
||
282 | |||
283 | void SetElementSizes() |
||
284 | { |
||
4677 | leency | 285 | address_box.top = TOOLBAR_H-TAB_H/2-7+TAB_H; |
286 | address_box.width = Form.cwidth - address_box.left - 25 - 22; |
||
4718 | leency | 287 | WB1.list.SetSizes(0, TOOLBAR_H, Form.width - 10 - scroll_wv.size_x, Form.cheight - TOOLBAR_H - STATUSBAR_H, 0, 11); |
4651 | leency | 288 | WB1.list.column_max = WB1.list.w - scroll_wv.size_x / 6; |
4692 | leency | 289 | WB1.list.visible = WB1.list.h - 5 / WB1.list.line_h; |
4674 | leency | 290 | WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, WB1.list.line_h); |
3067 | leency | 291 | } |
292 | |||
293 | void Draw_Window() |
||
294 | { |
||
4677 | leency | 295 | int img_off; |
296 | DefineAndDrawWindow(GetScreenWidth()-WIN_W/2,GetScreenHeight()-WIN_H/2,WIN_W,WIN_H,0x73,col_bg,0,0); |
||
3067 | leency | 297 | GetProcessInfo(#Form, SelfInfo); |
4677 | leency | 298 | if (Form.status_window>2) { DrawTitle(#header); return; } |
3067 | leency | 299 | if (Form.height<120) MoveSize(OLD,OLD,OLD,120); |
300 | if (Form.width<280) MoveSize(OLD,OLD,280,OLD); |
||
4677 | leency | 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); |
||
333 | 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 | |||
4413 | leency | 383 | case BACK: |
384 | if (!BrowserHistory.GoBack()) return; |
||
4416 | leency | 385 | OpenPage(); |
4413 | leency | 386 | return; |
387 | case FORWARD: |
||
388 | if (!BrowserHistory.GoForward()) return; |
||
4416 | leency | 389 | OpenPage(); |
4413 | leency | 390 | return; |
4718 | leency | 391 | case 052: //F3 |
392 | ShowSource(); |
||
393 | break; |
||
394 | case 053: //F4 |
||
4636 | leency | 395 | if (strncmp(#URL,"http:",5)==0) |
396 | { |
||
4718 | leency | 397 | WriteFile(bufsize, bufpointer, "/tmp0/1/WebView_tmp.htm"); |
398 | if (EAX==0) RunProgram("/rd/1/tinypad", "/tmp0/1/WebView_tmp.htm"); |
||
4636 | leency | 399 | } |
400 | else |
||
401 | { |
||
402 | RunProgram("/rd/1/tinypad", #URL); |
||
403 | } |
||
4413 | leency | 404 | return; |
405 | case 054: //F5 |
||
4688 | leency | 406 | IF(address_box.flags & 0b10) return; |
4413 | leency | 407 | case REFRESH: |
4643 | leency | 408 | if (http_transfer > 0) |
409 | { |
||
410 | StopLoading(); |
||
411 | Draw_Window(); |
||
412 | } |
||
4636 | leency | 413 | else OpenPage(); |
4413 | leency | 414 | return; |
4415 | leency | 415 | case 014: |
416 | case 020: |
||
4413 | leency | 417 | case NEWTAB: |
418 | MoveSize(190,80,OLD,OLD); |
||
419 | RunProgram(#program_path, #URL); |
||
420 | return; |
||
421 | |||
422 | case HOME: |
||
4571 | hidnplayr | 423 | strcpy(#editURL, "http://kolibrios.org/"); |
4413 | leency | 424 | case GOTOURL: |
425 | case 0x0D: //enter |
||
4718 | leency | 426 | if (!editURL[0]) return; |
4692 | leency | 427 | if ((strncmp(#editURL,"http:",5)!=0) && (editURL[0]!='/') && ((strncmp(#editURL,"WebView:",8)!=0)) |
428 | { |
||
429 | strcpy(#URL,"http://"); |
||
430 | } |
||
431 | else |
||
432 | URL[0] = 0; |
||
4413 | leency | 433 | strcat(#URL, #editURL); |
4416 | leency | 434 | OpenPage(); |
4413 | leency | 435 | return; |
436 | case SEARCHWEB: |
||
437 | strcpy(#URL, #search_path); |
||
438 | strcat(#URL, #editURL); |
||
4416 | leency | 439 | OpenPage(); |
4413 | leency | 440 | return; |
441 | |||
442 | case 183: //PgDown |
||
4415 | leency | 443 | if (WB1.list.count < WB1.list.visible) return; |
444 | IF(WB1.list.first == WB1.list.count - WB1.list.visible) return; |
||
445 | WB1.list.first += WB1.list.visible + 2; |
||
446 | IF(WB1.list.visible + WB1.list.first > WB1.list.count) WB1.list.first = WB1.list.count - WB1.list.visible; |
||
4636 | leency | 447 | WB1.Parse(); |
4415 | leency | 448 | return; |
449 | |||
4413 | leency | 450 | case 184: //PgUp |
4415 | leency | 451 | if (WB1.list.count < WB1.list.visible) return; |
452 | IF(WB1.list.first == 0) return; |
||
453 | WB1.list.first -= WB1.list.visible - 2; |
||
454 | IF(WB1.list.first < 0) WB1.list.first = 0; |
||
4636 | leency | 455 | WB1.Parse(); |
4415 | leency | 456 | return; |
457 | |||
458 | case 178: |
||
4544 | leency | 459 | case BTN_UP: |
4416 | leency | 460 | if (WB1.list.first <= 0) return; |
4415 | leency | 461 | WB1.list.first--; |
4636 | leency | 462 | WB1.Parse(); |
4415 | leency | 463 | return; |
464 | |||
465 | case 177: |
||
4544 | leency | 466 | case BTN_DOWN: |
4416 | leency | 467 | if (WB1.list.visible + WB1.list.first >= WB1.list.count) return; |
4415 | leency | 468 | WB1.list.first++; |
4636 | leency | 469 | WB1.Parse(); |
4415 | leency | 470 | return; |
471 | |||
4413 | leency | 472 | case 180: //home |
4636 | leency | 473 | if (WB1.list.KeyHome()) WB1.Parse(); |
4415 | leency | 474 | return; |
475 | |||
4413 | leency | 476 | case 181: //end |
4415 | leency | 477 | if (WB1.list.count < WB1.list.visible) return; |
4636 | leency | 478 | if (WB1.list.KeyEnd()) WB1.Parse(); |
4413 | leency | 479 | return; |
4677 | leency | 480 | case 312: |
481 | SwitchToAnotherThread(); |
||
482 | m.y = TOOLBAR_H-6; |
||
483 | m.x = Form.cwidth - 167; |
||
484 | CreateThread(#menu_rmb,#stak+4092); |
||
4413 | leency | 485 | } |
486 | } |
||
487 | |||
488 | |||
489 | |||
4415 | leency | 490 | void ProcessLinks(int id) |
491 | { |
||
4687 | leency | 492 | if (http_transfer > 0) |
493 | { |
||
494 | StopLoading(); |
||
495 | BrowserHistory.current--; |
||
496 | } |
||
497 | |||
4544 | leency | 498 | strcpy(#URL, PageLinks.GetURL(id-401)); |
4417 | leency | 499 | //$1 - Condition Script |
500 | if (URL[0] == '$') |
||
501 | { |
||
502 | if (URL[1]=='-') && (condition_href) condition_href--; |
||
503 | if (URL[1]=='+') |
||
504 | { |
||
505 | if (condition_href |
||
506 | } |
||
507 | if (URL[1]!='-') && (URL[1]!='+') condition_href = atoi(#URL+1); |
||
508 | strcpy(#URL, BrowserHistory.CurrentUrl()); |
||
4508 | leency | 509 | ShowPage(); |
4417 | leency | 510 | return; |
511 | } |
||
4415 | leency | 512 | //#1 |
513 | if (URL[0] == '#') |
||
514 | { |
||
4417 | leency | 515 | strcpy(#anchor, #URL+strrchr(#URL, '#')); |
4415 | leency | 516 | strcpy(#URL, BrowserHistory.CurrentUrl()); |
517 | WB1.list.first=WB1.list.count-WB1.list.visible; |
||
4508 | leency | 518 | ShowPage(); |
4415 | leency | 519 | return; |
520 | } |
||
521 | //liner.ru#1 |
||
4417 | leency | 522 | if (strrchr(#URL, '#')!=-1) |
4415 | leency | 523 | { |
524 | strcpy(#anchor, #URL+strrchr(#URL, '#')); |
||
4416 | leency | 525 | URL[strrchr(#URL, '#')-1] = 0x00; |
4415 | leency | 526 | } |
527 | |||
4686 | leency | 528 | PageLinks.GetAbsoluteURL(#URL); |
4415 | leency | 529 | |
530 | if (!strcmp(#URL + strlen(#URL) - 4, ".gif")) || (!strcmp(#URL + strlen(#URL) - 4, ".png")) || (!strcmp(#URL + strlen(#URL) - 4, ".jpg")) |
||
531 | { |
||
532 | //if (strstr(#URL,"http:")) |
||
533 | RunProgram("/sys/media/kiv", #URL); |
||
534 | strcpy(#editURL, BrowserHistory.CurrentUrl()); |
||
535 | strcpy(#URL, BrowserHistory.CurrentUrl()); |
||
536 | return; |
||
537 | } |
||
538 | if (!strcmpn(#URL,"mailto:", 7)) |
||
539 | { |
||
540 | notify(#URL); |
||
541 | strcpy(#editURL, BrowserHistory.CurrentUrl()); |
||
542 | strcpy(#URL, BrowserHistory.CurrentUrl()); |
||
543 | return; |
||
544 | } |
||
4416 | leency | 545 | OpenPage(); |
4415 | leency | 546 | return; |
547 | } |
||
548 | |||
4636 | leency | 549 | void StopLoading() |
550 | { |
||
4647 | leency | 551 | if (http_transfer<>0) |
552 | { |
||
553 | EAX = http_transfer; |
||
554 | EAX = EAX.http_msg.content_ptr; // get pointer to data |
||
555 | $push EAX // save it on the stack |
||
556 | http_free stdcall (http_transfer); // abort connection |
||
557 | $pop EAX |
||
558 | mem_Free(EAX); // free data |
||
559 | http_transfer=0; |
||
560 | bufsize = 0; |
||
4650 | leency | 561 | bufpointer = mem_Free(bufpointer); |
4647 | leency | 562 | } |
4677 | leency | 563 | progress_bar.value = 0; |
564 | img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-2, 17, skin.h, 52, 0); |
||
4645 | leency | 565 | } |
566 | |||
567 | void SetPageDefaults() |
||
568 | { |
||
569 | strcpy(#header, #version); |
||
570 | pre_text = 0; |
||
571 | WB1.list.count = WB1.list.first = 0; |
||
572 | stroka = 0; |
||
573 | cur_encoding = _DEFAULT; |
||
574 | if (o_bufpointer) o_bufpointer = free(o_bufpointer); |
||
4636 | leency | 575 | anchor_line_num=WB1.list.first; |
576 | anchor[0]='|'; |
||
577 | } |
||
578 | |||
4416 | leency | 579 | void OpenPage() |
580 | { |
||
4636 | leency | 581 | StopLoading(); |
4718 | leency | 582 | souce_mode = false; |
4416 | leency | 583 | strcpy(#editURL, #URL); |
4687 | leency | 584 | BrowserHistory.AddUrl(); |
4692 | leency | 585 | if (strncmp(#URL,"WebView:",8)==0) |
586 | { |
||
587 | SetPageDefaults(); |
||
588 | if (strcmp(#URL, URL_SERVICE_HOME)==0) |
||
589 | { |
||
590 | WB1.Prepare(#homepage, sizeof(homepage)); |
||
591 | } |
||
592 | if (strcmp(#URL, URL_SERVICE_HISTORY)==0) |
||
593 | { |
||
594 | ShowHistory(); |
||
595 | } |
||
596 | return; |
||
597 | } |
||
4636 | leency | 598 | if (strncmp(#URL,"http:",5)==0) |
4416 | leency | 599 | { |
4677 | leency | 600 | img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-2, 17, skin.h, 131, 0); |
4636 | leency | 601 | http_get stdcall (#URL, #accept_language); |
602 | http_transfer = EAX; |
||
4646 | leency | 603 | if (http_transfer == 0) |
604 | { |
||
605 | StopLoading(); |
||
606 | bufsize = 0; |
||
4650 | leency | 607 | bufpointer = mem_Free(bufpointer); |
4646 | leency | 608 | ShowPage(); |
609 | return; |
||
610 | } |
||
4416 | leency | 611 | } |
4636 | leency | 612 | else |
613 | { |
||
614 | file_size stdcall (#URL); |
||
615 | bufsize = EBX; |
||
4650 | leency | 616 | if (bufsize) |
617 | { |
||
4718 | leency | 618 | mem_Free(bufpointer); |
4650 | leency | 619 | bufpointer = mem_Alloc(bufsize); |
620 | SetPageDefaults(); |
||
4718 | leency | 621 | ReadFile(0, bufsize, bufpointer, #URL); |
622 | //ShowSource(); |
||
4650 | leency | 623 | } |
4645 | leency | 624 | ShowPage(); |
4636 | leency | 625 | } |
4416 | leency | 626 | } |
4415 | leency | 627 | |
4718 | leency | 628 | DrawEditBox() |
4508 | leency | 629 | { |
4718 | leency | 630 | address_box.size = address_box.pos = address_box.shift = address_box.shift_old = strlen(#editURL); |
631 | address_box.offset = 0; |
||
4508 | leency | 632 | edit_box_draw stdcall(#address_box); |
4718 | leency | 633 | } |
4415 | leency | 634 | |
4718 | leency | 635 | |
636 | void ShowPage() |
||
637 | { |
||
638 | DrawEditBox(); |
||
4540 | leency | 639 | if (!bufsize) |
4508 | leency | 640 | { |
641 | PageLinks.Clear(); |
||
4636 | leency | 642 | if (http_transfer<>0) |
643 | { |
||
644 | WB1.Prepare(#loading, sizeof(loading)); |
||
645 | } |
||
4508 | leency | 646 | else |
4636 | leency | 647 | WB1.Prepare(#page_not_found, sizeof(page_not_found)); |
4508 | leency | 648 | } |
649 | else |
||
4636 | leency | 650 | WB1.Parse(); |
4415 | leency | 651 | |
4508 | leency | 652 | if (!header) strcpy(#header, #version); |
653 | if (!strcmp(#version, #header)) DrawTitle(#header); |
||
654 | } |
||
655 | |||
656 | |||
4544 | leency | 657 | |
4636 | leency | 658 | |
3067 | leency | 659 | stop:>>>=>>>>>280)>120)>=5) |