Rev 7784 | Rev 7789 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 7784 | Rev 7788 | ||
---|---|---|---|
1 | //Copyright 2007-2020 by Veliant & Leency |
1 | //Copyright 2007-2020 by Veliant & Leency |
2 | //Asper, lev, Lrz, Barsuk, Nable, hidnplayr... |
2 | //Asper, lev, Lrz, Barsuk, Nable, hidnplayr... |
3 | 3 | ||
4 | #ifndef AUTOBUILD |
4 | #ifndef AUTOBUILD |
5 | #include "lang.h--" |
5 | #include "lang.h--" |
6 | #endif |
6 | #endif |
7 | 7 | ||
8 | //libraries |
8 | //libraries |
9 | #define MEMSIZE 1024 * 1000 |
9 | #define MEMSIZE 1024 * 1000 |
10 | #include "..\lib\gui.h" |
10 | #include "..\lib\gui.h" |
11 | #include "..\lib\draw_buf.h" |
11 | #include "..\lib\draw_buf.h" |
12 | #include "..\lib\list_box.h" |
12 | #include "..\lib\list_box.h" |
13 | #include "..\lib\cursor.h" |
13 | #include "..\lib\cursor.h" |
14 | #include "..\lib\collection.h" |
14 | #include "..\lib\collection.h" |
15 | #include "..\lib\random.h" |
15 | #include "..\lib\random.h" |
16 | #include "..\lib\clipboard.h" |
16 | #include "..\lib\clipboard.h" |
17 | 17 | ||
18 | // *.obj libraries |
18 | // *.obj libraries |
19 | #include "..\lib\obj\box_lib.h" |
19 | #include "..\lib\obj\box_lib.h" |
20 | #include "..\lib\obj\libio.h" |
20 | #include "..\lib\obj\libio.h" |
21 | #include "..\lib\obj\libimg.h" |
21 | #include "..\lib\obj\libimg.h" |
22 | #include "..\lib\obj\http.h" |
22 | #include "..\lib\obj\http.h" |
23 | #include "..\lib\obj\iconv.h" |
23 | #include "..\lib\obj\iconv.h" |
24 | #include "..\lib\obj\proc_lib.h" |
24 | #include "..\lib\obj\proc_lib.h" |
25 | 25 | ||
26 | //useful patterns |
26 | //useful patterns |
27 | #include "..\lib\patterns\history.h" |
27 | #include "..\lib\patterns\history.h" |
28 | #include "..\lib\patterns\http_downloader.h" |
28 | #include "..\lib\patterns\http_downloader.h" |
29 | #include "..\lib\patterns\simple_open_dialog.h" |
29 | #include "..\lib\patterns\simple_open_dialog.h" |
30 | #include "..\lib\patterns\toolbar_button.h" |
30 | #include "..\lib\patterns\toolbar_button.h" |
31 | 31 | ||
32 | #include "texts.h" |
32 | #include "texts.h" |
33 | #include "cache.h" |
33 | #include "cache.h" |
34 | #include "show_src.h" |
34 | #include "show_src.h" |
35 | #include "download_manager.h" |
35 | #include "download_manager.h" |
36 | 36 | ||
37 | bool debug_mode = false; |
37 | bool debug_mode = false; |
38 | 38 | ||
39 | #include "..\TWB\TWB.c" //HTML Parser, a core component |
39 | #include "..\TWB\TWB.c" //HTML Parser, a core component |
40 | 40 | ||
41 | TWebBrowser WB1; |
41 | TWebBrowser WB1; |
42 | _history history; |
42 | _history history; |
43 | 43 | ||
44 | #include "history.h" |
44 | #include "history.h" |
45 | 45 | ||
46 | #define PADDING 9 |
46 | #define PADDING 9 |
47 | #define TSZE 25 |
47 | #define TSZE 25 |
48 | #define STATUSBAR_H 15 |
48 | #define STATUSBAR_H 15 |
49 | #define TAB_H 20 |
49 | #define TAB_H 20 |
50 | dword TOOLBAR_H = PADDING+TSZE+PADDING+2; |
50 | dword TOOLBAR_H = PADDING+TSZE+PADDING+2; |
51 | 51 | ||
52 | #define URL_SIZE 4000 |
52 | #define URL_SIZE 4000 |
53 | 53 | ||
54 | int action_buf; |
54 | int action_buf; |
55 | 55 | ||
56 | _http http = 0; |
56 | _http http = 0; |
57 | 57 | ||
58 | bool source_mode = false; |
58 | bool source_mode = false; |
59 | 59 | ||
60 | progress_bar wv_progress_bar; |
60 | progress_bar wv_progress_bar; |
61 | char stak[4096]; |
61 | char stak[4096]; |
62 | proc_info Form; |
62 | proc_info Form; |
63 | 63 | ||
64 | int menu_id=NULL; |
64 | int menu_id=NULL; |
65 | 65 | ||
66 | enum { |
66 | enum { |
67 | NEW_TAB=600, |
67 | NEW_TAB=600, |
68 | ENCODINGS=700, |
68 | ENCODINGS=700, |
69 | BACK_BUTTON=800, |
69 | BACK_BUTTON=800, |
70 | FORWARD_BUTTON, |
70 | FORWARD_BUTTON, |
71 | REFRESH_BUTTON, |
71 | REFRESH_BUTTON, |
72 | GOTOURL_BUTTON, |
72 | GOTOURL_BUTTON, |
73 | CHANGE_ENCODING, |
73 | CHANGE_ENCODING, |
74 | SANDWICH_BUTTON, |
74 | SANDWICH_BUTTON, |
75 | VIEW_SOURCE, |
75 | VIEW_SOURCE, |
76 | EDIT_SOURCE, |
76 | EDIT_SOURCE, |
77 | OPEN_FILE, |
77 | OPEN_FILE, |
78 | NEW_WINDOW, |
78 | NEW_WINDOW, |
79 | VIEW_HISTORY, |
79 | VIEW_HISTORY, |
80 | DOWNLOAD_MANAGER, |
80 | DOWNLOAD_MANAGER, |
81 | CLEAR_CACHE, |
81 | CLEAR_CACHE, |
82 | UPDATE_BROWSER, |
82 | UPDATE_BROWSER, |
83 | COPY_LINK_URL, |
83 | COPY_LINK_URL, |
84 | DOWNLOAD_LINK_CONTENTS, |
84 | DOWNLOAD_LINK_CONTENTS, |
85 | TAB_ID, |
85 | TAB_ID, |
86 | TAB_CLOSE_ID = 900 |
86 | TAB_CLOSE_ID = 900 |
87 | }; |
87 | }; |
88 | 88 | ||
89 | #include "tabs.h" |
89 | #include "tabs.h" |
90 | 90 | ||
91 | char default_dir[] = "/rd/1"; |
91 | char default_dir[] = "/rd/1"; |
92 | od_filter filter2 = { 16, "TXT\0HTM\0HTML\0\0" }; |
92 | od_filter filter2 = { 22, "TXT\0HTM\0HTML\0DOCX\0\0" }; |
93 | 93 | ||
94 | char editURL[URL_SIZE+1]; |
94 | char editURL[URL_SIZE+1]; |
95 | edit_box address_box = {, PADDING+TSZE*2+PADDING+6, PADDING+3, 0xffffff, |
95 | edit_box address_box = {, PADDING+TSZE*2+PADDING+6, PADDING+3, 0xffffff, |
96 | 0x94AECE, 0xffffff, 0xffffff,0x10000000,URL_SIZE-2,#editURL,0,,19,19}; |
96 | 0x94AECE, 0xffffff, 0xffffff,0x10000000,URL_SIZE-2,#editURL,0,,19,19}; |
97 | 97 | ||
98 | char editbox_icons[] = FROM "editbox_icons.raw"; |
98 | char editbox_icons[] = FROM "editbox_icons.raw"; |
99 | 99 | ||
100 | 100 | ||
101 | void LoadLibraries() |
101 | void LoadLibraries() |
102 | { |
102 | { |
103 | load_dll(boxlib, #box_lib_init,0); |
103 | load_dll(boxlib, #box_lib_init,0); |
104 | load_dll(libio, #libio_init,1); |
104 | load_dll(libio, #libio_init,1); |
105 | load_dll(libimg, #libimg_init,1); |
105 | load_dll(libimg, #libimg_init,1); |
106 | load_dll(libHTTP, #http_lib_init,1); |
106 | load_dll(libHTTP, #http_lib_init,1); |
107 | load_dll(iconv_lib, #iconv_open,0); |
107 | load_dll(iconv_lib, #iconv_open,0); |
108 | load_dll(Proc_lib, #OpenDialog_init,0); |
108 | load_dll(Proc_lib, #OpenDialog_init,0); |
109 | OpenDialog_init stdcall (#o_dialog); |
109 | OpenDialog_init stdcall (#o_dialog); |
110 | } |
110 | } |
111 | 111 | ||
112 | void HandleParam() |
112 | void HandleParam() |
113 | { |
113 | { |
114 | if (param) { |
114 | if (param) { |
115 | if (!strncmp(#param, "-download_and_exit ", 19)) { |
115 | if (!strncmp(#param, "-download_and_exit ", 19)) { |
116 | download_and_exit = true; |
116 | download_and_exit = true; |
117 | strcpy(#downloader_edit, #param+19); |
117 | strcpy(#downloader_edit, #param+19); |
118 | Downloader(); |
118 | Downloader(); |
119 | ExitProcess(); |
119 | ExitProcess(); |
120 | } else if (!strncmp(#param, "-download ", 10)) { |
120 | } else if (!strncmp(#param, "-download ", 10)) { |
121 | strcpy(#downloader_edit, #param+10); |
121 | strcpy(#downloader_edit, #param+10); |
122 | //CreateThread(#Downloader,#downloader_stak+4092); |
122 | //CreateThread(#Downloader,#downloader_stak+4092); |
123 | Downloader(); |
123 | Downloader(); |
124 | ExitProcess(); |
124 | ExitProcess(); |
125 | } else if (!strncmp(#param, "-source ", 8)) { |
125 | } else if (!strncmp(#param, "-source ", 8)) { |
126 | source_mode = true; |
126 | source_mode = true; |
127 | history.add(#param + 8); |
127 | history.add(#param + 8); |
128 | } else { |
128 | } else { |
129 | history.add(#param); |
129 | history.add(#param); |
130 | } |
130 | } |
131 | } else { |
131 | } else { |
132 | history.add(URL_SERVICE_HOMEPAGE); |
132 | history.add(URL_SERVICE_HOMEPAGE); |
133 | } |
133 | } |
134 | } |
134 | } |
135 | 135 | ||
136 | void main() |
136 | void main() |
137 | { |
137 | { |
138 | int i, btn, redirect_count=0; |
138 | int i, btn, redirect_count=0; |
139 | LoadLibraries(); |
139 | LoadLibraries(); |
140 | CreateDir("/tmp0/1/Downloads"); |
140 | CreateDir("/tmp0/1/Downloads"); |
141 | //CreateDir("/tmp0/1/WebView_Cache"); |
141 | //CreateDir("/tmp0/1/WebView_Cache"); |
142 | HandleParam(); |
142 | HandleParam(); |
143 | WB1.list.SetFont(8, 14, 10011000b); |
143 | WB1.list.SetFont(8, 14, 10011000b); |
144 | WB1.list.no_selection = true; |
144 | WB1.list.no_selection = true; |
145 | WB1.custom_encoding = -1; |
145 | WB1.custom_encoding = -1; |
146 | SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER + EVM_STACK); |
146 | SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER + EVM_STACK); |
147 | loop() switch(WaitEvent()) |
147 | loop() switch(WaitEvent()) |
148 | { |
148 | { |
149 | case evMouse: |
149 | case evMouse: |
150 | edit_box_mouse stdcall (#address_box); |
150 | edit_box_mouse stdcall (#address_box); |
151 | mouse.get(); |
151 | mouse.get(); |
152 | if (PageLinks.HoverAndProceed(mouse.x, WB1.list.first + mouse.y, WB1.list.y, WB1.list.first)) |
152 | if (PageLinks.HoverAndProceed(mouse.x, WB1.list.first + mouse.y, WB1.list.y, WB1.list.first)) |
153 | && (mouse.pkm) && (mouse.up) { |
153 | && (mouse.pkm) && (mouse.up) { |
154 | if (WB1.list.MouseOver(mouse.x, mouse.y)) EventShowPageMenu(); |
154 | if (WB1.list.MouseOver(mouse.x, mouse.y)) EventShowPageMenu(); |
155 | break; |
155 | break; |
156 | } |
156 | } |
157 | if (WB1.list.MouseScroll(mouse.vert)) WB1.DrawPage(); |
157 | if (WB1.list.MouseScroll(mouse.vert)) WB1.DrawPage(); |
158 | scrollbar_v_mouse (#scroll_wv); |
158 | scrollbar_v_mouse (#scroll_wv); |
159 | if (WB1.list.first != scroll_wv.position) |
159 | if (WB1.list.first != scroll_wv.position) |
160 | { |
160 | { |
161 | WB1.list.first = scroll_wv.position; |
161 | WB1.list.first = scroll_wv.position; |
162 | WB1.DrawPage(); |
162 | WB1.DrawPage(); |
163 | break; |
163 | break; |
164 | } |
164 | } |
165 | if (mouse.up) && (! address_box.flags & ed_focus) && (address_box.flags & ed_shift_bac) |
165 | if (mouse.up) && (! address_box.flags & ed_focus) && (address_box.flags & ed_shift_bac) |
166 | { |
166 | { |
167 | DrawOmnibox(); //reset text selection |
167 | DrawOmnibox(); //reset text selection |
168 | } |
168 | } |
169 | break; |
169 | break; |
170 | 170 | ||
171 | case evButton: |
171 | case evButton: |
172 | btn = GetButtonID(); |
172 | btn = GetButtonID(); |
173 | if (1==btn) ExitProcess(); else ProcessEvent(btn); |
173 | if (1==btn) ExitProcess(); else ProcessEvent(btn); |
174 | break; |
174 | break; |
175 | 175 | ||
176 | case evKey: |
176 | case evKey: |
177 | GetKeys(); |
177 | GetKeys(); |
178 | //if (key_scancode == SCAN_CODE_F1) {DebugTabs();break;} |
178 | //if (key_scancode == SCAN_CODE_F1) {DebugTabs();break;} |
179 | 179 | ||
180 | if (key_modifier&KEY_LSHIFT) || (key_modifier&KEY_RSHIFT) { |
180 | if (key_modifier&KEY_LSHIFT) || (key_modifier&KEY_RSHIFT) { |
181 | if (key_scancode == SCAN_CODE_TAB) {EventActivatePreviousTab();break;} |
181 | if (key_scancode == SCAN_CODE_TAB) {EventActivatePreviousTab();break;} |
182 | } |
182 | } |
183 | 183 | ||
184 | if (ProcessCtrlKeyEvent()) break; |
184 | if (ProcessCtrlKeyEvent()) break; |
185 | 185 | ||
186 | if (key_scancode == SCAN_CODE_F5) ProcessEvent(REFRESH_BUTTON); |
186 | if (key_scancode == SCAN_CODE_F5) ProcessEvent(REFRESH_BUTTON); |
187 | 187 | ||
188 | if (address_box.flags & ed_focus) |
188 | if (address_box.flags & ed_focus) |
189 | { |
189 | { |
190 | if (key_scancode == SCAN_CODE_ENTER) { |
190 | if (key_scancode == SCAN_CODE_ENTER) { |
191 | ProcessEvent(key_scancode); |
191 | ProcessEvent(key_scancode); |
192 | } else { |
192 | } else { |
193 | EAX = key_editbox; |
193 | EAX = key_editbox; |
194 | edit_box_key stdcall(#address_box); |
194 | edit_box_key stdcall(#address_box); |
195 | } |
195 | } |
196 | } else { |
196 | } else { |
197 | #define KEY_SCROLL_N 11 |
197 | #define KEY_SCROLL_N 11 |
198 | if (SCAN_CODE_UP == key_scancode) for (i=0;i |
198 | if (SCAN_CODE_UP == key_scancode) for (i=0;i |
199 | if (SCAN_CODE_DOWN == key_scancode) for (i=0;i |
199 | if (SCAN_CODE_DOWN == key_scancode) for (i=0;i |
200 | if (key_scancode == SCAN_CODE_F6) {address_box.flags=ed_focus; DrawOmnibox();} |
200 | if (key_scancode == SCAN_CODE_F6) {address_box.flags=ed_focus; DrawOmnibox();} |
201 | if (WB1.list.ProcessKey(key_scancode)) WB1.DrawPage(); |
201 | if (WB1.list.ProcessKey(key_scancode)) WB1.DrawPage(); |
202 | else ProcessEvent(key_scancode); |
202 | else ProcessEvent(key_scancode); |
203 | } |
203 | } |
204 | break; |
204 | break; |
205 | 205 | ||
206 | case evReDraw: |
206 | case evReDraw: |
207 | DefineAndDrawWindow(GetScreenWidth()-800/2-random(80), //40 |
207 | DefineAndDrawWindow(GetScreenWidth()-800/2-random(80), //40 |
208 | GetScreenHeight()-700/2-random(80),800,700,0x73,0,0,0); |
208 | GetScreenHeight()-700/2-random(80),800,700,0x73,0,0,0); |
209 | GetProcessInfo(#Form, SelfInfo); |
209 | GetProcessInfo(#Form, SelfInfo); |
210 | ProcessMenuClick(); |
210 | ProcessMenuClick(); |
211 | system.color.get(); |
211 | system.color.get(); |
212 | if (Form.status_window>2) break; |
212 | if (Form.status_window>2) break; |
213 | if (Form.height<120) { MoveSize(OLD,OLD,OLD,120); break; } |
213 | if (Form.height<120) { MoveSize(OLD,OLD,OLD,120); break; } |
214 | if (Form.width<280) { MoveSize(OLD,OLD,280,OLD); break; } |
214 | if (Form.width<280) { MoveSize(OLD,OLD,280,OLD); break; } |
215 | draw_window(); |
215 | draw_window(); |
216 | break; |
216 | break; |
217 | 217 | ||
218 | case evNetwork: |
218 | case evNetwork: |
219 | if (http.transfer <= 0) break; |
219 | if (http.transfer <= 0) break; |
220 | http.receive(); |
220 | http.receive(); |
221 | EventUpdateProgressBar(); |
221 | EventUpdateProgressBar(); |
222 | if (http.receive_result != 0) break; |
222 | if (http.receive_result != 0) break; |
223 | if (http.status_code >= 300) && (http.status_code < 400) |
223 | if (http.status_code >= 300) && (http.status_code < 400) |
224 | { |
224 | { |
225 | // Handle redirects |
225 | // Handle redirects |
226 | if (redirect_count<=5) { |
226 | if (redirect_count<=5) { |
227 | redirect_count++; |
227 | redirect_count++; |
228 | http.handle_redirect(); |
228 | http.handle_redirect(); |
229 | http.free(); |
229 | http.free(); |
230 | GetAbsoluteURL(#http.redirect_url, history.current()); |
230 | GetAbsoluteURL(#http.redirect_url, history.current()); |
231 | history.back(); |
231 | history.back(); |
232 | OpenPage(#http.redirect_url); |
232 | OpenPage(#http.redirect_url); |
233 | } else { |
233 | } else { |
234 | notify("'Too many redirects.' -E"); |
234 | notify("'Too many redirects.' -E"); |
235 | StopLoading(); |
235 | StopLoading(); |
236 | } |
236 | } |
237 | } else { |
237 | } else { |
238 | // Loading the page is complete, free resources |
238 | // Loading the page is complete, free resources |
239 | redirect_count = 0; |
239 | redirect_count = 0; |
240 | http.free(); |
240 | http.free(); |
241 | pages_cache.add(history.current(), http.content_pointer, http.content_received); |
241 | pages_cache.add(history.current(), http.content_pointer, http.content_received); |
242 | LoadInternalPage(http.content_pointer, http.content_received); |
242 | LoadInternalPage(http.content_pointer, http.content_received); |
243 | } |
243 | } |
244 | } |
244 | } |
245 | } |
245 | } |
246 | 246 | ||
247 | bool ProcessCtrlKeyEvent() |
247 | bool ProcessCtrlKeyEvent() |
248 | { |
248 | { |
249 | if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL) switch(key_scancode) |
249 | if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL) switch(key_scancode) |
250 | { |
250 | { |
251 | case SCAN_CODE_KEY_O: |
251 | case SCAN_CODE_KEY_O: |
252 | EventOpenDialog(); |
252 | EventOpenDialog(); |
253 | return true; |
253 | return true; |
254 | case SCAN_CODE_KEY_H: |
254 | case SCAN_CODE_KEY_H: |
255 | ProcessEvent(VIEW_HISTORY); |
255 | ProcessEvent(VIEW_HISTORY); |
256 | return true; |
256 | return true; |
257 | case SCAN_CODE_KEY_U: |
257 | case SCAN_CODE_KEY_U: |
258 | EventViewSource(); |
258 | EventViewSource(); |
259 | return true; |
259 | return true; |
260 | case SCAN_CODE_KEY_T: |
260 | case SCAN_CODE_KEY_T: |
261 | EventOpenNewTab(URL_SERVICE_HOMEPAGE); |
261 | EventOpenNewTab(URL_SERVICE_HOMEPAGE); |
262 | return true; |
262 | return true; |
263 | case SCAN_CODE_KEY_N: |
263 | case SCAN_CODE_KEY_N: |
264 | RunProgram(#program_path, NULL); |
264 | RunProgram(#program_path, NULL); |
265 | return true; |
265 | return true; |
266 | case SCAN_CODE_KEY_J: |
266 | case SCAN_CODE_KEY_J: |
267 | ProcessEvent(DOWNLOAD_MANAGER); |
267 | ProcessEvent(DOWNLOAD_MANAGER); |
268 | return true; |
268 | return true; |
269 | case SCAN_CODE_KEY_R: |
269 | case SCAN_CODE_KEY_R: |
270 | ProcessEvent(REFRESH_BUTTON); |
270 | ProcessEvent(REFRESH_BUTTON); |
271 | return true; |
271 | return true; |
272 | case SCAN_CODE_ENTER: |
272 | case SCAN_CODE_ENTER: |
273 | EventSeachWeb(); |
273 | EventSeachWeb(); |
274 | return true; |
274 | return true; |
275 | case SCAN_CODE_LEFT: |
275 | case SCAN_CODE_LEFT: |
276 | ProcessEvent(BACK_BUTTON); |
276 | ProcessEvent(BACK_BUTTON); |
277 | return true; |
277 | return true; |
278 | case SCAN_CODE_RIGHT: |
278 | case SCAN_CODE_RIGHT: |
279 | ProcessEvent(FORWARD_BUTTON); |
279 | ProcessEvent(FORWARD_BUTTON); |
280 | return true; |
280 | return true; |
281 | case SCAN_CODE_KEY_W: |
281 | case SCAN_CODE_KEY_W: |
282 | EventCloseActiveTab(); |
282 | EventCloseActiveTab(); |
283 | return true; |
283 | return true; |
284 | case SCAN_CODE_TAB: |
284 | case SCAN_CODE_TAB: |
285 | EventActivateNextTab(); |
285 | EventActivateNextTab(); |
286 | return true; |
286 | return true; |
287 | } |
287 | } |
288 | return false; |
288 | return false; |
289 | } |
289 | } |
290 | 290 | ||
291 | void SetElementSizes() |
291 | void SetElementSizes() |
292 | { |
292 | { |
293 | address_box.width = Form.cwidth - address_box.left - 52 - 16; |
293 | address_box.width = Form.cwidth - address_box.left - 52 - 16; |
294 | WB1.list.SetSizes(0, TOOLBAR_H+TAB_H, Form.width - 10 - scroll_wv.size_x, |
294 | WB1.list.SetSizes(0, TOOLBAR_H+TAB_H, Form.width - 10 - scroll_wv.size_x, |
295 | Form.cheight - TOOLBAR_H - STATUSBAR_H - TAB_H, BASIC_LINE_H); |
295 | Form.cheight - TOOLBAR_H - STATUSBAR_H - TAB_H, BASIC_LINE_H); |
296 | WB1.list.wheel_size = 7 * BASIC_LINE_H; |
296 | WB1.list.wheel_size = 7 * BASIC_LINE_H; |
297 | WB1.list.column_max = WB1.list.w - scroll_wv.size_x / WB1.list.font_w + 1; |
297 | WB1.list.column_max = WB1.list.w - scroll_wv.size_x / WB1.list.font_w + 1; |
298 | WB1.list.visible = WB1.list.h; |
298 | WB1.list.visible = WB1.list.h; |
299 | } |
299 | } |
300 | 300 | ||
301 | 301 | ||
302 | void draw_window() |
302 | void draw_window() |
303 | { |
303 | { |
304 | int i; |
304 | int i; |
305 | SetElementSizes(); |
305 | SetElementSizes(); |
306 | 306 | ||
307 | DrawBar(0,0, Form.cwidth,PADDING, system.color.work); |
307 | DrawBar(0,0, Form.cwidth,PADDING, system.color.work); |
308 | DrawBar(0,PADDING+TSZE+1, Form.cwidth,PADDING-1, system.color.work); |
308 | DrawBar(0,PADDING+TSZE+1, Form.cwidth,PADDING-1, system.color.work); |
309 | DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, MixColors(system.color.work_dark, system.color.work, 180)); |
309 | DrawBar(0,TOOLBAR_H-2, Form.cwidth,1, MixColors(system.color.work_dark, system.color.work, 180)); |
310 | DrawBar(0,TOOLBAR_H-1, Form.cwidth,1, system.color.work_graph); |
310 | DrawBar(0,TOOLBAR_H-1, Form.cwidth,1, system.color.work_graph); |
311 | DrawBar(0, PADDING, address_box.left-2, TSZE+1, system.color.work); |
311 | DrawBar(0, PADDING, address_box.left-2, TSZE+1, system.color.work); |
312 | DrawBar(address_box.left+address_box.width+18, PADDING, Form.cwidth-address_box.left-address_box.width-18, TSZE+1, system.color.work); |
312 | DrawBar(address_box.left+address_box.width+18, PADDING, Form.cwidth-address_box.left-address_box.width-18, TSZE+1, system.color.work); |
313 | 313 | ||
314 | DrawTopPanelButton(BACK_BUTTON, PADDING-1, PADDING, 30); |
314 | DrawTopPanelButton(BACK_BUTTON, PADDING-1, PADDING, 30); |
315 | DrawTopPanelButton(FORWARD_BUTTON, PADDING+TSZE+PADDING-2, PADDING, 31); |
315 | DrawTopPanelButton(FORWARD_BUTTON, PADDING+TSZE+PADDING-2, PADDING, 31); |
316 | DrawTopPanelButton(SANDWICH_BUTTON, Form.cwidth-PADDING-TSZE-3, PADDING, -1); |
316 | DrawTopPanelButton(SANDWICH_BUTTON, Form.cwidth-PADDING-TSZE-3, PADDING, -1); |
317 | for (i=0; i<=2; i++) DrawBar(Form.cwidth-PADDING-TSZE+3, i*5+PADDING+7, 15, 3, system.color.work_graph); |
317 | for (i=0; i<=2; i++) DrawBar(Form.cwidth-PADDING-TSZE+3, i*5+PADDING+7, 15, 3, system.color.work_graph); |
318 | 318 | ||
319 | DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, system.color.work_graph); |
319 | DrawBar(0,Form.cheight - STATUSBAR_H, Form.cwidth,1, system.color.work_graph); |
320 | 320 | ||
321 | DrawRectangle(WB1.list.x + WB1.list.w, WB1.list.y, scroll_wv.size_x, |
321 | DrawRectangle(WB1.list.x + WB1.list.w, WB1.list.y, scroll_wv.size_x, |
322 | WB1.list.h-1, scroll_wv.bckg_col); |
322 | WB1.list.h-1, scroll_wv.bckg_col); |
323 | 323 | ||
324 | if (!BrowserWidthChanged()) { |
324 | if (!BrowserWidthChanged()) { |
325 | WB1.DrawPage(); |
325 | WB1.DrawPage(); |
326 | DrawOmnibox(); |
326 | DrawOmnibox(); |
327 | } |
327 | } |
328 | DrawProgress(); |
328 | DrawProgress(); |
329 | DrawStatusBar(NULL); |
329 | DrawStatusBar(NULL); |
330 | DrawTabsBar(); |
330 | DrawTabsBar(); |
331 | } |
331 | } |
332 | 332 | ||
333 | bool BrowserWidthChanged() |
333 | bool BrowserWidthChanged() |
334 | { |
334 | { |
335 | dword source_mode_holder; |
335 | dword source_mode_holder; |
336 | if (WB1.list.w!=DrawBuf.bufw) { |
336 | if (WB1.list.w!=DrawBuf.bufw) { |
337 | DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, 400*20); |
337 | DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, 400*20); |
338 | if (!strncmp(history.current(),"http",4)) { |
338 | if (!strncmp(history.current(),"http",4)) { |
339 | //nihuya ne izyashnoe reshenie, no pust' poka butet tak |
339 | //nihuya ne izyashnoe reshenie, no pust' poka butet tak |
340 | source_mode_holder = source_mode; |
340 | source_mode_holder = source_mode; |
341 | LoadInternalPage(#loading_text, sizeof(loading_text)); |
341 | LoadInternalPage(#loading_text, sizeof(loading_text)); |
342 | source_mode = source_mode_holder; |
342 | source_mode = source_mode_holder; |
343 | } |
343 | } |
344 | OpenPage(history.current()); |
344 | OpenPage(history.current()); |
345 | return true; |
345 | return true; |
346 | } |
346 | } |
347 | return false; |
347 | return false; |
348 | } |
348 | } |
349 | 349 | ||
350 | 350 | ||
351 | void EventChangeEncodingAndLoadPage(int _new_encoding) |
351 | void EventChangeEncodingAndLoadPage(int _new_encoding) |
352 | { |
352 | { |
353 | dword newbuf, newsize; |
353 | dword newbuf, newsize; |
354 | WB1.custom_encoding = _new_encoding; |
354 | WB1.custom_encoding = _new_encoding; |
355 | newsize = strlen(WB1.o_bufpointer); |
355 | newsize = strlen(WB1.o_bufpointer); |
356 | newbuf = malloc(newsize); |
356 | newbuf = malloc(newsize); |
357 | memmov(newbuf, WB1.o_bufpointer, newsize); |
357 | memmov(newbuf, WB1.o_bufpointer, newsize); |
358 | LoadInternalPage(newbuf, newsize); |
358 | LoadInternalPage(newbuf, newsize); |
359 | free(newbuf); |
359 | free(newbuf); |
360 | } |
360 | } |
361 | 361 | ||
362 | 362 | ||
363 | void ProcessEvent(dword id__) |
363 | void ProcessEvent(dword id__) |
364 | { |
364 | { |
365 | switch (id__) |
365 | switch (id__) |
366 | { |
366 | { |
367 | case ENCODINGS...ENCODINGS+6: |
367 | case ENCODINGS...ENCODINGS+6: |
368 | EventChangeEncodingAndLoadPage(id__-ENCODINGS); |
368 | EventChangeEncodingAndLoadPage(id__-ENCODINGS); |
369 | return; |
369 | return; |
370 | case NEW_WINDOW: |
370 | case NEW_WINDOW: |
371 | RunProgram(#program_path, NULL); |
371 | RunProgram(#program_path, NULL); |
372 | return; |
372 | return; |
373 | case SCAN_CODE_BS: |
373 | case SCAN_CODE_BS: |
374 | case BACK_BUTTON: |
374 | case BACK_BUTTON: |
375 | if (history.back()) { |
375 | if (history.back()) { |
376 | OpenPage(history.current()); |
376 | OpenPage(history.current()); |
377 | } |
377 | } |
378 | return; |
378 | return; |
379 | case FORWARD_BUTTON: |
379 | case FORWARD_BUTTON: |
380 | if (history.forward()) { |
380 | if (history.forward()) { |
381 | OpenPage(history.current()); |
381 | OpenPage(history.current()); |
382 | } |
382 | } |
383 | return; |
383 | return; |
384 | case GOTOURL_BUTTON: |
384 | case GOTOURL_BUTTON: |
385 | case SCAN_CODE_ENTER: |
385 | case SCAN_CODE_ENTER: |
386 | EventSubmitOmnibox(); |
386 | EventSubmitOmnibox(); |
387 | return; |
387 | return; |
388 | case REFRESH_BUTTON: |
388 | case REFRESH_BUTTON: |
389 | if (http.transfer) { |
389 | if (http.transfer) { |
390 | StopLoading(); |
390 | StopLoading(); |
391 | draw_window(); |
391 | draw_window(); |
392 | } else { |
392 | } else { |
393 | OpenPage(history.current()); |
393 | OpenPage(history.current()); |
394 | } |
394 | } |
395 | return; |
395 | return; |
396 | case CHANGE_ENCODING: |
396 | case CHANGE_ENCODING: |
397 | EventShowEncodingsList(); |
397 | EventShowEncodingsList(); |
398 | return; |
398 | return; |
399 | case SANDWICH_BUTTON: |
399 | case SANDWICH_BUTTON: |
400 | EventShowMainMenu(); |
400 | EventShowMainMenu(); |
401 | return; |
401 | return; |
402 | case VIEW_SOURCE: |
402 | case VIEW_SOURCE: |
403 | EventViewSource(); |
403 | EventViewSource(); |
404 | break; |
404 | break; |
405 | case EDIT_SOURCE: |
405 | case EDIT_SOURCE: |
406 | if (check_is_the_adress_local(history.current())) { |
406 | if (check_is_the_adress_local(history.current())) { |
407 | RunProgram("/rd/1/tinypad", history.current()); |
407 | RunProgram("/rd/1/tinypad", history.current()); |
408 | } else { |
408 | } else { |
409 | CreateFile(WB1.bufsize, WB1.bufpointer, "/tmp0/1/WebView_tmp.htm"); |
409 | CreateFile(WB1.bufsize, WB1.bufpointer, "/tmp0/1/WebView_tmp.htm"); |
410 | if (!EAX) RunProgram("/rd/1/tinypad", "/tmp0/1/WebView_tmp.htm"); |
410 | if (!EAX) RunProgram("/rd/1/tinypad", "/tmp0/1/WebView_tmp.htm"); |
411 | } |
411 | } |
412 | return; |
412 | return; |
413 | case VIEW_HISTORY: |
413 | case VIEW_HISTORY: |
414 | OpenPage(URL_SERVICE_HISTORY); |
414 | OpenPage(URL_SERVICE_HISTORY); |
415 | return; |
415 | return; |
416 | case DOWNLOAD_MANAGER: |
416 | case DOWNLOAD_MANAGER: |
417 | if (!downloader_opened) { |
417 | if (!downloader_opened) { |
418 | downloader_edit = NULL; |
418 | downloader_edit = NULL; |
419 | CreateThread(#Downloader,#downloader_stak+4092); |
419 | CreateThread(#Downloader,#downloader_stak+4092); |
420 | } |
420 | } |
421 | return; |
421 | return; |
422 | case UPDATE_BROWSER: |
422 | case UPDATE_BROWSER: |
423 | EventUpdateBrowser(); |
423 | EventUpdateBrowser(); |
424 | return; |
424 | return; |
425 | case CLEAR_CACHE: |
425 | case CLEAR_CACHE: |
426 | pages_cache.clear(); |
426 | pages_cache.clear(); |
427 | notify(#clear_cache_ok); |
427 | notify(#clear_cache_ok); |
428 | return; |
428 | return; |
429 | case COPY_LINK_URL: |
429 | case COPY_LINK_URL: |
430 | Clipboard__CopyText(PageLinks.GetURL(PageLinks.active)); |
430 | Clipboard__CopyText(PageLinks.GetURL(PageLinks.active)); |
431 | notify("'URL copied to clipboard'O"); |
431 | notify("'URL copied to clipboard'O"); |
432 | return; |
432 | return; |
433 | case DOWNLOAD_LINK_CONTENTS: |
433 | case DOWNLOAD_LINK_CONTENTS: |
434 | if (!downloader_opened) { |
434 | if (!downloader_opened) { |
435 | strcpy(#downloader_edit, PageLinks.GetURL(PageLinks.active)); |
435 | strcpy(#downloader_edit, PageLinks.GetURL(PageLinks.active)); |
436 | CreateThread(#Downloader,#downloader_stak+4092); |
436 | CreateThread(#Downloader,#downloader_stak+4092); |
437 | } |
437 | } |
438 | return; |
438 | return; |
439 | case OPEN_FILE: |
439 | case OPEN_FILE: |
440 | EventOpenDialog(); |
440 | EventOpenDialog(); |
441 | return; |
441 | return; |
442 | case SCAN_CODE_F12: |
442 | case SCAN_CODE_F12: |
443 | debug_mode ^= 1; |
443 | debug_mode ^= 1; |
444 | if (debug_mode) notify("'Debug mode ON'-I"); |
444 | if (debug_mode) notify("'Debug mode ON'-I"); |
445 | else notify("'Debug mode OFF'-I"); |
445 | else notify("'Debug mode OFF'-I"); |
446 | return; |
446 | return; |
447 | case NEW_TAB: |
447 | case NEW_TAB: |
448 | if (http.transfer) break; |
448 | if (http.transfer) break; |
449 | EventOpenNewTab(URL_SERVICE_HOMEPAGE); |
449 | EventOpenNewTab(URL_SERVICE_HOMEPAGE); |
450 | return; |
450 | return; |
451 | case TAB_ID...TAB_ID+TABS_MAX: |
451 | case TAB_ID...TAB_ID+TABS_MAX: |
452 | if (http.transfer) break; |
452 | if (http.transfer) break; |
453 | if (mouse.mkm) { |
453 | if (mouse.mkm) { |
454 | EventTabClose(id__ - TAB_ID); |
454 | EventTabClose(id__ - TAB_ID); |
455 | } else { |
455 | } else { |
456 | EventTabClick(id__ - TAB_ID); |
456 | EventTabClick(id__ - TAB_ID); |
457 | } |
457 | } |
458 | return; |
458 | return; |
459 | case TAB_CLOSE_ID...TAB_CLOSE_ID+TABS_MAX: |
459 | case TAB_CLOSE_ID...TAB_CLOSE_ID+TABS_MAX: |
460 | EventTabClose(id__ - TAB_CLOSE_ID); |
460 | EventTabClose(id__ - TAB_CLOSE_ID); |
461 | return; |
461 | return; |
462 | } |
462 | } |
463 | } |
463 | } |
464 | 464 | ||
465 | void StopLoading() |
465 | void StopLoading() |
466 | { |
466 | { |
467 | if (http.transfer) |
467 | if (http.transfer) |
468 | { |
468 | { |
469 | EAX = http.transfer; |
469 | EAX = http.transfer; |
470 | EAX = EAX.http_msg.content_ptr; // get pointer to data |
470 | EAX = EAX.http_msg.content_ptr; // get pointer to data |
471 | $push EAX // save it on the stack |
471 | $push EAX // save it on the stack |
472 | http_free stdcall (http.transfer); // abort connection |
472 | http_free stdcall (http.transfer); // abort connection |
473 | $pop EAX |
473 | $pop EAX |
474 | free(EAX); // free data |
474 | free(EAX); // free data |
475 | http.transfer=0; |
475 | http.transfer=0; |
476 | pause(10); |
476 | pause(10); |
477 | } |
477 | } |
478 | wv_progress_bar.value = 0; |
478 | wv_progress_bar.value = 0; |
479 | DrawOmnibox(); |
479 | DrawOmnibox(); |
480 | } |
480 | } |
481 | 481 | ||
482 | //rewrite into |
482 | //rewrite into |
483 | //bool strrpl(dword dst, from, into, dst_len); |
483 | //bool strrpl(dword dst, from, into, dst_len); |
484 | bool ReplaceSpaceInUrl(dword url, size) { |
484 | bool ReplaceSpaceInUrl(dword url, size) { |
485 | unsigned int i, j; |
485 | unsigned int i, j; |
486 | bool was_changed=false; |
486 | bool was_changed=false; |
487 | for (i=url+size-3; i>url; i--) |
487 | for (i=url+size-3; i>url; i--) |
488 | { |
488 | { |
489 | if (ESBYTE[i]!=' ') continue; |
489 | if (ESBYTE[i]!=' ') continue; |
490 | for (j=url+size-3; j>=i; j--) { |
490 | for (j=url+size-3; j>=i; j--) { |
491 | ESBYTE[j+3]=ESBYTE[j+2]; |
491 | ESBYTE[j+3]=ESBYTE[j+2]; |
492 | ESBYTE[j+2]=ESBYTE[j+1]; |
492 | ESBYTE[j+2]=ESBYTE[j+1]; |
493 | ESBYTE[j+1]=ESBYTE[j]; |
493 | ESBYTE[j+1]=ESBYTE[j]; |
494 | } |
494 | } |
495 | ESBYTE[i] = '%'; |
495 | ESBYTE[i] = '%'; |
496 | ESBYTE[i+1] = '2'; |
496 | ESBYTE[i+1] = '2'; |
497 | ESBYTE[i+2] = '0'; |
497 | ESBYTE[i+2] = '0'; |
498 | was_changed = true; |
498 | was_changed = true; |
499 | } |
499 | } |
500 | return was_changed; |
500 | return was_changed; |
501 | } |
501 | } |
502 | 502 | ||
503 | bool GetLocalFileData(dword _path) |
503 | bool GetLocalFileData(dword _path) |
504 | { |
504 | { |
505 | dword data, size; |
505 | dword data, size; |
506 | file_size stdcall (_path); |
506 | file_size stdcall (_path); |
507 | if (!EBX) { |
507 | if (!EBX) { |
508 | return false; |
508 | return false; |
509 | } else { |
509 | } else { |
510 | size = EBX; |
510 | size = EBX; |
511 | data = malloc(size); |
511 | data = malloc(size); |
512 | ReadFile(0, size, data, _path); |
512 | ReadFile(0, size, data, _path); |
513 | LoadInternalPage(data, size); |
513 | LoadInternalPage(data, size); |
514 | free(data); |
514 | free(data); |
515 | return true; |
515 | return true; |
516 | } |
516 | } |
517 | } |
517 | } |
518 | 518 | ||
519 | void OpenPage(dword _open_URL) |
519 | void OpenPage(dword _open_URL) |
520 | { |
520 | { |
521 | char new_url[URL_SIZE+1]; |
521 | char new_url[URL_SIZE+1]; |
- | 522 | int unz_id; |
|
522 | 523 | ||
523 | StopLoading(); |
524 | StopLoading(); |
524 | 525 | ||
525 | if (open_new_tab) { |
526 | if (open_new_tab) { |
526 | open_new_tab = false; |
527 | open_new_tab = false; |
527 | EventOpenNewTab(_open_URL); |
528 | EventOpenNewTab(_open_URL); |
528 | return; |
529 | return; |
529 | } |
530 | } |
530 | 531 | ||
531 | SetOmniboxText(_open_URL); |
532 | SetOmniboxText(_open_URL); |
532 | 533 | ||
533 | strncpy(#new_url, _open_URL, URL_SIZE); |
534 | strncpy(#new_url, _open_URL, URL_SIZE); |
534 | 535 | ||
535 | //Exclude # from the URL to the load page |
536 | //Exclude # from the URL to the load page |
536 | //We will bring it back when we get the buffer |
537 | //We will bring it back when we get the buffer |
537 | if (strrchr(#new_url, '#')) anchors.take_anchor_from(#new_url); |
538 | if (strrchr(#new_url, '#')) anchors.take_anchor_from(#new_url); |
538 | 539 | ||
539 | history.add(#new_url); |
540 | history.add(#new_url); |
540 | 541 | ||
541 | if (pages_cache.has(#new_url)) { |
542 | if (pages_cache.has(#new_url)) { |
542 | //CACHED PAGE |
543 | //CACHED PAGE |
543 | LoadInternalPage(pages_cache.current_page_buf, pages_cache.current_page_size); |
544 | LoadInternalPage(pages_cache.current_page_buf, pages_cache.current_page_size); |
544 | 545 | ||
545 | } else if (!strncmp(#new_url,"WebView:",8)) { |
546 | } else if (!strncmp(#new_url,"WebView:",8)) { |
546 | //INTERNAL PAGE |
547 | //INTERNAL PAGE |
547 | if (!strcmp(#new_url, URL_SERVICE_HOMEPAGE)) LoadInternalPage(#homepage, sizeof(homepage)); |
548 | if (!strcmp(#new_url, URL_SERVICE_HOMEPAGE)) LoadInternalPage(#homepage, sizeof(homepage)); |
548 | else if (!strcmp(#new_url, URL_SERVICE_HELP)) LoadInternalPage(#help, sizeof(help)); |
549 | else if (!strcmp(#new_url, URL_SERVICE_HELP)) LoadInternalPage(#help, sizeof(help)); |
549 | else if (!strcmp(#new_url, URL_SERVICE_HISTORY)) ShowHistory(); |
550 | else if (!strcmp(#new_url, URL_SERVICE_HISTORY)) ShowHistory(); |
550 | else LoadInternalPage(#page_not_found, sizeof(page_not_found)); |
551 | else LoadInternalPage(#page_not_found, sizeof(page_not_found)); |
551 | 552 | ||
552 | } else if (!strncmp(#new_url,"http:",5)) || (!strncmp(#new_url,"https:",6)) { |
553 | } else if (!strncmp(#new_url,"http:",5)) || (!strncmp(#new_url,"https:",6)) { |
553 | //WEB PAGE |
554 | //WEB PAGE |
554 | if (ReplaceSpaceInUrl(#new_url, URL_SIZE)) { |
555 | if (ReplaceSpaceInUrl(#new_url, URL_SIZE)) { |
555 | strcpy(#editURL, #new_url); |
556 | strcpy(#editURL, #new_url); |
556 | } |
557 | } |
557 | 558 | ||
558 | if (!strncmp(#new_url,"http:",5)) { |
559 | if (!strncmp(#new_url,"http:",5)) { |
559 | http.get(#new_url); |
560 | http.get(#new_url); |
560 | } else if (!strncmp(#new_url,"https://",8)) { |
561 | } else if (!strncmp(#new_url,"https://",8)) { |
561 | strcpy(#new_url, "http://gate.aspero.pro/?site="); |
562 | strcpy(#new_url, "http://gate.aspero.pro/?site="); |
562 | strncat(#new_url, _open_URL, URL_SIZE); |
563 | strncat(#new_url, _open_URL, URL_SIZE); |
563 | http.get(#new_url); |
564 | http.get(#new_url); |
564 | } |
565 | } |
565 | 566 | ||
566 | DrawOmnibox(); |
567 | DrawOmnibox(); |
567 | 568 | ||
568 | if (!http.transfer) { |
569 | if (!http.transfer) { |
569 | StopLoading(); |
570 | StopLoading(); |
570 | LoadInternalPage(#page_not_found, sizeof(page_not_found)); |
571 | LoadInternalPage(#page_not_found, sizeof(page_not_found)); |
571 | } |
572 | } |
572 | } else { |
573 | } else { |
573 | //LOCAL PAGE |
574 | //LOCAL PAGE |
- | 575 | if (UrlExtIs(#new_url,".docx")) { |
|
- | 576 | DeleteFile("/tmp0/1/temp/word/document.xml"); |
|
- | 577 | CreateDir("/tmp0/1/temp"); |
|
- | 578 | unz_id = RunProgram("/sys/unz", sprintf(#param, "-o \"/tmp0/1/temp\" -h \"%s\"", #new_url)); |
|
- | 579 | while (GetProcessSlot(unz_id)) pause(2); |
|
- | 580 | strcpy(#new_url, "/tmp0/1/temp/word/document.xml"); |
|
- | 581 | } |
|
574 | if (!GetLocalFileData(#new_url)) { |
582 | if (!GetLocalFileData(#new_url)) { |
575 | LoadInternalPage(#page_not_found, sizeof(page_not_found)); |
583 | LoadInternalPage(#page_not_found, sizeof(page_not_found)); |
576 | } |
584 | } |
577 | } |
585 | } |
578 | } |
586 | } |
579 | 587 | ||
580 | void EventClickLink(dword _click_URL) |
588 | void EventClickLink(dword _click_URL) |
581 | { |
589 | { |
582 | char new_url[URL_SIZE+1]; |
590 | char new_url[URL_SIZE+1]; |
583 | 591 | ||
584 | if (open_new_window) { |
592 | if (open_new_window) { |
585 | strcpy(#new_url, _click_URL); |
593 | strcpy(#new_url, _click_URL); |
586 | GetAbsoluteURL(#new_url, history.current()); |
594 | GetAbsoluteURL(#new_url, history.current()); |
587 | RunProgram(#program_path, #new_url); |
595 | RunProgram(#program_path, #new_url); |
588 | return; |
596 | return; |
589 | } |
597 | } |
590 | 598 | ||
591 | if (ESBYTE[_click_URL]=='#') { |
599 | if (ESBYTE[_click_URL]=='#') { |
592 | if (anchors.get_pos_by_name(_click_URL+1)!=-1) { |
600 | if (anchors.get_pos_by_name(_click_URL+1)!=-1) { |
593 | WB1.list.first = anchors.get_pos_by_name(_click_URL+1); |
601 | WB1.list.first = anchors.get_pos_by_name(_click_URL+1); |
594 | WB1.list.CheckDoesValuesOkey(); |
602 | WB1.list.CheckDoesValuesOkey(); |
595 | } |
603 | } |
596 | strcpy(#editURL, history.current()); |
604 | strcpy(#editURL, history.current()); |
597 | strcat(#editURL, _click_URL); |
605 | strcat(#editURL, _click_URL); |
598 | DrawOmnibox(); |
606 | DrawOmnibox(); |
599 | WB1.DrawPage(); |
607 | WB1.DrawPage(); |
600 | return; |
608 | return; |
601 | } |
609 | } |
602 | 610 | ||
603 | if (!strncmp(_click_URL,"mailto:", 7)) || (!strncmp(_click_URL,"tel:", 4)) { |
611 | if (!strncmp(_click_URL,"mailto:", 7)) || (!strncmp(_click_URL,"tel:", 4)) { |
604 | notify(_click_URL); |
612 | notify(_click_URL); |
605 | return; |
613 | return; |
606 | } |
614 | } |
607 | 615 | ||
608 | if (http.transfer) { |
616 | if (http.transfer) { |
609 | StopLoading(); |
617 | StopLoading(); |
610 | history.back(); |
618 | history.back(); |
611 | } |
619 | } |
612 | 620 | ||
613 | strcpy(#new_url, _click_URL); |
621 | strcpy(#new_url, _click_URL); |
614 | GetAbsoluteURL(#new_url, history.current()); |
622 | GetAbsoluteURL(#new_url, history.current()); |
615 | 623 | ||
616 | if (strrchr(#new_url, '#')!=0) { |
624 | if (strrchr(#new_url, '#')!=0) { |
617 | anchors.take_anchor_from(#new_url); |
625 | anchors.take_anchor_from(#new_url); |
618 | OpenPage(#new_url); |
626 | OpenPage(#new_url); |
619 | return; |
627 | return; |
620 | } |
628 | } |
621 | 629 | ||
622 | if (!strncmp(#new_url,"WebView:",8)) { |
630 | if (!strncmp(#new_url,"WebView:",8)) { |
623 | OpenPage(#new_url); |
631 | OpenPage(#new_url); |
624 | return; |
632 | return; |
625 | } |
633 | } |
626 | 634 | ||
627 | if (strncmp(#new_url,"http://",7)!=0) && (strncmp(#new_url,"https://",8)!=0) |
635 | if (strncmp(#new_url,"http://",7)!=0) && (strncmp(#new_url,"https://",8)!=0) |
628 | { |
636 | { |
629 | if (UrlExtIs(#new_url,".htm")!=true) && (UrlExtIs(#new_url,".html")!=true) |
637 | if (UrlExtIs(#new_url,".htm")!=true) && (UrlExtIs(#new_url,".html")!=true) |
630 | { |
638 | { |
631 | if (strchr(#new_url, '|')) { |
639 | if (strchr(#new_url, '|')) { |
632 | ESBYTE[strchr(#new_url, '|')] = NULL; |
640 | ESBYTE[strchr(#new_url, '|')] = NULL; |
633 | RunProgram(#new_url, strlen(#new_url)+1+#new_url); |
641 | RunProgram(#new_url, strlen(#new_url)+1+#new_url); |
634 | } else { |
642 | } else { |
635 | RunProgram("/sys/@open", #new_url); |
643 | RunProgram("/sys/@open", #new_url); |
636 | } |
644 | } |
637 | return; |
645 | return; |
638 | } |
646 | } |
639 | } else { |
647 | } else { |
640 | if (UrlExtIs(#new_url,".png")==true) || (UrlExtIs(#new_url,".jpg")==true) |
648 | if (UrlExtIs(#new_url,".png")==true) || (UrlExtIs(#new_url,".jpg")==true) |
641 | || (UrlExtIs(#new_url,".zip")==true) || (UrlExtIs(#new_url,".kex")==true) || (UrlExtIs(#new_url,".pdf")==true) |
649 | || (UrlExtIs(#new_url,".zip")==true) || (UrlExtIs(#new_url,".kex")==true) || (UrlExtIs(#new_url,".pdf")==true) |
642 | || (UrlExtIs(#new_url,".7z")==true) { |
650 | || (UrlExtIs(#new_url,".7z")==true) { |
643 | if (!downloader_opened) { |
651 | if (!downloader_opened) { |
644 | strcpy(#downloader_edit, #new_url); |
652 | strcpy(#downloader_edit, #new_url); |
645 | CreateThread(#Downloader,#downloader_stak+4092); |
653 | CreateThread(#Downloader,#downloader_stak+4092); |
646 | } |
654 | } |
647 | else notify("'WebView\nPlease, start a new download only when previous ended.'Et"); |
655 | else notify("'WebView\nPlease, start a new download only when previous ended.'Et"); |
648 | return; |
656 | return; |
649 | } |
657 | } |
650 | } |
658 | } |
651 | OpenPage(#new_url); |
659 | OpenPage(#new_url); |
652 | } |
660 | } |
653 | 661 | ||
654 | void EventSubmitOmnibox() |
662 | void EventSubmitOmnibox() |
655 | { |
663 | { |
656 | char new_url[URL_SIZE+1]; |
664 | char new_url[URL_SIZE+1]; |
657 | if (!editURL[0]) return; |
665 | if (!editURL[0]) return; |
658 | if (!strncmp(#editURL,"http:",5)) || (editURL[0]=='/') |
666 | if (!strncmp(#editURL,"http:",5)) || (editURL[0]=='/') |
659 | || (!strncmp(#editURL,"https:",6)) || (!strncmp(#editURL,"WebView:",8)) { |
667 | || (!strncmp(#editURL,"https:",6)) || (!strncmp(#editURL,"WebView:",8)) { |
660 | OpenPage(#editURL); |
668 | OpenPage(#editURL); |
661 | } else { |
669 | } else { |
662 | strcpy(#new_url, "http://"); |
670 | strcpy(#new_url, "http://"); |
663 | strncat(#new_url, #editURL, sizeof(new_url)-1); |
671 | strncat(#new_url, #editURL, sizeof(new_url)-1); |
664 | OpenPage(#new_url); |
672 | OpenPage(#new_url); |
665 | } |
673 | } |
666 | } |
674 | } |
667 | 675 | ||
668 | void LoadInternalPage(dword _bufdata, _in_bufsize){ |
676 | void LoadInternalPage(dword _bufdata, _in_bufsize){ |
669 | if (!_bufdata) || (!_in_bufsize) { |
677 | if (!_bufdata) || (!_in_bufsize) { |
670 | LoadInternalPage(#page_not_found, sizeof(page_not_found)); |
678 | LoadInternalPage(#page_not_found, sizeof(page_not_found)); |
671 | } else { |
679 | } else { |
672 | WB1.list.first = 0; //scroll page to the top |
680 | WB1.list.first = 0; //scroll page to the top |
673 | DrawOmnibox(); |
681 | DrawOmnibox(); |
674 | if(!strrchr(#editURL, '#')) { |
682 | if(!strrchr(#editURL, '#')) { |
675 | strcat(#editURL, #anchors.current); |
683 | strcat(#editURL, #anchors.current); |
676 | DrawOmnibox(); |
684 | DrawOmnibox(); |
677 | } |
685 | } |
678 | WB1.ParseHtml(_bufdata, _in_bufsize); |
686 | WB1.ParseHtml(_bufdata, _in_bufsize); |
679 | DrawStatusBar(NULL); |
687 | DrawStatusBar(NULL); |
680 | DrawActiveTab(); |
688 | DrawActiveTab(); |
681 | if (source_mode) { |
689 | if (source_mode) { |
682 | source_mode = false; |
690 | source_mode = false; |
683 | ShowSource(WB1.bufpointer, _in_bufsize); |
691 | ShowSource(WB1.bufpointer, _in_bufsize); |
684 | } else { |
692 | } else { |
685 | WB1.DrawPage(); |
693 | WB1.DrawPage(); |
686 | } |
694 | } |
687 | } |
695 | } |
688 | } |
696 | } |
689 | 697 | ||
690 | byte UrlExtIs(dword base, ext) |
698 | byte UrlExtIs(dword base, ext) |
691 | { |
699 | { |
692 | if (!strcmpi(base + strlen(base) - strlen(ext), ext)) return true; |
700 | if (!strcmpi(base + strlen(base) - strlen(ext), ext)) return true; |
693 | return false; |
701 | return false; |
694 | } |
702 | } |
695 | 703 | ||
696 | void DrawProgress() |
704 | void DrawProgress() |
697 | { |
705 | { |
698 | dword persent; |
706 | dword persent; |
699 | if (http.transfer == 0) return; |
707 | if (http.transfer == 0) return; |
700 | if (wv_progress_bar.max) { |
708 | if (wv_progress_bar.max) { |
701 | persent = wv_progress_bar.value*100/wv_progress_bar.max; |
709 | persent = wv_progress_bar.value*100/wv_progress_bar.max; |
702 | } else { |
710 | } else { |
703 | persent = 10; |
711 | persent = 10; |
704 | } |
712 | } |
705 | DrawBar(address_box.left-1, address_box.top+20, persent*address_box.width+16/100, 2, 0x72B7EB); |
713 | DrawBar(address_box.left-1, address_box.top+20, persent*address_box.width+16/100, 2, 0x72B7EB); |
706 | } |
714 | } |
707 | 715 | ||
708 | void EventShowPageMenu() |
716 | void EventShowPageMenu() |
709 | { |
717 | { |
710 | open_lmenu(Form.left + mouse.x+4, Form.top + skin_height + mouse.y, MENU_ALIGN_TOP_LEFT, NULL, #rmb_menu); |
718 | open_lmenu(Form.left + mouse.x+4, Form.top + skin_height + mouse.y, MENU_ALIGN_TOP_LEFT, NULL, #rmb_menu); |
711 | menu_id = VIEW_SOURCE; |
719 | menu_id = VIEW_SOURCE; |
712 | } |
720 | } |
713 | 721 | ||
714 | void EventShowLinkMenu() |
722 | void EventShowLinkMenu() |
715 | { |
723 | { |
716 | open_lmenu(Form.left + mouse.x+4, Form.top + skin_height + mouse.y, MENU_ALIGN_TOP_LEFT, NULL, #link_menu); |
724 | open_lmenu(Form.left + mouse.x+4, Form.top + skin_height + mouse.y, MENU_ALIGN_TOP_LEFT, NULL, #link_menu); |
717 | menu_id = COPY_LINK_URL; |
725 | menu_id = COPY_LINK_URL; |
718 | } |
726 | } |
719 | 727 | ||
720 | void EventShowMainMenu() |
728 | void EventShowMainMenu() |
721 | { |
729 | { |
722 | open_lmenu(Form.left + Form.cwidth - PADDING, Form.top + skin_height + PADDING + TSZE + 3, |
730 | open_lmenu(Form.left + Form.cwidth - PADDING, Form.top + skin_height + PADDING + TSZE + 3, |
723 | MENU_ALIGN_TOP_RIGHT, NULL, #main_menu); |
731 | MENU_ALIGN_TOP_RIGHT, NULL, #main_menu); |
724 | menu_id = OPEN_FILE; |
732 | menu_id = OPEN_FILE; |
725 | } |
733 | } |
726 | 734 | ||
727 | void EventShowEncodingsList() |
735 | void EventShowEncodingsList() |
728 | { |
736 | { |
729 | open_lmenu(Form.left + Form.cwidth, Form.top + skin_height + status_text.start_y + 8, |
737 | open_lmenu(Form.left + Form.cwidth, Form.top + skin_height + status_text.start_y + 8, |
730 | MENU_ALIGN_BOT_RIGHT, WB1.cur_encoding + 1, "UTF-8\nKOI8-RU\nCP1251\nCP1252\nISO8859-5\nCP866"); |
738 | MENU_ALIGN_BOT_RIGHT, WB1.cur_encoding + 1, "UTF-8\nKOI8-RU\nCP1251\nCP1252\nISO8859-5\nCP866"); |
731 | menu_id = ENCODINGS; |
739 | menu_id = ENCODINGS; |
732 | } |
740 | } |
733 | 741 | ||
734 | void ProcessMenuClick() |
742 | void ProcessMenuClick() |
735 | { |
743 | { |
736 | int click_id; |
744 | int click_id; |
737 | if (menu_id) && (click_id = get_menu_click()) { |
745 | if (menu_id) && (click_id = get_menu_click()) { |
738 | click_id += menu_id - 1; |
746 | click_id += menu_id - 1; |
739 | menu_id = NULL; |
747 | menu_id = NULL; |
740 | ProcessEvent(click_id); |
748 | ProcessEvent(click_id); |
741 | } |
749 | } |
742 | } |
750 | } |
743 | 751 | ||
744 | void EventUpdateProgressBar() |
752 | void EventUpdateProgressBar() |
745 | { |
753 | { |
746 | wv_progress_bar.max = http.content_length; |
754 | wv_progress_bar.max = http.content_length; |
747 | if (wv_progress_bar.value != http.content_received) |
755 | if (wv_progress_bar.value != http.content_received) |
748 | { |
756 | { |
749 | wv_progress_bar.value = http.content_received; |
757 | wv_progress_bar.value = http.content_received; |
750 | DrawProgress(); |
758 | DrawProgress(); |
751 | } |
759 | } |
752 | } |
760 | } |
753 | 761 | ||
754 | void EventSeachWeb() |
762 | void EventSeachWeb() |
755 | { |
763 | { |
756 | char new_url[URL_SIZE+1]; |
764 | char new_url[URL_SIZE+1]; |
757 | replace_char(#editURL, ' ', '_', URL_SIZE); |
765 | replace_char(#editURL, ' ', '_', URL_SIZE); |
758 | strcpy(#new_url, "https://www.google.com/search?q="); |
766 | strcpy(#new_url, "https://www.google.com/search?q="); |
759 | strncat(#new_url, #editURL, URL_SIZE); |
767 | strncat(#new_url, #editURL, URL_SIZE); |
760 | OpenPage(#new_url); |
768 | OpenPage(#new_url); |
761 | } |
769 | } |
762 | 770 | ||
763 | void EventOpenDialog() |
771 | void EventOpenDialog() |
764 | { |
772 | { |
765 | OpenDialog_start stdcall (#o_dialog); |
773 | OpenDialog_start stdcall (#o_dialog); |
766 | if (o_dialog.status) { |
774 | if (o_dialog.status) { |
767 | OpenPage(#openfile_path); |
775 | OpenPage(#openfile_path); |
768 | } |
776 | } |
769 | } |
777 | } |
770 | 778 | ||
771 | void EventViewSource() |
779 | void EventViewSource() |
772 | { |
780 | { |
773 | char source_view_param[URL_SIZE+1]; |
781 | char source_view_param[URL_SIZE+1]; |
774 | //strcpy(#source_view_param, "-source "); |
782 | //strcpy(#source_view_param, "-source "); |
775 | //strncat(#source_view_param, history.current(), URL_SIZE); |
783 | //strncat(#source_view_param, history.current(), URL_SIZE); |
776 | //RunProgram(#program_path, #source_view_param); |
784 | //RunProgram(#program_path, #source_view_param); |
777 | source_mode = true; |
785 | source_mode = true; |
778 | EventOpenNewTab(history.current()); |
786 | EventOpenNewTab(history.current()); |
779 | } |
787 | } |
780 | 788 | ||
781 | dword GetFileSize(dword _path) |
789 | dword GetFileSize(dword _path) |
782 | { |
790 | { |
783 | BDVK bdvk; |
791 | BDVK bdvk; |
784 | if (GetFileInfo(_path, #bdvk)!=0) { |
792 | if (GetFileInfo(_path, #bdvk)!=0) { |
785 | return 0; |
793 | return 0; |
786 | } else { |
794 | } else { |
787 | return bdvk.sizelo; |
795 | return bdvk.sizelo; |
788 | } |
796 | } |
789 | } |
797 | } |
790 | 798 | ||
791 | void EventUpdateBrowser() |
799 | void EventUpdateBrowser() |
792 | { |
800 | { |
793 | dword downloader_id, slot_n; |
801 | dword downloader_id, slot_n; |
794 | dword current_size; |
802 | dword current_size; |
795 | dword new_size; |
803 | dword new_size; |
796 | int error; |
804 | int error; |
797 | 805 | ||
798 | draw_window(); |
806 | draw_window(); |
799 | 807 | ||
800 | downloader_id = RunProgram(#program_path, #update_param); |
808 | downloader_id = RunProgram(#program_path, #update_param); |
801 | do { |
809 | do { |
802 | slot_n = GetProcessSlot(downloader_id); |
810 | slot_n = GetProcessSlot(downloader_id); |
803 | pause(10); |
811 | pause(10); |
804 | } while (slot_n!=0); |
812 | } while (slot_n!=0); |
805 | 813 | ||
806 | current_size = GetFileSize(#program_path); |
814 | current_size = GetFileSize(#program_path); |
807 | new_size = GetFileSize("/tmp0/1/Downloads/WebView.com"); |
815 | new_size = GetFileSize("/tmp0/1/Downloads/WebView.com"); |
808 | 816 | ||
809 | if (!new_size) || (new_size<5000) { |
817 | if (!new_size) || (new_size<5000) { |
810 | notify(#update_download_error); |
818 | notify(#update_download_error); |
811 | return; |
819 | return; |
812 | } |
820 | } |
813 | 821 | ||
814 | if (current_size == new_size) { |
822 | if (current_size == new_size) { |
815 | notify(#update_is_current); |
823 | notify(#update_is_current); |
816 | return; |
824 | return; |
817 | } |
825 | } |
818 | 826 | ||
819 | if (error = CopyFileAtOnce(new_size, "/tmp0/1/Downloads/WebView.com", #program_path)) { |
827 | if (error = CopyFileAtOnce(new_size, "/tmp0/1/Downloads/WebView.com", #program_path)) { |
820 | notify(#update_can_not_copy); |
828 | notify(#update_can_not_copy); |
821 | } else { |
829 | } else { |
822 | notify(#update_ok); |
830 | notify(#update_ok); |
823 | RunProgram(#program_path, history.current()); |
831 | RunProgram(#program_path, history.current()); |
824 | ExitProcess(); |
832 | ExitProcess(); |
825 | } |
833 | } |
826 | } |
834 | } |
827 | 835 | ||
828 | void DrawStatusBar(dword _status_text) |
836 | void DrawStatusBar(dword _status_text) |
829 | { |
837 | { |
830 | status_text.font_color = system.color.work_text; |
838 | status_text.font_color = system.color.work_text; |
831 | status_text.start_x = 10; |
839 | status_text.start_x = 10; |
832 | status_text.start_y = Form.cheight - STATUSBAR_H + 4; |
840 | status_text.start_y = Form.cheight - STATUSBAR_H + 4; |
833 | status_text.area_size_x = Form.cwidth - status_text.start_x -3 - 70; |
841 | status_text.area_size_x = Form.cwidth - status_text.start_x -3 - 70; |
834 | //DrawBar(status_text.start_x, status_text.start_y, status_text.area_size_x, 9, system.color.work); |
842 | //DrawBar(status_text.start_x, status_text.start_y, status_text.area_size_x, 9, system.color.work); |
835 | DrawBar(0,Form.cheight - STATUSBAR_H+1, Form.cwidth,STATUSBAR_H-1, system.color.work); |
843 | DrawBar(0,Form.cheight - STATUSBAR_H+1, Form.cwidth,STATUSBAR_H-1, system.color.work); |
836 | if (_status_text) { |
844 | if (_status_text) { |
837 | status_text.text_pointer = _status_text; |
845 | status_text.text_pointer = _status_text; |
838 | PathShow_prepare stdcall(#status_text); |
846 | PathShow_prepare stdcall(#status_text); |
839 | PathShow_draw stdcall(#status_text); |
847 | PathShow_draw stdcall(#status_text); |
840 | } |
848 | } |
841 | DefineHiddenButton(status_text.start_x+status_text.area_size_x+10, status_text.start_y-3, |
849 | DefineHiddenButton(status_text.start_x+status_text.area_size_x+10, status_text.start_y-3, |
842 | 60, 12, CHANGE_ENCODING); |
850 | 60, 12, CHANGE_ENCODING); |
843 | WriteTextCenter(status_text.start_x+status_text.area_size_x+10, |
851 | WriteTextCenter(status_text.start_x+status_text.area_size_x+10, |
844 | status_text.start_y, 60, system.color.work_text, WB1.cur_encoding*10+#charsets); |
852 | status_text.start_y, 60, system.color.work_text, WB1.cur_encoding*10+#charsets); |
845 | } |
853 | } |
846 | 854 | ||
847 | void DrawOmnibox() |
855 | void DrawOmnibox() |
848 | { |
856 | { |
849 | int imgxoff; |
857 | int imgxoff; |
850 | 858 | ||
851 | DrawOvalBorder(address_box.left-2, address_box.top-3, address_box.width+18, 24, system.color.work_graph, |
859 | DrawOvalBorder(address_box.left-2, address_box.top-3, address_box.width+18, 24, system.color.work_graph, |
852 | system.color.work_graph, system.color.work_graph, system.color.work_dark); |
860 | system.color.work_graph, system.color.work_graph, system.color.work_dark); |
853 | DrawBar(address_box.left-1, address_box.top-2, address_box.width+18, 1, 0xD8DCD8); |
861 | DrawBar(address_box.left-1, address_box.top-2, address_box.width+18, 1, 0xD8DCD8); |
854 | DrawBar(address_box.left-1, address_box.top-1, address_box.width+18, 1, address_box.color); |
862 | DrawBar(address_box.left-1, address_box.top-1, address_box.width+18, 1, address_box.color); |
855 | DrawBar(address_box.left-1, address_box.top, 1, 22, address_box.color); |
863 | DrawBar(address_box.left-1, address_box.top, 1, 22, address_box.color); |
856 | 864 | ||
857 | if (address_box.flags & ed_focus) address_box.flags = ed_focus; else address_box.flags = 0; |
865 | if (address_box.flags & ed_focus) address_box.flags = ed_focus; else address_box.flags = 0; |
858 | EditBox_UpdateText(#address_box, address_box.flags); |
866 | EditBox_UpdateText(#address_box, address_box.flags); |
859 | edit_box_draw stdcall(#address_box); |
867 | edit_box_draw stdcall(#address_box); |
860 | if (http.transfer) imgxoff = 16*23*3; else imgxoff = 0; |
868 | if (http.transfer) imgxoff = 16*23*3; else imgxoff = 0; |
861 | _PutImage(address_box.left+address_box.width+1, address_box.top-1, 16, 23, imgxoff + #editbox_icons); |
869 | _PutImage(address_box.left+address_box.width+1, address_box.top-1, 16, 23, imgxoff + #editbox_icons); |
862 | DefineHiddenButton(address_box.left+address_box.width-1, address_box.top-2, 17, 23, REFRESH_BUTTON); |
870 | DefineHiddenButton(address_box.left+address_box.width-1, address_box.top-2, 17, 23, REFRESH_BUTTON); |
863 | 871 | ||
864 | DrawProgress(); |
872 | DrawProgress(); |
865 | } |
873 | } |
866 | 874 | ||
867 | void SetOmniboxText(dword _text) |
875 | void SetOmniboxText(dword _text) |
868 | { |
876 | { |
869 | strcpy(#editURL, _text); |
877 | strcpy(#editURL, _text); |
870 | address_box.flags=0; |
878 | address_box.flags=0; |
871 | DrawOmnibox(); |
879 | DrawOmnibox(); |
872 | } |
880 | } |
873 | 881 | ||
874 | 882 | ||
875 | stop:5000)>=2;>=5)>>=>280)>120)> |
883 | stop:5000)>=2;>=5)>>=>280)>120)> |