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