LibreOffice Module sw (master)  1
WrapPropertyPanel.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  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include "WrapPropertyPanel.hxx"
21 
22 #include <cmdid.h>
23 #include <svx/spacinglistbox.hxx>
24 #include <svx/svdtrans.hxx>
25 #include <sfx2/bindings.hxx>
26 #include <sfx2/dispatch.hxx>
27 #include <svl/eitem.hxx>
29 #include <vcl/settings.hxx>
30 #include <editeng/lrspitem.hxx>
31 #include <editeng/ulspitem.hxx>
32 #include <hintids.hxx>
33 #include <uitool.hxx>
34 #include <com/sun/star/lang/IllegalArgumentException.hpp>
35 #include <comphelper/lok.hxx>
36 
37 const char UNO_WRAPOFF[] = ".uno:WrapOff";
38 const char UNO_WRAPLEFT[] = ".uno:WrapLeft";
39 const char UNO_WRAPRIGHT[] = ".uno:WrapRight";
40 const char UNO_WRAPON[] = ".uno:WrapOn";
41 const char UNO_WRAPTHROUGH[] = ".uno:WrapThrough";
42 const char UNO_WRAPIDEAL[] = ".uno:WrapIdeal";
43 
44 namespace sw::sidebar {
45 
47  vcl::Window* pParent,
48  const css::uno::Reference< css::frame::XFrame >& rxFrame,
49  SfxBindings* pBindings)
50 {
51  if (pParent == nullptr)
52  throw css::lang::IllegalArgumentException("no parent Window given to WrapPropertyPanel::Create", nullptr, 0);
53  if ( ! rxFrame.is())
54  throw css::lang::IllegalArgumentException("no XFrame given to WrapPropertyPanel::Create", nullptr, 1);
55  if (pBindings == nullptr)
56  throw css::lang::IllegalArgumentException("no SfxBindings given to WrapPropertyPanel::Create", nullptr, 2);
57 
59  pParent,
60  rxFrame,
61  pBindings);
62 }
63 
65  vcl::Window* pParent,
66  const css::uno::Reference< css::frame::XFrame >& rxFrame,
67  SfxBindings* pBindings )
68  : PanelLayout(pParent, "WrapPropertyPanel", "modules/swriter/ui/sidebarwrap.ui", rxFrame, true)
69  , mxFrame( rxFrame )
70  , mpBindings(pBindings)
71  // spacing
72  , nTop(0)
73  , nBottom(0)
74  , nLeft(0)
75  , nRight(0)
76  // resources
77  , aCustomEntry()
78  // controller items
79  , maSwNoWrapControl(FN_FRAME_NOWRAP, *pBindings, *this)
80  , maSwWrapLeftControl(FN_FRAME_WRAP, *pBindings, *this)
81  , maSwWrapRightControl(FN_FRAME_WRAP_RIGHT, *pBindings, *this)
82  , maSwWrapParallelControl(FN_FRAME_WRAP_LEFT, *pBindings, *this)
83  , maSwWrapThroughControl(FN_FRAME_WRAPTHRU, *pBindings, *this)
84  , maSwWrapIdealControl(FN_FRAME_WRAP_IDEAL, *pBindings, *this)
85  , maSwEnableContourControl(FN_FRAME_WRAP_CONTOUR, *pBindings, *this)
86  , maSwLRSpacingControl(SID_ATTR_LRSPACE, *pBindings, *this)
87  , maSwULSpacingControl(SID_ATTR_ULSPACE, *pBindings, *this)
88  , mxRBNoWrap(m_xBuilder->weld_radio_button("buttonnone"))
89  , mxRBWrapLeft(m_xBuilder->weld_radio_button("buttonbefore"))
90  , mxRBWrapRight(m_xBuilder->weld_radio_button("buttonafter"))
91  , mxRBWrapParallel(m_xBuilder->weld_radio_button("buttonparallel"))
92  , mxRBWrapThrough(m_xBuilder->weld_radio_button("buttonthrough"))
93  , mxRBIdealWrap(m_xBuilder->weld_radio_button("buttonoptimal"))
94  , mxEditContour(m_xBuilder->weld_button("editcontour"))
95  , mxEnableContour(m_xBuilder->weld_check_button("enablecontour"))
96  , mxSpacingLB(m_xBuilder->weld_combo_box("spacingLB"))
97  , mxCustomEntry(m_xBuilder->weld_label("customlabel"))
98 {
99  FieldUnit eMetric = ::GetDfltMetric(false);
100  SpacingListBox::Fill(IsInch(eMetric) ? SpacingType::SPACING_INCH : SpacingType::SPACING_CM, *mxSpacingLB);
101 
102  Initialize();
103 }
104 
106 {
107  disposeOnce();
108 }
109 
111 {
112  mxRBNoWrap.reset();
113  mxRBWrapLeft.reset();
114  mxRBWrapRight.reset();
115  mxRBWrapParallel.reset();
116  mxRBWrapThrough.reset();
117  mxRBIdealWrap.reset();
118  mxEnableContour.reset();
119  mxEditContour.reset();
120  mxSpacingLB.reset();
121  mxCustomEntry.reset();
122 
132 
134 }
135 
137 {
138  Link<weld::ToggleButton&,void> aLink = LINK(this, WrapPropertyPanel, WrapTypeHdl);
139  mxRBNoWrap->connect_toggled(aLink);
140  mxRBWrapLeft->connect_toggled(aLink);
141  mxRBWrapRight->connect_toggled(aLink);
142  mxRBWrapParallel->connect_toggled(aLink);
143  mxRBWrapThrough->connect_toggled(aLink);
144  mxRBIdealWrap->connect_toggled(aLink);
145 
146  Link<weld::Button&,void> EditContourLink = LINK(this, WrapPropertyPanel, EditContourHdl);
147  mxEditContour->connect_clicked(EditContourLink);
148 
150  {
151  // Disable Edit Contour button for LOK purposes.
152  mxEditContour->hide();
153  }
154 
155  Link<weld::ToggleButton&, void> EnableContourLink = LINK(this,WrapPropertyPanel, EnableContourHdl);
156  mxEnableContour->connect_toggled(EnableContourLink);
157  mxSpacingLB->connect_changed(LINK(this, WrapPropertyPanel, SpacingLBHdl));
158 
161  {
164  }
165  else
166  {
169  }
173 
174  aCustomEntry = mxCustomEntry->get_label();
175 
183  mpBindings->Update( SID_ATTR_LRSPACE );
184  mpBindings->Update( SID_ATTR_ULSPACE );
185 
186 }
187 
189 {
190  if( (nLeft == nRight) && (nTop == nBottom) && (nLeft == nTop) )
191  {
192  sal_Int32 nCount = mxSpacingLB->get_count();
193  for (sal_Int32 i = 0; i < nCount; i++)
194  {
195  if (mxSpacingLB->get_id(i).toUInt32() == nLeft)
196  {
197  mxSpacingLB->set_active(i);
198  int nCustomEntry = mxSpacingLB->find_text(aCustomEntry);
199  if (nCustomEntry != -1)
200  mxSpacingLB->remove(nCustomEntry);
201  return;
202  }
203  }
204  }
205 
206  if (mxSpacingLB->find_text(aCustomEntry) == -1)
207  mxSpacingLB->append_text(aCustomEntry);
208  mxSpacingLB->set_active_text(aCustomEntry);
209 }
210 
212 {
213  SfxBoolItem aItem(SID_CONTOUR_DLG, true);
214  mpBindings->GetDispatcher()->ExecuteList(SID_CONTOUR_DLG,
215  SfxCallMode::RECORD, { &aItem });
216 }
217 
219 {
220  bool IsContour = mxEnableContour->get_active();
221  SfxBoolItem aItem(FN_FRAME_WRAP_CONTOUR, IsContour);
222  mpBindings->GetDispatcher()->ExecuteList(FN_FRAME_WRAP_CONTOUR,
223  SfxCallMode::RECORD, { &aItem });
224 }
225 
226 IMPL_LINK(WrapPropertyPanel, SpacingLBHdl, weld::ComboBox&, rBox, void)
227 {
228  sal_uInt16 nVal = rBox.get_active_id().toUInt32();
229 
230  SvxLRSpaceItem aLRItem(nVal, nVal, 0, 0, RES_LR_SPACE);
231  SvxULSpaceItem aULItem(nVal, nVal, RES_UL_SPACE);
232 
233  nTop = nBottom = nLeft = nRight = nVal;
234  mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_LRSPACE,
235  SfxCallMode::RECORD, { &aLRItem });
236  mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_ULSPACE,
237  SfxCallMode::RECORD, { &aULItem });
238 }
239 
241 {
242  sal_uInt16 nSlot = 0;
243  if ( mxRBWrapLeft->get_active() )
244  {
245  nSlot = FN_FRAME_WRAP_LEFT;
246  }
247  else if( mxRBWrapRight->get_active() )
248  {
249  nSlot = FN_FRAME_WRAP_RIGHT;
250  }
251  else if ( mxRBWrapParallel->get_active() )
252  {
253  nSlot = FN_FRAME_WRAP;
254  }
255  else if( mxRBWrapThrough->get_active() )
256  {
257  nSlot = FN_FRAME_WRAPTHRU;
258  }
259  else if( mxRBIdealWrap->get_active() )
260  {
261  nSlot = FN_FRAME_WRAP_IDEAL;
262  }
263  else
264  {
265  nSlot = FN_FRAME_NOWRAP;
266  }
267  SfxBoolItem bStateItem( nSlot, true );
268  mpBindings->GetDispatcher()->ExecuteList(nSlot,
269  SfxCallMode::RECORD, { &bStateItem });
270 
271 }
272 
274 {
275  if (mxRBNoWrap->get_active() || mxRBWrapThrough->get_active())
276  {
277  mxEnableContour->set_active(false);
278  mxEnableContour->set_sensitive(false);
279  }
280  else
281  {
282  mxEnableContour->set_sensitive(true);
283  }
284 
285 }
286 
288  const sal_uInt16 nSId,
289  const SfxItemState eState,
290  const SfxPoolItem* pState)
291 {
292  if ( eState == SfxItemState::DEFAULT &&
293  dynamic_cast< const SfxBoolItem *>( pState ) != nullptr )
294  {
295  //Set Radio Button enable
296  mxRBNoWrap->set_sensitive(true);
297  mxRBWrapLeft->set_sensitive(true);
298  mxRBWrapRight->set_sensitive(true);
299  mxRBWrapParallel->set_sensitive(true);
300  mxRBWrapThrough->set_sensitive(true);
301  mxRBIdealWrap->set_sensitive(true);
302  mxEnableContour->set_sensitive(true);
303 
304  const SfxBoolItem* pBoolItem = static_cast< const SfxBoolItem* >( pState );
305  switch( nSId )
306  {
307  case FN_FRAME_WRAP_RIGHT:
308  mxRBWrapRight->set_active( pBoolItem->GetValue() );
309  break;
310  case FN_FRAME_WRAP_LEFT:
311  mxRBWrapLeft->set_active( pBoolItem->GetValue() );
312  break;
313  case FN_FRAME_WRAPTHRU:
314  mxRBWrapThrough->set_active( pBoolItem->GetValue() );
315  break;
316  case FN_FRAME_WRAP_IDEAL:
317  mxRBIdealWrap->set_active( pBoolItem->GetValue() );
318  break;
319  case FN_FRAME_WRAP:
320  mxRBWrapParallel->set_active( pBoolItem->GetValue() );
321  break;
323  mxEnableContour->set_active( pBoolItem->GetValue() );
324  break;
325  case FN_FRAME_NOWRAP:
326  mxRBNoWrap->set_active( pBoolItem->GetValue() );
327  break;
328  }
330  }
331  switch(nSId)
332  {
333  case SID_ATTR_LRSPACE:
334  {
335  if(eState >= SfxItemState::DEFAULT)
336  {
337  const SvxLRSpaceItem* pItem = dynamic_cast< const SvxLRSpaceItem* >(pState);
338  if(pItem)
339  {
340  nLeft = pItem->GetLeft();
341  nRight = pItem->GetRight();
342 
343  UpdateSpacingLB();
344  }
345  }
346  }
347  break;
348  case SID_ATTR_ULSPACE:
349  {
350  if(eState >= SfxItemState::DEFAULT)
351  {
352  const SvxULSpaceItem* pItem = dynamic_cast< const SvxULSpaceItem* >(pState);
353  if(pItem)
354  {
355  nTop = pItem->GetUpper();
356  nBottom = pItem->GetLower();
357 
358  UpdateSpacingLB();
359  }
360  }
361  }
362  break;
363  }
364 }
365 
366 } // end of namespace ::sw::sidebar
367 
368 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
long GetLeft() const
bool GetValue() const
#define FN_FRAME_WRAP_RIGHT
Definition: cmdid.h:405
const char UNO_WRAPON[]
const char UNO_WRAPLEFT[]
FieldUnit
#define FN_FRAME_WRAP
Definition: cmdid.h:319
sal_uInt16 GetLower() const
virtual void NotifyItemUpdate(const sal_uInt16 nSId, const SfxItemState eState, const SfxPoolItem *pState) override
std::unique_ptr< weld::Label > mxCustomEntry
WrapPropertyPanel(vcl::Window *pParent, const css::uno::Reference< css::frame::XFrame > &rxFrame, SfxBindings *pBindings)
IMPL_LINK(PageColumnControl, ColumnButtonClickHdl_Impl, weld::Button &, rButton, void)
#define FN_FRAME_WRAP_IDEAL
Definition: cmdid.h:392
std::unique_ptr< weld::RadioButton > mxRBWrapRight
::sfx2::sidebar::ControllerItem maSwWrapParallelControl
std::unique_ptr< weld::RadioButton > mxRBNoWrap
std::unique_ptr< weld::RadioButton > mxRBWrapLeft
std::unique_ptr< weld::RadioButton > mxRBWrapThrough
::sfx2::sidebar::ControllerItem maSwULSpacingControl
int nCount
const char UNO_WRAPIDEAL[]
#define FN_FRAME_WRAP_LEFT
Definition: cmdid.h:404
css::uno::Reference< css::frame::XFrame > mxFrame
#define RES_UL_SPACE
Definition: hintids.hxx:292
std::unique_ptr< weld::ComboBox > mxSpacingLB
::sfx2::sidebar::ControllerItem maSwNoWrapControl
virtual void dispose() override
SW_DLLPUBLIC FieldUnit GetDfltMetric(bool bWeb)
Definition: uitool.cxx:698
::sfx2::sidebar::ControllerItem maSwWrapIdealControl
Reference< graphic::XGraphic > GetXGraphicForCommand(const OUString &rsCommandName, const Reference< frame::XFrame > &rxFrame, vcl::ImageType eImageType)
int i
static bool GetLayoutRTL()
std::unique_ptr< weld::CheckButton > mxEnableContour
IMPL_LINK_NOARG(PageColumnControl, MoreButtonClickHdl_Impl, weld::Button &, void)
::sfx2::sidebar::ControllerItem maSwWrapLeftControl
#define RES_LR_SPACE
Definition: hintids.hxx:291
void Update(sal_uInt16 nId)
virtual void dispose() override
::sfx2::sidebar::ControllerItem maSwWrapThroughControl
#define FN_FRAME_WRAPTHRU
Definition: cmdid.h:320
static VclPtr< vcl::Window > Create(vcl::Window *pParent, const css::uno::Reference< css::frame::XFrame > &rxFrame, SfxBindings *pBindings)
::sfx2::sidebar::ControllerItem maSwWrapRightControl
SfxItemState
const char UNO_WRAPOFF[]
const char UNO_WRAPTHROUGH[]
virtual void dispose() override
static VclPtr< reference_type > Create(Arg &&...arg)
::sfx2::sidebar::ControllerItem maSwLRSpacingControl
std::unique_ptr< weld::RadioButton > mxRBWrapParallel
long GetRight() const
bool IsInch(MapUnit eU)
std::unique_ptr< weld::RadioButton > mxRBIdealWrap
::sfx2::sidebar::ControllerItem maSwEnableContourControl
#define FN_FRAME_NOWRAP
Definition: cmdid.h:318
void Fill(SpacingType eType, weld::ComboBox &rComboBox)
const char UNO_WRAPRIGHT[]
#define FN_FRAME_WRAP_CONTOUR
Definition: cmdid.h:412
sal_uInt16 GetUpper() const
std::unique_ptr< weld::Button > mxEditContour