diff options
author | Caolán McNamara <caolanm@redhat.com> | 2020-12-03 15:54:45 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2020-12-04 15:57:41 +0100 |
commit | 51379fb3d46e5891bdaea0122bd62b0753663da3 (patch) | |
tree | 6c9e85ed41e6999bb3d9c5331da05dee2141ef0b /sw/source | |
parent | 30c54afbf5bf03da27db7f90b518817cd05e8ccd (diff) |
weld writer's FrameControl MenuButtons
Change-Id: I507b043672ffd102f85110bed221a05b756500db
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107174
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sw/source')
-rw-r--r-- | sw/source/uibase/docvw/FrameControlsManager.cxx | 22 | ||||
-rw-r--r-- | sw/source/uibase/docvw/HeaderFooterWin.cxx | 90 | ||||
-rw-r--r-- | sw/source/uibase/docvw/PageBreakWin.cxx | 69 | ||||
-rw-r--r-- | sw/source/uibase/docvw/UnfloatTableButton.cxx | 43 | ||||
-rw-r--r-- | sw/source/uibase/inc/FrameControl.hxx | 15 | ||||
-rw-r--r-- | sw/source/uibase/inc/HeaderFooterWin.hxx | 15 | ||||
-rw-r--r-- | sw/source/uibase/inc/PageBreakWin.hxx | 15 | ||||
-rw-r--r-- | sw/source/uibase/inc/UnfloatTableButton.hxx | 6 |
8 files changed, 156 insertions, 119 deletions
diff --git a/sw/source/uibase/docvw/FrameControlsManager.cxx b/sw/source/uibase/docvw/FrameControlsManager.cxx index 576033398827..2232ca7ed869 100644 --- a/sw/source/uibase/docvw/FrameControlsManager.cxx +++ b/sw/source/uibase/docvw/FrameControlsManager.cxx @@ -21,6 +21,8 @@ #include <OutlineContentVisibilityWin.hxx> #include <ndtxt.hxx> #include <IDocumentOutlineNodes.hxx> +#include <vcl/settings.hxx> +#include <vcl/svapp.hxx> using namespace std; @@ -177,10 +179,11 @@ void SwFrameControlsManager::SetUnfloatTableButton( const SwFlyFrame* pFlyFrame, pControl->ShowAll( bShow ); } -SwFrameMenuButtonBase::SwFrameMenuButtonBase( SwEditWin* pEditWin, const SwFrame* pFrame ) : - MenuButton( pEditWin, WB_DIALOGCONTROL ), - m_pEditWin( pEditWin ), - m_pFrame( pFrame ) +SwFrameMenuButtonBase::SwFrameMenuButtonBase(SwEditWin* pEditWin, const SwFrame* pFrame, + const OUString& rUIXMLDescription, const OString& rID) + : InterimItemWindow(pEditWin, rUIXMLDescription, rID) + , m_pEditWin(pEditWin) + , m_pFrame(pFrame) { } @@ -302,7 +305,16 @@ void SwFrameMenuButtonBase::dispose() { m_pEditWin.clear(); m_pFrame = nullptr; - MenuButton::dispose(); + m_xVirDev.disposeAndClear(); + InterimItemWindow::dispose(); +} + +void SwFrameMenuButtonBase::SetVirDevFont() +{ + // Get the font and configure it + vcl::Font aFont = Application::GetSettings().GetStyleSettings().GetToolFont(); + if (vcl::Window* pDefaultDevice = dynamic_cast<vcl::Window*>(Application::GetDefaultDevice())) + pDefaultDevice->SetPointFont(*m_xVirDev, aFont); } SwFrameControl::SwFrameControl( const VclPtr<vcl::Window> &pWindow ) diff --git a/sw/source/uibase/docvw/HeaderFooterWin.cxx b/sw/source/uibase/docvw/HeaderFooterWin.cxx index 7305a440d29a..0c4ed113f6c7 100644 --- a/sw/source/uibase/docvw/HeaderFooterWin.cxx +++ b/sw/source/uibase/docvw/HeaderFooterWin.cxx @@ -46,9 +46,9 @@ #include <vcl/canvastools.hxx> #include <vcl/menu.hxx> #include <vcl/metric.hxx> -#include <vcl/menubtn.hxx> #include <vcl/svapp.hxx> #include <vcl/settings.hxx> +#include <vcl/virdev.hxx> #include <memory> #define TEXT_PADDING 5 @@ -162,20 +162,20 @@ void SwFrameButtonPainter::PaintButton(drawinglayer::primitive2d::Primitive2DCon } SwHeaderFooterWin::SwHeaderFooterWin( SwEditWin* pEditWin, const SwFrame *pFrame, bool bHeader ) : - SwFrameMenuButtonBase( pEditWin, pFrame ), - m_aBuilder(nullptr, AllSettings::GetUIRootDir(), "modules/swriter/ui/headerfootermenu.ui", ""), + SwFrameMenuButtonBase(pEditWin, pFrame, "modules/swriter/ui/hfmenubutton.ui", "HFMenuButton"), + m_xMenuButton(m_xBuilder->weld_menu_button("menubutton")), + m_xPushButton(m_xBuilder->weld_button("button")), m_bIsHeader( bHeader ), - m_pPopupMenu(m_aBuilder.get_menu("menu")), m_pLine( nullptr ), m_bIsAppearing( false ), m_nFadeRate( 100 ), m_aFadeTimer( ) { - //FIXME RenderContext + m_xVirDev = m_xMenuButton->create_virtual_device(); + SetVirDevFont(); - // Get the font and configure it - vcl::Font aFont = Application::GetSettings().GetStyleSettings().GetToolFont(); - SetZoomedPointFont(*this, aFont); + m_xPushButton->connect_clicked(LINK(this, SwHeaderFooterWin, ClickHdl)); + m_xMenuButton->connect_selected(LINK(this, SwHeaderFooterWin, SelectHdl)); // Create the line control m_pLine = VclPtr<SwDashedLine>::Create(GetEditWin(), &SwViewOption::GetHeaderFooterMarkColor); @@ -185,17 +185,15 @@ SwHeaderFooterWin::SwHeaderFooterWin( SwEditWin* pEditWin, const SwFrame *pFrame // Rewrite the menu entries' text if (m_bIsHeader) { - m_pPopupMenu->SetItemText(m_pPopupMenu->GetItemId("edit"), SwResId(STR_FORMAT_HEADER)); - m_pPopupMenu->SetItemText(m_pPopupMenu->GetItemId("delete"), SwResId(STR_DELETE_HEADER)); + m_xMenuButton->set_item_label("edit", SwResId(STR_FORMAT_HEADER)); + m_xMenuButton->set_item_label("delete", SwResId(STR_DELETE_HEADER)); } else { - m_pPopupMenu->SetItemText(m_pPopupMenu->GetItemId("edit"), SwResId(STR_FORMAT_FOOTER)); - m_pPopupMenu->SetItemText(m_pPopupMenu->GetItemId("delete"), SwResId(STR_DELETE_FOOTER)); + m_xMenuButton->set_item_label("edit", SwResId(STR_FORMAT_FOOTER)); + m_xMenuButton->set_item_label("delete", SwResId(STR_DELETE_FOOTER)); } - SetPopupMenu(m_pPopupMenu); - m_aFadeTimer.SetTimeout(50); m_aFadeTimer.SetInvokeHandler(LINK(this, SwHeaderFooterWin, FadeHandler)); } @@ -207,9 +205,9 @@ SwHeaderFooterWin::~SwHeaderFooterWin( ) void SwHeaderFooterWin::dispose() { - m_pPopupMenu.clear(); - m_aBuilder.disposeBuilder(); m_pLine.disposeAndClear(); + m_xPushButton.reset(); + m_xMenuButton.reset(); SwFrameMenuButtonBase::dispose(); } @@ -234,12 +232,13 @@ void SwHeaderFooterWin::SetOffset(Point aOffset, tools::Long nXLineStart, tools: sal_Int32 nPos = m_sLabel.lastIndexOf("%1"); m_sLabel = m_sLabel.replaceAt(nPos, 2, pDesc->GetName()); + m_xMenuButton->set_accessible_name(m_sLabel); // Compute the text size and get the box position & size from it ::tools::Rectangle aTextRect; - GetTextBoundRect(aTextRect, m_sLabel); - ::tools::Rectangle aTextPxRect = LogicToPixel(aTextRect); - FontMetric aFontMetric = GetFontMetric(GetFont()); + m_xVirDev->GetTextBoundRect(aTextRect, m_sLabel); + ::tools::Rectangle aTextPxRect = m_xVirDev->LogicToPixel(aTextRect); + FontMetric aFontMetric = m_xVirDev->GetFontMetric(m_xVirDev->GetFont()); Size aBoxSize (aTextPxRect.GetWidth() + BUTTON_WIDTH + TEXT_PADDING * 2, aFontMetric.GetLineHeight() + TEXT_PADDING * 2 ); @@ -258,6 +257,9 @@ void SwHeaderFooterWin::SetOffset(Point aOffset, tools::Long nXLineStart, tools: // Set the position & Size of the window SetPosSizePixel(aBoxPos, aBoxSize); + m_xVirDev->SetOutputSizePixel(aBoxSize); + PaintButton(); + double nYLinePos = aBoxPos.Y(); if (!m_bIsHeader) nYLinePos += aBoxSize.Height(); @@ -268,6 +270,10 @@ void SwHeaderFooterWin::SetOffset(Point aOffset, tools::Long nXLineStart, tools: void SwHeaderFooterWin::ShowAll(bool bShow) { + bool bIsEmptyHeaderFooter = IsEmptyHeaderFooter(); + m_xMenuButton->set_visible(!bIsEmptyHeaderFooter); + m_xPushButton->set_visible(bIsEmptyHeaderFooter); + if (!PopupMenu::IsInExecute()) { m_bIsAppearing = bShow; @@ -288,21 +294,24 @@ bool SwHeaderFooterWin::Contains( const Point &rDocPt ) const return aLineRect.IsInside(rDocPt); } -void SwHeaderFooterWin::Paint(vcl::RenderContext& rRenderContext, const ::tools::Rectangle&) +void SwHeaderFooterWin::PaintButton() { + if (!m_xVirDev) + return; + // Use pixels for the rest of the drawing SetMapMode(MapMode(MapUnit::MapPixel)); drawinglayer::primitive2d::Primitive2DContainer aSeq; - const ::tools::Rectangle aRect(::tools::Rectangle(Point(0, 0), rRenderContext.PixelToLogic(GetSizePixel()))); + const ::tools::Rectangle aRect(::tools::Rectangle(Point(0, 0), m_xVirDev->PixelToLogic(GetSizePixel()))); SwFrameButtonPainter::PaintButton(aSeq, aRect, m_bIsHeader); // Create the text primitive basegfx::BColor aLineColor = SwViewOption::GetHeaderFooterMarkColor().getBColor(); B2DVector aFontSize; - FontAttribute aFontAttr = drawinglayer::primitive2d::getFontAttributeFromVclFont(aFontSize, rRenderContext.GetFont(), false, false); + FontAttribute aFontAttr = drawinglayer::primitive2d::getFontAttributeFromVclFont(aFontSize, m_xVirDev->GetFont(), false, false); - FontMetric aFontMetric = rRenderContext.GetFontMetric(rRenderContext.GetFont()); + FontMetric aFontMetric = m_xVirDev->GetFontMetric(m_xVirDev->GetFont()); double nTextOffsetY = aFontMetric.GetAscent() + TEXT_PADDING; Point aTextPos(TEXT_PADDING, nTextOffsetY); @@ -320,7 +329,8 @@ void SwHeaderFooterWin::Paint(vcl::RenderContext& rRenderContext, const ::tools: B2DSize(aRect.Right(), aRect.getHeight())); B2DPolygon aSign; - if (IsEmptyHeaderFooter()) + bool bIsEmptyHeaderFooter = IsEmptyHeaderFooter(); + if (bIsEmptyHeaderFooter) { // Create the + polygon double nLeft = aSignArea.getMinX() + TEXT_PADDING; @@ -367,7 +377,7 @@ void SwHeaderFooterWin::Paint(vcl::RenderContext& rRenderContext, const ::tools: // Create the processor and process the primitives const drawinglayer::geometry::ViewInformation2D aNewViewInfos; std::unique_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor( - drawinglayer::processor2d::createBaseProcessor2DFromOutputDevice(rRenderContext, aNewViewInfos)); + drawinglayer::processor2d::createBaseProcessor2DFromOutputDevice(*m_xVirDev, aNewViewInfos)); // TODO Ghost it all if needed drawinglayer::primitive2d::Primitive2DContainer aGhostedSeq(1); @@ -381,6 +391,11 @@ void SwHeaderFooterWin::Paint(vcl::RenderContext& rRenderContext, const ::tools: new drawinglayer::primitive2d::ModifiedColorPrimitive2D(aSeq, aBColorModifier)); pProcessor->process(aGhostedSeq); + + if (bIsEmptyHeaderFooter) + m_xPushButton->set_custom_button(m_xVirDev.get()); + else + m_xMenuButton->set_custom_button(m_xVirDev.get()); } bool SwHeaderFooterWin::IsEmptyHeaderFooter( ) const @@ -476,23 +491,22 @@ void SwHeaderFooterWin::SetReadonly( bool bReadonly ) ShowAll( !bReadonly ); } -void SwHeaderFooterWin::MouseButtonDown( const MouseEvent& rMEvt ) +IMPL_LINK_NOARG(SwHeaderFooterWin, ClickHdl, weld::Button&, void) { - if (IsEmptyHeaderFooter()) - { - SwView& rView = GetEditWin()->GetView(); - SwWrtShell& rSh = rView.GetWrtShell(); + SwView& rView = GetEditWin()->GetView(); + SwWrtShell& rSh = rView.GetWrtShell(); - const OUString& rStyleName = GetPageFrame()->GetPageDesc()->GetName(); - rSh.ChangeHeaderOrFooter( rStyleName, m_bIsHeader, true, false ); - } - else - MenuButton::MouseButtonDown( rMEvt ); + const OUString& rStyleName = GetPageFrame()->GetPageDesc()->GetName(); + rSh.ChangeHeaderOrFooter( rStyleName, m_bIsHeader, true, false ); + + m_xPushButton->hide(); + m_xMenuButton->show(); + PaintButton(); } -void SwHeaderFooterWin::Select() +IMPL_LINK(SwHeaderFooterWin, SelectHdl, const OString&, rIdent, void) { - ExecuteCommand(GetCurItemIdent()); + ExecuteCommand(rIdent); } IMPL_LINK_NOARG(SwHeaderFooterWin, FadeHandler, Timer *, void) @@ -513,7 +527,7 @@ IMPL_LINK_NOARG(SwHeaderFooterWin, FadeHandler, Timer *, void) m_pLine->Show(false); } else - Invalidate(); + PaintButton(); if (IsVisible() && m_nFadeRate > 0 && m_nFadeRate < 100) m_aFadeTimer.Start(); diff --git a/sw/source/uibase/docvw/PageBreakWin.cxx b/sw/source/uibase/docvw/PageBreakWin.cxx index 651ae3283df4..6167369ba219 100644 --- a/sw/source/uibase/docvw/PageBreakWin.cxx +++ b/sw/source/uibase/docvw/PageBreakWin.cxx @@ -24,6 +24,7 @@ #include <pagefrm.hxx> #include <PostItMgr.hxx> #include <FrameControlsManager.hxx> +#include <strings.hrc> #include <uiitems.hxx> #include <view.hxx> #include <viewopt.hxx> @@ -95,25 +96,27 @@ namespace } SwPageBreakWin::SwPageBreakWin( SwEditWin* pEditWin, const SwFrame *pFrame ) : - SwFrameMenuButtonBase( pEditWin, pFrame ), - m_aBuilder(nullptr, AllSettings::GetUIRootDir(), "modules/swriter/ui/pagebreakmenu.ui", ""), - m_pPopupMenu(m_aBuilder.get_menu("menu")), + SwFrameMenuButtonBase(pEditWin, pFrame, "modules/swriter/ui/pbmenubutton.ui", "PBMenuButton"), + m_xMenuButton(m_xBuilder->weld_menu_button("menubutton")), m_pLine( nullptr ), m_bIsAppearing( false ), m_nFadeRate( 100 ), m_nDelayAppearing( 0 ), m_bDestroyed( false ) { + m_xMenuButton->connect_toggled(LINK(this, SwPageBreakWin, ToggleHdl)); + m_xMenuButton->connect_selected(LINK(this, SwPageBreakWin, SelectHdl)); + m_xMenuButton->set_accessible_name(SwResId(STR_PAGE_BREAK_BUTTON)); + + m_xVirDev = m_xMenuButton->create_virtual_device(); + SetVirDevFont(); + // Use pixels for the rest of the drawing - SetMapMode( MapMode ( MapUnit::MapPixel ) ); + m_xVirDev->SetMapMode( MapMode ( MapUnit::MapPixel ) ); // Create the line control m_pLine = VclPtr<SwBreakDashedLine>::Create( GetEditWin(), &SwViewOption::GetPageBreakColor, this ); - // Set the popup menu - m_pPopupMenu->SetDeactivateHdl( LINK( this, SwPageBreakWin, HideHandler ) ); - SetPopupMenu(m_pPopupMenu); - m_aFadeTimer.SetTimeout( 50 ); m_aFadeTimer.SetInvokeHandler( LINK( this, SwPageBreakWin, FadeHandler ) ); } @@ -129,15 +132,17 @@ void SwPageBreakWin::dispose() m_aFadeTimer.Stop(); m_pLine.disposeAndClear(); - m_pPopupMenu.clear(); - m_aBuilder.disposeBuilder(); + m_xMenuButton.reset(); SwFrameMenuButtonBase::dispose(); } -void SwPageBreakWin::Paint(vcl::RenderContext& rRenderContext, const ::tools::Rectangle&) +void SwPageBreakWin::PaintButton() { - const ::tools::Rectangle aRect(::tools::Rectangle(Point(0, 0), rRenderContext.PixelToLogic(GetSizePixel()))); + if (!m_xVirDev) + return; + + const ::tools::Rectangle aRect(::tools::Rectangle(Point(0, 0), m_xVirDev->PixelToLogic(GetSizePixel()))); // Properly paint the control BColor aColor = SwViewOption::GetPageBreakColor().getBColor(); @@ -209,17 +214,18 @@ void SwPageBreakWin::Paint(vcl::RenderContext& rRenderContext, const ::tools::Re // Create the processor and process the primitives const drawinglayer::geometry::ViewInformation2D aNewViewInfos; std::unique_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor( - drawinglayer::processor2d::createBaseProcessor2DFromOutputDevice(rRenderContext, aNewViewInfos)); + drawinglayer::processor2d::createBaseProcessor2DFromOutputDevice(*m_xVirDev, aNewViewInfos)); pProcessor->process(aGhostedSeq); + + m_xMenuButton->set_custom_button(m_xVirDev.get()); } -void SwPageBreakWin::Select() +IMPL_LINK(SwPageBreakWin, SelectHdl, const OString&, rIdent, void) { SwFrameControlPtr pThis = GetEditWin()->GetFrameControlsManager( ).GetControl( FrameControlType::PageBreak, GetFrame() ); - OString sIdent = GetCurItemIdent(); - if (sIdent == "edit") + if (rIdent == "edit") { const SwLayoutFrame* pBodyFrame = static_cast< const SwLayoutFrame* >( GetPageFrame()->Lower() ); while ( pBodyFrame && !pBodyFrame->IsBodyFrame() ) @@ -271,7 +277,7 @@ void SwPageBreakWin::Select() pEditWin->GrabFocus( ); } } - else if (sIdent == "delete") + else if (rIdent == "delete") { const SwLayoutFrame* pBodyFrame = static_cast< const SwLayoutFrame* >( GetPageFrame()->Lower() ); while ( pBodyFrame && !pBodyFrame->IsBodyFrame() ) @@ -307,25 +313,6 @@ void SwPageBreakWin::Select() Fade( false ); } -void SwPageBreakWin::MouseMove( const MouseEvent& rMEvt ) -{ - if ( rMEvt.IsLeaveWindow() ) - { - // don't fade if we just move to the 'line', or the popup menu is open - Point aEventPos( rMEvt.GetPosPixel() + rMEvt.GetPosPixel() ); - if ( !Contains( aEventPos ) && !PopupMenu::IsInExecute() ) - Fade( false ); - } - else if ( !IsVisible() ) - Fade( true ); -} - -void SwPageBreakWin::Activate( ) -{ - Fade( true ); - MenuButton::Activate(); -} - void SwPageBreakWin::UpdatePosition(const std::optional<Point>& xEvtPt) { if ( xEvtPt ) @@ -390,6 +377,7 @@ void SwPageBreakWin::UpdatePosition(const std::optional<Point>& xEvtPt) // Set the button position Point aBtnPos( nBtnLeft, nYLineOffset - BUTTON_HEIGHT / 2 ); SetPosSizePixel( aBtnPos, aBtnSize ); + m_xVirDev->SetOutputSizePixel(aBtnSize); // Set the line position Point aLinePos( nLineLeft, nYLineOffset - 5 ); @@ -429,11 +417,10 @@ void SwPageBreakWin::Fade( bool bFadeIn ) m_aFadeTimer.Start( ); } -IMPL_LINK_NOARG(SwPageBreakWin, HideHandler, Menu *, bool) +IMPL_LINK(SwPageBreakWin, ToggleHdl, weld::ToggleButton&, rMenuButton, void) { - Fade( false ); - - return false; + // hide on dropdown, draw fully unfaded if dropdown before fully faded in + Fade(rMenuButton.get_active()); } IMPL_LINK_NOARG(SwPageBreakWin, FadeHandler, Timer *, void) @@ -458,7 +445,7 @@ IMPL_LINK_NOARG(SwPageBreakWin, FadeHandler, Timer *, void) else { UpdatePosition(); - Invalidate(); + PaintButton(); } if (IsVisible( ) && m_nFadeRate > 0 && m_nFadeRate < 100) diff --git a/sw/source/uibase/docvw/UnfloatTableButton.cxx b/sw/source/uibase/docvw/UnfloatTableButton.cxx index 4f7bda6566f6..24e6780e1ed2 100644 --- a/sw/source/uibase/docvw/UnfloatTableButton.cxx +++ b/sw/source/uibase/docvw/UnfloatTableButton.cxx @@ -46,20 +46,31 @@ #define BUTTON_WIDTH 12 UnfloatTableButton::UnfloatTableButton(SwEditWin* pEditWin, const SwFrame* pFrame) - : SwFrameMenuButtonBase(pEditWin, pFrame) + : SwFrameMenuButtonBase(pEditWin, pFrame, "modules/swriter/ui/unfloatbutton.ui", + "UnfloatButton") + , m_xPushButton(m_xBuilder->weld_button("button")) , m_sLabel(SwResId(STR_UNFLOAT_TABLE)) { + m_xPushButton->set_accessible_name(m_sLabel); + m_xVirDev = m_xPushButton->create_virtual_device(); + SetVirDevFont(); } UnfloatTableButton::~UnfloatTableButton() { disposeOnce(); } +void UnfloatTableButton::dispose() +{ + m_xPushButton.reset(); + SwFrameMenuButtonBase::dispose(); +} + void UnfloatTableButton::SetOffset(Point aTopRightPixel) { // Compute the text size and get the box position & size from it tools::Rectangle aTextRect; - GetTextBoundRect(aTextRect, m_sLabel); - tools::Rectangle aTextPxRect = LogicToPixel(aTextRect); - FontMetric aFontMetric = GetFontMetric(GetFont()); + m_xVirDev->GetTextBoundRect(aTextRect, m_sLabel); + tools::Rectangle aTextPxRect = m_xVirDev->LogicToPixel(aTextRect); + FontMetric aFontMetric = m_xVirDev->GetFontMetric(m_xVirDev->GetFont()); Size aBoxSize(aTextPxRect.GetWidth() + BUTTON_WIDTH + TEXT_PADDING * 2, aFontMetric.GetLineHeight() + TEXT_PADDING * 2); @@ -72,6 +83,9 @@ void UnfloatTableButton::SetOffset(Point aTopRightPixel) // Set the position & Size of the window SetPosSizePixel(aBoxPos, aBoxSize); + m_xVirDev->SetOutputSizePixel(aBoxSize); + + PaintButton(); } void UnfloatTableButton::MouseButtonDown(const MouseEvent& /*rMEvt*/) @@ -177,12 +191,15 @@ void UnfloatTableButton::MouseButtonDown(const MouseEvent& /*rMEvt*/) } } -void UnfloatTableButton::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&) +void UnfloatTableButton::PaintButton() { - SetMapMode(MapMode(MapUnit::MapPixel)); + if (!m_xVirDev) + return; + + m_xVirDev->SetMapMode(MapMode(MapUnit::MapPixel)); drawinglayer::primitive2d::Primitive2DContainer aSeq; const ::tools::Rectangle aRect( - ::tools::Rectangle(Point(0, 0), rRenderContext.PixelToLogic(GetSizePixel()))); + ::tools::Rectangle(Point(0, 0), m_xVirDev->PixelToLogic(GetSizePixel()))); // Create button SwFrameButtonPainter::PaintButton(aSeq, aRect, true); @@ -191,12 +208,12 @@ void UnfloatTableButton::Paint(vcl::RenderContext& rRenderContext, const tools:: basegfx::BColor aLineColor = SwViewOption::GetHeaderFooterMarkColor().getBColor(); basegfx::B2DVector aFontSize; drawinglayer::attribute::FontAttribute aFontAttr - = drawinglayer::primitive2d::getFontAttributeFromVclFont( - aFontSize, rRenderContext.GetFont(), false, false); + = drawinglayer::primitive2d::getFontAttributeFromVclFont(aFontSize, m_xVirDev->GetFont(), + false, false); - FontMetric aFontMetric = rRenderContext.GetFontMetric(rRenderContext.GetFont()); + FontMetric aFontMetric = m_xVirDev->GetFontMetric(m_xVirDev->GetFont()); double nTextOffsetY = aFontMetric.GetAscent() + TEXT_PADDING; - double nTextOffsetX = std::abs(aRect.GetWidth() - rRenderContext.GetTextWidth(m_sLabel)) / 2.0; + double nTextOffsetX = std::abs(aRect.GetWidth() - m_xVirDev->GetTextWidth(m_sLabel)) / 2.0; Point aTextPos(nTextOffsetX, nTextOffsetY); basegfx::B2DHomMatrix aTextMatrix(basegfx::utils::createScaleTranslateB2DHomMatrix( @@ -211,10 +228,12 @@ void UnfloatTableButton::Paint(vcl::RenderContext& rRenderContext, const tools:: // Create the processor and process the primitives const drawinglayer::geometry::ViewInformation2D aNewViewInfos; std::unique_ptr<drawinglayer::processor2d::BaseProcessor2D> pProcessor( - drawinglayer::processor2d::createBaseProcessor2DFromOutputDevice(rRenderContext, + drawinglayer::processor2d::createBaseProcessor2DFromOutputDevice(*m_xVirDev, aNewViewInfos)); pProcessor->process(aSeq); + + m_xPushButton->set_custom_button(m_xVirDev.get()); } void UnfloatTableButton::ShowAll(bool bShow) { Show(bShow); } diff --git a/sw/source/uibase/inc/FrameControl.hxx b/sw/source/uibase/inc/FrameControl.hxx index e3c98ca57e8a..a2cc7e9edf21 100644 --- a/sw/source/uibase/inc/FrameControl.hxx +++ b/sw/source/uibase/inc/FrameControl.hxx @@ -9,7 +9,8 @@ #ifndef INCLUDED_SW_SOURCE_UIBASE_INC_FRAMECONTROL_HXX #define INCLUDED_SW_SOURCE_UIBASE_INC_FRAMECONTROL_HXX -#include <vcl/menubtn.hxx> +#include <vcl/InterimItemWindow.hxx> +#include <vcl/virdev.hxx> #include "edtwin.hxx" @@ -54,8 +55,11 @@ public: /** Class sharing some MenuButton code */ -class SwFrameMenuButtonBase : public MenuButton, public ISwFrameControl +class SwFrameMenuButtonBase : public InterimItemWindow, public ISwFrameControl { +protected: + VclPtr<VirtualDevice> m_xVirDev; +private: VclPtr<SwEditWin> m_pEditWin; const SwFrame* m_pFrame; @@ -63,12 +67,15 @@ protected: virtual ~SwFrameMenuButtonBase() override { disposeOnce(); } virtual void dispose() override; + void SetVirDevFont(); + public: - SwFrameMenuButtonBase( SwEditWin* pEditWin, const SwFrame* pFrame ); + SwFrameMenuButtonBase(SwEditWin* pEditWin, const SwFrame* pFrame, + const OUString& rUIXMLDescription, const OString& rID); virtual const SwFrame* GetFrame() override { return m_pFrame; } virtual SwEditWin* GetEditWin() override { return m_pEditWin; } - virtual bool IsFocused() const override { return HasFocus(); } + virtual bool IsFocused() const override { return ControlHasFocus(); } const SwPageFrame* GetPageFrame() const; }; diff --git a/sw/source/uibase/inc/HeaderFooterWin.hxx b/sw/source/uibase/inc/HeaderFooterWin.hxx index f92d45f858fc..5b83bbc79548 100644 --- a/sw/source/uibase/inc/HeaderFooterWin.hxx +++ b/sw/source/uibase/inc/HeaderFooterWin.hxx @@ -11,8 +11,8 @@ #include "edtwin.hxx" #include "FrameControl.hxx" -#include <vcl/builder.hxx> #include <vcl/timer.hxx> +#include <vcl/virdev.hxx> #include <drawinglayer/primitive2d/Primitive2DContainer.hxx> /** @@ -34,10 +34,10 @@ public: */ class SwHeaderFooterWin : public SwFrameMenuButtonBase { - VclBuilder m_aBuilder; + std::unique_ptr<weld::MenuButton> m_xMenuButton; + std::unique_ptr<weld::Button> m_xPushButton; OUString m_sLabel; bool m_bIsHeader; - VclPtr<PopupMenu> m_pPopupMenu; VclPtr<vcl::Window> m_pLine; bool m_bIsAppearing; int m_nFadeRate; @@ -50,10 +50,6 @@ public: void SetOffset( Point aOffset, tools::Long nXLineStart, tools::Long nXLineEnd ); - virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override; - virtual void MouseButtonDown( const MouseEvent& rMEvt ) override; - virtual void Select( ) override; - virtual void ShowAll( bool bShow ) override; virtual bool Contains( const Point &rDocPt ) const override; @@ -65,7 +61,10 @@ public: void SetReadonly( bool bReadonly ) override; private: - DECL_LINK( FadeHandler, Timer *, void ); + DECL_LINK(FadeHandler, Timer *, void); + DECL_LINK(ClickHdl, weld::Button&, void); + DECL_LINK(SelectHdl, const OString&, void); + void PaintButton(); }; #endif diff --git a/sw/source/uibase/inc/PageBreakWin.hxx b/sw/source/uibase/inc/PageBreakWin.hxx index 982c81e157a4..90f0d9afe562 100644 --- a/sw/source/uibase/inc/PageBreakWin.hxx +++ b/sw/source/uibase/inc/PageBreakWin.hxx @@ -11,7 +11,6 @@ #include "edtwin.hxx" #include "FrameControl.hxx" -#include <vcl/builder.hxx> #include <vcl/timer.hxx> #include <optional> @@ -25,8 +24,7 @@ class SwPageFrame; */ class SwPageBreakWin : public SwFrameMenuButtonBase { - VclBuilder m_aBuilder; - VclPtr<PopupMenu> m_pPopupMenu; + std::unique_ptr<weld::MenuButton> m_xMenuButton; VclPtr<vcl::Window> m_pLine; bool m_bIsAppearing; int m_nFadeRate; @@ -41,11 +39,6 @@ public: virtual ~SwPageBreakWin() override; virtual void dispose() override; - virtual void Paint( vcl::RenderContext& /*rRenderContext*/, const tools::Rectangle& rRect ) override; - virtual void Select( ) override; - virtual void MouseMove( const MouseEvent& rMEvt ) override; - virtual void Activate( ) override; - void UpdatePosition(const std::optional<Point>& xEvtPt = std::optional<Point>()); virtual void ShowAll( bool bShow ) override; @@ -56,9 +49,11 @@ public: void Fade( bool bFadeIn ); private: - /// Hide the button (used when the popup menu is closed by clicking outside) - DECL_LINK( HideHandler, Menu *, bool ); DECL_LINK( FadeHandler, Timer *, void ); + /// Hide the button when the menu is toggled closed, e.g by clicking outside + DECL_LINK(ToggleHdl, weld::ToggleButton&, void); + DECL_LINK(SelectHdl, const OString&, void); + void PaintButton(); }; #endif diff --git a/sw/source/uibase/inc/UnfloatTableButton.hxx b/sw/source/uibase/inc/UnfloatTableButton.hxx index 701c824b814e..99598bcc2a15 100644 --- a/sw/source/uibase/inc/UnfloatTableButton.hxx +++ b/sw/source/uibase/inc/UnfloatTableButton.hxx @@ -24,21 +24,25 @@ */ class UnfloatTableButton : public SwFrameMenuButtonBase { + std::unique_ptr<weld::Button> m_xPushButton; OUString m_sLabel; public: UnfloatTableButton(SwEditWin* pEditWin, const SwFrame* pFrame); + virtual void dispose() override; virtual ~UnfloatTableButton() override; void SetOffset(Point aTopRightPixel); virtual void MouseButtonDown(const MouseEvent& rMEvt) override; - virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect) override; virtual void ShowAll(bool bShow) override; virtual bool Contains(const Point& rDocPt) const override; virtual void SetReadonly(bool bReadonly) override; + +private: + void PaintButton(); }; #endif |