[Libreoffice-commits] core.git: Branch 'feature/vclref' - 3 commits - canvas/source compilerplugins/clang cppcanvas/source desktop/source drawinglayer/source editeng/source include/editeng include/svtools include/toolkit include/vcl svtools/source vcl/inc vcl/source

Noel Grandin noel at peralex.com
Thu Mar 19 04:55:57 PDT 2015


 canvas/source/vcl/bitmapbackbuffer.hxx                       |    2 
 canvas/source/vcl/impltools.hxx                              |    2 
 compilerplugins/clang/vclwidgets.cxx                         |  112 +++---
 cppcanvas/source/mtfrenderer/implrenderer.cxx                |   12 
 cppcanvas/source/mtfrenderer/transparencygroupaction.cxx     |   14 
 desktop/source/splash/splash.cxx                             |    4 
 drawinglayer/source/primitive2d/controlprimitive2d.cxx       |    8 
 drawinglayer/source/primitive2d/graphicprimitivehelper2d.cxx |   48 +-
 drawinglayer/source/primitive2d/textlayoutdevice.cxx         |    4 
 drawinglayer/source/processor2d/vclhelperbufferdevice.cxx    |    8 
 drawinglayer/source/processor2d/vclhelperbufferdevice.hxx    |    6 
 drawinglayer/source/processor2d/vclmetafileprocessor2d.cxx   |   40 +-
 drawinglayer/source/processor2d/vclprocessor2d.hxx           |    3 
 drawinglayer/source/tools/converters.cxx                     |   24 -
 editeng/source/editeng/editeng.cxx                           |    4 
 editeng/source/editeng/impedit.hxx                           |    2 
 editeng/source/items/svxfont.cxx                             |    2 
 include/editeng/outliner.hxx                                 |    3 
 include/svtools/ctrlbox.hxx                                  |    2 
 include/svtools/ctrltool.hxx                                 |    4 
 include/svtools/prnsetup.hxx                                 |    6 
 include/svtools/ruler.hxx                                    |    2 
 include/svtools/valueset.hxx                                 |    2 
 include/toolkit/awt/vclxgraphics.hxx                         |    3 
 include/vcl/animate.hxx                                      |    9 
 include/vcl/decoview.hxx                                     |    3 
 include/vcl/event.hxx                                        |    4 
 include/vcl/gdimtf.hxx                                       |    3 
 include/vcl/outdev.hxx                                       |    6 
 include/vcl/print.hxx                                        |    9 
 include/vcl/texteng.hxx                                      |    3 
 include/vcl/vclptr.hxx                                       |   48 ++
 include/vcl/virdev.hxx                                       |    4 
 include/vcl/window.hxx                                       |    2 
 svtools/source/contnr/imivctl.hxx                            |    8 
 svtools/source/contnr/imivctl1.cxx                           |   16 
 svtools/source/control/ctrlbox.cxx                           |   29 -
 svtools/source/control/ctrltool.cxx                          |    2 
 svtools/source/control/ruler.cxx                             |   98 ++---
 svtools/source/control/valueset.cxx                          |   74 ++--
 svtools/source/dialogs/prnsetup.cxx                          |    9 
 svtools/source/graphic/grfmgr2.cxx                           |   16 
 svtools/source/graphic/provider.cxx                          |   16 
 svtools/source/inc/renderer.hxx                              |    2 
 svtools/source/misc/sampletext.cxx                           |   14 
 svtools/source/table/gridtablerenderer.cxx                   |    8 
 svtools/source/toolpanel/paneltabbar.cxx                     |   24 -
 svtools/source/toolpanel/toolpaneldrawer.hxx                 |    2 
 vcl/inc/brdwin.hxx                                           |    8 
 vcl/inc/controldata.hxx                                      |    2 
 vcl/inc/outdev.h                                             |    3 
 vcl/inc/printdlg.hxx                                         |    2 
 vcl/inc/svdata.hxx                                           |   20 -
 vcl/inc/window.h                                             |    2 
 vcl/source/app/svdata.cxx                                    |    2 
 vcl/source/edit/texteng.cxx                                  |    2 
 vcl/source/edit/textview.cxx                                 |    7 
 vcl/source/filter/graphicfilter.cxx                          |   16 
 vcl/source/filter/sgfbram.cxx                                |   14 
 vcl/source/filter/sgvmain.cxx                                |    4 
 vcl/source/filter/sgvtext.cxx                                |   16 
 vcl/source/filter/wmf/emfwr.cxx                              |  114 +++---
 vcl/source/filter/wmf/emfwr.hxx                              |    2 
 vcl/source/filter/wmf/wmfwr.cxx                              |    2 
 vcl/source/filter/wmf/wmfwr.hxx                              |    2 
 vcl/source/gdi/animate.cxx                                   |    6 
 vcl/source/gdi/bitmapex.cxx                                  |   14 
 vcl/source/gdi/cvtsvm.cxx                                    |   26 -
 vcl/source/gdi/gdimetafiletools.cxx                          |   20 -
 vcl/source/gdi/gdimtf.cxx                                    |  180 +++++------
 vcl/source/gdi/impanmvw.cxx                                  |   22 -
 vcl/source/gdi/impanmvw.hxx                                  |    6 
 vcl/source/gdi/impgraph.cxx                                  |   16 
 vcl/source/gdi/impvect.cxx                                   |    4 
 vcl/source/gdi/pdfwriter_impl.cxx                            |   14 
 vcl/source/gdi/pdfwriter_impl.hxx                            |    2 
 vcl/source/gdi/pdfwriter_impl2.cxx                           |    6 
 vcl/source/gdi/print.cxx                                     |   14 
 vcl/source/gdi/print2.cxx                                    |   94 ++---
 vcl/source/gdi/virdev.cxx                                    |    3 
 vcl/source/outdev/bitmap.cxx                                 |   10 
 vcl/source/outdev/outdev.cxx                                 |    4 
 vcl/source/outdev/text.cxx                                   |   48 +-
 vcl/source/outdev/transparent.cxx                            |   16 
 vcl/source/outdev/wallpaper.cxx                              |   10 
 vcl/source/window/brdwin.cxx                                 |   10 
 vcl/source/window/clipping.cxx                               |    6 
 vcl/source/window/decoview.cxx                               |    2 
 vcl/source/window/paint.cxx                                  |    4 
 vcl/source/window/printdlg.cxx                               |   43 +-
 vcl/source/window/status.cxx                                 |    4 
 vcl/source/window/window.cxx                                 |    1 
 92 files changed, 807 insertions(+), 722 deletions(-)

New commits:
commit dcb875f9261ce68bfef389d3a4ffea582fce3a67
Author: Noel Grandin <noel at peralex.com>
Date:   Thu Mar 19 13:54:12 2015 +0200

    start wrapping OutputDevice in VclPtr
    
    Change-Id: If3ecbb0599b50d50ce6b3997ca7892200c332ffe

diff --git a/canvas/source/vcl/bitmapbackbuffer.hxx b/canvas/source/vcl/bitmapbackbuffer.hxx
index c3f2a27..b518679 100644
--- a/canvas/source/vcl/bitmapbackbuffer.hxx
+++ b/canvas/source/vcl/bitmapbackbuffer.hxx
@@ -66,7 +66,7 @@ namespace vclcanvas
         void updateVDev() const;
 
         ::canvas::vcltools::VCLObject<BitmapEx> maBitmap;
-        mutable VirtualDevice*                  mpVDev; // created only on demand
+        mutable VclPtr<VirtualDevice>           mpVDev; // created only on demand
 
         const OutputDevice&                     mrRefDevice;
 
diff --git a/canvas/source/vcl/impltools.hxx b/canvas/source/vcl/impltools.hxx
index 0594955..c294efd 100644
--- a/canvas/source/vcl/impltools.hxx
+++ b/canvas/source/vcl/impltools.hxx
@@ -158,7 +158,7 @@ namespace vclcanvas
                 }
             }
 
-            OutputDevice*       mpOutDev;
+            VclPtr<OutputDevice> mpOutDev;
             const bool          mbMappingWasEnabled;
             const sal_uInt16    mnAntiAliasing;
         };
diff --git a/cppcanvas/source/mtfrenderer/implrenderer.cxx b/cppcanvas/source/mtfrenderer/implrenderer.cxx
index 2bd0956..3582537 100644
--- a/cppcanvas/source/mtfrenderer/implrenderer.cxx
+++ b/cppcanvas/source/mtfrenderer/implrenderer.cxx
@@ -2908,16 +2908,16 @@ namespace cppcanvas
 
             VectorOfOutDevStates    aStateStack;
 
-            VirtualDevice aVDev;
-            aVDev.EnableOutput( false );
+            ScopedVclPtr<VirtualDevice> aVDev = new VirtualDevice;
+            aVDev->EnableOutput( false );
 
             // Setup VDev for state tracking and mapping
             // =========================================
 
-            aVDev.SetMapMode( rMtf.GetPrefMapMode() );
+            aVDev->SetMapMode( rMtf.GetPrefMapMode() );
 
             const Size aMtfSize( rMtf.GetPrefSize() );
-            const Size aMtfSizePixPre( aVDev.LogicToPixel( aMtfSize,
+            const Size aMtfSizePixPre( aVDev->LogicToPixel( aMtfSize,
                                                            rMtf.GetPrefMapMode() ) );
 
             // #i44110# correct null-sized output - there are shapes
@@ -2928,7 +2928,7 @@ namespace cppcanvas
             sal_Int32 nCurrActions(0);
             ActionFactoryParameters aParms(aStateStack,
                                            rCanvas,
-                                           aVDev,
+                                           *aVDev.get(),
                                            rParams,
                                            nCurrActions );
 
@@ -2942,7 +2942,7 @@ namespace cppcanvas
                                                      1.0 / aMtfSizePix.Height() );
 
             tools::calcLogic2PixelAffineTransform( aStateStack.getState().mapModeTransform,
-                                                   aVDev );
+                                                   *aVDev.get() );
 
             ColorSharedPtr pColor( getCanvas()->createColor() );
 
diff --git a/cppcanvas/source/mtfrenderer/transparencygroupaction.cxx b/cppcanvas/source/mtfrenderer/transparencygroupaction.cxx
index fa91a85..74a9505 100644
--- a/cppcanvas/source/mtfrenderer/transparencygroupaction.cxx
+++ b/cppcanvas/source/mtfrenderer/transparencygroupaction.cxx
@@ -242,10 +242,10 @@ namespace cppcanvas
 
                     // render our content into an appropriately sized
                     // VirtualDevice with alpha channel
-                    VirtualDevice aVDev(
-                        *::Application::GetDefaultDevice(), 0, 0 );
-                    aVDev.SetOutputSizePixel( aBitmapSizePixel );
-                    aVDev.SetMapMode();
+                    ScopedVclPtr<VirtualDevice> aVDev(new VirtualDevice(
+                        *::Application::GetDefaultDevice(), 0, 0 ));
+                    aVDev->SetOutputSizePixel( aBitmapSizePixel );
+                    aVDev->SetMapMode();
 
                     if( rSubset.mnSubsetBegin != 0 ||
                         rSubset.mnSubsetEnd != -1 )
@@ -334,7 +334,7 @@ namespace cppcanvas
                             }
                         }
 
-                        aVDev.DrawTransparent( aMtf,
+                        aVDev->DrawTransparent( aMtf,
                                                aEmptyPoint,
                                                aOutputSizePixel,
                                                *mpAlphaGradient );
@@ -342,7 +342,7 @@ namespace cppcanvas
                     else
                     {
                         // no subsetting - render whole mtf
-                        aVDev.DrawTransparent( *mpGroupMtf,
+                        aVDev->DrawTransparent( *mpGroupMtf,
                                                aEmptyPoint,
                                                aOutputSizePixel,
                                                *mpAlphaGradient );
@@ -352,7 +352,7 @@ namespace cppcanvas
                     // update buffered bitmap and transformation
                     BitmapSharedPtr aBmp( VCLFactory::getInstance().createBitmap(
                                               mpCanvas,
-                                              aVDev.GetBitmapEx(
+                                              aVDev->GetBitmapEx(
                                                   aEmptyPoint,
                                                   aBitmapSizePixel ) ) );
                     mxBufferBitmap = aBmp->getUNOBitmap();
diff --git a/desktop/source/splash/splash.cxx b/desktop/source/splash/splash.cxx
index d6c8054..e3be3e0 100644
--- a/desktop/source/splash/splash.cxx
+++ b/desktop/source/splash/splash.cxx
@@ -63,7 +63,7 @@ private:
 
     static osl::Mutex _aMutex;
 
-    VirtualDevice   _vdev;
+    ScopedVclPtr<VirtualDevice> _vdev;
     BitmapEx        _aIntroBmp;
     Color           _cProgressFrameColor;
     Color           _cProgressBarColor;
@@ -119,7 +119,7 @@ public:
 
 SplashScreen::SplashScreen()
     : IntroWindow()
-    , _vdev(*((IntroWindow*)this))
+    , _vdev(new VirtualDevice(*((IntroWindow*)this)))
     , _cProgressFrameColor(sal::static_int_cast< ColorData >(NOT_LOADED))
     , _cProgressBarColor(sal::static_int_cast< ColorData >(NOT_LOADED))
     , _cProgressTextColor(sal::static_int_cast< ColorData >(NOT_LOADED))
diff --git a/drawinglayer/source/primitive2d/controlprimitive2d.cxx b/drawinglayer/source/primitive2d/controlprimitive2d.cxx
index b764e02..bb84b29 100644
--- a/drawinglayer/source/primitive2d/controlprimitive2d.cxx
+++ b/drawinglayer/source/primitive2d/controlprimitive2d.cxx
@@ -116,15 +116,15 @@ namespace drawinglayer
                     if(nSizeX > 0 && nSizeY > 0)
                     {
                         // prepare VirtualDevice
-                        VirtualDevice aVirtualDevice(*Application::GetDefaultDevice());
+                        ScopedVclPtr<VirtualDevice> aVirtualDevice(new VirtualDevice(*Application::GetDefaultDevice()));
                         const Size aSizePixel(nSizeX, nSizeY);
-                        aVirtualDevice.SetOutputSizePixel(aSizePixel);
+                        aVirtualDevice->SetOutputSizePixel(aSizePixel);
 
                         // set size at control
                         xControlWindow->setPosSize(0, 0, nSizeX, nSizeY, awt::PosSize::POSSIZE);
 
                         // get graphics and view
-                        uno::Reference< awt::XGraphics > xGraphics(aVirtualDevice.CreateUnoGraphics());
+                        uno::Reference< awt::XGraphics > xGraphics(aVirtualDevice->CreateUnoGraphics());
                         uno::Reference< awt::XView > xControlView(rXControl, uno::UNO_QUERY);
 
                         if(xGraphics.is() && xControlView.is())
@@ -190,7 +190,7 @@ namespace drawinglayer
                                 xControlView->draw(0, 0);
 
                                 // get bitmap
-                                const Bitmap aContent(aVirtualDevice.GetBitmap(Point(), aSizePixel));
+                                const Bitmap aContent(aVirtualDevice->GetBitmap(Point(), aSizePixel));
 
                                 // to avoid scaling, use the Bitmap pixel size as primitive size
                                 const Size aBitmapSize(aContent.GetSizePixel());
diff --git a/drawinglayer/source/primitive2d/graphicprimitivehelper2d.cxx b/drawinglayer/source/primitive2d/graphicprimitivehelper2d.cxx
index af59a45..8981278 100644
--- a/drawinglayer/source/primitive2d/graphicprimitivehelper2d.cxx
+++ b/drawinglayer/source/primitive2d/graphicprimitivehelper2d.cxx
@@ -96,16 +96,16 @@ namespace
         // with a step count of zero
         if(maAnimation.Count())
         {
-            VirtualDevice aVirtualDevice(*Application::GetDefaultDevice());
-            VirtualDevice aVirtualDeviceMask(*Application::GetDefaultDevice(), 1L);
+            ScopedVclPtr<VirtualDevice> aVirtualDevice(new VirtualDevice(*Application::GetDefaultDevice()));
+            ScopedVclPtr<VirtualDevice> aVirtualDeviceMask(new VirtualDevice(*Application::GetDefaultDevice(), 1L));
 
             // Prepare VirtualDevices and their states
-            aVirtualDevice.EnableMapMode(false);
-            aVirtualDeviceMask.EnableMapMode(false);
-            aVirtualDevice.SetOutputSizePixel(maAnimation.GetDisplaySizePixel());
-            aVirtualDeviceMask.SetOutputSizePixel(maAnimation.GetDisplaySizePixel());
-            aVirtualDevice.Erase();
-            aVirtualDeviceMask.Erase();
+            aVirtualDevice->EnableMapMode(false);
+            aVirtualDeviceMask->EnableMapMode(false);
+            aVirtualDevice->SetOutputSizePixel(maAnimation.GetDisplaySizePixel());
+            aVirtualDeviceMask->SetOutputSizePixel(maAnimation.GetDisplaySizePixel());
+            aVirtualDevice->Erase();
+            aVirtualDeviceMask->Erase();
 
             for(sal_uInt16 a(0L); a < maAnimation.Count(); a++)
             {
@@ -119,20 +119,20 @@ namespace
                 {
                     case DISPOSE_NOT:
                     {
-                        aVirtualDevice.DrawBitmapEx(rAnimBitmap.aPosPix, rAnimBitmap.aBmpEx);
+                        aVirtualDevice->DrawBitmapEx(rAnimBitmap.aPosPix, rAnimBitmap.aBmpEx);
                         Bitmap aMask = rAnimBitmap.aBmpEx.GetMask();
 
                         if(aMask.IsEmpty())
                         {
                             const Point aEmpty;
-                            const Rectangle aRect(aEmpty, aVirtualDeviceMask.GetOutputSizePixel());
+                            const Rectangle aRect(aEmpty, aVirtualDeviceMask->GetOutputSizePixel());
                             const Wallpaper aWallpaper(COL_BLACK);
-                            aVirtualDeviceMask.DrawWallpaper(aRect, aWallpaper);
+                            aVirtualDeviceMask->DrawWallpaper(aRect, aWallpaper);
                         }
                         else
                         {
                             BitmapEx aExpandVisibilityMask = BitmapEx(aMask, aMask);
-                            aVirtualDeviceMask.DrawBitmapEx(rAnimBitmap.aPosPix, aExpandVisibilityMask);
+                            aVirtualDeviceMask->DrawBitmapEx(rAnimBitmap.aPosPix, aExpandVisibilityMask);
                         }
 
                         break;
@@ -143,42 +143,42 @@ namespace
                         const Bitmap aMask(rAnimBitmap.aBmpEx.GetMask());
                         const Bitmap aContent(rAnimBitmap.aBmpEx.GetBitmap());
 
-                        aVirtualDeviceMask.Erase();
-                        aVirtualDevice.DrawBitmap(rAnimBitmap.aPosPix, aContent);
+                        aVirtualDeviceMask->Erase();
+                        aVirtualDevice->DrawBitmap(rAnimBitmap.aPosPix, aContent);
 
                         if(aMask.IsEmpty())
                         {
                             const Rectangle aRect(rAnimBitmap.aPosPix, aContent.GetSizePixel());
-                            aVirtualDeviceMask.SetFillColor(COL_BLACK);
-                            aVirtualDeviceMask.SetLineColor();
-                            aVirtualDeviceMask.DrawRect(aRect);
+                            aVirtualDeviceMask->SetFillColor(COL_BLACK);
+                            aVirtualDeviceMask->SetLineColor();
+                            aVirtualDeviceMask->DrawRect(aRect);
                         }
                         else
                         {
-                            aVirtualDeviceMask.DrawBitmap(rAnimBitmap.aPosPix, aMask);
+                            aVirtualDeviceMask->DrawBitmap(rAnimBitmap.aPosPix, aMask);
                         }
 
                         break;
                     }
                     case DISPOSE_FULL:
                     {
-                        aVirtualDevice.DrawBitmapEx(rAnimBitmap.aPosPix, rAnimBitmap.aBmpEx);
+                        aVirtualDevice->DrawBitmapEx(rAnimBitmap.aPosPix, rAnimBitmap.aBmpEx);
                         break;
                     }
                     case DISPOSE_PREVIOUS :
                     {
-                        aVirtualDevice.DrawBitmapEx(rAnimBitmap.aPosPix, rAnimBitmap.aBmpEx);
-                        aVirtualDeviceMask.DrawBitmap(rAnimBitmap.aPosPix, rAnimBitmap.aBmpEx.GetMask());
+                        aVirtualDevice->DrawBitmapEx(rAnimBitmap.aPosPix, rAnimBitmap.aBmpEx);
+                        aVirtualDeviceMask->DrawBitmap(rAnimBitmap.aPosPix, rAnimBitmap.aBmpEx.GetMask());
                         break;
                     }
                 }
 
                 // create BitmapEx
-                Bitmap aMainBitmap = aVirtualDevice.GetBitmap(Point(), aVirtualDevice.GetOutputSizePixel());
+                Bitmap aMainBitmap = aVirtualDevice->GetBitmap(Point(), aVirtualDevice->GetOutputSizePixel());
 #if defined(MACOSX) || defined(IOS)
-                AlphaMask aMaskBitmap( aVirtualDeviceMask.GetBitmap( Point(), aVirtualDeviceMask.GetOutputSizePixel()));
+                AlphaMask aMaskBitmap( aVirtualDeviceMask->GetBitmap( Point(), aVirtualDeviceMask->GetOutputSizePixel()));
 #else
-                Bitmap aMaskBitmap = aVirtualDeviceMask.GetBitmap( Point(), aVirtualDeviceMask.GetOutputSizePixel());
+                Bitmap aMaskBitmap = aVirtualDeviceMask->GetBitmap( Point(), aVirtualDeviceMask->GetOutputSizePixel());
 #endif
                 aNextStep.maBitmapEx = BitmapEx(aMainBitmap, aMaskBitmap);
 
diff --git a/drawinglayer/source/primitive2d/textlayoutdevice.cxx b/drawinglayer/source/primitive2d/textlayoutdevice.cxx
index 12e83f6..9f71472 100644
--- a/drawinglayer/source/primitive2d/textlayoutdevice.cxx
+++ b/drawinglayer/source/primitive2d/textlayoutdevice.cxx
@@ -59,7 +59,7 @@ namespace
     class ImpTimedRefDev : public Timer
     {
         scoped_timed_RefDev&                mrOwnerOfMe;
-        VirtualDevice*                      mpVirDev;
+        VclPtr<VirtualDevice>               mpVirDev;
         sal_uInt32                          mnUseCount;
 
     public:
@@ -84,7 +84,7 @@ namespace
     {
         OSL_ENSURE(0L == mnUseCount, "destruction of a still used ImpTimedRefDev (!)");
         const SolarMutexGuard aGuard;
-        delete mpVirDev;
+        mpVirDev.disposeAndClear();
     }
 
     void ImpTimedRefDev::Timeout()
diff --git a/drawinglayer/source/processor2d/vclhelperbufferdevice.cxx b/drawinglayer/source/processor2d/vclhelperbufferdevice.cxx
index 94a155d..adc5448 100644
--- a/drawinglayer/source/processor2d/vclhelperbufferdevice.cxx
+++ b/drawinglayer/source/processor2d/vclhelperbufferdevice.cxx
@@ -32,7 +32,7 @@
 
 namespace
 {
-    typedef ::std::vector< VirtualDevice* > aBuffers;
+    typedef ::std::vector< VclPtr<VirtualDevice> > aBuffers;
 
     class VDevBuffer : public Timer, protected comphelper::OBaseMutex
     {
@@ -69,13 +69,13 @@ namespace
 
         while(!maFreeBuffers.empty())
         {
-            delete *(maFreeBuffers.end() - 1);
+            (*(maFreeBuffers.end() - 1)).disposeAndClear();
             maFreeBuffers.pop_back();
         }
 
         while(!maUsedBuffers.empty())
         {
-            delete *(maUsedBuffers.end() - 1);
+            (*(maUsedBuffers.end() - 1)).disposeAndClear();
             maUsedBuffers.pop_back();
         }
     }
@@ -197,7 +197,7 @@ namespace
 
         while(!maFreeBuffers.empty())
         {
-            delete *(maFreeBuffers.end() - 1);
+            (*(maFreeBuffers.end() - 1)).disposeAndClear();
             maFreeBuffers.pop_back();
         }
     }
diff --git a/drawinglayer/source/processor2d/vclhelperbufferdevice.hxx b/drawinglayer/source/processor2d/vclhelperbufferdevice.hxx
index 02aa3c0..0ba7311 100644
--- a/drawinglayer/source/processor2d/vclhelperbufferdevice.hxx
+++ b/drawinglayer/source/processor2d/vclhelperbufferdevice.hxx
@@ -35,9 +35,9 @@ namespace drawinglayer
     class impBufferDevice
     {
         OutputDevice&                       mrOutDev;
-        VirtualDevice*                      mpContent;
-        VirtualDevice*                      mpMask;
-        VirtualDevice*                      mpAlpha;
+        VclPtr<VirtualDevice>               mpContent;
+        VclPtr<VirtualDevice>               mpMask;
+        VclPtr<VirtualDevice>               mpAlpha;
         Rectangle                           maDestPixel;
 
     public:
diff --git a/drawinglayer/source/processor2d/vclmetafileprocessor2d.cxx b/drawinglayer/source/processor2d/vclmetafileprocessor2d.cxx
index 2b2c0b8..935b0b5 100644
--- a/drawinglayer/source/processor2d/vclmetafileprocessor2d.cxx
+++ b/drawinglayer/source/processor2d/vclmetafileprocessor2d.cxx
@@ -252,20 +252,20 @@ namespace drawinglayer
             const Rectangle aPrimitiveRectangle(
                 basegfx::fround(aPrimitiveRange.getMinX()), basegfx::fround(aPrimitiveRange.getMinY()),
                 basegfx::fround(aPrimitiveRange.getMaxX()), basegfx::fround(aPrimitiveRange.getMaxY()));
-            VirtualDevice aContentVDev;
+            ScopedVclPtr<VirtualDevice> aContentVDev = new VirtualDevice;
             MapMode aNewMapMode(pLastOutputDevice->GetMapMode());
 
-            mpOutputDevice = &aContentVDev;
+            mpOutputDevice = aContentVDev.get();
             mpMetaFile = &o_rContentMetafile;
-            aContentVDev.EnableOutput(false);
-            aContentVDev.SetMapMode(pLastOutputDevice->GetMapMode());
-            o_rContentMetafile.Record(&aContentVDev);
-            aContentVDev.SetLineColor(pLastOutputDevice->GetLineColor());
-            aContentVDev.SetFillColor(pLastOutputDevice->GetFillColor());
-            aContentVDev.SetFont(pLastOutputDevice->GetFont());
-            aContentVDev.SetDrawMode(pLastOutputDevice->GetDrawMode());
-            aContentVDev.SetSettings(pLastOutputDevice->GetSettings());
-            aContentVDev.SetRefPoint(pLastOutputDevice->GetRefPoint());
+            aContentVDev->EnableOutput(false);
+            aContentVDev->SetMapMode(pLastOutputDevice->GetMapMode());
+            o_rContentMetafile.Record(aContentVDev.get());
+            aContentVDev->SetLineColor(pLastOutputDevice->GetLineColor());
+            aContentVDev->SetFillColor(pLastOutputDevice->GetFillColor());
+            aContentVDev->SetFont(pLastOutputDevice->GetFont());
+            aContentVDev->SetDrawMode(pLastOutputDevice->GetDrawMode());
+            aContentVDev->SetSettings(pLastOutputDevice->GetSettings());
+            aContentVDev->SetRefPoint(pLastOutputDevice->GetRefPoint());
 
             // dump to MetaFile
             process(rContent);
@@ -2016,7 +2016,7 @@ namespace drawinglayer
                             const Rectangle aRectPixel(mpOutputDevice->LogicToPixel(aRectLogic));
                             Size aSizePixel(aRectPixel.GetSize());
                             const Point aEmptyPoint;
-                            VirtualDevice aBufferDevice;
+                            ScopedVclPtr<VirtualDevice> aBufferDevice = new VirtualDevice;
                             const sal_uInt32 nMaxQuadratPixels(500000);
                             const sal_uInt32 nViewVisibleArea(aSizePixel.getWidth() * aSizePixel.getHeight());
                             double fReduceFactor(1.0);
@@ -2029,20 +2029,20 @@ namespace drawinglayer
                                     basegfx::fround((double)aSizePixel.getHeight() * fReduceFactor));
                             }
 
-                            if(aBufferDevice.SetOutputSizePixel(aSizePixel))
+                            if(aBufferDevice->SetOutputSizePixel(aSizePixel))
                             {
                                 // create and set MapModes for target devices
                                 MapMode aNewMapMode(mpOutputDevice->GetMapMode());
                                 aNewMapMode.SetOrigin(Point(-aRectLogic.Left(), -aRectLogic.Top()));
-                                aBufferDevice.SetMapMode(aNewMapMode);
+                                aBufferDevice->SetMapMode(aNewMapMode);
 
                                 // prepare view transformation for target renderers
                                 // ATTENTION! Need to apply another scaling because of the potential DPI differences
                                 // between Printer and VDev (mpOutputDevice and aBufferDevice here).
                                 // To get the DPI, LogicToPixel from (1,1) from MAP_INCH needs to be used.
-                                basegfx::B2DHomMatrix aViewTransform(aBufferDevice.GetViewTransformation());
+                                basegfx::B2DHomMatrix aViewTransform(aBufferDevice->GetViewTransformation());
                                 const Size aDPIOld(mpOutputDevice->LogicToPixel(Size(1, 1), MAP_INCH));
-                                const Size aDPINew(aBufferDevice.LogicToPixel(Size(1, 1), MAP_INCH));
+                                const Size aDPINew(aBufferDevice->LogicToPixel(Size(1, 1), MAP_INCH));
                                 const double fDPIXChange((double)aDPIOld.getWidth() / (double)aDPINew.getWidth());
                                 const double fDPIYChange((double)aDPIOld.getHeight() / (double)aDPINew.getHeight());
 
@@ -2067,16 +2067,16 @@ namespace drawinglayer
                                     getViewInformation2D().getViewTime(),
                                     getViewInformation2D().getExtendedInformationSequence());
 
-                                VclPixelProcessor2D aBufferProcessor(aViewInfo, aBufferDevice);
+                                VclPixelProcessor2D aBufferProcessor(aViewInfo, *aBufferDevice.get());
 
                                 // draw content using pixel renderer
                                 aBufferProcessor.process(rContent);
-                                const Bitmap aBmContent(aBufferDevice.GetBitmap(aEmptyPoint, aSizePixel));
+                                const Bitmap aBmContent(aBufferDevice->GetBitmap(aEmptyPoint, aSizePixel));
 
                                 // draw transparence using pixel renderer
-                                aBufferDevice.Erase();
+                                aBufferDevice->Erase();
                                 aBufferProcessor.process(rTransparence);
-                                const AlphaMask aBmAlpha(aBufferDevice.GetBitmap(aEmptyPoint, aSizePixel));
+                                const AlphaMask aBmAlpha(aBufferDevice->GetBitmap(aEmptyPoint, aSizePixel));
 
                                 // paint
                                 mpOutputDevice->DrawBitmapEx(
diff --git a/drawinglayer/source/processor2d/vclprocessor2d.hxx b/drawinglayer/source/processor2d/vclprocessor2d.hxx
index 70de6a1..a527bb2 100644
--- a/drawinglayer/source/processor2d/vclprocessor2d.hxx
+++ b/drawinglayer/source/processor2d/vclprocessor2d.hxx
@@ -26,6 +26,7 @@
 #include <basegfx/matrix/b2dhommatrix.hxx>
 #include <basegfx/color/bcolormodifier.hxx>
 #include <svtools/optionsdrawinglayer.hxx>
+#include <vcl/vclptr.hxx>
 
 
 // predefines
@@ -70,7 +71,7 @@ namespace drawinglayer
         {
         protected:
             // the destination OutDev
-            OutputDevice*                                           mpOutputDevice;
+            VclPtr<OutputDevice>                                    mpOutputDevice;
 
             // the modifiedColorPrimitive stack
             basegfx::BColorModifierStack                            maBColorModifierStack;
diff --git a/drawinglayer/source/tools/converters.cxx b/drawinglayer/source/tools/converters.cxx
index 0fbb6f9..03318cc 100644
--- a/drawinglayer/source/tools/converters.cxx
+++ b/drawinglayer/source/tools/converters.cxx
@@ -73,21 +73,21 @@ namespace drawinglayer
                 const Point aEmptyPoint;
                 const Size aSizePixel(nDiscreteWidth, nDiscreteHeight);
                 geometry::ViewInformation2D aViewInformation2D(rViewInformation2D);
-                VirtualDevice maContent;
+                ScopedVclPtr<VirtualDevice> maContent = new VirtualDevice;
 
                 // prepare vdev
-                maContent.SetOutputSizePixel(aSizePixel, false);
-                maContent.SetMapMode(aMapModePixel);
+                maContent->SetOutputSizePixel(aSizePixel, false);
+                maContent->SetMapMode(aMapModePixel);
 
                 // set to all white
-                maContent.SetBackground(Wallpaper(Color(COL_WHITE)));
-                maContent.Erase();
+                maContent->SetBackground(Wallpaper(Color(COL_WHITE)));
+                maContent->Erase();
 
                 // create pixel processor, also already takes care of AAing and
                 // checking the getOptionsDrawinglayer().IsAntiAliasing() switch. If
                 // not wanted, change after this call as needed
                 processor2d::BaseProcessor2D* pContentProcessor = processor2d::createPixelProcessor2DFromOutputDevice(
-                    maContent,
+                    *maContent.get(),
                     aViewInformation2D);
 
                 if(pContentProcessor)
@@ -96,8 +96,8 @@ namespace drawinglayer
                     pContentProcessor->process(aSequence);
 
                     // get content
-                    maContent.EnableMapMode(false);
-                    const Bitmap aContent(maContent.GetBitmap(aEmptyPoint, aSizePixel));
+                    maContent->EnableMapMode(false);
+                    const Bitmap aContent(maContent->GetBitmap(aEmptyPoint, aSizePixel));
 
 #ifdef DBG_UTIL
                     if(bDoSaveForVisualControl)
@@ -108,10 +108,10 @@ namespace drawinglayer
                     }
 #endif
                     // prepare for mask creation
-                    maContent.SetMapMode(aMapModePixel);
+                    maContent->SetMapMode(aMapModePixel);
 
                     // set alpha to all white (fully transparent)
-                    maContent.Erase();
+                    maContent->Erase();
 
                     // embed primitives to paint them black
                     const primitive2d::Primitive2DReference xRef(
@@ -127,8 +127,8 @@ namespace drawinglayer
                     delete pContentProcessor;
 
                     // get alpha cahannel from vdev
-                    maContent.EnableMapMode(false);
-                    const Bitmap aAlpha(maContent.GetBitmap(aEmptyPoint, aSizePixel));
+                    maContent->EnableMapMode(false);
+                    const Bitmap aAlpha(maContent->GetBitmap(aEmptyPoint, aSizePixel));
 #ifdef DBG_UTIL
                     if(bDoSaveForVisualControl)
                     {
diff --git a/editeng/source/editeng/editeng.cxx b/editeng/source/editeng/editeng.cxx
index 1208536..85e4d9c 100644
--- a/editeng/source/editeng/editeng.cxx
+++ b/editeng/source/editeng/editeng.cxx
@@ -1758,14 +1758,14 @@ SvxFont EditEngine::GetStandardSvxFont( sal_Int32 nPara )
 
 void EditEngine::StripPortions()
 {
-    VirtualDevice aTmpDev;
+    ScopedVclPtr<VirtualDevice> aTmpDev = new VirtualDevice;
     Rectangle aBigRect( Point( 0, 0 ), Size( 0x7FFFFFFF, 0x7FFFFFFF ) );
     if ( IsVertical() )
     {
         aBigRect.Right() = 0;
         aBigRect.Left() = -0x7FFFFFFF;
     }
-    pImpEditEngine->Paint( &aTmpDev, aBigRect, Point(), true );
+    pImpEditEngine->Paint( aTmpDev.get(), aBigRect, Point(), true );
 }
 
 void EditEngine::GetPortions( sal_Int32 nPara, std::vector<sal_Int32>& rList )
diff --git a/editeng/source/editeng/impedit.hxx b/editeng/source/editeng/impedit.hxx
index e193dbd..8ba1adf 100644
--- a/editeng/source/editeng/impedit.hxx
+++ b/editeng/source/editeng/impedit.hxx
@@ -111,7 +111,7 @@ struct DragAndDropInfo
     EditPaM             aDropDest;
     sal_Int32           nOutlinerDropDest;
     ESelection          aDropSel;
-    VirtualDevice*      pBackground;
+    VclPtr<VirtualDevice> pBackground;
     const SvxFieldItem* pField;
     bool            bVisCursor              : 1;
     bool            bDroppedInMe            : 1;
diff --git a/editeng/source/items/svxfont.cxx b/editeng/source/items/svxfont.cxx
index a306c68..34c03e2 100644
--- a/editeng/source/items/svxfont.cxx
+++ b/editeng/source/items/svxfont.cxx
@@ -163,7 +163,7 @@ OUString SvxFont::CalcCaseMap(const OUString &rTxt) const
 class SvxDoCapitals
 {
 protected:
-    OutputDevice *pOut;
+    VclPtr<OutputDevice> pOut;
     const OUString &rTxt;
     const sal_Int32 nIdx;
     const sal_Int32 nLen;
diff --git a/include/editeng/outliner.hxx b/include/editeng/outliner.hxx
index 7e250c4..c2d97eb 100644
--- a/include/editeng/outliner.hxx
+++ b/include/editeng/outliner.hxx
@@ -28,6 +28,7 @@
 #include <tools/color.hxx>
 #include <tools/contnr.hxx>
 #include <vcl/graph.hxx>
+#include <vcl/outdev.hxx>
 #include <tools/link.hxx>
 #include <rsc/rscsfx.hxx>
 #include <editeng/editengdllapi.h>
@@ -461,7 +462,7 @@ struct EDITENG_DLLPUBLIC PaintFirstLineInfo
     long mnBaseLineY;
     const Point& mrOrigin;
     short mnOrientation;
-    OutputDevice* mpOutDev;
+    VclPtr<OutputDevice> mpOutDev;
 
     PaintFirstLineInfo( sal_Int32 nPara, const Point& rStartPos, long nBaseLineY, const Point& rOrigin, short nOrientation, OutputDevice* pOutDev )
         : mnPara( nPara ), mrStartPos( rStartPos ), mnBaseLineY( nBaseLineY ), mrOrigin( rOrigin ), mnOrientation( nOrientation ), mpOutDev( pOutDev )
diff --git a/include/svtools/ctrlbox.hxx b/include/svtools/ctrlbox.hxx
index 6c62909..c63d7d8 100644
--- a/include/svtools/ctrlbox.hxx
+++ b/include/svtools/ctrlbox.hxx
@@ -281,7 +281,7 @@ class SVT_DLLPUBLIC LineListBox : public ListBox
     long            m_nWidth;
     OUString        m_sNone;
 
-    VirtualDevice   aVirDev;
+    ScopedVclPtr<VirtualDevice>   aVirDev;
     Size            aTxtSize;
     Color           aColor;
     Color           maPaintCol;
diff --git a/include/svtools/ctrltool.hxx b/include/svtools/ctrltool.hxx
index a28ff1d..01305c5 100644
--- a/include/svtools/ctrltool.hxx
+++ b/include/svtools/ctrltool.hxx
@@ -149,8 +149,8 @@ private:
     OUString                maBlack;
     OUString                maBlackItalic;
     sal_IntPtr*             mpSizeAry;
-    OutputDevice*           mpDev;
-    OutputDevice*           mpDev2;
+    VclPtr<OutputDevice>    mpDev;
+    VclPtr<OutputDevice>    mpDev2;
     boost::ptr_vector<ImplFontListNameInfo> maEntries;
 
     SVT_DLLPRIVATE ImplFontListNameInfo*    ImplFind( const OUString& rSearchName, sal_uLong* pIndex ) const;
diff --git a/include/svtools/prnsetup.hxx b/include/svtools/prnsetup.hxx
index c30062b..62d430a 100644
--- a/include/svtools/prnsetup.hxx
+++ b/include/svtools/prnsetup.hxx
@@ -47,9 +47,9 @@ private:
     VclPtr<FixedText>      m_pFiType;
     VclPtr<FixedText>      m_pFiLocation;
     VclPtr<FixedText>      m_pFiComment;
-    AutoTimer       maStatusTimer;
-    Printer*        mpPrinter;
-    Printer*        mpTempPrinter;
+    AutoTimer              maStatusTimer;
+    VclPtr<Printer>        mpPrinter;
+    VclPtr<Printer>        mpTempPrinter;
 
     SVT_DLLPRIVATE void         ImplSetInfo();
 
diff --git a/include/svtools/ruler.hxx b/include/svtools/ruler.hxx
index ba75ac7..e3d970c 100644
--- a/include/svtools/ruler.hxx
+++ b/include/svtools/ruler.hxx
@@ -607,7 +607,7 @@ class ImplRulerData;
 class SVT_DLLPUBLIC Ruler : public vcl::Window
 {
 private:
-    VirtualDevice   maVirDev;
+    ScopedVclPtr<VirtualDevice>   maVirDev;
     MapMode         maMapMode;
     long            mnBorderOff;
     long            mnWinOff;
diff --git a/include/svtools/valueset.hxx b/include/svtools/valueset.hxx
index a18700c..e725754 100644
--- a/include/svtools/valueset.hxx
+++ b/include/svtools/valueset.hxx
@@ -197,7 +197,7 @@ class SVT_DLLPUBLIC ValueSet : public Control
 {
 private:
 
-    VirtualDevice   maVirDev;
+    ScopedVclPtr<VirtualDevice>   maVirDev;
     Timer           maTimer;
     ValueItemList   mItemList;
     ValueSetItemPtr mpNoneItem;
diff --git a/include/toolkit/awt/vclxgraphics.hxx b/include/toolkit/awt/vclxgraphics.hxx
index 068ed3b..47edcf7 100644
--- a/include/toolkit/awt/vclxgraphics.hxx
+++ b/include/toolkit/awt/vclxgraphics.hxx
@@ -31,6 +31,7 @@
 #include <vcl/font.hxx>
 #include <tools/color.hxx>
 #include <vcl/vclenum.hxx>
+#include <vcl/vclptr.hxx>
 
 class OutputDevice;
 namespace vcl { class Region; }
@@ -56,7 +57,7 @@ private:
     // used to return same reference on each call to getDevice()
     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice> mxDevice;
 
-    OutputDevice*   mpOutputDevice;
+    VclPtr<OutputDevice> mpOutputDevice;
     vcl::Font       maFont;
     Color           maTextColor;
     Color           maTextFillColor;
diff --git a/include/vcl/animate.hxx b/include/vcl/animate.hxx
index e966e3f..17d62a1 100644
--- a/include/vcl/animate.hxx
+++ b/include/vcl/animate.hxx
@@ -23,6 +23,7 @@
 #include <vcl/dllapi.h>
 #include <vcl/timer.hxx>
 #include <vcl/bitmapex.hxx>
+#include <vcl/vclptr.hxx>
 
 #define ANIMATION_TIMEOUT_ON_CLICK 2147483647L
 
@@ -108,17 +109,13 @@ struct AInfo
     Point           aLastSavePoint;
     Point           aStartOrg;
     Size            aStartSize;
-    OutputDevice*   pOutDev;
+    VclPtr<OutputDevice>   pOutDev;
     void*           pViewData;
     long            nExtraData;
     bool            bWithSize;
     bool            bPause;
 
-                    AInfo() : pOutDev( NULL ),
-                              pViewData( NULL ),
-                              nExtraData( 0L ),
-                              bWithSize( false ),
-                              bPause( false ) {}
+    AInfo();
 };
 
 class ImplAnimView;
diff --git a/include/vcl/decoview.hxx b/include/vcl/decoview.hxx
index 8cff366..d9c1069 100644
--- a/include/vcl/decoview.hxx
+++ b/include/vcl/decoview.hxx
@@ -21,6 +21,7 @@
 #define INCLUDED_VCL_DECOVIEW_HXX
 
 #include <vcl/dllapi.h>
+#include <vcl/vclptr.hxx>
 #include <rsc/rsc-vcl-shared-types.hxx>
 
 class Rectangle;
@@ -70,7 +71,7 @@ class OutputDevice;
 class VCL_DLLPUBLIC DecorationView
 {
 private:
-    OutputDevice*       mpOutDev;
+    VclPtr<OutputDevice>  mpOutDev;
 
 public:
                         DecorationView( OutputDevice* pOutDev )
diff --git a/include/vcl/event.hxx b/include/vcl/event.hxx
index 11102e1..2bf00eb 100644
--- a/include/vcl/event.hxx
+++ b/include/vcl/event.hxx
@@ -26,9 +26,9 @@
 #include <vcl/keycod.hxx>
 #include <vcl/cmdevt.hxx>
 #include <vcl/vclptr.hxx>
+#include <vcl/outdev.hxx>
 
 class AllSettings;
-class OutputDevice;
 namespace vcl { class Window; }
 struct IDataObject;
 
@@ -302,7 +302,7 @@ inline HelpEvent::HelpEvent( HelpEventMode nHelpMode )
 class VCL_DLLPUBLIC UserDrawEvent
 {
 private:
-    OutputDevice*       mpOutDev;
+    VclPtr<OutputDevice> mpOutDev;
     Rectangle           maOutRect;
     sal_uInt16          mnItemId;
     sal_uInt16          mnStyle;
diff --git a/include/vcl/gdimtf.hxx b/include/vcl/gdimtf.hxx
index 65bf763..75093a2 100644
--- a/include/vcl/gdimtf.hxx
+++ b/include/vcl/gdimtf.hxx
@@ -25,6 +25,7 @@
 #include <tools/link.hxx>
 #include <vcl/mapmod.hxx>
 #include <vcl/bitmap.hxx>
+#include <vcl/vclptr.hxx>
 #include <vector>
 
 class OutputDevice;
@@ -81,7 +82,7 @@ private:
     Link            aHookHdlLink;
     GDIMetaFile*    pPrev;
     GDIMetaFile*    pNext;
-    OutputDevice*   pOutDev;
+    VclPtr<OutputDevice> pOutDev;
     bool            bPause;
     bool            bRecord;
     bool            bUseCanvas;
diff --git a/include/vcl/outdev.hxx b/include/vcl/outdev.hxx
index c94b76f..c85bfbd 100644
--- a/include/vcl/outdev.hxx
+++ b/include/vcl/outdev.hxx
@@ -281,8 +281,8 @@ private:
 
 private:
     mutable SalGraphics*            mpGraphics;         ///< Graphics context to draw on
-    mutable OutputDevice*           mpPrevGraphics;     ///< Previous output device in list
-    mutable OutputDevice*           mpNextGraphics;     ///< Next output device in list
+    mutable VclPtr<OutputDevice>    mpPrevGraphics;     ///< Previous output device in list
+    mutable VclPtr<OutputDevice>    mpNextGraphics;     ///< Next output device in list
     GDIMetaFile*                    mpMetaFile;
     mutable ImplFontEntry*          mpFontEntry;
     mutable ImplFontCache*          mpFontCache;
@@ -296,7 +296,7 @@ private:
     vcl::ExtOutDevData*             mpExtOutDevData;
 
     // TEMP TEMP TEMP
-    VirtualDevice*                  mpAlphaVDev;
+    VclPtr<VirtualDevice>           mpAlphaVDev;
 
     /// Additional output pixel offset, applied in LogicToPixel (used by SetPixelOffset/GetPixelOffset)
     long                            mnOutOffOrigX;
diff --git a/include/vcl/print.hxx b/include/vcl/print.hxx
index 756cb27..5c5f980 100644
--- a/include/vcl/print.hxx
+++ b/include/vcl/print.hxx
@@ -204,9 +204,9 @@ private:
     SalInfoPrinter*             mpInfoPrinter;
     SalPrinter*                 mpPrinter;
     SalGraphics*                mpJobGraphics;
-    Printer*                    mpPrev;
-    Printer*                    mpNext;
-    VirtualDevice*              mpDisplayDev;
+    VclPtr<Printer>             mpPrev;
+    VclPtr<Printer>             mpNext;
+    VclPtr<VirtualDevice>       mpDisplayDev;
     PrinterOptions*             mpPrinterOptions;
     OUString                    maPrinterName;
     OUString                    maDriver;
@@ -299,6 +299,7 @@ public:
                                 Printer( const QueueInfo& rQueueInfo );
                                 Printer( const OUString& rPrinterName );
     virtual                     ~Printer();
+    virtual void                dispose() SAL_OVERRIDE;
 
     static const std::vector< OUString >& GetPrinterQueues();
     static const QueueInfo*     GetQueueInfo( const OUString& rPrinterName, bool bStatusUpdate );
@@ -309,7 +310,7 @@ public:
     const OUString&             GetName() const             { return maPrinterName; }
     const OUString&             GetDriverName() const       { return maDriver; }
     bool                        IsDefPrinter() const        { return mbDefPrinter; }
-    bool                        IsDisplayPrinter() const    { return mpDisplayDev != NULL; }
+    bool                        IsDisplayPrinter() const    { return mpDisplayDev != nullptr; }
     bool                        IsValid() const             { return !IsDisplayPrinter(); }
 
     sal_uLong                   GetCapabilities( sal_uInt16 nType ) const;
diff --git a/include/vcl/texteng.hxx b/include/vcl/texteng.hxx
index 6c52b91..b5f2a12 100644
--- a/include/vcl/texteng.hxx
+++ b/include/vcl/texteng.hxx
@@ -20,6 +20,7 @@
 #define INCLUDED_VCL_TEXTENG_HXX
 
 #include <vcl/dllapi.h>
+#include <vcl/vclptr.hxx>
 
 class TextDoc;
 class TextView;
@@ -91,7 +92,7 @@ class VCL_DLLPUBLIC TextEngine : public SfxBroadcaster
 private:
     TextDoc*            mpDoc;
     TEParaPortions*     mpTEParaPortions;
-    OutputDevice*       mpRefDev;
+    VclPtr<OutputDevice> mpRefDev;
 
     TextViews*          mpViews;
     TextView*           mpActiveView;
diff --git a/include/vcl/virdev.hxx b/include/vcl/virdev.hxx
index 938eca6..763c27b 100644
--- a/include/vcl/virdev.hxx
+++ b/include/vcl/virdev.hxx
@@ -35,8 +35,8 @@ class VCL_DLLPUBLIC VirtualDevice : public OutputDevice
 
 private:
     SalVirtualDevice*   mpVirDev;
-    VirtualDevice*      mpPrev;
-    VirtualDevice*      mpNext;
+    VclPtr<VirtualDevice>  mpPrev;
+    VclPtr<VirtualDevice>  mpNext;
     sal_uInt16          mnBitCount;
     bool                mbScreenComp;
     sal_Int8            mnAlphaDepth;
diff --git a/include/vcl/window.hxx b/include/vcl/window.hxx
index 143f953..bf1d0c8 100644
--- a/include/vcl/window.hxx
+++ b/include/vcl/window.hxx
@@ -403,7 +403,7 @@ private:
 
     // This is a first attempt to start to remove the dependency of Window on
     // OutputDevice
-    ::OutputDevice* mpOutputDevice;
+    VclPtr<::OutputDevice> mpOutputDevice;
 
 #ifdef DBG_UTIL
     friend const char* ::ImplDbgCheckWindow( const void* pObj );
diff --git a/svtools/source/contnr/imivctl.hxx b/svtools/source/contnr/imivctl.hxx
index 54c87e3..a137392 100644
--- a/svtools/source/contnr/imivctl.hxx
+++ b/svtools/source/contnr/imivctl.hxx
@@ -199,10 +199,10 @@ class SvxIconChoiceCtrl_Impl
     SvxIconChoiceCtrlEntry* pPrevDropTarget;
     SvxIconChoiceCtrlEntry* pHdlEntry;
     SvxIconChoiceCtrlEntry* pDDRefEntry;
-    VirtualDevice*          pDDDev;
-    VirtualDevice*          pDDBufDev;
-    VirtualDevice*          pDDTempDev;
-    VirtualDevice*          pEntryPaintDev;
+    VclPtr<VirtualDevice>   pDDDev;
+    VclPtr<VirtualDevice>   pDDBufDev;
+    VclPtr<VirtualDevice>   pDDTempDev;
+    VclPtr<VirtualDevice>   pEntryPaintDev;
     SvxIconChoiceCtrlEntry* pAnchor;                    // for selection
     LocalFocus              aFocus;                             // Data for focusrect
     ::svt::AccessibleFactoryAccess aAccFactory;
diff --git a/svtools/source/contnr/imivctl1.cxx b/svtools/source/contnr/imivctl1.cxx
index 9e1e413..b3012c1 100644
--- a/svtools/source/contnr/imivctl1.cxx
+++ b/svtools/source/contnr/imivctl1.cxx
@@ -163,10 +163,10 @@ SvxIconChoiceCtrl_Impl::~SvxIconChoiceCtrl_Impl()
     delete pZOrderList;
     delete pImpCursor;
     delete pGridMap;
-    delete pDDDev;
-    delete pDDBufDev;
-    delete pDDTempDev;
-    delete pEntryPaintDev;
+    pDDDev.disposeAndClear();
+    pDDBufDev.disposeAndClear();
+    pDDTempDev.disposeAndClear();
+    pEntryPaintDev.disposeAndClear();
     ClearSelectedRectList();
     ClearColumnList();
     aVerSBar.disposeAndClear();
@@ -265,10 +265,10 @@ IMPL_LINK_NOARG(SvxIconChoiceCtrl_Impl, EndScrollHdl)
 void SvxIconChoiceCtrl_Impl::FontModified()
 {
     StopEditTimer();
-    DELETEZ(pDDDev);
-    DELETEZ(pDDBufDev);
-    DELETEZ(pDDTempDev);
-    DELETEZ(pEntryPaintDev);
+    pDDDev.disposeAndClear();
+    pDDBufDev.disposeAndClear();
+    pDDTempDev.disposeAndClear();
+    pEntryPaintDev.disposeAndClear();
     SetDefaultTextSize();
     ShowCursor( false );
     ShowCursor( true );
diff --git a/svtools/source/control/ctrlbox.cxx b/svtools/source/control/ctrlbox.cxx
index 99acbcd..aab8330 100644
--- a/svtools/source/control/ctrlbox.cxx
+++ b/svtools/source/control/ctrlbox.cxx
@@ -670,8 +670,8 @@ void LineListBox::ImpGetLine( long nLine1, long nLine2, long nDistance,
     }
 
     // Linien malen
-    aSize = aVirDev.PixelToLogic( aSize );
-    long nPix = aVirDev.PixelToLogic( Size( 0, 1 ) ).Height();
+    aSize = aVirDev->PixelToLogic( aSize );
+    long nPix = aVirDev->PixelToLogic( Size( 0, 1 ) ).Height();
     sal_uInt32 n1 = nLine1;
     sal_uInt32 n2 = nLine2;
     long nDist  = nDistance;
@@ -690,24 +690,24 @@ void LineListBox::ImpGetLine( long nLine1, long nLine2, long nDistance,
     // negative width should not be drawn
     if ( aSize.Width() > 0 )
     {
-        Size aVirSize = aVirDev.LogicToPixel( aSize );
-        if ( aVirDev.GetOutputSizePixel() != aVirSize )
-            aVirDev.SetOutputSizePixel( aVirSize );
-        aVirDev.SetFillColor( aColorDist );
-        aVirDev.DrawRect( Rectangle( Point(), aSize ) );
+        Size aVirSize = aVirDev->LogicToPixel( aSize );
+        if ( aVirDev->GetOutputSizePixel() != aVirSize )
+            aVirDev->SetOutputSizePixel( aVirSize );
+        aVirDev->SetFillColor( aColorDist );
+        aVirDev->DrawRect( Rectangle( Point(), aSize ) );
 
-        aVirDev.SetFillColor( aColor1 );
+        aVirDev->SetFillColor( aColor1 );
 
         double y1 = double( n1 ) / 2;
-        svtools::DrawLine( aVirDev, basegfx::B2DPoint( 0, y1 ), basegfx::B2DPoint( aSize.Width( ), y1 ), n1, nStyle );
+        svtools::DrawLine( *aVirDev.get(), basegfx::B2DPoint( 0, y1 ), basegfx::B2DPoint( aSize.Width( ), y1 ), n1, nStyle );
 
         if ( n2 )
         {
             double y2 =  n1 + nDist + double( n2 ) / 2;
-            aVirDev.SetFillColor( aColor2 );
-            svtools::DrawLine( aVirDev, basegfx::B2DPoint( 0, y2 ), basegfx::B2DPoint( aSize.Width(), y2 ), n2, table::BorderLineStyle::SOLID );
+            aVirDev->SetFillColor( aColor2 );
+            svtools::DrawLine( *aVirDev.get(), basegfx::B2DPoint( 0, y2 ), basegfx::B2DPoint( aSize.Width(), y2 ), n2, table::BorderLineStyle::SOLID );
         }
-        rBmp = aVirDev.GetBitmap( Point(), Size( aSize.Width(), n1+nDist+n2 ) );
+        rBmp = aVirDev->GetBitmap( Point(), Size( aSize.Width(), n1+nDist+n2 ) );
     }
 }
 
@@ -719,8 +719,8 @@ void LineListBox::ImplInit()
     eUnit       = FUNIT_POINT;
     eSourceUnit = FUNIT_POINT;
 
-    aVirDev.SetLineColor();
-    aVirDev.SetMapMode( MapMode( MAP_TWIP ) );
+    aVirDev->SetLineColor();
+    aVirDev->SetMapMode( MapMode( MAP_TWIP ) );
 
     UpdatePaintLineColor();
 }
@@ -729,6 +729,7 @@ LineListBox::LineListBox( vcl::Window* pParent, WinBits nWinStyle ) :
     ListBox( pParent, nWinStyle ),
     m_nWidth( 5 ),
     m_sNone( ),
+    aVirDev( new VirtualDevice ),
     aColor( COL_BLACK ),
     maPaintCol( COL_BLACK )
 {
diff --git a/svtools/source/control/ctrltool.cxx b/svtools/source/control/ctrltool.cxx
index 0c6f790..a5813f3 100644
--- a/svtools/source/control/ctrltool.cxx
+++ b/svtools/source/control/ctrltool.cxx
@@ -73,7 +73,7 @@ class ImplFontListFontInfo : public vcl::FontInfo
     friend class FontList;
 
 private:
-    OutputDevice*           mpDevice;
+    VclPtr<OutputDevice>    mpDevice;
     ImplFontListFontInfo*   mpNext;
 
 public:
diff --git a/svtools/source/control/ruler.cxx b/svtools/source/control/ruler.cxx
index dc0a887..d5332bb 100644
--- a/svtools/source/control/ruler.cxx
+++ b/svtools/source/control/ruler.cxx
@@ -284,7 +284,7 @@ void Ruler::ImplInit( WinBits nWinBits )
 
 Ruler::Ruler( vcl::Window* pParent, WinBits nWinStyle ) :
     Window( pParent, nWinStyle & WB_3DLOOK ),
-    maVirDev( *this ),
+    maVirDev( new VirtualDevice(*this) ),
     maMapMode( MAP_100TH_MM ),
     mpSaveData(new ImplRulerData),
     mpData(NULL),
@@ -331,9 +331,9 @@ void Ruler::ImplVDrawLine( long nX1, long nY1, long nX2, long nY2 )
     }
 
     if ( mnWinStyle & WB_HORZ )
-        maVirDev.DrawLine( Point( nX1, nY1 ), Point( nX2, nY2 ) );
+        maVirDev->DrawLine( Point( nX1, nY1 ), Point( nX2, nY2 ) );
     else
-        maVirDev.DrawLine( Point( nY1, nX1 ), Point( nY2, nX2 ) );
+        maVirDev->DrawLine( Point( nY1, nX1 ), Point( nY2, nX2 ) );
 }
 
 void Ruler::ImplVDrawRect( long nX1, long nY1, long nX2, long nY2 )
@@ -353,15 +353,15 @@ void Ruler::ImplVDrawRect( long nX1, long nY1, long nX2, long nY2 )
     }
 
     if ( mnWinStyle & WB_HORZ )
-        maVirDev.DrawRect( Rectangle( nX1, nY1, nX2, nY2 ) );
+        maVirDev->DrawRect( Rectangle( nX1, nY1, nX2, nY2 ) );
     else
-        maVirDev.DrawRect( Rectangle( nY1, nX1, nY2, nX2 ) );
+        maVirDev->DrawRect( Rectangle( nY1, nX1, nY2, nX2 ) );
 }
 
 void Ruler::ImplVDrawText( long nX, long nY, const OUString& rText, long nMin, long nMax )
 {
     Rectangle aRect;
-    maVirDev.GetTextBoundRect( aRect, rText );
+    maVirDev->GetTextBoundRect( aRect, rText );
 
     long nShiftX = ( aRect.GetWidth() / 2 ) + aRect.Left();
     long nShiftY = ( aRect.GetHeight() / 2 ) + aRect.Top();
@@ -369,9 +369,9 @@ void Ruler::ImplVDrawText( long nX, long nY, const OUString& rText, long nMin, l
     if ( (nX > -RULER_CLIP) && (nX < mnVirWidth + RULER_CLIP) && ( nX < nMax - nShiftX ) && ( nX > nMin + nShiftX ) )
     {
         if ( mnWinStyle & WB_HORZ )
-            maVirDev.DrawText( Point( nX - nShiftX, nY - nShiftY ), rText );
+            maVirDev->DrawText( Point( nX - nShiftX, nY - nShiftY ), rText );
         else
-            maVirDev.DrawText( Point( nY - nShiftX, nX - nShiftY ), rText );
+            maVirDev->DrawText( Point( nY - nShiftX, nX - nShiftY ), rText );
     }
 }
 
@@ -460,7 +460,7 @@ void Ruler::ImplDrawTicks( long nMin, long nMax, long nStart, long nTop, long nB
 
     double nAcceptanceDelta = 0.0001;
 
-    Size aPixSize = maVirDev.LogicToPixel( Size( nTick4, nTick4 ), maMapMode );
+    Size aPixSize = maVirDev->LogicToPixel( Size( nTick4, nTick4 ), maMapMode );
 
     if ( mnUnitIndex == RULER_UNIT_CHAR )
     {
@@ -492,11 +492,11 @@ void Ruler::ImplDrawTicks( long nMin, long nMax, long nStart, long nTop, long nB
             aFont.SetOrientation( 2700 );
         else
             aFont.SetOrientation( 900 );
-        maVirDev.SetFont( aFont );
+        maVirDev->SetFont( aFont );
         nTickWidth = aPixSize.Height();
     }
 
-    long nMaxWidth = maVirDev.PixelToLogic( Size( mpData->nPageWidth, 0 ), maMapMode ).Width();
+    long nMaxWidth = maVirDev->PixelToLogic( Size( mpData->nPageWidth, 0 ), maMapMode ).Width();
     if ( nMaxWidth < 0 )
         nMaxWidth = -nMaxWidth;
 
@@ -540,7 +540,7 @@ void Ruler::ImplDrawTicks( long nMin, long nMax, long nStart, long nTop, long nB
             }
 
             nTick4 = nOrgTick4 * nMulti;
-            aPixSize = maVirDev.LogicToPixel( Size( nTick4, nTick4 ), maMapMode );
+            aPixSize = maVirDev->LogicToPixel( Size( nTick4, nTick4 ), maMapMode );
             if ( mnWinStyle & WB_HORZ )
                 nTickWidth = aPixSize.Width();
             else
@@ -550,7 +550,7 @@ void Ruler::ImplDrawTicks( long nMin, long nMax, long nStart, long nTop, long nB
     }
     else
     {
-        maVirDev.SetLineColor( GetSettings().GetStyleSettings().GetShadowColor() );
+        maVirDev->SetLineColor( GetSettings().GetStyleSettings().GetShadowColor() );
     }
 
     if ( !bNoTicks )
@@ -565,11 +565,11 @@ void Ruler::ImplDrawTicks( long nMin, long nMax, long nStart, long nTop, long nB
 
         Size nTickGapSize;
 
-        nTickGapSize = maVirDev.LogicToPixel( Size( nTickCount, nTickCount ), maMapMode );
+        nTickGapSize = maVirDev->LogicToPixel( Size( nTickCount, nTickCount ), maMapMode );
         long nTickGap1 = mnWinStyle & WB_HORZ ? nTickGapSize.Width() : nTickGapSize.Height();
-        nTickGapSize = maVirDev.LogicToPixel( Size( nTick2, nTick2 ), maMapMode );
+        nTickGapSize = maVirDev->LogicToPixel( Size( nTick2, nTick2 ), maMapMode );
         long nTickGap2 = mnWinStyle & WB_HORZ ? nTickGapSize.Width() : nTickGapSize.Height();
-        nTickGapSize = maVirDev.LogicToPixel( Size( nTick3, nTick3 ), maMapMode );
+        nTickGapSize = maVirDev->LogicToPixel( Size( nTick3, nTick3 ), maMapMode );
         long nTickGap3 = mnWinStyle & WB_HORZ ? nTickGapSize.Width() : nTickGapSize.Height();
 
         while ( ((nStart - n) >= nMin) || ((nStart + n) <= nMax) )
@@ -589,7 +589,7 @@ void Ruler::ImplDrawTicks( long nMin, long nMax, long nStart, long nTop, long nB
             }
             else
             {
-                aPixSize = maVirDev.LogicToPixel( Size( nTick, nTick ), maMapMode );
+                aPixSize = maVirDev->LogicToPixel( Size( nTick, nTick ), maMapMode );
 
                 if ( mnWinStyle & WB_HORZ )
                     n = aPixSize.Width();
@@ -685,20 +685,20 @@ void Ruler::ImplDrawBorders( long nMin, long nMax, long nVirTop, long nVirBottom
         {
             if ( (n2-n1) > 3 )
             {
-                maVirDev.SetLineColor();
-                maVirDev.SetFillColor( rStyleSettings.GetFaceColor() );
+                maVirDev->SetLineColor();
+                maVirDev->SetFillColor( rStyleSettings.GetFaceColor() );
                 ImplVDrawRect( n1, nVirTop, n2, nVirBottom );
 
-                maVirDev.SetLineColor( rStyleSettings.GetLightColor() );
+                maVirDev->SetLineColor( rStyleSettings.GetLightColor() );
                 ImplVDrawLine( n1 + 1, nVirTop, n1 + 1, nVirBottom );
                 ImplVDrawLine( n1,     nVirTop, n2,     nVirTop );
 
-                maVirDev.SetLineColor( rStyleSettings.GetShadowColor() );
+                maVirDev->SetLineColor( rStyleSettings.GetShadowColor() );
                 ImplVDrawLine( n1,     nVirTop,    n1,     nVirBottom );
                 ImplVDrawLine( n1,     nVirBottom, n2,     nVirBottom );
                 ImplVDrawLine( n2 - 1, nVirTop,    n2 - 1, nVirBottom );
 
-                maVirDev.SetLineColor( rStyleSettings.GetDarkShadowColor() );
+                maVirDev->SetLineColor( rStyleSettings.GetDarkShadowColor() );
                 ImplVDrawLine( n2, nVirTop, n2, nVirBottom );
 
                 if ( mpData->pBorders[i].nStyle & RULER_BORDER_VARIABLE )
@@ -711,7 +711,7 @@ void Ruler::ImplDrawBorders( long nMin, long nMax, long nVirTop, long nVirBottom
                         long nTemp4 = nTemp2 + RULER_VAR_SIZE - 1;
                         long nTempY = nTemp2;
 
-                        maVirDev.SetLineColor( rStyleSettings.GetLightColor() );
+                        maVirDev->SetLineColor( rStyleSettings.GetLightColor() );
                         while ( nTempY <= nTemp4 )
                         {
                             ImplVDrawLine( nTemp1, nTempY, nTemp3, nTempY );
@@ -719,7 +719,7 @@ void Ruler::ImplDrawBorders( long nMin, long nMax, long nVirTop, long nVirBottom
                         }
 
                         nTempY = nTemp2 + 1;
-                        maVirDev.SetLineColor( rStyleSettings.GetShadowColor() );
+                        maVirDev->SetLineColor( rStyleSettings.GetShadowColor() );
                         while ( nTempY <= nTemp4 )
                         {
                             ImplVDrawLine( nTemp1, nTempY, nTemp3, nTempY );
@@ -732,10 +732,10 @@ void Ruler::ImplDrawBorders( long nMin, long nMax, long nVirTop, long nVirBottom
                 {
                     if ( n2-n1 > RULER_VAR_SIZE+10 )
                     {
-                        maVirDev.SetLineColor( rStyleSettings.GetShadowColor() );
+                        maVirDev->SetLineColor( rStyleSettings.GetShadowColor() );
                         ImplVDrawLine( n1 + 4, nVirTop + 3, n1 + 4, nVirBottom - 3 );
                         ImplVDrawLine( n2 - 5, nVirTop + 3, n2 - 5, nVirBottom - 3 );
-                        maVirDev.SetLineColor( rStyleSettings.GetLightColor() );
+                        maVirDev->SetLineColor( rStyleSettings.GetLightColor() );
                         ImplVDrawLine( n1 + 5, nVirTop + 3, n1 + 5, nVirBottom - 3 );
                         ImplVDrawLine( n2 - 4, nVirTop + 3, n2 - 4, nVirBottom - 3 );
                     }
@@ -744,7 +744,7 @@ void Ruler::ImplDrawBorders( long nMin, long nMax, long nVirTop, long nVirBottom
             else
             {
                 n = n1 + ((n2 - n1) / 2);
-                maVirDev.SetLineColor( rStyleSettings.GetShadowColor() );
+                maVirDev->SetLineColor( rStyleSettings.GetShadowColor() );
 
                 if ( mpData->pBorders[i].nStyle & RULER_BORDER_SNAP )
                     ImplVDrawLine( n, nVirTop, n, nVirBottom );
@@ -754,8 +754,8 @@ void Ruler::ImplDrawBorders( long nMin, long nMax, long nVirTop, long nVirBottom
                 {
                     ImplVDrawLine( n - 1, nVirTop, n - 1, nVirBottom );
                     ImplVDrawLine( n + 1, nVirTop, n + 1, nVirBottom );
-                    maVirDev.SetLineColor();
-                    maVirDev.SetFillColor( rStyleSettings.GetWindowColor() );
+                    maVirDev->SetLineColor();
+                    maVirDev->SetFillColor( rStyleSettings.GetWindowColor() );
                     ImplVDrawRect( n, nVirTop, n, nVirBottom );
                 }
             }
@@ -770,9 +770,9 @@ void Ruler::ImplDrawIndent( const Polygon& rPoly, sal_uInt16 nStyle, bool bIsHit
     if ( nStyle & RULER_STYLE_INVISIBLE )
         return;
 
-    maVirDev.SetLineColor( rStyleSettings.GetDarkShadowColor() );
-    maVirDev.SetFillColor( bIsHit ? rStyleSettings.GetDarkShadowColor() : rStyleSettings.GetWorkspaceColor() );
-    maVirDev.DrawPolygon( rPoly );
+    maVirDev->SetLineColor( rStyleSettings.GetDarkShadowColor() );
+    maVirDev->SetFillColor( bIsHit ? rStyleSettings.GetDarkShadowColor() : rStyleSettings.GetWorkspaceColor() );
+    maVirDev->DrawPolygon( rPoly );
 }
 
 void Ruler::ImplDrawIndents( long nMin, long nMax, long nVirTop, long nVirBottom )
@@ -799,7 +799,7 @@ void Ruler::ImplDrawIndents( long nMin, long nMax, long nVirTop, long nVirBottom
             if (nIndentStyle == RULER_INDENT_BORDER)
             {
                 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
-                maVirDev.SetLineColor( rStyleSettings.GetShadowColor() );
+                maVirDev->SetLineColor( rStyleSettings.GetShadowColor() );
                 ImplVDrawLine( n, nVirTop + 1, n, nVirBottom - 1 );
             }
             else if ( nIndentStyle == RULER_INDENT_BOTTOM )
@@ -998,7 +998,7 @@ void Ruler::ImplDrawTabs( long nMin, long nMax, long nVirTop, long nVirBottom )
         aPosition += +mpData->nNullVirOff;
         long nTopBottom = (GetStyle() & WB_RIGHT_ALIGNED) ? nVirTop : nVirBottom;
         if (nMin <= aPosition && aPosition <= nMax)
-            ImplDrawTab( &maVirDev, Point( aPosition, nTopBottom ), mpData->pTabs[i].nStyle );
+            ImplDrawTab( maVirDev.get(), Point( aPosition, nTopBottom ), mpData->pTabs[i].nStyle );
     }
 }
 
@@ -1053,16 +1053,16 @@ void Ruler::ImplInitSettings( bool bFont, bool bForeground, bool bBackground )
         SetBackground( aColor );
     }
 
-    maVirDev.SetSettings( GetSettings() );
-    maVirDev.SetBackground( GetBackground() );
+    maVirDev->SetSettings( GetSettings() );
+    maVirDev->SetBackground( GetBackground() );
     vcl::Font aFont = GetFont();
 
     if ( mnWinStyle & WB_VERT )
         aFont.SetOrientation( 900 );
 
-    maVirDev.SetFont( aFont );
-    maVirDev.SetTextColor( GetTextColor() );
-    maVirDev.SetTextFillColor( GetTextFillColor() );
+    maVirDev->SetFont( aFont );
+    maVirDev->SetTextColor( GetTextColor() );
+    maVirDev->SetTextFillColor( GetTextFillColor() );
 }
 
 void Ruler::ImplCalc()
@@ -1160,10 +1160,10 @@ void Ruler::ImplFormat()
         aVirDevSize.Height() = mnVirWidth;
         aVirDevSize.Width() = mnVirHeight;
     }
-    if ( aVirDevSize != maVirDev.GetOutputSizePixel() )
-        maVirDev.SetOutputSizePixel( aVirDevSize, true );
+    if ( aVirDevSize != maVirDev->GetOutputSizePixel() )
+        maVirDev->SetOutputSizePixel( aVirDevSize, true );
     else
-        maVirDev.Erase();
+        maVirDev->Erase();
 
     // calculate margins
     if ( !(mpData->nMargin1Style & RULER_STYLE_INVISIBLE) )
@@ -1204,7 +1204,7 @@ void Ruler::ImplFormat()
     }
 
     // top/bottom border
-    maVirDev.SetLineColor( rStyleSettings.GetShadowColor() );
+    maVirDev->SetLineColor( rStyleSettings.GetShadowColor() );
     ImplVDrawLine( nVirLeft, nVirTop + 1, nM1,     nVirTop + 1 ); //top left line
     ImplVDrawLine( nM2,      nVirTop + 1, nP2 - 1, nVirTop + 1 ); //top right line
 
@@ -1212,18 +1212,18 @@ void Ruler::ImplFormat()
     nVirBottom--;
 
     // draw margin1, margin2 and in-between
-    maVirDev.SetLineColor();
-    maVirDev.SetFillColor( rStyleSettings.GetDialogColor() );
+    maVirDev->SetLineColor();
+    maVirDev->SetFillColor( rStyleSettings.GetDialogColor() );
     if ( nM1 > nVirLeft )
         ImplVDrawRect( nP1, nVirTop+1, nM1, nVirBottom ); //left gray rectangle
     if ( nM2 < nP2 )
         ImplVDrawRect( nM2, nVirTop+1, nP2, nVirBottom ); //right gray rectangle
     if ( nM2-nM1 > 0 )
     {
-        maVirDev.SetFillColor( rStyleSettings.GetWindowColor() );
+        maVirDev->SetFillColor( rStyleSettings.GetWindowColor() );
         ImplVDrawRect( nM1 + 1, nVirTop, nM2 - 1, nVirBottom ); //center rectangle
     }
-    maVirDev.SetLineColor( rStyleSettings.GetShadowColor() );
+    maVirDev->SetLineColor( rStyleSettings.GetShadowColor() );
     if ( nM1 > nVirLeft )
     {
         ImplVDrawLine( nM1, nVirTop + 1, nM1, nVirBottom ); //right line of the left rectangle
@@ -1334,7 +1334,7 @@ void Ruler::ImplDraw()
     {
         // output the ruler to the virtual device
         Point   aOffPos;
-        Size    aVirDevSize = maVirDev.GetOutputSizePixel();
+        Size    aVirDevSize = maVirDev->GetOutputSizePixel();
 
         if ( mnWinStyle & WB_HORZ )
         {
@@ -1349,7 +1349,7 @@ void Ruler::ImplDraw()
             aOffPos.X() = RULER_OFF;
             aOffPos.Y() = mnVirOff;
         }
-        DrawOutDev( aOffPos, aVirDevSize, Point(), aVirDevSize, maVirDev );
+        DrawOutDev( aOffPos, aVirDevSize, Point(), aVirDevSize, *maVirDev.get() );
 
         // redraw positionlines
         ImplInvertLines( true );
diff --git a/svtools/source/control/valueset.cxx b/svtools/source/control/valueset.cxx
index ae0941c..cb2393f9 100644
--- a/svtools/source/control/valueset.cxx
+++ b/svtools/source/control/valueset.cxx
@@ -89,14 +89,14 @@ void ValueSet::ImplInit()
     mbHasVisibleItems   = false;
 
     // #106446#, #106601# force mirroring of virtual device
-    maVirDev.EnableRTL( GetParent()->IsRTLEnabled() );
+    maVirDev->EnableRTL( GetParent()->IsRTLEnabled() );
 
     ImplInitSettings( true, true, true );
 }
 
 ValueSet::ValueSet( vcl::Window* pParent, WinBits nWinStyle, bool bDisableTransientChildren ) :
     Control( pParent, nWinStyle ),
-    maVirDev( *this ),
+    maVirDev( new VirtualDevice(*this) ),
     maColor( COL_TRANSPARENT )
 {
     ImplInit();
@@ -116,7 +116,7 @@ extern "C" SAL_DLLPUBLIC_EXPORT vcl::Window* SAL_CALL makeValueSet(vcl::Window *
 
 ValueSet::ValueSet( vcl::Window* pParent, const ResId& rResId, bool bDisableTransientChildren ) :
     Control( pParent, rResId ),
-    maVirDev( *this ),
+    maVirDev( new VirtualDevice(*this) ),
     maColor( COL_TRANSPARENT )
 {
     ImplInit();
@@ -239,7 +239,7 @@ void ValueSet::ImplFormatItem( ValueSetItem* pItem, Rectangle aRect )
         }
         else
         {
-            DecorationView aView( &maVirDev );
+            DecorationView aView( maVirDev.get() );
             aRect = aView.DrawFrame( aRect, mnFrameStyle );
         }
     }
@@ -253,11 +253,11 @@ void ValueSet::ImplFormatItem( ValueSetItem* pItem, Rectangle aRect )
 
         if ( pItem == mpNoneItem.get() )
         {
-            maVirDev.SetFont( GetFont() );
-            maVirDev.SetTextColor( ( nStyle & WB_MENUSTYLEVALUESET ) ? rStyleSettings.GetMenuTextColor() : rStyleSettings.GetWindowTextColor() );
-            maVirDev.SetTextFillColor();
-            maVirDev.SetFillColor( ( nStyle & WB_MENUSTYLEVALUESET ) ? rStyleSettings.GetMenuColor() : rStyleSettings.GetWindowColor() );
-            maVirDev.DrawRect( aRect );
+            maVirDev->SetFont( GetFont() );
+            maVirDev->SetTextColor( ( nStyle & WB_MENUSTYLEVALUESET ) ? rStyleSettings.GetMenuTextColor() : rStyleSettings.GetWindowTextColor() );
+            maVirDev->SetTextFillColor();
+            maVirDev->SetFillColor( ( nStyle & WB_MENUSTYLEVALUESET ) ? rStyleSettings.GetMenuColor() : rStyleSettings.GetWindowColor() );
+            maVirDev->DrawRect( aRect );
             Point   aTxtPos( aRect.Left() + 2, aRect.Top() );
             long    nTxtWidth = GetTextWidth( pItem->maText );
             if ( nStyle & WB_RADIOSEL )
@@ -267,33 +267,33 @@ void ValueSet::ImplFormatItem( ValueSetItem* pItem, Rectangle aRect )
             }
             if ( (aTxtPos.X()+nTxtWidth) > aRect.Right() )
             {
-                maVirDev.SetClipRegion( vcl::Region( aRect ) );
-                maVirDev.DrawText( aTxtPos, pItem->maText );
-                maVirDev.SetClipRegion();
+                maVirDev->SetClipRegion( vcl::Region( aRect ) );
+                maVirDev->DrawText( aTxtPos, pItem->maText );
+                maVirDev->SetClipRegion();
             }
             else
-                maVirDev.DrawText( aTxtPos, pItem->maText );
+                maVirDev->DrawText( aTxtPos, pItem->maText );
         }
         else if ( pItem->meType == VALUESETITEM_COLOR )
         {
-            maVirDev.SetFillColor( pItem->maColor );
-            maVirDev.DrawRect( aRect );
+            maVirDev->SetFillColor( pItem->maColor );
+            maVirDev->DrawRect( aRect );
         }
         else
         {
             if ( IsColor() )
-                maVirDev.SetFillColor( maColor );
+                maVirDev->SetFillColor( maColor );
             else if ( nStyle & WB_MENUSTYLEVALUESET )
-                maVirDev.SetFillColor( rStyleSettings.GetMenuColor() );
+                maVirDev->SetFillColor( rStyleSettings.GetMenuColor() );
             else if ( IsEnabled() )
-                maVirDev.SetFillColor( rStyleSettings.GetWindowColor() );
+                maVirDev->SetFillColor( rStyleSettings.GetWindowColor() );
             else
-                maVirDev.SetFillColor( rStyleSettings.GetFaceColor() );
-            maVirDev.DrawRect( aRect );
+                maVirDev->SetFillColor( rStyleSettings.GetFaceColor() );
+            maVirDev->DrawRect( aRect );
 
             if ( pItem->meType == VALUESETITEM_USERDRAW )
             {
-                UserDrawEvent aUDEvt( &maVirDev, aRect, pItem->mnId );
+                UserDrawEvent aUDEvt( maVirDev.get(), aRect, pItem->mnId );
                 UserDraw( aUDEvt );
             }
             else
@@ -311,12 +311,12 @@ void ValueSet::ImplFormatItem( ValueSetItem* pItem, Rectangle aRect )
                 if ( aImageSize.Width()  > aRectSize.Width() ||
                      aImageSize.Height() > aRectSize.Height() )
                 {
-                    maVirDev.SetClipRegion( vcl::Region( aRect ) );
-                    maVirDev.DrawImage( aPos, pItem->maImage, nImageStyle);
-                    maVirDev.SetClipRegion();
+                    maVirDev->SetClipRegion( vcl::Region( aRect ) );
+                    maVirDev->DrawImage( aPos, pItem->maImage, nImageStyle);
+                    maVirDev->SetClipRegion();
                 }
                 else
-                    maVirDev.DrawImage( aPos, pItem->maImage, nImageStyle );
+                    maVirDev->DrawImage( aPos, pItem->maImage, nImageStyle );
             }
         }
 
@@ -331,7 +331,7 @@ void ValueSet::ImplFormatItem( ValueSetItem* pItem, Rectangle aRect )
 
             if(!aBlendFrame.IsEmpty())
             {
-                maVirDev.DrawBitmapEx(aRect.TopLeft(), aBlendFrame);
+                maVirDev->DrawBitmapEx(aRect.TopLeft(), aBlendFrame);
             }
         }
     }
@@ -494,9 +494,9 @@ void ValueSet::Format()
     }
 
     // Init VirDev
-    maVirDev.SetSettings( GetSettings() );
-    maVirDev.SetBackground( GetBackground() );
-    maVirDev.SetOutputSizePixel( aWinSize, true );
+    maVirDev->SetSettings( GetSettings() );
+    maVirDev->SetBackground( GetBackground() );
+    maVirDev->SetOutputSizePixel( aWinSize, true );
 
     // nothing is changed in case of too small items
     if ( (mnItemWidth <= 0) ||
@@ -569,7 +569,7 @@ void ValueSet::Format()
         }
 
         // calculate and draw items
-        maVirDev.SetLineColor();
+        maVirDev->SetLineColor();
         long x = nStartX;
         long y = nStartY;
 
@@ -909,7 +909,7 @@ void ValueSet::ImplHideSelect( sal_uInt16 nItemId )
     HideFocus();
     const Point aPos  = aRect.TopLeft();
     const Size  aSize = aRect.GetSize();
-    DrawOutDev( aPos, aSize, aPos, aSize, maVirDev );
+    DrawOutDev( aPos, aSize, aPos, aSize, *maVirDev.get() );
 }
 
 void ValueSet::ImplHighlightItem( sal_uInt16 nItemId, bool bIsSelection )
@@ -939,7 +939,7 @@ void ValueSet::ImplDraw()
     HideFocus();
 
     Point   aDefPos;
-    Size    aSize = maVirDev.GetOutputSizePixel();
+    Size    aSize = maVirDev->GetOutputSizePixel();
 
     if ( mpScrollBar.get() && mpScrollBar->IsVisible() )
     {
@@ -948,17 +948,17 @@ void ValueSet::ImplDraw()
         Point   aTempPos( 0, aScrPos.Y() );
         Size    aTempSize( aSize.Width(), aScrPos.Y() );
 
-        DrawOutDev( aDefPos, aTempSize, aDefPos, aTempSize, maVirDev );
+        DrawOutDev( aDefPos, aTempSize, aDefPos, aTempSize, *maVirDev.get() );
         aTempSize.Width()   = aScrPos.X() - 1;
         aTempSize.Height()  = aScrSize.Height();
-        DrawOutDev( aTempPos, aTempSize, aTempPos, aTempSize, maVirDev );
+        DrawOutDev( aTempPos, aTempSize, aTempPos, aTempSize, *maVirDev.get() );
         aTempPos.Y()        = aScrPos.Y() + aScrSize.Height();
         aTempSize.Width()   = aSize.Width();
         aTempSize.Height()  = aSize.Height() - aTempPos.Y();
-        DrawOutDev( aTempPos, aTempSize, aTempPos, aTempSize, maVirDev );
+        DrawOutDev( aTempPos, aTempSize, aTempPos, aTempSize, *maVirDev.get() );
     }
     else
-        DrawOutDev( aDefPos, aSize, aDefPos, aSize, maVirDev );
+        DrawOutDev( aDefPos, aSize, aDefPos, aSize, *maVirDev.get() );
 
     // draw parting line to the Namefield
     if ( GetStyle() & WB_NAMEFIELD )
@@ -1424,7 +1424,7 @@ void ValueSet::Paint( const Rectangle& )
         const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
         SetLineColor();
         SetFillColor( rStyleSettings.GetFaceColor() );
-        long nOffY = maVirDev.GetOutputSizePixel().Height();
+        long nOffY = maVirDev->GetOutputSizePixel().Height();
         Size aWinSize = GetOutputSizePixel();
         DrawRect( Rectangle( Point( 0, nOffY ), Point( aWinSize.Width(), aWinSize.Height() ) ) );
     }
diff --git a/svtools/source/dialogs/prnsetup.cxx b/svtools/source/dialogs/prnsetup.cxx
index c80e3c6..72da5fd 100644
--- a/svtools/source/dialogs/prnsetup.cxx
+++ b/svtools/source/dialogs/prnsetup.cxx
@@ -73,7 +73,7 @@ Printer* ImplPrnDlgListBoxSelect( ListBox* pBox, PushButton* pPropBtn,
                 if ( (pTempPrinter->GetName() != pInfo->GetPrinterName()) ||
                      (pTempPrinter->GetDriverName() != pInfo->GetDriver()) )
                 {
-                    delete pTempPrinter;
+                    VclPtr<Printer>(pTempPrinter).disposeAndClear();
                     pTempPrinter = new Printer( *pInfo );
                 }
             }
@@ -101,8 +101,7 @@ Printer* ImplPrnDlgUpdatePrinter( Printer* pPrinter, Printer* pTempPrinter )
 
     if ( ! Printer::GetQueueInfo( aPrnName, false ) )
     {
-        if ( pTempPrinter )
-            delete pTempPrinter;
+        VclPtr<Printer>(pTempPrinter).disposeAndClear();
         pTempPrinter = new Printer;
     }
 
@@ -251,8 +250,8 @@ PrinterSetupDialog::~PrinterSetupDialog()
 void PrinterSetupDialog::dispose()
 {
     ImplFreePrnDlgListBox(m_pLbName, false);
-    delete mpTempPrinter;
-    mpTempPrinter = NULL;
+    mpTempPrinter.disposeAndClear();
+    mpPrinter.disposeAndClear();
     m_pLbName.disposeAndClear();
     m_pBtnProperties.disposeAndClear();
     m_pBtnOptions.disposeAndClear();
diff --git a/svtools/source/graphic/grfmgr2.cxx b/svtools/source/graphic/grfmgr2.cxx
index f469623..e31bbe7 100644
--- a/svtools/source/graphic/grfmgr2.cxx
+++ b/svtools/source/graphic/grfmgr2.cxx
@@ -1900,19 +1900,19 @@ bool GraphicObject::ImplDrawTiled( OutputDevice* pOut, const Rectangle& rArea, c
         // First combine very small bitmaps into a larger tile
 
 
-        VirtualDevice   aVDev;
+        ScopedVclPtr<VirtualDevice>   aVDev = new VirtualDevice;
         const int       nNumTilesInCacheX( (nTileCacheSize1D + rSizePixel.Width()-1) / rSizePixel.Width() );
         const int       nNumTilesInCacheY( (nTileCacheSize1D + rSizePixel.Height()-1) / rSizePixel.Height() );
 
-        aVDev.SetOutputSizePixel( Size( nNumTilesInCacheX*rSizePixel.Width(),
+        aVDev->SetOutputSizePixel( Size( nNumTilesInCacheX*rSizePixel.Width(),
                                         nNumTilesInCacheY*rSizePixel.Height() ) );
-        aVDev.SetMapMode( aMapMode );
+        aVDev->SetMapMode( aMapMode );
 
         // draw bitmap content
-        if( ImplRenderTempTile( aVDev, SubdivisionExponent, nNumTilesInCacheX,
+        if( ImplRenderTempTile( *aVDev.get(), SubdivisionExponent, nNumTilesInCacheX,
                                 nNumTilesInCacheY, rSizePixel, pAttr, nFlags ) )
         {
-            BitmapEx aTileBitmap( aVDev.GetBitmap( Point(0,0), aVDev.GetOutputSize() ) );
+            BitmapEx aTileBitmap( aVDev->GetBitmap( Point(0,0), aVDev->GetOutputSize() ) );
 
             // draw alpha content, if any
             if( IsTransparent() )
@@ -1924,16 +1924,16 @@ bool GraphicObject::ImplDrawTiled( OutputDevice* pOut, const Rectangle& rArea, c
                 else
                     aAlphaGraphic.SetGraphic( GetGraphic().GetBitmapEx().GetMask() );
 
-                if( aAlphaGraphic.ImplRenderTempTile( aVDev, SubdivisionExponent, nNumTilesInCacheX,
+                if( aAlphaGraphic.ImplRenderTempTile( *aVDev.get(), SubdivisionExponent, nNumTilesInCacheX,
                                                       nNumTilesInCacheY, rSizePixel, pAttr, nFlags ) )
                 {
                     // Combine bitmap and alpha/mask
                     if( GetGraphic().IsAlpha() )
                         aTileBitmap = BitmapEx( aTileBitmap.GetBitmap(),
-                                                AlphaMask( aVDev.GetBitmap( Point(0,0), aVDev.GetOutputSize() ) ) );
+                                                AlphaMask( aVDev->GetBitmap( Point(0,0), aVDev->GetOutputSize() ) ) );
                     else
                         aTileBitmap = BitmapEx( aTileBitmap.GetBitmap(),
-                                                aVDev.GetBitmap( Point(0,0), aVDev.GetOutputSize() ).CreateMask( Color(COL_WHITE) ) );
+                                                aVDev->GetBitmap( Point(0,0), aVDev->GetOutputSize() ).CreateMask( Color(COL_WHITE) ) );
                 }
             }
 
diff --git a/svtools/source/graphic/provider.cxx b/svtools/source/graphic/provider.cxx
index f5a4292..360974b 100644
--- a/svtools/source/graphic/provider.cxx
+++ b/svtools/source/graphic/provider.cxx
@@ -634,7 +634,7 @@ void ImplApplyFilterData( ::Graphic& rGraphic, uno::Sequence< beans::PropertyVal
     }
     else if ( ( rGraphic.GetType() == GRAPHIC_GDIMETAFILE ) && nImageResolution )
     {
-        VirtualDevice aDummyVDev;
+        ScopedVclPtr<VirtualDevice> aDummyVDev = new VirtualDevice;
         GDIMetaFile aMtf( rGraphic.GetGDIMetaFile() );
         Size aMtfSize( OutputDevice::LogicToLogic( aMtf.GetPrefSize(), aMtf.GetPrefMapMode(), MAP_100TH_MM ) );
         if ( aMtfSize.Width() && aMtfSize.Height() )
@@ -642,8 +642,8 @@ void ImplApplyFilterData( ::Graphic& rGraphic, uno::Sequence< beans::PropertyVal
             MapMode aNewMapMode( MAP_100TH_MM );
             aNewMapMode.SetScaleX( static_cast< double >( aLogicalSize.Width ) / static_cast< double >( aMtfSize.Width() ) );
             aNewMapMode.SetScaleY( static_cast< double >( aLogicalSize.Height ) / static_cast< double >( aMtfSize.Height() ) );
-            aDummyVDev.EnableOutput( false );
-            aDummyVDev.SetMapMode( aNewMapMode );
+            aDummyVDev->EnableOutput( false );
+            aDummyVDev->SetMapMode( aNewMapMode );
 
             for( size_t i = 0, nObjCount = aMtf.GetActionSize(); i < nObjCount; i++ )
             {
@@ -653,18 +653,18 @@ void ImplApplyFilterData( ::Graphic& rGraphic, uno::Sequence< beans::PropertyVal
                     // only optimizing common bitmap actions:
                     case( META_MAPMODE_ACTION ):
                     {
-                        const_cast< MetaAction* >( pAction )->Execute( &aDummyVDev );
+                        const_cast< MetaAction* >( pAction )->Execute( aDummyVDev.get() );
                         break;
                     }
                     case( META_PUSH_ACTION ):
                     {
                         const MetaPushAction* pA = static_cast<const MetaPushAction*>(pAction);
-                        aDummyVDev.Push( pA->GetFlags() );
+                        aDummyVDev->Push( pA->GetFlags() );
                         break;
                     }
                     case( META_POP_ACTION ):
                     {
-                        aDummyVDev.Pop();
+                        aDummyVDev->Pop();
                         break;
                     }
                     case( META_BMPSCALE_ACTION ):
@@ -688,8 +688,8 @@ void ImplApplyFilterData( ::Graphic& rGraphic, uno::Sequence< beans::PropertyVal
                             aSize = pScaleAction->GetSize();
                         }
                         ::Graphic aGraphic( aBmpEx );
-                        const Size aSize100thmm( aDummyVDev.LogicToPixel( aSize ) );
-                        Size aSize100thmm2( aDummyVDev.PixelToLogic( aSize100thmm, MAP_100TH_MM ) );
+                        const Size aSize100thmm( aDummyVDev->LogicToPixel( aSize ) );
+                        Size aSize100thmm2( aDummyVDev->PixelToLogic( aSize100thmm, MAP_100TH_MM ) );
 
                         ImplApplyBitmapResolution( aGraphic, nImageResolution,
                             aGraphic.GetSizePixel(), awt::Size( aSize100thmm2.Width(), aSize100thmm2.Height() ) );
diff --git a/svtools/source/inc/renderer.hxx b/svtools/source/inc/renderer.hxx
index b50088d..ca3417b 100644
--- a/svtools/source/inc/renderer.hxx
+++ b/svtools/source/inc/renderer.hxx
@@ -70,7 +70,7 @@ private:
 
     ::com::sun::star::uno::Reference< ::com::sun::star::awt::XDevice > mxDevice;
 
-    OutputDevice*               mpOutDev;
+    VclPtr<OutputDevice>        mpOutDev;
     Rectangle                   maDestRect;
     ::com::sun::star::uno::Any  maRenderData;
 };
diff --git a/svtools/source/misc/sampletext.cxx b/svtools/source/misc/sampletext.cxx
index 40f5d7d..a1cb7a8 100644
--- a/svtools/source/misc/sampletext.cxx
+++ b/svtools/source/misc/sampletext.cxx
@@ -1623,12 +1623,12 @@ OUString makeRepresentativeTextForFont(sal_Int16 nScriptType, const vcl::Font &r
 {
     OUString sRet(makeRepresentativeTextForLanguage(rFont.GetLanguage()));
 
-    VirtualDevice aDevice;
-    if (sRet.isEmpty() || (-1 != aDevice.HasGlyphs(rFont, sRet)))
+    ScopedVclPtr<VirtualDevice> aDevice = new VirtualDevice;
+    if (sRet.isEmpty() || (-1 != aDevice->HasGlyphs(rFont, sRet)))
     {
-        aDevice.SetFont(rFont);
+        aDevice->SetFont(rFont);
         vcl::FontCapabilities aFontCapabilities;
-        if (aDevice.GetFontCapabilities(aFontCapabilities))
+        if (aDevice->GetFontCapabilities(aFontCapabilities))
         {
 #if OSL_DEBUG_LEVEL > 2
             lcl_dump_unicode_coverage(aFontCapabilities.maUnicodeRange);
@@ -1655,7 +1655,7 @@ OUString makeRepresentativeTextForFont(sal_Int16 nScriptType, const vcl::Font &r
             UScriptCode eScript = getScript(aFontCapabilities);
 
             if (nScriptType == com::sun::star::i18n::ScriptType::ASIAN)
-                eScript = attemptToDisambiguateHan(eScript, aDevice);
+                eScript = attemptToDisambiguateHan(eScript, *aDevice.get());
 
             sRet = makeRepresentativeTextForScript(eScript);
         }
@@ -1665,10 +1665,10 @@ OUString makeRepresentativeTextForFont(sal_Int16 nScriptType, const vcl::Font &r
             if (nScriptType == com::sun::star::i18n::ScriptType::COMPLEX)
             {
                 sRet = makeRepresentativeTextForScript(USCRIPT_HEBREW);
-                if (-1 != aDevice.HasGlyphs(rFont, sRet))
+                if (-1 != aDevice->HasGlyphs(rFont, sRet))
                 {
                     sRet = makeMinimalTextForScript(USCRIPT_HEBREW);
-                    if (-1 != aDevice.HasGlyphs(rFont, sRet))
+                    if (-1 != aDevice->HasGlyphs(rFont, sRet))
                         sRet = makeRepresentativeTextForScript(USCRIPT_ARABIC);
                 }
             }
diff --git a/svtools/source/table/gridtablerenderer.cxx b/svtools/source/table/gridtablerenderer.cxx
index e350a22..4f4ad26 100644
--- a/svtools/source/table/gridtablerenderer.cxx
+++ b/svtools/source/table/gridtablerenderer.cxx
@@ -86,17 +86,17 @@ namespace svt { namespace table
 
             Point const aBitmapPos( 0, 0 );
             Size const aBitmapSize( nSortIndicatorWidth, nSortIndicatorHeight );
-            VirtualDevice aDevice( i_device, 0, 0 );
-            aDevice.SetOutputSizePixel( aBitmapSize );
+            ScopedVclPtr<VirtualDevice> aDevice = new VirtualDevice( i_device, 0, 0 );
+            aDevice->SetOutputSizePixel( aBitmapSize );
 
-            DecorationView aDecoView( &aDevice );
+            DecorationView aDecoView( aDevice.get() );
             aDecoView.DrawSymbol(
                 Rectangle( aBitmapPos, aBitmapSize ),
                 i_sortAscending ? SymbolType::SPIN_UP : SymbolType::SPIN_DOWN,
                 i_style.GetActiveColor()
             );
 
-            rBitmap = aDevice.GetBitmapEx( aBitmapPos, aBitmapSize );
+            rBitmap = aDevice->GetBitmapEx( aBitmapPos, aBitmapSize );
             m_lastHeaderHeight = i_headerHeight;
             m_lastArrowColor = i_style.GetActiveColor();
         }
diff --git a/svtools/source/toolpanel/paneltabbar.cxx b/svtools/source/toolpanel/paneltabbar.cxx
index 29cb51d..8c29c17 100644
--- a/svtools/source/toolpanel/paneltabbar.cxx
+++ b/svtools/source/toolpanel/paneltabbar.cxx
@@ -415,7 +415,7 @@ namespace svt
         TabAlignment                m_eTabAlignment;
         IToolPanelDeck&             m_rPanelDeck;
 
-        VirtualDevice               m_aRenderDevice;
+        ScopedVclPtr<VirtualDevice> m_aRenderDevice;
         PTabBarRenderer             m_pRenderer;
 
         ::boost::optional< size_t > m_aHoveredItem;
@@ -499,7 +499,7 @@ namespace svt
         ,m_aNormalizer()
         ,m_eTabAlignment( i_eAlignment )
         ,m_rPanelDeck( i_rPanelDeck )
-        ,m_aRenderDevice( i_rTabBar )
+        ,m_aRenderDevice( new VirtualDevice(i_rTabBar) )
         ,m_pRenderer()
         ,m_aHoveredItem()
         ,m_aFocusedItem()
@@ -511,19 +511,19 @@ namespace svt
         ,m_nScrollPosition( 0 )
     {
 #ifdef WNT
-        if ( m_aRenderDevice.IsNativeControlSupported( CTRL_TAB_ITEM, PART_ENTIRE_CONTROL ) )
+        if ( m_aRenderDevice->IsNativeControlSupported( CTRL_TAB_ITEM, PART_ENTIRE_CONTROL ) )
             // this mode requires the NWF framework to be able to render those items onto a virtual
             // device. For some frameworks (some GTK themes, in particular), this is known to fail.
             // So, be on the safe side for the moment.
             m_pRenderer.reset( new NWFTabItemRenderer( m_aRenderDevice ) );
         else
 #endif
-        if ( m_aRenderDevice.IsNativeControlSupported( CTRL_TOOLBAR, PART_BUTTON ) )
-            m_pRenderer.reset( new NWFToolboxItemRenderer( m_aRenderDevice ) );
+        if ( m_aRenderDevice->IsNativeControlSupported( CTRL_TOOLBAR, PART_BUTTON ) )
+            m_pRenderer.reset( new NWFToolboxItemRenderer( *m_aRenderDevice.get() ) );
         else
-            m_pRenderer.reset( new VCLItemRenderer( m_aRenderDevice ) );
+            m_pRenderer.reset( new VCLItemRenderer( *m_aRenderDevice.get() ) );
 
-        m_aRenderDevice.SetLineColor();
+        m_aRenderDevice->SetLineColor();
 
         m_rPanelDeck.AddListener( *this );
 
@@ -710,7 +710,7 @@ namespace svt
 
     void PanelTabBar_Impl::CopyFromRenderDevice( const Rectangle& i_rLogicalRect ) const
     {
-        BitmapEx aBitmap( m_aRenderDevice.GetBitmapEx(
+        BitmapEx aBitmap( m_aRenderDevice->GetBitmapEx(
             i_rLogicalRect.TopLeft(),
             Size(
                 i_rLogicalRect.GetSize().Width(),
@@ -833,7 +833,7 @@ namespace svt
         const Size aLogicalOutputSize( m_aNormalizer.getReferenceSize() );
 
         // forward actual output size to our render device
-        m_aRenderDevice.SetOutputSizePixel( aLogicalOutputSize );
+        m_aRenderDevice->SetOutputSizePixel( aLogicalOutputSize );
 
         // re-calculate the size of the scroll buttons and of the items
         m_aGeometry.relayout( aLogicalOutputSize, m_aItems );
@@ -1050,10 +1050,10 @@ namespace svt
 
         // background
         const Rectangle aNormalizedPaintArea( m_pImpl->m_aNormalizer.getNormalized( i_rRect, m_pImpl->m_eTabAlignment ) );
-        m_pImpl->m_aRenderDevice.Push( PushFlags::CLIPREGION );
-        m_pImpl->m_aRenderDevice.SetClipRegion(vcl::Region(aNormalizedPaintArea));
+        m_pImpl->m_aRenderDevice->Push( PushFlags::CLIPREGION );
+        m_pImpl->m_aRenderDevice->SetClipRegion(vcl::Region(aNormalizedPaintArea));
         m_pImpl->m_pRenderer->renderBackground();
-        m_pImpl->m_aRenderDevice.Pop();
+        m_pImpl->m_aRenderDevice->Pop();
         m_pImpl->CopyFromRenderDevice( aNormalizedPaintArea );
 
         // ensure the items really paint into their own playground only
diff --git a/svtools/source/toolpanel/toolpaneldrawer.hxx b/svtools/source/toolpanel/toolpaneldrawer.hxx
index 1f66263..b13a12e 100644
--- a/svtools/source/toolpanel/toolpaneldrawer.hxx
+++ b/svtools/source/toolpanel/toolpaneldrawer.hxx
@@ -97,7 +97,7 @@ namespace svt
         using Window::Paint;
 
     private:
-        ::std::unique_ptr< VirtualDevice >  m_pPaintDevice;
+        ScopedVclPtr< VirtualDevice >       m_pPaintDevice;
         VclPtr<DrawerVisualization>         m_aVisualization;
         bool                                m_bFocused;
         bool                                m_bExpanded;
diff --git a/vcl/inc/brdwin.hxx b/vcl/inc/brdwin.hxx
index 0d4b12e..f2f2891 100644
--- a/vcl/inc/brdwin.hxx
+++ b/vcl/inc/brdwin.hxx
@@ -176,7 +176,7 @@ public:
 struct ImplBorderFrameData
 {
     VclPtr<ImplBorderWindow> mpBorderWindow;
-    OutputDevice*           mpOutDev;
+    VclPtr<OutputDevice>     mpOutDev;
     Rectangle               maTitleRect;
     Rectangle               maPinRect;
     Rectangle               maCloseRect;
@@ -255,7 +255,7 @@ public:
 class ImplSmallBorderWindowView : public ImplBorderWindowView
 {
     VclPtr<ImplBorderWindow> mpBorderWindow;
-    OutputDevice*           mpOutDev;
+    VclPtr<OutputDevice>     mpOutDev;
     long                    mnWidth;
     long                    mnHeight;
     sal_Int32               mnLeftBorder;
@@ -277,8 +277,8 @@ public:
 class ImplStdBorderWindowView : public ImplBorderWindowView
 {
     ImplBorderFrameData     maFrameData;
-    VirtualDevice*          mpATitleVirDev;
-    VirtualDevice*          mpDTitleVirDev;
+    VclPtr<VirtualDevice>   mpATitleVirDev;
+    VclPtr<VirtualDevice>   mpDTitleVirDev;
 
 public:
                             ImplStdBorderWindowView( ImplBorderWindow* pBorderWindow );
diff --git a/vcl/inc/controldata.hxx b/vcl/inc/controldata.hxx
index 2072091..0ef77c8 100644
--- a/vcl/inc/controldata.hxx
+++ b/vcl/inc/controldata.hxx
@@ -30,7 +30,7 @@ namespace vcl
     struct ImplControlData
     {
         mutable ControlLayoutData*  mpLayoutData;
-        OutputDevice*               mpReferenceDevice;
+        VclPtr<OutputDevice>        mpReferenceDevice;
 
         ImplControlData()
             :mpLayoutData( NULL )
diff --git a/vcl/inc/outdev.h b/vcl/inc/outdev.h
index c878d8b2..f34c186 100644
--- a/vcl/inc/outdev.h
+++ b/vcl/inc/outdev.h
@@ -25,6 +25,7 @@
 #include <vector>
 
 #include <tools/gen.hxx>
+#include <vcl/vclptr.hxx>
 
 #include "outfont.hxx"
 #include "PhysicalFontFace.hxx"
@@ -162,7 +163,7 @@ namespace basegfx { class B2DHomMatrix; }
 
 struct ImplOutDevData
 {
-    VirtualDevice*              mpRotateDev;
+    VclPtr<VirtualDevice>       mpRotateDev;
     vcl::ControlLayoutData*     mpRecordLayout;
     Rectangle                   maRecordRect;
 
diff --git a/vcl/inc/printdlg.hxx b/vcl/inc/printdlg.hxx
index baf2225..691356a 100644
--- a/vcl/inc/printdlg.hxx
+++ b/vcl/inc/printdlg.hxx
@@ -51,7 +51,7 @@ namespace vcl
             GDIMetaFile         maMtf;
             Size                maOrigSize;
             Size                maPreviewSize;
-            VirtualDevice       maPageVDev;
+            VclPtr<VirtualDevice> maPageVDev;
             Bitmap              maPreviewBitmap;
             OUString            maReplacementString;
             OUString            maToolTipString;
diff --git a/vcl/inc/svdata.hxx b/vcl/inc/svdata.hxx
index 60a2479..a8bbd58 100644
--- a/vcl/inc/svdata.hxx
+++ b/vcl/inc/svdata.hxx
@@ -152,18 +152,18 @@ struct ImplSVAppData
 
 struct ImplSVGDIData
 {
-    OutputDevice*           mpFirstWinGraphics;             // First OutputDevice with a Frame Graphics
-    OutputDevice*           mpLastWinGraphics;              // Last OutputDevice with a Frame Graphics
-    OutputDevice*           mpFirstVirGraphics;             // First OutputDevice with a VirtualDevice Graphics
-    OutputDevice*           mpLastVirGraphics;              // Last OutputDevice with a VirtualDevice Graphics
-    OutputDevice*           mpFirstPrnGraphics;             // First OutputDevice with a InfoPrinter Graphics
-    OutputDevice*           mpLastPrnGraphics;              // Last OutputDevice with a InfoPrinter Graphics
-    VirtualDevice*          mpFirstVirDev;                  // First VirtualDevice
-    VirtualDevice*          mpLastVirDev;                   // Last VirtualDevice
+    VclPtr<OutputDevice>    mpFirstWinGraphics;             // First OutputDevice with a Frame Graphics
+    VclPtr<OutputDevice>    mpLastWinGraphics;              // Last OutputDevice with a Frame Graphics
+    VclPtr<OutputDevice>    mpFirstVirGraphics;             // First OutputDevice with a VirtualDevice Graphics
+    VclPtr<OutputDevice>    mpLastVirGraphics;              // Last OutputDevice with a VirtualDevice Graphics
+    VclPtr<OutputDevice>    mpFirstPrnGraphics;             // First OutputDevice with a InfoPrinter Graphics
+    VclPtr<OutputDevice>    mpLastPrnGraphics;              // Last OutputDevice with a InfoPrinter Graphics
+    VclPtr<VirtualDevice>   mpFirstVirDev;                  // First VirtualDevice
+    VclPtr<VirtualDevice>   mpLastVirDev;                   // Last VirtualDevice
     OpenGLContext*          mpFirstContext;                 // First OpenGLContext
     OpenGLContext*          mpLastContext;                  // Last OpenGLContext
-    Printer*                mpFirstPrinter;                 // First Printer
-    Printer*                mpLastPrinter;                  // Last Printer
+    VclPtr<Printer>         mpFirstPrinter;                 // First Printer
+    VclPtr<Printer>         mpLastPrinter;                  // Last Printer
     ImplPrnQueueList*       mpPrinterQueueList;             // List of all printer queue
     PhysicalFontCollection* mpScreenFontList;               // Screen-Font-List
     ImplFontCache*          mpScreenFontCache;              // Screen-Font-Cache
diff --git a/vcl/inc/window.h b/vcl/inc/window.h
index 892198a..5bf3f93 100644
--- a/vcl/inc/window.h
+++ b/vcl/inc/window.h
@@ -121,7 +121,7 @@ struct ImplWinData
 
 struct ImplOverlapData
 {
-    VirtualDevice*      mpSaveBackDev;          //< saved background bitmap
+    VclPtr<VirtualDevice> mpSaveBackDev;          //< saved background bitmap
     vcl::Region*        mpSaveBackRgn;          //< saved region, which must be invalidated
     VclPtr<vcl::Window> mpNextBackWin;          //< next window with saved background
     sal_uIntPtr         mnSaveBackSize;         //< bitmap size of saved background
diff --git a/vcl/source/app/svdata.cxx b/vcl/source/app/svdata.cxx
index 45065ab..4459fad 100644
--- a/vcl/source/app/svdata.cxx
+++ b/vcl/source/app/svdata.cxx
@@ -37,6 +37,8 @@
 #include "vcl/layout.hxx"
 #include "vcl/button.hxx"
 #include "vcl/dockwin.hxx"
+#include "vcl/print.hxx"
+#include "vcl/virdev.hxx"
 #include "salinst.hxx"
 #include "salframe.hxx"
 #include "salgdi.hxx"
diff --git a/vcl/source/edit/texteng.cxx b/vcl/source/edit/texteng.cxx
index 81a1a0f..692d3f9 100644
--- a/vcl/source/edit/texteng.cxx
+++ b/vcl/source/edit/texteng.cxx
@@ -117,7 +117,7 @@ TextEngine::~TextEngine()
     delete mpDoc;
     delete mpTEParaPortions;
     delete mpViews; // only the list, not the Views
-    delete mpRefDev;
+    mpRefDev.disposeAndClear();
     delete mpUndoManager;
     delete mpIMEInfos;
     delete mpLocaleDataWrapper;
diff --git a/vcl/source/edit/textview.cxx b/vcl/source/edit/textview.cxx
index 482dc55..23297f0 100644
--- a/vcl/source/edit/textview.cxx
+++ b/vcl/source/edit/textview.cxx
@@ -156,7 +156,7 @@ struct ImpTextView
 
     TextDDInfo*         mpDDInfo;
 
-    VirtualDevice*      mpVirtDev;
+    VclPtr<VirtualDevice>  mpVirtDev;
 
     SelectionEngine*    mpSelEngine;
     TextSelFunctionSet* mpSelFuncSet;
@@ -235,7 +235,7 @@ TextView::~TextView()
 {
     delete mpImpl->mpSelEngine;
     delete mpImpl->mpSelFuncSet;
-    delete mpImpl->mpVirtDev;
+    mpImpl->mpVirtDev.disposeAndClear();
 
     if ( mpImpl->mpWindow->GetCursor() == mpImpl->mpCursor )
         mpImpl->mpWindow->SetCursor( 0 );
@@ -541,8 +541,7 @@ VirtualDevice* TextView::GetVirtualDevice()
 
 void TextView::EraseVirtualDevice()
 {
-    delete mpImpl->mpVirtDev;
-    mpImpl->mpVirtDev = 0;
+    mpImpl->mpVirtDev.disposeAndClear();
 }
 
 bool TextView::KeyInput( const KeyEvent& rKeyEvent )
diff --git a/vcl/source/filter/graphicfilter.cxx b/vcl/source/filter/graphicfilter.cxx
index b47e674..155104e 100644
--- a/vcl/source/filter/graphicfilter.cxx
+++ b/vcl/source/filter/graphicfilter.cxx
@@ -1889,16 +1889,16 @@ sal_uInt16 GraphicFilter::ExportGraphic( const Graphic& rGraphic, const OUString
         {
             Size aSizePixel;
             sal_uLong nColorCount,nBitsPerPixel,nNeededMem,nMaxMem;
-            VirtualDevice aVirDev;
+            ScopedVclPtr<VirtualDevice> aVirDev = new VirtualDevice;
 
             nMaxMem = 1024;
             nMaxMem *= 1024; // In Bytes
 
             // Calculate how big the image would normally be:
-            aSizePixel=aVirDev.LogicToPixel(aGraphic.GetPrefSize(),aGraphic.GetPrefMapMode());
+            aSizePixel=aVirDev->LogicToPixel(aGraphic.GetPrefSize(),aGraphic.GetPrefMapMode());
 
             // Calculate how much memory the image will take up
-            nColorCount=aVirDev.GetColorCount();
+            nColorCount=aVirDev->GetColorCount();
             if      (nColorCount<=2)     nBitsPerPixel=1;
             else if (nColorCount<=4)     nBitsPerPixel=2;
             else if (nColorCount<=16)    nBitsPerPixel=4;
@@ -1915,12 +1915,12 @@ sal_uInt16 GraphicFilter::ExportGraphic( const Graphic& rGraphic, const OUString
                 aSizePixel.Height()=(sal_uLong)(((double)aSizePixel.Height())*fFak);
             }
 
-            aVirDev.SetMapMode(MapMode(MAP_PIXEL));
-            aVirDev.SetOutputSizePixel(aSizePixel);
+            aVirDev->SetMapMode(MapMode(MAP_PIXEL));
+            aVirDev->SetOutputSizePixel(aSizePixel);
             Graphic aGraphic2=aGraphic;
-            aGraphic2.Draw(&aVirDev,Point(0,0),aSizePixel); // this changes the MapMode
-            aVirDev.SetMapMode(MapMode(MAP_PIXEL));
-            aGraphic=Graphic(aVirDev.GetBitmap(Point(0,0),aSizePixel));
+            aGraphic2.Draw(aVirDev.get(),Point(0,0),aSizePixel); // this changes the MapMode
+            aVirDev->SetMapMode(MapMode(MAP_PIXEL));
+            aGraphic=Graphic(aVirDev->GetBitmap(Point(0,0),aSizePixel));
         }
     }
     if( rOStm.GetError() )
diff --git a/vcl/source/filter/sgfbram.cxx b/vcl/source/filter/sgfbram.cxx
index 8a05999..11d3960 100644
--- a/vcl/source/filter/sgfbram.cxx
+++ b/vcl/source/filter/sgfbram.cxx
@@ -390,7 +390,7 @@ Color Hpgl2SvFarbe( sal_uInt8 nFarb )
 
 bool SgfFilterVect(SvStream& rInp, SgfHeader& rHead, SgfEntry&, GDIMetaFile& rMtf)
 {
-    VirtualDevice aOutDev;
+    ScopedVclPtr<VirtualDevice> aOutDev = new VirtualDevice;
     SgfVector aVect;
     sal_uInt8      nFarb;
     sal_uInt8      nFrb0=7;
@@ -402,9 +402,9 @@ bool SgfFilterVect(SvStream& rInp, SgfHeader& rHead, SgfEntry&, GDIMetaFile& rMt
     Point     aP1(0,0);
     sal_uInt16    RecNr=0;
 
-    rMtf.Record(&aOutDev);
-    aOutDev.SetLineColor(Color(COL_BLACK));
-    aOutDev.SetFillColor(Color(COL_BLACK));
+    rMtf.Record(aOutDev.get());
+    aOutDev->SetLineColor(Color(COL_BLACK));
+    aOutDev->SetFillColor(Color(COL_BLACK));
 
     while (!bEoDt && !rInp.GetError()) {
         ReadSgfVector( rInp, aVect ); RecNr++;
@@ -430,15 +430,15 @@ bool SgfFilterVect(SvStream& rInp, SgfHeader& rHead, SgfEntry&, GDIMetaFile& rMt
                 switch(nOTyp) {
                     case 1: if (nFarb!=nFrb0) {
                                 switch(rHead.SwGrCol) {
-                                    case SgfVectFarb: aOutDev.SetLineColor(Hpgl2SvFarbe(nFarb)); break;
+                                    case SgfVectFarb: aOutDev->SetLineColor(Hpgl2SvFarbe(nFarb)); break;
                                     case SgfVectGray:                          break;
                                     case SgfVectWdth:                          break;
                                 }
                             }
-                            aOutDev.DrawLine(aP0,aP1);            break; // line
+                            aOutDev->DrawLine(aP0,aP1);            break; // line
                     case 2:                                       break; // circle
                     case 3:                                       break; // text
-                    case 5: aOutDev.DrawRect(Rectangle(aP0,aP1)); break; // rectangle (solid)
+                    case 5: aOutDev->DrawRect(Rectangle(aP0,aP1)); break; // rectangle (solid)
                 }
             }
             aP0=aP1;
diff --git a/vcl/source/filter/sgvmain.cxx b/vcl/source/filter/sgvmain.cxx
index 18c51f3..d1d62a8 100644
--- a/vcl/source/filter/sgvmain.cxx
+++ b/vcl/source/filter/sgvmain.cxx
@@ -794,13 +794,13 @@ bool SgfFilterSDrw( SvStream& rInp, SgfHeader&, SgfEntry&, GDIMetaFile& rMtf )
 {
     bool          bRet = false;
     PageType      aPage;
-    VirtualDevice aOutDev;
+    ScopedVclPtr<VirtualDevice> aOutDev = new VirtualDevice;
     OutputDevice* pOutDev;
     sal_uLong         nStdPos;
     sal_uLong         nCharPos;
     sal_uInt16        Num;
 
-    pOutDev=&aOutDev;
+    pOutDev=aOutDev.get();
     DtHdOverSeek(rInp); // read dataheader
 
     nStdPos=rInp.Tell();
diff --git a/vcl/source/filter/sgvtext.cxx b/vcl/source/filter/sgvtext.cxx
index 234be20..4b343ae 100644
--- a/vcl/source/filter/sgvtext.cxx
+++ b/vcl/source/filter/sgvtext.cxx
@@ -664,7 +664,7 @@ void FormatLine(UCHAR* TBuf, sal_uInt16& Index, ObjTextType& Atr0, ObjTextType&
                 double, double,
                 UCHAR* cLine, bool TextFit)
 {
-    VirtualDevice vOut;
+    ScopedVclPtr<VirtualDevice> vOut = new VirtualDevice;
     UCHAR        c,c0;
     UCHAR        ct;
     bool         First;               // first char ?
@@ -689,18 +689,18 @@ void FormatLine(UCHAR* TBuf, sal_uInt16& Index, ObjTextType& Atr0, ObjTextType&
     sal_uInt16       i,j,k,h;
     sal_uInt16       re,li;
 
-    vOut.SetMapMode(MapMode(MAP_10TH_MM,Point(),Fraction(1,4),Fraction(1,4)));
+    vOut->SetMapMode(MapMode(MAP_10TH_MM,Point(),Fraction(1,4),Fraction(1,4)));
 
     nChars=0;
-    SetTextContext(vOut,AktAtr,false,0,1,1,1,1);

... etc. - the rest is truncated


More information about the Libreoffice-commits mailing list