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