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 <swtypes.hxx>
24 #include <svx/svxids.hrc>
25 #include <svx/svdtrans.hxx>
26 #include <sfx2/bindings.hxx>
27 #include <sfx2/dispatch.hxx>
29 #include <svl/eitem.hxx>
31 #include <vcl/svapp.hxx>
32 #include <vcl/lstbox.hxx>
33 #include <vcl/settings.hxx>
34 #include <editeng/lrspitem.hxx>
35 #include <editeng/ulspitem.hxx>
36 #include <hintids.hxx>
37 #include <uitool.hxx>
38 #include <com/sun/star/lang/IllegalArgumentException.hpp>
39 
40 const char UNO_WRAPOFF[] = ".uno:WrapOff";
41 const char UNO_WRAPLEFT[] = ".uno:WrapLeft";
42 const char UNO_WRAPRIGHT[] = ".uno:WrapRight";
43 const char UNO_WRAPON[] = ".uno:WrapOn";
44 const char UNO_WRAPTHROUGH[] = ".uno:WrapThrough";
45 const char UNO_WRAPIDEAL[] = ".uno:WrapIdeal";
46 
47 namespace sw { namespace sidebar {
48 
50  vcl::Window* pParent,
51  const css::uno::Reference< css::frame::XFrame >& rxFrame,
52  SfxBindings* pBindings)
53 {
54  if (pParent == nullptr)
55  throw css::lang::IllegalArgumentException("no parent Window given to WrapPropertyPanel::Create", nullptr, 0);
56  if ( ! rxFrame.is())
57  throw css::lang::IllegalArgumentException("no XFrame given to WrapPropertyPanel::Create", nullptr, 1);
58  if (pBindings == nullptr)
59  throw css::lang::IllegalArgumentException("no SfxBindings given to WrapPropertyPanel::Create", nullptr, 2);
60 
62  pParent,
63  rxFrame,
64  pBindings);
65 }
66 
68  vcl::Window* pParent,
69  const css::uno::Reference< css::frame::XFrame >& rxFrame,
70  SfxBindings* pBindings )
71  : PanelLayout(pParent, "WrapPropertyPanel", "modules/swriter/ui/sidebarwrap.ui", rxFrame)
72  , mxFrame( rxFrame )
73  , mpBindings(pBindings)
74  // spacing
75  , nTop(0)
76  , nBottom(0)
77  , nLeft(0)
78  , nRight(0)
79  // resources
80  , aCustomEntry()
81  // controller items
82  , maSwNoWrapControl(FN_FRAME_NOWRAP, *pBindings, *this)
83  , maSwWrapLeftControl(FN_FRAME_WRAP, *pBindings, *this)
84  , maSwWrapRightControl(FN_FRAME_WRAP_RIGHT, *pBindings, *this)
85  , maSwWrapParallelControl(FN_FRAME_WRAP_LEFT, *pBindings, *this)
86  , maSwWrapThroughControl(FN_FRAME_WRAPTHRU, *pBindings, *this)
87  , maSwWrapIdealControl(FN_FRAME_WRAP_IDEAL, *pBindings, *this)
88  , maSwEnableContourControl(FN_FRAME_WRAP_CONTOUR, *pBindings, *this)
89  , maSwLRSpacingControl(SID_ATTR_LRSPACE, *pBindings, *this)
90  , maSwULSpacingControl(SID_ATTR_ULSPACE, *pBindings, *this)
91 {
92  get(mpRBNoWrap, "buttonnone");
93  get(mpRBWrapLeft, "buttonbefore");
94  get(mpRBWrapRight, "buttonafter");
95  get(mpRBWrapParallel, "buttonparallel");
96  get(mpRBWrapThrough, "buttonthrough");
97  get(mpRBIdealWrap, "buttonoptimal");
98  get(mpEnableContour, "enablecontour");
99  get(mpEditContour, "editcontour");
100  get(mpSpacingLB, "spacingLB");
101  FieldUnit eMetric = ::GetDfltMetric(false);
102  mpSpacingLB->Init(IsInch(eMetric) ? SpacingType::SPACING_INCH : SpacingType::SPACING_CM);
103  get(mpCustomEntry, "customlabel");
104 
105  Initialize();
106 }
107 
109 {
110  disposeOnce();
111 }
112 
114 {
115  mpRBNoWrap.clear();
123  mpSpacingLB.clear();
125 
135 
137 }
138 
140 {
141  Link<Button*,void> aLink = LINK(this, WrapPropertyPanel, WrapTypeHdl);
142  mpRBNoWrap->SetClickHdl(aLink);
143  mpRBWrapLeft->SetClickHdl(aLink);
144  mpRBWrapRight->SetClickHdl(aLink);
147  mpRBIdealWrap->SetClickHdl(aLink);
148 
149  Link<Button*,void> EditContourLink = LINK(this, WrapPropertyPanel, EditContourHdl);
150  mpEditContour->SetClickHdl(EditContourLink);
151  Link<Button*, void> EnableContourLink = LINK(this,WrapPropertyPanel, EnableContourHdl);
152  mpEnableContour->SetClickHdl(EnableContourLink);
153  mpSpacingLB->SetSelectHdl(LINK(this, WrapPropertyPanel, SpacingLBHdl));
154 
157  {
160  }
161  else
162  {
165  }
169 
171 
179  mpBindings->Update( SID_ATTR_LRSPACE );
180  mpBindings->Update( SID_ATTR_ULSPACE );
181 
182 }
183 
185 {
186  if( (nLeft == nRight) && (nTop == nBottom) && (nLeft == nTop) )
187  {
188  for(sal_Int32 i = 0; i < mpSpacingLB->GetEntryCount(); i++)
189  {
190  if(reinterpret_cast<sal_uLong>(mpSpacingLB->GetEntryData(i)) == nLeft )
191  {
192  mpSpacingLB->SelectEntryPos(i);
193  mpSpacingLB->RemoveEntry(aCustomEntry);
194  return;
195  }
196  }
197  }
198 
199  if(mpSpacingLB->GetEntryPos(aCustomEntry) == LISTBOX_ENTRY_NOTFOUND)
200  mpSpacingLB->InsertEntry(aCustomEntry);
201  mpSpacingLB->SelectEntry(aCustomEntry);
202 }
203 
204 IMPL_LINK_NOARG(WrapPropertyPanel, EditContourHdl, Button*, void)
205 {
206  SfxBoolItem aItem(SID_CONTOUR_DLG, true);
207  mpBindings->GetDispatcher()->ExecuteList(SID_CONTOUR_DLG,
208  SfxCallMode::RECORD, { &aItem });
209 }
210 
211 IMPL_LINK_NOARG(WrapPropertyPanel, EnableContourHdl, Button*, void)
212 {
213  bool IsContour = mpEnableContour->IsChecked();
214  SfxBoolItem aItem(FN_FRAME_WRAP_CONTOUR, IsContour);
215  mpBindings->GetDispatcher()->ExecuteList(FN_FRAME_WRAP_CONTOUR,
216  SfxCallMode::RECORD, { &aItem });
217 }
218 
219 IMPL_LINK(WrapPropertyPanel, SpacingLBHdl, ListBox&, rBox, void)
220 {
221  sal_uInt16 nVal = static_cast<sal_uInt16>(reinterpret_cast<sal_uLong>(rBox.GetSelectedEntryData()));
222 
223  SvxLRSpaceItem aLRItem(nVal, nVal, 0, 0, RES_LR_SPACE);
224  SvxULSpaceItem aULItem(nVal, nVal, RES_UL_SPACE);
225 
226  nTop = nBottom = nLeft = nRight = nVal;
227  mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_LRSPACE,
228  SfxCallMode::RECORD, { &aLRItem });
229  mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_ULSPACE,
230  SfxCallMode::RECORD, { &aULItem });
231 }
232 
234 {
235  sal_uInt16 nSlot = 0;
236  if ( mpRBWrapLeft->IsChecked() )
237  {
238  nSlot = FN_FRAME_WRAP_LEFT;
239  }
240  else if( mpRBWrapRight->IsChecked() )
241  {
242  nSlot = FN_FRAME_WRAP_RIGHT;
243  }
244  else if ( mpRBWrapParallel->IsChecked() )
245  {
246  nSlot = FN_FRAME_WRAP;
247  }
248  else if( mpRBWrapThrough->IsChecked() )
249  {
250  nSlot = FN_FRAME_WRAPTHRU;
251  }
252  else if( mpRBIdealWrap->IsChecked() )
253  {
254  nSlot = FN_FRAME_WRAP_IDEAL;
255  }
256  else
257  {
258  nSlot = FN_FRAME_NOWRAP;
259  }
260  SfxBoolItem bStateItem( nSlot, true );
261  mpBindings->GetDispatcher()->ExecuteList(nSlot,
262  SfxCallMode::RECORD, { &bStateItem });
263 
264 }
265 
267 {
269  {
270  mpEnableContour->Check( false );
272  }
273  else
274  {
276  }
277 
278 }
279 
281  const sal_uInt16 nSId,
282  const SfxItemState eState,
283  const SfxPoolItem* pState,
284  const bool)
285 {
286  if ( eState == SfxItemState::DEFAULT &&
287  dynamic_cast< const SfxBoolItem *>( pState ) != nullptr )
288  {
289  //Set Radio Button enable
290  mpRBNoWrap->Enable();
291  mpRBWrapLeft->Enable();
297 
298  const SfxBoolItem* pBoolItem = static_cast< const SfxBoolItem* >( pState );
299  switch( nSId )
300  {
301  case FN_FRAME_WRAP_RIGHT:
302  mpRBWrapRight->Check( pBoolItem->GetValue() );
303  break;
304  case FN_FRAME_WRAP_LEFT:
305  mpRBWrapLeft->Check( pBoolItem->GetValue() );
306  break;
307  case FN_FRAME_WRAPTHRU:
308  mpRBWrapThrough->Check( pBoolItem->GetValue() );
309  break;
310  case FN_FRAME_WRAP_IDEAL:
311  mpRBIdealWrap->Check( pBoolItem->GetValue() );
312  break;
313  case FN_FRAME_WRAP:
314  mpRBWrapParallel->Check( pBoolItem->GetValue() );
315  break;
317  mpEnableContour->Check( pBoolItem->GetValue() );
318  break;
319  case FN_FRAME_NOWRAP:
320  mpRBNoWrap->Check( pBoolItem->GetValue() );
321  break;
322  }
324  }
325  switch(nSId)
326  {
327  case SID_ATTR_LRSPACE:
328  {
329  if(eState >= SfxItemState::DEFAULT)
330  {
331  const SvxLRSpaceItem* pItem = dynamic_cast< const SvxLRSpaceItem* >(pState);
332  if(pItem)
333  {
334  nLeft = pItem->GetLeft();
335  nRight = pItem->GetRight();
336 
337  UpdateSpacingLB();
338  }
339  }
340  }
341  break;
342  case SID_ATTR_ULSPACE:
343  {
344  if(eState >= SfxItemState::DEFAULT)
345  {
346  const SvxULSpaceItem* pItem = dynamic_cast< const SvxULSpaceItem* >(pState);
347  if(pItem)
348  {
349  nTop = pItem->GetUpper();
350  nBottom = pItem->GetLower();
351 
352  UpdateSpacingLB();
353  }
354  }
355  }
356  break;
357  }
358 }
359 
360 } } // end of namespace ::sw::sidebar
361 
362 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
long GetLeft() const
bool GetValue() const
#define FN_FRAME_WRAP_RIGHT
Definition: cmdid.h:396
const char UNO_WRAPON[]
const char UNO_WRAPLEFT[]
FieldUnit
#define FN_FRAME_WRAP
Definition: cmdid.h:310
sal_uInt16 GetLower() const
void SetModeRadioImage(const Image &rImage)
void SetClickHdl(const Link< Button *, void > &rLink)
void Init(SpacingType eType)
sal_uIntPtr sal_uLong
WrapPropertyPanel(vcl::Window *pParent, const css::uno::Reference< css::frame::XFrame > &rxFrame, SfxBindings *pBindings)
VclPtr< SpacingListBox > mpSpacingLB
Dialog to specify the properties of date form field.
Definition: accfrmobj.cxx:40
#define LISTBOX_ENTRY_NOTFOUND
#define FN_FRAME_WRAP_IDEAL
Definition: cmdid.h:383
::sfx2::sidebar::ControllerItem maSwWrapParallelControl
VclPtr< RadioButton > mpRBWrapThrough
void Enable(bool bEnable=true, bool bChild=true)
::sfx2::sidebar::ControllerItem maSwULSpacingControl
const char UNO_WRAPIDEAL[]
bool IsChecked() const
#define FN_FRAME_WRAP_LEFT
Definition: cmdid.h:395
css::uno::Reference< css::frame::XFrame > mxFrame
#define RES_UL_SPACE
Definition: hintids.hxx:197
virtual OUString GetText() const
::sfx2::sidebar::ControllerItem maSwNoWrapControl
VclPtr< RadioButton > mpRBWrapRight
Image GetImageForCommand(const OUString &rsCommandName, const Reference< frame::XFrame > &rxFrame, vcl::ImageType eImageType)
virtual void dispose() override
SW_DLLPUBLIC FieldUnit GetDfltMetric(bool bWeb)
Definition: uitool.cxx:710
void Check(bool bCheck=true)
::sfx2::sidebar::ControllerItem maSwWrapIdealControl
VclPtr< RadioButton > mpRBWrapLeft
IMPL_LINK_NOARG(PageColumnControl, MoreButtonClickHdl_Impl, Button *, void)
VclPtr< RadioButton > mpRBNoWrap
int i
static bool GetLayoutRTL()
void Check(bool bCheck=true)
::sfx2::sidebar::ControllerItem maSwWrapLeftControl
void Disable(bool bChild=true)
#define RES_LR_SPACE
Definition: hintids.hxx:196
void Update(sal_uInt16 nId)
virtual void dispose() override
::sfx2::sidebar::ControllerItem maSwWrapThroughControl
#define FN_FRAME_WRAPTHRU
Definition: cmdid.h:311
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[]
virtual void NotifyItemUpdate(const sal_uInt16 nSId, const SfxItemState eState, const SfxPoolItem *pState, const bool bIsEnabled) override
const char UNO_WRAPTHROUGH[]
virtual void dispose() override
VclPtr< RadioButton > mpRBWrapParallel
static VclPtr< reference_type > Create(Arg &&...arg)
::sfx2::sidebar::ControllerItem maSwLRSpacingControl
long GetRight() const
bool IsInch(MapUnit eU)
::sfx2::sidebar::ControllerItem maSwEnableContourControl
IMPL_LINK(PageColumnControl, ColumnButtonClickHdl_Impl, Button *, pButton, void)
#define FN_FRAME_NOWRAP
Definition: cmdid.h:309
VclPtr< RadioButton > mpRBIdealWrap
const char UNO_WRAPRIGHT[]
#define FN_FRAME_WRAP_CONTOUR
Definition: cmdid.h:403
sal_uInt16 GetUpper() const