|
1 /* |
|
2 * Copyright (c) 2002-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 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // disable "identifier was truncated to '255' characters in the browser information" warning |
|
21 #pragma warning (disable:4786) |
|
22 |
|
23 #include "MasterLayoutPack.h" |
|
24 #include "ZoomLevelNames.h" |
|
25 #include "LayoutCompilerErr.h" |
|
26 #include "CodeGenConsts.h" |
|
27 |
|
28 #include <sstream> |
|
29 #include <iostream> |
|
30 #include <list> |
|
31 #include <algorithm> |
|
32 |
|
33 using namespace std; |
|
34 using namespace CdlCompilerToolkit; |
|
35 |
|
36 typedef LayoutProcessArgsErr<MasterLayoutPackage> MasterLayoutPackageArgsErr; |
|
37 |
|
38 const string KMasterLayoutPackCdlFile = "MasterLayoutPack.cdl"; |
|
39 |
|
40 typedef vector<string> PackageInfoLine; |
|
41 |
|
42 class MasterLayoutIndex |
|
43 { |
|
44 public: |
|
45 MasterLayoutIndex(list<PackageInfoLine> packageInfo, CZoomLevelNames& zoomLevelName, const string& fileName); |
|
46 void BuildAndWrite(); |
|
47 |
|
48 private: |
|
49 enum InfoArgPositions |
|
50 { |
|
51 EPackNameArg = 0, |
|
52 EWidthArg = 1, |
|
53 EHeightArg = 2, |
|
54 EVariantArg = 3, |
|
55 EFirstContentArg = 4 |
|
56 }; |
|
57 |
|
58 struct PkgSize |
|
59 { |
|
60 string iW; |
|
61 string iH; |
|
62 bool operator==(const PkgSize& aRhs) |
|
63 { return iW == aRhs.iW && iH == aRhs.iH; } |
|
64 }; |
|
65 |
|
66 private: |
|
67 void BuildOptionsVectors(); |
|
68 void CreateTemplateInstance(); |
|
69 void SetSizes(); |
|
70 void SetVariants(); |
|
71 void SetZooms(); |
|
72 void SetContents(); |
|
73 void WriteInstance(); |
|
74 void Implement(const string& aApi, const string& aTarget, const string& aReplace); |
|
75 void AddPkg(PackageInfoLine& aLine, const string& aZoom, string& aExtra, string& aImpl); |
|
76 PackageInfoLine* FindLine(const PkgSize& aSize, const string& aVariant); |
|
77 |
|
78 private: |
|
79 list<PackageInfoLine> iPackageInfo; |
|
80 CZoomLevelNames& iZooms; |
|
81 const string& iInstName; |
|
82 vector<PkgSize> iSizes; |
|
83 vector<string> iVariants; |
|
84 auto_ptr<CCdlTkInterface> iIface; |
|
85 auto_ptr<CCdlTkInstance> iInst; |
|
86 }; |
|
87 |
|
88 |
|
89 int MasterLayoutPackage::Process(vector<string>& args) |
|
90 { |
|
91 CZoomLevelNames zoomLevelNames; |
|
92 zoomLevelNames.ProcessOptions(args); |
|
93 |
|
94 if (args.size() != 2) |
|
95 throw MasterLayoutPackageArgsErr(); |
|
96 |
|
97 string& fileName = args[1]; |
|
98 ifstream in; |
|
99 CdlTkUtil::OpenInput(in, fileName); |
|
100 |
|
101 list<PackageInfoLine> packageInfo; |
|
102 string line; |
|
103 while (!in.eof()) |
|
104 { |
|
105 getline(in, line); |
|
106 PackageInfoLine words; |
|
107 CdlTkUtil::Tokenize(line, back_insert_iterator<PackageInfoLine>(words)); |
|
108 if (words.size()) |
|
109 packageInfo.push_back(words); |
|
110 } |
|
111 in.close(); |
|
112 |
|
113 MasterLayoutIndex index(packageInfo, zoomLevelNames, fileName.substr(0,fileName.find_first_of('.'))); |
|
114 index.BuildAndWrite(); |
|
115 |
|
116 return 0; |
|
117 } |
|
118 |
|
119 void MasterLayoutPackage::ShowHelp(ostream& stream) |
|
120 { |
|
121 stream << "MasterLayPkg [-z<zoomList>] <packageListFile>" << endl; |
|
122 stream << " Creates CDL package according to MasterLayoutPack.cdl containing" << endl; |
|
123 stream << " all of the packages described in <packageListFile>." << endl; |
|
124 stream << " The <packageListFile> should contain lines with the following contents:" << endl; |
|
125 stream << " <layout pack name> <width> <height> <layout variant> <content>*" << endl; |
|
126 stream << " If -z<zoomList> is specified, then instances for zoom factors" << endl; |
|
127 stream << " (in the form \"n,string\") appearing in the file <zoomList> will be generated, " << endl; |
|
128 stream << " by replacing the keyword $ZOOM in the package definitions." << endl; |
|
129 } |
|
130 |
|
131 void MasterLayoutPackage_Process( |
|
132 const string& aName, |
|
133 const string& aWidth, |
|
134 const string& aHeight, |
|
135 const string& aId, |
|
136 vector<string>::const_iterator aBegin, |
|
137 vector<string>::const_iterator aEnd, |
|
138 const string& aZoomName) |
|
139 { |
|
140 CCdlTkCdlFileParser parser(KDirDomainSysHeader+KMasterLayoutPackCdlFile); |
|
141 auto_ptr<CCdlTkInterface> iface(parser.LoadAndParse(true)); |
|
142 CCdlTkInstance pkg(*iface); |
|
143 pkg.TemplateAllImplementations(); |
|
144 |
|
145 string zoomName = CdlTkUtil::Replace("$ZOOM", aZoomName, aName); |
|
146 string zoomIdName = "EAknUiZoom" + aZoomName; |
|
147 |
|
148 pkg.SetName(zoomName); |
|
149 |
|
150 /* Implement(pkg, "name", "\"\"", string("\"")+zoomName+"\""); |
|
151 Implement(pkg, "size", "?width", aWidth); |
|
152 Implement(pkg, "size", "?height", aHeight); |
|
153 Implement(pkg, "id", "?value", aId); |
|
154 Implement(pkg, "zoom", "?value", zoomIdName); |
|
155 */ |
|
156 cout << zoomName << endl; |
|
157 |
|
158 for (; aBegin != aEnd; ++aBegin) |
|
159 { |
|
160 string zoomContent = CdlTkUtil::Replace("$ZOOM", aZoomName, *aBegin); |
|
161 // pkg.AddLocalContent(zoomContent); |
|
162 cout << zoomContent << endl; |
|
163 } |
|
164 |
|
165 CCdlTkWriteInstance writer(pkg); |
|
166 writer.Process(); |
|
167 } |
|
168 |
|
169 |
|
170 MasterLayoutIndex::MasterLayoutIndex(list<PackageInfoLine> packageInfo, CZoomLevelNames& zoomLevelName, const string& fileName) |
|
171 : iPackageInfo(packageInfo), iZooms(zoomLevelName), iInstName(fileName) |
|
172 { |
|
173 } |
|
174 |
|
175 void MasterLayoutIndex::BuildAndWrite() |
|
176 { |
|
177 BuildOptionsVectors(); |
|
178 CreateTemplateInstance(); |
|
179 SetSizes(); |
|
180 SetVariants(); |
|
181 SetZooms(); |
|
182 SetContents(); |
|
183 WriteInstance(); |
|
184 } |
|
185 |
|
186 void MasterLayoutIndex::BuildOptionsVectors() |
|
187 { |
|
188 for (list<PackageInfoLine>::iterator pLine=iPackageInfo.begin(); pLine!=iPackageInfo.end(); ++pLine) |
|
189 { |
|
190 if (pLine->size() < EFirstContentArg) |
|
191 throw GeneralErr((*pLine)[EPackNameArg] + " package info has too few arguments"); |
|
192 |
|
193 PkgSize size; |
|
194 size.iW = (*pLine)[EWidthArg]; |
|
195 size.iH = (*pLine)[EHeightArg]; |
|
196 if (find(iSizes.begin(), iSizes.end(), size) == iSizes.end()) |
|
197 iSizes.push_back(size); |
|
198 |
|
199 string variant = (*pLine)[EVariantArg]; |
|
200 if (find(iVariants.begin(), iVariants.end(), variant) == iVariants.end()) |
|
201 iVariants.push_back(variant); |
|
202 } |
|
203 } |
|
204 |
|
205 void MasterLayoutIndex::CreateTemplateInstance() |
|
206 { |
|
207 CCdlTkCdlFileParser parser(KDirDomainSysHeader+KMasterLayoutPackCdlFile); |
|
208 iIface = parser.LoadAndParse(true); |
|
209 iInst = auto_ptr<CCdlTkInstance>(new CCdlTkInstance(*iIface)); |
|
210 iInst->TemplateAllImplementations(); |
|
211 iInst->SetName(iInstName); |
|
212 // This master index should be the first in the DLL, so write it first. |
|
213 cout << iInstName << endl; |
|
214 } |
|
215 |
|
216 void MasterLayoutIndex::SetSizes() |
|
217 { |
|
218 string impl; |
|
219 for (vector<PkgSize>::iterator pSize = iSizes.begin(); pSize != iSizes.end(); ++pSize) |
|
220 { |
|
221 CdlTkUtil::AppendString(impl, "\t{ "); |
|
222 CdlTkUtil::AppendString(impl, pSize->iW); |
|
223 CdlTkUtil::AppendString(impl, ", "); |
|
224 CdlTkUtil::AppendString(impl, pSize->iW); |
|
225 CdlTkUtil::AppendString(impl, " },\n"); |
|
226 } |
|
227 Implement("sizes", "?array_contents", impl); |
|
228 } |
|
229 |
|
230 void MasterLayoutIndex::SetVariants() |
|
231 { |
|
232 string impl; |
|
233 for (vector<string>::iterator pVar = iVariants.begin(); pVar != iVariants.end(); ++pVar) |
|
234 { |
|
235 CdlTkUtil::AppendString(impl, "\t"); |
|
236 CdlTkUtil::AppendString(impl, *pVar); |
|
237 CdlTkUtil::AppendString(impl, ",\n"); |
|
238 } |
|
239 Implement("variants", "?array_contents", impl); |
|
240 } |
|
241 |
|
242 void MasterLayoutIndex::SetZooms() |
|
243 { |
|
244 string impl; |
|
245 for (CZoomLevelNames::iterator pZoom = iZooms.begin(); pZoom != iZooms.end(); ++pZoom) |
|
246 { |
|
247 CdlTkUtil::AppendString(impl, "\tEAknUiZoom"); |
|
248 CdlTkUtil::AppendString(impl, pZoom->second); |
|
249 CdlTkUtil::AppendString(impl, ",\n"); |
|
250 } |
|
251 Implement("zooms", "?array_contents", impl); |
|
252 } |
|
253 |
|
254 void MasterLayoutIndex::SetContents() |
|
255 { |
|
256 string extra; |
|
257 string impl; |
|
258 for (vector<PkgSize>::iterator pSize = iSizes.begin(); pSize != iSizes.end(); ++pSize) |
|
259 { |
|
260 for (vector<string>::iterator pVar = iVariants.begin(); pVar != iVariants.end(); ++pVar) |
|
261 { |
|
262 PackageInfoLine* line = FindLine(*pSize, *pVar); |
|
263 for (CZoomLevelNames::iterator pZoom = iZooms.begin(); pZoom != iZooms.end(); ++pZoom) |
|
264 { |
|
265 if (line == NULL) |
|
266 CdlTkUtil::AppendString(impl, "\tNULL,\n"); |
|
267 else |
|
268 AddPkg(*line, pZoom->second, extra, impl); |
|
269 } |
|
270 } |
|
271 } |
|
272 Implement("contents", "?array_contents", impl); |
|
273 iInst->SetExtraCpp(extra); |
|
274 } |
|
275 |
|
276 void MasterLayoutIndex::WriteInstance() |
|
277 { |
|
278 CCdlTkWriteInstance writer(*iInst); |
|
279 writer.Process(); |
|
280 } |
|
281 |
|
282 void MasterLayoutIndex::Implement(const string& aApi, const string& aTarget, const string& aReplace) |
|
283 { |
|
284 CCdlTkImplementation* impl = iInst->Impl().Find(aApi); |
|
285 if (!impl) |
|
286 throw NotFoundErr(aApi + " in MasterLayoutPack.cdl"); |
|
287 CdlTkUtil::CReplaceSet implSet; |
|
288 implSet.Add(aTarget, aReplace); |
|
289 implSet.Add(" //TODO: Initialise this data.", ""); |
|
290 impl->SetDefinition(CdlTkUtil::MultiReplace(implSet, impl->Definition())); |
|
291 } |
|
292 |
|
293 void MasterLayoutIndex::AddPkg(PackageInfoLine& aLine, const string& aZoom, string& aExtra, string& aImpl) |
|
294 { |
|
295 string impl = "&"; |
|
296 string extra; |
|
297 |
|
298 string pkgName = CdlTkUtil::Replace("$ZOOM", aZoom, aLine[EPackNameArg]); |
|
299 impl+=pkgName; |
|
300 |
|
301 string refs; |
|
302 for (int refPos = EFirstContentArg; refPos < aLine.size(); ++refPos) |
|
303 { |
|
304 string refName = CdlTkUtil::Replace("$ZOOM", aZoom, aLine[refPos]); |
|
305 CdlTkUtil::AppendString(refs, CdlTkUtil::Replace("$NAME",refName,"\tLOCAL_CDL_REF($NAME),\n")); |
|
306 } |
|
307 |
|
308 CCdlTkDataTypeTranslations& translations = iIface->DataTypeTranslations(); |
|
309 string temp; |
|
310 extra = translations.Find("TCdlArray<TCdlRef>", temp)->Definition(); |
|
311 CdlTkUtil::CReplaceSet defnSet; |
|
312 defnSet.Add("aType", temp); |
|
313 defnSet.Add("aName", pkgName); |
|
314 defnSet.Add("?array_contents", refs); |
|
315 extra = CdlTkUtil::MultiReplace(defnSet, extra); |
|
316 |
|
317 CdlTkUtil::AppendString(aImpl, impl); |
|
318 CdlTkUtil::AppendString(aExtra, extra); |
|
319 } |
|
320 |
|
321 PackageInfoLine* MasterLayoutIndex::FindLine(const PkgSize& aSize, const string& aVariant) |
|
322 { |
|
323 for (list<PackageInfoLine>::iterator pLine=iPackageInfo.begin(); pLine!=iPackageInfo.end(); ++pLine) |
|
324 { |
|
325 if (aSize.iW == (*pLine)[EWidthArg] && |
|
326 aSize.iH == (*pLine)[EHeightArg] && |
|
327 aVariant == (*pLine)[EVariantArg]) |
|
328 return &*pLine; |
|
329 } |
|
330 return NULL; |
|
331 } |
|
332 |