Rev 7447 | 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." |
7428 | leency | 23 | #define VERSION "Text Reader v1.21a" |
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 |
||
33 | Ctrl+E - edit current document |
||
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; |
||
5819 | leency | 48 | |
49 | enum { |
||
5962 | leency | 50 | OPEN_FILE, |
5819 | leency | 51 | MAGNIFY_MINUS, |
52 | MAGNIFY_PLUS, |
||
53 | CHANGE_ENCODING, |
||
54 | RUN_EDIT, |
||
55 | SHOW_INFO, |
||
7218 | leency | 56 | SHOW_FILE_PROPERTIES |
5819 | leency | 57 | }; |
58 | |||
7051 | leency | 59 | int encoding; |
60 | |||
5819 | leency | 61 | #include "ini.h" |
5980 | leency | 62 | #include "prepare_page.h" |
5819 | leency | 63 | |
5980 | leency | 64 | |
5923 | leency | 65 | void InitDlls() |
66 | { |
||
67 | load_dll(boxlib, #box_lib_init, 0); |
||
68 | load_dll(libio, #libio_init, 1); |
||
69 | load_dll(libimg, #libimg_init, 1); |
||
70 | load_dll(libini, #lib_init, 1); |
||
71 | load_dll(iconv_lib, #iconv_open, 0); |
||
72 | load_dll(Proc_lib, #OpenDialog_init,0); |
||
73 | } |
||
74 | |||
75 | |||
5819 | leency | 76 | void main() |
5923 | leency | 77 | { |
5987 | leency | 78 | InitDlls(); |
5819 | leency | 79 | OpenDialog_init stdcall (#o_dialog); |
7286 | leency | 80 | LoadIniSettings(); |
6806 | leency | 81 | kfont.init(DEFAULT_FONT); |
5819 | leency | 82 | Libimg_LoadImage(#skin, abspath("toolbar.png")); |
83 | OpenFile(#param); |
||
84 | list.no_selection = true; |
||
7227 | leency | 85 | SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER); |
5819 | leency | 86 | loop() |
87 | { |
||
5923 | leency | 88 | switch(WaitEvent()) |
89 | { |
||
90 | case evMouse: |
||
91 | HandleMouseEvent(); |
||
5819 | leency | 92 | break; |
5923 | leency | 93 | case evKey: |
94 | HandleKeyEvent(); |
||
95 | break; |
||
96 | case evButton: |
||
97 | HandleButtonEvent(); |
||
98 | break; |
||
99 | case evReDraw: |
||
7450 | leency | 100 | if (menu.cur_y) { |
101 | encoding = menu.cur_y - 10; |
||
5923 | leency | 102 | OpenFile(#param); |
103 | PreparePage(); |
||
7450 | leency | 104 | menu.cur_y = NULL; |
5923 | leency | 105 | }; |
106 | draw_window(); |
||
107 | } |
||
5819 | leency | 108 | } |
109 | } |
||
110 | |||
5980 | leency | 111 | |
112 | void HandleButtonEvent() |
||
5819 | leency | 113 | { |
5923 | leency | 114 | |
5980 | leency | 115 | byte btn = GetButtonID(); |
116 | if (btn==1) { |
||
117 | SaveIniSettings(); |
||
118 | ExitProcess(); |
||
119 | } |
||
120 | btn-=10; |
||
121 | switch(btn) |
||
5923 | leency | 122 | { |
5980 | leency | 123 | case OPEN_FILE: |
124 | EventOpenFile(); |
||
125 | break; |
||
7218 | leency | 126 | case SHOW_FILE_PROPERTIES: |
127 | EventShowFileProperties(); |
||
128 | break; |
||
5980 | leency | 129 | case MAGNIFY_PLUS: |
130 | EventMagnifyPlus(); |
||
131 | break; |
||
132 | case MAGNIFY_MINUS: |
||
133 | EventMagnifyMinus(); |
||
134 | break; |
||
135 | case CHANGE_ENCODING: |
||
136 | EventChangeEncoding(); |
||
137 | break; |
||
138 | case RUN_EDIT: |
||
139 | EventRunEdit(); |
||
140 | break; |
||
141 | case SHOW_INFO: |
||
142 | EventShowInfo(); |
||
143 | break; |
||
5923 | leency | 144 | } |
5819 | leency | 145 | } |
146 | |||
147 | |||
5980 | leency | 148 | void HandleKeyEvent() |
5819 | leency | 149 | { |
5980 | leency | 150 | if (help_opened) { |
151 | help_opened = false; |
||
152 | DrawPage(); |
||
153 | return; |
||
154 | } |
||
155 | GetKeys(); |
||
7218 | leency | 156 | if (key_scancode == SCAN_CODE_F1) { |
5980 | leency | 157 | EventShowInfo(); |
158 | return; |
||
159 | } |
||
160 | if (key_modifier & KEY_LCTRL) || (key_modifier & KEY_RCTRL) { |
||
161 | switch (key_scancode) |
||
162 | { |
||
7218 | leency | 163 | case SCAN_CODE_KEY_O: |
5980 | leency | 164 | EventOpenFile(); |
165 | break; |
||
7218 | leency | 166 | case SCAN_CODE_KEY_I: |
167 | EventShowFileProperties(); |
||
168 | break; |
||
5980 | leency | 169 | case SCAN_CODE_UP: |
170 | EventMagnifyPlus(); |
||
171 | break; |
||
172 | case SCAN_CODE_DOWN: |
||
173 | EventMagnifyMinus(); |
||
174 | break; |
||
7218 | leency | 175 | case SCAN_CODE_KEY_E: |
5980 | leency | 176 | EventRunEdit(); |
177 | break; |
||
178 | case SCAN_CODE_TAB: |
||
179 | EventChangeEncoding(); |
||
180 | break; |
||
5819 | leency | 181 | } |
5980 | leency | 182 | return; |
5819 | leency | 183 | } |
5980 | leency | 184 | if (list.ProcessKey(key_scancode)) |
185 | DrawPage(); |
||
186 | } |
||
5819 | leency | 187 | |
188 | |||
5980 | leency | 189 | void HandleMouseEvent() |
190 | { |
||
191 | mouse.get(); |
||
192 | list.wheel_size = 7; |
||
193 | if (list.MouseScroll(mouse.vert)) { |
||
194 | DrawPage(); |
||
195 | return; |
||
5819 | leency | 196 | } |
5980 | leency | 197 | scrollbar_v_mouse (#scroll); |
198 | if (list.first != scroll.position) { |
||
199 | list.first = scroll.position; |
||
200 | DrawPage(); |
||
201 | } |
||
5819 | leency | 202 | } |
203 | |||
5980 | leency | 204 | |
205 | /* ----------------------------------------------------- */ |
||
206 | |||
207 | void EventOpenFile() |
||
5819 | leency | 208 | { |
5980 | leency | 209 | OpenDialog_start stdcall (#o_dialog); |
7286 | leency | 210 | if (o_dialog.status) { |
211 | OpenFile(#openfile_path); |
||
212 | PreparePage(); |
||
213 | } |
||
5819 | leency | 214 | } |
215 | |||
7218 | leency | 216 | void EventShowFileProperties() |
217 | { |
||
218 | char ss_param[4096]; |
||
219 | if (!param) return; |
||
220 | sprintf(#ss_param, "-p %s", #param); |
||
221 | io.run("/sys/File managers/Eolite", #ss_param); |
||
222 | } |
||
223 | |||
5980 | leency | 224 | void EventMagnifyPlus() |
5819 | leency | 225 | { |
6806 | leency | 226 | kfont.size.pt++; |
227 | if(!kfont.changeSIZE()) |
||
228 | kfont.size.pt--; |
||
5980 | leency | 229 | else |
230 | PreparePage(); |
||
5819 | leency | 231 | } |
232 | |||
5980 | leency | 233 | void EventMagnifyMinus() |
234 | { |
||
6806 | leency | 235 | kfont.size.pt--; |
236 | if(!kfont.changeSIZE()) |
||
237 | kfont.size.pt++; |
||
5980 | leency | 238 | else |
239 | PreparePage(); |
||
240 | } |
||
241 | |||
242 | void EventRunEdit() |
||
243 | { |
||
244 | io.run(DEFAULT_EDITOR, #param); |
||
245 | } |
||
246 | |||
247 | void EventChangeEncoding() |
||
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 | |||
261 | /* ------------------------------------------- */ |
||
262 | |||
263 | |||
5819 | leency | 264 | void OpenFile(dword f_path) |
265 | { |
||
266 | int tmp; |
||
267 | if (ESBYTE[f_path]) { |
||
268 | strcpy(#param, f_path); |
||
269 | io.read(#param); |
||
270 | strcpy(#title, #param); |
||
271 | strcat(#title, " - Text Reader"); |
||
272 | } |
||
273 | else { |
||
274 | if (list.count) return; |
||
5923 | leency | 275 | io.buffer_data = INTRO_TEXT; |
5819 | leency | 276 | strcpy(#title, "Text Reader"); |
277 | } |
||
278 | if (encoding!=CH_CP866) ChangeCharset(charsets[encoding], "CP866", io.buffer_data); |
||
279 | list.KeyHome(); |
||
280 | list.ClearList(); |
||
281 | } |
||
282 | |||
5980 | leency | 283 | void draw_window() |
284 | { |
||
7218 | leency | 285 | #define PADDING 6 |
286 | #define TOOLBAR_BUTTON_WIDTH 26 |
||
287 | incn x; |
||
6746 | leency | 288 | DefineAndDrawWindow(Form.left,Form.top,Form.width,Form.height,0x73,0,#title,0); |
5980 | leency | 289 | GetProcessInfo(#Form, SelfInfo); |
290 | if (Form.status_window>2) return; |
||
291 | |||
292 | if (Form.width < 200) { MoveSize(OLD,OLD,200,OLD); return; } |
||
293 | if (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); return; } |
||
294 | |||
295 | DrawBar(0, 0, Form.cwidth, TOOLBAR_H - 1, 0xe1e1e1); |
||
296 | DrawBar(0, TOOLBAR_H - 1, Form.cwidth, 1, 0x7F7F7F); |
||
297 | |||
7218 | leency | 298 | x.n = 0; |
299 | DrawToolbarButton(OPEN_FILE, x.inc(8)); |
||
300 | DrawToolbarButton(SHOW_FILE_PROPERTIES, x.inc(TOOLBAR_BUTTON_WIDTH + PADDING)); |
||
7428 | leency | 301 | DrawToolbarButton(MAGNIFY_MINUS, x.inc(TOOLBAR_BUTTON_WIDTH + PADDING + PADDING)); |
302 | DrawToolbarButton(MAGNIFY_PLUS, x.inc(TOOLBAR_BUTTON_WIDTH - 1)); |
||
7218 | leency | 303 | DrawToolbarButton(CHANGE_ENCODING, x.inc(TOOLBAR_BUTTON_WIDTH + PADDING + PADDING)); |
304 | charsets_menu_left = x.n; |
||
305 | DrawToolbarButton(RUN_EDIT, x.inc(TOOLBAR_BUTTON_WIDTH + PADDING)); |
||
5980 | leency | 306 | DrawToolbarButton(SHOW_INFO, Form.cwidth - 34); |
307 | |||
7043 | leency | 308 | |
5980 | leency | 309 | if ((Form.cwidth-scroll.size_x-1 == list.w) && |
310 | (Form.cheight-TOOLBAR_H == list.h) && |
||
311 | (list.count) |
||
312 | ) |
||
313 | { |
||
314 | DrawPage(); |
||
315 | } else { |
||
316 | PreparePage(); |
||
317 | } |
||
318 | DrawRectangle(scroll.start_x, scroll.start_y, scroll.size_x, scroll.size_y-1, scroll.bckg_col); |
||
5923 | leency | 319 | } |
5980 | leency | 320 | |
321 | void DrawPage() |
||
322 | { |
||
6808 | leency | 323 | kfont.ShowBufferPart(list.x, list.y, list.w, list.h, list.first*list.item_h*list.w); |
5980 | leency | 324 | DrawScroller(); |
7286 | leency | 325 | } |
326 | |||
327 | void DrawToolbarButton(char image_id, int x) |
||
328 | { |
||
329 | DefineButton(x+1, 6, TOOLBAR_ICON_WIDTH-2, TOOLBAR_ICON_HEIGHT-2, 10+image_id + BT_HIDE, 0); |
||
7428 | leency | 330 | img_draw stdcall(skin.image, x, 5, TOOLBAR_ICON_WIDTH, TOOLBAR_ICON_HEIGHT, TOOLBAR_ICON_WIDTH-1*image_id, 0); |
7286 | leency | 331 | } |
332 | |||
333 | void DrawScroller() |
||
334 | { |
||
335 | scroll.max_area = list.count; |
||
336 | scroll.cur_area = list.visible; |
||
337 | scroll.position = list.first; |
||
338 | scroll.all_redraw = 0; |
||
339 | scroll.start_x = list.x + list.w; |
||
340 | scroll.start_y = list.y; |
||
341 | scroll.size_y = list.h; |
||
342 | scrollbar_v_draw(#scroll); |
||
5980 | leency | 343 | }>> |