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