Rev 4411 | Rev 4414 | 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" |
||
3107 | leency | 19 | //*.obj libraries |
20 | #include "..\lib\lib.obj\box_lib.h" |
||
21 | #include "..\lib\lib.obj\libio_lib.h" |
||
22 | #include "..\lib\lib.obj\libimg_lib.h" |
||
23 | //images |
||
3067 | leency | 24 | #include "img\toolbar_icons.c" |
25 | #include "img\URLgoto.txt"; |
||
26 | |||
4026 | leency | 27 | #ifdef LANG_RUS |
4411 | leency | 28 | char version[]=" ’ҐЄбв®ўл© Ўа 㧥а 0.99.11"; |
4026 | leency | 29 | ?define IMAGES_CACHE_CLEARED "Љни Є авЁ®Є ®зЁйҐ" |
30 | #else |
||
4411 | leency | 31 | char version[]=" Text-based Browser 0.99.11"; |
4026 | leency | 32 | ?define IMAGES_CACHE_CLEARED "Images cache cleared" |
33 | #endif |
||
34 | |||
35 | |||
3067 | leency | 36 | #define URL param |
3449 | leency | 37 | char fontlol[64]; |
3067 | leency | 38 | |
39 | char editURL[sizeof(URL)], |
||
40 | page_links[12000], |
||
3464 | leency | 41 | header[2048]; |
3067 | leency | 42 | |
43 | struct lines{ |
||
44 | int visible, all, first, column_max; |
||
45 | }; |
||
46 | |||
47 | int mouse_dd; |
||
3466 | leency | 48 | edit_box address_box= {250,207,16,0xffffff,0x94AECE,0xffffff,0xffffff,0,sizeof(editURL),#editURL,#mouse_dd,2,19,19}; |
3464 | leency | 49 | scroll_bar scroll1 = { 18,200,398, 44,18,0,115,15,0,0xeeeeee,0xD2CED0,0x555555,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1}; |
3067 | leency | 50 | |
51 | |||
52 | proc_info Form; |
||
53 | #define WIN_W 640 |
||
54 | #define WIN_H 480 |
||
55 | |||
56 | |||
4074 | leency | 57 | char stak[4096]; |
3067 | leency | 58 | mouse m; |
59 | |||
4026 | leency | 60 | int action_buf; |
61 | |||
4413 | leency | 62 | #include "history.h" |
4411 | leency | 63 | #include "..\TWB\TWB.c" |
64 | #include "menu_rmb.h" |
||
3067 | leency | 65 | |
66 | |||
67 | void main() |
||
68 | { |
||
4081 | leency | 69 | int key, btn; |
3067 | leency | 70 | int half_scroll_size; |
4026 | leency | 71 | int scroll_used=0, show_menu; |
3067 | leency | 72 | |
73 | mem_Init(); |
||
3107 | leency | 74 | if (load_dll2(boxlib, #box_lib_init,0)!=0) {notify("System Error: library doesn't exists /rd/1/lib/box_lib.obj"); ExitProcess();} |
75 | if (load_dll2(libio, #libio_init,1)!=0) debug("Error: library doesn't exists - libio"w); |
||
76 | if (load_dll2(libimg, #libimg_init,1)!=0) debug("Error: library doesn't exists - libimg"w); |
||
3067 | leency | 77 | |
3987 | leency | 78 | if (!URL) strcpy(#URL, "/sys/index.htm"); |
3067 | leency | 79 | strcpy(#editURL, #URL); |
80 | |||
81 | Form.width=WIN_W; |
||
82 | Form.height=WIN_H; |
||
83 | SetElementSizes(); |
||
84 | WB1.OpenPage(); |
||
85 | |||
86 | SetEventMask(0x27); |
||
87 | loop() |
||
88 | { |
||
89 | WaitEventTimeout(2); |
||
90 | switch(EAX & 0xFF) |
||
91 | { |
||
92 | CASE evMouse: |
||
93 | /*scrollbar_v_mouse (#scroll1); //конченый скролл притормажимает, идём "своим путём" |
||
94 | if (lines.first <> scroll1.position) |
||
95 | { |
||
96 | lines.first = scroll1.position; |
||
97 | WB1.ParseHTML(buf, filesize); |
||
98 | //break; |
||
99 | };*/ |
||
100 | |||
4081 | leency | 101 | if (!CheckActiveProcess(Form.ID)) break; |
3067 | leency | 102 | |
3466 | leency | 103 | edit_box_mouse stdcall (#address_box); |
3067 | leency | 104 | |
105 | m.get(); |
||
106 | |||
4026 | leency | 107 | if (m.y>WB1.top) && (m.y |
3067 | leency | 108 | { |
4026 | leency | 109 | if (m.pkm) |
110 | { |
||
111 | show_menu = 1; |
||
112 | } |
||
113 | if (!m.pkm) && (show_menu) |
||
114 | { |
||
115 | show_menu = 0; |
||
116 | SwitchToAnotherThread(); |
||
4074 | leency | 117 | CreateThread(#menu_rmb,#stak+4092); |
4026 | leency | 118 | break; |
119 | } |
||
3067 | leency | 120 | } |
121 | |||
4026 | leency | 122 | if (m.vert==65535) |
3067 | leency | 123 | { |
3477 | leency | 124 | if (lines.first==0) break; |
125 | if (lines.first>3) lines.first-=2; ELSE lines.first=1; |
||
4413 | leency | 126 | Scan(ID1); |
3067 | leency | 127 | break; |
128 | } |
||
3477 | leency | 129 | if (m.vert==1) |
3067 | leency | 130 | { |
4413 | leency | 131 | if(lines.visible+lines.first+3>=lines.all) Scan(181); |
4026 | leency | 132 | else |
133 | { |
||
3067 | leency | 134 | lines.first+=2; |
4413 | leency | 135 | Scan(ID2); |
3067 | leency | 136 | } |
137 | break; |
||
138 | } |
||
139 | |||
140 | if (!m.lkm) scroll_used=0; |
||
3477 | leency | 141 | if (m.x>=scroll1.start_x) && (m.x<=scroll1.start_x+scroll1.size_x) |
4026 | leency | 142 | && (m.y>=scroll1.start_y+scroll1.btn_height) && (-scroll1.btn_height+scroll1.start_y+scroll1.size_y>m.y) |
143 | && (lines.all>lines.visible) && (m.lkm) |
||
144 | { |
||
145 | scroll_used=1; |
||
146 | } |
||
3067 | leency | 147 | |
148 | if (scroll_used) |
||
149 | { |
||
150 | half_scroll_size = WB1.height - 16 * lines.visible / lines.all - 3 /2; |
||
3477 | leency | 151 | if (half_scroll_size+WB1.top>m.y) || (m.y<0) || (m.y>4000) m.y=half_scroll_size+WB1.top; //если курсор над окном |
3067 | leency | 152 | btn=lines.first; //сохраняем старое количество |
153 | lines.first = m.y -half_scroll_size -WB1.top * lines.all / WB1.height; |
||
154 | if (lines.visible+lines.first>lines.all) lines.first=lines.all-lines.visible; |
||
155 | if (btn<>lines.first) WB1.ParseHTML(buf); //чтоб лишний раз не перерисовывать |
||
156 | } |
||
157 | |||
158 | break; |
||
159 | case evButton: |
||
160 | btn=GetButtonID(); |
||
3464 | leency | 161 | if (btn==1) |
3067 | leency | 162 | { |
163 | KillProcess(downloader_id); |
||
164 | ExitProcess(); |
||
165 | } |
||
166 | ELSE |
||
167 | { |
||
4413 | leency | 168 | Scan(btn); |
3067 | leency | 169 | } |
170 | break; |
||
171 | case evKey: |
||
172 | key = GetKey(); |
||
173 | |||
3466 | leency | 174 | if (address_box.flags & 0b10) SWITCH(key) //если активна строка адреса игнорируем некоторые кнопки |
3067 | leency | 175 | { CASE 52: CASE 53: CASE 54: goto _EDIT_MARK; } |
176 | |||
4413 | leency | 177 | Scan(key); |
3067 | leency | 178 | |
179 | _EDIT_MARK: |
||
3990 | leency | 180 | if (key<>0x0d) && (key<>183) && (key<>184) {EAX=key<<8; edit_box_key stdcall(#address_box);} //адресная строка |
3067 | leency | 181 | break; |
182 | case evReDraw: |
||
4413 | leency | 183 | if (action_buf) { Scan(action_buf); action_buf=0;} |
3067 | leency | 184 | Draw_Window(); |
185 | break; |
||
186 | default: |
||
187 | if (downloader_id<>0) |
||
188 | { |
||
189 | if (GetProcessSlot(downloader_id)<>0) break; |
||
190 | downloader_id=0; |
||
191 | lines.first = lines.all = 0; |
||
192 | WB1.ReadHtml(_WIN); |
||
193 | Draw_Window(); |
||
194 | } |
||
195 | } |
||
196 | } |
||
197 | } |
||
198 | |||
199 | void SetElementSizes() |
||
200 | { |
||
3466 | leency | 201 | address_box.width = Form.width-266; |
3464 | leency | 202 | WB1.top = 44; |
3466 | leency | 203 | WB1.width = Form.width - 10 - scroll1.size_x; |
204 | WB1.height = Form.height - WB1.top - GetSkinHeight() - 4; |
||
3464 | leency | 205 | WB1.line_h = 10; |
3067 | leency | 206 | lines.column_max = WB1.width - 30 / 6; |
3464 | leency | 207 | lines.visible = WB1.height - 3 / WB1.line_h - 2; |
3468 | leency | 208 | DrawBufInit(); |
3067 | leency | 209 | } |
210 | |||
211 | |||
212 | void Draw_Window() |
||
213 | { |
||
214 | int j; |
||
3466 | leency | 215 | DefineAndDrawWindow(215,100,WIN_W,WIN_H,0x73,0xE4DFE1,0,0); |
3067 | leency | 216 | |
217 | GetProcessInfo(#Form, SelfInfo); |
||
3464 | leency | 218 | if (Form.status_window>2) |
3067 | leency | 219 | { |
220 | DrawTitle(#header); |
||
221 | return; |
||
222 | } |
||
223 | if (Form.height<120) MoveSize(OLD,OLD,OLD,120); |
||
224 | if (Form.width<280) MoveSize(OLD,OLD,280,OLD); |
||
225 | |||
226 | PutPaletteImage(#toolbar,200,42,0,0,8,#toolbar_pal); |
||
3363 | leency | 227 | if (GetProcessSlot(downloader_id)<>0) _PutImage(88,10, 24,24, #stop_btn); |
3067 | leency | 228 | |
3464 | leency | 229 | DrawBar(200,0,Form.cwidth-200,43,0xE4DFE1); |
230 | DrawBar(0,42,Form.cwidth,1,0xE2DBDC); |
||
231 | DrawBar(0,43,Form.cwidth,1,0xD2CED0); |
||
3067 | leency | 232 | for (j=0; j<5; j++) DefineButton(j*37+11, 7, 29, 29, 300+j+BT_HIDE, 0xE4DFE1); |
3464 | leency | 233 | _PutImage(Form.cwidth-48,14, 40,19, #URLgoto); |
234 | DefineButton(Form.cwidth-28,15, 18, 16, GOTOURL+BT_HIDE, 0xE4DFE1); |
||
235 | DefineButton(Form.cwidth-47,15, 17, 16, SEARCHWEB+BT_HIDE, 0xE4DFE1); |
||
236 | DrawRectangle(205,14,Form.cwidth-205-49,18,0x94AECE); //around adress bar |
||
237 | DrawRectangle(206,15,Form.cwidth-205-50,16,0xE4ECF3); |
||
3067 | leency | 238 | |
239 | SetElementSizes(); |
||
240 | WB1.ShowPage(); |
||
3464 | leency | 241 | |
3067 | leency | 242 | DefineButton(scroll1.start_x+1, scroll1.start_y+1, 16, 16, ID1+BT_HIDE, 0xE4DFE1); |
243 | DefineButton(scroll1.start_x+1, scroll1.start_y+scroll1.size_y-18, 16, 16, ID2+BT_HIDE, 0xE4DFE1); |
||
244 | } |
||
245 | |||
246 | |||
4413 | leency | 247 | void Scan(int id) |
248 | { |
||
249 | if (id >= 400) |
||
250 | { |
||
251 | GetURLfromPageLinks(id); |
||
252 | |||
253 | //#1 |
||
254 | if (URL[0] == '#') |
||
255 | { |
||
256 | strcpy(#anchor, #URL+strrchr(#URL, '#')); |
||
257 | |||
258 | strcpy(#URL, BrowserHistory.CurrentUrl()); |
||
259 | |||
260 | lines.first=lines.all-lines.visible; |
||
261 | WB1.ShowPage(); |
||
262 | return; |
||
263 | } |
||
264 | //liner.ru#1 |
||
265 | if (strrchr(#URL, '#')<>-1) |
||
266 | { |
||
267 | strcpy(#anchor, #URL+strrchr(#URL, '#')); |
||
268 | URL[strrchr(#URL, '#')-1] = 0x00; //заглушка |
||
269 | } |
||
270 | |||
271 | WB1.GetNewUrl(); |
||
272 | |||
273 | if (!strcmp(#URL + strlen(#URL) - 4, ".gif")) || (!strcmp(#URL + strlen(#URL) - 4, ".png")) || (!strcmp(#URL + strlen(#URL) - 4, ".jpg")) |
||
274 | { |
||
275 | //if (strstr(#URL,"http:")) |
||
276 | RunProgram("/sys/media/kiv", #URL); |
||
277 | strcpy(#editURL, BrowserHistory.CurrentUrl()); |
||
278 | strcpy(#URL, BrowserHistory.CurrentUrl()); |
||
279 | return; |
||
280 | } |
||
281 | if (!strcmpn(#URL,"mailto:", 7)) |
||
282 | { |
||
283 | RunProgram("@notify", #URL); |
||
284 | strcpy(#editURL, BrowserHistory.CurrentUrl()); |
||
285 | strcpy(#URL, BrowserHistory.CurrentUrl()); |
||
286 | return; |
||
287 | } |
||
288 | |||
289 | WB1.OpenPage(); |
||
290 | return; |
||
291 | } |
||
292 | |||
293 | IF(lines.all < lines.visible) SWITCH(id) //если мало строк игнорируем некоторые кнопки |
||
294 | { CASE 183: CASE 184: CASE 180: CASE 181: return; } |
||
295 | |||
296 | switch (id) |
||
297 | { |
||
298 | case 011: //Ctrk+K |
||
299 | WB1.ReadHtml(_KOI); |
||
300 | break; |
||
301 | case 021: //Ctrl+U |
||
302 | WB1.ReadHtml(_UTF); |
||
303 | break; |
||
304 | case 004: //Ctrl+D |
||
305 | WB1.ReadHtml(_DOS); |
||
306 | break; |
||
307 | case 002: //free img cache |
||
308 | FreeImgCache(); |
||
309 | break; |
||
310 | case BACK: |
||
311 | if (!BrowserHistory.GoBack()) return; |
||
312 | WB1.OpenPage(); |
||
313 | return; |
||
314 | case FORWARD: |
||
315 | if (!BrowserHistory.GoForward()) return; |
||
316 | WB1.OpenPage(); |
||
317 | return; |
||
318 | case 052: //F3 |
||
319 | if (strcmp(get_URL_part(5),"http:")<>0) RunProgram("/rd/1/tinypad", #URL); else RunProgram("/rd/1/tinypad", #download_path); |
||
320 | return; |
||
321 | case 054: //F5 |
||
322 | IF(address_box.flags & 0b10) break; |
||
323 | case REFRESH: |
||
324 | if (GetProcessSlot(downloader_id)<>0) |
||
325 | { |
||
326 | KillProcess(downloader_id); |
||
327 | pause(20); |
||
328 | Draw_Window(); |
||
329 | return; |
||
330 | } |
||
331 | anchor_line_num=lines.first; //весёлый костыль :Р |
||
332 | anchor[0]='|'; |
||
333 | WB1.OpenPage(); |
||
334 | return; |
||
335 | case 014: //Ctrl+N новое окно |
||
336 | case 020: //Ctrl+T новая вкладка |
||
337 | case NEWTAB: |
||
338 | MoveSize(190,80,OLD,OLD); |
||
339 | RunProgram(#program_path, #URL); |
||
340 | return; |
||
341 | |||
342 | case HOME: |
||
343 | strcpy(#editURL, "http://kolibrios.org/en/index.htm"); |
||
344 | case GOTOURL: |
||
345 | case 0x0D: //enter |
||
346 | //почему ttp://? Господа, отличный вопрос. Дело в том, что это хак. |
||
347 | //strstr() если не нашло возвращает 0 и в случае успеха возвращает 0. Так что это хак. |
||
348 | if ((strstr(#editURL,"ttp://")==0) && (editURL[0]!='/')) strcpy(#URL,"http://"); else URL[0] = 0; |
||
349 | strcat(#URL, #editURL); |
||
350 | WB1.OpenPage(); |
||
351 | return; |
||
352 | case SEARCHWEB: |
||
353 | strcpy(#URL, #search_path); |
||
354 | strcat(#URL, #editURL); |
||
355 | WB1.OpenPage(); |
||
356 | return; |
||
357 | |||
358 | case ID1: //мотаем вверх |
||
359 | IF(lines.first <= 0) return; |
||
360 | lines.first--; |
||
361 | break; |
||
362 | case ID2: //мотаем вниз |
||
363 | IF(lines.visible + lines.first >= lines.all) return; |
||
364 | lines.first++; |
||
365 | break; |
||
366 | case 183: //PgDown |
||
367 | IF(lines.first == lines.all - lines.visible) return; |
||
368 | lines.first += lines.visible + 2; |
||
369 | IF(lines.visible + lines.first > lines.all) lines.first = lines.all - lines.visible; |
||
370 | break; |
||
371 | case 184: //PgUp |
||
372 | IF(lines.first == 0) return; |
||
373 | lines.first -= lines.visible - 2; |
||
374 | IF(lines.first < 0) lines.first = 0; |
||
375 | break; |
||
376 | case 180: //home |
||
377 | IF(lines.first == 0) return; |
||
378 | lines.first = 0; |
||
379 | break; |
||
380 | case 181: //end |
||
381 | IF (lines.first == lines.all - lines.visible) return; |
||
382 | lines.first = lines.all - lines.visible; |
||
383 | break; |
||
384 | default: |
||
385 | return; |
||
386 | } |
||
387 | WB1.ParseHTML(buf); |
||
388 | } |
||
389 | |||
390 | |||
391 | |||
392 | |||
3067 | leency | 393 | stop:>=>>>>>5;>>280)>120)>>>8;><8;>>>>>0)>=scroll1.start_x+scroll1.size_x)>> |