diff options
author | Armin Le Grand <alg@apache.org> | 2013-06-18 10:07:44 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2013-06-18 13:06:12 +0100 |
commit | 7377557f277b19c4953198c17b591fd964ac7c40 (patch) | |
tree | 205ee08ac0651082379c1bced5ada7105e27029a /svx/source/xoutdev/xtabgrdt.cxx | |
parent | 08337321e655a3b4991c895de98d96858e60d863 (diff) |
Resolves: #i122120# Changed UI preview creators...
to no longer need SdrModel/SdrObject
(cherry picked from commit 0c353433ad94786a937fa9da01d6e7382e3da942)
corrected unwanted change
(cherry picked from commit 8a10735b8ee3926a592d6919f4dbb823771bed9f)
Conflicts:
vcl/inc/vcl/outdev.hxx
7c096015d974382e6874a874370ee72a61f02e6a
Change-Id: Ib2afe135566eba2e99cc8c4a653de3df0fa7f0cd
Diffstat (limited to 'svx/source/xoutdev/xtabgrdt.cxx')
-rw-r--r-- | svx/source/xoutdev/xtabgrdt.cxx | 228 |
1 files changed, 125 insertions, 103 deletions
diff --git a/svx/source/xoutdev/xtabgrdt.cxx b/svx/source/xoutdev/xtabgrdt.cxx index 5815678dacac..73ff6ad10647 100644 --- a/svx/source/xoutdev/xtabgrdt.cxx +++ b/svx/source/xoutdev/xtabgrdt.cxx @@ -20,108 +20,27 @@ #include "svx/XPropertyTable.hxx" #include <vcl/virdev.hxx> -#include <svl/itemset.hxx> #include <svx/dialogs.hrc> #include <svx/dialmgr.hxx> #include <svx/xtable.hxx> -#include <svx/xpool.hxx> -#include <svx/xfillit0.hxx> -#include <svx/xflgrit.hxx> - -#include <svx/svdorect.hxx> -#include <svx/svdmodel.hxx> -#include <svx/sdr/contact/objectcontactofobjlistpainter.hxx> -#include <svx/sdr/contact/displayinfo.hxx> -#include <vcl/svapp.hxx> -#include <svx/xlnclit.hxx> -#include <svx/xgrscit.hxx> - -using namespace com::sun::star; -class impXGradientList -{ -private: - VirtualDevice* mpVirtualDevice; - SdrModel* mpSdrModel; - SdrObject* mpBackgroundObject; - -public: - impXGradientList(VirtualDevice* pV, SdrModel* pM, SdrObject* pB) - : mpVirtualDevice(pV), - mpSdrModel(pM), - mpBackgroundObject(pB) - {} - - ~impXGradientList() - { - delete mpVirtualDevice; - SdrObject::Free(mpBackgroundObject); - delete mpSdrModel; - } - - VirtualDevice* getVirtualDevice() const { return mpVirtualDevice; } - SdrObject* getBackgroundObject() const { return mpBackgroundObject; } -}; - -void XGradientList::impCreate() -{ - if(!mpData) - { - const Point aZero(0, 0); - const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings(); +#include <vcl/svapp.hxx> - VirtualDevice* pVirDev = new VirtualDevice; - OSL_ENSURE(0 != pVirDev, "XGradientList: no VirtualDevice created!" ); - pVirDev->SetMapMode(MAP_100TH_MM); - const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize(); - const Size aSize(pVirDev->PixelToLogic(rSize)); - pVirDev->SetOutputSize(aSize); - pVirDev->SetDrawMode(rStyleSettings.GetHighContrastMode() - ? DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT - : DRAWMODE_DEFAULT); - pVirDev->SetBackground(rStyleSettings.GetFieldColor()); - - SdrModel* pSdrModel = new SdrModel(); - OSL_ENSURE(0 != pSdrModel, "XGradientList: no SdrModel created!" ); - pSdrModel->GetItemPool().FreezeIdRanges(); - - const Size aSinglePixel(pVirDev->PixelToLogic(Size(1, 1))); - const Rectangle aBackgroundSize(aZero, Size(aSize.getWidth() - aSinglePixel.getWidth(), aSize.getHeight() - aSinglePixel.getHeight())); - SdrObject* pBackgroundObject = new SdrRectObj(aBackgroundSize); - OSL_ENSURE(0 != pBackgroundObject, "XGradientList: no BackgroundObject created!" ); - pBackgroundObject->SetModel(pSdrModel); - pBackgroundObject->SetMergedItem(XFillStyleItem(XFILL_GRADIENT)); - pBackgroundObject->SetMergedItem(XLineStyleItem(XLINE_SOLID)); - pBackgroundObject->SetMergedItem(XLineColorItem(String(), Color(COL_BLACK))); - pBackgroundObject->SetMergedItem(XGradientStepCountItem(sal_uInt16((rSize.Width() + rSize.Height()) / 3))); - - mpData = new impXGradientList(pVirDev, pSdrModel, pBackgroundObject); - OSL_ENSURE(0 != mpData, "XGradientList: data creation went wrong!" ); - } -} +#include <drawinglayer/attribute/fillgradientattribute.hxx> +#include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx> +#include <drawinglayer/primitive2d/polygonprimitive2d.hxx> +#include <drawinglayer/processor2d/processor2dtools.hxx> +#include <basegfx/polygon/b2dpolygontools.hxx> -void XGradientList::impDestroy() -{ - if(mpData) - { - delete mpData; - mpData = 0; - } -} +using namespace com::sun::star; -XGradientList::XGradientList( const String& rPath, XOutdevItemPool* pInPool ) -: XPropertyList( XGRADIENT_LIST, rPath, pInPool ), - mpData(0) +XGradientList::XGradientList( const String& rPath ) +: XPropertyList( XGRADIENT_LIST, rPath ) { } XGradientList::~XGradientList() { - if(mpData) - { - delete mpData; - mpData = 0; - } } XGradientEntry* XGradientList::Replace(XGradientEntry* pEntry, long nIndex ) @@ -170,23 +89,126 @@ sal_Bool XGradientList::Create() Bitmap XGradientList::CreateBitmapForUI( long nIndex ) { - impCreate(); - VirtualDevice* pVD = mpData->getVirtualDevice(); - SdrObject* pBackgroundObject = mpData->getBackgroundObject(); + Bitmap aRetval; - pBackgroundObject->SetMergedItem(XFillStyleItem(XFILL_GRADIENT)); - pBackgroundObject->SetMergedItem(XFillGradientItem(GetGradient(nIndex)->GetGradient())); + OSL_ENSURE(nIndex < Count(), "OOps, access out of range (!)"); - sdr::contact::SdrObjectVector aObjectVector; - aObjectVector.push_back(pBackgroundObject); - sdr::contact::ObjectContactOfObjListPainter aPainter(*pVD, aObjectVector, 0); - sdr::contact::DisplayInfo aDisplayInfo; + if(nIndex < Count()) + { + const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings(); + const Size& rSize = rStyleSettings.GetListBoxPreviewDefaultPixelSize(); - pVD->Erase(); - aPainter.ProcessDisplay(aDisplayInfo); + // prepare polygon geometry for rectangle + const basegfx::B2DPolygon aRectangle( + basegfx::tools::createPolygonFromRect( + basegfx::B2DRange(0.0, 0.0, rSize.Width(), rSize.Height()))); + + const XGradient& rGradient = GetGradient(nIndex)->GetGradient(); + const sal_uInt16 nStartIntens(rGradient.GetStartIntens()); + basegfx::BColor aStart(rGradient.GetStartColor().getBColor()); + + if(nStartIntens != 100) + { + const basegfx::BColor aBlack; + aStart = interpolate(aBlack, aStart, (double)nStartIntens * 0.01); + } + + const sal_uInt16 nEndIntens(rGradient.GetEndIntens()); + basegfx::BColor aEnd(rGradient.GetEndColor().getBColor()); + + if(nEndIntens != 100) + { + const basegfx::BColor aBlack; + aEnd = interpolate(aBlack, aEnd, (double)nEndIntens * 0.01); + } + + drawinglayer::attribute::GradientStyle aGradientStyle(drawinglayer::attribute::GRADIENTSTYLE_RECT); + + switch(rGradient.GetGradientStyle()) + { + case XGRAD_LINEAR : + { + aGradientStyle = drawinglayer::attribute::GRADIENTSTYLE_LINEAR; + break; + } + case XGRAD_AXIAL : + { + aGradientStyle = drawinglayer::attribute::GRADIENTSTYLE_AXIAL; + break; + } + { + aGradientStyle = drawinglayer::attribute::GRADIENTSTYLE_RADIAL; + break; + } + case XGRAD_ELLIPTICAL : + { + aGradientStyle = drawinglayer::attribute::GRADIENTSTYLE_ELLIPTICAL; + break; + } + case XGRAD_SQUARE : + { + aGradientStyle = drawinglayer::attribute::GRADIENTSTYLE_SQUARE; + break; + } + default : + { + aGradientStyle = drawinglayer::attribute::GRADIENTSTYLE_RECT; // XGRAD_RECT + break; + } + } + + const sal_uInt16 nSteps((rSize.Width() + rSize.Height()) / 3); + const drawinglayer::attribute::FillGradientAttribute aFillGradient( + aGradientStyle, + (double)rGradient.GetBorder() * 0.01, + (double)rGradient.GetXOffset() * 0.01, + (double)rGradient.GetYOffset() * 0.01, + (double)rGradient.GetAngle() * F_PI1800, + aStart, + aEnd, + nSteps); + + const drawinglayer::primitive2d::Primitive2DReference aGradientPrimitive( + new drawinglayer::primitive2d::PolyPolygonGradientPrimitive2D( + basegfx::B2DPolyPolygon(aRectangle), + aFillGradient)); + + const basegfx::BColor aBlack(0.0, 0.0, 0.0); + const drawinglayer::primitive2d::Primitive2DReference aBlackRectanglePrimitive( + new drawinglayer::primitive2d::PolygonHairlinePrimitive2D( + aRectangle, + aBlack)); + + // prepare VirtualDevice + VirtualDevice aVirtualDevice; + const drawinglayer::geometry::ViewInformation2D aNewViewInformation2D; + + aVirtualDevice.SetOutputSizePixel(rSize); + aVirtualDevice.SetDrawMode(rStyleSettings.GetHighContrastMode() + ? DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT + : DRAWMODE_DEFAULT); + + // create processor and draw primitives + drawinglayer::processor2d::BaseProcessor2D* pProcessor2D = drawinglayer::processor2d::createPixelProcessor2DFromOutputDevice( + aVirtualDevice, + aNewViewInformation2D); + + if(pProcessor2D) + { + drawinglayer::primitive2d::Primitive2DSequence aSequence(2); + + aSequence[0] = aGradientPrimitive; + aSequence[1] = aBlackRectanglePrimitive; + + pProcessor2D->process(aSequence); + delete pProcessor2D; + } + + // get result bitmap and scale + aRetval = aVirtualDevice.GetBitmap(Point(0, 0), aVirtualDevice.GetOutputSizePixel()); + } - const Point aZero(0, 0); - return pVD->GetBitmap(aZero, pVD->GetOutputSize()); + return aRetval; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |