|
1 /* |
|
2 * Copyright (c) 2006 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: Message extension handler |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "CCAMessageExtensionsHandler.h" |
|
20 #include "CCASmileyUtil.h" |
|
21 #include "ChatDefinitions.h" |
|
22 #include "IMUtils.h" |
|
23 |
|
24 // The Settings have been moved to Cenrep (also retained in the Resource file), |
|
25 // so the enums for keys and central repository header is added here |
|
26 #include "VariantKeys.h" |
|
27 #include <eikrted.h> |
|
28 #include <txtrich.h> |
|
29 |
|
30 _LIT( KRIGHT_TO_LEFT_MAKR, "\x200F" ); |
|
31 const TInt KLENGTHOFACHAR = 1; |
|
32 |
|
33 // ----------------------------------------------------------------------------- |
|
34 // CCAMessageExtensionsHandler::CCAMessageExtensionsHandler |
|
35 // Constructor |
|
36 // ----------------------------------------------------------------------------- |
|
37 // |
|
38 CCAMessageExtensionsHandler::CCAMessageExtensionsHandler() |
|
39 { |
|
40 } |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // CCAMessageExtensionsHandler::~CCAMessageExtensionsHandler |
|
44 // Destructor |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 CCAMessageExtensionsHandler::~CCAMessageExtensionsHandler() |
|
48 { |
|
49 iExtensionArray.ResetAndDestroy(); |
|
50 } |
|
51 |
|
52 |
|
53 // ----------------------------------------------------------------------------- |
|
54 // CCAMessageExtensionsHandler::ConstructL |
|
55 // Symbian OS Constructor |
|
56 // ----------------------------------------------------------------------------- |
|
57 // |
|
58 void CCAMessageExtensionsHandler::ConstructL( MCASkinVariant& aSkinVariant, |
|
59 MCAAppUi& aAppUi, TBool aAddSmileyHandler ) |
|
60 { |
|
61 if ( aAddSmileyHandler ) |
|
62 { |
|
63 //Register smileyUtils with identification type. |
|
64 CCASmileyUtil* smiley = CCASmileyUtil::NewL( aSkinVariant, aAppUi, EMessageExtensionSmiley ); |
|
65 CleanupStack::PushL( smiley ); |
|
66 User::LeaveIfError( iExtensionArray.Append( smiley ) ); |
|
67 CleanupStack::Pop( smiley ); |
|
68 } |
|
69 } |
|
70 |
|
71 // ----------------------------------------------------------------------------- |
|
72 // CCAMessageExtensionsHandler::NewL |
|
73 // Symbian two phased constructor |
|
74 // ----------------------------------------------------------------------------- |
|
75 // |
|
76 CCAMessageExtensionsHandler* CCAMessageExtensionsHandler::NewL( |
|
77 MCASkinVariant& aSkinVariant, |
|
78 MCAAppUi& aAppUi, |
|
79 TBool aAddSmileyHandler /*= ETrue */ ) |
|
80 { |
|
81 CCAMessageExtensionsHandler* self = |
|
82 new ( ELeave ) CCAMessageExtensionsHandler; |
|
83 CleanupStack::PushL( self ); |
|
84 self->ConstructL( aSkinVariant, aAppUi, aAddSmileyHandler ); |
|
85 CleanupStack::Pop( self ); |
|
86 return self; |
|
87 } |
|
88 |
|
89 // ----------------------------------------------------------------------------- |
|
90 // CCAMessageExtensionsHandler::ProcessMessageLC |
|
91 // Process messages trough extensions. |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 HBufC* CCAMessageExtensionsHandler::ProcessMessageLC( |
|
95 CEikRichTextEditor& aEditor ) |
|
96 { |
|
97 HBufC* msg = ExtensionToStringLC( aEditor ); |
|
98 for ( TInt a( 0 ); a < iExtensionArray.Count(); ++a ) |
|
99 { |
|
100 iExtensionArray[ a ]->Reset(); |
|
101 } |
|
102 return msg; |
|
103 } |
|
104 |
|
105 // ----------------------------------------------------------------------------- |
|
106 // CCAMessageExtensionHandler::ExtensionToStringL |
|
107 // Convert extensions to strings. |
|
108 // ----------------------------------------------------------------------------- |
|
109 // |
|
110 HBufC* CCAMessageExtensionsHandler::ExtensionToStringLC( |
|
111 CEikRichTextEditor& aEditor ) |
|
112 { |
|
113 HBufC* text = HBufC::NewMaxLC( IMUtils::MaxMsgLength() ); |
|
114 TPtr tBuf( text->Des() ); |
|
115 |
|
116 HBufC* msgBuf = aEditor.GetTextInHBufL(); |
|
117 |
|
118 // Because the comments in TSW, we delete the mark first and add it anywhere to |
|
119 // let the akn components know. |
|
120 |
|
121 // Get the pointer of the buffer. |
|
122 TPtr bufPtr = msgBuf->Des(); |
|
123 |
|
124 // An indicator for whether the buffer is processed. |
|
125 TBool isProcessed( EFalse ); |
|
126 |
|
127 // Delete the mark any way |
|
128 for ( TInt i = 0; i < bufPtr.Length(); i++ ) |
|
129 { |
|
130 TInt pos = bufPtr.Find( KRIGHT_TO_LEFT_MAKR ); |
|
131 |
|
132 // If can not find the right-to-left mark pos = -1 |
|
133 if ( pos >= 0 ) |
|
134 { |
|
135 bufPtr.Delete( pos, KLENGTHOFACHAR ); |
|
136 isProcessed = ETrue; |
|
137 } |
|
138 } |
|
139 |
|
140 // Re-add the mark back |
|
141 if ( isProcessed ) |
|
142 { |
|
143 bufPtr.Insert( 0, KRIGHT_TO_LEFT_MAKR ); |
|
144 bufPtr.Insert( bufPtr.Length(), KRIGHT_TO_LEFT_MAKR ); |
|
145 } |
|
146 |
|
147 CleanupStack::PushL( msgBuf ); |
|
148 TPtr msgPtr( msgBuf->Des() ); |
|
149 |
|
150 for ( TInt a( 0 ); a < iExtensionArray.Count(); ++a ) |
|
151 { |
|
152 tBuf = msgPtr; |
|
153 iExtensionArray[ a ]->ExtensionToStringL( aEditor, tBuf ); |
|
154 CleanupStack::PopAndDestroy( msgBuf ); |
|
155 msgBuf = NULL; |
|
156 msgBuf = tBuf.AllocLC(); |
|
157 TPtr newPtr( msgBuf->Des() ); |
|
158 msgPtr.Set( newPtr ); |
|
159 } |
|
160 |
|
161 tBuf = msgPtr; |
|
162 |
|
163 TInt length = tBuf.Length(); |
|
164 for ( TInt i = length - 1; i >= 0 ; --i ) |
|
165 { |
|
166 if ( tBuf[ i ] == CEditableText::EZeroWidthNoBreakSpace ) |
|
167 { |
|
168 tBuf.Delete( i, 1 ); // removing 1 character |
|
169 } |
|
170 } |
|
171 CleanupStack::PopAndDestroy( msgBuf ); |
|
172 return text; |
|
173 } |
|
174 |
|
175 // ----------------------------------------------------------------------------- |
|
176 // CCAMessageExtensionsHandler::InsertExtensionIcon |
|
177 // Find right extension handler and insert extension |
|
178 // ----------------------------------------------------------------------------- |
|
179 // |
|
180 void CCAMessageExtensionsHandler::InsertExtensionL( CEikRichTextEditor& aEditor, |
|
181 TMessageExtensionTypes aType, |
|
182 TBool& aCancelled ) |
|
183 { |
|
184 TBool flag( EFalse ); |
|
185 for ( TInt a( 0 ); a < iExtensionArray.Count() && !flag; ++a ) |
|
186 { |
|
187 if ( aType == iExtensionArray[ a ]->Type() ) |
|
188 { |
|
189 iExtensionArray[ a ]->InsertExtensionL( aEditor, aCancelled ); |
|
190 flag = ETrue; |
|
191 } |
|
192 } |
|
193 } |
|
194 |
|
195 // ----------------------------------------------------------------------------- |
|
196 // CCAMessageExtensionsHandler::DeleteExtensionIcon |
|
197 // Find right extension handler and delete extension |
|
198 // ----------------------------------------------------------------------------- |
|
199 // |
|
200 void CCAMessageExtensionsHandler::DeleteExtensionL( CEikRichTextEditor& aEditor, |
|
201 TMessageExtensionTypes aType, |
|
202 TInt aPos ) |
|
203 { |
|
204 TBool flag( EFalse ); |
|
205 for ( TInt a( 0 ); a < iExtensionArray.Count() && !flag; ++a ) |
|
206 { |
|
207 if ( aType == iExtensionArray[ a ]->Type() ) |
|
208 { |
|
209 iExtensionArray[ a ]->DeleteExtensionL( aEditor, aPos ); |
|
210 flag = ETrue; |
|
211 } |
|
212 } |
|
213 } |
|
214 |
|
215 // ----------------------------------------------------------------------------- |
|
216 // CCAMessageExtensionsHandler::ConvertSelectionToExtensionL |
|
217 // Convert all extensions from strings to extensions in area. |
|
218 // ----------------------------------------------------------------------------- |
|
219 // |
|
220 void CCAMessageExtensionsHandler::ConvertSelectionToExtensionL( |
|
221 CEikRichTextEditor& aEditor ) |
|
222 { |
|
223 for ( TInt a( 0 ); a < iExtensionArray.Count(); ++a ) |
|
224 { |
|
225 iExtensionArray[ a ]->ConvertSelectionToExtensionL( aEditor ); |
|
226 } |
|
227 } |
|
228 |
|
229 // ----------------------------------------------------------------------------- |
|
230 // CCAMessageExtensionsHandler::ConvertSelectionToExtensionL |
|
231 // Convert all extensions from strings to extensions in area. |
|
232 // ----------------------------------------------------------------------------- |
|
233 // |
|
234 void CCAMessageExtensionsHandler::ConvertSelectionToExtensionL( |
|
235 CRichText& aRichText, TCursorSelection& aSelection ) |
|
236 { |
|
237 for ( TInt a( 0 ); a < iExtensionArray.Count(); ++a ) |
|
238 { |
|
239 iExtensionArray[ a ]->ConvertSelectionToExtensionL( aRichText, aSelection ); |
|
240 } |
|
241 } |
|
242 |
|
243 // ----------------------------------------------------------------------------- |
|
244 // CCAMessageExtensionsHandler::ConvertSelectionToStringL |
|
245 // Convert all extensions from extensions to strings in area. |
|
246 // ----------------------------------------------------------------------------- |
|
247 // |
|
248 void CCAMessageExtensionsHandler::ConvertSelectionToStringL( |
|
249 CEikRichTextEditor& aEditor, TBool aPreserve /*= EFalse*/ ) |
|
250 { |
|
251 for ( TInt a( 0 ); a < iExtensionArray.Count(); ++a ) |
|
252 { |
|
253 iExtensionArray[ a ]->ConvertSelectionToStringL( aEditor, aPreserve ); |
|
254 } |
|
255 } |
|
256 |
|
257 // ----------------------------------------------------------------------------- |
|
258 // CCAMessageExtensionsHandler::SizeChanged |
|
259 // Convert all extensions from extensions to strings in area. |
|
260 // ----------------------------------------------------------------------------- |
|
261 // |
|
262 void CCAMessageExtensionsHandler::SizeChanged( TSize& aSize ) |
|
263 { |
|
264 for ( TInt a( 0 ); a < iExtensionArray.Count(); ++a ) |
|
265 { |
|
266 iExtensionArray[ a ]->SizeChanged( aSize ); |
|
267 } |
|
268 } |
|
269 |
|
270 // ----------------------------------------------------------------------------- |
|
271 // CCAMessageExtensionsHandler::ConvertSelectionToStringL |
|
272 // Convert all extensions from extensions to strings in area. |
|
273 // ----------------------------------------------------------------------------- |
|
274 // |
|
275 void CCAMessageExtensionsHandler::ConvertSelectionToStringL( |
|
276 CEikRichTextEditor& aEditor, |
|
277 TDes& aResultString, |
|
278 TCursorSelection& aSelectionAfterConversion, |
|
279 TBool aPreserve ) |
|
280 { |
|
281 for ( TInt a( 0 ); a < iExtensionArray.Count(); ++a ) |
|
282 { |
|
283 iExtensionArray[ a ]->ConvertSelectionToStringL( |
|
284 aEditor, aResultString, aSelectionAfterConversion, aPreserve ); |
|
285 } |
|
286 } |
|
287 |
|
288 // end of file |