From 1e57442fc9f275828943d316ac4b64f1d29b3f9b Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Thu, 13 Feb 2020 17:10:54 +0000 Subject: weld SearchLabelToolboxController MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit and split out LabelItemWindow to reuse it Change-Id: Ie14f1bdc6d8684db088c018afd341e10bee9d977 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88623 Tested-by: Jenkins Reviewed-by: Caolán McNamara --- svx/inc/pch/precompiled_svx.hxx | 3 +- svx/source/dialog/srchdlg.cxx | 13 +++--- svx/source/form/tbxform.cxx | 64 ++++++++++++++------------ svx/source/inc/labelitemwindow.hxx | 29 ++++++++++++ svx/source/tbxctrls/tbunosearchcontrollers.cxx | 28 ++++++----- 5 files changed, 89 insertions(+), 48 deletions(-) create mode 100644 svx/source/inc/labelitemwindow.hxx (limited to 'svx') diff --git a/svx/inc/pch/precompiled_svx.hxx b/svx/inc/pch/precompiled_svx.hxx index 2fbeb6430aac..3581e2087a00 100644 --- a/svx/inc/pch/precompiled_svx.hxx +++ b/svx/inc/pch/precompiled_svx.hxx @@ -13,7 +13,7 @@ manual changes will be rewritten by the next run of update_pch.sh (which presumably also fixes all possible problems, so it's usually better to use it). - Generated on 2020-02-13 17:41:02 using: + Generated on 2020-02-13 20:23:51 using: ./bin/update_pch svx svx --cutoff=3 --exclude:system --exclude:module --include:local If after updating build fails, use the following command to locate conflicting headers: @@ -368,6 +368,7 @@ #include #include #include +#include #include #include #include diff --git a/svx/source/dialog/srchdlg.cxx b/svx/source/dialog/srchdlg.cxx index 8f9cf9ed0be9..10357d49f944 100644 --- a/svx/source/dialog/srchdlg.cxx +++ b/svx/source/dialog/srchdlg.cxx @@ -74,6 +74,7 @@ #include #include +#include #include #include @@ -2400,13 +2401,13 @@ static void lcl_SetSearchLabelWindow(const OUString& rStr) sal_uInt16 id = pToolBox->GetItemId(i); if (pToolBox->GetItemCommand(id) == ".uno:SearchLabel") { - vcl::Window* pSearchLabel = pToolBox->GetItemWindow(id); + LabelItemWindow* pSearchLabel = dynamic_cast(pToolBox->GetItemWindow(id)); assert(pSearchLabel); - pSearchLabel->SetText(rStr); + pSearchLabel->set_label(rStr); if (rStr.isEmpty()) - pSearchLabel->SetSizePixel(Size(16, pSearchLabel->get_preferred_size().Height())); + pSearchLabel->SetSizePixel(Size(16, pSearchLabel->GetSizePixel().Height())); else - pSearchLabel->SetSizePixel(pSearchLabel->get_preferred_size()); + pSearchLabel->SetOptimalSize(); } if (pToolBox->GetItemCommand(id) == ".uno:FindText") @@ -2445,8 +2446,8 @@ OUString SvxSearchDialogWrapper::GetSearchLabel() sal_uInt16 id = pToolBox->GetItemId(i); if (pToolBox->GetItemCommand(id) == ".uno:SearchLabel") { - vcl::Window* pSearchLabel = pToolBox->GetItemWindow(id); - return pSearchLabel ? pSearchLabel->GetText() : OUString(); + LabelItemWindow* pSearchLabel = dynamic_cast(pToolBox->GetItemWindow(id)); + return pSearchLabel ? pSearchLabel->get_label() : OUString(); } } return OUString(); diff --git a/svx/source/form/tbxform.cxx b/svx/source/form/tbxform.cxx index 1bd90475e1cb..3d45d19519a1 100644 --- a/svx/source/form/tbxform.cxx +++ b/svx/source/form/tbxform.cxx @@ -21,12 +21,12 @@ #include #include #include -#include #include #include #include #include #include +#include #include #include @@ -163,41 +163,45 @@ SvxFmTbxCtlRecText::~SvxFmTbxCtlRecText() { } -class LabelItemWindow final : public InterimItemWindow +LabelItemWindow::LabelItemWindow(vcl::Window *pParent, const OUString& rLabel) + : InterimItemWindow(pParent, "svx/ui/labelbox.ui", "LabelBox") + , m_xLabel(m_xBuilder->weld_label("label")) { -private: - std::unique_ptr m_xLabel; -public: - LabelItemWindow(vcl::Window *pParent, const OUString& rLabel) - : InterimItemWindow(pParent, "svx/ui/labelbox.ui", "LabelBox") - , m_xLabel(m_xBuilder->weld_label("label")) - { - m_xLabel->set_label(rLabel); - Size aSize(m_xLabel->get_preferred_size()); - aSize.AdjustWidth(12); - m_xLabel->set_size_request(aSize.Width(), -1); + m_xLabel->set_label(rLabel); - SetSizePixel(m_xLabel->get_preferred_size()); + SetOptimalSize(); - m_xLabel->set_toolbar_background(); - } + m_xLabel->set_toolbar_background(); +} - void set_label(const OUString& rLabel) - { - m_xLabel->set_label(rLabel); - } +void LabelItemWindow::SetOptimalSize() +{ + Size aSize(m_xLabel->get_preferred_size()); + aSize.AdjustWidth(12); - virtual void dispose() override - { - m_xLabel.reset(); - InterimItemWindow::dispose(); - } + SetSizePixel(aSize); +} - virtual ~LabelItemWindow() override - { - disposeOnce(); - } -}; +void LabelItemWindow::set_label(const OUString& rLabel) +{ + m_xLabel->set_label(rLabel); +} + +OUString LabelItemWindow::get_label() const +{ + return m_xLabel->get_label(); +} + +void LabelItemWindow::dispose() +{ + m_xLabel.reset(); + InterimItemWindow::dispose(); +} + +LabelItemWindow::~LabelItemWindow() +{ + disposeOnce(); +} VclPtr SvxFmTbxCtlRecText::CreateItemWindow( vcl::Window* pParent ) { diff --git a/svx/source/inc/labelitemwindow.hxx b/svx/source/inc/labelitemwindow.hxx new file mode 100644 index 000000000000..1667cdc4edc6 --- /dev/null +++ b/svx/source/inc/labelitemwindow.hxx @@ -0,0 +1,29 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#pragma once + +#include + +class LabelItemWindow final : public InterimItemWindow +{ +private: + std::unique_ptr m_xLabel; + +public: + LabelItemWindow(vcl::Window* pParent, const OUString& rLabel); + void set_label(const OUString& rLabel); + OUString get_label() const; + + void SetOptimalSize(); + virtual void dispose() override; + virtual ~LabelItemWindow() override; +}; + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/svx/source/tbxctrls/tbunosearchcontrollers.cxx b/svx/source/tbxctrls/tbunosearchcontrollers.cxx index 1c620ef7da3e..ec8f23b7f8f0 100644 --- a/svx/source/tbxctrls/tbunosearchcontrollers.cxx +++ b/svx/source/tbxctrls/tbunosearchcontrollers.cxx @@ -59,10 +59,9 @@ #include #include #include -#include -#include #include +#include using namespace css; @@ -1300,7 +1299,7 @@ public: virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& rEvent ) override; private: - VclPtr m_pSL; + VclPtr m_xSL; }; SearchLabelToolboxController::SearchLabelToolboxController( const css::uno::Reference< css::uno::XComponentContext > & rxContext ) @@ -1355,7 +1354,7 @@ void SAL_CALL SearchLabelToolboxController::dispose() SearchToolbarControllersManager::createControllersManager().freeController(m_xFrame, m_aCommandURL); svt::ToolboxController::dispose(); - m_pSL.disposeAndClear(); + m_xSL.disposeAndClear(); } // XInitialization @@ -1368,20 +1367,27 @@ void SAL_CALL SearchLabelToolboxController::initialize( const css::uno::Sequence // XStatusListener void SAL_CALL SearchLabelToolboxController::statusChanged( const css::frame::FeatureStateEvent& ) { - if (m_pSL) + if (m_xSL) { OUString aStr = SvxSearchDialogWrapper::GetSearchLabel(); - m_pSL->SetText(aStr); - long aWidth = !aStr.isEmpty() ? m_pSL->get_preferred_size().getWidth() : 16; - m_pSL->SetSizePixel(Size(aWidth, m_pSL->get_preferred_size().getHeight())); + m_xSL->set_label(aStr); + m_xSL->SetOptimalSize(); + Size aSize(m_xSL->GetSizePixel()); + long nWidth = !aStr.isEmpty() ? aSize.getWidth() : 16; + m_xSL->SetSizePixel(Size(nWidth, aSize.Height())); } } css::uno::Reference< css::awt::XWindow > SAL_CALL SearchLabelToolboxController::createItemWindow( const css::uno::Reference< css::awt::XWindow >& Parent ) { - m_pSL = VclPtr::Create(VCLUnoHelper::GetWindow( Parent )); - m_pSL->SetSizePixel(Size(16, 25)); - return VCLUnoHelper::GetInterface(m_pSL); + ToolBox* pToolBox = nullptr; + sal_uInt16 nId = 0; + if (getToolboxId(nId, &pToolBox)) + pToolBox->SetItemWindowNonInteractive(nId, true); + + m_xSL = VclPtr::Create(VCLUnoHelper::GetWindow(Parent), ""); + m_xSL->SetSizePixel(Size(16, m_xSL->GetSizePixel().Height())); + return VCLUnoHelper::GetInterface(m_xSL); } // protocol handler for "vnd.sun.star.findbar:*" URLs -- cgit