|
1 /* |
|
2 * Copyright (c) 2005-2007 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: Phonebook 2 thumbnail popup control. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "CPbk2ThumbnailPopupControl.h" |
|
21 |
|
22 // System includes |
|
23 #include <eiklbx.h> |
|
24 #include <aknlayoutscalable_apps.cdl.h> |
|
25 #include <aknlayoutscalable_avkon.cdl.h> |
|
26 #include <layoutmetadata.cdl.h> |
|
27 #include <AknsDrawUtils.h> |
|
28 #include <AknsBasicBackgroundControlContext.h> |
|
29 #include <eikenv.h> |
|
30 #include <eikappui.h> |
|
31 #include <AknUtils.h> |
|
32 |
|
33 |
|
34 // Debugging headers |
|
35 #include <Pbk2Debug.h> |
|
36 |
|
37 // -------------------------------------------------------------------------- |
|
38 // |
|
39 // -------------------------------------------------------------------------- |
|
40 // |
|
41 CPbk2ThumbnailPopupControl::CPbk2ThumbnailPopupControl( TPbk2ThumbnailLocation aThumbnailLocation, |
|
42 const CEikListBox* aListBox ) |
|
43 : iThumbnailLocation( aThumbnailLocation ), |
|
44 iListBox( aListBox ) |
|
45 { |
|
46 } |
|
47 |
|
48 // -------------------------------------------------------------------------- |
|
49 // |
|
50 // -------------------------------------------------------------------------- |
|
51 // |
|
52 CPbk2ThumbnailPopupControl::~CPbk2ThumbnailPopupControl() |
|
53 { |
|
54 AknsUtils::DeregisterControlPosition( this ); |
|
55 CEikonEnv::Static()->EikAppUi()->RemoveFromStack( this ); |
|
56 delete iBitmap; |
|
57 delete iBgContext; |
|
58 } |
|
59 |
|
60 // -------------------------------------------------------------------------- |
|
61 // |
|
62 // -------------------------------------------------------------------------- |
|
63 // |
|
64 CPbk2ThumbnailPopupControl* CPbk2ThumbnailPopupControl::NewL( |
|
65 TPbk2ThumbnailLocation aThumbnailLocation, |
|
66 const CEikListBox* aListBox ) |
|
67 { |
|
68 CPbk2ThumbnailPopupControl* self = |
|
69 new( ELeave )CPbk2ThumbnailPopupControl( aThumbnailLocation, aListBox ); |
|
70 CleanupStack::PushL( self ); |
|
71 self->ConstructL(); |
|
72 CleanupStack::Pop( self ); |
|
73 return self; |
|
74 } |
|
75 |
|
76 // -------------------------------------------------------------------------- |
|
77 // |
|
78 // -------------------------------------------------------------------------- |
|
79 // |
|
80 void CPbk2ThumbnailPopupControl::ConstructL() |
|
81 { |
|
82 SetupSkinContext(); // we need to be able to clear the background using skin |
|
83 |
|
84 CreateWindowL( iListBox ); |
|
85 |
|
86 MakeVisible( EFalse ); |
|
87 SetFocusing( EFalse ); |
|
88 SetPointerCapture( EFalse ); |
|
89 |
|
90 // add to stack to get resource change notifications, |
|
91 // we must refuse focus and all input to prevent breaking the UI below |
|
92 CEikonEnv::Static()->EikAppUi()->AddToStackL( |
|
93 this, |
|
94 ECoeStackPriorityDefault, |
|
95 ECoeStackFlagRefusesAllKeys|ECoeStackFlagRefusesFocus ); |
|
96 } |
|
97 |
|
98 // -------------------------------------------------------------------------- |
|
99 // |
|
100 // -------------------------------------------------------------------------- |
|
101 // |
|
102 void CPbk2ThumbnailPopupControl::SetBitmap(CFbsBitmap* aBitmap) |
|
103 { |
|
104 if( aBitmap != iBitmap ) |
|
105 { |
|
106 delete iBitmap; |
|
107 iBitmap = aBitmap; |
|
108 } |
|
109 } |
|
110 |
|
111 // -------------------------------------------------------------------------- |
|
112 // |
|
113 // -------------------------------------------------------------------------- |
|
114 // |
|
115 void CPbk2ThumbnailPopupControl::SetThumbnailBackg( CFbsBitmap* aThumbBackg, |
|
116 CFbsBitmap* aThumbBackgMask ) |
|
117 { |
|
118 iThumbSize=aThumbBackg->SizeInPixels(); |
|
119 iThumbBackg = aThumbBackg; |
|
120 iThumbBackgMask = aThumbBackgMask; |
|
121 } |
|
122 |
|
123 // -------------------------------------------------------------------------- |
|
124 // |
|
125 // -------------------------------------------------------------------------- |
|
126 // |
|
127 void CPbk2ThumbnailPopupControl::MakeControlVisible(TBool aVisible) |
|
128 { |
|
129 // hide the thumbnail if the highlighted listbox item isn't visible anymore |
|
130 // (in ELocationUpDown mode the thumbnail is always visible) |
|
131 if( iThumbnailLocation == ELocationHanging && |
|
132 !iListBox->View()->ItemIsVisible( iListBox->CurrentItemIndex() ) ) |
|
133 { |
|
134 aVisible = EFalse; |
|
135 } |
|
136 |
|
137 if( aVisible ) |
|
138 { |
|
139 Layout(); |
|
140 ActivateL(); |
|
141 } |
|
142 MakeVisible( aVisible ); |
|
143 DrawDeferred(); // won't draw if invisible (or inactive) |
|
144 } |
|
145 |
|
146 // -------------------------------------------------------------------------- |
|
147 // |
|
148 // -------------------------------------------------------------------------- |
|
149 // |
|
150 void CPbk2ThumbnailPopupControl::Draw( const TRect& /*aRect*/ ) const |
|
151 { |
|
152 CWindowGc& gc = SystemGc(); |
|
153 if ( iBitmap ) |
|
154 { |
|
155 const TInt orientation( Layout_Meta_Data::IsLandscapeOrientation() ? 0 : 1 ); |
|
156 TAknLayoutRect thumbBgLayoutRect, thumbLayoutRect; |
|
157 thumbBgLayoutRect.LayoutRect( |
|
158 Rect(), |
|
159 AknLayoutScalable_Apps::bg_popup_preview_window_pane_cp01( orientation ) ); |
|
160 thumbLayoutRect.LayoutRect( |
|
161 Rect(), |
|
162 AknLayoutScalable_Apps::popup_phob_thumbnail2_window_g1( orientation ) ); |
|
163 |
|
164 AknsDrawUtils::BackgroundBetweenRects( AknsUtils::SkinInstance(), iBgContext, this, gc, Rect(), thumbLayoutRect.Rect() ); |
|
165 |
|
166 thumbBgLayoutRect.DrawImage( gc, iThumbBackg, iThumbBackgMask ); |
|
167 thumbLayoutRect.DrawImage( gc, iBitmap, NULL ); |
|
168 |
|
169 } |
|
170 else |
|
171 { |
|
172 AknsDrawUtils::Background( AknsUtils::SkinInstance(), iBgContext, this, gc, Rect() ); |
|
173 } |
|
174 } |
|
175 |
|
176 // -------------------------------------------------------------------------- |
|
177 // |
|
178 // -------------------------------------------------------------------------- |
|
179 // |
|
180 inline void CPbk2ThumbnailPopupControl::Layout() |
|
181 { |
|
182 // calculate indentation (0.5u) in pixels (aid_value_unit2 is a 10ux10u rectangle) |
|
183 TAknWindowComponentLayout unit( AknLayoutScalable_Avkon::aid_value_unit2() ); |
|
184 const TInt indent( unit.LayoutLine().iW / 10 / 2 ); // 0.5u |
|
185 |
|
186 // background bitmap was already sized according to the thumbnail size and LAF specification |
|
187 // -> set window size to match the size of the bg bitmap |
|
188 TSize thumbWindowSize; |
|
189 if (iThumbBackg) |
|
190 { |
|
191 thumbWindowSize= iThumbSize; |
|
192 } |
|
193 |
|
194 |
|
195 // calculate the thumbnail window X co-ordinate using listbox layout |
|
196 TAknLayoutRect listPaneLayoutRect; // for horizontal positioning |
|
197 listPaneLayoutRect.LayoutRect( iListBox->View()->ViewRect(), AknLayoutScalable_Avkon::list_gen_pane( 0 ) ); |
|
198 |
|
199 // window position: |
|
200 // normal - right side of the listbox -(thubnail window idth + indent) |
|
201 // mirrored - left side of the listbox + indent |
|
202 TPoint thumbWindowPt( Layout_Meta_Data::IsMirrored() ? |
|
203 listPaneLayoutRect.Rect().iTl.iX + indent : |
|
204 listPaneLayoutRect.Rect().iBr.iX - (indent + thumbWindowSize.iWidth), |
|
205 0 ); |
|
206 |
|
207 // thumbnail Y co-ordinate depends on the listbox focus position |
|
208 const TPoint focusPt( iListBox->View()->ItemPos( iListBox->CurrentItemIndex() ) ); |
|
209 const TInt yMax( iListBox->View()->ViewRect().iBr.iY ); |
|
210 |
|
211 if ( iThumbnailLocation == ELocationHanging ) |
|
212 // thumbnail moves with the focus |
|
213 { |
|
214 // bottom Y of the focused listbox item |
|
215 const TInt focusBottom( focusPt.iY + iListBox->ItemHeight() ); |
|
216 |
|
217 // place the thumbnail below the focus if there is enough space |
|
218 if ( yMax - focusBottom >= thumbWindowSize.iHeight + indent ) |
|
219 { |
|
220 thumbWindowPt.iY = focusBottom - iListBox->ItemHeight()/5; |
|
221 } |
|
222 else // otherwise place it above the focus |
|
223 { |
|
224 thumbWindowPt.iY = focusPt.iY + iListBox->ItemHeight()/4 - thumbWindowSize.iHeight; |
|
225 } |
|
226 } |
|
227 else if ( iThumbnailLocation == ELocationUpDown ) |
|
228 // thumbnail is placed at the top or bottom corner |
|
229 { |
|
230 thumbWindowPt.iY = indent; // default to top |
|
231 |
|
232 // thumbnail is always at the top if focus is not visible |
|
233 if( iListBox->View()->ItemIsVisible( iListBox->CurrentItemIndex() ) ) |
|
234 { |
|
235 const TRect focusRect( focusPt, iListBox->View()->ItemSize() ); |
|
236 const TRect thumbWindowRect( thumbWindowPt, thumbWindowSize ); |
|
237 |
|
238 // place the thumbnail at the bottom if it overlaps the focus |
|
239 if( thumbWindowRect.Intersects( focusRect ) ) |
|
240 { |
|
241 thumbWindowPt.iY = yMax - (indent + thumbWindowSize.iHeight); |
|
242 } |
|
243 } |
|
244 } |
|
245 |
|
246 SetExtent( thumbWindowPt, thumbWindowSize ); |
|
247 AknsUtils::RegisterControlPosition( this ); |
|
248 } |
|
249 |
|
250 // -------------------------------------------------------------------------- |
|
251 // |
|
252 // -------------------------------------------------------------------------- |
|
253 // |
|
254 void CPbk2ThumbnailPopupControl::HandleResourceChange(TInt aType) |
|
255 { |
|
256 CCoeControl::HandleResourceChange( aType ); |
|
257 |
|
258 if( aType == KEikDynamicLayoutVariantSwitch || |
|
259 aType == KAknsMessageSkinChange ) |
|
260 { |
|
261 SetupSkinContext(); |
|
262 // This control may be invalid when it's invisible |
|
263 // e.g. iThumbBackg,iThumbBackgMaksk may be destroyed |
|
264 if ( IsVisible() ) |
|
265 { |
|
266 Layout(); |
|
267 } |
|
268 } |
|
269 } |
|
270 |
|
271 // --------------------------------------------------------- |
|
272 // |
|
273 // --------------------------------------------------------- |
|
274 // |
|
275 void CPbk2ThumbnailPopupControl::SetupSkinContext() |
|
276 { |
|
277 delete iBgContext; |
|
278 iBgContext = NULL; |
|
279 iBgContext = CAknsBasicBackgroundControlContext::NewL( KAknsIIDQsnBgAreaMain, iListBox->Rect(), ETrue ); |
|
280 iBgContext->SetParentPos( iListBox->PositionRelativeToScreen() ); |
|
281 } |
|
282 |
|
283 |
|
284 // End of File |