1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
21 #include <vcl/virdev.hxx>
23 #include <vcl/svapp.hxx>
24 #include <svl/itemset.hxx>
26 #include <svx/dialogs.hrc>
27 #include <svx/dialmgr.hxx>
29 #include <svx/xtable.hxx>
30 #include <svx/xpool.hxx>
31 #include <svx/xfillit0.hxx>
32 #include <svx/xflclit.hxx>
33 #include <svx/xlnstwit.hxx>
34 #include <svx/xlnedwit.hxx>
35 #include <svx/xlnclit.hxx>
36 #include <svx/xlineit0.hxx>
37 #include <svx/xlnstit.hxx>
38 #include <svx/xlnedit.hxx>
39 #include <basegfx/point/b2dpoint.hxx>
40 #include <basegfx/polygon/b2dpolygon.hxx>
41 #include <basegfx/polygon/b2dpolygontools.hxx>
43 #include <svx/svdorect.hxx>
44 #include <svx/svdopath.hxx>
45 #include <svx/svdmodel.hxx>
46 #include <svx/sdr/contact/objectcontactofobjlistpainter.hxx>
47 #include <svx/sdr/contact/displayinfo.hxx>
48 #include <svx/xlnwtit.hxx>
50 using namespace com::sun::star
;
55 VirtualDevice
* mpVirtualDevice
;
57 SdrObject
* mpBackgroundObject
;
58 SdrObject
* mpLineObject
;
61 impXLineEndList(VirtualDevice
* pV
, SdrModel
* pM
, SdrObject
* pB
, SdrObject
* pL
)
62 : mpVirtualDevice(pV
),
64 mpBackgroundObject(pB
),
70 delete mpVirtualDevice
;
71 SdrObject::Free(mpBackgroundObject
);
72 SdrObject::Free(mpLineObject
);
76 VirtualDevice
* getVirtualDevice() const { return mpVirtualDevice
; }
77 SdrObject
* getBackgroundObject() const { return mpBackgroundObject
; }
78 SdrObject
* getLineObject() const { return mpLineObject
; }
81 void XLineEndList::impCreate()
85 const Point
aZero(0, 0);
86 const StyleSettings
& rStyleSettings
= Application::GetSettings().GetStyleSettings();
88 VirtualDevice
* pVirDev
= new VirtualDevice
;
89 OSL_ENSURE(0 != pVirDev
, "XLineEndList: no VirtualDevice created!" );
90 pVirDev
->SetMapMode(MAP_100TH_MM
);
91 const Size
& rSize
= rStyleSettings
.GetListBoxPreviewDefaultPixelSize();
92 const Size
aSize(pVirDev
->PixelToLogic(Size(rSize
.Width() * 2, rSize
.Height())));
93 pVirDev
->SetOutputSize(aSize
);
94 pVirDev
->SetDrawMode(rStyleSettings
.GetHighContrastMode()
95 ? DRAWMODE_SETTINGSLINE
| DRAWMODE_SETTINGSFILL
| DRAWMODE_SETTINGSTEXT
| DRAWMODE_SETTINGSGRADIENT
97 pVirDev
->SetBackground(rStyleSettings
.GetFieldColor());
99 SdrModel
* pSdrModel
= new SdrModel();
100 OSL_ENSURE(0 != pSdrModel
, "XLineEndList: no SdrModel created!" );
101 pSdrModel
->GetItemPool().FreezeIdRanges();
103 const Rectangle
aBackgroundSize(aZero
, aSize
);
104 SdrObject
* pBackgroundObject
= new SdrRectObj(aBackgroundSize
);
105 OSL_ENSURE(0 != pBackgroundObject
, "XLineEndList: no BackgroundObject created!" );
106 pBackgroundObject
->SetModel(pSdrModel
);
107 pBackgroundObject
->SetMergedItem(XFillStyleItem(XFILL_SOLID
));
108 pBackgroundObject
->SetMergedItem(XLineStyleItem(XLINE_NONE
));
109 pBackgroundObject
->SetMergedItem(XFillColorItem(String(), rStyleSettings
.GetFieldColor()));
111 const basegfx::B2DPoint
aStart(0, aSize
.Height() / 2);
112 const basegfx::B2DPoint
aEnd(aSize
.Width() - 1, aSize
.Height() / 2);
113 basegfx::B2DPolygon aPolygon
;
114 aPolygon
.append(aStart
);
115 aPolygon
.append(aEnd
);
116 SdrObject
* pLineObject
= new SdrPathObj(OBJ_LINE
, basegfx::B2DPolyPolygon(aPolygon
));
117 OSL_ENSURE(0 != pLineObject
, "XLineEndList: no LineObject created!" );
118 pLineObject
->SetModel(pSdrModel
);
119 const Size
aLineWidth(pVirDev
->PixelToLogic(Size(rStyleSettings
.GetListBoxPreviewDefaultLineWidth(), 0)));
120 pLineObject
->SetMergedItem(XLineWidthItem(aLineWidth
.getWidth()));
121 const sal_uInt32
nArrowHeight((aSize
.Height() * 8) / 10);
122 pLineObject
->SetMergedItem(XLineStartWidthItem(nArrowHeight
));
123 pLineObject
->SetMergedItem(XLineEndWidthItem(nArrowHeight
));
124 pLineObject
->SetMergedItem(XLineColorItem(String(), rStyleSettings
.GetFieldTextColor()));
126 mpData
= new impXLineEndList(pVirDev
, pSdrModel
, pBackgroundObject
, pLineObject
);
127 OSL_ENSURE(0 != mpData
, "XLineEndList: data creation went wrong!" );
131 void XLineEndList::impDestroy()
137 XLineEndList::XLineEndList( const String
& rPath
, XOutdevItemPool
* _pXPool
)
138 : XPropertyList( XLINE_END_LIST
, rPath
, _pXPool
),
143 XLineEndList::~XLineEndList()
148 XLineEndEntry
* XLineEndList::Remove(long nIndex
)
150 return (XLineEndEntry
*) XPropertyList::Remove(nIndex
);
153 XLineEndEntry
* XLineEndList::GetLineEnd(long nIndex
) const
155 return (XLineEndEntry
*) XPropertyList::Get(nIndex
, 0);
158 uno::Reference
< container::XNameContainer
> XLineEndList::createInstance()
160 return uno::Reference
< container::XNameContainer
>(
161 SvxUnoXLineEndTable_createInstance( this ), uno::UNO_QUERY
);
164 sal_Bool
XLineEndList::Create()
166 basegfx::B2DPolygon aTriangle
;
167 aTriangle
.append(basegfx::B2DPoint(10.0, 0.0));
168 aTriangle
.append(basegfx::B2DPoint(0.0, 30.0));
169 aTriangle
.append(basegfx::B2DPoint(20.0, 30.0));
170 aTriangle
.setClosed(true);
171 Insert( new XLineEndEntry( basegfx::B2DPolyPolygon(aTriangle
), SVX_RESSTR( RID_SVXSTR_ARROW
) ) );
173 basegfx::B2DPolygon aSquare
;
174 aSquare
.append(basegfx::B2DPoint(0.0, 0.0));
175 aSquare
.append(basegfx::B2DPoint(10.0, 0.0));
176 aSquare
.append(basegfx::B2DPoint(10.0, 10.0));
177 aSquare
.append(basegfx::B2DPoint(0.0, 10.0));
178 aSquare
.setClosed(true);
179 Insert( new XLineEndEntry( basegfx::B2DPolyPolygon(aSquare
), SVX_RESSTR( RID_SVXSTR_SQUARE
) ) );
181 basegfx::B2DPolygon
aCircle(basegfx::tools::createPolygonFromCircle(basegfx::B2DPoint(0.0, 0.0), 100.0));
182 Insert( new XLineEndEntry( basegfx::B2DPolyPolygon(aCircle
), SVX_RESSTR( RID_SVXSTR_CIRCLE
) ) );
187 Bitmap
XLineEndList::CreateBitmapForUI( long nIndex
)
190 VirtualDevice
* pVD
= mpData
->getVirtualDevice();
191 SdrObject
* pLine
= mpData
->getLineObject();
193 pLine
->SetMergedItem(XLineStyleItem(XLINE_SOLID
));
194 pLine
->SetMergedItem(XLineStartItem(String(), GetLineEnd(nIndex
)->GetLineEnd()));
195 pLine
->SetMergedItem(XLineEndItem(String(), GetLineEnd(nIndex
)->GetLineEnd()));
197 sdr::contact::SdrObjectVector aObjectVector
;
198 aObjectVector
.push_back(mpData
->getBackgroundObject());
199 aObjectVector
.push_back(pLine
);
200 sdr::contact::ObjectContactOfObjListPainter
aPainter(*pVD
, aObjectVector
, 0);
201 sdr::contact::DisplayInfo aDisplayInfo
;
204 aPainter
.ProcessDisplay(aDisplayInfo
);
206 const Point
aZero(0, 0);
207 return pVD
->GetBitmap(aZero
, pVD
->GetOutputSize());
210 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */