|
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: |
|
15 * Provides methods for Control for thumbnail popup window. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CPbkThumbnailPopupControl.h" |
|
22 #include <PbkView.rsg> |
|
23 #include <barsread.h> // TResourceReader |
|
24 #include <coemain.h> // CCoeEnv |
|
25 #include <eikenv.h> // CCoeMain |
|
26 #include <aknappui.h> |
|
27 #include <PbkDebug.h> |
|
28 |
|
29 #include <aknlayout.cdl.h> |
|
30 #include <applayout.cdl.h> |
|
31 #include <aknlayoutscalable_apps.cdl.h> |
|
32 |
|
33 // Unnamed namespace for local definitions |
|
34 namespace { |
|
35 |
|
36 // LOCAL CONSTANTS AND MACROS |
|
37 inline TRect RectFromCoords(const TRect& aParent, TAknWindowLineLayout& aLayout) |
|
38 { |
|
39 TAknLayoutRect layoutRect; |
|
40 layoutRect.LayoutRect(aParent, aLayout); |
|
41 return layoutRect.Rect(); |
|
42 } |
|
43 |
|
44 } // namespace |
|
45 |
|
46 |
|
47 // ================= MEMBER FUNCTIONS ======================= |
|
48 |
|
49 CPbkThumbnailPopupControl* CPbkThumbnailPopupControl::NewL() |
|
50 { |
|
51 CPbkThumbnailPopupControl* self = new (ELeave) CPbkThumbnailPopupControl(); |
|
52 CleanupStack::PushL(self); |
|
53 self->ConstructL(); |
|
54 CleanupStack::Pop(); |
|
55 return self; |
|
56 } |
|
57 |
|
58 CPbkThumbnailPopupControl::~CPbkThumbnailPopupControl() |
|
59 { |
|
60 delete iBitmap; |
|
61 } |
|
62 |
|
63 void CPbkThumbnailPopupControl::ChangeBitmap( |
|
64 CFbsBitmap* aBitmap, |
|
65 CEikListBox* /*aListBox*/) |
|
66 { |
|
67 |
|
68 if ( !aBitmap ) |
|
69 { |
|
70 return; |
|
71 } |
|
72 |
|
73 if(aBitmap != iBitmap && aBitmap != NULL ) |
|
74 { |
|
75 delete iBitmap; |
|
76 iBitmap = aBitmap; |
|
77 } |
|
78 |
|
79 |
|
80 if (iBitmap) |
|
81 { |
|
82 PBK_DEBUG_PRINT(PBK_DEBUG_STRING("Thumbnail size(W:%d H:%d)"), |
|
83 iBitmap->SizeInPixels().iWidth, |
|
84 iBitmap->SizeInPixels().iHeight); |
|
85 |
|
86 TRect appRect = iAvkonAppUi->ApplicationRect(); |
|
87 TAknLayoutRect statusPaneRect; |
|
88 statusPaneRect.LayoutRect(appRect, AknLayout::status_pane(appRect, 0)); |
|
89 |
|
90 TSize bitmapSize = iBitmap->SizeInPixels(); |
|
91 |
|
92 /// bitmap blit position |
|
93 TPoint controlPoint; |
|
94 |
|
95 // bitmap |
|
96 TAknWindowComponentLayout componentThumbnail = |
|
97 AknLayoutScalable_Apps::popup_phob_thumbnail_window_g1(); |
|
98 |
|
99 // center of bitmap |
|
100 TAknWindowComponentLayout componentThumbnailCenter = |
|
101 AknLayoutScalable_Apps::aid_phob_thumbnail_center_pane(); |
|
102 |
|
103 TAknWindowLineLayout lineThumbnail = componentThumbnail.LayoutLine(); |
|
104 TAknLayoutRect aknRectThumbnail; |
|
105 aknRectThumbnail.LayoutRect( TRect(), componentThumbnail ); |
|
106 |
|
107 TAknWindowLineLayout lineThumbnailCenter = componentThumbnailCenter.LayoutLine(); |
|
108 TAknLayoutRect aknRectThumbnailCenter; |
|
109 aknRectThumbnailCenter.LayoutRect( TRect(), componentThumbnailCenter ); |
|
110 |
|
111 // Calculate Y position |
|
112 const TInt imageMaxHeight( aknRectThumbnail.Rect().Height() ); |
|
113 if ( bitmapSize.iHeight/2 < aknRectThumbnailCenter.Rect().Height() ) |
|
114 { |
|
115 controlPoint.iY = aknRectThumbnailCenter.Rect().Height() - bitmapSize.iHeight/2; |
|
116 iControlSize.iHeight = bitmapSize.iHeight; |
|
117 } |
|
118 else |
|
119 { |
|
120 iCrop.iY = (bitmapSize.iHeight - imageMaxHeight )/2; |
|
121 controlPoint.iY = 1; |
|
122 iControlSize.iHeight = imageMaxHeight; |
|
123 } |
|
124 |
|
125 // calculate the X position of the bitmap |
|
126 const TInt imageMaxWidth( aknRectThumbnail.Rect().Width() ); |
|
127 controlPoint.iX = aknRectThumbnailCenter.Rect().Width() - bitmapSize.iWidth/2; |
|
128 if (controlPoint.iX <= 0) |
|
129 { |
|
130 controlPoint.iX = 0; |
|
131 iCrop.iX = (bitmapSize.iWidth - imageMaxWidth)/2; |
|
132 iControlSize.iWidth = imageMaxWidth; |
|
133 } |
|
134 else |
|
135 { |
|
136 iCrop.iX = 0; |
|
137 iControlSize.iWidth = bitmapSize.iWidth; |
|
138 } |
|
139 |
|
140 // x-coordinates of aknRectThumbnail's rect is calculated wrong in |
|
141 // Arab&Hebrew case. If Arab/Hebrew layout is used, update only |
|
142 // y-coordinate to control point. |
|
143 if (aknRectThumbnail.Rect().iTl.iX > 0) |
|
144 { |
|
145 controlPoint += aknRectThumbnail.Rect().iTl; |
|
146 } |
|
147 else |
|
148 { |
|
149 controlPoint.iY += aknRectThumbnail.Rect().iTl.iY; |
|
150 } |
|
151 |
|
152 // calculate the actual bitmap position according to LAF |
|
153 TAknWindowLineLayout popupLayout = AppLayout::popup_pbook_thumbnail_window(); |
|
154 TRect popupWindowRect = RectFromCoords(statusPaneRect.Rect(), popupLayout); |
|
155 controlPoint += popupWindowRect.iTl; |
|
156 |
|
157 |
|
158 // Shadow size |
|
159 TAknWindowComponentLayout componentThumbnailShadow = |
|
160 AknLayoutScalable_Apps::popup_phob_thumbnail_window_g2(); |
|
161 TAknWindowLineLayout lineThumbnailShadow = componentThumbnailShadow.LayoutLine(); |
|
162 TAknLayoutRect aknRectThumbnailShadow; |
|
163 aknRectThumbnailShadow.LayoutRect( TRect(), componentThumbnailShadow ); |
|
164 |
|
165 iShadowWidth = aknRectThumbnailShadow.Rect().iTl.iX - aknRectThumbnail.Rect().iTl.iX ; |
|
166 if ( iShadowWidth < 0 ) |
|
167 { |
|
168 iShadowWidth = aknRectThumbnail.Rect().iTl.iX - aknRectThumbnailShadow.Rect().iTl.iX; |
|
169 } |
|
170 iShadowHeight = aknRectThumbnailShadow.Rect().iTl.iY - aknRectThumbnail.Rect().iTl.iY; |
|
171 if ( iShadowHeight < 0 ) |
|
172 { |
|
173 iShadowHeight = aknRectThumbnail.Rect().iTl.iY - aknRectThumbnailShadow.Rect().iTl.iY; |
|
174 } |
|
175 |
|
176 // increment shadow size |
|
177 iControlSize.iWidth += iShadowWidth; |
|
178 iControlSize.iHeight += iShadowHeight; |
|
179 |
|
180 // set the control size |
|
181 SetExtent(controlPoint, iControlSize); |
|
182 } |
|
183 |
|
184 DrawNow(); |
|
185 } |
|
186 |
|
187 void CPbkThumbnailPopupControl::Draw |
|
188 (const TRect& /*aRect*/) const |
|
189 { |
|
190 CWindowGc& gc = SystemGc(); |
|
191 |
|
192 if (iBitmap) |
|
193 { |
|
194 // draw the bitmap |
|
195 PBK_DEBUG_PRINT(PBK_DEBUG_STRING("Thumbnail draw (Left:%d Top:%d Right:%d Bottom:%d)"), |
|
196 Position().iX, |
|
197 Position().iY, |
|
198 Position().iX + iBitmap->SizeInPixels().iWidth, |
|
199 Position().iY + iBitmap->SizeInPixels().iHeight); |
|
200 |
|
201 gc.BitBltMasked( TPoint(iShadowWidth, iShadowHeight), |
|
202 iThumbBackg, |
|
203 TRect(0,0,iThumbBackg->SizeInPixels().iWidth, iThumbBackg->SizeInPixels().iHeight ), |
|
204 iThumbBackgMask, |
|
205 EFalse); |
|
206 gc.BitBlt(TPoint(), iBitmap); |
|
207 } |
|
208 } |
|
209 |
|
210 CPbkThumbnailPopupControl::CPbkThumbnailPopupControl() |
|
211 { |
|
212 } |
|
213 |
|
214 void CPbkThumbnailPopupControl::ConstructL() |
|
215 { |
|
216 CreateWindowL(); |
|
217 MakeVisible(EFalse); |
|
218 SetExtent(TPoint(0,0),TSize(0,0)); |
|
219 ActivateL(); |
|
220 } |
|
221 |
|
222 void CPbkThumbnailPopupControl::SetThumbnailBackg( CFbsBitmap* aThumbBackg, CFbsBitmap* aThumbBackgMask ) |
|
223 { |
|
224 iThumbBackg = aThumbBackg; |
|
225 iThumbBackgMask = aThumbBackgMask; |
|
226 } |
|
227 |
|
228 void CPbkThumbnailPopupControl::MakeControlVisible( TBool aVisible ) |
|
229 { |
|
230 // make control visible |
|
231 MakeVisible(aVisible); |
|
232 // MakeVisible does not seem to make sure the control is redrawn |
|
233 DrawDeferred(); |
|
234 } |
|
235 |
|
236 |
|
237 // End of File |