FreeCalypso > hg > leo2moko-debug
comparison g23m/condat/ms/src/mfw/mfw_edt.c @ 0:509db1a7b7b8
initial import: leo2moko-r1
author | Space Falcon <falcon@ivan.Harhan.ORG> |
---|---|
date | Mon, 01 Jun 2015 03:24:05 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:509db1a7b7b8 |
---|---|
1 /* | |
2 +--------------------------------------------------------------------+ | |
3 | PROJECT: MMI-Framework (8417) $Workfile:: mfw_edt.c $| | |
4 | $Author:: Es $ CONDAT GmbH $Revision:: 15 $| | |
5 | CREATED: 21.09.98 $Modtime:: 23.03.00 8:57 $| | |
6 | STATE : code | | |
7 +--------------------------------------------------------------------+ | |
8 | |
9 MODULE : MFW_EDT | |
10 | |
11 PURPOSE : edit handling functions | |
12 | |
13 EXPORT : | |
14 | |
15 TO DO : | |
16 | |
17 $History:: mfw_edt.c | |
18 | |
19 Aug 16, 2004 REF: CRR 24323 Deepa M.D | |
20 Bug:Clenup of sprintf used for tracing | |
21 Fix:Replace the char buf[]; sprintf (buf, "...", ...); TRACE_EVENT (buf); statements by TRACE_EVENT_PX $ | |
22 * | |
23 * ***************** Version 15 ***************** | |
24 * User: Es Date: 23.03.00 Time: 14:40 | |
25 * Updated in $/GSM/Condat/MS/SRC/MFW | |
26 * added edtUnhide() | |
27 * | |
28 * ***************** Version 14 ***************** | |
29 * User: Kk Date: 21.02.00 Time: 9:36 | |
30 * Updated in $/GSM/Condat/MS/SRC/MFW | |
31 * changes from es inserted | |
32 * | |
33 * ***************** Version 13 ***************** | |
34 * User: Es Date: 18.02.00 Time: 15:45 | |
35 * Updated in $/GSM/Condat/MS/SRC/MFW | |
36 * added edit controls: ecTop, ecBottom | |
37 | | |
38 | ***************** Version 12 ***************** | |
39 | User: Le Date: 6.01.00 Time: 9:23 | |
40 | Updated in $/GSM/Condat/MS/SRC/MFW | |
41 | Alignment of MFW versions | |
42 * | |
43 * ***************** Version 3 ***************** | |
44 * User: Kk Date: 13.12.99 Time: 17:30 | |
45 * Updated in $/GSM/Condat/SND-MMI/MFW | |
46 * | |
47 * ***************** Version 2 ***************** | |
48 * User: Es Date: 22.11.99 Time: 10:29 | |
49 * Updated in $/GSM/Condat/SND-MMI/MFW | |
50 * | |
51 * ***************** Version 1 ***************** | |
52 * User: Es Date: 18.11.99 Time: 16:35 | |
53 * Created in $/GSM/Condat/SND-MMI/MFW | |
54 * Initial | |
55 * | |
56 * ***************** Version 11 ***************** | |
57 * User: Es Date: 6.07.99 Time: 12:18 | |
58 * Updated in $/GSM/DEV/MS/SRC/MFW | |
59 * | |
60 * ***************** Version 10 ***************** | |
61 * User: Es Date: 14.04.99 Time: 17:34 | |
62 * Updated in $/GSM/DEV/MS/SRC/MFW | |
63 * moved to CST | |
64 | | |
65 | ***************** Version 9 ***************** | |
66 | User: Le Date: 14.04.99 Time: 9:51 | |
67 | Updated in $/GSM/DEV/MS/SRC/MFW | |
68 * | |
69 * ***************** Version 8 ***************** | |
70 * User: Es Date: 1.04.99 Time: 17:07 | |
71 * Updated in $/GSM/DEV/MS/SRC/MFW | |
72 * removed lots of traces | |
73 * | |
74 * ***************** Version 7 ***************** | |
75 * User: Es Date: 18.02.99 Time: 17:01 | |
76 * Updated in $/GSM/DEV/MS/SRC/MFW | |
77 * | |
78 * ***************** Version 6 ***************** | |
79 * User: Es Date: 17.02.99 Time: 19:10 | |
80 * Updated in $/GSM/DEV/MS/SRC/MFW | |
81 * | |
82 * ***************** Version 5 ***************** | |
83 * User: Es Date: 8.02.99 Time: 19:06 | |
84 * Updated in $/GSM/DEV/MS/SRC/MFW | |
85 * Cursor auf 0 ! | |
86 * | |
87 * ***************** Version 4 ***************** | |
88 * User: Es Date: 27.01.99 Time: 15:06 | |
89 * Updated in $/GSM/DEV/MS/SRC/MFW | |
90 * | |
91 * ***************** Version 3 ***************** | |
92 * User: Es Date: 14.01.99 Time: 17:19 | |
93 * Updated in $/GSM/DEV/MS/SRC/MFW | |
94 * | |
95 * ***************** Version 2 ***************** | |
96 * User: Es Date: 23.12.98 Time: 16:19 | |
97 * Updated in $/GSM/DEV/MS/SRC/MFW | |
98 */ | |
99 | |
100 | |
101 #if defined (NEW_FRAME) | |
102 | |
103 #include "typedefs.h" | |
104 #include "vsi.h" | |
105 #include "pei.h" | |
106 #include "custom.h" | |
107 #include "gsm.h" | |
108 | |
109 #else | |
110 | |
111 #include "STDDEFS.H" | |
112 #include "custom.h" | |
113 #include "gsm.h" | |
114 #include "vsi.h" | |
115 | |
116 #endif | |
117 | |
118 #include <stdio.h> | |
119 #include <string.h> | |
120 | |
121 #include "mfw_mfw.h" | |
122 #include "mfw_sys.h" | |
123 #include "gdi.h" | |
124 #include "dspl.h" | |
125 #include "mfw_edt.h" | |
126 #include "font_bitmaps.h" | |
127 | |
128 #include "mfw_mmi.h" | |
129 | |
130 #define TIME_TRACE_EVENT TRACE_EVENT | |
131 #ifndef TIME_TRACE_EVENT | |
132 #define TIME_TRACE_EVENT | |
133 #endif | |
134 | |
135 static int edtInsert (int c, char *b, int s, U8 curMode, U16 curCP); | |
136 static int edtCommand (U32 cmd, void *h); | |
137 void moveLeft (char * str, int ofs); | |
138 | |
139 static void edtUnicodeSplitLine (int px, int py, int ls, int ly, U16 *tp); | |
140 | |
141 static void moveLeftUnicode(U16 *unicodeStr, int nChars); | |
142 static int edtInsertUnicode (MfwEdt *e, int c, U16 *b, int s); | |
143 | |
144 U16 strlenUnicode(U16* str); | |
145 | |
146 static void edtOutTextLines (int px, int py, int ls, int ly, U16 *tpUnicode, unsigned char* tpAscii, | |
147 int fontHeight, int display); | |
148 MfwRes updateWindow (MfwEdt *e, int dy ); | |
149 | |
150 int isAWordChar( char chr); | |
151 | |
152 //Define the chars that correspond to the end of a word. | |
153 #define STR_WORDBREAK " .?!" | |
154 | |
155 /* | |
156 +--------------------------------------------------------------------+ | |
157 | PROJECT : MMI-Framework (8417) MODULE : MFW_EDT | | |
158 | STATE : code ROUTINE : edtInit | | |
159 +--------------------------------------------------------------------+ | |
160 | |
161 PURPOSE : initialize edit handler | |
162 | |
163 */ | |
164 | |
165 MfwRes edtInit (void) | |
166 { | |
167 mfwCommand[MfwTypEdt] = (MfwCb) edtCommand; | |
168 | |
169 return MfwResOk; | |
170 } | |
171 | |
172 | |
173 /* | |
174 +--------------------------------------------------------------------+ | |
175 | PROJECT : MMI-Framework (8417) MODULE : MFW_EDT | | |
176 | STATE : code ROUTINE : edtExit | | |
177 +--------------------------------------------------------------------+ | |
178 | |
179 PURPOSE : finalize edit handler | |
180 | |
181 */ | |
182 | |
183 MfwRes edtExit (void) | |
184 { | |
185 mfwCommand[MfwTypEdt] = 0; | |
186 | |
187 return MfwResOk; | |
188 } | |
189 | |
190 | |
191 /* | |
192 +--------------------------------------------------------------------+ | |
193 | PROJECT : MMI-Framework (8417) MODULE : MFW_EDT | | |
194 | STATE : code ROUTINE : edtCreate | | |
195 +--------------------------------------------------------------------+ | |
196 | |
197 PURPOSE : create editor control | |
198 | |
199 */ | |
200 | |
201 MfwHnd edtCreate (MfwHnd w, MfwEdtAttr *a, MfwEvt e, MfwCb f) | |
202 { | |
203 MfwHdr *hdr = (MfwHdr *) mfwAlloc(sizeof(MfwHdr)); | |
204 MfwEdt *edt = (MfwEdt *) mfwAlloc(sizeof(MfwEdt)); | |
205 MfwHdr *insert_status =0; | |
206 TRACE_FUNCTION("edtCreate"); | |
207 | |
208 if (!hdr || !edt) | |
209 { | |
210 TRACE_ERROR("ERROR: edtCreate() Mem Alloc Failed."); | |
211 | |
212 if(hdr) | |
213 mfwFree((U8*)hdr,sizeof(MfwHdr)); | |
214 | |
215 if(edt) | |
216 mfwFree((U8*)edt,sizeof(MfwEdt)); | |
217 return 0; | |
218 } | |
219 | |
220 edt->mask = e; | |
221 edt->flags = 0; | |
222 edt->handler = f; | |
223 edt->attr = a; | |
224 edt->cp = 0; /* cursor position */ | |
225 edt->curOffs = 0; | |
226 | |
227 hdr->data = edt; | |
228 hdr->type = MfwTypEdt; | |
229 | |
230 edtUpdate(edt); | |
231 | |
232 insert_status = mfwInsert(w,hdr); | |
233 | |
234 if(!insert_status) | |
235 { | |
236 TRACE_ERROR("ERROR: edtCreate() Failed to Install Handler. "); | |
237 mfwFree((U8*)hdr,sizeof(MfwHdr)); | |
238 mfwFree((U8*)edt,sizeof(MfwEdt)); | |
239 return 0; | |
240 } | |
241 return insert_status; | |
242 } | |
243 | |
244 | |
245 /* | |
246 +--------------------------------------------------------------------+ | |
247 | PROJECT : MMI-Framework (8417) MODULE : MFW_EDT | | |
248 | STATE : code ROUTINE : edtDelete | | |
249 +--------------------------------------------------------------------+ | |
250 | |
251 PURPOSE : delete editor control | |
252 | |
253 */ | |
254 | |
255 MfwRes edtDelete (MfwHnd e) | |
256 { | |
257 MfwRes res; | |
258 | |
259 if (!e) | |
260 return MfwResIllHnd; | |
261 | |
262 edtHide(e); /* hide editor contents */ | |
263 res = (mfwRemove(e)) ? MfwResOk : MfwResIllHnd; | |
264 | |
265 mfwFree(((MfwHdr *) e)->data,sizeof(MfwEdt)); | |
266 mfwFree(e,sizeof(MfwHdr)); | |
267 | |
268 return res; | |
269 } | |
270 | |
271 | |
272 /* | |
273 +--------------------------------------------------------------------+ | |
274 | PROJECT : MMI-Framework (8417) MODULE : MFW_EDT | | |
275 | STATE : code ROUTINE : edtReset | | |
276 +--------------------------------------------------------------------+ | |
277 | |
278 PURPOSE : reset editor control | |
279 | |
280 */ | |
281 | |
282 MfwRes edtReset (MfwHnd w) | |
283 { | |
284 MfwEdt *e; | |
285 | |
286 | |
287 TRACE_FUNCTION("edtReset()"); | |
288 if (!w) | |
289 return MfwResIllHnd; /* editor does not exist */ | |
290 | |
291 e = ((MfwHdr *) w)->data; | |
292 | |
293 if (!e) | |
294 return MfwResIllHnd; /* editor does not exist */ | |
295 | |
296 e->cp = 0; /* cursor position */ | |
297 e->curOffs = 0; | |
298 | |
299 return MfwResOk; | |
300 } | |
301 | |
302 | |
303 /* | |
304 +--------------------------------------------------------------------+ | |
305 | PROJECT : MMI-Framework (8417) MODULE : MFW_EDT | | |
306 | STATE : code ROUTINE : edtShow | | |
307 +--------------------------------------------------------------------+ | |
308 | |
309 PURPOSE : show editor | |
310 | |
311 */ | |
312 | |
313 MfwRes edtShow (MfwHnd e) | |
314 { | |
315 MfwEdt *edt; | |
316 | |
317 TRACE_FUNCTION("edtShow()"); | |
318 | |
319 if (!e) | |
320 return MfwResIllHnd; /* editor does not exist */ | |
321 | |
322 edt = ((MfwHdr *) e)->data; /* get control block */ | |
323 | |
324 edt->flags |= MfwEdtVisible; /* editor is visible */ | |
325 if (edt->handler) /* call event handler */ | |
326 if (edt->mask & MfwEdtVisible) | |
327 edt->handler(MfwEdtVisible,edt); | |
328 edt->display = 1; /* really show it */ | |
329 edtUpdate(edt); /* draw editor elements */ | |
330 | |
331 return MfwResOk; | |
332 } | |
333 | |
334 | |
335 /* | |
336 +--------------------------------------------------------------------+ | |
337 | PROJECT : MMI-Framework (8417) MODULE : MFW_EDT | | |
338 | STATE : code ROUTINE : edtHide | | |
339 +--------------------------------------------------------------------+ | |
340 | |
341 PURPOSE : hide editor | |
342 | |
343 */ | |
344 | |
345 MfwRes edtHide (MfwHnd e) | |
346 { | |
347 MfwEdt *edt; | |
348 | |
349 TRACE_FUNCTION("edtHide()"); | |
350 if (!e) | |
351 return MfwResIllHnd; /* element does not exist */ | |
352 | |
353 edt = ((MfwHdr *) e)->data; /* get edit control block */ | |
354 edt->flags &= ~MfwEdtVisible; /* editor is not visible */ | |
355 if (edt->handler) /* call event handler */ | |
356 if (edt->mask & MfwEdtVisible) | |
357 edt->handler(MfwEdtVisible,edt); | |
358 | |
359 return MfwResOk; | |
360 } | |
361 | |
362 | |
363 /* | |
364 +--------------------------------------------------------------------+ | |
365 | PROJECT : MMI-Framework (8417) MODULE : MFW_EDT | | |
366 | STATE : code ROUTINE : edtUnhide | | |
367 +--------------------------------------------------------------------+ | |
368 | |
369 PURPOSE : unhide editor (without drawing) | |
370 | |
371 */ | |
372 | |
373 MfwRes edtUnhide (MfwHnd e) | |
374 { | |
375 MfwEdt *edt; | |
376 | |
377 TRACE_FUNCTION("edtunhide()"); | |
378 | |
379 if (!e) | |
380 return MfwResIllHnd; /* element does not exist */ | |
381 | |
382 edt = ((MfwHdr *) e)->data; /* get edit control block */ | |
383 edt->flags |= MfwEdtVisible; /* editor is visible */ | |
384 if (edt->handler) /* call event handler */ | |
385 if (edt->mask & MfwEdtVisible) | |
386 edt->handler(MfwEdtVisible,edt); | |
387 | |
388 return MfwResOk; | |
389 } | |
390 | |
391 | |
392 /* | |
393 +--------------------------------------------------------------------+ | |
394 | PROJECT : MMI-Framework (8417) MODULE : MFW_EDT | | |
395 | STATE : code ROUTINE : edtClear | | |
396 +--------------------------------------------------------------------+ | |
397 | |
398 PURPOSE : clear editor | |
399 | |
400 */ | |
401 | |
402 MfwRes edtClear (MfwHnd e) | |
403 { | |
404 MfwEdt *edt; | |
405 | |
406 TRACE_FUNCTION("edtClear()"); | |
407 | |
408 if (!e) | |
409 return MfwResIllHnd; /* element does not exist */ | |
410 | |
411 edt = ((MfwHdr *) e)->data; /* get edit control block */ | |
412 if (edtReset(e) && edt->attr->text) | |
413 { | |
414 *(edt->attr->text) = 0; /* clear buffer */ | |
415 edtUpdate(edt); /* clear edit area */ | |
416 } | |
417 | |
418 return MfwResOk; | |
419 } | |
420 | |
421 | |
422 /* | |
423 +--------------------------------------------------------------------+ | |
424 | PROJECT : MMI-Framework (8417) MODULE : MFW_EDT | | |
425 | STATE : code ROUTINE : edtUpdate | | |
426 +--------------------------------------------------------------------+ | |
427 | |
428 PURPOSE : draw editor | |
429 GW 06/09/01 - Call chinese update if first char is 0x80,0x81 or 0x82. | |
430 GW 06/09/01 - Added extra parameters to displ_setCursorPos for the size of cursor. | |
431 */ | |
432 | |
433 //Return non-zero result if chr is in the string str. | |
434 int chrInString(char chr,char* str) | |
435 { | |
436 int i; | |
437 i=0; | |
438 | |
439 TRACE_FUNCTION("chrInString()"); | |
440 | |
441 while (str[i] != 0x00) | |
442 { | |
443 if (str[i]== chr) | |
444 return (i+1); | |
445 else | |
446 i++; | |
447 } | |
448 //Not found - | |
449 return (0); | |
450 } | |
451 | |
452 //GW 18/09/01 Use 'isAWordChar' procedure instead of 'chrInString' | |
453 void findWordBounds(MfwEdt *e, int *opStChr, int *opEndChr) | |
454 { | |
455 int found; | |
456 int stChr,endChr; | |
457 | |
458 TRACE_FUNCTION("findWordBounds()"); | |
459 | |
460 //Find char before start of the word. | |
461 stChr = e->cp-1; | |
462 found = FALSE; | |
463 while ((stChr >0) && (!found)) | |
464 { | |
465 if (isAWordChar(e->attr->text[stChr])==0) | |
466 found = TRUE; | |
467 else | |
468 stChr--; | |
469 } | |
470 //find char after end of the word. | |
471 endChr = e->cp; | |
472 found = FALSE; | |
473 while ((e->attr->text[endChr]!=0x00 ) && (!found)) | |
474 { | |
475 if (isAWordChar(e->attr->text[endChr])==0) | |
476 found = TRUE; | |
477 else | |
478 endChr++; | |
479 } | |
480 *opStChr = stChr; | |
481 *opEndChr = endChr; | |
482 } | |
483 | |
484 //GW 18/09/01 Commented out debug code. | |
485 MfwRes edtUpdate (MfwEdt *e) | |
486 { | |
487 UBYTE temp; | |
488 | |
489 char *tp; | |
490 S16 px, py; /* top left corner of edit */ | |
491 S16 ls; /* width of edit window */ | |
492 S16 ly; /* bottom of edit window */ | |
493 U8 oldFont = -1; /* store previous font */ | |
494 char* endChar; | |
495 | |
496 unsigned char *tb; | |
497 | |
498 //Data used to add word highlight | |
499 char saveChr[2]; | |
500 char startHtext[2] = {0x01,0x00}; | |
501 char endHtext[2] = {0x02,0x00}; | |
502 int stChr,endChr; | |
503 | |
504 U16* tmp; | |
505 | |
506 TRACE_FUNCTION("edtUpdate()"); | |
507 | |
508 if (!e) | |
509 return MfwResIllHnd; | |
510 | |
511 if (!e->attr->text) | |
512 return MfwResErr; /* no text to display */ | |
513 | |
514 //Have we still got keys in the buffer to process? - process them first! | |
515 if (mfwKey_skipDisplay()) | |
516 return (MfwResOk); | |
517 | |
518 tb = (unsigned char*)e->attr->text; | |
519 | |
520 if ((tb[0] == 0x80) || (tb[0] == 0x81) || (tb[0] == 0x82)) | |
521 { | |
522 return( edtUpdateUnicode (e ) ); | |
523 } | |
524 | |
525 temp = dspl_get_char_type(); | |
526 dspl_set_char_type(DSPL_TYPE_ASCII); | |
527 | |
528 //TRACE_EVENT_P1("flags: %d", e->flags); | |
529 if (!(e->flags & MfwEdtVisible)) | |
530 e->display = 0; /* invisible editor */ | |
531 | |
532 resources_setColour(e->attr->edtCol); | |
533 tp = e->attr->text + e->curOffs; /* start of display buffer */ | |
534 px = e->attr->win.px; /* left of edit window */ | |
535 py = e->attr->win.py; /* top of edit window */ | |
536 ls = e->attr->win.sx; /* width of edit window */ | |
537 ly = (S16) (py+e->attr->win.sy); /* bottom of edit window */ | |
538 if (e->attr->font != (U8) -1) | |
539 oldFont = dspl_SelectFontbyID(e->attr->font); /* setup font */ | |
540 e->fontHeight = dspl_GetFontHeight(); /* get height of curr font */ | |
541 e->curMode = e->attr->mode; /* setup edi mode */ | |
542 if (e->display) | |
543 { | |
544 dspl_TextOut (e->attr->win.px, e->attr->win.py, 0, endHtext); | |
545 dspl_Clear(e->attr->win.px,e->attr->win.py,(U16)(ls+e->attr->win.px-1),(U16)(ly-1)); | |
546 } | |
547 | |
548 dspl_SetCursor(0,(U8)(e->curMode&edtCurMask)); | |
549 | |
550 //Add a space to the end of the line | |
551 endChar = &tp[strlen(tp)]; | |
552 if ((endChar[0] == 0x00) && | |
553 (endChar[1] == 0x00)) | |
554 { | |
555 endChar[0] = ' '; | |
556 endChar[1] = 0x00; | |
557 //For some editors, we want to highlight a complete word | |
558 if (e->curMode & edtModWordSkip) | |
559 { | |
560 | |
561 //find char at the start of the word | |
562 findWordBounds(e,&stChr,&endChr); | |
563 saveChr[0] = e->attr->text[stChr]; | |
564 saveChr[1] = e->attr->text[endChr]; | |
565 if (endChr == e->cp) // do not highlight if at the start of a word | |
566 { | |
567 if (stChr > e->curOffs) | |
568 e->attr->text[stChr] = 0x01; | |
569 else | |
570 dspl_TextOut (e->attr->win.px, e->attr->win.py, 0, startHtext); | |
571 e->attr->text[endChr] = 0x02; | |
572 } | |
573 | |
574 } | |
575 edtOutTextLines(e->attr->win.px, e->attr->win.py, ls, ly, NULL, (unsigned char*)tp, | |
576 e->fontHeight, e->display); //* show it * / | |
577 if (e->curMode & edtModWordSkip) | |
578 { | |
579 e->attr->text[stChr] = saveChr[0]; | |
580 e->attr->text[endChr]= saveChr[1]; | |
581 } | |
582 //and remove space again. | |
583 endChar[0] = 0x00; | |
584 } | |
585 else | |
586 { //Cannot add space | |
587 edtOutTextLines(e->attr->win.px, e->attr->win.py, ls, ly, NULL, (unsigned char*)tp, | |
588 e->fontHeight, e->display); //* show it * / | |
589 } | |
590 //GW 18/09/01 - Display predicted word. | |
591 if (e->display) | |
592 { | |
593 if ((e->attr->predText[0] != '\0') && (e->attr->win.py >=e->fontHeight)) | |
594 { | |
595 dspl_TextOut(0,e->attr->win.py-e->fontHeight,0," " ); | |
596 dspl_TextOut(0,e->attr->win.py-e->fontHeight,1,e->attr->predText ); | |
597 } | |
598 } | |
599 | |
600 if (e->display && (e->curMode & edtCurMask)) | |
601 { | |
602 dspl_SetCursorPos(e->curCX+e->attr->win.px,e->curCY,e->curCSize,(S16)e->fontHeight); // sbh 19/02/02, position cursor correctly | |
603 } | |
604 if (oldFont != (U8) -1) | |
605 dspl_SelectFontbyID(oldFont); /* restore previous font */ | |
606 | |
607 #ifdef MFW_DEBUG_DISPLAY_SIZE | |
608 { | |
609 USHORT ax,ay,aw,ah; | |
610 ax = e->attr->win.px; | |
611 ay = e->attr->win.py; | |
612 aw = e->attr->win.sx; | |
613 ah = e->attr->win.sy; | |
614 dspl_DrawRect(ax,ay,(ax+aw-1),(ay+ah-1)); | |
615 { | |
616 /***************************Go-lite Optimization changes Start***********************/ | |
617 // Aug 16, 2004 REF: CRR 24323 Deepa M.D | |
618 TRACE_EVENT_P4(" ax:%d ay:%d aw:%d ah:%d",ax,ay,aw,ah); | |
619 /***************************Go-lite Optimization changes end***********************/ | |
620 } | |
621 } | |
622 #endif | |
623 dspl_set_char_type(temp); | |
624 resources_restoreColour(); | |
625 TIME_TRACE_EVENT("edtUpdate-end"); | |
626 return MfwResOk; | |
627 } | |
628 | |
629 | |
630 | |
631 //GW 18/09/01 - Corrected linefeed definition and added carriage return definition. | |
632 #define UNICODE_SPACE 0x2000 | |
633 #define UNICODE_LINEFEED 0x0A00 | |
634 #define UNICODE_CR 0x0D00 | |
635 #define UNICODE_EOLN 0x0000 | |
636 #define UNICODE_NONASCII 0x00FF | |
637 #define UNICODE_STARTHIGHLIGHT 0x0100 | |
638 #define UNICODE_ENDHIGHLIGHT 0x0200 | |
639 | |
640 | |
641 /* | |
642 +--------------------------------------------------------------------+ | |
643 | PROJECT : MMI-Framework (8417) MODULE : MFW_EDT | | |
644 | STATE : code ROUTINE : edtChar | | |
645 +--------------------------------------------------------------------+ | |
646 | |
647 PURPOSE : handle editing char | |
648 //GW 06/09/01 - Call chinese procedure if first char is 0x80,0x81 or 0x82 or display type is not ascii. | |
649 | |
650 */ | |
651 char getCursorChar(MfwHnd e, int offset ) | |
652 { | |
653 MfwEdt *edit; | |
654 int chPos; | |
655 | |
656 TRACE_FUNCTION("getCursorChar()"); | |
657 | |
658 if (!e) | |
659 return (0xFF); | |
660 | |
661 if (((MfwHdr *)e)->type != MfwTypEdt) | |
662 return (0xFF); /* not an editor */ | |
663 | |
664 edit = ((MfwHdr *) e)->data; | |
665 | |
666 | |
667 chPos = offset + edit->cp; | |
668 if ((chPos < 0) || (chPos > strlen(edit->attr->text))) | |
669 return (0x00); | |
670 else | |
671 return (edit->attr->text[chPos]); | |
672 } | |
673 int isAWordChar( char chr) | |
674 { TRACE_FUNCTION("isAWordChar()"); | |
675 | |
676 | |
677 | |
678 if ( ((chr >='A') && (chr <='Z')) || | |
679 ((chr >='a') && (chr <='z')) ) | |
680 return (TRUE); | |
681 else | |
682 return(FALSE); | |
683 } | |
684 MfwRes edtChar (MfwHnd e, int c) | |
685 { | |
686 int warn99; | |
687 MfwEdt *edit; | |
688 U16 bs; | |
689 int dy; //Change in cursor y position when moving up/down lines. | |
690 char *tbString; | |
691 int found; | |
692 | |
693 TRACE_FUNCTION("edtChar()"); | |
694 | |
695 if (!e) | |
696 return MfwResIllHnd; | |
697 | |
698 if (((MfwHdr *)e)->type != MfwTypEdt) | |
699 return MfwResIllHnd; /* not an editor */ | |
700 | |
701 edit = ((MfwHdr *) e)->data; | |
702 tbString = &edit->attr->text[0]; | |
703 | |
704 if (tbString[0] & 0x80) | |
705 { | |
706 return(edtCharUnicode(e,c)); | |
707 } | |
708 bs = edit->attr->size; | |
709 dy = 0; | |
710 switch (c) | |
711 { | |
712 | |
713 case ecEscape: //* quit editor | |
714 return MfwResDone; | |
715 case ecLeft: //* cursor left | |
716 if (edit->attr->mode & edtModWordSkip) | |
717 { | |
718 edit->cp = edit->cp-1; | |
719 if (isAWordChar(edit->attr->text[edit->cp])) | |
720 { //pointing to a letter in a word. Move left until next char is not a word char | |
721 found = FALSE; | |
722 while (!found) | |
723 { | |
724 if (edit->cp == 0) | |
725 found = TRUE; | |
726 else if (isAWordChar(edit->attr->text[edit->cp-1])) | |
727 edit->cp = edit->cp-1; | |
728 else | |
729 found = TRUE; | |
730 } | |
731 } | |
732 } | |
733 else | |
734 edit->cp = edit->cp-1; | |
735 if (edit->cp <= 0) | |
736 edit->cp = 0; | |
737 break; | |
738 case ecRight: //* cursor right | |
739 if (edit->attr->mode & edtModWordSkip) | |
740 { | |
741 if (!isAWordChar(edit->attr->text[edit->cp])) | |
742 edit->cp = edit->cp+1;//current char is not a word - move to next and stop. | |
743 else | |
744 { | |
745 found = FALSE; | |
746 while (!found) | |
747 { | |
748 edit->cp = edit->cp+1; | |
749 if (!isAWordChar(edit->attr->text[edit->cp])) | |
750 found = TRUE;//found a non-word char (could be the end of the string | |
751 } | |
752 } | |
753 } | |
754 else | |
755 edit->cp = edit->cp+1; | |
756 break; | |
757 case ecUp: //* cursor up | |
758 dy = -1; | |
759 break; | |
760 case ecDown: //* cursor down | |
761 dy = 1; | |
762 break; | |
763 case ecTop: //* cursor to start of text | |
764 edit->cp = 0; | |
765 edit->curOffs = 0; | |
766 break; | |
767 case ecBottom: //* cursor to end of text | |
768 edit->cp = strlen(tbString); | |
769 edit->curOffs = 0; | |
770 break; | |
771 case ecBack: //* backspace * | |
772 if ((edit->cp != 0) && (strlen(tbString)+1 > edit->cp)) | |
773 { | |
774 moveLeft(&tbString[edit->cp-1],1); | |
775 } | |
776 edit->cp = edit->cp-1; | |
777 if (edit->cp <= 0) | |
778 edit->cp = 0; | |
779 break; | |
780 case ecDel: //* delete * | |
781 if (strlen(tbString) > edit->cp) | |
782 { | |
783 moveLeft(&tbString[edit->cp],1); | |
784 } | |
785 break; | |
786 case ecEnter: //* cr/lf | |
787 c = UNICODE_LINEFEED; | |
788 edtInsert(c,tbString,bs, edit->curMode, edit->cp); | |
789 return (edtChar(e,ecRight)); | |
790 break; | |
791 default: //* normal char | |
792 edtInsert(c,tbString,bs, edit->curMode, edit->cp); | |
793 | |
794 if (edit->attr->alphaMode NEQ TRUE) | |
795 return (edtChar(e,ecRight)); | |
796 /*NM, p003 end*/ | |
797 break; | |
798 } | |
799 edit->display = 1; //* really show it | |
800 updateWindow( edit, dy); | |
801 edtUpdate(edit); | |
802 | |
803 return MfwResOk; | |
804 } | |
805 | |
806 | |
807 /* | |
808 +--------------------------------------------------------------------+ | |
809 | PROJECT : MMI-Framework (8417) MODULE : MFW_EDT | | |
810 | STATE : code ROUTINE : edtCharUnicode | | |
811 +--------------------------------------------------------------------+ | |
812 | |
813 PURPOSE : | |
814 | |
815 GW 06/09/01 - Created | |
816 */ | |
817 MfwRes edtCharUnicode (MfwHnd e, int c) | |
818 { | |
819 MfwEdt *edit; | |
820 U16 bs; | |
821 int dy; | |
822 U16 *tbUnicode; | |
823 | |
824 TRACE_FUNCTION("edtCharUnicode()"); | |
825 | |
826 if (!e) | |
827 return MfwResIllHnd; | |
828 | |
829 if (((MfwHdr *)e)->type != MfwTypEdt) | |
830 return MfwResIllHnd; //* not an editor | |
831 | |
832 edit = ((MfwHdr *) e)->data; | |
833 bs = edit->attr->size; | |
834 tbUnicode = (U16*) &edit->attr->text[2]; | |
835 | |
836 dy = 0; | |
837 switch (c) | |
838 { | |
839 case ecEscape: //* quit editor | |
840 return MfwResDone; | |
841 case ecLeft: //* cursor left | |
842 if (edit->cp <= 0) | |
843 edit->cp = 0; | |
844 else | |
845 edit->cp = edit->cp-1; | |
846 break; | |
847 case ecRight: //* cursor right | |
848 if (tbUnicode[edit->cp]!=UNICODE_EOLN) | |
849 edit->cp = edit->cp +1; | |
850 break; | |
851 case ecUp: //* cursor up | |
852 dy = -1; | |
853 break; | |
854 case ecDown: //* cursor down | |
855 dy = 1; | |
856 break; | |
857 case ecTop: //* cursor to start of text | |
858 edit->cp = 0; | |
859 edit->curOffs = 0; | |
860 dy = 0; | |
861 break; | |
862 case ecBottom: //* cursor to end of text | |
863 while (tbUnicode[edit->cp]!=UNICODE_EOLN) | |
864 { | |
865 edit->cp = edit->cp +1; | |
866 } | |
867 break; | |
868 case ecBack: //* backspace | |
869 if (edit->cp != 0) | |
870 moveLeftUnicode(tbUnicode+edit->cp-1,1); | |
871 return edtCharUnicode(e,ecLeft); | |
872 case ecDel: //* delete | |
873 moveLeftUnicode(tbUnicode+edit->cp,1); | |
874 break; | |
875 case ecEnter: //* cr/lf | |
876 c = UNICODE_LINEFEED; | |
877 edtInsertUnicode(edit,c,tbUnicode,bs); | |
878 return edtCharUnicode(e,ecRight); | |
879 default: //* normal char | |
880 edtInsertUnicode(edit,c,tbUnicode,bs); | |
881 | |
882 if (edit->attr->alphaMode NEQ TRUE) | |
883 return (edtCharUnicode(e,ecRight)); | |
884 /*MC end*/ | |
885 break; | |
886 | |
887 } | |
888 edit->display = 1; // really show it | |
889 updateWindow( edit, dy); | |
890 edtUpdateUnicode(edit); | |
891 | |
892 | |
893 return MfwResOk; | |
894 } | |
895 | |
896 | |
897 | |
898 | |
899 /* | |
900 +--------------------------------------------------------------------+ | |
901 | PROJECT : MMI-Framework (8417) MODULE : MFW_EDT | | |
902 | STATE : code ROUTINE : | | |
903 +--------------------------------------------------------------------+ | |
904 | |
905 PURPOSE : Return no of chinese chars in a string | |
906 | |
907 GW 06/09/01 - Created | |
908 GW 25/09/01 - Corrected length - now skips first two chars. | |
909 */ | |
910 | |
911 U16 strlenUnicode(U16* str) | |
912 { | |
913 U16 len = 2; //First char is 0x80, second char is 0x00 | |
914 | |
915 TRACE_FUNCTION("strlenUnicode()"); | |
916 | |
917 while (*str!=UNICODE_EOLN) | |
918 { | |
919 //treat ascii chars as half size chinese chars. | |
920 len = len + 2; | |
921 str++; | |
922 } | |
923 return (len); | |
924 } | |
925 | |
926 | |
927 //Assumptions :- | |
928 //str is a null-terminated string | |
929 //edit->cp is the cursor position of the char | |
930 //The string is inserted before the cursor char | |
931 //The cursor is moved strlen(str) chars forward. | |
932 MfwRes edtInsertString (MfwHnd e, char* insWord) | |
933 { | |
934 MfwEdt *edit; | |
935 char *textBfr; | |
936 | |
937 int lenText; | |
938 int lenInsWord; | |
939 int maxTextBfrLen; | |
940 int i; | |
941 | |
942 | |
943 TRACE_FUNCTION("edtInsertString()"); | |
944 | |
945 if (!e) | |
946 return MfwResIllHnd; | |
947 | |
948 if (((MfwHdr *)e)->type != MfwTypEdt) | |
949 return MfwResIllHnd; /* not an editor */ | |
950 | |
951 edit = ((MfwHdr *) e)->data; | |
952 if (insWord == NULL) | |
953 return (MfwResOk); //no string to insert - trivial operation. | |
954 if (insWord[0] == 0x00) | |
955 return (MfwResOk); //no string to insert - trivial operation. | |
956 textBfr = edit->attr->text; | |
957 if ((textBfr[0] == 0x80) || (textBfr[1] == 0x81) || (textBfr[2] == 0x82)) | |
958 {//String is unicode | |
959 return (edtInsertUnicodeString (e, insWord)); | |
960 } | |
961 maxTextBfrLen = edit->attr->size; | |
962 lenText = strlen(textBfr); | |
963 lenInsWord = strlen(insWord); | |
964 if ((lenText+lenInsWord) >= maxTextBfrLen) | |
965 return (MfwResErr); //String too long | |
966 | |
967 //move text up by 'lemnInsWord' words | |
968 for (i=lenText;i>=edit->cp;i--) | |
969 { | |
970 textBfr[i+lenInsWord]=textBfr[i]; | |
971 } | |
972 //and copy string into buffer. | |
973 for (i=0;i<lenInsWord;i++) | |
974 textBfr[edit->cp+i] = insWord[i]; | |
975 edit->cp = edit->cp+lenInsWord; | |
976 //Update cursor position | |
977 //<TBD> | |
978 //And output updated text | |
979 edit->display = 1; | |
980 updateWindow( edit, 0); | |
981 edtUpdate(edit); | |
982 | |
983 return MfwResOk; | |
984 } | |
985 #define MAXWORD_ARRAY 32 | |
986 //Assumptions :- | |
987 //'removeWord' is char array of MAXWORD chars | |
988 //edit->cp is the cursor position of the char | |
989 //The word removed is at or just before the cursor char | |
990 //The cursor is placed before the previous word. | |
991 //a space char (start or end) will be removed if there is one. | |
992 //GW 18/09/01 - Use 'isAWordChar' procedure | |
993 MfwRes edtRemoveString (MfwHnd e, char* removeWord) | |
994 { | |
995 MfwEdt *edit; | |
996 char *textBfr; | |
997 | |
998 int i,j; | |
999 int stChr,endChr; | |
1000 | |
1001 TRACE_FUNCTION("edtRemoveString"); | |
1002 | |
1003 if (dspl_get_char_type() != DSPL_TYPE_ASCII) | |
1004 { //String is unicode - can't remove word (could remove a char but...) | |
1005 return(MfwResIllHnd); | |
1006 } | |
1007 | |
1008 if (!e) | |
1009 return MfwResIllHnd; | |
1010 | |
1011 if (((MfwHdr *)e)->type != MfwTypEdt) | |
1012 return MfwResIllHnd; //* not an editor * | |
1013 | |
1014 edit = ((MfwHdr *) e)->data; | |
1015 textBfr = edit->attr->text; | |
1016 if ((textBfr[0] == 0x80) || (textBfr[1] == 0x81) || (textBfr[2] == 0x82)) | |
1017 {//String is unicode - can't remove word (could remove a char but...) | |
1018 return(MfwResIllHnd); | |
1019 } | |
1020 | |
1021 findWordBounds(edit, &stChr, &endChr); | |
1022 //Copy word out | |
1023 j = 0; | |
1024 for (i=stChr;i<endChr;i++) | |
1025 { | |
1026 if (j<MAXWORD_ARRAY-1) | |
1027 { | |
1028 removeWord[j] = textBfr[i]; | |
1029 if (isAWordChar(removeWord[j])) | |
1030 j++;//not punctuation . | |
1031 else if (removeWord[j] == ' ') //but do include last space (if it is a space) | |
1032 j++; | |
1033 } | |
1034 } | |
1035 removeWord[j] = 0x00; | |
1036 | |
1037 //and now move text up by 'j' chars. | |
1038 i=stChr; | |
1039 j=endChr; | |
1040 //skip one space at start/end. | |
1041 if (textBfr[i] != ' ') | |
1042 { | |
1043 i++; | |
1044 if (textBfr[j] == ' ') | |
1045 j++; | |
1046 } | |
1047 //else overwrite first space | |
1048 edit->cp = i; | |
1049 | |
1050 while((textBfr[i] != 0x00) && (i < j)) | |
1051 { | |
1052 textBfr[i] = textBfr[j]; | |
1053 i++; | |
1054 j++; | |
1055 } | |
1056 | |
1057 edit->display = 1; | |
1058 updateWindow( edit, 0); | |
1059 edtUpdate(edit); | |
1060 | |
1061 return MfwResOk; | |
1062 } | |
1063 | |
1064 | |
1065 //Create a copy of the current word. | |
1066 //GW 18/09/01 - Use 'isAWordChar' procedure | |
1067 MfwRes edtCopyString (MfwHnd e, char* removeWord) | |
1068 { | |
1069 MfwEdt *edit; | |
1070 char *textBfr; | |
1071 | |
1072 int i,j; | |
1073 int stChr,endChr; | |
1074 | |
1075 TRACE_FUNCTION("edtCopyString"); | |
1076 | |
1077 if (dspl_get_char_type() != DSPL_TYPE_ASCII) | |
1078 { //String is unicode - can't remove word (could remove a char but...) | |
1079 return(MfwResIllHnd); | |
1080 } | |
1081 | |
1082 if (!e) | |
1083 return MfwResIllHnd; | |
1084 | |
1085 if (((MfwHdr *)e)->type != MfwTypEdt) | |
1086 return MfwResIllHnd; //* not an editor * | |
1087 | |
1088 edit = ((MfwHdr *) e)->data; | |
1089 textBfr = edit->attr->text; | |
1090 if ((textBfr[0] == 0x80) || (textBfr[0] == 0x81) || (textBfr[0] == 0x82)) | |
1091 {//String is unicode - can't remove word (could remove a char but...) | |
1092 return(MfwResIllHnd); | |
1093 } | |
1094 | |
1095 findWordBounds(edit, &stChr, &endChr); | |
1096 //Copy word out | |
1097 j = 0; | |
1098 for (i=stChr;i<endChr;i++) | |
1099 { | |
1100 if (j<MAXWORD_ARRAY-1) | |
1101 { | |
1102 removeWord[j] = textBfr[i]; | |
1103 if (isAWordChar(removeWord[j])) | |
1104 j++;//not punctuation. | |
1105 else if (removeWord[j] == ' ') //but do include last space (if it is a space) | |
1106 j++; | |
1107 } | |
1108 } | |
1109 removeWord[j] = 0x00; | |
1110 | |
1111 edit->display = 1; | |
1112 updateWindow( edit, 0); | |
1113 edtUpdate(edit); | |
1114 | |
1115 return MfwResOk; | |
1116 } | |
1117 | |
1118 | |
1119 | |
1120 | |
1121 MfwRes edtInsertUnicodeString (MfwHnd e, char* insWordChar) | |
1122 { | |
1123 MfwEdt *edit; | |
1124 U16 *unicodeBfr; | |
1125 | |
1126 int lenText; | |
1127 int lenInsWord; | |
1128 int maxTextBfrLen; | |
1129 int i; | |
1130 U16* insWordUnicode; | |
1131 insWordUnicode = (U16*) insWordChar; | |
1132 | |
1133 | |
1134 TRACE_FUNCTION("edtInsertUnicodeString"); | |
1135 if (!e) | |
1136 return MfwResIllHnd; | |
1137 | |
1138 if (((MfwHdr *)e)->type != MfwTypEdt) | |
1139 return MfwResIllHnd; //* not an editor | |
1140 | |
1141 edit = ((MfwHdr *) e)->data; | |
1142 if (insWordUnicode == NULL) | |
1143 return (MfwResOk); //no string to insert - trivial operation. | |
1144 if (insWordUnicode[0] == 0x0000) | |
1145 return (MfwResOk); //no string to insert - trivial operation. | |
1146 unicodeBfr = (U16*) &edit->attr->text[2]; | |
1147 if ((edit->attr->text[0] != (char)0x80) && | |
1148 (edit->attr->text[0] != (char)0x81) && | |
1149 (edit->attr->text[0] != (char)0x82)) | |
1150 {//String is unicode | |
1151 return (edtInsertString (e, insWordChar)); | |
1152 } | |
1153 | |
1154 maxTextBfrLen = edit->attr->size; | |
1155 lenText = strlenUnicode(unicodeBfr); | |
1156 lenInsWord = strlenUnicode(insWordUnicode); | |
1157 if ((lenText+lenInsWord) >= maxTextBfrLen) | |
1158 return (MfwResErr); //String too long | |
1159 | |
1160 //move text up by 'lemnInsWord' chars | |
1161 for (i=lenText/2;i>=edit->cp;i--) | |
1162 { | |
1163 unicodeBfr[i+lenInsWord]=unicodeBfr[i]; | |
1164 } | |
1165 //and copy string into buffer. | |
1166 for (i=0;i<lenInsWord/2;i++) | |
1167 unicodeBfr[edit->cp+i] = insWordUnicode[i]; | |
1168 edit->cp = edit->cp+lenInsWord/2; | |
1169 //Update cursor position | |
1170 //<TBD> | |
1171 //And output updated text | |
1172 edit->display = 1; | |
1173 updateWindow( edit, 0); | |
1174 edtUpdateUnicode(edit); | |
1175 | |
1176 return MfwResOk; | |
1177 } | |
1178 | |
1179 | |
1180 | |
1181 | |
1182 /* | |
1183 | |
1184 | |
1185 | |
1186 | |
1187 | |
1188 | |
1189 +--------------------------------------------------------------------+ | |
1190 | PROJECT : MMI-Framework (8417) MODULE : MFW_EDT | | |
1191 | STATE : code ROUTINE : edtInsert | | |
1192 +--------------------------------------------------------------------+ | |
1193 | |
1194 PURPOSE : insert editing char | |
1195 SPR1017 - NH - Added "curMode" and "curCP" parameters. | |
1196 | |
1197 */ | |
1198 | |
1199 static int edtInsert (int c, char *b, int s, U8 curMode, U16 curCP) | |
1200 { | |
1201 int size = (c > 0x80) ? 2 : 1; | |
1202 | |
1203 TRACE_FUNCTION("edtInsert"); | |
1204 if (!curMode) | |
1205 return 0; | |
1206 | |
1207 if (!(curMode & edtModOverWr)) | |
1208 { | |
1209 if ((int) strlen(b) >= s - size) /* no more space in buffer */ | |
1210 return 0; | |
1211 | |
1212 moveRight(b+curCP,strlen(b+curCP),size); | |
1213 } | |
1214 else | |
1215 { | |
1216 if (curCP > s-size ) /* SH - for overwrite mode, only stop input */ | |
1217 return 0; /* when the cursor is at the maximum string size */ | |
1218 } | |
1219 | |
1220 if (size == 2) | |
1221 *((U16 *) (b+curCP)) = (U16) c; | |
1222 else | |
1223 { | |
1224 *(b+strlen(b)+1) = (char) 0; // SH - make sure string is null terminated | |
1225 *(b+curCP) = (char) c; | |
1226 } | |
1227 return 1; | |
1228 } | |
1229 | |
1230 | |
1231 /* | |
1232 +--------------------------------------------------------------------+ | |
1233 | PROJECT : MMI-Framework (8417) MODULE : MFW_EDT | | |
1234 | STATE : code ROUTINE : moveRight | | |
1235 +--------------------------------------------------------------------+ | |
1236 | |
1237 PURPOSE : move right memory | |
1238 s = no of chars to move | |
1239 d = size (no of chars to be inserted in string) | |
1240 b = current position | |
1241 */ | |
1242 void moveRight (char *b, int s, int d) | |
1243 { | |
1244 char *p; | |
1245 | |
1246 TRACE_FUNCTION("edtInsert"); | |
1247 | |
1248 b += s++; /* start with trailing zero */ | |
1249 p = b + d; /* new = old + distance */ | |
1250 while (s--) | |
1251 { | |
1252 *p = *b; | |
1253 p--; | |
1254 b--; | |
1255 } | |
1256 } | |
1257 | |
1258 /* | |
1259 +--------------------------------------------------------------------+ | |
1260 | PROJECT : MMI-Framework (8417) MODULE : MFW_EDT | | |
1261 | STATE : code ROUTINE : moveLeft | | |
1262 +--------------------------------------------------------------------+ | |
1263 | |
1264 PURPOSE : move left memory | |
1265 s = no of chars to move | |
1266 d = size (no of chars to be inserted in string) | |
1267 b = current position | |
1268 str - string | |
1269 */ | |
1270 void moveLeft (char * str, int ofs) | |
1271 { | |
1272 | |
1273 | |
1274 while (*str) | |
1275 { | |
1276 str[0] = str[ofs]; | |
1277 if (*str) | |
1278 str++; | |
1279 } | |
1280 | |
1281 } | |
1282 | |
1283 | |
1284 /* | |
1285 +--------------------------------------------------------------------+ | |
1286 | PROJECT : MMI-Framework (8417) MODULE : MFW_EDT | | |
1287 | STATE : code ROUTINE : edtCommand | | |
1288 +--------------------------------------------------------------------+ | |
1289 | |
1290 PURPOSE : handle mfw windows command | |
1291 | |
1292 */ | |
1293 | |
1294 static int edtCommand (U32 cmd, void *h) | |
1295 { | |
1296 TRACE_FUNCTION("edtCommand"); | |
1297 | |
1298 switch (cmd) | |
1299 { | |
1300 case MfwCmdDelete: /* delete me */ | |
1301 if (!h) | |
1302 return 0; | |
1303 edtDelete(h); | |
1304 return 1; | |
1305 case MfwCmdUpdate: /* repaint */ | |
1306 if (!h || ((MfwHdr *) h)->type != MfwTypEdt) | |
1307 return 0; | |
1308 edtUpdate(((MfwHdr *) h)->data); | |
1309 return 1; | |
1310 default: | |
1311 break; | |
1312 } | |
1313 | |
1314 return 0; | |
1315 } | |
1316 | |
1317 | |
1318 | |
1319 | |
1320 /* | |
1321 +--------------------------------------------------------------------+ | |
1322 | PROJECT : MMI-Framework (8417) MODULE : MFW_EDT | | |
1323 | STATE : code ROUTINE : | | |
1324 +--------------------------------------------------------------------+ | |
1325 | |
1326 PURPOSE : | |
1327 | |
1328 GW 06/09/01 - Created | |
1329 */ | |
1330 //Move part of string right (delete char) | |
1331 void moveLeftUnicode(U16* unicodeStr, int nChars) | |
1332 { | |
1333 TRACE_FUNCTION("moveLeftUnicode"); | |
1334 //Copy until end of line char reached - do not overwrite existing EOLN char | |
1335 while (unicodeStr[0] != UNICODE_EOLN) | |
1336 { | |
1337 unicodeStr[0] = unicodeStr[nChars]; | |
1338 if (unicodeStr[0] != UNICODE_EOLN) | |
1339 unicodeStr++; | |
1340 //else we have copied end of line char - stop. | |
1341 } | |
1342 | |
1343 } | |
1344 | |
1345 | |
1346 /* | |
1347 +--------------------------------------------------------------------+ | |
1348 | PROJECT : MMI-Framework (8417) MODULE : MFW_EDT | | |
1349 | STATE : code ROUTINE : | | |
1350 +--------------------------------------------------------------------+ | |
1351 | |
1352 PURPOSE : | |
1353 | |
1354 GW 06/09/01 - Created | |
1355 */ | |
1356 U16 strlenUnicodePixels(U16* str) | |
1357 { | |
1358 U16 len = 0; | |
1359 | |
1360 TRACE_FUNCTION("strlenUnicodePixels"); | |
1361 | |
1362 while (*str!=UNICODE_EOLN) | |
1363 { //Is next char an ascii char ? | |
1364 if ((*str & UNICODE_NONASCII) != 0) | |
1365 len = len+12; | |
1366 else | |
1367 len = len+6; | |
1368 str++; | |
1369 } | |
1370 return (len); | |
1371 } | |
1372 | |
1373 /* | |
1374 +--------------------------------------------------------------------+ | |
1375 | PROJECT : MMI-Framework (8417) MODULE : MFW_EDT | | |
1376 | STATE : code ROUTINE : | | |
1377 +--------------------------------------------------------------------+ | |
1378 | |
1379 PURPOSE : | |
1380 | |
1381 GW 06/09/01 - Created | |
1382 */ | |
1383 U16* strchrUnicode(U16* str,U16 chr) | |
1384 { | |
1385 TRACE_FUNCTION("strchrUnicode"); | |
1386 | |
1387 while (*str!=UNICODE_EOLN) | |
1388 { | |
1389 if (*str==chr) | |
1390 return (str); | |
1391 else | |
1392 str++; | |
1393 } | |
1394 return (NULL); | |
1395 } | |
1396 | |
1397 /* | |
1398 +--------------------------------------------------------------------+ | |
1399 | PROJECT : MMI-Framework (8417) MODULE : MFW_EDT | | |
1400 | STATE : code ROUTINE : | | |
1401 +--------------------------------------------------------------------+ | |
1402 | |
1403 PURPOSE : | |
1404 | |
1405 GW 06/09/01 - Created | |
1406 */ | |
1407 //Return pointer to end of unicode string. | |
1408 U16* strendUnicode(U16* tp) | |
1409 { TRACE_FUNCTION("strendUnicode"); | |
1410 while (*tp!=UNICODE_EOLN) | |
1411 { | |
1412 tp++; | |
1413 } | |
1414 return (tp); | |
1415 | |
1416 } | |
1417 /* | |
1418 +--------------------------------------------------------------------+ | |
1419 | PROJECT : MMI-Framework (8417) MODULE : MFW_EDT | | |
1420 | STATE : code ROUTINE : | | |
1421 +--------------------------------------------------------------------+ | |
1422 | |
1423 PURPOSE : | |
1424 | |
1425 GW 06/09/01 - Created | |
1426 */ | |
1427 //Move string right by 'nChars' (insert char) | |
1428 static void moveRightUnicode(U16 *unicodeStr, int nChars) | |
1429 { | |
1430 U16* strEndPtr; | |
1431 | |
1432 TRACE_FUNCTION("moveRightUnicode"); | |
1433 | |
1434 strEndPtr = strendUnicode( unicodeStr); | |
1435 while (strEndPtr >= unicodeStr) | |
1436 { | |
1437 strEndPtr[nChars] = strEndPtr[0]; | |
1438 strEndPtr--; | |
1439 } | |
1440 } | |
1441 | |
1442 static int edtInsertUnicode (MfwEdt *edit, int c, U16 *b, int s) | |
1443 { //Unicode chars are always 2 bytes. | |
1444 U16* bCursor; | |
1445 | |
1446 TRACE_FUNCTION("edtInsertUnicode"); | |
1447 | |
1448 if (!edit->curMode) | |
1449 return 0; | |
1450 | |
1451 if ( strlenUnicode(b) >= s/* -2 MC SPR 1319, allow last 2 bytes to be used*/ ) //* no more space in buffer * | |
1452 return 0; | |
1453 | |
1454 bCursor = b+edit->cp; | |
1455 | |
1456 if (!(edit->curMode & edtModOverWr)) | |
1457 moveRightUnicode(bCursor,1); | |
1458 | |
1459 *((U16 *) (b+edit->cp )) = (U16) c; | |
1460 | |
1461 return 1; | |
1462 | |
1463 } | |
1464 | |
1465 int wArray[20]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; | |
1466 | |
1467 int getCharWidth(int nextChar) | |
1468 { | |
1469 int w; | |
1470 if ((nextChar == UNICODE_LINEFEED) || (nextChar == UNICODE_CR)) | |
1471 w = 6; | |
1472 else | |
1473 w = font_getCharWidth( ((nextChar & 0x00FF) <<8) | ((nextChar & 0xFF00) >>8) ); | |
1474 return (w); | |
1475 } | |
1476 | |
1477 static void edtOutTextLines (int px, int py, int ls, int ly, U16 *tpUnicode, unsigned char* tpAscii, | |
1478 int fontHeight, int display) | |
1479 { | |
1480 U16 ctWord; | |
1481 unsigned char ctByte; | |
1482 unsigned int fitChars; //No of chars that fit on this line. | |
1483 U16 nextChar; //next char to display | |
1484 int lineWidth; //Width (so far) of the current line of text. | |
1485 int dispEnd = 0; | |
1486 int spaceChar; | |
1487 int charWidth; | |
1488 int punctuation; | |
1489 char chr; | |
1490 if ((tpAscii==NULL) && (tpUnicode == NULL)) | |
1491 return; | |
1492 | |
1493 | |
1494 fitChars = 0; | |
1495 if (tpAscii) | |
1496 { | |
1497 nextChar = (tpAscii[fitChars] << 8) & 0xFF00; | |
1498 if ((nextChar == UNICODE_LINEFEED) || (nextChar == UNICODE_CR)) | |
1499 { | |
1500 fitChars++; | |
1501 nextChar = (tpAscii[fitChars] << 8) & 0xFF00; | |
1502 } | |
1503 } | |
1504 else | |
1505 { | |
1506 nextChar = tpUnicode[fitChars]; | |
1507 if ((nextChar == UNICODE_LINEFEED) || (nextChar == UNICODE_CR)) | |
1508 { | |
1509 fitChars++; | |
1510 nextChar = tpUnicode[fitChars]; | |
1511 } | |
1512 } | |
1513 | |
1514 while ((nextChar != UNICODE_EOLN) && (!dispEnd)) /* any more to display */ | |
1515 { | |
1516 fitChars = 0; | |
1517 if (tpAscii) | |
1518 { | |
1519 charWidth = getCharWidth(nextChar); | |
1520 nextChar = (tpAscii[fitChars] << 8) & 0xFF00; | |
1521 if ((nextChar == UNICODE_LINEFEED) || (nextChar == UNICODE_CR)) | |
1522 { //linefeed - always start a new-line. | |
1523 charWidth = ls+1; | |
1524 } | |
1525 } | |
1526 else | |
1527 { | |
1528 nextChar = tpUnicode[fitChars]; | |
1529 charWidth = getCharWidth(nextChar); | |
1530 if ((nextChar == UNICODE_LINEFEED) || (nextChar == UNICODE_CR)) | |
1531 { //linefeed - always start a new-line. | |
1532 charWidth = ls+1; | |
1533 } | |
1534 } | |
1535 lineWidth = 0; | |
1536 spaceChar = -1; | |
1537 | |
1538 while ((lineWidth <= ls) && (nextChar != UNICODE_EOLN)) | |
1539 { | |
1540 lineWidth = lineWidth + charWidth; | |
1541 | |
1542 //If the last char added still fits on the line | |
1543 if (lineWidth <= ls) | |
1544 { //move on to the next character. | |
1545 fitChars++; | |
1546 //if the previous char was a space, we can cut the line on the next char. | |
1547 punctuation = FALSE; | |
1548 if ((nextChar & UNICODE_NONASCII) == 0) | |
1549 { | |
1550 chr = (nextChar >> 8) & 0x00FF; | |
1551 if (chr==' ') // sbh - only space is punctuation now. | |
1552 punctuation = TRUE; | |
1553 } | |
1554 //Remember when we find a space if it is not the first char of a new line | |
1555 if ((fitChars > 1) && | |
1556 ((punctuation) || | |
1557 (nextChar == UNICODE_STARTHIGHLIGHT)|| | |
1558 (nextChar == UNICODE_ENDHIGHLIGHT))) | |
1559 { //save char after space. | |
1560 spaceChar = fitChars; | |
1561 } | |
1562 if (tpAscii) | |
1563 { | |
1564 charWidth = getCharWidth(nextChar); | |
1565 nextChar = (tpAscii[fitChars] << 8) & 0xFF00; | |
1566 } | |
1567 else | |
1568 { | |
1569 nextChar = tpUnicode[fitChars]; | |
1570 charWidth = getCharWidth(nextChar); | |
1571 } | |
1572 if ((nextChar == UNICODE_LINEFEED) || (nextChar == UNICODE_CR)) | |
1573 { //linefeed - always start a new-line. | |
1574 charWidth = ls+1; | |
1575 } | |
1576 | |
1577 } | |
1578 } | |
1579 if (nextChar == UNICODE_EOLN) | |
1580 { /* all fits fine ... */ | |
1581 dispEnd = TRUE; | |
1582 } | |
1583 else if ((nextChar == UNICODE_LINEFEED) || (nextChar == UNICODE_CR)) | |
1584 { //Break line on this linefeed char | |
1585 } | |
1586 else if (spaceChar != -1) // we have a space in the line | |
1587 { | |
1588 fitChars = spaceChar; | |
1589 } | |
1590 if (tpAscii) | |
1591 { | |
1592 ctByte = tpAscii[fitChars]; /* save not fitting char */ | |
1593 tpAscii[fitChars] = 0x00;//UNICODE_EOLN; /* cut the line */ | |
1594 if (display) | |
1595 dspl_TextOut((U16)px,(U16)py, 0, (char*)tpAscii); /* display line */ | |
1596 tpAscii[fitChars] = ctByte; /* restore */ | |
1597 tpAscii = &tpAscii[fitChars]; /* and go ahead */ | |
1598 //For linefeed char - move to next char. | |
1599 if (((ctByte <<8) == UNICODE_LINEFEED) || ((ctByte <<8) == UNICODE_CR)) | |
1600 tpAscii++; | |
1601 | |
1602 } | |
1603 else | |
1604 { | |
1605 ctWord = tpUnicode[fitChars]; /* save not fitting char */ | |
1606 tpUnicode[fitChars] = UNICODE_EOLN; /* cut the line */ | |
1607 if (display) | |
1608 dspl_TextOut((U16)px,(U16)py, DSPL_TXTATTR_UNICODE, (char*)tpUnicode); /* display line */ | |
1609 tpUnicode[fitChars] = ctWord; /* restore */ | |
1610 tpUnicode = &tpUnicode[fitChars]; /* and go ahead */ | |
1611 if ((ctWord == UNICODE_LINEFEED) || (ctWord == UNICODE_CR)) | |
1612 tpUnicode++; | |
1613 } | |
1614 py = py + fontHeight; /* move to next screen line */ | |
1615 if (py > ly - fontHeight) /* past end of screen ? */ | |
1616 dispEnd = TRUE; /* clip the rest */ | |
1617 } | |
1618 } | |
1619 | |
1620 /* | |
1621 +--------------------------------------------------------------------+ | |
1622 | PROJECT : MMI-Framework (8417) MODULE : MFW_EDT | | |
1623 | STATE : code ROUTINE : | | |
1624 +--------------------------------------------------------------------+ | |
1625 | |
1626 PURPOSE : | |
1627 | |
1628 GW 06/09/01 - Created | |
1629 */ | |
1630 MfwRes edtUpdateUnicode (MfwEdt *e) | |
1631 { | |
1632 int warn; | |
1633 UBYTE temp; | |
1634 | |
1635 S16 ls; /* width of edit window */ | |
1636 S16 ly; /* bottom of edit window */ | |
1637 U8 oldFont = -1; /* store previous font */ | |
1638 /* NM p004 | |
1639 U8 uMode; | |
1640 */ | |
1641 U16 *tpWord; | |
1642 U16 *endChar; | |
1643 static char bmp[5]; | |
1644 | |
1645 TRACE_FUNCTION("edtUpdateUnicode"); | |
1646 | |
1647 if (!e) | |
1648 return MfwResIllHnd; | |
1649 | |
1650 if (!e->attr->text) | |
1651 return MfwResErr; /* no text to display */ | |
1652 | |
1653 if (((unsigned char)e->attr->text[0] < 0x80) || ((unsigned char)e->attr->text[0] > 0x83)) | |
1654 return MfwResErr; /* text is not unicode */ | |
1655 | |
1656 temp = dspl_get_char_type(); | |
1657 dspl_set_char_type(DSPL_TYPE_UNICODE); | |
1658 | |
1659 if (!(e->flags & MfwEdtVisible)) | |
1660 e->display = 0; /* invisible editor */ | |
1661 | |
1662 tpWord = ((U16*)&e->attr->text[2]) + e->curOffs; | |
1663 ls = e->attr->win.sx; /* width of edit window */ | |
1664 ly = (S16) (e->attr->win.py+e->attr->win.sy); /* bottom of edit window */ | |
1665 if (e->attr->font != (U8) -1) | |
1666 oldFont = dspl_SelectFontbyID(e->attr->font); /* setup font */ | |
1667 e->fontHeight = dspl_GetFontHeight(); /* get height of curr font */ | |
1668 e->curMode = e->attr->mode; /* setup edi mode */ | |
1669 if (e->display) | |
1670 dspl_Clear(e->attr->win.px,e->attr->win.py,(U16)(ls+e->attr->win.px-1),(U16)(ly-1)); | |
1671 dspl_SetCursor(0,(U8)(e->curMode&edtCurMask)); | |
1672 | |
1673 //Add a space to the end of the line | |
1674 endChar = strendUnicode(tpWord); | |
1675 if ((endChar[0] == UNICODE_EOLN) && | |
1676 (endChar[1] == UNICODE_EOLN)) | |
1677 { | |
1678 | |
1679 endChar[0] = UNICODE_SPACE; | |
1680 endChar[1] = UNICODE_EOLN; | |
1681 | |
1682 edtOutTextLines(e->attr->win.px, e->attr->win.py, ls, ly, tpWord, NULL, | |
1683 e->fontHeight, e->display); //* show it * / | |
1684 | |
1685 //and remove space again. | |
1686 endChar[0] = UNICODE_EOLN; | |
1687 } | |
1688 else | |
1689 { //Cannot add space | |
1690 edtOutTextLines(e->attr->win.px, e->attr->win.py, ls, ly, tpWord, NULL, | |
1691 e->fontHeight, e->display); //* show it * / | |
1692 } | |
1693 | |
1694 | |
1695 if (e->display && (e->curMode & edtCurMask)) | |
1696 dspl_SetCursorPos(e->curCX,e->curCY,e->curCSize,(S16)e->fontHeight); /* display cursor */ | |
1697 if (oldFont != (U8) -1) | |
1698 dspl_SelectFontbyID(oldFont); /* restore previous font */ | |
1699 | |
1700 | |
1701 | |
1702 dspl_set_char_type(temp); | |
1703 | |
1704 return MfwResOk; | |
1705 } | |
1706 | |
1707 | |
1708 /* | |
1709 +--------------------------------------------------------------------+ | |
1710 | PROJECT : MMI-Framework (8417) MODULE : MFW_EDT | | |
1711 | STATE : code ROUTINE : | | |
1712 +--------------------------------------------------------------------+ | |
1713 | |
1714 PURPOSE : | |
1715 | |
1716 GW 06/09/01 - Created | |
1717 */ | |
1718 | |
1719 //Incodmation relating to last 'space' char found. | |
1720 typedef struct { | |
1721 int charWidth; | |
1722 int lineCharPos; | |
1723 } T_SPACE_EDITINFO; | |
1724 | |
1725 //Information about current editor | |
1726 typedef struct { | |
1727 int txtWidth; | |
1728 int charWidth; | |
1729 int endOfLine; //TRUE indicates end of a text line | |
1730 int endOfText; //TRUE indicates no more chars in line. | |
1731 int lineXpos; //Current x-pos (in pixels) of cursor. | |
1732 int lineCharPos; //Current char/word position in array | |
1733 int lastChar; //index of last char on cursor line | |
1734 BOOL precedingEOL; // sbh - preceding character was a CR/LF | |
1735 T_SPACE_EDITINFO space; | |
1736 } T_EDITINFO; | |
1737 | |
1738 | |
1739 //Calculate width of chars on screen so far. | |
1740 //GW 18/09/01 - Corrected code dealing with linefeeds and also deal with carriage returns. | |
1741 void getTotalWidth(U16 txtChar, int scrSxPixels, T_EDITINFO *editInfo ) | |
1742 { | |
1743 char chr; | |
1744 int punctuation; | |
1745 | |
1746 TRACE_FUNCTION("getTotalWidth"); | |
1747 | |
1748 editInfo->endOfLine = FALSE; | |
1749 | |
1750 if (editInfo->precedingEOL) // Previous character was CR/LF | |
1751 { | |
1752 editInfo->precedingEOL = FALSE; | |
1753 editInfo->endOfLine = TRUE; | |
1754 } | |
1755 | |
1756 if (txtChar == UNICODE_EOLN) | |
1757 { | |
1758 editInfo->endOfText = TRUE; | |
1759 editInfo->charWidth = getCharWidth(txtChar);//6; // sbh - Has width, so it can be wrapped if necessary | |
1760 } | |
1761 else if ((txtChar == UNICODE_LINEFEED) || (txtChar == UNICODE_CR)) | |
1762 { | |
1763 editInfo->precedingEOL = TRUE; | |
1764 editInfo->charWidth = getCharWidth(txtChar);//6; | |
1765 } | |
1766 else //GW-Get actual width for proportional fonts. | |
1767 editInfo->charWidth = getCharWidth(txtChar); | |
1768 | |
1769 if (editInfo->txtWidth+editInfo->charWidth > scrSxPixels) | |
1770 { //newline | |
1771 editInfo->txtWidth = 0; | |
1772 editInfo->endOfLine = TRUE; | |
1773 | |
1774 //update start of window. | |
1775 if ((txtChar == UNICODE_LINEFEED)||(txtChar == UNICODE_CR)) | |
1776 { | |
1777 editInfo->lineCharPos = editInfo->space.lineCharPos+1; | |
1778 | |
1779 } | |
1780 else if (editInfo->space.lineCharPos > 0) | |
1781 { //reset editor position back to here | |
1782 editInfo->lineCharPos = editInfo->space.lineCharPos+1; | |
1783 editInfo->charWidth = editInfo->space.charWidth; | |
1784 editInfo->endOfText = FALSE; | |
1785 } | |
1786 | |
1787 editInfo->space.lineCharPos = 0; | |
1788 } | |
1789 else | |
1790 { | |
1791 punctuation = FALSE; | |
1792 if (txtChar==UNICODE_SPACE) // sbh - will only wrap on a space | |
1793 punctuation = TRUE; | |
1794 | |
1795 if ((punctuation) && (editInfo->txtWidth > 0)) | |
1796 { //A space is a good point for a soft break - remember enough info so that this | |
1797 //point can be restored | |
1798 editInfo->space.lineCharPos = editInfo->lineCharPos; | |
1799 if ((txtChar == UNICODE_LINEFEED) || (txtChar == UNICODE_CR)) | |
1800 editInfo->space.charWidth = getCharWidth(txtChar); | |
1801 else | |
1802 editInfo->space.charWidth = editInfo->charWidth; | |
1803 } | |
1804 } | |
1805 | |
1806 } | |
1807 //Update the cursor position | |
1808 // SPR920 - NH (SH) - provide editor handle e, as cursor vars are now in structure | |
1809 | |
1810 void updateCursorPos(MfwEdt *e, T_EDITINFO *editInfo) | |
1811 { | |
1812 TRACE_FUNCTION("updateCursorPos"); | |
1813 e->curCSize = editInfo->charWidth; | |
1814 if (e->curCSize < 3) | |
1815 e->curCSize = 3; | |
1816 e->curCX = editInfo->txtWidth; | |
1817 } | |
1818 | |
1819 //dy - move cursor up/down screen by dy lines | |
1820 MfwRes updateWindow (MfwEdt *e, int dy ) | |
1821 { | |
1822 T_EDITINFO editInfo; | |
1823 | |
1824 int winCharPos; //char position in string of the first text line in current window | |
1825 int winLineNo; //line no of the first text line to be displayed | |
1826 | |
1827 int ipCursorCharPos; | |
1828 int opCursorCharPos; | |
1829 int cursorLineNo; //line no the cursor is on | |
1830 | |
1831 int linePos; //char pos in string of current line. | |
1832 int lineNo; //overall displayed line (from start of text) | |
1833 | |
1834 int editComplete; //flag indicating cursor position found/updated or end of line reached. | |
1835 | |
1836 int scrSxPixels; | |
1837 int scrSyLines; | |
1838 | |
1839 char* textStartAscii; | |
1840 U16* textStartUnicode; | |
1841 U16 charUnicode; //current unicode char. | |
1842 | |
1843 int textStrType; | |
1844 | |
1845 TRACE_FUNCTION("UpdateWindow()"); | |
1846 | |
1847 //Set up screen size - the width in pixels and no of lines displayed. | |
1848 if (e->fontHeight > 5) | |
1849 scrSyLines = e->attr->win.sy / e->fontHeight; | |
1850 else | |
1851 scrSyLines = e->attr->win.sy / 6; | |
1852 scrSxPixels = e->attr->win.sx; | |
1853 | |
1854 ipCursorCharPos = e->cp; | |
1855 if ((ipCursorCharPos < 0) || (ipCursorCharPos > 32767)) | |
1856 ipCursorCharPos = 0; | |
1857 opCursorCharPos = ipCursorCharPos; | |
1858 lineNo = 0; | |
1859 winLineNo = 0; | |
1860 winCharPos = 0; | |
1861 editComplete = FALSE; | |
1862 editInfo.endOfText = FALSE; | |
1863 editInfo.lineCharPos = 0; | |
1864 editInfo.lastChar = 9999; | |
1865 editInfo.space.lineCharPos = 0; | |
1866 editInfo.precedingEOL = FALSE; | |
1867 linePos = 0; | |
1868 | |
1869 editInfo.txtWidth = 0; | |
1870 cursorLineNo = 0; | |
1871 | |
1872 if ((e->attr->text[0] == (char)0x80) || | |
1873 (e->attr->text[0] == (char)0x81) || | |
1874 (e->attr->text[0] == (char)0x82)) | |
1875 { | |
1876 textStrType = DSPL_TYPE_UNICODE; | |
1877 textStartUnicode = (U16*) &e->attr->text[2]; /* start of edit text - 16 bits/char */ | |
1878 } | |
1879 else | |
1880 { | |
1881 textStrType = DSPL_TYPE_ASCII; | |
1882 textStartAscii = &e->attr->text[0]; /* start of edit text - 8 bits/char */ | |
1883 } | |
1884 | |
1885 //Go through editor and work out | |
1886 // (1) current x-pixel position for cursor | |
1887 // (2) line number of the start of the display. | |
1888 while( (!editInfo.endOfText) && (!editComplete) ) | |
1889 { | |
1890 if (textStrType == DSPL_TYPE_UNICODE) | |
1891 { | |
1892 charUnicode = textStartUnicode[editInfo.lineCharPos]; | |
1893 getTotalWidth(charUnicode,scrSxPixels,&editInfo); | |
1894 } | |
1895 else | |
1896 { | |
1897 charUnicode = (textStartAscii[editInfo.lineCharPos] << 8) & 0xFF00; | |
1898 getTotalWidth(charUnicode,scrSxPixels,&editInfo); | |
1899 } | |
1900 | |
1901 if (editInfo.endOfLine) | |
1902 { | |
1903 //newline or current char will not fit on previous line. | |
1904 lineNo++; | |
1905 linePos = editInfo.lineCharPos; | |
1906 editInfo.txtWidth = 0; | |
1907 //Is this the first line to be displayed in the editor? | |
1908 if (editInfo.lineCharPos <= e->curOffs) | |
1909 { | |
1910 winLineNo = lineNo; | |
1911 winCharPos= editInfo.lineCharPos; | |
1912 } | |
1913 } | |
1914 | |
1915 if (editInfo.endOfText) | |
1916 { | |
1917 //Cursor is past end of line - move to char before end of line. | |
1918 if (ipCursorCharPos > editInfo.lineCharPos) | |
1919 { | |
1920 ipCursorCharPos = editInfo.lineCharPos; | |
1921 opCursorCharPos = editInfo.lineCharPos; | |
1922 } | |
1923 } | |
1924 | |
1925 if (editInfo.lineCharPos == ipCursorCharPos) | |
1926 { //found the cursor position - either | |
1927 // the new pos if dy=0 or | |
1928 // the old pos if we have moved up/down a line. | |
1929 updateCursorPos(e, &editInfo); | |
1930 editInfo.lineXpos = editInfo.txtWidth; | |
1931 cursorLineNo = lineNo; | |
1932 } | |
1933 else if ((editInfo.lineCharPos > ipCursorCharPos) && | |
1934 (lineNo > cursorLineNo ) && | |
1935 (lineNo > cursorLineNo + dy)) | |
1936 { | |
1937 //we have moved far enough down to store all required information | |
1938 editComplete = TRUE; | |
1939 } | |
1940 editInfo.txtWidth = editInfo.txtWidth + editInfo.charWidth; | |
1941 editInfo.lineCharPos++; | |
1942 } //end while | |
1943 | |
1944 //We now know either (a) the line the cursor is on and the char offset of the cursor or (b) the | |
1945 //original line the cursor was on and the x-pixel position of the cursor (for dy != 0) | |
1946 | |
1947 if (dy) | |
1948 { //update line with the cursor on it | |
1949 if (cursorLineNo+dy >lineNo ) | |
1950 cursorLineNo = lineNo; //last line of editor. | |
1951 else if (cursorLineNo+dy < 0) | |
1952 cursorLineNo = 0; | |
1953 else | |
1954 cursorLineNo = cursorLineNo+dy; | |
1955 | |
1956 //Now we need to calculate cursor char pos. 'opCursorCharPos' | |
1957 | |
1958 } | |
1959 else | |
1960 { | |
1961 //Cursor line no is already set up. | |
1962 | |
1963 //the new cursor position was passed into the procedure. | |
1964 opCursorCharPos = ipCursorCharPos; | |
1965 } | |
1966 | |
1967 editInfo.lineCharPos = 0; | |
1968 lineNo = 0; | |
1969 editInfo.txtWidth = 0; | |
1970 editComplete = FALSE; | |
1971 editInfo.endOfText = FALSE; | |
1972 editInfo.space.lineCharPos = 0; | |
1973 | |
1974 //Update start of windows position | |
1975 if (cursorLineNo < winLineNo || !(e->attr->mode & edtCurMask)) | |
1976 {//cursor is on a line before current window screen - search from the start | |
1977 // sbh - or we're in read-only mode, no cursor, scroll with every up/down press | |
1978 winLineNo = cursorLineNo; | |
1979 winCharPos = 0; | |
1980 } | |
1981 else if (cursorLineNo >= winLineNo+scrSyLines) | |
1982 { //cursor is below the bottom of the screen | |
1983 winLineNo = cursorLineNo-(scrSyLines-1); | |
1984 winCharPos = 0; | |
1985 } | |
1986 else if (dy != 0) | |
1987 { //windows line no is unchanged - start search at win char pos. | |
1988 editInfo.lineCharPos = winCharPos; | |
1989 lineNo = winLineNo; | |
1990 } | |
1991 else | |
1992 { //we do not need to calculate new window position - it is unchanged. | |
1993 //and we have already calculated the new cursor position. | |
1994 editComplete = TRUE; | |
1995 } | |
1996 | |
1997 //Calculate last char on cursor line and winCharPos | |
1998 if (!editComplete) | |
1999 { | |
2000 while( (!editInfo.endOfText) && (!editComplete) ) | |
2001 { | |
2002 if (textStrType == DSPL_TYPE_UNICODE) | |
2003 { | |
2004 charUnicode = textStartUnicode[editInfo.lineCharPos]; | |
2005 getTotalWidth(charUnicode,scrSxPixels,&editInfo); | |
2006 } | |
2007 else | |
2008 { | |
2009 charUnicode = (textStartAscii[editInfo.lineCharPos] << 8) & 0xFF00; | |
2010 getTotalWidth(charUnicode,scrSxPixels,&editInfo); | |
2011 } | |
2012 if (editInfo.endOfLine) | |
2013 { //newline | |
2014 editInfo.txtWidth = 0; | |
2015 //update start of window. | |
2016 linePos = editInfo.lineCharPos; | |
2017 | |
2018 //Remember char before first char on next line. | |
2019 if (lineNo == cursorLineNo) | |
2020 { | |
2021 if (ipCursorCharPos >= editInfo.lineCharPos) | |
2022 ipCursorCharPos = editInfo.lineCharPos-1; | |
2023 } | |
2024 lineNo++; | |
2025 if (winLineNo == lineNo) | |
2026 winCharPos = editInfo.lineCharPos; | |
2027 } | |
2028 if (dy!=0) | |
2029 { //line number has changed | |
2030 //Once we have found the correct line, look for the char at the same x-pixel pos | |
2031 //as before (or the last char before we pass the position). | |
2032 if (lineNo == cursorLineNo) | |
2033 { | |
2034 if (editInfo.txtWidth <= editInfo.lineXpos) | |
2035 { //Update cursor char pos... | |
2036 ipCursorCharPos = editInfo.lineCharPos; | |
2037 } | |
2038 } | |
2039 } | |
2040 else if (lineNo > cursorLineNo) //...or we start a new line | |
2041 { | |
2042 editComplete = TRUE; | |
2043 } | |
2044 | |
2045 editInfo.txtWidth = editInfo.txtWidth + editInfo.charWidth; | |
2046 editInfo.lineCharPos++; | |
2047 } //end while | |
2048 | |
2049 editComplete = FALSE; | |
2050 } | |
2051 | |
2052 editInfo.lineCharPos = winCharPos; | |
2053 lineNo = winLineNo; | |
2054 editInfo.txtWidth = 0; | |
2055 editInfo.endOfText = FALSE; | |
2056 editInfo.space.lineCharPos = 0; | |
2057 | |
2058 //Calculate where the window is to start from | |
2059 while( (!editInfo.endOfText) && (!editComplete) ) | |
2060 { | |
2061 if (textStrType == DSPL_TYPE_UNICODE) | |
2062 { | |
2063 charUnicode = textStartUnicode[editInfo.lineCharPos]; | |
2064 getTotalWidth(charUnicode,scrSxPixels,&editInfo); | |
2065 } | |
2066 else | |
2067 { | |
2068 charUnicode = (textStartAscii[editInfo.lineCharPos] << 8) & 0xFF00; | |
2069 getTotalWidth(charUnicode,scrSxPixels,&editInfo); | |
2070 } | |
2071 if (editInfo.endOfLine) | |
2072 { //newline | |
2073 editInfo.txtWidth = 0; | |
2074 //update start of window. | |
2075 linePos = editInfo.lineCharPos; | |
2076 lineNo++; | |
2077 } | |
2078 | |
2079 if ((lineNo == cursorLineNo) && | |
2080 (ipCursorCharPos == editInfo.lineCharPos)) | |
2081 { //we have reached desired char. | |
2082 opCursorCharPos = editInfo.lineCharPos; | |
2083 updateCursorPos(e, &editInfo); | |
2084 cursorLineNo = lineNo; | |
2085 editComplete = TRUE; | |
2086 } | |
2087 | |
2088 editInfo.txtWidth = editInfo.txtWidth + editInfo.charWidth; | |
2089 editInfo.lineCharPos++; | |
2090 } //end while | |
2091 | |
2092 //Calculate y position of cursor | |
2093 //GW 17/09/01 Place cursor for windows that have blank lines at the top of the screen | |
2094 e->curCY = (cursorLineNo - winLineNo)*e->fontHeight+e->attr->win.py; | |
2095 | |
2096 //Output updated window start position | |
2097 e->curOffs = winCharPos; | |
2098 e->cp = opCursorCharPos; | |
2099 | |
2100 return (MfwResOk); | |
2101 } | |
2102 | |
2103 | |
2104 | |
2105 | |
2106 | |
2107 | |
2108 | |
2109 |