|
1 /* |
|
2 * Copyright (c) 2002 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: MsgHeader implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // ========== INCLUDE FILES ================================ |
|
21 |
|
22 #include <eikenv.h> // for CEikonEnv |
|
23 #include <gulutil.h> // for ColorUtils |
|
24 #include <AknUtils.h> // for AknUtils |
|
25 |
|
26 #include <applayout.cdl.h> // LAF |
|
27 #include <AknsDrawUtils.h> // for Skinned drawing |
|
28 |
|
29 #include "MsgEditorCommon.h" // |
|
30 #include "MsgHeader.h" // for CMsgHeader |
|
31 #include "MsgCaptionedHighlight.h" |
|
32 #include "MsgDummyHeaderCleaner.h" |
|
33 #include "MsgControlArray.h" // for CMsgControlArray |
|
34 #include "MsgExpandableControl.h" |
|
35 #include "MsgEditorPanic.h" // for CMsgEditor panics |
|
36 #include "MsgEditorLogging.h" |
|
37 |
|
38 // ========== EXTERNAL DATA STRUCTURES ===================== |
|
39 |
|
40 // ========== EXTERNAL FUNCTION PROTOTYPES ================= |
|
41 |
|
42 // ========== CONSTANTS ==================================== |
|
43 |
|
44 // ========== MACROS ======================================= |
|
45 |
|
46 // ========== LOCAL CONSTANTS AND MACROS =================== |
|
47 |
|
48 // ========== MODULE DATA STRUCTURES ======================= |
|
49 |
|
50 // ========== LOCAL FUNCTION PROTOTYPES ==================== |
|
51 |
|
52 // ========== LOCAL FUNCTIONS ============================== |
|
53 |
|
54 // ========== MEMBER FUNCTIONS ============================= |
|
55 |
|
56 // --------------------------------------------------------- |
|
57 // CMsgHeader::CMsgHeader |
|
58 // |
|
59 // Constructor. |
|
60 // --------------------------------------------------------- |
|
61 // |
|
62 CMsgHeader::CMsgHeader( const TMargins& aMargins ) |
|
63 : CMsgFormComponent( aMargins ) |
|
64 { |
|
65 } |
|
66 |
|
67 // --------------------------------------------------------- |
|
68 // CMsgHeader::~CMsgHeader |
|
69 // |
|
70 // Destructor. |
|
71 // --------------------------------------------------------- |
|
72 // |
|
73 CMsgHeader::~CMsgHeader() |
|
74 { |
|
75 AknsUtils::DeregisterControlPosition( iFrame ); |
|
76 delete iFrame; |
|
77 delete iHeaderCleaner; |
|
78 AknsUtils::DeregisterControlPosition( this ); |
|
79 } |
|
80 |
|
81 // --------------------------------------------------------- |
|
82 // CMsgHeader::NewL |
|
83 // |
|
84 // Factory method that creates this control. |
|
85 // --------------------------------------------------------- |
|
86 // |
|
87 CMsgHeader* CMsgHeader::NewL( const CCoeControl& aParent, const TMargins& aMargins ) |
|
88 { |
|
89 CMsgHeader* self = new ( ELeave ) CMsgHeader( aMargins ); |
|
90 |
|
91 CleanupStack::PushL( self ); |
|
92 self->ConstructL( aParent ); |
|
93 CleanupStack::Pop(); |
|
94 |
|
95 return self; |
|
96 } |
|
97 |
|
98 // --------------------------------------------------------- |
|
99 // CMsgHeader::ConstructL |
|
100 // |
|
101 // 2nd phase constructor. |
|
102 // --------------------------------------------------------- |
|
103 // |
|
104 void CMsgHeader::ConstructL( const CCoeControl& aParent ) |
|
105 { |
|
106 CMsgFormComponent::BaseConstructL( aParent ); |
|
107 |
|
108 iFrame = CMsgCaptionedHighlight::NewL( *this ); |
|
109 |
|
110 iHeaderCleaner = new (ELeave) CMsgDummyHeaderCleaner(this); |
|
111 iHeaderCleaner->ConstructL(); |
|
112 |
|
113 #ifdef RD_SCALABLE_UI_V2 |
|
114 User::LeaveIfError( iFrame->SetHitTest( this ) ); |
|
115 User::LeaveIfError( iHeaderCleaner->SetHitTest( this ) ); |
|
116 #endif // RD_SCALABLE_UI_V2 |
|
117 } |
|
118 |
|
119 // --------------------------------------------------------- |
|
120 // CMsgHeader::SetAndGetSizeL |
|
121 // |
|
122 // Calculates and sets the size for the header and returns new size as reference |
|
123 // aSize. If aInit == ETrue, sets also size for the controls by calling their |
|
124 // SetAndGetSizeL functions. |
|
125 // --------------------------------------------------------- |
|
126 // |
|
127 void CMsgHeader::SetAndGetSizeL( TSize& aSize, TBool aInit ) |
|
128 { |
|
129 aSize = MsgEditorCommons::MsgHeaderPane().Size(); |
|
130 |
|
131 TInt numberOfControls( iControls->Count() ); |
|
132 iMargins.iTop = 0; |
|
133 iMargins.iBottom = numberOfControls ? MsgEditorCommons::MsgBaseLineDelta() : |
|
134 0; |
|
135 |
|
136 TInt marginsDeltaHeight = iMargins.iTop + iMargins.iBottom; |
|
137 TInt marginsDeltaWidth = iMargins.iLeft + iMargins.iRight; |
|
138 TSize headerSize( aSize.iWidth, marginsDeltaHeight ); |
|
139 TSize controlSize( 0, 0 ); |
|
140 |
|
141 controlSize.iWidth = aSize.iWidth - marginsDeltaWidth; |
|
142 CMsgBaseControl* control = NULL; |
|
143 TInt minimumHeigth = marginsDeltaHeight; |
|
144 |
|
145 for ( TInt cc = 0; cc < numberOfControls; cc++ ) |
|
146 { |
|
147 controlSize.iHeight = aSize.iHeight; |
|
148 control = (*iControls)[cc]; |
|
149 |
|
150 if ( aInit ) |
|
151 { |
|
152 control->SetAndGetSizeL( controlSize ); |
|
153 } |
|
154 else |
|
155 { |
|
156 controlSize = control->Size(); |
|
157 } |
|
158 |
|
159 headerSize.iHeight += control->DistanceFromComponentAbove() + controlSize.iHeight /* + 1 */; |
|
160 minimumHeigth += control->DistanceFromComponentAbove() + control->MinimumSize().iHeight /* + 1 */; |
|
161 |
|
162 //MEBLOGGER_WRITEF(_L("MEB: CMsgHeader::SetAndGetSizeL: headerSize.iHeight %d "), headerSize.iHeight); |
|
163 } |
|
164 |
|
165 if ( minimumHeigth < marginsDeltaHeight ) |
|
166 // make top margin higher if there is no space for the icon |
|
167 { |
|
168 TInt additionalTopMargin = marginsDeltaHeight - minimumHeigth; |
|
169 headerSize.iHeight += additionalTopMargin; |
|
170 iMargins.iTop += additionalTopMargin; |
|
171 } |
|
172 |
|
173 SetSizeWithoutNotification( headerSize ); |
|
174 aSize = headerSize; |
|
175 } |
|
176 |
|
177 // --------------------------------------------------------- |
|
178 // CMsgHeader::CountComponentControls |
|
179 // |
|
180 // Returns a number of controls. |
|
181 // --------------------------------------------------------- |
|
182 // |
|
183 TInt CMsgHeader::CountComponentControls() const |
|
184 { |
|
185 // Component controls + iFrame + iHeaderCleaner |
|
186 return ( CMsgFormComponent::CountComponentControls() + 1 + 1); |
|
187 } |
|
188 |
|
189 // --------------------------------------------------------- |
|
190 // CMsgHeader::ComponentControl |
|
191 // |
|
192 // Returns a control of index aIndex. |
|
193 // --------------------------------------------------------- |
|
194 // |
|
195 CCoeControl* CMsgHeader::ComponentControl( TInt aIndex ) const |
|
196 { |
|
197 // The order of component is important as now the frame gets drawn |
|
198 // before the editor edwins. In the end iHeaderCleaner |
|
199 // cleans the top of the display |
|
200 TInt compCount = CMsgFormComponent::CountComponentControls(); |
|
201 // Component controls + iFrame |
|
202 __ASSERT_DEBUG( aIndex < compCount + 1 + 1, |
|
203 Panic( EMsgIncorrectComponentIndex ) ); |
|
204 |
|
205 if ( aIndex == 0 ) |
|
206 { |
|
207 return iFrame; |
|
208 } |
|
209 |
|
210 if ( aIndex <= compCount ) |
|
211 { |
|
212 return CMsgFormComponent::ComponentControl( aIndex-1 ); |
|
213 } |
|
214 |
|
215 if ( aIndex == compCount +1 ) |
|
216 { |
|
217 return iHeaderCleaner; |
|
218 } |
|
219 |
|
220 return NULL; |
|
221 } |
|
222 |
|
223 // --------------------------------------------------------- |
|
224 // CMsgHeader::HitRegionContains |
|
225 // |
|
226 // Note! CONE will do final verification if control is really hit so |
|
227 // not need to do it here. |
|
228 // --------------------------------------------------------- |
|
229 // |
|
230 TBool CMsgHeader::HitRegionContains( const TPoint& /*aPoint*/, |
|
231 const CCoeControl& /*aControl*/ ) const |
|
232 { |
|
233 return EFalse; |
|
234 } |
|
235 |
|
236 // --------------------------------------------------------- |
|
237 // CMsgHeader::SizeChanged |
|
238 // |
|
239 // Sets new position for all the controls. |
|
240 // --------------------------------------------------------- |
|
241 // |
|
242 void CMsgHeader::SizeChanged() |
|
243 { |
|
244 MEBLOGGER_ENTERFN( "CMsgHeader::SizeChanged" ); |
|
245 |
|
246 CMsgFormComponent::SizeChanged(); |
|
247 TRect rect = Rect( ); |
|
248 iFrame->SetRect( rect ); |
|
249 iHeaderCleaner->SetRect( rect ); |
|
250 AknsUtils::RegisterControlPosition( iFrame ); |
|
251 AknsUtils::RegisterControlPosition( this ); |
|
252 |
|
253 // Resize also the frame control around the focused editor |
|
254 CMsgBaseControl* ctrl = FocusedControl(); |
|
255 if( ctrl ) |
|
256 { |
|
257 switch( ctrl->ControlType( ) ) |
|
258 { // HandleFrameSizeChange should be called only for expandable and address controls |
|
259 case EMsgExpandableControl: |
|
260 case EMsgAddressControl: |
|
261 case EMsgAttachmentControl: |
|
262 { |
|
263 (static_cast<CMsgExpandableControl*>(ctrl))->HandleFrameSizeChange( ); |
|
264 break; |
|
265 } |
|
266 default: // don't call it for example for body control as there's no frame |
|
267 break; |
|
268 } |
|
269 } |
|
270 |
|
271 MEBLOGGER_LEAVEFN( "CMsgHeader::SizeChanged" ); |
|
272 } |
|
273 |
|
274 // --------------------------------------------------------- |
|
275 // CMsgFormComponent::FocusChanged |
|
276 // |
|
277 // Sets focus off or on if this form component lost focus or gets focused. |
|
278 // --------------------------------------------------------- |
|
279 // |
|
280 void CMsgHeader::FocusChanged( TDrawNow /*aDrawNow*/ ) |
|
281 { |
|
282 CMsgFormComponent::FocusChanged( ENoDrawNow ); |
|
283 DrawNow(); |
|
284 } |
|
285 |
|
286 |
|
287 // --------------------------------------------------------- |
|
288 // CMsgHeader::Draw |
|
289 // |
|
290 // Draws the header. |
|
291 // --------------------------------------------------------- |
|
292 // |
|
293 void CMsgHeader::Draw( const TRect& /*aRect*/ ) const |
|
294 { |
|
295 CWindowGc& gc = SystemGc(); |
|
296 TRect rect( Rect() ); |
|
297 |
|
298 if ( !AknsDrawUtils::Background( AknsUtils::SkinInstance(), |
|
299 AknsDrawUtils::ControlContext( this ), |
|
300 this, |
|
301 gc, |
|
302 rect ) ) |
|
303 { |
|
304 gc.SetBrushColor( AKN_LAF_COLOR( 0 ) ); |
|
305 gc.SetBrushStyle( CGraphicsContext::ESolidBrush ); |
|
306 gc.SetPenStyle( CGraphicsContext::ENullPen ); |
|
307 gc.DrawRect( rect ); |
|
308 } |
|
309 } |
|
310 |
|
311 // End of File |