|
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 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 |
|
22 #include <e32std.h> |
|
23 #include <mifconvdefs.h> |
|
24 #include "AknIconLocationInfo.h" |
|
25 #include "AknIconLoader.h" |
|
26 |
|
27 |
|
28 // CONSTANTS |
|
29 |
|
30 // ================= MEMBER FUNCTIONS ========================================== |
|
31 |
|
32 CAknIconLocationInfo::CAknIconLocationInfo() |
|
33 { |
|
34 } |
|
35 |
|
36 CAknIconLocationInfo::CAknIconLocationInfo( const TDesC& aFileName ) |
|
37 { |
|
38 // This constructor is used when the object is instantiated in stack, |
|
39 // so CBase's zero initialization is not done. |
|
40 Mem::FillZ( this, sizeof( CAknIconLocationInfo ) ); |
|
41 iFileNameRef = &aFileName; |
|
42 } |
|
43 |
|
44 CAknIconLocationInfo::~CAknIconLocationInfo() |
|
45 { |
|
46 delete iFileName; |
|
47 delete [] iLocations; |
|
48 delete iSharedOffsets; |
|
49 } |
|
50 |
|
51 CAknIconLocationInfo* CAknIconLocationInfo::NewL( |
|
52 const TDesC& aFileName, |
|
53 MifHeader::CInstance& aOffsets ) |
|
54 { |
|
55 CAknIconLocationInfo* item = new( ELeave ) CAknIconLocationInfo; |
|
56 CleanupStack::PushL( item ); |
|
57 item->ConstructL( aFileName, aOffsets ); |
|
58 CleanupStack::Pop(); |
|
59 return item; |
|
60 } |
|
61 |
|
62 CAknIconLocationInfo* CAknIconLocationInfo::NewL( |
|
63 const TDesC& aFileName, |
|
64 const TDesC8& aOffsetArray ) |
|
65 { |
|
66 CAknIconLocationInfo* item = new( ELeave ) CAknIconLocationInfo; |
|
67 CleanupStack::PushL( item ); |
|
68 item->ConstructL( aFileName, aOffsetArray ); |
|
69 CleanupStack::Pop(); |
|
70 return item; |
|
71 } |
|
72 |
|
73 CAknIconLocationInfo* CAknIconLocationInfo::NewL( |
|
74 const TDesC& aFileName ) |
|
75 { |
|
76 CAknIconLocationInfo* item = new( ELeave ) CAknIconLocationInfo; |
|
77 CleanupStack::PushL( item ); |
|
78 item->ConstructL( aFileName ); |
|
79 CleanupStack::Pop(); |
|
80 return item; |
|
81 } |
|
82 |
|
83 void CAknIconLocationInfo::ConstructL( |
|
84 const TDesC& aFileName, |
|
85 MifHeader::CInstance& aOffsets ) |
|
86 { |
|
87 iFileName = aFileName.AllocL(); |
|
88 |
|
89 iSharedOffsets = MifHeader::CInstance::NewL(aOffsets.Ref()); |
|
90 iCount = iSharedOffsets->indicies().Count(); |
|
91 } |
|
92 |
|
93 void CAknIconLocationInfo::ConstructL( |
|
94 const TDesC& aFileName, |
|
95 const TDesC8& aOffsetArray ) |
|
96 { |
|
97 iFileName = aFileName.AllocL(); |
|
98 |
|
99 if ( aOffsetArray.Size() % sizeof( TMifBitmapOffsetElement ) ) |
|
100 { |
|
101 User::Leave( KErrCorrupt ); |
|
102 } |
|
103 |
|
104 iCount = aOffsetArray.Size() / sizeof(TMifBitmapOffsetElement); |
|
105 |
|
106 // iCount must always be even number |
|
107 if (iCount % 2) |
|
108 { |
|
109 User::Leave( KErrCorrupt ); |
|
110 } |
|
111 |
|
112 iLocations = new( ELeave ) TInt[iCount]; |
|
113 |
|
114 TMifBitmapOffsetElement* ptr = (TMifBitmapOffsetElement*)aOffsetArray.Ptr(); |
|
115 |
|
116 for ( TInt i = 0 ; i < iCount ; i++ ) |
|
117 { |
|
118 iLocations[i] = ptr->iOffset; // copy the offset variable in iLocations |
|
119 ptr++; |
|
120 } |
|
121 } |
|
122 |
|
123 void CAknIconLocationInfo::ConstructL( const TDesC& aFileName ) |
|
124 { |
|
125 iFileName = aFileName.AllocL(); |
|
126 } |
|
127 |
|
128 // ----------------------------------------------------------------------------- |
|
129 // CAknIconLocationInfo::LinearOrder |
|
130 // ----------------------------------------------------------------------------- |
|
131 // |
|
132 TInt CAknIconLocationInfo::LinearOrder( |
|
133 const CAknIconLocationInfo& aFirst, |
|
134 const CAknIconLocationInfo& aSecond ) |
|
135 { |
|
136 const TDesC* firstFileName = aFirst.iFileNameRef ? |
|
137 aFirst.iFileNameRef : aFirst.iFileName; |
|
138 |
|
139 const TDesC* secondFileName = aSecond.iFileNameRef ? |
|
140 aSecond.iFileNameRef : aSecond.iFileName; |
|
141 |
|
142 return firstFileName->CompareF( *secondFileName ); |
|
143 } |
|
144 |
|
145 // ----------------------------------------------------------------------------- |
|
146 // CAknIconLocationInfo::GetIconLocation |
|
147 // ----------------------------------------------------------------------------- |
|
148 // |
|
149 TInt CAknIconLocationInfo::GetIconLocation( |
|
150 TInt16& aBitmapId, TInt16& aMaskId ) const |
|
151 { |
|
152 if ( !iLocations && !iSharedOffsets ) |
|
153 { |
|
154 // V1 MIF file. IDs do not need to be changed. |
|
155 return KErrNone; |
|
156 } |
|
157 |
|
158 TInt16 bitmapId; |
|
159 |
|
160 // MBG indexes start from KMifIdFirst. |
|
161 TInt bitmapIndex = aBitmapId - KMifIdFirst; |
|
162 |
|
163 if ( bitmapIndex < 0 || |
|
164 bitmapIndex >= iCount ) |
|
165 { |
|
166 return KErrEof; |
|
167 } |
|
168 |
|
169 TInt offset; |
|
170 if (iLocations) |
|
171 { |
|
172 // Fetch the icon offset info from the offset array that is |
|
173 // retrieved from the MIF file |
|
174 offset = iLocations[bitmapIndex]; |
|
175 } |
|
176 else |
|
177 { |
|
178 // Fetch the icon offset info from the offset array that is |
|
179 // stored in the shared MifHeader instance |
|
180 offset = iSharedOffsets->indicies()[bitmapIndex].iOffset; |
|
181 } |
|
182 |
|
183 // Negative or zero offset means that it is a MBM icon, |
|
184 // and the real icon index is then that offset changed to positive. |
|
185 if ( offset <= 0 ) |
|
186 { |
|
187 bitmapId = -offset; |
|
188 } |
|
189 // Positive offset means that it is a MIF icon, |
|
190 // the original icon index (from MBG file) should be used in that case. |
|
191 else |
|
192 { |
|
193 bitmapId = aBitmapId; |
|
194 } |
|
195 |
|
196 // Mask used? |
|
197 if ( aMaskId >= 0 ) |
|
198 { |
|
199 // MBG indexes start from KMifIdFirst. |
|
200 TInt maskIndex = aMaskId - KMifIdFirst; |
|
201 |
|
202 if ( maskIndex < 0 || |
|
203 maskIndex >= iCount ) |
|
204 { |
|
205 return KErrEof; |
|
206 } |
|
207 |
|
208 if (iLocations) |
|
209 offset = iLocations[maskIndex]; |
|
210 else |
|
211 offset = iSharedOffsets->indicies()[maskIndex].iOffset; |
|
212 |
|
213 if ( offset <= 0 ) |
|
214 { |
|
215 aMaskId = -offset; |
|
216 } |
|
217 } |
|
218 |
|
219 aBitmapId = bitmapId; |
|
220 return KErrNone; |
|
221 } |
|
222 |
|
223 // End of File |