|
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 the License "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 * View images popup box |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 #include "ImageMapPopup.h" |
|
22 |
|
23 #include <e32math.h> |
|
24 #include <apmstd.h> |
|
25 #include <bitdev.h> |
|
26 #include <gulicon.h> |
|
27 #include <akniconarray.h> |
|
28 |
|
29 #include <avkon.mbg> |
|
30 #include <avkon.rsg> |
|
31 |
|
32 // EXTERNAL DATA STRUCTURES |
|
33 |
|
34 // EXTERNAL FUNCTION PROTOTYPES |
|
35 |
|
36 // CONSTANTS |
|
37 const TInt KImageMapBitmapMaxWidth = 43; |
|
38 const TInt KImageMapBitmapMaxHeight = 32; |
|
39 const TInt KImageMapPopupWidth = 176; |
|
40 const TInt KImageMapPopupHeight = 144; |
|
41 const TInt KImageMapPopupWidth2 = 20; |
|
42 const TInt KImageMapMaxAreaNum = 6; |
|
43 _LIT( KImageMapAltTextTab, "\t" ); |
|
44 // MACROS |
|
45 |
|
46 // LOCAL CONSTANTS AND MACROS |
|
47 |
|
48 // MODULE DATA STRUCTURES |
|
49 |
|
50 // LOCAL FUNCTION PROTOTYPES |
|
51 |
|
52 // FORWARD DECLARATIONS |
|
53 |
|
54 // ============================= LOCAL FUNCTIONS =============================== |
|
55 |
|
56 |
|
57 // ============================ MEMBER FUNCTIONS =============================== |
|
58 |
|
59 // ----------------------------------------------------------------------------- |
|
60 // CImageMapListBox::CImageMapListBox |
|
61 // C++ default constructor can NOT contain any code, that |
|
62 // might leave. |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 CImageMapListBox::CImageMapListBox() : CAknDoubleLargeGraphicPopupMenuStyleListBox() |
|
66 { |
|
67 } |
|
68 |
|
69 // ----------------------------------------------------------------------------- |
|
70 // CImageMapListBox::~CImageMapListBox |
|
71 // destructor. |
|
72 // ----------------------------------------------------------------------------- |
|
73 // |
|
74 CImageMapListBox::~CImageMapListBox() |
|
75 { |
|
76 } |
|
77 |
|
78 // ----------------------------------------------------------------------------- |
|
79 // CImageMapListBox::ConstructL |
|
80 // Symbian 2nd phase constructor can leave. |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 void CImageMapListBox::ConstructL( CCoeControl& aParent, CArrayPtrFlat<CFbsBitmap>& aBitmapList, |
|
84 CArrayPtrFlat<HBufC>& aAltTextList ) |
|
85 { |
|
86 // call base class |
|
87 CAknDoubleLargeGraphicPopupMenuStyleListBox::ConstructL( &aParent, 0 ); |
|
88 // create icon array which shows up in the left column |
|
89 CArrayPtrFlat<CGulIcon>* iconList = new( ELeave) CAknIconArray( 5 ); |
|
90 CleanupStack::PushL( iconList ); |
|
91 |
|
92 CDesCArray* itemList = STATIC_CAST( CDesCArray*, Model()->ItemTextArray() ); |
|
93 |
|
94 // create icons out of bitmaps |
|
95 HBufC* tempBuf; |
|
96 TSize bitmapSize; |
|
97 CGulIcon* icon; |
|
98 CFbsBitmap* bitmap; |
|
99 |
|
100 TInt bitmapCount( aBitmapList.Count() ); |
|
101 for( TInt i = 0; i < bitmapCount; i++ ) |
|
102 { |
|
103 // create icons |
|
104 bitmap = aBitmapList.At( i ); |
|
105 bitmapSize = bitmap->SizeInPixels(); |
|
106 // check if the bitmap needs to be squeezed |
|
107 if( bitmapSize.iWidth > KImageMapBitmapMaxWidth || bitmapSize.iHeight > KImageMapBitmapMaxHeight ) |
|
108 { |
|
109 CFbsBitmap* modifiedBitmap = new( ELeave )CFbsBitmap(); |
|
110 CleanupStack::PushL( modifiedBitmap ); |
|
111 |
|
112 User::LeaveIfError( modifiedBitmap->Create( TSize( KImageMapBitmapMaxWidth, KImageMapBitmapMaxHeight ), EColor4K ) ); |
|
113 // create bitmap device |
|
114 CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL( modifiedBitmap ); |
|
115 CleanupStack::PushL( bitmapDevice ); |
|
116 |
|
117 // create graphics context for bitmap device |
|
118 CGraphicsContext* bitmapContext; |
|
119 User::LeaveIfError( bitmapDevice->CreateContext( bitmapContext ) ); |
|
120 CleanupStack::PushL( bitmapContext ); |
|
121 |
|
122 // squeze it |
|
123 TSize targetSize = Fit( bitmapSize, modifiedBitmap->SizeInPixels() ); |
|
124 |
|
125 // copy bitmap to modified bitmap |
|
126 bitmapContext->DrawBitmap( TRect( TPoint( 0,0 ), targetSize ), bitmap, TRect( TPoint( 0,0 ), bitmapSize ) ); |
|
127 |
|
128 CleanupStack::PopAndDestroy( 2 ); // bitmapContext, bitmapDevice |
|
129 |
|
130 // replace bitmap in the array |
|
131 delete bitmap; |
|
132 aBitmapList.At( i ) = modifiedBitmap; |
|
133 // bitmap array takes ownership |
|
134 CleanupStack::Pop(); // modifiedBitmap |
|
135 |
|
136 bitmap = modifiedBitmap; |
|
137 } |
|
138 // create icon. CGulIcon takes bitmap ownership |
|
139 icon = CGulIcon::NewL( bitmap, bitmap ); |
|
140 // remove bitmap array ownership |
|
141 aBitmapList.At( i ) = NULL; |
|
142 CleanupStack::PushL( icon ); |
|
143 |
|
144 // iconlist takes icon ownership |
|
145 iconList->AppendL( icon ); |
|
146 CleanupStack::Pop(); // icon |
|
147 |
|
148 // add alt text too |
|
149 // alt text build up as follows |
|
150 // 0/talt text1 |
|
151 // 1/talt text2 |
|
152 // 2/talt text3 |
|
153 tempBuf = HBufC::NewLC( |
|
154 // max num is 999999 |
|
155 KImageMapMaxAreaNum + |
|
156 aAltTextList.At( i )->Des().Length() + |
|
157 KImageMapAltTextTab().Length() ); |
|
158 |
|
159 tempBuf->Des().AppendNum( i ); |
|
160 tempBuf->Des().Append( KImageMapAltTextTab ); |
|
161 tempBuf->Des().Append( aAltTextList.At( i )->Des() ); |
|
162 itemList->AppendL( tempBuf->Des() ); |
|
163 CleanupStack::PopAndDestroy(); // tempBuf |
|
164 } |
|
165 // pass iconList ownership |
|
166 ItemDrawer()->ColumnData()->SetIconArray( iconList ); |
|
167 CleanupStack::Pop(); // iconList |
|
168 } |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 // CImageMapListBox::Fit |
|
172 // Checks if the source bitmap can fit into the target bitmap |
|
173 // ----------------------------------------------------------------------------- |
|
174 // |
|
175 TSize CImageMapListBox::Fit( const TSize& aSource, const TSize& aTarget ) |
|
176 { |
|
177 TSize result1( aTarget ); |
|
178 TSize result2( aTarget ); |
|
179 |
|
180 TInt dA( aTarget.iWidth - aSource.iWidth ); |
|
181 TInt dB( aTarget.iHeight - aSource.iHeight ); |
|
182 //lint -e{790} Suspicious truncation, integral to float) |
|
183 TReal tmp = aSource.iHeight + ((TReal)(aSource.iHeight * dA) / (TReal)aSource.iWidth); |
|
184 TReal res; |
|
185 Math::Round( res, tmp, 0); |
|
186 result1.iHeight = (TInt)res; |
|
187 //lint -e{790} Suspicious truncation, integral to float) |
|
188 tmp = aSource.iWidth + ((TReal)(aSource.iWidth * dB) / (TReal)aSource.iHeight); |
|
189 Math::Round( res, tmp, 0); |
|
190 result2.iWidth = (TInt)res; |
|
191 |
|
192 TSize result; |
|
193 if(result1.iWidth <= aTarget.iWidth && result1.iHeight <= aTarget.iHeight) |
|
194 { |
|
195 result = result1; |
|
196 } |
|
197 else |
|
198 { |
|
199 result = result2; |
|
200 } |
|
201 return result; |
|
202 } |
|
203 |
|
204 |
|
205 // ----------------------------------------------------------------------------- |
|
206 // CImageMapPopup::CImageMapPopup |
|
207 // C++ default constructor can NOT contain any code, that |
|
208 // might leave. |
|
209 // ----------------------------------------------------------------------------- |
|
210 // |
|
211 CImageMapPopup::CImageMapPopup() |
|
212 { |
|
213 } |
|
214 |
|
215 // ----------------------------------------------------------------------------- |
|
216 // CImageMapPopup::~CImageMapPopup |
|
217 // destructor. |
|
218 // ----------------------------------------------------------------------------- |
|
219 // |
|
220 CImageMapPopup::~CImageMapPopup() |
|
221 { |
|
222 delete iSkinContext; |
|
223 // delete lists. |
|
224 if(iBitmapList) |
|
225 { |
|
226 iBitmapList->ResetAndDestroy(); |
|
227 } |
|
228 delete iBitmapList; |
|
229 // iAltTextList->ResetAndDestroy(); |
|
230 // delete iAltTextList; |
|
231 } |
|
232 |
|
233 // ----------------------------------------------------------------------------- |
|
234 // CImageMapPopup::ConstructL |
|
235 // Symbian 2nd phase constructor can leave. |
|
236 // ----------------------------------------------------------------------------- |
|
237 // |
|
238 void CImageMapPopup::ConstructL( CEikListBox *aListBox, TInt aCbaResource, |
|
239 AknPopupLayouts::TAknPopupLayouts aType ) |
|
240 { |
|
241 // call base class construct |
|
242 CAknPopupList::ConstructL( aListBox, aCbaResource, aType ); |
|
243 |
|
244 TAknsItemID tileIID = KAknsIIDSkinBmpListPaneNarrowA; |
|
245 // these values should come as consts (from LAF). |
|
246 AknLayoutUtils::SAknLayoutRect tile = { 0, 0, 0, ELayoutEmpty, ELayoutEmpty, KImageMapPopupWidth2, KImageMapPopupHeight }; |
|
247 AknLayoutUtils::SAknLayoutRect bg = { 0, 0, 0, ELayoutEmpty, ELayoutEmpty, KImageMapPopupWidth, KImageMapPopupHeight }; |
|
248 |
|
249 if( AknLayoutUtils::LayoutMirrored( ) ) |
|
250 { |
|
251 tile.iL = ELayoutEmpty; |
|
252 tile.iR = 0; |
|
253 } |
|
254 |
|
255 // these values should come as consts (from LAF) |
|
256 TRect clientRect( 0, 0, KImageMapPopupWidth, KImageMapPopupHeight ); |
|
257 TAknLayoutRect tileRect; |
|
258 TAknLayoutRect bgRect; |
|
259 |
|
260 tileRect.LayoutRect( clientRect, tile ); |
|
261 bgRect.LayoutRect( clientRect, bg ); |
|
262 |
|
263 iSkinContext = CAknsListBoxBackgroundControlContext::NewL( |
|
264 KAknsIIDSkinBmpMainPaneUsual, |
|
265 bgRect.Rect(), |
|
266 EFalse, tileIID, |
|
267 tileRect.Rect() ); |
|
268 } |
|
269 |
|
270 // ----------------------------------------------------------------------------- |
|
271 // CImageMapPopup::CreateAndRunL |
|
272 // Executes the popup dialog |
|
273 // ----------------------------------------------------------------------------- |
|
274 // |
|
275 TInt CImageMapPopup::CreateAndRunL( CArrayPtrFlat<CFbsBitmap>& aBitmapList, CArrayPtrFlat<HBufC>& aAltTextList ) |
|
276 { |
|
277 TInt selectedItem( KErrNotFound ); |
|
278 // construct dialog |
|
279 CImageMapPopup* self = new( ELeave )CImageMapPopup(); |
|
280 CleanupStack::PushL( self ); |
|
281 // take lists ownership |
|
282 self->iBitmapList = &aBitmapList; |
|
283 self->iAltTextList = &aAltTextList; |
|
284 |
|
285 // construct image listboxs |
|
286 CImageMapListBox* listBox = new( ELeave )CImageMapListBox(); |
|
287 CleanupStack::PushL( listBox ); |
|
288 |
|
289 // construct dialog |
|
290 self->ConstructL( listBox, R_AVKON_SOFTKEYS_OK_BACK__OK, AknPopupLayouts::EMenuDoubleLargeGraphicWindow ); |
|
291 |
|
292 // construct listbox |
|
293 listBox->ConstructL( *self, aBitmapList, aAltTextList ); |
|
294 listBox->CreateScrollBarFrameL( ETrue ); |
|
295 listBox->ScrollBarFrame()->SetScrollBarVisibilityL( CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto ); |
|
296 listBox->SetObserver( self ); |
|
297 |
|
298 HBufC* title = HBufC::NewLC( 200 ); // must come from resource CEikonEnv::Static()->AllocReadResourceL( ); |
|
299 title->Des().Copy( _L("Image map areas") ); |
|
300 self->SetTitleL( *title ); |
|
301 CleanupStack::PopAndDestroy(); // title |
|
302 |
|
303 // launch dialog |
|
304 if( self->ExecuteLD() ) |
|
305 { |
|
306 selectedItem = listBox->CurrentItemIndex(); |
|
307 } |
|
308 CleanupStack::PopAndDestroy(); // listbox |
|
309 CleanupStack::Pop(); // self |
|
310 return selectedItem; |
|
311 } |
|
312 |
|
313 // ----------------------------------------------------------------------------- |
|
314 // CImageMapPopup::HandleListBoxEventL |
|
315 // |
|
316 // ----------------------------------------------------------------------------- |
|
317 // |
|
318 void CImageMapPopup::HandleListBoxEventL( CEikListBox* /*aListBox*/, TListBoxEvent aEventType ) |
|
319 { |
|
320 if(aEventType == MEikListBoxObserver::EEventItemDoubleClicked || |
|
321 aEventType == MEikListBoxObserver::EEventEnterKeyPressed) |
|
322 { |
|
323 AttemptExitL( ETrue ); |
|
324 } |
|
325 return; |
|
326 } |
|
327 |
|
328 // ----------------------------------------------------------------------------- |
|
329 // CImageMapPopup::HandleControlEventL |
|
330 // |
|
331 // ----------------------------------------------------------------------------- |
|
332 // |
|
333 void CImageMapPopup::HandleControlEventL( CCoeControl* /*aControl*/, TCoeEvent /*aEventType*/ ) |
|
334 { |
|
335 // overwrite base implementation as it does change CBAs to Mark and Cancel |
|
336 } |
|
337 |
|
338 // ----------------------------------------------------------------------------- |
|
339 // CImageMapPopup::MopSupplyObject |
|
340 // |
|
341 // ----------------------------------------------------------------------------- |
|
342 // |
|
343 TTypeUid::Ptr CImageMapPopup::MopSupplyObject( TTypeUid aId ) |
|
344 { |
|
345 if( aId.iUid == MAknsControlContext::ETypeId /*&& iUseSkinContext*/ ) |
|
346 { |
|
347 return MAknsControlContext::SupplyMopObject( aId, iSkinContext ); |
|
348 } |
|
349 return SupplyMopObject( aId, (MAknEditingStateIndicator*)NULL ); |
|
350 } |
|
351 |
|
352 // End of File |