Rev 9602 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 9602 | Rev 9644 | ||
---|---|---|---|
1 | //Copyright 2007-2021 by Veliant & Leency |
1 | //Copyright 2007-2021 by Veliant & Leency |
2 | //Asper, lev, Lrz, Barsuk, Nable, hidnplayr... |
2 | //Asper, lev, Lrz, Barsuk, Nable, hidnplayr... |
3 | 3 | ||
4 | //BUGS |
4 | //BUGS |
5 | //if maximize a window on image load => crash |
5 | //if maximize a window on image load => crash |
6 | //issues with a long line |
6 | //issues with a long line |
7 | //add proxy settings |
7 | //add proxy settings |
8 | 8 | ||
9 | //===================================================// |
9 | //===================================================// |
10 | // // |
10 | // // |
11 | // LIB // |
11 | // LIB // |
12 | // // |
12 | // // |
13 | //===================================================// |
13 | //===================================================// |
14 | 14 | ||
15 | #define MEMSIZE 1024 * 160 |
15 | #define MEMSIZE 1024 * 160 |
16 | #include "..\lib\gui.h" |
16 | #include "..\lib\gui.h" |
17 | #include "..\lib\draw_buf.h" |
17 | #include "..\lib\draw_buf.h" |
18 | #include "..\lib\list_box.h" |
18 | #include "..\lib\list_box.h" |
19 | #include "..\lib\cursor.h" |
19 | #include "..\lib\cursor.h" |
20 | #include "..\lib\collection.h" |
20 | #include "..\lib\collection.h" |
21 | #include "..\lib\random.h" |
21 | #include "..\lib\random.h" |
22 | #include "..\lib\clipboard.h" |
22 | #include "..\lib\clipboard.h" |
23 | 23 | ||
24 | #include "..\lib\obj\box_lib.h" |
24 | #include "..\lib\obj\box_lib.h" |
25 | #include "..\lib\obj\libimg.h" |
25 | #include "..\lib\obj\libimg.h" |
26 | #include "..\lib\obj\http.h" |
26 | #include "..\lib\obj\http.h" |
27 | #include "..\lib\obj\iconv.h" |
27 | #include "..\lib\obj\iconv.h" |
28 | #include "..\lib\obj\proc_lib.h" |
28 | #include "..\lib\obj\proc_lib.h" |
29 | #include "..\lib\obj\netcode.h" |
29 | #include "..\lib\obj\netcode.h" |
30 | 30 | ||
31 | #include "..\lib\patterns\history.h" |
31 | #include "..\lib\patterns\history.h" |
32 | #include "..\lib\patterns\simple_open_dialog.h" |
32 | #include "..\lib\patterns\simple_open_dialog.h" |
33 | #include "..\lib\patterns\toolbar_button.h" |
33 | #include "..\lib\patterns\toolbar_button.h" |
34 | #include "..\lib\patterns\restart_process.h" |
34 | #include "..\lib\patterns\restart_process.h" |
35 | 35 | ||
36 | #include "const.h" |
36 | #include "const.h" |
37 | #include "cache.h" |
37 | #include "cache.h" |
38 | #include "show_src.h" |
38 | #include "show_src.h" |
39 | 39 | ||
40 | //===================================================// |
40 | //===================================================// |
41 | // // |
41 | // // |
42 | // DATA // |
42 | // DATA // |
43 | // // |
43 | // // |
44 | //===================================================// |
44 | //===================================================// |
45 | bool debug_mode = false; |
45 | bool debug_mode = false; |
46 | bool show_images = true; |
46 | bool show_images = true; |
47 | bool source_mode = false; |
47 | bool source_mode = false; |
48 | bool application_mode = false; |
48 | bool application_mode = false; |
49 | 49 | ||
50 | _history history; |
50 | _history history; |
51 | 51 | ||
52 | enum { TARGET_SAME_TAB, TARGET_NEW_WINDOW, TARGET_NEW_TAB }; |
52 | enum { TARGET_SAME_TAB, TARGET_NEW_WINDOW, TARGET_NEW_TAB }; |
53 | 53 | ||
54 | #include "TWB\TWB.c" //HTML Parser, a core component |
54 | #include "TWB\TWB.c" //HTML Parser, a core component |
55 | 55 | ||
56 | TWebBrowser WB1; |
56 | TWebBrowser WB1; |
57 | 57 | ||
58 | #include "history.h" |
58 | #include "history.h" |
59 | 59 | ||
60 | dword PADDING = 9; |
60 | dword PADDING = 9; |
61 | dword TSZE = 25; |
61 | dword TSZE = 25; |
62 | dword STATUSBAR_H = 15; |
62 | dword STATUSBAR_H = 15; |
63 | dword TAB_H = 20; |
63 | dword TAB_H = 20; |
64 | dword TOOLBAR_H = 0; |
64 | dword TOOLBAR_H = 0; |
65 | 65 | ||
66 | _http http = 0; |
66 | _http http = 0; |
67 | 67 | ||
68 | progress_bar prbar; |
68 | progress_bar prbar; |
69 | proc_info Form; |
69 | proc_info Form; |
70 | 70 | ||
71 | #include "tabs.h" |
71 | #include "tabs.h" |
72 | 72 | ||
73 | dword cur_img_url; |
73 | dword cur_img_url; |
74 | dword shared_url; |
74 | dword shared_url; |
75 | dword http_get_type=PAGE; |
75 | dword http_get_type=PAGE; |
76 | dword render_start_time; |
76 | dword render_start_time; |
77 | int menu_id=NULL; |
77 | int menu_id=NULL; |
78 | 78 | ||
79 | char default_dir[] = "/sys"; |
79 | char default_dir[] = "/sys"; |
80 | od_filter filter2 = { 22, "TXT\0HTM\0HTML\0DOCX\0\0" }; |
80 | od_filter filter2 = { 22, "TXT\0HTM\0HTML\0DOCX\0\0" }; |
81 | 81 | ||
82 | char editURL[URL_SIZE+1]; |
82 | char editURL[URL_SIZE+1]; |
83 | edit_box omnibox_edit = {, 0, 0, 0xffffff, |
83 | edit_box omnibox_edit = {, 0, 0, 0xffffff, |
84 | 0x94AECE, 0xffffff, 0xffffff,0x10000000,URL_SIZE-2,#editURL,0,,19,19}; |
84 | 0x94AECE, 0xffffff, 0xffffff,0x10000000,URL_SIZE-2,#editURL,0,,19,19}; |
85 | 85 | ||
86 | //===================================================// |
86 | //===================================================// |
87 | // // |
87 | // // |
88 | // CODE // |
88 | // CODE // |
89 | // // |
89 | // // |
90 | //===================================================// |
90 | //===================================================// |
91 | 91 | ||
92 | void LoadLibraries() |
92 | void LoadLibraries() |
93 | { |
93 | { |
94 | load_dll(boxlib, #box_lib_init,0); |
94 | load_dll(boxlib, #box_lib_init,0); |
95 | load_dll(libimg, #libimg_init,1); |
95 | load_dll(libimg, #libimg_init,1); |
96 | load_dll(libHTTP, #http_lib_init,1); |
96 | load_dll(libHTTP, #http_lib_init,1); |
97 | load_dll(iconv_lib, #iconv_open,0); |
97 | load_dll(iconv_lib, #iconv_open,0); |
98 | load_dll(netcode_lib, #base64_encode,0); |
98 | load_dll(netcode_lib, #base64_encode,0); |
99 | load_dll(Proc_lib, #OpenDialog_init,0); |
99 | load_dll(Proc_lib, #OpenDialog_init,0); |
100 | OpenDialog_init stdcall (#o_dialog); |
100 | OpenDialog_init stdcall (#o_dialog); |
101 | } |
101 | } |
102 | 102 | ||
103 | void HandleParam() |
103 | void HandleParam() |
104 | { |
104 | { |
105 | if (!param) { |
105 | if (!param) { |
106 | history.add(DEFAULT_URL); |
106 | history.add(DEFAULT_URL); |
107 | } else { |
107 | } else { |
108 | if (!strncmp(#param, "-source ", 8)) { |
108 | if (!strncmp(#param, "-source ", 8)) { |
109 | source_mode = true; |
109 | source_mode = true; |
110 | history.add(#param + 8); |
110 | history.add(#param + 8); |
111 | } else if (!strncmp(#param, "-new ", 5)) { |
111 | } else if (!strncmp(#param, "-new ", 5)) { |
112 | history.add(#param + 5); |
112 | history.add(#param + 5); |
113 | } else if (!strncmp(#param, "-app ", 5)) { |
113 | } else if (!strncmp(#param, "-app ", 5)) { |
114 | history.add(#param + 5); |
114 | history.add(#param + 5); |
115 | application_mode = true; |
115 | application_mode = true; |
116 | } else { |
116 | } else { |
117 | if (GetProcessesCount("WEBVIEW") == 1) { |
117 | if (GetProcessesCount("WEBVIEW") == 1) { |
118 | history.add(#param); |
118 | history.add(#param); |
119 | } else { |
119 | } else { |
120 | shared_url = memopen(#webview_shared, URL_SIZE+1, SHM_OPEN + SHM_WRITE); |
120 | shared_url = memopen(#webview_shared, URL_SIZE+1, SHM_OPEN + SHM_WRITE); |
121 | strncpy(shared_url, #param, URL_SIZE); |
121 | strncpy(shared_url, #param, URL_SIZE); |
122 | ExitProcess(); |
122 | ExitProcess(); |
123 | } |
123 | } |
124 | } |
124 | } |
125 | } |
125 | } |
126 | shared_url = memopen(#webview_shared, URL_SIZE+1, SHM_CREATE + SHM_WRITE); |
126 | shared_url = memopen(#webview_shared, URL_SIZE+1, SHM_CREATE + SHM_WRITE); |
127 | ESDWORD[shared_url] = '\0'; |
127 | ESDWORD[shared_url] = '\0'; |
128 | } |
128 | } |
129 | 129 | ||
130 | void main() |
130 | void main() |
131 | { |
131 | { |
132 | int redirect_count=0; |
132 | int redirect_count=0; |
133 | 133 | ||
134 | TOOLBAR_H = PADDING+TSZE+PADDING+2; |
134 | TOOLBAR_H = PADDING+TSZE+PADDING+2; |
135 | 135 | ||
136 | LoadLibraries(); |
136 | LoadLibraries(); |
137 | HandleParam(); |
137 | HandleParam(); |
138 | 138 | ||
139 | if (application_mode) { |
139 | if (application_mode) { |
140 | TOOLBAR_H = 0; |
140 | TOOLBAR_H = 0; |
141 | PADDING = 0; |
141 | PADDING = 0; |
142 | TSZE = 0; |
142 | TSZE = 0; |
143 | STATUSBAR_H = 0; |
143 | STATUSBAR_H = 0; |
144 | TAB_H = 0; |
144 | TAB_H = 0; |
145 | } |
145 | } |
146 | 146 | ||
147 | omnibox_edit.left = PADDING+TSZE*2+PADDING+6; |
147 | omnibox_edit.left = PADDING+TSZE*2+PADDING+6; |
148 | omnibox_edit.top = PADDING+3; |
148 | omnibox_edit.top = PADDING+3; |
149 | 149 | ||
150 | WB1.list.SetFont(8, 14, 10011000b); |
150 | WB1.list.SetFont(8, 14, 10011000b); |
151 | WB1.list.no_selection = true; |
151 | WB1.list.no_selection = true; |
152 | WB1.custom_encoding = -1; |
152 | WB1.custom_encoding = -1; |
153 | @SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER + EVM_STACK); |
153 | @SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER + EVM_STACK); |
154 | loop() switch(@WaitEventTimeout(30)) |
154 | loop() switch(@WaitEventTimeout(30)) |
155 | { |
155 | { |
156 | case evMouse: |
156 | case evMouse: |
157 | edit_box_mouse stdcall (#omnibox_edit); |
157 | edit_box_mouse stdcall (#omnibox_edit); |
158 | mouse.get(); |
158 | mouse.get(); |
159 | 159 | ||
160 | if (WB1.list.MouseScroll(mouse.vert)) WB1.DrawPage(); |
160 | if (WB1.list.MouseScroll(mouse.vert)) WB1.DrawPage(); |
161 | 161 | ||
162 | if (WB1.list.count > WB1.list.visible) { |
162 | if (WB1.list.count > WB1.list.visible) { |
163 | scrollbar_v_mouse (#scroll_wv); |
163 | scrollbar_v_mouse (#scroll_wv); |
164 | if (WB1.list.first != scroll_wv.position) { |
164 | if (WB1.list.first != scroll_wv.position) { |
165 | WB1.list.first = scroll_wv.position; |
165 | WB1.list.first = scroll_wv.position; |
166 | WB1.DrawPage(); |
166 | WB1.DrawPage(); |
167 | break; |
167 | break; |
168 | } |
168 | } |
169 | } |
169 | } |
170 | 170 | ||
171 | if (WB1.list.MouseOver(mouse.x, mouse.y)) && (links.hover(WB1.list.y, WB1.list.first)) |
171 | if (WB1.list.MouseOver(mouse.x, mouse.y)) && (links.hover(WB1.list.y, WB1.list.first)) |
172 | { |
172 | { |
173 | if (mouse.key&MOUSE_MIDDLE) && (mouse.up) { |
173 | if (mouse.key&MOUSE_MIDDLE) && (mouse.up) { |
174 | GetKeyModifier(); |
174 | GetKeyModifier(); |
175 | if (key_modifier&KEY_LSHIFT) || (key_modifier&KEY_RSHIFT) { |
175 | if (key_modifier&KEY_LSHIFT) || (key_modifier&KEY_RSHIFT) { |
176 | EventClickLink(TARGET_NEW_WINDOW); |
176 | EventClickLink(TARGET_NEW_WINDOW); |
177 | } else { |
177 | } else { |
178 | EventClickLink(TARGET_NEW_TAB); |
178 | EventClickLink(TARGET_NEW_TAB); |
179 | } |
179 | } |
180 | } |
180 | } |
181 | if (mouse.key&MOUSE_LEFT) && (mouse.up) { |
181 | if (mouse.key&MOUSE_LEFT) && (mouse.up) { |
182 | CursorPointer.Restore(); |
182 | CursorPointer.Restore(); |
183 | EventClickLink(TARGET_SAME_TAB); |
183 | EventClickLink(TARGET_SAME_TAB); |
184 | } |
184 | } |
185 | if (mouse.key&MOUSE_RIGHT) && (mouse.up) { |
185 | if (mouse.key&MOUSE_RIGHT) && (mouse.up) { |
186 | CursorPointer.Restore(); |
186 | CursorPointer.Restore(); |
187 | EventShowLinkMenu(); |
187 | EventShowLinkMenu(); |
188 | } |
188 | } |
189 | } else { |
189 | } else { |
190 | CursorPointer.Restore(); |
190 | CursorPointer.Restore(); |
191 | if (mouse.key&MOUSE_RIGHT) && (mouse.up) && (WB1.list.MouseOver(mouse.x, mouse.y)) { |
191 | if (mouse.key&MOUSE_RIGHT) && (mouse.up) && (WB1.list.MouseOver(mouse.x, mouse.y)) { |
192 | EventShowPageMenu(); |
192 | EventShowPageMenu(); |
193 | } |
193 | } |
194 | } |
194 | } |
195 | break; |
195 | break; |
196 | 196 | ||
197 | case evButton: |
197 | case evButton: |
198 | ProcessButtonClick( @GetButtonID() ); |
198 | ProcessButtonClick( @GetButtonID() ); |
199 | break; |
199 | break; |
200 | 200 | ||
201 | case evKey: |
201 | case evKey: |
202 | @GetKeys(); |
202 | @GetKeys(); |
203 | edit_box_key stdcall(#omnibox_edit); |
203 | edit_box_key stdcall(#omnibox_edit); |
204 | ProcessKeyEvent(); |
204 | ProcessKeyEvent(); |
205 | break; |
205 | break; |
206 | 206 | ||
207 | case evReDraw: |
207 | case evReDraw: |
208 | DefineAndDrawWindow(GetScreenWidth()-WIN_W/2-random(80),GetScreenHeight()-WIN_H/2-random(80), |
208 | DefineAndDrawWindow(GetScreenWidth()-WIN_W/2-random(80),GetScreenHeight()-WIN_H/2-random(80), |
209 | //DefineAndDrawWindow(0,0, |
209 | //DefineAndDrawWindow(0,0, |
210 | WIN_W,WIN_H,0x73,0,0,0); |
210 | WIN_W,WIN_H,0x73,0,0,0); |
211 | GetProcessInfo(#Form, SelfInfo); |
211 | GetProcessInfo(#Form, SelfInfo); |
212 | ProcessMenuClick(); |
212 | ProcessMenuClick(); |
213 | sc.get(); |
213 | sc.get(); |
214 | if (Form.status_window>2) break; |
214 | if (Form.status_window>2) break; |
215 | if (Form.height<120) { MoveSize(OLD,OLD,OLD,120); break; } |
215 | if (Form.height<120) { MoveSize(OLD,OLD,OLD,120); break; } |
216 | if (Form.width<280) { MoveSize(OLD,OLD,280,OLD); break; } |
216 | if (Form.width<280) { MoveSize(OLD,OLD,280,OLD); break; } |
217 | draw_window(); |
217 | draw_window(); |
218 | break; |
218 | break; |
219 | 219 | ||
220 | case evNetwork: |
220 | case evNetwork: |
221 | if (http.transfer <= 0) break; |
221 | if (http.transfer <= 0) break; |
222 | http.receive(); |
222 | http.receive(); |
223 | 223 | ||
224 | if (http_get_type==PAGE) { |
224 | if (http_get_type==PAGE) { |
225 | CheckContentType(); |
225 | CheckContentType(); |
226 | prbar.max = http.content_length; |
226 | prbar.max = http.content_length; |
227 | if (prbar.value != http.content_received) { |
227 | if (prbar.value != http.content_received) { |
228 | prbar.value = http.content_received; |
228 | prbar.value = http.content_received; |
229 | DrawProgress(); |
229 | DrawProgress(); |
230 | } |
230 | } |
231 | } |
231 | } |
232 | 232 | ||
233 | if (http.receive_result != 0) break; |
233 | if (http.receive_result != 0) break; |
234 | if (debug_mode) { |
234 | if (debug_mode) { |
235 | EAX = http.transfer; |
235 | EAX = http.transfer; |
236 | debugln(#EAX.http_msg.http_header); |
236 | debugln(#EAX.http_msg.http_header); |
237 | } |
237 | } |
238 | if (http.status_code >= 300) && (http.status_code < 400) |
238 | if (http.status_code >= 300) && (http.status_code < 400) |
239 | { |
239 | { |
240 | // Handle redirects |
240 | // Handle redirects |
241 | if (redirect_count<=5) { |
241 | if (redirect_count<=5) { |
242 | redirect_count++; |
242 | redirect_count++; |
243 | HandleRedirect(); |
243 | HandleRedirect(); |
244 | } else { |
244 | } else { |
245 | StopLoading(); |
245 | StopLoading(); |
246 | redirect_count = 0; |
246 | redirect_count = 0; |
247 | if (http_get_type==IMG) goto _IMG_RES; |
247 | if (http_get_type==IMG) goto _IMG_RES; |
248 | notify("'Too many redirects.' -E"); |
248 | notify("'Too many redirects.' -E"); |
249 | } |
249 | } |
250 | } else { |
250 | } else { |
251 | // Loading the page is complete, free resources |
251 | // Loading the page is complete, free resources |
252 | redirect_count = 0; |
252 | redirect_count = 0; |
253 | if (http_get_type==PAGE) { |
253 | if (http_get_type==PAGE) { |
254 | history.add(http.cur_url); |
254 | history.add(http.cur_url); |
255 | if (!strchr(http.cur_url, '?')) { |
255 | if (!strchr(http.cur_url, '?')) { |
256 | cache.add(http.cur_url, http.content_pointer, http.content_received, PAGE, WB1.custom_encoding); |
256 | cache.add(http.cur_url, http.content_pointer, http.content_received, PAGE, WB1.custom_encoding); |
257 | } |
257 | } |
258 | LoadInternalPage(http.content_pointer, http.content_received); |
258 | LoadInternalPage(http.content_pointer, http.content_received); |
259 | free(http.content_pointer); |
259 | free(http.content_pointer); |
260 | DrawOmnibox(); |
260 | DrawOmnibox(); |
261 | } |
261 | } |
262 | else if (http_get_type==IMG) { |
262 | else if (http_get_type==IMG) { |
263 | _IMG_RES: |
263 | _IMG_RES: |
264 | if (http.status_code >= 200) && (http.status_code < 300) { |
264 | if (http.status_code >= 200) && (http.status_code < 300) { |
265 | cache.add(cur_img_url, http.content_pointer, http.content_received, IMG, NULL); |
265 | cache.add(cur_img_url, http.content_pointer, http.content_received, IMG, NULL); |
266 | } else { |
266 | } else { |
267 | cache.add(cur_img_url, 0, 0, IMG, NULL); |
267 | cache.add(cur_img_url, 0, 0, IMG, NULL); |
268 | } |
268 | } |
269 | http.hfree(); |
269 | http.hfree(); |
270 | free(http.content_pointer); |
270 | free(http.content_pointer); |
271 | GetImg(false); |
271 | GetImg(false); |
272 | } |
272 | } |
273 | } |
273 | } |
274 | break; |
274 | break; |
275 | default: |
275 | default: |
276 | if (ESDWORD[shared_url] != '\0') { |
276 | if (ESDWORD[shared_url] != '\0') { |
277 | EventOpenNewTab(shared_url); |
277 | EventOpenNewTab(shared_url); |
278 | ESDWORD[shared_url] = '\0'; |
278 | ESDWORD[shared_url] = '\0'; |
279 | ActivateWindow(GetProcessSlot(Form.ID)); |
279 | ActivateWindow(GetProcessSlot(Form.ID)); |
280 | } |
280 | } |
281 | } |
281 | } |
282 | } |
282 | } |
283 | 283 | ||
284 | 284 | ||
285 | //===================================================// |
285 | //===================================================// |
286 | // // |
286 | // // |
287 | // EVENTS // |
287 | // EVENTS // |
288 | // // |
288 | // // |
289 | //===================================================// |
289 | //===================================================// |
290 | 290 | ||
291 | void ProcessButtonClick(dword id__) |
291 | void ProcessButtonClick(dword id__) |
292 | { |
292 | { |
293 | switch (id__) |
293 | switch (id__) |
294 | { |
294 | { |
295 | case 1: ExitProcess(); |
295 | case 1: ExitProcess(); |
296 | case TAB_CLOSE_ID...TAB_CLOSE_ID+TABS_MAX: EventTabClose(id__ - TAB_CLOSE_ID); return; |
296 | case TAB_CLOSE_ID...TAB_CLOSE_ID+TABS_MAX: EventTabClose(id__ - TAB_CLOSE_ID); return; |
297 | case TAB_ID...TAB_ID+TABS_MAX: EventAllTabsClick(id__ - TAB_ID); return; |
297 | case TAB_ID...TAB_ID+TABS_MAX: EventAllTabsClick(id__ - TAB_ID); return; |
298 | case ENCODINGS...ENCODINGS+6: EventManuallyChangeEncoding(id__-ENCODINGS); return; |
298 | case ENCODINGS...ENCODINGS+6: EventManuallyChangeEncoding(id__-ENCODINGS); return; |
299 | case NEW_WINDOW: RunProgram(#program_path, NULL); return; |
299 | case NEW_WINDOW: RunProgram(#program_path, NULL); return; |
300 | case NEW_TAB: if (!http.transfer) EventOpenNewTab(URL_SERVICE_HOMEPAGE); return; |
300 | case NEW_TAB: if (!http.transfer) EventOpenNewTab(URL_SERVICE_HOMEPAGE); return; |
301 | case SCAN_CODE_BS: |
301 | case SCAN_CODE_BS: |
302 | case BACK_BUTTON: if (history.back()) OpenPage(history.current()); return; |
302 | case BACK_BUTTON: if (history.back()) OpenPage(history.current()); return; |
303 | case FORWARD_BUTTON: if (history.forward()) OpenPage(history.current()); return; |
303 | case FORWARD_BUTTON: if (history.forward()) OpenPage(history.current()); return; |
304 | case GOTOURL_BUTTON: EventSubmitOmnibox(); return; |
304 | case GOTOURL_BUTTON: EventSubmitOmnibox(); return; |
305 | case REFRESH_BUTTON: EventRefreshPage(); return; |
305 | case REFRESH_BUTTON: EventRefreshPage(); return; |
306 | case CHANGE_ENCODING: EventShowEncodingsList(); return; |
306 | case CHANGE_ENCODING: EventShowEncodingsList(); return; |
307 | case SANDWICH_BUTTON: EventShowMainMenu(); return; |
307 | case SANDWICH_BUTTON: EventShowMainMenu(); return; |
308 | case VIEW_SOURCE: EventViewSource(); return; |
308 | case VIEW_SOURCE: EventViewSource(); return; |
309 | case EDIT_SOURCE: EventEditSource(); return; |
309 | case EDIT_SOURCE: EventEditSource(); return; |
310 | case VIEW_HISTORY: OpenPage(URL_SERVICE_HISTORY); return; |
310 | case VIEW_HISTORY: OpenPage(URL_SERVICE_HISTORY); return; |
311 | case DOWNLOAD_MANAGER: EventOpenDownloader(""); return; |
311 | case DOWNLOAD_MANAGER: EventOpenDownloader(""); return; |
312 | case UPDATE_BROWSER: EventUpdateBrowser(); return; |
312 | case UPDATE_BROWSER: EventUpdateBrowser(); return; |
313 | case CLEAR_CACHE: EventClearCache(); return; |
313 | case CLEAR_CACHE: EventClearCache(); return; |
314 | case IN_NEW_TAB: EventClickLink(TARGET_NEW_TAB); return; |
314 | case IN_NEW_TAB: EventClickLink(TARGET_NEW_TAB); return; |
315 | case IN_NEW_WINDOW: EventClickLink(TARGET_NEW_WINDOW); return; |
315 | case IN_NEW_WINDOW: EventClickLink(TARGET_NEW_WINDOW); return; |
316 | case COPY_LINK_URL: EventCopyLinkToClipboard(); return; |
316 | case COPY_LINK_URL: EventCopyLinkToClipboard(); return; |
317 | case DOWNLOAD_LINK_CT: EventOpenDownloader( GetAbsoluteActiveURL() ); return; |
317 | case DOWNLOAD_LINK_CT: EventOpenDownloader( GetAbsoluteActiveURL() ); return; |
318 | case OPEN_FILE: EventOpenDialog(); return; |
318 | case OPEN_FILE: EventOpenDialog(); return; |
319 | } |
319 | } |
320 | } |
320 | } |
321 | 321 | ||
322 | void ProcessKeyEvent() |
322 | void ProcessKeyEvent() |
323 | { |
323 | { |
324 | if (key_modifier&KEY_LSHIFT) || (key_modifier&KEY_RSHIFT) |
324 | if (key_modifier&KEY_LSHIFT) || (key_modifier&KEY_RSHIFT) |
325 | { |
325 | { |
326 | if (key_scancode == SCAN_CODE_TAB) {EventActivatePreviousTab();return;} |
326 | if (key_scancode == SCAN_CODE_TAB) {EventActivatePreviousTab();return;} |
327 | if (key_scancode == SCAN_CODE_KEY_T) {EventOpenNewTab(URL_SERVICE_TEST);return;} |
327 | if (key_scancode == SCAN_CODE_KEY_T) {EventOpenNewTab(URL_SERVICE_TEST);return;} |
328 | } |
328 | } |
329 | 329 | ||
330 | if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL) switch(key_scancode) |
330 | if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL) switch(key_scancode) |
331 | { |
331 | { |
332 | case SCAN_CODE_KEY_O: EventOpenDialog(); return; |
332 | case SCAN_CODE_KEY_O: EventOpenDialog(); return; |
333 | case SCAN_CODE_KEY_H: ProcessButtonClick(VIEW_HISTORY); return; |
333 | case SCAN_CODE_KEY_H: ProcessButtonClick(VIEW_HISTORY); return; |
334 | case SCAN_CODE_KEY_U: EventViewSource(); return; |
334 | case SCAN_CODE_KEY_U: EventViewSource(); return; |
335 | case SCAN_CODE_KEY_T: EventOpenNewTab(URL_SERVICE_HOMEPAGE); return; |
335 | case SCAN_CODE_KEY_T: EventOpenNewTab(URL_SERVICE_HOMEPAGE); return; |
336 | case SCAN_CODE_KEY_N: RunProgram(#program_path, NULL); return; |
336 | case SCAN_CODE_KEY_N: RunProgram(#program_path, NULL); return; |
337 | case SCAN_CODE_KEY_J: ProcessButtonClick(DOWNLOAD_MANAGER); return; |
337 | case SCAN_CODE_KEY_J: ProcessButtonClick(DOWNLOAD_MANAGER); return; |
338 | case SCAN_CODE_KEY_R: ProcessButtonClick(REFRESH_BUTTON); return; |
338 | case SCAN_CODE_KEY_R: ProcessButtonClick(REFRESH_BUTTON); return; |
339 | case SCAN_CODE_ENTER: EventSeachWeb(); return; |
339 | case SCAN_CODE_ENTER: EventSeachWeb(); return; |
340 | case SCAN_CODE_LEFT: ProcessButtonClick(BACK_BUTTON); return; |
340 | case SCAN_CODE_LEFT: ProcessButtonClick(BACK_BUTTON); return; |
341 | case SCAN_CODE_RIGHT: ProcessButtonClick(FORWARD_BUTTON); return; |
341 | case SCAN_CODE_RIGHT: ProcessButtonClick(FORWARD_BUTTON); return; |
342 | case SCAN_CODE_KEY_W: EventCloseActiveTab(); return; |
342 | case SCAN_CODE_KEY_W: EventCloseActiveTab(); return; |
343 | case SCAN_CODE_TAB: EventActivateNextTab(); return; |
343 | case SCAN_CODE_TAB: EventActivateNextTab(); return; |
344 | case SCAN_CODE_F5: EventClearCache(); return; |
344 | case SCAN_CODE_F5: EventClearCache(); return; |
345 | default: return; |
345 | default: return; |
346 | } |
346 | } |
347 | 347 | ||
348 | switch(key_scancode) |
348 | switch(key_scancode) |
349 | { |
349 | { |
350 | case SCAN_CODE_UP: EventScrollUpAndDown(SCAN_CODE_UP); return; |
350 | case SCAN_CODE_UP: EventScrollUpAndDown(SCAN_CODE_UP); return; |
351 | case SCAN_CODE_DOWN: EventScrollUpAndDown(SCAN_CODE_DOWN); return; |
351 | case SCAN_CODE_DOWN: EventScrollUpAndDown(SCAN_CODE_DOWN); return; |
352 | case SCAN_CODE_F6: {omnibox_edit.flags=ed_focus; DrawOmnibox();} return; |
352 | case SCAN_CODE_F6: {omnibox_edit.flags=ed_focus; DrawOmnibox();} return; |
353 | case SCAN_CODE_F5: EventRefreshPage(); return; |
353 | case SCAN_CODE_F5: EventRefreshPage(); return; |
354 | case SCAN_CODE_ENTER: if (omnibox_edit.flags & ed_focus) EventSubmitOmnibox(); return; |
354 | case SCAN_CODE_ENTER: if (omnibox_edit.flags & ed_focus) EventSubmitOmnibox(); return; |
355 | case SCAN_CODE_F12: EventToggleDebugMode(); return; |
355 | case SCAN_CODE_F12: EventToggleDebugMode(); return; |
356 | case SCAN_CODE_F11: show_images^=1; EventClearCache(); return; |
356 | case SCAN_CODE_F11: show_images^=1; EventClearCache(); return; |
357 | default: if (WB1.list.ProcessKey(key_scancode)) WB1.DrawPage(); return; |
357 | default: if (WB1.list.ProcessKey(key_scancode)) WB1.DrawPage(); return; |
358 | } |
358 | } |
359 | } |
359 | } |
360 | 360 | ||
361 | void SetElementSizes() |
361 | void SetElementSizes() |
362 | { |
362 | { |
363 | omnibox_edit.width = Form.cwidth - omnibox_edit.left - 52 - 16; |
363 | omnibox_edit.width = Form.cwidth - omnibox_edit.left - 52 - 16; |
364 | if (Form.cwidth - scroll_wv.size_x != WB1.list.w) { |
364 | if (Form.cwidth - scroll_wv.size_x != WB1.list.w) { |
365 | //temporary fix for crash |
365 | //temporary fix for crash |
366 | //related to 'cur_img_url' var read |
366 | //related to 'cur_img_url' var read |
367 | //http://board.kolibrios.org/viewtopic.php?f=1&t=1712&start=60#p77523 |
367 | //http://board.kolibrios.org/viewtopic.php?f=1&t=1712&start=60#p77523 |
368 | StopLoading(); |
368 | StopLoading(); |
369 | } |
369 | } |
370 | WB1.list.SetSizes(0, TOOLBAR_H+TAB_H, Form.cwidth - scroll_wv.size_x, |
370 | WB1.list.SetSizes(0, TOOLBAR_H+TAB_H, Form.cwidth - scroll_wv.size_x, |
371 | Form.cheight - TOOLBAR_H - STATUSBAR_H - TAB_H, BASIC_LINE_H); |
371 | Form.cheight - TOOLBAR_H - STATUSBAR_H - TAB_H, BASIC_LINE_H); |
372 | WB1.list.wheel_size = 7 * BASIC_LINE_H; |
372 | WB1.list.wheel_size = 7 * BASIC_LINE_H; |
373 | WB1.list.column_max = WB1.list.w - scroll_wv.size_x / WB1.list.font_w + 1; |
373 | WB1.list.column_max = WB1.list.w - scroll_wv.size_x / WB1.list.font_w + 1; |
374 | WB1.list.visible = WB1.list.h; |
374 | WB1.list.visible = WB1.list.h; |
375 | } |
375 | } |
376 | 376 | ||
377 | 377 | ||
378 | void draw_window() |
378 | void draw_window() |
379 | { |
379 | { |
380 | bool burger_active = false; |
380 | bool burger_active = false; |
381 | if (menu_id == OPEN_FILE) burger_active = true; |
381 | if (menu_id == OPEN_FILE) burger_active = true; |
382 | 382 | ||
383 | SetElementSizes(); |
383 | SetElementSizes(); |
384 | 384 | ||
385 | if (!application_mode) { |
385 | if (!application_mode) { |
386 | DrawBar(0,0, Form.cwidth,PADDING, sc.work); |
386 | DrawBar(0,0, Form.cwidth,PADDING, sc.work); |
387 | DrawBar(0,PADDING+TSZE+1, Form.cwidth,PADDING-1, sc.work); |
387 | DrawBar(0,PADDING+TSZE+1, Form.cwidth,PADDING-1, sc.work); |
388 | DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, MixColors(sc.dark, sc.work, 180)); |
388 | DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, MixColors(sc.dark, sc.work, 180)); |
389 | DrawBar(0,TOOLBAR_H-1, Form.cwidth,1, sc.line); |
389 | DrawBar(0,TOOLBAR_H-1, Form.cwidth,1, sc.line); |
390 | DrawBar(0, PADDING, omnibox_edit.left-2, TSZE+1, sc.work); |
390 | DrawBar(0, PADDING, omnibox_edit.left-2, TSZE+1, sc.work); |
391 | DrawBar(omnibox_edit.left+omnibox_edit.width+18, PADDING, Form.cwidth-omnibox_edit.left-omnibox_edit.width-18, TSZE+1, sc.work); |
391 | DrawBar(omnibox_edit.left+omnibox_edit.width+18, PADDING, Form.cwidth-omnibox_edit.left-omnibox_edit.width-18, TSZE+1, sc.work); |
392 | 392 | ||
393 | DrawTopPanelButton(BACK_BUTTON, PADDING-1, PADDING, 30, false); |
393 | DrawTopPanelButton(BACK_BUTTON, PADDING-1, PADDING, 30, false); |
394 | DrawTopPanelButton(FORWARD_BUTTON, PADDING+TSZE+PADDING-2, PADDING, 31, false); |
394 | DrawTopPanelButton(FORWARD_BUTTON, PADDING+TSZE+PADDING-2, PADDING, 31, false); |
395 | DrawTopPanelButton(SANDWICH_BUTTON, Form.cwidth-PADDING-TSZE-3, PADDING, -1, burger_active); //burger menu |
395 | DrawTopPanelButton(SANDWICH_BUTTON, Form.cwidth-PADDING-TSZE-3, PADDING, -1, burger_active); //burger menu |
396 | 396 | ||
397 | DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, sc.line); |
397 | DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, sc.line); |
398 | 398 | ||
399 | DrawRectangle(WB1.list.x + WB1.list.w, WB1.list.y, scroll_wv.size_x, |
399 | DrawRectangle(WB1.list.x + WB1.list.w, WB1.list.y, scroll_wv.size_x, |
400 | WB1.list.h-1, scroll_wv.bckg_col); |
400 | WB1.list.h-1, scroll_wv.bckg_col); |
401 | } |
401 | } |
402 | 402 | ||
403 | if (!canvas.bufw) { |
403 | if (!canvas.bufw) { |
404 | EventOpenFirstPage(); |
404 | EventOpenFirstPage(); |
405 | } else { |
405 | } else { |
406 | WB1.DrawPage(); |
406 | WB1.DrawPage(); |
407 | DrawOmnibox(); |
407 | DrawOmnibox(); |
408 | } |
408 | } |
409 | if (!application_mode) { |
409 | if (!application_mode) { |
410 | DrawProgress(); |
410 | DrawProgress(); |
411 | DrawStatusBar(NULL); |
411 | DrawStatusBar(NULL); |
412 | DrawTabsBar(); |
412 | DrawTabsBar(); |
413 | } |
413 | } |
414 | 414 | ||
415 | } |
415 | } |
416 | 416 | ||
417 | void EventOpenFirstPage() |
417 | void EventOpenFirstPage() |
418 | { |
418 | { |
419 | OpenPage(history.current()); |
419 | OpenPage(history.current()); |
420 | } |
420 | } |
421 | 421 | ||
422 | void EventManuallyChangeEncoding(int _new_encoding) |
422 | void EventManuallyChangeEncoding(int _new_encoding) |
423 | { |
423 | { |
424 | dword newbuf, newsize; |
424 | dword newbuf, newsize; |
425 | WB1.custom_encoding = _new_encoding; |
425 | WB1.custom_encoding = _new_encoding; |
426 | newsize = strlen(WB1.o_bufpointer); |
426 | newsize = strlen(WB1.o_bufpointer); |
427 | newbuf = malloc(newsize); |
427 | newbuf = malloc(newsize); |
428 | memmov(newbuf, WB1.o_bufpointer, newsize); |
428 | memmov(newbuf, WB1.o_bufpointer, newsize); |
429 | LoadInternalPage(newbuf, newsize); |
429 | LoadInternalPage(newbuf, newsize); |
430 | free(newbuf); |
430 | free(newbuf); |
431 | } |
431 | } |
432 | 432 | ||
433 | 433 | ||
434 | void EventScrollUpAndDown(int _direction) |
434 | void EventScrollUpAndDown(int _direction) |
435 | { |
435 | { |
436 | int i; |
436 | int i; |
437 | for (i=0;i |
437 | for (i=0;i |
438 | if (_direction == SCAN_CODE_UP) WB1.list.KeyUp(); |
438 | if (_direction == SCAN_CODE_UP) WB1.list.KeyUp(); |
439 | if (_direction == SCAN_CODE_DOWN) WB1.list.KeyDown(); |
439 | if (_direction == SCAN_CODE_DOWN) WB1.list.KeyDown(); |
440 | } |
440 | } |
441 | WB1.DrawPage(); |
441 | WB1.DrawPage(); |
442 | } |
442 | } |
443 | 443 | ||
444 | void EventToggleDebugMode() |
444 | void EventToggleDebugMode() |
445 | { |
445 | { |
446 | debug_mode ^= 1; |
446 | debug_mode ^= 1; |
447 | if (debug_mode) notify("'Debug mode ON'-I"); |
447 | if (debug_mode) notify("'Debug mode ON'-I"); |
448 | else notify("'Debug mode OFF'-I"); |
448 | else notify("'Debug mode OFF'-I"); |
449 | } |
449 | } |
450 | 450 | ||
451 | void EventAllTabsClick(dword _n) |
451 | void EventAllTabsClick(dword _n) |
452 | { |
452 | { |
453 | if (mouse.mkm) { |
453 | if (mouse.mkm) { |
454 | StopLoading(); |
454 | StopLoading(); |
455 | EventTabClose(_n); |
455 | EventTabClose(_n); |
456 | } else { |
456 | } else { |
457 | if (!http.transfer) EventTabClick(_n); |
457 | if (!http.transfer) EventTabClick(_n); |
458 | } |
458 | } |
459 | } |
459 | } |
460 | 460 | ||
461 | void EventEditSource() |
461 | void EventEditSource() |
462 | { |
462 | { |
463 | if (check_is_the_adress_local(history.current())) { |
463 | if (check_is_the_adress_local(history.current())) { |
464 | RunProgram("/sys/develop/cedit", history.current()); |
464 | RunProgram("/sys/develop/cedit", history.current()); |
465 | } else { |
465 | } else { |
466 | CreateFile(WB1.bufsize, WB1.bufpointer, "/tmp0/1/WebView_tmp.htm"); |
466 | CreateFile(WB1.bufsize, WB1.bufpointer, "/tmp0/1/WebView_tmp.htm"); |
467 | if (!EAX) RunProgram("/sys/develop/cedit", "/tmp0/1/WebView_tmp.htm"); |
467 | if (!EAX) RunProgram("/sys/develop/cedit", "/tmp0/1/WebView_tmp.htm"); |
468 | } |
468 | } |
469 | } |
469 | } |
470 | 470 | ||
471 | void EventClearCache() |
471 | void EventClearCache() |
472 | { |
472 | { |
473 | cache.clear(); |
473 | cache.clear(); |
474 | notify(#clear_cache_ok); |
474 | notify(#clear_cache_ok); |
475 | EventRefreshPage(); |
475 | EventRefreshPage(); |
476 | } |
476 | } |
477 | 477 | ||
478 | void EventCopyLinkToClipboard() |
478 | void EventCopyLinkToClipboard() |
479 | { |
479 | { |
480 | Clipboard__CopyText(GetAbsoluteActiveURL()); |
480 | Clipboard__CopyText(GetAbsoluteActiveURL()); |
481 | notify("'URL copied to clipboard'O"); |
481 | notify("'URL copied to clipboard'O"); |
482 | } |
482 | } |
483 | 483 | ||
484 | void StopLoading() |
484 | void StopLoading() |
485 | { |
485 | { |
486 | if (http.stop()) pause(10); |
486 | if (http.stop()) pause(10); |
487 | prbar.value = 0; |
487 | prbar.value = 0; |
488 | } |
488 | } |
489 | 489 | ||
490 | //rewrite into |
490 | //rewrite into |
491 | //bool strrpl(dword dst, from, into, dst_len); |
491 | //bool strrpl(dword dst, from, into, dst_len); |
492 | bool ReplaceSpaceInUrl(dword url, size) { |
492 | bool ReplaceSpaceInUrl(dword url, size) { |
493 | unsigned int i, j; |
493 | unsigned int i, j; |
494 | bool was_changed=false; |
494 | bool was_changed=false; |
495 | for (i=url+size-3; i>url; i--) |
495 | for (i=url+size-3; i>url; i--) |
496 | { |
496 | { |
497 | if (ESBYTE[i]!=' ') continue; |
497 | if (ESBYTE[i]!=' ') continue; |
498 | for (j=url+size-3; j>=i; j--) { |
498 | for (j=url+size-3; j>=i; j--) { |
499 | ESBYTE[j+3]=ESBYTE[j+2]; |
499 | ESBYTE[j+3]=ESBYTE[j+2]; |
500 | ESBYTE[j+2]=ESBYTE[j+1]; |
500 | ESBYTE[j+2]=ESBYTE[j+1]; |
501 | ESBYTE[j+1]=ESBYTE[j]; |
501 | ESBYTE[j+1]=ESBYTE[j]; |
502 | } |
502 | } |
503 | ESBYTE[i] = '%'; |
503 | ESBYTE[i] = '%'; |
504 | ESBYTE[i+1] = '2'; |
504 | ESBYTE[i+1] = '2'; |
505 | ESBYTE[i+2] = '0'; |
505 | ESBYTE[i+2] = '0'; |
506 | was_changed = true; |
506 | was_changed = true; |
507 | } |
507 | } |
508 | return was_changed; |
508 | return was_changed; |
509 | } |
509 | } |
510 | 510 | ||
511 | bool HandleUrlFiles(dword _path, _data) |
511 | bool HandleUrlFiles(dword _path, _data) |
512 | { |
512 | { |
513 | dword url_from_file; |
513 | dword url_from_file; |
514 | if (!UrlExtIs(_path, "url")) return false; |
514 | if (!UrlExtIs(_path, "url")) return false; |
515 | if (! url_from_file = strstri(_data, "URL=")) return false; |
515 | if (! url_from_file = strstri(_data, "URL=")) return false; |
516 | replace_char(url_from_file, '\n', '\0', strlen(url_from_file)); |
516 | replace_char(url_from_file, '\n', '\0', strlen(url_from_file)); |
517 | OpenPage(url_from_file); |
517 | OpenPage(url_from_file); |
518 | return true; |
518 | return true; |
519 | } |
519 | } |
520 | 520 | ||
521 | bool GetLocalFileData(dword _path) |
521 | bool GetLocalFileData(dword _path) |
522 | { |
522 | { |
523 | dword data, size; |
523 | dword data, size; |
524 | read_file(_path, #data, #size); |
524 | read_file(_path, #data, #size); |
525 | if (!HandleUrlFiles(_path, data)) { |
525 | if (!HandleUrlFiles(_path, data)) { |
526 | LoadInternalPage(data, size); |
526 | LoadInternalPage(data, size); |
527 | } |
527 | } |
528 | free(data); |
528 | free(data); |
529 | return true; |
529 | return true; |
530 | } |
530 | } |
531 | 531 | ||
532 | bool GetUrl(dword _http_url) |
532 | bool GetUrl(dword _http_url) |
533 | { |
533 | { |
534 | char new_url_full[URL_SIZE+1]; |
534 | char new_url_full[URL_SIZE+1]; |
535 | 535 | ||
536 | if (!strncmp(_http_url,"http:",5)) { |
536 | if (!strncmp(_http_url,"http:",5)) { |
537 | http.get(_http_url); |
537 | http.get(_http_url); |
538 | return true; |
538 | return true; |
539 | } else if (!strncmp(_http_url,"https://",8)) { |
539 | } else if (!strncmp(_http_url,"https://",8)) { |
540 | strcpy(#new_url_full, "http://gate.aspero.pro/?site="); |
540 | strcpy(#new_url_full, "http://gate.aspero.pro/?site="); |
541 | strncat(#new_url_full, _http_url, URL_SIZE); |
541 | strncat(#new_url_full, _http_url, URL_SIZE); |
542 | http.get(#new_url_full); |
542 | http.get(#new_url_full); |
543 | return true; |
543 | return true; |
544 | } |
544 | } |
545 | return false; |
545 | return false; |
546 | } |
546 | } |
547 | 547 | ||
548 | void OpenPage(dword _open_URL) |
548 | void OpenPage(dword _open_URL) |
549 | { |
549 | { |
550 | char new_url[URL_SIZE+1]; |
550 | char new_url[URL_SIZE+1]; |
551 | int unz_id; |
551 | int unz_id; |
552 | 552 | ||
553 | StopLoading(); |
553 | StopLoading(); |
554 | 554 | ||
555 | SetOmniboxText(_open_URL); |
555 | SetOmniboxText(_open_URL); |
556 | 556 | ||
557 | strncpy(#new_url, _open_URL, URL_SIZE); |
557 | strncpy(#new_url, _open_URL, URL_SIZE); |
558 | 558 | ||
559 | //Exclude # from the URL to the load page |
559 | //Exclude # from the URL to the load page |
560 | //We will bring it back when we get the buffer |
560 | //We will bring it back when we get the buffer |
561 | if (strrchr(#new_url, '#')) { |
561 | if (strrchr(#new_url, '#')) { |
562 | anchors.take_anchor_from(#new_url); |
562 | anchors.take_anchor_from(#new_url); |
563 | } |
563 | } |
564 | 564 | ||
565 | /* |
565 | /* |
566 | There could be several possible types of addresses: |
566 | There could be several possible types of addresses: |
567 | - cached page (only http/https) |
567 | - cached page (only http/https) |
568 | - internal page |
568 | - internal page |
569 | - web page |
569 | - web page |
570 | - local file |
570 | - local file |
571 | So we need to detect what incoming address is |
571 | So we need to detect what incoming address is |
572 | and then halndle it in the propper way. |
572 | and then halndle it in the propper way. |
573 | */ |
573 | */ |
574 | 574 | ||
575 | if (cache.has(#new_url)) { |
575 | if (cache.has(#new_url)) { |
576 | //CACHED PAGE |
576 | //CACHED PAGE |
577 | if (cache.current_type==PAGE) { |
577 | if (cache.current_type==PAGE) { |
578 | history.add(#new_url); |
578 | history.add(#new_url); |
579 | WB1.custom_encoding = cache.current_charset; |
579 | WB1.custom_encoding = cache.current_charset; |
580 | LoadInternalPage(cache.current_buf, cache.current_size); |
580 | LoadInternalPage(cache.current_buf, cache.current_size); |
581 | } |
581 | } |
582 | else { |
582 | else { |
583 | EventDownloadAndOpenImage(#new_url); |
583 | EventDownloadAndOpenImage(#new_url); |
584 | } |
584 | } |
585 | 585 | ||
586 | } else if (!strncmp(#new_url,"WebView:",8)) { |
586 | } else if (!strncmp(#new_url,"WebView:",8)) { |
587 | //INTERNAL PAGE |
587 | //INTERNAL PAGE |
588 | history.add(#new_url); |
588 | history.add(#new_url); |
589 | WB1.custom_encoding = -1; |
589 | WB1.custom_encoding = -1; |
590 | if (streq(#new_url, URL_SERVICE_HOMEPAGE)) LoadInternalPage(#buildin_page_home, sizeof(buildin_page_home)); |
590 | if (streq(#new_url, URL_SERVICE_HOMEPAGE)) LoadInternalPage(#buildin_page_home, sizeof(buildin_page_home)); |
591 | else if (streq(#new_url, URL_SERVICE_HELP)) LoadInternalPage(#buildin_page_help, sizeof(buildin_page_help)); |
591 | else if (streq(#new_url, URL_SERVICE_HELP)) LoadInternalPage(#buildin_page_help, sizeof(buildin_page_help)); |
592 | else if (streq(#new_url, URL_SERVICE_TEST)) LoadInternalPage(#buildin_page_test, sizeof(buildin_page_test)); |
592 | else if (streq(#new_url, URL_SERVICE_TEST)) LoadInternalPage(#buildin_page_test, sizeof(buildin_page_test)); |
593 | else if (streq(#new_url, URL_SERVICE_HISTORY)) ShowHistory(); |
593 | else if (streq(#new_url, URL_SERVICE_HISTORY)) ShowHistory(); |
594 | else LoadInternalPage(#buildin_page_error, sizeof(buildin_page_error)); |
594 | else LoadInternalPage(#buildin_page_error, sizeof(buildin_page_error)); |
595 | 595 | ||
596 | } else if (!strncmp(#new_url,"http:",5)) || (!strncmp(#new_url,"https:",6)) { |
596 | } else if (!strncmp(#new_url,"http:",5)) || (!strncmp(#new_url,"https:",6)) { |
597 | //WEB PAGE |
597 | //WEB PAGE |
598 | if (ReplaceSpaceInUrl(#new_url, URL_SIZE)) { |
598 | if (ReplaceSpaceInUrl(#new_url, URL_SIZE)) { |
599 | strcpy(#editURL, #new_url); |
599 | strcpy(#editURL, #new_url); |
600 | } |
600 | } |
601 | 601 | ||
602 | http_get_type = PAGE; |
602 | http_get_type = PAGE; |
603 | GetUrl(#new_url); |
603 | GetUrl(#new_url); |
604 | 604 | ||
605 | DrawOmnibox(); |
605 | DrawOmnibox(); |
606 | 606 | ||
607 | if (!http.transfer) { |
607 | if (!http.transfer) { |
608 | history.add(#new_url); |
608 | history.add(#new_url); |
609 | LoadInternalPage(#buildin_page_error, sizeof(buildin_page_error)); |
609 | LoadInternalPage(#buildin_page_error, sizeof(buildin_page_error)); |
610 | } |
610 | } |
611 | } else { |
611 | } else { |
612 | //LOCAL PAGE |
612 | //LOCAL PAGE |
613 | history.add(#new_url); |
613 | history.add(#new_url); |
614 | if (UrlExtIs(#new_url,".docx")) { |
614 | if (UrlExtIs(#new_url,".docx")) { |
615 | DeleteFile("/tmp0/1/temp/word/document.xml"); |
615 | DeleteFile("/tmp0/1/temp/word/document.xml"); |
616 | CreateDir("/tmp0/1/temp"); |
616 | CreateDir("/tmp0/1/temp"); |
617 | unz_id = RunProgram("/sys/unz", sprintf(#param, "-o \"/tmp0/1/temp\" -h \"%s\"", #new_url)); |
617 | unz_id = RunProgram("/sys/unz", sprintf(#param, "-o \"/tmp0/1/temp\" -h \"%s\"", #new_url)); |
618 | while (GetProcessSlot(unz_id)) pause(2); |
618 | while (GetProcessSlot(unz_id)) pause(2); |
619 | strcpy(#new_url, "/tmp0/1/temp/word/document.xml"); |
619 | strcpy(#new_url, "/tmp0/1/temp/word/document.xml"); |
620 | } |
620 | } |
621 | if (!GetLocalFileData(#new_url)) { |
621 | if (!GetLocalFileData(#new_url)) { |
622 | LoadInternalPage(#buildin_page_error, sizeof(buildin_page_error)); |
622 | LoadInternalPage(#buildin_page_error, sizeof(buildin_page_error)); |
623 | } |
623 | } |
624 | } |
624 | } |
625 | } |
625 | } |
626 | 626 | ||
627 | dword EventOpenDownloader(dword _url) |
627 | dword EventOpenDownloader(dword _url) |
628 | { |
628 | { |
629 | //char download_params[URL_SIZE+50]; |
629 | //char download_params[URL_SIZE+50]; |
630 | return RunProgram("/sys/network/dl", _url); |
630 | return RunProgram("/sys/network/dl", _url); |
631 | } |
631 | } |
632 | 632 | ||
633 | bool EventClickAnchor() |
633 | bool EventClickAnchor() |
634 | { |
634 | { |
635 | dword aURL = links.active_url; |
635 | dword aURL = links.active_url; |
636 | 636 | ||
637 | if (anchors.get_pos_by_name(aURL+1)!=-1) { |
637 | if (anchors.get_pos_by_name(aURL+1)!=-1) { |
638 | WB1.list.first = anchors.get_pos_by_name(aURL+1); |
638 | WB1.list.first = anchors.get_pos_by_name(aURL+1); |
639 | WB1.list.CheckDoesValuesOkey(); |
639 | WB1.list.CheckDoesValuesOkey(); |
640 | strcpy(#editURL, history.current()); |
640 | strcpy(#editURL, history.current()); |
641 | strcat(#editURL, aURL); |
641 | strcat(#editURL, aURL); |
642 | DrawOmnibox(); |
642 | DrawOmnibox(); |
643 | WB1.DrawPage(); |
643 | WB1.DrawPage(); |
644 | return true; |
644 | return true; |
645 | } |
645 | } |
646 | return false; |
646 | return false; |
647 | } |
647 | } |
648 | 648 | ||
649 | void EventClickLink(dword _target) |
649 | void EventClickLink(dword _target) |
650 | { |
650 | { |
651 | char new_url[URL_SIZE+1]; |
651 | char new_url[URL_SIZE+1]; |
652 | char new_url_full[URL_SIZE+1]; |
652 | char new_url_full[URL_SIZE+1]; |
653 | dword aURL = GetAbsoluteActiveURL(); |
653 | dword aURL = GetAbsoluteActiveURL(); |
654 | if (!aURL) return; |
654 | if (!aURL) return; |
655 | 655 | ||
656 | strcpy(#new_url, aURL); |
656 | strcpy(#new_url, aURL); |
657 | 657 | ||
658 | if (ESBYTE[aURL]=='#') { |
658 | if (ESBYTE[aURL]=='#') { |
659 | if (_target == TARGET_SAME_TAB) { |
659 | if (_target == TARGET_SAME_TAB) { |
660 | EventClickAnchor(); |
660 | EventClickAnchor(); |
661 | return; |
661 | return; |
662 | } else { |
662 | } else { |
663 | strcpy(#new_url, history.current()); |
663 | strcpy(#new_url, history.current()); |
664 | strcat(#new_url, aURL); |
664 | strcat(#new_url, aURL); |
665 | } |
665 | } |
666 | } |
666 | } |
667 | 667 | ||
668 | if (_target == TARGET_NEW_TAB) { |
668 | if (_target == TARGET_NEW_TAB) { |
669 | EventOpenNewTab(#new_url); |
669 | EventOpenNewTab(#new_url); |
670 | return; |
670 | return; |
671 | } |
671 | } |
672 | 672 | ||
673 | if (_target == TARGET_NEW_WINDOW) { |
673 | if (_target == TARGET_NEW_WINDOW) { |
674 | strcpy(#new_url_full, "-new "); |
674 | strcpy(#new_url_full, "-new "); |
675 | strncat(#new_url_full, #new_url, URL_SIZE); |
675 | strncat(#new_url_full, #new_url, URL_SIZE); |
676 | RunProgram(#program_path, #new_url_full); |
676 | RunProgram(#program_path, #new_url_full); |
677 | return; |
677 | return; |
678 | } |
678 | } |
679 | 679 | ||
680 | if (!strncmp(#new_url,"mailto:", 7)) || (!strncmp(#new_url,"tel:", 4)) { |
680 | if (!strncmp(#new_url,"mailto:", 7)) || (!strncmp(#new_url,"tel:", 4)) { |
681 | notify(#new_url); |
681 | notify(#new_url); |
682 | return; |
682 | return; |
683 | } |
683 | } |
684 | 684 | ||
685 | if (http.transfer) { |
685 | if (http.transfer) { |
686 | StopLoading(); |
686 | StopLoading(); |
687 | } |
687 | } |
688 | 688 | ||
689 | if (strrchr(#new_url, '#')!=0) { |
689 | if (strrchr(#new_url, '#')!=0) { |
690 | anchors.take_anchor_from(#new_url); |
690 | anchors.take_anchor_from(#new_url); |
691 | OpenPage(#new_url); |
691 | OpenPage(#new_url); |
692 | return; |
692 | return; |
693 | } |
693 | } |
694 | 694 | ||
695 | if (!strncmp(#new_url,"WebView:",8)) { |
695 | if (!strncmp(#new_url,"WebView:",8)) { |
696 | OpenPage(#new_url); |
696 | OpenPage(#new_url); |
697 | return; |
697 | return; |
698 | } |
698 | } |
699 | 699 | ||
700 | if (strncmp(#new_url,"http://",7)!=0) && (strncmp(#new_url,"https://",8)!=0) |
700 | if (strncmp(#new_url,"http://",7)!=0) && (strncmp(#new_url,"https://",8)!=0) |
701 | { |
701 | { |
702 | if (UrlExtIs(#new_url,".htm")!=true) && (UrlExtIs(#new_url,".html")!=true) |
702 | if (UrlExtIs(#new_url,".htm")!=true) && (UrlExtIs(#new_url,".html")!=true) |
703 | { |
703 | { |
704 | if (strchr(#new_url, '|')) { |
704 | if (strchr(#new_url, '|')) { |
705 | ESBYTE[strchr(#new_url, '|')] = NULL; |
705 | ESBYTE[strchr(#new_url, '|')] = NULL; |
706 | RunProgram(#new_url, strlen(#new_url)+1+#new_url); |
706 | RunProgram(#new_url, strlen(#new_url)+1+#new_url); |
707 | } else { |
707 | } else { |
708 | RunProgram("/sys/@open", #new_url); |
708 | RunProgram("/sys/@open", #new_url); |
709 | } |
709 | } |
710 | return; |
710 | return; |
711 | } |
711 | } |
712 | } |
712 | } |
713 | OpenPage(#new_url); |
713 | OpenPage(#new_url); |
714 | } |
714 | } |
715 | 715 | ||
716 | void EventSubmitOmnibox() |
716 | void EventSubmitOmnibox() |
717 | { |
717 | { |
718 | char new_url[URL_SIZE+1]; |
718 | char new_url[URL_SIZE+1]; |
719 | if (!editURL[0]) return; |
719 | if (!editURL[0]) return; |
720 | if (!strncmp(#editURL,"http:",5)) || (editURL[0]=='/') |
720 | if (!strncmp(#editURL,"http:",5)) || (editURL[0]=='/') |
721 | || (!strncmp(#editURL,"https:",6)) || (!strncmp(#editURL,"WebView:",8)) { |
721 | || (!strncmp(#editURL,"https:",6)) || (!strncmp(#editURL,"WebView:",8)) { |
722 | OpenPage(#editURL); |
722 | OpenPage(#editURL); |
723 | } else { |
723 | } else { |
724 | strcpy(#new_url, "http://"); |
724 | strcpy(#new_url, "http://"); |
725 | strncat(#new_url, #editURL, URL_SIZE-1); |
725 | strncat(#new_url, #editURL, URL_SIZE-1); |
726 | OpenPage(#new_url); |
726 | OpenPage(#new_url); |
727 | } |
727 | } |
728 | } |
728 | } |
729 | 729 | ||
730 | void LoadInternalPage(dword _bufdata, _in_bufsize){ |
730 | void LoadInternalPage(dword _bufdata, _in_bufsize){ |
731 | if (!_bufdata) || (!_in_bufsize) { |
731 | if (!_bufdata) || (!_in_bufsize) { |
732 | LoadInternalPage(#buildin_page_error, sizeof(buildin_page_error)); |
732 | LoadInternalPage(#buildin_page_error, sizeof(buildin_page_error)); |
733 | } else { |
733 | } else { |
734 | WB1.list.first = 0; //scroll page to the top |
734 | WB1.list.first = 0; //scroll page to the top |
735 | DrawOmnibox(); |
735 | DrawOmnibox(); |
736 | if(!strrchr(#editURL, '#')) { |
736 | if(!strrchr(#editURL, '#')) { |
737 | strcat(#editURL, #anchors.current); |
737 | strcat(#editURL, #anchors.current); |
738 | DrawOmnibox(); |
738 | DrawOmnibox(); |
739 | } |
739 | } |
740 | render_start_time = GetStartTime(); |
740 | render_start_time = GetStartTime(); |
741 | WB1.ParseHtml(_bufdata, _in_bufsize); |
741 | WB1.ParseHtml(_bufdata, _in_bufsize); |
742 | // REJECTED. Reason: infinite redirect at Google Results. |
742 | // REJECTED. Reason: infinite redirect at Google Results. |
743 | /* |
743 | /* |
744 | if (WB1.redirect) { // |
744 | if (WB1.redirect) { // |
745 | get_absolute_url(#WB1.redirect, history.current()); |
745 | get_absolute_url(#WB1.redirect, history.current()); |
746 | history.back(); |
746 | history.back(); |
747 | OpenPage(#WB1.redirect); |
747 | OpenPage(#WB1.redirect); |
748 | } |
748 | } |
749 | */ |
749 | */ |
750 | DrawStatusBar(NULL); |
750 | DrawStatusBar(NULL); |
751 | DrawActiveTab(); |
751 | DrawActiveTab(); |
752 | if (source_mode) { |
752 | if (source_mode) { |
753 | source_mode = false; |
753 | source_mode = false; |
754 | WB1.custom_encoding = CH_CP866; |
754 | WB1.custom_encoding = CH_CP866; |
755 | ShowSource(WB1.bufpointer, _in_bufsize); |
755 | ShowSource(WB1.bufpointer, _in_bufsize); |
756 | } else { |
756 | } else { |
757 | WB1.DrawPage(); |
757 | WB1.DrawPage(); |
758 | } |
758 | } |
759 | http.hfree(); |
759 | http.hfree(); |
760 | if (WB1.img_url.count) { GetImg(true); DrawOmnibox(); } |
760 | if (WB1.img_url.count) { GetImg(true); DrawOmnibox(); } |
761 | } |
761 | } |
762 | } |
762 | } |
763 | 763 | ||
764 | bool UrlExtIs(dword base, ext) |
764 | bool UrlExtIs(dword base, ext) |
765 | { |
765 | { |
766 | if (!strcmpi(base + strlen(base) - strlen(ext), ext)) return true; |
766 | if (!strcmpi(base + strlen(base) - strlen(ext), ext)) return true; |
767 | return false; |
767 | return false; |
768 | } |
768 | } |
769 | 769 | ||
770 | void DrawProgress() |
770 | void DrawProgress() |
771 | { |
771 | { |
772 | dword pct; |
772 | dword pct; |
773 | if (application_mode) return; |
773 | if (application_mode) return; |
774 | if (!http.transfer) return; |
774 | if (!http.transfer) return; |
775 | if (http_get_type==PAGE) && (prbar.max) pct = prbar.value*30/prbar.max; else pct = 10; |
775 | if (http_get_type==PAGE) && (prbar.max) pct = prbar.value*30/prbar.max; else pct = 10; |
776 | if (http_get_type==IMG) pct = prbar.value * 70 / prbar.max + 30; |
776 | if (http_get_type==IMG) pct = prbar.value * 70 / prbar.max + 30; |
777 | DrawBar(omnibox_edit.left-1, omnibox_edit.top+20, pct*omnibox_edit.width+16/100, 2, 0x72B7EB); |
777 | DrawBar(omnibox_edit.left-1, omnibox_edit.top+20, pct*omnibox_edit.width+16/100, 2, 0x72B7EB); |
778 | } |
778 | } |
779 | 779 | ||
780 | void EventShowPageMenu() |
780 | void EventShowPageMenu() |
781 | { |
781 | { |
782 | if (application_mode) return; |
782 | if (application_mode) return; |
783 | open_lmenu(mouse.x, mouse.y, MENU_TOP_LEFT, NULL, #rmb_menu); |
783 | open_lmenu(mouse.x, mouse.y, MENU_TOP_LEFT, NULL, #rmb_menu); |
784 | menu_id = VIEW_SOURCE; |
784 | menu_id = VIEW_SOURCE; |
785 | } |
785 | } |
786 | 786 | ||
787 | void EventShowLinkMenu() |
787 | void EventShowLinkMenu() |
788 | { |
788 | { |
789 | if (application_mode) return; |
789 | if (application_mode) return; |
790 | open_lmenu(mouse.x, mouse.y, MENU_TOP_LEFT, NULL, #link_menu); |
790 | open_lmenu(mouse.x, mouse.y, MENU_TOP_LEFT, NULL, #link_menu); |
791 | menu_id = IN_NEW_TAB; |
791 | menu_id = IN_NEW_TAB; |
792 | } |
792 | } |
793 | 793 | ||
794 | void EventShowMainMenu() |
794 | void EventShowMainMenu() |
795 | { |
795 | { |
796 | if (application_mode) return; |
796 | if (application_mode) return; |
797 | open_lmenu(Form.cwidth - PADDING -4, PADDING + TSZE + 3, |
797 | open_lmenu(Form.cwidth - PADDING -4, PADDING + TSZE + 3, |
798 | MENU_TOP_RIGHT, NULL, #main_menu); |
798 | MENU_TOP_RIGHT, NULL, #main_menu); |
799 | menu_id = OPEN_FILE; |
799 | menu_id = OPEN_FILE; |
800 | } |
800 | } |
801 | 801 | ||
802 | void EventShowEncodingsList() |
802 | void EventShowEncodingsList() |
803 | { |
803 | { |
804 | if (application_mode) return; |
804 | if (application_mode) return; |
805 | open_lmenu(Form.cwidth-4, Form.cheight - STATUSBAR_H + 12, |
805 | open_lmenu(Form.cwidth-4, Form.cheight - STATUSBAR_H + 12, |
806 | MENU_BOT_RIGHT, WB1.cur_encoding + 1, |
806 | MENU_BOT_RIGHT, WB1.cur_encoding + 1, |
807 | "UTF-8\nKOI8-RU\nCP1251\nCP1252\nISO8859-5\nCP866"); |
807 | "UTF-8\nKOI8-RU\nCP1251\nCP1252\nISO8859-5\nCP866"); |
808 | menu_id = ENCODINGS; |
808 | menu_id = ENCODINGS; |
809 | } |
809 | } |
810 | 810 | ||
811 | void ProcessMenuClick() |
811 | void ProcessMenuClick() |
812 | { |
812 | { |
813 | int click_id; |
813 | int click_id; |
814 | if (menu_id) { |
814 | if (menu_id) { |
815 | if (click_id = get_menu_click()) { |
815 | if (click_id = get_menu_click()) { |
816 | click_id += menu_id - 1; |
816 | click_id += menu_id - 1; |
817 | ProcessButtonClick(click_id); |
817 | ProcessButtonClick(click_id); |
818 | } |
818 | } |
819 | if (!menu_process_id) menu_id = NULL; |
819 | if (!menu_process_id) menu_id = NULL; |
820 | } |
820 | } |
821 | } |
821 | } |
822 | 822 | ||
823 | void EventSeachWeb() |
823 | void EventSeachWeb() |
824 | { |
824 | { |
825 | char new_url[URL_SIZE+1]; |
825 | char new_url[URL_SIZE+1]; |
826 | replace_char(#editURL, ' ', '+', URL_SIZE); |
826 | replace_char(#editURL, ' ', '+', URL_SIZE); |
827 | strcpy(#new_url, "https://www.google.com/search?q="); |
827 | strcpy(#new_url, "https://www.google.com/search?q="); |
828 | strncat(#new_url, #editURL, URL_SIZE); |
828 | strncat(#new_url, #editURL, URL_SIZE); |
829 | OpenPage(#new_url); |
829 | OpenPage(#new_url); |
830 | } |
830 | } |
831 | 831 | ||
832 | void EventOpenDialog() |
832 | void EventOpenDialog() |
833 | { |
833 | { |
834 | OpenDialog_start stdcall (#o_dialog); |
834 | OpenDialog_start stdcall (#o_dialog); |
835 | if (o_dialog.status) { |
835 | if (o_dialog.status) { |
836 | OpenPage(#openfile_path); |
836 | OpenPage(#openfile_path); |
837 | } |
837 | } |
838 | } |
838 | } |
839 | 839 | ||
840 | void EventViewSource() |
840 | void EventViewSource() |
841 | { |
841 | { |
842 | source_mode = true; |
842 | source_mode = true; |
843 | EventOpenNewTab(history.current()); |
843 | EventOpenNewTab(history.current()); |
844 | } |
844 | } |
845 | 845 | ||
846 | void EventRefreshPage() |
846 | void EventRefreshPage() |
847 | { |
847 | { |
848 | if (http.transfer) { |
848 | if (http.transfer) { |
849 | StopLoading(); |
849 | StopLoading(); |
850 | draw_window(); |
850 | draw_window(); |
851 | } else { |
851 | } else { |
852 | OpenPage(history.current()); |
852 | OpenPage(history.current()); |
853 | } |
853 | } |
854 | } |
854 | } |
855 | 855 | ||
856 | void EventUpdateBrowser() |
856 | void EventUpdateBrowser() |
857 | { |
857 | { |
858 | dword downloader_id, slot_n; |
858 | dword downloader_id, slot_n; |
859 | dword current_size; |
859 | dword current_size; |
860 | dword new_size; |
860 | dword new_size; |
861 | 861 | ||
862 | draw_window(); |
862 | draw_window(); |
863 | 863 | ||
864 | downloader_id = EventOpenDownloader(#update_param); |
864 | downloader_id = EventOpenDownloader(#update_param); |
865 | do { |
865 | do { |
866 | slot_n = GetProcessSlot(downloader_id); |
866 | slot_n = GetProcessSlot(downloader_id); |
867 | pause(10); |
867 | pause(10); |
868 | } while (slot_n!=0); |
868 | } while (slot_n!=0); |
869 | 869 | ||
870 | current_size = get_file_size(#program_path); |
870 | current_size = get_file_size(#program_path); |
871 | new_size = get_file_size("/tmp0/1/Downloads/WebView.com"); |
871 | new_size = get_file_size("/tmp0/1/Downloads/WebView.com"); |
872 | 872 | ||
873 | if (!new_size) || (new_size<5000) { notify(#update_download_error); return; } |
873 | if (!new_size) || (new_size<5000) { notify(#update_download_error); return; } |
874 | if (current_size == new_size) { notify(#update_is_current); return; } |
874 | if (current_size == new_size) { notify(#update_is_current); return; } |
875 | 875 | ||
876 | if (CopyFileAtOnce(new_size, "/tmp0/1/Downloads/WebView.com", #program_path)) { |
876 | if (CopyFileAtOnce(new_size, "/tmp0/1/Downloads/WebView.com", #program_path)) { |
877 | notify(#update_can_not_copy); |
877 | notify(#update_can_not_copy); |
878 | } else { |
878 | } else { |
879 | notify(#update_ok); |
879 | notify(#update_ok); |
880 | RunProgram(#program_path, history.current()); |
880 | RunProgram(#program_path, history.current()); |
881 | ExitProcess(); |
881 | ExitProcess(); |
882 | } |
882 | } |
883 | } |
883 | } |
884 | 884 | ||
885 | void DrawStatusBar(dword _msg) |
885 | void DrawStatusBar(dword _msg) |
886 | { |
886 | { |
887 | dword status_y = Form.cheight - STATUSBAR_H + 4; |
887 | dword status_y = Form.cheight - STATUSBAR_H + 4; |
888 | dword status_w = Form.cwidth - 90; |
888 | dword status_w = Form.cwidth - 90; |
889 | if (application_mode) return; |
889 | if (application_mode) return; |
890 | if (Form.status_window>2) return; |
890 | if (Form.status_window>2) return; |
891 | DrawBar(0,Form.cheight - STATUSBAR_H+1, Form.cwidth,STATUSBAR_H-1, sc.work); |
891 | DrawBar(0,Form.cheight - STATUSBAR_H+1, Form.cwidth,STATUSBAR_H-1, sc.work); |
892 | if (_msg) { |
892 | if (_msg) { |
893 | ESI = math.min(status_w/6, strlen(_msg)); |
893 | ESI = math.min(status_w/6, strlen(_msg)); |
894 | WriteText(10, status_y, 0, sc.work_text, _msg); |
894 | WriteText(10, status_y, 0, sc.work_text, _msg); |
895 | } |
895 | } |
896 | DefineHiddenButton(status_w+20, status_y-3, 60, 12, CHANGE_ENCODING); |
896 | DefineHiddenButton(status_w+20, status_y-3, 60, 12, CHANGE_ENCODING); |
897 | WriteTextCenter(status_w+20, status_y, 60, sc.work_text, WB1.cur_encoding*10+#charsets); |
897 | WriteTextCenter(status_w+20, status_y, 60, sc.work_text, WB1.cur_encoding*10+#charsets); |
898 | } |
898 | } |
899 | 899 | ||
900 | void DrawOmnibox() |
900 | void DrawOmnibox() |
901 | { |
901 | { |
902 | int imgxoff; |
902 | int imgxoff; |
903 | if (application_mode) return; |
903 | if (application_mode) return; |
904 | DrawOvalBorder(omnibox_edit.left-2, omnibox_edit.top-3, omnibox_edit.width+18, 24, sc.line, |
904 | DrawOvalBorder(omnibox_edit.left-2, omnibox_edit.top-3, omnibox_edit.width+18, 24, sc.line, |
905 | sc.line, sc.line, sc.dark); |
905 | sc.line, sc.line, sc.dark); |
906 | DrawBar(omnibox_edit.left-1, omnibox_edit.top-2, omnibox_edit.width+18, 1, 0xD8DCD8); |
906 | DrawBar(omnibox_edit.left-1, omnibox_edit.top-2, omnibox_edit.width+18, 1, 0xD8DCD8); |
907 | DrawBar(omnibox_edit.left-1, omnibox_edit.top-1, omnibox_edit.width+18, 1, omnibox_edit.color); |
907 | DrawBar(omnibox_edit.left-1, omnibox_edit.top-1, omnibox_edit.width+18, 1, omnibox_edit.bg_color); |
908 | DrawBar(omnibox_edit.left-1, omnibox_edit.top, 1, 22, omnibox_edit.color); |
908 | DrawBar(omnibox_edit.left-1, omnibox_edit.top, 1, 22, omnibox_edit.bg_color); |
909 | 909 | ||
910 | if (omnibox_edit.flags & ed_focus) omnibox_edit.flags = ed_focus; else omnibox_edit.flags = 0; |
910 | if (omnibox_edit.flags & ed_focus) omnibox_edit.flags = ed_focus; else omnibox_edit.flags = 0; |
911 | EditBox_UpdateText(#omnibox_edit, omnibox_edit.flags); |
911 | EditBox_UpdateText(#omnibox_edit, omnibox_edit.flags); |
912 | edit_box_draw stdcall(#omnibox_edit); |
912 | edit_box_draw stdcall(#omnibox_edit); |
913 | if (http.transfer) imgxoff = 16*23*3; else imgxoff = 0; |
913 | if (http.transfer) imgxoff = 16*23*3; else imgxoff = 0; |
914 | PutImage(omnibox_edit.left+omnibox_edit.width+1, omnibox_edit.top-1, 16, 23, imgxoff + #editbox_icons); |
914 | PutImage(omnibox_edit.left+omnibox_edit.width+1, omnibox_edit.top-1, 16, 23, imgxoff + #editbox_icons); |
915 | DefineHiddenButton(omnibox_edit.left+omnibox_edit.width-1, omnibox_edit.top-2, 17, 23, REFRESH_BUTTON); |
915 | DefineHiddenButton(omnibox_edit.left+omnibox_edit.width-1, omnibox_edit.top-2, 17, 23, REFRESH_BUTTON); |
916 | 916 | ||
917 | DrawProgress(); |
917 | DrawProgress(); |
918 | } |
918 | } |
919 | 919 | ||
920 | void SetOmniboxText(dword _text) |
920 | void SetOmniboxText(dword _text) |
921 | { |
921 | { |
922 | if (application_mode) return; |
922 | if (application_mode) return; |
923 | edit_box_set_text stdcall (#omnibox_edit, _text); |
923 | edit_box_set_text stdcall (#omnibox_edit, _text); |
924 | omnibox_edit.pos = omnibox_edit.flags = 0; |
924 | omnibox_edit.pos = omnibox_edit.flags = 0; |
925 | DrawOmnibox(); |
925 | DrawOmnibox(); |
926 | } |
926 | } |
927 | 927 | ||
928 | dword GetAbsoluteActiveURL() |
928 | dword GetAbsoluteActiveURL() |
929 | { |
929 | { |
930 | char abs_url[URL_SIZE]; |
930 | char abs_url[URL_SIZE]; |
931 | if (links.active_url) { |
931 | if (links.active_url) { |
932 | strncpy(#abs_url, links.active_url, URL_SIZE); |
932 | strncpy(#abs_url, links.active_url, URL_SIZE); |
933 | get_absolute_url(#abs_url, history.current()); |
933 | get_absolute_url(#abs_url, history.current()); |
934 | return #abs_url; |
934 | return #abs_url; |
935 | } |
935 | } |
936 | return 0; |
936 | return 0; |
937 | } |
937 | } |
938 | 938 | ||
939 | void CheckContentType() |
939 | void CheckContentType() |
940 | { |
940 | { |
941 | char content_type[64]; |
941 | char content_type[64]; |
942 | if (http.header_field("content-type", #content_type, sizeof(content_type))) // application || image |
942 | if (http.header_field("content-type", #content_type, sizeof(content_type))) // application || image |
943 | 943 | ||
944 | if (content_type[0] == 'i') { |
944 | if (content_type[0] == 'i') { |
945 | EventDownloadAndOpenImage(http.cur_url); |
945 | EventDownloadAndOpenImage(http.cur_url); |
946 | StopLoading(); |
946 | StopLoading(); |
947 | } |
947 | } |
948 | else if (content_type[0] == 'a') { |
948 | else if (content_type[0] == 'a') { |
949 | EventOpenDownloader(http.cur_url); |
949 | EventOpenDownloader(http.cur_url); |
950 | StopLoading(); |
950 | StopLoading(); |
951 | } |
951 | } |
952 | else { |
952 | else { |
953 | WB1.custom_encoding = -1; |
953 | WB1.custom_encoding = -1; |
954 | if (EAX = strchr(#content_type, '=')) { |
954 | if (EAX = strchr(#content_type, '=')) { |
955 | WB1.custom_encoding = get_encoding_type_by_name(EAX+1); |
955 | WB1.custom_encoding = get_encoding_type_by_name(EAX+1); |
956 | } |
956 | } |
957 | } |
957 | } |
958 | } |
958 | } |
959 | 959 | ||
960 | void EventDownloadAndOpenImage(dword _url) |
960 | void EventDownloadAndOpenImage(dword _url) |
961 | { |
961 | { |
962 | char image_download_url[URL_SIZE]; |
962 | char image_download_url[URL_SIZE]; |
963 | strcpy(#image_download_url, "-eo "); |
963 | strcpy(#image_download_url, "-eo "); |
964 | strncat(#image_download_url, _url, URL_SIZE); |
964 | strncat(#image_download_url, _url, URL_SIZE); |
965 | EventOpenDownloader(#image_download_url); |
965 | EventOpenDownloader(#image_download_url); |
966 | } |
966 | } |
967 | 967 | ||
968 | void HandleRedirect() |
968 | void HandleRedirect() |
969 | { |
969 | { |
970 | dword redirect_url = malloc(URL_SIZE); |
970 | dword redirect_url = malloc(URL_SIZE); |
971 | http.header_field("location", redirect_url, URL_SIZE); |
971 | http.header_field("location", redirect_url, URL_SIZE); |
972 | get_absolute_url(redirect_url, http.cur_url); |
972 | get_absolute_url(redirect_url, http.cur_url); |
973 | http.hfree(); |
973 | http.hfree(); |
974 | if (http_get_type==PAGE) OpenPage(redirect_url); |
974 | if (http_get_type==PAGE) OpenPage(redirect_url); |
975 | else if (http_get_type==IMG) GetUrl(redirect_url); |
975 | else if (http_get_type==IMG) GetUrl(redirect_url); |
976 | free(redirect_url); |
976 | free(redirect_url); |
977 | } |
977 | } |
978 | 978 | ||
979 | dword GetImg(bool _new) |
979 | dword GetImg(bool _new) |
980 | { |
980 | { |
981 | int i; |
981 | int i; |
982 | if (!show_images) return; |
982 | if (!show_images) return; |
983 | http_get_type = IMG; |
983 | http_get_type = IMG; |
984 | 984 | ||
985 | for (i = 0; i < WB1.img_url.count; i++) |
985 | for (i = 0; i < WB1.img_url.count; i++) |
986 | { |
986 | { |
987 | cur_img_url = WB1.img_url.get(i); |
987 | cur_img_url = WB1.img_url.get(i); |
988 | if (debug_mode) |
988 | if (debug_mode) |
989 | {debug("get img: ");debugln(cur_img_url);} |
989 | {debug("get img: ");debugln(cur_img_url);} |
990 | if (cache.has(cur_img_url)==false) { |
990 | if (cache.has(cur_img_url)==false) { |
991 | prbar.max = WB1.img_url.count; |
991 | prbar.max = WB1.img_url.count; |
992 | prbar.value = i; |
992 | prbar.value = i; |
993 | if (GetUrl(cur_img_url)) {DrawStatusBar(cur_img_url); DrawProgress(); return;} |
993 | if (GetUrl(cur_img_url)) {DrawStatusBar(cur_img_url); DrawProgress(); return;} |
994 | } |
994 | } |
995 | } |
995 | } |
996 | if (_new) return; |
996 | if (_new) return; |
997 | DrawOmnibox(); |
997 | DrawOmnibox(); |
998 | DrawStatusBar(T_RENDERING); |
998 | DrawStatusBar(T_RENDERING); |
999 | WB1.Reparse(); |
999 | WB1.Reparse(); |
1000 | WB1.DrawPage(); |
1000 | WB1.DrawPage(); |
1001 | debugln(sprintf(#param, T_DONE_IN_SEC, GetStartTime()-render_start_time/100)); |
1001 | debugln(sprintf(#param, T_DONE_IN_SEC, GetStartTime()-render_start_time/100)); |
1002 | DrawStatusBar(NULL); |
1002 | DrawStatusBar(NULL); |
1003 | } |
1003 | } |
1004 | 1004 | ||
1005 | stop:>5000)>>=5)>>=>280)>120)> |
1005 | stop:>5000)>>=5)>>=>280)>120)> |