1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xtabcolr.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
36 #include <com/sun/star/container/XNameContainer.hpp>
37 #include "XPropertyTable.hxx"
38 #include <unotools/ucbstreamhelper.hxx>
40 #include <svtools/pathoptions.hxx>
42 #include "xmlxtexp.hxx"
43 #include "xmlxtimp.hxx"
47 #include <sfx2/docfile.hxx>
48 #include <tools/urlobj.hxx>
49 #include <svx/dialogs.hrc>
50 #include <svx/dialmgr.hxx>
51 #include <svx/xtable.hxx>
52 #include <svx/xpool.hxx>
54 #define GLOBALOVERFLOW
56 using namespace com::sun::star
;
59 sal_Unicode
const pszExtColor
[] = {'s','o','c'};
61 static char const aChckColor
[] = { 0x04, 0x00, 'S','O','C','L'}; // < 5.2
62 static char const aChckColor0
[] = { 0x04, 0x00, 'S','O','C','0'}; // = 5.2
63 static char const aChckXML
[] = { '<', '?', 'x', 'm', 'l' }; // = 6.0
69 static XColorTable
* pTable
=0;
71 /*************************************************************************
73 |* XColorTable::XColorTable()
75 *************************************************************************/
77 XColorTable::XColorTable( const String
& rPath
,
78 XOutdevItemPool
* pInPool
,
79 USHORT nInitSize
, USHORT nReSize
) :
80 XPropertyTable( rPath
, pInPool
, nInitSize
, nReSize
)
82 // ColorTable braucht keine eigene BmpTable
83 // pBmpTable = new Table( nInitSize, nReSize );
86 /************************************************************************/
88 XColorTable::~XColorTable()
92 XColorTable
* XColorTable::GetStdColorTable()
95 pTable
= new XColorTable( SvtPathOptions().GetPalettePath() );
99 /************************************************************************/
101 XColorEntry
* XColorTable::Replace(long nIndex
, XColorEntry
* pEntry
)
103 return (XColorEntry
*) XPropertyTable::Replace(nIndex
, pEntry
);
106 /************************************************************************/
108 XColorEntry
* XColorTable::Remove(long nIndex
)
110 return (XColorEntry
*) XPropertyTable::Remove(nIndex
, 0);
113 /************************************************************************/
115 XColorEntry
* XColorTable::GetColor(long nIndex
) const
117 return (XColorEntry
*) XPropertyTable::Get(nIndex
, 0);
120 /************************************************************************/
122 BOOL
XColorTable::Load()
128 INetURLObject
aURL( aPath
);
130 if( INET_PROT_NOT_VALID
== aURL
.GetProtocol() )
132 DBG_ASSERT( !aPath
.Len(), "invalid URL" );
136 aURL
.Append( aName
);
138 if( !aURL
.getExtension().getLength() )
139 aURL
.setExtension( rtl::OUString( pszExtColor
, 3 ) );
141 uno::Reference
< container::XNameContainer
> xTable( SvxUnoXColorTable_createInstance( this ), uno::UNO_QUERY
);
142 return SvxXMLXTableImport::load( aURL
.GetMainURL( INetURLObject::NO_DECODE
), xTable
);
147 /************************************************************************/
149 BOOL
XColorTable::Save()
151 INetURLObject
aURL( aPath
);
153 if( INET_PROT_NOT_VALID
== aURL
.GetProtocol() )
155 DBG_ASSERT( !aPath
.Len(), "invalid URL" );
159 aURL
.Append( aName
);
161 if( !aURL
.getExtension().getLength() )
162 aURL
.setExtension( rtl::OUString( pszExtColor
, 3 ) );
164 uno::Reference
< container::XNameContainer
> xTable( SvxUnoXColorTable_createInstance( this ), uno::UNO_QUERY
);
165 return SvxXMLXTableExportComponent::save( aURL
.GetMainURL( INetURLObject::NO_DECODE
), xTable
);
168 /************************************************************************/
170 BOOL
XColorTable::Create()
174 ResMgr
& rRes
= DIALOG_MGR();
176 static USHORT __READONLY_DATA aResId
[] =
186 RID_SVXSTR_LIGHTGREY
,
187 RID_SVXSTR_LIGHTBLUE
,
188 RID_SVXSTR_LIGHTGREEN
,
189 RID_SVXSTR_LIGHTCYAN
,
191 RID_SVXSTR_LIGHTMAGENTA
,
196 // MT: COL_XXX ist in VCL kein enum mehr!!!
197 // COL_WHITE ist seeeehr gross! ( => Zugriff ueber das obige Array hinweg )
198 // Mit der unteren Schleife gibt es keinen Absturtz, aber es ist
199 // alles schwarz, weil alles kleine Werte.
200 // Ausserdem ist die ganze Vorgehensweise laut MM sehr unperformant
201 // => lieber gleich Stringlisten laden.
203 // BM: ifndef VCL part removed (deprecated)
205 static ColorData __READONLY_DATA aColTab
[] =
225 for( USHORT n
= 0; n
< 16; ++n
)
227 Insert( n
, new XColorEntry( Color( aColTab
[n
] ),
228 String( ResId( aResId
[ n
], rRes
)) ) );
231 aStr
= SVX_RESSTR( RID_SVXSTR_GREY
);
232 aStr
.AppendAscii(" 80%");
233 nLen
= aStr
.Len() - 3;
234 Insert(16, new XColorEntry( Color( 51, 51, 51 ), aStr
) );
235 aStr
.SetChar(nLen
, sal_Unicode('7'));
236 Insert(17, new XColorEntry( Color( 76, 76, 76 ), aStr
) );
237 aStr
.SetChar(nLen
, sal_Unicode('6'));
238 Insert(18, new XColorEntry( Color(102,102,102 ), aStr
) );
239 aStr
.SetChar(nLen
, sal_Unicode('4'));
240 Insert(19, new XColorEntry( Color(153,153,153 ), aStr
) );
241 aStr
.SetChar(nLen
, sal_Unicode('3'));
242 Insert(20, new XColorEntry( Color(179,179,179 ), aStr
) );
243 aStr
.SetChar(nLen
, sal_Unicode('2'));
244 Insert(21, new XColorEntry( Color(204,204,204 ), aStr
) );
246 aStr
.SetChar(nLen
, sal_Unicode('1'));
247 aStr
.SetChar(nLen
+ 1, sal_Unicode('5'));
248 Insert(22, new XColorEntry( Color(217,217,217 ), aStr
) );
249 aStr
.SetChar(nLen
+ 1, sal_Unicode('0'));
250 Insert(23, new XColorEntry( Color(230,230,230 ), aStr
) );
251 Insert(24, new XColorEntry( Color(230,230,255 ), SVX_RESSTR( RID_SVXSTR_BLUEGREY
) ) );
253 aStr
= SVX_RESSTR( RID_SVXSTR_RED
);
254 aStr
.AppendAscii(" 1");
255 nLen
= aStr
.Len() - 1;
256 Insert(25, new XColorEntry( Color(255, 51,102 ), aStr
) );
257 aStr
.SetChar(nLen
, sal_Unicode('2'));
258 Insert(26, new XColorEntry( Color(220, 35, 0 ), aStr
) );
259 aStr
.SetChar(nLen
, sal_Unicode('3'));
260 Insert(27, new XColorEntry( Color(184, 71, 0 ), aStr
) );
261 aStr
.SetChar(nLen
, sal_Unicode('4'));
262 Insert(28, new XColorEntry( Color(255, 51, 51 ), aStr
) );
263 aStr
.SetChar(nLen
, sal_Unicode('5'));
264 Insert(29, new XColorEntry( Color(235, 97, 61 ), aStr
) );
265 aStr
.SetChar(nLen
, sal_Unicode('6'));
266 Insert(30, new XColorEntry( Color(184, 71, 71 ), aStr
) );
267 aStr
.SetChar(nLen
, sal_Unicode('7'));
268 Insert(31, new XColorEntry( Color(184, 0, 71 ), aStr
) );
269 aStr
.SetChar(nLen
, sal_Unicode('8'));
270 Insert(32, new XColorEntry( Color(153, 40, 76 ), aStr
) );
272 aStr
= SVX_RESSTR( RID_SVXSTR_MAGENTA
);
273 aStr
.AppendAscii(" 1");
274 nLen
= aStr
.Len() - 1;
275 Insert(33, new XColorEntry( Color(148, 0,107 ), aStr
) );
276 aStr
.SetChar(nLen
, sal_Unicode('2'));
277 Insert(34, new XColorEntry( Color(148, 71,107 ), aStr
) );
278 aStr
.SetChar(nLen
, sal_Unicode('3'));
279 Insert(35, new XColorEntry( Color(148, 71,148 ), aStr
) );
280 aStr
.SetChar(nLen
, sal_Unicode('4'));
281 Insert(36, new XColorEntry( Color(153,102,204 ), aStr
) );
282 aStr
.SetChar(nLen
, sal_Unicode('5'));
283 Insert(37, new XColorEntry( Color(107, 71,148 ), aStr
) );
284 aStr
.SetChar(nLen
, sal_Unicode('6'));
285 Insert(38, new XColorEntry( Color(107, 35,148 ), aStr
) );
286 aStr
.SetChar(nLen
, sal_Unicode('7'));
287 Insert(39, new XColorEntry( Color(107, 0,148 ), aStr
) );
288 aStr
.SetChar(nLen
, sal_Unicode('8'));
289 Insert(40, new XColorEntry( Color( 94, 17,166 ), aStr
) );
291 aStr
= SVX_RESSTR( RID_SVXSTR_BLUE
);
292 aStr
.AppendAscii(" 1");
293 nLen
= aStr
.Len() - 1;
294 Insert(41, new XColorEntry( Color( 40, 0,153 ), aStr
) );
295 aStr
.SetChar(nLen
, sal_Unicode('2'));
296 Insert(42, new XColorEntry( Color( 71, 0,184 ), aStr
) );
297 aStr
.SetChar(nLen
, sal_Unicode('3'));
298 Insert(43, new XColorEntry( Color( 35, 0,220 ), aStr
) );
299 aStr
.SetChar(nLen
, sal_Unicode('4'));
300 Insert(44, new XColorEntry( Color( 35, 35,220 ), aStr
) );
301 aStr
.SetChar(nLen
, sal_Unicode('5'));
302 Insert(45, new XColorEntry( Color( 0, 71,255 ), aStr
) );
303 aStr
.SetChar(nLen
, sal_Unicode('6'));
304 Insert(46, new XColorEntry( Color( 0,153,255 ), aStr
) );
305 aStr
.SetChar(nLen
, sal_Unicode('7'));
306 Insert(47, new XColorEntry( Color( 0,184,255 ), aStr
) );
307 aStr
.SetChar(nLen
, sal_Unicode('8'));
308 Insert(48, new XColorEntry( Color(153,204,255 ), aStr
) );
309 //Insert(48, new XColorEntry( Color( 46,215,255 ), aStr ) );
311 aStr
= SVX_RESSTR( RID_SVXSTR_CYAN
);
312 aStr
.AppendAscii(" 1");
313 nLen
= aStr
.Len() - 1;
314 Insert(49, new XColorEntry( Color( 0,220,255 ), aStr
) );
315 aStr
.SetChar(nLen
, sal_Unicode('2'));
316 Insert(50, new XColorEntry( Color( 0,204,204 ), aStr
) );
317 aStr
.SetChar(nLen
, sal_Unicode('3'));
318 Insert(51, new XColorEntry( Color( 35,184,220 ), aStr
) );
319 aStr
.SetChar(nLen
, sal_Unicode('4'));
320 Insert(52, new XColorEntry( Color( 71,184,184 ), aStr
) );
321 aStr
.SetChar(nLen
, sal_Unicode('5'));
322 Insert(53, new XColorEntry( Color( 51,163,163 ), aStr
) );
323 aStr
.SetChar(nLen
, sal_Unicode('6'));
324 Insert(54, new XColorEntry( Color( 25,138,138 ), aStr
) );
325 aStr
.SetChar(nLen
, sal_Unicode('7'));
326 Insert(55, new XColorEntry( Color( 0,107,107 ), aStr
) );
327 aStr
.SetChar(nLen
, sal_Unicode('8'));
328 Insert(56, new XColorEntry( Color( 0, 74, 74 ), aStr
) );
330 aStr
= SVX_RESSTR( RID_SVXSTR_GREEN
);
331 aStr
.AppendAscii(" 1");
332 nLen
= aStr
.Len() - 1;
333 Insert(57, new XColorEntry( Color( 53, 94, 0 ), aStr
) );
334 aStr
.SetChar(nLen
, sal_Unicode('2'));
335 Insert(58, new XColorEntry( Color( 92,133, 38 ), aStr
) );
336 aStr
.SetChar(nLen
, sal_Unicode('3'));
337 Insert(59, new XColorEntry( Color(125,166, 71 ), aStr
) );
338 aStr
.SetChar(nLen
, sal_Unicode('4'));
339 Insert(60, new XColorEntry( Color(148,189, 94 ), aStr
) );
340 aStr
.SetChar(nLen
, sal_Unicode('5'));
341 Insert(61, new XColorEntry( Color( 0,174, 0 ), aStr
) );
342 aStr
.SetChar(nLen
, sal_Unicode('6'));
343 Insert(62, new XColorEntry( Color( 51,204,102 ), aStr
) );
344 aStr
.SetChar(nLen
, sal_Unicode('7'));
345 Insert(63, new XColorEntry( Color( 61,235, 61 ), aStr
) );
346 aStr
.SetChar(nLen
, sal_Unicode('8'));
347 Insert(64, new XColorEntry( Color( 35,255, 35 ), aStr
) );
349 aStr
= SVX_RESSTR( RID_SVXSTR_YELLOW
);
350 aStr
.AppendAscii(" 1");
351 nLen
= aStr
.Len() - 1;
352 Insert(65, new XColorEntry( Color(230,255, 0 ), aStr
) );
353 aStr
.SetChar(nLen
, sal_Unicode('2'));
354 Insert(66, new XColorEntry( Color(255,255,153 ), aStr
) );
355 aStr
.SetChar(nLen
, sal_Unicode('3'));
356 Insert(67, new XColorEntry( Color(255,255,102 ), aStr
) );
357 aStr
.SetChar(nLen
, sal_Unicode('4'));
358 Insert(68, new XColorEntry( Color(230,230, 76 ), aStr
) );
359 aStr
.SetChar(nLen
, sal_Unicode('5'));
360 Insert(69, new XColorEntry( Color(204,204, 0 ), aStr
) );
361 aStr
.SetChar(nLen
, sal_Unicode('6'));
362 Insert(70, new XColorEntry( Color(179,179, 0 ), aStr
) );
363 aStr
.SetChar(nLen
, sal_Unicode('7'));
364 Insert(71, new XColorEntry( Color(128,128, 25 ), aStr
) );
365 aStr
.SetChar(nLen
, sal_Unicode('8'));
366 Insert(72, new XColorEntry( Color(102,102, 0 ), aStr
) );
368 aStr
= SVX_RESSTR( RID_SVXSTR_BROWN
);
369 aStr
.AppendAscii(" 1");
370 nLen
= aStr
.Len() - 1;
371 Insert(73, new XColorEntry( Color( 76, 25, 0 ), aStr
) );
372 aStr
.SetChar(nLen
, sal_Unicode('2'));
373 Insert(74, new XColorEntry( Color(102, 51, 0 ), aStr
) );
374 aStr
.SetChar(nLen
, sal_Unicode('3'));
375 Insert(75, new XColorEntry( Color(128, 76, 25 ), aStr
) );
376 aStr
.SetChar(nLen
, sal_Unicode('4'));
377 Insert(76, new XColorEntry( Color(153,102, 51 ), aStr
) );
379 aStr
= SVX_RESSTR( RID_SVXSTR_ORANGE
);
380 aStr
.AppendAscii(" 1");
381 nLen
= aStr
.Len() - 1;
382 Insert(77, new XColorEntry( Color(204,102, 51 ), aStr
) );
383 aStr
.SetChar(nLen
, sal_Unicode('2'));
384 Insert(78, new XColorEntry( Color(255,102, 51 ), aStr
) );
385 aStr
.SetChar(nLen
, sal_Unicode('3'));
386 Insert(79, new XColorEntry( Color(255,153,102 ), aStr
) );
387 aStr
.SetChar(nLen
, sal_Unicode('4'));
388 Insert(80, new XColorEntry( Color(255,204,153 ), aStr
) );
391 aStr
= SVX_RESSTR( RID_SVXSTR_VIOLET
);
392 Insert( 81, new XColorEntry( Color( 0x99, 0x99, 0xff ), aStr
) );
394 aStr
= SVX_RESSTR( RID_SVXSTR_BORDEAUX
);
395 Insert( 82, new XColorEntry( Color( 0x99, 0x33, 0x66 ), aStr
) );
397 aStr
= SVX_RESSTR( RID_SVXSTR_PALE_YELLOW
);
398 Insert( 83, new XColorEntry( Color( 0xff, 0xff, 0xcc ), aStr
) );
400 aStr
= SVX_RESSTR( RID_SVXSTR_PALE_GREEN
);
401 Insert( 84, new XColorEntry( Color( 0xcc, 0xff, 0xff ), aStr
) );
403 aStr
= SVX_RESSTR( RID_SVXSTR_DKVIOLET
);
404 Insert( 85, new XColorEntry( Color( 0x66, 0x00, 0x66 ), aStr
) );
406 aStr
= SVX_RESSTR( RID_SVXSTR_SALMON
);
407 Insert( 86, new XColorEntry( Color( 0xff, 0x80, 0x80 ), aStr
) );
409 aStr
= SVX_RESSTR( RID_SVXSTR_SEABLUE
);
410 Insert( 87, new XColorEntry( Color( 0x00, 0x66, 0xcc ), aStr
) );
413 aStr
= SVX_RESSTR( RID_SVXSTR_COLOR_SUN
);
414 aStr
.AppendAscii(" 1");
415 nLen
= aStr
.Len() - 1;
416 Insert( 88, new XColorEntry( Color( 0x33, 0x33, 0x66 ), aStr
) );
417 aStr
.SetChar(nLen
, sal_Unicode('2'));
418 Insert( 89, new XColorEntry( Color( 0x66, 0x66, 0x99 ), aStr
) );
419 aStr
.SetChar(nLen
, sal_Unicode('3'));
420 Insert( 90, new XColorEntry( Color( 0x99, 0x99, 0xcc ), aStr
) );
421 aStr
.SetChar(nLen
, sal_Unicode('4'));
422 Insert( 91, new XColorEntry( Color( 0xcc, 0xcc, 0xff ), aStr
) );
424 // Chart default colors
425 aStr
= SVX_RESSTR( RID_SVXSTR_COLOR_CHART
);
426 aStr
.AppendAscii(" 1");
427 nLen
= aStr
.Len() - 1;
428 Insert( 92, new XColorEntry( Color( 0x00, 0x45, 0x86 ), aStr
) );
429 aStr
.SetChar(nLen
, sal_Unicode('2'));
430 Insert( 93, new XColorEntry( Color( 0xff, 0x42, 0x0e ), aStr
) );
431 aStr
.SetChar(nLen
, sal_Unicode('3'));
432 Insert( 94, new XColorEntry( Color( 0xff, 0xd3, 0x20 ), aStr
) );
433 aStr
.SetChar(nLen
, sal_Unicode('4'));
434 Insert( 95, new XColorEntry( Color( 0x57, 0x9d, 0x1c ), aStr
) );
435 aStr
.SetChar(nLen
, sal_Unicode('5'));
436 Insert( 96, new XColorEntry( Color( 0x7e, 0x00, 0x21 ), aStr
) );
437 aStr
.SetChar(nLen
, sal_Unicode('6'));
438 Insert( 97, new XColorEntry( Color( 0x83, 0xca, 0xff ), aStr
) );
439 aStr
.SetChar(nLen
, sal_Unicode('7'));
440 Insert( 98, new XColorEntry( Color( 0x31, 0x40, 0x04 ), aStr
) );
441 aStr
.SetChar(nLen
, sal_Unicode('8'));
442 Insert( 99, new XColorEntry( Color( 0xae, 0xcf, 0x00 ), aStr
) );
443 aStr
.SetChar(nLen
, sal_Unicode('9'));
444 Insert( 100, new XColorEntry( Color( 0x4b, 0x1f, 0x6f ), aStr
) );
445 aStr
.SetChar(nLen
, sal_Unicode('1'));
446 aStr
.AppendAscii("0");
447 nLen
= aStr
.Len() - 1;
448 Insert( 101, new XColorEntry( Color( 0xff, 0x95, 0x0e ), aStr
) );
449 aStr
.SetChar(nLen
, sal_Unicode('1'));
450 Insert( 102, new XColorEntry( Color( 0xc5, 0x00, 0x0b ), aStr
) );
451 aStr
.SetChar(nLen
, sal_Unicode('2'));
452 Insert( 103, new XColorEntry( Color( 0x00, 0x84, 0xd1 ), aStr
) );
454 return( Count() == 104 );
457 /************************************************************************/
459 BOOL
XColorTable::CreateBitmapsForUI()
464 /************************************************************************/
466 Bitmap
* XColorTable::CreateBitmapForUI( long /*nIndex*/, BOOL
/*bDelete*/)
471 // --------------------
473 // --------------------
475 /*************************************************************************
477 |* XColorList::XColorList()
479 *************************************************************************/
481 XColorList::XColorList( const String
& rPath
,
482 XOutdevItemPool
* pInPool
,
483 USHORT nInitSize
, USHORT nReSize
) :
484 XPropertyList( rPath
, pInPool
, nInitSize
, nReSize
)
486 // pBmpList = new List( nInitSize, nReSize );
489 /************************************************************************/
491 XColorList::~XColorList()
495 /************************************************************************/
497 XColorEntry
* XColorList::Replace(XColorEntry
* pEntry
, long nIndex
)
499 return (XColorEntry
*) XPropertyList::Replace(pEntry
, nIndex
);
502 /************************************************************************/
504 XColorEntry
* XColorList::Remove(long nIndex
)
506 return (XColorEntry
*) XPropertyList::Remove(nIndex
, 0);
509 /************************************************************************/
511 XColorEntry
* XColorList::GetColor(long nIndex
) const
513 return (XColorEntry
*) XPropertyList::Get(nIndex
, 0);
516 /************************************************************************/
518 BOOL
XColorList::Load()
523 /************************************************************************/
525 BOOL
XColorList::Save()
530 /************************************************************************/
532 BOOL
XColorList::Create()
537 /************************************************************************/
539 BOOL
XColorList::CreateBitmapsForUI()
544 /************************************************************************/
546 Bitmap
* XColorList::CreateBitmapForUI( long /*nIndex*/, BOOL
/*bDelete*/)