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