|
1 /* |
|
2 * Copyright (c) 2005 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 * Reads default parameters for composing SMIL from resource file |
|
16 * |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include <e32math.h> |
|
23 |
|
24 #include <barsread.h> |
|
25 #include <bautils.h> |
|
26 #include <data_caging_path_literals.hrh> |
|
27 |
|
28 #include <UniDataModel.rsg> |
|
29 |
|
30 #include "UniSmil.hrh" |
|
31 #include "UniSmilParams.h" |
|
32 #include "UniModelConst.h" |
|
33 |
|
34 |
|
35 // ================= MEMBER FUNCTIONS ======================= |
|
36 |
|
37 // C++ default constructor can NOT contain any code, that |
|
38 // might leave. |
|
39 // |
|
40 CUniSmilParams::CUniSmilParams( const RFs& aSession ) : iSession( aSession ) |
|
41 { |
|
42 } |
|
43 |
|
44 // Symbian OS default constructor can leave. |
|
45 void CUniSmilParams::ConstructL() |
|
46 { |
|
47 iComposeParams = new( ELeave ) TUniSmilComposeParam(); |
|
48 iImageRegionParams = new( ELeave ) TUniSmilRegionParam(); |
|
49 iTextRegionParams = new( ELeave ) TUniSmilRegionParam(); |
|
50 ReadResourcesL(); |
|
51 } |
|
52 |
|
53 // Two-phased constructor. |
|
54 EXPORT_C CUniSmilParams* CUniSmilParams::NewL( const RFs& aSession ) |
|
55 { |
|
56 CUniSmilParams* self = new ( ELeave ) CUniSmilParams( aSession ); |
|
57 CleanupStack::PushL( self ); |
|
58 self->ConstructL(); |
|
59 CleanupStack::Pop( self ); |
|
60 return self; |
|
61 } |
|
62 |
|
63 // Two-phased constructor. |
|
64 EXPORT_C CUniSmilParams* CUniSmilParams::NewLC( const RFs& aSession ) |
|
65 { |
|
66 CUniSmilParams* self = new (ELeave) CUniSmilParams( aSession ); |
|
67 CleanupStack::PushL( self ); |
|
68 self->ConstructL(); |
|
69 return self; |
|
70 } |
|
71 |
|
72 // Destructor |
|
73 CUniSmilParams::~CUniSmilParams() |
|
74 { |
|
75 delete iImageRegionParams; |
|
76 delete iTextRegionParams; |
|
77 delete iComposeParams; |
|
78 } |
|
79 |
|
80 |
|
81 // --------------------------------------------------------- |
|
82 // CUniSmilParams::ReadResourcesL() |
|
83 // |
|
84 // --------------------------------------------------------- |
|
85 // |
|
86 void CUniSmilParams::ReadResourcesL() |
|
87 { |
|
88 RResourceFile resFile; |
|
89 OpenResourceFileL( resFile ); |
|
90 |
|
91 ReadComposeParamResourcesL( resFile ); |
|
92 ReadImageRegionResourcesL( resFile ); |
|
93 ReadTextRegionResourcesL( resFile ); |
|
94 |
|
95 resFile.Close(); |
|
96 } |
|
97 |
|
98 // --------------------------------------------------------- |
|
99 // ReadComposeParamResourcesL() |
|
100 // |
|
101 // --------------------------------------------------------- |
|
102 // |
|
103 void CUniSmilParams::ReadComposeParamResourcesL( |
|
104 const RResourceFile& aResFile ) |
|
105 { |
|
106 TResourceReader reader; |
|
107 HBufC8* buf = aResFile.AllocReadLC( R_COMPOSE_PARAMS ); |
|
108 reader.SetBuffer( buf ); |
|
109 |
|
110 iComposeParams->iRootLayoutCompose = reader.ReadInt16(); |
|
111 iComposeParams->iDisplayWidth = reader.ReadInt16(); |
|
112 iComposeParams->iDisplayHeight = reader.ReadInt16(); |
|
113 iComposeParams->iComposeXmlns = reader.ReadInt16(); |
|
114 iComposeParams->iTopPadding = reader.ReadInt16(); |
|
115 iComposeParams->iRegionPadding = reader.ReadInt16(); |
|
116 iComposeParams->iBottomPadding = reader.ReadInt16(); |
|
117 |
|
118 CleanupStack::PopAndDestroy( buf ); |
|
119 |
|
120 buf = aResFile.AllocReadLC( R_SLIDE_PARAMS ); |
|
121 reader.SetBuffer( buf ); |
|
122 |
|
123 iComposeParams->iSlideDuration = reader.ReadInt16(); |
|
124 |
|
125 CleanupStack::PopAndDestroy( buf ); |
|
126 } |
|
127 |
|
128 // --------------------------------------------------------- |
|
129 // CUniSmilParams::ReadImageRegionResourcesL |
|
130 // |
|
131 // --------------------------------------------------------- |
|
132 // |
|
133 void CUniSmilParams::ReadImageRegionResourcesL( |
|
134 const RResourceFile& aResFile ) |
|
135 { |
|
136 TResourceReader reader; |
|
137 HBufC8* buf = aResFile.AllocReadLC( R_IMAGE_REGION_ATTRIBUTES ); |
|
138 reader.SetBuffer( buf ); |
|
139 |
|
140 TPtrC ptr; |
|
141 |
|
142 // Id |
|
143 ptr.Set( reader.ReadTPtrC() ); |
|
144 iImageRegionParams->iId = HBufC::NewL( ptr.Length() ); |
|
145 iImageRegionParams->iId->Des().Copy( ptr ); |
|
146 |
|
147 // Fit |
|
148 ptr.Set( reader.ReadTPtrC() ); |
|
149 iImageRegionParams->iFit = HBufC::NewL( ptr.Length() ); |
|
150 iImageRegionParams->iFit->Des().Copy( ptr ); |
|
151 |
|
152 // Max/Min width/height |
|
153 iImageRegionParams->iMaxSize.iHeight = reader.ReadInt16(); //r_max_height |
|
154 iImageRegionParams->iMinSize.iHeight = reader.ReadInt16(); //r_min_height |
|
155 iImageRegionParams->iMaxSize.iWidth = reader.ReadInt16(); //r_max_width |
|
156 iImageRegionParams->iMinSize.iWidth = reader.ReadInt16(); //r_min_width |
|
157 |
|
158 iImageRegionParams->iTopLeft.iY = reader.ReadInt16(); //r_top = 0; |
|
159 iImageRegionParams->iTopLeft.iX = reader.ReadInt16(); //r_left = 0; |
|
160 |
|
161 // Default Default ;) |
|
162 iImageRegionParams->iSize = iImageRegionParams->iMaxSize; |
|
163 |
|
164 CleanupStack::PopAndDestroy( buf ); |
|
165 |
|
166 // Make some sanity checks |
|
167 if ( iImageRegionParams->iMaxSize.iHeight < iImageRegionParams->iMinSize.iHeight || |
|
168 iImageRegionParams->iMaxSize.iWidth < iImageRegionParams->iMinSize.iWidth ) |
|
169 { |
|
170 User::Leave( KErrArgument ); |
|
171 } |
|
172 |
|
173 } |
|
174 |
|
175 |
|
176 // --------------------------------------------------------- |
|
177 // CUniSmilParams::ReadTextRegionResourcesL() |
|
178 // |
|
179 // --------------------------------------------------------- |
|
180 // |
|
181 void CUniSmilParams::ReadTextRegionResourcesL( |
|
182 const RResourceFile& aResFile ) |
|
183 { |
|
184 TResourceReader reader; |
|
185 HBufC8* buf = aResFile.AllocReadLC( R_TEXT_REGION_ATTRIBUTES ); |
|
186 reader.SetBuffer( buf ); |
|
187 |
|
188 TPtrC ptr; |
|
189 |
|
190 // Id |
|
191 ptr.Set( reader.ReadTPtrC() ); |
|
192 iTextRegionParams->iId = HBufC::NewL( ptr.Length() ); |
|
193 iTextRegionParams->iId->Des().Copy( ptr ); |
|
194 |
|
195 // Fit |
|
196 ptr.Set( reader.ReadTPtrC() ); |
|
197 iTextRegionParams->iFit = HBufC::NewL( ptr.Length() ); |
|
198 iTextRegionParams->iFit->Des().Copy( ptr ); |
|
199 |
|
200 // Max/Min width/height |
|
201 //r_max_height |
|
202 iTextRegionParams->iMaxSize.iHeight = reader.ReadInt16(); |
|
203 //r_min_height |
|
204 iTextRegionParams->iMinSize.iHeight = reader.ReadInt16(); |
|
205 //r_max_width |
|
206 iTextRegionParams->iMaxSize.iWidth = reader.ReadInt16(); |
|
207 //r_min_width |
|
208 iTextRegionParams->iMinSize.iWidth = reader.ReadInt16(); |
|
209 |
|
210 //r_top = 0; |
|
211 iTextRegionParams->iTopLeft.iY = reader.ReadInt16(); |
|
212 //r_left = 0; |
|
213 iTextRegionParams->iTopLeft.iX = reader.ReadInt16(); |
|
214 |
|
215 // Default Default ;) |
|
216 iTextRegionParams->iSize = iTextRegionParams->iMaxSize; |
|
217 |
|
218 CleanupStack::PopAndDestroy( buf ); |
|
219 |
|
220 // Make some sanity checks |
|
221 if ( iTextRegionParams->iMaxSize.iHeight < iTextRegionParams->iMinSize.iHeight || |
|
222 iTextRegionParams->iMaxSize.iWidth < iTextRegionParams->iMinSize.iWidth ) |
|
223 { |
|
224 User::Leave( KErrArgument ); |
|
225 } |
|
226 |
|
227 } |
|
228 |
|
229 // --------------------------------------------------------- |
|
230 // CUniSmilParams::OpenResourceFileL() |
|
231 // |
|
232 // --------------------------------------------------------- |
|
233 // |
|
234 void CUniSmilParams::OpenResourceFileL( RResourceFile& aResFile ) |
|
235 { |
|
236 TFileName fileName; |
|
237 TParse parse; |
|
238 parse.Set( KUniDataModelResourceFilename, &KDC_RESOURCE_FILES_DIR, NULL ); |
|
239 fileName = parse.FullName(); |
|
240 BaflUtils::NearestLanguageFile( iSession, fileName ); |
|
241 aResFile.OpenL( const_cast<RFs&>( iSession ), fileName ); |
|
242 aResFile.ConfirmSignatureL( KDefResFileSignature ); |
|
243 } |
|
244 |
|
245 // End of File |
|
246 |