1 | //--------------------------------------------------------------
|
---|
2 | //File name: editor.c
|
---|
3 | //--------------------------------------------------------------
|
---|
4 | #include "launchelf.h"
|
---|
5 |
|
---|
6 | enum
|
---|
7 | {
|
---|
8 | COL_NORM_BG = GS_SETREG_RGBA(160,160,160,0),
|
---|
9 | COL_NORM_TEXT = GS_SETREG_RGBA(0,0,0,0),
|
---|
10 | COL_MARK_BG = GS_SETREG_RGBA(0,40,160,0),
|
---|
11 | COL_MARK_TEXT = GS_SETREG_RGBA(160,160,160,0),
|
---|
12 | COL_CUR_INSERT = GS_SETREG_RGBA(0,160,0,0),
|
---|
13 | COL_CUR_OVERWR = GS_SETREG_RGBA(160,0,0,0),
|
---|
14 | COL_LINE_END = GS_SETREG_RGBA(160,80,0,0),
|
---|
15 | COL_TAB = GS_SETREG_RGBA(0,0,160,0),
|
---|
16 | COL_TEXT_END = GS_SETREG_RGBA(0,160,160,0),
|
---|
17 | COL_dummy
|
---|
18 | };
|
---|
19 |
|
---|
20 | enum
|
---|
21 | {
|
---|
22 | NEW,
|
---|
23 | OPEN,
|
---|
24 | CLOSE,
|
---|
25 | SAVE,
|
---|
26 | SAVE_AS,
|
---|
27 | WINDOWS,
|
---|
28 | EXIT,
|
---|
29 | NUM_MENU
|
---|
30 | }; // Menu Fonction.
|
---|
31 |
|
---|
32 | enum
|
---|
33 | {
|
---|
34 | MARK_START,
|
---|
35 | MARK_ON,
|
---|
36 | MARK_COPY,
|
---|
37 | MARK_CUT,
|
---|
38 | MARK_IN,
|
---|
39 | MARK_OUT,
|
---|
40 | MARK_TMP,
|
---|
41 | MARK_SIZE,
|
---|
42 | MARK_PRINT,
|
---|
43 | MARK_COLOR,
|
---|
44 | NUM_MARK
|
---|
45 | }; // Marking Fonction/State.
|
---|
46 |
|
---|
47 | enum
|
---|
48 | {
|
---|
49 | CREATED,
|
---|
50 | OPENED,
|
---|
51 | SAVED,
|
---|
52 | NUM_STATE
|
---|
53 | }; // Windowing State.
|
---|
54 |
|
---|
55 | #define OTHER 1 // CR/LF Return Text Mode, 'All Normal System'.
|
---|
56 | #define UNIX 2 // CR Return Text Mode, Unix.
|
---|
57 | #define MAC 3 // LF Return Text Mode, Mac.
|
---|
58 |
|
---|
59 | #define TMP 10 // Temp Buffer For Add / Remove Char.
|
---|
60 | #define EDIT 11 // Edit Buffer For Copy / Cut / Paste.
|
---|
61 |
|
---|
62 | static u8 *TextBuffer[12]; // Text Buffers, 10 Windows Max + 1 TMP + 1 EDIT. See above.
|
---|
63 | static int Window[10][NUM_STATE], // Windowing System, 10 Windows Max.
|
---|
64 | TextMode[10], // Text Mode, UNIX, MAC, OTHER.
|
---|
65 | TextSize[10], // Text Size, 10 Windows Max.
|
---|
66 | Editor_nRowsWidth[MAX_ENTRY], // Current Window, Char Number For Each Rows. (MAX_ENTRY???)
|
---|
67 | Mark[NUM_MARK], // Marking System,(Mark, Copy, Cut, Paste, Delete),Work From 1 Window To An Other.
|
---|
68 | Active_Window, // Activated Windows Number.
|
---|
69 | Num_Window, // Opened Windows Count.
|
---|
70 | Editor_Cur, // Text Cursor.
|
---|
71 | Tmp_Cur, // Temp Cursor For Rules Calculations.
|
---|
72 | Editor_nChar, // Current Window, Total Char Number.
|
---|
73 | Editor_nRowsNum, // Current Window, Total Rows Number.
|
---|
74 | Editor_nCharRows, // Current Window, Char Number Per Rows Height.
|
---|
75 | Editor_nRowsTop, // Current Window, Rows Number Above Top Screen For Rules Calculations.
|
---|
76 | Rows_Num, // Rows Number Feeting In Screen Height.
|
---|
77 | Rows_Width, // Char Number Feeting In Screen Width.
|
---|
78 | Top_Width, // Char Number In Rows Above Top Screen.
|
---|
79 | Top_Height, // Current Window Rows Number Above Top Screen.
|
---|
80 | Editor_Insert, // Setting Insert On/Off.
|
---|
81 | Editor_RetMode, // Setting Insert On/Off.
|
---|
82 | Editor_Home, // Goto Line Home.
|
---|
83 | Editor_End, // Goto Line End
|
---|
84 | Editor_PushRows, // Push 1 Row Height Up(+1) Or Down(-1), Use For Page Up/Down Too.
|
---|
85 | Editor_TextEnd, // Set To 1 When '\0' Char Is Found Tell Text End.
|
---|
86 | KeyBoard_Cur, // Virtual KeyBoard Cursor.
|
---|
87 | KeyBoard_Active, // Virtual KeyBoard Activated Or Not.
|
---|
88 | del1, del2, del3, del4, // Deleted Chars Different Cases.
|
---|
89 | ins1, ins2, ins3, ins4, ins5, // Added Chars Different Cases.
|
---|
90 | t; // Text Cursor Timer.
|
---|
91 | static char Path[10][MAX_PATH]; // File Path For Each Opened Windows. 10 Max.
|
---|
92 |
|
---|
93 | static const int WFONTS=20, // Virtual KeyBoard Width.
|
---|
94 | HFONTS=5; // Virtual KeyBoard Height.
|
---|
95 | static char *KEY= " 01ABCDEFGHIJKLM:; "
|
---|
96 | " 23NOPQRSTUVWXYZ., "
|
---|
97 | " 45abcdefghijklm() "
|
---|
98 | " 67nopqrstuvwxyz[] "
|
---|
99 | " 89+-=!# $%&@_^' "; // Virtual KeyBoard Matrix.
|
---|
100 |
|
---|
101 | //--------------------------------------------------------------
|
---|
102 | int MenuEditor(void)
|
---|
103 | {
|
---|
104 | u64 color;
|
---|
105 | char enable[NUM_MENU], tmp[64];
|
---|
106 | int x, y, i, Menu_Sel;
|
---|
107 | int event, post_event=0;
|
---|
108 |
|
---|
109 | int menu_len=strlen(LNG(New))>strlen(LNG(Open))?
|
---|
110 | strlen(LNG(New)):strlen(LNG(Open));
|
---|
111 | menu_len=strlen(LNG(Close))>menu_len? strlen(LNG(Close)):menu_len;
|
---|
112 | menu_len=strlen(LNG(Save))>menu_len? strlen(LNG(Save)):menu_len;
|
---|
113 | menu_len=strlen(LNG(Save_As))>menu_len? strlen(LNG(Save_As)):menu_len;
|
---|
114 | menu_len=strlen(LNG(Windows))>menu_len? strlen(LNG(Windows)):menu_len;
|
---|
115 | menu_len=strlen(LNG(Exit))>menu_len? strlen(LNG(Exit)):menu_len;
|
---|
116 |
|
---|
117 | int menu_ch_w = menu_len+1; //Total characters in longest menu string.
|
---|
118 | int menu_ch_h = NUM_MENU; //Total number of menu lines.
|
---|
119 | int mSprite_Y1 = 64; //Top edge of sprite.
|
---|
120 | int mSprite_X2 = SCREEN_WIDTH-35; //Right edge of sprite.
|
---|
121 | int mSprite_X1 = mSprite_X2-(menu_ch_w+3)*FONT_WIDTH; //Left edge of sprite
|
---|
122 | int mSprite_Y2 = mSprite_Y1+(menu_ch_h+1)*FONT_HEIGHT; //Bottom edge of sprite
|
---|
123 |
|
---|
124 | memset(enable, TRUE, NUM_MENU);
|
---|
125 |
|
---|
126 | if(!Window[Active_Window][OPENED]){
|
---|
127 | enable[CLOSE] = FALSE;
|
---|
128 | enable[SAVE] = FALSE;
|
---|
129 | enable[SAVE_AS] = FALSE;
|
---|
130 | }
|
---|
131 | if(Window[Active_Window][CREATED]){
|
---|
132 | enable[SAVE] = FALSE;
|
---|
133 | }
|
---|
134 | if(!Num_Window)
|
---|
135 | enable[WINDOWS] = FALSE;
|
---|
136 |
|
---|
137 | for(Menu_Sel=0; Menu_Sel<NUM_MENU; Menu_Sel++)
|
---|
138 | if(enable[Menu_Sel]==TRUE) break;
|
---|
139 |
|
---|
140 | event = 1; //event = initial entry.
|
---|
141 | while(1){
|
---|
142 | //Pad response section.
|
---|
143 | waitPadReady(0, 0);
|
---|
144 | if(readpad()){
|
---|
145 | if(new_pad & PAD_UP && Menu_Sel<NUM_MENU){
|
---|
146 | event |= 2; //event |= valid pad command.
|
---|
147 | do{
|
---|
148 | Menu_Sel--;
|
---|
149 | if(Menu_Sel<0) Menu_Sel=NUM_MENU-1;
|
---|
150 | }while(!enable[Menu_Sel]);
|
---|
151 | }else if(new_pad & PAD_DOWN && Menu_Sel<NUM_MENU){
|
---|
152 | event |= 2; //event |= valid pad command.
|
---|
153 | do{
|
---|
154 | Menu_Sel++;
|
---|
155 | if(Menu_Sel==NUM_MENU) Menu_Sel=0;
|
---|
156 | }while(!enable[Menu_Sel]);
|
---|
157 | }else if((new_pad & PAD_TRIANGLE)
|
---|
158 | || (!swapKeys && new_pad & PAD_CROSS)
|
---|
159 | || (swapKeys && new_pad & PAD_CIRCLE) ){
|
---|
160 | return -1;
|
---|
161 | }else if((swapKeys && new_pad & PAD_CROSS)
|
---|
162 | || (!swapKeys && new_pad & PAD_CIRCLE) ){
|
---|
163 | event |= 2; //event |= valid pad command.
|
---|
164 | break;
|
---|
165 | }
|
---|
166 | }
|
---|
167 |
|
---|
168 | if(event||post_event){ //NB: We need to update two frame buffers per event.
|
---|
169 |
|
---|
170 | //Display section.
|
---|
171 | drawPopSprite(setting->color[0],
|
---|
172 | mSprite_X1, mSprite_Y1,
|
---|
173 | mSprite_X2, mSprite_Y2);
|
---|
174 | drawFrame(mSprite_X1, mSprite_Y1, mSprite_X2, mSprite_Y2, setting->color[1]);
|
---|
175 |
|
---|
176 | for(i=0,y=mSprite_Y1+FONT_HEIGHT/2; i<NUM_MENU; i++){
|
---|
177 | if(i==NEW) strcpy(tmp, LNG(New));
|
---|
178 | else if(i==OPEN) strcpy(tmp, LNG(Open));
|
---|
179 | else if(i==CLOSE) strcpy(tmp, LNG(Close));
|
---|
180 | else if(i==SAVE) strcpy(tmp, LNG(Save));
|
---|
181 | else if(i==SAVE_AS) strcpy(tmp, LNG(Save_As));
|
---|
182 | else if(i==WINDOWS) strcpy(tmp, LNG(Windows));
|
---|
183 | else if(i==EXIT) strcpy(tmp, LNG(Exit));
|
---|
184 |
|
---|
185 | if(enable[i]) color = setting->color[3];
|
---|
186 | else color = setting->color[1];
|
---|
187 |
|
---|
188 | printXY(tmp, mSprite_X1+2*FONT_WIDTH, y, color, TRUE, 0);
|
---|
189 | y+=FONT_HEIGHT;
|
---|
190 | }
|
---|
191 | if(Menu_Sel<NUM_MENU)
|
---|
192 | drawChar(LEFT_CUR, mSprite_X1+FONT_WIDTH, mSprite_Y1+(FONT_HEIGHT/2+Menu_Sel*FONT_HEIGHT), setting->color[3]);
|
---|
193 |
|
---|
194 | //Tooltip section.
|
---|
195 | x = SCREEN_MARGIN;
|
---|
196 | y = Menu_tooltip_y;
|
---|
197 | drawSprite(setting->color[0],
|
---|
198 | 0, y-1,
|
---|
199 | SCREEN_WIDTH, y+16);
|
---|
200 | if (swapKeys)
|
---|
201 | sprintf(tmp, "ÿ1:%s ÿ0:%s ÿ3:%s", LNG(OK), LNG(Cancel), LNG(Back));
|
---|
202 | else
|
---|
203 | sprintf(tmp, "ÿ0:%s ÿ1:%s ÿ3:%s", LNG(OK), LNG(Cancel), LNG(Back));
|
---|
204 | printXY(tmp, x, y, setting->color[2], TRUE, 0);
|
---|
205 | }//ends if(event||post_event).
|
---|
206 | drawScr();
|
---|
207 | post_event = event;
|
---|
208 | event = 0;
|
---|
209 | }//ends while.
|
---|
210 | return Menu_Sel;
|
---|
211 | }//ends menu.
|
---|
212 | //--------------------------------------------------------------
|
---|
213 | void Virt_KeyBoard_Entry(void)
|
---|
214 | {
|
---|
215 | int i, Operation;
|
---|
216 |
|
---|
217 | Operation=0;
|
---|
218 |
|
---|
219 | if(new_pad & PAD_UP){ // Virtual KeyBoard move up.
|
---|
220 | if(!KeyBoard_Cur)
|
---|
221 | KeyBoard_Cur=WFONTS*(HFONTS-1);
|
---|
222 | else if(KeyBoard_Cur==WFONTS-1)
|
---|
223 | KeyBoard_Cur=WFONTS*HFONTS-1;
|
---|
224 | else if(KeyBoard_Cur>0){
|
---|
225 | if((KeyBoard_Cur-=WFONTS)<0)
|
---|
226 | KeyBoard_Cur=0;
|
---|
227 | }
|
---|
228 | //ends Virtual KeyBoard move up.
|
---|
229 | }else if(new_pad & PAD_DOWN){ // Virtual KeyBoard move down.
|
---|
230 | if(KeyBoard_Cur==WFONTS*HFONTS-1)
|
---|
231 | KeyBoard_Cur=WFONTS-1;
|
---|
232 | else if(KeyBoard_Cur==WFONTS*(HFONTS-1))
|
---|
233 | KeyBoard_Cur=0;
|
---|
234 | else if(KeyBoard_Cur<WFONTS*HFONTS-1){
|
---|
235 | if((KeyBoard_Cur+=WFONTS)>WFONTS*HFONTS-1)
|
---|
236 | KeyBoard_Cur=WFONTS*HFONTS-1;
|
---|
237 | }
|
---|
238 | //ends Virtual KeyBoard move down.
|
---|
239 | }else if(new_pad & PAD_LEFT){ // Virtual KeyBoard move left.
|
---|
240 | if(!KeyBoard_Cur)
|
---|
241 | KeyBoard_Cur=WFONTS*HFONTS-1;
|
---|
242 | else
|
---|
243 | KeyBoard_Cur--;
|
---|
244 | //ends Virtual KeyBoard move left.
|
---|
245 | }else if(new_pad & PAD_RIGHT){ // Virtual KeyBoard move right.
|
---|
246 | if(KeyBoard_Cur==WFONTS*HFONTS-1)
|
---|
247 | KeyBoard_Cur=0;
|
---|
248 | else
|
---|
249 | KeyBoard_Cur++;
|
---|
250 | //ends Virtual KeyBoard move right.
|
---|
251 | }else if(new_pad & PAD_L2){ // Text move left.
|
---|
252 | if(Editor_Cur>0)
|
---|
253 | Editor_Cur--;
|
---|
254 | }else if(new_pad & PAD_R2){ // Text move right.
|
---|
255 | if(Editor_Cur<Editor_nChar && TextBuffer[Active_Window][Editor_Cur]!='\0')
|
---|
256 | Editor_Cur++;
|
---|
257 | }else if(new_pad & PAD_SELECT){ // Virtual KeyBoard Exit.
|
---|
258 | Rows_Num += 6;
|
---|
259 | KeyBoard_Active = 0;
|
---|
260 | }else if((!swapKeys && new_pad & PAD_CROSS)
|
---|
261 | || (swapKeys && new_pad & PAD_CIRCLE) ){ // Virtual KeyBoard Backspace
|
---|
262 | if(Editor_Cur>0){
|
---|
263 | if( TextMode[Active_Window]==OTHER
|
---|
264 | && TextBuffer[Active_Window][Editor_Cur]=='\n'
|
---|
265 | && TextBuffer[Active_Window][Editor_Cur-1]=='\r'
|
---|
266 | ){
|
---|
267 | Editor_Cur += 1; //Backspace at LF of CRLF must work after LF instead
|
---|
268 | }
|
---|
269 | if(Mark[MARK_ON]){
|
---|
270 | Mark[MARK_OUT]=Editor_Cur;
|
---|
271 | if(Mark[MARK_OUT]<Mark[MARK_IN]){
|
---|
272 | Mark[MARK_TMP]=Mark[MARK_IN];
|
---|
273 | Mark[MARK_IN]=Mark[MARK_OUT];
|
---|
274 | Mark[MARK_OUT]=Mark[MARK_TMP];
|
---|
275 | }else if(Mark[MARK_IN]==Mark[MARK_OUT])
|
---|
276 | goto abort;
|
---|
277 | Mark[MARK_SIZE]=Mark[MARK_OUT]-Mark[MARK_IN];
|
---|
278 | del1= -Mark[MARK_SIZE], del2=0, del3= -Mark[MARK_SIZE], del4= -Mark[MARK_SIZE];
|
---|
279 | Mark[MARK_ON]=0;
|
---|
280 | }else if(TextMode[Active_Window]==OTHER
|
---|
281 | && TextBuffer[Active_Window][Editor_Cur-1]=='\n'
|
---|
282 | && Editor_Cur>1
|
---|
283 | && TextBuffer[Active_Window][Editor_Cur-2]=='\r'){
|
---|
284 | del1=-2, del2=0, del3=-2, del4=-2; //Backspace CRLF
|
---|
285 | }else{
|
---|
286 | del1=-1, del2=0, del3=-1, del4=-1; //Backspace single char
|
---|
287 | }
|
---|
288 | Operation=-1;
|
---|
289 | }
|
---|
290 | //ends Virtual KeyBoard Backspace
|
---|
291 | }else if((swapKeys && new_pad & PAD_CROSS)
|
---|
292 | || (!swapKeys && new_pad & PAD_CIRCLE) ){ // Virtual KeyBoard Select.
|
---|
293 | if(!KeyBoard_Cur){ // Virtual KeyBoard MARK.
|
---|
294 | Mark[MARK_ON]=!Mark[MARK_ON];
|
---|
295 | if(Mark[MARK_ON]){
|
---|
296 | if( TextMode[Active_Window]==OTHER
|
---|
297 | && TextBuffer[Active_Window][Editor_Cur]=='\n'
|
---|
298 | && Editor_Cur>0
|
---|
299 | && TextBuffer[Active_Window][Editor_Cur-1]=='\r'
|
---|
300 | ){
|
---|
301 | Editor_Cur -= 1; //Marking at LF of CRLF must start at CR instead
|
---|
302 | }
|
---|
303 | if(Mark[MARK_COPY] || Mark[MARK_CUT])
|
---|
304 | free(TextBuffer[EDIT]);
|
---|
305 | Mark[MARK_ON]=1, Mark[MARK_COPY]=0, Mark[MARK_CUT]=0,
|
---|
306 | Mark[MARK_IN]=0, Mark[MARK_OUT]=0, Mark[MARK_TMP]=0,
|
---|
307 | Mark[MARK_SIZE]=0, Mark[MARK_PRINT]=0, Mark[MARK_COLOR]=0;
|
---|
308 | Mark[MARK_IN]=Mark[MARK_OUT]=Editor_Cur;
|
---|
309 | }
|
---|
310 | Mark[MARK_START]=1;
|
---|
311 | //ends Virtual KeyBoard MARK.
|
---|
312 | }else if(KeyBoard_Cur == WFONTS){ // Virtual KeyBoard COPY.
|
---|
313 | if(Mark[MARK_ON]){
|
---|
314 | if( TextMode[Active_Window]==OTHER
|
---|
315 | && TextBuffer[Active_Window][Editor_Cur]=='\n'
|
---|
316 | && Editor_Cur>0
|
---|
317 | && TextBuffer[Active_Window][Editor_Cur-1]=='\r'
|
---|
318 | ){
|
---|
319 | Editor_Cur += 1; //Mark end at LF of CRLF must include LF as well
|
---|
320 | }
|
---|
321 | Mark[MARK_OUT]=Editor_Cur;
|
---|
322 | if(Mark[MARK_OUT]<Mark[MARK_IN]){
|
---|
323 | Mark[MARK_TMP]=Mark[MARK_IN];
|
---|
324 | Mark[MARK_IN]=Mark[MARK_OUT];
|
---|
325 | Mark[MARK_OUT]=Mark[MARK_TMP];
|
---|
326 | }else if(Mark[MARK_IN]==Mark[MARK_OUT])
|
---|
327 | goto abort;
|
---|
328 | if(Mark[MARK_COPY] || Mark[MARK_CUT])
|
---|
329 | free(TextBuffer[EDIT]);
|
---|
330 | Mark[MARK_SIZE]=Mark[MARK_OUT]-Mark[MARK_IN];
|
---|
331 | TextBuffer[EDIT] = malloc(Mark[MARK_SIZE]+256); // 256 To Avoid Crash 256???
|
---|
332 | for(i=0; i<Mark[MARK_SIZE]; i++)
|
---|
333 | TextBuffer[EDIT][i]=TextBuffer[Active_Window][i+Mark[MARK_IN]];
|
---|
334 | Mark[MARK_COPY]=1, Mark[MARK_CUT]=0, Mark[MARK_ON]=0;
|
---|
335 | }
|
---|
336 | //ends Virtual KeyBoard COPY.
|
---|
337 | }else if(KeyBoard_Cur == 2*WFONTS){ // Virtual KeyBoard CUT.
|
---|
338 | if(Mark[MARK_ON]){
|
---|
339 | if( TextMode[Active_Window]==OTHER
|
---|
340 | && TextBuffer[Active_Window][Editor_Cur]=='\n'
|
---|
341 | && Editor_Cur>0
|
---|
342 | && TextBuffer[Active_Window][Editor_Cur-1]=='\r'
|
---|
343 | ){
|
---|
344 | Editor_Cur += 1; //Mark end at LF of CRLF must include LF as well
|
---|
345 | }
|
---|
346 | Mark[MARK_OUT]=Editor_Cur;
|
---|
347 | if(Mark[MARK_OUT]<Mark[MARK_IN]){
|
---|
348 | Mark[MARK_TMP]=Mark[MARK_IN];
|
---|
349 | Mark[MARK_IN]=Mark[MARK_OUT];
|
---|
350 | Mark[MARK_OUT]=Mark[MARK_TMP];
|
---|
351 | }else if(Mark[MARK_IN]==Mark[MARK_OUT])
|
---|
352 | goto abort;
|
---|
353 | if(Mark[MARK_COPY] || Mark[MARK_CUT])
|
---|
354 | free(TextBuffer[EDIT]);
|
---|
355 | Mark[MARK_SIZE]=Mark[MARK_OUT]-Mark[MARK_IN];
|
---|
356 | TextBuffer[EDIT] = malloc(Mark[MARK_SIZE]+256); // 256 To Avoid Crash 256???
|
---|
357 | for(i=0; i<Mark[MARK_SIZE]; i++)
|
---|
358 | TextBuffer[EDIT][i]=TextBuffer[Active_Window][i+Mark[MARK_IN]];
|
---|
359 | del1= -Mark[MARK_SIZE], del2=0, del3= -Mark[MARK_SIZE], del4= -Mark[MARK_SIZE];
|
---|
360 | Mark[MARK_CUT]=1, Mark[MARK_COPY]=0, Mark[MARK_ON]=0;
|
---|
361 | Operation=-1;
|
---|
362 | }
|
---|
363 | abort:
|
---|
364 | Mark[MARK_TMP]=0; // just for compiler warning.
|
---|
365 | //ends Virtual KeyBoard CUT.
|
---|
366 | }else if(KeyBoard_Cur == 3*WFONTS){ // Virtual KeyBoard PASTE.
|
---|
367 | if( Mark[MARK_COPY] || Mark[MARK_CUT]){
|
---|
368 | if(TextMode[Active_Window]==OTHER && TextBuffer[Active_Window][Editor_Cur]=='\n'){
|
---|
369 | Editor_Cur-=1;
|
---|
370 | Mark[MARK_SIZE]-=1;
|
---|
371 | }
|
---|
372 | ins1=Mark[MARK_SIZE], ins2=Mark[MARK_SIZE], ins3=Mark[MARK_SIZE], ins4=0, ins5=Mark[MARK_SIZE];
|
---|
373 | Operation=1;
|
---|
374 | }
|
---|
375 | //ends Virtual KeyBoard PASTE.
|
---|
376 | }else if(KeyBoard_Cur == 4*WFONTS){ // Virtual KeyBoard HOME.
|
---|
377 | Editor_Home=1;
|
---|
378 | }else if(KeyBoard_Cur == 1){ // Virtual KeyBoard LINE UP.
|
---|
379 | if(Editor_Cur>0)
|
---|
380 | Editor_PushRows++;
|
---|
381 | }else if(KeyBoard_Cur == WFONTS+1){ // Virtual KeyBoard LINE DOWN.
|
---|
382 | if(Editor_Cur<Editor_nChar)
|
---|
383 | Editor_PushRows--;
|
---|
384 | }else if(KeyBoard_Cur == 2*WFONTS+1){ // Virtual KeyBoard PAGE UP.
|
---|
385 | if(Editor_Cur>0)
|
---|
386 | Editor_PushRows += 1*(Rows_Num-1);
|
---|
387 | }else if(KeyBoard_Cur == 3*WFONTS+1){ // Virtual KeyBoard PAGE DOWN.
|
---|
388 | if(Editor_Cur<Editor_nChar && TextBuffer[Active_Window][Editor_Cur]!='\0')
|
---|
389 | Editor_PushRows -= 1*(Rows_Num-1);
|
---|
390 | }else if(KeyBoard_Cur == 4*WFONTS+1){ // Virtual KeyBoard END.
|
---|
391 | Editor_End=1;
|
---|
392 | }else if(KeyBoard_Cur == WFONTS-1){ // Virtual KeyBoard INSERT.
|
---|
393 | Editor_Insert = !Editor_Insert;
|
---|
394 | }else if(KeyBoard_Cur == 2*WFONTS-1){ // Virtual KeyBoard Return Mode CR/LF, LF, CR.
|
---|
395 | if((Editor_RetMode++)>=4)
|
---|
396 | Editor_RetMode=OTHER;
|
---|
397 | }else if(KeyBoard_Cur == 5*WFONTS-1){ // Virtual KeyBoard RETURN.
|
---|
398 |
|
---|
399 | if( TextMode[Active_Window]==OTHER
|
---|
400 | && TextBuffer[Active_Window][Editor_Cur]=='\n'
|
---|
401 | && Editor_Cur>0
|
---|
402 | && TextBuffer[Active_Window][Editor_Cur-1]=='\r'
|
---|
403 | ){
|
---|
404 | Editor_Cur -= 1; //Entry at LF of CRLF must work at CR instead
|
---|
405 | }
|
---|
406 | if(Editor_Insert || TextBuffer[Active_Window][Editor_Cur]=='\0')
|
---|
407 | if(Editor_RetMode==OTHER)
|
---|
408 | ins1=2, ins2=0, ins3=2, ins4=0, ins5=2; //Insert CRLF
|
---|
409 | else
|
---|
410 | ins1=1, ins2=0, ins3=1, ins4=0, ins5=1; //Insert LF/CR
|
---|
411 | else
|
---|
412 | if( TextMode[Active_Window]==OTHER
|
---|
413 | && TextBuffer[Active_Window][Editor_Cur]=='\r'
|
---|
414 | && TextBuffer[Active_Window][Editor_Cur+1]=='\n'
|
---|
415 | ){ //OWrite Return at CRLF
|
---|
416 | if(Editor_RetMode==OTHER)
|
---|
417 | ins1=0, ins2=0, ins3=2, ins4=2, ins5=2; //OWrite CRLF at CRLF
|
---|
418 | else
|
---|
419 | ins1=0, ins2=0, ins3=1, ins4=2, ins5=1; //OWrite LF/CR at CRLF
|
---|
420 | }else{ //OWrite return at normal char
|
---|
421 | if(Editor_RetMode==OTHER)
|
---|
422 | ins1=1, ins2=0, ins3=2, ins4=1, ins5=2; //OWrite CRLF at char
|
---|
423 | else
|
---|
424 | ins1=0, ins2=0, ins3=1, ins4=1, ins5=1; //OWrite LF/CR at char
|
---|
425 | }
|
---|
426 | Operation=2;
|
---|
427 | //ends Virtual KeyBoard RETURN.
|
---|
428 | }else{ // Virtual KeyBoard Any other char + Space + Tabulation.
|
---|
429 | if( TextMode[Active_Window]==OTHER
|
---|
430 | && TextBuffer[Active_Window][Editor_Cur]=='\n'
|
---|
431 | && Editor_Cur>0
|
---|
432 | && TextBuffer[Active_Window][Editor_Cur-1]=='\r'
|
---|
433 | ){
|
---|
434 | Editor_Cur -= 1; //Entry at LF of CRLF must work at CR instead
|
---|
435 | }
|
---|
436 | if(Editor_Insert || TextBuffer[Active_Window][Editor_Cur]=='\0'){
|
---|
437 | ins1=1, ins2=0, ins3=1, ins4=0, ins5=1; //Insert char normally
|
---|
438 | }else{
|
---|
439 | if(TextMode[Active_Window]==OTHER
|
---|
440 | && TextBuffer[Active_Window][Editor_Cur]=='\r'
|
---|
441 | && TextBuffer[Active_Window][Editor_Cur+1]=='\n'
|
---|
442 | ){ //OWrite char at CRLF
|
---|
443 | ins1=0, ins2= 0, ins3=1, ins4= 2, ins5= 1; //OWrite at CR of CRLF
|
---|
444 | }else{ //OWrite return at normal char
|
---|
445 | ins1=0, ins2= 0, ins3=1, ins4= 1, ins5= 1; //OWrite normal char
|
---|
446 | }
|
---|
447 | }
|
---|
448 | if(KeyBoard_Cur == 3*WFONTS-1) // Tabulation.
|
---|
449 | Operation=3;
|
---|
450 | else if(KeyBoard_Cur == 4*WFONTS-1) // Space.
|
---|
451 | Operation=4;
|
---|
452 | else // Any other char.
|
---|
453 | Operation=5;
|
---|
454 | }
|
---|
455 | //ends Virtual KeyBoard Select.
|
---|
456 | }
|
---|
457 |
|
---|
458 | if(Operation>0){ // Perform Add Char / Paste. Can Be Simplify???
|
---|
459 | TextBuffer[TMP] = malloc(TextSize[Active_Window]+ins1+256); // 256 To Avoid Crash 256???
|
---|
460 | strcpy(TextBuffer[TMP], TextBuffer[Active_Window]);
|
---|
461 | //memset(TextBuffer[Active_Window], 0, TextSize[Active_Window]+256); // 256 To Avoid Crash 256??? free(TextBuffer[Active_Window]);
|
---|
462 | TextBuffer[Active_Window] = malloc(TextSize[Active_Window]+ins1+256); // 256 To Avoid Crash 256???
|
---|
463 | strcpy(TextBuffer[Active_Window], TextBuffer[TMP]);
|
---|
464 | }
|
---|
465 |
|
---|
466 | switch(Operation){
|
---|
467 | case 0:
|
---|
468 | break;
|
---|
469 | case -1:// Perform Del Char / Cut. Can Be Simplify???
|
---|
470 | TextBuffer[TMP] = malloc(TextSize[Active_Window]+256); // 256 To Avoid Crash 256???
|
---|
471 | strcpy(TextBuffer[TMP], TextBuffer[Active_Window]);
|
---|
472 | TextBuffer[Active_Window][Editor_Cur+del1]='\0';
|
---|
473 | strcat(TextBuffer[Active_Window], TextBuffer[TMP]+(Editor_Cur+del2));
|
---|
474 | strcpy(TextBuffer[TMP], TextBuffer[Active_Window]);
|
---|
475 | //memset(TextBuffer[Active_Window], 0, TextSize[Active_Window]+256); // 256 To Avoid Crash 256???
|
---|
476 | free(TextBuffer[Active_Window]);
|
---|
477 | TextBuffer[Active_Window] = malloc(TextSize[Active_Window]+del3+256); // 256 To Avoid Crash 256???
|
---|
478 | strcpy(TextBuffer[Active_Window], TextBuffer[TMP]);
|
---|
479 | //memset(TextBuffer[TMP], 0, TextSize[Active_Window]+256); // 256 To Avoid Crash 256???
|
---|
480 | free(TextBuffer[TMP]);
|
---|
481 | Editor_Cur+=del3, TextSize[Active_Window]+=del4;
|
---|
482 | t=0;
|
---|
483 | break;
|
---|
484 | case 1: // Paste.
|
---|
485 | for(i=0; i<ins2; i++)
|
---|
486 | TextBuffer[Active_Window][i+Editor_Cur]=TextBuffer[EDIT][i];
|
---|
487 | goto common;
|
---|
488 | case 2: // Return.
|
---|
489 | if(Editor_RetMode==OTHER){
|
---|
490 | TextBuffer[Active_Window][Editor_Cur+ins2]='\r';
|
---|
491 | TextBuffer[Active_Window][Editor_Cur+ins2+1]='\n';
|
---|
492 | }else if(Editor_RetMode==UNIX){
|
---|
493 | TextBuffer[Active_Window][Editor_Cur+ins2]='\r';
|
---|
494 | }else if(Editor_RetMode==MAC){
|
---|
495 | TextBuffer[Active_Window][Editor_Cur+ins2]='\n';
|
---|
496 | }
|
---|
497 | goto common;
|
---|
498 | case 3: // Tabulation.
|
---|
499 | TextBuffer[Active_Window][Editor_Cur+ins2]='\t';
|
---|
500 | goto common;
|
---|
501 | case 4: // Space.
|
---|
502 | TextBuffer[Active_Window][Editor_Cur+ins2]=' ';
|
---|
503 | goto common;
|
---|
504 | case 5: // Any Char.
|
---|
505 | TextBuffer[Active_Window][Editor_Cur+ins2]=KEY[KeyBoard_Cur];
|
---|
506 | goto common;
|
---|
507 | common:
|
---|
508 | TextBuffer[Active_Window][Editor_Cur+ins3]='\0';
|
---|
509 | strcat(TextBuffer[Active_Window], TextBuffer[TMP]+(Editor_Cur+ins4));
|
---|
510 | //memset(TextBuffer[TMP], 0, TextSize[Active_Window]+256); // 256 To Avoid Crash 256???
|
---|
511 | free(TextBuffer[TMP]);
|
---|
512 | Editor_Cur+=ins5, TextSize[Active_Window]+=ins1;
|
---|
513 | t=0;
|
---|
514 | break;
|
---|
515 | }
|
---|
516 | }
|
---|
517 | //------------------------------
|
---|
518 | //endfunc Virt_KeyBoard_Entry
|
---|
519 | //--------------------------------------------------------------
|
---|
520 | int KeyBoard_Entry(void)
|
---|
521 | {
|
---|
522 | int i, ret=0, Operation;
|
---|
523 | unsigned char KeyPress;
|
---|
524 |
|
---|
525 | Operation=0;
|
---|
526 |
|
---|
527 | if(PS2KbdRead(&KeyPress)) { //KeyBoard Response Section.
|
---|
528 |
|
---|
529 | ret=1; // Equal To event |= pad command.
|
---|
530 |
|
---|
531 | if(KeyPress == PS2KBD_ESCAPE_KEY) {
|
---|
532 | PS2KbdRead(&KeyPress);
|
---|
533 | if(KeyPress)
|
---|
534 | t=0;
|
---|
535 | if(KeyPress == 0x29){ // Key Right.
|
---|
536 | if(Editor_Cur<Editor_nChar && TextBuffer[Active_Window][Editor_Cur]!='\0')
|
---|
537 | Editor_Cur++;
|
---|
538 | }else if(KeyPress == 0x2A){ // Key Left.
|
---|
539 | if(Editor_Cur>0)
|
---|
540 | Editor_Cur--;
|
---|
541 | }else if(KeyPress == 0x2C){ // Key Up.
|
---|
542 | if(Editor_Cur>0)
|
---|
543 | Editor_PushRows++;
|
---|
544 | }else if(KeyPress == 0x2B){ // Key Down.
|
---|
545 | if(Editor_Cur<Editor_nChar && TextBuffer[Active_Window][Editor_Cur]!='\0')
|
---|
546 | Editor_PushRows--;
|
---|
547 | }else if(KeyPress == 0x24) // Key Home.
|
---|
548 | Editor_Home=1;
|
---|
549 | else if(KeyPress == 0x27) // Key End.
|
---|
550 | Editor_End=1;
|
---|
551 | else if(KeyPress == 0x25){ // Key PgUp.
|
---|
552 | if(Editor_Cur>0)
|
---|
553 | Editor_PushRows += 1*(Rows_Num-1);
|
---|
554 | }else if(KeyPress == 0x28){ // Key PgDn.
|
---|
555 | if(Editor_Cur<Editor_nChar && TextBuffer[Active_Window][Editor_Cur]!='\0')
|
---|
556 | Editor_PushRows -= 1*(Rows_Num-1);
|
---|
557 | }else if(KeyPress == 0x23) // Key Insert.
|
---|
558 | Editor_Insert = !Editor_Insert;
|
---|
559 | else if(KeyPress == 0x26){ // Key Delete.
|
---|
560 | if(Editor_Cur<Editor_nChar){
|
---|
561 | if( TextMode[Active_Window]==OTHER
|
---|
562 | && TextBuffer[Active_Window][Editor_Cur]=='\n'
|
---|
563 | && Editor_Cur>0
|
---|
564 | && TextBuffer[Active_Window][Editor_Cur-1]=='\r'
|
---|
565 | ){
|
---|
566 | Editor_Cur -= 1; //Delete at LF of CRLF must work at CR instead
|
---|
567 | }
|
---|
568 | if(Mark[MARK_ON]){
|
---|
569 | Mark[MARK_OUT]=Editor_Cur;
|
---|
570 | if(Mark[MARK_OUT]<Mark[MARK_IN]){
|
---|
571 | Mark[MARK_TMP]=Mark[MARK_IN];
|
---|
572 | Mark[MARK_IN]=Mark[MARK_OUT];
|
---|
573 | Mark[MARK_OUT]=Mark[MARK_TMP];
|
---|
574 | }else if(Mark[MARK_IN]==Mark[MARK_OUT])
|
---|
575 | goto abort;
|
---|
576 | Mark[MARK_SIZE]=Mark[MARK_OUT]-Mark[MARK_IN];
|
---|
577 | del1= -Mark[MARK_SIZE], del2=0, del3= -Mark[MARK_SIZE], del4= -Mark[MARK_SIZE];
|
---|
578 | Mark[MARK_ON]=0;
|
---|
579 | }else if(TextMode[Active_Window]==OTHER
|
---|
580 | && TextBuffer[Active_Window][Editor_Cur]=='\r'
|
---|
581 | && TextBuffer[Active_Window][Editor_Cur+1]=='\n'
|
---|
582 | ){ //Delete at CRLF
|
---|
583 | del1=0, del2=2, del3=0, del4=-2; //delete CRLF
|
---|
584 | }else if(TextMode[Active_Window]==OTHER && TextBuffer[Active_Window][Editor_Cur]=='\n'){
|
---|
585 | del1=-1, del2=1, del3=-1, del4=-2;
|
---|
586 | }else{
|
---|
587 | del1=0, del2=1, del3=0, del4=-1; //delete single char
|
---|
588 | }
|
---|
589 | Operation=-1;
|
---|
590 | }
|
---|
591 | }else if(KeyPress == 0x01){ // Key F1 MENU.
|
---|
592 | ret=2;
|
---|
593 | }else if(KeyPress == 0x1B){ // Key Escape EXIT Editor.
|
---|
594 | ret=3;
|
---|
595 | }
|
---|
596 | }else{
|
---|
597 | if(KeyPress == 0x12){ // Key Ctrl+r Return Mode CR/LF Or LF Or CR.
|
---|
598 | if((Editor_RetMode++)>=4)
|
---|
599 | Editor_RetMode=OTHER;
|
---|
600 | }else if(KeyPress == 0x02){ // Key Ctrl+b MARK.
|
---|
601 | Mark[MARK_ON]=!Mark[MARK_ON];
|
---|
602 | if(Mark[MARK_ON]){
|
---|
603 | if( TextMode[Active_Window]==OTHER
|
---|
604 | && TextBuffer[Active_Window][Editor_Cur]=='\n'
|
---|
605 | && Editor_Cur>0
|
---|
606 | && TextBuffer[Active_Window][Editor_Cur-1]=='\r'
|
---|
607 | ){
|
---|
608 | Editor_Cur -= 1; //Marking at LF of CRLF must start at CR instead
|
---|
609 | }
|
---|
610 | if(Mark[MARK_COPY] || Mark[MARK_CUT])
|
---|
611 | free(TextBuffer[EDIT]);
|
---|
612 | Mark[MARK_ON]=1, Mark[MARK_COPY]=0, Mark[MARK_CUT]=0,
|
---|
613 | Mark[MARK_IN]=0, Mark[MARK_OUT]=0, Mark[MARK_TMP]=0,
|
---|
614 | Mark[MARK_SIZE]=0, Mark[MARK_PRINT]=0, Mark[MARK_COLOR]=0;
|
---|
615 | Mark[MARK_IN]=Mark[MARK_OUT]=Editor_Cur;
|
---|
616 | }
|
---|
617 | Mark[MARK_START]=1;
|
---|
618 | //ends Key Ctrl+b MARK.
|
---|
619 | }else if(KeyPress == 0x03){ // Key Ctrl+c COPY.
|
---|
620 | if( TextMode[Active_Window]==OTHER
|
---|
621 | && TextBuffer[Active_Window][Editor_Cur]=='\n'
|
---|
622 | && Editor_Cur>0
|
---|
623 | && TextBuffer[Active_Window][Editor_Cur-1]=='\r'
|
---|
624 | ){
|
---|
625 | Editor_Cur += 1; //Mark end at LF of CRLF must include LF as well
|
---|
626 | }
|
---|
627 | if(Mark[MARK_ON]){
|
---|
628 | Mark[MARK_OUT]=Editor_Cur;
|
---|
629 | if(Mark[MARK_OUT]<Mark[MARK_IN]){
|
---|
630 | Mark[MARK_TMP]=Mark[MARK_IN];
|
---|
631 | Mark[MARK_IN]=Mark[MARK_OUT];
|
---|
632 | Mark[MARK_OUT]=Mark[MARK_TMP];
|
---|
633 | }else if(Mark[MARK_IN]==Mark[MARK_OUT])
|
---|
634 | goto abort;
|
---|
635 | if(Mark[MARK_COPY] || Mark[MARK_CUT])
|
---|
636 | free(TextBuffer[EDIT]);
|
---|
637 | Mark[MARK_SIZE]=Mark[MARK_OUT]-Mark[MARK_IN];
|
---|
638 | TextBuffer[EDIT] = malloc(Mark[MARK_SIZE]+256); // 256 To Avoid Crash 256???
|
---|
639 | for(i=0; i<Mark[MARK_SIZE]; i++)
|
---|
640 | TextBuffer[EDIT][i]=TextBuffer[Active_Window][i+Mark[MARK_IN]];
|
---|
641 | Mark[MARK_COPY]=1, Mark[MARK_CUT]=0, Mark[MARK_ON]=0, Mark[MARK_TMP]=0;
|
---|
642 | }
|
---|
643 | //ends Key Ctrl+c COPY.
|
---|
644 | }else if(KeyPress == 0x18){ // Key Ctrl+x CUT.
|
---|
645 | if(Mark[MARK_ON]){
|
---|
646 | if( TextMode[Active_Window]==OTHER
|
---|
647 | && TextBuffer[Active_Window][Editor_Cur]=='\n'
|
---|
648 | && Editor_Cur>0
|
---|
649 | && TextBuffer[Active_Window][Editor_Cur-1]=='\r'
|
---|
650 | ){
|
---|
651 | Editor_Cur += 1; //Mark end at LF of CRLF must include LF as well
|
---|
652 | }
|
---|
653 | Mark[MARK_OUT]=Editor_Cur;
|
---|
654 | if(Mark[MARK_OUT]<Mark[MARK_IN]){
|
---|
655 | Mark[MARK_TMP]=Mark[MARK_IN];
|
---|
656 | Mark[MARK_IN]=Mark[MARK_OUT];
|
---|
657 | Mark[MARK_OUT]=Mark[MARK_TMP];
|
---|
658 | }else if(Mark[MARK_IN]==Mark[MARK_OUT])
|
---|
659 | goto abort;
|
---|
660 | if(Mark[MARK_COPY] || Mark[MARK_CUT])
|
---|
661 | free(TextBuffer[EDIT]);
|
---|
662 | Mark[MARK_SIZE]=Mark[MARK_OUT]-Mark[MARK_IN];
|
---|
663 | TextBuffer[EDIT] = malloc(Mark[MARK_SIZE]+256); // 256 To Avoid Crash 256???
|
---|
664 | for(i=0; i<Mark[MARK_SIZE]; i++)
|
---|
665 | TextBuffer[EDIT][i]=TextBuffer[Active_Window][i+Mark[MARK_IN]];
|
---|
666 | del1= -Mark[MARK_SIZE], del2=0, del3= -Mark[MARK_SIZE], del4= -Mark[MARK_SIZE];
|
---|
667 | Mark[MARK_CUT]=1, Mark[MARK_COPY]=0, Mark[MARK_ON]=0, Mark[MARK_TMP]=0;
|
---|
668 | Operation=-2;
|
---|
669 | }
|
---|
670 | //ends Key Ctrl+x CUT.
|
---|
671 | }else if(KeyPress == 0x16){ // Key Ctrl+v PASTE.
|
---|
672 | if( Mark[MARK_COPY] || Mark[MARK_CUT]){
|
---|
673 | if(TextMode[Active_Window]==OTHER && TextBuffer[Active_Window][Editor_Cur]=='\n'){
|
---|
674 | Editor_Cur-=1;
|
---|
675 | Mark[MARK_SIZE]-=1;
|
---|
676 | }
|
---|
677 | ins1=Mark[MARK_SIZE], ins2=Mark[MARK_SIZE], ins3=Mark[MARK_SIZE], ins4=0, ins5=Mark[MARK_SIZE];
|
---|
678 | Operation=1;
|
---|
679 | }
|
---|
680 | //ends Key Ctrl+v PASTE.
|
---|
681 | }else if(KeyPress == 0x07){ // Key BackSpace.
|
---|
682 | if(Editor_Cur>0){
|
---|
683 | if( TextMode[Active_Window]==OTHER
|
---|
684 | && TextBuffer[Active_Window][Editor_Cur]=='\n'
|
---|
685 | && TextBuffer[Active_Window][Editor_Cur-1]=='\r'
|
---|
686 | ){
|
---|
687 | Editor_Cur += 1; //Backspace at LF of CRLF must work after LF
|
---|
688 | }
|
---|
689 | if(Mark[MARK_ON]){
|
---|
690 | Mark[MARK_OUT]=Editor_Cur;
|
---|
691 | if(Mark[MARK_OUT]<Mark[MARK_IN]){
|
---|
692 | Mark[MARK_TMP]=Mark[MARK_IN];
|
---|
693 | Mark[MARK_IN]=Mark[MARK_OUT];
|
---|
694 | Mark[MARK_OUT]=Mark[MARK_TMP];
|
---|
695 | }else if(Mark[MARK_IN]==Mark[MARK_OUT])
|
---|
696 | goto abort;
|
---|
697 | Mark[MARK_SIZE]=Mark[MARK_OUT]-Mark[MARK_IN];
|
---|
698 | del1= -Mark[MARK_SIZE], del2=0, del3= -Mark[MARK_SIZE], del4= -Mark[MARK_SIZE];
|
---|
699 | Mark[MARK_ON]=0;
|
---|
700 | }else if(TextMode[Active_Window]==OTHER
|
---|
701 | && TextBuffer[Active_Window][Editor_Cur-1]=='\n'
|
---|
702 | && Editor_Cur>1
|
---|
703 | && TextBuffer[Active_Window][Editor_Cur-2]=='\r'){
|
---|
704 | del1=-2, del2=0, del3=-2, del4=-2; //Backspace CRLF
|
---|
705 | }else{
|
---|
706 | del1=-1, del2=0, del3=-1, del4=-1; //Backspace single char
|
---|
707 | }
|
---|
708 | Operation=-3;
|
---|
709 | }
|
---|
710 | //ends Key BackSpace.
|
---|
711 | }else if(KeyPress == 0x0A){ // Key Return.
|
---|
712 |
|
---|
713 | if( TextMode[Active_Window]==OTHER
|
---|
714 | && TextBuffer[Active_Window][Editor_Cur]=='\n'
|
---|
715 | && Editor_Cur>0
|
---|
716 | && TextBuffer[Active_Window][Editor_Cur-1]=='\r'
|
---|
717 | ){
|
---|
718 | Editor_Cur -= 1; //Entry at LF of CRLF must work at CR instead
|
---|
719 | }
|
---|
720 | if(Editor_Insert || TextBuffer[Active_Window][Editor_Cur]=='\0')
|
---|
721 | if(Editor_RetMode==OTHER)
|
---|
722 | ins1=2, ins2=0, ins3=2, ins4=0, ins5=2; //Insert CRLF
|
---|
723 | else
|
---|
724 | ins1=1, ins2=0, ins3=1, ins4=0, ins5=1; //Insert LF/CR
|
---|
725 | else
|
---|
726 | if( TextMode[Active_Window]==OTHER
|
---|
727 | && TextBuffer[Active_Window][Editor_Cur]=='\r'
|
---|
728 | && TextBuffer[Active_Window][Editor_Cur+1]=='\n'
|
---|
729 | ){ //OWrite Return at CRLF
|
---|
730 | if(Editor_RetMode==OTHER)
|
---|
731 | ins1=0, ins2=0, ins3=2, ins4=2, ins5=2; //OWrite CRLF at CRLF
|
---|
732 | else
|
---|
733 | ins1=0, ins2=0, ins3=1, ins4=2, ins5=1; //OWrite LF/CR at CRLF
|
---|
734 | }else{ //OWrite return at normal char
|
---|
735 | if(Editor_RetMode==OTHER)
|
---|
736 | ins1=1, ins2=0, ins3=2, ins4=1, ins5=2; //OWrite CRLF at char
|
---|
737 | else
|
---|
738 | ins1=0, ins2=0, ins3=1, ins4=1, ins5=1; //OWrite LF/CR at char
|
---|
739 | }
|
---|
740 | Operation=2;
|
---|
741 | //ends Key Return.
|
---|
742 | }else{ // All Other Keys.
|
---|
743 | if( TextMode[Active_Window]==OTHER
|
---|
744 | && TextBuffer[Active_Window][Editor_Cur]=='\n'
|
---|
745 | && Editor_Cur>0
|
---|
746 | && TextBuffer[Active_Window][Editor_Cur-1]=='\r'
|
---|
747 | ){
|
---|
748 | Editor_Cur -= 1; //Entry at LF of CRLF must work at CR instead
|
---|
749 | }
|
---|
750 | if(Editor_Insert || TextBuffer[Active_Window][Editor_Cur]=='\0'){
|
---|
751 | ins1=1, ins2=0, ins3=1, ins4=0, ins5=1; //Insert char normally
|
---|
752 | }else{
|
---|
753 | if(TextMode[Active_Window]==OTHER
|
---|
754 | && TextBuffer[Active_Window][Editor_Cur]=='\r'
|
---|
755 | && TextBuffer[Active_Window][Editor_Cur+1]=='\n'
|
---|
756 | ){ //OWrite char at CRLF
|
---|
757 | ins1=0, ins2= 0, ins3=1, ins4= 2, ins5= 1; //OWrite at CR of CRLF
|
---|
758 | }else{ //OWrite return at normal char
|
---|
759 | ins1=0, ins2= 0, ins3=1, ins4= 1, ins5= 1; //OWrite normal char
|
---|
760 | }
|
---|
761 | }
|
---|
762 | Operation=3;
|
---|
763 | }
|
---|
764 | }
|
---|
765 |
|
---|
766 | if(Operation>0){ // Perform Add Char / Paste. Can Be Simplify???
|
---|
767 | TextBuffer[TMP] = malloc(TextSize[Active_Window]+ins1+256); // 256 To Avoid Crash 256???
|
---|
768 | strcpy(TextBuffer[TMP], TextBuffer[Active_Window]);
|
---|
769 | //memset(TextBuffer[Active_Window], 0, TextSize[Active_Window]+256); // 256 To Avoid Crash 256??? free(TextBuffer[Active_Window]);
|
---|
770 | TextBuffer[Active_Window] = malloc(TextSize[Active_Window]+ins1+256); // 256 To Avoid Crash 256???
|
---|
771 | strcpy(TextBuffer[Active_Window], TextBuffer[TMP]);
|
---|
772 | }
|
---|
773 |
|
---|
774 | switch(Operation){
|
---|
775 | case 0:
|
---|
776 | break;
|
---|
777 | case -1:// Perform Del Char / Cut. Can Be Simplify???
|
---|
778 | case -2:
|
---|
779 | case -3:
|
---|
780 | TextBuffer[TMP] = malloc(TextSize[Active_Window]+256); // 256 To Avoid Crash 256???
|
---|
781 | strcpy(TextBuffer[TMP], TextBuffer[Active_Window]);
|
---|
782 | TextBuffer[Active_Window][Editor_Cur+del1]='\0';
|
---|
783 | strcat(TextBuffer[Active_Window], TextBuffer[TMP]+(Editor_Cur+del2));
|
---|
784 | strcpy(TextBuffer[TMP], TextBuffer[Active_Window]);
|
---|
785 | //memset(TextBuffer[Active_Window], 0, TextSize[Active_Window]+256); // 256 To Avoid Crash 256???
|
---|
786 | free(TextBuffer[Active_Window]);
|
---|
787 | TextBuffer[Active_Window] = malloc(TextSize[Active_Window]+del3+256); // 256 To Avoid Crash 256???
|
---|
788 | strcpy(TextBuffer[Active_Window], TextBuffer[TMP]);
|
---|
789 | //memset(TextBuffer[TMP], 0, TextSize[Active_Window]+256); // 256 To Avoid Crash 256???
|
---|
790 | free(TextBuffer[TMP]);
|
---|
791 | Editor_Cur+=del3, TextSize[Active_Window]+=del4;
|
---|
792 | t=0;
|
---|
793 | break;
|
---|
794 | case 1: // Paste.
|
---|
795 | for(i=0; i<ins2; i++)
|
---|
796 | TextBuffer[Active_Window][i+Editor_Cur]=TextBuffer[EDIT][i];
|
---|
797 | goto common;
|
---|
798 | case 2: // Return.
|
---|
799 | if(Editor_RetMode==OTHER){
|
---|
800 | TextBuffer[Active_Window][Editor_Cur+ins2]='\r';
|
---|
801 | TextBuffer[Active_Window][Editor_Cur+ins2+1]='\n';
|
---|
802 | }else if(Editor_RetMode==UNIX){
|
---|
803 | TextBuffer[Active_Window][Editor_Cur+ins2]='\r';
|
---|
804 | }else if(Editor_RetMode==MAC){
|
---|
805 | TextBuffer[Active_Window][Editor_Cur+ins2]='\n';
|
---|
806 | }
|
---|
807 | goto common;
|
---|
808 | case 3: // Normal characters
|
---|
809 | TextBuffer[Active_Window][Editor_Cur+ins2]=KeyPress;
|
---|
810 | common:
|
---|
811 | TextBuffer[Active_Window][Editor_Cur+ins3]='\0';
|
---|
812 | strcat(TextBuffer[Active_Window], TextBuffer[TMP]+(Editor_Cur+ins4));
|
---|
813 | //memset(TextBuffer[TMP], 0, TextSize[Active_Window]+256); // 256 To Avoid Crash 256???
|
---|
814 | free(TextBuffer[TMP]);
|
---|
815 | Editor_Cur+=ins5, TextSize[Active_Window]+=ins1;
|
---|
816 | t=0;
|
---|
817 | break;
|
---|
818 | }
|
---|
819 |
|
---|
820 | abort:
|
---|
821 | KeyPress = '\0';
|
---|
822 | } //ends if(PS2KbdRead(&KeyPress)).
|
---|
823 | return ret;
|
---|
824 | }
|
---|
825 | //------------------------------
|
---|
826 | //endfunc KeyBoard_Entry
|
---|
827 | //--------------------------------------------------------------
|
---|
828 | void Editor_Rules(void)
|
---|
829 | {
|
---|
830 | int i;
|
---|
831 |
|
---|
832 | Editor_nChar=TextSize[Active_Window]+1;
|
---|
833 |
|
---|
834 | Top_Height=0, Top_Width =0;
|
---|
835 | Editor_nRowsNum=0, Editor_nCharRows=1, Editor_nRowsTop=1;
|
---|
836 | for(i=0; i<Editor_nChar; i++) // Rows Number, Width, Top, Calucations.
|
---|
837 | {
|
---|
838 | if((TextMode[Active_Window]==UNIX && TextBuffer[Active_Window][i]=='\r') || // Text Mode UNIX End Line.
|
---|
839 | TextBuffer[Active_Window][i]=='\n' || // Text Mode MAC Or OTHER End Line.
|
---|
840 | Editor_nCharRows>=Rows_Width || // Line Width > Screen Width.
|
---|
841 | TextBuffer[Active_Window][i]=='\0'){ // End Text.
|
---|
842 | if(i<Editor_Cur){
|
---|
843 | if((Editor_nRowsTop += 1)>Rows_Num){
|
---|
844 | Top_Width += Editor_nRowsWidth[Top_Height];
|
---|
845 | Top_Height += 1;
|
---|
846 | }
|
---|
847 | }
|
---|
848 | Editor_nRowsWidth[Editor_nRowsNum]=Editor_nCharRows;
|
---|
849 | Editor_nRowsNum++;
|
---|
850 | Editor_nCharRows=0;
|
---|
851 | }
|
---|
852 | if(TextBuffer[Active_Window][i]=='\0') // End Text Stop Calculations.
|
---|
853 | break;
|
---|
854 | Editor_nCharRows++;
|
---|
855 | }
|
---|
856 |
|
---|
857 | if(Editor_Home){
|
---|
858 | Tmp_Cur=0;
|
---|
859 | for(i=0; i<Editor_nRowsNum; i++) // Home Rules.
|
---|
860 | {
|
---|
861 | if((Tmp_Cur += Editor_nRowsWidth[i])>=Editor_Cur+1)
|
---|
862 | break;
|
---|
863 | }
|
---|
864 | Tmp_Cur -= (Editor_nRowsWidth[i]-1);
|
---|
865 | Editor_Cur = Tmp_Cur-1;
|
---|
866 | Editor_Home=0;
|
---|
867 | }
|
---|
868 |
|
---|
869 | if(Editor_End){
|
---|
870 | Tmp_Cur=0;
|
---|
871 | for(i=0; i<Editor_nRowsNum; i++) // End Rules.
|
---|
872 | {
|
---|
873 | if((Tmp_Cur += Editor_nRowsWidth[i])>=Editor_Cur+1)
|
---|
874 | break;
|
---|
875 | }
|
---|
876 | Editor_Cur = Tmp_Cur-1;
|
---|
877 | Editor_End=0;
|
---|
878 | }
|
---|
879 |
|
---|
880 | if(Editor_PushRows<0){
|
---|
881 | Tmp_Cur=0;
|
---|
882 | for(i=0; i<Editor_nRowsNum; i++) // Line / Page Up Rules.
|
---|
883 | {
|
---|
884 | if((Tmp_Cur += Editor_nRowsWidth[i])>=Editor_Cur+1)
|
---|
885 | break;
|
---|
886 | }
|
---|
887 | Tmp_Cur -= (Editor_nRowsWidth[i]-1);
|
---|
888 | if(Editor_nRowsWidth[i+1]<=((Editor_Cur+1)-(Tmp_Cur-1)))
|
---|
889 | Editor_Cur = Tmp_Cur+Editor_nRowsWidth[i]+Editor_nRowsWidth[i+1]-1-1;
|
---|
890 | else
|
---|
891 | Editor_Cur = Tmp_Cur+Editor_nRowsWidth[i]+((Editor_Cur+1)-Tmp_Cur)-1;
|
---|
892 |
|
---|
893 | if(Editor_PushRows++ >= 0)
|
---|
894 | Editor_PushRows=0;
|
---|
895 |
|
---|
896 | if(Editor_Cur+1>=Editor_nChar && TextBuffer[Active_Window][Editor_Cur]!='\0'){
|
---|
897 | Editor_Cur=Editor_nChar-1;
|
---|
898 | Editor_PushRows=0;
|
---|
899 | }
|
---|
900 | }
|
---|
901 |
|
---|
902 | if(Editor_PushRows>0){
|
---|
903 | Tmp_Cur=0;
|
---|
904 | for(i=0; i<Editor_nRowsNum; i++) // Line / Page Down Rules.
|
---|
905 | {
|
---|
906 | if((Tmp_Cur += Editor_nRowsWidth[i])>=Editor_Cur+1)
|
---|
907 | break;
|
---|
908 | }
|
---|
909 | Tmp_Cur -= (Editor_nRowsWidth[i]-1);
|
---|
910 |
|
---|
911 | if(Editor_nRowsWidth[i-1]<=((Editor_Cur+1)-(Tmp_Cur-1)))
|
---|
912 | Editor_Cur = Tmp_Cur-1-1;
|
---|
913 | else
|
---|
914 | Editor_Cur = Tmp_Cur-Editor_nRowsWidth[i-1]+((Editor_Cur+1)-Tmp_Cur)-1;
|
---|
915 |
|
---|
916 | if(Editor_PushRows-- <= 0)
|
---|
917 | Editor_PushRows=0;
|
---|
918 |
|
---|
919 | if(Editor_Cur<=0){
|
---|
920 | Editor_Cur=0;
|
---|
921 | Editor_PushRows=0;
|
---|
922 | }
|
---|
923 | }
|
---|
924 |
|
---|
925 | if(Editor_Cur >= Editor_nChar) // Max Char Number Rules.
|
---|
926 | Editor_Cur=Editor_nChar-1;
|
---|
927 |
|
---|
928 | if(Editor_Cur < 0) // Min Char Number Rules.
|
---|
929 | Editor_Cur=0;
|
---|
930 |
|
---|
931 | if(Mark[MARK_ON]){ // Mark Rules.
|
---|
932 | Mark[MARK_SIZE]=Editor_Cur-Mark[MARK_IN];
|
---|
933 | if(Mark[MARK_SIZE]>0){
|
---|
934 | Mark[MARK_PRINT]=Mark[MARK_SIZE];
|
---|
935 | if(Mark[MARK_IN]<Top_Width)
|
---|
936 | Mark[MARK_PRINT]=Editor_Cur-Top_Width;
|
---|
937 | }else if(Mark[MARK_SIZE]<0)
|
---|
938 | Mark[MARK_PRINT]=1;
|
---|
939 | else
|
---|
940 | Mark[MARK_PRINT]=0;
|
---|
941 | }
|
---|
942 |
|
---|
943 | }
|
---|
944 | //--------------------------------------------------------------
|
---|
945 | int Windows_Selector(void)
|
---|
946 | {
|
---|
947 | u64 color;
|
---|
948 | int x, y, i, Window_Sel=Active_Window;
|
---|
949 | int event, post_event=0;
|
---|
950 |
|
---|
951 | int Window_ch_w = 36; //Total characters in longest Window Name.
|
---|
952 | int Window_ch_h = 10; //Total number of Window Menu lines.
|
---|
953 | int wSprite_Y1 = 200; //Top edge of sprite.
|
---|
954 | int wSprite_X2 = SCREEN_WIDTH-35; //Right edge of sprite.
|
---|
955 | int wSprite_X1 = wSprite_X2-(Window_ch_w+3)*FONT_WIDTH-3; //Left edge of sprite.
|
---|
956 | int wSprite_Y2 = wSprite_Y1+(Window_ch_h+1)*FONT_HEIGHT+3; //Bottom edge of sprite.
|
---|
957 |
|
---|
958 | char tmp[64];
|
---|
959 |
|
---|
960 | event = 1; //event = initial entry.
|
---|
961 | while(1){
|
---|
962 | //Pad response section.
|
---|
963 | waitPadReady(0, 0);
|
---|
964 | if(readpad()){
|
---|
965 | if(new_pad & PAD_UP){
|
---|
966 | event |= 2; //event |= valid pad command.
|
---|
967 | if((Window_Sel--)<=0)
|
---|
968 | Window_Sel=9;
|
---|
969 | }else if(new_pad & PAD_DOWN){
|
---|
970 | event |= 2; //event |= valid pad command.
|
---|
971 | if((Window_Sel++)>=9)
|
---|
972 | Window_Sel=0;
|
---|
973 | }else if((new_pad & PAD_TRIANGLE)
|
---|
974 | || (!swapKeys && new_pad & PAD_CROSS)
|
---|
975 | || (swapKeys && new_pad & PAD_CIRCLE) ){
|
---|
976 | return -1;
|
---|
977 | }else if((swapKeys && new_pad & PAD_CROSS)
|
---|
978 | || (!swapKeys && new_pad & PAD_CIRCLE) ){
|
---|
979 | event |= 2; //event |= valid pad command.
|
---|
980 | break;
|
---|
981 | }
|
---|
982 | }
|
---|
983 |
|
---|
984 | if(event||post_event){ //NB: We need to update two frame buffers per event.
|
---|
985 |
|
---|
986 | //Display section.
|
---|
987 | drawPopSprite(setting->color[0],
|
---|
988 | wSprite_X1, wSprite_Y1,
|
---|
989 | wSprite_X2, wSprite_Y2);
|
---|
990 | drawFrame(wSprite_X1, wSprite_Y1, wSprite_X2, wSprite_Y2, setting->color[1]);
|
---|
991 |
|
---|
992 | for(i=0,y=wSprite_Y1+FONT_HEIGHT/2; i<10; i++){
|
---|
993 | if(Window_Sel==i)
|
---|
994 | color = setting->color[2];
|
---|
995 | else
|
---|
996 | color = setting->color[3];
|
---|
997 |
|
---|
998 | if(!Window[i][OPENED])
|
---|
999 | printXY(LNG(Free_Window), wSprite_X1+2*FONT_WIDTH, y, color, TRUE, 0);
|
---|
1000 | else if(Window[i][CREATED])
|
---|
1001 | printXY(LNG(Window_Not_Yet_Saved), wSprite_X1+2*FONT_WIDTH, y, color, TRUE, 0);
|
---|
1002 | else if(Window[i][OPENED])
|
---|
1003 | printXY(Path[i], wSprite_X1+2*FONT_WIDTH, y, color, TRUE, 0);
|
---|
1004 |
|
---|
1005 | y+=FONT_HEIGHT;
|
---|
1006 | }
|
---|
1007 |
|
---|
1008 | if(Window_Sel<=10)
|
---|
1009 | drawChar(LEFT_CUR, wSprite_X1+FONT_WIDTH, wSprite_Y1+(FONT_HEIGHT/2+Window_Sel*FONT_HEIGHT), setting->color[3]);
|
---|
1010 |
|
---|
1011 | //Tooltip section.
|
---|
1012 | x = SCREEN_MARGIN;
|
---|
1013 | y = Menu_tooltip_y;
|
---|
1014 | drawSprite(setting->color[0],
|
---|
1015 | 0, y-1,
|
---|
1016 | SCREEN_WIDTH, y+16);
|
---|
1017 | if (swapKeys)
|
---|
1018 | sprintf(tmp, "ÿ1:%s ÿ0:%s ÿ3:%s", LNG(OK), LNG(Cancel), LNG(Back));
|
---|
1019 | else
|
---|
1020 | sprintf(tmp, "ÿ0:%s ÿ1:%s ÿ3:%s", LNG(OK), LNG(Cancel), LNG(Back));
|
---|
1021 | printXY(tmp, x, y, setting->color[2], TRUE, 0);
|
---|
1022 | }//ends if(event||post_event).
|
---|
1023 | drawScr();
|
---|
1024 | post_event = event;
|
---|
1025 | event = 0;
|
---|
1026 | }//ends while.
|
---|
1027 | return Window_Sel;
|
---|
1028 | }//ends Window_Selector.
|
---|
1029 | //--------------------------------------------------------------
|
---|
1030 | void Init(void)
|
---|
1031 | {
|
---|
1032 | int i;
|
---|
1033 |
|
---|
1034 | for(i=0; i<MAX_ENTRY; i++)
|
---|
1035 | Editor_nRowsWidth[i]=0;
|
---|
1036 |
|
---|
1037 | Editor_Cur=0, Tmp_Cur=0,
|
---|
1038 | Editor_nChar=0, Editor_nRowsNum=0,
|
---|
1039 | Editor_nCharRows=0, Editor_nRowsTop=0,
|
---|
1040 | Editor_PushRows=0, Editor_TextEnd=0;
|
---|
1041 |
|
---|
1042 | Top_Width=0, Top_Height=0;
|
---|
1043 |
|
---|
1044 | Rows_Width = (SCREEN_WIDTH-SCREEN_MARGIN-LINE_THICKNESS-26-Menu_start_x)/FONT_WIDTH;
|
---|
1045 | Rows_Num = (Menu_end_y-Menu_start_y)/FONT_HEIGHT;
|
---|
1046 |
|
---|
1047 | KeyBoard_Cur=2, KeyBoard_Active=0,
|
---|
1048 | Editor_Insert=1, Editor_RetMode=TextMode[Active_Window];
|
---|
1049 | Editor_Home=0, Editor_End=0;
|
---|
1050 |
|
---|
1051 | del1=0, del2=0, del3=0, del4=0;
|
---|
1052 | ins1=0, ins2=0, ins3=0, ins4=0, ins5=0;
|
---|
1053 |
|
---|
1054 | if(Mark[MARK_ON]){
|
---|
1055 | Mark[MARK_ON]=0, Mark[MARK_IN]=0,
|
---|
1056 | Mark[MARK_OUT]=0, Mark[MARK_TMP]=0,
|
---|
1057 | Mark[MARK_PRINT]=0, Mark[MARK_COLOR]=0;
|
---|
1058 | }
|
---|
1059 |
|
---|
1060 | }
|
---|
1061 | //--------------------------------------------------------------
|
---|
1062 | int New(int Win)
|
---|
1063 | {
|
---|
1064 | int ret=0;
|
---|
1065 |
|
---|
1066 | TextSize[Win]=1;
|
---|
1067 |
|
---|
1068 | if( TextSize[Win] ){
|
---|
1069 | if( ( TextBuffer[Win] = malloc( TextSize[Win]+256 ) ) > 0 ){
|
---|
1070 | TextBuffer[Win][0]='\0';
|
---|
1071 | TextMode[Win]=OTHER;
|
---|
1072 | Window[Win][CREATED]=1, Window[Win][OPENED]=1, Window[Win][SAVED]=0;
|
---|
1073 | Init();
|
---|
1074 | ret=1;
|
---|
1075 | }
|
---|
1076 | }
|
---|
1077 |
|
---|
1078 | if(ret){
|
---|
1079 | drawMsg(LNG(File_Created));
|
---|
1080 | }else{
|
---|
1081 | drawMsg(LNG(Failed_Creating_File));
|
---|
1082 | }
|
---|
1083 |
|
---|
1084 | WaitTime=Timer();
|
---|
1085 | while(Timer()<WaitTime+1500); // print operation result during 1.5 sec.
|
---|
1086 |
|
---|
1087 | return ret;
|
---|
1088 | }
|
---|
1089 | //--------------------------------------------------------------
|
---|
1090 | int Open(int Win)
|
---|
1091 | {
|
---|
1092 | int fd, i, ret=0;
|
---|
1093 | char filePath[MAX_PATH];
|
---|
1094 |
|
---|
1095 | getFilePath(Path[Win], TEXT_CNF); // No Filtering, Be Careful.
|
---|
1096 |
|
---|
1097 | if(Path[Win][0]=='\0')
|
---|
1098 | goto abort;
|
---|
1099 |
|
---|
1100 | genFixPath(Path[Win], filePath);
|
---|
1101 | fd = genOpen( filePath, O_RDONLY );
|
---|
1102 |
|
---|
1103 | if( fd >= 0 ) {
|
---|
1104 | TextSize[Win] = genLseek ( fd, 0, SEEK_END );
|
---|
1105 | genLseek ( fd, 0, SEEK_SET );
|
---|
1106 |
|
---|
1107 | if( TextSize[Win] && TextSize[Win] <= 512*1024 ){ // Limit Text Size To 512Kb???
|
---|
1108 | if( ( TextBuffer[Win] = malloc( TextSize[Win]+256 ) ) > 0 ){ // 256 To Avoid Crash 256???
|
---|
1109 | memset(TextBuffer[Win], 0, TextSize[Win]+256); // 256 To Avoid Crash 256???
|
---|
1110 | genRead( fd, TextBuffer[Win], TextSize[Win] );
|
---|
1111 |
|
---|
1112 | for(i=0; i<TextSize[Win]; i++){ // Scan For Text Mode.
|
---|
1113 | if(TextBuffer[Win][i-1]!='\r' && TextBuffer[Win][i]=='\n'){
|
---|
1114 | // Mode MAC Only LF At Line End.
|
---|
1115 | TextMode[Win]=MAC;
|
---|
1116 | break;
|
---|
1117 | }else if(TextBuffer[Win][i]=='\r' && TextBuffer[Win][i+1]=='\n'){
|
---|
1118 | // Mode OTHER CR/LF At Line End.
|
---|
1119 | TextMode[Win]=OTHER;
|
---|
1120 | break;
|
---|
1121 | }else if(TextBuffer[Win][i]=='\r' && TextBuffer[Win][i+1]!='\n'){
|
---|
1122 | // Mode UNIX Only CR At Line End.
|
---|
1123 | TextMode[Win]=UNIX;
|
---|
1124 | break;
|
---|
1125 | }
|
---|
1126 | }
|
---|
1127 |
|
---|
1128 | Window[Win][OPENED]=1, Window[Win][SAVED]=0;
|
---|
1129 | Init();
|
---|
1130 | ret=1;
|
---|
1131 | }
|
---|
1132 | }
|
---|
1133 | }
|
---|
1134 |
|
---|
1135 | genClose( fd );
|
---|
1136 |
|
---|
1137 | if(ret){
|
---|
1138 | drawMsg(LNG(File_Opened));
|
---|
1139 | }else{
|
---|
1140 | abort:
|
---|
1141 | TextSize[Win]=0;
|
---|
1142 | drawMsg(LNG(Failed_Opening_File));
|
---|
1143 | }
|
---|
1144 |
|
---|
1145 | WaitTime=Timer();
|
---|
1146 | while(Timer()<WaitTime+1500); // print operation result during 1.5 sec.
|
---|
1147 |
|
---|
1148 | return ret;
|
---|
1149 | }
|
---|
1150 | //--------------------------------------------------------------
|
---|
1151 | void Close(int Win)
|
---|
1152 | {
|
---|
1153 | char msg[MAX_PATH];
|
---|
1154 |
|
---|
1155 | //memset(TextBuffer[Win], 0, TextSize[Win]+256); // 256 To Avoid Crash 256???
|
---|
1156 | free(TextBuffer[Win]);
|
---|
1157 |
|
---|
1158 | if(Window[Win][CREATED])
|
---|
1159 | strcpy(msg, LNG(File_Not_Yet_Saved_Closed));
|
---|
1160 | else
|
---|
1161 | sprintf(msg, LNG(File_Closed), Path[Win]);
|
---|
1162 |
|
---|
1163 | Path[Win][0]='\0';
|
---|
1164 |
|
---|
1165 | TextMode[Win]=0, TextSize[Win]=0, Window[Win][CREATED]=0, Window[Win][OPENED]=0, Window[Win][SAVED]=1;
|
---|
1166 |
|
---|
1167 | Init();
|
---|
1168 |
|
---|
1169 | drawMsg(msg);
|
---|
1170 |
|
---|
1171 | WaitTime=Timer();
|
---|
1172 | while(Timer()<WaitTime+1500); // print operation result during 1.5 sec.
|
---|
1173 | }
|
---|
1174 | //--------------------------------------------------------------
|
---|
1175 | void Save(int Win)
|
---|
1176 | {
|
---|
1177 | int fd, ret=0;
|
---|
1178 |
|
---|
1179 | char filePath[MAX_PATH];
|
---|
1180 |
|
---|
1181 | if(!strncmp(Path[Win], "cdfs", 4))
|
---|
1182 | goto abort;
|
---|
1183 | genFixPath(Path[Win], filePath);
|
---|
1184 |
|
---|
1185 | fd = genOpen( filePath, O_CREAT|O_WRONLY|O_TRUNC );
|
---|
1186 |
|
---|
1187 | if( fd >= 0 ) {
|
---|
1188 | if(TextMode[Win]==OTHER && TextBuffer[Win][TextSize[Win]]=='\n')
|
---|
1189 | genWrite(fd, TextBuffer[Win], TextSize[Win]-1);
|
---|
1190 | else
|
---|
1191 | genWrite(fd, TextBuffer[Win], TextSize[Win]);
|
---|
1192 | Window[Win][OPENED]=1, Window[Win][SAVED]=1;
|
---|
1193 | ret=1;
|
---|
1194 | }
|
---|
1195 |
|
---|
1196 | genClose( fd );
|
---|
1197 | if(!strncmp(filePath, "pfs", 3))
|
---|
1198 | unmountParty(filePath[3]-'0');
|
---|
1199 |
|
---|
1200 | if(ret){
|
---|
1201 | drawMsg(LNG(File_Saved));
|
---|
1202 | }else{
|
---|
1203 | abort:
|
---|
1204 | drawMsg(LNG(Failed_Saving_File));
|
---|
1205 | }
|
---|
1206 |
|
---|
1207 | WaitTime=Timer();
|
---|
1208 | while(Timer()<WaitTime+1500); // print operation result during 1.5 sec.
|
---|
1209 | }
|
---|
1210 | //--------------------------------------------------------------
|
---|
1211 | void Save_As(int Win)
|
---|
1212 | {
|
---|
1213 | int fd, ret=0;
|
---|
1214 | char tmp[MAX_PATH], oldPath[MAX_PATH], filePath[MAX_PATH];
|
---|
1215 | char *p;
|
---|
1216 |
|
---|
1217 | tmp[0]='\0', oldPath[0]='\0', filePath[0]='\0';
|
---|
1218 |
|
---|
1219 | if(Path[Win][0]!='\0'){
|
---|
1220 | strcpy(oldPath, Path[Win]);
|
---|
1221 | Path[Win][0]='\0';
|
---|
1222 | p=strrchr(oldPath, '/');
|
---|
1223 | if(p)
|
---|
1224 | strcpy(tmp, p+1);
|
---|
1225 | }
|
---|
1226 |
|
---|
1227 | getFilePath(Path[Win], DIR_CNF);
|
---|
1228 | if(Path[Win][0] == '\0')
|
---|
1229 | goto abort;
|
---|
1230 | if(!strncmp(Path[Win], "cdfs", 4))
|
---|
1231 | goto abort;
|
---|
1232 |
|
---|
1233 | drawMsg(LNG(Enter_File_Name));
|
---|
1234 |
|
---|
1235 | if(keyboard(tmp, 36)>0){
|
---|
1236 | //strcat(Path[Win], tmp); //This is what we want, but malfunctions for MC!
|
---|
1237 | //sprintf(&Path[Win][strlen(Path[Win])], "%s", tmp); //This always works
|
---|
1238 | strcpy(&Path[Win][strlen(Path[Win])], tmp); //And this one works too
|
---|
1239 | //Note that the strcat call SHOULD have done the same thing, but won't.
|
---|
1240 | } else goto abort;
|
---|
1241 |
|
---|
1242 | genFixPath(Path[Win], filePath);
|
---|
1243 |
|
---|
1244 | fd = genOpen( filePath, O_CREAT|O_WRONLY|O_TRUNC );
|
---|
1245 |
|
---|
1246 | if( fd >= 0 ) {
|
---|
1247 | if(TextMode[Win]==OTHER && TextBuffer[Win][TextSize[Win]]=='\n')
|
---|
1248 | genWrite(fd, TextBuffer[Win], TextSize[Win]-1);
|
---|
1249 | else
|
---|
1250 | genWrite(fd, TextBuffer[Win], TextSize[Win]);
|
---|
1251 | Window[Win][CREATED]=0, Window[Win][OPENED]=1, Window[Win][SAVED]=1;
|
---|
1252 | ret=1;
|
---|
1253 | genClose( fd );
|
---|
1254 | }
|
---|
1255 |
|
---|
1256 | if(!strncmp(filePath, "pfs", 3))
|
---|
1257 | unmountParty(filePath[3]-'0');
|
---|
1258 |
|
---|
1259 | if(ret){
|
---|
1260 | drawMsg(LNG(File_Saved));
|
---|
1261 | goto result_delay;
|
---|
1262 | }
|
---|
1263 |
|
---|
1264 | abort:
|
---|
1265 | if(oldPath[0]!='\0')
|
---|
1266 | strcpy(Path[Win], oldPath);
|
---|
1267 | drawMsg(LNG(Failed_Saving_File));
|
---|
1268 |
|
---|
1269 | result_delay:
|
---|
1270 | WaitTime=Timer();
|
---|
1271 | while(Timer()<WaitTime+1500); // display operation result during 1.5 sec.
|
---|
1272 | }
|
---|
1273 | //--------------------------------------------------------------
|
---|
1274 | void TextEditor(void)
|
---|
1275 | {
|
---|
1276 | char tmp[MAX_PATH], tmp1[MAX_PATH], tmp2[MAX_PATH];
|
---|
1277 | int ch;
|
---|
1278 | int x, y, y0, y1;
|
---|
1279 | int i=0, j, ret=0;
|
---|
1280 | int tmpLen=0;
|
---|
1281 | int event=1, post_event=0;
|
---|
1282 | int Editor_Start=0;
|
---|
1283 | u64 color;
|
---|
1284 | const int KEY_W=350,
|
---|
1285 | KEY_H=98,
|
---|
1286 | KEY_X=(SCREEN_WIDTH - KEY_W)/2,
|
---|
1287 | KEY_Y=(Menu_end_y - KEY_H);
|
---|
1288 | int KEY_LEN = strlen(KEY);
|
---|
1289 |
|
---|
1290 | tmp[0]='\0', tmp1[0]='\0', ch='\0';
|
---|
1291 |
|
---|
1292 | Active_Window=0, Num_Window=0;
|
---|
1293 |
|
---|
1294 | for(i=0; i<10; i++){
|
---|
1295 | Window[i][CREATED]=0;
|
---|
1296 | Window[i][OPENED]=0;
|
---|
1297 | Window[i][SAVED]=1;
|
---|
1298 | TextMode[i]=0;
|
---|
1299 | TextSize[i]=0;
|
---|
1300 | Path[i][0]='\0';
|
---|
1301 | }
|
---|
1302 |
|
---|
1303 | for(i=0; i<NUM_MARK; i++)
|
---|
1304 | Mark[i]=0;
|
---|
1305 |
|
---|
1306 | Init();
|
---|
1307 |
|
---|
1308 | t=0;
|
---|
1309 |
|
---|
1310 | event = 1; //event = initial entry.
|
---|
1311 |
|
---|
1312 | Rows_Width = (SCREEN_WIDTH-SCREEN_MARGIN-LINE_THICKNESS-26-Menu_start_x)/FONT_WIDTH;
|
---|
1313 | Rows_Num = (Menu_end_y-Menu_start_y)/FONT_HEIGHT;
|
---|
1314 |
|
---|
1315 | x = Menu_start_x;
|
---|
1316 | y = Menu_start_y;
|
---|
1317 |
|
---|
1318 | while(1){
|
---|
1319 |
|
---|
1320 | //Pad response section.
|
---|
1321 | waitPadReady(0, 0);
|
---|
1322 | if(readpad_no_KB()){
|
---|
1323 | if(new_pad){
|
---|
1324 | event |= 2; //event |= pad command.
|
---|
1325 | }
|
---|
1326 | if(!KeyBoard_Active){ // Pad Response Without KeyBoard.
|
---|
1327 | if(new_pad & PAD_UP){ // Text move up.
|
---|
1328 | if(Editor_Cur>0)
|
---|
1329 | Editor_PushRows++;
|
---|
1330 | }else if(new_pad & PAD_DOWN){ // Text move down.
|
---|
1331 | if(Editor_Cur<Editor_nChar && TextBuffer[Active_Window][Editor_Cur]!='\0')
|
---|
1332 | Editor_PushRows--;
|
---|
1333 | }else if(new_pad & PAD_LEFT){ // Text move left.
|
---|
1334 | if(Editor_Cur>0)
|
---|
1335 | Editor_Cur--;
|
---|
1336 | }else if(new_pad & PAD_RIGHT){ // Text move right.
|
---|
1337 | if(Editor_Cur<Editor_nChar && TextBuffer[Active_Window][Editor_Cur]!='\0')
|
---|
1338 | Editor_Cur++;
|
---|
1339 | }else if(new_pad & PAD_L2){ // Text move page up.
|
---|
1340 | if(Editor_Cur>0)
|
---|
1341 | Editor_PushRows += 1*(Rows_Num-1);
|
---|
1342 | }else if(new_pad & PAD_R2){ // Text move page down.
|
---|
1343 | if(Editor_Cur<Editor_nChar && TextBuffer[Active_Window][Editor_Cur]!='\0')
|
---|
1344 | Editor_PushRows -= 1*(Rows_Num-1);
|
---|
1345 | }else if(new_pad & PAD_SELECT && Window[Active_Window][OPENED]){ // Virtual KeyBoard Active Rows_Num -= 7.
|
---|
1346 | KeyBoard_Cur=2;
|
---|
1347 | Rows_Num -= 6;
|
---|
1348 | KeyBoard_Active = 1;
|
---|
1349 | }
|
---|
1350 | }else{ // Pad Response With Virtual KeyBoard.
|
---|
1351 | Virt_KeyBoard_Entry();
|
---|
1352 | }
|
---|
1353 |
|
---|
1354 | if(new_pad & PAD_TRIANGLE){ // General Pad Response.
|
---|
1355 | exit:
|
---|
1356 | drawMsg(LNG(Exiting_Editor));
|
---|
1357 | for(i=0; i<10; i++){
|
---|
1358 | if(!Window[i][SAVED])
|
---|
1359 | goto unsave;
|
---|
1360 | }
|
---|
1361 | force:
|
---|
1362 | for(i=0; i<10; i++){
|
---|
1363 | if(Window[i][OPENED]){
|
---|
1364 | Close(i);
|
---|
1365 | Path[i][0]='\0';
|
---|
1366 | }
|
---|
1367 | }
|
---|
1368 | if(Mark[MARK_COPY] || Mark[MARK_CUT])
|
---|
1369 | free(TextBuffer[EDIT]);
|
---|
1370 | Mark[MARK_START]=0, Mark[MARK_ON]=0, Mark[MARK_COPY]=0, Mark[MARK_CUT]=0,
|
---|
1371 | Mark[MARK_IN]=0, Mark[MARK_OUT]=0, Mark[MARK_TMP]=0,
|
---|
1372 | Mark[MARK_SIZE]=0, Mark[MARK_PRINT]=0, Mark[MARK_COLOR]=0;
|
---|
1373 |
|
---|
1374 | return;
|
---|
1375 | unsave:
|
---|
1376 | if(ynDialog(LNG(Exit_Without_Saving))!=1)
|
---|
1377 | goto abort;
|
---|
1378 | else
|
---|
1379 | goto force;
|
---|
1380 | }else if(new_pad & PAD_R1) {
|
---|
1381 | menu:
|
---|
1382 | ret = MenuEditor();
|
---|
1383 | if(ret==NEW){
|
---|
1384 | Num_Window=0;
|
---|
1385 | for(i=0; i<10; i++){
|
---|
1386 | if(Window[i][OPENED])
|
---|
1387 | Num_Window++;
|
---|
1388 | }
|
---|
1389 | if(Num_Window<10){
|
---|
1390 | for(i=0; i<10; i++){
|
---|
1391 | if(!Window[i][OPENED]){
|
---|
1392 | Active_Window=i;
|
---|
1393 | break;
|
---|
1394 | }
|
---|
1395 | }
|
---|
1396 | ret=New(Active_Window);
|
---|
1397 | if(!ret)
|
---|
1398 | goto fail;
|
---|
1399 | Editor_Cur=0, Editor_PushRows=0;
|
---|
1400 | }
|
---|
1401 | Num_Window=0;
|
---|
1402 | for(i=0; i<10; i++){
|
---|
1403 | if(Window[i][OPENED])
|
---|
1404 | Num_Window++;
|
---|
1405 | }
|
---|
1406 | } else if(ret==OPEN){
|
---|
1407 | drawMsg(LNG(Select_A_File_For_Editing));
|
---|
1408 | drawMsg(LNG(Select_A_File_For_Editing));
|
---|
1409 | Num_Window=0;
|
---|
1410 | for(i=0; i<10; i++){
|
---|
1411 | if(Window[i][OPENED])
|
---|
1412 | Num_Window++;
|
---|
1413 | }
|
---|
1414 | if(Num_Window<10){
|
---|
1415 | for(i=0; i<10; i++){
|
---|
1416 | if(!Window[i][OPENED]){
|
---|
1417 | Active_Window=i;
|
---|
1418 | break;
|
---|
1419 | }
|
---|
1420 | }
|
---|
1421 | ret=Open(Active_Window);
|
---|
1422 | if(!ret)
|
---|
1423 | goto fail;
|
---|
1424 | Editor_Cur=0, Editor_PushRows=0;
|
---|
1425 | }
|
---|
1426 | Num_Window=0;
|
---|
1427 | for(i=0; i<10; i++){
|
---|
1428 | if(Window[i][OPENED])
|
---|
1429 | Num_Window++;
|
---|
1430 | }
|
---|
1431 | } else if(ret==CLOSE){
|
---|
1432 | if(!Window[Active_Window][SAVED]){
|
---|
1433 | if(ynDialog(LNG(Close_Without_Saving))!=1)
|
---|
1434 | goto abort;
|
---|
1435 | }
|
---|
1436 | Close(Active_Window);
|
---|
1437 | fail:
|
---|
1438 | for(i=9; i>-1; i--){
|
---|
1439 | if(Window[i][OPENED]){
|
---|
1440 | Active_Window=i;
|
---|
1441 | break;
|
---|
1442 | }
|
---|
1443 | }
|
---|
1444 | Num_Window=0;
|
---|
1445 | for(i=0; i<10; i++){
|
---|
1446 | if(Window[i][OPENED])
|
---|
1447 | Num_Window++;
|
---|
1448 | }
|
---|
1449 | abort:
|
---|
1450 | i=0; // just for compiler warning.
|
---|
1451 | } else if(ret==SAVE){
|
---|
1452 | Save(Active_Window);
|
---|
1453 | } else if(ret==SAVE_AS){
|
---|
1454 | Save_As(Active_Window);
|
---|
1455 | } else if(ret==WINDOWS){
|
---|
1456 | ret=Windows_Selector();
|
---|
1457 | if(ret>=0){
|
---|
1458 | Active_Window=ret;
|
---|
1459 | Init();
|
---|
1460 | }
|
---|
1461 | } else if(ret==EXIT){
|
---|
1462 | goto exit;
|
---|
1463 | }
|
---|
1464 | }
|
---|
1465 | }//ends pad response section.
|
---|
1466 |
|
---|
1467 | if(!Num_Window)
|
---|
1468 | Editor_Start++;
|
---|
1469 | if(Editor_Start==4){
|
---|
1470 | Editor_Start=0;
|
---|
1471 | event |= 2;
|
---|
1472 | goto menu;
|
---|
1473 | }
|
---|
1474 |
|
---|
1475 | if(setting->usbkbd_used){ // Kbd response section.
|
---|
1476 |
|
---|
1477 | ret = KeyBoard_Entry();
|
---|
1478 | if(ret)
|
---|
1479 | event |=2;
|
---|
1480 | if(ret==2)
|
---|
1481 | goto menu;
|
---|
1482 | else if(ret==3)
|
---|
1483 | goto exit;
|
---|
1484 |
|
---|
1485 | } // end Kbd response section.
|
---|
1486 |
|
---|
1487 | t++;
|
---|
1488 |
|
---|
1489 | if(t & 0x0F) event |= 4; //repetitive timer event.
|
---|
1490 |
|
---|
1491 | if(event||post_event){ //NB: We need to update two frame buffers per event.
|
---|
1492 |
|
---|
1493 | //Display section.
|
---|
1494 | clrScr(setting->color[0]);
|
---|
1495 |
|
---|
1496 | if(TextSize[Active_Window]==0)
|
---|
1497 | goto end;
|
---|
1498 |
|
---|
1499 | drawOpSprite(COL_NORM_BG,
|
---|
1500 | SCREEN_MARGIN, Frame_start_y,
|
---|
1501 | SCREEN_WIDTH-SCREEN_MARGIN, Frame_end_y);
|
---|
1502 |
|
---|
1503 | if(KeyBoard_Active){ //Display Virtual KeyBoard Section.
|
---|
1504 |
|
---|
1505 | drawPopSprite(setting->color[0],
|
---|
1506 | SCREEN_MARGIN, KEY_Y+6,
|
---|
1507 | SCREEN_WIDTH-SCREEN_MARGIN, Frame_end_y);
|
---|
1508 | drawOpSprite(setting->color[1],
|
---|
1509 | SCREEN_MARGIN, KEY_Y+6,
|
---|
1510 | SCREEN_WIDTH-SCREEN_MARGIN, KEY_Y+6+LINE_THICKNESS-1);
|
---|
1511 | drawOpSprite(setting->color[1],
|
---|
1512 | KEY_X-48, KEY_Y+6,
|
---|
1513 | KEY_X-48+LINE_THICKNESS-1, Frame_end_y);
|
---|
1514 | drawOpSprite(setting->color[1],
|
---|
1515 | KEY_X+32, KEY_Y+6,
|
---|
1516 | KEY_X+32+LINE_THICKNESS-1, Frame_end_y);
|
---|
1517 | drawOpSprite(setting->color[1],
|
---|
1518 | KEY_X+KEY_W+32, KEY_Y+6,
|
---|
1519 | KEY_X+KEY_W+32+LINE_THICKNESS-1, Frame_end_y);
|
---|
1520 |
|
---|
1521 | if(Mark[MARK_ON])
|
---|
1522 | color=setting->color[2];
|
---|
1523 | else
|
---|
1524 | color=setting->color[3];
|
---|
1525 | printXY(LNG(MARK), KEY_X+2+4-120, KEY_Y+12,
|
---|
1526 | color, TRUE, ((KEY_X-48)-SCREEN_MARGIN-3*FONT_WIDTH));
|
---|
1527 | printXY(LNG(LINE_UP), KEY_X+2+4-120+10*FONT_WIDTH, KEY_Y+12,
|
---|
1528 | setting->color[3], TRUE, ((KEY_X+32)-(KEY_X-48)-3*FONT_WIDTH));
|
---|
1529 | if(Mark[MARK_COPY])
|
---|
1530 | color=setting->color[2];
|
---|
1531 | else
|
---|
1532 | color=setting->color[3];
|
---|
1533 | printXY(LNG(COPY), KEY_X+2+4-120, KEY_Y+12+FONT_HEIGHT+2,
|
---|
1534 | color, TRUE, ((KEY_X-48)-SCREEN_MARGIN-3*FONT_WIDTH));
|
---|
1535 | printXY(LNG(LINE_DOWN), KEY_X+2+4-120+10*FONT_WIDTH, KEY_Y+12+FONT_HEIGHT+2,
|
---|
1536 | setting->color[3], TRUE, ((KEY_X+32)-(KEY_X-48)-3*FONT_WIDTH));
|
---|
1537 | if(Mark[MARK_CUT])
|
---|
1538 | color=setting->color[2];
|
---|
1539 | else
|
---|
1540 | color=setting->color[3];
|
---|
1541 | printXY(LNG(CUT), KEY_X+2+4-120, KEY_Y+12+FONT_HEIGHT*2+4,
|
---|
1542 | color, TRUE, ((KEY_X-48)-SCREEN_MARGIN-3*FONT_WIDTH));
|
---|
1543 | printXY(LNG(PAGE_UP), KEY_X+2+4-120+10*FONT_WIDTH, KEY_Y+12+FONT_HEIGHT*2+4,
|
---|
1544 | setting->color[3], TRUE, ((KEY_X+32)-(KEY_X-48)-3*FONT_WIDTH));
|
---|
1545 | printXY(LNG(PASTE), KEY_X+2+4-120, KEY_Y+12+FONT_HEIGHT*3+6,
|
---|
1546 | setting->color[3], TRUE, ((KEY_X-48)-SCREEN_MARGIN-3*FONT_WIDTH));
|
---|
1547 | printXY(LNG(PAGE_DOWN), KEY_X+2+4-120+10*FONT_WIDTH, KEY_Y+12+FONT_HEIGHT*3+6,
|
---|
1548 | setting->color[3], TRUE, ((KEY_X+32)-(KEY_X-48)-3*FONT_WIDTH));
|
---|
1549 | printXY(LNG(HOME), KEY_X+2+4-120, KEY_Y+12+FONT_HEIGHT*4+8,
|
---|
1550 | setting->color[3], TRUE, ((KEY_X-48)-SCREEN_MARGIN-3*FONT_WIDTH));
|
---|
1551 | printXY(LNG(END), KEY_X+2+4-120+10*FONT_WIDTH, KEY_Y+12+FONT_HEIGHT*4+8,
|
---|
1552 | setting->color[3], TRUE, ((KEY_X+32)-(KEY_X-48)-3*FONT_WIDTH));
|
---|
1553 |
|
---|
1554 | if(Editor_Insert)
|
---|
1555 | color=setting->color[2];
|
---|
1556 | else
|
---|
1557 | color=setting->color[3];
|
---|
1558 | printXY(LNG(INSERT), KEY_X+2+4+392, KEY_Y+12,
|
---|
1559 | color, TRUE, ((SCREEN_WIDTH-SCREEN_MARGIN)-(KEY_X+KEY_W+32)-3*FONT_WIDTH));
|
---|
1560 | tmp[0]='\0';
|
---|
1561 | if(Editor_RetMode==OTHER)
|
---|
1562 | strcpy(tmp, LNG(RET_CRLF));
|
---|
1563 | else if(Editor_RetMode==UNIX)
|
---|
1564 | strcpy(tmp, LNG(RET_CR));
|
---|
1565 | else if(Editor_RetMode==MAC)
|
---|
1566 | strcpy(tmp, LNG(RET_LF));
|
---|
1567 | printXY(tmp, KEY_X+2+4 + 392, KEY_Y+12+FONT_HEIGHT+2,
|
---|
1568 | setting->color[3], TRUE, ((SCREEN_WIDTH-SCREEN_MARGIN)-(KEY_X+KEY_W+32)-3*FONT_WIDTH));
|
---|
1569 | printXY(LNG(TAB), KEY_X+2+4 + 392, KEY_Y+12+FONT_HEIGHT*2+4,
|
---|
1570 | setting->color[3], TRUE, ((SCREEN_WIDTH-SCREEN_MARGIN)-(KEY_X+KEY_W+32)-3*FONT_WIDTH));
|
---|
1571 | printXY(LNG(SPACE), KEY_X+2+4 + 392, KEY_Y+12+FONT_HEIGHT*3+6,
|
---|
1572 | setting->color[3], TRUE, ((SCREEN_WIDTH-SCREEN_MARGIN)-(KEY_X+KEY_W+32)-3*FONT_WIDTH));
|
---|
1573 | printXY(LNG(KB_RETURN), KEY_X+2+4 + 392, KEY_Y+12+FONT_HEIGHT*4+8,
|
---|
1574 | setting->color[3], TRUE, ((SCREEN_WIDTH-SCREEN_MARGIN)-(KEY_X+KEY_W+32)-3*FONT_WIDTH));
|
---|
1575 |
|
---|
1576 | for(i=0; i<KEY_LEN; i++){
|
---|
1577 | drawChar(KEY[i],
|
---|
1578 | KEY_X+2+4+14 + (i%WFONTS+1)*20 - 32,
|
---|
1579 | KEY_Y+12 + (i/WFONTS)*18,
|
---|
1580 | setting->color[3]);
|
---|
1581 | }
|
---|
1582 |
|
---|
1583 | //Virtual KeyBoard Cursor positioning section.
|
---|
1584 | if(!KeyBoard_Cur || KeyBoard_Cur%WFONTS==0)
|
---|
1585 | x = KEY_X+2+4 - 128;
|
---|
1586 | else if(KeyBoard_Cur==1 || (KeyBoard_Cur-1)%WFONTS==0)
|
---|
1587 | x = KEY_X+2+4 - 48;
|
---|
1588 | else if((KeyBoard_Cur+1)%WFONTS==0)
|
---|
1589 | x = KEY_X+2+4 + 384;
|
---|
1590 | else
|
---|
1591 | x = KEY_X+2+4+14 + (KeyBoard_Cur%WFONTS+1)*20 - 40;
|
---|
1592 | y = KEY_Y+12 + (KeyBoard_Cur/WFONTS)*18;
|
---|
1593 | drawChar(LEFT_CUR, x, y, setting->color[2]);
|
---|
1594 |
|
---|
1595 | } // end Display Virtual KeyBoard Section.
|
---|
1596 |
|
---|
1597 | x = Menu_start_x;
|
---|
1598 | y = Menu_start_y;
|
---|
1599 |
|
---|
1600 | Editor_Rules();
|
---|
1601 |
|
---|
1602 | Editor_TextEnd=0, tmpLen=0;
|
---|
1603 |
|
---|
1604 | for(i=Top_Height; i<Rows_Num+Top_Height; i++)
|
---|
1605 | {
|
---|
1606 | for(j=0; j<Editor_nRowsWidth[i]; j++)
|
---|
1607 | {
|
---|
1608 | Mark[MARK_COLOR]=0;
|
---|
1609 |
|
---|
1610 | if(Mark[MARK_ON] && Mark[MARK_PRINT]>0){ //Mark Text.
|
---|
1611 | if(Mark[MARK_SIZE]>0){
|
---|
1612 | if(Top_Width+tmpLen+j == (Editor_Cur-Mark[MARK_PRINT])){
|
---|
1613 | drawOpSprite(COL_MARK_BG, x, y-1, x+FONT_WIDTH, y+FONT_HEIGHT-1);
|
---|
1614 | Mark[MARK_COLOR]=1;
|
---|
1615 | Mark[MARK_PRINT]--;
|
---|
1616 | }
|
---|
1617 | }else if(Mark[MARK_SIZE]<0){
|
---|
1618 | if(Top_Width+tmpLen+j == (Editor_Cur+Mark[MARK_PRINT]-1)){
|
---|
1619 | drawOpSprite(COL_MARK_BG, x, y-1, x+FONT_WIDTH, y+FONT_HEIGHT-1);
|
---|
1620 | Mark[MARK_COLOR]=1;
|
---|
1621 | if((Mark[MARK_PRINT]++) == (-Mark[MARK_SIZE]))
|
---|
1622 | Mark[MARK_PRINT]=0;
|
---|
1623 | }
|
---|
1624 | }
|
---|
1625 | } // end mark.
|
---|
1626 |
|
---|
1627 | if(Top_Width+tmpLen+j == Editor_Cur){ //Text Cursor.
|
---|
1628 | if(Editor_Insert)
|
---|
1629 | color = COL_CUR_INSERT;
|
---|
1630 | else
|
---|
1631 | color = COL_CUR_OVERWR;
|
---|
1632 | if(((event|post_event)&4) && (t & 0x10))
|
---|
1633 | drawChar(TEXT_CUR, x-4, y, color);
|
---|
1634 | }
|
---|
1635 |
|
---|
1636 | if(TextBuffer[Active_Window][Top_Width+tmpLen+j]=='\n'){ // Line Feed.
|
---|
1637 | ch=DN_ARROW;
|
---|
1638 | color = COL_LINE_END;
|
---|
1639 | }else if (TextBuffer[Active_Window][Top_Width+tmpLen+j]=='\r'){ // Carriage Return.
|
---|
1640 | ch=LT_ARROW;
|
---|
1641 | color = COL_LINE_END;
|
---|
1642 | }else if (TextBuffer[Active_Window][Top_Width+tmpLen+j]=='\t'){ // Tabulation.
|
---|
1643 | ch=RT_ARROW;
|
---|
1644 | color = COL_TAB;
|
---|
1645 | }else if (TextBuffer[Active_Window][Top_Width+tmpLen+j]=='\0'){ // Text End.
|
---|
1646 | ch=BR_SPLIT;
|
---|
1647 | color = COL_TEXT_END;
|
---|
1648 | Editor_TextEnd=1;
|
---|
1649 | }else{
|
---|
1650 | ch=TextBuffer[Active_Window][Top_Width+tmpLen+j];
|
---|
1651 | if(Mark[MARK_ON] && Mark[MARK_COLOR]) //Text Color Black / White If Mark.
|
---|
1652 | color = COL_MARK_TEXT;
|
---|
1653 | else
|
---|
1654 | color = COL_NORM_TEXT;
|
---|
1655 | }
|
---|
1656 |
|
---|
1657 | drawChar(ch, x, y, color);
|
---|
1658 |
|
---|
1659 | if(Editor_TextEnd)
|
---|
1660 | goto end;
|
---|
1661 |
|
---|
1662 | x += FONT_WIDTH;
|
---|
1663 | }
|
---|
1664 |
|
---|
1665 | tmpLen += Editor_nRowsWidth[i];
|
---|
1666 |
|
---|
1667 | x = Menu_start_x;
|
---|
1668 | y += FONT_HEIGHT;
|
---|
1669 |
|
---|
1670 | } //ends for, so all editor Rows_Num were fixed above.
|
---|
1671 | end:
|
---|
1672 | if(Editor_nRowsNum > Rows_Num) { //if more lines than available Rows_Num, use scrollbar.
|
---|
1673 | if(KeyBoard_Active){
|
---|
1674 | drawFrame(SCREEN_WIDTH-SCREEN_MARGIN-LINE_THICKNESS*8, Frame_start_y,
|
---|
1675 | SCREEN_WIDTH-SCREEN_MARGIN, KEY_Y+6, setting->color[1]);
|
---|
1676 | y0=(KEY_Y+6-Menu_start_y+8)*((double)Top_Height/Editor_nRowsNum);
|
---|
1677 | y1=(KEY_Y+6-Menu_start_y+8)*((double)(Top_Height+Rows_Num)/Editor_nRowsNum);
|
---|
1678 | drawOpSprite(setting->color[1],
|
---|
1679 | SCREEN_WIDTH-SCREEN_MARGIN-LINE_THICKNESS*6, (y0+Menu_start_y-2),
|
---|
1680 | SCREEN_WIDTH-SCREEN_MARGIN-LINE_THICKNESS*2, (y1+Menu_start_y-10));
|
---|
1681 | }else{
|
---|
1682 | drawFrame(SCREEN_WIDTH-SCREEN_MARGIN-LINE_THICKNESS*8, Frame_start_y,
|
---|
1683 | SCREEN_WIDTH-SCREEN_MARGIN, Frame_end_y, setting->color[1]);
|
---|
1684 | y0=(Menu_end_y-Menu_start_y+8)*((double)Top_Height/Editor_nRowsNum);
|
---|
1685 | y1=(Menu_end_y-Menu_start_y+8)*((double)(Top_Height+Rows_Num)/Editor_nRowsNum);
|
---|
1686 | drawOpSprite(setting->color[1],
|
---|
1687 | SCREEN_WIDTH-SCREEN_MARGIN-LINE_THICKNESS*6, (y0+Menu_start_y-2),
|
---|
1688 | SCREEN_WIDTH-SCREEN_MARGIN-LINE_THICKNESS*2, (y1+Menu_start_y-6));
|
---|
1689 | } //ends clause for scrollbar with KeyBoard.
|
---|
1690 | } //ends clause for scrollbar.
|
---|
1691 |
|
---|
1692 | //Tooltip section.
|
---|
1693 | tmp[0]='\0', tmp1[0]='\0', tmp2[0]='\0';
|
---|
1694 | if(KeyBoard_Active){ //Display Virtual KeyBoard Tooltip.
|
---|
1695 | if(swapKeys)
|
---|
1696 | sprintf(tmp1, "R1:%s ÿ3:%s ÿ1:%s ÿ0:%s L2:%s R2:%s Sel:%s",
|
---|
1697 | LNG(Menu), LNG(Exit), LNG(Sel), LNG(BackSpace),
|
---|
1698 | LNG(Left), LNG(Right), LNG(Close_KB));
|
---|
1699 | else
|
---|
1700 | sprintf(tmp1, "R1:%s ÿ3:%s ÿ0:%s ÿ1:%s L2:%s R2:%s Sel:%s",
|
---|
1701 | LNG(Menu), LNG(Exit), LNG(Sel), LNG(BackSpace),
|
---|
1702 | LNG(Left), LNG(Right), LNG(Close_KB));
|
---|
1703 | }else if(setting->usbkbd_used){ //Display KeyBoard Tooltip.
|
---|
1704 | if(Window[Active_Window][OPENED]){
|
---|
1705 | if(Mark[MARK_ON])
|
---|
1706 | sprintf(tmp1, "F1/R1:%s Esc/ÿ3:%s Ctrl+ b:%s: %s ",
|
---|
1707 | LNG(Menu), LNG(Exit), LNG(Mark), LNG(On));
|
---|
1708 | else
|
---|
1709 | sprintf(tmp1, "F1/R1:%s Esc/ÿ3:%s Ctrl+ b:%s: %s ",
|
---|
1710 | LNG(Menu), LNG(Exit), LNG(Mark), LNG(Off));
|
---|
1711 | sprintf(tmp2, "x:%s c:%s v:%s ", LNG(Cut), LNG(Copy), LNG(Paste));
|
---|
1712 | strcat(tmp1, tmp2);
|
---|
1713 | if(Editor_RetMode==OTHER)
|
---|
1714 | sprintf(tmp2, "r:%s ", LNG(CrLf));
|
---|
1715 | else if(Editor_RetMode==UNIX)
|
---|
1716 | sprintf(tmp2, "r:%s ", LNG(Cr));
|
---|
1717 | else if(Editor_RetMode==MAC)
|
---|
1718 | sprintf(tmp2, "r:%s ", LNG(Lf));
|
---|
1719 | strcat(tmp1, tmp2);
|
---|
1720 | if(Editor_Insert)
|
---|
1721 | sprintf(tmp2, "%s:%s", LNG(Ins), LNG(On));
|
---|
1722 | else
|
---|
1723 | sprintf(tmp2, "%s:%s", LNG(Ins), LNG(Off));
|
---|
1724 | strcat(tmp1, tmp2);
|
---|
1725 | }else
|
---|
1726 | sprintf(tmp1, "F1/R1:%s Esc/ÿ3:%s", LNG(Menu), LNG(Exit));
|
---|
1727 | }else{ //Display Basic Tooltip.
|
---|
1728 | if(Window[Active_Window][OPENED])
|
---|
1729 | sprintf(tmp1, "R1:%s ÿ3:%s Select:%s", LNG(Menu), LNG(Exit), LNG(Open_KeyBoard));
|
---|
1730 | else
|
---|
1731 | sprintf(tmp1, "R1:%s ÿ3:%s", LNG(Menu), LNG(Exit));
|
---|
1732 | }
|
---|
1733 | if(Window[Active_Window][CREATED])
|
---|
1734 | sprintf(tmp, "%s : %s", LNG(PS2_TEXT_EDITOR), LNG(File_Not_Yet_Saved));
|
---|
1735 | else if(Window[Active_Window][OPENED])
|
---|
1736 | sprintf(tmp, "%s : %s", LNG(PS2_TEXT_EDITOR), Path[Active_Window]);
|
---|
1737 | else
|
---|
1738 | strcpy(tmp, LNG(PS2_TEXT_EDITOR));
|
---|
1739 | setScrTmp(tmp, tmp1);
|
---|
1740 | }//ends if(event||post_event).
|
---|
1741 | drawScr();
|
---|
1742 | post_event = event;
|
---|
1743 | event = 0;
|
---|
1744 | }//ends while.
|
---|
1745 |
|
---|
1746 | return;
|
---|
1747 | }
|
---|
1748 | //--------------------------------------------------------------
|
---|
1749 | //End of file: editor.c
|
---|
1750 | //--------------------------------------------------------------
|
---|