xref: /trunk/main/svx/source/xoutdev/xtabcolr.cxx (revision 28806869)
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 
42 sal_Unicode const pszExtColor[]	 = {'s','o','c'};
43 
44 static char const aChckColor[]  = { 0x04, 0x00, 'S','O','C','L'};	// < 5.2
45 static char const aChckColor0[] = { 0x04, 0x00, 'S','O','C','0'};	// = 5.2
46 static char const aChckXML[]    = { '<', '?', 'x', 'm', 'l' };		// = 6.0
47 
48 /*************************************************************************
49 |*
50 |* XColorList::XColorList()
51 |*
52 *************************************************************************/
53 
54 static XColorListSharedPtr aStaticGlobalColorList;
55 
XColorList(const String & rPath)56 XColorList::XColorList( const String& rPath ) :
57 				XPropertyList( rPath )
58 {
59 }
60 
61 /************************************************************************/
62 
~XColorList()63 XColorList::~XColorList()
64 {
65 }
66 
67 /************************************************************************/
68 
Replace(XColorEntry * pEntry,long nIndex)69 XColorEntry* XColorList::Replace(XColorEntry* pEntry, long nIndex )
70 {
71 	return (XColorEntry*) XPropertyList::Replace(pEntry, nIndex);
72 }
73 
74 /************************************************************************/
75 
Remove(long nIndex)76 XColorEntry* XColorList::Remove(long nIndex)
77 {
78 	return (XColorEntry*) XPropertyList::Remove(nIndex);
79 }
80 
81 /************************************************************************/
82 
GetColor(long nIndex) const83 XColorEntry* XColorList::GetColor(long nIndex) const
84 {
85 	return (XColorEntry*) XPropertyList::Get(nIndex);
86 }
87 
88 /************************************************************************/
89 
Load()90 bool XColorList::Load()
91 {
92 	if( mbListDirty )
93 	{
94 		mbListDirty = false;
95 
96 		INetURLObject aURL( maPath );
97 
98 		if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
99 		{
100 			OSL_ENSURE( !maPath.Len(), "invalid URL" );
101 			return false;
102 		}
103 
104 		aURL.Append( maName );
105 
106 		if( !aURL.getExtension().getLength() )
107 			aURL.setExtension( rtl::OUString( pszExtColor, 3 ) );
108 
109 		uno::Reference< container::XNameContainer > xTable( SvxUnoXColorTable_createInstance( this ), uno::UNO_QUERY );
110 		return SvxXMLXTableImport::load( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable );
111 	}
112 
113 	return false;
114 }
115 
116 /************************************************************************/
117 
Save()118 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 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 
Create()139 bool XColorList::Create()
140 {
141     sal_uInt32 a(0);
142     sal_uInt32 b(0);
143 
144     // <!-- Gray palette from white to black -->
145     XubString aStrGrey( SVX_RESSTR( RID_SVXSTR_COLOR_GREY ) );
146 
147     Insert( new XColorEntry( Color( 0xff, 0xff, 0xff ), SVX_RESSTR( RID_SVXSTR_COLOR_WHITE ) ) );
148     aStrGrey.AppendAscii(" 1"); Insert( new XColorEntry( Color( 0xee, 0xee, 0xee ), aStrGrey ) );
149     aStrGrey.SetChar(aStrGrey.Len() - 1, sal_Unicode('2')); Insert( new XColorEntry( Color( 0xdd, 0xdd, 0xdd ), aStrGrey ) );
150     aStrGrey.SetChar(aStrGrey.Len() - 1, sal_Unicode('3')); Insert( new XColorEntry( Color( 0xcc, 0xcc, 0xcc ), aStrGrey ) );
151     aStrGrey.SetChar(aStrGrey.Len() - 1, sal_Unicode('4')); Insert( new XColorEntry( Color( 0xb2, 0xb2, 0xb2 ), aStrGrey ) );
152     aStrGrey.SetChar(aStrGrey.Len() - 1, sal_Unicode('5')); Insert( new XColorEntry( Color( 0x99, 0x99, 0x99 ), aStrGrey ) );
153     aStrGrey.SetChar(aStrGrey.Len() - 1, sal_Unicode('6')); Insert( new XColorEntry( Color( 0x80, 0x80, 0x80 ), aStrGrey ) );
154     aStrGrey.SetChar(aStrGrey.Len() - 1, sal_Unicode('7')); Insert( new XColorEntry( Color( 0x66, 0x66, 0x66 ), aStrGrey ) );
155     aStrGrey.SetChar(aStrGrey.Len() - 1, sal_Unicode('8')); Insert( new XColorEntry( Color( 0x33, 0x33, 0x33 ), aStrGrey ) );
156     aStrGrey.SetChar(aStrGrey.Len() - 1, sal_Unicode('9')); Insert( new XColorEntry( Color( 0x1c, 0x1c, 0x1c  ), aStrGrey ) );
157     aStrGrey.SetChar(aStrGrey.Len() - 1, sal_Unicode('1')); aStrGrey.AppendAscii("0"); Insert( new XColorEntry( Color( 0x11, 0x11, 0x11 ), aStrGrey ) );
158     Insert( new XColorEntry( Color( 0x00, 0x00, 0x00 ), SVX_RESSTR( RID_SVXSTR_COLOR_BLACK ) ) );
159 
160     // <!-- Base colors step 0 to 10 -->
161     const sal_uInt32 nNumColorsInGroup(12);
162     const sal_uInt32 nNumGroups(11);
163     XubString aStrCol[nNumColorsInGroup];
164     const sal_uInt32 aStdCol[nNumColorsInGroup * nNumGroups] = {
165         0xffff99, 0xff6600, 0xff3333, 0xff00cc, 0xff33ff, 0x9900ff, 0x6666ff, 0x00ccff, 0x66ffff, 0x33ff99, 0x99ff66, 0xccff00,
166         0xffff66, 0xffcc00, 0xff9999, 0xff66cc, 0xff99ff, 0xcc66ff, 0x9999ff, 0x9999ff, 0x99ffff, 0x66ff99, 0x99ff99, 0xccff66,
167         0xffff00, 0xff9900, 0xff6666, 0xff3399, 0xff66ff, 0x9933ff, 0x3333ff, 0x3399ff, 0x00ffff, 0x00ff66, 0x66ff66, 0x99ff33,
168         0xcc9900, 0xff3300, 0xff0000, 0xff0066, 0xff00ff, 0x6600ff, 0x0000ff, 0x0066ff, 0x00cccc, 0x00cc33, 0x00cc00, 0x66ff00,
169         0x996600, 0xcc3300, 0xcc0000, 0xcc0066, 0xcc00cc, 0x6600cc, 0x0000cc, 0x0066cc, 0x009999, 0x009933, 0x009900, 0x66cc00,
170         0x663300, 0x801900, 0x990000, 0x990066, 0x990099, 0x330099, 0x000099, 0x006699, 0x006666, 0x007826, 0x006600, 0x669900,
171         0x333300, 0x461900, 0x330000, 0x330033, 0x660066, 0x000033, 0x000066, 0x000080, 0x003333, 0x00331a, 0x003300, 0x193300,
172         0x666633, 0x661900, 0x663333, 0x660033, 0x663366, 0x330066, 0x333366, 0x003366, 0x336666, 0x006633, 0x336633, 0x336600,
173         0x999966, 0x996633, 0x996666, 0x993366, 0x996699, 0x663399, 0x666699, 0x336699, 0x669999, 0x339966, 0x669966, 0x669933,
174         0xcccc99, 0xcc9966, 0xcc9999, 0xcc6699, 0xcc99cc, 0x9966cc, 0x9999cc, 0x6699cc, 0x99cccc, 0x66cc99, 0x99cc99, 0x99cc66,
175         0xffffcc, 0xffcc99, 0xffcccc, 0xff99cc, 0xffccff, 0xcc99ff, 0xccccff, 0x99ccff, 0xccffff, 0x99ffcc, 0xccffcc, 0xccff99 };
176 
177     for(a = 0; a < nNumGroups; a++)
178     {
179         switch(a)
180         {
181             case 0:
182             {
183                 aStrCol[0] = SVX_RESSTR(RID_SVXSTR_COLOR_YELLOW);
184                 aStrCol[1] = SVX_RESSTR(RID_SVXSTR_COLOR_ORANGE);
185                 aStrCol[2] = SVX_RESSTR(RID_SVXSTR_COLOR_RED);
186                 aStrCol[3] = SVX_RESSTR(RID_SVXSTR_COLOR_PINK);
187                 aStrCol[4] = SVX_RESSTR(RID_SVXSTR_COLOR_MAGENTA);
188                 aStrCol[5] = SVX_RESSTR(RID_SVXSTR_COLOR_PURPLE);
189                 aStrCol[6] = SVX_RESSTR(RID_SVXSTR_COLOR_BLUE);
190                 aStrCol[7] = SVX_RESSTR(RID_SVXSTR_COLOR_SKYBLUE);
191                 aStrCol[8] = SVX_RESSTR(RID_SVXSTR_COLOR_CYAN);
192                 aStrCol[9] = SVX_RESSTR(RID_SVXSTR_COLOR_TURQUOISE);
193                 aStrCol[10] = SVX_RESSTR(RID_SVXSTR_COLOR_GREEN);
194                 aStrCol[11] = SVX_RESSTR(RID_SVXSTR_COLOR_YELLOWGREEN);
195                 break;
196             }
197             case 1:
198             {
199                 for(b = 0; b < nNumColorsInGroup; b++)
200                 {
201                     aStrCol[b].AppendAscii(" 1");
202                 }
203                 break;
204             }
205             case 10:
206             {
207                 for(b = 0; b < nNumColorsInGroup; b++)
208                 {
209                     aStrCol[b].SetChar(aStrCol[b].Len() - 1, sal_Unicode('1'));
210                     aStrCol[b].AppendAscii("0");
211                 }
212                 break;
213             }
214             default: // 2 .. 9, 11
215             {
216                 for(b = 0; b < nNumColorsInGroup; b++)
217                 {
218                     aStrCol[b].SetChar(aStrCol[b].Len() - 1, sal_Unicode('0') + sal_Unicode(a % 10));
219                 }
220                 break;
221             }
222         }
223 
224         const sal_uInt32 nOffset(a * nNumColorsInGroup);
225 
226         for(b = 0; b < nNumColorsInGroup; b++)
227         {
228             Insert( new XColorEntry( aStdCol[nOffset + b], aStrCol[b] ) );
229         }
230     }
231 
232     // <!-- use some 'nice' colors from original palette -->
233     Insert( new XColorEntry( Color( 0xe6, 0xe6, 0xff ), SVX_RESSTR( RID_SVXSTR_COLOR_BLUEGREY) ) );
234     Insert( new XColorEntry( Color( 0xCF, 0xE7, 0xF5  ), SVX_RESSTR( RID_SVXSTR_COLOR_BLUE_CLASSIC ) ) );
235 
236     // <!-- add 'pale' colors from original palette -->
237     Insert( new XColorEntry( Color( 0x99, 0x99, 0xff ), SVX_RESSTR( RID_SVXSTR_COLOR_VIOLET ) ) );
238     Insert( new XColorEntry( Color( 0x99, 0x33, 0x66 ), SVX_RESSTR( RID_SVXSTR_COLOR_BORDEAUX ) ) );
239     Insert( new XColorEntry( Color( 0xff, 0xff, 0xcc ), SVX_RESSTR( RID_SVXSTR_COLOR_PALE_YELLOW ) ) );
240     Insert( new XColorEntry( Color( 0xcc, 0xff, 0xff ), SVX_RESSTR( RID_SVXSTR_COLOR_PALE_GREEN ) ) );
241     Insert( new XColorEntry( Color( 0x66, 0x00, 0x66 ), SVX_RESSTR( RID_SVXSTR_COLOR_DARKVIOLET ) ) );
242     Insert( new XColorEntry( Color( 0xff, 0x80, 0x80 ), SVX_RESSTR( RID_SVXSTR_COLOR_SALMON ) ) );
243     Insert( new XColorEntry( Color( 0x00, 0x66, 0xcc ), SVX_RESSTR( RID_SVXSTR_COLOR_SEABLUE ) ) );
244 
245     // <!-- add Chart colors from original palette (also 12, coincidence?) -->
246     XubString aStrChart( SVX_RESSTR( RID_SVXSTR_COLOR_CHART ) );
247     aStrChart.AppendAscii(" 1");
248     Insert( new XColorEntry( Color( 0x00, 0x45, 0x86 ), aStrChart ) );
249     aStrChart.SetChar(aStrChart.Len() - 1, sal_Unicode('2'));
250     Insert( new XColorEntry( Color( 0xff, 0x42, 0x0e ), aStrChart ) );
251     aStrChart.SetChar(aStrChart.Len() - 1, sal_Unicode('3'));
252     Insert( new XColorEntry( Color( 0xff, 0xd3, 0x20 ), aStrChart ) );
253     aStrChart.SetChar(aStrChart.Len() - 1, sal_Unicode('4'));
254     Insert( new XColorEntry( Color( 0x57, 0x9d, 0x1c ), aStrChart ) );
255     aStrChart.SetChar(aStrChart.Len() - 1, sal_Unicode('5'));
256     Insert( new XColorEntry( Color( 0x7e, 0x00, 0x21 ), aStrChart ) );
257     aStrChart.SetChar(aStrChart.Len() - 1, sal_Unicode('6'));
258     Insert( new XColorEntry( Color( 0x83, 0xca, 0xff ), aStrChart ) );
259     aStrChart.SetChar(aStrChart.Len() - 1, sal_Unicode('7'));
260     Insert( new XColorEntry( Color( 0x31, 0x40, 0x04 ), aStrChart ) );
261     aStrChart.SetChar(aStrChart.Len() - 1, sal_Unicode('8'));
262     Insert( new XColorEntry( Color( 0xae, 0xcf, 0x00 ), aStrChart ) );
263     aStrChart.SetChar(aStrChart.Len() - 1, sal_Unicode('9'));
264     Insert( new XColorEntry( Color( 0x4b, 0x1f, 0x6f ), aStrChart ) );
265     aStrChart.SetChar(aStrChart.Len() - 1, sal_Unicode('1'));
266     aStrChart.AppendAscii("0");
267     Insert( new XColorEntry( Color( 0xff, 0x95, 0x0e ), aStrChart ) );
268     aStrChart.SetChar(aStrChart.Len() - 1, sal_Unicode('1'));
269     Insert( new XColorEntry( Color( 0xc5, 0x00, 0x0b ), aStrChart ) );
270     aStrChart.SetChar(aStrChart.Len() - 1, sal_Unicode('2'));
271     Insert( new XColorEntry( Color( 0x00, 0x84, 0xd1 ), aStrChart ) );
272 
273     return(165 == Count());
274 }
275 
276 /************************************************************************/
277 
CreateBitmapForUI(long)278 Bitmap XColorList::CreateBitmapForUI( long /*nIndex*/ )
279 {
280 	return Bitmap();
281 }
282 
283 /************************************************************************/
284 
GetStdColorList()285 XColorListSharedPtr XColorList::GetStdColorList()
286 {
287     if ( !aStaticGlobalColorList.get() )
288     {
289         aStaticGlobalColorList = XPropertyListFactory::CreateSharedXColorList(SvtPathOptions().GetPalettePath());
290     }
291 
292     return aStaticGlobalColorList;
293 }
294 
295 // eof
296