Rev 8020 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 8020 | Rev 8392 | ||
---|---|---|---|
1 | //Calypte 0.35 - Leency |
1 | //Calypte 0.35 - Leency |
2 | //Calypte 0.15 - Punk Joker |
2 | //Calypte 0.15 - Punk Joker |
3 | 3 | ||
4 | /* |
4 | /* |
5 | TODO |
5 | TODO |
6 | - word wrap |
6 | - word wrap |
7 | - draw by line |
7 | - draw by line |
8 | - text selection |
8 | - text selection |
9 | */ |
9 | */ |
10 | 10 | ||
11 | #define MEMSIZE 1024*200 |
11 | #define MEMSIZE 1024*200 |
12 | 12 | ||
13 | #ifndef AUTOBUILD |
13 | #ifndef AUTOBUILD |
14 | #include "lang.h--" |
14 | #include "lang.h--" |
15 | #endif |
15 | #endif |
16 | 16 | ||
17 | //===================================================// |
17 | //===================================================// |
18 | // // |
18 | // // |
19 | // LIB // |
19 | // LIB // |
20 | // // |
20 | // // |
21 | //===================================================// |
21 | //===================================================// |
22 | 22 | ||
23 | #include "../lib/kolibri.h" |
23 | #include "../lib/kolibri.h" |
24 | #include "../lib/fs.h" |
24 | #include "../lib/fs.h" |
25 | #include "../lib/gui.h" |
25 | #include "../lib/gui.h" |
26 | #include "../lib/list_box.h" |
26 | #include "../lib/list_box.h" |
27 | #include "../lib/collection.h" |
27 | #include "../lib/collection.h" |
28 | 28 | ||
29 | #include "../lib/obj/iconv.h" |
29 | #include "../lib/obj/iconv.h" |
30 | #include "../lib/obj/box_lib.h" |
30 | #include "../lib/obj/box_lib.h" |
31 | #include "../lib/obj/libio.h" |
- | |
32 | #include "../lib/obj/proc_lib.h" |
31 | #include "../lib/obj/proc_lib.h" |
33 | #include "../lib/obj/librasterworks.h" |
32 | #include "../lib/obj/librasterworks.h" |
34 | 33 | ||
35 | #include "../lib/patterns/simple_open_dialog.h" |
34 | #include "../lib/patterns/simple_open_dialog.h" |
36 | 35 | ||
37 | //===================================================// |
36 | //===================================================// |
38 | // // |
37 | // // |
39 | // DATA // |
38 | // DATA // |
40 | // // |
39 | // // |
41 | //===================================================// |
40 | //===================================================// |
42 | 41 | ||
43 | char default_dir[] = "/rd/1"; |
42 | char default_dir[] = "/rd/1"; |
44 | od_filter filter2 = { 8, "TXT\0\0" }; |
43 | od_filter filter2 = { 8, "TXT\0\0" }; |
45 | 44 | ||
46 | /*========= MENU ==========*/ |
45 | /*========= MENU ==========*/ |
47 | ?define MENU1 "File" |
46 | ?define MENU1 "File" |
48 | ?define MENU2 "Encoding" |
47 | ?define MENU2 "Encoding" |
49 | ?define MENU3 "Reopen" |
48 | ?define MENU3 "Reopen" |
50 | 49 | ||
51 | char menu_file_list[] = |
50 | char menu_file_list[] = |
52 | "Open|Ctrl+O |
51 | "Open|Ctrl+O |
53 | Close |
52 | Close |
54 | Properties |
53 | Properties |
55 | Exit"; |
54 | Exit"; |
56 | 55 | ||
57 | char menu_encoding_list[] = |
56 | char menu_encoding_list[] = |
58 | "UTF-8 |
57 | "UTF-8 |
59 | KOI8-RU |
58 | KOI8-RU |
60 | CP1251 |
59 | CP1251 |
61 | CP1252 |
60 | CP1252 |
62 | ISO8859-5 |
61 | ISO8859-5 |
63 | CP866"; |
62 | CP866"; |
64 | 63 | ||
65 | char menu_reopen_list[] = |
64 | char menu_reopen_list[] = |
66 | "Tinypad |
65 | "Tinypad |
67 | TextEdit |
66 | TextEdit |
68 | TextRead |
67 | TextRead |
69 | WebView |
68 | WebView |
70 | FB2Read |
69 | FB2Read |
71 | HexView"; |
70 | HexView"; |
72 | 71 | ||
73 | enum |
72 | enum |
74 | { |
73 | { |
75 | MENU_ID_FILE=10, |
74 | MENU_ID_FILE=10, |
76 | FILE_SUBMENU_ID_OPEN=10, |
75 | FILE_SUBMENU_ID_OPEN=10, |
77 | FILE_SUBMENU_ID_CLOSE, |
76 | FILE_SUBMENU_ID_CLOSE, |
78 | FILE_SUBMENU_ID_PROPERTIES, |
77 | FILE_SUBMENU_ID_PROPERTIES, |
79 | FILE_SUBMENU_ID_EXIT, |
78 | FILE_SUBMENU_ID_EXIT, |
80 | 79 | ||
81 | MENU_ID_ENCODING=20, |
80 | MENU_ID_ENCODING=20, |
82 | 81 | ||
83 | MENU_ID_REOPEN=30, |
82 | MENU_ID_REOPEN=30, |
84 | FILE_SUBMENU_ID_TINYPAD=30, |
83 | FILE_SUBMENU_ID_TINYPAD=30, |
85 | FILE_SUBMENU_ID_TEXTEDIT, |
84 | FILE_SUBMENU_ID_TEXTEDIT, |
86 | FILE_SUBMENU_ID_TEXTREAD, |
85 | FILE_SUBMENU_ID_TEXTREAD, |
87 | FILE_SUBMENU_ID_WEBVIEW, |
86 | FILE_SUBMENU_ID_WEBVIEW, |
88 | FILE_SUBMENU_ID_FB2READ, |
87 | FILE_SUBMENU_ID_FB2READ, |
89 | FILE_SUBMENU_ID_HEXVIEW |
88 | FILE_SUBMENU_ID_HEXVIEW |
90 | }; |
89 | }; |
91 | 90 | ||
92 | int menu_file_x = 6; |
91 | int menu_file_x = 6; |
93 | int menu_encoding_x = NULL; |
92 | int menu_encoding_x = NULL; |
94 | int menu_reopen_x = NULL; |
93 | int menu_reopen_x = NULL; |
95 | /*======== MENU END ==========*/ |
94 | /*======== MENU END ==========*/ |
96 | 95 | ||
97 | #define TITLE "Calypte v0.38 dev" |
96 | #define TITLE "Calypte v0.38 dev" |
98 | char win_title[4096] = TITLE; |
97 | char win_title[4096] = TITLE; |
99 | 98 | ||
100 | #define TOPPANELH 23 |
99 | #define TOPPANELH 23 |
101 | #define BOTPANELH 10 |
100 | #define BOTPANELH 10 |
102 | #define WIN_W 750 |
101 | #define WIN_W 750 |
103 | #define WIN_H 550 |
102 | #define WIN_H 550 |
104 | #define SCROLL_SIZE 15 |
103 | #define SCROLL_SIZE 15 |
105 | 104 | ||
106 | proc_info Form; |
105 | proc_info Form; |
107 | llist rows; |
106 | llist rows; |
108 | 107 | ||
109 | int encoding; |
108 | int encoding; |
110 | 109 | ||
111 | dword old_width,old_height; |
110 | dword old_width,old_height; |
112 | 111 | ||
113 | dword bufpointer; |
112 | dword bufpointer; |
114 | dword bufsize; |
113 | dword bufsize; |
115 | 114 | ||
116 | scroll_bar scroll_v = { SCROLL_SIZE,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}; |
115 | scroll_bar scroll_v = { SCROLL_SIZE,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}; |
117 | scroll_bar scroll_h = { SCROLL_SIZE,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}; |
116 | scroll_bar scroll_h = { SCROLL_SIZE,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}; |
118 | 117 | ||
119 | collection s=0; |
118 | collection s=0; |
120 | 119 | ||
121 | //===================================================// |
120 | //===================================================// |
122 | // // |
121 | // // |
123 | // CODE // |
122 | // CODE // |
124 | // // |
123 | // // |
125 | //===================================================// |
124 | //===================================================// |
126 | 125 | ||
127 | void main() |
126 | void main() |
128 | { |
127 | { |
129 | int id; |
128 | int id; |
130 | 129 | ||
131 | load_dll(boxlib, #box_lib_init, 0); |
130 | load_dll(boxlib, #box_lib_init, 0); |
132 | load_dll(libio, #libio_init, 1); |
- | |
133 | //load_dll(libini, #lib_init, 1); |
131 | //load_dll(libini, #lib_init, 1); |
134 | load_dll(iconv_lib, #iconv_open, 0); |
132 | load_dll(iconv_lib, #iconv_open, 0); |
135 | load_dll(Proc_lib, #OpenDialog_init,0); |
133 | load_dll(Proc_lib, #OpenDialog_init,0); |
136 | load_dll(librasterworks, #rasterworks_drawText,0); |
134 | load_dll(librasterworks, #rasterworks_drawText,0); |
137 | OpenDialog_init stdcall (#o_dialog); |
135 | OpenDialog_init stdcall (#o_dialog); |
138 | 136 | ||
139 | if (param) |
137 | if (param) |
140 | { |
138 | { |
141 | draw_window(); |
139 | draw_window(); |
142 | OpenFile(#param); |
140 | OpenFile(#param); |
143 | Prepare(); |
141 | Prepare(); |
144 | DrawText(); |
142 | DrawText(); |
145 | } |
143 | } |
146 | 144 | ||
147 | SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER); |
145 | SetEventMask(EVM_REDRAW+EVM_KEY+EVM_BUTTON+EVM_MOUSE+EVM_MOUSE_FILTER); |
148 | 146 | ||
149 | loop() |
147 | loop() |
150 | { |
148 | { |
151 | switch(WaitEvent()) |
149 | switch(WaitEvent()) |
152 | { |
150 | { |
153 | case evMouse: |
151 | case evMouse: |
154 | mouse.get(); |
152 | mouse.get(); |
155 | rows.wheel_size = 3; |
153 | rows.wheel_size = 3; |
156 | if (rows.MouseScroll(mouse.vert)) |
154 | if (rows.MouseScroll(mouse.vert)) |
157 | { |
155 | { |
158 | DrawText(); |
156 | DrawText(); |
159 | } |
157 | } |
160 | break; |
158 | break; |
161 | 159 | ||
162 | case evButton: |
160 | case evButton: |
163 | id=GetButtonID(); |
161 | id=GetButtonID(); |
164 | if (id==1) |
162 | if (id==1) |
165 | { |
163 | { |
166 | ExitProcess(); |
164 | ExitProcess(); |
167 | } |
165 | } |
168 | if (id==MENU_ID_FILE) |
166 | if (id==MENU_ID_FILE) |
169 | { |
167 | { |
170 | EventShowMenu(menu_file_x, #menu_file_list, MENU_ID_FILE, NULL); |
168 | EventShowMenu(menu_file_x, #menu_file_list, MENU_ID_FILE, NULL); |
171 | } |
169 | } |
172 | if (id==MENU_ID_ENCODING) |
170 | if (id==MENU_ID_ENCODING) |
173 | { |
171 | { |
174 | EventShowMenu(menu_encoding_x, #menu_encoding_list, MENU_ID_ENCODING, encoding+1); |
172 | EventShowMenu(menu_encoding_x, #menu_encoding_list, MENU_ID_ENCODING, encoding+1); |
175 | } |
173 | } |
176 | if (id==MENU_ID_REOPEN) |
174 | if (id==MENU_ID_REOPEN) |
177 | { |
175 | { |
178 | EventShowMenu(menu_reopen_x, #menu_reopen_list, MENU_ID_REOPEN, NULL); |
176 | EventShowMenu(menu_reopen_x, #menu_reopen_list, MENU_ID_REOPEN, NULL); |
179 | } |
177 | } |
180 | break; |
178 | break; |
181 | 179 | ||
182 | case evKey: |
180 | case evKey: |
183 | GetKeys(); |
181 | GetKeys(); |
184 | if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL) |
182 | if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL) |
185 | { |
183 | { |
186 | if (key_scancode == SCAN_CODE_KEY_O) |
184 | if (key_scancode == SCAN_CODE_KEY_O) |
187 | { |
185 | { |
188 | EventOpenFile(); |
186 | EventOpenFile(); |
189 | } |
187 | } |
190 | break; |
188 | break; |
191 | } |
189 | } |
192 | if (rows.ProcessKey(key_scancode)) |
190 | if (rows.ProcessKey(key_scancode)) |
193 | { |
191 | { |
194 | DrawText(); |
192 | DrawText(); |
195 | } |
193 | } |
196 | break; |
194 | break; |
197 | 195 | ||
198 | case evReDraw: |
196 | case evReDraw: |
199 | if (CheckActiveProcess(Form.ID)) EventMenuClick(); |
197 | if (CheckActiveProcess(Form.ID)) EventMenuClick(); |
200 | draw_window(); |
198 | draw_window(); |
201 | break; |
199 | break; |
202 | } |
200 | } |
203 | } |
201 | } |
204 | } |
202 | } |
205 | 203 | ||
206 | int DrawMenuButton(dword x,y,id,text) |
204 | int DrawMenuButton(dword x,y,id,text) |
207 | { |
205 | { |
208 | int textlen = strlen(text)*8; |
206 | int textlen = strlen(text)*8; |
209 | int padding = 12; |
207 | int padding = 12; |
210 | DefineHiddenButton(x, y, textlen+padding+padding, TOPPANELH-2, id); |
208 | DefineHiddenButton(x, y, textlen+padding+padding, TOPPANELH-2, id); |
211 | WriteText(x+padding,y+4, 0x90, MixColors(sc.work, sc.work_text, 70), text); |
209 | WriteText(x+padding,y+4, 0x90, MixColors(sc.work, sc.work_text, 70), text); |
212 | return textlen+padding+padding; |
210 | return textlen+padding+padding; |
213 | } |
211 | } |
214 | 212 | ||
215 | void draw_window() |
213 | void draw_window() |
216 | { |
214 | { |
217 | sc.get(); |
215 | sc.get(); |
218 | DefineAndDrawWindow(screen.width-WIN_W/2,screen.height-WIN_H/2,WIN_W,WIN_H,0x73,0xFFFFFF,#win_title,0); |
216 | DefineAndDrawWindow(screen.width-WIN_W/2,screen.height-WIN_H/2,WIN_W,WIN_H,0x73,0xFFFFFF,#win_title,0); |
219 | GetProcessInfo(#Form, SelfInfo); |
217 | GetProcessInfo(#Form, SelfInfo); |
220 | DrawBar(0, 0, Form.cwidth, TOPPANELH-1, sc.work); |
218 | DrawBar(0, 0, Form.cwidth, TOPPANELH-1, sc.work); |
221 | DrawBar(0, TOPPANELH-1, Form.cwidth, 1, sc.work_dark); |
219 | DrawBar(0, TOPPANELH-1, Form.cwidth, 1, sc.work_dark); |
222 | DrawBar(0, Form.cheight-BOTPANELH, Form.cwidth, BOTPANELH, sc.work); |
220 | DrawBar(0, Form.cheight-BOTPANELH, Form.cwidth, BOTPANELH, sc.work); |
223 | 221 | ||
224 | menu_encoding_x = menu_file_x + DrawMenuButton(menu_file_x, 0, MENU_ID_FILE, MENU1); |
222 | menu_encoding_x = menu_file_x + DrawMenuButton(menu_file_x, 0, MENU_ID_FILE, MENU1); |
225 | menu_reopen_x = menu_encoding_x + DrawMenuButton(menu_encoding_x, 0, MENU_ID_ENCODING, MENU2); |
223 | menu_reopen_x = menu_encoding_x + DrawMenuButton(menu_encoding_x, 0, MENU_ID_ENCODING, MENU2); |
226 | DrawMenuButton(menu_reopen_x, 0, MENU_ID_REOPEN, MENU3); |
224 | DrawMenuButton(menu_reopen_x, 0, MENU_ID_REOPEN, MENU3); |
227 | 225 | ||
228 | if (old_width!=Form.width) || (old_height!=Form.height) |
226 | if (old_width!=Form.width) || (old_height!=Form.height) |
229 | { |
227 | { |
230 | old_width = Form.width; |
228 | old_width = Form.width; |
231 | old_height = Form.height; |
229 | old_height = Form.height; |
232 | 230 | ||
233 | rows.no_selection = true; |
231 | rows.no_selection = true; |
234 | rows.SetFont(8, 14, 0x90); |
232 | rows.SetFont(8, 14, 0x90); |
235 | rows.SetSizes(0, TOPPANELH, Form.cwidth - SCROLL_SIZE, Form.cheight - TOPPANELH - BOTPANELH, 20); |
233 | rows.SetSizes(0, TOPPANELH, Form.cwidth - SCROLL_SIZE, Form.cheight - TOPPANELH - BOTPANELH, 20); |
236 | rows.column_max = rows.w / rows.font_w; |
234 | rows.column_max = rows.w / rows.font_w; |
237 | 235 | ||
238 | if (bufpointer) |
236 | if (bufpointer) |
239 | { |
237 | { |
240 | Prepare(); |
238 | Prepare(); |
241 | } |
239 | } |
242 | rows.CheckDoesValuesOkey(); |
240 | rows.CheckDoesValuesOkey(); |
243 | } |
241 | } |
244 | DrawRectangle(rows.x+rows.w-1, rows.y, SCROLL_SIZE, rows.h-1, 0xEEEeee); |
242 | DrawRectangle(rows.x+rows.w-1, rows.y, SCROLL_SIZE, rows.h-1, 0xEEEeee); |
245 | DrawText(); |
243 | DrawText(); |
246 | } |
244 | } |
247 | 245 | ||
248 | void OpenFile(dword _path) |
246 | void OpenFile(dword _path) |
249 | { |
247 | { |
250 | strcpy(#param, _path); |
248 | strcpy(#param, _path); |
251 | sprintf(#win_title, "%s - %s", TITLE, #param); |
249 | sprintf(#win_title, "%s - %s", TITLE, #param); |
252 | rows.KeyHome(); |
250 | rows.KeyHome(); |
253 | file_size stdcall (#param); |
251 | read_file(#param, #bufpointer, #bufsize); |
254 | bufsize = EBX; |
- | |
255 | if (bufsize) |
252 | if (!EAX) |
256 | { |
- | |
257 | bufpointer = mem_Free(bufpointer); |
- | |
258 | bufpointer = mem_Alloc(bufsize); |
- | |
259 | if (ReadFile(0, bufsize, bufpointer, #param) != 0) |
- | |
260 | { |
253 | { |
261 | bufpointer = 0; |
254 | bufpointer = 0; |
262 | notify("'Error opening file'-E"); |
255 | notify("'Error opening file'-E"); |
263 | return; |
256 | return; |
264 | } |
257 | } |
265 | } |
- | |
266 | if (encoding!=CH_CP866) |
258 | if (encoding!=CH_CP866) |
267 | { |
259 | { |
268 | ChangeCharset(encoding, "CP866", bufpointer); |
260 | ChangeCharset(encoding, "CP866", bufpointer); |
269 | } |
261 | } |
270 | } |
262 | } |
271 | 263 | ||
272 | enum |
264 | enum |
273 | { |
265 | { |
274 | PARSE_CALCULATE_ROWS_COUNT, |
266 | PARSE_CALCULATE_ROWS_COUNT, |
275 | PARSE_DRAW_PREPARE, |
267 | PARSE_DRAW_PREPARE, |
276 | }; |
268 | }; |
277 | 269 | ||
278 | void Parse(int mode) |
270 | void Parse(int mode) |
279 | { |
271 | { |
280 | int pos=0; |
272 | int pos=0; |
281 | int sub_pos=0; |
273 | int sub_pos=0; |
282 | int len_str = 0; |
274 | int len_str = 0; |
283 | bool do_eof = false; |
275 | bool do_eof = false; |
284 | word bukva[2]; |
276 | word bukva[2]; |
285 | 277 | ||
286 | while(1) |
278 | while(1) |
287 | { |
279 | { |
288 | while(1) |
280 | while(1) |
289 | { |
281 | { |
290 | bukva = DSBYTE[bufpointer+pos+len_str]; |
282 | bukva = DSBYTE[bufpointer+pos+len_str]; |
291 | if (bukva=='\0') |
283 | if (bukva=='\0') |
292 | { |
284 | { |
293 | do_eof = true; |
285 | do_eof = true; |
294 | break; |
286 | break; |
295 | } |
287 | } |
296 | if (bukva==0x0a) |
288 | if (bukva==0x0a) |
297 | { |
289 | { |
298 | break; |
290 | break; |
299 | } |
291 | } |
300 | else |
292 | else |
301 | { |
293 | { |
302 | len_str++; |
294 | len_str++; |
303 | } |
295 | } |
304 | } |
296 | } |
305 | if (len_str<=rows.column_max) |
297 | if (len_str<=rows.column_max) |
306 | { |
298 | { |
307 | if (mode==PARSE_DRAW_PREPARE) |
299 | if (mode==PARSE_DRAW_PREPARE) |
308 | { |
300 | { |
309 | s.addn(bufpointer+pos, len_str); |
301 | s.addn(bufpointer+pos, len_str); |
310 | } |
302 | } |
311 | pos += len_str+1; |
303 | pos += len_str+1; |
312 | } |
304 | } |
313 | else |
305 | else |
314 | { |
306 | { |
315 | if (mode==PARSE_DRAW_PREPARE) |
307 | if (mode==PARSE_DRAW_PREPARE) |
316 | { |
308 | { |
317 | s.addn(bufpointer+pos, rows.column_max); |
309 | s.addn(bufpointer+pos, rows.column_max); |
318 | } |
310 | } |
319 | pos += rows.column_max; |
311 | pos += rows.column_max; |
320 | } |
312 | } |
321 | sub_pos++; |
313 | sub_pos++; |
322 | if (mode==PARSE_CALCULATE_ROWS_COUNT) && (do_eof) |
314 | if (mode==PARSE_CALCULATE_ROWS_COUNT) && (do_eof) |
323 | { |
315 | { |
324 | break; |
316 | break; |
325 | } |
317 | } |
326 | if (mode==PARSE_DRAW_PREPARE) && (pos>=bufsize-1) |
318 | if (mode==PARSE_DRAW_PREPARE) && (pos>=bufsize-1) |
327 | { |
319 | { |
328 | break; |
320 | break; |
329 | } |
321 | } |
330 | len_str = 0; |
322 | len_str = 0; |
331 | } |
323 | } |
332 | if (mode == PARSE_CALCULATE_ROWS_COUNT) |
324 | if (mode == PARSE_CALCULATE_ROWS_COUNT) |
333 | { |
325 | { |
334 | rows.count = sub_pos; |
326 | rows.count = sub_pos; |
335 | Parse(PARSE_DRAW_PREPARE); |
327 | Parse(PARSE_DRAW_PREPARE); |
336 | } |
328 | } |
337 | } |
329 | } |
338 | 330 | ||
339 | void Prepare() |
331 | void Prepare() |
340 | { |
332 | { |
341 | Parse(PARSE_CALCULATE_ROWS_COUNT); |
333 | Parse(PARSE_CALCULATE_ROWS_COUNT); |
342 | } |
334 | } |
343 | 335 | ||
344 | void DrawText() |
336 | void DrawText() |
345 | { |
337 | { |
346 | int i=0, top; |
338 | int i=0, top; |
347 | 339 | ||
348 | if (rows.count |
340 | if (rows.count |
349 | { |
341 | { |
350 | top = rows.count; |
342 | top = rows.count; |
351 | } |
343 | } |
352 | else |
344 | else |
353 | { |
345 | { |
354 | if (rows.count-rows.first<=rows.visible) |
346 | if (rows.count-rows.first<=rows.visible) |
355 | { |
347 | { |
356 | top = rows.count-rows.first-1; |
348 | top = rows.count-rows.first-1; |
357 | } |
349 | } |
358 | else |
350 | else |
359 | { |
351 | { |
360 | top = rows.visible; |
352 | top = rows.visible; |
361 | } |
353 | } |
362 | } |
354 | } |
363 | 355 | ||
364 | if (bufpointer) |
356 | if (bufpointer) |
365 | { |
357 | { |
366 | for (i=0; i |
358 | for (i=0; i |
367 | { |
359 | { |
368 | DrawBar(0, i*rows.item_h+TOPPANELH, rows.w, rows.item_h, 0xFFFFFF); |
360 | DrawBar(0, i*rows.item_h+TOPPANELH, rows.w, rows.item_h, 0xFFFFFF); |
369 | WriteText(2, i*rows.item_h+TOPPANELH, 0x90, 0x000000, s.get(i+rows.first)); |
361 | WriteText(2, i*rows.item_h+TOPPANELH, 0x90, 0x000000, s.get(i+rows.first)); |
370 | } |
362 | } |
371 | } |
363 | } |
372 | DrawBar(0, i*rows.item_h+rows.y, rows.w, -i*rows.item_h + rows.h, 0xFFFfff); |
364 | DrawBar(0, i*rows.item_h+rows.y, rows.w, -i*rows.item_h + rows.h, 0xFFFfff); |
373 | DrawVerticalScroll(); |
365 | DrawVerticalScroll(); |
374 | } |
366 | } |
375 | 367 | ||
376 | void DrawVerticalScroll() |
368 | void DrawVerticalScroll() |
377 | { |
369 | { |
378 | scroll_v.max_area = rows.count; |
370 | scroll_v.max_area = rows.count; |
379 | scroll_v.cur_area = rows.visible; |
371 | scroll_v.cur_area = rows.visible; |
380 | scroll_v.position = rows.first; |
372 | scroll_v.position = rows.first; |
381 | scroll_v.start_y = rows.y; |
373 | scroll_v.start_y = rows.y; |
382 | scroll_v.size_y = rows.h; |
374 | scroll_v.size_y = rows.h; |
383 | scroll_v.start_x = rows.w + rows.x -1; |
375 | scroll_v.start_x = rows.w + rows.x -1; |
384 | scroll_v.all_redraw = 0; |
376 | scroll_v.all_redraw = 0; |
385 | scrollbar_v_draw(#scroll_v); |
377 | scrollbar_v_draw(#scroll_v); |
386 | } |
378 | } |
387 | 379 | ||
388 | //===================================================// |
380 | //===================================================// |
389 | // // |
381 | // // |
390 | // EVENTS // |
382 | // EVENTS // |
391 | // // |
383 | // // |
392 | //===================================================// |
384 | //===================================================// |
393 | dword menu_id; |
385 | dword menu_id; |
394 | void EventMenuClick() |
386 | void EventMenuClick() |
395 | { |
387 | { |
396 | dword click_id = get_menu_click(); |
388 | dword click_id = get_menu_click(); |
397 | if (click_id) switch(click_id + menu_id - 1) |
389 | if (click_id) switch(click_id + menu_id - 1) |
398 | { |
390 | { |
399 | //File |
391 | //File |
400 | case FILE_SUBMENU_ID_OPEN: |
392 | case FILE_SUBMENU_ID_OPEN: |
401 | EventOpenFile(); |
393 | EventOpenFile(); |
402 | break; |
394 | break; |
403 | case FILE_SUBMENU_ID_CLOSE: |
395 | case FILE_SUBMENU_ID_CLOSE: |
404 | EventCloseFile(); |
396 | EventCloseFile(); |
405 | break; |
397 | break; |
406 | case FILE_SUBMENU_ID_PROPERTIES: |
398 | case FILE_SUBMENU_ID_PROPERTIES: |
407 | EventShowFileProperties(); |
399 | EventShowFileProperties(); |
408 | break; |
400 | break; |
409 | case FILE_SUBMENU_ID_EXIT: |
401 | case FILE_SUBMENU_ID_EXIT: |
410 | ExitProcess(); |
402 | ExitProcess(); |
411 | break; |
403 | break; |
412 | //Encoding |
404 | //Encoding |
413 | case MENU_ID_ENCODING...MENU_ID_ENCODING+9: |
405 | case MENU_ID_ENCODING...MENU_ID_ENCODING+9: |
414 | EventChangeEncoding(click_id-1); |
406 | EventChangeEncoding(click_id-1); |
415 | break; |
407 | break; |
416 | //Reopen |
408 | //Reopen |
417 | case FILE_SUBMENU_ID_TINYPAD: |
409 | case FILE_SUBMENU_ID_TINYPAD: |
418 | EventOpenFileInAnotherProgram("/sys/tinypad"); |
410 | EventOpenFileInAnotherProgram("/sys/tinypad"); |
419 | break; |
411 | break; |
420 | case FILE_SUBMENU_ID_TEXTEDIT: |
412 | case FILE_SUBMENU_ID_TEXTEDIT: |
421 | EventOpenFileInAnotherProgram("/sys/develop/t_edit"); |
413 | EventOpenFileInAnotherProgram("/sys/develop/t_edit"); |
422 | break; |
414 | break; |
423 | case FILE_SUBMENU_ID_TEXTREAD: |
415 | case FILE_SUBMENU_ID_TEXTREAD: |
424 | EventOpenFileInAnotherProgram("/sys/quark"); |
416 | EventOpenFileInAnotherProgram("/sys/quark"); |
425 | break; |
417 | break; |
426 | case FILE_SUBMENU_ID_WEBVIEW: |
418 | case FILE_SUBMENU_ID_WEBVIEW: |
427 | EventOpenFileInAnotherProgram("/sys/network/webview"); |
419 | EventOpenFileInAnotherProgram("/sys/network/webview"); |
428 | break; |
420 | break; |
429 | case FILE_SUBMENU_ID_FB2READ: |
421 | case FILE_SUBMENU_ID_FB2READ: |
430 | EventOpenFileInAnotherProgram("/sys/fb2read"); |
422 | EventOpenFileInAnotherProgram("/sys/fb2read"); |
431 | break; |
423 | break; |
432 | case FILE_SUBMENU_ID_HEXVIEW: |
424 | case FILE_SUBMENU_ID_HEXVIEW: |
433 | EventOpenFileInAnotherProgram("/sys/develop/heed"); |
425 | EventOpenFileInAnotherProgram("/sys/develop/heed"); |
434 | break; |
426 | break; |
435 | } |
427 | } |
436 | } |
428 | } |
437 | 429 | ||
438 | void EventShowMenu(dword _menu_item_x, _menu_list, _id, _selected) |
430 | void EventShowMenu(dword _menu_item_x, _menu_list, _id, _selected) |
439 | { |
431 | { |
440 | open_lmenu(_menu_item_x, TOPPANELH, MENU_TOP_LEFT, |
432 | open_lmenu(_menu_item_x, TOPPANELH, MENU_TOP_LEFT, |
441 | _selected, _menu_list); |
433 | _selected, _menu_list); |
442 | menu_id = _id; |
434 | menu_id = _id; |
443 | } |
435 | } |
444 | 436 | ||
445 | void EventOpenFile() |
437 | void EventOpenFile() |
446 | { |
438 | { |
447 | OpenDialog_start stdcall (#o_dialog); |
439 | OpenDialog_start stdcall (#o_dialog); |
448 | if (o_dialog.status) |
440 | if (o_dialog.status) |
449 | { |
441 | { |
450 | OpenFile(#openfile_path); |
442 | OpenFile(#openfile_path); |
451 | Prepare(); |
443 | Prepare(); |
452 | draw_window(); |
444 | draw_window(); |
453 | } |
445 | } |
454 | } |
446 | } |
455 | 447 | ||
456 | void EventCloseFile() |
448 | void EventCloseFile() |
457 | { |
449 | { |
458 | if (bufpointer) |
450 | if (bufpointer) |
459 | { |
451 | { |
460 | s.drop(); |
452 | s.drop(); |
461 | bufpointer = mem_Free(bufpointer); |
453 | bufpointer = mem_Free(bufpointer); |
462 | strcpy(#win_title, TITLE); |
454 | strcpy(#win_title, TITLE); |
463 | draw_window(); |
455 | draw_window(); |
464 | } |
456 | } |
465 | } |
457 | } |
466 | 458 | ||
467 | void EventShowFileProperties() |
459 | void EventShowFileProperties() |
468 | { |
460 | { |
469 | char ss_param[4096]; |
461 | char ss_param[4096]; |
470 | if (bufpointer) |
462 | if (bufpointer) |
471 | { |
463 | { |
472 | sprintf(#ss_param, "-p %s", #param); |
464 | sprintf(#ss_param, "-p %s", #param); |
473 | RunProgram("/sys/File managers/Eolite", #ss_param); |
465 | RunProgram("/sys/File managers/Eolite", #ss_param); |
474 | } |
466 | } |
475 | } |
467 | } |
476 | 468 | ||
477 | void EventChangeEncoding(dword id) |
469 | void EventChangeEncoding(dword id) |
478 | { |
470 | { |
479 | encoding = id; |
471 | encoding = id; |
480 | OpenFile(#openfile_path); |
472 | OpenFile(#openfile_path); |
481 | Prepare(); |
473 | Prepare(); |
482 | draw_window(); |
474 | draw_window(); |
483 | } |
475 | } |
484 | 476 | ||
485 | void EventOpenFileInAnotherProgram(dword _app) |
477 | void EventOpenFileInAnotherProgram(dword _app) |
486 | { |
478 | { |
487 | RunProgram(_app, #param); |
479 | RunProgram(_app, #param); |
488 | } |
480 | } |
489 | 481 | ||
490 | 482 | ||
491 | 483 | ||
492 | stop:=rows.visible) |
484 | stop:=rows.visible) |
493 | > |
485 | > |
494 | >=rows.column_max)> |
486 | >=rows.column_max)> |