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