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