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