Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5962 | leency | 1 | #define MEMSIZE 4096*25 |
5819 | leency | 2 | |
7466 | leency | 3 | //===================================================// |
4 | // // |
||
5 | // LIB // |
||
6 | // // |
||
7 | //===================================================// |
||
8 | |||
5886 | pavelyakov | 9 | #include "../lib/io.h" |
7288 | leency | 10 | #include "../lib/gui.h" |
5819 | leency | 11 | #include "../lib/list_box.h" |
7286 | leency | 12 | #include "../lib/kfont.h" |
7230 | leency | 13 | |
5819 | leency | 14 | #include "../lib/obj/box_lib.h" |
15 | #include "../lib/obj/libini.h" |
||
7230 | leency | 16 | #include "../lib/obj/libimg.h" |
5819 | leency | 17 | #include "../lib/obj/iconv.h" |
18 | #include "../lib/obj/proc_lib.h" |
||
7230 | leency | 19 | |
5819 | leency | 20 | #include "../lib/patterns/simple_open_dialog.h" |
21 | |||
7466 | leency | 22 | //===================================================// |
23 | // // |
||
24 | // DATA // |
||
25 | // // |
||
26 | //===================================================// |
||
27 | |||
5819 | leency | 28 | #define TOOLBAR_H 34 |
5923 | leency | 29 | #define TOOLBAR_ICON_WIDTH 26 |
30 | #define TOOLBAR_ICON_HEIGHT 24 |
||
5819 | leency | 31 | |
5923 | leency | 32 | #define DEFAULT_EDITOR "/sys/tinypad" |
33 | |||
5980 | leency | 34 | #define INTRO_TEXT "This is a plain Text Reader.\nTry to open some text file." |
7466 | leency | 35 | #define VERSION "Text Reader v1.3" |
5962 | leency | 36 | #define ABOUT "Idea: Leency, punk_joker |
37 | Code: Leency, Veliant, KolibriOS Team |
||
5923 | leency | 38 | |
5962 | leency | 39 | Hotkeys: |
40 | Ctrl+O - open file |
||
7218 | leency | 41 | Ctrl+I - show file properties |
5962 | leency | 42 | Ctrl+Up - bigger font |
43 | Ctrl+Down - smaller font |
||
44 | Ctrl+Tab - select charset |
||
7462 | leency | 45 | Ctrl+E - reopen current file in another app |
5962 | leency | 46 | |
47 | Press any key..." |
||
48 | |||
7466 | leency | 49 | dword color_schemes[] = { |
50 | 0xFFFfff, 0, |
||
51 | 0xF0F0F0, 0, |
||
7493 | leency | 52 | 0xFDF6E3, 0x101A21, |
53 | 0xFCF0DA, 0x171501, |
||
7466 | leency | 54 | 0xF0F0C7, 0, |
55 | 0x282C34, 0xABB2BF, |
||
56 | 0x282923, 0xD8D8D2 |
||
57 | }; |
||
58 | |||
59 | char color_scheme_names[] = |
||
60 | "White & Black |
||
61 | Grey & Black RtfRead |
||
7493 | leency | 62 | Linen & Black Horst |
63 | Antique & Black Pocket |
||
7466 | leency | 64 | Lemon & Black Fb2Read |
65 | DarkGrey & Grey Godot |
||
66 | DarkGrey & Grey Monokai"; |
||
67 | |||
5819 | leency | 68 | char default_dir[] = "/rd/1"; |
7286 | leency | 69 | od_filter filter2 = { 8, "TXT\0\0" }; |
5819 | leency | 70 | |
71 | scroll_bar scroll = { 15,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}; |
||
72 | llist list; |
||
73 | |||
74 | proc_info Form; |
||
75 | char title[4196]; |
||
76 | |||
7218 | leency | 77 | bool help_opened = false; |
7466 | leency | 78 | int charsets_mx; |
79 | int reopenin_mx; |
||
80 | int colscheme_mx; |
||
5819 | leency | 81 | |
7466 | leency | 82 | int curcol_scheme; |
83 | |||
5819 | leency | 84 | enum { |
5962 | leency | 85 | OPEN_FILE, |
5819 | leency | 86 | MAGNIFY_MINUS, |
87 | MAGNIFY_PLUS, |
||
88 | CHANGE_ENCODING, |
||
89 | RUN_EDIT, |
||
90 | SHOW_INFO, |
||
7466 | leency | 91 | SHOW_FILE_PROPERTIES, |
92 | COLOR_SCHEME |
||
5819 | leency | 93 | }; |
94 | |||
7051 | leency | 95 | int encoding; |
96 | |||
7466 | leency | 97 | dword bg_color; |
98 | dword text_color; |
||
7462 | leency | 99 | |
7466 | leency | 100 | //===================================================// |
101 | // // |
||
102 | // INTERNAL INCLUDES // |
||
103 | // // |
||
104 | //===================================================// |
||
105 | |||
5819 | leency | 106 | #include "ini.h" |
5980 | leency | 107 | #include "prepare_page.h" |
5819 | leency | 108 | |
7466 | leency | 109 | //===================================================// |
110 | // // |
||
111 | // CODE // |
||
112 | // // |
||
113 | //===================================================// |
||
114 | |||
5923 | leency | 115 | void InitDlls() |
116 | { |
||
117 | load_dll(boxlib, #box_lib_init, 0); |
||
118 | load_dll(libio, #libio_init, 1); |
||
119 | load_dll(libimg, #libimg_init, 1); |
||
120 | load_dll(libini, #lib_init, 1); |
||
121 | load_dll(iconv_lib, #iconv_open, 0); |
||
122 | load_dll(Proc_lib, #OpenDialog_init,0); |
||
123 | } |
||
124 | |||
5819 | leency | 125 | void main() |
5923 | leency | 126 | { |
5987 | leency | 127 | InitDlls(); |
5819 | leency | 128 | OpenDialog_init stdcall (#o_dialog); |
7516 | leency | 129 | if (param) strcpy(#openfile_path, #param); |
7286 | leency | 130 | LoadIniSettings(); |
7466 | leency | 131 | EventSetColorScheme(curcol_scheme); |
6806 | leency | 132 | kfont.init(DEFAULT_FONT); |
5819 | leency | 133 | Libimg_LoadImage(#skin, abspath("toolbar.png")); |
134 | OpenFile(#param); |
||
135 | list.no_selection = true; |
||
7227 | leency | 136 | SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER); |
5819 | leency | 137 | loop() |
138 | { |
||
5923 | leency | 139 | switch(WaitEvent()) |
140 | { |
||
141 | case evMouse: |
||
142 | HandleMouseEvent(); |
||
5819 | leency | 143 | break; |
5923 | leency | 144 | case evKey: |
145 | HandleKeyEvent(); |
||
146 | break; |
||
147 | case evButton: |
||
148 | HandleButtonEvent(); |
||
149 | break; |
||
150 | case evReDraw: |
||
7462 | leency | 151 | EventMenuClick(); |
5923 | leency | 152 | draw_window(); |
153 | } |
||
5819 | leency | 154 | } |
155 | } |
||
156 | |||
7466 | leency | 157 | //===================================================// |
158 | // // |
||
159 | // EVENTS // |
||
160 | // // |
||
161 | //===================================================// |
||
5980 | leency | 162 | |
163 | void HandleButtonEvent() |
||
5819 | leency | 164 | { |
5923 | leency | 165 | |
5980 | leency | 166 | byte btn = GetButtonID(); |
167 | if (btn==1) { |
||
168 | SaveIniSettings(); |
||
169 | ExitProcess(); |
||
170 | } |
||
171 | btn-=10; |
||
172 | switch(btn) |
||
5923 | leency | 173 | { |
5980 | leency | 174 | case OPEN_FILE: |
175 | EventOpenFile(); |
||
176 | break; |
||
7218 | leency | 177 | case SHOW_FILE_PROPERTIES: |
178 | EventShowFileProperties(); |
||
179 | break; |
||
5980 | leency | 180 | case MAGNIFY_PLUS: |
181 | EventMagnifyPlus(); |
||
182 | break; |
||
183 | case MAGNIFY_MINUS: |
||
184 | EventMagnifyMinus(); |
||
185 | break; |
||
186 | case CHANGE_ENCODING: |
||
7462 | leency | 187 | EventShowEncodingList(); |
5980 | leency | 188 | break; |
189 | case RUN_EDIT: |
||
7466 | leency | 190 | EventShowReopenMenu(); |
5980 | leency | 191 | break; |
7466 | leency | 192 | case COLOR_SCHEME: |
193 | EventShowColorSchemesList(); |
||
194 | break; |
||
5980 | leency | 195 | case SHOW_INFO: |
196 | EventShowInfo(); |
||
197 | break; |
||
5923 | leency | 198 | } |
5819 | leency | 199 | } |
200 | |||
201 | |||
5980 | leency | 202 | void HandleKeyEvent() |
5819 | leency | 203 | { |
5980 | leency | 204 | if (help_opened) { |
205 | help_opened = false; |
||
206 | DrawPage(); |
||
207 | return; |
||
208 | } |
||
209 | GetKeys(); |
||
7218 | leency | 210 | if (key_scancode == SCAN_CODE_F1) { |
5980 | leency | 211 | EventShowInfo(); |
212 | return; |
||
213 | } |
||
214 | if (key_modifier & KEY_LCTRL) || (key_modifier & KEY_RCTRL) { |
||
215 | switch (key_scancode) |
||
216 | { |
||
7218 | leency | 217 | case SCAN_CODE_KEY_O: |
5980 | leency | 218 | EventOpenFile(); |
219 | break; |
||
7218 | leency | 220 | case SCAN_CODE_KEY_I: |
221 | EventShowFileProperties(); |
||
222 | break; |
||
5980 | leency | 223 | case SCAN_CODE_UP: |
224 | EventMagnifyPlus(); |
||
225 | break; |
||
226 | case SCAN_CODE_DOWN: |
||
227 | EventMagnifyMinus(); |
||
228 | break; |
||
7218 | leency | 229 | case SCAN_CODE_KEY_E: |
7466 | leency | 230 | EventShowReopenMenu(); |
5980 | leency | 231 | break; |
232 | case SCAN_CODE_TAB: |
||
233 | EventChangeEncoding(); |
||
234 | break; |
||
5819 | leency | 235 | } |
5980 | leency | 236 | return; |
5819 | leency | 237 | } |
5980 | leency | 238 | if (list.ProcessKey(key_scancode)) |
239 | DrawPage(); |
||
240 | } |
||
5819 | leency | 241 | |
242 | |||
5980 | leency | 243 | void HandleMouseEvent() |
244 | { |
||
245 | mouse.get(); |
||
246 | list.wheel_size = 7; |
||
247 | if (list.MouseScroll(mouse.vert)) { |
||
248 | DrawPage(); |
||
249 | return; |
||
5819 | leency | 250 | } |
5980 | leency | 251 | scrollbar_v_mouse (#scroll); |
252 | if (list.first != scroll.position) { |
||
253 | list.first = scroll.position; |
||
254 | DrawPage(); |
||
255 | } |
||
5819 | leency | 256 | } |
257 | |||
5980 | leency | 258 | /* ----------------------------------------------------- */ |
259 | |||
260 | void EventOpenFile() |
||
5819 | leency | 261 | { |
5980 | leency | 262 | OpenDialog_start stdcall (#o_dialog); |
7286 | leency | 263 | if (o_dialog.status) { |
264 | OpenFile(#openfile_path); |
||
265 | PreparePage(); |
||
266 | } |
||
5819 | leency | 267 | } |
268 | |||
7218 | leency | 269 | void EventShowFileProperties() |
270 | { |
||
271 | char ss_param[4096]; |
||
272 | if (!param) return; |
||
273 | sprintf(#ss_param, "-p %s", #param); |
||
7462 | leency | 274 | RunProgram("/sys/File managers/Eolite", #ss_param); |
7218 | leency | 275 | } |
276 | |||
5980 | leency | 277 | void EventMagnifyPlus() |
5819 | leency | 278 | { |
6806 | leency | 279 | kfont.size.pt++; |
280 | if(!kfont.changeSIZE()) |
||
281 | kfont.size.pt--; |
||
5980 | leency | 282 | else |
283 | PreparePage(); |
||
5819 | leency | 284 | } |
285 | |||
5980 | leency | 286 | void EventMagnifyMinus() |
287 | { |
||
6806 | leency | 288 | kfont.size.pt--; |
289 | if(!kfont.changeSIZE()) |
||
290 | kfont.size.pt++; |
||
5980 | leency | 291 | else |
292 | PreparePage(); |
||
293 | } |
||
294 | |||
7466 | leency | 295 | void EventShowEncodingList() |
5980 | leency | 296 | { |
7466 | leency | 297 | menu.selected = encoding + 1; |
298 | menu.show(Form.left+5 + charsets_mx, Form.top+29+skin_height, 130, |
||
299 | "UTF-8\nKOI8-RU\nCP1251\nCP1252\nISO8859-5\nCP866", 10); |
||
300 | } |
||
301 | |||
302 | void EventShowReopenMenu() |
||
303 | { |
||
7462 | leency | 304 | menu.selected = 0; |
7466 | leency | 305 | menu.show(Form.left+5 + reopenin_mx, Form.top+29+skin_height, 130, |
306 | "Tinypad\nTextEdit\nWebView\nFB2Read\nHexView\nOther", 20); |
||
5980 | leency | 307 | } |
308 | |||
7466 | leency | 309 | void EventShowColorSchemesList() |
5980 | leency | 310 | { |
7466 | leency | 311 | menu.selected = curcol_scheme + 1; |
312 | menu.show(Form.left+5 + colscheme_mx, Form.top+29+skin_height, 175, #color_scheme_names, 30); |
||
5980 | leency | 313 | } |
314 | |||
7466 | leency | 315 | void EventSetColorScheme(dword _setn) |
316 | { |
||
317 | curcol_scheme = _setn; |
||
318 | bg_color = color_schemes[curcol_scheme*2]; |
||
319 | text_color = color_schemes[curcol_scheme*2+1]; |
||
320 | } |
||
321 | |||
5980 | leency | 322 | void EventShowInfo() { |
323 | help_opened = true; |
||
324 | DrawBar(list.x, list.y, list.w, list.h, 0xFFFfff); |
||
325 | WriteText(list.x + 10, list.y + 10, 10000001b, 0x555555, VERSION); |
||
326 | WriteTextLines(list.x + 10, list.y+40, 10110000b, 0, ABOUT, 20); |
||
327 | } |
||
328 | |||
7462 | leency | 329 | void EventChangeEncoding(dword id) |
330 | { |
||
331 | encoding = id; |
||
332 | OpenFile(#openfile_path); |
||
333 | PreparePage(); |
||
334 | draw_window(); |
||
335 | } |
||
336 | |||
337 | void EventOpenFileInAnotherProgram(dword _app) |
||
338 | { |
||
339 | RunProgram(_app, #param); |
||
340 | } |
||
341 | |||
342 | void EventMenuClick() |
||
343 | { |
||
7466 | leency | 344 | byte open_param[4096]; |
7462 | leency | 345 | switch(menu.cur_y) |
346 | { |
||
347 | //Encoding |
||
348 | case 10...15: |
||
349 | EventChangeEncoding(menu.cur_y-10); |
||
350 | break; |
||
351 | //Reopen |
||
352 | case 20: |
||
353 | EventOpenFileInAnotherProgram("/sys/tinypad"); |
||
354 | break; |
||
355 | case 21: |
||
356 | EventOpenFileInAnotherProgram("/sys/develop/t_edit"); |
||
357 | break; |
||
358 | case 22: |
||
359 | EventOpenFileInAnotherProgram("/sys/network/webview"); |
||
360 | break; |
||
361 | case 23: |
||
362 | EventOpenFileInAnotherProgram("/sys/fb2read"); |
||
363 | break; |
||
364 | case 24: |
||
365 | EventOpenFileInAnotherProgram("/sys/develop/heed"); |
||
366 | break; |
||
7466 | leency | 367 | case 25: |
368 | sprintf(#open_param,"~%s",#param); |
||
369 | RunProgram("/sys/@open", #open_param); |
||
370 | break; |
||
371 | //ColorSchemes |
||
372 | case 30...38: |
||
373 | EventSetColorScheme(menu.cur_y-30); |
||
374 | PreparePage(); |
||
375 | break; |
||
7462 | leency | 376 | } |
377 | menu.cur_y = 0; |
||
378 | } |
||
379 | |||
7466 | leency | 380 | //===================================================// |
381 | // // |
||
382 | // DRAWS AND OTHER FUNCS // |
||
383 | // // |
||
384 | //===================================================// |
||
5980 | leency | 385 | |
5819 | leency | 386 | void OpenFile(dword f_path) |
387 | { |
||
388 | int tmp; |
||
389 | if (ESBYTE[f_path]) { |
||
390 | strcpy(#param, f_path); |
||
391 | io.read(#param); |
||
392 | strcpy(#title, #param); |
||
393 | strcat(#title, " - Text Reader"); |
||
394 | } |
||
395 | else { |
||
396 | if (list.count) return; |
||
5923 | leency | 397 | io.buffer_data = INTRO_TEXT; |
5819 | leency | 398 | strcpy(#title, "Text Reader"); |
399 | } |
||
400 | if (encoding!=CH_CP866) ChangeCharset(charsets[encoding], "CP866", io.buffer_data); |
||
401 | list.KeyHome(); |
||
402 | list.ClearList(); |
||
403 | } |
||
404 | |||
5980 | leency | 405 | void draw_window() |
406 | { |
||
7466 | leency | 407 | #define BUTTONS_GAP 6 |
408 | #define BLOCKS_GAP 15 |
||
7218 | leency | 409 | #define TOOLBAR_BUTTON_WIDTH 26 |
410 | incn x; |
||
6746 | leency | 411 | DefineAndDrawWindow(Form.left,Form.top,Form.width,Form.height,0x73,0,#title,0); |
5980 | leency | 412 | GetProcessInfo(#Form, SelfInfo); |
413 | if (Form.status_window>2) return; |
||
414 | |||
415 | if (Form.width < 200) { MoveSize(OLD,OLD,200,OLD); return; } |
||
416 | if (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); return; } |
||
417 | |||
418 | DrawBar(0, 0, Form.cwidth, TOOLBAR_H - 1, 0xe1e1e1); |
||
419 | DrawBar(0, TOOLBAR_H - 1, Form.cwidth, 1, 0x7F7F7F); |
||
420 | |||
7218 | leency | 421 | x.n = 0; |
422 | DrawToolbarButton(OPEN_FILE, x.inc(8)); |
||
7466 | leency | 423 | DrawToolbarButton(SHOW_FILE_PROPERTIES, x.inc(TOOLBAR_BUTTON_WIDTH + BUTTONS_GAP)); |
424 | |||
425 | DrawToolbarButton(MAGNIFY_MINUS, x.inc(TOOLBAR_BUTTON_WIDTH + BLOCKS_GAP)); |
||
7428 | leency | 426 | DrawToolbarButton(MAGNIFY_PLUS, x.inc(TOOLBAR_BUTTON_WIDTH - 1)); |
7466 | leency | 427 | DrawToolbarButton(COLOR_SCHEME, x.inc(TOOLBAR_BUTTON_WIDTH + BUTTONS_GAP)); colscheme_mx = x.n; |
428 | |||
429 | DrawToolbarButton(CHANGE_ENCODING, x.inc(TOOLBAR_BUTTON_WIDTH + BLOCKS_GAP)); charsets_mx = x.n; |
||
430 | DrawToolbarButton(RUN_EDIT, x.inc(TOOLBAR_BUTTON_WIDTH + BLOCKS_GAP)); reopenin_mx = x.n; |
||
5980 | leency | 431 | DrawToolbarButton(SHOW_INFO, Form.cwidth - 34); |
432 | |||
433 | if ((Form.cwidth-scroll.size_x-1 == list.w) && |
||
434 | (Form.cheight-TOOLBAR_H == list.h) && |
||
435 | (list.count) |
||
436 | ) |
||
437 | { |
||
438 | DrawPage(); |
||
439 | } else { |
||
440 | PreparePage(); |
||
7466 | leency | 441 | } |
442 | |||
5980 | leency | 443 | DrawRectangle(scroll.start_x, scroll.start_y, scroll.size_x, scroll.size_y-1, scroll.bckg_col); |
5923 | leency | 444 | } |
5980 | leency | 445 | |
446 | void DrawPage() |
||
447 | { |
||
6808 | leency | 448 | kfont.ShowBufferPart(list.x, list.y, list.w, list.h, list.first*list.item_h*list.w); |
5980 | leency | 449 | DrawScroller(); |
7286 | leency | 450 | } |
451 | |||
452 | void DrawToolbarButton(char image_id, int x) |
||
453 | { |
||
454 | DefineButton(x+1, 6, TOOLBAR_ICON_WIDTH-2, TOOLBAR_ICON_HEIGHT-2, 10+image_id + BT_HIDE, 0); |
||
7428 | leency | 455 | img_draw stdcall(skin.image, x, 5, TOOLBAR_ICON_WIDTH, TOOLBAR_ICON_HEIGHT, TOOLBAR_ICON_WIDTH-1*image_id, 0); |
7286 | leency | 456 | } |
457 | |||
458 | void DrawScroller() |
||
459 | { |
||
460 | scroll.max_area = list.count; |
||
461 | scroll.cur_area = list.visible; |
||
462 | scroll.position = list.first; |
||
463 | scroll.all_redraw = 0; |
||
464 | scroll.start_x = list.x + list.w; |
||
465 | scroll.start_y = list.y; |
||
466 | scroll.size_y = list.h; |
||
467 | scrollbar_v_draw(#scroll); |
||
5980 | leency | 468 | }>> |