1f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3f6e50924SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4f6e50924SAndrew Rist * or more contributor license agreements. See the NOTICE file
5f6e50924SAndrew Rist * distributed with this work for additional information
6f6e50924SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7f6e50924SAndrew Rist * to you under the Apache License, Version 2.0 (the
8f6e50924SAndrew Rist * "License"); you may not use this file except in compliance
9f6e50924SAndrew Rist * with the License. You may obtain a copy of the License at
10f6e50924SAndrew Rist *
11f6e50924SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12f6e50924SAndrew Rist *
13f6e50924SAndrew Rist * Unless required by applicable law or agreed to in writing,
14f6e50924SAndrew Rist * software distributed under the License is distributed on an
15f6e50924SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f6e50924SAndrew Rist * KIND, either express or implied. See the License for the
17f6e50924SAndrew Rist * specific language governing permissions and limitations
18f6e50924SAndrew Rist * under the License.
19f6e50924SAndrew Rist *
20f6e50924SAndrew Rist *************************************************************/
21f6e50924SAndrew Rist
22cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
23cdf0e10cSrcweir #include "precompiled_svx.hxx"
24cdf0e10cSrcweir
25cdf0e10cSrcweir // include ---------------------------------------------------------------
26cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
27cdf0e10cSrcweir #include "svx/XPropertyTable.hxx"
28cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx>
29cdf0e10cSrcweir #include "xmlxtexp.hxx"
30cdf0e10cSrcweir #include "xmlxtimp.hxx"
31cdf0e10cSrcweir #include <tools/urlobj.hxx>
32cdf0e10cSrcweir #include <vcl/virdev.hxx>
33cdf0e10cSrcweir #include <vcl/svapp.hxx>
34cdf0e10cSrcweir #include <svx/dialogs.hrc>
35cdf0e10cSrcweir #include <svx/dialmgr.hxx>
36cdf0e10cSrcweir #include <svx/xtable.hxx>
3735726d9dSArmin Le Grand #include <drawinglayer/attribute/linestartendattribute.hxx>
3835726d9dSArmin Le Grand #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
3935726d9dSArmin Le Grand #include <drawinglayer/processor2d/processor2dtools.hxx>
40cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx>
41cdf0e10cSrcweir
42cdf0e10cSrcweir #define GLOBALOVERFLOW
43cdf0e10cSrcweir
44cdf0e10cSrcweir using namespace com::sun::star;
45cdf0e10cSrcweir using namespace rtl;
46cdf0e10cSrcweir
47cdf0e10cSrcweir sal_Unicode const pszExtLineEnd[] = {'s','o','e'};
4897e8a929SArmin Le Grand //static char const aChckLEnd[] = { 0x04, 0x00, 'S','O','E','L'}; // < 5.2
4997e8a929SArmin Le Grand //static char const aChckLEnd0[] = { 0x04, 0x00, 'S','O','E','0'}; // = 5.2
5097e8a929SArmin Le Grand //static char const aChckXML[] = { '<', '?', 'x', 'm', 'l' }; // = 6.0
51cdf0e10cSrcweir
52cdf0e10cSrcweir // --------------------
53cdf0e10cSrcweir // class XLineEndList
54cdf0e10cSrcweir // --------------------
55cdf0e10cSrcweir
XLineEndList(const String & rPath)56c7be74b1SArmin Le Grand XLineEndList::XLineEndList(const String& rPath)
5735726d9dSArmin Le Grand : XPropertyList(rPath)
58cdf0e10cSrcweir {
59cdf0e10cSrcweir }
60cdf0e10cSrcweir
~XLineEndList()61cdf0e10cSrcweir XLineEndList::~XLineEndList()
62cdf0e10cSrcweir {
63cdf0e10cSrcweir }
64cdf0e10cSrcweir
Replace(XLineEndEntry * pEntry,long nIndex)65cdf0e10cSrcweir XLineEndEntry* XLineEndList::Replace(XLineEndEntry* pEntry, long nIndex )
66cdf0e10cSrcweir {
67cdf0e10cSrcweir return (XLineEndEntry*) XPropertyList::Replace(pEntry, nIndex);
68cdf0e10cSrcweir }
69cdf0e10cSrcweir
Remove(long nIndex)70cdf0e10cSrcweir XLineEndEntry* XLineEndList::Remove(long nIndex)
71cdf0e10cSrcweir {
72c7be74b1SArmin Le Grand return (XLineEndEntry*) XPropertyList::Remove(nIndex);
73cdf0e10cSrcweir }
74cdf0e10cSrcweir
GetLineEnd(long nIndex) const75cdf0e10cSrcweir XLineEndEntry* XLineEndList::GetLineEnd(long nIndex) const
76cdf0e10cSrcweir {
77c7be74b1SArmin Le Grand return (XLineEndEntry*) XPropertyList::Get(nIndex);
78cdf0e10cSrcweir }
79cdf0e10cSrcweir
Load()803e407bd8SArmin Le Grand bool XLineEndList::Load()
81cdf0e10cSrcweir {
8297e8a929SArmin Le Grand if( mbListDirty )
83cdf0e10cSrcweir {
8497e8a929SArmin Le Grand mbListDirty = false;
85cdf0e10cSrcweir
8697e8a929SArmin Le Grand INetURLObject aURL( maPath );
87cdf0e10cSrcweir
88cdf0e10cSrcweir if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
89cdf0e10cSrcweir {
9035726d9dSArmin Le Grand OSL_ENSURE( !maPath.Len(), "invalid URL" );
913e407bd8SArmin Le Grand return false;
92cdf0e10cSrcweir }
93cdf0e10cSrcweir
9497e8a929SArmin Le Grand aURL.Append( maName );
95cdf0e10cSrcweir
96cdf0e10cSrcweir if( !aURL.getExtension().getLength() )
97cdf0e10cSrcweir aURL.setExtension( rtl::OUString( pszExtLineEnd, 3 ) );
98cdf0e10cSrcweir
99cdf0e10cSrcweir uno::Reference< container::XNameContainer > xTable( SvxUnoXLineEndTable_createInstance( this ), uno::UNO_QUERY );
100cdf0e10cSrcweir return SvxXMLXTableImport::load( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable );
101cdf0e10cSrcweir }
1023e407bd8SArmin Le Grand
1033e407bd8SArmin Le Grand return false;
104cdf0e10cSrcweir }
105cdf0e10cSrcweir
Save()1063e407bd8SArmin Le Grand bool XLineEndList::Save()
107cdf0e10cSrcweir {
10897e8a929SArmin Le Grand INetURLObject aURL( maPath );
109cdf0e10cSrcweir
110cdf0e10cSrcweir if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
111cdf0e10cSrcweir {
11235726d9dSArmin Le Grand OSL_ENSURE( !maPath.Len(), "invalid URL" );
1133e407bd8SArmin Le Grand return false;
114cdf0e10cSrcweir }
115cdf0e10cSrcweir
11697e8a929SArmin Le Grand aURL.Append( maName );
117cdf0e10cSrcweir
118cdf0e10cSrcweir if( !aURL.getExtension().getLength() )
119cdf0e10cSrcweir aURL.setExtension( rtl::OUString( pszExtLineEnd, 3 ) );
120cdf0e10cSrcweir
121cdf0e10cSrcweir uno::Reference< container::XNameContainer > xTable( SvxUnoXLineEndTable_createInstance( this ), uno::UNO_QUERY );
122cdf0e10cSrcweir return SvxXMLXTableExportComponent::save( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable );
123cdf0e10cSrcweir }
124cdf0e10cSrcweir
Create()1253e407bd8SArmin Le Grand bool XLineEndList::Create()
126cdf0e10cSrcweir {
127cdf0e10cSrcweir basegfx::B2DPolygon aTriangle;
128cdf0e10cSrcweir aTriangle.append(basegfx::B2DPoint(10.0, 0.0));
129cdf0e10cSrcweir aTriangle.append(basegfx::B2DPoint(0.0, 30.0));
130cdf0e10cSrcweir aTriangle.append(basegfx::B2DPoint(20.0, 30.0));
131cdf0e10cSrcweir aTriangle.setClosed(true);
132cdf0e10cSrcweir Insert( new XLineEndEntry( basegfx::B2DPolyPolygon(aTriangle), SVX_RESSTR( RID_SVXSTR_ARROW ) ) );
133cdf0e10cSrcweir
134cdf0e10cSrcweir basegfx::B2DPolygon aSquare;
135cdf0e10cSrcweir aSquare.append(basegfx::B2DPoint(0.0, 0.0));
136cdf0e10cSrcweir aSquare.append(basegfx::B2DPoint(10.0, 0.0));
137cdf0e10cSrcweir aSquare.append(basegfx::B2DPoint(10.0, 10.0));
138cdf0e10cSrcweir aSquare.append(basegfx::B2DPoint(0.0, 10.0));
139cdf0e10cSrcweir aSquare.setClosed(true);
140cdf0e10cSrcweir Insert( new XLineEndEntry( basegfx::B2DPolyPolygon(aSquare), SVX_RESSTR( RID_SVXSTR_SQUARE ) ) );
141cdf0e10cSrcweir
142cdf0e10cSrcweir basegfx::B2DPolygon aCircle(basegfx::tools::createPolygonFromCircle(basegfx::B2DPoint(0.0, 0.0), 100.0));
143cdf0e10cSrcweir Insert( new XLineEndEntry( basegfx::B2DPolyPolygon(aCircle), SVX_RESSTR( RID_SVXSTR_CIRCLE ) ) );
144cdf0e10cSrcweir
1453e407bd8SArmin Le Grand return true;
146cdf0e10cSrcweir }
147cdf0e10cSrcweir
CreateBitmapForUI(long nIndex)14897e8a929SArmin Le Grand Bitmap XLineEndList::CreateBitmapForUI( long nIndex )
149cdf0e10cSrcweir {
150c7be74b1SArmin Le Grand Bitmap aRetval;
15135726d9dSArmin Le Grand OSL_ENSURE(nIndex < Count(), "OOps, access out of range (!)");
152cdf0e10cSrcweir
15335726d9dSArmin Le Grand if(nIndex < Count())
154c7be74b1SArmin Le Grand {
155c7be74b1SArmin Le Grand const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
156c7be74b1SArmin Le Grand const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize();
15735726d9dSArmin Le Grand const Size aSize(rSize.Width() * 2, rSize.Height());
15835726d9dSArmin Le Grand
15935726d9dSArmin Le Grand // prepare line geometry
16035726d9dSArmin Le Grand basegfx::B2DPolygon aLine;
16135726d9dSArmin Le Grand const double fBorderDistance(aSize.Height() * 0.1);
16235726d9dSArmin Le Grand
16335726d9dSArmin Le Grand aLine.append(basegfx::B2DPoint(fBorderDistance, aSize.Height() / 2));
16435726d9dSArmin Le Grand aLine.append(basegfx::B2DPoint(aSize.Width() - fBorderDistance, aSize.Height() / 2));
16535726d9dSArmin Le Grand
16635726d9dSArmin Le Grand // prepare LineAttribute
16735726d9dSArmin Le Grand const basegfx::BColor aLineColor(rStyleSettings.GetFieldTextColor().getBColor());
16835726d9dSArmin Le Grand const double fLineWidth(rStyleSettings.GetListBoxPreviewDefaultLineWidth() * 1.1);
16935726d9dSArmin Le Grand const drawinglayer::attribute::LineAttribute aLineAttribute(
17035726d9dSArmin Le Grand aLineColor,
17135726d9dSArmin Le Grand fLineWidth);
17235726d9dSArmin Le Grand
17335726d9dSArmin Le Grand const basegfx::B2DPolyPolygon aLineEnd(GetLineEnd(nIndex)->GetLineEnd());
17435726d9dSArmin Le Grand const double fArrowHeight(aSize.Height() - (2.0 * fBorderDistance));
17535726d9dSArmin Le Grand const drawinglayer::attribute::LineStartEndAttribute aLineStartEndAttribute(
17635726d9dSArmin Le Grand fArrowHeight,
17735726d9dSArmin Le Grand aLineEnd,
17835726d9dSArmin Le Grand false);
17935726d9dSArmin Le Grand
18035726d9dSArmin Le Grand // prepare line primitive
18135726d9dSArmin Le Grand const drawinglayer::primitive2d::Primitive2DReference aLineStartEndPrimitive(
18235726d9dSArmin Le Grand new drawinglayer::primitive2d::PolygonStrokeArrowPrimitive2D(
18335726d9dSArmin Le Grand aLine,
18435726d9dSArmin Le Grand aLineAttribute,
18535726d9dSArmin Le Grand aLineStartEndAttribute,
18635726d9dSArmin Le Grand aLineStartEndAttribute));
18735726d9dSArmin Le Grand
18835726d9dSArmin Le Grand // prepare VirtualDevice
18935726d9dSArmin Le Grand VirtualDevice aVirtualDevice;
19035726d9dSArmin Le Grand const drawinglayer::geometry::ViewInformation2D aNewViewInformation2D;
19135726d9dSArmin Le Grand
19235726d9dSArmin Le Grand aVirtualDevice.SetOutputSizePixel(aSize);
19335726d9dSArmin Le Grand aVirtualDevice.SetDrawMode(rStyleSettings.GetHighContrastMode()
194c7be74b1SArmin Le Grand ? DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT
195c7be74b1SArmin Le Grand : DRAWMODE_DEFAULT);
196c7be74b1SArmin Le Grand
197*33b19716SArmin Le Grand if(rStyleSettings.GetPreviewUsesCheckeredBackground())
198c7be74b1SArmin Le Grand {
19935726d9dSArmin Le Grand const Point aNull(0, 0);
20035726d9dSArmin Le Grand static const sal_uInt32 nLen(8);
20135726d9dSArmin Le Grand static const Color aW(COL_WHITE);
20235726d9dSArmin Le Grand static const Color aG(0xef, 0xef, 0xef);
203c7be74b1SArmin Le Grand
20435726d9dSArmin Le Grand aVirtualDevice.DrawCheckered(aNull, aSize, nLen, aW, aG);
20535726d9dSArmin Le Grand }
20635726d9dSArmin Le Grand else
207c7be74b1SArmin Le Grand {
20835726d9dSArmin Le Grand aVirtualDevice.SetBackground(rStyleSettings.GetFieldColor());
20935726d9dSArmin Le Grand aVirtualDevice.Erase();
210c7be74b1SArmin Le Grand }
211c7be74b1SArmin Le Grand
21235726d9dSArmin Le Grand // create processor and draw primitives
21335726d9dSArmin Le Grand drawinglayer::processor2d::BaseProcessor2D* pProcessor2D = drawinglayer::processor2d::createPixelProcessor2DFromOutputDevice(
21435726d9dSArmin Le Grand aVirtualDevice,
21535726d9dSArmin Le Grand aNewViewInformation2D);
216c7be74b1SArmin Le Grand
21735726d9dSArmin Le Grand if(pProcessor2D)
21835726d9dSArmin Le Grand {
21935726d9dSArmin Le Grand const drawinglayer::primitive2d::Primitive2DSequence aSequence(&aLineStartEndPrimitive, 1);
220c7be74b1SArmin Le Grand
22135726d9dSArmin Le Grand pProcessor2D->process(aSequence);
22235726d9dSArmin Le Grand delete pProcessor2D;
22335726d9dSArmin Le Grand }
224c7be74b1SArmin Le Grand
22535726d9dSArmin Le Grand // get result bitmap and scale
22635726d9dSArmin Le Grand aRetval = aVirtualDevice.GetBitmap(Point(0, 0), aVirtualDevice.GetOutputSizePixel());
227c7be74b1SArmin Le Grand }
228cdf0e10cSrcweir
229c7be74b1SArmin Le Grand return aRetval;
230cdf0e10cSrcweir }
231cdf0e10cSrcweir
232cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
233cdf0e10cSrcweir // eof
234