xref: /trunk/main/svx/source/xoutdev/xtablend.cxx (revision a68b38df8f36d7e7f7b866ad7a09436e835bfe07)
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 ---------------------------------------------------------------
28 
29 #ifndef SVX_LIGHT
30 
31 #include <com/sun/star/container/XNameContainer.hpp>
32 #include "svx/XPropertyTable.hxx"
33 #include <unotools/ucbstreamhelper.hxx>
34 
35 #include "xmlxtexp.hxx"
36 #include "xmlxtimp.hxx"
37 
38 #endif
39 #include <tools/urlobj.hxx>
40 #include <vcl/virdev.hxx>
41 
42 #ifndef _SV_APP_HXX
43 #include <vcl/svapp.hxx>
44 #endif
45 #include <svl/itemset.hxx>
46 #include <sfx2/docfile.hxx>
47 
48 #include <svx/dialogs.hrc>
49 #include <svx/dialmgr.hxx>
50 
51 #include <svx/xtable.hxx>
52 #include <svx/xpool.hxx>
53 #include <svx/xfillit0.hxx>
54 #include <svx/xflclit.hxx>
55 #include <svx/xlnstwit.hxx>
56 #include <svx/xlnedwit.hxx>
57 #include <svx/xlnclit.hxx>
58 #include <svx/xlineit0.hxx>
59 #include <svx/xlnstit.hxx>
60 #include <svx/xlnedit.hxx>
61 #include <basegfx/point/b2dpoint.hxx>
62 #include <basegfx/polygon/b2dpolygon.hxx>
63 #include <basegfx/polygon/b2dpolygontools.hxx>
64 
65 #include <svx/svdorect.hxx>
66 #include <svx/svdopath.hxx>
67 #include <svx/svdmodel.hxx>
68 #include <svx/sdr/contact/objectcontactofobjlistpainter.hxx>
69 #include <svx/sdr/contact/displayinfo.hxx>
70 #include <svx/xlnwtit.hxx>
71 
72 #define GLOBALOVERFLOW
73 
74 using namespace com::sun::star;
75 using namespace rtl;
76 
77 sal_Unicode const pszExtLineEnd[]   = {'s','o','e'};
78 //static char const aChckLEnd[]  = { 0x04, 0x00, 'S','O','E','L'};  // < 5.2
79 //static char const aChckLEnd0[] = { 0x04, 0x00, 'S','O','E','0'};  // = 5.2
80 //static char const aChckXML[]   = { '<', '?', 'x', 'm', 'l' };     // = 6.0
81 
82 // --------------------
83 // class XLineEndList
84 // --------------------
85 
86 class impXLineEndList
87 {
88 private:
89     VirtualDevice*          mpVirtualDevice;
90     SdrModel*               mpSdrModel;
91     SdrObject*              mpBackgroundObject;
92     SdrObject*              mpLineObject;
93 
94 public:
95     impXLineEndList(VirtualDevice* pV, SdrModel* pM, SdrObject* pB, SdrObject* pL)
96     :   mpVirtualDevice(pV),
97         mpSdrModel(pM),
98         mpBackgroundObject(pB),
99         mpLineObject(pL)
100     {}
101 
102     ~impXLineEndList()
103     {
104         delete mpVirtualDevice;
105         SdrObject::Free(mpBackgroundObject);
106         SdrObject::Free(mpLineObject);
107         delete mpSdrModel;
108     }
109 
110     VirtualDevice* getVirtualDevice() const { return mpVirtualDevice; }
111     SdrObject* getBackgroundObject() const { return mpBackgroundObject; }
112     SdrObject* getLineObject() const { return mpLineObject; }
113 };
114 
115 void XLineEndList::impCreate()
116 {
117     if(!mpData)
118     {
119         const Point aZero(0, 0);
120         const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
121 
122         VirtualDevice* pVirDev = new VirtualDevice;
123         OSL_ENSURE(0 != pVirDev, "XLineEndList: no VirtualDevice created!" );
124         pVirDev->SetMapMode(MAP_100TH_MM);
125         const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize();
126         const Size aSize(pVirDev->PixelToLogic(Size(rSize.Width() * 2, rSize.Height())));
127         pVirDev->SetOutputSize(aSize);
128         pVirDev->SetDrawMode(rStyleSettings.GetHighContrastMode()
129             ? DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT
130             : DRAWMODE_DEFAULT);
131         pVirDev->SetBackground(rStyleSettings.GetFieldColor());
132 
133         SdrModel* pSdrModel = new SdrModel();
134         OSL_ENSURE(0 != pSdrModel, "XLineEndList: no SdrModel created!" );
135         pSdrModel->GetItemPool().FreezeIdRanges();
136 
137         const Rectangle aBackgroundSize(aZero, aSize);
138         SdrObject* pBackgroundObject = new SdrRectObj(aBackgroundSize);
139         OSL_ENSURE(0 != pBackgroundObject, "XLineEndList: no BackgroundObject created!" );
140         pBackgroundObject->SetModel(pSdrModel);
141         pBackgroundObject->SetMergedItem(XFillStyleItem(XFILL_SOLID));
142         pBackgroundObject->SetMergedItem(XLineStyleItem(XLINE_NONE));
143         pBackgroundObject->SetMergedItem(XFillColorItem(String(), rStyleSettings.GetFieldColor()));
144 
145         const basegfx::B2DPoint aStart(0, aSize.Height() / 2);
146         const basegfx::B2DPoint aEnd(aSize.Width(), aSize.Height() / 2);
147         basegfx::B2DPolygon aPolygon;
148         aPolygon.append(aStart);
149         aPolygon.append(aEnd);
150         SdrObject* pLineObject = new SdrPathObj(OBJ_LINE, basegfx::B2DPolyPolygon(aPolygon));
151         OSL_ENSURE(0 != pLineObject, "XLineEndList: no LineObject created!" );
152         pLineObject->SetModel(pSdrModel);
153         const Size aLineWidth(pVirDev->PixelToLogic(Size(rStyleSettings.GetListBoxPreviewDefaultLineWidth(), 0)));
154         pLineObject->SetMergedItem(XLineWidthItem(aLineWidth.getWidth()));
155         const sal_uInt32 nArrowHeight((aSize.Height() * 8) / 10);
156         pLineObject->SetMergedItem(XLineStartWidthItem(nArrowHeight));
157         pLineObject->SetMergedItem(XLineEndWidthItem(nArrowHeight));
158         pLineObject->SetMergedItem(XLineColorItem(String(), rStyleSettings.GetFieldTextColor()));
159 
160         mpData = new impXLineEndList(pVirDev, pSdrModel, pBackgroundObject, pLineObject);
161         OSL_ENSURE(0 != mpData, "XLineEndList: data creation went wrong!" );
162     }
163 }
164 
165 void XLineEndList::impDestroy()
166 {
167     if(mpData)
168     {
169         delete mpData;
170         mpData = 0;
171     }
172 }
173 
174 XLineEndList::XLineEndList(const String& rPath, XOutdevItemPool* _pXPool)
175 :   XPropertyList(rPath, _pXPool),
176     mpData(0)
177 {
178 }
179 
180 XLineEndList::~XLineEndList()
181 {
182     impDestroy();
183 }
184 
185 XLineEndEntry* XLineEndList::Replace(XLineEndEntry* pEntry, long nIndex )
186 {
187     return (XLineEndEntry*) XPropertyList::Replace(pEntry, nIndex);
188 }
189 
190 XLineEndEntry* XLineEndList::Remove(long nIndex)
191 {
192     return (XLineEndEntry*) XPropertyList::Remove(nIndex, 0);
193 }
194 
195 XLineEndEntry* XLineEndList::GetLineEnd(long nIndex) const
196 {
197     return (XLineEndEntry*) XPropertyList::Get(nIndex, 0);
198 }
199 
200 sal_Bool XLineEndList::Load()
201 {
202     if( mbListDirty )
203     {
204         mbListDirty = false;
205 
206         INetURLObject aURL( maPath );
207 
208         if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
209         {
210             DBG_ASSERT( !maPath.Len(), "invalid URL" );
211             return sal_False;
212         }
213 
214         aURL.Append( maName );
215 
216         if( !aURL.getExtension().getLength() )
217             aURL.setExtension( rtl::OUString( pszExtLineEnd, 3 ) );
218 
219         uno::Reference< container::XNameContainer > xTable( SvxUnoXLineEndTable_createInstance( this ), uno::UNO_QUERY );
220         return SvxXMLXTableImport::load( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable );
221     }
222     return( sal_False );
223 }
224 
225 sal_Bool XLineEndList::Save()
226 {
227     INetURLObject aURL( maPath );
228 
229     if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
230     {
231         DBG_ASSERT( !maPath.Len(), "invalid URL" );
232         return sal_False;
233     }
234 
235     aURL.Append( maName );
236 
237     if( !aURL.getExtension().getLength() )
238         aURL.setExtension( rtl::OUString( pszExtLineEnd, 3 ) );
239 
240     uno::Reference< container::XNameContainer > xTable( SvxUnoXLineEndTable_createInstance( this ), uno::UNO_QUERY );
241     return SvxXMLXTableExportComponent::save( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable );
242 }
243 
244 sal_Bool XLineEndList::Create()
245 {
246     basegfx::B2DPolygon aTriangle;
247     aTriangle.append(basegfx::B2DPoint(10.0, 0.0));
248     aTriangle.append(basegfx::B2DPoint(0.0, 30.0));
249     aTriangle.append(basegfx::B2DPoint(20.0, 30.0));
250     aTriangle.setClosed(true);
251     Insert( new XLineEndEntry( basegfx::B2DPolyPolygon(aTriangle), SVX_RESSTR( RID_SVXSTR_ARROW ) ) );
252 
253     basegfx::B2DPolygon aSquare;
254     aSquare.append(basegfx::B2DPoint(0.0, 0.0));
255     aSquare.append(basegfx::B2DPoint(10.0, 0.0));
256     aSquare.append(basegfx::B2DPoint(10.0, 10.0));
257     aSquare.append(basegfx::B2DPoint(0.0, 10.0));
258     aSquare.setClosed(true);
259     Insert( new XLineEndEntry( basegfx::B2DPolyPolygon(aSquare), SVX_RESSTR( RID_SVXSTR_SQUARE ) ) );
260 
261     basegfx::B2DPolygon aCircle(basegfx::tools::createPolygonFromCircle(basegfx::B2DPoint(0.0, 0.0), 100.0));
262     Insert( new XLineEndEntry( basegfx::B2DPolyPolygon(aCircle), SVX_RESSTR( RID_SVXSTR_CIRCLE ) ) );
263 
264     return( sal_True );
265 }
266 
267 Bitmap XLineEndList::CreateBitmapForUI( long nIndex )
268 {
269     impCreate();
270     VirtualDevice* pVD = mpData->getVirtualDevice();
271     SdrObject* pLine = mpData->getLineObject();
272 
273     pLine->SetMergedItem(XLineStyleItem(XLINE_SOLID));
274     pLine->SetMergedItem(XLineStartItem(String(), GetLineEnd(nIndex)->GetLineEnd()));
275     pLine->SetMergedItem(XLineEndItem(String(), GetLineEnd(nIndex)->GetLineEnd()));
276 
277     sdr::contact::SdrObjectVector aObjectVector;
278     aObjectVector.push_back(mpData->getBackgroundObject());
279     aObjectVector.push_back(pLine);
280     sdr::contact::ObjectContactOfObjListPainter aPainter(*pVD, aObjectVector, 0);
281     sdr::contact::DisplayInfo aDisplayInfo;
282 
283     pVD->Erase();
284     aPainter.ProcessDisplay(aDisplayInfo);
285 
286     const Point aZero(0, 0);
287     return pVD->GetBitmap(aZero, pVD->GetOutputSize());
288 }
289 
290 //////////////////////////////////////////////////////////////////////////////
291 // eof
292