|
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: Resource Manager |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "BMResourceManager.h" |
|
21 #include "BMBubbleManager.h" |
|
22 #include "BMUtils.h" |
|
23 #include "BMPanic.h" |
|
24 #include "BMBubbleImage.h" |
|
25 #include <eikimage.h> //CEikImage |
|
26 #include <eiklabel.h> //CEikLabel |
|
27 #include <AknsUtils.h> |
|
28 |
|
29 // CONSTANTS |
|
30 const TInt KBubbleMaxEikImages = 17; |
|
31 const TInt KBubbleMaxEikLabels = 6; |
|
32 |
|
33 // ================= MEMBER FUNCTIONS * ====================================== |
|
34 |
|
35 // C++ default constructor can NOT contain any code, that |
|
36 // might leave. |
|
37 // |
|
38 CBubbleResourceManager::CBubbleResourceManager( CBubbleManager& aParentWindow ) |
|
39 : iParentWindow( aParentWindow ) |
|
40 { |
|
41 } |
|
42 |
|
43 // Symbian OS default constructor can leave. |
|
44 void CBubbleResourceManager::ConstructL() |
|
45 { |
|
46 // Set max values to each resource |
|
47 iMaxAmounts.Append( KBubbleMaxEikImages ); |
|
48 iMaxAmounts.Append( KBubbleMaxEikLabels ); |
|
49 |
|
50 const TInt kDifferentResources = iMaxAmounts.Count(); |
|
51 |
|
52 // Zero all availabilities |
|
53 for ( TInt i = 0 ; i < kDifferentResources ; i++ ) |
|
54 { |
|
55 iAvailabilities.Append( 0 ); |
|
56 } |
|
57 |
|
58 |
|
59 // Create main array |
|
60 iResources = new( ELeave ) |
|
61 CArrayPtrFlat<CSingleResource>( kDifferentResources ); |
|
62 iResources->SetReserveL( kDifferentResources ); |
|
63 |
|
64 // Create arrays inside the main array and add them to the main array |
|
65 TInt resource = 0; |
|
66 for ( resource = 0 ; resource < kDifferentResources ; resource++ ) |
|
67 { |
|
68 CSingleResource* single = new( ELeave ) |
|
69 CSingleResource( iMaxAmounts[resource] ); |
|
70 CleanupStack::PushL( single ); |
|
71 single->SetReserveL( iMaxAmounts[resource] ); |
|
72 iResources->AppendL( single ); |
|
73 CleanupStack::Pop(); // single |
|
74 } |
|
75 |
|
76 //Create components to individual arrays: |
|
77 for ( resource = 0 ; resource < kDifferentResources ; resource++ ) |
|
78 { |
|
79 TInt maxCellAmount = iMaxAmounts[resource]; |
|
80 CSingleResource* single = iResources->At( resource ); |
|
81 switch( resource ) |
|
82 { |
|
83 case EBMEikImage: |
|
84 { |
|
85 for ( TInt i = 0 ; i < maxCellAmount ; i++ ) |
|
86 { |
|
87 CBubbleImage* newImage = new( ELeave ) CBubbleImage; |
|
88 CleanupStack::PushL( newImage ); |
|
89 newImage->SetContainerWindowL( iParentWindow ); |
|
90 newImage->SetParent( &iParentWindow ); |
|
91 newImage->SetPictureOwnedExternally( ETrue ); |
|
92 newImage->SetPicture( NULL ); |
|
93 newImage->MakeVisible( EFalse ); |
|
94 single->AppendL( newImage ); |
|
95 CleanupStack::Pop(); //newImage |
|
96 } |
|
97 break; |
|
98 } |
|
99 case EBMEikLabel: |
|
100 { |
|
101 for ( TInt i = 0 ; i < maxCellAmount ; i++ ) |
|
102 { |
|
103 CEikLabel* newText = new( ELeave ) CEikLabel; |
|
104 CleanupStack::PushL( newText ); |
|
105 newText->SetContainerWindowL( iParentWindow ); |
|
106 newText->SetParent( &iParentWindow ); |
|
107 newText->SetBufferReserveLengthL( KBubbleLabelMaxLength ); |
|
108 newText->SetTextL( KNullDesC ); |
|
109 single->AppendL( newText ); |
|
110 CleanupStack::Pop(); //newText |
|
111 } |
|
112 break; |
|
113 } |
|
114 default: |
|
115 Panic( EBMPanicUnhandledSwitchCase ); |
|
116 } |
|
117 } |
|
118 } |
|
119 |
|
120 // Two-phased constructor. |
|
121 CBubbleResourceManager* CBubbleResourceManager::NewL( |
|
122 CBubbleManager& aParentWindow ) |
|
123 { |
|
124 CBubbleResourceManager* self = |
|
125 new (ELeave) CBubbleResourceManager( aParentWindow ); |
|
126 |
|
127 CleanupStack::PushL( self ); |
|
128 self->ConstructL(); |
|
129 CleanupStack::Pop(); |
|
130 |
|
131 return self; |
|
132 } |
|
133 |
|
134 |
|
135 // Destructor |
|
136 CBubbleResourceManager::~CBubbleResourceManager() |
|
137 { |
|
138 if ( iResources ) |
|
139 { |
|
140 // Destroy the inner arrays |
|
141 for ( TInt i = 0 ; i < iResources->Count() ; i++ ) |
|
142 { |
|
143 if ( iResources->At( i ) ) |
|
144 { |
|
145 iResources->At( i )->ResetAndDestroy(); |
|
146 } |
|
147 } |
|
148 iResources->ResetAndDestroy(); |
|
149 delete iResources; |
|
150 } |
|
151 |
|
152 iAvailabilities.Close(); |
|
153 iMaxAmounts.Close(); |
|
154 } |
|
155 |
|
156 |
|
157 |
|
158 // --------------------------------------------------------------------------- |
|
159 // CBubbleResourceManager::ActivateL |
|
160 // Activates all the controls. |
|
161 // |
|
162 // --------------------------------------------------------------------------- |
|
163 // |
|
164 void CBubbleResourceManager::ActivateL() |
|
165 { |
|
166 TInt resourcesTotal = iResources->Count(); |
|
167 for ( TInt oneResource = 0 ; oneResource < resourcesTotal ; oneResource++ ) |
|
168 { |
|
169 CSingleResource* singleResource = iResources->At( oneResource ); |
|
170 TInt elementsTotal = singleResource->Count(); |
|
171 for ( TInt element = 0 ; element < elementsTotal ; element++) |
|
172 { |
|
173 singleResource->At( element )->ActivateL(); |
|
174 } |
|
175 } |
|
176 } |
|
177 |
|
178 // --------------------------------------------------------------------------- |
|
179 // CBubbleResourceManager::ReserveEikLabel |
|
180 // Gets free label and returns pointer to it. |
|
181 // |
|
182 // --------------------------------------------------------------------------- |
|
183 // |
|
184 CEikLabel* CBubbleResourceManager::ReserveEikLabel() |
|
185 { |
|
186 CEikLabel* label = NULL; |
|
187 ReserveResource( (CCoeControl*&)label , EBMEikLabel ); |
|
188 return label; |
|
189 } |
|
190 |
|
191 // --------------------------------------------------------------------------- |
|
192 // CBubbleResourceManager::ReleaseEikLabel |
|
193 // Zeros the label and releases it. |
|
194 // |
|
195 // --------------------------------------------------------------------------- |
|
196 // |
|
197 void CBubbleResourceManager::ReleaseEikLabel( CEikLabel*& aLabel ) |
|
198 { |
|
199 if ( aLabel ) |
|
200 { |
|
201 BubbleUtils::AddTextToEikLabel( aLabel , KNullDesC ); |
|
202 } |
|
203 ReleaseResource( (CCoeControl*&)aLabel , EBMEikLabel ); |
|
204 } |
|
205 |
|
206 // --------------------------------------------------------------------------- |
|
207 // CBubbleResourceManager::ReserveEikImage |
|
208 // Gets new image object and sets it visible. |
|
209 // |
|
210 // --------------------------------------------------------------------------- |
|
211 // |
|
212 CEikImage* CBubbleResourceManager::ReserveEikImage( |
|
213 TBool aIsBackgroundImage ) |
|
214 { |
|
215 CBubbleImage* image = NULL; |
|
216 ReserveResource( ( CCoeControl*& )image , EBMEikImage ); |
|
217 if ( image ) |
|
218 { |
|
219 if( aIsBackgroundImage ) |
|
220 { |
|
221 image->SetAsBackgroundImage( ETrue ); |
|
222 } |
|
223 image->MakeVisible( ETrue ); |
|
224 } |
|
225 return image; |
|
226 } |
|
227 |
|
228 // --------------------------------------------------------------------------- |
|
229 // CBubbleResourceManager::ReleaseEikImage |
|
230 // NULLs the bitmaps, makes invisible and releases the image. |
|
231 // |
|
232 // --------------------------------------------------------------------------- |
|
233 // |
|
234 void CBubbleResourceManager::ReleaseEikImage( CEikImage*& aImage ) |
|
235 { |
|
236 if ( aImage ) |
|
237 { |
|
238 aImage->SetPicture( NULL , NULL ); |
|
239 aImage->SetPictureOwnedExternally( ETrue ); |
|
240 aImage->MakeVisible( EFalse ); |
|
241 static_cast<CBubbleImage*>( aImage )->SetAsBackgroundImage( EFalse ); |
|
242 } |
|
243 ReleaseResource( (CCoeControl*&)aImage , EBMEikImage ); |
|
244 } |
|
245 |
|
246 |
|
247 // --------------------------------------------------------------------------- |
|
248 // CBubbleResourceManager::ReserveResource |
|
249 // Reserves some CCoeControl. Uses the second parameter for indexing |
|
250 // the main arrays. |
|
251 // --------------------------------------------------------------------------- |
|
252 // |
|
253 void CBubbleResourceManager::ReserveResource( CCoeControl*& aResource , |
|
254 TBubbleResource aType ) |
|
255 { |
|
256 TUint amount = iResources->At( aType )->Count(); |
|
257 // 1 mean is reserved and 0 free slot |
|
258 TUint& available = iAvailabilities[aType]; |
|
259 TUint bit = 1; // start from first bit |
|
260 for ( TUint slot = 0 ; slot < amount ; slot++ ) |
|
261 { |
|
262 // if flag is one the seat is taken... |
|
263 if ( available&bit ) |
|
264 { |
|
265 bit = bit<<1; //move to next bit of for next round |
|
266 continue; |
|
267 } |
|
268 |
|
269 // so we found a free slot |
|
270 aResource = iResources->At( aType )->At( slot ); |
|
271 if ( aResource != NULL ) |
|
272 { |
|
273 available |= bit; // set the corrensponding bit |
|
274 // for reserved indicator |
|
275 } |
|
276 break; |
|
277 } |
|
278 __ASSERT_DEBUG( aResource != NULL , Panic( EBMPanicImages ) ); |
|
279 } |
|
280 |
|
281 // --------------------------------------------------------------------------- |
|
282 // CBubbleResourceManager::ReleaseResource |
|
283 // Releases CCoeControl object. |
|
284 // |
|
285 // --------------------------------------------------------------------------- |
|
286 // |
|
287 void CBubbleResourceManager::ReleaseResource( CCoeControl*& aResource , |
|
288 TBubbleResource aType ) |
|
289 { |
|
290 if ( aResource == NULL ) |
|
291 { |
|
292 return; |
|
293 } |
|
294 |
|
295 CSingleResource* single = iResources->At( aType ); |
|
296 TUint amount = single->Count(); |
|
297 TUint& available = iAvailabilities[aType]; // 1 mean is reserved |
|
298 // and 0 free slot |
|
299 TUint bit = 1; // start from first bit |
|
300 for ( TUint slot = 0 ; slot < amount ; slot++ ) |
|
301 { |
|
302 if ( single->At( slot ) == aResource ) |
|
303 { |
|
304 __ASSERT_DEBUG( available&bit , Panic( EBMPanicImages ) ); |
|
305 available &= ~bit; // zero the corrensponding bit |
|
306 // for freed indicator |
|
307 aResource = NULL; |
|
308 break; |
|
309 } |
|
310 bit = bit<<1; //move to next bit of for next round |
|
311 } |
|
312 __ASSERT_DEBUG( aResource == NULL , Panic( EBMPanicImages ) ); |
|
313 } |
|
314 |
|
315 // End of File |