Rev 6808 | Rev 6985 | 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 | |
4085 | leency | 5 | #ifndef AUTOBUILD |
6 | #include "lang.h--" |
||
7 | #endif |
||
8 | |||
3107 | leency | 9 | //libraries |
6738 | leency | 10 | #define MEMSIZE 4096 * 200 |
5499 | leency | 11 | #include "..\lib\gui.h" |
4508 | leency | 12 | #include "..\lib\draw_buf.h" |
13 | #include "..\lib\list_box.h" |
||
14 | #include "..\lib\cursor.h" |
||
5978 | leency | 15 | #include "..\lib\collection.h" |
6045 | leency | 16 | #include "..\lib\menu.h" |
6795 | leency | 17 | #include "..\lib\random.h" |
5981 | leency | 18 | |
3107 | leency | 19 | //*.obj libraries |
5499 | leency | 20 | #include "..\lib\obj\box_lib.h" |
21 | #include "..\lib\obj\libio_lib.h" |
||
22 | #include "..\lib\obj\libimg_lib.h" |
||
23 | #include "..\lib\obj\http.h" |
||
5690 | leency | 24 | #include "..\lib\obj\iconv.h" |
5408 | leency | 25 | //useful patterns |
26 | #include "..\lib\patterns\libimg_load_skin.h" |
||
5978 | leency | 27 | #include "..\lib\patterns\history.h" |
6058 | leency | 28 | #include "..\lib\patterns\http_downloader.h" |
5408 | leency | 29 | |
6698 | leency | 30 | char homepage[] = FROM "html\\homepage.htm""\0"; |
4677 | leency | 31 | |
4026 | leency | 32 | #ifdef LANG_RUS |
6931 | leency | 33 | char version[]="Текстовый браузер 1.6"; |
6045 | leency | 34 | ?define IMAGES_CACHE_CLEARED "Кэш картинок очищен" |
35 | ?define T_LAST_SLIDE "Это последний слайд" |
||
36 | char loading[] = "Загрузка страницы... |
||
6698 | leency | 37 | char page_not_found[] = FROM "html\\page_not_found_ru.htm""\0"; |
6045 | leency | 38 | char accept_language[]= "Accept-Language: ru\n"; |
39 | char rmb_menu[] = |
||
40 | "Посмотреть исходник |
||
41 | Редактировать исходник |
||
42 | История |
||
43 | Очистить кэш картинок |
||
44 | Менеджер загрузок"; |
||
4026 | leency | 45 | #else |
6931 | leency | 46 | char version[]="Text-based Browser 1.6"; |
6045 | leency | 47 | ?define IMAGES_CACHE_CLEARED "Images cache cleared" |
48 | ?define T_LAST_SLIDE "This slide is the last" |
||
49 | char loading[] = "Loading... |
||
6698 | leency | 50 | char page_not_found[] = FROM "html\\page_not_found_en.htm""\0"; |
6045 | leency | 51 | char accept_language[]= "Accept-Language: en\n"; |
52 | char rmb_menu[] = |
||
53 | "View source |
||
54 | Edit source |
||
55 | History |
||
56 | Free image cache |
||
57 | Download Manager"; |
||
4026 | leency | 58 | #endif |
59 | |||
6795 | leency | 60 | char link_menu[] = |
61 | "Copy link |
||
62 | Download link"; |
||
63 | |||
5773 | leency | 64 | #define URL_SERVICE_HISTORY "WebView://history" |
65 | #define URL_SERVICE_HOME "WebView://home" |
||
66 | #define URL_SERVICE_SOURCE "WebView://source:" |
||
5631 | pavelyakov | 67 | |
3067 | leency | 68 | proc_info Form; |
69 | |||
5772 | leency | 70 | //char search_path[]="http://nigma.ru/index.php?s="; |
4558 | hidnplayr | 71 | int redirected = 0; |
3067 | leency | 72 | |
4074 | leency | 73 | char stak[4096]; |
5640 | pavelyakov | 74 | |
4026 | leency | 75 | int action_buf; |
76 | |||
4565 | leency | 77 | dword http_transfer = 0; |
4537 | leency | 78 | dword http_buffer; |
4534 | leency | 79 | |
6731 | leency | 80 | dword TOOLBAR_H = 40; |
5519 | leency | 81 | dword STATUSBAR_H = 15; |
4718 | leency | 82 | dword col_bg; |
83 | dword panel_color; |
||
84 | dword border_color; |
||
4677 | leency | 85 | |
5718 | leency | 86 | progress_bar wv_progress_bar; |
6931 | leency | 87 | bool souce_mode = false; |
88 | bool open_in_a_new_window = false; |
||
4677 | leency | 89 | |
5718 | leency | 90 | enum { |
91 | BACK_BUTTON=1000, |
||
92 | FORWARD_BUTTON, |
||
93 | REFRESH_BUTTON, |
||
94 | GOTOURL_BUTTON, |
||
6795 | leency | 95 | SANDWICH_BUTTON, |
5768 | leency | 96 | VIEW_SOURCE=1100, |
5718 | leency | 97 | EDIT_SOURCE, |
98 | VIEW_HISTORY, |
||
99 | FREE_IMG_CACHE, |
||
6795 | leency | 100 | DOWNLOAD_MANAGER, |
101 | COPY_LINK=1200, |
||
102 | DOWNLOAD_LINK |
||
5718 | leency | 103 | }; |
104 | |||
4411 | leency | 105 | #include "..\TWB\TWB.c" |
4636 | leency | 106 | #include "history.h" |
4718 | leency | 107 | #include "show_src.h" |
6001 | leency | 108 | #include "download_manager.h" |
3067 | leency | 109 | |
4534 | leency | 110 | char editURL[sizeof(URL)]; |
111 | int mouse_twb; |
||
6731 | leency | 112 | edit_box address_box = {250,60,30,0xffffff,0x94AECE,0xffffff,0xffffff,0x10000000,sizeof(URL),#editURL,#mouse_twb,2,19,19}; |
4534 | leency | 113 | |
114 | |||
3067 | leency | 115 | void main() |
116 | { |
||
4536 | leency | 117 | CursorPointer.Load(#CursorFile); |
5626 | leency | 118 | load_dll(boxlib, #box_lib_init,0); |
119 | load_dll(libio, #libio_init,1); |
||
120 | load_dll(libimg, #libimg_init,1); |
||
121 | load_dll(libHTTP, #http_lib_init,1); |
||
5690 | leency | 122 | load_dll(iconv_lib, #iconv_open,0); |
5408 | leency | 123 | Libimg_LoadImage(#skin, abspath("wv_skin.png")); |
124 | SetSkinColors(); |
||
5772 | leency | 125 | CreateDir("/tmp0/1/downloads"); |
126 | if (param) strcpy(#URL, #param); else strcpy(#URL, URL_SERVICE_HOME); |
||
6045 | leency | 127 | WB1.list.SetFont(8, 14, 10011000b); |
5779 | leency | 128 | WB1.list.no_selection = true; |
4536 | leency | 129 | SetEventMask(0xa7); |
5631 | pavelyakov | 130 | BEGIN_LOOP_APPLICATION: |
3067 | leency | 131 | WaitEventTimeout(2); |
132 | switch(EAX & 0xFF) |
||
133 | { |
||
134 | CASE evMouse: |
||
4081 | leency | 135 | if (!CheckActiveProcess(Form.ID)) break; |
3466 | leency | 136 | edit_box_mouse stdcall (#address_box); |
5640 | pavelyakov | 137 | mouse.get(); |
5772 | leency | 138 | if (WB1.list.MouseOver(mouse.x, mouse.y)) |
3067 | leency | 139 | { |
6795 | leency | 140 | if (PageLinks.HoverAndProceed(mouse.x, WB1.list.first + mouse.y)) |
141 | && (bufsize) && (mouse.pkm) && (mouse.up) { |
||
142 | EventShowPageMenu(mouse.x, mouse.y); |
||
6045 | leency | 143 | break; |
144 | } |
||
5772 | leency | 145 | if (WB1.list.MouseScroll(mouse.vert)) WB1.DrawPage(); |
3067 | leency | 146 | } |
5782 | leency | 147 | scrollbar_v_mouse (#scroll_wv); |
148 | if (WB1.list.first != scroll_wv.position) |
||
3067 | leency | 149 | { |
5782 | leency | 150 | WB1.list.first = scroll_wv.position; |
151 | WB1.DrawPage(); |
||
152 | break; |
||
3067 | leency | 153 | } |
154 | break; |
||
5711 | leency | 155 | |
3067 | leency | 156 | case evButton: |
6698 | leency | 157 | ProcessEvent(GetButtonID()); |
3067 | leency | 158 | break; |
5711 | leency | 159 | |
3067 | leency | 160 | case evKey: |
5711 | leency | 161 | GetKeys(); |
5531 | leency | 162 | if (address_box.flags & 0b10) |
5530 | leency | 163 | { |
6698 | leency | 164 | if (key_ascii == ASCII_KEY_ENTER) ProcessEvent(key_scancode); else { |
6641 | leency | 165 | EAX = key_editbox; |
166 | edit_box_key stdcall(#address_box); |
||
167 | } |
||
5530 | leency | 168 | } |
5711 | leency | 169 | else |
170 | { |
||
6698 | leency | 171 | if (WB1.list.ProcessKey(key_scancode)) WB1.DrawPage(); |
172 | else ProcessEvent(key_scancode); |
||
5711 | leency | 173 | } |
5530 | leency | 174 | break; |
3067 | leency | 175 | |
176 | case evReDraw: |
||
6045 | leency | 177 | if (menu.list.cur_y) { |
6698 | leency | 178 | ProcessEvent(menu.list.cur_y); |
6045 | leency | 179 | menu.list.cur_y = 0; |
180 | } |
||
6795 | leency | 181 | DefineAndDrawWindow(GetScreenWidth()-800/2-random(80),GetScreenHeight()-600/2-random(80),800,600,0x73,col_bg,0,0); |
4725 | leency | 182 | GetProcessInfo(#Form, SelfInfo); |
4727 | leency | 183 | if (Form.status_window>2) { DrawTitle(#header); break; } |
5811 | leency | 184 | if (Form.height<120) { MoveSize(OLD,OLD,OLD,120); break; } |
185 | if (Form.width<280) { MoveSize(OLD,OLD,280,OLD); break; } |
||
3067 | leency | 186 | Draw_Window(); |
187 | break; |
||
4540 | leency | 188 | |
4536 | leency | 189 | case evNetwork: |
4540 | leency | 190 | if (http_transfer > 0) { |
5534 | hidnplayr | 191 | http_receive stdcall (http_transfer); |
4677 | leency | 192 | $push EAX |
193 | ESI = http_transfer; |
||
5519 | leency | 194 | wv_progress_bar.max = ESI.http_msg.content_length; |
195 | if (wv_progress_bar.value != ESI.http_msg.content_received) |
||
4686 | leency | 196 | { |
5519 | leency | 197 | wv_progress_bar.value = ESI.http_msg.content_received; |
4686 | leency | 198 | DrawProgress(); |
199 | } |
||
4677 | leency | 200 | $pop EAX |
201 | if (EAX == 0) { |
||
4558 | hidnplayr | 202 | ESI = http_transfer; |
203 | // Handle redirects |
||
4563 | leency | 204 | if (ESI.http_msg.status >= 300) && (ESI.http_msg.status < 400) |
205 | { |
||
4558 | hidnplayr | 206 | redirected++; |
4563 | leency | 207 | if (redirected<=5) |
208 | { |
||
5773 | leency | 209 | http_find_header_field stdcall (http_transfer, "location\0"); |
4558 | hidnplayr | 210 | if (EAX!=0) { |
211 | ESI = EAX; |
||
212 | EDI = #URL; |
||
213 | do { |
||
214 | $lodsb; |
||
215 | $stosb; |
||
6698 | leency | 216 | } while (AL != 0) && (AL != 13) && (AL != 10); |
4558 | hidnplayr | 217 | DSBYTE[EDI-1]='\0'; |
6738 | leency | 218 | if (!strncmp(#URL,"https://",8)) |
6730 | leency | 219 | { |
6794 | leency | 220 | ShowErrorMessageThatHttpsIsNotSupportedYet(); |
6738 | leency | 221 | StopLoading(); |
222 | break; |
||
6730 | leency | 223 | } |
4558 | hidnplayr | 224 | } |
4563 | leency | 225 | } |
226 | else |
||
227 | { |
||
5772 | leency | 228 | notify("Too many redirects"); |
229 | StopLoading(); |
||
230 | break; |
||
4558 | hidnplayr | 231 | } |
4563 | leency | 232 | } |
233 | else |
||
234 | { |
||
4558 | hidnplayr | 235 | redirected = 0; |
236 | } |
||
4554 | leency | 237 | // Loading the page is complete, free resources |
4563 | leency | 238 | if (redirected>0) |
239 | { |
||
4643 | leency | 240 | http_free stdcall (http_transfer); |
241 | http_transfer=0; |
||
5990 | leency | 242 | GetAbsoluteURL(#URL); |
6021 | leency | 243 | history.back(); |
4558 | hidnplayr | 244 | strcpy(#editURL, #URL); |
6278 | leency | 245 | DrawEditBoxWebView(); |
4558 | hidnplayr | 246 | OpenPage(); |
4563 | leency | 247 | } |
248 | else |
||
249 | { |
||
6021 | leency | 250 | history.add(#URL); |
4643 | leency | 251 | ESI = http_transfer; |
252 | bufpointer = ESI.http_msg.content_ptr; |
||
253 | bufsize = ESI.http_msg.content_received; |
||
254 | http_free stdcall (http_transfer); |
||
255 | http_transfer=0; |
||
4645 | leency | 256 | SetPageDefaults(); |
5772 | leency | 257 | ShowPage(); |
4558 | hidnplayr | 258 | } |
4536 | leency | 259 | } |
260 | } |
||
3067 | leency | 261 | } |
5631 | pavelyakov | 262 | goto BEGIN_LOOP_APPLICATION; |
3067 | leency | 263 | } |
264 | |||
265 | void SetElementSizes() |
||
266 | { |
||
6731 | leency | 267 | address_box.top = TOOLBAR_H/2-10; |
6794 | leency | 268 | basic_line_h = calc(WB1.list.font_h * 130) / 100; |
6731 | leency | 269 | address_box.width = Form.cwidth - address_box.left - 50; |
6803 | leency | 270 | WB1.list.SetSizes(0, TOOLBAR_H, Form.width - 10 - scroll_wv.size_x, |
6794 | leency | 271 | Form.cheight - TOOLBAR_H - STATUSBAR_H, basic_line_h); |
272 | WB1.list.wheel_size = 7 * basic_line_h; |
||
5710 | leency | 273 | WB1.list.column_max = WB1.list.w - scroll_wv.size_x / WB1.list.font_w; |
6794 | leency | 274 | WB1.list.visible = WB1.list.h; |
6045 | leency | 275 | if (WB1.list.w!=WB1.DrawBuf.bufw) { |
6803 | leency | 276 | WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, 32700); |
6698 | leency | 277 | ProcessEvent(REFRESH_BUTTON); |
6045 | leency | 278 | } |
3067 | leency | 279 | } |
280 | |||
5981 | leency | 281 | |
5982 | leency | 282 | |
3067 | leency | 283 | void Draw_Window() |
284 | { |
||
5772 | leency | 285 | DrawBar(0,0, Form.cwidth,TOOLBAR_H-2, panel_color); |
5718 | leency | 286 | DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, 0xD7D0D3); |
4677 | leency | 287 | DrawBar(0,TOOLBAR_H-1, Form.cwidth,1, border_color); |
3067 | leency | 288 | SetElementSizes(); |
6731 | leency | 289 | DrawRectangle(address_box.left-3, address_box.top-3, address_box.width+5, 25,border_color); |
290 | DefineButton(address_box.left-52, address_box.top-2, 24, skin.h-2, BACK_BUTTON+BT_HIDE, 0); |
||
291 | DefineButton(address_box.left-27, address_box.top-2, 24, skin.h-2, FORWARD_BUTTON+BT_HIDE, 0); |
||
292 | img_draw stdcall(skin.image, address_box.left-53, address_box.top-3, 51, skin.h, 3, 0); |
||
5718 | leency | 293 | DefineButton(address_box.left+address_box.width+1, address_box.top-3, 16, skin.h-1, REFRESH_BUTTON+BT_HIDE+BT_NOFRAME, 0); |
6731 | leency | 294 | DefineButton(Form.cwidth-27, address_box.top-3, 23, skin.h-1, SANDWICH_BUTTON+BT_HIDE, 0); |
295 | img_draw stdcall(skin.image, Form.cwidth-24, address_box.top-3, 17, skin.h, 87, 0); |
||
4677 | leency | 296 | DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,STATUSBAR_H, col_bg); |
297 | DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, border_color); |
||
6278 | leency | 298 | if (!header) OpenPage(); else { WB1.DrawPage(); DrawEditBoxWebView(); } |
4692 | leency | 299 | DrawRectangle(scroll_wv.start_x, scroll_wv.start_y, scroll_wv.size_x, scroll_wv.size_y-1, scroll_wv.bckg_col); |
4693 | leency | 300 | DrawProgress(); |
3067 | leency | 301 | } |
302 | |||
303 | |||
6698 | leency | 304 | void ProcessEvent(dword id__) |
4413 | leency | 305 | { |
6698 | leency | 306 | switch (id__) |
4413 | leency | 307 | { |
6698 | leency | 308 | case 1: |
309 | ExitProcess(); |
||
310 | return; |
||
5711 | leency | 311 | case SCAN_CODE_BS: |
5718 | leency | 312 | case BACK_BUTTON: |
6021 | leency | 313 | if (history.back()) { |
314 | strcpy(#URL, history.current()); |
||
5978 | leency | 315 | OpenPage(); |
316 | } |
||
5711 | leency | 317 | return; |
5718 | leency | 318 | case FORWARD_BUTTON: |
6021 | leency | 319 | if (history.forward()) { |
320 | strcpy(#URL, history.current()); |
||
5978 | leency | 321 | OpenPage(); |
322 | } |
||
5711 | leency | 323 | return; |
5718 | leency | 324 | case GOTOURL_BUTTON: |
5772 | leency | 325 | case SCAN_CODE_ENTER: |
6730 | leency | 326 | if (!strncmp(#editURL,"http:",5)) || (editURL[0]=='/') |
327 | || (!strncmp(#editURL,"https:",6)) || (!strncmp(#editURL,"WebView:",8)) |
||
5772 | leency | 328 | { |
329 | strcpy(#URL, #editURL); |
||
330 | } |
||
5711 | leency | 331 | else |
5772 | leency | 332 | { |
5803 | leency | 333 | strlcpy(#URL,"http://",7); |
5772 | leency | 334 | strcat(#URL, #editURL); |
335 | } |
||
5711 | leency | 336 | OpenPage(); |
337 | return; |
||
5718 | leency | 338 | case 063: //F5 |
339 | IF(address_box.flags & 0b10) return; |
||
340 | case REFRESH_BUTTON: |
||
5713 | leency | 341 | if (http_transfer > 0) |
342 | { |
||
343 | StopLoading(); |
||
344 | Draw_Window(); |
||
345 | } |
||
346 | else OpenPage(); |
||
347 | return; |
||
5718 | leency | 348 | case SANDWICH_BUTTON: |
6795 | leency | 349 | EventShowPageMenu(Form.cwidth - 215, TOOLBAR_H-6); |
4415 | leency | 350 | return; |
5718 | leency | 351 | case VIEW_SOURCE: |
352 | WB1.list.first = 0; |
||
353 | ShowSource(); |
||
5773 | leency | 354 | WB1.LoadInternalPage(bufpointer, bufsize); |
5718 | leency | 355 | break; |
356 | case EDIT_SOURCE: |
||
357 | if (!strncmp(#URL,"http:",5)) |
||
358 | { |
||
359 | WriteFile(bufsize, bufpointer, "/tmp0/1/WebView_tmp.htm"); |
||
360 | if (!EAX) RunProgram("/rd/1/tinypad", "/tmp0/1/WebView_tmp.htm"); |
||
361 | } |
||
362 | else RunProgram("/rd/1/tinypad", #URL); |
||
4415 | leency | 363 | return; |
5718 | leency | 364 | case FREE_IMG_CACHE: |
4491 | leency | 365 | ImgCache.Free(); |
4416 | leency | 366 | notify(IMAGES_CACHE_CLEARED); |
5766 | leency | 367 | WB1.DrawPage(); |
4415 | leency | 368 | return; |
5718 | leency | 369 | case VIEW_HISTORY: |
4677 | leency | 370 | strcpy(#URL, URL_SERVICE_HISTORY); |
4544 | leency | 371 | OpenPage(); |
372 | return; |
||
5718 | leency | 373 | case DOWNLOAD_MANAGER: |
5519 | leency | 374 | if (!downloader_opened) { |
6001 | leency | 375 | downloader_edit = NULL; |
5519 | leency | 376 | CreateThread(#Downloader,#downloader_stak+4092); |
377 | } |
||
4413 | leency | 378 | return; |
379 | } |
||
380 | } |
||
381 | |||
382 | |||
4636 | leency | 383 | void StopLoading() |
384 | { |
||
5631 | pavelyakov | 385 | if (http_transfer) |
4647 | leency | 386 | { |
387 | EAX = http_transfer; |
||
388 | EAX = EAX.http_msg.content_ptr; // get pointer to data |
||
389 | $push EAX // save it on the stack |
||
390 | http_free stdcall (http_transfer); // abort connection |
||
391 | $pop EAX |
||
5631 | pavelyakov | 392 | free(EAX); // free data |
4647 | leency | 393 | http_transfer=0; |
394 | bufsize = 0; |
||
5631 | pavelyakov | 395 | bufpointer = free(bufpointer); |
4647 | leency | 396 | } |
5519 | leency | 397 | wv_progress_bar.value = 0; |
6731 | leency | 398 | DrawEditBoxWebView(); |
4645 | leency | 399 | } |
400 | |||
401 | void SetPageDefaults() |
||
402 | { |
||
403 | strcpy(#header, #version); |
||
404 | WB1.list.count = WB1.list.first = 0; |
||
5704 | leency | 405 | cur_encoding = CH_NULL; |
4645 | leency | 406 | if (o_bufpointer) o_bufpointer = free(o_bufpointer); |
4636 | leency | 407 | } |
408 | |||
4416 | leency | 409 | void OpenPage() |
410 | { |
||
4636 | leency | 411 | StopLoading(); |
4718 | leency | 412 | souce_mode = false; |
4416 | leency | 413 | strcpy(#editURL, #URL); |
6021 | leency | 414 | history.add(#URL); |
5631 | pavelyakov | 415 | if (!strncmp(#URL,"WebView:",8)) |
4692 | leency | 416 | { |
417 | SetPageDefaults(); |
||
5747 | leency | 418 | if (!strcmp(#URL, URL_SERVICE_HOME)) WB1.LoadInternalPage(#homepage, sizeof(homepage)); |
5631 | pavelyakov | 419 | else if (!strcmp(#URL, URL_SERVICE_HISTORY)) ShowHistory(); |
6278 | leency | 420 | DrawEditBoxWebView(); |
4692 | leency | 421 | return; |
422 | } |
||
5631 | pavelyakov | 423 | if (!strncmp(#URL,"http:",5)) |
4416 | leency | 424 | { |
5718 | leency | 425 | img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-3, 17, skin.h, 131, 0); |
5534 | hidnplayr | 426 | http_get stdcall (#URL, 0, 0, #accept_language); |
4636 | leency | 427 | http_transfer = EAX; |
5631 | pavelyakov | 428 | if (!http_transfer) |
4646 | leency | 429 | { |
430 | StopLoading(); |
||
431 | bufsize = 0; |
||
5631 | pavelyakov | 432 | bufpointer = free(bufpointer); |
4646 | leency | 433 | ShowPage(); |
434 | return; |
||
435 | } |
||
4416 | leency | 436 | } |
4636 | leency | 437 | else |
438 | { |
||
439 | file_size stdcall (#URL); |
||
440 | bufsize = EBX; |
||
4650 | leency | 441 | if (bufsize) |
442 | { |
||
5631 | pavelyakov | 443 | free(bufpointer); |
444 | bufpointer = malloc(bufsize); |
||
4650 | leency | 445 | SetPageDefaults(); |
4718 | leency | 446 | ReadFile(0, bufsize, bufpointer, #URL); |
4650 | leency | 447 | } |
4645 | leency | 448 | ShowPage(); |
4636 | leency | 449 | } |
4416 | leency | 450 | } |
4415 | leency | 451 | |
6278 | leency | 452 | DrawEditBoxWebView() |
4508 | leency | 453 | { |
6731 | leency | 454 | DrawBar(address_box.left-2, address_box.top-2, address_box.width+3, 2, address_box.color); |
455 | DrawBar(address_box.left-2, address_box.top, 2, 22, address_box.color); |
||
4718 | leency | 456 | address_box.size = address_box.pos = address_box.shift = address_box.shift_old = strlen(#editURL); |
457 | address_box.offset = 0; |
||
4508 | leency | 458 | edit_box_draw stdcall(#address_box); |
6731 | leency | 459 | if (http_transfer > 0) EAX = 131; else EAX = 54; |
5772 | leency | 460 | img_draw stdcall(skin.image, address_box.left+address_box.width+1, address_box.top-3, 17, skin.h, EAX, 0); |
4718 | leency | 461 | } |
4415 | leency | 462 | |
4718 | leency | 463 | |
464 | void ShowPage() |
||
465 | { |
||
6278 | leency | 466 | DrawEditBoxWebView(); |
6783 | leency | 467 | debugval("bufsize", bufsize); |
4540 | leency | 468 | if (!bufsize) |
4508 | leency | 469 | { |
5773 | leency | 470 | if (http_transfer) WB1.LoadInternalPage(#loading, sizeof(loading)); |
471 | else WB1.LoadInternalPage(#page_not_found, sizeof(page_not_found)); |
||
4508 | leency | 472 | } |
473 | else |
||
5768 | leency | 474 | { |
5766 | leency | 475 | WB1.Prepare(); |
5768 | leency | 476 | } |
4508 | leency | 477 | } |
478 | |||
5493 | leency | 479 | byte UrlExtIs(dword ext) |
480 | { |
||
5631 | pavelyakov | 481 | if (!strcmpi(#URL + strlen(#URL) - strlen(ext), ext)) return true; |
482 | return false; |
||
5493 | leency | 483 | } |
4508 | leency | 484 | |
5772 | leency | 485 | int SetSkinColors() |
486 | { |
||
487 | dword image_data; |
||
488 | image_data = DSDWORD[skin.image+24]; |
||
489 | col_bg = DSDWORD[image_data]; |
||
490 | panel_color = DSDWORD[skin.w*4*4 + image_data]; |
||
491 | border_color = DSDWORD[skin.w*4*7 + image_data]; |
||
492 | wv_progress_bar.progress_color = DSDWORD[skin.w*4*10 + image_data]; |
||
493 | $and col_bg, 0x00ffffff |
||
494 | $and panel_color, 0x00ffffff |
||
495 | $and border_color, 0x00ffffff |
||
496 | $and wv_progress_bar.progress_color, 0x00ffffff |
||
497 | } |
||
4544 | leency | 498 | |
5772 | leency | 499 | void DrawProgress() |
500 | { |
||
501 | unsigned long btn; |
||
502 | if (http_transfer == 0) return; |
||
503 | if (wv_progress_bar.max) btn = address_box.width*wv_progress_bar.value/wv_progress_bar.max; else btn = 30; |
||
6731 | leency | 504 | DrawBar(address_box.left-2, address_box.top+20, btn, 2, wv_progress_bar.progress_color); |
5772 | leency | 505 | } |
5746 | leency | 506 | |
6931 | leency | 507 | |
6803 | leency | 508 | char anchor[256]; |
5774 | leency | 509 | void ClickLink() |
510 | { |
||
511 | if (http_transfer > 0) |
||
512 | { |
||
513 | StopLoading(); |
||
6021 | leency | 514 | history.back(); |
5774 | leency | 515 | } |
5772 | leency | 516 | |
5774 | leency | 517 | strcpy(#URL, PageLinks.GetURL(PageLinks.active)); |
518 | //#1 |
||
519 | if (URL[0] == '#') |
||
520 | { |
||
6730 | leency | 521 | if (URL[1] == NULL) { |
522 | WB1.list.first = 0; |
||
523 | strcpy(#URL, history.current()); |
||
524 | } |
||
525 | else { |
||
526 | strlcpy(#anchor, #URL+strrchr(#URL, '#'), sizeof(anchor)); |
||
527 | strcpy(#URL, history.current()); |
||
528 | } |
||
529 | ShowPage(); |
||
5774 | leency | 530 | return; |
531 | } |
||
532 | //liner.ru#1 |
||
6730 | leency | 533 | if (strrchr(#URL, '#')!=0) |
5774 | leency | 534 | { |
6803 | leency | 535 | strlcpy(#anchor, #URL+strrchr(#URL, '#'), sizeof(anchor)); |
5774 | leency | 536 | URL[strrchr(#URL, '#')-1] = 0x00; |
537 | } |
||
6730 | leency | 538 | |
539 | if (!strncmp(#URL,"mailto:", 7)) |
||
540 | { |
||
541 | notify(#URL); |
||
542 | strcpy(#editURL, history.current()); |
||
543 | strcpy(#URL, history.current()); |
||
544 | return; |
||
545 | } |
||
546 | |||
6731 | leency | 547 | if (!strncmp(#URL,"https://",8)) |
6730 | leency | 548 | { |
6794 | leency | 549 | ShowErrorMessageThatHttpsIsNotSupportedYet(); |
6730 | leency | 550 | } |
5774 | leency | 551 | |
5990 | leency | 552 | GetAbsoluteURL(#URL); |
6730 | leency | 553 | |
554 | if (strncmp(#URL,"http://",7)!=0) |
||
5774 | leency | 555 | { |
6730 | leency | 556 | if (UrlExtIs(".htm")!=true) && (UrlExtIs(".html")!=true) |
557 | { |
||
558 | RunProgram("/sys/@open", #URL); |
||
559 | strcpy(#editURL, history.current()); |
||
560 | strcpy(#URL, history.current()); |
||
561 | return; |
||
562 | } |
||
563 | } |
||
564 | else |
||
565 | { |
||
566 | if (UrlExtIs(".png")==true) || (UrlExtIs(".gif")==true) || (UrlExtIs(".jpg")==true) |
||
6794 | leency | 567 | || (UrlExtIs(".zip")==true) || (UrlExtIs(".kex")==true) || (UrlExtIs(".pdf")==true) |
568 | || (UrlExtIs(".7z")==true) { |
||
6001 | leency | 569 | strcpy(#downloader_edit, #URL); |
5774 | leency | 570 | CreateThread(#Downloader,#downloader_stak+4092); |
6730 | leency | 571 | strcpy(#editURL, history.current()); |
572 | strcpy(#URL, history.current()); |
||
573 | return; |
||
5774 | leency | 574 | } |
575 | } |
||
6931 | leency | 576 | if (open_in_a_new_window) |
577 | { |
||
578 | RunProgram(#program_path, #URL); |
||
579 | strcpy(#editURL, history.current()); |
||
580 | strcpy(#URL, history.current()); |
||
581 | } |
||
582 | else |
||
583 | { |
||
584 | OpenPage(); |
||
585 | } |
||
586 | open_in_a_new_window = false; |
||
5774 | leency | 587 | } |
588 | |||
6795 | leency | 589 | void EventShowPageMenu(dword _left, _top) |
6782 | leency | 590 | { |
591 | menu.show(Form.left+_left-6,Form.top+_top+skin_height+3, 220, #rmb_menu, VIEW_SOURCE); |
||
592 | } |
||
593 | |||
6795 | leency | 594 | void EventShowLinkMenu(dword _left, _top) |
595 | { |
||
596 | menu.show(Form.left+_left-6,Form.top+_top+skin_height+3, 180, #link_menu, COPY_LINK); |
||
597 | } |
||
598 | |||
599 | |||
6794 | leency | 600 | void ShowErrorMessageThatHttpsIsNotSupportedYet() |
601 | { |
||
602 | notify("'HTTPS protocol is not supported yet' -E"); |
||
603 | } |
||
604 | |||
6795 | leency | 605 | DrawStatusBar(dword _status_text) |
606 | { |
||
607 | status_text.start_x = wv_progress_bar.left + wv_progress_bar.width + 10; |
||
608 | status_text.start_y = Form.cheight - STATUSBAR_H + 3; |
||
609 | status_text.area_size_x = Form.cwidth - status_text.start_x -3; |
||
610 | DrawBar(status_text.start_x, status_text.start_y, status_text.area_size_x, 9, col_bg); |
||
611 | status_text.text_pointer = _status_text; |
||
612 | PathShow_prepare stdcall(#status_text); |
||
613 | PathShow_draw stdcall(#status_text); |
||
614 | } |
||
615 | |||
5631 | pavelyakov | 616 | stop:=5) |