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 <strings.hrc>
34 #include <uitool.hxx>
35 #include <com/sun/star/lang/IllegalArgumentException.hpp>
36 #include <comphelper/lok.hxx>
37 
38 namespace sw::sidebar {
39 
41  vcl::Window* pParent,
42  const css::uno::Reference< css::frame::XFrame >& rxFrame,
43  SfxBindings* pBindings)
44 {
45  if (pParent == nullptr)
46  throw css::lang::IllegalArgumentException("no parent Window given to WrapPropertyPanel::Create", nullptr, 0);
47  if ( ! rxFrame.is())
48  throw css::lang::IllegalArgumentException("no XFrame given to WrapPropertyPanel::Create", nullptr, 1);
49  if (pBindings == nullptr)
50  throw css::lang::IllegalArgumentException("no SfxBindings given to WrapPropertyPanel::Create", nullptr, 2);
51 
53  pParent,
54  rxFrame,
55  pBindings);
56 }
57 
59  vcl::Window* pParent,
60  const css::uno::Reference< css::frame::XFrame >& rxFrame,
61  SfxBindings* pBindings )
62  : PanelLayout(pParent, "WrapPropertyPanel", "modules/swriter/ui/sidebarwrap.ui", rxFrame)
63  , mpBindings(pBindings)
64  // spacing
65  , nTop(0)
66  , nBottom(0)
67  , nLeft(0)
68  , nRight(0)
69  // resources
70  , aCustomEntry(SwResId(STR_WRAP_PANEL_CUSTOM_STR))
71  // controller items
72  , maSwLRSpacingControl(SID_ATTR_LRSPACE, *pBindings, *this)
73  , maSwULSpacingControl(SID_ATTR_ULSPACE, *pBindings, *this)
74  , mxWrapOptions(m_xBuilder->weld_toolbar("wrapoptions"))
75  , mxWrapOptionsDispatch(new ToolbarUnoDispatcher(*mxWrapOptions, *m_xBuilder, rxFrame))
76  , mxSpacingLB(m_xBuilder->weld_combo_box("spacingLB"))
77 {
78  FieldUnit eMetric = ::GetDfltMetric(false);
79  SpacingListBox::Fill(IsInch(eMetric) ? SpacingType::SPACING_INCH : SpacingType::SPACING_CM, *mxSpacingLB);
80 
81  Initialize();
82 }
83 
85 {
86  disposeOnce();
87 }
88 
90 {
91  mxSpacingLB.reset();
92 
93  mxWrapOptionsDispatch.reset();
94  mxWrapOptions.reset();
95 
98 
100 }
101 
103 {
104  mxSpacingLB->connect_changed(LINK(this, WrapPropertyPanel, SpacingLBHdl));
105 
106  mpBindings->Update( SID_ATTR_LRSPACE );
107  mpBindings->Update( SID_ATTR_ULSPACE );
108 }
109 
111 {
112  if( (nLeft == nRight) && (nTop == nBottom) && (nLeft == nTop) )
113  {
114  sal_Int32 nCount = mxSpacingLB->get_count();
115  for (sal_Int32 i = 0; i < nCount; i++)
116  {
117  if (mxSpacingLB->get_id(i).toUInt32() == nLeft)
118  {
119  mxSpacingLB->set_active(i);
120  int nCustomEntry = mxSpacingLB->find_text(aCustomEntry);
121  if (nCustomEntry != -1)
122  mxSpacingLB->remove(nCustomEntry);
123  return;
124  }
125  }
126  }
127 
128  if (mxSpacingLB->find_text(aCustomEntry) == -1)
129  mxSpacingLB->append_text(aCustomEntry);
130  mxSpacingLB->set_active_text(aCustomEntry);
131 }
132 
133 IMPL_LINK(WrapPropertyPanel, SpacingLBHdl, weld::ComboBox&, rBox, void)
134 {
135  sal_uInt16 nVal = rBox.get_active_id().toUInt32();
136 
137  SvxLRSpaceItem aLRItem(nVal, nVal, 0, 0, RES_LR_SPACE);
138  SvxULSpaceItem aULItem(nVal, nVal, RES_UL_SPACE);
139 
140  nTop = nBottom = nLeft = nRight = nVal;
141  mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_LRSPACE,
142  SfxCallMode::RECORD, { &aLRItem });
143  mpBindings->GetDispatcher()->ExecuteList(SID_ATTR_ULSPACE,
144  SfxCallMode::RECORD, { &aULItem });
145 }
146 
148  const sal_uInt16 nSId,
149  const SfxItemState eState,
150  const SfxPoolItem* pState)
151 {
152  switch(nSId)
153  {
154  case SID_ATTR_LRSPACE:
155  {
156  if(eState >= SfxItemState::DEFAULT)
157  {
158  const SvxLRSpaceItem* pItem = dynamic_cast< const SvxLRSpaceItem* >(pState);
159  if(pItem)
160  {
161  nLeft = pItem->GetLeft();
162  nRight = pItem->GetRight();
163 
164  UpdateSpacingLB();
165  }
166  }
167  }
168  break;
169  case SID_ATTR_ULSPACE:
170  {
171  if(eState >= SfxItemState::DEFAULT)
172  {
173  const SvxULSpaceItem* pItem = dynamic_cast< const SvxULSpaceItem* >(pState);
174  if(pItem)
175  {
176  nTop = pItem->GetUpper();
177  nBottom = pItem->GetLower();
178 
179  UpdateSpacingLB();
180  }
181  }
182  }
183  break;
184  }
185 }
186 
187 } // end of namespace ::sw::sidebar
188 
189 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
long GetLeft() const
FieldUnit
sal_uInt16 GetLower() const
virtual void NotifyItemUpdate(const sal_uInt16 nSId, const SfxItemState eState, const SfxPoolItem *pState) override
std::unique_ptr< weld::Toolbar > mxWrapOptions
WrapPropertyPanel(vcl::Window *pParent, const css::uno::Reference< css::frame::XFrame > &rxFrame, SfxBindings *pBindings)
IMPL_LINK(PageColumnControl, ColumnButtonClickHdl_Impl, weld::Button &, rButton, void)
std::unique_ptr< ToolbarUnoDispatcher > mxWrapOptionsDispatch
::sfx2::sidebar::ControllerItem maSwULSpacingControl
int nCount
std::unique_ptr< weld::ComboBox > mxSpacingLB
virtual void dispose() override
SW_DLLPUBLIC FieldUnit GetDfltMetric(bool bWeb)
Definition: uitool.cxx:686
int i
virtual void dispose()
void Fill(SpacingType eType, weld::ComboBox &rComboBox)
OUString SwResId(const char *pId)
Definition: swmodule.cxx:165
void Update(sal_uInt16 nId)
virtual void dispose() override
static VclPtr< vcl::Window > Create(vcl::Window *pParent, const css::uno::Reference< css::frame::XFrame > &rxFrame, SfxBindings *pBindings)
SfxItemState
static VclPtr< reference_type > Create(Arg &&...arg)
::sfx2::sidebar::ControllerItem maSwLRSpacingControl
constexpr TypedWhichId< SvxLRSpaceItem > RES_LR_SPACE(91)
long GetRight() const
bool IsInch(MapUnit eU)
constexpr TypedWhichId< SvxULSpaceItem > RES_UL_SPACE(92)
sal_uInt16 GetUpper() const