bump product version to 4.1.6.2
[LibreOffice.git] / svx / source / xoutdev / xtabdash.cxx
blobbf5deff7cc966b87424c1b1c9cf0d69bf0808e01
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "svx/XPropertyTable.hxx"
22 #include <vcl/svapp.hxx>
24 #include <vcl/virdev.hxx>
25 #include <vcl/window.hxx>
26 #include <svl/itemset.hxx>
27 #include <svx/dialogs.hrc>
28 #include <svx/dialmgr.hxx>
29 #include <svx/xtable.hxx>
30 #include <svx/xpool.hxx>
31 #include <svx/xlineit0.hxx>
32 #include <svx/xlnclit.hxx>
33 #include <svx/xlnwtit.hxx>
34 #include <svx/xlndsit.hxx>
35 #include <svx/xflclit.hxx>
37 #include <svx/svdorect.hxx>
38 #include <svx/svdopath.hxx>
39 #include <svx/svdmodel.hxx>
40 #include <svx/sdr/contact/objectcontactofobjlistpainter.hxx>
41 #include <svx/sdr/contact/displayinfo.hxx>
42 #include <basegfx/polygon/b2dpolygon.hxx>
44 using namespace com::sun::star;
46 class impXDashList
48 private:
49 VirtualDevice* mpVirtualDevice;
50 SdrModel* mpSdrModel;
51 SdrObject* mpBackgroundObject;
52 SdrObject* mpLineObject;
54 public:
55 impXDashList(VirtualDevice* pV, SdrModel* pM, SdrObject* pB, SdrObject* pL)
56 : mpVirtualDevice(pV),
57 mpSdrModel(pM),
58 mpBackgroundObject(pB),
59 mpLineObject(pL)
62 ~impXDashList()
64 delete mpVirtualDevice;
65 SdrObject::Free(mpBackgroundObject);
66 SdrObject::Free(mpLineObject);
67 delete mpSdrModel;
70 VirtualDevice* getVirtualDevice() const { return mpVirtualDevice; }
71 SdrObject* getBackgroundObject() const { return mpBackgroundObject; }
72 SdrObject* getLineObject() const { return mpLineObject; }
75 void XDashList::impCreate()
77 if(!mpData)
79 const Point aZero(0, 0);
80 const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
82 VirtualDevice* pVirDev = new VirtualDevice;
83 OSL_ENSURE(0 != pVirDev, "XDashList: no VirtualDevice created!" );
84 pVirDev->SetMapMode(MAP_100TH_MM);
85 const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize();
86 const Size aSize(pVirDev->PixelToLogic(Size(rSize.Width() * 2, rSize.Height())));
87 pVirDev->SetOutputSize(aSize);
88 pVirDev->SetDrawMode(rStyleSettings.GetHighContrastMode()
89 ? DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT
90 : DRAWMODE_DEFAULT);
91 pVirDev->SetBackground(rStyleSettings.GetFieldColor());
93 SdrModel* pSdrModel = new SdrModel();
94 OSL_ENSURE(0 != pSdrModel, "XDashList: no SdrModel created!" );
95 pSdrModel->GetItemPool().FreezeIdRanges();
97 const Rectangle aBackgroundSize(aZero, aSize);
98 SdrObject* pBackgroundObject = new SdrRectObj(aBackgroundSize);
99 OSL_ENSURE(0 != pBackgroundObject, "XDashList: no BackgroundObject created!" );
100 pBackgroundObject->SetModel(pSdrModel);
101 pBackgroundObject->SetMergedItem(XFillStyleItem(XFILL_SOLID));
102 pBackgroundObject->SetMergedItem(XLineStyleItem(XLINE_NONE));
103 pBackgroundObject->SetMergedItem(XFillColorItem(String(), rStyleSettings.GetFieldColor()));
105 const basegfx::B2DPoint aStart(0, aSize.Height() / 2);
106 const basegfx::B2DPoint aEnd(aSize.Width(), aSize.Height() / 2);
107 basegfx::B2DPolygon aPolygon;
108 aPolygon.append(aStart);
109 aPolygon.append(aEnd);
110 SdrObject* pLineObject = new SdrPathObj(OBJ_LINE, basegfx::B2DPolyPolygon(aPolygon));
111 OSL_ENSURE(0 != pLineObject, "XDashList: no LineObject created!" );
112 pLineObject->SetModel(pSdrModel);
113 pLineObject->SetMergedItem(XLineStyleItem(XLINE_DASH));
114 pLineObject->SetMergedItem(XLineColorItem(String(), rStyleSettings.GetFieldTextColor()));
115 const Size aLineWidth(pVirDev->PixelToLogic(Size(rStyleSettings.GetListBoxPreviewDefaultLineWidth(), 0)));
116 pLineObject->SetMergedItem(XLineWidthItem(aLineWidth.getWidth()));
117 mpData = new impXDashList(pVirDev, pSdrModel, pBackgroundObject, pLineObject);
118 OSL_ENSURE(0 != mpData, "XDashList: data creation went wrong!" );
122 void XDashList::impDestroy()
124 delete mpData;
125 mpData = 0;
128 XDashList::XDashList(const String& rPath, XOutdevItemPool* pInPool )
129 : XPropertyList( XDASH_LIST, rPath, pInPool ),
130 mpData(0),
131 maBitmapSolidLine(),
132 maStringSolidLine(),
133 maStringNoLine()
137 XDashList::~XDashList()
139 impDestroy();
142 XDashEntry* XDashList::Replace(XDashEntry* pEntry, long nIndex )
144 return (XDashEntry*) XPropertyList::Replace(pEntry, nIndex);
147 XDashEntry* XDashList::Remove(long nIndex)
149 return (XDashEntry*) XPropertyList::Remove(nIndex);
152 XDashEntry* XDashList::GetDash(long nIndex) const
154 return (XDashEntry*) XPropertyList::Get(nIndex, 0);
157 uno::Reference< container::XNameContainer > XDashList::createInstance()
159 return uno::Reference< container::XNameContainer >(
160 SvxUnoXDashTable_createInstance( this ), uno::UNO_QUERY );
163 sal_Bool XDashList::Create()
165 XubString aStr( SVX_RES( RID_SVXSTR_LINESTYLE ) );
166 xub_StrLen nLen;
168 aStr.AppendAscii(" 1");
169 nLen = aStr.Len() - 1;
170 Insert(new XDashEntry(XDash(XDASH_RECT,1, 50,1, 50, 50),aStr));
171 aStr.SetChar(nLen, sal_Unicode('2'));
172 Insert(new XDashEntry(XDash(XDASH_RECT,1,500,1,500,500),aStr));
173 aStr.SetChar(nLen, sal_Unicode('3'));
174 Insert(new XDashEntry(XDash(XDASH_RECT,2, 50,3,250,120),aStr));
176 return sal_True;
179 Bitmap XDashList::ImpCreateBitmapForXDash(const XDash* pDash)
181 impCreate();
182 VirtualDevice* pVD = mpData->getVirtualDevice();
183 SdrObject* pLine = mpData->getLineObject();
185 if(pDash)
187 pLine->SetMergedItem(XLineStyleItem(XLINE_DASH));
188 pLine->SetMergedItem(XLineDashItem(String(), *pDash));
190 else
192 pLine->SetMergedItem(XLineStyleItem(XLINE_SOLID));
195 sdr::contact::SdrObjectVector aObjectVector;
196 aObjectVector.push_back(mpData->getBackgroundObject());
197 aObjectVector.push_back(pLine);
198 sdr::contact::ObjectContactOfObjListPainter aPainter(*pVD, aObjectVector, 0);
199 sdr::contact::DisplayInfo aDisplayInfo;
201 pVD->Erase();
202 aPainter.ProcessDisplay(aDisplayInfo);
204 const Point aZero(0, 0);
205 return pVD->GetBitmap(aZero, pVD->GetOutputSize());
208 Bitmap XDashList::CreateBitmapForUI( long nIndex )
210 const XDash& rDash = GetDash(nIndex)->GetDash();
212 return ImpCreateBitmapForXDash(&rDash);
215 Bitmap XDashList::GetBitmapForUISolidLine() const
217 if(maBitmapSolidLine.IsEmpty())
219 const_cast< XDashList* >(this)->maBitmapSolidLine = const_cast< XDashList* >(this)->ImpCreateBitmapForXDash(0);
222 return maBitmapSolidLine;
225 String XDashList::GetStringForUiSolidLine() const
227 if(!maStringSolidLine.Len())
229 const_cast< XDashList* >(this)->maStringSolidLine = String(ResId(RID_SVXSTR_SOLID, DIALOG_MGR()));
232 return maStringSolidLine;
235 String XDashList::GetStringForUiNoLine() const
237 if(!maStringNoLine.Len())
239 // formally was RID_SVXSTR_INVISIBLE, but tomake equal
240 // everywhere, use RID_SVXSTR_NONE
241 const_cast< XDashList* >(this)->maStringNoLine = String(ResId(RID_SVXSTR_NONE, DIALOG_MGR()));
244 return maStringNoLine;
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */