[PATCH] fdo#36690: Don't broadcast setting changes during painting of button.

Kohei Yoshida kyoshida at novell.com
Thu May 19 21:15:01 PDT 2011


Calling SetSettings() when the output device is Window causes it to
broadcast data change.  PushButton::Draw() in fact calls this method
when the button contains colors, which ends up broadcasting its change
via Window::DataChanged call.  But depending on the output device
this DataChanged call may end up painting it again, which basically
causes a recursive loop.

The solution is to provide a way to only change the settings without
doing anything else, and use that when settings need to be changed
during the painting of a control (like PushButton).
---
 vcl/inc/vcl/outdev.hxx        |    7 +++++++
 vcl/source/control/button.cxx |    2 +-
 vcl/source/gdi/outdev.cxx     |    7 ++++++-
 3 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/vcl/inc/vcl/outdev.hxx b/vcl/inc/vcl/outdev.hxx
index b624cd9..f4f7475 100644
--- a/vcl/inc/vcl/outdev.hxx
+++ b/vcl/inc/vcl/outdev.hxx
@@ -917,6 +917,13 @@ public:
     void                SetTextAlign( TextAlign eAlign );
     TextAlign           GetTextAlign() const { return maFont.GetAlign(); }
 
+    /**
+     * Unlike SetSettings() which is virtual & may do more than just updating
+     * the settings, this method only sets the new settings and do nothing
+     * extra.  This method should be called instead of SetSettings() when
+     * changing the settings during painting of controls.
+     */
+    void                SetSettingsOnly( const AllSettings& rSettings );
     virtual void        SetSettings( const AllSettings& rSettings );
     const AllSettings&  GetSettings() const { return maSettings; }
 
diff --git a/vcl/source/control/button.cxx b/vcl/source/control/button.cxx
index c77d14a..b0ce14f 100644
--- a/vcl/source/control/button.cxx
+++ b/vcl/source/control/button.cxx
@@ -1522,7 +1522,7 @@ void PushButton::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize,
         else
             aStyleSettings.SetFaceColor( GetSettings().GetStyleSettings().GetFaceColor() );
         aSettings.SetStyleSettings( aStyleSettings );
-        pDev->SetSettings( aSettings );
+        pDev->SetSettingsOnly( aSettings );
     }
     pDev->SetTextFillColor();
 
diff --git a/vcl/source/gdi/outdev.cxx b/vcl/source/gdi/outdev.cxx
index da9ddc3..96a5e1d 100644
--- a/vcl/source/gdi/outdev.cxx
+++ b/vcl/source/gdi/outdev.cxx
@@ -2558,7 +2558,7 @@ void OutputDevice::EnableOutput( sal_Bool bEnable )
 
 // -----------------------------------------------------------------------
 
-void OutputDevice::SetSettings( const AllSettings& rSettings )
+void OutputDevice::SetSettingsOnly( const AllSettings& rSettings )
 {
     maSettings = rSettings;
 
@@ -2566,6 +2566,11 @@ void OutputDevice::SetSettings( const AllSettings& rSettings )
         mpAlphaVDev->SetSettings( rSettings );
 }
 
+void OutputDevice::SetSettings( const AllSettings& rSettings )
+{
+    SetSettingsOnly(rSettings);
+}
+
 // -----------------------------------------------------------------------
 
 sal_uInt16 OutputDevice::GetBitCount() const
-- 
1.7.3.4


--=-I0Wts9ZPXuOhkjsoAOG8--



More information about the LibreOffice mailing list