1 /* |
|
2 * Copyright (c) 2007-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: message editer |
|
15 * |
|
16 */ |
|
17 |
|
18 // INCLUDE FILES |
|
19 #include <AknsBasicBackgroundControlContext.h> |
|
20 #include "cimcvappmessageeditor.h" |
|
21 #include <eikmenub.h> |
|
22 #include <eikdef.h> |
|
23 #include <akninfrm.h> |
|
24 #include <eikon.rsg> |
|
25 #include <eikenv.h> |
|
26 #include <txtglobl.h> |
|
27 #include <gulfont.h> |
|
28 #include <txtfrmat.h> |
|
29 #include <eikrted.h> |
|
30 #include <aknconsts.h> |
|
31 #include <aknEditStateIndicator.h> |
|
32 #include <featmgr.h> |
|
33 #include <fepbase.h> |
|
34 #include <AknUtils.h> |
|
35 #include <aknappui.h> |
|
36 #include <imcvuiapp.mbg> |
|
37 #include <eikcolib.h> //CEikAppUiFactory |
|
38 #include <avkon.mbg> |
|
39 #include <skinlayout.cdl.h> |
|
40 #include <txtrich.h> |
|
41 #include <eikedwin.h> |
|
42 #include "cimcvappview.h" |
|
43 #include "mimcvtapeventobserver.h" |
|
44 #include "cimcvappmessageextensionshandler.h" |
|
45 #include <aknlayoutscalable_avkon.cdl.h> |
|
46 using namespace SkinLayout; |
|
47 |
|
48 |
|
49 // CONSTANTS |
|
50 const TInt KChatKeyEventHotkeyLimit = 100; |
|
51 const TInt KChatResourceBufferSize = 24; |
|
52 const TInt KMaxMsgLength = 400; |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 // --------------------------------------------------------------------------- |
|
58 // CIMCVAppMessageEditor::NewL |
|
59 // --------------------------------------------------------------------------- |
|
60 // |
|
61 CIMCVAppMessageEditor* CIMCVAppMessageEditor::NewL(const CCoeControl* aParent, |
|
62 TDesC& mbmPath, |
|
63 CIMCVAppView& aAppView, |
|
64 CIMCVAppMessageExtensionsHandler& aExtensionsHandler) |
|
65 { |
|
66 CIMCVAppMessageEditor* msgEditor = new(ELeave)CIMCVAppMessageEditor(aAppView, |
|
67 aExtensionsHandler); |
|
68 CleanupStack::PushL( msgEditor ); |
|
69 msgEditor->ConstructL( aParent, mbmPath ); |
|
70 msgEditor->SetFocus( ETrue ); |
|
71 CleanupStack::Pop(); // msgEditor |
|
72 return msgEditor; |
|
73 } |
|
74 |
|
75 |
|
76 // --------------------------------------------------------------------------- |
|
77 // CIMCVAppMessageEditor::~CBrowserGotoPane |
|
78 // --------------------------------------------------------------------------- |
|
79 // |
|
80 CIMCVAppMessageEditor::~CIMCVAppMessageEditor() |
|
81 { |
|
82 if(iBgContext) |
|
83 { |
|
84 delete iBgContext; |
|
85 } |
|
86 delete iEditor; |
|
87 delete iInputFrame; |
|
88 iEditorObserver = NULL; |
|
89 } |
|
90 |
|
91 // --------------------------------------------------------------------------- |
|
92 // CIMCVAppMessageEditor::CIMCVAppMessageEditor |
|
93 // --------------------------------------------------------------------------- |
|
94 // |
|
95 CIMCVAppMessageEditor::CIMCVAppMessageEditor(CIMCVAppView& aAppView, |
|
96 CIMCVAppMessageExtensionsHandler& aExtensionHandler): |
|
97 iAppView (aAppView), |
|
98 iExtensionHandler(aExtensionHandler) |
|
99 { |
|
100 } |
|
101 |
|
102 // --------------------------------------------------------------------------- |
|
103 // CIMCVAppMessageEditor::ConstructL |
|
104 // --------------------------------------------------------------------------- |
|
105 // |
|
106 void CIMCVAppMessageEditor::ConstructL ( const CCoeControl* aParent, TDesC& mbmPath ) |
|
107 { |
|
108 CreateWindowL(); |
|
109 |
|
110 // remove 'const' modifier and set parent control |
|
111 SetMopParent( CONST_CAST( CCoeControl*, aParent ) ); |
|
112 |
|
113 iEditor = new (ELeave) CEikRichTextEditor; |
|
114 |
|
115 iInputFrame = CAknInputFrame::NewL( |
|
116 iEditor, |
|
117 EFalse, |
|
118 mbmPath, |
|
119 EMbmImcvuiappQgn_indi_im_msg_editor, |
|
120 EMbmImcvuiappQgn_indi_im_msg_editor_mask, |
|
121 0 ); |
|
122 |
|
123 iInputFrame->SetContainerWindowL( *this ); |
|
124 |
|
125 AknEditUtils::ConstructEditingL ( iEditor, |
|
126 KMaxMsgLength, |
|
127 1, |
|
128 EAknEditorCharactersLowerCase, |
|
129 EAknEditorAlignRight, |
|
130 EFalse, |
|
131 ETrue, |
|
132 EFalse ); |
|
133 |
|
134 iEditor->SetContainerWindowL( *this ); |
|
135 iEditor->SetObserver( this ); |
|
136 iEditor->SetBorder( TGulBorder::ENone ); |
|
137 iEditor->SetAknEditorCase( EAknEditorLowerCase ); |
|
138 iEditor->SetAknEditorInputMode( EAknEditorAllInputModes ); |
|
139 iEditor->SetAllowPictures(ETrue); |
|
140 // iEditor->SetAknEditorFlags(CEikRichTextEditor::ENoTextParsers); |
|
141 iEditor->SetAknEditorPermittedCaseModes ( EAknEditorAllCaseModes ); |
|
142 iEditor->CreateTextViewL(); |
|
143 TRect screen( 0,0,0,0 ); |
|
144 |
|
145 AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EScreen, screen ); |
|
146 //get the background skin context |
|
147 iBgContext = CAknsBasicBackgroundControlContext::NewL( |
|
148 KAknsIIDQsnBgAreaMain, screen, EFalse ); |
|
149 //set the editor background color to background skin context |
|
150 iEditor->SetSkinBackgroundControlContextL( iBgContext ); |
|
151 iEditor->OverrideColorL(EColorControlSurroundBackground,KRgbRed); |
|
152 iEditor->EnableCcpuSupportL(ETrue); |
|
153 iEditor->SetEdwinObserver(this); |
|
154 iServiceId = iAppView.ActiveEngine().GetServiceId(); |
|
155 ActivateL(); |
|
156 } |
|
157 |
|
158 // --------------------------------------------------------------------------- |
|
159 // CIMCVAppMessageEditor::HandleControlEventL |
|
160 // --------------------------------------------------------------------------- |
|
161 // |
|
162 void CIMCVAppMessageEditor::HandleControlEventL ( CCoeControl* /*aControl*/, |
|
163 TCoeEvent aEventType ) |
|
164 { |
|
165 switch (aEventType) |
|
166 { |
|
167 case EEventStateChanged: |
|
168 { |
|
169 iEditor->DrawNow(); |
|
170 iAppView.UpdateToolbarButtonsStateL(); |
|
171 break; |
|
172 } |
|
173 case EEventRequestFocus: |
|
174 { |
|
175 FocusChanged( EDrawNow ); |
|
176 break; |
|
177 } |
|
178 default: |
|
179 break; |
|
180 } |
|
181 } |
|
182 |
|
183 // --------------------------------------------------------------------------- |
|
184 // CIMCVAppMessageEditor::HandleControlEventL |
|
185 // --------------------------------------------------------------------------- |
|
186 // |
|
187 void CIMCVAppMessageEditor::HandleEdwinEventL(CEikEdwin* /*aEdwin*/, |
|
188 TEdwinEvent /*aEventType*/) |
|
189 { |
|
190 iEditor->DrawNow(); |
|
191 } |
|
192 // ----------------------------------------------------------------------------- |
|
193 // CIMCVAppMessageEditor::NotifyObserverIfNeededL |
|
194 // Called to force refresh of editor contents after inserting a smiley |
|
195 // ----------------------------------------------------------------------------- |
|
196 // |
|
197 void CIMCVAppMessageEditor::NotifyObserverIfNeededL( TInt aOldLen, TInt aCurLen ) const |
|
198 { |
|
199 if ( iEditorObserver ) |
|
200 { |
|
201 if ( aCurLen == 0 && aOldLen > 0 ) |
|
202 { |
|
203 iEditorObserver->HandleMessageEditorEventL( |
|
204 MIMCVAppMessageEditorObserver::EEditorContentCleared ); |
|
205 |
|
206 return; |
|
207 } |
|
208 if (aOldLen != aCurLen) |
|
209 { |
|
210 iEditorObserver->HandleMessageEditorEventL( |
|
211 MIMCVAppMessageEditorObserver::EEditorContentChanged ); |
|
212 return; |
|
213 } |
|
214 } |
|
215 |
|
216 } |
|
217 // ---------------------------------------------------------------------------- |
|
218 // CIMCVAppMessageEditor::OfferKeyEventL |
|
219 // ---------------------------------------------------------------------------- |
|
220 // |
|
221 TKeyResponse CIMCVAppMessageEditor::OfferKeyEventL |
|
222 ( const TKeyEvent& aKeyEvent, TEventCode aType ) |
|
223 { |
|
224 TInt oldLen = iEditor->TextLength(); |
|
225 if ( iEditor->TextLength() == iEditor->MaxLength() ) |
|
226 { |
|
227 if(( aType == EEventKey && |
|
228 ( aKeyEvent.iCode != EKeyBackspace && |
|
229 aKeyEvent.iCode < EKeyDelete ) |
|
230 ) || |
|
231 ( aType == EEventKeyUp && |
|
232 aKeyEvent.iScanCode >= '0' && |
|
233 aKeyEvent.iScanCode <= '9' |
|
234 ) |
|
235 ) |
|
236 { |
|
237 |
|
238 return EKeyWasConsumed; |
|
239 } |
|
240 } |
|
241 |
|
242 TKeyResponse res = EKeyWasNotConsumed; |
|
243 |
|
244 // This logic comes from CEikEdwin |
|
245 // We need to handle hot keys cut and copy |
|
246 TBool select = aKeyEvent.iModifiers & EModifierShift; |
|
247 TBool magnify = aKeyEvent.iModifiers & EModifierCtrl; |
|
248 if ( magnify && aKeyEvent.iCode < KChatKeyEventHotkeyLimit |
|
249 && aKeyEvent.iCode != ' ' ) |
|
250 { |
|
251 TBuf<KChatResourceBufferSize> buf; |
|
252 if ( select ) |
|
253 { |
|
254 iCoeEnv->ReadResourceL( buf, R_EIK_EDWIN_SHIFT_CTRL_HOTKEYS ); |
|
255 } |
|
256 else |
|
257 { |
|
258 iCoeEnv->ReadResourceL( buf, R_EIK_EDWIN_CTRL_HOTKEYS ); |
|
259 } |
|
260 |
|
261 const TInt ret = buf.Locate( TChar( aKeyEvent.iCode + 'a' - 1 ) ); |
|
262 switch( ret ) |
|
263 { |
|
264 case CEikEdwin::EHotKeyCut: |
|
265 { |
|
266 iEditor->CcpuCutL(); |
|
267 res = EKeyWasConsumed; |
|
268 break; |
|
269 } |
|
270 case CEikEdwin::EHotKeyCopy: |
|
271 { |
|
272 iEditor->CcpuCopyL(); |
|
273 res = EKeyWasConsumed; |
|
274 break; |
|
275 } |
|
276 default: |
|
277 { |
|
278 // No need to handle other hot keys here |
|
279 break; |
|
280 } |
|
281 } |
|
282 } |
|
283 // -------------------- |
|
284 |
|
285 if ( res != EKeyWasConsumed ) |
|
286 { |
|
287 res = iEditor->OfferKeyEventL( aKeyEvent, aType ); |
|
288 } |
|
289 |
|
290 NotifyObserverIfNeededL(oldLen, iEditor->TextLength()); |
|
291 return res; |
|
292 |
|
293 } |
|
294 |
|
295 // ---------------------------------------------------------------------------- |
|
296 // CIMCVAppMessageEditor::HandlePointerEventL |
|
297 // ---------------------------------------------------------------------------- |
|
298 // |
|
299 void CIMCVAppMessageEditor::HandlePointerEventL(const TPointerEvent& aPointerEvent) |
|
300 { |
|
301 if( !AknLayoutUtils::PenEnabled() ) |
|
302 { |
|
303 return; |
|
304 } |
|
305 iEditor->HandlePointerEventL( aPointerEvent ); |
|
306 } |
|
307 |
|
308 // ---------------------------------------------------------------------------- |
|
309 // CIMCVAppMessageEditor::CountComponentControls |
|
310 // ---------------------------------------------------------------------------- |
|
311 // |
|
312 TInt CIMCVAppMessageEditor::CountComponentControls() const |
|
313 { |
|
314 return 2; // iEditor and input frame |
|
315 } |
|
316 |
|
317 // ---------------------------------------------------------------------------- |
|
318 // CIMCVAppMessageEditor::ComponentControl |
|
319 // ---------------------------------------------------------------------------- |
|
320 // |
|
321 CCoeControl* CIMCVAppMessageEditor::ComponentControl ( TInt aIndex ) const |
|
322 { |
|
323 switch(aIndex) |
|
324 { |
|
325 case 0: |
|
326 { |
|
327 return iInputFrame; |
|
328 } |
|
329 case 1: |
|
330 { |
|
331 return iEditor; |
|
332 } |
|
333 default: |
|
334 return NULL; |
|
335 } |
|
336 } |
|
337 |
|
338 // ---------------------------------------------------------------------------- |
|
339 // CIMCVAppMessageEditor::SizeChanged |
|
340 // ---------------------------------------------------------------------------- |
|
341 // |
|
342 void CIMCVAppMessageEditor::SizeChanged() |
|
343 { |
|
344 TAknLayoutRect layoutRectTemp; |
|
345 TAknWindowLineLayout windowLayoutTmp, windowLayoutTmp2; |
|
346 |
|
347 windowLayoutTmp = AknLayout::Find_pane_elements_Line_4(); |
|
348 windowLayoutTmp2 = windowLayoutTmp; |
|
349 layoutRectTemp.LayoutRect( Rect(), windowLayoutTmp2 ); |
|
350 iEditor->SetRect( layoutRectTemp.Rect() ); |
|
351 iInputFrame->SetRect( Rect() ); |
|
352 } |
|
353 |
|
354 // ---------------------------------------------------------------------------- |
|
355 // CIMCVAppMessageEditor::FocusChanged |
|
356 // ---------------------------------------------------------------------------- |
|
357 // |
|
358 void CIMCVAppMessageEditor::FocusChanged( TDrawNow aDrawNow ) |
|
359 { |
|
360 iEditor->SetFocus( IsFocused(), aDrawNow ); |
|
361 } |
|
362 |
|
363 // ---------------------------------------------------------------------------- |
|
364 // CIMCVAppMessageEditor::TextLength |
|
365 // ---------------------------------------------------------------------------- |
|
366 // |
|
367 TInt CIMCVAppMessageEditor::TextLength() const |
|
368 { |
|
369 return iEditor->TextLength(); |
|
370 } |
|
371 |
|
372 // ---------------------------------------------------------------------------- |
|
373 // CIMCVAppMessageEditor::SetTextL |
|
374 // ---------------------------------------------------------------------------- |
|
375 // |
|
376 void CIMCVAppMessageEditor::SetTextL( const TDesC& aTxt ) |
|
377 { |
|
378 iEditor->SetTextL( &aTxt ); |
|
379 TInt curPos = TextLength(); |
|
380 // Cursor to end, no selection. |
|
381 iEditor->SetSelectionL( curPos, curPos ); |
|
382 iEditor->DrawNow(); |
|
383 } |
|
384 |
|
385 |
|
386 // ---------------------------------------------------------------------------- |
|
387 // CIMCVAppMessageEditor::Editor |
|
388 // ---------------------------------------------------------------------------- |
|
389 CEikRichTextEditor& CIMCVAppMessageEditor::Editor() const |
|
390 { |
|
391 return *iEditor; |
|
392 } |
|
393 |
|
394 // ----------------------------------------------------------------------------- |
|
395 // CIMCVAppMessageEditor::SetMessageEditorObserver |
|
396 // Called to force refresh of editor contents after inserting a smiley |
|
397 // ----------------------------------------------------------------------------- |
|
398 // |
|
399 void CIMCVAppMessageEditor::SetMessageEditorObserver( MIMCVAppMessageEditorObserver* aObserver ) |
|
400 { |
|
401 iEditorObserver = aObserver; |
|
402 } |
|
403 |
|
404 // --------------------------------------------------------------------------- |
|
405 // CIMCVAppMessageEditor::HandleFindSizeChanged |
|
406 // --------------------------------------------------------------------------- |
|
407 // |
|
408 void CIMCVAppMessageEditor::HandleFindSizeChanged() |
|
409 { |
|
410 // Lay out Goto Pane as if it was the old Find Pane. |
|
411 TRect rect; |
|
412 AknLayoutUtils::LayoutMetricsRect(AknLayoutUtils::EMainPane,rect); |
|
413 TAknWindowLineLayout msgPane=AknLayoutScalable_Avkon::find_pane(); |
|
414 |
|
415 |
|
416 AknLayoutUtils::LayoutControl( this, rect, msgPane ); |
|
417 |
|
418 SizeChanged(); |
|
419 } |
|
420 |
|
421 // ----------------------------------------------------------------------------- |
|
422 // CIMCVAppMessageEditor::SetTapObserver |
|
423 // (other items were commented in a header). |
|
424 // ----------------------------------------------------------------------------- |
|
425 // |
|
426 void CIMCVAppMessageEditor::SetTapObserver( MIMCVTapEventObserver* aObserver, TUint aId ) |
|
427 { |
|
428 iTapObserver = aObserver; |
|
429 iTapControlId = aId; |
|
430 } |
|
431 |
|
432 // ----------------------------------------------------------------------------- |
|
433 // CIMCVAppMessageEditor::MopSupplyObject |
|
434 // (other items were commented in a header). |
|
435 // ----------------------------------------------------------------------------- |
|
436 // |
|
437 TTypeUid::Ptr CIMCVAppMessageEditor::MopSupplyObject( TTypeUid aId ) |
|
438 { |
|
439 if( aId.iUid == MAknsControlContext::ETypeId && iBgContext ) |
|
440 { |
|
441 return MAknsControlContext::SupplyMopObject( aId, iBgContext ); |
|
442 } |
|
443 return CCoeControl::MopSupplyObject(aId); |
|
444 } |
|
445 |
|
446 // END OF FILE |
|