Tackle Menu with RenderContext refactoring, Invalidate

Change-Id: Ib2812723141c5dfe39b30c95f12d1aeca9c367bd
diff --git a/include/vcl/menu.hxx b/include/vcl/menu.hxx
index 2af6a53..6c5316c 100644
--- a/include/vcl/menu.hxx
+++ b/include/vcl/menu.hxx
@@ -165,7 +165,7 @@ protected:
    SAL_DLLPRIVATE sal_uInt16           ImplGetFirstVisible() const;
    SAL_DLLPRIVATE sal_uInt16           ImplGetPrevVisible( sal_uInt16 nPos ) const;
    SAL_DLLPRIVATE sal_uInt16           ImplGetNextVisible( sal_uInt16 nPos ) const;
    SAL_DLLPRIVATE void             ImplPaint( vcl::Window* pWin, sal_uInt16 nBorder, long nOffY = 0, MenuItemData* pThisDataOnly = 0, bool bHighlighted = false, bool bLayout = false, bool bRollover = false ) const;
    SAL_DLLPRIVATE void             ImplPaint(vcl::RenderContext& rRenderContext, sal_uInt16 nBorder, long nOffY = 0, MenuItemData* pThisDataOnly = 0, bool bHighlighted = false, bool bLayout = false, bool bRollover = false ) const;
    SAL_DLLPRIVATE void             ImplSelect();
    SAL_DLLPRIVATE void             ImplCallHighlight( sal_uInt16 nHighlightItem );
    SAL_DLLPRIVATE void             ImplCallEventListeners( sal_uLong nEvent, sal_uInt16 nPos );
@@ -178,11 +178,11 @@ protected:

    // returns native check and option menu symbol height in rCheckHeight and rRadioHeight
    // return value is maximum width and height of checkboxes and radiobuttons
    SAL_DLLPRIVATE Size             ImplGetNativeCheckAndRadioSize( const vcl::Window*, long& rCheckHeight, long& rRadioHeight ) const;
    SAL_DLLPRIVATE Size             ImplGetNativeCheckAndRadioSize(vcl::RenderContext& rRenderContext, long& rCheckHeight, long& rRadioHeight) const;

    // returns native submenu arrow size and spacing from right border
    // return value is whether it's supported natively
    SAL_DLLPRIVATE bool         ImplGetNativeSubmenuArrowSize( vcl::Window* pWin, Size& rArrowSize, long& rArrowSpacing ) const;
    SAL_DLLPRIVATE bool         ImplGetNativeSubmenuArrowSize(vcl::RenderContext& rRenderContext, Size& rArrowSize, long& rArrowSpacing ) const;

    SAL_DLLPRIVATE void                ImplAddDel( ImplMenuDelData &rDel );
    SAL_DLLPRIVATE void                ImplRemoveDel( ImplMenuDelData &rDel );
diff --git a/vcl/source/window/menu.cxx b/vcl/source/window/menu.cxx
index 3560c6c..94df528 100644
--- a/vcl/source/window/menu.cxx
+++ b/vcl/source/window/menu.cxx
@@ -1393,7 +1393,7 @@ void Menu::SetAccessible( const ::com::sun::star::uno::Reference< ::com::sun::st
    mxAccessible = rxAccessible;
}

Size Menu::ImplGetNativeCheckAndRadioSize( const vcl::Window* pWin, long& rCheckHeight, long& rRadioHeight ) const
Size Menu::ImplGetNativeCheckAndRadioSize(vcl::RenderContext& rRenderContext, long& rCheckHeight, long& rRadioHeight) const
{
    long nCheckWidth = 0, nRadioWidth = 0;
    rCheckHeight = rRadioHeight = 0;
@@ -1405,32 +1405,21 @@ Size Menu::ImplGetNativeCheckAndRadioSize( const vcl::Window* pWin, long& rCheck
        Rectangle aNativeContent;
        Point tmp( 0, 0 );
        Rectangle aCtrlRegion( Rectangle( tmp, Size( 100, 15 ) ) );
        if( pWin->IsNativeControlSupported( CTRL_MENU_POPUP, PART_MENU_ITEM_CHECK_MARK ) )
        if (rRenderContext.IsNativeControlSupported(CTRL_MENU_POPUP, PART_MENU_ITEM_CHECK_MARK) )
        {
            if( pWin->GetNativeControlRegion( ControlType(CTRL_MENU_POPUP),
                                              ControlPart(PART_MENU_ITEM_CHECK_MARK),
                                              aCtrlRegion,
                                              ControlState(ControlState::ENABLED),
                                              aVal,
                                              OUString(),
                                              aNativeBounds,
                                              aNativeContent )
            )
            if (rRenderContext.GetNativeControlRegion(ControlType(CTRL_MENU_POPUP), ControlPart(PART_MENU_ITEM_CHECK_MARK),
                                                      aCtrlRegion, ControlState(ControlState::ENABLED), aVal, OUString(),
                                                      aNativeBounds, aNativeContent))
            {
                rCheckHeight = aNativeBounds.GetHeight();
                nCheckWidth = aNativeContent.GetWidth();
            }
        }
        if( pWin->IsNativeControlSupported( CTRL_MENU_POPUP, PART_MENU_ITEM_RADIO_MARK ) )
        if (rRenderContext.IsNativeControlSupported(CTRL_MENU_POPUP, PART_MENU_ITEM_RADIO_MARK))
        {
            if( pWin->GetNativeControlRegion( ControlType(CTRL_MENU_POPUP),
                                              ControlPart(PART_MENU_ITEM_RADIO_MARK),
                                              aCtrlRegion,
                                              ControlState(ControlState::ENABLED),
                                              aVal,
                                              OUString(),
                                              aNativeBounds,
                                              aNativeContent )
            if (rRenderContext.GetNativeControlRegion(ControlType(CTRL_MENU_POPUP), ControlPart(PART_MENU_ITEM_RADIO_MARK),
                                                      aCtrlRegion, ControlState(ControlState::ENABLED), aVal, OUString(),
                                                      aNativeBounds, aNativeContent)
            )
            {
                rRadioHeight = aNativeBounds.GetHeight();
@@ -1441,34 +1430,24 @@ Size Menu::ImplGetNativeCheckAndRadioSize( const vcl::Window* pWin, long& rCheck
    return Size(std::max(nCheckWidth, nRadioWidth), std::max(rCheckHeight, rRadioHeight));
}

bool Menu::ImplGetNativeSubmenuArrowSize( vcl::Window* pWin, Size& rArrowSize, long& rArrowSpacing ) const
bool Menu::ImplGetNativeSubmenuArrowSize(vcl::RenderContext& rRenderContext, Size& rArrowSize, long& rArrowSpacing) const
{
    ImplControlValue aVal;
    Rectangle aNativeBounds;
    Rectangle aNativeContent;
    Point tmp( 0, 0 );
    Rectangle aCtrlRegion( Rectangle( tmp, Size( 100, 15 ) ) );
    if( pWin->IsNativeControlSupported( CTRL_MENU_POPUP,
                                        PART_MENU_SUBMENU_ARROW ) )
    Rectangle aCtrlRegion(Rectangle(Point(), Size(100, 15)));
    if (rRenderContext.IsNativeControlSupported(CTRL_MENU_POPUP, PART_MENU_SUBMENU_ARROW))
    {
        if (rRenderContext.GetNativeControlRegion(ControlType(CTRL_MENU_POPUP), ControlPart(PART_MENU_SUBMENU_ARROW),
                                                 aCtrlRegion, ControlState(ControlState::ENABLED),
                                                 aVal, OUString(), aNativeBounds, aNativeContent))
        {
            if( pWin->GetNativeControlRegion( ControlType(CTRL_MENU_POPUP),
                                              ControlPart(PART_MENU_SUBMENU_ARROW),
                                              aCtrlRegion,
                                              ControlState(ControlState::ENABLED),
                                              aVal,
                                              OUString(),
                                              aNativeBounds,
                                              aNativeContent )
            )
            {
                Size aSize( Size ( aNativeContent.GetWidth(),
                                   aNativeContent.GetHeight() ) );
                rArrowSize = aSize;
                rArrowSpacing = aNativeBounds.GetWidth() - aNativeContent.GetWidth();

                return true;
            }
            Size aSize(aNativeContent.GetWidth(), aNativeContent.GetHeight());
            rArrowSize = aSize;
            rArrowSpacing = aNativeBounds.GetWidth() - aNativeContent.GetWidth();
            return true;
        }
    }
    return false;
}

@@ -1512,7 +1491,7 @@ Size Menu::ImplCalcSize( const vcl::Window* pWin )

    long nMinMenuItemHeight = nFontHeight;
    long nCheckHeight = 0, nRadioHeight = 0;
    Size aMaxSize = ImplGetNativeCheckAndRadioSize(pWin, nCheckHeight, nRadioHeight);
    Size aMaxSize = ImplGetNativeCheckAndRadioSize(const_cast<vcl::Window&>(*pWin), nCheckHeight, nRadioHeight); // FIXME
    if( aMaxSize.Height() > nMinMenuItemHeight )
        nMinMenuItemHeight = aMaxSize.Height();

@@ -1712,7 +1691,7 @@ Size Menu::ImplCalcSize( const vcl::Window* pWin )
    return aSz;
}

static void ImplPaintCheckBackground( vcl::Window* i_pWindow, const Rectangle& i_rRect, bool i_bHighlight )
static void ImplPaintCheckBackground(vcl::Window* i_pWindow, const Rectangle& i_rRect, bool i_bHighlight ) // FIXME
{
    bool bNativeOk = false;
    if( i_pWindow->IsNativeControlSupported( CTRL_TOOLBAR, PART_BUTTON ) )
@@ -1736,11 +1715,11 @@ static void ImplPaintCheckBackground( vcl::Window* i_pWindow, const Rectangle& i
    }
}

static OUString getShortenedString( const OUString& i_rLong, vcl::Window* i_pWin, long i_nMaxWidth )
static OUString getShortenedString(const OUString& i_rLong, vcl::RenderContext& rRenderContext, long i_nMaxWidth)
{
    sal_Int32 nPos = -1;
    OUString aNonMnem( OutputDevice::GetNonMnemonicString( i_rLong, nPos ) );
    aNonMnem = i_pWin->GetEllipsisString( aNonMnem, i_nMaxWidth, TEXT_DRAW_CENTERELLIPSIS );
    OUString aNonMnem(OutputDevice::GetNonMnemonicString(i_rLong, nPos));
    aNonMnem = rRenderContext.GetEllipsisString( aNonMnem, i_nMaxWidth, TEXT_DRAW_CENTERELLIPSIS );
    // re-insert mnemonic
    if( nPos != -1 )
    {
@@ -1756,17 +1735,17 @@ static OUString getShortenedString( const OUString& i_rLong, vcl::Window* i_pWin
    return aNonMnem;
}

void Menu::ImplPaint( vcl::Window* pWin, sal_uInt16 nBorder, long nStartY, MenuItemData* pThisItemOnly, bool bHighlighted, bool bLayout, bool bRollover ) const
void Menu::ImplPaint(vcl::RenderContext& rRenderContext, sal_uInt16 nBorder, long nStartY, MenuItemData* pThisItemOnly, bool bHighlighted, bool bLayout, bool bRollover ) const
{
    // for symbols: nFontHeight x nFontHeight
    long nFontHeight = pWin->GetTextHeight();
    long nExtra = nFontHeight/4;
    long nFontHeight = rRenderContext.GetTextHeight();
    long nExtra = nFontHeight / 4;

    long nCheckHeight = 0, nRadioHeight = 0;
    ImplGetNativeCheckAndRadioSize( pWin, nCheckHeight, nRadioHeight );
    ImplGetNativeCheckAndRadioSize(rRenderContext, nCheckHeight, nRadioHeight);

    DecorationView aDecoView( pWin );
    const StyleSettings& rSettings = pWin->GetSettings().GetStyleSettings();
    DecorationView aDecoView(&rRenderContext);
    const StyleSettings& rSettings = rRenderContext.GetSettings().GetStyleSettings();

    Point aTopLeft, aTmpPos;

@@ -1781,7 +1760,7 @@ void Menu::ImplPaint( vcl::Window* pWin, sal_uInt16 nBorder, long nStartY, MenuI
        aTopLeft.Y() += ImplGetSVData()->maNWFData.mnMenuFormatBorderY;
    }

    Size aOutSz = pWin->GetOutputSizePixel();
    Size aOutSz = rRenderContext.GetOutputSizePixel();
    size_t nCount = pItemList->size();
    if( bLayout )
        mpLayoutData->m_aVisibleItemBoundRects.clear();
@@ -1794,9 +1773,9 @@ void Menu::ImplPaint( vcl::Window* pWin, sal_uInt16 nBorder, long nStartY, MenuI
            if ( pThisItemOnly )
            {
                if (IsMenuBar()&& bRollover )
                    pWin->SetTextColor( rSettings.GetMenuBarRolloverTextColor() );
                    rRenderContext.SetTextColor( rSettings.GetMenuBarRolloverTextColor() );
                else if ( bHighlighted )
                    pWin->SetTextColor( rSettings.GetMenuHighlightTextColor() );
                    rRenderContext.SetTextColor( rSettings.GetMenuHighlightTextColor() );
            }

            Point aPos( aTopLeft );
@@ -1827,8 +1806,7 @@ void Menu::ImplPaint( vcl::Window* pWin, sal_uInt16 nBorder, long nStartY, MenuI
                if (!bLayout && !IsMenuBar() && (pData->eType == MenuItemType::SEPARATOR))
                {
                    bool bNativeOk = false;
                    if( pWin->IsNativeControlSupported( CTRL_MENU_POPUP,
                                                        PART_MENU_SEPARATOR ) )
                    if (rRenderContext.IsNativeControlSupported(CTRL_MENU_POPUP, PART_MENU_SEPARATOR))
                    {
                        ControlState nState = ControlState::NONE;
                        if ( pData->bEnabled )
@@ -1839,22 +1817,19 @@ void Menu::ImplPaint( vcl::Window* pWin, sal_uInt16 nBorder, long nStartY, MenuI
                        aSz.Width() = aOutSz.Width() - 2*nOuterSpaceX;
                        Rectangle aItemRect( aPos, aSz );
                        MenupopupValue aVal( nTextPos-GUTTERBORDER, aItemRect );
                        bNativeOk = pWin->DrawNativeControl( CTRL_MENU_POPUP, PART_MENU_SEPARATOR,
                                                             aItemRect,
                                                             nState,
                                                             aVal,
                                                             OUString() );
                        bNativeOk = rRenderContext.DrawNativeControl(CTRL_MENU_POPUP, PART_MENU_SEPARATOR,
                                                                     aItemRect, nState, aVal, OUString());
                    }
                    if( ! bNativeOk )
                    if (!bNativeOk)
                    {
                        aTmpPos.Y() = aPos.Y() + ((pData->aSz.Height()-2)/2);
                        aTmpPos.X() = aPos.X() + 2 + nOuterSpaceX;
                        pWin->SetLineColor( rSettings.GetShadowColor() );
                        pWin->DrawLine( aTmpPos, Point( aOutSz.Width() - 3 - 2*nOuterSpaceX, aTmpPos.Y() ) );
                        rRenderContext.SetLineColor( rSettings.GetShadowColor() );
                        rRenderContext.DrawLine( aTmpPos, Point( aOutSz.Width() - 3 - 2*nOuterSpaceX, aTmpPos.Y() ) );
                        aTmpPos.Y()++;
                        pWin->SetLineColor( rSettings.GetLightColor() );
                        pWin->DrawLine( aTmpPos, Point( aOutSz.Width() - 3 - 2*nOuterSpaceX, aTmpPos.Y() ) );
                        pWin->SetLineColor();
                        rRenderContext.SetLineColor( rSettings.GetLightColor() );
                        rRenderContext.DrawLine( aTmpPos, Point( aOutSz.Width() - 3 - 2*nOuterSpaceX, aTmpPos.Y() ) );
                        rRenderContext.SetLineColor();
                    }
                }

@@ -1873,12 +1848,12 @@ void Menu::ImplPaint( vcl::Window* pWin, sal_uInt16 nBorder, long nStartY, MenuI
                    // however do not do this if native checks will be painted since
                    // the selection color too often does not fit the theme's check and/or radio

                    if( ! ( ( pData->eType == MenuItemType::IMAGE ) || ( pData->eType == MenuItemType::STRINGIMAGE ) ) )
                    if (!((pData->eType == MenuItemType::IMAGE) || (pData->eType == MenuItemType::STRINGIMAGE)))
                    {
                        if ( pWin->IsNativeControlSupported( CTRL_MENU_POPUP,
                        if (rRenderContext.IsNativeControlSupported(CTRL_MENU_POPUP,
                                                             (pData->nBits & MenuItemBits::RADIOCHECK)
                                                             ? PART_MENU_ITEM_CHECK_MARK
                                                             : PART_MENU_ITEM_RADIO_MARK ) )
                                                             : PART_MENU_ITEM_RADIO_MARK))
                        {
                            ControlPart nPart = ((pData->nBits & MenuItemBits::RADIOCHECK)
                                                 ? PART_MENU_ITEM_RADIO_MARK
@@ -1904,15 +1879,12 @@ void Menu::ImplPaint( vcl::Window* pWin, sal_uInt16 nBorder, long nStartY, MenuI
                            aSz.Width() = aOutSz.Width() - 2*nOuterSpaceX;
                            Rectangle aItemRect( aPos, aSz );
                            MenupopupValue aVal( nTextPos-GUTTERBORDER, aItemRect );
                            pWin->DrawNativeControl( CTRL_MENU_POPUP, nPart,
                                                     aCheckRect,
                                                     nState,
                                                     aVal,
                                                     OUString() );
                            rRenderContext.DrawNativeControl(CTRL_MENU_POPUP, nPart, aCheckRect,
                                                             nState, aVal, OUString());
                        }
                        else if ( pData->bChecked ) // by default do nothing for unchecked items
                        {
                            ImplPaintCheckBackground( pWin, aOuterCheckRect, pThisItemOnly && bHighlighted );
                            ImplPaintCheckBackground(pWindow, aOuterCheckRect, pThisItemOnly && bHighlighted);

                            SymbolType eSymbol;
                            Size aSymbolSize;
@@ -1929,7 +1901,7 @@ void Menu::ImplPaint( vcl::Window* pWin, sal_uInt16 nBorder, long nStartY, MenuI
                            aTmpPos.X() = aOuterCheckRect.Left() + (aOuterCheckRect.GetWidth() - aSymbolSize.Width())/2;
                            aTmpPos.Y() = aOuterCheckRect.Top() + (aOuterCheckRect.GetHeight() - aSymbolSize.Height())/2;
                            Rectangle aRect( aTmpPos, aSymbolSize );
                            aDecoView.DrawSymbol( aRect, eSymbol, pWin->GetTextColor(), nSymbolStyle );
                            aDecoView.DrawSymbol( aRect, eSymbol, rRenderContext.GetTextColor(), nSymbolStyle );
                        }
                    }
                }
@@ -1939,11 +1911,11 @@ void Menu::ImplPaint( vcl::Window* pWin, sal_uInt16 nBorder, long nStartY, MenuI
                {
                    // Don't render an image for a check thing
                    if( pData->bChecked )
                        ImplPaintCheckBackground( pWin, aOuterCheckRect, pThisItemOnly && bHighlighted );
                        ImplPaintCheckBackground(pWindow, aOuterCheckRect, pThisItemOnly && bHighlighted);

                    Image aImage = pData->aImage;

                    sal_Int32 nScaleFactor = pWindow->GetDPIScaleFactor();
                    sal_Int32 nScaleFactor = rRenderContext.GetDPIScaleFactor();
                    if (nScaleFactor != 1)
                    {
                        BitmapEx aBitmap = aImage.GetBitmapEx();
@@ -1953,7 +1925,7 @@ void Menu::ImplPaint( vcl::Window* pWin, sal_uInt16 nBorder, long nStartY, MenuI
                    aTmpPos = aOuterCheckRect.TopLeft();
                    aTmpPos.X() += (aOuterCheckRect.GetWidth() - aImage.GetSizePixel().Width()) / 2;
                    aTmpPos.Y() += (aOuterCheckRect.GetHeight() - aImage.GetSizePixel().Height()) / 2;
                    pWin->DrawImage(aTmpPos, aImage, nImageStyle);
                    rRenderContext.DrawImage(aTmpPos, aImage, nImageStyle);
                }

                // Text:
@@ -1978,57 +1950,55 @@ void Menu::ImplPaint( vcl::Window* pWin, sal_uInt16 nBorder, long nStartY, MenuI
                    // TEXT_DRAW_DISABLE), temporarily set a background which
                    // hopefully matches the NWF background since it is read
                    // from the system style settings
                    bool bSetTmpBackground = !pWin->IsBackground() && pWin->IsNativeControlSupported( CTRL_MENU_POPUP, PART_ENTIRE_CONTROL );
                    if( bSetTmpBackground )
                    bool bSetTmpBackground = !rRenderContext.IsBackground() && rRenderContext.IsNativeControlSupported(CTRL_MENU_POPUP, PART_ENTIRE_CONTROL);
                    if (bSetTmpBackground)
                    {
                        Color aBg = IsMenuBar()?
                            pWin->GetSettings().GetStyleSettings().GetMenuBarColor() :
                            pWin->GetSettings().GetStyleSettings().GetMenuColor();
                        pWin->SetBackground( Wallpaper( aBg ) );
                            rRenderContext.GetSettings().GetStyleSettings().GetMenuBarColor() :
                            rRenderContext.GetSettings().GetStyleSettings().GetMenuColor();
                        rRenderContext.SetBackground( Wallpaper( aBg ) );
                    }
                    // how much space is there for the text ?
                    long nMaxItemTextWidth = aOutSz.Width() - aTmpPos.X() - nExtra - nOuterSpaceX;
                    if (!IsMenuBar() && pData->aAccelKey.GetCode() && !ImplAccelDisabled())
                    {
                        OUString aAccText = pData->aAccelKey.GetName();
                        nMaxItemTextWidth -= pWin->GetTextWidth( aAccText ) + 3*nExtra;
                        nMaxItemTextWidth -= rRenderContext.GetTextWidth(aAccText) + 3 * nExtra;
                    }
                    if (!IsMenuBar() && pData->pSubMenu)
                    {
                        nMaxItemTextWidth -= nFontHeight - nExtra;
                    }
                    OUString aItemText( getShortenedString( pData->aText, pWin, nMaxItemTextWidth ) );
                    pWin->DrawCtrlText( aTmpPos, aItemText, 0, aItemText.getLength(), nStyle, pVector, pDisplayText );
                    if( bSetTmpBackground )
                        pWin->SetBackground();
                    OUString aItemText(getShortenedString(pData->aText, rRenderContext, nMaxItemTextWidth));
                    rRenderContext.DrawCtrlText(aTmpPos, aItemText, 0, aItemText.getLength(), nStyle, pVector, pDisplayText);
                    if (bSetTmpBackground)
                        rRenderContext.SetBackground();
                }

                // Accel
                if (!bLayout && !IsMenuBar() && pData->aAccelKey.GetCode() && !ImplAccelDisabled())
                {
                    OUString aAccText = pData->aAccelKey.GetName();
                    aTmpPos.X() = aOutSz.Width() - pWin->GetTextWidth( aAccText );
                    aTmpPos.X() = aOutSz.Width() - rRenderContext.GetTextWidth(aAccText);
                    aTmpPos.X() -= 4*nExtra;

                    aTmpPos.X() -= nOuterSpaceX;
                    aTmpPos.Y() = aPos.Y();
                    aTmpPos.Y() += nTextOffsetY;
                    pWin->DrawCtrlText( aTmpPos, aAccText, 0, aAccText.getLength(), nTextStyle );
                    rRenderContext.DrawCtrlText(aTmpPos, aAccText, 0, aAccText.getLength(), nTextStyle);
                }

                // SubMenu?
                if (!bLayout && !IsMenuBar() && pData->pSubMenu)
                {
                    bool bNativeOk = false;
                    if( pWin->IsNativeControlSupported( CTRL_MENU_POPUP,
                                                        PART_MENU_SUBMENU_ARROW ) )
                    if (rRenderContext.IsNativeControlSupported(CTRL_MENU_POPUP, PART_MENU_SUBMENU_ARROW))
                    {
                        ControlState nState = ControlState::NONE;
                        Size aTmpSz( 0, 0 );
                        long aSpacing = 0;

                        if( !ImplGetNativeSubmenuArrowSize( pWin,
                                                            aTmpSz, aSpacing ) )
                        if (!ImplGetNativeSubmenuArrowSize(rRenderContext, aTmpSz, aSpacing))
                        {
                            aTmpSz = Size( nFontHeight, nFontHeight );
                            aSpacing = nOuterSpaceX;
@@ -2045,14 +2015,10 @@ void Menu::ImplPaint( vcl::Window* pWin, sal_uInt16 nBorder, long nStartY, MenuI

                        Rectangle aItemRect( aTmpPos, aTmpSz );
                        MenupopupValue aVal( nTextPos-GUTTERBORDER, aItemRect );
                        bNativeOk = pWin->DrawNativeControl( CTRL_MENU_POPUP,
                                                             PART_MENU_SUBMENU_ARROW,
                                                             aItemRect,
                                                             nState,
                                                             aVal,
                                                             OUString() );
                        bNativeOk = rRenderContext.DrawNativeControl(CTRL_MENU_POPUP, PART_MENU_SUBMENU_ARROW,
                                                                     aItemRect, nState, aVal, OUString());
                    }
                    if( ! bNativeOk )
                    if (!bNativeOk)
                    {
                        aTmpPos.X() = aOutSz.Width() - nFontHeight + nExtra - nOuterSpaceX;
                        aTmpPos.Y() = aPos.Y();
@@ -2060,15 +2026,15 @@ void Menu::ImplPaint( vcl::Window* pWin, sal_uInt16 nBorder, long nStartY, MenuI
                        aTmpPos.Y() += ( pData->aSz.Height() / 2 ) - ( nFontHeight/4 );
                        if ( pData->nBits & MenuItemBits::POPUPSELECT )
                        {
                            pWin->SetTextColor( rSettings.GetMenuTextColor() );
                            rRenderContext.SetTextColor( rSettings.GetMenuTextColor() );
                            Point aTmpPos2( aPos );
                            aTmpPos2.X() = aOutSz.Width() - nFontHeight - nFontHeight/4;
                            aDecoView.DrawFrame(
                                Rectangle( aTmpPos2, Size( nFontHeight+nFontHeight/4, pData->aSz.Height() ) ), FRAME_DRAW_GROUP );
                        }
                        aDecoView.DrawSymbol(
                            Rectangle( aTmpPos, Size( nFontHeight/2, nFontHeight/2 ) ),
                            SymbolType::SPIN_RIGHT, pWin->GetTextColor(), nSymbolStyle );
                            Rectangle(aTmpPos, Size(nFontHeight / 2, nFontHeight / 2)),
                            SymbolType::SPIN_RIGHT, rRenderContext.GetTextColor(), nSymbolStyle);
                    }
                }

@@ -2077,9 +2043,9 @@ void Menu::ImplPaint( vcl::Window* pWin, sal_uInt16 nBorder, long nStartY, MenuI
                    // This restores the normal menu or menu bar text
                    // color for when it is no longer highlighted.
                    if (IsMenuBar())
                        pWin->SetTextColor( rSettings.GetMenuBarTextColor() );
                        rRenderContext.SetTextColor(rSettings.GetMenuBarTextColor());
                    else
                        pWin->SetTextColor( rSettings.GetMenuTextColor() );
                        rRenderContext.SetTextColor(rSettings.GetMenuTextColor());
                }
            }
            if( bLayout )
@@ -2106,21 +2072,21 @@ void Menu::ImplPaint( vcl::Window* pWin, sal_uInt16 nBorder, long nStartY, MenuI
        Size aLogoSz = pLogo->aBitmap.GetSizePixel();

        Rectangle aRect( Point( 0, 0 ), Point( aLogoSz.Width()-1, aOutSz.Height() ) );
        if ( pWin->GetColorCount() >= 256 )
        if (rRenderContext.GetColorCount() >= 256)
        {
            Gradient aGrad( GradientStyle_LINEAR, pLogo->aStartColor, pLogo->aEndColor );
            aGrad.SetAngle( 1800 );
            aGrad.SetBorder( 15 );
            pWin->DrawGradient( aRect, aGrad );
            rRenderContext.DrawGradient(aRect, aGrad);
        }
        else
        {
            pWin->SetFillColor( pLogo->aStartColor );
            pWin->DrawRect( aRect );
            rRenderContext.SetFillColor(pLogo->aStartColor);
            rRenderContext.DrawRect(aRect);
        }

        Point aLogoPos( 0, aOutSz.Height() - aLogoSz.Height() );
        pLogo->aBitmap.Draw( pWin, aLogoPos );
        pLogo->aBitmap.Draw(&rRenderContext, aLogoPos);
    }
}

@@ -2260,14 +2226,15 @@ void Menu::ImplFillLayoutData() const
    if( pWindow && pWindow->IsReallyVisible() )
    {
        mpLayoutData = new MenuLayoutData();
        if (IsMenuBar())
        pWindow->Invalidate();
        if (IsMenuBar()) // FIXME
        {
            ImplPaint( pWindow, 0, 0, 0, false, true );
            //ImplPaint(pWindow, 0, 0, 0, false, true);
        }
        else
        {
            MenuFloatingWindow* pFloat = static_cast<MenuFloatingWindow*>(pWindow.get());
            ImplPaint( pWindow, pFloat->nScrollerHeight, pFloat->ImplGetStartY(), 0, false, true );
            //MenuFloatingWindow* pFloat = static_cast<MenuFloatingWindow*>(pWindow.get()); // FIXME
            //ImplPaint(pWindow, pFloat->nScrollerHeight, pFloat->ImplGetStartY(), 0, false, true);
        }
    }
}
diff --git a/vcl/source/window/menubarwindow.cxx b/vcl/source/window/menubarwindow.cxx
index 9acf9f7..0a55e01 100644
--- a/vcl/source/window/menubarwindow.cxx
+++ b/vcl/source/window/menubarwindow.cxx
@@ -408,7 +408,7 @@ void MenuBarWindow::MouseMove( const MouseEvent& rMEvt )
    if ( rMEvt.IsLeaveWindow() )
    {
        if ( nRolloveredItem != ITEMPOS_INVALID && nRolloveredItem != nHighlightedItem )
            HighlightItem( nRolloveredItem, false );
            Invalidate();

        nRolloveredItem = ITEMPOS_INVALID;
        return;
@@ -420,10 +420,10 @@ void MenuBarWindow::MouseMove( const MouseEvent& rMEvt )
        if ( nRolloveredItem != nEntry  )
        {
            if ( nRolloveredItem != ITEMPOS_INVALID )
                HighlightItem( nRolloveredItem, false );
                Invalidate();

            nRolloveredItem = nEntry;
            HighlightItem( nRolloveredItem, true );
            Invalidate();
        }
        return;
    }
@@ -507,7 +507,7 @@ void MenuBarWindow::ChangeHighlightItem( sal_uInt16 n, bool bSelectEntry, bool b
    if ( nHighlightedItem != ITEMPOS_INVALID )
    {
        if ( nHighlightedItem != nRolloveredItem )
            HighlightItem( nHighlightedItem, false );
            Invalidate();

        pMenu->ImplCallEventListeners( VCLEVENT_MENU_DEHIGHLIGHT, nHighlightedItem );
    }
@@ -515,9 +515,9 @@ void MenuBarWindow::ChangeHighlightItem( sal_uInt16 n, bool bSelectEntry, bool b
    nHighlightedItem = (sal_uInt16)n;
    DBG_ASSERT( ( nHighlightedItem == ITEMPOS_INVALID ) || pMenu->ImplIsVisible( nHighlightedItem ), "ChangeHighlightItem: Not visible!" );
    if ( nHighlightedItem != ITEMPOS_INVALID )
        HighlightItem( nHighlightedItem, true );
        Invalidate();
    else if ( nRolloveredItem != ITEMPOS_INVALID )
        HighlightItem( nRolloveredItem, true );
        Invalidate();
    pMenu->ImplCallHighlight(nHighlightedItem);

    if( mbAutoPopup )
@@ -563,113 +563,111 @@ static int ImplGetTopDockingAreaHeight( vcl::Window *pWindow )
    return 0;
}

static void ImplAddNWFSeparator( vcl::Window *pThis, const MenubarValue& rMenubarValue )
static void ImplAddNWFSeparator(vcl::RenderContext& rRenderContext, const MenubarValue& rMenubarValue )
{
    // add a separator if
    // - we have an adjacent docking area
    // - and if toolbars would draw them as well (mbDockingAreaSeparateTB must not be set, see dockingarea.cxx)
    if( rMenubarValue.maTopDockingAreaHeight && !ImplGetSVData()->maNWFData.mbDockingAreaSeparateTB && !ImplGetSVData()->maNWFData.mbDockingAreaAvoidTBFrames )
    if (rMenubarValue.maTopDockingAreaHeight
       && !ImplGetSVData()->maNWFData.mbDockingAreaSeparateTB
       && !ImplGetSVData()->maNWFData.mbDockingAreaAvoidTBFrames)
    {
        // note: the menubar only provides the upper (dark) half of it, the rest (bright part) is drawn by the docking area

        pThis->SetLineColor( pThis->GetSettings().GetStyleSettings().GetSeparatorColor() );
        rRenderContext.SetLineColor(rRenderContext.GetSettings().GetStyleSettings().GetSeparatorColor());
        Point aPt;
        Rectangle aRect( aPt, pThis->GetOutputSizePixel() );
        pThis->DrawLine( aRect.BottomLeft(), aRect.BottomRight() );
        Rectangle aRect(aPt, rRenderContext.GetOutputSizePixel());
        rRenderContext.DrawLine(aRect.BottomLeft(), aRect.BottomRight());
    }
}

void MenuBarWindow::HighlightItem( sal_uInt16 nPos, bool bHighlight )
void MenuBarWindow::HighlightItem(vcl::RenderContext& rRenderContext, sal_uInt16 nPos, bool bHighlight)
{
    if( ! pMenu )
    if (!pMenu)
        return;

    long nX = 0;
    size_t nCount = pMenu->pItemList->size();
    for ( size_t n = 0; n < nCount; n++ )
    for (size_t n = 0; n < nCount; n++)
    {
        MenuItemData* pData = pMenu->pItemList->GetDataFromPos( n );
        if ( n == nPos )
        MenuItemData* pData = pMenu->pItemList->GetDataFromPos(n);
        if (n == nPos)
        {
            if ( pData->eType != MenuItemType::SEPARATOR )
            if (pData->eType != MenuItemType::SEPARATOR)
            {
                // #107747# give menuitems the height of the menubar
                Rectangle aRect = Rectangle( Point( nX, 1 ), Size( pData->aSz.Width(), GetOutputSizePixel().Height()-2 ) );
                Push( PushFlags::CLIPREGION );
                IntersectClipRegion( aRect );
                Rectangle aRect = Rectangle(Point(nX, 1), Size(pData->aSz.Width(), GetOutputSizePixel().Height() - 2));
                rRenderContext.Push(PushFlags::CLIPREGION);
                IntersectClipRegion(aRect);
                bool bRollover = bHighlight && nPos != nHighlightedItem;
                if ( bHighlight )
                if (bHighlight)
                {
                    if( IsNativeControlSupported( CTRL_MENUBAR, PART_MENU_ITEM ) &&
                        IsNativeControlSupported( CTRL_MENUBAR, PART_ENTIRE_CONTROL ) )
                    if (rRenderContext.IsNativeControlSupported(CTRL_MENUBAR, PART_MENU_ITEM) &&
                        rRenderContext.IsNativeControlSupported(CTRL_MENUBAR, PART_ENTIRE_CONTROL))
                    {
                        // draw background (transparency)
                        MenubarValue aControlValue;
                        aControlValue.maTopDockingAreaHeight = ImplGetTopDockingAreaHeight( this );
                        aControlValue.maTopDockingAreaHeight = ImplGetTopDockingAreaHeight(this);

                        if ( !Application::GetSettings().GetStyleSettings().GetPersonaHeader().IsEmpty() )
                            Erase();
                        if (!Application::GetSettings().GetStyleSettings().GetPersonaHeader().IsEmpty())
                            rRenderContext.Erase();
                        else
                        {
                            Point tmp(0,0);
                            Rectangle aBgRegion( tmp, GetOutputSizePixel() );
                            DrawNativeControl( CTRL_MENUBAR, PART_ENTIRE_CONTROL,
                                    aBgRegion,
                                    ControlState::ENABLED,
                                    aControlValue,
                                    OUString() );
                            Rectangle aBgRegion(Point(), GetOutputSizePixel());
                            rRenderContext.DrawNativeControl(CTRL_MENUBAR, PART_ENTIRE_CONTROL, aBgRegion,
                                                             ControlState::ENABLED, aControlValue, OUString() );
                        }

                        ImplAddNWFSeparator( this, aControlValue );
                        ImplAddNWFSeparator(rRenderContext, aControlValue);

                        // draw selected item
                        ControlState nState = ControlState::ENABLED;
                        if ( bRollover )
                        if (bRollover)
                            nState |= ControlState::ROLLOVER;
                        else
                            nState |= ControlState::SELECTED;
                        DrawNativeControl( CTRL_MENUBAR, PART_MENU_ITEM,
                                           aRect,
                                           nState,
                                           aControlValue,
                                           OUString() );
                        rRenderContext.DrawNativeControl(CTRL_MENUBAR, PART_MENU_ITEM, aRect,
                                                         nState, aControlValue, OUString());
                    }
                    else
                    {
                        if ( bRollover )
                            SetFillColor( GetSettings().GetStyleSettings().GetMenuBarRolloverColor() );
                        if (bRollover)
                            rRenderContext.SetFillColor(rRenderContext.GetSettings().GetStyleSettings().GetMenuBarRolloverColor());
                        else
                            SetFillColor( GetSettings().GetStyleSettings().GetMenuHighlightColor() );
                        SetLineColor();
                        DrawRect( aRect );
                            rRenderContext.SetFillColor(rRenderContext.GetSettings().GetStyleSettings().GetMenuHighlightColor());
                        rRenderContext.SetLineColor();
                        rRenderContext.DrawRect(aRect);
                    }
                }
                else
                {
                    if( IsNativeControlSupported( CTRL_MENUBAR, PART_ENTIRE_CONTROL) )
                    if (rRenderContext.IsNativeControlSupported(CTRL_MENUBAR, PART_ENTIRE_CONTROL))
                    {
                        MenubarValue aMenubarValue;
                        aMenubarValue.maTopDockingAreaHeight = ImplGetTopDockingAreaHeight( this );
                        aMenubarValue.maTopDockingAreaHeight = ImplGetTopDockingAreaHeight(this);

                        if ( !Application::GetSettings().GetStyleSettings().GetPersonaHeader().IsEmpty() )
                            Erase( aRect );
                        if (!Application::GetSettings().GetStyleSettings().GetPersonaHeader().IsEmpty())
                        {
                            rRenderContext.Erase(aRect);
                        }
                        else
                        {
                            // use full window size to get proper gradient
                            // but clip accordingly
                            Point aPt;
                            Rectangle aCtrlRect( aPt, GetOutputSizePixel() );

                            DrawNativeControl( CTRL_MENUBAR, PART_ENTIRE_CONTROL, aCtrlRect, ControlState::ENABLED, aMenubarValue, OUString() );
                            Rectangle aCtrlRect(aPt, rRenderContext.GetOutputSizePixel());
                            rRenderContext.DrawNativeControl(CTRL_MENUBAR, PART_ENTIRE_CONTROL, aCtrlRect, ControlState::ENABLED, aMenubarValue, OUString());
                        }

                        ImplAddNWFSeparator( this, aMenubarValue );
                        ImplAddNWFSeparator(rRenderContext, aMenubarValue);
                    }
                    else
                        Erase( aRect );
                    {
                        rRenderContext.Erase(aRect);
                    }
                }
                Pop();
                pMenu->ImplPaint( this, 0, 0, pData, bHighlight, false, bRollover );
                rRenderContext.Pop();
                pMenu->ImplPaint(rRenderContext, 0, 0, pData, bHighlight, false, bRollover);
            }
            return;
        }
@@ -870,52 +868,53 @@ bool MenuBarWindow::HandleKeyEvent( const KeyEvent& rKEvent, bool bFromMenu )
    return bDone;
}

void MenuBarWindow::Paint( vcl::RenderContext& /*rRenderContext*/, const Rectangle& )
void MenuBarWindow::Paint(vcl::RenderContext& rRenderContext, const Rectangle&)
{
    if( ! pMenu )
    if (!pMenu)
        return;

    // no VCL paint if native menus
    if( pMenu->ImplGetSalMenu() && pMenu->ImplGetSalMenu()->VisibleMenuBar() )
    if (pMenu->ImplGetSalMenu() && pMenu->ImplGetSalMenu()->VisibleMenuBar())
    {
        ImplGetFrame()->DrawMenuBar();
        return;
    }

    if( IsNativeControlSupported( CTRL_MENUBAR, PART_ENTIRE_CONTROL) )
    if (rRenderContext.IsNativeControlSupported(CTRL_MENUBAR, PART_ENTIRE_CONTROL))
    {
        MenubarValue aMenubarValue;
        aMenubarValue.maTopDockingAreaHeight = ImplGetTopDockingAreaHeight( this );

        if ( !Application::GetSettings().GetStyleSettings().GetPersonaHeader().IsEmpty() )
            Erase();
        if (!Application::GetSettings().GetStyleSettings().GetPersonaHeader().IsEmpty())
        {
            rRenderContext.Erase();
        }
        else
        {
            Point aPt;
            Rectangle aCtrlRegion( aPt, GetOutputSizePixel() );

            DrawNativeControl( CTRL_MENUBAR, PART_ENTIRE_CONTROL, aCtrlRegion, ControlState::ENABLED, aMenubarValue, OUString() );
            Rectangle aCtrlRegion(aPt, rRenderContext.GetOutputSizePixel());
            rRenderContext.DrawNativeControl(CTRL_MENUBAR, PART_ENTIRE_CONTROL, aCtrlRegion,
                                             ControlState::ENABLED, aMenubarValue, OUString());
        }

        ImplAddNWFSeparator( this, aMenubarValue );
        ImplAddNWFSeparator(rRenderContext, aMenubarValue);
    }
    SetFillColor( GetSettings().GetStyleSettings().GetMenuColor() );
    pMenu->ImplPaint( this, 0 );
    if ( nHighlightedItem != ITEMPOS_INVALID )
        HighlightItem( nHighlightedItem, true );
    rRenderContext.SetFillColor(rRenderContext.GetSettings().GetStyleSettings().GetMenuColor());
    pMenu->ImplPaint(rRenderContext, 0);
    if (nHighlightedItem != ITEMPOS_INVALID)
        HighlightItem(rRenderContext, nHighlightedItem, true);

    // in high contrast mode draw a separating line on the lower edge
    if( ! IsNativeControlSupported( CTRL_MENUBAR, PART_ENTIRE_CONTROL) &&
        GetSettings().GetStyleSettings().GetHighContrastMode() )
    if (!rRenderContext.IsNativeControlSupported(CTRL_MENUBAR, PART_ENTIRE_CONTROL) &&
        rRenderContext.GetSettings().GetStyleSettings().GetHighContrastMode())
    {
        Push( PushFlags::LINECOLOR | PushFlags::MAPMODE );
        SetLineColor( Color( COL_WHITE ) );
        SetMapMode( MapMode( MAP_PIXEL ) );
        rRenderContext.Push(PushFlags::LINECOLOR | PushFlags::MAPMODE);
        rRenderContext.SetLineColor(Color(COL_WHITE));
        rRenderContext.SetMapMode(MapMode(MAP_PIXEL));
        Size aSize = GetSizePixel();
        DrawLine( Point( 0, aSize.Height()-1 ), Point( aSize.Width()-1, aSize.Height()-1 ) );
        Pop();
        rRenderContext.DrawLine(Point(0, aSize.Height() - 1), Point(aSize.Width() - 1, aSize.Height() - 1));
        rRenderContext.Pop();
    }

}

void MenuBarWindow::Resize()
diff --git a/vcl/source/window/menubarwindow.hxx b/vcl/source/window/menubarwindow.hxx
index 5a6f2e9..a248bca 100644
--- a/vcl/source/window/menubarwindow.hxx
+++ b/vcl/source/window/menubarwindow.hxx
@@ -87,7 +87,7 @@ private:

    std::map< sal_uInt16, AddButtonEntry > m_aAddButtons;

    void            HighlightItem( sal_uInt16 nPos, bool bHighlight );
    void            HighlightItem(vcl::RenderContext& rRenderContext, sal_uInt16 nPos, bool bHighlight);
    virtual void    ChangeHighlightItem(sal_uInt16 n, bool bSelectPopupEntry, bool bAllowRestoreFocus = true, bool bDefaultToDocument = true) SAL_OVERRIDE;

    sal_uInt16      ImplFindEntry( const Point& rMousePos ) const;
diff --git a/vcl/source/window/menufloatingwindow.cxx b/vcl/source/window/menufloatingwindow.cxx
index 247821c..26ef558 100644
--- a/vcl/source/window/menufloatingwindow.cxx
+++ b/vcl/source/window/menufloatingwindow.cxx
@@ -61,7 +61,7 @@ MenuFloatingWindow::MenuFloatingWindow( Menu* pMen, vcl::Window* pParent, WinBit

void MenuFloatingWindow::doShutdown()
{
    if( pMenu )
    if (pMenu)
    {
        // #105373# notify toolkit that highlight was removed
        // otherwise the entry will not be read when the menu is opened again
@@ -77,11 +77,11 @@ void MenuFloatingWindow::doShutdown()
                if( pData && ( pData->pSubMenu == pMenu ) )
                    break;
            }
            if( i < nCount )
            if (i < nCount)
            {
                MenuFloatingWindow* pPWin = static_cast<MenuFloatingWindow*>(pMenu->pStartedFrom->ImplGetWindow());
                if( pPWin )
                    pPWin->HighlightItem( i, false );
                if (pPWin)
                    pPWin->Invalidate();
            }
        }

@@ -162,7 +162,7 @@ void MenuFloatingWindow::InitMenuClipRegion()

void MenuFloatingWindow::ImplHighlightItem( const MouseEvent& rMEvt, bool bMBDown )
{
    if( ! pMenu )
    if (!pMenu)
        return;

    long nY = nScrollerHeight + ImplGetSVData()->maNWFData.mnMenuFormatBorderY;
@@ -558,7 +558,7 @@ void MenuFloatingWindow::ImplScroll( bool bUp )
    if( ! pMenu )
        return;

    HighlightItem( nHighlightedItem, false );
    Invalidate();

    pMenu->ImplKillLayoutData();

@@ -608,7 +608,7 @@ void MenuFloatingWindow::ImplScroll( bool bUp )
        Scroll( 0, -nScrollEntryHeight, ImplCalcClipRegion( false ).GetBoundRect(), SCROLL_CLIP );
    }

    HighlightItem( nHighlightedItem, true );
    Invalidate();
}

void MenuFloatingWindow::ImplScroll( const Point& rMousePos )
@@ -663,7 +663,7 @@ void MenuFloatingWindow::ChangeHighlightItem( sal_uInt16 n, bool bStartPopupTime

    if ( nHighlightedItem != ITEMPOS_INVALID )
    {
        HighlightItem( nHighlightedItem, false );
        Invalidate();
        pMenu->ImplCallEventListeners( VCLEVENT_MENU_DEHIGHLIGHT, nHighlightedItem );
    }

@@ -686,12 +686,12 @@ void MenuFloatingWindow::ChangeHighlightItem( sal_uInt16 n, bool bStartPopupTime
                MenuFloatingWindow* pPWin = static_cast<MenuFloatingWindow*>(pMenu->pStartedFrom->ImplGetWindow());
                if( pPWin && pPWin->nHighlightedItem != i )
                {
                    pPWin->HighlightItem( i, true );
                    pPWin->Invalidate();
                    pPWin->nHighlightedItem = i;
                }
            }
        }
        HighlightItem( nHighlightedItem, true );
        Invalidate();
        pMenu->ImplCallHighlight( nHighlightedItem );
    }
    else
@@ -710,26 +710,26 @@ void MenuFloatingWindow::ChangeHighlightItem( sal_uInt16 n, bool bStartPopupTime
    }
}

void MenuFloatingWindow::HighlightItem( sal_uInt16 nPos, bool bHighlight )
void MenuFloatingWindow::HighlightItem(vcl::RenderContext& rRenderContext, sal_uInt16 nPos, bool bHighlight)
{
    if( ! pMenu )
    if (!pMenu)
        return;

    Size    aSz = GetOutputSizePixel();
    long    nStartY = ImplGetStartY();
    long    nY = nScrollerHeight + nStartY + ImplGetSVData()->maNWFData.mnMenuFormatBorderY;
    long    nX = 0;
    Size aSz = GetOutputSizePixel();
    long nStartY = ImplGetStartY();
    long nY = nScrollerHeight + nStartY + ImplGetSVData()->maNWFData.mnMenuFormatBorderY;
    long nX = 0;

    if ( pMenu->pLogo )
    if (pMenu->pLogo)
        nX = pMenu->pLogo->aBitmap.GetSizePixel().Width();

    int nOuterSpaceX = ImplGetSVData()->maNWFData.mnMenuFormatBorderX;

    size_t nCount = pMenu->pItemList->size();
    for ( size_t n = 0; n < nCount; n++ )
    for (size_t n = 0; n < nCount; n++)
    {
        MenuItemData* pData = pMenu->pItemList->GetDataFromPos( n );
        if ( n == nPos )
        MenuItemData* pData = pMenu->pItemList->GetDataFromPos(n);
        if (n == nPos)
        {
            DBG_ASSERT( pMenu->ImplIsVisible( n ), "Highlight: Item not visible!" );
            if ( pData->eType != MenuItemType::SEPARATOR )
@@ -738,64 +738,65 @@ void MenuFloatingWindow::HighlightItem( sal_uInt16 nPos, bool bHighlight )
                Color oldLineColor;
                bool bDrawItemRect = true;

                Rectangle aItemRect( Point( nX+nOuterSpaceX, nY ), Size( aSz.Width()-2*nOuterSpaceX, pData->aSz.Height() ) );
                if ( pData->nBits & MenuItemBits::POPUPSELECT )
                Rectangle aItemRect(Point(nX + nOuterSpaceX, nY), Size(aSz.Width() - 2 * nOuterSpaceX, pData->aSz.Height()));
                if (pData->nBits & MenuItemBits::POPUPSELECT)
                {
                    long nFontHeight = GetTextHeight();
                    aItemRect.Right() -= nFontHeight + nFontHeight/4;
                    long nFontHeight = rRenderContext.GetTextHeight();
                    aItemRect.Right() -= nFontHeight + nFontHeight / 4;
                }

                if( IsNativeControlSupported( CTRL_MENU_POPUP, PART_ENTIRE_CONTROL ) )
                if (rRenderContext.IsNativeControlSupported(CTRL_MENU_POPUP, PART_ENTIRE_CONTROL))
                {
                    Size aPxSize( GetOutputSizePixel() );
                    Push( PushFlags::CLIPREGION );
                    IntersectClipRegion( Rectangle( Point( nX, nY ), Size( aSz.Width(), pData->aSz.Height() ) ) );
                    Rectangle aCtrlRect( Point( nX, 0 ), Size( aPxSize.Width()-nX, aPxSize.Height() ) );
                    MenupopupValue aVal( pMenu->nTextPos-GUTTERBORDER, aItemRect );
                    DrawNativeControl( CTRL_MENU_POPUP, PART_ENTIRE_CONTROL,
                                       aCtrlRect,
                                       ControlState::ENABLED,
                                       aVal,
                                       OUString() );
                    if( bHighlight &&
                        IsNativeControlSupported( CTRL_MENU_POPUP, PART_MENU_ITEM ) )
                    Size aPxSize(rRenderContext.GetOutputSizePixel());
                    rRenderContext.Push(PushFlags::CLIPREGION);
                    rRenderContext.IntersectClipRegion(Rectangle(Point(nX, nY), Size(aSz.Width(), pData->aSz.Height())));
                    Rectangle aCtrlRect(Point(nX, 0), Size(aPxSize.Width() - nX, aPxSize.Height()));
                    MenupopupValue aVal(pMenu->nTextPos - GUTTERBORDER, aItemRect);
                    rRenderContext.DrawNativeControl(CTRL_MENU_POPUP, PART_ENTIRE_CONTROL, aCtrlRect,
                                                     ControlState::ENABLED, aVal, OUString());
                    if (bHighlight &&
                        rRenderContext.IsNativeControlSupported(CTRL_MENU_POPUP, PART_MENU_ITEM))
                    {
                        bDrawItemRect = false;
                        if( !DrawNativeControl( CTRL_MENU_POPUP, PART_MENU_ITEM,
                        if (!rRenderContext.DrawNativeControl(CTRL_MENU_POPUP, PART_MENU_ITEM,
                                                        aItemRect,
                                                        ControlState::SELECTED | ( pData->bEnabled? ControlState::ENABLED: ControlState::NONE ),
                                                        aVal,
                                                        OUString() ) )
                                                        aVal, OUString()))
                        {
                            bDrawItemRect = bHighlight;
                        }
                    }
                    else
                        bDrawItemRect = bHighlight;
                    Pop();
                }
                if( bDrawItemRect )
                {
                    if ( bHighlight )
                    {
                        if( pData->bEnabled )
                            SetFillColor( GetSettings().GetStyleSettings().GetMenuHighlightColor() );
                        bDrawItemRect = bHighlight;
                    }
                    rRenderContext.Pop();
                }
                if (bDrawItemRect)
                {
                    if (bHighlight)
                    {
                        if (pData->bEnabled)
                        {
                            rRenderContext.SetFillColor(rRenderContext.GetSettings().GetStyleSettings().GetMenuHighlightColor());
                        }
                        else
                        {
                            SetFillColor();
                            oldLineColor = GetLineColor();
                            SetLineColor( GetSettings().GetStyleSettings().GetMenuHighlightColor() );
                            rRenderContext.SetFillColor();
                            oldLineColor = rRenderContext.GetLineColor();
                            rRenderContext.SetLineColor(rRenderContext.GetSettings().GetStyleSettings().GetMenuHighlightColor());
                            bRestoreLineColor = true;
                        }
                    }
                    else
                        SetFillColor( GetSettings().GetStyleSettings().GetMenuColor() );

                    DrawRect( aItemRect );
                    {
                        rRenderContext.SetFillColor(rRenderContext.GetSettings().GetStyleSettings().GetMenuColor());
                    }
                    rRenderContext.DrawRect(aItemRect);
                }
                pMenu->ImplPaint( this, nScrollerHeight, nStartY, pData, bHighlight );
                if( bRestoreLineColor )
                    SetLineColor( oldLineColor );
                pMenu->ImplPaint(rRenderContext, nScrollerHeight, nStartY, pData, bHighlight);
                if (bRestoreLineColor)
                    rRenderContext.SetLineColor(oldLineColor);
            }
            return;
        }
@@ -1082,34 +1083,32 @@ void MenuFloatingWindow::KeyInput( const KeyEvent& rKEvent )
    }
}

void MenuFloatingWindow::Paint( vcl::RenderContext& /*rRenderContext*/, const Rectangle& )
void MenuFloatingWindow::Paint( vcl::RenderContext& rRenderContext, const Rectangle& )
{
    if( ! pMenu )
    if (!pMenu)
        return;

    if( IsNativeControlSupported( CTRL_MENU_POPUP, PART_ENTIRE_CONTROL ) )
    if (rRenderContext.IsNativeControlSupported(CTRL_MENU_POPUP, PART_ENTIRE_CONTROL))
    {
        SetClipRegion();
        rRenderContext.SetClipRegion();
        long nX = pMenu->pLogo ? pMenu->pLogo->aBitmap.GetSizePixel().Width() : 0;
        Size aPxSize( GetOutputSizePixel() );
        Size aPxSize(rRenderContext.GetOutputSizePixel());
        aPxSize.Width() -= nX;
        ImplControlValue aVal( pMenu->nTextPos-GUTTERBORDER );
        DrawNativeControl( CTRL_MENU_POPUP, PART_ENTIRE_CONTROL,
                           Rectangle( Point( nX, 0 ), aPxSize ),
                           ControlState::ENABLED,
                           aVal,
                           OUString() );
        ImplControlValue aVal(pMenu->nTextPos - GUTTERBORDER);
        DrawNativeControl(CTRL_MENU_POPUP, PART_ENTIRE_CONTROL,
                          Rectangle(Point(nX, 0), aPxSize),
                          ControlState::ENABLED, aVal, OUString());
        InitMenuClipRegion();
    }
    if ( IsScrollMenu() )
    if (IsScrollMenu())
    {
        ImplDrawScroller( true );
        ImplDrawScroller( false );
        ImplDrawScroller(true);
        ImplDrawScroller(false);
    }
    SetFillColor( GetSettings().GetStyleSettings().GetMenuColor() );
    pMenu->ImplPaint( this, nScrollerHeight, ImplGetStartY() );
    if ( nHighlightedItem != ITEMPOS_INVALID )
        HighlightItem( nHighlightedItem, true );
    rRenderContext.SetFillColor(rRenderContext.GetSettings().GetStyleSettings().GetMenuColor());
    pMenu->ImplPaint(rRenderContext, nScrollerHeight, ImplGetStartY());
    if (nHighlightedItem != ITEMPOS_INVALID)
        HighlightItem(rRenderContext, nHighlightedItem, true);
}

void MenuFloatingWindow::ImplDrawScroller( bool bUp )
diff --git a/vcl/source/window/menufloatingwindow.hxx b/vcl/source/window/menufloatingwindow.hxx
index 030fde0..d0748e0 100644
--- a/vcl/source/window/menufloatingwindow.hxx
+++ b/vcl/source/window/menufloatingwindow.hxx
@@ -90,7 +90,7 @@ public:
    virtual void    MouseButtonUp( const MouseEvent& rMEvt ) SAL_OVERRIDE;
    virtual void    KeyInput( const KeyEvent& rKEvent ) SAL_OVERRIDE;
    virtual void    Command( const CommandEvent& rCEvt ) SAL_OVERRIDE;
    virtual void    Paint( vcl::RenderContext& /*rRenderContext*/, const Rectangle& rRect ) SAL_OVERRIDE;
    virtual void    Paint(vcl::RenderContext& rRenderContext, const Rectangle& rRect) SAL_OVERRIDE;
    virtual void    RequestHelp( const HelpEvent& rHEvt ) SAL_OVERRIDE;
    virtual void    Resize() SAL_OVERRIDE;

@@ -109,7 +109,7 @@ public:
    PopupMenu*      GetActivePopup() const  { return pActivePopup; }
    void            KillActivePopup( PopupMenu* pThisOnly = NULL );

    void            HighlightItem( sal_uInt16 nPos, bool bHighlight );
    void            HighlightItem(vcl::RenderContext& rRenderContext, sal_uInt16 nPos, bool bHighlight);
    void            ChangeHighlightItem( sal_uInt16 n, bool bStartPopupTimer );
    sal_uInt16          GetHighlightedItem() const { return nHighlightedItem; }