Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include "svx/XPropertyTable.hxx"
21 :
22 : #include <vcl/svapp.hxx>
23 : #include <vcl/settings.hxx>
24 :
25 : #include <vcl/virdev.hxx>
26 : #include <svx/dialogs.hrc>
27 : #include <svx/dialmgr.hxx>
28 : #include <svx/xtable.hxx>
29 :
30 : #include <drawinglayer/attribute/lineattribute.hxx>
31 : #include <drawinglayer/attribute/strokeattribute.hxx>
32 : #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
33 : #include <drawinglayer/processor2d/processor2dtools.hxx>
34 : #include <boost/scoped_ptr.hpp>
35 :
36 : using namespace com::sun::star;
37 :
38 6962 : XDashList::XDashList(const OUString& rPath, const OUString& rReferer)
39 : : XPropertyList(XDASH_LIST, rPath, rReferer)
40 : , maBitmapSolidLine()
41 : , maStringSolidLine()
42 6962 : , maStringNoLine()
43 : {
44 6962 : }
45 :
46 13842 : XDashList::~XDashList()
47 : {
48 13842 : }
49 :
50 0 : XDashEntry* XDashList::Replace(XDashEntry* pEntry, long nIndex )
51 : {
52 0 : return static_cast<XDashEntry*>( XPropertyList::Replace(pEntry, nIndex) );
53 : }
54 :
55 0 : XDashEntry* XDashList::Remove(long nIndex)
56 : {
57 0 : return static_cast<XDashEntry*>( XPropertyList::Remove(nIndex) );
58 : }
59 :
60 2100 : XDashEntry* XDashList::GetDash(long nIndex) const
61 : {
62 2100 : return static_cast<XDashEntry*>( XPropertyList::Get(nIndex) );
63 : }
64 :
65 231 : uno::Reference< container::XNameContainer > XDashList::createInstance()
66 : {
67 : return uno::Reference< container::XNameContainer >(
68 231 : SvxUnoXDashTable_createInstance( this ), uno::UNO_QUERY );
69 : }
70 :
71 90 : bool XDashList::Create()
72 : {
73 90 : const OUString aStr(SVX_RESSTR(RID_SVXSTR_LINESTYLE));
74 :
75 90 : Insert(new XDashEntry(XDash(XDASH_RECT,1, 50,1, 50, 50),aStr + " 1"));
76 90 : Insert(new XDashEntry(XDash(XDASH_RECT,1,500,1,500,500),aStr + " 2"));
77 90 : Insert(new XDashEntry(XDash(XDASH_RECT,2, 50,3,250,120),aStr + " 3"));
78 :
79 90 : return true;
80 : }
81 :
82 1155 : Bitmap XDashList::ImpCreateBitmapForXDash(const XDash* pDash)
83 : {
84 1155 : const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
85 1155 : const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize();
86 1155 : const sal_uInt32 nFactor(2);
87 1155 : const Size aSize((rSize.Width() * 5 * 2) / 2, rSize.Height() * nFactor);
88 :
89 : // prepare polygon geometry for line
90 1155 : basegfx::B2DPolygon aLine;
91 :
92 1155 : aLine.append(basegfx::B2DPoint(0.0, aSize.Height() / 2.0));
93 1155 : aLine.append(basegfx::B2DPoint(aSize.Width(), aSize.Height() / 2.0));
94 :
95 : // prepare LineAttribute
96 2310 : const basegfx::BColor aLineColor(rStyleSettings.GetFieldTextColor().getBColor());
97 1155 : const double fLineWidth(rStyleSettings.GetListBoxPreviewDefaultLineWidth() * (nFactor * 1.1));
98 : const drawinglayer::attribute::LineAttribute aLineAttribute(
99 : aLineColor,
100 2310 : fLineWidth);
101 :
102 : // prepare StrokeAttribute
103 2310 : ::std::vector< double > aDotDashArray;
104 1155 : double fFullDotDashLen(0.0);
105 :
106 1155 : if(pDash && (pDash->GetDots() || pDash->GetDashes()))
107 : {
108 1050 : const basegfx::B2DHomMatrix aScaleMatrix(OutputDevice::LogicToLogic(MAP_100TH_MM, MAP_PIXEL));
109 2100 : const basegfx::B2DVector aScaleVector(aScaleMatrix * basegfx::B2DVector(1.0, 0.0));
110 1050 : const double fScaleValue(aScaleVector.getLength() * (nFactor * (1.4 / 2.0)));
111 1050 : const double fLineWidthInUnits(fLineWidth / fScaleValue);
112 :
113 1050 : fFullDotDashLen = pDash->CreateDotDashArray(aDotDashArray, fLineWidthInUnits);
114 :
115 1050 : if(!aDotDashArray.empty())
116 : {
117 7770 : for(sal_uInt32 a(0); a < aDotDashArray.size(); a++)
118 : {
119 6720 : aDotDashArray[a] *= fScaleValue;
120 : }
121 :
122 1050 : fFullDotDashLen *= fScaleValue;
123 1050 : }
124 : }
125 :
126 : const drawinglayer::attribute::StrokeAttribute aStrokeAttribute(
127 : aDotDashArray,
128 2310 : fFullDotDashLen);
129 :
130 : // cerate LinePrimitive
131 : const drawinglayer::primitive2d::Primitive2DReference aLinePrimitive(
132 : new drawinglayer::primitive2d::PolygonStrokePrimitive2D(
133 : aLine,
134 : aLineAttribute,
135 2310 : aStrokeAttribute));
136 :
137 : // prepare VirtualDevice
138 2310 : VirtualDevice aVirtualDevice;
139 2310 : const drawinglayer::geometry::ViewInformation2D aNewViewInformation2D;
140 :
141 1155 : aVirtualDevice.SetOutputSizePixel(aSize);
142 1155 : aVirtualDevice.SetDrawMode(rStyleSettings.GetHighContrastMode()
143 : ? DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT
144 1155 : : DRAWMODE_DEFAULT);
145 :
146 1155 : if(rStyleSettings.GetPreviewUsesCheckeredBackground())
147 : {
148 0 : const Point aNull(0, 0);
149 : static const sal_uInt32 nLen(8 * nFactor);
150 0 : static const Color aW(COL_WHITE);
151 0 : static const Color aG(0xef, 0xef, 0xef);
152 :
153 0 : aVirtualDevice.DrawCheckered(aNull, aSize, nLen, aW, aG);
154 : }
155 : else
156 : {
157 1155 : aVirtualDevice.SetBackground(rStyleSettings.GetFieldColor());
158 1155 : aVirtualDevice.Erase();
159 : }
160 :
161 : // create processor and draw primitives
162 : boost::scoped_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor2D(drawinglayer::processor2d::createPixelProcessor2DFromOutputDevice(
163 : aVirtualDevice,
164 2310 : aNewViewInformation2D));
165 :
166 1155 : if(pProcessor2D)
167 : {
168 1155 : const drawinglayer::primitive2d::Primitive2DSequence aSequence(&aLinePrimitive, 1);
169 :
170 1155 : pProcessor2D->process(aSequence);
171 1155 : pProcessor2D.reset();
172 : }
173 :
174 : // get result bitmap and scale
175 1155 : Bitmap aRetval(aVirtualDevice.GetBitmap(Point(0, 0), aVirtualDevice.GetOutputSizePixel()));
176 :
177 : if(1 != nFactor)
178 : {
179 1155 : aRetval.Scale(Size((rSize.Width() * 5) / 2, rSize.Height()), BMP_SCALE_DEFAULT);
180 : }
181 :
182 2310 : return aRetval;
183 : }
184 :
185 1050 : Bitmap XDashList::CreateBitmapForUI( long nIndex )
186 : {
187 1050 : const XDash& rDash = GetDash(nIndex)->GetDash();
188 :
189 1050 : return ImpCreateBitmapForXDash(&rDash);
190 : }
191 :
192 105 : Bitmap XDashList::GetBitmapForUISolidLine() const
193 : {
194 105 : if(maBitmapSolidLine.IsEmpty())
195 : {
196 105 : const_cast< XDashList* >(this)->maBitmapSolidLine = const_cast< XDashList* >(this)->ImpCreateBitmapForXDash(0);
197 : }
198 :
199 105 : return maBitmapSolidLine;
200 : }
201 :
202 105 : OUString XDashList::GetStringForUiSolidLine() const
203 : {
204 105 : if(maStringSolidLine.isEmpty())
205 : {
206 105 : const_cast< XDashList* >(this)->maStringSolidLine = ResId(RID_SVXSTR_SOLID, DIALOG_MGR()).toString();
207 : }
208 :
209 105 : return maStringSolidLine;
210 : }
211 :
212 105 : OUString XDashList::GetStringForUiNoLine() const
213 : {
214 105 : if(maStringNoLine.isEmpty())
215 : {
216 : // formally was RID_SVXSTR_INVISIBLE, but tomake equal
217 : // everywhere, use RID_SVXSTR_NONE
218 105 : const_cast< XDashList* >(this)->maStringNoLine = ResId(RID_SVXSTR_NONE, DIALOG_MGR()).toString();
219 : }
220 :
221 105 : return maStringNoLine;
222 651 : }
223 :
224 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|