LibreOffice Module svx (master) 1
bulletsnumbering.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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 */
9
10#include <com/sun/star/text/DefaultNumberingProvider.hpp>
11#include <com/sun/star/text/XNumberingFormatter.hpp>
12
17#include <svx/strings.hrc>
18#include <svx/dialmgr.hxx>
19#include <svx/numvset.hxx>
21#include <vcl/toolbox.hxx>
22#include <vcl/settings.hxx>
23#include <vcl/svapp.hxx>
24
25namespace {
26
27class NumberingToolBoxControl;
28
29class NumberingPopup : public WeldToolbarPopup
30{
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);
38
39 virtual void GrabFocus() override;
40
41public:
42 NumberingPopup(NumberingToolBoxControl& rController, weld::Widget* pParent, NumberingPageType ePageType);
43
44 virtual void statusChanged( const css::frame::FeatureStateEvent& rEvent ) override;
45};
46
47class NumberingToolBoxControl : public svt::PopupWindowController
48{
49 NumberingPageType mePageType;
50
51public:
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;
55
56 // XInitialization
57 virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
58
59 // XServiceInfo
60 virtual OUString SAL_CALL getImplementationName() override;
61 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
62};
63
64}
65
66NumberingPopup::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"))
74{
75 mxValueSet->SetStyle(WB_MENUSTYLEVALUESET | WB_FLATVALUESET | WB_NO_DIRECTSELECT);
76 mxValueSet->init(mePageType);
77
78 if ( mePageType != NumberingPageType::BULLET )
79 {
80 css::uno::Reference< css::text::XDefaultNumberingProvider > xDefNum = css::text::DefaultNumberingProvider::create( mrController.getContext() );
81 if ( xDefNum.is() )
82 {
83 css::lang::Locale aLocale = Application::GetSettings().GetLanguageTag().getLocale();
84 css::uno::Reference< css::text::XNumberingFormatter > xFormat( xDefNum, css::uno::UNO_QUERY );
85
86 if ( mePageType == NumberingPageType::SINGLENUM )
87 {
88 css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > aNumberings(
89 xDefNum->getDefaultContinuousNumberingLevels( aLocale ) );
90 mxValueSet->SetNumberingSettings( aNumberings, xFormat, aLocale );
91 }
92 else if ( mePageType == NumberingPageType::OUTLINE )
93 {
94 css::uno::Sequence< css::uno::Reference< css::container::XIndexAccess > > aOutline(
95 xDefNum->getDefaultOutlineNumberings( aLocale ) );
96 mxValueSet->SetOutlineNumberingSettings( aOutline, xFormat, aLocale );
97 }
98 }
99 }
100
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());
109
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" );
117
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));
122
123 mxValueSet->SetSelectHdl(LINK(this, NumberingPopup, VSSelectValueSetHdl));
124}
125
126void NumberingPopup::statusChanged( const css::frame::FeatureStateEvent& rEvent )
127{
128 mxValueSet->SetNoSelection();
129
130 sal_Int32 nSelItem;
131 if ( rEvent.State >>= nSelItem )
132 mxValueSet->SelectItem( nSelItem );
133}
134
135IMPL_LINK_NOARG(NumberingPopup, VSSelectValueSetHdl, ValueSet*, void)
136{
137 sal_uInt16 nSelItem = mxValueSet->GetSelectedItemId();
138 if ( mePageType == NumberingPageType::BULLET )
139 {
140 auto aArgs( comphelper::InitPropertySequence( { { "SetBullet", css::uno::Any( nSelItem ) } } ) );
141 mrController.dispatchCommand( ".uno:SetBullet", aArgs );
142 }
143 else if ( mePageType == NumberingPageType::SINGLENUM )
144 {
145 auto aArgs( comphelper::InitPropertySequence( { { "SetNumber", css::uno::Any( nSelItem ) } } ) );
146 mrController.dispatchCommand( ".uno:SetNumber", aArgs );
147 }
148 else
149 {
150 auto aArgs( comphelper::InitPropertySequence( { { "SetOutline", css::uno::Any( nSelItem ) } } ) );
151 mrController.dispatchCommand( ".uno:SetOutline", aArgs );
152 }
153 mrController.EndPopupMode();
154}
155
156void NumberingPopup::GrabFocus()
157{
158 mxValueSet->GrabFocus();
159}
160
161IMPL_LINK_NOARG(NumberingPopup, VSButtonClickSetHdl, weld::Button&, void)
162{
163 auto aArgs( comphelper::InitPropertySequence( { { "Page", css::uno::Any( OUString("customize") ) } } ) );
164 mrController.dispatchCommand( ".uno:OutlineBullet", aArgs );
165
166 mrController.EndPopupMode();
167}
168
169NumberingToolBoxControl::NumberingToolBoxControl( const css::uno::Reference< css::uno::XComponentContext >& rxContext ):
170 svt::PopupWindowController( rxContext, css::uno::Reference< css::frame::XFrame >(), OUString() ),
171 mePageType( NumberingPageType::SINGLENUM )
172{
173}
174
175std::unique_ptr<WeldToolbarPopup> NumberingToolBoxControl::weldPopupWindow()
176{
177 return std::make_unique<NumberingPopup>(*this, m_pToolbar, mePageType);
178}
179
180VclPtr<vcl::Window> NumberingToolBoxControl::createVclPopupWindow( vcl::Window* pParent )
181{
182 mxInterimPopover = VclPtr<InterimToolbarPopup>::Create(getFrameInterface(), pParent,
183 std::make_unique<NumberingPopup>(*this, pParent->GetFrameWeld(), mePageType));
184
185 mxInterimPopover->Show();
186
187 return mxInterimPopover;
188}
189
190void SAL_CALL NumberingToolBoxControl::initialize( const css::uno::Sequence< css::uno::Any >& aArguments )
191{
192 svt::PopupWindowController::initialize( aArguments );
193
194 if ( m_aCommandURL == ".uno:DefaultBullet" )
195 mePageType = NumberingPageType::BULLET;
196 else if ( m_aCommandURL == ".uno:SetOutline" )
197 mePageType = NumberingPageType::OUTLINE;
198
199 if (m_pToolbar)
200 {
201 mxPopoverContainer.reset(new ToolbarPopupContainer(m_pToolbar));
202 m_pToolbar->set_item_popover(m_aCommandURL, mxPopoverContainer->getTopLevel());
203 return;
204 }
205
206 ToolBox* pToolBox = nullptr;
208 if (getToolboxId(nId, &pToolBox))
209 {
210 ToolBoxItemBits nBits = mePageType == NumberingPageType::OUTLINE
211 ? ToolBoxItemBits::DROPDOWNONLY
212 : ToolBoxItemBits::DROPDOWN;
213 pToolBox->SetItemBits( nId, pToolBox->GetItemBits( nId ) | nBits );
214 }
215}
216
217OUString SAL_CALL NumberingToolBoxControl::getImplementationName()
218{
219 return "com.sun.star.comp.svx.NumberingToolBoxControl";
220}
221
222css::uno::Sequence< OUString > SAL_CALL NumberingToolBoxControl::getSupportedServiceNames()
223{
224 return { "com.sun.star.frame.ToolbarController" };
225}
226
227extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
229 css::uno::XComponentContext *rxContext,
230 css::uno::Sequence<css::uno::Any> const & )
231{
232 return cppu::acquire( new NumberingToolBoxControl( rxContext ) );
233}
234
235/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SlideSorterController & mrController
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_svx_NumberingToolBoxControl_get_implementation(css::uno::XComponentContext *rxContext, css::uno::Sequence< css::uno::Any > const &)
IMPL_LINK_NOARG(NumberingPopup, VSSelectValueSetHdl, ValueSet *, void)
const LanguageTag & GetLanguageTag() const
static const AllSettings & GetSettings()
const css::lang::Locale & getLocale(bool bResolveSystem=true) const
SAL_WARN_UNUSED_RESULT Point LogicToPixel(const Point &rLogicPt) const
ToolBoxItemBits GetItemBits(ToolBoxItemId nItemId) const
void SetItemBits(ToolBoxItemId nItemId, ToolBoxItemBits nBits)
static VclPtr< reference_type > Create(Arg &&... arg)
virtual void GrabFocus()=0
virtual void statusChanged(const css::frame::FeatureStateEvent &Event)
virtual std::unique_ptr< WeldToolbarPopup > weldPopupWindow()=0
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override=0
virtual VclPtr< vcl::Window > createVclPopupWindow(vcl::Window *pParent)
virtual OUString SAL_CALL getImplementationName() override=0
weld::Window * GetFrameWeld() const
virtual OutputDevice & get_ref_device()=0
virtual void set_size_request(int nWidth, int nHeight)=0
OUString SvxResId(TranslateId aId)
Definition: dialmgr.cxx:24
DECL_LINK(CheckNameHdl, SvxNameDialog &, bool)
css::uno::Sequence< css::beans::PropertyValue > InitPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
Reference
Reference< graphic::XGraphic > GetXGraphicForCommand(const OUString &rsCommandName, const Reference< frame::XFrame > &rxFrame, vcl::ImageType eImageType)
NumberingPageType
Definition: numvset.hxx:42
sal_Int16 nId
ToolBoxItemBits