Rev 7290 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
7043 | leency | 1 | //Calypte 0.35 - Leency |
7041 | leency | 2 | //Calypte 0.15 - Punk Joker |
3 | |||
7330 | leency | 4 | /* |
5 | TODO |
||
6 | - word wrap |
||
7 | - draw by line |
||
8 | - text selection |
||
9 | */ |
||
10 | |||
7049 | leency | 11 | #define MEMSIZE 1024*200 |
7041 | leency | 12 | |
5614 | punk_joker | 13 | #ifndef AUTOBUILD |
14 | #include "lang.h--" |
||
15 | #endif |
||
16 | |||
7041 | leency | 17 | //===================================================// |
18 | // // |
||
19 | // LIB // |
||
20 | // // |
||
21 | //===================================================// |
||
5915 | punk_joker | 22 | |
7041 | leency | 23 | #include "../lib/kolibri.h" |
7219 | leency | 24 | #include "../lib/fs.h" |
7041 | leency | 25 | #include "../lib/gui.h" |
26 | #include "../lib/list_box.h" |
||
27 | #include "../lib/menu.h" |
||
7049 | leency | 28 | #include "../lib/collection.h" |
5915 | punk_joker | 29 | |
7041 | leency | 30 | #include "../lib/obj/iconv.h" |
7043 | leency | 31 | #include "../lib/obj/box_lib.h" |
7049 | leency | 32 | #include "../lib/obj/libio.h" |
7041 | leency | 33 | #include "../lib/obj/proc_lib.h" |
7290 | punk_joker | 34 | #include "../lib/obj/librasterworks.h" |
5915 | punk_joker | 35 | |
7041 | leency | 36 | #include "../lib/patterns/simple_open_dialog.h" |
5915 | punk_joker | 37 | |
7041 | leency | 38 | //===================================================// |
39 | // // |
||
40 | // DATA // |
||
41 | // // |
||
42 | //===================================================// |
||
5915 | punk_joker | 43 | |
7049 | leency | 44 | char default_dir[] = "/rd/1"; |
45 | od_filter filter2 = { 8, "TXT\0\0" }; |
||
46 | |||
7041 | leency | 47 | /*========= MENU ==========*/ |
48 | ?define MENU1 "File" |
||
49 | ?define MENU2 "Encoding" |
||
50 | ?define MENU3 "Reopen" |
||
5612 | punk_joker | 51 | |
7041 | leency | 52 | char menu_file_list[] = |
53 | "Open |
||
54 | Close |
||
55 | Properties |
||
56 | Exit"; |
||
5612 | punk_joker | 57 | |
7041 | leency | 58 | char menu_encoding_list[] = |
59 | "UTF-8 |
||
60 | KOI8-RU |
||
61 | CP1251 |
||
62 | CP1252 |
||
63 | ISO8859-5 |
||
64 | CP866"; |
||
5915 | punk_joker | 65 | |
7041 | leency | 66 | char menu_reopen_list[] = |
67 | "Tinypad |
||
68 | TextEdit |
||
69 | TextRead |
||
70 | WebView |
||
71 | FB2Read |
||
72 | HexView"; |
||
5612 | punk_joker | 73 | |
7290 | punk_joker | 74 | enum |
75 | { |
||
7041 | leency | 76 | MENU_ID_FILE=10, |
77 | FILE_SUBMENU_ID_OPEN=10, |
||
78 | FILE_SUBMENU_ID_CLOSE, |
||
79 | FILE_SUBMENU_ID_PROPERTIES, |
||
80 | FILE_SUBMENU_ID_EXIT, |
||
5674 | pavelyakov | 81 | |
7041 | leency | 82 | MENU_ID_ENCODING=20, |
5612 | punk_joker | 83 | |
7041 | leency | 84 | MENU_ID_REOPEN=30, |
85 | FILE_SUBMENU_ID_TINYPAD=30, |
||
86 | FILE_SUBMENU_ID_TEXTEDIT, |
||
87 | FILE_SUBMENU_ID_TEXTREAD, |
||
88 | FILE_SUBMENU_ID_WEBVIEW, |
||
89 | FILE_SUBMENU_ID_FB2READ, |
||
90 | FILE_SUBMENU_ID_HEXVIEW |
||
5612 | punk_joker | 91 | }; |
92 | |||
7041 | leency | 93 | int menu_file_x = 6; |
94 | int menu_encoding_x = NULL; |
||
95 | int menu_reopen_x = NULL; |
||
96 | /*======== MENU END ==========*/ |
||
5612 | punk_joker | 97 | |
7290 | punk_joker | 98 | #define TITLE "Calypte v0.38 dev" |
7041 | leency | 99 | char win_title[4096] = TITLE; |
5612 | punk_joker | 100 | |
7041 | leency | 101 | #define TOPPANELH 23 |
102 | #define BOTPANELH 10 |
||
103 | #define WIN_W 750 |
||
104 | #define WIN_H 550 |
||
7043 | leency | 105 | #define SCROLL_SIZE 15 |
7041 | leency | 106 | |
107 | proc_info Form; |
||
108 | llist rows; |
||
109 | |||
110 | int encoding; |
||
5915 | punk_joker | 111 | |
112 | dword old_width,old_height; |
||
5612 | punk_joker | 113 | |
114 | dword bufpointer; |
||
115 | dword bufsize; |
||
116 | |||
7043 | leency | 117 | scroll_bar scroll_v = { SCROLL_SIZE,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}; |
118 | scroll_bar scroll_h = { SCROLL_SIZE,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}; |
||
119 | |||
7049 | leency | 120 | collection s; |
7043 | leency | 121 | |
7041 | leency | 122 | //===================================================// |
123 | // // |
||
124 | // CODE // |
||
125 | // // |
||
126 | //===================================================// |
||
5612 | punk_joker | 127 | |
7049 | leency | 128 | void main() |
129 | { |
||
130 | int id; |
||
131 | |||
7043 | leency | 132 | load_dll(boxlib, #box_lib_init, 0); |
7041 | leency | 133 | load_dll(libio, #libio_init, 1); |
7049 | leency | 134 | //load_dll(libini, #lib_init, 1); |
7041 | leency | 135 | load_dll(iconv_lib, #iconv_open, 0); |
136 | load_dll(Proc_lib, #OpenDialog_init,0); |
||
7290 | punk_joker | 137 | load_dll(librasterworks, #rasterworks_drawText,0); |
7041 | leency | 138 | OpenDialog_init stdcall (#o_dialog); |
139 | |||
7049 | leency | 140 | if (param) |
141 | { |
||
142 | draw_window(); |
||
143 | OpenFile(#param); |
||
144 | Prepare(); |
||
145 | DrawText(); |
||
146 | } |
||
147 | |||
148 | SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER); |
||
5612 | punk_joker | 149 | |
150 | loop() |
||
151 | { |
||
7041 | leency | 152 | switch(WaitEvent()) |
153 | { |
||
5612 | punk_joker | 154 | case evMouse: |
7041 | leency | 155 | mouse.get(); |
156 | rows.wheel_size = 3; |
||
7290 | punk_joker | 157 | if (rows.MouseScroll(mouse.vert)) |
158 | { |
||
7041 | leency | 159 | DrawText(); |
5612 | punk_joker | 160 | } |
161 | break; |
||
162 | |||
7041 | leency | 163 | case evButton: |
5915 | punk_joker | 164 | id=GetButtonID(); |
7290 | punk_joker | 165 | if (id==1) |
166 | { |
||
167 | ExitProcess(); |
||
168 | } |
||
7043 | leency | 169 | if (id==MENU_ID_FILE) |
7290 | punk_joker | 170 | { |
7043 | leency | 171 | EventShowMenu(menu_file_x, #menu_file_list, MENU_ID_FILE, NULL); |
7290 | punk_joker | 172 | } |
7043 | leency | 173 | if (id==MENU_ID_ENCODING) |
7290 | punk_joker | 174 | { |
7043 | leency | 175 | EventShowMenu(menu_encoding_x, #menu_encoding_list, MENU_ID_ENCODING, encoding+1); |
7290 | punk_joker | 176 | } |
7043 | leency | 177 | if (id==MENU_ID_REOPEN) |
7290 | punk_joker | 178 | { |
7043 | leency | 179 | EventShowMenu(menu_reopen_x, #menu_reopen_list, MENU_ID_REOPEN, NULL); |
7290 | punk_joker | 180 | } |
5612 | punk_joker | 181 | break; |
5915 | punk_joker | 182 | |
7041 | leency | 183 | case evKey: |
184 | GetKeys(); |
||
185 | if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL) |
||
5612 | punk_joker | 186 | { |
7290 | punk_joker | 187 | if (key_scancode == SCAN_CODE_KEY_O) |
188 | { |
||
189 | EventOpenFile(); |
||
190 | } |
||
5705 | punk_joker | 191 | break; |
192 | } |
||
7290 | punk_joker | 193 | if (rows.ProcessKey(key_scancode)) |
194 | { |
||
195 | DrawText(); |
||
196 | } |
||
5612 | punk_joker | 197 | break; |
7041 | leency | 198 | |
199 | case evReDraw: |
||
7290 | punk_joker | 200 | if (menu.list.cur_y) |
201 | { |
||
202 | EventMenuClick(); |
||
203 | } |
||
5612 | punk_joker | 204 | draw_window(); |
205 | break; |
||
7041 | leency | 206 | } |
5612 | punk_joker | 207 | } |
208 | } |
||
209 | |||
7041 | leency | 210 | int DrawMenuButton(dword x,y,id,text) |
211 | { |
||
212 | int textlen = strlen(text)*8; |
||
213 | int padding = 12; |
||
214 | DefineHiddenButton(x, y, textlen+padding+padding, TOPPANELH-2, id); |
||
215 | WriteText(x+padding,y+4, 0x90, MixColors(system.color.work, system.color.work_text, 70), text); |
||
216 | return textlen+padding+padding; |
||
217 | } |
||
218 | |||
5612 | punk_joker | 219 | void draw_window() |
220 | { |
||
5674 | pavelyakov | 221 | system.color.get(); |
7049 | leency | 222 | DefineAndDrawWindow(screen.width-WIN_W/2,screen.height-WIN_H/2,WIN_W,WIN_H,0x73,0xFFFFFF,#win_title,0); |
5612 | punk_joker | 223 | GetProcessInfo(#Form, SelfInfo); |
7041 | leency | 224 | DrawBar(0, 0, Form.cwidth, TOPPANELH-1, system.color.work); |
225 | DrawBar(0, TOPPANELH-1, Form.cwidth, 1, system.color.work_dark); |
||
5674 | pavelyakov | 226 | DrawBar(0, Form.cheight-BOTPANELH, Form.cwidth, BOTPANELH, system.color.work); |
5612 | punk_joker | 227 | |
7041 | leency | 228 | menu_encoding_x = menu_file_x + DrawMenuButton(menu_file_x, 0, MENU_ID_FILE, MENU1); |
229 | menu_reopen_x = menu_encoding_x + DrawMenuButton(menu_encoding_x, 0, MENU_ID_ENCODING, MENU2); |
||
230 | DrawMenuButton(menu_reopen_x, 0, MENU_ID_REOPEN, MENU3); |
||
231 | |||
5612 | punk_joker | 232 | if (old_width!=Form.width) || (old_height!=Form.height) |
233 | { |
||
234 | old_width = Form.width; |
||
235 | old_height = Form.height; |
||
5915 | punk_joker | 236 | |
7041 | leency | 237 | rows.no_selection = true; |
238 | rows.SetFont(8, 14, 0x90); |
||
7043 | leency | 239 | rows.SetSizes(0, TOPPANELH, Form.cwidth - SCROLL_SIZE, Form.cheight - TOPPANELH - BOTPANELH, 20); |
7041 | leency | 240 | rows.column_max = rows.w / rows.font_w; |
241 | |||
7290 | punk_joker | 242 | if (bufpointer) |
243 | { |
||
244 | Prepare(); |
||
245 | } |
||
7041 | leency | 246 | rows.CheckDoesValuesOkey(); |
5612 | punk_joker | 247 | } |
7043 | leency | 248 | DrawRectangle(rows.x+rows.w-1, rows.y, SCROLL_SIZE, rows.h-1, 0xEEEeee); |
249 | DrawText(); |
||
5612 | punk_joker | 250 | } |
251 | |||
7041 | leency | 252 | void OpenFile(dword _path) |
5612 | punk_joker | 253 | { |
7041 | leency | 254 | strcpy(#param, _path); |
255 | sprintf(#win_title, "%s - %s", TITLE, #param); |
||
256 | rows.KeyHome(); |
||
257 | file_size stdcall (#param); |
||
5612 | punk_joker | 258 | bufsize = EBX; |
259 | if (bufsize) |
||
260 | { |
||
7041 | leency | 261 | bufpointer = mem_Free(bufpointer); |
5612 | punk_joker | 262 | bufpointer = mem_Alloc(bufsize); |
7290 | punk_joker | 263 | if (ReadFile(0, bufsize, bufpointer, #param) != 0) |
264 | { |
||
7041 | leency | 265 | bufpointer = 0; |
266 | notify("'Error opening file'-E"); |
||
7049 | leency | 267 | return; |
7041 | leency | 268 | } |
5612 | punk_joker | 269 | } |
7290 | punk_joker | 270 | if (encoding!=CH_CP866) |
271 | { |
||
272 | ChangeCharset(charsets[encoding], "CP866", bufpointer); |
||
273 | } |
||
5612 | punk_joker | 274 | } |
275 | |||
7290 | punk_joker | 276 | enum |
277 | { |
||
7041 | leency | 278 | PARSE_CALCULATE_ROWS_COUNT, |
279 | PARSE_DRAW_PREPARE, |
||
280 | }; |
||
7290 | punk_joker | 281 | |
7041 | leency | 282 | void Parse(int mode) |
5612 | punk_joker | 283 | { |
7041 | leency | 284 | int pos=0; |
285 | int sub_pos=0; |
||
5612 | punk_joker | 286 | int len_str = 0; |
7041 | leency | 287 | bool do_eof = false; |
5612 | punk_joker | 288 | word bukva[2]; |
7041 | leency | 289 | |
5612 | punk_joker | 290 | while(1) |
291 | { |
||
292 | while(1) |
||
293 | { |
||
5915 | punk_joker | 294 | bukva = DSBYTE[bufpointer+pos+len_str]; |
5612 | punk_joker | 295 | if (bukva=='\0') |
296 | { |
||
7041 | leency | 297 | do_eof = true; |
5612 | punk_joker | 298 | break; |
299 | } |
||
7290 | punk_joker | 300 | if (bukva==0x0a) |
301 | { |
||
302 | break; |
||
303 | } |
||
304 | else |
||
305 | { |
||
306 | len_str++; |
||
307 | } |
||
5612 | punk_joker | 308 | } |
7041 | leency | 309 | if (len_str<=rows.column_max) |
5612 | punk_joker | 310 | { |
7290 | punk_joker | 311 | if (mode==PARSE_DRAW_PREPARE) |
312 | { |
||
313 | s.addn(bufpointer+pos, len_str); |
||
314 | } |
||
7041 | leency | 315 | pos += len_str+1; |
5612 | punk_joker | 316 | } |
317 | else |
||
318 | { |
||
7290 | punk_joker | 319 | if (mode==PARSE_DRAW_PREPARE) |
320 | { |
||
321 | s.addn(bufpointer+pos, rows.column_max); |
||
322 | } |
||
7041 | leency | 323 | pos += rows.column_max; |
5612 | punk_joker | 324 | } |
7041 | leency | 325 | sub_pos++; |
7290 | punk_joker | 326 | if (mode==PARSE_CALCULATE_ROWS_COUNT) && (do_eof) |
327 | { |
||
328 | break; |
||
329 | } |
||
330 | if (mode==PARSE_DRAW_PREPARE) && (pos>=bufsize-1) |
||
331 | { |
||
332 | break; |
||
333 | } |
||
5612 | punk_joker | 334 | len_str = 0; |
335 | } |
||
7041 | leency | 336 | if (mode == PARSE_CALCULATE_ROWS_COUNT) |
337 | { |
||
338 | rows.count = sub_pos; |
||
339 | Parse(PARSE_DRAW_PREPARE); |
||
340 | } |
||
5612 | punk_joker | 341 | } |
342 | |||
7041 | leency | 343 | void Prepare() |
344 | { |
||
345 | Parse(PARSE_CALCULATE_ROWS_COUNT); |
||
346 | } |
||
347 | |||
5612 | punk_joker | 348 | void DrawText() |
349 | { |
||
7043 | leency | 350 | int i=0, top; |
7041 | leency | 351 | |
7290 | punk_joker | 352 | if (rows.count |
353 | { |
||
354 | top = rows.count; |
||
355 | } |
||
5612 | punk_joker | 356 | else |
357 | { |
||
7290 | punk_joker | 358 | if (rows.count-rows.first<=rows.visible) |
359 | { |
||
360 | top = rows.count-rows.first-1; |
||
361 | } |
||
362 | else |
||
363 | { |
||
364 | top = rows.visible; |
||
365 | } |
||
5612 | punk_joker | 366 | } |
7041 | leency | 367 | |
7290 | punk_joker | 368 | if (bufpointer) |
5612 | punk_joker | 369 | { |
7290 | punk_joker | 370 | for (i=0; i |
371 | { |
||
372 | DrawBar(0, i*rows.item_h+TOPPANELH, rows.w, rows.item_h, 0xFFFFFF); |
||
373 | WriteText(2, i*rows.item_h+TOPPANELH, 0x90, 0x000000, s.get(i+rows.first)); |
||
374 | } |
||
5612 | punk_joker | 375 | } |
7041 | leency | 376 | DrawBar(0, i*rows.item_h+rows.y, rows.w, -i*rows.item_h + rows.h, 0xFFFfff); |
7043 | leency | 377 | DrawVerticalScroll(); |
5612 | punk_joker | 378 | } |
379 | |||
7043 | leency | 380 | void DrawVerticalScroll() |
381 | { |
||
382 | scroll_v.max_area = rows.count; |
||
383 | scroll_v.cur_area = rows.visible; |
||
384 | scroll_v.position = rows.first; |
||
385 | scroll_v.start_y = rows.y; |
||
386 | scroll_v.size_y = rows.h; |
||
387 | scroll_v.start_x = rows.w + rows.x -1; |
||
388 | scroll_v.all_redraw = 0; |
||
389 | scrollbar_v_draw(#scroll_v); |
||
390 | } |
||
391 | |||
7049 | leency | 392 | //===================================================// |
393 | // // |
||
394 | // EVENTS // |
||
395 | // // |
||
396 | //===================================================// |
||
397 | |||
398 | void EventMenuClick() |
||
399 | { |
||
400 | switch(menu.list.cur_y) |
||
401 | { |
||
402 | //File |
||
7290 | punk_joker | 403 | case FILE_SUBMENU_ID_OPEN: |
404 | EventOpenFile(); |
||
405 | break; |
||
406 | case FILE_SUBMENU_ID_CLOSE: |
||
407 | EventCloseFile(); |
||
408 | break; |
||
409 | case FILE_SUBMENU_ID_PROPERTIES: |
||
410 | EventShowFileProperties(); |
||
411 | break; |
||
412 | case FILE_SUBMENU_ID_EXIT: |
||
413 | ExitProcess(); |
||
414 | break; |
||
7049 | leency | 415 | //Encoding |
7290 | punk_joker | 416 | case MENU_ID_ENCODING...MENU_ID_ENCODING+9: |
417 | EventChangeEncoding(menu.list.cur_y-MENU_ID_ENCODING); |
||
418 | break; |
||
7049 | leency | 419 | //Reopen |
7290 | punk_joker | 420 | case FILE_SUBMENU_ID_TINYPAD: |
421 | EventOpenFileInAnotherProgram("/sys/tinypad"); |
||
422 | break; |
||
423 | case FILE_SUBMENU_ID_TEXTEDIT: |
||
424 | EventOpenFileInAnotherProgram("/sys/develop/t_edit"); |
||
425 | break; |
||
426 | case FILE_SUBMENU_ID_TEXTREAD: |
||
427 | EventOpenFileInAnotherProgram("/sys/txtread"); |
||
428 | break; |
||
429 | case FILE_SUBMENU_ID_WEBVIEW: |
||
430 | EventOpenFileInAnotherProgram("/sys/network/webview"); |
||
431 | break; |
||
432 | case FILE_SUBMENU_ID_FB2READ: |
||
433 | EventOpenFileInAnotherProgram("/sys/fb2read"); |
||
434 | break; |
||
435 | case FILE_SUBMENU_ID_HEXVIEW: |
||
436 | EventOpenFileInAnotherProgram("/sys/develop/heed"); |
||
437 | break; |
||
7049 | leency | 438 | } |
439 | menu.list.cur_y = 0; |
||
440 | } |
||
441 | |||
442 | void EventShowMenu(dword _menu_item_x, _menu_list, _id, _selected) |
||
443 | { |
||
444 | menu.selected = _selected; |
||
7290 | punk_joker | 445 | menu.show(Form.left+5 + _menu_item_x, Form.top+skin_height + TOPPANELH, 140, _menu_list, _id); |
7049 | leency | 446 | } |
447 | |||
448 | void EventOpenFile() |
||
449 | { |
||
450 | OpenDialog_start stdcall (#o_dialog); |
||
7290 | punk_joker | 451 | if (o_dialog.status) |
452 | { |
||
453 | OpenFile(#openfile_path); |
||
454 | Prepare(); |
||
455 | draw_window(); |
||
456 | } |
||
7049 | leency | 457 | } |
458 | |||
459 | void EventCloseFile() |
||
460 | { |
||
7290 | punk_joker | 461 | if (bufpointer) |
462 | { |
||
463 | s.drop(); |
||
464 | bufpointer = mem_Free(bufpointer); |
||
465 | strcpy(#win_title, TITLE); |
||
466 | draw_window(); |
||
467 | } |
||
7049 | leency | 468 | } |
469 | |||
470 | void EventShowFileProperties() |
||
471 | { |
||
7290 | punk_joker | 472 | char ss_param[4096]; |
473 | if (bufpointer) |
||
474 | { |
||
475 | sprintf(#ss_param, "-p %s", #param); |
||
476 | RunProgram("/sys/File managers/Eolite", #ss_param); |
||
477 | } |
||
7049 | leency | 478 | } |
479 | |||
480 | void EventChangeEncoding(dword id) |
||
481 | { |
||
482 | encoding = id; |
||
483 | OpenFile(#openfile_path); |
||
484 | Prepare(); |
||
485 | draw_window(); |
||
486 | } |
||
487 | |||
488 | void EventOpenFileInAnotherProgram(dword _app) |
||
489 | { |
||
490 | RunProgram(_app, #param); |
||
491 | } |
||
492 | |||
493 | |||
494 | |||
7290 | punk_joker | 495 | stop:=rows.visible) |