Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / svx / source / xoutdev / xtabdash.cxx
blob41e3547cf0973795f50ba9f70173ce01719a4e74
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 // include ---------------------------------------------------------------
32 #include "svx/XPropertyTable.hxx"
34 #include <vcl/svapp.hxx>
36 #include <vcl/virdev.hxx>
37 #include <vcl/window.hxx>
38 #include <svl/itemset.hxx>
39 #include <svx/dialogs.hrc>
40 #include <svx/dialmgr.hxx>
41 #include <svx/xtable.hxx>
42 #include <svx/xpool.hxx>
43 #include <svx/xlineit0.hxx>
44 #include <svx/xlnclit.hxx>
45 #include <svx/xlnwtit.hxx>
46 #include <svx/xlndsit.hxx>
47 #include <svx/xflclit.hxx>
49 #include <svx/svdorect.hxx>
50 #include <svx/svdopath.hxx>
51 #include <svx/svdmodel.hxx>
52 #include <svx/sdr/contact/objectcontactofobjlistpainter.hxx>
53 #include <svx/sdr/contact/displayinfo.hxx>
54 #include <basegfx/polygon/b2dpolygon.hxx>
56 using namespace com::sun::star;
58 class impXDashList
60 private:
61 VirtualDevice* mpVirtualDevice;
62 SdrModel* mpSdrModel;
63 SdrObject* mpBackgroundObject;
64 SdrObject* mpLineObject;
66 public:
67 impXDashList(VirtualDevice* pV, SdrModel* pM, SdrObject* pB, SdrObject* pL)
68 : mpVirtualDevice(pV),
69 mpSdrModel(pM),
70 mpBackgroundObject(pB),
71 mpLineObject(pL)
74 ~impXDashList()
76 delete mpVirtualDevice;
77 SdrObject::Free(mpBackgroundObject);
78 SdrObject::Free(mpLineObject);
79 delete mpSdrModel;
82 VirtualDevice* getVirtualDevice() const { return mpVirtualDevice; }
83 SdrObject* getBackgroundObject() const { return mpBackgroundObject; }
84 SdrObject* getLineObject() const { return mpLineObject; }
87 void XDashList::impCreate()
89 if(!mpData)
91 const Point aZero(0, 0);
92 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
94 VirtualDevice* pVirDev = new VirtualDevice;
95 OSL_ENSURE(0 != pVirDev, "XDashList: no VirtualDevice created!" );
96 pVirDev->SetMapMode(MAP_100TH_MM);
97 const Size aSize(pVirDev->PixelToLogic(Size(BITMAP_WIDTH * 2, BITMAP_HEIGHT)));
98 pVirDev->SetOutputSize(aSize);
99 pVirDev->SetDrawMode(rStyleSettings.GetHighContrastMode()
100 ? DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT
101 : DRAWMODE_DEFAULT);
103 SdrModel* pSdrModel = new SdrModel();
104 OSL_ENSURE(0 != pSdrModel, "XDashList: no SdrModel created!" );
105 pSdrModel->GetItemPool().FreezeIdRanges();
107 const Rectangle aBackgroundSize(aZero, aSize);
108 SdrObject* pBackgroundObject = new SdrRectObj(aBackgroundSize);
109 OSL_ENSURE(0 != pBackgroundObject, "XDashList: no BackgroundObject created!" );
110 pBackgroundObject->SetModel(pSdrModel);
111 pBackgroundObject->SetMergedItem(XFillStyleItem(XFILL_SOLID));
112 pBackgroundObject->SetMergedItem(XLineStyleItem(XLINE_NONE));
113 pBackgroundObject->SetMergedItem(XFillColorItem(String(), rStyleSettings.GetFieldColor()));
115 const basegfx::B2DPoint aStart(0, aSize.Height() / 2);
116 const basegfx::B2DPoint aEnd(aSize.Width(), aSize.Height() / 2);
117 basegfx::B2DPolygon aPolygon;
118 aPolygon.append(aStart);
119 aPolygon.append(aEnd);
120 SdrObject* pLineObject = new SdrPathObj(OBJ_LINE, basegfx::B2DPolyPolygon(aPolygon));
121 OSL_ENSURE(0 != pLineObject, "XDashList: no LineObject created!" );
122 pLineObject->SetModel(pSdrModel);
123 pLineObject->SetMergedItem(XLineStyleItem(XLINE_DASH));
124 pLineObject->SetMergedItem(XLineColorItem(String(), rStyleSettings.GetFieldTextColor()));
125 pLineObject->SetMergedItem(XLineWidthItem(30));
127 mpData = new impXDashList(pVirDev, pSdrModel, pBackgroundObject, pLineObject);
128 OSL_ENSURE(0 != mpData, "XDashList: data creation went wrong!" );
132 void XDashList::impDestroy()
134 delete mpData;
135 mpData = 0;
138 XDashList::XDashList( const String& rPath,
139 XOutdevItemPool* pInPool) :
140 XPropertyList( XDASH_LIST, rPath, pInPool ),
141 mpData(0)
143 pBmpList = new BitmapList_impl();
146 XDashList::~XDashList()
148 impDestroy();
151 XDashEntry* XDashList::Replace(XDashEntry* pEntry, long nIndex )
153 return (XDashEntry*) XPropertyList::Replace(pEntry, nIndex);
156 XDashEntry* XDashList::Remove(long nIndex)
158 return (XDashEntry*) XPropertyList::Remove(nIndex);
161 XDashEntry* XDashList::GetDash(long nIndex) const
163 return (XDashEntry*) XPropertyList::Get(nIndex, 0);
166 uno::Reference< container::XNameContainer > XDashList::createInstance()
168 return uno::Reference< container::XNameContainer >(
169 SvxUnoXDashTable_createInstance( this ), uno::UNO_QUERY );
172 sal_Bool XDashList::Create()
174 XubString aStr( SVX_RES( RID_SVXSTR_LINESTYLE ) );
175 xub_StrLen nLen;
177 aStr.AppendAscii(" 1");
178 nLen = aStr.Len() - 1;
179 Insert(new XDashEntry(XDash(XDASH_RECT,1, 50,1, 50, 50),aStr));
180 aStr.SetChar(nLen, sal_Unicode('2'));
181 Insert(new XDashEntry(XDash(XDASH_RECT,1,500,1,500,500),aStr));
182 aStr.SetChar(nLen, sal_Unicode('3'));
183 Insert(new XDashEntry(XDash(XDASH_RECT,2, 50,3,250,120),aStr));
185 return sal_True;
188 sal_Bool XDashList::CreateBitmapsForUI()
190 impCreate();
192 for( long i = 0; i < Count(); i++)
194 Bitmap* pBmp = CreateBitmapForUI( i, sal_False );
195 DBG_ASSERT( pBmp, "XDashList: Bitmap(UI) konnte nicht erzeugt werden!" );
197 if( pBmp )
199 if ( (size_t)i < pBmpList->size() ) {
200 pBmpList->insert( pBmpList->begin() + i, pBmp );
201 } else {
202 pBmpList->push_back( pBmp );
207 impDestroy();
209 return sal_True;
212 Bitmap* XDashList::CreateBitmapForUI( long nIndex, sal_Bool bDelete )
214 impCreate();
215 VirtualDevice* pVD = mpData->getVirtualDevice();
216 SdrObject* pLine = mpData->getLineObject();
218 pLine->SetMergedItem(XLineStyleItem(XLINE_DASH));
219 pLine->SetMergedItem(XLineDashItem(String(), GetDash(nIndex)->GetDash()));
221 sdr::contact::SdrObjectVector aObjectVector;
222 aObjectVector.push_back(mpData->getBackgroundObject());
223 aObjectVector.push_back(pLine);
224 sdr::contact::ObjectContactOfObjListPainter aPainter(*pVD, aObjectVector, 0);
225 sdr::contact::DisplayInfo aDisplayInfo;
227 aPainter.ProcessDisplay(aDisplayInfo);
229 const Point aZero(0, 0);
230 Bitmap* pBitmap = new Bitmap(pVD->GetBitmap(aZero, pVD->GetOutputSize()));
232 if(bDelete)
233 impDestroy();
235 return pBitmap;
238 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */