xref: /aoo41x/main/svx/source/xoutdev/xtabbtmp.cxx (revision c7be74b1)
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 #include <com/sun/star/container/XNameContainer.hpp>
28 #include "svx/XPropertyTable.hxx"
29 #include <unotools/ucbstreamhelper.hxx>
30 #include <xmlxtexp.hxx>
31 #include <xmlxtimp.hxx>
32 #include <tools/urlobj.hxx>
33 #include <vcl/virdev.hxx>
34 #include <svl/itemset.hxx>
35 #include <sfx2/docfile.hxx>
36 #include <svx/dialogs.hrc>
37 #include <svx/dialmgr.hxx>
38 #include <svx/xtable.hxx>
39 #include <svx/xpool.hxx>
40 #include <svx/xbtmpit.hxx>
41 
42 #define GLOBALOVERFLOW
43 
44 using namespace com::sun::star;
45 using namespace rtl;
46 
47 sal_Unicode const pszExtBitmap[]  = {'s','o','b'};
48 
49 static char const aChckBitmap[]  = { 0x04, 0x00, 'S','O','B','L'};	// very old
50 static char const aChckBitmap0[] = { 0x04, 0x00, 'S','O','B','0'};	// old
51 static char const aChckBitmap1[] = { 0x04, 0x00, 'S','O','B','1'};	// = 5.2
52 static char const aChckXML[]     = { 'P', 'K', 0x03, 0x04 };		// = 6.0
53 
54 // ------------------
55 // class XBitmapList
56 // ------------------
57 
58 XBitmapList::XBitmapList( const String& rPath ) :
59 				XPropertyList( rPath )
60 {
61 }
62 
63 /************************************************************************/
64 
65 XBitmapList::~XBitmapList()
66 {
67 }
68 
69 /************************************************************************/
70 
71 XBitmapEntry* XBitmapList::Replace(XBitmapEntry* pEntry, long nIndex )
72 {
73 	return (XBitmapEntry*) XPropertyList::Replace(pEntry, nIndex);
74 }
75 
76 /************************************************************************/
77 
78 XBitmapEntry* XBitmapList::Remove(long nIndex)
79 {
80 	return (XBitmapEntry*) XPropertyList::Remove(nIndex);
81 }
82 
83 /************************************************************************/
84 
85 XBitmapEntry* XBitmapList::GetBitmap(long nIndex) const
86 {
87 	return (XBitmapEntry*) XPropertyList::Get(nIndex);
88 }
89 
90 /************************************************************************/
91 
92 sal_Bool XBitmapList::Load()
93 {
94 	if( mbListDirty )
95 	{
96 		mbListDirty = false;
97 
98 		INetURLObject aURL( maPath );
99 
100 		if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
101 		{
102 			DBG_ASSERT( !maPath.Len(), "invalid URL" );
103 			return sal_False;
104 		}
105 
106 		aURL.Append( maName );
107 
108 		if( !aURL.getExtension().getLength() )
109 			aURL.setExtension( rtl::OUString( pszExtBitmap, 3 ) );
110 
111 		uno::Reference< container::XNameContainer > xTable( SvxUnoXBitmapTable_createInstance( this ), uno::UNO_QUERY );
112 		return SvxXMLXTableImport::load( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable );
113 	}
114 	return( sal_False );
115 }
116 
117 /************************************************************************/
118 
119 sal_Bool XBitmapList::Save()
120 {
121 	INetURLObject aURL( maPath );
122 
123 	if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
124 	{
125 		DBG_ASSERT( !maPath.Len(), "invalid URL" );
126 		return sal_False;
127 	}
128 
129 	aURL.Append( maName );
130 
131 	if( !aURL.getExtension().getLength() )
132 		aURL.setExtension( rtl::OUString( pszExtBitmap, 3 ) );
133 
134 	uno::Reference< container::XNameContainer > xTable( SvxUnoXBitmapTable_createInstance( this ), uno::UNO_QUERY );
135 	return SvxXMLXTableExportComponent::save( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable );
136 }
137 
138 /************************************************************************/
139 // Umgestellt am 27.07.95 auf XBitmap
140 
141 sal_Bool XBitmapList::Create()
142 {
143 	//-----------------------
144 	// 00 01 02 03 04 05 06 07
145 	// 08 09 10 11 12 13 14 15
146 	// 16 17 18 19 20 21 22 23
147 	// 24 25 26 27 28 29 30 31
148 	// 32 33 34 35 36 37 38 39
149 	// 40 41 42 43 44 45 46 47
150 	// 48 49 50 51 52 53 54 55
151 	// 56 57 58 59 60 61 62 63
152 	String aStr(SVX_RES(RID_SVXSTR_BITMAP));
153     sal_uInt16 aArray[64];
154     Bitmap aBitmap;
155 	const xub_StrLen nLen(aStr.Len() - 1);
156 
157     memset(aArray, 0, sizeof(aArray));
158 
159     // white/white bitmap
160 	aStr.AppendAscii(" 1");
161     aBitmap = createHistorical8x8FromArray(aArray, RGB_Color(COL_WHITE), RGB_Color(COL_WHITE));
162 	Insert(new XBitmapEntry(Graphic(aBitmap), aStr));
163 
164     // black/white bitmap
165 	aArray[ 0] = 1; aArray[ 9] = 1; aArray[18] = 1; aArray[27] = 1;
166 	aArray[36] = 1; aArray[45] = 1; aArray[54] = 1; aArray[63] = 1;
167 	aStr.SetChar(nLen, sal_Unicode('2'));
168     aBitmap = createHistorical8x8FromArray(aArray, RGB_Color(COL_BLACK), RGB_Color(COL_WHITE));
169 	Insert(new XBitmapEntry(Graphic(aBitmap), aStr));
170 
171     // lightred/white bitmap
172 	aArray[ 7] = 1; aArray[14] = 1; aArray[21] = 1; aArray[28] = 1;
173 	aArray[35] = 1; aArray[42] = 1; aArray[49] = 1; aArray[56] = 1;
174 	aStr.SetChar(nLen, sal_Unicode('3'));
175     aBitmap = createHistorical8x8FromArray(aArray, RGB_Color(COL_LIGHTRED), RGB_Color(COL_WHITE));
176 	Insert(new XBitmapEntry(Graphic(aBitmap), aStr));
177 
178     // lightblue/white bitmap
179 	aArray[24] = 1; aArray[25] = 1; aArray[26] = 1;
180 	aArray[29] = 1; aArray[30] = 1; aArray[31] = 1;
181 	aStr.SetChar(nLen, sal_Unicode('4'));
182     aBitmap = createHistorical8x8FromArray(aArray, RGB_Color(COL_LIGHTBLUE), RGB_Color(COL_WHITE));
183 	Insert(new XBitmapEntry(Graphic(aBitmap), aStr));
184 
185 	return( sal_True );
186 }
187 
188 /************************************************************************/
189 
190 Bitmap XBitmapList::CreateBitmapForUI( long /*nIndex*/ )
191 {
192 	return Bitmap();
193 }
194 
195 // eof
196