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