Rev 5987 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5987 | Rev 5996 | ||
---|---|---|---|
1 | #define MEMSIZE 4096*25 |
1 | #define MEMSIZE 4096*25 |
2 | 2 | ||
3 | #include "../lib/font.h" |
3 | #include "../lib/font.h" |
4 | #include "../lib/io.h" |
4 | #include "../lib/io.h" |
5 | #include "../lib/gui.h" |
5 | #include "../lib/gui.h" |
6 | #include "../lib/list_box.h" |
6 | #include "../lib/list_box.h" |
7 | #include "../lib/obj/box_lib.h" |
7 | #include "../lib/obj/box_lib.h" |
8 | #include "../lib/obj/libini.h" |
8 | #include "../lib/obj/libini.h" |
9 | #include "../lib/obj/iconv.h" |
9 | #include "../lib/obj/iconv.h" |
10 | #include "../lib/obj/proc_lib.h" |
10 | #include "../lib/obj/proc_lib.h" |
11 | #include "../lib/patterns/libimg_load_skin.h" |
11 | #include "../lib/patterns/libimg_load_skin.h" |
12 | #include "../lib/patterns/simple_open_dialog.h" |
12 | #include "../lib/patterns/simple_open_dialog.h" |
13 | 13 | ||
14 | #define TOOLBAR_H 34 |
14 | #define TOOLBAR_H 34 |
15 | #define TOOLBAR_ICON_WIDTH 26 |
15 | #define TOOLBAR_ICON_WIDTH 26 |
16 | #define TOOLBAR_ICON_HEIGHT 24 |
16 | #define TOOLBAR_ICON_HEIGHT 24 |
17 | 17 | ||
18 | #define DEFAULT_EDITOR "/sys/tinypad" |
18 | #define DEFAULT_EDITOR "/sys/tinypad" |
19 | 19 | ||
20 | #define INTRO_TEXT "This is a plain Text Reader.\nTry to open some text file." |
20 | #define INTRO_TEXT "This is a plain Text Reader.\nTry to open some text file." |
21 | #define VERSION "Text Reader v1.05" |
21 | #define VERSION "Text Reader v1.06" |
22 | #define ABOUT "Idea: Leency, punk_joker |
22 | #define ABOUT "Idea: Leency, punk_joker |
23 | Code: Leency, Veliant, KolibriOS Team |
23 | Code: Leency, Veliant, KolibriOS Team |
24 | 24 | ||
25 | Hotkeys: |
25 | Hotkeys: |
26 | Ctrl+O - open file |
26 | Ctrl+O - open file |
27 | Ctrl+Up - bigger font |
27 | Ctrl+Up - bigger font |
28 | Ctrl+Down - smaller font |
28 | Ctrl+Down - smaller font |
29 | Ctrl+Tab - select charset |
29 | Ctrl+Tab - select charset |
30 | Ctrl+E - edit current document |
30 | Ctrl+E - edit current document |
31 | 31 | ||
32 | Press any key..." |
32 | Press any key..." |
33 | 33 | ||
34 | char default_dir[] = "/rd/1"; |
34 | char default_dir[] = "/rd/1"; |
35 | od_filter filter2 = {0,0}; |
35 | od_filter filter2 = {0,0}; |
36 | 36 | ||
37 | 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}; |
37 | 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}; |
38 | llist list; |
38 | llist list; |
39 | 39 | ||
40 | proc_info Form; |
40 | proc_info Form; |
41 | char title[4196]; |
41 | char title[4196]; |
42 | 42 | ||
43 | byte help_opened = false; |
43 | byte help_opened = false; |
44 | 44 | ||
45 | enum { |
45 | enum { |
46 | OPEN_FILE, |
46 | OPEN_FILE, |
47 | MAGNIFY_MINUS, |
47 | MAGNIFY_MINUS, |
48 | MAGNIFY_PLUS, |
48 | MAGNIFY_PLUS, |
49 | CHANGE_ENCODING, |
49 | CHANGE_ENCODING, |
50 | RUN_EDIT, |
50 | RUN_EDIT, |
51 | SHOW_INFO, |
51 | SHOW_INFO, |
52 | }; |
52 | }; |
53 | 53 | ||
54 | #include "ini.h" |
54 | #include "ini.h" |
55 | #include "menu.h" |
55 | #include "menu.h" |
56 | #include "gui.h" |
56 | #include "gui.h" |
57 | #include "prepare_page.h" |
57 | #include "prepare_page.h" |
58 | 58 | ||
59 | 59 | ||
60 | void InitDlls() |
60 | void InitDlls() |
61 | { |
61 | { |
62 | load_dll(boxlib, #box_lib_init, 0); |
62 | load_dll(boxlib, #box_lib_init, 0); |
63 | load_dll(libio, #libio_init, 1); |
63 | load_dll(libio, #libio_init, 1); |
64 | load_dll(libimg, #libimg_init, 1); |
64 | load_dll(libimg, #libimg_init, 1); |
65 | load_dll(libini, #lib_init, 1); |
65 | load_dll(libini, #lib_init, 1); |
66 | load_dll(iconv_lib, #iconv_open, 0); |
66 | load_dll(iconv_lib, #iconv_open, 0); |
67 | load_dll(Proc_lib, #OpenDialog_init,0); |
67 | load_dll(Proc_lib, #OpenDialog_init,0); |
68 | } |
68 | } |
69 | 69 | ||
70 | 70 | ||
71 | void main() |
71 | void main() |
72 | { |
72 | { |
73 | InitDlls(); |
73 | InitDlls(); |
74 | OpenDialog_init stdcall (#o_dialog); |
74 | OpenDialog_init stdcall (#o_dialog); |
75 | label.init(DEFAULT_FONT); |
75 | label.init(DEFAULT_FONT); |
76 | Libimg_LoadImage(#skin, abspath("toolbar.png")); |
76 | Libimg_LoadImage(#skin, abspath("toolbar.png")); |
77 | LoadIniSettings(); |
77 | LoadIniSettings(); |
78 | OpenFile(#param); |
78 | OpenFile(#param); |
79 | list.no_selection = true; |
79 | list.no_selection = true; |
80 | SetEventMask(10000000000000000000000001100111b); |
80 | SetEventMask(10000000000000000000000001100111b); |
81 | loop() |
81 | loop() |
82 | { |
82 | { |
83 | switch(WaitEvent()) |
83 | switch(WaitEvent()) |
84 | { |
84 | { |
85 | case evMouse: |
85 | case evMouse: |
86 | HandleMouseEvent(); |
86 | HandleMouseEvent(); |
87 | break; |
87 | break; |
88 | case evKey: |
88 | case evKey: |
89 | HandleKeyEvent(); |
89 | HandleKeyEvent(); |
90 | break; |
90 | break; |
91 | case evButton: |
91 | case evButton: |
92 | HandleButtonEvent(); |
92 | HandleButtonEvent(); |
93 | break; |
93 | break; |
94 | case evReDraw: |
94 | case evReDraw: |
95 | if (action_buf) { |
95 | if (action_buf) { |
96 | OpenFile(#param); |
96 | OpenFile(#param); |
97 | PreparePage(); |
97 | PreparePage(); |
98 | action_buf = false; |
98 | action_buf = false; |
99 | }; |
99 | }; |
100 | draw_window(); |
100 | draw_window(); |
101 | } |
101 | } |
102 | } |
102 | } |
103 | } |
103 | } |
104 | 104 | ||
105 | 105 | ||
106 | void HandleButtonEvent() |
106 | void HandleButtonEvent() |
107 | { |
107 | { |
108 | 108 | ||
109 | byte btn = GetButtonID(); |
109 | byte btn = GetButtonID(); |
110 | if (btn==1) { |
110 | if (btn==1) { |
111 | SaveIniSettings(); |
111 | SaveIniSettings(); |
112 | ExitProcess(); |
112 | ExitProcess(); |
113 | } |
113 | } |
114 | btn-=10; |
114 | btn-=10; |
115 | switch(btn) |
115 | switch(btn) |
116 | { |
116 | { |
117 | case OPEN_FILE: |
117 | case OPEN_FILE: |
118 | EventOpenFile(); |
118 | EventOpenFile(); |
119 | break; |
119 | break; |
120 | case MAGNIFY_PLUS: |
120 | case MAGNIFY_PLUS: |
121 | EventMagnifyPlus(); |
121 | EventMagnifyPlus(); |
122 | break; |
122 | break; |
123 | case MAGNIFY_MINUS: |
123 | case MAGNIFY_MINUS: |
124 | EventMagnifyMinus(); |
124 | EventMagnifyMinus(); |
125 | break; |
125 | break; |
126 | case CHANGE_ENCODING: |
126 | case CHANGE_ENCODING: |
127 | EventChangeEncoding(); |
127 | EventChangeEncoding(); |
128 | break; |
128 | break; |
129 | case RUN_EDIT: |
129 | case RUN_EDIT: |
130 | EventRunEdit(); |
130 | EventRunEdit(); |
131 | break; |
131 | break; |
132 | case SHOW_INFO: |
132 | case SHOW_INFO: |
133 | EventShowInfo(); |
133 | EventShowInfo(); |
134 | break; |
134 | break; |
135 | } |
135 | } |
136 | } |
136 | } |
137 | 137 | ||
138 | 138 | ||
139 | void HandleKeyEvent() |
139 | void HandleKeyEvent() |
140 | { |
140 | { |
141 | if (help_opened) { |
141 | if (help_opened) { |
142 | help_opened = false; |
142 | help_opened = false; |
143 | DrawPage(); |
143 | DrawPage(); |
144 | return; |
144 | return; |
145 | } |
145 | } |
146 | GetKeys(); |
146 | GetKeys(); |
147 | if (key_scancode==059) { |
147 | if (key_scancode==059) { |
148 | EventShowInfo(); |
148 | EventShowInfo(); |
149 | return; |
149 | return; |
150 | } |
150 | } |
151 | if (key_modifier & KEY_LCTRL) || (key_modifier & KEY_RCTRL) { |
151 | if (key_modifier & KEY_LCTRL) || (key_modifier & KEY_RCTRL) { |
152 | switch (key_scancode) |
152 | switch (key_scancode) |
153 | { |
153 | { |
154 | case 024: |
154 | case 024: |
155 | EventOpenFile(); |
155 | EventOpenFile(); |
156 | break; |
156 | break; |
157 | case SCAN_CODE_UP: |
157 | case SCAN_CODE_UP: |
158 | EventMagnifyPlus(); |
158 | EventMagnifyPlus(); |
159 | break; |
159 | break; |
160 | case SCAN_CODE_DOWN: |
160 | case SCAN_CODE_DOWN: |
161 | EventMagnifyMinus(); |
161 | EventMagnifyMinus(); |
162 | break; |
162 | break; |
163 | case 018: |
163 | case 018: |
164 | EventRunEdit(); |
164 | EventRunEdit(); |
165 | break; |
165 | break; |
166 | case SCAN_CODE_TAB: |
166 | case SCAN_CODE_TAB: |
167 | EventChangeEncoding(); |
167 | EventChangeEncoding(); |
168 | break; |
168 | break; |
169 | } |
169 | } |
170 | return; |
170 | return; |
171 | } |
171 | } |
172 | if (list.ProcessKey(key_scancode)) |
172 | if (list.ProcessKey(key_scancode)) |
173 | DrawPage(); |
173 | DrawPage(); |
174 | } |
174 | } |
175 | 175 | ||
176 | 176 | ||
177 | void HandleMouseEvent() |
177 | void HandleMouseEvent() |
178 | { |
178 | { |
179 | mouse.get(); |
179 | mouse.get(); |
180 | list.wheel_size = 7; |
180 | list.wheel_size = 7; |
181 | if (list.MouseScroll(mouse.vert)) { |
181 | if (list.MouseScroll(mouse.vert)) { |
182 | DrawPage(); |
182 | DrawPage(); |
183 | return; |
183 | return; |
184 | } |
184 | } |
185 | scrollbar_v_mouse (#scroll); |
185 | scrollbar_v_mouse (#scroll); |
186 | if (list.first != scroll.position) { |
186 | if (list.first != scroll.position) { |
187 | list.first = scroll.position; |
187 | list.first = scroll.position; |
188 | DrawPage(); |
188 | DrawPage(); |
189 | } |
189 | } |
190 | } |
190 | } |
191 | 191 | ||
192 | 192 | ||
193 | /* ----------------------------------------------------- */ |
193 | /* ----------------------------------------------------- */ |
194 | 194 | ||
195 | void EventOpenFile() |
195 | void EventOpenFile() |
196 | { |
196 | { |
197 | OpenDialog_start stdcall (#o_dialog); |
197 | OpenDialog_start stdcall (#o_dialog); |
198 | OpenFile(#openfile_path); |
198 | OpenFile(#openfile_path); |
199 | PreparePage(); |
199 | PreparePage(); |
200 | } |
200 | } |
201 | 201 | ||
202 | void EventMagnifyPlus() |
202 | void EventMagnifyPlus() |
203 | { |
203 | { |
204 | label.size.pt++; |
204 | label.size.pt++; |
205 | if(!label.changeSIZE()) |
205 | if(!label.changeSIZE()) |
206 | label.size.pt--; |
206 | label.size.pt--; |
207 | else |
207 | else |
208 | PreparePage(); |
208 | PreparePage(); |
209 | } |
209 | } |
210 | 210 | ||
211 | void EventMagnifyMinus() |
211 | void EventMagnifyMinus() |
212 | { |
212 | { |
213 | label.size.pt--; |
213 | label.size.pt--; |
214 | if(!label.changeSIZE()) |
214 | if(!label.changeSIZE()) |
215 | label.size.pt++; |
215 | label.size.pt++; |
216 | else |
216 | else |
217 | PreparePage(); |
217 | PreparePage(); |
218 | } |
218 | } |
219 | 219 | ||
220 | void EventRunEdit() |
220 | void EventRunEdit() |
221 | { |
221 | { |
222 | io.run(DEFAULT_EDITOR, #param); |
222 | io.run(DEFAULT_EDITOR, #param); |
223 | } |
223 | } |
224 | 224 | ||
225 | void EventChangeEncoding() |
225 | void EventChangeEncoding() |
226 | { |
226 | { |
227 | CreateThread(#menu_rmb,#stak+4092); |
227 | CreateThread(#menu_rmb,#stak+4092); |
228 | } |
228 | } |
229 | 229 | ||
230 | void EventShowInfo() { |
230 | void EventShowInfo() { |
231 | help_opened = true; |
231 | help_opened = true; |
232 | DrawBar(list.x, list.y, list.w, list.h, 0xFFFfff); |
232 | DrawBar(list.x, list.y, list.w, list.h, 0xFFFfff); |
233 | WriteText(list.x + 10, list.y + 10, 10000001b, 0x555555, VERSION); |
233 | WriteText(list.x + 10, list.y + 10, 10000001b, 0x555555, VERSION); |
234 | WriteTextLines(list.x + 10, list.y+40, 10110000b, 0, ABOUT, 20); |
234 | WriteTextLines(list.x + 10, list.y+40, 10110000b, 0, ABOUT, 20); |
235 | } |
235 | } |
236 | 236 | ||
237 | /* ------------------------------------------- */ |
237 | /* ------------------------------------------- */ |
238 | 238 | ||
239 | 239 | ||
240 | void OpenFile(dword f_path) |
240 | void OpenFile(dword f_path) |
241 | { |
241 | { |
242 | int tmp; |
242 | int tmp; |
243 | if (ESBYTE[f_path]) { |
243 | if (ESBYTE[f_path]) { |
244 | strcpy(#param, f_path); |
244 | strcpy(#param, f_path); |
245 | io.read(#param); |
245 | io.read(#param); |
246 | strcpy(#title, #param); |
246 | strcpy(#title, #param); |
247 | strcat(#title, " - Text Reader"); |
247 | strcat(#title, " - Text Reader"); |
248 | } |
248 | } |
249 | else { |
249 | else { |
250 | if (list.count) return; |
250 | if (list.count) return; |
251 | io.buffer_data = INTRO_TEXT; |
251 | io.buffer_data = INTRO_TEXT; |
252 | strcpy(#title, "Text Reader"); |
252 | strcpy(#title, "Text Reader"); |
253 | } |
253 | } |
254 | if (encoding!=CH_CP866) ChangeCharset(charsets[encoding], "CP866", io.buffer_data); |
254 | if (encoding!=CH_CP866) ChangeCharset(charsets[encoding], "CP866", io.buffer_data); |
255 | list.KeyHome(); |
255 | list.KeyHome(); |
256 | list.ClearList(); |
256 | list.ClearList(); |
257 | } |
257 | } |
258 | 258 | ||
259 | void draw_window() |
259 | void draw_window() |
260 | { |
260 | { |
261 | DefineAndDrawWindow(Form.left,Form.top,Form.width,Form.height,0x73,0,#title); |
261 | DefineAndDrawWindow(Form.left,Form.top,Form.width,Form.height,0x73,0,#title); |
262 | GetProcessInfo(#Form, SelfInfo); |
262 | GetProcessInfo(#Form, SelfInfo); |
263 | if (Form.status_window>2) return; |
263 | if (Form.status_window>2) return; |
264 | 264 | ||
265 | if (Form.width < 200) { MoveSize(OLD,OLD,200,OLD); return; } |
265 | if (Form.width < 200) { MoveSize(OLD,OLD,200,OLD); return; } |
266 | if (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); return; } |
266 | if (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); return; } |
267 | 267 | ||
268 | DrawBar(0, 0, Form.cwidth, TOOLBAR_H - 1, 0xe1e1e1); |
268 | DrawBar(0, 0, Form.cwidth, TOOLBAR_H - 1, 0xe1e1e1); |
269 | DrawBar(0, TOOLBAR_H - 1, Form.cwidth, 1, 0x7F7F7F); |
269 | DrawBar(0, TOOLBAR_H - 1, Form.cwidth, 1, 0x7F7F7F); |
270 | 270 | ||
271 | DrawToolbarButton(OPEN_FILE, 8); |
271 | DrawToolbarButton(OPEN_FILE, 8); |
272 | DrawToolbarButton(MAGNIFY_PLUS, 42); |
272 | DrawToolbarButton(MAGNIFY_PLUS, 42); |
273 | DrawToolbarButton(MAGNIFY_MINUS, 67); |
273 | DrawToolbarButton(MAGNIFY_MINUS, 67); |
274 | DrawToolbarButton(CHANGE_ENCODING, 101); |
274 | DrawToolbarButton(CHANGE_ENCODING, 101); |
275 | DrawToolbarButton(RUN_EDIT, 135); |
275 | DrawToolbarButton(RUN_EDIT, 135); |
276 | DrawToolbarButton(SHOW_INFO, Form.cwidth - 34); |
276 | DrawToolbarButton(SHOW_INFO, Form.cwidth - 34); |
277 | 277 | ||
278 | if ((Form.cwidth-scroll.size_x-1 == list.w) && |
278 | if ((Form.cwidth-scroll.size_x-1 == list.w) && |
279 | (Form.cheight-TOOLBAR_H == list.h) && |
279 | (Form.cheight-TOOLBAR_H == list.h) && |
280 | (list.count) |
280 | (list.count) |
281 | ) |
281 | ) |
282 | { |
282 | { |
283 | DrawPage(); |
283 | DrawPage(); |
284 | } else { |
284 | } else { |
285 | PreparePage(); |
285 | PreparePage(); |
286 | } |
286 | } |
287 | DrawRectangle(scroll.start_x, scroll.start_y, scroll.size_x, scroll.size_y-1, scroll.bckg_col); |
287 | DrawRectangle(scroll.start_x, scroll.start_y, scroll.size_x, scroll.size_y-1, scroll.bckg_col); |
288 | } |
288 | } |
289 | 289 | ||
290 | void DrawPage() |
290 | void DrawPage() |
291 | { |
291 | { |
292 | _PutImage(list.x,list.y,list.w,list.h,list.first*list.item_h*list.w*3 + label.raw); |
292 | _PutImage(list.x,list.y,list.w,list.h,list.first*list.item_h*list.w*3 + label.raw); |
293 | DrawScroller(); |
293 | DrawScroller(); |
294 | }>> |
294 | }>> |