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