Rev 4415 | Rev 4417 | 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" |
||
4415 | leency | 19 | #include "..\lib\list_box.h" |
3107 | leency | 20 | //*.obj libraries |
21 | #include "..\lib\lib.obj\box_lib.h" |
||
22 | #include "..\lib\lib.obj\libio_lib.h" |
||
23 | #include "..\lib\lib.obj\libimg_lib.h" |
||
24 | //images |
||
3067 | leency | 25 | #include "img\toolbar_icons.c" |
26 | #include "img\URLgoto.txt"; |
||
27 | |||
4026 | leency | 28 | #ifdef LANG_RUS |
4416 | leency | 29 | char version[]=" ’¥ªáâ®¢ë© ¡à 㧥à 0.99.31"; |
30 | ?define IMAGES_CACHE_CLEARED "Šíè ª à⨮ª ®ç¨é¥" |
||
4026 | leency | 31 | #else |
4416 | leency | 32 | char version[]=" Text-based Browser 0.99.31"; |
4026 | leency | 33 | ?define IMAGES_CACHE_CLEARED "Images cache cleared" |
34 | #endif |
||
35 | |||
3067 | leency | 36 | proc_info Form; |
37 | #define WIN_W 640 |
||
38 | #define WIN_H 480 |
||
39 | |||
4416 | leency | 40 | char search_path[]="http://nigma.ru/index.php?s="; |
3067 | leency | 41 | |
4074 | leency | 42 | char stak[4096]; |
3067 | leency | 43 | mouse m; |
4026 | leency | 44 | int action_buf; |
45 | |||
4416 | leency | 46 | |
47 | |||
4411 | leency | 48 | #include "..\TWB\TWB.c" |
49 | #include "menu_rmb.h" |
||
3067 | leency | 50 | |
51 | |||
52 | void main() |
||
53 | { |
||
4081 | leency | 54 | int key, btn; |
3067 | leency | 55 | int half_scroll_size; |
4026 | leency | 56 | int scroll_used=0, show_menu; |
3067 | leency | 57 | |
58 | mem_Init(); |
||
3107 | leency | 59 | 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 | 60 | if (load_dll2(libio, #libio_init,1)!=0) debug("Error: library doesn't exists - libio"); |
61 | if (load_dll2(libimg, #libimg_init,1)!=0) debug("Error: library doesn't exists - libimg"); |
||
3067 | leency | 62 | |
3987 | leency | 63 | if (!URL) strcpy(#URL, "/sys/index.htm"); |
3067 | leency | 64 | strcpy(#editURL, #URL); |
65 | |||
66 | Form.width=WIN_W; |
||
67 | Form.height=WIN_H; |
||
68 | SetElementSizes(); |
||
4416 | leency | 69 | OpenPage(); |
3067 | leency | 70 | |
71 | SetEventMask(0x27); |
||
72 | loop() |
||
73 | { |
||
74 | WaitEventTimeout(2); |
||
75 | switch(EAX & 0xFF) |
||
76 | { |
||
77 | CASE evMouse: |
||
4414 | leency | 78 | /* |
79 | //not work well, so we are use custom way of processing scroll |
||
4416 | leency | 80 | scrollbar_v_mouse (#scroll_wv); |
81 | if (WB1.list.first <> scroll_wv.position) |
||
3067 | leency | 82 | { |
4416 | leency | 83 | WB1.list.first = scroll_wv.position; |
3067 | leency | 84 | WB1.ParseHTML(buf, filesize); |
4414 | leency | 85 | }; |
86 | */ |
||
3067 | leency | 87 | |
4081 | leency | 88 | if (!CheckActiveProcess(Form.ID)) break; |
3067 | leency | 89 | |
3466 | leency | 90 | edit_box_mouse stdcall (#address_box); |
3067 | leency | 91 | |
92 | m.get(); |
||
93 | |||
4414 | leency | 94 | if (m.y>WB1.list.y) && (m.y |
3067 | leency | 95 | { |
4026 | leency | 96 | if (m.pkm) |
97 | { |
||
98 | show_menu = 1; |
||
99 | } |
||
100 | if (!m.pkm) && (show_menu) |
||
101 | { |
||
102 | show_menu = 0; |
||
103 | SwitchToAnotherThread(); |
||
4074 | leency | 104 | CreateThread(#menu_rmb,#stak+4092); |
4026 | leency | 105 | break; |
106 | } |
||
3067 | leency | 107 | } |
108 | |||
4415 | leency | 109 | if (m.vert) |
3067 | leency | 110 | { |
4415 | leency | 111 | if (WB1.list.MouseScroll(m.vert)) WB1.ParseHTML(buf); |
3067 | leency | 112 | } |
113 | |||
114 | if (!m.lkm) scroll_used=0; |
||
4416 | leency | 115 | if (m.x>=scroll_wv.start_x) && (m.x<=scroll_wv.start_x+scroll_wv.size_x) |
116 | && (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 | 117 | && (WB1.list.count>WB1.list.visible) && (m.lkm) |
4026 | leency | 118 | { |
119 | scroll_used=1; |
||
120 | } |
||
3067 | leency | 121 | |
122 | if (scroll_used) |
||
123 | { |
||
4415 | leency | 124 | half_scroll_size = WB1.list.h - 16 * WB1.list.visible / WB1.list.count - 3 /2; |
4416 | leency | 125 | if (half_scroll_size+WB1.list.y>m.y) || (m.y<0) || (m.y>4000) m.y=half_scroll_size+WB1.list.y; |
126 | btn=WB1.list.first; |
||
4415 | leency | 127 | WB1.list.first = m.y -half_scroll_size -WB1.list.y * WB1.list.count / WB1.list.h; |
128 | if (WB1.list.visible+WB1.list.first>WB1.list.count) WB1.list.first=WB1.list.count-WB1.list.visible; |
||
4416 | leency | 129 | if (btn<>WB1.list.first) WB1.ParseHTML(buf); |
3067 | leency | 130 | } |
131 | |||
132 | break; |
||
133 | case evButton: |
||
134 | btn=GetButtonID(); |
||
3464 | leency | 135 | if (btn==1) |
3067 | leency | 136 | { |
137 | KillProcess(downloader_id); |
||
138 | ExitProcess(); |
||
139 | } |
||
140 | ELSE |
||
141 | { |
||
4413 | leency | 142 | Scan(btn); |
3067 | leency | 143 | } |
144 | break; |
||
145 | case evKey: |
||
146 | key = GetKey(); |
||
147 | |||
4416 | leency | 148 | if (address_box.flags & 0b10) SWITCH(key) |
3067 | leency | 149 | { CASE 52: CASE 53: CASE 54: goto _EDIT_MARK; } |
150 | |||
4413 | leency | 151 | Scan(key); |
3067 | leency | 152 | |
153 | _EDIT_MARK: |
||
4416 | leency | 154 | if (key<>0x0d) && (key<>183) && (key<>184) {EAX=key<<8; edit_box_key stdcall(#address_box);} |
3067 | leency | 155 | break; |
156 | case evReDraw: |
||
4413 | leency | 157 | if (action_buf) { Scan(action_buf); action_buf=0;} |
3067 | leency | 158 | Draw_Window(); |
159 | break; |
||
160 | default: |
||
161 | if (downloader_id<>0) |
||
162 | { |
||
163 | if (GetProcessSlot(downloader_id)<>0) break; |
||
164 | downloader_id=0; |
||
4415 | leency | 165 | WB1.list.first = WB1.list.count = 0; |
3067 | leency | 166 | WB1.ReadHtml(_WIN); |
167 | Draw_Window(); |
||
168 | } |
||
169 | } |
||
170 | } |
||
171 | } |
||
172 | |||
173 | void SetElementSizes() |
||
174 | { |
||
4416 | leency | 175 | address_box.width = Form.width - 266; |
176 | WB1.list.SetSizes(0, 44, Form.width - 10 - scroll_wv.size_x, Form.cheight - 44, 0, 10); |
||
4415 | leency | 177 | WB1.list.column_max = WB1.list.w - 30 / 6; |
178 | WB1.list.visible = WB1.list.h - 3 / WB1.list.line_h - 2; |
||
3468 | leency | 179 | DrawBufInit(); |
3067 | leency | 180 | } |
181 | |||
182 | |||
183 | void Draw_Window() |
||
184 | { |
||
185 | int j; |
||
3466 | leency | 186 | DefineAndDrawWindow(215,100,WIN_W,WIN_H,0x73,0xE4DFE1,0,0); |
3067 | leency | 187 | |
188 | GetProcessInfo(#Form, SelfInfo); |
||
3464 | leency | 189 | if (Form.status_window>2) |
3067 | leency | 190 | { |
191 | DrawTitle(#header); |
||
192 | return; |
||
193 | } |
||
194 | if (Form.height<120) MoveSize(OLD,OLD,OLD,120); |
||
195 | if (Form.width<280) MoveSize(OLD,OLD,280,OLD); |
||
196 | |||
197 | PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal); |
||
3363 | leency | 198 | if (GetProcessSlot(downloader_id)<>0) _PutImage(88,10, 24,24, #stop_btn); |
3067 | leency | 199 | |
3464 | leency | 200 | DrawBar(200,0,Form.cwidth-200,43,0xE4DFE1); |
201 | DrawBar(0,42,Form.cwidth,1,0xE2DBDC); |
||
202 | DrawBar(0,43,Form.cwidth,1,0xD2CED0); |
||
3067 | leency | 203 | for (j=0; j<5; j++) DefineButton(j*37+11, 7, 29, 29, 300+j+BT_HIDE, 0xE4DFE1); |
3464 | leency | 204 | _PutImage(Form.cwidth-48,14, 40,19, #URLgoto); |
205 | DefineButton(Form.cwidth-28,15, 18, 16, GOTOURL+BT_HIDE, 0xE4DFE1); |
||
206 | DefineButton(Form.cwidth-47,15, 17, 16, SEARCHWEB+BT_HIDE, 0xE4DFE1); |
||
207 | DrawRectangle(205,14,Form.cwidth-205-49,18,0x94AECE); //around adress bar |
||
208 | DrawRectangle(206,15,Form.cwidth-205-50,16,0xE4ECF3); |
||
3067 | leency | 209 | |
210 | SetElementSizes(); |
||
211 | WB1.ShowPage(); |
||
3464 | leency | 212 | |
4416 | leency | 213 | DefineButton(scroll_wv.start_x+1, scroll_wv.start_y+1, 16, 16, BTN_UP+BT_HIDE, 0xE4DFE1); |
214 | DefineButton(scroll_wv.start_x+1, scroll_wv.start_y+scroll_wv.size_y-18, 16, 16, BTN_DOWN+BT_HIDE, 0xE4DFE1); |
||
3067 | leency | 215 | } |
216 | |||
217 | |||
4413 | leency | 218 | void Scan(int id) |
219 | { |
||
4415 | leency | 220 | if (id >= 400) ProcessLinks(id); |
4413 | leency | 221 | |
222 | switch (id) |
||
223 | { |
||
224 | case 011: //Ctrk+K |
||
225 | WB1.ReadHtml(_KOI); |
||
4415 | leency | 226 | WB1.ParseHTML(buf); |
227 | return; |
||
228 | |||
4413 | leency | 229 | case 021: //Ctrl+U |
230 | WB1.ReadHtml(_UTF); |
||
4415 | leency | 231 | WB1.ParseHTML(buf); |
232 | return; |
||
233 | |||
4413 | leency | 234 | case 004: //Ctrl+D |
235 | WB1.ReadHtml(_DOS); |
||
4415 | leency | 236 | WB1.ParseHTML(buf); |
237 | return; |
||
238 | |||
4413 | leency | 239 | case 002: //free img cache |
240 | FreeImgCache(); |
||
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 |
||
4415 | leency | 254 | if (strcmp(get_URL_part(5),"http:")<>0) RunProgram("/rd/1/tinypad", #URL); |
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 | { |
||
339 | GetURLfromPageLinks(id); |
||
340 | |||
341 | //#1 |
||
342 | if (URL[0] == '#') |
||
343 | { |
||
344 | strcpy(#anchor, #URL+strrchr(#URL, '#')); |
||
345 | |||
346 | strcpy(#URL, BrowserHistory.CurrentUrl()); |
||
347 | |||
348 | WB1.list.first=WB1.list.count-WB1.list.visible; |
||
349 | WB1.ShowPage(); |
||
350 | return; |
||
351 | } |
||
352 | //liner.ru#1 |
||
353 | if (strrchr(#URL, '#')<>-1) |
||
354 | { |
||
355 | strcpy(#anchor, #URL+strrchr(#URL, '#')); |
||
4416 | leency | 356 | URL[strrchr(#URL, '#')-1] = 0x00; |
4415 | leency | 357 | } |
358 | |||
359 | WB1.GetNewUrl(); |
||
360 | |||
361 | if (!strcmp(#URL + strlen(#URL) - 4, ".gif")) || (!strcmp(#URL + strlen(#URL) - 4, ".png")) || (!strcmp(#URL + strlen(#URL) - 4, ".jpg")) |
||
362 | { |
||
363 | //if (strstr(#URL,"http:")) |
||
364 | RunProgram("/sys/media/kiv", #URL); |
||
365 | strcpy(#editURL, BrowserHistory.CurrentUrl()); |
||
366 | strcpy(#URL, BrowserHistory.CurrentUrl()); |
||
367 | return; |
||
368 | } |
||
369 | if (!strcmpn(#URL,"mailto:", 7)) |
||
370 | { |
||
371 | notify(#URL); |
||
372 | strcpy(#editURL, BrowserHistory.CurrentUrl()); |
||
373 | strcpy(#URL, BrowserHistory.CurrentUrl()); |
||
374 | return; |
||
375 | } |
||
4413 | leency | 376 | |
4416 | leency | 377 | OpenPage(); |
4415 | leency | 378 | return; |
379 | } |
||
380 | |||
4416 | leency | 381 | void OpenPage() |
382 | { |
||
383 | if (GetProcessSlot(downloader_id)<>0) PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal); |
||
384 | KillProcess(downloader_id); |
||
385 | strcpy(#editURL, #URL); |
||
386 | BrowserHistory.AddUrl(); |
||
387 | strcpy(#header, #version); |
||
388 | pre_text =0; |
||
389 | if (!strcmp(get_URL_part(5),"http:"))) |
||
390 | { |
||
391 | KillProcess(downloader_id); |
||
392 | DeleteFile(#download_path); |
||
393 | IF (URL[strlen(#URL)-1]=='/') URL[strlen(#URL)-1]=NULL; |
||
394 | downloader_id = RunProgram("/sys/network/downloader", #URL); |
||
395 | IF (downloader_id<0) notify("Error running Downloader. Internet unavilable."); |
||
396 | Draw_Window(); |
||
397 | return; |
||
398 | } |
||
399 | WB1.list.first = WB1.list.count =0; |
||
400 | WB1.ReadHtml(_WIN); |
||
401 | WB1.ShowPage(); |
||
402 | } |
||
4415 | leency | 403 | |
404 | |||
405 | |||
3067 | leency | 406 | stop:0)>>>>=>>>>>>5;>>280)>120)>>>8;><8;>>>>>0)>=scroll_wv.start_x+scroll_wv.size_x)>> |