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