xref: /aoo41x/main/svx/source/xoutdev/xtabhtch.cxx (revision 3e407bd8)
1f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5f6e50924SAndrew Rist  * distributed with this work for additional information
6f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10f6e50924SAndrew Rist  *
11f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12f6e50924SAndrew Rist  *
13f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17f6e50924SAndrew Rist  * specific language governing permissions and limitations
18f6e50924SAndrew Rist  * under the License.
19f6e50924SAndrew Rist  *
20f6e50924SAndrew Rist  *************************************************************/
21f6e50924SAndrew Rist 
22cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
23cdf0e10cSrcweir #include "precompiled_svx.hxx"
24cdf0e10cSrcweir 
25cdf0e10cSrcweir // include ---------------------------------------------------------------
26cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
27cdf0e10cSrcweir #include "svx/XPropertyTable.hxx"
28cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx>
29cdf0e10cSrcweir #include <vcl/svapp.hxx>
30cdf0e10cSrcweir #include "xmlxtexp.hxx"
31cdf0e10cSrcweir #include "xmlxtimp.hxx"
32cdf0e10cSrcweir #include <tools/urlobj.hxx>
33cdf0e10cSrcweir #include <vcl/virdev.hxx>
34cdf0e10cSrcweir #include <svx/dialogs.hrc>
35cdf0e10cSrcweir #include <svx/dialmgr.hxx>
36cdf0e10cSrcweir #include <svx/xtable.hxx>
3735726d9dSArmin Le Grand #include <drawinglayer/attribute/fillhatchattribute.hxx>
3835726d9dSArmin Le Grand #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
3935726d9dSArmin Le Grand #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
4035726d9dSArmin Le Grand #include <drawinglayer/processor2d/processor2dtools.hxx>
4135726d9dSArmin Le Grand #include <basegfx/polygon/b2dpolygontools.hxx>
42cdf0e10cSrcweir 
43cdf0e10cSrcweir using namespace ::com::sun::star;
44cdf0e10cSrcweir using namespace ::rtl;
45cdf0e10cSrcweir 
46cdf0e10cSrcweir sal_Unicode const pszExtHatch[]	 = {'s','o','h'};
47c7be74b1SArmin Le Grand //char const aChckHatch[]  = { 0x04, 0x00, 'S','O','H','L'};	// < 5.2
48c7be74b1SArmin Le Grand //char const aChckHatch0[] = { 0x04, 0x00, 'S','O','H','0'};	// = 5.2
49c7be74b1SArmin Le Grand //char const aChckXML[]    = { '<', '?', 'x', 'm', 'l' };		// = 6.0
50cdf0e10cSrcweir 
51cdf0e10cSrcweir // -----------------
52cdf0e10cSrcweir // class XHatchList
53cdf0e10cSrcweir // -----------------
54cdf0e10cSrcweir 
55c7be74b1SArmin Le Grand XHatchList::XHatchList(const String& rPath )
5635726d9dSArmin Le Grand :   XPropertyList(rPath)
57cdf0e10cSrcweir {
58cdf0e10cSrcweir }
59cdf0e10cSrcweir 
60cdf0e10cSrcweir XHatchList::~XHatchList()
61cdf0e10cSrcweir {
62cdf0e10cSrcweir }
63cdf0e10cSrcweir 
64cdf0e10cSrcweir XHatchEntry* XHatchList::Replace(XHatchEntry* pEntry, long nIndex )
65cdf0e10cSrcweir {
66cdf0e10cSrcweir 	return (XHatchEntry*) XPropertyList::Replace(pEntry, nIndex);
67cdf0e10cSrcweir }
68cdf0e10cSrcweir 
69cdf0e10cSrcweir XHatchEntry* XHatchList::Remove(long nIndex)
70cdf0e10cSrcweir {
71c7be74b1SArmin Le Grand 	return (XHatchEntry*) XPropertyList::Remove(nIndex);
72cdf0e10cSrcweir }
73cdf0e10cSrcweir 
74cdf0e10cSrcweir XHatchEntry* XHatchList::GetHatch(long nIndex) const
75cdf0e10cSrcweir {
76c7be74b1SArmin Le Grand 	return (XHatchEntry*) XPropertyList::Get(nIndex);
77cdf0e10cSrcweir }
78cdf0e10cSrcweir 
79*3e407bd8SArmin Le Grand bool XHatchList::Load()
80cdf0e10cSrcweir {
8197e8a929SArmin Le Grand 	if( mbListDirty )
82cdf0e10cSrcweir 	{
8397e8a929SArmin Le Grand 		mbListDirty = false;
84cdf0e10cSrcweir 
8597e8a929SArmin Le Grand 		INetURLObject aURL( maPath );
86cdf0e10cSrcweir 
87cdf0e10cSrcweir 		if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
88cdf0e10cSrcweir 		{
8935726d9dSArmin Le Grand 			OSL_ENSURE( !maPath.Len(), "invalid URL" );
90*3e407bd8SArmin Le Grand 			return false;
91cdf0e10cSrcweir 		}
92cdf0e10cSrcweir 
9397e8a929SArmin Le Grand 		aURL.Append( maName );
94cdf0e10cSrcweir 
95cdf0e10cSrcweir 		if( !aURL.getExtension().getLength() )
96cdf0e10cSrcweir 			aURL.setExtension( rtl::OUString( pszExtHatch, 3 ) );
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 		uno::Reference< container::XNameContainer > xTable( SvxUnoXHatchTable_createInstance( this ), uno::UNO_QUERY );
99cdf0e10cSrcweir 		return SvxXMLXTableImport::load( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable );
100cdf0e10cSrcweir 	}
101*3e407bd8SArmin Le Grand 
102*3e407bd8SArmin Le Grand     return false;
103cdf0e10cSrcweir }
104cdf0e10cSrcweir 
105*3e407bd8SArmin Le Grand bool XHatchList::Save()
106cdf0e10cSrcweir {
10797e8a929SArmin Le Grand 	INetURLObject aURL( maPath );
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 	if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
110cdf0e10cSrcweir 	{
11135726d9dSArmin Le Grand 		OSL_ENSURE( !maPath.Len(), "invalid URL" );
112*3e407bd8SArmin Le Grand 		return false;
113cdf0e10cSrcweir 	}
114cdf0e10cSrcweir 
11597e8a929SArmin Le Grand 	aURL.Append( maName );
116cdf0e10cSrcweir 
117cdf0e10cSrcweir 	if( !aURL.getExtension().getLength() )
118cdf0e10cSrcweir 		aURL.setExtension( rtl::OUString( pszExtHatch, 3 ) );
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 	uno::Reference< container::XNameContainer > xTable( SvxUnoXHatchTable_createInstance( this ), uno::UNO_QUERY );
121cdf0e10cSrcweir 	return SvxXMLXTableExportComponent::save( aURL.GetMainURL( INetURLObject::NO_DECODE ), xTable );
122cdf0e10cSrcweir }
123cdf0e10cSrcweir 
124*3e407bd8SArmin Le Grand bool XHatchList::Create()
125cdf0e10cSrcweir {
126cdf0e10cSrcweir 	XubString aStr( SVX_RES( RID_SVXSTR_HATCH ) );
127cdf0e10cSrcweir 	xub_StrLen nLen;
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 	aStr.AppendAscii(" 1");
130cdf0e10cSrcweir 	nLen = aStr.Len() - 1;
131cdf0e10cSrcweir 	Insert(new XHatchEntry(XHatch(RGB_Color(COL_BLACK),XHATCH_SINGLE,100,  0),aStr));
132cdf0e10cSrcweir 	aStr.SetChar(nLen, sal_Unicode('2'));
133cdf0e10cSrcweir 	Insert(new XHatchEntry(XHatch(RGB_Color(COL_RED  ),XHATCH_DOUBLE, 80,450),aStr));
134cdf0e10cSrcweir 	aStr.SetChar(nLen, sal_Unicode('3'));
135cdf0e10cSrcweir 	Insert(new XHatchEntry(XHatch(RGB_Color(COL_BLUE ),XHATCH_TRIPLE,120,  0),aStr));
136cdf0e10cSrcweir 
137*3e407bd8SArmin Le Grand 	return true;
138cdf0e10cSrcweir }
139cdf0e10cSrcweir 
14097e8a929SArmin Le Grand Bitmap XHatchList::CreateBitmapForUI( long nIndex )
141cdf0e10cSrcweir {
142c7be74b1SArmin Le Grand     Bitmap aRetval;
14335726d9dSArmin Le Grand     OSL_ENSURE(nIndex < Count(), "OOps, access out of range (!)");
144cdf0e10cSrcweir 
14535726d9dSArmin Le Grand     if(nIndex < Count())
146c7be74b1SArmin Le Grand     {
147c7be74b1SArmin Le Grand         const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
14835726d9dSArmin Le Grand         const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize();
149c7be74b1SArmin Le Grand 
15035726d9dSArmin Le Grand         // prepare polygon geometry for rectangle
15135726d9dSArmin Le Grand         const basegfx::B2DPolygon aRectangle(
15235726d9dSArmin Le Grand             basegfx::tools::createPolygonFromRect(
15335726d9dSArmin Le Grand                 basegfx::B2DRange(0.0, 0.0, rSize.Width(), rSize.Height())));
154cdf0e10cSrcweir 
15535726d9dSArmin Le Grand         const XHatch& rHatch = GetHatch(nIndex)->GetHatch();
15635726d9dSArmin Le Grand         drawinglayer::attribute::HatchStyle aHatchStyle(drawinglayer::attribute::HATCHSTYLE_TRIPLE);
157cdf0e10cSrcweir 
15835726d9dSArmin Le Grand         switch(rHatch.GetHatchStyle())
159c7be74b1SArmin Le Grand         {
16035726d9dSArmin Le Grand             case XHATCH_SINGLE :
16135726d9dSArmin Le Grand             {
16235726d9dSArmin Le Grand                 aHatchStyle = drawinglayer::attribute::HATCHSTYLE_SINGLE;
16335726d9dSArmin Le Grand                 break;
16435726d9dSArmin Le Grand             }
16535726d9dSArmin Le Grand             case XHATCH_DOUBLE :
16635726d9dSArmin Le Grand             {
16735726d9dSArmin Le Grand                 aHatchStyle = drawinglayer::attribute::HATCHSTYLE_DOUBLE;
16835726d9dSArmin Le Grand                 break;
16935726d9dSArmin Le Grand             }
17035726d9dSArmin Le Grand             default :
17135726d9dSArmin Le Grand             {
17235726d9dSArmin Le Grand                 aHatchStyle = drawinglayer::attribute::HATCHSTYLE_TRIPLE; // XHATCH_TRIPLE
17335726d9dSArmin Le Grand                 break;
17435726d9dSArmin Le Grand             }
175c7be74b1SArmin Le Grand         }
176c7be74b1SArmin Le Grand 
17735726d9dSArmin Le Grand         const basegfx::B2DHomMatrix aScaleMatrix(OutputDevice::LogicToLogic(MAP_100TH_MM, MAP_PIXEL));
17835726d9dSArmin Le Grand         const basegfx::B2DVector aScaleVector(aScaleMatrix * basegfx::B2DVector(1.0, 0.0));
17935726d9dSArmin Le Grand         const double fScaleValue(aScaleVector.getLength());
18035726d9dSArmin Le Grand 
18135726d9dSArmin Le Grand         const drawinglayer::attribute::FillHatchAttribute aFillHatch(
18235726d9dSArmin Le Grand             aHatchStyle,
18335726d9dSArmin Le Grand             (double)rHatch.GetDistance() * fScaleValue,
18435726d9dSArmin Le Grand             (double)rHatch.GetAngle() * F_PI1800,
18535726d9dSArmin Le Grand             rHatch.GetColor().getBColor(),
18635726d9dSArmin Le Grand             3, // same default as VCL, a minimum of three discrete units (pixels) offset
18735726d9dSArmin Le Grand             false);
18835726d9dSArmin Le Grand 
18935726d9dSArmin Le Grand         const basegfx::BColor aBlack(0.0, 0.0, 0.0);
19035726d9dSArmin Le Grand         const drawinglayer::primitive2d::Primitive2DReference aHatchPrimitive(
19135726d9dSArmin Le Grand             new drawinglayer::primitive2d::PolyPolygonHatchPrimitive2D(
19235726d9dSArmin Le Grand                 basegfx::B2DPolyPolygon(aRectangle),
19335726d9dSArmin Le Grand                 aBlack,
19435726d9dSArmin Le Grand                 aFillHatch));
19535726d9dSArmin Le Grand 
19635726d9dSArmin Le Grand         const drawinglayer::primitive2d::Primitive2DReference aBlackRectanglePrimitive(
19735726d9dSArmin Le Grand             new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(
19835726d9dSArmin Le Grand                 aRectangle,
19935726d9dSArmin Le Grand                 aBlack));
20035726d9dSArmin Le Grand 
20135726d9dSArmin Le Grand         // prepare VirtualDevice
20235726d9dSArmin Le Grand         VirtualDevice aVirtualDevice;
20335726d9dSArmin Le Grand         const drawinglayer::geometry::ViewInformation2D aNewViewInformation2D;
20435726d9dSArmin Le Grand 
20535726d9dSArmin Le Grand         aVirtualDevice.SetOutputSizePixel(rSize);
20635726d9dSArmin Le Grand         aVirtualDevice.SetDrawMode(rStyleSettings.GetHighContrastMode()
20735726d9dSArmin Le Grand             ? DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT
20835726d9dSArmin Le Grand             : DRAWMODE_DEFAULT);
20935726d9dSArmin Le Grand 
21035726d9dSArmin Le Grand         if(rStyleSettings.GetUIPreviewUsesCheckeredBackground())
211c7be74b1SArmin Le Grand         {
21235726d9dSArmin Le Grand             const Point aNull(0, 0);
21335726d9dSArmin Le Grand             static const sal_uInt32 nLen(8);
21435726d9dSArmin Le Grand             static const Color aW(COL_WHITE);
21535726d9dSArmin Le Grand             static const Color aG(0xef, 0xef, 0xef);
216c7be74b1SArmin Le Grand 
21735726d9dSArmin Le Grand             aVirtualDevice.DrawCheckered(aNull, rSize, nLen, aW, aG);
21835726d9dSArmin Le Grand         }
21935726d9dSArmin Le Grand         else
22035726d9dSArmin Le Grand         {
22135726d9dSArmin Le Grand             aVirtualDevice.SetBackground(rStyleSettings.GetFieldColor());
22235726d9dSArmin Le Grand             aVirtualDevice.Erase();
22335726d9dSArmin Le Grand         }
224c7be74b1SArmin Le Grand 
22535726d9dSArmin Le Grand         // create processor and draw primitives
22635726d9dSArmin Le Grand         drawinglayer::processor2d::BaseProcessor2D* pProcessor2D = drawinglayer::processor2d::createPixelProcessor2DFromOutputDevice(
22735726d9dSArmin Le Grand             aVirtualDevice,
22835726d9dSArmin Le Grand             aNewViewInformation2D);
229c7be74b1SArmin Le Grand 
23035726d9dSArmin Le Grand         if(pProcessor2D)
23135726d9dSArmin Le Grand         {
23235726d9dSArmin Le Grand             drawinglayer::primitive2d::Primitive2DSequence aSequence(2);
233c7be74b1SArmin Le Grand 
23435726d9dSArmin Le Grand             aSequence[0] = aHatchPrimitive;
23535726d9dSArmin Le Grand             aSequence[1] = aBlackRectanglePrimitive;
236c7be74b1SArmin Le Grand 
23735726d9dSArmin Le Grand             pProcessor2D->process(aSequence);
23835726d9dSArmin Le Grand             delete pProcessor2D;
23935726d9dSArmin Le Grand         }
240c7be74b1SArmin Le Grand 
24135726d9dSArmin Le Grand         // get result bitmap and scale
24235726d9dSArmin Le Grand         aRetval = aVirtualDevice.GetBitmap(Point(0, 0), aVirtualDevice.GetOutputSizePixel());
243c7be74b1SArmin Le Grand     }
244cdf0e10cSrcweir 
245c7be74b1SArmin Le Grand     return aRetval;
246cdf0e10cSrcweir }
247cdf0e10cSrcweir 
248cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
249cdf0e10cSrcweir // eof
250