xref: /aoo41x/main/svx/source/xoutdev/xtabcolr.cxx (revision 35726d9d)
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 // MARKER(update_precomp.py): autogen include statement, do not remove
23 #include "precompiled_svx.hxx"
24 
25 #include <com/sun/star/container/XNameContainer.hpp>
26 #include "svx/XPropertyTable.hxx"
27 #include <unotools/ucbstreamhelper.hxx>
28 #include <unotools/pathoptions.hxx>
29 #include "xmlxtexp.hxx"
30 #include "xmlxtimp.hxx"
31 #include <sfx2/docfile.hxx>
32 #include <tools/urlobj.hxx>
33 #include <svx/dialogs.hrc>
34 #include <svx/dialmgr.hxx>
35 #include <svx/xtable.hxx>
36 #include <svx/xpool.hxx>
37 
38 #define GLOBALOVERFLOW
39 
40 using namespace com::sun::star;
41 using namespace rtl;
42 
43 sal_Unicode const pszExtColor[]	 = {'s','o','c'};
44 
45 static char const aChckColor[]  = { 0x04, 0x00, 'S','O','C','L'};	// < 5.2
46 static char const aChckColor0[] = { 0x04, 0x00, 'S','O','C','0'};	// = 5.2
47 static char const aChckXML[]    = { '<', '?', 'x', 'm', 'l' };		// = 6.0
48 
49 /*************************************************************************
50 |*
51 |* XColorList::XColorList()
52 |*
53 *************************************************************************/
54 
55 static XColorListSharedPtr aStaticGlobalColorList;
56 
57 XColorList::XColorList( const String& rPath ) :
58 				XPropertyList( rPath )
59 {
60 }
61 
62 /************************************************************************/
63 
64 XColorList::~XColorList()
65 {
66 }
67 
68 /************************************************************************/
69 
70 XColorEntry* XColorList::Replace(XColorEntry* pEntry, long nIndex )
71 {
72 	return (XColorEntry*) XPropertyList::Replace(pEntry, nIndex);
73 }
74 
75 /************************************************************************/
76 
77 XColorEntry* XColorList::Remove(long nIndex)
78 {
79 	return (XColorEntry*) XPropertyList::Remove(nIndex);
80 }
81 
82 /************************************************************************/
83 
84 XColorEntry* XColorList::GetColor(long nIndex) const
85 {
86 	return (XColorEntry*) XPropertyList::Get(nIndex);
87 }
88 
89 /************************************************************************/
90 
91 sal_Bool XColorList::Load()
92 {
93 	if( mbListDirty )
94 	{
95 		mbListDirty = false;
96 
97 		INetURLObject aURL( maPath );
98 
99 		if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
100 		{
101 			OSL_ENSURE( !maPath.Len(), "invalid URL" );
102 			return sal_False;
103 		}
104 
105 		aURL.Append( maName );
106 
107 		if( !aURL.getExtension().getLength() )
108 			aURL.setExtension( rtl::OUString( pszExtColor, 3 ) );
109 
110 		uno::Reference< container::XNameContainer > xTable( SvxUnoXColorTable_createInstance( this ), uno::UNO_QUERY );
111 		return SvxXMLXTableImport::load( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable );
112 	}
113 	return( sal_False );
114 }
115 
116 /************************************************************************/
117 
118 sal_Bool XColorList::Save()
119 {
120 	INetURLObject aURL( maPath );
121 
122 	if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
123 	{
124 		OSL_ENSURE( !maPath.Len(), "invalid URL" );
125 		return sal_False;
126 	}
127 
128 	aURL.Append( maName );
129 
130 	if( !aURL.getExtension().getLength() )
131 		aURL.setExtension( rtl::OUString( pszExtColor, 3 ) );
132 
133 	uno::Reference< container::XNameContainer > xTable( SvxUnoXColorTable_createInstance( this ), uno::UNO_QUERY );
134 	return SvxXMLXTableExportComponent::save( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable );
135 }
136 
137 /************************************************************************/
138 
139 sal_Bool XColorList::Create()
140 {
141 	XubString aStr;
142 	xub_StrLen nLen;
143 	ResMgr& rRes = DIALOG_MGR();
144 
145 	static sal_uInt16 __READONLY_DATA aResId[] =
146 	{
147 		RID_SVXSTR_BLACK,
148 		RID_SVXSTR_BLUE,
149 		RID_SVXSTR_GREEN,
150 		RID_SVXSTR_CYAN,
151 		RID_SVXSTR_RED,
152 		RID_SVXSTR_MAGENTA,
153 		RID_SVXSTR_BROWN,
154 		RID_SVXSTR_GREY,
155 		RID_SVXSTR_LIGHTGREY,
156 		RID_SVXSTR_LIGHTBLUE,
157 		RID_SVXSTR_LIGHTGREEN,
158 		RID_SVXSTR_LIGHTCYAN,
159 		RID_SVXSTR_LIGHTRED,
160 		RID_SVXSTR_LIGHTMAGENTA,
161 		RID_SVXSTR_YELLOW,
162 		RID_SVXSTR_WHITE
163 	};
164 
165 	// MT: COL_XXX ist in VCL kein enum mehr!!!
166 	// COL_WHITE ist seeeehr gross! ( => Zugriff ueber das obige Array hinweg )
167 	// Mit der unteren Schleife gibt es keinen Absturtz, aber es ist
168 	// alles schwarz, weil alles kleine Werte.
169 	// Ausserdem ist die ganze Vorgehensweise laut MM sehr unperformant
170 	// => lieber gleich Stringlisten laden.
171 
172 	// BM: ifndef VCL part removed (deprecated)
173 
174 	static ColorData __READONLY_DATA aColTab[] =
175 	{
176 		COL_BLACK,
177 		COL_BLUE,
178 		COL_GREEN,
179 		COL_CYAN,
180 		COL_RED,
181 		COL_MAGENTA,
182 		COL_BROWN,
183 		COL_GRAY,
184 		COL_LIGHTGRAY,
185 		COL_LIGHTBLUE,
186 		COL_LIGHTGREEN,
187 		COL_LIGHTCYAN,
188 		COL_LIGHTRED,
189 		COL_LIGHTMAGENTA,
190 		COL_YELLOW,
191 		COL_WHITE
192 	};
193 
194 	for( sal_uInt16 n = 0; n < 16; ++n )
195 	{
196 		Insert( new XColorEntry( Color( aColTab[n] ), String( ResId( aResId[ n ], rRes )) ), n );
197 	}
198 
199 	aStr = SVX_RESSTR( RID_SVXSTR_GREY );
200 	aStr.AppendAscii(" 80%");
201 	nLen = aStr.Len() - 3;
202 	Insert( new XColorEntry( Color( 51, 51, 51 ), aStr ) , 16);
203 	aStr.SetChar(nLen, sal_Unicode('7'));
204 	Insert( new XColorEntry( Color( 76, 76, 76 ), aStr ) , 17);
205 	aStr.SetChar(nLen, sal_Unicode('6'));
206 	Insert( new XColorEntry( Color(102,102,102 ), aStr ) , 18);
207 	aStr.SetChar(nLen, sal_Unicode('4'));
208 	Insert( new XColorEntry( Color(153,153,153 ), aStr ) , 19);
209 	aStr.SetChar(nLen, sal_Unicode('3'));
210 	Insert( new XColorEntry( Color(179,179,179 ), aStr ) , 20);
211 	aStr.SetChar(nLen, sal_Unicode('2'));
212 	Insert( new XColorEntry( Color(204,204,204 ), aStr ) , 21);
213 	// BM: new 15%
214 	aStr.SetChar(nLen, sal_Unicode('1'));
215 	aStr.SetChar(nLen + 1, sal_Unicode('5'));
216 	Insert( new XColorEntry( Color(217,217,217 ), aStr ) , 22);
217 	aStr.SetChar(nLen + 1, sal_Unicode('0'));
218 	Insert( new XColorEntry( Color(230,230,230 ), aStr ) , 23);
219 	Insert( new XColorEntry( Color(230,230,255 ), SVX_RESSTR( RID_SVXSTR_BLUEGREY ) ) , 24);
220 
221 	aStr = SVX_RESSTR( RID_SVXSTR_RED );
222 	aStr.AppendAscii(" 1");
223 	nLen = aStr.Len() - 1;
224 	Insert( new XColorEntry( Color(255, 51,102 ), aStr ) , 25);
225 	aStr.SetChar(nLen, sal_Unicode('2'));
226 	Insert( new XColorEntry( Color(220, 35,  0 ), aStr ) , 26);
227 	aStr.SetChar(nLen, sal_Unicode('3'));
228 	Insert( new XColorEntry( Color(184, 71,  0 ), aStr ) , 27);
229 	aStr.SetChar(nLen, sal_Unicode('4'));
230 	Insert( new XColorEntry( Color(255, 51, 51 ), aStr ) , 28);
231 	aStr.SetChar(nLen, sal_Unicode('5'));
232 	Insert( new XColorEntry( Color(235, 97, 61 ), aStr ) , 29);
233 	aStr.SetChar(nLen, sal_Unicode('6'));
234 	Insert( new XColorEntry( Color(184, 71, 71 ), aStr ) , 30);
235 	aStr.SetChar(nLen, sal_Unicode('7'));
236 	Insert( new XColorEntry( Color(184,  0, 71 ), aStr ) , 31);
237 	aStr.SetChar(nLen, sal_Unicode('8'));
238 	Insert( new XColorEntry( Color(153, 40, 76 ), aStr ) , 32);
239 
240 	aStr = SVX_RESSTR( RID_SVXSTR_MAGENTA );
241 	aStr.AppendAscii(" 1");
242 	nLen = aStr.Len() - 1;
243 	Insert( new XColorEntry( Color(148,  0,107 ), aStr ) , 33);
244 	aStr.SetChar(nLen, sal_Unicode('2'));
245 	Insert( new XColorEntry( Color(148, 71,107 ), aStr ) , 34);
246 	aStr.SetChar(nLen, sal_Unicode('3'));
247 	Insert( new XColorEntry( Color(148, 71,148 ), aStr ) , 35);
248 	aStr.SetChar(nLen, sal_Unicode('4'));
249 	Insert( new XColorEntry( Color(153,102,204 ), aStr ) , 36);
250 	aStr.SetChar(nLen, sal_Unicode('5'));
251 	Insert( new XColorEntry( Color(107, 71,148 ), aStr ) , 37);
252 	aStr.SetChar(nLen, sal_Unicode('6'));
253 	Insert( new XColorEntry( Color(107, 35,148 ), aStr ) , 38);
254 	aStr.SetChar(nLen, sal_Unicode('7'));
255 	Insert( new XColorEntry( Color(107,  0,148 ), aStr ) , 39);
256 	aStr.SetChar(nLen, sal_Unicode('8'));
257 	Insert( new XColorEntry( Color( 94, 17,166 ), aStr ) , 40);
258 
259 	aStr = SVX_RESSTR( RID_SVXSTR_BLUE );
260 	aStr.AppendAscii(" 1");
261 	nLen = aStr.Len() - 1;
262 	Insert( new XColorEntry( Color( 40,  0,153 ), aStr ) , 41);
263 	aStr.SetChar(nLen, sal_Unicode('2'));
264 	Insert( new XColorEntry( Color( 71,  0,184 ), aStr ) , 42);
265 	aStr.SetChar(nLen, sal_Unicode('3'));
266 	Insert( new XColorEntry( Color( 35,  0,220 ), aStr ) , 43);
267 	aStr.SetChar(nLen, sal_Unicode('4'));
268 	Insert( new XColorEntry( Color( 35, 35,220 ), aStr ) , 44);
269 	aStr.SetChar(nLen, sal_Unicode('5'));
270 	Insert( new XColorEntry( Color(  0, 71,255 ), aStr ) , 45);
271 	aStr.SetChar(nLen, sal_Unicode('6'));
272 	Insert( new XColorEntry( Color(  0,153,255 ), aStr ) , 46);
273 	aStr.SetChar(nLen, sal_Unicode('7'));
274 	Insert( new XColorEntry( Color(  0,184,255 ), aStr ) , 47);
275 	aStr.SetChar(nLen, sal_Unicode('8'));
276 	Insert( new XColorEntry( Color(153,204,255 ), aStr ) , 48);
277 	//Insert(48, new XColorEntry( Color( 46,215,255 ), aStr ) );
278 
279 	aStr = SVX_RESSTR( RID_SVXSTR_CYAN );
280 	aStr.AppendAscii(" 1");
281 	nLen = aStr.Len() - 1;
282 	Insert( new XColorEntry( Color(  0,220,255 ), aStr ) , 49);
283 	aStr.SetChar(nLen, sal_Unicode('2'));
284 	Insert( new XColorEntry( Color(  0,204,204 ), aStr ) , 50);
285 	aStr.SetChar(nLen, sal_Unicode('3'));
286 	Insert( new XColorEntry( Color( 35,184,220 ), aStr ) , 51);
287 	aStr.SetChar(nLen, sal_Unicode('4'));
288 	Insert( new XColorEntry( Color( 71,184,184 ), aStr ) , 52);
289 	aStr.SetChar(nLen, sal_Unicode('5'));
290 	Insert( new XColorEntry( Color( 51,163,163 ), aStr ) , 53);
291 	aStr.SetChar(nLen, sal_Unicode('6'));
292 	Insert( new XColorEntry( Color( 25,138,138 ), aStr ) , 54);
293 	aStr.SetChar(nLen, sal_Unicode('7'));
294 	Insert( new XColorEntry( Color(  0,107,107 ), aStr ) , 55);
295 	aStr.SetChar(nLen, sal_Unicode('8'));
296 	Insert( new XColorEntry( Color(  0, 74, 74 ), aStr ) , 56);
297 
298 	aStr = SVX_RESSTR( RID_SVXSTR_GREEN );
299 	aStr.AppendAscii(" 1");
300 	nLen = aStr.Len() - 1;
301 	Insert( new XColorEntry( Color( 53, 94,  0 ), aStr ) , 57);
302 	aStr.SetChar(nLen, sal_Unicode('2'));
303 	Insert( new XColorEntry( Color( 92,133, 38 ), aStr ) , 58);
304 	aStr.SetChar(nLen, sal_Unicode('3'));
305 	Insert( new XColorEntry( Color(125,166, 71 ), aStr ) , 59);
306 	aStr.SetChar(nLen, sal_Unicode('4'));
307 	Insert( new XColorEntry( Color(148,189, 94 ), aStr ) , 60);
308 	aStr.SetChar(nLen, sal_Unicode('5'));
309 	Insert( new XColorEntry( Color(  0,174,  0 ), aStr ) , 61);
310 	aStr.SetChar(nLen, sal_Unicode('6'));
311 	Insert( new XColorEntry( Color( 51,204,102 ), aStr ) , 62);
312 	aStr.SetChar(nLen, sal_Unicode('7'));
313 	Insert( new XColorEntry( Color( 61,235, 61 ), aStr ) , 63);
314 	aStr.SetChar(nLen, sal_Unicode('8'));
315 	Insert( new XColorEntry( Color( 35,255, 35 ), aStr ) , 64);
316 
317 	aStr = SVX_RESSTR( RID_SVXSTR_YELLOW );
318 	aStr.AppendAscii(" 1");
319 	nLen = aStr.Len() - 1;
320 	Insert( new XColorEntry( Color(230,255,  0 ), aStr ) , 65);
321 	aStr.SetChar(nLen, sal_Unicode('2'));
322 	Insert( new XColorEntry( Color(255,255,153 ), aStr ) , 66);
323 	aStr.SetChar(nLen, sal_Unicode('3'));
324 	Insert( new XColorEntry( Color(255,255,102 ), aStr ) , 67);
325 	aStr.SetChar(nLen, sal_Unicode('4'));
326 	Insert( new XColorEntry( Color(230,230, 76 ), aStr ) , 68);
327 	aStr.SetChar(nLen, sal_Unicode('5'));
328 	Insert( new XColorEntry( Color(204,204,  0 ), aStr ) , 69);
329 	aStr.SetChar(nLen, sal_Unicode('6'));
330 	Insert( new XColorEntry( Color(179,179,  0 ), aStr ) , 70);
331 	aStr.SetChar(nLen, sal_Unicode('7'));
332 	Insert( new XColorEntry( Color(128,128, 25 ), aStr ) , 71);
333 	aStr.SetChar(nLen, sal_Unicode('8'));
334 	Insert( new XColorEntry( Color(102,102,  0 ), aStr ) , 72);
335 
336 	aStr = SVX_RESSTR( RID_SVXSTR_BROWN );
337 	aStr.AppendAscii(" 1");
338 	nLen = aStr.Len() - 1;
339 	Insert( new XColorEntry( Color( 76, 25,  0 ), aStr ) , 73);
340 	aStr.SetChar(nLen, sal_Unicode('2'));
341 	Insert( new XColorEntry( Color(102, 51,  0 ), aStr ) , 74);
342 	aStr.SetChar(nLen, sal_Unicode('3'));
343 	Insert( new XColorEntry( Color(128, 76, 25 ), aStr ) , 75);
344 	aStr.SetChar(nLen, sal_Unicode('4'));
345 	Insert( new XColorEntry( Color(153,102, 51 ), aStr ) , 76);
346 
347 	aStr = SVX_RESSTR( RID_SVXSTR_ORANGE );
348 	aStr.AppendAscii(" 1");
349 	nLen = aStr.Len() - 1;
350 	Insert( new XColorEntry( Color(204,102, 51 ), aStr ) , 77);
351 	aStr.SetChar(nLen, sal_Unicode('2'));
352 	Insert( new XColorEntry( Color(255,102, 51 ), aStr ) , 78);
353 	aStr.SetChar(nLen, sal_Unicode('3'));
354 	Insert( new XColorEntry( Color(255,153,102 ), aStr ) , 79);
355 	aStr.SetChar(nLen, sal_Unicode('4'));
356 	Insert( new XColorEntry( Color(255,204,153 ), aStr ) , 80);
357 
358 	// new chart colors
359 	aStr = SVX_RESSTR( RID_SVXSTR_VIOLET );
360 	Insert( new XColorEntry( Color( 0x99, 0x99, 0xff ), aStr ) , 81);
361 
362 	aStr = SVX_RESSTR( RID_SVXSTR_BORDEAUX );
363 	Insert( new XColorEntry( Color( 0x99, 0x33, 0x66 ), aStr ) , 82);
364 
365 	aStr = SVX_RESSTR( RID_SVXSTR_PALE_YELLOW );
366 	Insert( new XColorEntry( Color( 0xff, 0xff, 0xcc ), aStr ) , 83);
367 
368 	aStr = SVX_RESSTR( RID_SVXSTR_PALE_GREEN );
369 	Insert( new XColorEntry( Color( 0xcc, 0xff, 0xff ), aStr ) , 84);
370 
371 	aStr = SVX_RESSTR( RID_SVXSTR_DKVIOLET );
372 	Insert( new XColorEntry( Color( 0x66, 0x00, 0x66 ), aStr ) , 85);
373 
374 	aStr = SVX_RESSTR( RID_SVXSTR_SALMON );
375 	Insert( new XColorEntry( Color( 0xff, 0x80, 0x80 ), aStr ) , 86);
376 
377 	aStr = SVX_RESSTR( RID_SVXSTR_SEABLUE );
378 	Insert( new XColorEntry( Color( 0x00, 0x66, 0xcc ), aStr ) , 87);
379 
380 	// Sun colors
381 	aStr = SVX_RESSTR( RID_SVXSTR_COLOR_SUN );
382 	aStr.AppendAscii(" 1");
383 	nLen = aStr.Len() - 1;
384 	Insert( new XColorEntry( Color( 0x33, 0x33, 0x66 ), aStr ) , 88);
385 	aStr.SetChar(nLen, sal_Unicode('2'));
386 	Insert( new XColorEntry( Color( 0x66, 0x66, 0x99 ), aStr ) , 89);
387 	aStr.SetChar(nLen, sal_Unicode('3'));
388 	Insert( new XColorEntry( Color( 0x99, 0x99, 0xcc ), aStr ) , 90);
389 	aStr.SetChar(nLen, sal_Unicode('4'));
390 	Insert( new XColorEntry( Color( 0xcc, 0xcc, 0xff ), aStr ) , 91);
391 
392     // Chart default colors
393     aStr = SVX_RESSTR( RID_SVXSTR_COLOR_CHART );
394     aStr.AppendAscii(" 1");
395     nLen = aStr.Len() - 1;
396     Insert( new XColorEntry( Color( 0x00, 0x45, 0x86 ), aStr ) , 92);
397     aStr.SetChar(nLen, sal_Unicode('2'));
398     Insert( new XColorEntry( Color( 0xff, 0x42, 0x0e ), aStr ) , 93);
399     aStr.SetChar(nLen, sal_Unicode('3'));
400     Insert( new XColorEntry( Color( 0xff, 0xd3, 0x20 ), aStr ) , 94);
401     aStr.SetChar(nLen, sal_Unicode('4'));
402     Insert( new XColorEntry( Color( 0x57, 0x9d, 0x1c ), aStr ) , 95);
403     aStr.SetChar(nLen, sal_Unicode('5'));
404     Insert( new XColorEntry( Color( 0x7e, 0x00, 0x21 ), aStr ) , 96);
405     aStr.SetChar(nLen, sal_Unicode('6'));
406     Insert( new XColorEntry( Color( 0x83, 0xca, 0xff ), aStr ) , 97);
407     aStr.SetChar(nLen, sal_Unicode('7'));
408     Insert( new XColorEntry( Color( 0x31, 0x40, 0x04 ), aStr ) , 98);
409     aStr.SetChar(nLen, sal_Unicode('8'));
410     Insert( new XColorEntry( Color( 0xae, 0xcf, 0x00 ), aStr ) , 99);
411     aStr.SetChar(nLen, sal_Unicode('9'));
412     Insert( new XColorEntry( Color( 0x4b, 0x1f, 0x6f ), aStr ) , 100);
413     aStr.SetChar(nLen, sal_Unicode('1'));
414     aStr.AppendAscii("0");
415     nLen = aStr.Len() - 1;
416     Insert( new XColorEntry( Color( 0xff, 0x95, 0x0e ), aStr ) , 101);
417     aStr.SetChar(nLen, sal_Unicode('1'));
418     Insert( new XColorEntry( Color( 0xc5, 0x00, 0x0b ), aStr ) , 102);
419     aStr.SetChar(nLen, sal_Unicode('2'));
420     Insert( new XColorEntry( Color( 0x00, 0x84, 0xd1 ), aStr ) , 103);
421 
422 	return( Count() == 104 );
423 }
424 
425 /************************************************************************/
426 
427 Bitmap XColorList::CreateBitmapForUI( long /*nIndex*/ )
428 {
429 	return Bitmap();
430 }
431 
432 /************************************************************************/
433 
434 XColorListSharedPtr XColorList::GetStdColorList()
435 {
436     if ( !aStaticGlobalColorList.get() )
437     {
438         aStaticGlobalColorList = XPropertyListFactory::CreateSharedXColorList(SvtPathOptions().GetPalettePath());
439     }
440 
441     return aStaticGlobalColorList;
442 }
443 
444 // eof
445