Rev 4508 | Rev 4534 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
3067 | leency | 1 | //HTML Viewer in C-- |
3987 | leency | 2 | //Copyright 2007-2013 by Veliant & Leency |
3107 | leency | 3 | //Asper, lev, Lrz, Barsuk, Nable... |
3067 | leency | 4 | //home icon - rachel fu, GPL licence |
5 | |||
4085 | leency | 6 | #ifndef AUTOBUILD |
7 | #include "lang.h--" |
||
8 | #endif |
||
9 | |||
3107 | leency | 10 | //libraries |
3363 | leency | 11 | #define MEMSIZE 0x100000 |
3067 | leency | 12 | #include "..\lib\kolibri.h" |
13 | #include "..\lib\strings.h" |
||
14 | #include "..\lib\figures.h" |
||
15 | #include "..\lib\encoding.h" |
||
16 | #include "..\lib\file_system.h" |
||
17 | #include "..\lib\mem.h" |
||
18 | #include "..\lib\dll.h" |
||
4508 | leency | 19 | #include "..\lib\draw_buf.h" |
20 | #include "..\lib\list_box.h" |
||
21 | #include "..\lib\cursor.h" |
||
22 | |||
3107 | leency | 23 | //*.obj libraries |
24 | #include "..\lib\lib.obj\box_lib.h" |
||
25 | #include "..\lib\lib.obj\libio_lib.h" |
||
26 | #include "..\lib\lib.obj\libimg_lib.h" |
||
27 | //images |
||
3067 | leency | 28 | #include "img\toolbar_icons.c" |
29 | #include "img\URLgoto.txt"; |
||
30 | |||
4026 | leency | 31 | #ifdef LANG_RUS |
4497 | leency | 32 | char version[]=" Текстовый браузер 0.99.64"; |
4416 | leency | 33 | ?define IMAGES_CACHE_CLEARED "Кэш картинок очищен" |
4417 | leency | 34 | ?define T_LAST_SLIDE "Это последний слайд" |
4026 | leency | 35 | #else |
4497 | leency | 36 | char version[]=" Text-based Browser 0.99.64"; |
4026 | leency | 37 | ?define IMAGES_CACHE_CLEARED "Images cache cleared" |
4417 | leency | 38 | ?define T_LAST_SLIDE "This slide is the last" |
4026 | leency | 39 | #endif |
40 | |||
3067 | leency | 41 | proc_info Form; |
42 | #define WIN_W 640 |
||
43 | #define WIN_H 480 |
||
44 | |||
4416 | leency | 45 | char search_path[]="http://nigma.ru/index.php?s="; |
3067 | leency | 46 | |
4074 | leency | 47 | char stak[4096]; |
3067 | leency | 48 | mouse m; |
4026 | leency | 49 | int action_buf; |
50 | |||
4411 | leency | 51 | #include "..\TWB\TWB.c" |
52 | #include "menu_rmb.h" |
||
3067 | leency | 53 | |
4488 | leency | 54 | enum { BACK=300, FORWARD, REFRESH, HOME, NEWTAB, GOTOURL, SEARCHWEB, INPUT_CH, INPUT_BT, BTN_UP, BTN_DOWN }; |
3067 | leency | 55 | |
4488 | leency | 56 | |
3067 | leency | 57 | void main() |
58 | { |
||
4081 | leency | 59 | int key, btn; |
3067 | leency | 60 | int half_scroll_size; |
4026 | leency | 61 | int scroll_used=0, show_menu; |
3067 | leency | 62 | |
63 | mem_Init(); |
||
3107 | leency | 64 | if (load_dll2(boxlib, #box_lib_init,0)!=0) {notify("System Error: library doesn't exists /rd/1/lib/box_lib.obj"); ExitProcess();} |
4415 | leency | 65 | if (load_dll2(libio, #libio_init,1)!=0) debug("Error: library doesn't exists - libio"); |
66 | if (load_dll2(libimg, #libimg_init,1)!=0) debug("Error: library doesn't exists - libimg"); |
||
3067 | leency | 67 | |
4508 | leency | 68 | if (!URL) strcpy(#URL, "/sys/index.htm"); |
4497 | leency | 69 | CursorPointer.Load(#CursorFile); |
3067 | leency | 70 | Form.width=WIN_W; |
71 | Form.height=WIN_H; |
||
72 | SetElementSizes(); |
||
4416 | leency | 73 | OpenPage(); |
3067 | leency | 74 | |
75 | SetEventMask(0x27); |
||
76 | loop() |
||
77 | { |
||
78 | WaitEventTimeout(2); |
||
79 | switch(EAX & 0xFF) |
||
80 | { |
||
81 | CASE evMouse: |
||
4081 | leency | 82 | if (!CheckActiveProcess(Form.ID)) break; |
3067 | leency | 83 | |
3466 | leency | 84 | edit_box_mouse stdcall (#address_box); |
3067 | leency | 85 | |
86 | m.get(); |
||
4492 | leency | 87 | PageLinks.Hover(m.x, m.y, link_color_inactive, link_color_active, bg_color); |
3067 | leency | 88 | |
4414 | leency | 89 | if (m.y>WB1.list.y) && (m.y |
3067 | leency | 90 | { |
4026 | leency | 91 | if (m.pkm) |
92 | { |
||
93 | show_menu = 1; |
||
94 | } |
||
95 | if (!m.pkm) && (show_menu) |
||
96 | { |
||
97 | show_menu = 0; |
||
98 | SwitchToAnotherThread(); |
||
4074 | leency | 99 | CreateThread(#menu_rmb,#stak+4092); |
4026 | leency | 100 | break; |
101 | } |
||
3067 | leency | 102 | } |
103 | |||
4415 | leency | 104 | if (m.vert) |
3067 | leency | 105 | { |
4415 | leency | 106 | if (WB1.list.MouseScroll(m.vert)) WB1.ParseHTML(buf); |
3067 | leency | 107 | } |
108 | |||
109 | if (!m.lkm) scroll_used=0; |
||
4416 | leency | 110 | if (m.x>=scroll_wv.start_x) && (m.x<=scroll_wv.start_x+scroll_wv.size_x) |
111 | && (m.y>=scroll_wv.start_y+scroll_wv.btn_height) && (-scroll_wv.btn_height+scroll_wv.start_y+scroll_wv.size_y>m.y) |
||
4415 | leency | 112 | && (WB1.list.count>WB1.list.visible) && (m.lkm) |
4026 | leency | 113 | { |
114 | scroll_used=1; |
||
115 | } |
||
3067 | leency | 116 | |
117 | if (scroll_used) |
||
118 | { |
||
4415 | leency | 119 | half_scroll_size = WB1.list.h - 16 * WB1.list.visible / WB1.list.count - 3 /2; |
4416 | leency | 120 | if (half_scroll_size+WB1.list.y>m.y) || (m.y<0) || (m.y>4000) m.y=half_scroll_size+WB1.list.y; |
121 | btn=WB1.list.first; |
||
4415 | leency | 122 | WB1.list.first = m.y -half_scroll_size -WB1.list.y * WB1.list.count / WB1.list.h; |
123 | if (WB1.list.visible+WB1.list.first>WB1.list.count) WB1.list.first=WB1.list.count-WB1.list.visible; |
||
4416 | leency | 124 | if (btn<>WB1.list.first) WB1.ParseHTML(buf); |
3067 | leency | 125 | } |
126 | |||
127 | break; |
||
128 | case evButton: |
||
129 | btn=GetButtonID(); |
||
3464 | leency | 130 | if (btn==1) |
3067 | leency | 131 | { |
132 | KillProcess(downloader_id); |
||
133 | ExitProcess(); |
||
134 | } |
||
135 | ELSE |
||
136 | { |
||
4413 | leency | 137 | Scan(btn); |
3067 | leency | 138 | } |
139 | break; |
||
140 | case evKey: |
||
141 | key = GetKey(); |
||
142 | |||
4416 | leency | 143 | if (address_box.flags & 0b10) SWITCH(key) |
3067 | leency | 144 | { CASE 52: CASE 53: CASE 54: goto _EDIT_MARK; } |
145 | |||
4413 | leency | 146 | Scan(key); |
3067 | leency | 147 | |
148 | _EDIT_MARK: |
||
4416 | leency | 149 | if (key<>0x0d) && (key<>183) && (key<>184) {EAX=key<<8; edit_box_key stdcall(#address_box);} |
3067 | leency | 150 | break; |
151 | case evReDraw: |
||
4413 | leency | 152 | if (action_buf) { Scan(action_buf); action_buf=0;} |
3067 | leency | 153 | Draw_Window(); |
154 | break; |
||
155 | default: |
||
156 | if (downloader_id<>0) |
||
157 | { |
||
158 | if (GetProcessSlot(downloader_id)<>0) break; |
||
159 | downloader_id=0; |
||
4415 | leency | 160 | WB1.list.first = WB1.list.count = 0; |
3067 | leency | 161 | WB1.ReadHtml(_WIN); |
162 | Draw_Window(); |
||
163 | } |
||
164 | } |
||
165 | } |
||
166 | } |
||
167 | |||
168 | void SetElementSizes() |
||
169 | { |
||
4416 | leency | 170 | address_box.width = Form.width - 266; |
171 | WB1.list.SetSizes(0, 44, Form.width - 10 - scroll_wv.size_x, Form.cheight - 44, 0, 10); |
||
4415 | leency | 172 | WB1.list.column_max = WB1.list.w - 30 / 6; |
173 | WB1.list.visible = WB1.list.h - 3 / WB1.list.line_h - 2; |
||
4475 | leency | 174 | WB1.DrawBuf.Init(WB1.list.x, WB1.list.y, WB1.list.w, WB1.list.h, WB1.list.line_h); |
3067 | leency | 175 | } |
176 | |||
177 | |||
178 | void Draw_Window() |
||
179 | { |
||
180 | int j; |
||
3466 | leency | 181 | DefineAndDrawWindow(215,100,WIN_W,WIN_H,0x73,0xE4DFE1,0,0); |
3067 | leency | 182 | |
183 | GetProcessInfo(#Form, SelfInfo); |
||
3464 | leency | 184 | if (Form.status_window>2) |
3067 | leency | 185 | { |
186 | DrawTitle(#header); |
||
187 | return; |
||
188 | } |
||
189 | if (Form.height<120) MoveSize(OLD,OLD,OLD,120); |
||
190 | if (Form.width<280) MoveSize(OLD,OLD,280,OLD); |
||
191 | |||
192 | PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal); |
||
3363 | leency | 193 | if (GetProcessSlot(downloader_id)<>0) _PutImage(88,10, 24,24, #stop_btn); |
3067 | leency | 194 | |
3464 | leency | 195 | DrawBar(200,0,Form.cwidth-200,43,0xE4DFE1); |
196 | DrawBar(0,42,Form.cwidth,1,0xE2DBDC); |
||
197 | DrawBar(0,43,Form.cwidth,1,0xD2CED0); |
||
3067 | leency | 198 | for (j=0; j<5; j++) DefineButton(j*37+11, 7, 29, 29, 300+j+BT_HIDE, 0xE4DFE1); |
3464 | leency | 199 | _PutImage(Form.cwidth-48,14, 40,19, #URLgoto); |
200 | DefineButton(Form.cwidth-28,15, 18, 16, GOTOURL+BT_HIDE, 0xE4DFE1); |
||
201 | DefineButton(Form.cwidth-47,15, 17, 16, SEARCHWEB+BT_HIDE, 0xE4DFE1); |
||
202 | DrawRectangle(205,14,Form.cwidth-205-49,18,0x94AECE); //around adress bar |
||
203 | DrawRectangle(206,15,Form.cwidth-205-50,16,0xE4ECF3); |
||
3067 | leency | 204 | |
205 | SetElementSizes(); |
||
4508 | leency | 206 | ShowPage(); |
3464 | leency | 207 | |
4416 | leency | 208 | DefineButton(scroll_wv.start_x+1, scroll_wv.start_y+1, 16, 16, BTN_UP+BT_HIDE, 0xE4DFE1); |
209 | DefineButton(scroll_wv.start_x+1, scroll_wv.start_y+scroll_wv.size_y-18, 16, 16, BTN_DOWN+BT_HIDE, 0xE4DFE1); |
||
3067 | leency | 210 | } |
211 | |||
212 | |||
4413 | leency | 213 | void Scan(int id) |
214 | { |
||
4415 | leency | 215 | if (id >= 400) ProcessLinks(id); |
4413 | leency | 216 | |
217 | switch (id) |
||
218 | { |
||
219 | case 011: //Ctrk+K |
||
220 | WB1.ReadHtml(_KOI); |
||
4415 | leency | 221 | WB1.ParseHTML(buf); |
222 | return; |
||
223 | |||
4413 | leency | 224 | case 021: //Ctrl+U |
225 | WB1.ReadHtml(_UTF); |
||
4415 | leency | 226 | WB1.ParseHTML(buf); |
227 | return; |
||
228 | |||
4413 | leency | 229 | case 004: //Ctrl+D |
230 | WB1.ReadHtml(_DOS); |
||
4415 | leency | 231 | WB1.ParseHTML(buf); |
232 | return; |
||
233 | |||
4533 | leency | 234 | case 005: //Win encoding |
235 | WB1.ReadHtml(_WIN); |
||
236 | WB1.ParseHTML(buf); |
||
237 | return; |
||
238 | |||
239 | case 009: //free img cache |
||
4491 | leency | 240 | ImgCache.Free(); |
4416 | leency | 241 | notify(IMAGES_CACHE_CLEARED); |
4415 | leency | 242 | WB1.ParseHTML(buf); |
243 | return; |
||
244 | |||
4413 | leency | 245 | case BACK: |
246 | if (!BrowserHistory.GoBack()) return; |
||
4416 | leency | 247 | OpenPage(); |
4413 | leency | 248 | return; |
249 | case FORWARD: |
||
250 | if (!BrowserHistory.GoForward()) return; |
||
4416 | leency | 251 | OpenPage(); |
4413 | leency | 252 | return; |
253 | case 052: //F3 |
||
4488 | leency | 254 | if (strncmp(#URL,"http:",5)<>0) RunProgram("/rd/1/tinypad", #URL); |
4415 | leency | 255 | else RunProgram("/rd/1/tinypad", #download_path); |
4413 | leency | 256 | return; |
257 | case 054: //F5 |
||
4415 | leency | 258 | IF(address_box.flags & 0b10) WB1.ParseHTML(buf); |
259 | return; |
||
260 | |||
4413 | leency | 261 | case REFRESH: |
262 | if (GetProcessSlot(downloader_id)<>0) |
||
263 | { |
||
264 | KillProcess(downloader_id); |
||
265 | pause(20); |
||
266 | Draw_Window(); |
||
267 | return; |
||
268 | } |
||
4415 | leency | 269 | anchor_line_num=WB1.list.first; |
4413 | leency | 270 | anchor[0]='|'; |
4416 | leency | 271 | OpenPage(); |
4413 | leency | 272 | return; |
4415 | leency | 273 | case 014: |
274 | case 020: |
||
4413 | leency | 275 | case NEWTAB: |
276 | MoveSize(190,80,OLD,OLD); |
||
277 | RunProgram(#program_path, #URL); |
||
278 | return; |
||
279 | |||
280 | case HOME: |
||
281 | strcpy(#editURL, "http://kolibrios.org/en/index.htm"); |
||
282 | case GOTOURL: |
||
283 | case 0x0D: //enter |
||
284 | if ((strstr(#editURL,"ttp://")==0) && (editURL[0]!='/')) strcpy(#URL,"http://"); else URL[0] = 0; |
||
285 | strcat(#URL, #editURL); |
||
4416 | leency | 286 | OpenPage(); |
4413 | leency | 287 | return; |
288 | case SEARCHWEB: |
||
289 | strcpy(#URL, #search_path); |
||
290 | strcat(#URL, #editURL); |
||
4416 | leency | 291 | OpenPage(); |
4413 | leency | 292 | return; |
293 | |||
294 | case 183: //PgDown |
||
4415 | leency | 295 | if (WB1.list.count < WB1.list.visible) return; |
296 | IF(WB1.list.first == WB1.list.count - WB1.list.visible) return; |
||
297 | WB1.list.first += WB1.list.visible + 2; |
||
298 | IF(WB1.list.visible + WB1.list.first > WB1.list.count) WB1.list.first = WB1.list.count - WB1.list.visible; |
||
299 | WB1.ParseHTML(buf); |
||
300 | return; |
||
301 | |||
4413 | leency | 302 | case 184: //PgUp |
4415 | leency | 303 | if (WB1.list.count < WB1.list.visible) return; |
304 | IF(WB1.list.first == 0) return; |
||
305 | WB1.list.first -= WB1.list.visible - 2; |
||
306 | IF(WB1.list.first < 0) WB1.list.first = 0; |
||
307 | WB1.ParseHTML(buf); |
||
308 | return; |
||
309 | |||
310 | case 178: |
||
4416 | leency | 311 | case BTN_UP: //ьюЄрхь ттхЁї |
312 | if (WB1.list.first <= 0) return; |
||
4415 | leency | 313 | WB1.list.first--; |
314 | WB1.ParseHTML(buf); |
||
315 | return; |
||
316 | |||
317 | case 177: |
||
4416 | leency | 318 | case BTN_DOWN: //ьюЄрхь тэшч |
319 | if (WB1.list.visible + WB1.list.first >= WB1.list.count) return; |
||
4415 | leency | 320 | WB1.list.first++; |
321 | WB1.ParseHTML(buf); |
||
322 | return; |
||
323 | |||
4413 | leency | 324 | case 180: //home |
4415 | leency | 325 | if (WB1.list.KeyHome()) WB1.ParseHTML(buf); |
326 | return; |
||
327 | |||
4413 | leency | 328 | case 181: //end |
4415 | leency | 329 | if (WB1.list.count < WB1.list.visible) return; |
330 | if (WB1.list.KeyEnd()) WB1.ParseHTML(buf); |
||
4413 | leency | 331 | return; |
332 | } |
||
333 | } |
||
334 | |||
335 | |||
336 | |||
4415 | leency | 337 | void ProcessLinks(int id) |
338 | { |
||
4491 | leency | 339 | strcpy(#URL, PageLinks.GetURL(id-401)); |
4415 | leency | 340 | |
4417 | leency | 341 | //$1 - Condition Script |
342 | if (URL[0] == '$') |
||
343 | { |
||
344 | if (URL[1]=='-') && (condition_href) condition_href--; |
||
345 | if (URL[1]=='+') |
||
346 | { |
||
347 | if (condition_href |
||
348 | } |
||
349 | if (URL[1]!='-') && (URL[1]!='+') condition_href = atoi(#URL+1); |
||
350 | strcpy(#URL, BrowserHistory.CurrentUrl()); |
||
4508 | leency | 351 | ShowPage(); |
4417 | leency | 352 | return; |
353 | } |
||
4415 | leency | 354 | //#1 |
355 | if (URL[0] == '#') |
||
356 | { |
||
4417 | leency | 357 | strcpy(#anchor, #URL+strrchr(#URL, '#')); |
4415 | leency | 358 | strcpy(#URL, BrowserHistory.CurrentUrl()); |
359 | WB1.list.first=WB1.list.count-WB1.list.visible; |
||
4508 | leency | 360 | ShowPage(); |
4415 | leency | 361 | return; |
362 | } |
||
363 | //liner.ru#1 |
||
4417 | leency | 364 | if (strrchr(#URL, '#')!=-1) |
4415 | leency | 365 | { |
366 | strcpy(#anchor, #URL+strrchr(#URL, '#')); |
||
4416 | leency | 367 | URL[strrchr(#URL, '#')-1] = 0x00; |
4415 | leency | 368 | } |
369 | |||
370 | WB1.GetNewUrl(); |
||
371 | |||
372 | if (!strcmp(#URL + strlen(#URL) - 4, ".gif")) || (!strcmp(#URL + strlen(#URL) - 4, ".png")) || (!strcmp(#URL + strlen(#URL) - 4, ".jpg")) |
||
373 | { |
||
374 | //if (strstr(#URL,"http:")) |
||
375 | RunProgram("/sys/media/kiv", #URL); |
||
376 | strcpy(#editURL, BrowserHistory.CurrentUrl()); |
||
377 | strcpy(#URL, BrowserHistory.CurrentUrl()); |
||
378 | return; |
||
379 | } |
||
380 | if (!strcmpn(#URL,"mailto:", 7)) |
||
381 | { |
||
382 | notify(#URL); |
||
383 | strcpy(#editURL, BrowserHistory.CurrentUrl()); |
||
384 | strcpy(#URL, BrowserHistory.CurrentUrl()); |
||
385 | return; |
||
386 | } |
||
4413 | leency | 387 | |
4416 | leency | 388 | OpenPage(); |
4415 | leency | 389 | return; |
390 | } |
||
391 | |||
4416 | leency | 392 | void OpenPage() |
393 | { |
||
394 | if (GetProcessSlot(downloader_id)<>0) PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal); |
||
395 | KillProcess(downloader_id); |
||
396 | strcpy(#editURL, #URL); |
||
397 | BrowserHistory.AddUrl(); |
||
398 | strcpy(#header, #version); |
||
399 | pre_text =0; |
||
4488 | leency | 400 | if (!strncmp(#URL,"http:",5)) |
4416 | leency | 401 | { |
402 | KillProcess(downloader_id); |
||
403 | DeleteFile(#download_path); |
||
404 | IF (URL[strlen(#URL)-1]=='/') URL[strlen(#URL)-1]=NULL; |
||
405 | downloader_id = RunProgram("/sys/network/downloader", #URL); |
||
406 | IF (downloader_id<0) notify("Error running Downloader. Internet unavilable."); |
||
407 | Draw_Window(); |
||
408 | return; |
||
409 | } |
||
410 | WB1.list.first = WB1.list.count =0; |
||
411 | WB1.ReadHtml(_WIN); |
||
4508 | leency | 412 | ShowPage(); |
4416 | leency | 413 | } |
4415 | leency | 414 | |
4508 | leency | 415 | void ShowPage() |
416 | { |
||
417 | address_box.size = address_box.pos = strlen(#editURL); |
||
418 | address_box.offset=0; |
||
419 | edit_box_draw stdcall(#address_box); |
||
4415 | leency | 420 | |
4508 | leency | 421 | if (!filesize) |
422 | { |
||
423 | PageLinks.Clear(); |
||
424 | DrawBar(WB1.list.x, WB1.list.y, WB1.list.w+scroll_wv.size_x+1, WB1.list.h, 0xFFFFFF); //fill all |
||
425 | if (GetProcessSlot(downloader_id)<>0) WriteText(WB1.list.x + 10, WB1.list.y + 18, 0x80, 0, "Loading..."); |
||
426 | else |
||
427 | { |
||
428 | WriteText(WB1.list.x + 10, WB1.list.y + 18, 0x80, 0, "Page not found. May be, URL contains some errors."); |
||
429 | if (!strncmp(#URL,"http:",5)) WriteText(WB1.list.x + 10, WB1.list.y + 32, 0x80, 0, "Or Internet unavilable for your configuration."); |
||
430 | } |
||
431 | //return; |
||
432 | } |
||
433 | else |
||
434 | WB1.ParseHTML(buf); |
||
4415 | leency | 435 | |
4508 | leency | 436 | if (!header) strcpy(#header, #version); |
437 | if (!strcmp(#version, #header)) DrawTitle(#header); |
||
438 | } |
||
439 | |||
440 | |||
3067 | leency | 441 | stop:>0)>>>=>>>>>>5;>>280)>120)>>>8;><8;>>>>>0)>=scroll_wv.start_x+scroll_wv.size_x)> |