xref: /AOO42X/main/svx/source/xoutdev/xtablend.cxx (revision c7be74b172cff98608900673693e02cf2b814c3c)
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
10cdf0e10cSrcweir  *
11f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
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.
19cdf0e10cSrcweir  *
20f6e50924SAndrew Rist  *************************************************************/
21f6e50924SAndrew Rist 
22f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir // include ---------------------------------------------------------------
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #ifndef SVX_LIGHT
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
32cdf0e10cSrcweir #include "svx/XPropertyTable.hxx"
33cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir #include "xmlxtexp.hxx"
36cdf0e10cSrcweir #include "xmlxtimp.hxx"
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #endif
39cdf0e10cSrcweir #include <tools/urlobj.hxx>
40cdf0e10cSrcweir #include <vcl/virdev.hxx>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir #ifndef _SV_APP_HXX
43cdf0e10cSrcweir #include <vcl/svapp.hxx>
44cdf0e10cSrcweir #endif
45cdf0e10cSrcweir #include <svl/itemset.hxx>
46cdf0e10cSrcweir #include <sfx2/docfile.hxx>
47cdf0e10cSrcweir 
48cdf0e10cSrcweir #include <svx/dialogs.hrc>
49cdf0e10cSrcweir #include <svx/dialmgr.hxx>
50cdf0e10cSrcweir 
51cdf0e10cSrcweir #include <svx/xtable.hxx>
52cdf0e10cSrcweir #include <svx/xpool.hxx>
53cdf0e10cSrcweir #include <svx/xfillit0.hxx>
54cdf0e10cSrcweir #include <svx/xflclit.hxx>
55cdf0e10cSrcweir #include <svx/xlnstwit.hxx>
56cdf0e10cSrcweir #include <svx/xlnedwit.hxx>
57cdf0e10cSrcweir #include <svx/xlnclit.hxx>
58cdf0e10cSrcweir #include <svx/xlineit0.hxx>
59cdf0e10cSrcweir #include <svx/xlnstit.hxx>
60cdf0e10cSrcweir #include <svx/xlnedit.hxx>
61cdf0e10cSrcweir #include <basegfx/point/b2dpoint.hxx>
62cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx>
63cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx>
64cdf0e10cSrcweir 
65cdf0e10cSrcweir #include <svx/svdorect.hxx>
66cdf0e10cSrcweir #include <svx/svdopath.hxx>
67cdf0e10cSrcweir #include <svx/svdmodel.hxx>
68cdf0e10cSrcweir #include <svx/sdr/contact/objectcontactofobjlistpainter.hxx>
69cdf0e10cSrcweir #include <svx/sdr/contact/displayinfo.hxx>
7097e8a929SArmin Le Grand #include <svx/xlnwtit.hxx>
71cdf0e10cSrcweir 
72cdf0e10cSrcweir #define GLOBALOVERFLOW
73cdf0e10cSrcweir 
74cdf0e10cSrcweir using namespace com::sun::star;
75cdf0e10cSrcweir using namespace rtl;
76cdf0e10cSrcweir 
77cdf0e10cSrcweir sal_Unicode const pszExtLineEnd[]   = {'s','o','e'};
7897e8a929SArmin Le Grand //static char const aChckLEnd[]  = { 0x04, 0x00, 'S','O','E','L'};  // < 5.2
7997e8a929SArmin Le Grand //static char const aChckLEnd0[] = { 0x04, 0x00, 'S','O','E','0'};  // = 5.2
8097e8a929SArmin Le Grand //static char const aChckXML[]   = { '<', '?', 'x', 'm', 'l' };     // = 6.0
81cdf0e10cSrcweir 
82cdf0e10cSrcweir // --------------------
83cdf0e10cSrcweir // class XLineEndList
84cdf0e10cSrcweir // --------------------
85cdf0e10cSrcweir 
86*c7be74b1SArmin Le Grand XLineEndList::XLineEndList(const String& rPath)
87*c7be74b1SArmin Le Grand :   XPropertyList(rPath),
88*c7be74b1SArmin Le Grand     mpBackgroundObject(0),
89*c7be74b1SArmin Le Grand     mpLineObject(0)
90cdf0e10cSrcweir {
91cdf0e10cSrcweir }
92cdf0e10cSrcweir 
93cdf0e10cSrcweir XLineEndList::~XLineEndList()
94cdf0e10cSrcweir {
95*c7be74b1SArmin Le Grand     SdrObject::Free(mpBackgroundObject);
96*c7be74b1SArmin Le Grand     SdrObject::Free(mpLineObject);
97cdf0e10cSrcweir }
98cdf0e10cSrcweir 
99cdf0e10cSrcweir XLineEndEntry* XLineEndList::Replace(XLineEndEntry* pEntry, long nIndex )
100cdf0e10cSrcweir {
101cdf0e10cSrcweir     return (XLineEndEntry*) XPropertyList::Replace(pEntry, nIndex);
102cdf0e10cSrcweir }
103cdf0e10cSrcweir 
104cdf0e10cSrcweir XLineEndEntry* XLineEndList::Remove(long nIndex)
105cdf0e10cSrcweir {
106*c7be74b1SArmin Le Grand     return (XLineEndEntry*) XPropertyList::Remove(nIndex);
107cdf0e10cSrcweir }
108cdf0e10cSrcweir 
109cdf0e10cSrcweir XLineEndEntry* XLineEndList::GetLineEnd(long nIndex) const
110cdf0e10cSrcweir {
111*c7be74b1SArmin Le Grand     return (XLineEndEntry*) XPropertyList::Get(nIndex);
112cdf0e10cSrcweir }
113cdf0e10cSrcweir 
114cdf0e10cSrcweir sal_Bool XLineEndList::Load()
115cdf0e10cSrcweir {
11697e8a929SArmin Le Grand     if( mbListDirty )
117cdf0e10cSrcweir     {
11897e8a929SArmin Le Grand         mbListDirty = false;
119cdf0e10cSrcweir 
12097e8a929SArmin Le Grand         INetURLObject aURL( maPath );
121cdf0e10cSrcweir 
122cdf0e10cSrcweir         if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
123cdf0e10cSrcweir         {
12497e8a929SArmin Le Grand             DBG_ASSERT( !maPath.Len(), "invalid URL" );
125cdf0e10cSrcweir             return sal_False;
126cdf0e10cSrcweir         }
127cdf0e10cSrcweir 
12897e8a929SArmin Le Grand         aURL.Append( maName );
129cdf0e10cSrcweir 
130cdf0e10cSrcweir         if( !aURL.getExtension().getLength() )
131cdf0e10cSrcweir             aURL.setExtension( rtl::OUString( pszExtLineEnd, 3 ) );
132cdf0e10cSrcweir 
133cdf0e10cSrcweir         uno::Reference< container::XNameContainer > xTable( SvxUnoXLineEndTable_createInstance( this ), uno::UNO_QUERY );
134cdf0e10cSrcweir         return SvxXMLXTableImport::load( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable );
135cdf0e10cSrcweir     }
136cdf0e10cSrcweir     return( sal_False );
137cdf0e10cSrcweir }
138cdf0e10cSrcweir 
139cdf0e10cSrcweir sal_Bool XLineEndList::Save()
140cdf0e10cSrcweir {
14197e8a929SArmin Le Grand     INetURLObject aURL( maPath );
142cdf0e10cSrcweir 
143cdf0e10cSrcweir     if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
144cdf0e10cSrcweir     {
14597e8a929SArmin Le Grand         DBG_ASSERT( !maPath.Len(), "invalid URL" );
146cdf0e10cSrcweir         return sal_False;
147cdf0e10cSrcweir     }
148cdf0e10cSrcweir 
14997e8a929SArmin Le Grand     aURL.Append( maName );
150cdf0e10cSrcweir 
151cdf0e10cSrcweir     if( !aURL.getExtension().getLength() )
152cdf0e10cSrcweir         aURL.setExtension( rtl::OUString( pszExtLineEnd, 3 ) );
153cdf0e10cSrcweir 
154cdf0e10cSrcweir     uno::Reference< container::XNameContainer > xTable( SvxUnoXLineEndTable_createInstance( this ), uno::UNO_QUERY );
155cdf0e10cSrcweir     return SvxXMLXTableExportComponent::save( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable );
156cdf0e10cSrcweir }
157cdf0e10cSrcweir 
158cdf0e10cSrcweir sal_Bool XLineEndList::Create()
159cdf0e10cSrcweir {
160cdf0e10cSrcweir     basegfx::B2DPolygon aTriangle;
161cdf0e10cSrcweir     aTriangle.append(basegfx::B2DPoint(10.0, 0.0));
162cdf0e10cSrcweir     aTriangle.append(basegfx::B2DPoint(0.0, 30.0));
163cdf0e10cSrcweir     aTriangle.append(basegfx::B2DPoint(20.0, 30.0));
164cdf0e10cSrcweir     aTriangle.setClosed(true);
165cdf0e10cSrcweir     Insert( new XLineEndEntry( basegfx::B2DPolyPolygon(aTriangle), SVX_RESSTR( RID_SVXSTR_ARROW ) ) );
166cdf0e10cSrcweir 
167cdf0e10cSrcweir     basegfx::B2DPolygon aSquare;
168cdf0e10cSrcweir     aSquare.append(basegfx::B2DPoint(0.0, 0.0));
169cdf0e10cSrcweir     aSquare.append(basegfx::B2DPoint(10.0, 0.0));
170cdf0e10cSrcweir     aSquare.append(basegfx::B2DPoint(10.0, 10.0));
171cdf0e10cSrcweir     aSquare.append(basegfx::B2DPoint(0.0, 10.0));
172cdf0e10cSrcweir     aSquare.setClosed(true);
173cdf0e10cSrcweir     Insert( new XLineEndEntry( basegfx::B2DPolyPolygon(aSquare), SVX_RESSTR( RID_SVXSTR_SQUARE ) ) );
174cdf0e10cSrcweir 
175cdf0e10cSrcweir     basegfx::B2DPolygon aCircle(basegfx::tools::createPolygonFromCircle(basegfx::B2DPoint(0.0, 0.0), 100.0));
176cdf0e10cSrcweir     Insert( new XLineEndEntry( basegfx::B2DPolyPolygon(aCircle), SVX_RESSTR( RID_SVXSTR_CIRCLE ) ) );
177cdf0e10cSrcweir 
178cdf0e10cSrcweir     return( sal_True );
179cdf0e10cSrcweir }
180cdf0e10cSrcweir 
18197e8a929SArmin Le Grand Bitmap XLineEndList::CreateBitmapForUI( long nIndex )
182cdf0e10cSrcweir {
183*c7be74b1SArmin Le Grand     Bitmap aRetval;
184*c7be74b1SArmin Le Grand     OSL_ENSURE(pGlobalsharedModelAndVDev, "OOps, global values missing (!)");
185*c7be74b1SArmin Le Grand     OSL_ENSURE(nIndex < Count(), "OOps, global values missing (!)");
186cdf0e10cSrcweir 
187*c7be74b1SArmin Le Grand     if(pGlobalsharedModelAndVDev && nIndex < Count())
188*c7be74b1SArmin Le Grand     {
189*c7be74b1SArmin Le Grand         SdrModel& rModel = pGlobalsharedModelAndVDev->getSharedSdrModel();
190*c7be74b1SArmin Le Grand         VirtualDevice& rVirDev = pGlobalsharedModelAndVDev->getSharedVirtualDevice();
191*c7be74b1SArmin Le Grand         const Point aZero(0, 0);
192*c7be74b1SArmin Le Grand         const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
193*c7be74b1SArmin Le Grand         const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize();
194*c7be74b1SArmin Le Grand         const Size aSize(rVirDev.PixelToLogic(Size(rSize.Width() * 2, rSize.Height())));
195*c7be74b1SArmin Le Grand 
196*c7be74b1SArmin Le Grand         rVirDev.SetOutputSize(aSize);
197*c7be74b1SArmin Le Grand         rVirDev.SetDrawMode(rStyleSettings.GetHighContrastMode()
198*c7be74b1SArmin Le Grand             ? DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT
199*c7be74b1SArmin Le Grand             : DRAWMODE_DEFAULT);
200*c7be74b1SArmin Le Grand         rVirDev.SetBackground(rStyleSettings.GetFieldColor());
201*c7be74b1SArmin Le Grand 
202*c7be74b1SArmin Le Grand         if(!mpBackgroundObject)
203*c7be74b1SArmin Le Grand         {
204*c7be74b1SArmin Le Grand             const Rectangle aBackgroundSize(aZero, aSize);
205*c7be74b1SArmin Le Grand             mpBackgroundObject = new SdrRectObj(aBackgroundSize);
206*c7be74b1SArmin Le Grand             OSL_ENSURE(0 != mpBackgroundObject, "XLineEndList: no BackgroundObject created!" );
207*c7be74b1SArmin Le Grand             mpBackgroundObject->SetModel(&rModel);
208*c7be74b1SArmin Le Grand             mpBackgroundObject->SetMergedItem(XFillStyleItem(XFILL_SOLID));
209*c7be74b1SArmin Le Grand             mpBackgroundObject->SetMergedItem(XLineStyleItem(XLINE_NONE));
210*c7be74b1SArmin Le Grand             mpBackgroundObject->SetMergedItem(XFillColorItem(String(), rStyleSettings.GetFieldColor()));
211*c7be74b1SArmin Le Grand         }
212*c7be74b1SArmin Le Grand 
213*c7be74b1SArmin Le Grand         if(!mpLineObject)
214*c7be74b1SArmin Le Grand         {
215*c7be74b1SArmin Le Grand             const basegfx::B2DPoint aStart(0, aSize.Height() / 2);
216*c7be74b1SArmin Le Grand             const basegfx::B2DPoint aEnd(aSize.Width(), aSize.Height() / 2);
217*c7be74b1SArmin Le Grand             basegfx::B2DPolygon aPolygon;
218*c7be74b1SArmin Le Grand             aPolygon.append(aStart);
219*c7be74b1SArmin Le Grand             aPolygon.append(aEnd);
220*c7be74b1SArmin Le Grand             mpLineObject = new SdrPathObj(OBJ_LINE, basegfx::B2DPolyPolygon(aPolygon));
221*c7be74b1SArmin Le Grand             OSL_ENSURE(0 != mpLineObject, "XLineEndList: no LineObject created!" );
222*c7be74b1SArmin Le Grand             mpLineObject->SetModel(&rModel);
223*c7be74b1SArmin Le Grand             const Size aLineWidth(rVirDev.PixelToLogic(Size(rStyleSettings.GetListBoxPreviewDefaultLineWidth(), 0)));
224*c7be74b1SArmin Le Grand             mpLineObject->SetMergedItem(XLineWidthItem(aLineWidth.getWidth()));
225*c7be74b1SArmin Le Grand             const sal_uInt32 nArrowHeight((aSize.Height() * 8) / 10);
226*c7be74b1SArmin Le Grand             mpLineObject->SetMergedItem(XLineStartWidthItem(nArrowHeight));
227*c7be74b1SArmin Le Grand             mpLineObject->SetMergedItem(XLineEndWidthItem(nArrowHeight));
228*c7be74b1SArmin Le Grand             mpLineObject->SetMergedItem(XLineColorItem(String(), rStyleSettings.GetFieldTextColor()));
229*c7be74b1SArmin Le Grand         }
230*c7be74b1SArmin Le Grand 
231*c7be74b1SArmin Le Grand         mpLineObject->SetMergedItem(XLineStyleItem(XLINE_SOLID));
232*c7be74b1SArmin Le Grand         mpLineObject->SetMergedItem(XLineStartItem(String(), GetLineEnd(nIndex)->GetLineEnd()));
233*c7be74b1SArmin Le Grand         mpLineObject->SetMergedItem(XLineEndItem(String(), GetLineEnd(nIndex)->GetLineEnd()));
234cdf0e10cSrcweir 
235cdf0e10cSrcweir         sdr::contact::SdrObjectVector aObjectVector;
236*c7be74b1SArmin Le Grand 
237*c7be74b1SArmin Le Grand         aObjectVector.push_back(mpBackgroundObject);
238*c7be74b1SArmin Le Grand         aObjectVector.push_back(mpLineObject);
239*c7be74b1SArmin Le Grand 
240*c7be74b1SArmin Le Grand         sdr::contact::ObjectContactOfObjListPainter aPainter(rVirDev, aObjectVector, 0);
241cdf0e10cSrcweir         sdr::contact::DisplayInfo aDisplayInfo;
242cdf0e10cSrcweir 
243*c7be74b1SArmin Le Grand         rVirDev.Erase();
244cdf0e10cSrcweir         aPainter.ProcessDisplay(aDisplayInfo);
245cdf0e10cSrcweir 
246*c7be74b1SArmin Le Grand         aRetval = rVirDev.GetBitmap(aZero, rVirDev.GetOutputSize());
247*c7be74b1SArmin Le Grand     }
248*c7be74b1SArmin Le Grand 
249*c7be74b1SArmin Le Grand     return aRetval;
250cdf0e10cSrcweir }
251cdf0e10cSrcweir 
252cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
253cdf0e10cSrcweir // eof
254