|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 #include <eikedwin.h> |
|
18 #include <tagma.h> |
|
19 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
20 #include <tagmaLayoutAndSource.h> |
|
21 #endif |
|
22 |
|
23 |
|
24 #include <frmtlay.h> |
|
25 #include <frmtview.h> |
|
26 #include <txtrich.h> |
|
27 |
|
28 #include "FormCursorModifier.h" |
|
29 #include "FromCursorModifierUtils.h" |
|
30 |
|
31 CFormCursorModifier* CFormCursorModifier::NewL(CTextView* aTextView, CTextLayout* aTextLayout) |
|
32 { |
|
33 CFormCursorModifier* self = new (ELeave) CFormCursorModifier(aTextView, aTextLayout); |
|
34 CleanupStack::PushL(self); |
|
35 self->ConstructL(); |
|
36 CleanupStack::Pop(); |
|
37 return self; |
|
38 } |
|
39 |
|
40 CFormCursorModifier::~CFormCursorModifier() |
|
41 { |
|
42 } |
|
43 |
|
44 void CFormCursorModifier::HandleFormCursorModifierEventL(TFormCursorModifierEvent aEvent, TInt aData1, TAny* aData2) |
|
45 { |
|
46 switch (aEvent) |
|
47 { |
|
48 case EEventNull: |
|
49 break; |
|
50 case EEventInitialiseEditor: |
|
51 if (iTextLayout) |
|
52 { |
|
53 if (iTextLayout->DocumentLength() == 0 && aData2) // Added aData2 check. It is NULL when whole text is selected and cut operation is made. |
|
54 InitialiseCursorPositionL(static_cast<CEikEdwin*>(aData2)); |
|
55 } |
|
56 break; |
|
57 case EEventInlineEditUpdate: |
|
58 break; |
|
59 case EEventInsertion: |
|
60 break; |
|
61 case EEventDeletion: |
|
62 if (iTextLayout) |
|
63 { |
|
64 if (iTextLayout->DocumentLength() == 0) |
|
65 InitialiseCursorPositionL(static_cast<CEikEdwin*>(aData2)); |
|
66 else |
|
67 NormaliseCursorPositionFollowingDeleteL(); |
|
68 } |
|
69 break; |
|
70 case EEventNavigation: |
|
71 if (iTextLayout && aData1 == 0) // aData1 is selection length |
|
72 NormaliseCursorPositionFollowingNavigationL(); |
|
73 break; |
|
74 case EEventInputDirectionIsLeftToRight: |
|
75 SetDirectionality(ELeftToRight); |
|
76 break; |
|
77 case EEventInputDirectionIsRightToLeft: |
|
78 SetDirectionality(ERightToLeft); |
|
79 break; |
|
80 default: |
|
81 // as yet undefined enumerations should be handled gracefully |
|
82 // here - this must not panic |
|
83 break; |
|
84 } |
|
85 } |
|
86 |
|
87 void CFormCursorModifier::SetTextView(CTextView* aTextView) |
|
88 { |
|
89 iTextView = aTextView; |
|
90 } |
|
91 |
|
92 void CFormCursorModifier::SetTextLayout(CTextLayout* aTextLayout) |
|
93 { |
|
94 iTextLayout = aTextLayout; |
|
95 } |
|
96 |
|
97 CFormCursorModifier::CFormCursorModifier(CTextView* aTextView, CTextLayout* aTextLayout) : |
|
98 iTextView(aTextView), |
|
99 iTextLayout(aTextLayout), |
|
100 iDirectionality(ELeftToRight) |
|
101 { |
|
102 } |
|
103 |
|
104 void CFormCursorModifier::ConstructL() |
|
105 { |
|
106 } |
|
107 |
|
108 void CFormCursorModifier::NormaliseCursorPositionFollowingDeleteL() |
|
109 { |
|
110 TFormCursorModifierUtils cursorModifierUtils(*iTextView, *iTextLayout); |
|
111 TTmDocPosSpec pos = cursorModifierUtils.DocPos(); |
|
112 |
|
113 CTmTextLayout::TTmChunkDescription leftChunk; |
|
114 CTmTextLayout::TTmChunkDescription rightChunk; |
|
115 iTextLayout->TagmaTextLayout().FindAdjacentChunks(pos, leftChunk, rightChunk); |
|
116 |
|
117 TBool isRTLPara = cursorModifierUtils.IsRightToLeftParagraph(pos); |
|
118 if (isRTLPara && !rightChunk.iRightToLeft || !isRTLPara && leftChunk.iRightToLeft) |
|
119 cursorModifierUtils.ToggleVisualDocPosL(); |
|
120 } |
|
121 |
|
122 void CFormCursorModifier::NormaliseCursorPositionFollowingNavigationL() |
|
123 { |
|
124 TFormCursorModifierUtils cursorModifierUtils(*iTextView, *iTextLayout); |
|
125 |
|
126 if (cursorModifierUtils.VisualCursorBetweenOpposingChunks()) |
|
127 { |
|
128 TTmDocPosSpec pos = cursorModifierUtils.DocPos(); |
|
129 CTmTextLayout::TTmChunkDescription leftChunk; |
|
130 CTmTextLayout::TTmChunkDescription rightChunk; |
|
131 iTextLayout->TagmaTextLayout().FindAdjacentChunks(pos, leftChunk, rightChunk); |
|
132 |
|
133 if (leftChunk.iStart == -1) |
|
134 { // left end of a line |
|
135 if (rightChunk.iRightToLeft) |
|
136 { // set doc pos trailing at the end of the right chunk |
|
137 pos.iType = TTmDocPosSpec::ETrailing; |
|
138 pos.iPos = rightChunk.iEnd; |
|
139 } |
|
140 else // rightChunk is LTR |
|
141 { // set doc pos leading at start of right chunk |
|
142 pos.iType = TTmDocPosSpec::ELeading; |
|
143 pos.iPos = rightChunk.iStart; |
|
144 } |
|
145 } |
|
146 else if (rightChunk.iStart == -1) |
|
147 { // right end of a line |
|
148 if (leftChunk.iRightToLeft) |
|
149 { // set doc pos leading at start of left chunk |
|
150 pos.iType = TTmDocPosSpec::ELeading; |
|
151 pos.iPos = leftChunk.iStart; |
|
152 } |
|
153 else // leftChunk is LTR |
|
154 { // set doc pos trailing at the end of the left chunk |
|
155 pos.iType = TTmDocPosSpec::ETrailing; |
|
156 pos.iPos = leftChunk.iEnd; |
|
157 } |
|
158 } |
|
159 |
|
160 else // middle of a line |
|
161 { |
|
162 if (iDirectionality == ERightToLeft) |
|
163 { |
|
164 if (rightChunk.iRightToLeft) |
|
165 { // set doc pos trailing at the end of the right chunk |
|
166 pos.iType = TTmDocPosSpec::ETrailing; |
|
167 pos.iPos = rightChunk.iEnd; |
|
168 } |
|
169 else // rightChunk is LTR |
|
170 { // set doc pos leading at start of left chunk |
|
171 pos.iType = TTmDocPosSpec::ELeading; |
|
172 pos.iPos = leftChunk.iStart; |
|
173 } |
|
174 } |
|
175 else // direction is LTR |
|
176 { |
|
177 if (rightChunk.iRightToLeft) |
|
178 { // set doc pos trailing at the end of left chunk |
|
179 pos.iType = TTmDocPosSpec::ETrailing; |
|
180 pos.iPos = leftChunk.iEnd; |
|
181 } |
|
182 else // rightChunk is LTR |
|
183 { // set doc pos leading at the start of right chunk |
|
184 pos.iType = TTmDocPosSpec::ELeading; |
|
185 pos.iPos = rightChunk.iStart; |
|
186 } |
|
187 } |
|
188 } |
|
189 // set the doc position... |
|
190 cursorModifierUtils.SetDocPosL(pos); |
|
191 } |
|
192 } |
|
193 |
|
194 void CFormCursorModifier::InitialiseCursorPositionL(CEikEdwin* aEdwin) |
|
195 { |
|
196 CRichText* rT = static_cast<CRichText*>(aEdwin->Text()); |
|
197 CParaFormat* paraF = CParaFormat::NewLC(); |
|
198 paraF->iLanguage = (iDirectionality == ELeftToRight) ? ELangEnglish : ELangArabic; |
|
199 TParaFormatMask langMask; |
|
200 langMask.SetAttrib(EAttParaLanguage); |
|
201 rT->ApplyParaFormatL(paraF, langMask, 0, 1); |
|
202 if (iTextView) |
|
203 iTextView->HandleRangeFormatChangeL(TCursorSelection(0, iTextLayout->DocumentLength()), ETrue); |
|
204 |
|
205 CleanupStack::PopAndDestroy(); // paraF |
|
206 } |
|
207 |
|
208 |
|
209 void CFormCursorModifier::SetDirectionality(TDirectionality aDirectionality) |
|
210 { |
|
211 iDirectionality = aDirectionality; |
|
212 } |