|
1 /* |
|
2 * Copyright (c) 2008 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: smiely engine class |
|
15 * |
|
16 */ |
|
17 |
|
18 #include <coecntrl.h> |
|
19 #include <eikedwin.h> |
|
20 #include <frmtlay.h> |
|
21 |
|
22 #include "smileymodel.h" |
|
23 #include "smileyinforeader.h" |
|
24 #include "smileydrawer.h" |
|
25 #include "smileyimagedata.h" |
|
26 #include "smileymanager.h" |
|
27 #include "smileyiconrecord.h" |
|
28 |
|
29 // ======== MEMBER FUNCTIONS ======== |
|
30 // --------------------------------------------------------------------------- |
|
31 // CSmileyManager::NewL |
|
32 // --------------------------------------------------------------------------- |
|
33 // |
|
34 CSmileyManager* CSmileyManager::NewL( CEikEdwin& aEdwin ) |
|
35 { |
|
36 CSmileyManager* self = CSmileyManager::NewLC( aEdwin ); |
|
37 CleanupStack::Pop( self ); |
|
38 return self; |
|
39 } |
|
40 |
|
41 // --------------------------------------------------------------------------- |
|
42 // CSmileyManager::NewLC |
|
43 // --------------------------------------------------------------------------- |
|
44 // |
|
45 CSmileyManager* CSmileyManager::NewLC( CEikEdwin& aEdwin ) |
|
46 { |
|
47 CSmileyManager* self( new( ELeave ) CSmileyManager ); |
|
48 CleanupStack::PushL( self ); |
|
49 self->ConstructL( aEdwin ); |
|
50 return self; |
|
51 } |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // destructor |
|
55 // --------------------------------------------------------------------------- |
|
56 // |
|
57 CSmileyManager::~CSmileyManager() |
|
58 { |
|
59 delete iDrawer; |
|
60 delete iReader; |
|
61 delete iModel; |
|
62 delete iIconRecord; |
|
63 } |
|
64 |
|
65 // --------------------------------------------------------------------------- |
|
66 // CSmileyManager::ConvertSmileyStrings |
|
67 // --------------------------------------------------------------------------- |
|
68 // |
|
69 TBool CSmileyManager::ConvertTextForSmileyL( TInt aStart, TDes& aText, |
|
70 TBool aStringToCodes ) |
|
71 { |
|
72 TBool ret( EFalse ); |
|
73 if ( aStringToCodes ) |
|
74 { |
|
75 ret = ConvertTextToCodesL( aText, aStart ); |
|
76 } |
|
77 else if ( iIconRecord->HasSmileyIcon() ) |
|
78 { |
|
79 ret = ConvertCodesToTextL( aText, aStart ); |
|
80 } |
|
81 return ret; |
|
82 } |
|
83 |
|
84 // --------------------------------------------------------------------------- |
|
85 // CSmileyManager::ConvertCodesToTextL |
|
86 // --------------------------------------------------------------------------- |
|
87 // |
|
88 TBool CSmileyManager::ConvertCodesToTextL( TDes& aText, TInt aStart ) |
|
89 { |
|
90 TBool ret( EFalse ); |
|
91 for ( TInt i( 0 ); i < aText.Length(); i++ ) |
|
92 { |
|
93 if ( IsSmileyCode( aText[i] ) ) |
|
94 { |
|
95 ret = ETrue; |
|
96 CSmileyIcon* icon( iIconRecord->SmileyIconAtPos( i + aStart ) ); |
|
97 if ( icon ) |
|
98 { |
|
99 const TDesC& smileyText( icon->SmileyString() ); |
|
100 aText.Replace( i, smileyText.Length(), smileyText ); |
|
101 } |
|
102 } |
|
103 } |
|
104 return ret; |
|
105 } |
|
106 |
|
107 TBool CSmileyManager::ConvertTextToCodesL( TDes& aText, TInt aStart ) |
|
108 { |
|
109 TBool ret( EFalse ); |
|
110 TInt i( 0 ); |
|
111 while ( i < aText.Length() ) |
|
112 { |
|
113 TInt index( iModel->TryFindMatchNode( aText, i ) ); |
|
114 if ( iModel->IsFinalNode( index ) ) |
|
115 { |
|
116 TInt smileyLength( iModel->SmileyStringLength( index ) ); |
|
117 TInt docPos( aStart + i ); |
|
118 CSmileyIcon* icon( iIconRecord->SmileyIconAtPos( docPos ) ); |
|
119 if ( !icon || ( icon && !icon->IsDisabled() ) ) |
|
120 { |
|
121 if ( !icon ) |
|
122 { |
|
123 TText smileyCode( iModel->SmileyCode( index ) ); |
|
124 AddSmileyToRecordL( aText.Mid( i, smileyLength ), docPos, |
|
125 smileyCode ); |
|
126 } |
|
127 iModel->ReplaceTextWithCodes( aText, i, index ); |
|
128 ret = ETrue; |
|
129 } |
|
130 i += smileyLength; |
|
131 } |
|
132 else |
|
133 { |
|
134 i++; |
|
135 } |
|
136 } |
|
137 return ret; |
|
138 } |
|
139 |
|
140 void CSmileyManager::AddSmileyToRecordL( const TDesC& aSmileyText, TInt aDocPos, |
|
141 TText aCode ) |
|
142 { |
|
143 CSmileyIcon* icon( new( ELeave ) CSmileyIcon( aCode ) ); |
|
144 icon->SetDocPos( aDocPos ); |
|
145 icon->SetSmileyString( aSmileyText ); |
|
146 iIconRecord->InsertIconL( icon ); |
|
147 } |
|
148 |
|
149 // --------------------------------------------------------------------------- |
|
150 // CSmileyManager::SetHighlightColor |
|
151 // --------------------------------------------------------------------------- |
|
152 // |
|
153 void CSmileyManager::SetHighlightColor( TRgb aColor ) |
|
154 { |
|
155 iDrawer->SetHighlightColor( aColor ); |
|
156 } |
|
157 |
|
158 // --------------------------------------------------------------------------- |
|
159 // CSmileyManager::SetAnimationPlayTimes |
|
160 // --------------------------------------------------------------------------- |
|
161 // |
|
162 void CSmileyManager::SetAnimationPlayTimes( TInt aPlayTimes ) |
|
163 { |
|
164 iDrawer->SetPlayTimes( aPlayTimes ); |
|
165 } |
|
166 |
|
167 // --------------------------------------------------------------------------- |
|
168 // CSmileyManager::DrawIcon |
|
169 // --------------------------------------------------------------------------- |
|
170 // |
|
171 void CSmileyManager::DrawIconL( CBitmapContext& aGc, const TRect& aRect, |
|
172 TInt aDocPos ) |
|
173 { |
|
174 CSmileyIcon* icon( iIconRecord->SmileyIconAtPos( aDocPos ) ); |
|
175 if ( icon && !icon->IsDisabled() ) |
|
176 { |
|
177 icon->SetRect( aRect ); |
|
178 CSmileyImageData* image( icon->ImageData() ); |
|
179 if ( image && aRect.Size() != image->BitmapSize() ) |
|
180 { |
|
181 image->SetBitmapSize( aRect.Size() ); |
|
182 if ( icon->IsPlayFinished() ) |
|
183 { |
|
184 icon->PlayOneTime(); |
|
185 iDrawer->CreateImageL( image ); |
|
186 } |
|
187 } |
|
188 else if ( !image ) |
|
189 { |
|
190 iDrawer->CreateImageByIconL( icon ); |
|
191 } |
|
192 iDrawer->DrawImageByIconL( aGc, icon ); |
|
193 } |
|
194 } |
|
195 |
|
196 // --------------------------------------------------------------------------- |
|
197 // CSmileyManager::IsSmileyCode |
|
198 // --------------------------------------------------------------------------- |
|
199 // |
|
200 TBool CSmileyManager::IsSmileyCode( TText aCode ) |
|
201 { |
|
202 return ( aCode >= KSmileyCodeMin && aCode <= KSmileyCodeMax ); |
|
203 } |
|
204 |
|
205 // --------------------------------------------------------------------------- |
|
206 // CSmileyManager::HandleDeleteL |
|
207 // --------------------------------------------------------------------------- |
|
208 // |
|
209 void CSmileyManager::HandleDeleteL( TInt aStart, TInt aLength ) |
|
210 { |
|
211 iIconRecord->HandleTextDelete( aStart, aLength ); |
|
212 } |
|
213 |
|
214 // --------------------------------------------------------------------------- |
|
215 // CSmileyManager::HandleInsertL |
|
216 // --------------------------------------------------------------------------- |
|
217 // |
|
218 void CSmileyManager::HandleInsertL( TInt aStart, TInt aLength ) |
|
219 { |
|
220 if ( aLength > 0 ) |
|
221 { |
|
222 iIconRecord->HandleTextInsert( aStart, aLength ); |
|
223 } |
|
224 } |
|
225 |
|
226 // --------------------------------------------------------------------------- |
|
227 // CSmileyManager::HandleSetCursorL |
|
228 // --------------------------------------------------------------------------- |
|
229 // |
|
230 void CSmileyManager::HandleSetCursor( TInt aOldCursor, TInt& aNewCursor ) |
|
231 { |
|
232 CSmileyIcon* icon( iIconRecord->SmileyIconAtPos( aNewCursor ) ); |
|
233 if ( icon && !icon->IsDisabled() && aNewCursor != icon->DocPos() ) |
|
234 { |
|
235 if ( aOldCursor <= aNewCursor ) |
|
236 { |
|
237 aNewCursor = icon->EndPos(); |
|
238 } |
|
239 else |
|
240 { |
|
241 aNewCursor = icon->DocPos(); |
|
242 } |
|
243 } |
|
244 } |
|
245 |
|
246 // --------------------------------------------------------------------------- |
|
247 // CSmileyManager::HandleSelectionL |
|
248 // --------------------------------------------------------------------------- |
|
249 // |
|
250 void CSmileyManager::HandleSelection( TInt aStart, TInt aLength ) |
|
251 { |
|
252 iIconRecord->CancelSelection(); |
|
253 iIconRecord->SetSelection( aStart, aLength ); |
|
254 iSelStart = aStart; |
|
255 iSelLength = aLength; |
|
256 } |
|
257 |
|
258 // --------------------------------------------------------------------------- |
|
259 // CSmileyManager::SmileyCodeByPos |
|
260 // --------------------------------------------------------------------------- |
|
261 // |
|
262 TText CSmileyManager::SmileyCodeByPos( TInt aDocPos ) |
|
263 { |
|
264 CSmileyIcon* icon( iIconRecord->SmileyIconAtPos( aDocPos ) ); |
|
265 if ( icon ) |
|
266 { |
|
267 return icon->Code(); |
|
268 } |
|
269 return 0; |
|
270 } |
|
271 |
|
272 // --------------------------------------------------------------------------- |
|
273 // CSmileyManager::SetVisibleRange |
|
274 // --------------------------------------------------------------------------- |
|
275 // |
|
276 void CSmileyManager::SetVisibleRange( TInt aDocPos, TInt aLength ) |
|
277 { |
|
278 iDrawer->SetVisibleRange( aDocPos, aLength ); |
|
279 } |
|
280 |
|
281 // --------------------------------------------------------------------------- |
|
282 // CSmileyManager::TextBlockLength |
|
283 // --------------------------------------------------------------------------- |
|
284 // |
|
285 TInt CSmileyManager::SmileyLength( TInt aDocPos ) |
|
286 { |
|
287 CSmileyIcon* icon( iIconRecord->SmileyIconAtPos( aDocPos ) ); |
|
288 if ( icon ) |
|
289 { |
|
290 return icon->SmileyLength(); |
|
291 } |
|
292 return 0; |
|
293 } |
|
294 |
|
295 // --------------------------------------------------------------------------- |
|
296 // CSmileyManager::TotalTextLength |
|
297 // --------------------------------------------------------------------------- |
|
298 // |
|
299 TBool CSmileyManager::HasSmileyIconsInText() |
|
300 { |
|
301 return iIconRecord->HasSmileyIcon(); |
|
302 } |
|
303 |
|
304 // --------------------------------------------------------------------------- |
|
305 // CSmileyManager::RemoveIconsInRange |
|
306 // --------------------------------------------------------------------------- |
|
307 // |
|
308 void CSmileyManager::RemoveIconsInRange( TInt aStart, TInt aLength ) |
|
309 { |
|
310 iIconRecord->HandleTextDelete( aStart, aLength ); |
|
311 } |
|
312 |
|
313 // --------------------------------------------------------------------------- |
|
314 // CSmileyManager::DisableSmileyIcon |
|
315 // --------------------------------------------------------------------------- |
|
316 // |
|
317 void CSmileyManager::DisableSmileyIcon( TInt aDocPos ) |
|
318 { |
|
319 CSmileyIcon* icon( iIconRecord->SmileyIconAtPos( aDocPos ) ); |
|
320 if ( icon ) |
|
321 { |
|
322 icon->DisableIcon(); |
|
323 } |
|
324 } |
|
325 |
|
326 // --------------------------------------------------------------------------- |
|
327 // CSmileyManager::IsDisabledSmileyIcon |
|
328 // --------------------------------------------------------------------------- |
|
329 // |
|
330 TBool CSmileyManager::IsDisabledSmileyIcon( TInt aDocPos ) |
|
331 { |
|
332 CSmileyIcon* icon( iIconRecord->SmileyIconAtPos( aDocPos ) ); |
|
333 if ( icon ) |
|
334 { |
|
335 return icon->IsDisabled(); |
|
336 } |
|
337 return EFalse; |
|
338 } |
|
339 |
|
340 // ================= Private member functions ====================== |
|
341 // --------------------------------------------------------------------------- |
|
342 // CSmileyManager::CSmileyManager |
|
343 // c++ default constructor |
|
344 // --------------------------------------------------------------------------- |
|
345 // |
|
346 CSmileyManager::CSmileyManager() |
|
347 { |
|
348 } |
|
349 |
|
350 // --------------------------------------------------------------------------- |
|
351 // second phase constructor |
|
352 // --------------------------------------------------------------------------- |
|
353 // |
|
354 void CSmileyManager::ConstructL( CEikEdwin& aEdwin ) |
|
355 { |
|
356 iIconRecord = new( ELeave ) CSmileyIconRecord; |
|
357 iModel = new( ELeave ) CSmileyModel; |
|
358 iReader = new( ELeave ) CSmileyInfoReader( *iModel ); |
|
359 iDrawer = new( ELeave ) CSmileyDrawer( *iModel, aEdwin ); |
|
360 iReader->LoadSmileysFromResourceL(); |
|
361 } |
|
362 |
|
363 |
|
364 |
|
365 |
|
366 |