Rev 5962 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5962 | Rev 5980 | ||
---|---|---|---|
Line 13... | Line 13... | ||
13 | 13 | ||
14 | #define TOOLBAR_H 34 |
14 | #define TOOLBAR_H 34 |
15 | #define TOOLBAR_ICON_WIDTH 26 |
15 | #define TOOLBAR_ICON_WIDTH 26 |
Line 16... | Line -... | ||
16 | #define TOOLBAR_ICON_HEIGHT 24 |
- | |
17 | - | ||
18 | #define TOOLBAR_OPEN_FILE_LEFT 8 |
- | |
19 | #define TOOLBAR_MAGNIFY_PLUS_LEFT 42 |
- | |
20 | #define TOOLBAR_MAGNIFY_MINUS_LEFT 67 |
- | |
21 | #define TOOLBAR_CHANGE_ENCODING_LEFT 101 |
- | |
22 | #define TOOLBAR_RUN_EDIT_LEFT 135 |
16 | #define TOOLBAR_ICON_HEIGHT 24 |
23 | 17 | ||
Line 24... | Line 18... | ||
24 | #define DEFAULT_FONT "/sys/fonts/Tahoma.kf" |
18 | #define DEFAULT_FONT "/sys/fonts/Tahoma.kf" |
25 | #define DEFAULT_EDITOR "/sys/tinypad" |
19 | #define DEFAULT_EDITOR "/sys/tinypad" |
26 | 20 | ||
27 | #define INTRO_TEXT "This is a plain text reader.\nTry to open some text file." |
21 | #define INTRO_TEXT "This is a plain Text Reader.\nTry to open some text file." |
Line 28... | Line 22... | ||
28 | #define VERSION "Text Reader v1.02" |
22 | #define VERSION "Text Reader v1.03" |
29 | #define ABOUT "Idea: Leency, punk_joker |
23 | #define ABOUT "Idea: Leency, punk_joker |
Line 47... | Line 41... | ||
47 | proc_info Form; |
41 | proc_info Form; |
48 | char title[4196]; |
42 | char title[4196]; |
Line 49... | Line 43... | ||
49 | 43 | ||
Line 50... | Line -... | ||
50 | byte help_opened = false; |
- | |
51 | - | ||
52 | char char_width[255]; |
- | |
53 | dword line_offset; |
- | |
54 | #define DWORD 4; |
44 | byte help_opened = false; |
55 | 45 | ||
56 | enum { |
46 | enum { |
57 | OPEN_FILE, |
47 | OPEN_FILE, |
58 | MAGNIFY_MINUS, |
48 | MAGNIFY_MINUS, |
Line 62... | Line 52... | ||
62 | SHOW_INFO, |
52 | SHOW_INFO, |
63 | }; |
53 | }; |
Line 64... | Line 54... | ||
64 | 54 | ||
65 | #include "ini.h" |
55 | #include "ini.h" |
- | 56 | #include "menu.h" |
|
- | 57 | #include "gui.h" |
|
- | 58 | #include "prepare_page.h" |
|
Line 66... | Line 59... | ||
66 | #include "menu.h" |
59 | |
67 | 60 | ||
68 | void InitDlls() |
61 | void InitDlls() |
69 | { |
62 | { |
Line 73... | Line 66... | ||
73 | load_dll(libini, #lib_init, 1); |
66 | load_dll(libini, #lib_init, 1); |
74 | load_dll(iconv_lib, #iconv_open, 0); |
67 | load_dll(iconv_lib, #iconv_open, 0); |
75 | load_dll(Proc_lib, #OpenDialog_init,0); |
68 | load_dll(Proc_lib, #OpenDialog_init,0); |
76 | } |
69 | } |
Line 77... | Line -... | ||
77 | - | ||
78 | void EventShowInfo() |
- | |
79 | { |
- | |
80 | ShowAbout(); |
- | |
Line 81... | Line 70... | ||
81 | } |
70 | |
82 | 71 | ||
83 | void EventOpenFile() |
- | |
84 | { |
- | |
85 | OpenDialog_start stdcall (#o_dialog); |
72 | void main() |
86 | OpenFile(#openfile_path); |
- | |
Line 87... | Line 73... | ||
87 | PreparePage(); |
73 | { |
88 | } |
74 | InitDlls(); |
89 | 75 | ||
90 | void EventMagnifyPlus() |
76 | OpenDialog_init stdcall (#o_dialog); |
- | 77 | ||
- | 78 | font.no_bg_copy = true; |
|
91 | { |
79 | font.color = 0; |
92 | font.size.text++; |
80 | font.bg_color = 0xFFFFFF; |
- | 81 | ||
- | 82 | font.load(DEFAULT_FONT); |
|
93 | if(!font.changeSIZE()) |
83 | |
94 | font.size.text--; |
84 | if (!font.data) { |
Line -... | Line 85... | ||
- | 85 | io.run("/sys/@notify","'Error: Font is not loaded.' -E"); |
|
- | 86 | ExitProcess(); |
|
95 | else |
87 | } |
- | 88 | ||
- | 89 | Libimg_LoadImage(#skin, abspath("toolbar.png")); |
|
- | 90 | ||
- | 91 | LoadIniSettings(); |
|
- | 92 | ||
96 | PreparePage(); |
93 | OpenFile(#param); |
97 | } |
94 | list.no_selection = true; |
- | 95 | SetEventMask(10000000000000000000000001100111b); |
|
- | 96 | loop() |
|
98 | 97 | { |
|
- | 98 | switch(WaitEvent()) |
|
- | 99 | { |
|
99 | void EventMagnifyMinus() |
100 | case evMouse: |
- | 101 | HandleMouseEvent(); |
|
- | 102 | break; |
|
- | 103 | case evKey: |
|
100 | { |
104 | HandleKeyEvent(); |
- | 105 | break; |
|
- | 106 | case evButton: |
|
- | 107 | HandleButtonEvent(); |
|
101 | font.size.text--; |
108 | break; |
- | 109 | case evReDraw: |
|
- | 110 | if (action_buf) { |
|
- | 111 | OpenFile(#param); |
|
102 | if(!font.changeSIZE()) |
112 | PreparePage(); |
103 | font.size.text++; |
- | |
104 | else |
- | |
105 | PreparePage(); |
- | |
106 | } |
- | |
107 | 113 | action_buf = false; |
|
108 | void EventRunEdit() |
- | |
109 | { |
- | |
110 | io.run(DEFAULT_EDITOR, #param); |
- | |
111 | } |
- | |
112 | 114 | }; |
|
Line -... | Line 115... | ||
- | 115 | draw_window(); |
|
113 | void EventChangeEncoding() |
116 | } |
114 | { |
117 | } |
115 | CreateThread(#menu_rmb,#stak+4092); |
118 | } |
116 | } |
119 | |
117 | 120 | ||
118 | void HandleMouseEvent() |
121 | void HandleButtonEvent() |
119 | { |
122 | { |
120 | mouse.get(); |
123 | |
- | 124 | byte btn = GetButtonID(); |
|
- | 125 | if (btn==1) { |
|
- | 126 | SaveIniSettings(); |
|
- | 127 | ExitProcess(); |
|
- | 128 | } |
|
- | 129 | btn-=10; |
|
- | 130 | switch(btn) |
|
121 | list.wheel_size = 7; |
131 | { |
- | 132 | case OPEN_FILE: |
|
- | 133 | EventOpenFile(); |
|
122 | if (list.MouseScroll(mouse.vert)) { |
134 | break; |
- | 135 | case MAGNIFY_PLUS: |
|
- | 136 | EventMagnifyPlus(); |
|
123 | DrawPage(); |
137 | break; |
- | 138 | case MAGNIFY_MINUS: |
|
- | 139 | EventMagnifyMinus(); |
|
- | 140 | break; |
|
- | 141 | case CHANGE_ENCODING: |
|
- | 142 | EventChangeEncoding(); |
|
- | 143 | break; |
|
124 | return; |
144 | case RUN_EDIT: |
125 | } |
145 | EventRunEdit(); |
126 | scrollbar_v_mouse (#scroll); |
146 | break; |
Line -... | Line 147... | ||
- | 147 | case SHOW_INFO: |
|
127 | if (list.first != scroll.position) { |
148 | EventShowInfo(); |
128 | list.first = scroll.position; |
149 | break; |
129 | DrawPage(); |
150 | } |
130 | } |
151 | } |
131 | } |
152 | |
Line 165... | Line 186... | ||
165 | } |
186 | } |
166 | if (list.ProcessKey(key_scancode)) |
187 | if (list.ProcessKey(key_scancode)) |
167 | DrawPage(); |
188 | DrawPage(); |
168 | } |
189 | } |
Line 169... | Line -... | ||
169 | - | ||
170 | void HandleButtonEvent() |
- | |
Line 171... | Line 190... | ||
171 | { |
190 | |
172 | - | ||
173 | byte btn = GetButtonID(); |
- | |
174 | if (btn==1) { |
- | |
175 | SaveIniSettings(); |
- | |
176 | ExitProcess(); |
- | |
177 | } |
- | |
178 | btn-=10; |
191 | |
179 | switch(btn) |
192 | void HandleMouseEvent() |
180 | { |
193 | { |
181 | case OPEN_FILE: |
- | |
182 | EventOpenFile(); |
- | |
183 | break; |
194 | mouse.get(); |
184 | case MAGNIFY_PLUS: |
195 | list.wheel_size = 7; |
185 | EventMagnifyPlus(); |
- | |
186 | break; |
- | |
187 | case MAGNIFY_MINUS: |
196 | if (list.MouseScroll(mouse.vert)) { |
188 | EventMagnifyMinus(); |
- | |
189 | break; |
- | |
190 | case CHANGE_ENCODING: |
197 | DrawPage(); |
191 | EventChangeEncoding(); |
198 | return; |
192 | break; |
199 | } |
193 | case RUN_EDIT: |
- | |
194 | EventRunEdit(); |
- | |
195 | break; |
200 | scrollbar_v_mouse (#scroll); |
196 | case SHOW_INFO: |
201 | if (list.first != scroll.position) { |
197 | EventShowInfo(); |
202 | list.first = scroll.position; |
198 | break; |
203 | DrawPage(); |
Line -... | Line 204... | ||
- | 204 | } |
|
- | 205 | } |
|
- | 206 | ||
199 | } |
207 | |
200 | } |
208 | /* ----------------------------------------------------- */ |
- | 209 | ||
- | 210 | void EventOpenFile() |
|
201 | 211 | { |
|
- | 212 | OpenDialog_start stdcall (#o_dialog); |
|
Line -... | Line 213... | ||
- | 213 | OpenFile(#openfile_path); |
|
- | 214 | PreparePage(); |
|
- | 215 | } |
|
202 | void main() |
216 | |
- | 217 | void EventMagnifyPlus() |
|
- | 218 | { |
|
- | 219 | font.size.text++; |
|
- | 220 | if(!font.changeSIZE()) |
|
Line -... | Line 221... | ||
- | 221 | font.size.text--; |
|
- | 222 | else |
|
203 | { |
223 | PreparePage(); |
204 | InitDlls(); |
224 | } |
205 | 225 | ||
- | 226 | void EventMagnifyMinus() |
|
- | 227 | { |
|
- | 228 | font.size.text--; |
|
Line -... | Line 229... | ||
- | 229 | if(!font.changeSIZE()) |
|
- | 230 | font.size.text++; |
|
206 | OpenDialog_init stdcall (#o_dialog); |
231 | else |
- | 232 | PreparePage(); |
|
Line 207... | Line 233... | ||
207 | 233 | } |
|
- | 234 | ||
208 | font.no_bg_copy = true; |
235 | void EventRunEdit() |
209 | font.color = 0; |
- | |
210 | font.bg_color = 0xFFFFFF; |
236 | { |
Line -... | Line 237... | ||
- | 237 | io.run(DEFAULT_EDITOR, #param); |
|
- | 238 | } |
|
211 | 239 | ||
- | 240 | void EventChangeEncoding() |
|
- | 241 | { |
|
- | 242 | CreateThread(#menu_rmb,#stak+4092); |
|
Line 212... | Line 243... | ||
212 | font.load(DEFAULT_FONT); |
243 | } |
Line 213... | Line -... | ||
213 | - | ||
214 | if (!font.data) { |
- | |
215 | io.run("/sys/@notify","'Error: Font is not loaded.' -E"); |
- | |
216 | ExitProcess(); |
- | |
217 | } |
244 | |
218 | 245 | void EventShowInfo() { |
|
219 | Libimg_LoadImage(#skin, abspath("toolbar.png")); |
246 | help_opened = true; |
220 | - | ||
221 | LoadIniSettings(); |
- | |
222 | 247 | DrawBar(list.x, list.y, list.w, list.h, 0xFFFfff); |
|
223 | OpenFile(#param); |
- | |
224 | list.no_selection = true; |
248 | WriteText(list.x + 10, list.y + 10, 10000001b, 0x555555, VERSION); |
225 | SetEventMask(10000000000000000000000001100111b); |
- | |
226 | loop() |
- | |
227 | { |
249 | WriteTextLines(list.x + 10, list.y+40, 10110000b, 0, ABOUT, 20); |
228 | switch(WaitEvent()) |
- | |
229 | { |
250 | } |
230 | case evMouse: |
- | |
231 | HandleMouseEvent(); |
251 | |
232 | break; |
- | |
233 | case evKey: |
252 | /* ------------------------------------------- */ |
234 | HandleKeyEvent(); |
- | |
235 | break; |
- | |
236 | case evButton: |
253 | |
- | 254 | ||
- | 255 | void OpenFile(dword f_path) |
|
- | 256 | { |
|
- | 257 | int tmp; |
|
237 | HandleButtonEvent(); |
258 | if (ESBYTE[f_path]) { |
- | 259 | strcpy(#param, f_path); |
|
- | 260 | io.read(#param); |
|
- | 261 | strcpy(#title, #param); |
|
238 | break; |
262 | strcat(#title, " - Text Reader"); |
Line 239... | Line 263... | ||
239 | case evReDraw: |
263 | } |
240 | if (action_buf) { |
264 | else { |
241 | OpenFile(#param); |
265 | if (list.count) return; |
Line 257... | Line 281... | ||
257 | if (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); return; } |
281 | if (Form.height < 200) { MoveSize(OLD,OLD,OLD,200); return; } |
Line 258... | Line 282... | ||
258 | 282 | ||
259 | DrawBar(0, 0, Form.cwidth, TOOLBAR_H - 1, 0xe1e1e1); |
283 | DrawBar(0, 0, Form.cwidth, TOOLBAR_H - 1, 0xe1e1e1); |
Line 260... | Line 284... | ||
260 | DrawBar(0, TOOLBAR_H - 1, Form.cwidth, 1, 0x7F7F7F); |
284 | DrawBar(0, TOOLBAR_H - 1, Form.cwidth, 1, 0x7F7F7F); |
261 | 285 | ||
262 | DrawToolbarButton(OPEN_FILE, TOOLBAR_OPEN_FILE_LEFT); |
286 | DrawToolbarButton(OPEN_FILE, 8); |
263 | DrawToolbarButton(MAGNIFY_PLUS, TOOLBAR_MAGNIFY_PLUS_LEFT); |
287 | DrawToolbarButton(MAGNIFY_PLUS, 42); |
264 | DrawToolbarButton(MAGNIFY_MINUS, TOOLBAR_MAGNIFY_MINUS_LEFT); |
288 | DrawToolbarButton(MAGNIFY_MINUS, 67); |
265 | DrawToolbarButton(CHANGE_ENCODING, TOOLBAR_CHANGE_ENCODING_LEFT); |
289 | DrawToolbarButton(CHANGE_ENCODING, 101); |
Line 266... | Line 290... | ||
266 | DrawToolbarButton(RUN_EDIT, TOOLBAR_RUN_EDIT_LEFT); |
290 | DrawToolbarButton(RUN_EDIT, 135); |
267 | DrawToolbarButton(SHOW_INFO, Form.cwidth - 34); |
291 | DrawToolbarButton(SHOW_INFO, Form.cwidth - 34); |
268 | 292 | ||
Line 281... | Line 305... | ||
281 | void DrawPage() |
305 | void DrawPage() |
282 | { |
306 | { |
283 | _PutImage(list.x,list.y,list.w,list.h,list.first*list.item_h*list.w*3 + font.buffer); |
307 | _PutImage(list.x,list.y,list.w,list.h,list.first*list.item_h*list.w*3 + font.buffer); |
284 | DrawScroller(); |
308 | DrawScroller(); |
285 | } |
309 | }>> |
286 | - | ||
287 | void PreparePage() |
- | |
288 | { |
- | |
289 | char line[4096]=0; |
- | |
290 | dword line_start; |
- | |
291 | byte ch; |
- | |
292 | dword bufoff; |
- | |
293 | dword line_length=30; |
- | |
294 | dword stroka_y = 5; |
- | |
295 | dword stroka=0; |
- | |
296 | int i, srch_pos; |
- | |
297 | - | ||
298 | font.changeSIZE(); |
- | |
299 | list.w = Form.cwidth-scroll.size_x-1; |
- | |
300 | //get font chars width, need to increase performance |
- | |
301 | for (i=0; i<256; i++) char_width[i] = font.symbol_size(i); |
- | |
302 | //get font buffer height |
- | |
303 | for (bufoff=io.buffer_data; ESBYTE[bufoff]; bufoff++) |
- | |
304 | { |
- | |
305 | ch = ESBYTE[bufoff]; |
- | |
306 | line_length += char_width[ch]; |
- | |
307 | if (line_length>=list.w) || (ch==10) { |
- | |
308 | srch_pos = bufoff; |
- | |
309 | loop() |
- | |
310 | { |
- | |
311 | if (__isWhite(ESBYTE[srch_pos])) { bufoff=srch_pos+1; break; } //normal word-break |
- | |
312 | if (srch_pos == line_start) break; //no white space found in whole line |
- | |
313 | srch_pos--; |
- | |
314 | } |
- | |
315 | line_start = bufoff; |
- | |
316 | line_length = 30; |
- | |
317 | stroka++; |
- | |
318 | } |
- | |
319 | } |
- | |
320 | //draw text in buffer |
- | |
321 | list.count = stroka+2; |
- | |
322 | list.SetSizes(0, TOOLBAR_H, list.w, Form.cheight-TOOLBAR_H, font.size.text+1); |
- | |
323 | if (list.count < list.visible) list.count = list.visible; |
- | |
324 | - | ||
325 | font.size.height = list.count+1*list.item_h; |
- | |
326 | font.buffer_size = 0; |
- | |
327 | - | ||
328 | line_length = 30; |
- | |
329 | line_start = io.buffer_data; |
- | |
330 | for (bufoff=io.buffer_data; ESBYTE[bufoff]; bufoff++) |
- | |
331 | { |
- | |
332 | ch = ESBYTE[bufoff]; |
- | |
333 | line_length += char_width[ch]; |
- | |
334 | if (line_length>=list.w) || (ch==10) |
- | |
335 | { |
- | |
336 | //set word break |
- | |
337 | srch_pos = bufoff; |
- | |
338 | loop() |
- | |
339 | { |
- | |
340 | if (__isWhite(ESBYTE[srch_pos])) { bufoff=srch_pos+1; break; } //normal word-break |
- | |
341 | if (srch_pos == line_start) break; //no white space found in whole line |
- | |
342 | srch_pos--; |
- | |
343 | } |
- | |
344 | i = bufoff-line_start; |
- | |
345 | strlcpy(#line, line_start, i); |
- | |
346 | font.prepare_buf(8,stroka_y,list.w,font.size.height, #line); |
- | |
347 | stroka_y += list.item_h; |
- | |
348 | line_start = bufoff; |
- | |
349 | line_length = 30; |
- | |
350 | } |
- | |
351 | } |
- | |
352 | font.prepare_buf(8,stroka_y,list.w,font.size.height, line_start); |
- | |
353 | SmoothFont(font.buffer, font.size.width, font.size.height); |
- | |
354 | DrawPage(); |
- | |
355 | } |
- | |
356 | - | ||
357 | void DrawToolbarButton(char image_id, int x) |
- | |
358 | { |
- | |
359 | DefineButton(x, 5, TOOLBAR_ICON_WIDTH-1, TOOLBAR_ICON_HEIGHT-1, 10+image_id + BT_HIDE, 0); |
- | |
360 | img_draw stdcall(skin.image, x, 5, TOOLBAR_ICON_WIDTH, TOOLBAR_ICON_HEIGHT, 0, image_id*TOOLBAR_ICON_HEIGHT); |
- | |
361 | } |
- | |
362 | - | ||
363 | void DrawScroller() |
- | |
364 | { |
- | |
365 | scroll.max_area = list.count; |
- | |
366 | scroll.cur_area = list.visible; |
- | |
367 | scroll.position = list.first; |
- | |
368 | scroll.all_redraw = 0; |
- | |
369 | scroll.start_x = list.x + list.w; |
- | |
370 | scroll.start_y = list.y; |
- | |
371 | scroll.size_y = list.h; |
- | |
372 | scroll.start_x = list.x + list.w; |
- | |
373 | scrollbar_v_draw(#scroll); |
- | |
374 | } |
- | |
375 | - | ||
376 | void OpenFile(dword f_path) |
- | |
377 | { |
- | |
378 | int tmp; |
- | |
379 | if (ESBYTE[f_path]) { |
- | |
380 | strcpy(#param, f_path); |
- | |
381 | io.read(#param); |
- | |
382 | strcpy(#title, #param); |
- | |
383 | strcat(#title, " - Text Reader"); |
- | |
384 | } |
- | |
385 | else { |
- | |
386 | if (list.count) return; |
- | |
387 | io.buffer_data = INTRO_TEXT; |
- | |
388 | strcpy(#title, "Text Reader"); |
- | |
389 | } |
- | |
390 | if (encoding!=CH_CP866) ChangeCharset(charsets[encoding], "CP866", io.buffer_data); |
- | |
391 | list.KeyHome(); |
- | |
392 | list.ClearList(); |
- | |
393 | } |
- | |
394 | - | ||
395 | ShowAbout() { |
- | |
396 | help_opened = true; |
- | |
397 | DrawBar(list.x, list.y, list.w, list.h, 0xFFFfff); |
- | |
398 | WriteText(list.x + 10, list.y + 10, 10000001b, 0x555555, VERSION); |
- | |
399 | WriteTextLines(list.x + 10, list.y+40, 10110000b, 0, ABOUT, 20); |
- | |
400 | }>256;>>> |
- |