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