comparison src/aci2/atb/ATBEditor.c @ 3:93999a60b835

src/aci2, src/condat2: import of g23m/condat source pieces from TCS211
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 26 Sep 2016 00:29:36 +0000
parents
children
comparison
equal deleted inserted replaced
2:c41a534f33c6 3:93999a60b835
1 /*******************************************************************************
2
3 CONDAT (UK)
4
5 ********************************************************************************
6
7 This software product is the property of Condat (UK) Ltd and may not be
8 disclosed to any third party without the express permission of the owner.
9
10 ********************************************************************************
11
12 $Project name:
13 $Project code:
14 $Module:
15 $File: ATBEditor.c
16 $Revision:
17
18 $Author: SH - Condat(UK)
19 $Date:
20
21 ********************************************************************************
22
23 Description: ATB Editor component.
24
25
26 ********************************************************************************
27
28 $History: ATBEditor.c
29
30 Feb 02, 2006 DR: OMAPS00061468 - x0035544.
31 Description: SAT 27.22.4.22.2 SET UP IDLE MODE TEXT (Icon support) fails
32 Solution : Modifications for displaying idle mode text and icon are done in
33 ATB_edit_OutTextLines.
34
35 Jan 16, 2006 DR: OMAPS00061460 - Shashi Shekar B.S.
36 Description: SAT Icon support
37 Solution : Modifications done in ATB_edit_OutTextLines
38 for display of the title icon.
39
40 CRR:25542 - xpradipg - 26 Oct 2004
41 Description: The last character is not deleted from the text entry screen in
42 any WAP page.
43 Solution: The formatIndex was set to zero on reaching the last character which
44 skips the removal of the last character. This assignment is moved out.
45
46 Jul 22,2004 CRR:21605 xrashmic - SASKEN
47 Description: After deleting all the characters in the editor the case does not change to
48 sentence case.
49 Fix: After deleting a character, check if editor is empty and then set the case to
50 sentence case only if the user has not modified the case.
51
52
53 $End
54
55 *******************************************************************************/
56
57 #ifndef ATB_EDITOR_C
58 #define ATB_EDITOR_C
59 #if defined (NEW_FRAME)
60
61 #include "typedefs.h"
62 #include "vsi.h"
63 #include "pei.h"
64 #include "custom.h"
65 #include "gsm.h"
66
67 #else
68
69 #include "STDDEFS.H"
70 #include "custom.h"
71 #include "gsm.h"
72 #include "vsi.h"
73
74 #endif
75
76 #include <stdio.h>
77 #include <string.h>
78 #include <math.h>
79
80 #include "dspl.h"
81 #include "ATBCommon.h"
82 #include "ATBDisplay.h"
83 #include "ATBEditor.h"
84 #include "font_bitmaps.h"
85
86 #include "cus_aci.h"
87 #include "prim.h"
88 #include "pcm.h"
89
90 #undef TRACE_ATBEDITOR
91
92 extern UBYTE CaseChanged; // SPR 21605
93
94 // Shashi Shekar B.S., a0876501, Jan 16, 2006, DR: OMAPS00061460
95 #ifdef FF_MMI_SAT_ICON
96 const unsigned char SATIconQuestionMark[] =
97 {
98 0x25,0x25,0x00,0x00,0x00,0x00,0x25,0x25,
99 0x25,0x00,0xE0,0xE0,0xE0,0xE0,0x00,0x25,
100 0x00,0xE0,0xE0,0xFF,0xFF,0xE0,0xE0,0x00,
101 0x00,0xE0,0xFF,0xE0,0xE0,0xFF,0xE0,0x00,
102 0x00,0xE0,0xE0,0xE0,0xE0,0xFF,0xE0,0x00,
103 0x00,0xE0,0xE0,0xFF,0xFF,0xE0,0xE0,0x00,
104 0x00,0xE0,0xE0,0xFF,0xE0,0xE0,0xE0,0x00,
105 0x00,0xE0,0xE0,0xFF,0xE0,0xE0,0xE0,0x00,
106 0x25,0x00,0xE0,0xE0,0xE0,0xE0,0x00,0x25,
107 0x25,0x25,0x00,0x00,0x00,0x00,0x25,0x25,
108 };
109 #endif
110
111
112 /*******************************************************************************
113
114 LOCAL FUNCTION PROTOTYPES
115
116 *******************************************************************************/
117
118 /* SPR#1983 - SH - Add 'text' parameter */
119 static int ATB_edit_Insert (T_ED_DATA *editor, T_ATB_TEXT *text, USHORT character);
120 static void ATB_edit_FindNext(T_ED_DATA *editor);
121 static USHORT ATB_edit_FindPrev(T_ED_DATA *editor);
122 static void ATB_edit_OutTextLines (T_ED_DATA *editor);
123 static void ATB_edit_WordWrap(T_ED_DATA *editor);
124 static void ATB_edit_UpdateCursorPos(T_ED_DATA *editor);
125 static ED_RES ATB_edit_Update (T_ED_DATA *editor, int dy);
126 static void ATB_edit_LineDestroyAll(T_ED_DATA *editor);
127
128
129 /*******************************************************************************
130
131 $Function: ATB_edit_Create
132
133 $Description: Create the editor. Allocate memory for the editor data and set up
134 some default parameters.
135
136 $Returns: Pointer to the editor data, or NULL if memory allocation failed.
137
138 $Arguments: editAttr - The editor attributes (caller allocated)
139 callback - Callback function
140
141 *******************************************************************************/
142
143 T_ED_DATA* ATB_edit_Create (T_ED_ATTR *editAttr, T_ED_CB callback)
144 {
145 T_ED_DATA *editor;
146
147 TRACE_FUNCTION("ATB_edit_Create()");
148
149 /* Allocate memory for editor data */
150
151 editor = (T_ED_DATA *) ATB_mem_Alloc(sizeof(T_ED_DATA));
152
153 if (!editor)
154 return NULL;
155
156 /* Reset editor data */
157
158 memset(editor, 0, sizeof(T_ED_DATA));
159 editor->display = FALSE;
160 editor->handler = callback;
161 editor->attr = editAttr;
162 editor->cursor.width = 8;
163 editor->initialised = FALSE;
164 editor->line = NULL;
165
166 return editor;
167 }
168
169
170 /*******************************************************************************
171
172 $Function: ATB_edit_Destroy
173
174 $Description: Delete the editor. Free the allocated memory.
175
176 $Returns: ED_OK - OK
177 ED_BAD_HANDLE - Editor data is null pointer
178
179 $Arguments: editor - The editor data
180
181 *******************************************************************************/
182
183 ED_RES ATB_edit_Destroy (T_ED_DATA *editor)
184 {
185 ED_RES result = ED_OK;
186
187 TRACE_FUNCTION("ATB_edit_Destroy()");
188
189 if (editor)
190 {
191 ATB_edit_LineDestroyAll(editor);
192
193 if (editor->hiddenText)
194 {
195 ATB_edit_HiddenExit(editor);
196 }
197
198 ATB_mem_Free((void *)editor, sizeof(T_ED_DATA));
199 }
200 else
201 result = ED_BAD_HANDLE;
202
203 return result;
204 }
205
206
207 /*******************************************************************************
208
209 $Function: ATB_edit_Init
210
211 $Description: Initialise the editor. Ensures that valid combinations of editing modes
212 are set. Sets uppercase/lowercase appropriately. Moves the cursor
213 to the correct place in the text. Performs a word-wrap.
214
215 $Returns: ED_OK - OK
216
217 $Arguments: editor - The editor data
218
219 *******************************************************************************/
220
221 ED_RES ATB_edit_Init (T_ED_DATA *editor)
222 {
223 TRACE_FUNCTION("ATB_edit_Init()");
224
225
226 if (!editor) /* If editor handle doesn't exist, return error */
227 return ED_BAD_HANDLE;
228
229 /* Get the length of the supplied string */
230
231 ATB_string_Length(&editor->attr->text);
232
233 /* SPR#1983 - SH - Set CAPS preference after moving cursor,
234 * as any cursor moves now reset CAPS to LOWER case. */
235
236 ATB_edit_SetCase(editor, ED_CASE_LOWER);
237
238 /* Non read-only modes*/
239
240 if (!ATB_edit_Mode(editor, ED_MODE_READONLY))
241 {
242 /* Initialise hidden mode */
243
244 if (ATB_edit_Mode(editor, ED_MODE_HIDDEN))
245 {
246 ATB_edit_HiddenInit(editor);
247 ATB_edit_SetMode(editor, ED_MODE_OVERWRITE);
248 }
249
250 /* Initialise formatted mode */
251
252 if (ATB_edit_Mode(editor, ED_MODE_FORMATTED))
253 {
254 ATB_edit_SetMode(editor, ED_MODE_OVERWRITE | ED_MODE_ALPHA);
255 ATB_edit_MoveCursor(editor,ctrlTop,FALSE); /* Send cursor to start of string */
256
257 /* Check for "M" & "m" formats; these set the case to upper/lower by default. */
258 /* SPR#1983 - SH - Also, overwrite mode can be switched off for these
259 * cases, free entry allowed.*/
260
261 ATB_edit_SetCase(editor, ED_CASE_CAPS); /* Caps is on by default */
262
263 if (strcmp(editor->attr->FormatString, "*M")==0)
264 {
265 ATB_edit_SetCase(editor, ED_CASE_UPPER);
266 ATB_edit_ResetMode(editor, ED_MODE_OVERWRITE);
267 }
268
269 if (strcmp(editor->attr->FormatString, "*m")==0)
270 {
271 ATB_edit_SetCase(editor, ED_CASE_LOWER);
272 ATB_edit_ResetMode(editor, ED_MODE_OVERWRITE);
273 }
274
275 }
276 /* Of the cursor modes, only formatted starts at the top, others start at the bottom */
277 else
278 {
279 ATB_edit_MoveCursor(editor, ctrlBottom, FALSE);
280
281 /* SPR#1983 - SH - If the buffer is empty, first character will be capitalised.
282 * Otherwise, lowercase is the default. */
283
284 if (editor->attr->text.len==0)
285 {
286 ATB_edit_SetCase(editor, ED_CASE_CAPS); /* Caps is on if first character */
287 }
288 }
289 }
290
291 /* No cursor modes */
292 else
293 {
294 ATB_edit_MoveCursor(editor, ctrlTop, FALSE);
295 }
296
297 /* Format text */
298
299 ATB_edit_Update(editor, 0);
300
301 /* Make editor visible */
302
303 editor->display = TRUE; /* really show it */
304
305 return ED_OK;
306 }
307
308
309 /*******************************************************************************
310
311 $Function: ATB_edit_Reset
312
313 $Description: Reset the editor - move the cursor to the start.
314
315 $Returns: ED_BAD_HANDLE - Editor data pointer is null
316 ED_OK - OK
317
318 $Arguments: editor - The editor data
319
320 *******************************************************************************/
321
322 ED_RES ATB_edit_Reset (T_ED_DATA *editor)
323 {
324
325 TRACE_FUNCTION("ATB_edit_Reset()");
326
327 if (!editor)
328 return ED_BAD_HANDLE; /* Editor does not exist */
329
330 editor->cursor.pos = 0; /* Reset cursor position */
331 editor->initialised = FALSE; /* Fully wrap all of text */
332 ATB_edit_Refresh(editor); /* Refresh word wrap */
333 return ED_OK;
334 }
335
336
337 /*******************************************************************************
338
339 $Function: ATB_edit_Show
340
341 $Description: Show the editor, if it is visible.
342
343 $Returns: ED_OK - OK
344
345 $Arguments: editor - The editor data
346
347 *******************************************************************************/
348
349 ED_RES ATB_edit_Show (T_ED_DATA *editor)
350 {
351 UBYTE previousFont = -1; // store previous font
352 USHORT editX = editor->attr->win_size.px; // pos. of left of edit window
353 USHORT editY = editor->attr->win_size.py; // pos. of top of edit window
354 USHORT editWidth = editor->attr->win_size.sx; // width of edit window
355 USHORT editHeight = editor->attr->win_size.sy; // height of edit window
356
357 TRACE_FUNCTION("ATB_edit_Show()");
358
359 if (!editor)
360 return ED_BAD_HANDLE; // Editor doesn't exist
361
362 if (editor->display)
363 {
364 resources_setColour(editor->attr->colour);
365
366 if (editor->attr->font != (UBYTE) -1)
367 previousFont = dspl_SelectFontbyID(editor->attr->font); // setup font
368
369 dspl_Clear(editX,editY,editX+editWidth-1,editY+editHeight-1); // Clear the editor window
370
371 ATB_edit_OutTextLines(editor); // Show text
372
373 /* Display cursor, if it's switched on and we're not in multitap */
374
375 if (editor->attr->cursor!=ED_CURSOR_NONE && !editor->multitap)
376 {
377 ATB_display_Cursor(&editor->attr->text, editor->cursor.pos, editor->attr->cursor, editX+editor->cursor.x,editY+editor->cursor.y,
378 editor->cursor.width,editor->cursor.height);
379 }
380 }
381
382 if (previousFont != (UBYTE) -1)
383 dspl_SelectFontbyID(previousFont); // Restore previous font
384
385 return ED_OK;
386 }
387
388
389 /*******************************************************************************
390
391 $Function: ATB_edit_Refresh
392
393 $Description: Refresh the editor word wrap etc.
394
395 $Returns: ED_OK - OK
396
397 $Arguments: editor - The editor data
398
399 *******************************************************************************/
400
401 ED_RES ATB_edit_Refresh (T_ED_DATA *editor)
402 {
403 TRACE_FUNCTION("ATB_edit_Refresh()");
404
405 if (!editor)
406 return ED_BAD_HANDLE; /* editor does not exist */
407
408 /* Get the length of the supplied string */
409
410 ATB_string_Length(&editor->attr->text);
411
412 /* Update word wrap */
413
414 ATB_edit_Update(editor, 0);
415
416 return ED_OK;
417 }
418
419
420 /*******************************************************************************
421
422 $Function: ATB_edit_Hide
423
424 $Description: Hide the editor
425
426 $Returns: ED_BAD_HANDLE - Editor data pointer is null
427 ED_OK - OK
428
429 $Arguments: editor - The editor data
430
431 *******************************************************************************/
432
433 ED_RES ATB_edit_Hide (T_ED_DATA *editor)
434 {
435 TRACE_FUNCTION("ATB_edit_Hide()");
436
437 if (!editor)
438 return ED_BAD_HANDLE; /* element does not exist */
439
440 editor->display = FALSE; /* editor is not visible */
441
442 if (editor->handler) /* call event handler */
443 {
444 editor->handler(ED_INVISIBLE,editor);
445 }
446 return ED_OK;
447 }
448
449
450 /*******************************************************************************
451
452 $Function: ATB_edit_Unhide
453
454 $Description: Unhide the editor
455
456 $Returns: ED_BAD_HANDLE - Editor data pointer is null
457 ED_OK - OK
458
459 $Arguments: editor - The editor data
460
461 *******************************************************************************/
462
463 ED_RES ATB_edit_Unhide (T_ED_DATA *editor)
464 {
465 TRACE_FUNCTION("ATB_edit_Unhide()");
466
467 if (!editor)
468 return ED_BAD_HANDLE; /* element does not exist */
469
470 editor->display = TRUE;
471
472 if (editor->handler) /* call event handler */
473 {
474 editor->handler(ED_VISIBLE,editor);
475 }
476 return ED_OK;
477 }
478
479
480 /*******************************************************************************
481
482 $Function: ATB_edit_MoveCursor
483
484 $Description: Move the cursor
485
486 $Returns: ED_ERROR - Unexpected cursor movement
487 ED_OK - OK
488
489 $Arguments: editor - The editor data
490 character - The control character (ctrlLeft etc)
491 update - TRUE if word wrap is to be carried out after move
492
493 *******************************************************************************/
494
495 ED_RES ATB_edit_MoveCursor (T_ED_DATA *editor, USHORT control, UBYTE update)
496 {
497 USHORT altCursorPos;
498 SHORT dy;
499 ED_RES result;
500
501 TRACE_FUNCTION("ATB_edit_MoveCursor");
502
503 if (!editor)
504 return ED_BAD_HANDLE; /* element does not exist */
505
506 /* Can't move cursor in hidden mode, except to start and end */
507
508 result = ED_OK;
509 dy = 0;
510
511 switch(control)
512 {
513 case ctrlLeft:
514 if (!ATB_edit_Mode(editor, ED_MODE_READONLY)) /* Not in read only mode*/
515 {
516 if (ATB_edit_Mode(editor, ED_MODE_FORMATTED)) /* formatted input */
517 {
518 ATB_edit_FindPrev(editor); /* find previous non-fixed character */
519 }
520 else
521 {
522 altCursorPos = editor->cursor.pos; /* Store original cursor position */
523
524 editor->cursor.pos = ATB_string_IndexMove(&editor->attr->text, editor->cursor.pos, -1);
525
526 if (editor->cursor.pos==altCursorPos) /* If we're at the start of text */
527 {
528 ATB_edit_MoveCursor(editor, ctrlBottom, FALSE); /* .. then go to the end of text! */
529 }
530 }
531 }
532 break;
533
534 case ctrlRight:
535 if (!ATB_edit_Mode(editor, ED_MODE_READONLY)) /* Not in read only mode*/
536 {
537 if (ATB_edit_Mode(editor, ED_MODE_FORMATTED)) /* formatted input */
538 {
539 ATB_edit_FindNext(editor); /* Move cursor forward once */
540 }
541 else
542 {
543 altCursorPos = editor->cursor.pos; /* Store original cursor position */
544
545 editor->cursor.pos = ATB_string_IndexMove(&editor->attr->text, editor->cursor.pos, 1);
546 if (editor->cursor.pos==altCursorPos) /* If we're at the end of text */
547 {
548 ATB_edit_MoveCursor(editor, ctrlTop, FALSE); /* .. then go to the start of text! */
549 }
550 }
551 }
552 break;
553
554 case ctrlUp:
555 if (editor->cursor.line > 0)
556 dy = -1;
557 break;
558
559 case ctrlDown:
560 if (editor->cursor.line < (editor->numLines-1))
561 dy = 1;
562 break;
563
564 case ctrlTop:
565 editor->cursor.pos = 0;
566 editor->initialised = FALSE; /* We need to recalculate whole editor */
567
568 /* For formatted mode, skip over any fixed characters at the start */
569
570 if (ATB_edit_Mode(editor, ED_MODE_FORMATTED))
571 {
572 editor->formatIndex = 0;
573 editor->fieldIndex = 0;
574 ATB_edit_FindNext(editor);
575 ATB_edit_FindPrev(editor);
576 }
577 break;
578
579 case ctrlBottom:
580 /* Search until we find end of text */
581 while (ATB_string_GetChar(&editor->attr->text, editor->cursor.pos)!=UNICODE_EOLN)
582 {
583 editor->cursor.pos++;
584 }
585 editor->initialised = FALSE; /* We need to recalculate whole editor */
586 break;
587
588 default:
589 TRACE_EVENT("** ERROR ** Unexpected cursor movement.");
590 return ED_ERROR;
591 break;
592 }
593
594 /* SPR#1983 - SH - In caps mode, any keypress switches to lower case */
595
596 if (editor->textcase==ED_CASE_CAPS)
597 editor->textcase = ED_CASE_LOWER;
598
599 if (update || dy!=0)
600 {
601 ATB_edit_Update(editor, dy);
602 }
603
604 return ED_OK;
605 }
606
607
608 /*******************************************************************************
609
610 $Function: ATB_edit_DeleteLeft
611
612 $Description: Delete the character to the left of the cursor
613 SPR#2342 - SH - Added flag 'update'
614
615 $Returns: ED_OK - OK
616
617 $Arguments: editor - The editor data
618 update - TRUE if word wrap is to be carried out after deletion
619
620 *******************************************************************************/
621
622 ED_RES ATB_edit_DeleteLeft (T_ED_DATA *editor, UBYTE update)
623 {
624 ED_RES result = ED_OK;
625 USHORT altCursorPos;
626 char formatchar;
627
628 TRACE_FUNCTION("ATB_edit_DeleteLeft");
629
630 if (!editor)
631 return ED_BAD_HANDLE; /* element does not exist */
632
633 /* SPR#1983 - SH - Hidden text changes now mirror normal text changes. */
634
635 /* Formatted mode */
636
637 if (ATB_edit_Mode(editor, ED_MODE_FORMATTED)) /* Formatted input */
638 {
639 if (ATB_edit_FindPrev(editor)!=FINDPREV_FIRST_CHAR) /* Skip over fixed characters */
640 {
641 if (editor->formatIndex>0) /* So we don't look back beyond start of string */
642 {
643 /* If we're in a delimited field, do normal delete, otherwise just cursor back */
644 formatchar = editor->attr->FormatString[editor->formatIndex-1];
645 if ((formatchar>'0' && formatchar<='9') || formatchar=='*') /* If it's a number between 1 and 9, or a * */
646 {
647 ATB_string_MoveLeft(&editor->attr->text, editor->cursor.pos, 1);
648 if (ATB_edit_Mode(editor, ED_MODE_HIDDEN))
649 {
650 ATB_string_MoveLeft(editor->hiddenText, editor->cursor.pos, 1);
651 }
652 //CRR:25546 - xpradipg - 26 Oct 2004
653 //the if block is moved out from the ATB_edit_FindPrev()
654 if (editor->fieldIndex==0) // If we've reached the beginning of the field
655 editor->formatIndex--;
656 }
657 }
658 result = ED_OK;
659 }
660 else
661 {
662 result = ED_DONE; /* Delete with empty buffer - escape from editor */
663 }
664 }
665
666 /* Overwrite mode */
667
668 else if (ATB_edit_Mode(editor, ED_MODE_OVERWRITE))
669 {
670 /* If we're at the end of the string, shift the '0' back */
671 if (editor->cursor.pos>0)
672 {
673 if (editor->cursor.pos == editor->attr->text.len)
674 {
675 result = ATB_edit_MoveCursor(editor, ctrlLeft, FALSE);
676 ATB_string_SetChar(&editor->attr->text, editor->cursor.pos, UNICODE_EOLN);
677 editor->attr->text.len--;
678 if (ATB_edit_Mode(editor, ED_MODE_HIDDEN))
679 {
680 ATB_string_SetChar(editor->hiddenText, editor->cursor.pos, UNICODE_EOLN);
681 editor->hiddenText->len--;
682 }
683 }
684 /* Otherwise, overwrite with a space */
685 else
686 {
687 result = ATB_edit_MoveCursor(editor, ctrlLeft, FALSE);
688 ATB_string_SetChar(&editor->attr->text, editor->cursor.pos, UNICODE_SPACE);
689 if (ATB_edit_Mode(editor, ED_MODE_HIDDEN))
690 {
691 ATB_string_SetChar(editor->hiddenText, editor->cursor.pos, UNICODE_SPACE);
692 }
693 }
694 }
695 else
696 {
697 result = ED_DONE; /* Delete with empty buffer - escape from editor */
698 }
699 }
700 else
701 {
702 /* Otherwise, just perform normal delete operation */
703 altCursorPos = ATB_string_IndexMove(&editor->attr->text, editor->cursor.pos,-1);
704 if (altCursorPos!=editor->cursor.pos)
705 {
706 ATB_string_MoveLeft(&editor->attr->text, altCursorPos, editor->cursor.pos-altCursorPos); // Delete the difference!
707
708 if (ATB_edit_Mode(editor, ED_MODE_HIDDEN))
709 {
710 ATB_string_MoveLeft(editor->hiddenText, altCursorPos, editor->cursor.pos-altCursorPos); // Delete the difference!
711 }
712
713 editor->cursor.pos = altCursorPos;
714 result = ED_OK;
715 }
716 else
717 result = ED_DONE;
718 }
719
720 /* SPR#1983 - SH - In caps mode, any keypress switches to lower case */
721
722 if (editor->textcase==ED_CASE_CAPS)
723 editor->textcase = ED_CASE_LOWER;
724
725 // Jul 22,2004 CRR:21605 xrashmic - SASKEN
726 // When deleting a character, if editor is empty, then set the case to
727 // sentence case only if the user has not modified the case explicitly.
728 if(editor->cursor.pos==0 && CaseChanged == FALSE)
729 {
730 editor->textcase = ED_CASE_CAPS;
731 }
732
733 if (update)
734 {
735 ATB_edit_Update(editor,0);
736 }
737
738 return result;
739 }
740
741
742 /*******************************************************************************
743
744 $Function: ATB_edit_DeleteRight
745
746 $Description: Delete the character to the right of the cursor
747 SPR#2342 - SH - Added flag 'update'
748
749 $Returns: ED_OK - OK
750
751 $Arguments: editor - The editor data
752 update - TRUE if word wrap is to be carried out after deletion
753
754 *******************************************************************************/
755
756 ED_RES ATB_edit_DeleteRight (T_ED_DATA *editor, UBYTE update)
757 {
758 ED_RES result;
759 char formatchar;
760
761 TRACE_FUNCTION("ATB_edit_DeleteRight");
762
763 if (!editor)
764 return ED_BAD_HANDLE; /* element does not exist */
765
766 /* SPR#1983 - SH - Hidden text changes now mirror normal text changes. */
767
768 /* Formatted mode */
769
770 if (ATB_edit_Mode(editor, ED_MODE_FORMATTED)) /* Formatted input */
771 {
772 /* If we're in a delimited field, do normal delete right, otherwise ignore */
773 if (editor->formatIndex>0)
774 {
775 formatchar = editor->attr->FormatString[editor->formatIndex-1];
776 if ((formatchar>'0' && formatchar<='9') || formatchar=='*') /* If it's a number between 1 and 9, or a * */
777 {
778 ATB_string_MoveLeft(&editor->attr->text, editor->cursor.pos, 1);
779 if (ATB_edit_Mode(editor, ED_MODE_HIDDEN))
780 {
781 ATB_string_MoveLeft(editor->hiddenText, editor->cursor.pos, 1);
782 }
783 }
784 }
785 }
786
787 /* Overwrite mode */
788
789 else if (ATB_edit_Mode(editor, ED_MODE_OVERWRITE))
790 {
791 /* Make sure we're not at the end of the string */
792 if (editor->cursor.pos<editor->attr->text.len)
793 {
794 if (!ATB_edit_Mode(editor, ED_MODE_HIDDEN))
795 {
796 ATB_string_SetChar(&editor->attr->text, editor->cursor.pos, UNICODE_SPACE);
797 }
798 }
799 }
800 else
801 {
802 ATB_string_MoveLeft(&editor->attr->text, editor->cursor.pos, 1); /* Otherwise, just perform normal delete operation */
803 if (ATB_edit_Mode(editor, ED_MODE_HIDDEN))
804 {
805 ATB_string_MoveLeft(&editor->attr->text, editor->cursor.pos, 1); /* Otherwise, just perform normal delete operation */
806 }
807 }
808
809 /* SPR#1983 - SH - In caps mode, any keypress switches to lower case, if we're
810 * not in multi-tap */
811
812 if (!editor->multitap && editor->textcase==ED_CASE_CAPS)
813 editor->textcase = ED_CASE_LOWER;
814
815 if (update)
816 {
817 ATB_edit_Update(editor,0);
818 }
819
820 return ED_OK;
821 }
822
823
824 /*******************************************************************************
825
826 $Function: ATB_edit_ClearAll
827
828 $Description: Clear all text from the editor, move cursor to the top
829
830 $Returns: ED_BAD_HANDLE - Editor data pointer is null
831 ED_DONE - Deleted from start of editor, exit editor
832 ED_OK - OK
833
834 $Arguments: editor - The editor data
835
836 *******************************************************************************/
837
838 ED_RES ATB_edit_ClearAll (T_ED_DATA *editor)
839 {
840 /* SPR#2275 - SH - No longer use variable 'textlength' */
841 ED_RES result;
842
843 TRACE_FUNCTION("ATB_edit_ClearAll()");
844
845 if (!editor)
846 return ED_BAD_HANDLE; // element does not exist
847
848 /* FORMATTED MODE */
849
850 if (ATB_edit_Mode(editor, ED_MODE_FORMATTED))
851 {
852 /* Find first non-fixed character. SPR#2275 - Simplified */
853 ATB_edit_MoveCursor(editor, ctrlTop, FALSE); // starting from the top.
854 }
855
856 /* NORMAL MODE */
857
858 else
859 {
860 if (editor->attr->text.len==0)
861 {
862 result = ED_DONE;
863 }
864 else
865 {
866 memset(editor->attr->text.data,'\0',editor->attr->size*ATB_string_Size(&editor->attr->text)); /* Clear buffer */
867 editor->attr->text.len = 0;
868 if (ATB_edit_Mode(editor, ED_MODE_HIDDEN))
869 {
870 memset(editor->hiddenText->data,'\0',editor->attr->size*ATB_string_Size(&editor->attr->text));
871 editor->hiddenText->len = 0;
872 }
873 ATB_edit_Reset(editor); /* Send cursor to start */
874
875 result = ED_OK;
876 }
877 }
878
879 ATB_edit_Update(editor,0); /* Update word wrap & cursor */
880
881 return ED_OK;
882 }
883
884
885 /*******************************************************************************
886
887 $Function: ATB_edit_Char
888
889 $Description: Insert a character into the editor text, or execute a control code
890
891 $Returns: ED_OK - OK
892
893 $Arguments: editor - The editor data
894 character - The character - in unicode representation
895 update - TRUE if word wrap is to be carried out after insertion
896
897 *******************************************************************************/
898
899 ED_RES ATB_edit_Char (T_ED_DATA *editor, USHORT character, UBYTE update)
900 {
901 TRACE_FUNCTION("ATB_edit_Char()");
902
903 if (!editor)
904 return ED_BAD_HANDLE; // element does not exist
905
906 switch (character)
907 {
908 /* Quit editor */
909
910 case ctrlEscape:
911 return ED_DONE;
912 break;
913
914 /* Cursor movements*/
915
916 case ctrlLeft:
917 case ctrlRight:
918 case ctrlUp:
919 case ctrlDown:
920 case ctrlTop:
921 case ctrlBottom:
922 ATB_edit_MoveCursor(editor, character, update);
923 break;
924
925 /* Backspace */
926
927 case ctrlBack:
928 ATB_edit_DeleteLeft(editor, update); /* SPR#2342 - SH */
929 break;
930
931 /* Delete character under cursor */
932
933 case ctrlDel:
934 ATB_edit_DeleteRight(editor, update); /* SPR#2342 - SH */
935 break;
936
937 /* CR/LF */
938
939 case ctrlEnter:
940 character = UNICODE_LINEFEED;
941 /* SPR#1983 - SH - Insert into normal buffer */
942 if (ATB_edit_Insert(editor, &editor->attr->text, character))
943 {
944 ATB_edit_MoveCursor(editor,ctrlRight,update);
945 }
946 break;
947
948 /* Normal character */
949
950 default:
951 /* SPR#1983 - SH - Insert into normal buffer */
952 if (ATB_edit_Insert(editor, &editor->attr->text, character))
953 {
954 /* Character inserted OK. Move cursor to right if we're not in multitap */
955 if (!editor->multitap)
956 {
957 ATB_edit_MoveCursor(editor,ctrlRight,FALSE);
958 }
959
960 if (update)
961 {
962 ATB_edit_Update(editor, 0);
963 }
964 }
965 break;
966 }
967
968 /* SPR#1983 - SH - In caps mode, any keypress switches to lower case */
969
970 if (!editor->multitap && editor->textcase==ED_CASE_CAPS)
971 editor->textcase = ED_CASE_LOWER;
972
973 return ED_OK;
974 }
975
976
977 /*******************************************************************************
978
979 $Function: ATB_edit_AsciiChar
980
981 $Description: Insert an ascii character into the editor text, or execute a control code
982
983 $Returns: ED_OK - OK
984
985 $Arguments: editor - The editor data
986 character - The ascii character
987 update - TRUE if word wrap is to be carried out after insertion
988
989 *******************************************************************************/
990
991 ED_RES ATB_edit_AsciiChar (T_ED_DATA *editor, char character, UBYTE update)
992 {
993 USHORT unicodeChar;
994
995 if (character<ctrlMax)
996 unicodeChar = (USHORT)character;
997 else
998 unicodeChar = ATB_char_Unicode(character);
999
1000 return ATB_edit_Char(editor, unicodeChar, update);
1001 }
1002
1003
1004 /*******************************************************************************
1005
1006 $Function: ATB_edit_Insert
1007
1008 $Description: Insert a character into the editor text
1009 SPR#1983 - SH - Added 'text' parameter.
1010
1011 $Returns: TRUE if character was inserted
1012
1013 $Arguments: editor - The editor data
1014 text - The text string (normal or hidden buffer)
1015 character - The character - in unicode representation
1016
1017 *******************************************************************************/
1018
1019 static int ATB_edit_Insert (T_ED_DATA *editor, T_ATB_TEXT *text, USHORT character)
1020 {
1021 int result = FALSE;
1022
1023 TRACE_FUNCTION("ATB_edit_Insert()");
1024
1025 if (!ATB_edit_Mode(editor, ED_MODE_READONLY)) // Can't insert into read only mode
1026 {
1027 if (ATB_edit_Mode(editor, ED_MODE_OVERWRITE))
1028 {
1029 if (editor->cursor.pos < (editor->attr->size-1)) /* Make sure character will fit */
1030 {
1031 result = TRUE; /* We can write the cahracter */
1032
1033 /* If overwriting end of line, we need to increment length of string */
1034 if (ATB_string_GetChar(text, editor->cursor.pos)==UNICODE_EOLN)
1035 {
1036
1037 /* Ensure string ends with end of line character */
1038 ATB_string_SetChar(text, editor->cursor.pos+1, UNICODE_EOLN);
1039 text->len++;
1040 }
1041 }
1042 }
1043 else /* For insert mode, check if we have space */
1044 {
1045 result = ATB_string_MoveRight(text, editor->cursor.pos, 1, editor->attr->size); // move rest of text right to leave space
1046 }
1047
1048 if (result)
1049 {
1050 ATB_string_SetChar(text, editor->cursor.pos, character); // Insert the character
1051 }
1052 }
1053 else
1054 {
1055 result = FALSE;
1056 }
1057
1058 return result;
1059 }
1060
1061
1062 /*******************************************************************************
1063
1064 $Function: ATB_edit_MultiTap
1065
1066 $Description: Displays the specified character over the cursor
1067
1068 $Returns: None.
1069
1070 $Arguments: editor - The editor data
1071 character - The character to display
1072 multitap - TRUE if multi-tap is currently in progress
1073
1074 *******************************************************************************/
1075
1076 ED_RES ATB_edit_MultiTap(T_ED_DATA *editor, USHORT character, BOOL multitap)
1077 {
1078 UBYTE oldmultitap;
1079 ED_RES result = ED_OK;
1080
1081 TRACE_FUNCTION("ATB_edit_MultiTap()");
1082
1083 if (!editor)
1084 return ED_BAD_HANDLE; // element does not exist
1085
1086 oldmultitap = editor->multitap;
1087 editor->multitap = multitap;
1088
1089 /* If we were previously in multitap, and in insert mode, delete character under cursor.
1090 * Since this deletes current character in both visible and
1091 * hidden buffer, do this before inserting character to either buffer. */
1092
1093 if (oldmultitap && !multitap && !ATB_edit_Mode(editor, ED_MODE_HIDDEN))
1094 {
1095 result = ATB_edit_MoveCursor(editor, ctrlRight, TRUE);
1096 }
1097 else
1098 {
1099 if (oldmultitap && !ATB_edit_Mode(editor, ED_MODE_OVERWRITE))
1100 {
1101 ATB_edit_DeleteRight(editor, FALSE); /* SPR#2342 - SH */
1102 }
1103
1104 /* Hidden mode */
1105
1106 if (ATB_edit_Mode(editor, ED_MODE_HIDDEN)) /* In hidden mode... */
1107 {
1108 ATB_edit_Insert(editor, editor->hiddenText, character);
1109
1110 if (!multitap) /* n multi-tap, show character...*/
1111 character = UNICODE_STAR; /* ...otherwise show star */
1112 }
1113
1114 result = ATB_edit_Char(editor,character,TRUE);
1115 }
1116
1117 return result;
1118 }
1119
1120
1121 /*******************************************************************************
1122
1123 $Function: ATB_edit_AsciiMultiTap
1124
1125 $Description: Displays the specified ascii character over the cursor
1126
1127 $Returns: None.
1128
1129 $Arguments: editor - The editor data
1130 character - The ascii character to display
1131 multitap - TRUE if multi-tap is currently in progress
1132
1133 *******************************************************************************/
1134
1135 ED_RES ATB_edit_AsciiMultiTap(T_ED_DATA *editor, char character, BOOL multitap)
1136 {
1137 USHORT unicodeChar;
1138
1139 if (character<ctrlMax)
1140 unicodeChar = (USHORT)character;
1141 else
1142 unicodeChar = ATB_char_Unicode(character);
1143
1144 return ATB_edit_MultiTap(editor, unicodeChar, multitap);
1145 }
1146
1147
1148 /*******************************************************************************
1149
1150 $Function: ATB_edit_FindNext
1151
1152 $Description: For formatted input, adds a character to the input buffer then finds
1153 the next non-fixed character space for the cursor to occupy
1154
1155 $Returns: None
1156
1157 $Arguments: editor - The editor data
1158 character - The character (or code) to insert
1159
1160 *******************************************************************************/
1161
1162 static void ATB_edit_FindNext(T_ED_DATA *editor)
1163 {
1164 char *format = editor->attr->FormatString;
1165 char formatchar;
1166 UBYTE inField = ENTRY_NOT_IN_FIELD;
1167
1168 TRACE_FUNCTION("ATB_edit_FindNext()");
1169
1170 // xreddymn - Included xrashmic's fix for 12470
1171 if(editor->attr->text.len==0)
1172 {
1173 return;
1174 }
1175
1176 /* Check for delimited field */
1177
1178 if (editor->formatIndex>0)
1179 {
1180 formatchar = format[editor->formatIndex-1];
1181 if ((formatchar>'0' && formatchar<='9') || formatchar=='*')
1182 inField = ENTRY_IN_FIELD;
1183 }
1184
1185 formatchar = format[editor->formatIndex];
1186 if ((formatchar>'0' && formatchar<='9') || formatchar=='*')
1187 inField = ENTRY_ENTERING_FIELD;
1188
1189 /* Check for cursor right at end of string - don't allow */
1190
1191 if (editor->cursor.pos>=editor->attr->text.len
1192 && editor->formatIndex>-1 && inField==ENTRY_NOT_IN_FIELD)
1193 {
1194 return;
1195 }
1196
1197 /* Move cursor position right */
1198
1199 editor->cursor.pos = ATB_string_IndexMove(&editor->attr->text, editor->cursor.pos, 1);
1200
1201 /* Check for start of fixed input field */
1202
1203 if (inField==ENTRY_ENTERING_FIELD)
1204 {
1205 editor->formatIndex++; // Get us into the field...
1206 editor->fieldIndex = 0; // ...and reset the field index
1207 formatchar = format[editor->formatIndex];
1208 if (formatchar=='M')
1209 editor->textcase = ED_CASE_UPPER;
1210 if (formatchar=='m')
1211 editor->textcase = ED_CASE_LOWER;
1212 inField = ENTRY_IN_FIELD;
1213 }
1214
1215 /* Check whether we're in a fixed input field, e.g. "4N" or "8X" */
1216
1217 if (inField==ENTRY_IN_FIELD) // So we don't look back beyond start of string
1218 {
1219 formatchar = format[editor->formatIndex-1];
1220 editor->fieldIndex++; // Increment the position in the field
1221 if (editor->fieldIndex==(int)(formatchar-'0')) // If we've entered the number of characters specified (note- will never happen for the '*' !)
1222 {
1223 editor->formatIndex++; // point to NULL at end of string (no more input)
1224 }
1225 return;
1226 }
1227
1228 /* If not, just look at next format character as usual */
1229
1230 editor->formatIndex++; // Point to next character
1231
1232 while (editor->formatIndex<strlen(format) && format[editor->formatIndex]=='\\') // Fixed characters encountered
1233 {
1234 editor->cursor.pos = ATB_string_IndexMove(&editor->attr->text, editor->cursor.pos, 1); // Skip over them
1235 editor->formatIndex+=2;
1236 }
1237
1238 if (editor->formatIndex>(strlen(format))) // Don't look beyond end of string
1239 editor->formatIndex = strlen(format);
1240
1241 return;
1242 }
1243
1244
1245 /*******************************************************************************
1246
1247 $Function: ATB_edit_FindPrev
1248
1249 $Description: For formatted input, finds the previous non-fixed character and
1250 moves the cursor there if possible
1251
1252 $Returns: FINDPREV_NO_CHANGE if the cursor position is not changed (nowhere to go)
1253 FINDPREV_PREV_FOUND if the previous character has been found
1254 FINDPREV_FIRST_CHAR if the cursor was over the first non-fixed character
1255 FINDPREV_LAST_CHAR if the cursor is at the last non-fixed character
1256
1257 $Arguments: editor - The editor data
1258
1259 *******************************************************************************/
1260
1261 static USHORT ATB_edit_FindPrev(T_ED_DATA *editor)
1262 {
1263 char *format = editor->attr->FormatString;
1264 char formatchar;
1265 SHORT editIndex;
1266
1267 TRACE_FUNCTION("ATB_edit_FindPrev()");
1268
1269 /* Check if cursor is at start of string, return 2 */
1270
1271 if (editor->cursor.pos == 0)
1272 {
1273 return FINDPREV_FIRST_CHAR;
1274 }
1275
1276 /* Check whether we're in a fixed input field, e.g. "4N" or "8X" */
1277
1278 if (editor->formatIndex>0) // So we don't look back beyond start of string
1279 {
1280 formatchar = format[editor->formatIndex-1];
1281 if ((formatchar>'0' && formatchar<='9') || formatchar=='*') // If it's a number between 1 and 9, or a *
1282 {
1283 if (editor->cursor.pos > 0)
1284 editor->cursor.pos--;
1285
1286 if (editor->cursor.pos < editor->attr->size-1) // (Don't decrement if at last char in string)
1287 editor->fieldIndex--; // Decrement the position in the field
1288
1289 if (editor->cursor.pos==editor->attr->text.len-1) // Special case if last character - tell editor to shorten the string
1290 return FINDPREV_LAST_CHAR;
1291
1292 return FINDPREV_PREV_FOUND; // then we're done
1293 }
1294 }
1295
1296 /* If not (or if we've just come out of one) just look at next format character as usual */
1297
1298 editIndex = editor->formatIndex-1; // Make copy of format position, starting off to left
1299
1300 while (editIndex>0)
1301 {
1302 if (format[editIndex-1]=='\\') // If there's a fixed char
1303 editIndex -=2; // Look back a further 2 characters
1304 else // If there's a non-fixed character
1305 break; // then exit loop
1306 }
1307
1308 if (editIndex==-1) // Go back from 1st character in editor
1309 {
1310 return FINDPREV_FIRST_CHAR;
1311 }
1312
1313 formatchar = format[editIndex-1];
1314 if ((formatchar>'0' && formatchar<='9') || formatchar=='*')
1315 editor->fieldIndex--;
1316
1317 if (editIndex>-1) // Provided there is somewhere to go....
1318 {
1319 while(editor->formatIndex>editIndex)
1320 {
1321 if (editor->cursor.pos > 0)
1322 {
1323 editor->cursor.pos--; // move cursor there
1324 editor->formatIndex--;
1325 }
1326 if (format[editor->formatIndex]=='\\')
1327 editor->formatIndex--;
1328 }
1329 return FINDPREV_PREV_FOUND; // Found new position
1330 }
1331
1332 return FINDPREV_NO_CHANGE; // Position unchanged
1333 }
1334
1335
1336 /*******************************************************************************
1337
1338 $Function: ATB_edit_GetCasePref
1339
1340 $Description: Returns the preferred case for the current position in the editor
1341
1342 $Returns: ED_CASEPREF_NUM - Any numeric character
1343 ED_CASEPREF_ALPHA_UC - Any symbolic or alphabetic uppercase
1344 character
1345 ED_CASEPREF_ALPHA_LC - Any symbolic or alphabetic lowercase
1346 character
1347 ED_CASEPREF_ALPHANUM - Any symbolic, numeric, or alphabetic
1348 character
1349 ED_CASEPREF_ALPHANUM_UC - Any symbolic, numeric, or alphabetic
1350 uppercase character
1351 ED_CASEPREF_ALPHANUM_LC - Any symbolic, numeric, or alphabetic
1352 lowercase character
1353
1354 $Arguments: editor - The editor data
1355
1356 *******************************************************************************/
1357
1358 T_ED_CASE_PREF ATB_edit_GetCasePref(T_ED_DATA *editor)
1359 {
1360 T_ED_CASE_PREF casePref;
1361 char formatchar;
1362 char *format;
1363
1364 /* FORMATTED MODE */
1365
1366 if (ATB_edit_Mode(editor, ED_MODE_FORMATTED))
1367 {
1368 format = editor->attr->FormatString;
1369 formatchar = format[editor->formatIndex];
1370
1371 if ((formatchar>'0' && formatchar<='9') || formatchar=='*') // Delimiter for format field
1372 {
1373 editor->formatIndex++;
1374 editor->fieldIndex = 0;
1375 formatchar = format[editor->formatIndex]; // Next character is the format for the field
1376 }
1377
1378 switch(formatchar)
1379 {
1380 case 'X': /* Uppercase alphanumeric */
1381 casePref = ED_CASEPREF_ALPHANUM_UC;
1382 break;
1383 case 'x':
1384 casePref = ED_CASEPREF_ALPHANUM_LC; /* Lowercase alphanumeric */
1385 break;
1386 case 'A': /* Uppercase alphabetic */
1387 casePref = ED_CASEPREF_ALPHA_UC;
1388 break;
1389 case 'a': /* Lowercase alphabetic */
1390 casePref = ED_CASEPREF_ALPHA_LC;
1391 break;
1392 case 'M':
1393 casePref = ED_CASEPREF_ALPHANUM;
1394 break;
1395 case 'm':
1396 casePref = ED_CASEPREF_ALPHANUM;
1397 break;
1398 case 'N':
1399 casePref = ED_CASEPREF_NUM;
1400 break;
1401
1402 default:
1403 casePref = ED_CASEPREF_NONE;
1404 break;
1405 }
1406 }
1407
1408 /* NORMAL MODE */
1409 else
1410 {
1411 casePref = ED_CASEPREF_NUM; /* SPR#2342 - SH - Default to numeric mode */
1412
1413 if (ATB_edit_Mode(editor, ED_MODE_ALPHA)
1414 && ATB_edit_GetCase(editor)!=ED_CASE_NUM)
1415 {
1416 casePref = ED_CASEPREF_ALPHANUM;
1417 }
1418 }
1419
1420 return casePref;
1421 }
1422
1423
1424 /*******************************************************************************
1425
1426 $Function: ATB_edit_OutTextLines
1427
1428 $Description: Draw the visible lines of text onto the screen
1429
1430 $Returns: None
1431
1432 $Arguments: editor - The editor data
1433
1434 *******************************************************************************/
1435
1436 static void ATB_edit_OutTextLines (T_ED_DATA *editor)
1437 {
1438 USHORT editX = editor->attr->win_size.px; /* X position in editor */
1439 USHORT editY = editor->attr->win_size.py; /* Y position in editor */
1440 USHORT editWidth = editor->attr->win_size.sx; /* Height of the editor */
1441 USHORT editHeight = editor->attr->win_size.sy; /* Height of the editor */
1442 USHORT lineNo;
1443 USHORT heightOnScreen; /* Height of lines shown so far */
1444 USHORT offsetX; /* X offset of line */
1445 T_DS_TEXTFORMAT tempFormat; /* Temporary storage for format attributes */
1446 T_ED_LINE *line; /* Current line attributes */
1447 T_ATB_TEXT currentLine; /* Current line */
1448 // Shashi Shekar B.S., a0876501, Jan 16, 2006, DR: OMAPS00061460
1449 #ifdef FF_MMI_SAT_ICON
1450 USHORT titleIconWidth = 0;
1451 USHORT iconX, iconY;
1452 USHORT titleHeight = 0;
1453 #endif
1454
1455 TRACE_FUNCTION("ATB_edit_OutTextLines()");
1456
1457 if (editor == NULL)
1458 return;
1459
1460 // Shashi Shekar B.S., a0876501, Jan 16, 2006, DR: OMAPS00061460
1461 #ifdef FF_MMI_SAT_ICON
1462 if (editor->attr->TitleIcon.data != NULL && !editor->attr->TitleIcon.isTitle)
1463 {
1464 if (editor->attr->TitleIcon.width > TITLE_ICON_WIDTH)
1465 {
1466 titleIconWidth = TITLE_ICON_WIDTH;
1467 }
1468 else
1469 {
1470 titleIconWidth = editor->attr->TitleIcon.width;
1471 }
1472 }
1473 else
1474 {
1475 titleIconWidth = 0;
1476 }
1477
1478 if(titleIconWidth)
1479 editX = editX + titleIconWidth + 1;
1480 #endif
1481
1482 heightOnScreen = 0;
1483 line = ATB_edit_LineGet(editor, editor->winStartLine);
1484
1485 // Shashi Shekar B.S., a0876501, Jan 16, 2006, DR: OMAPS00061460
1486 #ifdef FF_MMI_SAT_ICON
1487 if(line != NULL)
1488 titleHeight = line->height;
1489 #endif
1490
1491 for (lineNo = editor->winStartLine; lineNo < editor->numLines && heightOnScreen<=editHeight; lineNo++)
1492 {
1493 heightOnScreen += line->height; /* Add this height to the total height so far... */
1494
1495 if (editor->display && heightOnScreen <= editHeight) /* and make sure this fits onto the screen */
1496 {
1497 currentLine.len = line->next->pos - line->pos; /* End of line is the first character of the next line */
1498 currentLine.dcs = editor->attr->text.dcs;
1499 currentLine.data = &editor->attr->text.data[line->pos*ATB_string_Size(&currentLine)];
1500
1501 offsetX = 0;
1502 if (line->format.attr & DS_ALIGN_RIGHT)
1503 {
1504 offsetX = editWidth-ATB_display_StringWidth(&currentLine, &line->format);
1505 }
1506 else if (line->format.attr & DS_ALIGN_CENTRE)
1507 {
1508 offsetX = (editWidth-ATB_display_StringWidth(&currentLine, &line->format))/2;
1509 }
1510 ATB_display_CopyFormat(&tempFormat, &line->format); /* So format of lines doesn't change */
1511 ATB_display_Text(offsetX+editX, editY, &tempFormat, &currentLine);
1512 }
1513
1514 editY += line->height; /* Move down by line height, ready for the next one */
1515 line = line->next; /* Get next line */
1516 }
1517 //Sudha.V., x0035544, Feb 02, 2006, DR: OMAPS00061468
1518 // Shashi Shekar B.S., a0876501, Jan 16, 2006, DR: OMAPS00061460
1519 #ifdef FF_MMI_SAT_ICON
1520 if(editor->attr->TitleIcon.data != NULL && !editor->attr->TitleIcon.isTitle)
1521 {
1522 switch(editor->attr->TitleIcon.display_type)
1523 {
1524 case SAT_ICON_NONE:
1525 break;
1526 case SAT_ICON_IDLEMODE_TEXT:
1527
1528 if ((editor->attr->TitleIcon.width > TITLE_ICON_WIDTH) || (editor->
1529 attr->TitleIcon.height > TITLE_ICON_HEIGHT))
1530 {
1531 iconX = editX+offsetX - editor->attr->TitleIcon.width-2;
1532 iconY = editor->attr->win_size.py+ ((titleHeight-2)/2);
1533 dspl_BitBlt2(iconX, iconY, 8,
1534 10, (void*)SATIconQuestionMark, 0, BMP_FORMAT_256_COLOUR);
1535
1536 }
1537 else
1538 {
1539 iconX = editX+offsetX - editor->attr->TitleIcon.width-2;
1540 iconY = editor->attr->win_size.py + ((titleHeight-2)/2) - (
1541 editor->attr->TitleIcon.height / 2);
1542 dspl_BitBlt2(iconX, iconY, editor->attr->TitleIcon.width,
1543 editor->attr->TitleIcon.height, (void*)editor->attr->TitleIcon.
1544 data, 0, BMP_FORMAT_256_COLOUR);
1545 }
1546 break;
1547
1548 case SAT_ICON_DISPLAY_TEXT:
1549
1550 if ((editor->attr->TitleIcon.width > TITLE_ICON_WIDTH) || (editor->
1551 attr->TitleIcon.height > TITLE_ICON_HEIGHT))
1552 {
1553 iconX = 1;
1554 iconY = 1+ ((titleHeight-2) / 2) - (10 / 2);
1555 dspl_BitBlt2(iconX, iconY, 8,
1556 10, (void*)SATIconQuestionMark, 0, BMP_FORMAT_256_COLOUR);
1557
1558 }
1559 else
1560 {
1561 iconX = 1;
1562 iconY = 1+ ((titleHeight-2) / 2) - (editor->attr->TitleIcon.
1563 height / 2);
1564 dspl_BitBlt2(iconX, iconY, editor->attr->TitleIcon.width,
1565 editor->attr->TitleIcon.height, (void*)editor->attr->TitleIcon.data, 0
1566 , BMP_FORMAT_256_COLOUR);
1567 }
1568 break;
1569 }
1570 }
1571 #endif
1572
1573 return;
1574 }
1575
1576
1577 /*******************************************************************************
1578
1579 $Function: ATB_edit_Update
1580
1581 $Description: Update editor (without displaying), moving cursor up or down by 'dy' lines.
1582
1583 This function goes through the text, word-wraps it with the help of ATB_edit_WordWrap,
1584 and works out the start position of text on-screen and the X and Y pixel positions
1585 of the cursor (with the help of ATB_edit_UpdateCursorPos). The character position of
1586 the start of each line within the string is stored, so that ATB_edit_OutTextLines can
1587 quickly display the editor contents without further calculation.
1588
1589 $Returns: ED_BAD_HANDLE - Editor data pointer is null
1590 ED_OK - OK
1591
1592 $Arguments: editor - The editor data
1593 dy - number of lines (+ or -) that the cursor must scroll
1594 up or down.
1595
1596 *******************************************************************************/
1597
1598 static ED_RES ATB_edit_Update (T_ED_DATA *editor, int dy)
1599 {
1600 USHORT cursorCharPos; /* New cursor character position */
1601 USHORT linePos; /* Char pos in string of current line. */
1602 USHORT lineNo; /* Line being considered */
1603 USHORT editComplete; /* Flag indicating cursor position found/updated or end of line reached. */
1604 USHORT character; /* Current unicode char. */
1605 T_ED_LINE *line; /* Pointer to current entry in line chain */
1606 USHORT cursorColumn; /* Column cursor is in - always multiple of 8 pixels */
1607 SHORT charMaxWidth;
1608
1609 TRACE_FUNCTION("ATB_edit_Update()");
1610
1611 /* Make sure the editor exists and has text in it */
1612
1613 if (!editor)
1614 return ED_BAD_HANDLE;
1615
1616 /* For non read-only modes, or on first process, perform word wrap */
1617
1618 if (!ATB_edit_Mode(editor, ED_MODE_READONLY) || editor->initialised==FALSE)
1619 {
1620 editor->viewStartPos = 0;
1621 editor->viewHeight = 0;
1622 editor->totalHeight = 0;
1623 editor->startOfLine = TRUE; /* We're at the start of a line */
1624 editor->endOfText = FALSE;
1625 editor->precedingEOL = FALSE; /* Used to detect if preceding character was CR/LF */
1626 editor->thischar.lineWidth = 0; /* Width of current line */
1627 editor->cursor.line = 0; /* Line that the cursor is on */
1628 editor->space.pos = 0; /* Possible position for soft linebreak - none as yet */
1629
1630 /* Set up data if this is the first time... */
1631
1632 if (!editor->initialised)
1633 {
1634 editor->thischar.pos = 0;
1635 editor->numLines = 0; /* total number of lines in editor, start at 0 */
1636
1637 line = ATB_edit_LineGet(editor, 0);
1638 line->pos = 0; /* first line starts at start of buffer */
1639 line->height = 0; /* Height of first line */
1640 ATB_display_CopyFormat(&line->format, &editor->attr->startFormat); /* Start with this text formatting */
1641 ATB_display_CopyFormat(&editor->thischar.format, &editor->attr->startFormat); // Start with this text formatting
1642
1643 editor->winStartLine = 0; /* First line to be displayed in window */
1644
1645 editor->initialised = TRUE;
1646 }
1647
1648 /* Set up data if this is NOT the first time */
1649
1650 else
1651 {
1652 /* We only need to word wrap text that might have been changed by user text entry.
1653 * The user can affect the previous line (by inserting a space or deleting, so the word is
1654 * wrapped to a previous line) and all subsequent lines. Therefore if we start word wrapping
1655 * on the line previous to where the cursor is, we can encompass all changes. */
1656 line = ATB_edit_LineGet(editor, 0);
1657 for (lineNo = 0; lineNo<editor->numLines && editor->cursor.pos>=line->pos; lineNo++)
1658 {
1659 line = line->next;
1660 }
1661 if (lineNo>0)
1662 lineNo--;
1663 if (lineNo>0)
1664 lineNo--;
1665
1666 line = ATB_edit_LineGet(editor, lineNo);
1667 editor->thischar.pos = line->pos; /* Start looking at this line */
1668 editor->numLines = lineNo; /* This no. of lines so far */
1669 ATB_display_CopyFormat(&editor->thischar.format, &line->format); /* Start with this text formatting */
1670 line->height = 0; /* Height of first line */
1671 }
1672
1673
1674 /* Set up some values */
1675
1676 cursorCharPos = editor->cursor.pos; /* Cursor position in the string */
1677 linePos = 0; // Position on the current line
1678
1679 /* Word wrap the text into separate lines, storing the start position and height of each.
1680 * Also, find the cursor and work out its X position. */
1681
1682 while(!editor->endOfText) // Go through from first character to last character
1683 {
1684 ATB_edit_WordWrap(editor); // What is the character? What's its width?
1685
1686 if (editor->endOfLine) // Newline, or current char will not fit on previous line.
1687 {
1688 editor->numLines++; // We've got another line
1689 editor->startOfLine = TRUE; // New line is starting
1690 }
1691
1692 if (editor->startOfLine)
1693 {
1694 line = ATB_edit_LineGet(editor, editor->numLines);
1695 line->pos = editor->startPos;
1696 line->height = editor->thischar.height; // Height of line set to that of first character
1697 ATB_display_CopyFormat(&line->format,&editor->thischar.format);
1698 /* Formatting at start of line to that of 1st character */
1699 editor->thischar.lineWidth = 0;
1700
1701 line = ATB_edit_LineGet(editor, editor->winStartLine);
1702 if (editor->startPos <= line->pos) /* Is this the first line to be displayed in the editor? */
1703 {
1704 editor->winStartLine = editor->numLines; /* If so, set this line to the start window line */
1705 }
1706 editor->startOfLine = FALSE;
1707 }
1708
1709 if (editor->endOfText) /* If it's a unicode terminator... */
1710 {
1711 if (cursorCharPos > editor->thischar.pos) /* Cursor is past end of text - move to char before end of line. */
1712 cursorCharPos = editor->thischar.pos;
1713 }
1714
1715 if (editor->startPos == cursorCharPos) // We've found the cursor
1716 {
1717 editor->cursor.line = editor->numLines; // Store the line it's on
1718 editor->cursor.width = editor->thischar.width; // Set the width of the cursor
1719 editor->cursor.x = editor->thischar.lineWidth; // And its position
1720 editor->cursor.attr = editor->thischar.format.attr; // Save the format attribute
1721 }
1722
1723 editor->thischar.lineWidth += editor->thischar.width;
1724 editor->thischar.pos++;
1725 } // End while
1726
1727 editor->numLines++; // Number of lines is one more than the last line
1728 line = ATB_edit_LineGet(editor, editor->numLines);
1729 line->pos = editor->thischar.pos; // End of last line
1730
1731 ATB_edit_UpdateCursorPos(editor); // Update, but if dy!=0 we may have to change this
1732 }
1733
1734 /* We now have the start position of each line and its height stored in an array.
1735 * We also have the cursor's current X position on its line (but its line may be offscreen) */
1736
1737 if (dy) // If we're sending the cursor up/down some lines...
1738 {
1739 editor->cursor.line = editor->cursor.line+dy; // Change cursor line
1740
1741 if (editor->cursor.line >= editor->numLines ) // Make sure line cursor is on doesn't go beyond...
1742 editor->cursor.line = editor->numLines-1; // ...last line of editor...
1743
1744 if (editor->cursor.line < 0) // ...or above...
1745 editor->cursor.line = 0; // ...first line of editor
1746
1747 /* In read-only mode, stop scrolling down when the bottom line of the text
1748 * is visible at the bottom of the window */
1749
1750 if (ATB_edit_Mode(editor,ED_MODE_READONLY))
1751 {
1752 if (editor->numLines>=editor->linesPerScreen
1753 && editor->cursor.line >= (editor->numLines - editor->linesPerScreen))
1754 {
1755 editor->cursor.line = (editor->numLines - editor->linesPerScreen);
1756 }
1757
1758 editor->winStartLine = editor->cursor.line;
1759 }
1760 }
1761
1762 /* Reset all our horizontal variables */
1763
1764 editor->thischar.pos = 0;
1765 editor->thischar.lineWidth = 0;
1766 editComplete = TRUE;
1767 editor->endOfText = FALSE;
1768 editor->space.pos = 0;
1769
1770 /* Work out how many lines fit on the current screen */
1771
1772 ATB_edit_UpdateCursorPos(editor);
1773 lineNo = 0;
1774
1775 /* Update the line where we start showing the text on the window */
1776
1777 if (editor->cursor.line < editor->winStartLine) //cursor is on a line before current window screen
1778 {
1779 editor->winStartLine = editor->cursor.line;
1780 editComplete = FALSE;
1781 }
1782 else if (editor->cursor.line >= (editor->winStartLine+editor->linesPerScreen)) //cursor is below the bottom of the screen
1783 {
1784 editor->winStartLine = editor->cursor.line-(editor->linesPerScreen-1);
1785 editComplete = FALSE;
1786 }
1787
1788 if (dy!= 0) /* If we're moving up or down */
1789 {
1790 editComplete = FALSE;
1791 }
1792
1793 if (!editComplete) /* Calculate new cursor X and Y positions */
1794 {
1795 if (dy!=0) /* If we've changed line, find new X position */
1796 {
1797 line = ATB_edit_LineGet(editor, editor->cursor.line);
1798 editor->thischar.lineWidth = 0;
1799 linePos = line->pos; // Start of current line
1800 ATB_display_CopyFormat(&editor->thischar.format, &line->format); // Format attributes of 1st character
1801 /* Get column - is always a multiple of the maximum character width. Makes sure cursor doesn't wander
1802 * left or right too much when moving up or down by lines */
1803 charMaxWidth = (SHORT)ATB_display_GetMaxCharWidth(&editor->thischar.format);
1804 cursorColumn = editor->cursor.x - (editor->cursor.x % charMaxWidth);
1805
1806 linePos--;
1807 editor->thischar.width = 0;
1808
1809 /* SPR#2342 - SH - Improved finding cursor position on adjacent lines.
1810 * First search until we're in the column or at the end of the line */
1811
1812 do
1813 {
1814 linePos++;
1815 editor->thischar.lineWidth += editor->thischar.width;
1816 character = ATB_string_GetChar(&editor->attr->text, linePos);
1817 editor->thischar.width = ATB_display_GetCharWidth(character, &editor->thischar.format);
1818 }
1819 while (editor->thischar.lineWidth<cursorColumn && linePos < (line->next->pos-1));
1820
1821 /* Is there a character also in the column, but closer to our original character? */
1822
1823 while ((editor->thischar.lineWidth+editor->thischar.width) < (cursorColumn+charMaxWidth)
1824 && linePos< (line->next->pos-1)
1825 && (editor->cursor.x - editor->thischar.lineWidth)> editor->thischar.width)
1826 {
1827 linePos++;
1828 editor->thischar.lineWidth += editor->thischar.width;
1829 character = ATB_string_GetChar(&editor->attr->text, linePos);
1830 editor->thischar.width = ATB_display_GetCharWidth(character, &editor->thischar.format);
1831 }
1832
1833 /* Set the new cursor X position */
1834 cursorCharPos = linePos; // New cursor position in buffer
1835 editor->cursor.width = editor->thischar.width; // Set the width of the cursor
1836 editor->cursor.x = editor->thischar.lineWidth; // And its position
1837 editor->cursor.attr = editor->thischar.format.attr; // Save the format attribute
1838 }
1839 ATB_edit_UpdateCursorPos(editor);
1840 }
1841
1842 /* Change cursor position */
1843
1844 editor->cursor.pos = cursorCharPos;
1845
1846 return ED_OK;
1847 }
1848
1849
1850 /*******************************************************************************
1851
1852 $Function: ATB_edit_WordWrap
1853
1854 $Description: Main word wrap function. Takes in the characters of the string
1855 one by one, calculating the total width displayed on screen and setting flags
1856 when a string should be wrapped, a carriage return is encountered, the end
1857 of string has been reached.
1858
1859 Tracks the last space character and goes back there when a word runs over
1860 the edge of the screen. Also works out the height of the current line, based on
1861 the maximum character height found.
1862
1863 $Returns: None
1864
1865 $Arguments: editor - The editor data
1866
1867 *******************************************************************************/
1868
1869 static void ATB_edit_WordWrap(T_ED_DATA *editor)
1870 {
1871 USHORT character;
1872 char asciiChar;
1873 int punctuation;
1874 T_ED_LINE *line;
1875
1876 #ifdef TRACE_ATBEDITOR
1877 TRACE_FUNCTION("ATB_edit_WordWrap()");
1878 #endif
1879
1880 editor->endOfLine = FALSE;
1881 line = ATB_edit_LineGet(editor, editor->numLines);
1882
1883 /* Get the character from the buffer */
1884
1885 editor->startPos = editor->thischar.pos;
1886 character = ATB_string_GetChar(&editor->attr->text, editor->thischar.pos);
1887
1888 /* Find the character's dimensions */
1889
1890 /* If we're multi-tapping a character, or in fixed-width mode, it has the maximum width */
1891
1892 if (editor->multitap && editor->thischar.pos==editor->cursor.pos)
1893 editor->thischar.width = ATB_display_GetCharWidth(UNICODE_WIDEST_CHAR, &editor->thischar.format);
1894 else
1895 editor->thischar.width = ATB_display_GetCharWidth(character, &editor->thischar.format); // Character width
1896
1897 editor->thischar.height = ATB_display_GetCharHeight(character, &editor->thischar.format);
1898
1899 /* Check to see if last character was a CR/LF */
1900
1901 if (editor->precedingEOL)
1902 {
1903 editor->endOfLine = TRUE;
1904 editor->precedingEOL = FALSE;
1905 }
1906 else // otherwise, character included on line
1907 {
1908 if (editor->thischar.height > line->height) // if height>height so far...
1909 line->height = editor->thischar.height; // ...adjust the height so far
1910 }
1911
1912 /* Set flags appropriate for the character */
1913
1914 switch(character)
1915 {
1916 case UNICODE_EOLN:
1917 editor->endOfText = TRUE; // We're at the end of the editor text
1918 break;
1919
1920 case UNICODE_LINEFEED:
1921 case UNICODE_CR:
1922 editor->precedingEOL = TRUE; // This is an end of line
1923 break;
1924
1925 default:
1926 break;
1927 }
1928
1929 /* Check if wrapping required */
1930
1931 if ( (editor->thischar.lineWidth+editor->thischar.width)>editor->attr->win_size.sx ) // Current character will go off edge of editor
1932 {
1933 editor->endOfLine = TRUE;
1934
1935 // If we've found a space, and it's a word wrapping mode */
1936
1937 if (editor->space.pos > 0 && editor->precedingSpace==FALSE
1938 && !ATB_edit_Mode(editor, ED_MODE_OVERWRITE))
1939 {
1940 editor->thischar.pos = editor->space.pos; // reset character position back to here
1941 editor->startPos = editor->space.pos; // character is space, so start of block=character pos
1942 editor->thischar.width = editor->space.width;
1943 editor->thischar.height = editor->space.height;
1944 ATB_display_CopyFormat(&editor->thischar.format,&editor->space.format);
1945 line->height = editor->space.lineHeight;
1946 editor->endOfText = FALSE; // If we're wrapping on an EOLN, we've gone back
1947 }
1948 editor->space.pos = 0; // Reset space position to start of line
1949 editor->precedingSpace = FALSE;
1950 }
1951 else
1952 {
1953 if (editor->precedingSpace) // Remember enough info so that this point can be restored
1954 {
1955 editor->space.pos = editor->startPos; // Store position of start of current block, or just character pos.
1956 editor->space.width = editor->thischar.width;
1957 editor->space.height = editor->thischar.height;
1958 ATB_display_CopyFormat(&editor->space.format,&editor->thischar.format);
1959 editor->space.lineHeight = line->height;
1960 editor->precedingSpace = FALSE;
1961 }
1962
1963 punctuation = FALSE;
1964 if (character==UNICODE_SPACE) // Wrap only on spaces
1965 {
1966 punctuation = TRUE;
1967 }
1968
1969 if ((punctuation) && (editor->thischar.lineWidth > 0)) //A space is a good point for a soft break
1970 {
1971 editor->precedingSpace = TRUE;
1972 }
1973 }
1974
1975 return;
1976 }
1977
1978
1979 /*******************************************************************************
1980
1981 $Function: ATB_edit_UpdateCursorPos
1982
1983 $Description: Update the cursor's vertical position, based on its position within
1984 the string.
1985
1986 $Returns: None
1987
1988 $Arguments: editor - The editor data
1989
1990 *******************************************************************************/
1991
1992 static void ATB_edit_UpdateCursorPos(T_ED_DATA *editor)
1993 {
1994 USHORT lineNo;
1995 USHORT lineHeight;
1996 USHORT editHeight = editor->attr->win_size.sy;
1997 T_ED_LINE *line;
1998
1999 #ifdef TRACE_ATBEDITOR
2000 TRACE_FUNCTION("ATB_edit_UpdateCursorPos()");
2001 #endif
2002
2003 editor->cursor.y = 0; // Recalculate cursor Y position...
2004 editor->viewHeight = 0; // ...and height of viewable screen...
2005 editor->totalHeight = 0; // ...and total height of screen...
2006 editor->viewStartPos = 0; // ...and the start pixel position of the view...
2007 editor->linesPerScreen = 0; // ...and number of lines to the screen
2008 lineNo = 0;
2009
2010 while (lineNo<editor->numLines)
2011 {
2012 line = ATB_edit_LineGet(editor, lineNo);
2013
2014 lineHeight = line->height;
2015
2016 if (lineNo==editor->cursor.line)
2017 editor->cursor.y = editor->viewHeight; // Y position of cursor
2018
2019 if (lineNo==editor->winStartLine) // starting posn rel to start of editor text
2020 editor->viewStartPos = editor->totalHeight;
2021
2022 if (lineNo>=editor->winStartLine && (editor->viewHeight+lineHeight)<=editHeight)
2023 {
2024 editor->viewHeight += lineHeight;
2025 editor->linesPerScreen++;
2026 }
2027
2028 editor->totalHeight += lineHeight;
2029 lineNo++;
2030 }
2031
2032 line = ATB_edit_LineGet(editor, editor->cursor.line);
2033 editor->cursor.height = line->height; // Change its height
2034
2035 return;
2036 }
2037
2038
2039 /************************************/
2040 /* GLOBAL PROCEDURES */
2041 /* Add/removing words in the editor */
2042 /************************************/
2043
2044 /*******************************************************************************
2045
2046 $Function: ATB_edit_InsertString
2047
2048 $Description: Insert a string at the cursor.
2049
2050 $Returns: ED_BAD_HANDLE - Editor data pointer is null
2051 ED_OK - OK
2052
2053 $Arguments: editor - The editor data
2054 insText - The text to insert
2055
2056 *******************************************************************************/
2057
2058 ED_RES ATB_edit_InsertString (T_ED_DATA *editor, T_ATB_TEXT *insText)
2059 {
2060 T_ATB_TEXT *text;
2061 int textIndex;
2062 USHORT character;
2063
2064 TRACE_FUNCTION("ATB_edit_InsertString()");
2065
2066 if (!editor) // Make sure editor exists
2067 return ED_BAD_HANDLE;
2068
2069 if (insText==NULL || insText->len==0)
2070 return ED_OK; /* No string to insert - trivial operation. */
2071
2072 if (ATB_edit_Mode(editor, ED_MODE_READONLY) ) /* Don't insert in read-only mode*/
2073 return ED_ERROR;
2074
2075 text = &editor->attr->text;
2076
2077 if ((text->len+insText->len) >= editor->attr->size)
2078 return ED_ERROR; /* String too long */
2079
2080 /* Move text up by the length of insText */
2081
2082 ATB_string_MoveRight(text, editor->cursor.pos, insText->len, editor->attr->size);
2083
2084 /* Copy string into buffer */
2085
2086 for (textIndex=0; textIndex<insText->len; textIndex++)
2087 {
2088 character = ATB_string_GetChar(insText, textIndex);
2089 ATB_string_SetChar(text, editor->cursor.pos+textIndex, character);
2090 }
2091
2092 editor->cursor.pos = editor->cursor.pos+insText->len;
2093
2094 /* Reformat updated text */
2095
2096 ATB_edit_Update(editor, 0);
2097
2098 return ED_OK;
2099 }
2100
2101
2102 /*******************************************************************************
2103
2104 $Function: ATB_edit_GetCursorChar
2105
2106 $Description: Return the character at a position offset from the current cursor
2107 position by the value supplied.
2108
2109 $Returns: The character, or UNICODE_EOLN if goes beyond bounds of string.
2110
2111 $Arguments: editor - The editor data
2112 offset - The offset from the current cursor position from which
2113 to get the character
2114
2115 *******************************************************************************/
2116
2117 USHORT ATB_edit_GetCursorChar(T_ED_DATA *editor, int offset)
2118 {
2119 USHORT textIndex;
2120 USHORT character;
2121
2122 TRACE_FUNCTION("ATB_edit_GetCursorChar");
2123
2124 textIndex = editor->cursor.pos+offset;
2125
2126 if (textIndex<0 || textIndex > editor->attr->text.len)
2127 character = UNICODE_EOLN;
2128 else
2129 character = ATB_string_GetChar(&editor->attr->text, textIndex);
2130
2131 return character;
2132 }
2133
2134
2135 /*******************************************************************************
2136
2137 $Function: ATB_edit_CapitaliseWord
2138
2139 $Description: Returns TRUE if next word after cursor ought to be capitalised
2140
2141 $Returns: None.
2142
2143 $Arguments: editor - The editor data
2144
2145 *******************************************************************************/
2146
2147 BOOL ATB_edit_CapitaliseWord(T_ED_DATA *editor)
2148 {
2149 USHORT LastChar;
2150 USHORT CharBefore;
2151
2152 /* First check to see if first word is to be capitalised */
2153
2154 if (editor->textcase==ED_CASE_CAPS)
2155 return TRUE;
2156
2157 /* If not, look at preceding characters */
2158
2159 LastChar = ATB_edit_GetCursorChar(editor, -1);
2160 CharBefore = ATB_edit_GetCursorChar(editor, -2);
2161
2162 if (LastChar==UNICODE_FULLSTOP || LastChar==UNICODE_EXCLAMATION
2163 || LastChar==UNICODE_QUESTION || LastChar==UNICODE_EOLN)
2164 return TRUE;
2165
2166 if (LastChar==UNICODE_SPACE)
2167 if(CharBefore==UNICODE_FULLSTOP || CharBefore==UNICODE_EXCLAMATION || CharBefore==UNICODE_QUESTION)
2168 return TRUE;
2169
2170 return FALSE;
2171 }
2172
2173 /*******************************************************************************
2174
2175 $Function: ATB_edit_FindCapital
2176
2177 $Description: returns the code of the input char converted to a capital. If char has no
2178 upper case equivalent returns original char.
2179 Added for issue 1508
2180
2181 $Returns: UBYTE
2182
2183 $Arguments: char
2184
2185 *******************************************************************************/
2186
2187 USHORT ATB_edit_FindCapital(USHORT small_char)
2188 { char ascii_code= ATB_char_Ascii(small_char);
2189
2190
2191 /*if "normal" character*/
2192 if (ascii_code>96 && ascii_code< 123)
2193 return (ATB_char_Unicode(ascii_code - 0x20));
2194
2195 switch (ascii_code)
2196 {
2197 case (130): return ATB_char_Unicode(154);break;/*U with umlaut*/
2198 case (132): return ATB_char_Unicode(142);break;/*A with umlaut*/
2199 case (148): return ATB_char_Unicode(153);break;/*O with umlaut*/
2200 default: return ATB_char_Unicode(ascii_code);
2201 }
2202
2203 }
2204 /*******************************************************************************
2205
2206 $Function: ATB_edit_HiddenInit
2207
2208 $Description: Initialize editor for hidden mode.
2209
2210 $Returns: None.
2211
2212 $Arguments: editor - The editor data
2213
2214 *******************************************************************************/
2215
2216 ED_RES ATB_edit_HiddenInit(T_ED_DATA *editor)
2217 {
2218 USHORT len = editor->attr->text.len;
2219
2220 TRACE_FUNCTION("ATB_edit_HiddenInit()");
2221
2222 if (!editor)
2223 return ED_BAD_HANDLE; // element does not exist
2224 if (editor->hiddenText)
2225 return ED_ERROR;
2226
2227 /* get memory for the temporary buffer */
2228 editor->hiddenText = (T_ATB_TEXT *) ATB_mem_Alloc(sizeof(T_ATB_TEXT));
2229 editor->hiddenText->len = 0;
2230 editor->hiddenText->data = (UBYTE *)ATB_mem_Alloc(editor->attr->size*ATB_string_Size(&editor->attr->text));
2231
2232 /* copy text to the temporary buffer */
2233 ATB_string_Copy(editor->hiddenText, &editor->attr->text);
2234
2235 /* overwrite the string in the editor buffer with stars */
2236 memset(editor->attr->text.data,'\0',editor->attr->size*ATB_string_Size(&editor->attr->text)); /* Clear buffer */
2237 editor->attr->text.len = 0;
2238 ATB_edit_Reset(editor); /* Send cursor to start */
2239
2240 while (editor->attr->text.len < len)
2241 ATB_edit_AsciiChar(editor,'*',FALSE);
2242
2243 return ED_OK;
2244 }
2245
2246
2247 /*******************************************************************************
2248
2249 $Function: ATB_edit_HiddenExit
2250
2251 $Description: Deinitialize editor for hidden mode.
2252
2253 $Returns: None.
2254
2255 $Arguments: editor - The editor data
2256
2257 *******************************************************************************/
2258
2259 ED_RES ATB_edit_HiddenExit(T_ED_DATA *editor)
2260 {
2261 TRACE_FUNCTION("ATB_edit_HiddenExit()");
2262
2263 if (!editor)
2264 return ED_BAD_HANDLE; // element does not exist
2265 if (!editor->hiddenText)
2266 return ED_ERROR;
2267
2268 /* For hidden mode, copy the hidden text into the buffer & free memory */
2269 ATB_string_Copy(&editor->attr->text, editor->hiddenText);
2270 ATB_mem_Free ((void *)editor->hiddenText->data, editor->attr->size*ATB_string_Size(editor->hiddenText));
2271 ATB_mem_Free ((void *)editor->hiddenText, sizeof(T_ATB_TEXT));
2272 editor->hiddenText = NULL;
2273
2274 return;
2275 }
2276
2277
2278 /*******************************************************************************
2279
2280 $Function: ATB_edit_Mode
2281
2282 $Description: Returns TRUE if the appropriate bits are set in the editor mode
2283
2284 $Returns: None.
2285
2286 $Arguments: editor - The editor data
2287 mode - The mode bits to check
2288
2289 *******************************************************************************/
2290
2291 void ATB_edit_SetAttr(T_ED_DATA *editor, T_ATB_WIN_SIZE *win_size, ULONG colour, UBYTE font, USHORT mode, USHORT cursor, T_ATB_TEXT *text, USHORT size)
2292 {
2293 memcpy(&editor->attr->win_size, win_size, sizeof(T_ATB_WIN_SIZE));
2294 editor->attr->colour = colour;
2295 editor->attr->font = font;
2296 editor->attr->cursor = cursor;
2297 editor->attr->mode = mode;
2298 memcpy(&editor->attr->text, text, sizeof(T_ATB_TEXT));
2299 editor->attr->size = size;
2300
2301 return;
2302 }
2303
2304
2305 /*******************************************************************************
2306
2307 $Function: ATB_edit_Mode
2308
2309 $Description: Returns TRUE if the appropriate bits are set in the editor mode
2310
2311 $Returns: None.
2312
2313 $Arguments: editor - The editor data
2314 mode - The mode bits to check
2315
2316 *******************************************************************************/
2317
2318 UBYTE ATB_edit_Mode(T_ED_DATA *editor, USHORT mode)
2319 {
2320 UBYTE result;
2321
2322 if (editor->attr->mode & mode)
2323 result = TRUE;
2324 else
2325 result = FALSE;
2326
2327 return result;
2328 }
2329
2330
2331 /*******************************************************************************
2332
2333 $Function: ATB_edit_SetMode
2334
2335 $Description: Sets the appropriate bits in the editor mode
2336
2337 $Returns: None.
2338
2339 $Arguments: editor - The editor data
2340 mode - The mode bits to set
2341
2342 *******************************************************************************/
2343
2344 void ATB_edit_SetMode(T_ED_DATA *editor, USHORT mode)
2345 {
2346 editor->attr->mode |= mode;
2347
2348 return;
2349 }
2350
2351
2352 /*******************************************************************************
2353
2354 $Function: ATB_edit_ResetMode
2355
2356 $Description: Resets the appropriate bits in the editor mode
2357
2358 $Returns: None.
2359
2360 $Arguments: editor - The editor data
2361 mode - The mode bits to reset
2362
2363 *******************************************************************************/
2364
2365 void ATB_edit_ResetMode(T_ED_DATA *editor, USHORT mode)
2366 {
2367 editor->attr->mode &= (~mode);
2368
2369 return;
2370 }
2371
2372
2373 /*******************************************************************************
2374
2375 $Function: ATB_edit_SetStyle
2376
2377 $Description: Sets the appropriate bits in the editor style
2378
2379 $Returns: None.
2380
2381 $Arguments: editor - The editor data
2382 format - The format bits to set
2383
2384 *******************************************************************************/
2385
2386 void ATB_edit_SetStyle(T_ED_DATA *editor, USHORT style)
2387 {
2388 UBYTE mask;
2389
2390 mask = 0;
2391
2392 switch(style)
2393 {
2394 case DS_ALIGN_LEFT:
2395 case DS_ALIGN_RIGHT:
2396 case DS_ALIGN_CENTRE:
2397 mask = DS_ALIGN_RIGHT | DS_ALIGN_CENTRE;
2398 break;
2399 }
2400
2401 /* Switch off previous format */
2402 editor->attr->startFormat.attr &= (~mask);
2403 /* Switch on new format */
2404 editor->attr->startFormat.attr |= style;
2405
2406 return;
2407 }
2408
2409 /*******************************************************************************
2410
2411 $Function: ATB_edit_ResetFormat
2412
2413 $Description: Resets the appropriate bits in the editor format
2414
2415 $Returns: None.
2416
2417 $Arguments: editor - The editor data
2418 format - The format bits to reset
2419
2420 *******************************************************************************/
2421
2422 void ATB_edit_ResetFormat(T_ED_DATA *editor, USHORT format)
2423 {
2424 editor->attr->startFormat.attr &= (~format);
2425
2426 return;
2427 }
2428
2429
2430 /*******************************************************************************
2431
2432 $Function: ATB_edit_GetCase
2433
2434 $Description: Returns the currently selected text case
2435
2436 $Returns: ED_CASE_UPPER
2437 ED_CASE_LOWER
2438 ED_CASE_CAPS
2439 ED_CASE_NUM
2440 ED_CASE_NONE
2441
2442 $Arguments: editor - The editor data
2443
2444 *******************************************************************************/
2445
2446 UBYTE ATB_edit_GetCase(T_ED_DATA *editor)
2447 {
2448 return (UBYTE)editor->textcase;
2449 }
2450
2451
2452 /*******************************************************************************
2453
2454 $Function: ATB_edit_SetCase
2455
2456 $Description: Changes the currently selected text case
2457
2458 $Returns: None
2459
2460 $Arguments: editor - The editor data
2461 textcase - Case to select. One of:
2462 ED_CASE_UPPER
2463 ED_CASE_LOWER
2464 ED_CASE_CAPS
2465 ED_CASE_NUM
2466 ED_CASE_NONE
2467
2468 *******************************************************************************/
2469
2470 void ATB_edit_SetCase(T_ED_DATA *editor, UBYTE textcase)
2471 {
2472 editor->textcase = textcase;
2473 return;
2474 }
2475
2476
2477 /*******************************************************************************
2478
2479 $Function: ATB_edit_LineGet
2480
2481 $Description: Get the pointer to the requested line in the linked list
2482
2483 $Returns: The required line structure
2484
2485 $Arguments: editor - The text editor
2486 lineNo - The line required
2487
2488 *******************************************************************************/
2489
2490 T_ED_LINE *ATB_edit_LineGet(T_ED_DATA *editor, SHORT lineNo)
2491 {
2492 T_ED_LINE *line = editor->line;
2493 SHORT thisLineNo;
2494
2495 thisLineNo = 0;
2496 if (lineNo<0)
2497 lineNo = 0;
2498
2499 /* If the first line doesn't exist... */
2500
2501 if (line==NULL)
2502 {
2503 editor->line = (T_ED_LINE *)ATB_mem_Alloc(sizeof(T_ED_LINE));
2504 memset(editor->line, 0, sizeof(T_ED_LINE));
2505 editor->line->next = NULL;
2506 line = editor->line;
2507 }
2508
2509 /* Search for the line required */
2510
2511 while (thisLineNo<lineNo)
2512 {
2513 if (line->next==NULL)
2514 {
2515 line->next = (T_ED_LINE *)ATB_mem_Alloc(sizeof(T_ED_LINE));
2516 memset(line->next, 0, sizeof(T_ED_LINE));
2517 line->next->next = NULL;
2518 }
2519 line = line->next;
2520 lineNo--;
2521 }
2522
2523 return line;
2524 }
2525
2526
2527 /*******************************************************************************
2528
2529 $Function: ATB_edit_LineDestroyAll
2530
2531 $Description: Destroy all entries in the line linked list
2532
2533 $Returns: None
2534
2535 $Arguments: editor - The text editor
2536
2537 *******************************************************************************/
2538
2539 static void ATB_edit_LineDestroyAll(T_ED_DATA *editor)
2540 {
2541 T_ED_LINE *line = editor->line;
2542 T_ED_LINE *newLine;
2543 SHORT lineNo;
2544
2545 while (line!=NULL)
2546 {
2547 newLine = line->next;
2548 ATB_mem_Free((void *)line, sizeof(T_ED_LINE));
2549 line = newLine;
2550 }
2551
2552 return;
2553 }
2554 #endif