Rev 6746 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
6058 | leency | 1 | #define MEMSIZE 4096*60 |
6043 | leency | 2 | |
6805 | leency | 3 | #include "../lib/kfont.h" |
6043 | leency | 4 | #include "../lib/io.h" |
5 | #include "../lib/gui.h" |
||
6 | #include "../lib/list_box.h" |
||
7 | #include "../lib/menu.h" |
||
8 | #include "../lib/obj/box_lib.h" |
||
9 | #include "../lib/obj/libini.h" |
||
10 | #include "../lib/obj/iconv.h" |
||
11 | #include "../lib/obj/proc_lib.h" |
||
12 | #include "../lib/obj/http.h" |
||
6059 | leency | 13 | #include "../lib/cursor.h" |
6043 | leency | 14 | #include "../lib/patterns/libimg_load_skin.h" |
15 | #include "../lib/patterns/simple_open_dialog.h" |
||
16 | #include "../lib/patterns/history.h" |
||
6058 | leency | 17 | #include "../lib/patterns/http_downloader.h" |
6366 | leency | 18 | #include "../browser/download_manager.h" |
6043 | leency | 19 | |
20 | char default_dir[] = "/rd/1"; |
||
21 | od_filter filter2 = {0,0}; |
||
22 | |||
23 | char accept_language[]= "Accept-Language: ru\n"; |
||
24 | |||
25 | #define TOOLBAR_H 36 |
||
26 | #define TOOLBAR_ICON_WIDTH 26 |
||
27 | #define TOOLBAR_ICON_HEIGHT 24 |
||
28 | |||
29 | #define DEFAULT_EDITOR "/sys/tinypad" |
||
30 | #define DEFAULT_PREVIEW_PATH "/tmp0/1/aelia_preview.txt" |
||
31 | |||
32 | //ATTENTION: each page must have '\0' character at the end of the file |
||
33 | char buidin_page_home[] = FROM "buidin_pages\\home.htm"; |
||
34 | char buidin_page_about[] = FROM "buidin_pages\\about.htm"; |
||
35 | char buidin_page_not_found[] = FROM "buidin_pages\\not_found.htm"; |
||
36 | |||
37 | #define UML 4096*2 |
||
38 | |||
39 | scroll_bar scroll = { 15,200,398,44,0,2,115,15,0,0xeeeeee,0xBBBbbb,0xeeeeee,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1}; |
||
40 | llist list; |
||
41 | |||
42 | proc_info Form; |
||
43 | char title[4196]; |
||
44 | |||
45 | enum { |
||
46 | OPEN_FILE, |
||
47 | MAGNIFY_MINUS, |
||
48 | MAGNIFY_PLUS, |
||
49 | CHANGE_ENCODING, |
||
50 | RUN_EDIT, |
||
51 | GO_BACK, |
||
52 | GO_FORWARD, |
||
6058 | leency | 53 | SANDWICH |
6043 | leency | 54 | }; |
55 | |||
56 | char address[UML]="http://"; |
||
57 | int mouse_address_box; |
||
58 | edit_box address_box = {250,56,34,0xffffff,0x94AECE,0xffffff,0xffffff,0,UML,#address,#mouse_address_box,2,19,19}; |
||
59 | |||
6059 | leency | 60 | CustomCursor CursorPointer; |
61 | dword CursorFile = FROM "pointer.cur"; |
||
62 | |||
6152 | leency | 63 | #include "favicon.h" |
6043 | leency | 64 | #include "ini.h" |
65 | #include "gui.h" |
||
6053 | leency | 66 | #include "label.h" |
6058 | leency | 67 | #include "link.h" |
6217 | leency | 68 | #include "tag.h" |
6043 | leency | 69 | #include "prepare_page.h" |
6058 | leency | 70 | //#include "special_symbols.h" |
6043 | leency | 71 | |
6366 | leency | 72 | #define SANDWICH_MENU "Refresh page\nEdit page\nHistory\nDownloader\nAbout" |
6058 | leency | 73 | |
6043 | leency | 74 | void InitDlls() |
75 | { |
||
76 | load_dll(boxlib, #box_lib_init, 0); |
||
77 | load_dll(libHTTP, #http_lib_init, 1); |
||
78 | load_dll(libio, #libio_init, 1); |
||
79 | load_dll(libimg, #libimg_init, 1); |
||
80 | //load_dll(libini, #lib_init, 1); |
||
81 | load_dll(iconv_lib, #iconv_open, 0); |
||
82 | load_dll(Proc_lib, #OpenDialog_init,0); |
||
83 | } |
||
84 | |||
85 | |||
86 | void main() |
||
6058 | leency | 87 | { |
6043 | leency | 88 | InitDlls(); |
89 | OpenDialog_init stdcall (#o_dialog); |
||
6059 | leency | 90 | CursorPointer.Load(#CursorFile); |
6043 | leency | 91 | label.init(DEFAULT_FONT); |
92 | Libimg_LoadImage(#skin, abspath("toolbar.png")); |
||
93 | LoadIniSettings(); |
||
94 | list.no_selection = true; |
||
95 | SetEventMask(10000000000000000000000001100111b); |
||
96 | loop() |
||
97 | { |
||
98 | switch(WaitEvent()) |
||
99 | { |
||
100 | case evMouse: |
||
101 | HandleMouseEvent(); |
||
102 | break; |
||
103 | case evKey: |
||
104 | HandleKeyEvent(); |
||
105 | break; |
||
106 | case evButton: |
||
107 | HandleButtonEvent(); |
||
108 | break; |
||
109 | case evReDraw: |
||
6053 | leency | 110 | draw_window(); |
6058 | leency | 111 | if (menu.list.cur_y>=10) && (menu.list.cur_y<20) { |
6043 | leency | 112 | encoding = menu.list.cur_y - 10; |
6058 | leency | 113 | EventPageRefresh(); |
6053 | leency | 114 | menu.list.cur_y = 0; |
6043 | leency | 115 | } |
6058 | leency | 116 | if (menu.list.cur_y>=20) { |
117 | menu.list.cur_y-=20; |
||
118 | if (menu.list.cur_y==0) EventPageRefresh(); |
||
119 | if (menu.list.cur_y==1) EventRunEdit(); |
||
120 | if (menu.list.cur_y==2) EventShowHistory(); |
||
6366 | leency | 121 | if (menu.list.cur_y==3) EventShowDownloader(); |
122 | if (menu.list.cur_y==4) EventShowInfo(); |
||
6058 | leency | 123 | menu.list.cur_y = 0; |
124 | } |
||
6043 | leency | 125 | } |
126 | } |
||
127 | } |
||
128 | |||
129 | |||
130 | void HandleButtonEvent() |
||
131 | { |
||
132 | byte btn = GetButtonID(); |
||
133 | if (btn==1) { |
||
134 | SaveIniSettings(); |
||
135 | ExitProcess(); |
||
136 | } |
||
137 | switch(btn-10) |
||
138 | { |
||
139 | case GO_BACK: |
||
140 | EventGoBack(); |
||
141 | break; |
||
142 | case GO_FORWARD: |
||
143 | EventGoForward(); |
||
144 | break; |
||
145 | case OPEN_FILE: |
||
146 | EventOpenDialog(); |
||
147 | break; |
||
148 | case MAGNIFY_PLUS: |
||
149 | EventMagnifyPlus(); |
||
150 | break; |
||
151 | case MAGNIFY_MINUS: |
||
152 | EventMagnifyMinus(); |
||
153 | break; |
||
154 | case CHANGE_ENCODING: |
||
155 | EventChangeEncoding(); |
||
156 | break; |
||
157 | case RUN_EDIT: |
||
158 | EventRunEdit(); |
||
159 | break; |
||
6058 | leency | 160 | case SANDWICH: |
161 | EventShowSandwichMenu(); |
||
6043 | leency | 162 | break; |
163 | } |
||
164 | } |
||
165 | |||
166 | |||
167 | void HandleKeyEvent() |
||
168 | { |
||
169 | GetKeys(); |
||
170 | switch (key_scancode) |
||
171 | { |
||
172 | case 059: |
||
173 | EventShowInfo(); |
||
174 | return; |
||
175 | case SCAN_CODE_ENTER: |
||
176 | EventOpenAddress(#address); |
||
177 | return; |
||
178 | case SCAN_CODE_BS: |
||
179 | if (! address_box.flags & 0b10) { |
||
180 | EventGoBack(); |
||
181 | return; |
||
182 | } |
||
183 | } |
||
184 | if (key_modifier & KEY_LCTRL) || (key_modifier & KEY_RCTRL) { |
||
185 | switch (key_scancode) |
||
186 | { |
||
187 | case 024: //O |
||
188 | EventOpenDialog(); |
||
189 | break; |
||
190 | case SCAN_CODE_UP: |
||
191 | EventMagnifyPlus(); |
||
192 | break; |
||
193 | case SCAN_CODE_DOWN: |
||
194 | EventMagnifyMinus(); |
||
195 | break; |
||
196 | case 018: //E |
||
197 | EventRunEdit(); |
||
198 | break; |
||
199 | case 035: //H |
||
200 | EventShowHistory(); |
||
201 | break; |
||
202 | case SCAN_CODE_TAB: |
||
203 | EventChangeEncoding(); |
||
204 | break; |
||
205 | } |
||
206 | } |
||
207 | if (list.ProcessKey(key_scancode)) { |
||
208 | DrawPage(); |
||
209 | return; |
||
210 | } |
||
211 | if (key_ascii != 0x0d) |
||
212 | && (key_ascii != ASCII_KEY_PGDN) |
||
213 | && (key_ascii != ASCII_KEY_PGUP) { |
||
6641 | leency | 214 | EAX = key_editbox; |
6043 | leency | 215 | edit_box_key stdcall(#address_box); |
216 | } |
||
217 | } |
||
218 | |||
219 | |||
220 | void HandleMouseEvent() |
||
221 | { |
||
222 | edit_box_mouse stdcall (#address_box); |
||
223 | mouse.get(); |
||
224 | list.wheel_size = 7; |
||
6058 | leency | 225 | link.hover(); |
6043 | leency | 226 | if (list.MouseScroll(mouse.vert)) { |
227 | DrawPage(); |
||
228 | return; |
||
229 | } |
||
230 | scrollbar_v_mouse (#scroll); |
||
231 | if (list.first != scroll.position) { |
||
232 | list.first = scroll.position; |
||
233 | DrawPage(); |
||
234 | } |
||
235 | } |
||
236 | |||
237 | |||
238 | /* ----------------------------------------------------- */ |
||
239 | |||
240 | void EventOpenDialog() |
||
241 | { |
||
242 | OpenDialog_start stdcall (#o_dialog); |
||
243 | if (o_dialog.status) EventOpenAddress(#openfile_path); |
||
244 | } |
||
245 | |||
246 | void EventOpenAddress(dword _new_address) |
||
247 | { |
||
248 | char temp[UML]; |
||
6152 | leency | 249 | char favicon_address[UML]; |
6043 | leency | 250 | if (!ESBYTE[_new_address]) return; |
251 | debugln("===================================="); |
||
252 | debug("address: "); |
||
253 | debugln(_new_address); |
||
254 | strlcpy(#address, _new_address, UML); |
||
255 | strlwr(#address); |
||
256 | DrawAddressBox(); |
||
257 | |||
258 | /* |
||
259 | There could be several possible types of addresses: |
||
260 | - build in page |
||
261 | - local file |
||
262 | - url |
||
263 | So we need to detect what incoming address is |
||
264 | and then halndle it in the propper way. |
||
265 | */ |
||
266 | |||
267 | io.buffer_data = 0; |
||
6152 | leency | 268 | favicon.get(NULL); |
6043 | leency | 269 | |
270 | // - build in page |
||
271 | if (!strncmp(#address,"aelia:",6)) { |
||
272 | debugln("this is buildin page"); |
||
273 | if (!strcmp(#address,"aelia:home")) io.buffer_data = #buidin_page_home; |
||
274 | if (!strcmp(#address,"aelia:about")) io.buffer_data = #buidin_page_about; |
||
275 | if (!strcmp(#address,"aelia:history")) io.buffer_data = MakePageWithHistory(); |
||
276 | } |
||
277 | // - local file |
||
278 | else if (check_is_the_adress_local(#address)==true) { |
||
279 | debugln("this is local address"); |
||
280 | io.read(#address); |
||
281 | } |
||
282 | // - url |
||
283 | else { |
||
284 | debugln("this is url"); |
||
285 | if (strncmp(#address,"http://",7)!=0) { |
||
286 | strcpy(#temp, "http://"); |
||
287 | strlcpy(#temp, #address, UML); |
||
288 | strlcpy(#address, #temp, UML); |
||
289 | DrawAddressBox(); |
||
290 | } |
||
291 | if (!downloader.Start(#address)) { |
||
292 | downloader.Stop(); |
||
6053 | leency | 293 | } else { |
6043 | leency | 294 | while (downloader.state!=STATE_COMPLETED) |
295 | { |
||
296 | downloader.MonitorProgress(); |
||
297 | if (downloader.data_full_size>0) |
||
298 | DrawProgress(STEP_2_COUNT_PAGE_HEIGHT-STEP_1_DOWNLOAD_PAGE*downloader.data_downloaded_size/downloader.data_full_size); |
||
299 | else |
||
300 | DrawProgress(STEP_2_COUNT_PAGE_HEIGHT-STEP_1_DOWNLOAD_PAGE/2); |
||
301 | } |
||
6058 | leency | 302 | strcpy(#address,downloader.url); |
303 | DrawAddressBox(); |
||
6043 | leency | 304 | io.buffer_data = downloader.bufpointer; |
6152 | leency | 305 | get_absolute_url(#favicon_address, #address, "/favicon.ico"); |
306 | favicon.get(#favicon_address); |
||
6043 | leency | 307 | } |
308 | } |
||
309 | |||
310 | if (!io.buffer_data) { |
||
311 | debugln("page not found"); |
||
312 | io.buffer_data = #buidin_page_not_found; |
||
313 | } |
||
314 | |||
315 | history.add(#address); |
||
6152 | leency | 316 | favicon.draw(address_box.left-18, address_box.top-1); |
6043 | leency | 317 | |
318 | /* |
||
319 | Great! So we have the page in our buffer. |
||
320 | We don't know is it a plain text or html. |
||
321 | So we need to parse it and draw. |
||
322 | */ |
||
323 | |||
324 | list.KeyHome(); |
||
325 | list.ClearList(); |
||
326 | PreparePage(); |
||
327 | } |
||
328 | |||
329 | void EventMagnifyPlus() |
||
330 | { |
||
331 | label.size.pt++; |
||
332 | if(!label.changeSIZE()) |
||
333 | label.size.pt--; |
||
334 | else |
||
335 | PreparePage(); |
||
336 | } |
||
337 | |||
338 | void EventMagnifyMinus() |
||
339 | { |
||
340 | label.size.pt--; |
||
341 | if(!label.changeSIZE()) |
||
342 | label.size.pt++; |
||
343 | else |
||
344 | PreparePage(); |
||
345 | } |
||
346 | |||
347 | void EventRunEdit() |
||
348 | { |
||
349 | if (check_is_the_adress_local(history.current())==true) { |
||
350 | io.run(DEFAULT_EDITOR, history.current()); |
||
351 | } |
||
352 | else { |
||
353 | //io.write(strlen(io.buffer_data), io.buffer_data, DEFAULT_PREVIEW_PATH); // <--- doesn't work, smth odd, need to check |
||
354 | WriteFile(strlen(io.buffer_data), io.buffer_data, DEFAULT_PREVIEW_PATH); |
||
355 | io.run(DEFAULT_EDITOR, DEFAULT_PREVIEW_PATH); |
||
356 | } |
||
357 | } |
||
358 | |||
359 | void EventChangeEncoding() |
||
360 | { |
||
361 | menu.selected = encoding + 1; |
||
362 | menu.show(Form.left+Form.cwidth-97,Form.top+TOOLBAR_H+skin_height-6, 130, "UTF-8\nKOI8-RU\nCP1251\nCP1252\nISO8859-5\nCP866", 10); |
||
363 | } |
||
364 | |||
365 | void EventShowInfo() { |
||
366 | EventOpenAddress("aelia:about"); |
||
367 | } |
||
368 | |||
369 | void EventShowHistory() |
||
370 | { |
||
371 | EventOpenAddress("aelia:history"); |
||
372 | } |
||
373 | |||
374 | void EventGoBack() |
||
375 | { |
||
376 | if (history.back()) EventOpenAddress(history.current()); |
||
377 | } |
||
378 | |||
379 | void EventGoForward() |
||
380 | { |
||
381 | if (history.forward()) EventOpenAddress(history.current()); |
||
382 | } |
||
383 | |||
6058 | leency | 384 | void EventShowSandwichMenu() |
385 | { |
||
386 | menu.selected = 0; |
||
387 | menu.show(Form.left+Form.cwidth-130,Form.top+TOOLBAR_H+skin_height-10, 130, SANDWICH_MENU, 20); |
||
388 | } |
||
389 | |||
390 | void EventPageRefresh() |
||
391 | { |
||
392 | EventOpenAddress(history.current()); |
||
393 | } |
||
394 | |||
6366 | leency | 395 | void EventShowDownloader() |
396 | { |
||
397 | if (!downloader_opened) { |
||
398 | downloader_edit = NULL; |
||
399 | CreateThread(#Downloader,#downloader_stak+4092); |
||
400 | } |
||
401 | } |
||
402 | |||
6043 | leency | 403 | /* ------------------------------------------- */ |
404 | |||
405 | |||
406 | void draw_window() |
||
407 | { |
||
6746 | leency | 408 | DefineAndDrawWindow(Form.left,Form.top,Form.width,Form.height,0x73,0,#title,0); |
6043 | leency | 409 | GetProcessInfo(#Form, SelfInfo); |
410 | if (Form.status_window>2) return; |
||
411 | |||
412 | if (Form.width < 200) { MoveSize(OLD,OLD,200,OLD); return; } |
||
413 | if (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); return; } |
||
414 | |||
415 | DrawBar(0, 0, Form.cwidth, TOOLBAR_H - 2, 0xe1e1e1); |
||
416 | DrawBar(0, TOOLBAR_H - 2, Form.cwidth, 1, 0xcecece); |
||
417 | DrawBar(0, TOOLBAR_H - 1, Form.cwidth, 1, 0x7F7F7F); |
||
418 | |||
419 | DrawToolbarButton(GO_BACK, 8); |
||
420 | DrawToolbarButton(GO_FORWARD, 33); |
||
421 | DrawToolbarButton(OPEN_FILE, 68); |
||
6058 | leency | 422 | DrawToolbarButton(MAGNIFY_PLUS, Form.cwidth - 125); |
423 | DrawToolbarButton(MAGNIFY_MINUS, Form.cwidth - 100); |
||
424 | DrawToolbarButton(CHANGE_ENCODING, Form.cwidth - 64); |
||
425 | DrawToolbarButton(SANDWICH, Form.cwidth - 31); |
||
6043 | leency | 426 | |
427 | DrawAddressBox(); |
||
428 | |||
429 | if ((Form.cwidth-scroll.size_x-1 == list.w) && |
||
430 | (Form.cheight-TOOLBAR_H == list.h) && |
||
431 | (list.count) |
||
432 | ) |
||
433 | { |
||
434 | DrawPage(); |
||
435 | } |
||
436 | else |
||
437 | { |
||
438 | if (!label.raw) { //this code need to be run |
||
439 | if (param) EventOpenAddress(#param); //only once at browser sturtup |
||
440 | else EventOpenAddress("aelia:home"); |
||
441 | } |
||
442 | else PreparePage(); |
||
443 | } |
||
444 | |||
445 | DrawRectangle(scroll.start_x, scroll.start_y, scroll.size_x, scroll.size_y-1, scroll.bckg_col); |
||
446 | } |
||
447 | |||
448 | void DrawPage() |
||
449 | { |
||
450 | list.CheckDoesValuesOkey(); |
||
451 | if (list.count) _PutImage(list.x,list.y,list.w,list.h,list.first*list.item_h*list.w*3 + label.raw); |
||
452 | DrawScroller(); |
||
453 | } |
||
454 | |||
455 | void DrawAddressBox() |
||
456 | { |
||
6152 | leency | 457 | address_box.left = 97+19; |
6043 | leency | 458 | address_box.top = 11; |
6058 | leency | 459 | address_box.width = Form.cwidth - address_box.left - 138; |
6152 | leency | 460 | DrawRectangle(address_box.left-4-19, address_box.top-5, address_box.width+6+19, 23, 0x8C8C8C); |
461 | DrawWideRectangle(address_box.left-3-19, address_box.top-3, address_box.width+5+19, 21, 4, address_box.color); |
||
6043 | leency | 462 | address_box.size = address_box.pos = address_box.shift = address_box.shift_old = strlen(#address); |
463 | address_box.offset = 0; |
||
464 | edit_box_draw stdcall(#address_box); |
||
6152 | leency | 465 | favicon.draw(address_box.left-18, address_box.top-1); |
466 | DrawBar(address_box.left-2, address_box.top+1, 2, 13, 0xFFFfff); |
||
6043 | leency | 467 | }>>--->20)> |