fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / view / main / DummyXShape.cxx
blobeec97ff3395d477c0d6c95a98e148df3c1f05a3d
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/.
8 */
9 #include "DummyXShape.hxx"
11 #include <string>
12 #include <vector>
13 #include <iostream>
14 #include <fstream>
15 #include <algorithm>
16 #include <stdlib.h>
17 #include <string.h>
19 #include "CommonConverters.hxx"
21 #include <rtl/ustring.hxx>
23 #include <vcl/window.hxx>
24 #include <vcl/virdev.hxx>
25 #include <vcl/svapp.hxx>
26 #include <tools/gen.hxx>
27 #include <cppuhelper/supportsservice.hxx>
28 #include <cppuhelper/implbase1.hxx>
29 #include <editeng/unoprnms.hxx>
30 #include <toolkit/helper/vclunohelper.hxx>
32 #include <basegfx/point/b2dpoint.hxx>
33 #include <basegfx/matrix/b3dhommatrix.hxx>
35 #include <com/sun/star/beans/Property.hpp>
37 #include <com/sun/star/awt/XBitmap.hpp>
39 #define ENABLE_DEBUG_PROPERTIES 0
41 using namespace com::sun::star;
43 using namespace std;
45 namespace chart {
47 namespace dummy {
49 #if 0
51 std::ostream& operator<<(std::ostream& rStrm, const awt::Point& rPoint)
53 rStrm << rPoint.X << "," << rPoint.Y;
54 return rStrm;
57 std::ostream& operator<<(std::ostream& rStrm, const awt::Size& rSize)
59 rStrm << rSize.Width << "," << rSize.Height;
60 return rStrm;
63 #endif
65 bool TextCache::hasEntry(const TextCacheKey& rKey)
67 return maCache.find(rKey) != maCache.end();
70 BitmapEx& TextCache::getBitmap(const TextCacheKey& rKey)
72 return maCache.find(rKey)->second;
75 void TextCache::insertBitmap(const TextCacheKey& rKey, const BitmapEx& rBitmap)
77 maCache.insert(std::pair<TextCacheKey, BitmapEx>(rKey, rBitmap));
80 class DummyPropertySetInfo : public cppu::WeakImplHelper1<
81 com::sun::star::beans::XPropertySetInfo >
83 public:
84 DummyPropertySetInfo(const std::map<OUString, uno::Any>& rProps ):
85 mrProperties(rProps) {}
87 virtual sal_Bool SAL_CALL hasPropertyByName( const OUString& rName )
88 throw(uno::RuntimeException, std::exception) SAL_OVERRIDE;
90 virtual beans::Property SAL_CALL getPropertyByName( const OUString& rName )
91 throw(uno::RuntimeException, beans::UnknownPropertyException, std::exception) SAL_OVERRIDE;
93 virtual uno::Sequence< beans::Property > SAL_CALL getProperties()
94 throw(uno::RuntimeException, std::exception) SAL_OVERRIDE;
96 private:
97 const std::map<OUString, uno::Any>& mrProperties;
100 sal_Bool SAL_CALL DummyPropertySetInfo::hasPropertyByName( const OUString& rName )
101 throw(uno::RuntimeException, std::exception)
103 return mrProperties.find(rName) != mrProperties.end();
106 beans::Property SAL_CALL DummyPropertySetInfo::getPropertyByName( const OUString& rName )
107 throw(uno::RuntimeException, beans::UnknownPropertyException, std::exception)
109 beans::Property aRet;
110 if(mrProperties.find(rName) == mrProperties.end())
111 throw beans::UnknownPropertyException();
113 std::map<OUString, uno::Any>::const_iterator itr = mrProperties.find(rName);
114 aRet.Name = rName;
115 aRet.Type = itr->second.getValueType();
117 return aRet;
120 uno::Sequence< beans::Property > SAL_CALL DummyPropertySetInfo::getProperties()
121 throw(uno::RuntimeException, std::exception)
123 uno::Sequence< beans::Property > aRet(mrProperties.size());
125 size_t i = 0;
126 for(std::map<OUString, uno::Any>::const_iterator itr = mrProperties.begin(),
127 itrEnd = mrProperties.end(); itr != itrEnd; ++itr, ++i)
129 beans::Property aProp;
131 aProp.Name = itr->first;
132 aProp.Type = itr->second.getValueType();
133 aRet[i] = aProp;
135 return aRet;
138 namespace {
140 struct PrintProperties
142 #if ENABLE_DEBUG_PROPERTIES
143 void operator()(const std::pair<OUString, uno::Any>& rProp)
145 SAL_INFO("chart2.opengl.properties", "Property: " << rProp.first);
147 #else
148 void operator()(const std::pair<OUString, uno::Any>&)
151 #endif
154 void debugProperties(std::map<OUString, uno::Any>& rProperties)
156 for_each(rProperties.begin(), rProperties.end(), PrintProperties());
161 DummyXShape::DummyXShape()
165 OUString SAL_CALL DummyXShape::getName()
166 throw(uno::RuntimeException, std::exception)
168 return maName;
171 void SAL_CALL DummyXShape::setName( const OUString& rName )
172 throw(uno::RuntimeException, std::exception)
174 maName = rName;
177 awt::Point SAL_CALL DummyXShape::getPosition()
178 throw(uno::RuntimeException, std::exception)
180 return maPosition;
183 void SAL_CALL DummyXShape::setPosition( const awt::Point& rPoint )
184 throw(uno::RuntimeException, std::exception)
186 maPosition = rPoint;
189 awt::Size SAL_CALL DummyXShape::getSize()
190 throw(uno::RuntimeException, std::exception)
192 return maSize;
195 void SAL_CALL DummyXShape::setSize( const awt::Size& rSize )
196 throw(beans::PropertyVetoException, uno::RuntimeException, std::exception)
198 maSize = rSize;
201 OUString SAL_CALL DummyXShape::getShapeType()
202 throw(uno::RuntimeException, std::exception)
204 return OUString("dummy shape");
207 uno::Reference< beans::XPropertySetInfo > SAL_CALL DummyXShape::getPropertySetInfo()
208 throw(uno::RuntimeException, std::exception)
210 return new DummyPropertySetInfo(maProperties);
213 void SAL_CALL DummyXShape::setPropertyValue( const OUString& rName, const uno::Any& rValue)
214 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
215 lang::IllegalArgumentException, lang::WrappedTargetException,
216 uno::RuntimeException, std::exception)
218 SAL_INFO("chart2", "DummyXShape::setProperty: " << rName << " Any");
219 maProperties[rName] = rValue;
220 if(rName == "Transformation")
222 SAL_INFO("chart2.opengl", "Transformation");
226 uno::Any SAL_CALL DummyXShape::getPropertyValue( const OUString& rName )
227 throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
229 SAL_INFO("chart2.opengl", "DummyXShape::getPropertyValue: " << rName);
230 std::map<OUString, uno::Any>::iterator itr = maProperties.find(rName);
231 if(itr != maProperties.end())
232 return itr->second;
234 return uno::Any();
237 void SAL_CALL DummyXShape::addPropertyChangeListener( const OUString&, const uno::Reference< beans::XPropertyChangeListener >& )
238 throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
242 void SAL_CALL DummyXShape::removePropertyChangeListener( const OUString&, const uno::Reference< beans::XPropertyChangeListener >& )
243 throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
247 void SAL_CALL DummyXShape::addVetoableChangeListener( const OUString&, const uno::Reference< beans::XVetoableChangeListener >& )
248 throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
252 void SAL_CALL DummyXShape::removeVetoableChangeListener( const OUString&, const uno::Reference< beans::XVetoableChangeListener >& )
253 throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException, std::exception)
257 void SAL_CALL DummyXShape::setPropertyValues( const uno::Sequence< OUString >& rNames,
258 const uno::Sequence< uno::Any >& rValues)
259 throw (beans::PropertyVetoException, lang::IllegalArgumentException,
260 lang::WrappedTargetException, uno::RuntimeException, std::exception)
262 size_t n = std::min<size_t>(rNames.getLength(), rValues.getLength());
263 for(size_t i = 0; i < n; ++i)
265 maProperties[rNames[i]] = rValues[i];
269 uno::Sequence< uno::Any > SAL_CALL DummyXShape::getPropertyValues(
270 const uno::Sequence< OUString >& rNames)
271 throw (uno::RuntimeException, std::exception)
273 uno::Sequence< uno::Any > aValues(rNames.getLength());
274 for(sal_Int32 i = 0; i < rNames.getLength(); ++i)
276 OUString aName = rNames[i];
278 std::map<OUString, uno::Any>::iterator itr = maProperties.find(aName);
279 if(itr != maProperties.end())
280 aValues[i] = itr->second;
282 return aValues;
285 void SAL_CALL DummyXShape::addPropertiesChangeListener( const uno::Sequence< OUString >& , const uno::Reference< beans::XPropertiesChangeListener >& ) throw (uno::RuntimeException, std::exception)
289 void SAL_CALL DummyXShape::removePropertiesChangeListener( const uno::Reference< beans::XPropertiesChangeListener >& ) throw (uno::RuntimeException, std::exception)
293 void SAL_CALL DummyXShape::firePropertiesChangeEvent( const uno::Sequence< OUString >& ,
294 const uno::Reference< beans::XPropertiesChangeListener >& )
295 throw (uno::RuntimeException, std::exception)
299 OUString SAL_CALL DummyXShape::getImplementationName()
300 throw(uno::RuntimeException, std::exception)
302 return OUString("DummyXShape");
305 namespace {
307 uno::Sequence< OUString > listSupportedServices()
309 static uno::Sequence< OUString > aSupportedServices;
310 if(aSupportedServices.getLength() == 0)
312 aSupportedServices.realloc(3);
313 aSupportedServices[0] = "com.sun.star.drawing.Shape";
314 aSupportedServices[1] = "com.sun.star.container.Named";
315 aSupportedServices[2] = "com.sun.star.beans.PropertySet";
318 return aSupportedServices;
323 uno::Sequence< OUString > SAL_CALL DummyXShape::getSupportedServiceNames()
324 throw(uno::RuntimeException, std::exception)
326 return listSupportedServices();
329 sal_Bool SAL_CALL DummyXShape::supportsService( const OUString& rServiceName )
330 throw(uno::RuntimeException, std::exception)
332 return cppu::supportsService(this, rServiceName);
335 uno::Reference< uno::XInterface > SAL_CALL DummyXShape::getParent()
336 throw(uno::RuntimeException, std::exception)
338 return mxParent;
341 void SAL_CALL DummyXShape::setParent( const uno::Reference< uno::XInterface >& xParent )
342 throw(lang::NoSupportException, uno::RuntimeException, std::exception)
344 mxParent = xParent;
347 void DummyXShape::render()
349 SAL_WARN("chart2.opengl", "maybe a missing implementation in a subclass?");
352 namespace {
354 void setProperties( const uno::Reference< beans::XPropertySet > & xPropSet, const tPropertyNameMap& rPropertyNameMap,
355 std::map<OUString, uno::Any>& rTargetMap)
357 tNameSequence aNames;
358 tAnySequence aValues;
359 PropertyMapper::getMultiPropertyLists( aNames, aValues,
360 xPropSet, rPropertyNameMap );
362 sal_Int32 nSize = std::min(aNames.getLength(), aValues.getLength());
363 for(sal_Int32 i = 0; i < nSize; ++i)
365 rTargetMap[aNames[i]] = aValues[i];
369 void setProperties( const tNameSequence& rNames, const tAnySequence& rValues,
370 std::map<OUString, uno::Any>& rTargetMap)
372 sal_Int32 nSize = std::min(rNames.getLength(), rValues.getLength());
373 for(sal_Int32 i = 0; i < nSize; ++i)
375 rTargetMap[rNames[i]] = rValues[i];
381 DummyCube::DummyCube(const drawing::Position3D &rPos, const drawing::Direction3D& rSize,
382 const uno::Reference< beans::XPropertySet > & xPropSet,
383 const tPropertyNameMap& rPropertyNameMap )
385 setPosition(Position3DToAWTPoint(rPos));
386 setSize(Direction3DToAWTSize(rSize));
387 setProperties(xPropSet, rPropertyNameMap, maProperties);
390 DummyCylinder::DummyCylinder(const drawing::Position3D& rPos, const drawing::Direction3D& rSize )
392 setPosition(Position3DToAWTPoint(rPos));
393 setSize(Direction3DToAWTSize(rSize));
396 DummyPyramid::DummyPyramid(const drawing::Position3D& rPos, const drawing::Direction3D& rSize,
397 const uno::Reference< beans::XPropertySet > & xPropSet,
398 const tPropertyNameMap& rPropertyNameMap)
400 setPosition(Position3DToAWTPoint(rPos));
401 setSize(Direction3DToAWTSize(rSize));
402 setProperties(xPropSet, rPropertyNameMap, maProperties);
405 DummyCone::DummyCone(const drawing::Position3D& rPos, const drawing::Direction3D& rSize)
407 setPosition(Position3DToAWTPoint(rPos));
408 setSize(Direction3DToAWTSize(rSize));
411 DummyPieSegment2D::DummyPieSegment2D(double fUnitCircleStartAngleDegree, double fUnitCircleWidthAngleDegree,
412 double fUnitCircleInnerRadius, double fUnitCircleOuterRadius,
413 const drawing::Direction3D& rOffset, const drawing::HomogenMatrix& rUnitCircleToScene):
414 mfUnitCircleStartAngleDegree(fUnitCircleStartAngleDegree),
415 mfUnitCircleWidthAngleDegree(fUnitCircleWidthAngleDegree),
416 mfUnitCircleInnerRadius(fUnitCircleInnerRadius),
417 mfUnitCircleOuterRadius(fUnitCircleOuterRadius),
418 maOffset(rOffset),
419 maUnitCircleToScene(rUnitCircleToScene)
423 void DummyPieSegment2D::render()
425 SAL_INFO("chart2.opengl", "render DummyPieSegment2D");
426 DummyChart* pChart = getRootShape();
428 while(mfUnitCircleWidthAngleDegree>360)
429 mfUnitCircleWidthAngleDegree -= 360.0;
430 while(mfUnitCircleWidthAngleDegree<0)
431 mfUnitCircleWidthAngleDegree += 360.0;
433 pChart->m_GLRender.GeneratePieSegment2D(mfUnitCircleInnerRadius, mfUnitCircleOuterRadius,
434 mfUnitCircleStartAngleDegree, mfUnitCircleWidthAngleDegree);
436 sal_uInt8 nAlpha = 255;
437 std::map<OUString, uno::Any>::const_iterator itr = maProperties.find(UNO_NAME_FILL_TRANSPARENCE);
438 if(itr != maProperties.end())
440 nAlpha = 255 - itr->second.get<sal_Int32>();
443 itr = maProperties.find(UNO_NAME_FILLCOLOR);
444 if(itr != maProperties.end())
446 sal_Int32 nColor = itr->second.get<sal_Int32>();
447 pChart->m_GLRender.SetColor(nColor, nAlpha);
450 float nSize = std::max<float>(maUnitCircleToScene.Line1.Column1, maUnitCircleToScene.Line2.Column2);
451 pChart->m_GLRender.RenderPieSegment2DShape(nSize, maUnitCircleToScene.Line1.Column4 + maOffset.DirectionX,
452 maUnitCircleToScene.Line2.Column4 + maOffset.DirectionY);
456 DummyPieSegment::DummyPieSegment(
457 const drawing::Direction3D& rOffset, const drawing::HomogenMatrix& rUnitCircleToScene ):
458 maOffset(rOffset),
459 maUnitCircleToScene(rUnitCircleToScene)
463 DummyStripe::DummyStripe(const Stripe& rStripe, const uno::Reference< beans::XPropertySet > & xPropSet,
464 const tPropertyNameMap& rPropertyNameMap ):
465 maStripe(rStripe)
467 setProperties(xPropSet, rPropertyNameMap, maProperties);
470 DummyArea3D::DummyArea3D(const drawing::PolyPolygonShape3D& rShape):
471 maShapes(rShape)
475 DummyArea2D::DummyArea2D(const drawing::PointSequenceSequence& rShape):
476 maShapes(rShape)
480 void DummyArea2D::render()
482 SAL_INFO("chart2.opengl", "render DummyArea2D");
483 DummyChart* pChart = getRootShape();
484 sal_Int32 nPointssCount = maShapes.getLength();
485 for(sal_Int32 i = 0; i < nPointssCount; i++)
487 const com::sun::star::uno::Sequence<com::sun::star::awt::Point>& points = maShapes[i];
488 sal_Int32 nPointsCount = points.getLength();
489 for(sal_Int32 j = 0; j < nPointsCount; j++)
491 const com::sun::star::awt::Point& p = points[j];
492 pChart->m_GLRender.SetArea2DShapePoint((float)p.X, (float)p.Y, nPointsCount);
496 std::map<OUString, uno::Any>::const_iterator itr = maProperties.find(UNO_NAME_FILLCOLOR);
497 if(itr != maProperties.end())
499 sal_Int32 nColor = itr->second.get<sal_Int32>();
500 pChart->m_GLRender.SetColor(nColor, 255);
503 pChart->m_GLRender.RenderArea2DShape();
506 DummySymbol2D::DummySymbol2D(const drawing::Position3D& rPos, const drawing::Direction3D& rSize,
507 sal_Int32 nStandardSymbol, sal_Int32 nFillColor):
508 mrPosition(rPos),
509 mrSize(rSize),
510 mnStandardSymbol(nStandardSymbol),
511 mnFillColor(nFillColor)
513 setPosition(Position3DToAWTPoint(rPos));
514 setSize(Direction3DToAWTSize(rSize));
517 void DummySymbol2D::render()
519 DummyChart* pChart = getRootShape();
521 pChart->m_GLRender.SetColor(mnFillColor, 255);
523 pChart->m_GLRender.RenderSymbol2DShape(maPosition.X, maPosition.Y, maSize.Width, maSize.Height, mnStandardSymbol);
526 DummyCircle::DummyCircle(const awt::Point& rPos, const awt::Size& rSize)
528 setPosition(rPos);
529 setSize(rSize);
532 void DummyCircle::render()
534 SAL_INFO("chart2.opengl", "render DummyCircle");
535 debugProperties(maProperties);
536 DummyChart* pChart = getRootShape();
538 sal_uInt8 nAlpha = 255;
539 std::map<OUString, uno::Any>::const_iterator itr = maProperties.find("FillTransparence");
540 if(itr != maProperties.end())
542 sal_Int32 nTrans = itr->second.get<sal_Int32>()/100.0*255;
543 nAlpha = 255 - static_cast<sal_uInt8>(nTrans & 0xFF);
545 if(nAlpha == 0)
546 return;
549 itr = maProperties.find("FillColor");
550 if(itr != maProperties.end())
552 sal_Int32 nColor = itr->second.get<sal_Int32>();
553 pChart->m_GLRender.SetColor(nColor, nAlpha);
555 else
556 SAL_WARN("chart2.opengl", "missing color");
558 pChart->m_GLRender.Bubble2DShapePoint(maPosition.X, maPosition.Y,
559 maSize.Width, maSize.Height);
560 pChart->m_GLRender.RenderBubble2FBO(GL_TRUE);
563 namespace {
565 void setProperties( const VLineProperties& rLineProperties, std::map<OUString, uno::Any>& rTargetProps )
567 //Transparency
568 if(rLineProperties.Transparence.hasValue())
569 rTargetProps.insert(std::pair<OUString, uno::Any>(
570 UNO_NAME_LINETRANSPARENCE, rLineProperties.Transparence));
572 //LineStyle
573 if(rLineProperties.LineStyle.hasValue())
574 rTargetProps.insert(std::pair<OUString, uno::Any>(
575 UNO_NAME_LINESTYLE, rLineProperties.LineStyle));
577 //LineWidth
578 if(rLineProperties.Width.hasValue())
579 rTargetProps.insert(std::pair<OUString, uno::Any>(
580 UNO_NAME_LINEWIDTH, rLineProperties.Width));
582 //LineColor
583 if(rLineProperties.Color.hasValue())
584 rTargetProps.insert(std::pair<OUString, uno::Any>(
585 UNO_NAME_LINECOLOR, rLineProperties.Color));
587 //LineDashName
588 if(rLineProperties.DashName.hasValue())
589 rTargetProps.insert(std::pair<OUString, uno::Any>(
590 "LineDashName", rLineProperties.DashName));
595 DummyLine3D::DummyLine3D(const drawing::PolyPolygonShape3D& rPoints, const VLineProperties& rLineProperties):
596 maPoints(rPoints)
598 setProperties(rLineProperties, maProperties);
601 DummyLine2D::DummyLine2D(const drawing::PointSequenceSequence& rPoints, const VLineProperties* pLineProperties):
602 maPoints(rPoints)
604 if(pLineProperties)
605 setProperties(*pLineProperties, maProperties);
608 DummyLine2D::DummyLine2D(const awt::Size& rSize, const awt::Point& rPosition)
610 setPosition(rPosition);
611 setSize(rSize);
614 void DummyLine2D::render()
616 SAL_INFO("chart2.opengl", "rendering line 2D");
617 debugProperties(maProperties);
618 DummyChart* pChart = getRootShape();
620 //add style and transparency
621 std::map< OUString, uno::Any >::const_iterator itr = maProperties.find(UNO_NAME_LINESTYLE);
622 if (itr != maProperties.end())
624 uno::Any cow = itr->second;
625 drawing::LineStyle nStyle = cow.get<drawing::LineStyle>();
626 if (drawing::LineStyle_NONE == nStyle)
628 // nothing to render
629 return;
633 sal_uInt8 nAlpha = 255;
634 itr = maProperties.find("LineTransparence");
635 if(itr != maProperties.end())
637 uno::Any al = itr->second;
638 nAlpha = 255 - al.get<sal_Int32>();
641 itr = maProperties.find(UNO_NAME_LINECOLOR);
642 if(itr != maProperties.end())
644 //set line color
645 uno::Any co = itr->second;
646 sal_Int32 nColorValue = co.get<sal_Int32>();
647 SAL_INFO("chart2.opengl", "line colorvalue = " << nColorValue);
648 sal_uInt8 R = (nColorValue & 0x00FF0000) >> 16;
649 sal_uInt8 G = (nColorValue & 0x0000FF00) >> 8;
650 sal_uInt8 B = (nColorValue & 0x000000FF);
651 pChart->m_GLRender.SetLine2DColor(R, G, B, nAlpha);
653 SAL_INFO("chart2.opengl", "line colorvalue = " << nColorValue << ", R = " << (int)R << ", G = " << (int)G << ", B = " << (int)B);
655 else
656 SAL_WARN("chart2.opengl", "no line color set");
658 //set line width
659 itr = maProperties.find(UNO_NAME_LINEWIDTH);
660 if(itr != maProperties.end())
662 uno::Any cow = itr->second;
663 sal_Int32 nWidth = cow.get<sal_Int32>();
664 pChart->m_GLRender.SetLine2DWidth(nWidth);
666 SAL_INFO("chart2.opengl", "width = " << nWidth);
668 else
669 SAL_WARN("chart2.opengl", "no line width set");
671 sal_Int32 pointsscount = maPoints.getLength();
672 for(sal_Int32 i = 0; i < pointsscount; i++)
674 com::sun::star::uno::Sequence<com::sun::star::awt::Point>& points = maPoints[i];
675 sal_Int32 pointscount = points.getLength();
676 for(sal_Int32 j = 0; j < pointscount; j++)
678 com::sun::star::awt::Point& p = points[j];
679 pChart->m_GLRender.SetLine2DShapePoint((float)p.X, (float)p.Y, pointscount);
683 pChart->m_GLRender.RenderLine2FBO(GL_TRUE);
687 DummyRectangle::DummyRectangle()
691 DummyRectangle::DummyRectangle(const awt::Size& rSize)
693 setSize(rSize);
696 DummyRectangle::DummyRectangle(const awt::Size& rSize, const awt::Point& rPoint, const tNameSequence& rNames,
697 const tAnySequence& rValues)
699 setSize(rSize);
700 setPosition(rPoint);
701 setProperties(rNames, rValues, maProperties);
704 void DummyRectangle::render()
706 SAL_INFO("chart2.opengl", "render DummyRectangle");
707 debugProperties(maProperties);
708 DummyChart* pChart = getRootShape();
709 std::map< OUString, uno::Any >::const_iterator itr = maProperties.find("Invisible");
710 if(itr != maProperties.end())
712 return;
715 bool bFill = true;
716 drawing::FillStyle eStyle = drawing::FillStyle_NONE;
717 itr = maProperties.find("FillStyle");
718 if(itr != maProperties.end())
720 eStyle = itr->second.get<drawing::FillStyle>();
721 if(eStyle == drawing::FillStyle_NONE)
723 bFill = false;
727 itr = maProperties.find("FillColor");
728 if(itr != maProperties.end())
730 uno::Any co = itr->second;
731 sal_Int32 nColorValue = co.get<sal_Int32>();
732 //here FillStyle works for background color and gradients
733 pChart->m_GLRender.SetBackGroundColor(nColorValue, nColorValue, eStyle);
736 bool bBorder = true;
737 itr = maProperties.find(UNO_NAME_LINESTYLE);
738 if (itr != maProperties.end())
740 uno::Any cow = itr->second;
741 drawing::LineStyle nStyle = cow.get<drawing::LineStyle>();
742 if (drawing::LineStyle_NONE == nStyle)
744 bBorder = false;
748 //TODO: moggi: correct handling of gradients
749 itr = maProperties.find("FillTransparenceGradientName");
750 if (itr != maProperties.end())
752 uno::Any co = itr->second;
753 rtl::OUString aGradientValue = co.get<rtl::OUString>();
754 if (aGradientValue.endsWith("1"))
756 pChart->m_GLRender.SetChartTransparencyGradient(1);
759 pChart->m_GLRender.RectangleShapePoint(maPosition.X, maPosition.Y, maSize.Width, maSize.Height);
760 pChart->m_GLRender.RenderRectangleShape(bBorder, bFill);
763 namespace {
765 struct FontAttribSetter
767 FontAttribSetter(vcl::Font& rFont):
768 mrFont(rFont) {}
770 void operator()(const std::pair<OUString, uno::Any>& rProp)
772 const OUString& rPropName = rProp.first;
773 if(rPropName == "CharFontName")
775 OUString aName = rProp.second.get<OUString>();
776 mrFont.SetName(aName);
778 else if(rPropName == "CharColor")
780 sal_Int32 nColor = rProp.second.get<sal_Int32>();
781 mrFont.SetFillColor(nColor);
783 else if(rPropName == "CharHeight")
785 float fHeight = rProp.second.get<float>();
786 mrFont.SetSize(Size(0,(fHeight*127+36)/72)); //taken from the MCW implementation
788 else if(rPropName == "CharUnderline")
790 FontUnderline eUnderline = static_cast<FontUnderline>(rProp.second.get<sal_Int16>());
791 mrFont.SetUnderline(eUnderline);
793 else if(rPropName == "CharWeight")
795 float fWeight = rProp.second.get<float>();
796 FontWeight eFontWeight = VCLUnoHelper::ConvertFontWeight(fWeight);
797 mrFont.SetWeight(eFontWeight);
799 else if(rPropName == "ChartWidth")
801 float fWidth = rProp.second.get<float>();
802 FontWidth eFontWidth = VCLUnoHelper::ConvertFontWidth(fWidth);
803 mrFont.SetWidth(eFontWidth);
806 private:
807 vcl::Font& mrFont;
812 DummyText::DummyText(const OUString& rText, const tNameSequence& rNames,
813 const tAnySequence& rValues, const uno::Any& rTrans, uno::Reference< drawing::XShapes > xTarget, double nRotation ):
814 maText(rText),
815 maTrans(rTrans),
816 mnRotation(nRotation)
818 setProperties(rNames, rValues, maProperties);
820 xTarget->add(this);
821 DummyChart* pChart = getRootShape();
822 TextCache& rCache = pChart->getTextCache();
823 TextCache::TextCacheKey aKey;
824 aKey.maText = maText;
825 aKey.maProperties = maProperties;
826 int bmpWidth;
827 int bmpHeight;
828 if(rCache.hasEntry(aKey))
830 maBitmap = rCache.getBitmap(aKey);
831 bmpWidth = maBitmap.GetSizePixel().Width();
832 bmpHeight = maBitmap.GetSizePixel().Height();
834 else
836 vcl::Font aFont;
837 std::for_each(maProperties.begin(), maProperties.end(), FontAttribSetter(aFont));
838 ScopedVclPtrInstance< VirtualDevice > pDevice(*Application::GetDefaultDevice(), 0, 0);
839 pDevice->Erase();
840 Rectangle aRect;
841 pDevice->SetFont(aFont);
842 pDevice->GetTextBoundRect(aRect, rText);
843 int screenWidth = (aRect.BottomRight().X());
844 int screenHeight = (aRect.BottomRight().Y());
845 pDevice->SetOutputSizePixel(Size(screenWidth * 3, screenHeight));
846 pDevice->SetBackground(Wallpaper(COL_TRANSPARENT));
847 pDevice->DrawText(Point(0, 0), rText);
848 bmpWidth = aRect.Right() - aRect.Left();
849 bmpHeight = aRect.Bottom() - aRect.Top();
850 maBitmap = BitmapEx(pDevice->GetBitmapEx(aRect.TopLeft(), Size(bmpWidth, bmpHeight)));
851 rCache.insertBitmap(aKey, maBitmap);
854 if(rTrans.hasValue())
856 drawing::HomogenMatrix3 aTrans = rTrans.get<drawing::HomogenMatrix3>();
857 setSize(awt::Size(20*bmpWidth, 20*bmpHeight));
858 setPosition(awt::Point(aTrans.Line1.Column3, aTrans.Line2.Column3));
859 aTrans.Line1.Column1 = 20 * bmpWidth;
860 aTrans.Line2.Column2 = 20 * bmpHeight;
861 setTransformatAsProperty(aTrans);
863 else
865 setSize(awt::Size(20*bmpWidth, 20*bmpHeight));
866 uno::Reference< drawing::XShape > xTargetShape(xTarget, uno::UNO_QUERY);
867 drawing::HomogenMatrix3 aTrans;
868 aTrans.Line1.Column1 = 20 * bmpWidth;
869 aTrans.Line2.Column2 = 20 * bmpHeight;
870 aTrans.Line3.Column3 = 1;
871 if(xTargetShape.is())
873 const awt::Point rPoint = xTargetShape->getPosition();
874 setPosition(rPoint);
875 aTrans.Line1.Column3 = rPoint.X;
876 aTrans.Line2.Column3 = rPoint.Y;
878 setTransformatAsProperty(aTrans);
882 void DummyText::render()
884 SAL_INFO("chart2.opengl", "render DummyText");
885 debugProperties(maProperties);
887 DummyChart* pChart = getRootShape();
889 drawing::HomogenMatrix3 aTransformation;
890 std::map<OUString, uno::Any>::const_iterator itr =
891 maProperties.find("Transformation");
892 if(itr != maProperties.end())
894 SAL_INFO("chart2.opengl", "found a transformation");
895 if(itr->second.hasValue())
897 aTransformation = itr->second.get<drawing::HomogenMatrix3>();
900 else if(maTrans.hasValue())
902 aTransformation = maTrans.get<drawing::HomogenMatrix3>();
904 pChart->m_GLRender.CreateTextTexture(maBitmap, maPosition, maSize,
905 mnRotation, aTransformation);
906 pChart->m_GLRender.RenderTextShape();
909 void SAL_CALL DummyText::setPropertyValue( const OUString& rName, const uno::Any& rValue)
910 throw(beans::UnknownPropertyException, beans::PropertyVetoException,
911 lang::IllegalArgumentException, lang::WrappedTargetException,
912 uno::RuntimeException, std::exception)
914 SAL_INFO("chart2.opengl", "property value set after image has been created");
915 DummyXShape::setPropertyValue(rName, rValue);
918 void SAL_CALL DummyText::setPosition(const awt::Point& rPosition )
919 throw(uno::RuntimeException, std::exception)
921 DummyXShape::setPosition(rPosition);
922 if(maTrans.hasValue())
923 return;
925 std::map<OUString, uno::Any>::const_iterator itr =
926 maProperties.find("Transformation");
927 if(itr != maProperties.end())
929 if(itr->second.hasValue())
931 drawing::HomogenMatrix3 aTrans = itr->second.get<drawing::HomogenMatrix3>();
932 aTrans.Line1.Column3 = rPosition.X;
933 aTrans.Line2.Column3 = rPosition.Y;
934 setTransformatAsProperty(aTrans);
939 void DummyText::setTransformatAsProperty(const drawing::HomogenMatrix3& rMatrix)
941 uno::Any aNewTrans;
942 aNewTrans <<= rMatrix;
943 setPropertyValue("Transformation", aNewTrans);
946 DummyGroup3D::DummyGroup3D(const OUString& rName)
948 setName(rName);
951 DummyGroup2D::DummyGroup2D(const OUString& rName)
953 setName(rName);
956 awt::Point SAL_CALL DummyGroup2D::getPosition()
957 throw(uno::RuntimeException, std::exception)
959 long nTop = std::numeric_limits<long>::max();
960 long nLeft = std::numeric_limits<long>::max();
961 for(std::vector<DummyXShape*>::iterator itr = maShapes.begin(),
962 itrEnd = maShapes.end(); itr != itrEnd; ++itr)
964 awt::Point aPoint = (*itr)->getPosition();
965 if(aPoint.X >= 0 && aPoint.Y >= 0)
967 nLeft = std::min<long>(nLeft, aPoint.X);
968 nTop = std::min<long>(nTop, aPoint.Y);
972 return awt::Point(nLeft, nTop);
975 awt::Size SAL_CALL DummyGroup2D::getSize()
976 throw(uno::RuntimeException, std::exception)
978 long nTop = std::numeric_limits<long>::max();
979 long nLeft = std::numeric_limits<long>::max();
980 long nBottom = 0;
981 long nRight = 0;
982 for(std::vector<DummyXShape*>::iterator itr = maShapes.begin(),
983 itrEnd = maShapes.end(); itr != itrEnd; ++itr)
985 awt::Point aPoint = (*itr)->getPosition();
986 nLeft = std::min<long>(nLeft, aPoint.X);
987 nTop = std::min<long>(nTop, aPoint.Y);
988 awt::Size aSize = (*itr)->getSize();
989 nRight = std::max<long>(nRight, aPoint.X + aSize.Width);
990 nBottom = std::max<long>(nBottom, aPoint.Y + aSize.Height);
993 return awt::Size(nRight - nLeft, nBottom - nTop);
996 void SAL_CALL DummyGroup2D::setPosition( const awt::Point& rPos )
997 throw(uno::RuntimeException, std::exception)
999 for(std::vector<DummyXShape*>::const_iterator itr = maShapes.begin(),
1000 itrEnd = maShapes.end(); itr != itrEnd; ++itr)
1002 const awt::Point& rOldPos = (*itr)->getPos();
1003 awt::Point aNewPos( rPos.X + rOldPos.X, rPos.Y + rOldPos.Y);
1004 (*itr)->setPosition(aNewPos);
1008 void SAL_CALL DummyGroup2D::setSize( const awt::Size& )
1009 throw( beans::PropertyVetoException, uno::RuntimeException, std::exception )
1011 SAL_WARN("chart2.opengl", "set size on group shape");
1014 DummyGraphic2D::DummyGraphic2D(const drawing::Position3D& rPos, const drawing::Direction3D& rSize,
1015 const uno::Reference< graphic::XGraphic >& rGraphic ):
1016 mxGraphic(rGraphic)
1018 setPosition(Position3DToAWTPoint(rPos));
1019 setSize(Direction3DToAWTSize(rSize));
1022 DummyChart* DummyXShape::getRootShape()
1024 assert(mxParent.is());
1025 DummyXShape& rParent = dynamic_cast<DummyXShape&>(*mxParent.get());
1026 return rParent.getRootShape();
1029 DummyChart* DummyChart::getRootShape()
1031 return this;
1034 #define QUERYINT( xint ) \
1035 if( rType == cppu::UnoType<xint>::get() ) \
1036 aAny <<= uno::Reference< xint >(this)
1038 #define QUERY_INTERFACE( xint ) \
1039 if( rType == cppu::UnoType<xint>::get() ) \
1040 return uno::makeAny(uno::Reference<xint>(this));
1042 uno::Any SAL_CALL DummyXShapes::queryInterface( const uno::Type& rType )
1043 throw(uno::RuntimeException, std::exception)
1045 QUERY_INTERFACE( drawing::XShapes );
1046 QUERY_INTERFACE( container::XIndexAccess );
1047 return DummyXShape::queryInterface(rType);
1050 uno::Any SAL_CALL DummyXShapes::queryAggregation( const uno::Type & rType )
1051 throw(uno::RuntimeException, std::exception)
1053 uno::Any aAny;
1055 //QUERYINT( drawing::XShapeGroup );
1056 QUERYINT( drawing::XShapes );
1057 else
1058 return DummyXShape::queryAggregation( rType );
1060 return aAny;
1063 void SAL_CALL DummyXShapes::acquire()
1064 throw()
1066 DummyXShape::acquire();
1069 void DummyXShapes::release()
1070 throw()
1072 DummyXShape::release();
1075 void SAL_CALL DummyXShapes::add( const uno::Reference< drawing::XShape>& xShape )
1076 throw(uno::RuntimeException, std::exception)
1078 DummyXShape& rChild = dynamic_cast<DummyXShape&>(*xShape.get());
1079 maUNOShapes.push_back(xShape);
1080 rChild.setParent(static_cast< ::cppu::OWeakObject* >( this ));
1081 maShapes.push_back(&rChild);
1084 void SAL_CALL DummyXShapes::remove( const uno::Reference< drawing::XShape>& xShape )
1085 throw(uno::RuntimeException, std::exception)
1087 std::vector< uno::Reference<drawing::XShape> >::iterator itr = std::find(maUNOShapes.begin(), maUNOShapes.end(), xShape);
1088 if(itr != maUNOShapes.end())
1090 DummyXShape* pChild = dynamic_cast<DummyXShape*>((*itr).get());
1091 std::vector< DummyXShape* >::iterator itrShape = std::find(maShapes.begin(), maShapes.end(), pChild);
1092 if(itrShape != maShapes.end())
1093 maShapes.erase(itrShape);
1095 maUNOShapes.erase(itr);
1099 uno::Type SAL_CALL DummyXShapes::getElementType()
1100 throw(uno::RuntimeException, std::exception)
1102 return cppu::UnoType<drawing::XShape>::get();
1105 sal_Bool SAL_CALL SAL_CALL DummyXShapes::hasElements()
1106 throw(uno::RuntimeException, std::exception)
1108 return !maUNOShapes.empty();
1111 sal_Int32 SAL_CALL DummyXShapes::getCount()
1112 throw(uno::RuntimeException, std::exception)
1114 return maUNOShapes.size();
1117 uno::Any SAL_CALL DummyXShapes::getByIndex(sal_Int32 nIndex)
1118 throw(lang::IndexOutOfBoundsException, lang::WrappedTargetException,
1119 uno::RuntimeException, std::exception)
1121 uno::Any aShape;
1122 aShape <<= maUNOShapes[nIndex];
1123 return aShape;
1126 void DummyXShapes::render()
1128 SAL_INFO("chart2.opengl", "render DummyShapes");
1129 for(std::vector<DummyXShape*>::iterator itr = maShapes.begin(),
1130 itrEnd = maShapes.end(); itr != itrEnd; ++itr)
1132 (*itr)->render();
1136 DummyChart::DummyChart():
1137 mbNotInit(true),
1138 m_GLRender()
1140 SAL_INFO("chart2.opengl", "DummyXShape::DummyChart()-----test: ");
1141 setName("com.sun.star.chart2.shapes");
1144 void SAL_CALL DummyChart::setPosition( const awt::Point& aPosition )
1145 throw( uno::RuntimeException, std::exception )
1147 DummyXShape::setPosition(aPosition);
1150 DummyChart::~DummyChart()
1154 void SAL_CALL DummyChart::setSize( const awt::Size& aSize )
1155 throw( beans::PropertyVetoException, uno::RuntimeException, std::exception )
1157 SAL_INFO("chart2.opengl", "DummyChart::setSize()---aSize.Width = " << aSize.Width << ", aSize.Height = " << aSize.Height);
1158 int width = aSize.Width;
1159 int height = aSize.Height;
1160 DummyXShape::setSize(awt::Size(0,0));
1161 m_GLRender.SetSize(width, height);
1162 SAL_INFO("chart2.opengl", "DummyChart::GLRender.Width = " << width << ", GLRender.Height = " << height);
1165 void DummyChart::render()
1167 if(mbNotInit)
1169 m_GLRender.InitOpenGL();
1170 mbNotInit = false;
1173 SAL_INFO("chart2.opengl", "render chart");
1174 m_GLRender.prepareToRender();
1175 #if 0
1176 m_GLRender.renderDebug();
1177 #else
1178 DummyXShapes::render();
1179 #endif
1182 void DummyChart::clear()
1184 maUNOShapes.clear();
1185 maShapes.clear();
1192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */