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