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