[Libreoffice-commits] .: vcl/inc vcl/source

Ivan Timofeev ivantimofeev at kemper.freedesktop.org
Wed Jul 25 11:32:42 PDT 2012


 vcl/inc/vcl/button.hxx         |    5 ++--
 vcl/source/control/button.cxx  |   47 ++++++++++++++++-------------------------
 vcl/source/control/menubtn.cxx |    5 +---
 3 files changed, 24 insertions(+), 33 deletions(-)

New commits:
commit 452e452d3e9dcc259bc3e58ed6509284004f04fe
Author: Ivan Timofeev <timofeev.i.s at gmail.com>
Date:   Wed Jul 25 22:28:48 2012 +0400

    refactor the symbol hit test
    
    Change-Id: I739855830a7135c8e0a8d80d4f1f84e5a3901204

diff --git a/vcl/inc/vcl/button.hxx b/vcl/inc/vcl/button.hxx
index 9eb6088..0fd0bcf 100644
--- a/vcl/inc/vcl/button.hxx
+++ b/vcl/inc/vcl/button.hxx
@@ -66,8 +66,9 @@ public:
     SAL_DLLPRIVATE const Rectangle& ImplGetFocusRect() const;
     SAL_DLLPRIVATE void             ImplSetSymbolAlign( SymbolAlign eAlign );
     SAL_DLLPRIVATE void             ImplSetSmallSymbol( sal_Bool bSmall = sal_True );
-    SAL_DLLPRIVATE const Rectangle& ImplGetSymbolRect() const;
-    SAL_DLLPRIVATE void             ImplSetSymbolRect(const Rectangle&);
+    /// The x-coordinate of the vertical separator line, use in MenuButton subclass only.
+    SAL_DLLPRIVATE long             ImplGetSeparatorX() const;
+    SAL_DLLPRIVATE void             ImplSetSeparatorX( long nX );
 
 protected:
                         Button( WindowType nType );
diff --git a/vcl/source/control/button.cxx b/vcl/source/control/button.cxx
index 42579ac..406377b 100644
--- a/vcl/source/control/button.cxx
+++ b/vcl/source/control/button.cxx
@@ -72,7 +72,7 @@ class ImplCommonButtonData
 {
 public:
     Rectangle       maFocusRect;
-    Rectangle       maSymbolRect;
+    long            mnSeparatorX;
     sal_uInt16          mnButtonState;
     sal_Bool            mbSmallSymbol;
 
@@ -223,14 +223,14 @@ void Button::SetFocusRect( const Rectangle& rFocusRect )
 
 // -----------------------------------------------------------------------
 
-const Rectangle& Button::ImplGetSymbolRect() const
+long Button::ImplGetSeparatorX() const
 {
-    return mpButtonData->maSymbolRect;
+    return mpButtonData->mnSeparatorX;
 }
 
-void Button::ImplSetSymbolRect( const Rectangle& i_rRect )
+void Button::ImplSetSeparatorX( long nX )
 {
-    mpButtonData->maSymbolRect = i_rRect;
+    mpButtonData->mnSeparatorX = nX;
 }
 
 // -----------------------------------------------------------------------
@@ -860,47 +860,39 @@ void PushButton::ImplDrawPushButtonContent( OutputDevice* pDev, sal_uLong nDrawF
         nImageSep = 1;
     if ( mnDDStyle == PUSHBUTTON_DROPDOWN_MENUBUTTON )
     {
-        Rectangle aHotspotRect = rRect;
+        long nSeparatorX = 0;
+        Rectangle aSymbolRect = aInRect;
         if ( aText.Len() && ! (ImplGetButtonState() & BUTTON_DRAW_NOTEXT) )
         {
             // calculate symbol size
             long nSymbolSize    = pDev->GetTextHeight() / 2 + 1;
 
-            // caluclate dimension of hotspot rectangle
-            aHotspotRect.Left() = aHotspotRect.Right() - 2*nSymbolSize;
+            nSeparatorX = aInRect.Right() - 2*nSymbolSize;
+            aSize.Width() -= 2*nSymbolSize;
 
-            // center symbol rectangle inside hotspot rectangle
-            aInRect.Right() = aHotspotRect.Right() - nSymbolSize/2 + 1;
-            aInRect.Left()  = aInRect.Right() - nSymbolSize;
-
-            aSize.Width() -= aHotspotRect.GetWidth();
+            // center symbol rectangle in the separated area
+            aSymbolRect.Right() -= nSymbolSize/2;
+            aSymbolRect.Left()  = aSymbolRect.Right() - nSymbolSize;
 
             ImplDrawAlignedImage( pDev, aPos, aSize, bLayout, nImageSep,
                                   nDrawFlags, nTextStyle, NULL, true );
         }
         else
-            ImplCalcSymbolRect( aInRect );
+            ImplCalcSymbolRect( aSymbolRect );
 
         if( ! bLayout )
         {
-            long nDistance = (aInRect.GetHeight() > 10) ? 2 : 1;
+            long nDistance = (aSymbolRect.GetHeight() > 10) ? 2 : 1;
             DecorationView aDecoView( pDev );
-            if( bMenuBtnSep )
+            if( bMenuBtnSep && nSeparatorX > 0 )
             {
-                long nX = aHotspotRect.Left();
-                Point aStartPt( nX, aHotspotRect.Top()+nDistance );
-                Point aEndPt( nX, aHotspotRect.Bottom()-nDistance );
+                Point aStartPt( nSeparatorX, aSymbolRect.Top()+nDistance );
+                Point aEndPt( nSeparatorX, aSymbolRect.Bottom()-nDistance );
                 aDecoView.DrawSeparator( aStartPt, aEndPt );
             }
+            ImplSetSeparatorX( nSeparatorX );
 
-            aDecoView.DrawSymbol( aInRect, SYMBOL_SPIN_DOWN, aColor, nStyle );
-
-            // hack: include decoration into hotspot rectangle (hopefully +10 is enough)
-            aHotspotRect.Right() += 10;
-            aHotspotRect.Bottom() += 10;
-            aHotspotRect.Top() -= 10;
-
-            ImplSetSymbolRect( aHotspotRect );
+            aDecoView.DrawSymbol( aSymbolRect, SYMBOL_SPIN_DOWN, aColor, nStyle );
         }
 
     }
@@ -916,7 +908,6 @@ void PushButton::ImplDrawPushButtonContent( OutputDevice* pDev, sal_uLong nDrawF
         {
             DecorationView aDecoView( pDev );
             aDecoView.DrawSymbol( aSymbolRect, meSymbol, aColor, nStyle );
-            ImplSetSymbolRect( aSymbolRect );
         }
 
         if ( mnDDStyle == PUSHBUTTON_DROPDOWN_TOOLBOX && !bLayout )
diff --git a/vcl/source/control/menubtn.cxx b/vcl/source/control/menubtn.cxx
index 5715367..5994522 100644
--- a/vcl/source/control/menubtn.cxx
+++ b/vcl/source/control/menubtn.cxx
@@ -153,9 +153,8 @@ void MenuButton::MouseButtonDown( const MouseEvent& rMEvt )
     bool bExecute = true;
     if ( mnMenuMode & MENUBUTTON_MENUMODE_TIMED )
     {
-        // if the separated dropdown symbol is hit,
-        // execute the popup immediately
-        if( ! ImplGetSymbolRect().IsInside( rMEvt.GetPosPixel() ) )
+        // if the separated dropdown symbol is not hit, delay the popup execution
+        if( rMEvt.GetPosPixel().X() <= ImplGetSeparatorX() )
         {
             if ( !mpMenuTimer )
             {


More information about the Libreoffice-commits mailing list