Rev 7051 | 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 | |
6805 | leency | 3 | #include "../lib/kfont.h" |
5886 | pavelyakov | 4 | #include "../lib/io.h" |
5819 | leency | 5 | #include "../lib/gui.h" |
6 | #include "../lib/list_box.h" |
||
6042 | leency | 7 | #include "../lib/menu.h" |
5819 | leency | 8 | #include "../lib/obj/box_lib.h" |
9 | #include "../lib/obj/libini.h" |
||
10 | #include "../lib/obj/iconv.h" |
||
11 | #include "../lib/obj/proc_lib.h" |
||
12 | #include "../lib/patterns/libimg_load_skin.h" |
||
13 | #include "../lib/patterns/simple_open_dialog.h" |
||
14 | |||
15 | #define TOOLBAR_H 34 |
||
5923 | leency | 16 | #define TOOLBAR_ICON_WIDTH 26 |
17 | #define TOOLBAR_ICON_HEIGHT 24 |
||
5819 | leency | 18 | |
5923 | leency | 19 | #define DEFAULT_EDITOR "/sys/tinypad" |
20 | |||
5980 | leency | 21 | #define INTRO_TEXT "This is a plain Text Reader.\nTry to open some text file." |
7218 | leency | 22 | #define VERSION "Text Reader v1.21" |
5962 | leency | 23 | #define ABOUT "Idea: Leency, punk_joker |
24 | Code: Leency, Veliant, KolibriOS Team |
||
5923 | leency | 25 | |
5962 | leency | 26 | Hotkeys: |
27 | Ctrl+O - open file |
||
7218 | leency | 28 | Ctrl+I - show file properties |
5962 | leency | 29 | Ctrl+Up - bigger font |
30 | Ctrl+Down - smaller font |
||
31 | Ctrl+Tab - select charset |
||
32 | Ctrl+E - edit current document |
||
33 | |||
34 | Press any key..." |
||
35 | |||
5819 | leency | 36 | char default_dir[] = "/rd/1"; |
37 | od_filter filter2 = {0,0}; |
||
38 | |||
39 | 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}; |
||
40 | llist list; |
||
41 | |||
42 | proc_info Form; |
||
43 | char title[4196]; |
||
44 | |||
7218 | leency | 45 | bool help_opened = false; |
46 | int charsets_menu_left = 0; |
||
5819 | leency | 47 | |
48 | enum { |
||
5962 | leency | 49 | OPEN_FILE, |
5819 | leency | 50 | MAGNIFY_MINUS, |
51 | MAGNIFY_PLUS, |
||
52 | CHANGE_ENCODING, |
||
53 | RUN_EDIT, |
||
54 | SHOW_INFO, |
||
7218 | leency | 55 | SHOW_FILE_PROPERTIES |
5819 | leency | 56 | }; |
57 | |||
7051 | leency | 58 | int encoding; |
59 | |||
5819 | leency | 60 | #include "ini.h" |
5980 | leency | 61 | #include "gui.h" |
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); |
6806 | leency | 80 | kfont.init(DEFAULT_FONT); |
5819 | leency | 81 | Libimg_LoadImage(#skin, abspath("toolbar.png")); |
82 | LoadIniSettings(); |
||
83 | OpenFile(#param); |
||
84 | list.no_selection = true; |
||
85 | SetEventMask(10000000000000000000000001100111b); |
||
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: |
||
6042 | leency | 100 | if (menu.list.cur_y) { |
101 | encoding = menu.list.cur_y - 10; |
||
5923 | leency | 102 | OpenFile(#param); |
103 | PreparePage(); |
||
6753 | leency | 104 | menu.list.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); |
210 | OpenFile(#openfile_path); |
||
211 | PreparePage(); |
||
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); |
||
219 | io.run("/sys/File managers/Eolite", #ss_param); |
||
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 | |||
240 | void EventRunEdit() |
||
241 | { |
||
242 | io.run(DEFAULT_EDITOR, #param); |
||
243 | } |
||
244 | |||
245 | void EventChangeEncoding() |
||
246 | { |
||
6042 | leency | 247 | menu.selected = encoding + 1; |
7218 | leency | 248 | menu.show(Form.left+5 + charsets_menu_left, Form.top+29+skin_height, 130, |
249 | "UTF-8\nKOI8-RU\nCP1251\nCP1252\nISO8859-5\nCP866", 10); |
||
5980 | leency | 250 | } |
251 | |||
252 | void EventShowInfo() { |
||
253 | help_opened = true; |
||
254 | DrawBar(list.x, list.y, list.w, list.h, 0xFFFfff); |
||
255 | WriteText(list.x + 10, list.y + 10, 10000001b, 0x555555, VERSION); |
||
256 | WriteTextLines(list.x + 10, list.y+40, 10110000b, 0, ABOUT, 20); |
||
257 | } |
||
258 | |||
259 | /* ------------------------------------------- */ |
||
260 | |||
261 | |||
5819 | leency | 262 | void OpenFile(dword f_path) |
263 | { |
||
264 | int tmp; |
||
265 | if (ESBYTE[f_path]) { |
||
266 | strcpy(#param, f_path); |
||
267 | io.read(#param); |
||
268 | strcpy(#title, #param); |
||
269 | strcat(#title, " - Text Reader"); |
||
270 | } |
||
271 | else { |
||
272 | if (list.count) return; |
||
5923 | leency | 273 | io.buffer_data = INTRO_TEXT; |
5819 | leency | 274 | strcpy(#title, "Text Reader"); |
275 | } |
||
276 | if (encoding!=CH_CP866) ChangeCharset(charsets[encoding], "CP866", io.buffer_data); |
||
277 | list.KeyHome(); |
||
278 | list.ClearList(); |
||
279 | } |
||
280 | |||
5980 | leency | 281 | void draw_window() |
282 | { |
||
7218 | leency | 283 | #define PADDING 6 |
284 | #define TOOLBAR_BUTTON_WIDTH 26 |
||
285 | incn x; |
||
6746 | leency | 286 | DefineAndDrawWindow(Form.left,Form.top,Form.width,Form.height,0x73,0,#title,0); |
5980 | leency | 287 | GetProcessInfo(#Form, SelfInfo); |
288 | if (Form.status_window>2) return; |
||
289 | |||
290 | if (Form.width < 200) { MoveSize(OLD,OLD,200,OLD); return; } |
||
291 | if (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); return; } |
||
292 | |||
293 | DrawBar(0, 0, Form.cwidth, TOOLBAR_H - 1, 0xe1e1e1); |
||
294 | DrawBar(0, TOOLBAR_H - 1, Form.cwidth, 1, 0x7F7F7F); |
||
295 | |||
7218 | leency | 296 | x.n = 0; |
297 | DrawToolbarButton(OPEN_FILE, x.inc(8)); |
||
298 | DrawToolbarButton(SHOW_FILE_PROPERTIES, x.inc(TOOLBAR_BUTTON_WIDTH + PADDING)); |
||
299 | DrawToolbarButton(MAGNIFY_PLUS, x.inc(TOOLBAR_BUTTON_WIDTH + PADDING + PADDING)); |
||
300 | DrawToolbarButton(MAGNIFY_MINUS, x.inc(TOOLBAR_BUTTON_WIDTH - 1)); |
||
301 | DrawToolbarButton(CHANGE_ENCODING, x.inc(TOOLBAR_BUTTON_WIDTH + PADDING + PADDING)); |
||
302 | charsets_menu_left = x.n; |
||
303 | DrawToolbarButton(RUN_EDIT, x.inc(TOOLBAR_BUTTON_WIDTH + PADDING)); |
||
5980 | leency | 304 | DrawToolbarButton(SHOW_INFO, Form.cwidth - 34); |
305 | |||
7043 | leency | 306 | |
5980 | leency | 307 | if ((Form.cwidth-scroll.size_x-1 == list.w) && |
308 | (Form.cheight-TOOLBAR_H == list.h) && |
||
309 | (list.count) |
||
310 | ) |
||
311 | { |
||
312 | DrawPage(); |
||
313 | } else { |
||
314 | PreparePage(); |
||
315 | } |
||
316 | DrawRectangle(scroll.start_x, scroll.start_y, scroll.size_x, scroll.size_y-1, scroll.bckg_col); |
||
5923 | leency | 317 | } |
5980 | leency | 318 | |
319 | void DrawPage() |
||
320 | { |
||
6808 | leency | 321 | kfont.ShowBufferPart(list.x, list.y, list.w, list.h, list.first*list.item_h*list.w); |
5980 | leency | 322 | DrawScroller(); |
323 | }>> |