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