Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / tbxctrls / bulletsnumbering.cxx
blobe1a55a112346ac0d5ace5e2b05a897cfbea1e320
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <com/sun/star/text/DefaultNumberingProvider.hpp>
11 #include <com/sun/star/text/XNumberingFormatter.hpp>
13 #include <comphelper/propertysequence.hxx>
14 #include <i18nlangtag/languagetag.hxx>
15 #include <svtools/popupwindowcontroller.hxx>
16 #include <svtools/toolbarmenu.hxx>
17 #include <svx/strings.hrc>
18 #include <svx/dialmgr.hxx>
19 #include <svx/numvset.hxx>
20 #include <vcl/commandinfoprovider.hxx>
21 #include <vcl/toolbox.hxx>
22 #include <vcl/settings.hxx>
23 #include <vcl/svapp.hxx>
25 namespace {
27 class NumberingToolBoxControl;
29 class NumberingPopup : public WeldToolbarPopup
31 NumberingPageType mePageType;
32 NumberingToolBoxControl& mrController;
33 std::unique_ptr<SvxNumValueSet> mxValueSet;
34 std::unique_ptr<weld::CustomWeld> mxValueSetWin;
35 std::unique_ptr<weld::Button> mxMoreButton;
36 DECL_LINK(VSSelectValueSetHdl, ValueSet*, void);
37 DECL_LINK(VSButtonClickSetHdl, weld::Button&, void);
39 virtual void GrabFocus() override;
41 public:
42 NumberingPopup(NumberingToolBoxControl& rController, weld::Widget* pParent, NumberingPageType ePageType);
44 virtual void statusChanged( const css::frame::FeatureStateEvent& rEvent ) override;
47 class NumberingToolBoxControl : public svt::PopupWindowController
49 NumberingPageType mePageType;
51 public:
52 explicit NumberingToolBoxControl( const css::uno::Reference< css::uno::XComponentContext >& rxContext );
53 virtual VclPtr<vcl::Window> createVclPopupWindow( vcl::Window* pParent ) override;
54 std::unique_ptr<WeldToolbarPopup> weldPopupWindow() override;
56 // XInitialization
57 virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
59 // XServiceInfo
60 virtual OUString SAL_CALL getImplementationName() override;
61 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
66 NumberingPopup::NumberingPopup(NumberingToolBoxControl& rController,
67 weld::Widget* pParent, NumberingPageType ePageType)
68 : WeldToolbarPopup(rController.getFrameInterface(), pParent, "svx/ui/numberingwindow.ui", "NumberingWindow")
69 , mePageType(ePageType)
70 , mrController(rController)
71 , mxValueSet(new SvxNumValueSet(m_xBuilder->weld_scrolled_window("valuesetwin", true)))
72 , mxValueSetWin(new weld::CustomWeld(*m_xBuilder, "valueset", *mxValueSet))
73 , mxMoreButton(m_xBuilder->weld_button("more"))
75 mxValueSet->SetStyle(WB_MENUSTYLEVALUESET | WB_FLATVALUESET | WB_NO_DIRECTSELECT);
76 mxValueSet->init(mePageType);
78 if ( mePageType != NumberingPageType::BULLET )
80 css::uno::Reference< css::text::XDefaultNumberingProvider > xDefNum = css::text::DefaultNumberingProvider::create( mrController.getContext() );
81 if ( xDefNum.is() )
83 css::lang::Locale aLocale = Application::GetSettings().GetLanguageTag().getLocale();
84 css::uno::Reference< css::text::XNumberingFormatter > xFormat( xDefNum, css::uno::UNO_QUERY );
86 if ( mePageType == NumberingPageType::SINGLENUM )
88 css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > aNumberings(
89 xDefNum->getDefaultContinuousNumberingLevels( aLocale ) );
90 mxValueSet->SetNumberingSettings( aNumberings, xFormat, aLocale );
92 else if ( mePageType == NumberingPageType::OUTLINE )
94 css::uno::Sequence< css::uno::Reference< css::container::XIndexAccess > > aOutline(
95 xDefNum->getDefaultOutlineNumberings( aLocale ) );
96 mxValueSet->SetOutlineNumberingSettings( aOutline, xFormat, aLocale );
101 weld::DrawingArea* pDrawingArea = mxValueSet->GetDrawingArea();
102 OutputDevice& rRefDevice = pDrawingArea->get_ref_device();
103 Size aItemSize(rRefDevice.LogicToPixel(Size(30, 42), MapMode(MapUnit::MapAppFont)));
104 mxValueSet->SetExtraSpacing( 2 );
105 Size aSize(mxValueSet->CalcWindowSizePixel(aItemSize));
106 pDrawingArea->set_size_request(aSize.Width(), aSize.Height());
107 mxValueSet->SetOutputSizePixel(aSize);
108 mxValueSet->SetColor(Application::GetSettings().GetStyleSettings().GetFieldColor());
110 OUString aMoreItemText = SvxResId( RID_SVXSTR_CUSTOMIZE );
111 if ( mePageType == NumberingPageType::BULLET )
112 AddStatusListener( ".uno:CurrentBulletListType" );
113 else if ( mePageType == NumberingPageType::SINGLENUM )
114 AddStatusListener( ".uno:CurrentNumListType" );
115 else
116 AddStatusListener( ".uno:CurrentOutlineType" );
118 auto xImage = vcl::CommandInfoProvider::GetXGraphicForCommand(".uno:OutlineBullet", mrController.getFrameInterface());
119 mxMoreButton->set_image(xImage);
120 mxMoreButton->set_label(aMoreItemText);
121 mxMoreButton->connect_clicked(LINK(this, NumberingPopup, VSButtonClickSetHdl));
123 mxValueSet->SetSelectHdl(LINK(this, NumberingPopup, VSSelectValueSetHdl));
126 void NumberingPopup::statusChanged( const css::frame::FeatureStateEvent& rEvent )
128 mxValueSet->SetNoSelection();
130 sal_Int32 nSelItem;
131 if ( rEvent.State >>= nSelItem )
132 mxValueSet->SelectItem( nSelItem );
135 IMPL_LINK_NOARG(NumberingPopup, VSSelectValueSetHdl, ValueSet*, void)
137 sal_uInt16 nSelItem = mxValueSet->GetSelectedItemId();
138 if ( mePageType == NumberingPageType::BULLET )
140 auto aArgs( comphelper::InitPropertySequence( { { "SetBullet", css::uno::Any( nSelItem ) } } ) );
141 mrController.dispatchCommand( ".uno:SetBullet", aArgs );
143 else if ( mePageType == NumberingPageType::SINGLENUM )
145 auto aArgs( comphelper::InitPropertySequence( { { "SetNumber", css::uno::Any( nSelItem ) } } ) );
146 mrController.dispatchCommand( ".uno:SetNumber", aArgs );
148 else
150 auto aArgs( comphelper::InitPropertySequence( { { "SetOutline", css::uno::Any( nSelItem ) } } ) );
151 mrController.dispatchCommand( ".uno:SetOutline", aArgs );
153 mrController.EndPopupMode();
156 void NumberingPopup::GrabFocus()
158 mxValueSet->GrabFocus();
161 IMPL_LINK_NOARG(NumberingPopup, VSButtonClickSetHdl, weld::Button&, void)
163 auto aArgs( comphelper::InitPropertySequence( { { "Page", css::uno::Any( OUString("customize") ) } } ) );
164 mrController.dispatchCommand( ".uno:OutlineBullet", aArgs );
166 mrController.EndPopupMode();
169 NumberingToolBoxControl::NumberingToolBoxControl( const css::uno::Reference< css::uno::XComponentContext >& rxContext ):
170 svt::PopupWindowController( rxContext, css::uno::Reference< css::frame::XFrame >(), OUString() ),
171 mePageType( NumberingPageType::SINGLENUM )
175 std::unique_ptr<WeldToolbarPopup> NumberingToolBoxControl::weldPopupWindow()
177 return std::make_unique<NumberingPopup>(*this, m_pToolbar, mePageType);
180 VclPtr<vcl::Window> NumberingToolBoxControl::createVclPopupWindow( vcl::Window* pParent )
182 mxInterimPopover = VclPtr<InterimToolbarPopup>::Create(getFrameInterface(), pParent,
183 std::make_unique<NumberingPopup>(*this, pParent->GetFrameWeld(), mePageType));
185 mxInterimPopover->Show();
187 return mxInterimPopover;
190 void SAL_CALL NumberingToolBoxControl::initialize( const css::uno::Sequence< css::uno::Any >& aArguments )
192 svt::PopupWindowController::initialize( aArguments );
194 if ( m_aCommandURL == ".uno:DefaultBullet" )
195 mePageType = NumberingPageType::BULLET;
196 else if ( m_aCommandURL == ".uno:SetOutline" )
197 mePageType = NumberingPageType::OUTLINE;
199 if (m_pToolbar)
201 mxPopoverContainer.reset(new ToolbarPopupContainer(m_pToolbar));
202 m_pToolbar->set_item_popover(m_aCommandURL, mxPopoverContainer->getTopLevel());
203 return;
206 ToolBox* pToolBox = nullptr;
207 ToolBoxItemId nId;
208 if (getToolboxId(nId, &pToolBox))
210 ToolBoxItemBits nBits = mePageType == NumberingPageType::OUTLINE
211 ? ToolBoxItemBits::DROPDOWNONLY
212 : ToolBoxItemBits::DROPDOWN;
213 pToolBox->SetItemBits( nId, pToolBox->GetItemBits( nId ) | nBits );
217 OUString SAL_CALL NumberingToolBoxControl::getImplementationName()
219 return "com.sun.star.comp.svx.NumberingToolBoxControl";
222 css::uno::Sequence< OUString > SAL_CALL NumberingToolBoxControl::getSupportedServiceNames()
224 return { "com.sun.star.frame.ToolbarController" };
227 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
228 com_sun_star_comp_svx_NumberingToolBoxControl_get_implementation(
229 css::uno::XComponentContext *rxContext,
230 css::uno::Sequence<css::uno::Any> const & )
232 return cppu::acquire( new NumberingToolBoxControl( rxContext ) );
235 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */