Date: prev next · Thread: first prev next last
2011 Archives by date, by thread · List index


Hi all,
this should ideally be my last patch to DecoView, just to not leave the work incomplete. Sadly, I think this patch also needs some thorough review, since the underlying architecture is not so clear to me. Apart from some recoding that should have kept the functionalities, the corrections are:
* Share code between draw/nodraw on window devices (this needs review
  for sure, I didn't understand clearly the conditions to be met for
  the nodraw case);
* Fix drawn FRAME_DRAW_GROUP not resizing its Rectangle;
* Avoid filtering/recreating FRAME_DRAW_MENU flag.

Ciao
Matteo
From 9ed12c989a64306e1503edf2943e6bd5d60d3140 Mon Sep 17 00:00:00 2001
From: Matteo Casalin <matteo.casalin@poste.it>
Date: Fri, 9 Dec 2011 21:13:58 +0100
Subject: [PATCH] DecoView cleanup: rework ImplDrawFrame

---
 vcl/source/window/decoview.cxx |  398 +++++++++++++++++++---------------------
 1 files changed, 187 insertions(+), 211 deletions(-)

diff --git a/vcl/source/window/decoview.cxx b/vcl/source/window/decoview.cxx
index a1511ab..38dbe74 100644
--- a/vcl/source/window/decoview.cxx
+++ b/vcl/source/window/decoview.cxx
@@ -633,6 +633,193 @@ void ImplDrawButton( OutputDevice *const pDev, Rectangle aFillRect,
     }
 }
 
+void ImplDrawFrame( OutputDevice *const pDev, Rectangle& rRect,
+                    const StyleSettings& rStyleSettings, sal_uInt16 nStyle )
+{
+    Window *const pWin = (pDev->GetOutDevType()==OUTDEV_WINDOW) ? (Window*) pDev : NULL;
+
+    const bool bMenuStyle = nStyle & FRAME_DRAW_MENU;
+
+    // UseFlatBorders disables 3D style for all frames except menus
+    // menus may use different border colors (eg on XP)
+    // normal frames will be drawn using the shadow color
+    // whereas window frame borders will use black
+    bool bFlatBorders = !bMenuStyle && rStyleSettings.GetUseFlatBorders();
+
+    // no flat borders for standard VCL controls (ie formcontrols that keep their classic look)
+    // will not affect frame windows (like dropdowns)
+    if( bFlatBorders && pWin && pWin->GetType() == WINDOW_BORDERWINDOW && (pWin != 
pWin->ImplGetFrameWindow()) )
+    {
+        // check for formcontrol, i.e., a control without NWF enabled
+        Control *const pControl = dynamic_cast< Control* >( pWin->GetWindow( WINDOW_CLIENT ) );
+        if( !pControl || !pControl->IsNativeWidgetEnabled() )
+            bFlatBorders = false;
+    }
+
+    const bool bNoDraw = nStyle & FRAME_DRAW_NODRAW;
+
+    if ( (rStyleSettings.GetOptions() & STYLE_OPTION_MONO) ||
+         (pDev->GetOutDevType() == OUTDEV_PRINTER) ||
+         bFlatBorders )
+        nStyle |= FRAME_DRAW_MONO;
+
+    if( pWin && pWin->IsNativeControlSupported(CTRL_FRAME, PART_BORDER) )
+    {
+        ImplControlValue aControlValue( nStyle |
+                                        (pWin->GetType()==WINDOW_BORDERWINDOW) ?
+                                        FRAME_DRAW_BORDERWINDOWBORDER : 0 );
+        Rectangle aBound, aContent;
+        Rectangle aNatRgn( rRect );
+        if( pWin->GetNativeControlRegion(CTRL_FRAME, PART_BORDER,
+            aNatRgn, 0, aControlValue, rtl::OUString(), aBound, aContent) )
+        {
+            // if bNoDraw is true then don't call the drawing routine
+            // but just update the target rectangle
+            if( bNoDraw ||
+                pWin->DrawNativeControl( CTRL_FRAME, PART_BORDER, aContent, CTRL_STATE_ENABLED,
+                                         aControlValue, rtl::OUString()) )
+            {
+                rRect = aContent;
+                return;
+            }
+        }
+    }
+
+    if ( nStyle & FRAME_DRAW_MONO )
+    {
+        // no round corners for window frame borders
+        const bool bRound = bFlatBorders && !(nStyle & FRAME_DRAW_WINDOWBORDER);
+
+        if ( bNoDraw )
+        {
+            ImplDrawDPILineRect( pDev, rRect, NULL, bRound );
+        }
+        else
+        {
+            Color aColor = bRound ? rStyleSettings.GetShadowColor()
+                                  : pDev->GetSettings().GetStyleSettings().GetMonoColor();
+            // when the MonoColor wasn't set, check face color
+            if (
+                (bRound && aColor.IsDark()) ||
+                (
+                  (aColor == Color(COL_BLACK)) &&
+                  pDev->GetSettings().GetStyleSettings().GetFaceColor().IsDark()
+                )
+               )
+            {
+                aColor = Color( COL_WHITE );
+            }
+            ImplDrawDPILineRect( pDev, rRect, &aColor, bRound );
+        }
+    }
+    else
+    {
+        if ( bNoDraw )
+        {
+            switch ( nStyle & FRAME_DRAW_STYLE )
+            {
+                case FRAME_DRAW_IN:
+                case FRAME_DRAW_OUT:
+                    ++rRect.Left();
+                    ++rRect.Top();
+                    --rRect.Right();
+                    --rRect.Bottom();
+                    break;
+
+                case FRAME_DRAW_GROUP:
+                case FRAME_DRAW_DOUBLEIN:
+                case FRAME_DRAW_DOUBLEOUT:
+                    rRect.Left()   += 2;
+                    rRect.Top()    += 2;
+                    rRect.Right()  -= 2;
+                    rRect.Bottom() -= 2;
+                    break;
+            }
+        }
+        else
+        {
+            switch ( nStyle & FRAME_DRAW_STYLE )
+            {
+                case FRAME_DRAW_GROUP:
+                    pDev->SetFillColor();
+                    pDev->SetLineColor( rStyleSettings.GetLightColor() );
+                    pDev->DrawRect( Rectangle( rRect.Left()+1, rRect.Top()+1,
+                                            rRect.Right(), rRect.Bottom() ) );
+                    pDev->SetLineColor( rStyleSettings.GetShadowColor() );
+                    pDev->DrawRect( Rectangle( rRect.Left(), rRect.Top(),
+                                            rRect.Right()+1, rRect.Bottom()+1 ) );
+
+                    // adjust target rectangle
+                    rRect.Left()   += 2;
+                    rRect.Top()    += 2;
+                    rRect.Right()  -= 2;
+                    rRect.Bottom() -= 2;
+                    break;
+
+                case FRAME_DRAW_IN:
+                    ImplDraw2ColorFrame( pDev, rRect,
+                                         rStyleSettings.GetShadowColor(),
+                                         rStyleSettings.GetLightColor() );
+                    break;
+
+                case FRAME_DRAW_OUT:
+                    ImplDraw2ColorFrame( pDev, rRect,
+                                         rStyleSettings.GetLightColor(),
+                                         rStyleSettings.GetShadowColor() );
+                    break;
+
+                case FRAME_DRAW_DOUBLEIN:
+                    if( bFlatBorders )
+                    {
+                        // no 3d effect
+                        ImplDraw2ColorFrame( pDev, rRect,
+                                             rStyleSettings.GetShadowColor(),
+                                             rStyleSettings.GetShadowColor() );
+                        ImplDraw2ColorFrame( pDev, rRect,
+                                             rStyleSettings.GetFaceColor(),
+                                             rStyleSettings.GetFaceColor() );
+                    }
+                    else
+                    {
+                        ImplDraw2ColorFrame( pDev, rRect,
+                                             rStyleSettings.GetShadowColor(),
+                                             rStyleSettings.GetLightColor() );
+                        ImplDraw2ColorFrame( pDev, rRect,
+                                             rStyleSettings.GetDarkShadowColor(),
+                                             rStyleSettings.GetLightBorderColor() );
+                    }
+                    break;
+
+                case FRAME_DRAW_DOUBLEOUT:
+                    if( bMenuStyle )
+                    {
+                        ImplDraw2ColorFrame( pDev, rRect,
+                                             rStyleSettings.GetMenuBorderColor(),
+                                             rStyleSettings.GetDarkShadowColor() );
+                        if ( !rStyleSettings.GetUseFlatMenues() )
+                        {
+                            ImplDraw2ColorFrame( pDev, rRect,
+                                                 rStyleSettings.GetLightColor(),
+                                                 rStyleSettings.GetShadowColor() );
+                        }
+                    }
+                    else
+                    {
+                        ImplDraw2ColorFrame( pDev, rRect,
+                                             bFlatBorders ? // no 3d effect
+                                             rStyleSettings.GetDarkShadowColor() :
+                                             rStyleSettings.GetLightBorderColor(),
+                                             rStyleSettings.GetDarkShadowColor() );
+                        ImplDraw2ColorFrame( pDev, rRect,
+                                             rStyleSettings.GetLightColor(),
+                                             rStyleSettings.GetShadowColor() );
+                    }
+                    break;
+            }
+        }
+    }
+}
+
 }
 
 
@@ -748,217 +935,6 @@ void DecorationView::DrawHighlightFrame( const Rectangle& rRect,
 
 // =======================================================================
 
-static void ImplDrawFrame( OutputDevice* pDev, Rectangle& rRect,
-                           const StyleSettings& rStyleSettings, sal_uInt16 nStyle )
-{
-    // mask menu style
-    sal_Bool bMenuStyle = (nStyle & FRAME_DRAW_MENU) ? sal_True : sal_False;
-    nStyle &= ~FRAME_DRAW_MENU;
-
-    Window *pWin = NULL;
-    if( pDev->GetOutDevType() == OUTDEV_WINDOW )
-        pWin = (Window*) pDev;
-
-    // UseFlatBorders disables 3D style for all frames except menus
-    // menus may use different border colors (eg on XP)
-    // normal frames will be drawn using the shadow color
-    // whereas window frame borders will use black
-    sal_Bool bFlatBorders = ( !bMenuStyle && rStyleSettings.GetUseFlatBorders() );
-
-    // no flat borders for standard VCL controls (ie formcontrols that keep their classic look)
-    // will not affect frame windows (like dropdowns)
-    if( bFlatBorders && pWin && pWin->GetType() == WINDOW_BORDERWINDOW && (pWin != 
pWin->ImplGetFrameWindow()) )
-    {
-        // check for formcontrol, i.e., a control without NWF enabled
-        Control *pControl = dynamic_cast< Control* >( pWin->GetWindow( WINDOW_CLIENT ) );
-        if( pControl && pControl->IsNativeWidgetEnabled() )
-            bFlatBorders = sal_True;
-        else
-            bFlatBorders = sal_False;
-    }
-
-    // no round corners for window frame borders
-    sal_Bool bRound = (bFlatBorders && !(nStyle & FRAME_DRAW_WINDOWBORDER));
-
-    if ( (rStyleSettings.GetOptions() & STYLE_OPTION_MONO) ||
-         (pDev->GetOutDevType() == OUTDEV_PRINTER) ||
-         bFlatBorders )
-        nStyle |= FRAME_DRAW_MONO;
-
-    if ( nStyle & FRAME_DRAW_NODRAW )
-    {
-        sal_uInt16 nValueStyle = bMenuStyle ? nStyle | FRAME_DRAW_MENU : nStyle;
-        if( pWin && pWin->GetType() == WINDOW_BORDERWINDOW )
-            nValueStyle |= FRAME_DRAW_BORDERWINDOWBORDER;
-        ImplControlValue aControlValue( nValueStyle );
-        Rectangle aBound, aContent;
-        Rectangle aNatRgn( rRect );
-        if(pWin && pWin->GetNativeControlRegion(CTRL_FRAME, PART_BORDER,
-            aNatRgn, 0, aControlValue, rtl::OUString(), aBound, aContent) )
-        {
-            rRect = aContent;
-        }
-        else if ( nStyle & FRAME_DRAW_MONO )
-            ImplDrawDPILineRect( pDev, rRect, NULL, bRound );
-        else
-        {
-            sal_uInt16 nFrameStyle = nStyle & FRAME_DRAW_STYLE;
-
-            if ( nFrameStyle == FRAME_DRAW_GROUP )
-            {
-                rRect.Left()    += 2;
-                rRect.Top()     += 2;
-                rRect.Right()   -= 2;
-                rRect.Bottom()  -= 2;
-            }
-            else if ( (nFrameStyle == FRAME_DRAW_IN) ||
-                      (nFrameStyle == FRAME_DRAW_OUT) )
-            {
-                rRect.Left()++;
-                rRect.Top()++;
-                rRect.Right()--;
-                rRect.Bottom()--;
-            }
-            else // FRAME_DRAW_DOUBLEIN || FRAME_DRAW_DOUBLEOUT
-            {
-                rRect.Left()    += 2;
-                rRect.Top()     += 2;
-                rRect.Right()   -= 2;
-                rRect.Bottom()  -= 2;
-            }
-        }
-    }
-    else
-    {
-        if( pWin && pWin->IsNativeControlSupported(CTRL_FRAME, PART_BORDER) )
-        {
-            sal_uInt16 nValueStyle = bMenuStyle ? nStyle | FRAME_DRAW_MENU : nStyle;
-            if( pWin->GetType() == WINDOW_BORDERWINDOW )
-                nValueStyle |= FRAME_DRAW_BORDERWINDOWBORDER;
-            ImplControlValue aControlValue( nValueStyle );
-            Rectangle aBound, aContent;
-            Rectangle aNatRgn( rRect );
-            if( pWin->GetNativeControlRegion(CTRL_FRAME, PART_BORDER,
-                aNatRgn, 0, aControlValue, rtl::OUString(), aBound, aContent) )
-            {
-                if( pWin->DrawNativeControl( CTRL_FRAME, PART_BORDER, aContent, CTRL_STATE_ENABLED,
-                             aControlValue, rtl::OUString()) )
-                {
-                    rRect = aContent;
-                    return;
-                }
-            }
-        }
-
-        if ( nStyle & FRAME_DRAW_MONO )
-        {
-            Color aColor = bRound ? rStyleSettings.GetShadowColor()
-                                  : pDev->GetSettings().GetStyleSettings().GetMonoColor();
-            // when the MonoColor wasn't set, check face color
-            if (
-                (bRound && aColor.IsDark()) ||
-                (
-                  (aColor == Color(COL_BLACK)) &&
-                  (pDev->GetSettings().GetStyleSettings().GetFaceColor().IsDark())
-                )
-               )
-            {
-                aColor = Color( COL_WHITE );
-            }
-            ImplDrawDPILineRect( pDev, rRect, &aColor, bRound );
-        }
-        else
-        {
-            sal_uInt16 nFrameStyle = nStyle & FRAME_DRAW_STYLE;
-            if ( nFrameStyle == FRAME_DRAW_GROUP )
-            {
-                pDev->SetFillColor();
-                pDev->SetLineColor( rStyleSettings.GetLightColor() );
-                rRect.Top()++;
-                rRect.Left()++;
-                pDev->DrawRect( rRect );
-                rRect.Top()--;
-                rRect.Left()--;
-                pDev->SetLineColor( rStyleSettings.GetShadowColor() );
-                rRect.Right()--;
-                rRect.Bottom()--;
-                pDev->DrawRect( rRect );
-                rRect.Right()++;
-                rRect.Bottom()++;
-            }
-            else
-            {
-                if ( (nFrameStyle == FRAME_DRAW_IN) ||
-                     (nFrameStyle == FRAME_DRAW_OUT) )
-                {
-                    if ( nFrameStyle == FRAME_DRAW_IN )
-                    {
-                        ImplDraw2ColorFrame( pDev, rRect,
-                                             rStyleSettings.GetShadowColor(),
-                                             rStyleSettings.GetLightColor() );
-                    }
-                    else
-                    {
-                        ImplDraw2ColorFrame( pDev, rRect,
-                                             rStyleSettings.GetLightColor(),
-                                             rStyleSettings.GetShadowColor() );
-                    }
-                }
-                else // FRAME_DRAW_DOUBLEIN || FRAME_DRAW_DOUBLEOUT
-                {
-                    if ( nFrameStyle == FRAME_DRAW_DOUBLEIN )
-                    {
-                        if( bFlatBorders ) // no 3d effect
-                            ImplDraw2ColorFrame( pDev, rRect,
-                                                 rStyleSettings.GetShadowColor(),
-                                                 rStyleSettings.GetShadowColor() );
-                        else
-                            ImplDraw2ColorFrame( pDev, rRect,
-                                                 rStyleSettings.GetShadowColor(),
-                                                 rStyleSettings.GetLightColor() );
-                    }
-                    else
-                    {
-                        if( bMenuStyle )
-                            ImplDraw2ColorFrame( pDev, rRect,
-                                                 rStyleSettings.GetMenuBorderColor(),
-                                                 rStyleSettings.GetDarkShadowColor() );
-                        else
-                            ImplDraw2ColorFrame( pDev, rRect,
-                                                 bFlatBorders ? // no 3d effect
-                                                 rStyleSettings.GetDarkShadowColor() :
-                                                 rStyleSettings.GetLightBorderColor(),
-                                                 rStyleSettings.GetDarkShadowColor() );
-
-                    }
-
-                    if ( nFrameStyle == FRAME_DRAW_DOUBLEIN )
-                    {
-                        if( bFlatBorders ) // no 3d effect
-                            ImplDraw2ColorFrame( pDev, rRect,
-                                                 rStyleSettings.GetFaceColor(),
-                                                 rStyleSettings.GetFaceColor() );
-                        else
-                            ImplDraw2ColorFrame( pDev, rRect,
-                                                 rStyleSettings.GetDarkShadowColor(),
-                                                 rStyleSettings.GetLightBorderColor() );
-                    }
-                    else
-                    {
-                        // flat menus have no shadow border
-                        if( !bMenuStyle || !rStyleSettings.GetUseFlatMenues() )
-                            ImplDraw2ColorFrame( pDev, rRect,
-                                                 rStyleSettings.GetLightColor(),
-                                                 rStyleSettings.GetShadowColor() );
-                    }
-                }
-            }
-        }
-    }
-}
-
-// -----------------------------------------------------------------------
-
 Rectangle DecorationView::DrawFrame( const Rectangle& rRect, sal_uInt16 nStyle )
 {
     Rectangle   aRect = rRect;
-- 
1.7.5.4


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.