1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sdext.hxx"
26 
27 #include "pppoptimizertoken.hxx"
28 #include <osl/mutex.hxx>
29 #include <hash_map>
30 #include <string.h>
31 
32 struct TCheck
33 {
34 	bool operator()( const char* s1, const char* s2 ) const
35 	{
36 		return strcmp( s1, s2 ) == 0;
37 	}
38 };
39 typedef std::hash_map< const char*, PPPOptimizerTokenEnum, std::hash<const char*>, TCheck> TypeNameHashMap;
40 static TypeNameHashMap* pHashMap = NULL;
41 static ::osl::Mutex& getHashMapMutex()
42 {
43 	static osl::Mutex s_aHashMapProtection;
44 	return s_aHashMapProtection;
45 }
46 
47 struct TokenTable
48 {
49 	const char*						    pS;
50 	PPPOptimizerTokenEnum				pE;
51 };
52 
53 static const TokenTable pTokenTableArray[] =
54 {
55 	{ "rdmNavi",			TK_rdmNavi },
56 	{ "lnNavSep1",			TK_lnNavSep1 },
57 	{ "lnNavSep2",			TK_lnNavSep2 },
58 	{ "btnNavHelp",			TK_btnNavHelp },
59 	{ "btnNavBack",			TK_btnNavBack },
60 	{ "btnNavNext",			TK_btnNavNext },
61 	{ "btnNavFinish",		TK_btnNavFinish },
62 	{ "btnNavCancel",		TK_btnNavCancel },
63 
64 	{ "FixedText0Pg0",		TK_FixedText0Pg0 },
65 	{ "FixedText1Pg0",		TK_FixedText1Pg0 },
66 	{ "Separator1Pg0",		TK_Separator1Pg0 },
67 	{ "FixedText2Pg0",		TK_FixedText2Pg0 },
68 	{ "ListBox0Pg0",		TK_ListBox0Pg0 },
69 	{ "Button0Pg0",			TK_Button0Pg0 },
70 	{ "RadioButton0Pg1",	TK_RadioButton0Pg1 },
71 	{ "RadioButton1Pg1",	TK_RadioButton1Pg1 },
72 	{ "FixedText0Pg1",		TK_FixedText0Pg1 },
73 	{ "CheckBox1Pg1",		TK_CheckBox1Pg1 },
74 	{ "FixedText1Pg1",		TK_FixedText1Pg1 },
75 	{ "FixedText2Pg1",		TK_FixedText2Pg1 },
76 	{ "FormattedField0Pg1",	TK_FormattedField0Pg1 },
77 	{ "ComboBox0Pg1",		TK_ComboBox0Pg1 },
78 	{ "CheckBox2Pg1",		TK_CheckBox2Pg1 },
79 	{ "FixedText0Pg2",		TK_FixedText0Pg2 },
80 	{ "FixedText1Pg2",		TK_FixedText1Pg2 },
81 	{ "CheckBox0Pg2",		TK_CheckBox0Pg2 },
82 	{ "RadioButton0Pg2",	TK_RadioButton0Pg2 },
83 	{ "RadioButton1Pg2",	TK_RadioButton1Pg2 },
84 	{ "FixedText0Pg3",		TK_FixedText0Pg3 },
85 	{ "CheckBox0Pg3",		TK_CheckBox0Pg3 },
86 	{ "FixedText1Pg3",		TK_FixedText1Pg3 },
87 	{ "CheckBox1Pg3",		TK_CheckBox1Pg3 },
88 	{ "FixedText2Pg3",		TK_FixedText2Pg3 },
89 	{ "CheckBox2Pg3",		TK_CheckBox2Pg3 },
90 	{ "CheckBox3Pg3",		TK_CheckBox3Pg3 },
91 	{ "ListBox0Pg3",		TK_ListBox0Pg3 },
92 	{ "Separator0Pg4",		TK_Separator0Pg4 },
93 	{ "RadioButton0Pg4",	TK_RadioButton0Pg4 },
94 	{ "RadioButton1Pg4",	TK_RadioButton1Pg4 },
95 	{ "Separator1Pg4",		TK_Separator1Pg4 },
96 	{ "FixedText0Pg4",		TK_FixedText0Pg4 },
97 	{ "FixedText1Pg4",		TK_FixedText1Pg4 },
98 	{ "FixedText2Pg4",		TK_FixedText2Pg4 },
99 	{ "FixedText3Pg4",		TK_FixedText3Pg4 },
100 	{ "FixedText4Pg4",		TK_FixedText4Pg4 },
101 	{ "FixedText5Pg4",		TK_FixedText5Pg4 },
102 	{ "FixedText6Pg4",		TK_FixedText6Pg4 },
103 	{ "FixedText7Pg4",		TK_FixedText7Pg4 },
104 	{ "FixedText8Pg4",		TK_FixedText8Pg4 },
105 	{ "CheckBox1Pg4",		TK_CheckBox1Pg4 },
106 	{ "ComboBox0Pg4",		TK_ComboBox0Pg4 },
107 
108 	{ "_blank",				TK__blank },
109 	{ "_self",				TK__self },
110 	{ "Activated",			TK_Activated },
111 	{ "Align",				TK_Align },
112 	{ "Alpha",				TK_Alpha },
113 	{ "Animated",			TK_Animated },
114 	{ "Background",			TK_Background },
115 	{ "BitmapPath",			TK_BitmapPath },
116 	{ "Border",				TK_Border },
117 	{ "Closeable",			TK_Closeable },
118 	{ "ColorMode",			TK_ColorMode },
119 	{ "Complete",			TK_Complete },
120 	{ "Compression",		TK_Compression },
121 	{ "CurrentItemID",		TK_CurrentItemID },
122 	{ "DefaultButton",		TK_DefaultButton },
123 	{ "DocumentService",	TK_DocumentService },
124 	{ "Dropdown",			TK_Dropdown },
125 	{ "EffectiveValue",		TK_EffectiveValue },
126 	{ "EffectiveMin",		TK_EffectiveMin },
127 	{ "EffectiveMax",		TK_EffectiveMax },
128 	{ "Enabled",			TK_Enabled },
129 	{ "Extensions",			TK_Extensions },
130 	{ "FileSizeDestination",TK_FileSizeDestination },
131 	{ "FileSizeSource",		TK_FileSizeSource },
132 	{ "FillBitmap",			TK_FillBitmap },
133 	{ "FillBitmapLogicalSize",TK_FillBitmapLogicalSize },
134 	{ "FillBitmapMode",		TK_FillBitmapMode },
135 	{ "FillBitmapSizeX",	TK_FillBitmapSizeX },
136 	{ "FillBitmapSizeY",	TK_FillBitmapSizeY },
137 	{ "FillBitmapURL",		TK_FillBitmapURL },
138 	{ "FillStyle",			TK_FillStyle },
139 	{ "FilterData",			TK_FilterData },
140 	{ "FilterName",			TK_FilterName },
141 	{ "Flags",				TK_Flags },
142 	{ "FontDescriptor",		TK_FontDescriptor },
143 	{ "Graphic",			TK_Graphic },
144 	{ "GraphicCrop",		TK_GraphicCrop },
145 	{ "GraphicCropLogic",	TK_GraphicCropLogic },
146 	{ "GraphicURL",			TK_GraphicURL },
147 	{ "GraphicStreamURL",	TK_GraphicStreamURL },
148 	{ "Height",				TK_Height },
149 	{ "HelpFile",			TK_HelpFile },
150 	{ "Hidden",				TK_Hidden },
151 	{ "ID",					TK_ID },
152 	{ "ImageURL",			TK_ImageURL },
153 	{ "InformationDialog",	TK_InformationDialog },
154 	{ "InputStream",		TK_InputStream },
155 	{ "Interlaced",			TK_Interlaced },
156 	{ "IsInternal",			TK_IsInternal },
157 	{ "Label",				TK_Label },
158 	{ "LineCount",			TK_LineCount },
159 	{ "LogicalHeight",		TK_LogicalHeight },
160 	{ "LogicalWidth",		TK_LogicalWidth },
161 	{ "LogicalSize",		TK_LogicalSize },
162 	{ "MimeType",			TK_MimeType },
163 	{ "Moveable",			TK_Moveable },
164 	{ "MultiLine",			TK_MultiLine },
165 	{ "MultiSelection",		TK_MultiSelection },
166 	{ "Name",				TK_Name },
167 	{ "Orientation",		TK_Orientation },
168 	{ "OutputStream",		TK_OutputStream },
169 	{ "PixelHeight",		TK_PixelHeight },
170 	{ "PixelWidth",			TK_PixelWidth },
171 	{ "PositionX",			TK_PositionX },
172 	{ "PositionY",			TK_PositionY },
173 	{ "Progress",			TK_Progress },
174 	{ "ProgressValue",		TK_ProgressValue },
175 	{ "ProgressValueMax",	TK_ProgressValueMax },
176 	{ "ProgressValueMin",	TK_ProgressValueMin },
177 	{ "PushButtonType",		TK_PushButtonType },
178 	{ "Quality",			TK_Quality },
179 	{ "ReadOnly",			TK_ReadOnly },
180 	{ "Repeat",				TK_Repeat },
181 	{ "ScaleImage",			TK_ScaleImage },
182 	{ "SelectedItems",		TK_SelectedItems },
183 	{ "Settings",			TK_Settings },
184 	{ "Size100thMM",		TK_Size100thMM },
185 	{ "SizePixel",			TK_SizePixel },
186 	{ "Spin",				TK_Spin },
187 	{ "Step",				TK_Step },
188 	{ "State",				TK_State },
189 	{ "StatusDispatcher",	TK_StatusDispatcher },
190 	{ "StringItemList",		TK_StringItemList },
191 	{ "Strings",			TK_Strings },
192 	{ "TabIndex",			TK_TabIndex },
193 	{ "Template",			TK_Template },
194 	{ "Text",				TK_Text },
195 	{ "Title",				TK_Title },
196 	{ "Transparent",		TK_Transparent },
197 	{ "Type",				TK_Type },
198 	{ "UIName",				TK_UIName },
199 	{ "Value",				TK_Value },
200 	{ "Width",				TK_Width },
201 	{ "ZOrder",				TK_ZOrder },
202 
203 	{ "LastUsedSettings",	TK_LastUsedSettings },
204 	{ "Settings/Templates",	TK_Settings_Templates },
205 	{ "Settings/Templates/",TK_Settings_Templates_ },
206 	{ "JPEGCompression",	TK_JPEGCompression },
207 	{ "JPEGQuality",		TK_JPEGQuality },
208 	{ "RemoveCropArea",		TK_RemoveCropArea },
209 	{ "ImageResolution",	TK_ImageResolution },
210 	{ "EmbedLinkedGraphics",TK_EmbedLinkedGraphics },
211 	{ "OLEOptimization",	TK_OLEOptimization },
212 	{ "OLEOptimizationType",TK_OLEOptimizationType },
213 	{ "DeleteUnusedMasterPages", TK_DeleteUnusedMasterPages },
214 	{ "DeleteHiddenSlides", TK_DeleteHiddenSlides },
215 	{ "DeleteNotesPages",	TK_DeleteNotesPages },
216 	{ "CustomShowName",		TK_CustomShowName },
217 	{ "SaveAs",				TK_SaveAs },
218 	{ "SaveAsURL",			TK_SaveAsURL },
219 	{ "OpenNewDocument",	TK_OpenNewDocument },
220 	{ "EstimatedFileSize",	TK_EstimatedFileSize },
221 
222 	{ "Status",				TK_Status },
223 	{ "Pages",				TK_Pages },
224 	{ "CurrentPage",		TK_CurrentPage },
225 	{ "GraphicObjects",		TK_GraphicObjects },
226 	{ "CurrentGraphicObject",TK_CurrentGraphicObject },
227 	{ "OLEObjects",			TK_OLEObjects },
228 	{ "CurrentOLEObject",	TK_CurrentOLEObject },
229 
230 	{ "STR_SUN_OPTIMIZATION_WIZARD2",STR_SUN_OPTIMIZATION_WIZARD2 },
231 	{ "STR_STEPS",					STR_STEPS },
232 	{ "STR_HELP",					STR_HELP },
233 	{ "STR_BACK",					STR_BACK },
234 	{ "STR_NEXT",					STR_NEXT },
235 	{ "STR_FINISH",					STR_FINISH },
236 	{ "STR_CANCEL",					STR_CANCEL },
237 	{ "STR_INTRODUCTION",			STR_INTRODUCTION },
238 	{ "STR_INTRODUCTION_T",			STR_INTRODUCTION_T },
239 	{ "STR_CHOSE_SETTINGS",			STR_CHOSE_SETTINGS },
240 	{ "STR_REMOVE",					STR_REMOVE },
241 	{ "STR_GRAPHIC_OPTIMIZATION",	STR_GRAPHIC_OPTIMIZATION },
242 	{ "STR_IMAGE_OPTIMIZATION",		STR_IMAGE_OPTIMIZATION },
243 	{ "STR_LOSSLESS_COMPRESSION",	STR_LOSSLESS_COMPRESSION },
244 	{ "STR_JPEG_COMPRESSION",		STR_JPEG_COMPRESSION },
245 	{ "STR_QUALITY",				STR_QUALITY },
246 	{ "STR_REMOVE_CROP_AREA",		STR_REMOVE_CROP_AREA },
247 	{ "STR_IMAGE_RESOLUTION",		STR_IMAGE_RESOLUTION },
248 	{ "STR_IMAGE_RESOLUTION_0",		STR_IMAGE_RESOLUTION_0 },
249 	{ "STR_IMAGE_RESOLUTION_1",		STR_IMAGE_RESOLUTION_1 },
250 	{ "STR_IMAGE_RESOLUTION_2",		STR_IMAGE_RESOLUTION_2 },
251 	{ "STR_IMAGE_RESOLUTION_3",		STR_IMAGE_RESOLUTION_3 },
252 	{ "STR_EMBED_LINKED_GRAPHICS",	STR_EMBED_LINKED_GRAPHICS },
253 	{ "STR_OLE_OBJECTS",			STR_OLE_OBJECTS },
254 	{ "STR_OLE_OPTIMIZATION",		STR_OLE_OPTIMIZATION },
255 	{ "STR_OLE_REPLACE",			STR_OLE_REPLACE },
256 	{ "STR_ALL_OLE_OBJECTS",		STR_ALL_OLE_OBJECTS },
257 	{ "STR_ALIEN_OLE_OBJECTS_ONLY",	STR_ALIEN_OLE_OBJECTS_ONLY },
258 	{ "STR__OLE_OBJECTS_DESC",		STR_OLE_OBJECTS_DESC },
259 	{ "STR_NO_OLE_OBJECTS_DESC",	STR_NO_OLE_OBJECTS_DESC },
260 	{ "STR_SLIDES",					STR_SLIDES },
261 	{ "STR_CHOOSE_SLIDES",			STR_CHOOSE_SLIDES },
262 	{ "STR_MASTER_PAGES",			STR_MASTER_PAGES },
263 	{ "STR_DELETE_MASTER_PAGES",	STR_DELETE_MASTER_PAGES },
264 	{ "STR_DELETE_NOTES_PAGES",		STR_DELETE_NOTES_PAGES },
265 	{ "STR_DELETE_HIDDEN_SLIDES",	STR_DELETE_HIDDEN_SLIDES },
266 	{ "STR_CUSTOM_SHOW",			STR_CUSTOM_SHOW },
267 	{ "STR_SUMMARY",				STR_SUMMARY },
268 	{ "STR_SUMMARY_TITLE",			STR_SUMMARY_TITLE },
269 	{ "STR_PROGRESS",				STR_PROGRESS },
270 	{ "STR_OBJECTS_OPTIMIZED",		STR_OBJECTS_OPTIMIZED },
271 	{ "STR_APPLY_TO_CURRENT",		STR_APPLY_TO_CURRENT },
272 	{ "STR_AUTOMATICALLY_OPEN",		STR_AUTOMATICALLY_OPEN },
273 	{ "STR_SAVE_SETTINGS",			STR_SAVE_SETTINGS },
274 	{ "STR_SAVE_AS",				STR_SAVE_AS },
275 	{ "STR_DELETE_SLIDES",			STR_DELETE_SLIDES },
276 	{ "STR_OPTIMIZE_IMAGES",		STR_OPTIMIZE_IMAGES },
277 	{ "STR_CREATE_REPLACEMENT",		STR_CREATE_REPLACEMENT },
278 	{ "STR_CURRENT_FILESIZE",		STR_CURRENT_FILESIZE },
279 	{ "STR_ESTIMATED_FILESIZE",		STR_ESTIMATED_FILESIZE },
280 	{ "STR_MB",						STR_MB },
281 	{ "MY_SETTINGS",				STR_MY_SETTINGS },
282 	{ "STR_DEFAULT_SESSION",		STR_DEFAULT_SESSION },
283 	{ "STR_MODIFY_WARNING",			STR_MODIFY_WARNING },
284 	{ "STR_YES",					STR_YES },
285 	{ "STR_OK",						STR_OK },
286 	{ "STR_INFO_1",					STR_INFO_1 },
287 	{ "STR_INFO_2",					STR_INFO_2 },
288 	{ "STR_INFO_3",					STR_INFO_3 },
289 	{ "STR_INFO_4",					STR_INFO_4 },
290 	{ "STR_DUPLICATING_PRESENTATION",STR_DUPLICATING_PRESENTATION },
291 	{ "STR_DELETING_SLIDES",		STR_DELETING_SLIDES },
292 	{ "STR_OPTIMIZING_GRAPHICS",	STR_OPTIMIZING_GRAPHICS },
293 	{ "STR_CREATING_OLE_REPLACEMENTS",STR_CREATING_OLE_REPLACEMENTS },
294 	{ "STR_FileSizeSeparator",		STR_FILESIZESEPARATOR },
295 
296 	{ "Last",				TK_Last },
297 	{ "NotFound",			TK_NotFound }
298 };
299 
300 PPPOptimizerTokenEnum TKGet( const rtl::OUString& rToken )
301 {
302 	if ( !pHashMap )
303 	{	// init hash map
304 		::osl::MutexGuard aGuard( getHashMapMutex() );
305 		if ( !pHashMap )
306 		{
307 			TypeNameHashMap* pH = new TypeNameHashMap;
308 			const TokenTable* pPtr = pTokenTableArray;
309 			const TokenTable* pEnd = pPtr + ( sizeof( pTokenTableArray ) / sizeof( TokenTable ) );
310 			for ( ; pPtr < pEnd; pPtr++ )
311 				(*pH)[ pPtr->pS ] = pPtr->pE;
312 			pHashMap = pH;
313 		}
314 	}
315 	PPPOptimizerTokenEnum eRetValue = TK_NotFound;
316 	int i, nLen = rToken.getLength();
317 	char* pBuf = new char[ nLen + 1 ];
318 	for ( i = 0; i < nLen; i++ )
319 		pBuf[ i ] = (char)rToken[ i ];
320 	pBuf[ i ] = 0;
321 	TypeNameHashMap::iterator aHashIter( pHashMap->find( pBuf ) );
322 	delete[] pBuf;
323 	if ( aHashIter != pHashMap->end() )
324 		eRetValue = (*aHashIter).second;
325 	return eRetValue;
326 }
327 
328 rtl::OUString TKGet( const PPPOptimizerTokenEnum eToken )
329 {
330 	sal_uInt32 i = eToken >= TK_Last
331 		? (sal_uInt32)TK_NotFound
332 		: (sal_uInt32)eToken;
333 	return rtl::OUString::createFromAscii( pTokenTableArray[ i ].pS );
334 }
335