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 
16 #include <svtools/toolbarmenu.hxx>
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 
25 namespace {
26 
27 class NumberingToolBoxControl;
28 
29 class 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 
41 public:
42  NumberingPopup(NumberingToolBoxControl& rController, weld::Widget* pParent, NumberingPageType ePageType);
43 
44  virtual void statusChanged( const css::frame::FeatureStateEvent& rEvent ) override;
45 };
46 
47 class NumberingToolBoxControl : public svt::PopupWindowController
48 {
49  NumberingPageType mePageType;
50 
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;
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 
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(nullptr))
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;
111  if ( mePageType == NumberingPageType::BULLET )
112  {
113  aMoreItemText = SvxResId( RID_SVXSTR_MOREBULLETS );
114  AddStatusListener( ".uno:CurrentBulletListType" );
115  }
116  else if ( mePageType == NumberingPageType::SINGLENUM )
117  {
118  aMoreItemText = SvxResId( RID_SVXSTR_MORENUMBERING );
119  AddStatusListener( ".uno:CurrentNumListType" );
120  }
121  else
122  {
123  aMoreItemText = SvxResId( RID_SVXSTR_MORE );
124  AddStatusListener( ".uno:CurrentOutlineType" );
125  }
126 
127  auto xImage = vcl::CommandInfoProvider::GetXGraphicForCommand(".uno:OutlineBullet", mrController.getFrameInterface());
128  mxMoreButton->set_image(xImage);
129  mxMoreButton->set_label(aMoreItemText);
130  mxMoreButton->connect_clicked(LINK(this, NumberingPopup, VSButtonClickSetHdl));
131 
132  mxValueSet->SetSelectHdl(LINK(this, NumberingPopup, VSSelectValueSetHdl));
133 }
134 
135 void NumberingPopup::statusChanged( const css::frame::FeatureStateEvent& rEvent )
136 {
137  mxValueSet->SetNoSelection();
138 
139  sal_Int32 nSelItem;
140  if ( rEvent.State >>= nSelItem )
141  mxValueSet->SelectItem( nSelItem );
142 }
143 
144 IMPL_LINK_NOARG(NumberingPopup, VSSelectValueSetHdl, ValueSet*, void)
145 {
146  sal_uInt16 nSelItem = mxValueSet->GetSelectedItemId();
147  if ( mePageType == NumberingPageType::BULLET )
148  {
149  auto aArgs( comphelper::InitPropertySequence( { { "SetBullet", css::uno::makeAny( nSelItem ) } } ) );
150  mrController.dispatchCommand( ".uno:SetBullet", aArgs );
151  }
152  else if ( mePageType == NumberingPageType::SINGLENUM )
153  {
154  auto aArgs( comphelper::InitPropertySequence( { { "SetNumber", css::uno::makeAny( nSelItem ) } } ) );
155  mrController.dispatchCommand( ".uno:SetNumber", aArgs );
156  }
157  else
158  {
159  auto aArgs( comphelper::InitPropertySequence( { { "SetOutline", css::uno::makeAny( nSelItem ) } } ) );
160  mrController.dispatchCommand( ".uno:SetOutline", aArgs );
161  }
162  mrController.EndPopupMode();
163 }
164 
165 void NumberingPopup::GrabFocus()
166 {
167  mxValueSet->GrabFocus();
168 }
169 
170 IMPL_LINK_NOARG(NumberingPopup, VSButtonClickSetHdl, weld::Button&, void)
171 {
172  auto aArgs( comphelper::InitPropertySequence( { { "Page", css::uno::makeAny( OUString("customize") ) } } ) );
173  mrController.dispatchCommand( ".uno:OutlineBullet", aArgs );
174 
175  mrController.EndPopupMode();
176 }
177 
178 NumberingToolBoxControl::NumberingToolBoxControl( const css::uno::Reference< css::uno::XComponentContext >& rxContext ):
179  svt::PopupWindowController( rxContext, css::uno::Reference< css::frame::XFrame >(), OUString() ),
180  mePageType( NumberingPageType::SINGLENUM )
181 {
182 }
183 
184 std::unique_ptr<WeldToolbarPopup> NumberingToolBoxControl::weldPopupWindow()
185 {
186  return std::make_unique<NumberingPopup>(*this, m_pToolbar, mePageType);
187 }
188 
189 VclPtr<vcl::Window> NumberingToolBoxControl::createVclPopupWindow( vcl::Window* pParent )
190 {
191  mxInterimPopover = VclPtr<InterimToolbarPopup>::Create(getFrameInterface(), pParent,
192  std::make_unique<NumberingPopup>(*this, pParent->GetFrameWeld(), mePageType));
193 
194  mxInterimPopover->Show();
195 
196  return mxInterimPopover;
197 }
198 
199 void SAL_CALL NumberingToolBoxControl::initialize( const css::uno::Sequence< css::uno::Any >& aArguments )
200 {
201  svt::PopupWindowController::initialize( aArguments );
202 
203  if ( m_aCommandURL == ".uno:DefaultBullet" )
204  mePageType = NumberingPageType::BULLET;
205  else if ( m_aCommandURL == ".uno:SetOutline" )
206  mePageType = NumberingPageType::OUTLINE;
207 
208  if (m_pToolbar)
209  {
210  mxPopoverContainer.reset(new ToolbarPopupContainer(m_pToolbar));
211  m_pToolbar->set_item_popover(m_aCommandURL.toUtf8(), mxPopoverContainer->getTopLevel());
212  return;
213  }
214 
215  ToolBox* pToolBox = nullptr;
216  sal_uInt16 nId = 0;
217  if (getToolboxId(nId, &pToolBox))
218  {
219  ToolBoxItemBits nBits = ( mePageType == NumberingPageType::OUTLINE ) ? ToolBoxItemBits::DROPDOWNONLY : ToolBoxItemBits::DROPDOWN;
220  pToolBox->SetItemBits( nId, pToolBox->GetItemBits( nId ) | nBits );
221  }
222 }
223 
224 OUString SAL_CALL NumberingToolBoxControl::getImplementationName()
225 {
226  return "com.sun.star.comp.svx.NumberingToolBoxControl";
227 }
228 
229 css::uno::Sequence< OUString > SAL_CALL NumberingToolBoxControl::getSupportedServiceNames()
230 {
231  return { "com.sun.star.frame.ToolbarController" };
232 }
233 
234 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
236  css::uno::XComponentContext *rxContext,
237  css::uno::Sequence<css::uno::Any> const & )
238 {
239  return cppu::acquire( new NumberingToolBoxControl( rxContext ) );
240 }
241 
242 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ToolBoxItemBits GetItemBits(sal_uInt16 nItemId) const
SlideSorterController & mrController
static const AllSettings & GetSettings()
Reference
sal_Int16 nId
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
const css::lang::Locale & getLocale(bool bResolveSystem=true) const
weld::Window * GetFrameWeld() const
OUString SvxResId(const char *pId)
Definition: dialmgr.cxx:28
exports com.sun.star. frame
virtual OutputDevice & get_ref_device()=0
css::uno::Sequence< css::beans::PropertyValue > InitPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
const LanguageTag & GetLanguageTag() const
NumberingPageType
Definition: numvset.hxx:41
ToolBoxItemBits
Reference< graphic::XGraphic > GetXGraphicForCommand(const OUString &rsCommandName, const Reference< frame::XFrame > &rxFrame, vcl::ImageType eImageType)
void SetItemBits(sal_uInt16 nItemId, ToolBoxItemBits nBits)
Point LogicToPixel(const Point &rLogicPt) const
static VclPtr< reference_type > Create(Arg &&...arg)
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)
virtual void set_size_request(int nWidth, int nHeight)=0