xref: /trunk/main/svx/source/xoutdev/xtablend.cxx (revision 33b19716)
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 ---------------------------------------------------------------
26 #include <com/sun/star/container/XNameContainer.hpp>
27 #include "svx/XPropertyTable.hxx"
28 #include <unotools/ucbstreamhelper.hxx>
29 #include "xmlxtexp.hxx"
30 #include "xmlxtimp.hxx"
31 #include <tools/urlobj.hxx>
32 #include <vcl/virdev.hxx>
33 #include <vcl/svapp.hxx>
34 #include <svx/dialogs.hrc>
35 #include <svx/dialmgr.hxx>
36 #include <svx/xtable.hxx>
37 #include <drawinglayer/attribute/linestartendattribute.hxx>
38 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
39 #include <drawinglayer/processor2d/processor2dtools.hxx>
40 #include <basegfx/polygon/b2dpolygontools.hxx>
41 
42 #define GLOBALOVERFLOW
43 
44 using namespace com::sun::star;
45 using namespace rtl;
46 
47 sal_Unicode const pszExtLineEnd[]	= {'s','o','e'};
48 //static char const aChckLEnd[]  = { 0x04, 0x00, 'S','O','E','L'};	// < 5.2
49 //static char const aChckLEnd0[] = { 0x04, 0x00, 'S','O','E','0'};	// = 5.2
50 //static char const aChckXML[]   = { '<', '?', 'x', 'm', 'l' };		// = 6.0
51 
52 // --------------------
53 // class XLineEndList
54 // --------------------
55 
XLineEndList(const String & rPath)56 XLineEndList::XLineEndList(const String& rPath)
57 :	XPropertyList(rPath)
58 {
59 }
60 
~XLineEndList()61 XLineEndList::~XLineEndList()
62 {
63 }
64 
Replace(XLineEndEntry * pEntry,long nIndex)65 XLineEndEntry* XLineEndList::Replace(XLineEndEntry* pEntry, long nIndex )
66 {
67 	return (XLineEndEntry*) XPropertyList::Replace(pEntry, nIndex);
68 }
69 
Remove(long nIndex)70 XLineEndEntry* XLineEndList::Remove(long nIndex)
71 {
72 	return (XLineEndEntry*) XPropertyList::Remove(nIndex);
73 }
74 
GetLineEnd(long nIndex) const75 XLineEndEntry* XLineEndList::GetLineEnd(long nIndex) const
76 {
77 	return (XLineEndEntry*) XPropertyList::Get(nIndex);
78 }
79 
Load()80 bool XLineEndList::Load()
81 {
82 	if( mbListDirty )
83 	{
84 		mbListDirty = false;
85 
86 		INetURLObject aURL( maPath );
87 
88 		if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
89 		{
90 			OSL_ENSURE( !maPath.Len(), "invalid URL" );
91 			return false;
92 		}
93 
94 		aURL.Append( maName );
95 
96 		if( !aURL.getExtension().getLength() )
97 			aURL.setExtension( rtl::OUString( pszExtLineEnd, 3 ) );
98 
99 		uno::Reference< container::XNameContainer > xTable( SvxUnoXLineEndTable_createInstance( this ), uno::UNO_QUERY );
100 		return SvxXMLXTableImport::load( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable );
101 	}
102 
103     return false;
104 }
105 
Save()106 bool XLineEndList::Save()
107 {
108 	INetURLObject aURL( maPath );
109 
110 	if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
111 	{
112 		OSL_ENSURE( !maPath.Len(), "invalid URL" );
113 		return false;
114 	}
115 
116 	aURL.Append( maName );
117 
118 	if( !aURL.getExtension().getLength() )
119 		aURL.setExtension( rtl::OUString( pszExtLineEnd, 3 ) );
120 
121 	uno::Reference< container::XNameContainer > xTable( SvxUnoXLineEndTable_createInstance( this ), uno::UNO_QUERY );
122 	return SvxXMLXTableExportComponent::save( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable );
123 }
124 
Create()125 bool XLineEndList::Create()
126 {
127 	basegfx::B2DPolygon aTriangle;
128 	aTriangle.append(basegfx::B2DPoint(10.0, 0.0));
129 	aTriangle.append(basegfx::B2DPoint(0.0, 30.0));
130 	aTriangle.append(basegfx::B2DPoint(20.0, 30.0));
131 	aTriangle.setClosed(true);
132 	Insert( new XLineEndEntry( basegfx::B2DPolyPolygon(aTriangle), SVX_RESSTR( RID_SVXSTR_ARROW ) ) );
133 
134 	basegfx::B2DPolygon aSquare;
135 	aSquare.append(basegfx::B2DPoint(0.0, 0.0));
136 	aSquare.append(basegfx::B2DPoint(10.0, 0.0));
137 	aSquare.append(basegfx::B2DPoint(10.0, 10.0));
138 	aSquare.append(basegfx::B2DPoint(0.0, 10.0));
139 	aSquare.setClosed(true);
140 	Insert( new XLineEndEntry( basegfx::B2DPolyPolygon(aSquare), SVX_RESSTR( RID_SVXSTR_SQUARE ) ) );
141 
142 	basegfx::B2DPolygon aCircle(basegfx::tools::createPolygonFromCircle(basegfx::B2DPoint(0.0, 0.0), 100.0));
143 	Insert( new XLineEndEntry( basegfx::B2DPolyPolygon(aCircle), SVX_RESSTR( RID_SVXSTR_CIRCLE ) ) );
144 
145 	return true;
146 }
147 
CreateBitmapForUI(long nIndex)148 Bitmap XLineEndList::CreateBitmapForUI( long nIndex )
149 {
150     Bitmap aRetval;
151     OSL_ENSURE(nIndex < Count(), "OOps, access out of range (!)");
152 
153     if(nIndex < Count())
154     {
155         const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
156         const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize();
157         const Size aSize(rSize.Width() * 2, rSize.Height());
158 
159         // prepare line geometry
160         basegfx::B2DPolygon aLine;
161         const double fBorderDistance(aSize.Height() * 0.1);
162 
163         aLine.append(basegfx::B2DPoint(fBorderDistance, aSize.Height() / 2));
164         aLine.append(basegfx::B2DPoint(aSize.Width() - fBorderDistance, aSize.Height() / 2));
165 
166         // prepare LineAttribute
167         const basegfx::BColor aLineColor(rStyleSettings.GetFieldTextColor().getBColor());
168         const double fLineWidth(rStyleSettings.GetListBoxPreviewDefaultLineWidth() * 1.1);
169         const drawinglayer::attribute::LineAttribute aLineAttribute(
170             aLineColor,
171             fLineWidth);
172 
173         const basegfx::B2DPolyPolygon aLineEnd(GetLineEnd(nIndex)->GetLineEnd());
174         const double fArrowHeight(aSize.Height() - (2.0 * fBorderDistance));
175         const drawinglayer::attribute::LineStartEndAttribute aLineStartEndAttribute(
176             fArrowHeight,
177             aLineEnd,
178             false);
179 
180         // prepare line primitive
181         const drawinglayer::primitive2d::Primitive2DReference aLineStartEndPrimitive(
182             new drawinglayer::primitive2d::PolygonStrokeArrowPrimitive2D(
183                 aLine,
184                 aLineAttribute,
185                 aLineStartEndAttribute,
186                 aLineStartEndAttribute));
187 
188         // prepare VirtualDevice
189         VirtualDevice aVirtualDevice;
190         const drawinglayer::geometry::ViewInformation2D aNewViewInformation2D;
191 
192         aVirtualDevice.SetOutputSizePixel(aSize);
193         aVirtualDevice.SetDrawMode(rStyleSettings.GetHighContrastMode()
194             ? DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT
195             : DRAWMODE_DEFAULT);
196 
197         if(rStyleSettings.GetPreviewUsesCheckeredBackground())
198         {
199             const Point aNull(0, 0);
200             static const sal_uInt32 nLen(8);
201             static const Color aW(COL_WHITE);
202             static const Color aG(0xef, 0xef, 0xef);
203 
204             aVirtualDevice.DrawCheckered(aNull, aSize, nLen, aW, aG);
205         }
206         else
207         {
208             aVirtualDevice.SetBackground(rStyleSettings.GetFieldColor());
209             aVirtualDevice.Erase();
210         }
211 
212         // create processor and draw primitives
213         drawinglayer::processor2d::BaseProcessor2D* pProcessor2D = drawinglayer::processor2d::createPixelProcessor2DFromOutputDevice(
214             aVirtualDevice,
215             aNewViewInformation2D);
216 
217         if(pProcessor2D)
218         {
219             const drawinglayer::primitive2d::Primitive2DSequence aSequence(&aLineStartEndPrimitive, 1);
220 
221             pProcessor2D->process(aSequence);
222             delete pProcessor2D;
223         }
224 
225         // get result bitmap and scale
226         aRetval = aVirtualDevice.GetBitmap(Point(0, 0), aVirtualDevice.GetOutputSizePixel());
227     }
228 
229     return aRetval;
230 }
231 
232 //////////////////////////////////////////////////////////////////////////////
233 // eof
234