|
1 /* |
|
2 * Copyright (c) 2007-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: Response dialog's custom control implementation |
|
15 * |
|
16 */ |
|
17 #include "cmrresponsedialogview.h" |
|
18 // System includes |
|
19 #include <AknsDrawUtils.h> |
|
20 #include <AknsBasicBackgroundControlContext.h> |
|
21 #include <eikrted.h> |
|
22 #include <eiksbfrm.h> |
|
23 #include <AknDef.h> |
|
24 #include <AknUtils.h> |
|
25 #include <gdi.h> |
|
26 |
|
27 // DEBUG |
|
28 #include "emailtrace.h" |
|
29 |
|
30 // LOCAL DEFINITIONS |
|
31 namespace // codescanner::namespace |
|
32 { |
|
33 #define KDefaultTextColor TRgb( 0x000000 ); |
|
34 /// Get the text color from skin |
|
35 TRgb TextColor( TInt aSkinColorId ) |
|
36 { |
|
37 TRgb bgColor; |
|
38 TInt err; |
|
39 |
|
40 err = AknsUtils::GetCachedColor( AknsUtils::SkinInstance(), |
|
41 bgColor, |
|
42 KAknsIIDQsnTextColors, |
|
43 aSkinColorId ); |
|
44 if( err != KErrNone ) |
|
45 { |
|
46 bgColor = KDefaultTextColor; |
|
47 } |
|
48 return bgColor; |
|
49 } |
|
50 } |
|
51 |
|
52 // --------------------------------------------------------------------------- |
|
53 // CESMRResponseDialogView::NewL |
|
54 // --------------------------------------------------------------------------- |
|
55 // |
|
56 CESMRResponseDialogView* CESMRResponseDialogView::NewL() |
|
57 { |
|
58 FUNC_LOG; |
|
59 CESMRResponseDialogView* self = |
|
60 new (ELeave) CESMRResponseDialogView(); |
|
61 CleanupStack::PushL( self ); |
|
62 self->ConstructL(); |
|
63 CleanupStack::Pop( self ); |
|
64 return self; |
|
65 } |
|
66 |
|
67 // --------------------------------------------------------------------------- |
|
68 // CESMRResponseDialogView::CESMRResponseDialogView |
|
69 // --------------------------------------------------------------------------- |
|
70 // |
|
71 CESMRResponseDialogView::CESMRResponseDialogView() |
|
72 { |
|
73 FUNC_LOG; |
|
74 // Do nothing |
|
75 } |
|
76 |
|
77 // --------------------------------------------------------------------------- |
|
78 // CESMRResponseDialogView::ConstructL |
|
79 // --------------------------------------------------------------------------- |
|
80 // |
|
81 void CESMRResponseDialogView::ConstructL() |
|
82 { |
|
83 FUNC_LOG; |
|
84 iBgContext = CAknsBasicBackgroundControlContext::NewL( |
|
85 KAknsIIDQsnBgAreaMain, Rect() , ETrue ); |
|
86 } |
|
87 |
|
88 // --------------------------------------------------------------------------- |
|
89 // CESMRResponseDialogView::~CESMRResponseDialogView |
|
90 // --------------------------------------------------------------------------- |
|
91 // |
|
92 CESMRResponseDialogView::~CESMRResponseDialogView() |
|
93 { |
|
94 FUNC_LOG; |
|
95 delete iEditor; |
|
96 delete iBgContext; |
|
97 } |
|
98 |
|
99 // --------------------------------------------------------------------------- |
|
100 // CESMRResponseDialogView::OfferKeyEventL |
|
101 // --------------------------------------------------------------------------- |
|
102 // |
|
103 TKeyResponse CESMRResponseDialogView::OfferKeyEventL( |
|
104 const TKeyEvent& aEvent, |
|
105 TEventCode aType) |
|
106 { |
|
107 FUNC_LOG; |
|
108 return iEditor->OfferKeyEventL( aEvent, aType ); |
|
109 } |
|
110 |
|
111 // --------------------------------------------------------------------------- |
|
112 // CESMRResponseDialogView::Draw |
|
113 // --------------------------------------------------------------------------- |
|
114 // |
|
115 void CESMRResponseDialogView::Draw(const TRect& aRect) const |
|
116 { |
|
117 FUNC_LOG; |
|
118 CWindowGc& gc = SystemGc(); |
|
119 |
|
120 // Redraw the background using the default skin |
|
121 MAknsSkinInstance* skin = AknsUtils::SkinInstance(); |
|
122 MAknsControlContext* cc = AknsDrawUtils::ControlContext( this ); |
|
123 AknsDrawUtils::Background( skin, cc, this, gc, aRect ); |
|
124 } |
|
125 |
|
126 // --------------------------------------------------------------------------- |
|
127 // CESMRResponseDialogView::MopSupplyObject |
|
128 // --------------------------------------------------------------------------- |
|
129 // |
|
130 TTypeUid::Ptr CESMRResponseDialogView::MopSupplyObject(TTypeUid aId) |
|
131 { |
|
132 if (iBgContext ) |
|
133 { |
|
134 return MAknsControlContext::SupplyMopObject( aId, iBgContext ); |
|
135 } |
|
136 return CCoeControl::MopSupplyObject(aId); |
|
137 } |
|
138 |
|
139 // --------------------------------------------------------------------------- |
|
140 // CESMRResponseDialogView::CountComponentControls |
|
141 // --------------------------------------------------------------------------- |
|
142 // |
|
143 TInt CESMRResponseDialogView::CountComponentControls() const |
|
144 { |
|
145 FUNC_LOG; |
|
146 return 1; |
|
147 } |
|
148 |
|
149 // --------------------------------------------------------------------------- |
|
150 // CESMRResponseDialogView::ComponentControl |
|
151 // --------------------------------------------------------------------------- |
|
152 // |
|
153 CCoeControl* CESMRResponseDialogView::ComponentControl( TInt /*aInd*/ ) const |
|
154 { |
|
155 FUNC_LOG; |
|
156 return iEditor; |
|
157 } |
|
158 |
|
159 // --------------------------------------------------------------------------- |
|
160 // CESMRResponseDialogView::GetTextL |
|
161 // --------------------------------------------------------------------------- |
|
162 // |
|
163 HBufC* CESMRResponseDialogView::GetTextL() |
|
164 { |
|
165 FUNC_LOG; |
|
166 return iEditor->GetTextInHBufL(); |
|
167 } |
|
168 |
|
169 // --------------------------------------------------------------------------- |
|
170 // CESMRResponseDialogView::SetContainerWindowL |
|
171 // --------------------------------------------------------------------------- |
|
172 // |
|
173 void CESMRResponseDialogView::SetContainerWindowL( |
|
174 const CCoeControl& aContainer) |
|
175 { |
|
176 FUNC_LOG; |
|
177 CCoeControl::SetContainerWindowL( aContainer ); |
|
178 iEditor = new (ELeave )CEikRichTextEditor(); |
|
179 iEditor->ConstructL( this, 0, 0, CEikEdwin::ENoAutoSelection, 0, 0 ); |
|
180 iEditor->SetFocus( ETrue ); |
|
181 iEditor->SetContainerWindowL( *this ); |
|
182 iEditor->SetSize( Rect().Size() ); |
|
183 iEditor->SetSkinBackgroundControlContextL( iBgContext ); |
|
184 |
|
185 // Create vertical scrollbar for editor |
|
186 iScrollBarFrame = iEditor->CreateScrollBarFrameL(); |
|
187 iScrollBarFrame->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff, CEikScrollBarFrame::EOn ); |
|
188 |
|
189 TRAP_IGNORE( SetFontColorL() ); |
|
190 } |
|
191 |
|
192 // --------------------------------------------------------------------------- |
|
193 // CESMRResponseDialogView::HandleResourceChange() |
|
194 // --------------------------------------------------------------------------- |
|
195 // |
|
196 void CESMRResponseDialogView::HandleResourceChange( TInt aType ) |
|
197 { |
|
198 FUNC_LOG; |
|
199 CCoeControl::HandleResourceChange( aType ); |
|
200 |
|
201 if ( aType == KEikDynamicLayoutVariantSwitch ) |
|
202 { |
|
203 SizeChanged(); |
|
204 } |
|
205 else if ( aType == KAknsMessageSkinChange || |
|
206 aType == KEikMessageColorSchemeChange ) |
|
207 { |
|
208 TRAP_IGNORE( SetFontColorL() ); |
|
209 } |
|
210 } |
|
211 |
|
212 // --------------------------------------------------------------------------- |
|
213 // CESMRResponseDialogView::SizeChanged() |
|
214 // --------------------------------------------------------------------------- |
|
215 // |
|
216 void CESMRResponseDialogView::SizeChanged() |
|
217 { |
|
218 if(iBgContext) |
|
219 { |
|
220 iBgContext->SetRect(Rect()); |
|
221 if ( &Window() ) |
|
222 { |
|
223 iBgContext->SetParentPos( PositionRelativeToScreen() ); |
|
224 } |
|
225 } |
|
226 if( iEditor ) |
|
227 { |
|
228 // Reduce scrollbar width from the editor width |
|
229 TRect rect = Rect(); |
|
230 TInt scrollbarWidth = iEditor->ScrollBarFrame()->ScrollBarBreadth( CEikScrollBar::EVertical ); |
|
231 TInt editorWidth = rect.Width() - scrollbarWidth; |
|
232 if ( AknLayoutUtils::LayoutMirrored() ) |
|
233 { |
|
234 iEditor->SetExtent( TPoint( scrollbarWidth, 0 ), TSize( editorWidth, rect.Height() ) ); |
|
235 } |
|
236 else |
|
237 { |
|
238 iEditor->SetExtent( TPoint( 0, 0 ), TSize( editorWidth, rect.Height() ) ); |
|
239 } |
|
240 } |
|
241 } |
|
242 |
|
243 // --------------------------------------------------------------------------- |
|
244 // CESMRResponseDialogView::MinimumSize() |
|
245 // --------------------------------------------------------------------------- |
|
246 // |
|
247 TSize CESMRResponseDialogView::MinimumSize() |
|
248 { |
|
249 FUNC_LOG; |
|
250 TRect rect; |
|
251 AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EMainPane, rect ); |
|
252 return rect.Size(); |
|
253 } |
|
254 |
|
255 // ----------------------------------------------------------------------------- |
|
256 // CESMRResponseDialogView::SetFontColorL() |
|
257 // ----------------------------------------------------------------------------- |
|
258 // |
|
259 void CESMRResponseDialogView::SetFontColorL() |
|
260 { |
|
261 const CFont* sysfont = AknLayoutUtils::FontFromId( EAknLogicalFontPrimaryFont, NULL ); |
|
262 TFontSpec fontSpec = sysfont->FontSpecInTwips(); |
|
263 TCharFormat charFormat; |
|
264 TCharFormatMask formatMask; |
|
265 charFormat.iFontSpec = fontSpec; |
|
266 |
|
267 formatMask.SetAttrib( EAttFontTypeface ); |
|
268 formatMask.SetAttrib( EAttFontHeight ); |
|
269 formatMask.SetAttrib( EAttFontPosture ); |
|
270 |
|
271 charFormat.iFontPresentation.iTextColor = TextColor( EAknsCIQsnTextColorsCG6 ); |
|
272 formatMask.SetAttrib( EAttColor ); |
|
273 |
|
274 CCharFormatLayer* charFormatLayer = |
|
275 CCharFormatLayer::NewL( charFormat, formatMask ); |
|
276 |
|
277 iEditor->SetCharFormatLayer( charFormatLayer ); |
|
278 } |
|
279 |
|
280 // end of file |