LibreOffice Module sw (master)  1
PageFooterPanel.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 #include <sal/config.h>
20 #include <svl/intitem.hxx>
21 #include <svl/eitem.hxx>
22 #include <svx/dlgutil.hxx>
23 #include <svx/rulritem.hxx>
24 #include <svx/svdtrans.hxx>
25 #include <svx/spacinglistbox.hxx>
27 #include "PageFooterPanel.hxx"
28 #include <sfx2/dispatch.hxx>
29 #include <sfx2/bindings.hxx>
30 #include <cmdid.h>
31 
32 #include <com/sun/star/lang/IllegalArgumentException.hpp>
33 
34 namespace sw::sidebar{
35 
36 std::unique_ptr<PanelLayout> PageFooterPanel::Create(
37  weld::Widget* pParent,
38  SfxBindings* pBindings)
39 {
40  if( pParent == nullptr )
41  throw ::com::sun::star::lang::IllegalArgumentException("no parent window given to PageFooterPanel::Create", nullptr, 0);
42  return std::make_unique<PageFooterPanel>(pParent, pBindings);
43 }
44 
46 {
47  SpacingListBox::Fill(IsInch(meFUnit) ? SpacingType::SPACING_INCH : SpacingType::SPACING_CM, *mxFooterSpacingLB);
48  SpacingListBox::Fill(IsInch(meFUnit) ? SpacingType::MARGINS_INCH : SpacingType::MARGINS_CM, *mxFooterMarginPresetLB);
49 }
50 
52  weld::Widget* pParent,
53  SfxBindings* pBindings) :
54  PanelLayout(pParent, "PageFooterPanel", "modules/swriter/ui/pagefooterpanel.ui"),
55  mpBindings( pBindings ),
56  maHFToggleController(SID_ATTR_PAGE_FOOTER, *pBindings, *this),
57  maMetricController(SID_ATTR_METRIC, *pBindings,*this),
58  maFooterLRMarginController(SID_ATTR_PAGE_FOOTER_LRMARGIN, *pBindings, *this),
59  maFooterSpacingController(SID_ATTR_PAGE_FOOTER_SPACING, *pBindings, *this),
60  maFooterLayoutController(SID_ATTR_PAGE_FOOTER_LAYOUT, *pBindings, *this),
61  meFUnit(GetModuleFieldUnit()),
62  aCustomEntry(),
63  mpFooterItem( new SfxBoolItem(SID_ATTR_PAGE_FOOTER) ),
64  mpFooterLRMarginItem( new SvxLongLRSpaceItem(0, 0, SID_ATTR_PAGE_FOOTER_LRMARGIN)),
65  mpFooterSpacingItem( new SvxLongULSpaceItem(0, 0, SID_ATTR_PAGE_FOOTER_SPACING)),
66  mpFooterLayoutItem( new SfxInt16Item(SID_ATTR_PAGE_FOOTER_LAYOUT)),
67  mxFooterToggle(m_xBuilder->weld_check_button("footertoggle")),
68  mxFooterSpacingLB(m_xBuilder->weld_combo_box("spacingpreset")),
69  mxFooterMarginPresetLB(m_xBuilder->weld_combo_box("footermarginpreset")),
70  mxFooterLayoutLB(m_xBuilder->weld_combo_box("samecontentLB")),
71  mxCustomEntry(m_xBuilder->weld_label("customlabel"))
72 {
73  Initialize();
74 }
75 
77 {
78  mxFooterToggle.reset();
80  mxFooterSpacingLB.reset();
81  mxFooterLayoutLB.reset();
82  mxFooterMarginPresetLB.reset();
83  mxCustomEntry.reset();
84 }
85 
87 {
88  FieldUnit eUnit;
89 
90  if (pState && eState >= SfxItemState::DEFAULT)
91  eUnit = static_cast<FieldUnit>(static_cast<const SfxUInt16Item*>(pState)->GetValue());
92  else
93  eUnit = GetModuleFieldUnit();
94 
95  return eUnit;
96 }
97 
99 {
101 
103 
104  aCustomEntry = mxCustomEntry->get_label();
105  mxFooterToggle->connect_toggled( LINK(this, PageFooterPanel, FooterToggleHdl) );
106  mxFooterMarginPresetLB->connect_changed( LINK(this, PageFooterPanel, FooterLRMarginHdl));
107  mxFooterSpacingLB->connect_changed( LINK(this, PageFooterPanel, FooterSpacingHdl));
108  mxFooterLayoutLB->connect_changed( LINK(this, PageFooterPanel, FooterLayoutHdl));
109 
110  mpBindings->Invalidate(SID_ATTR_METRIC);
115 }
116 
118 {
119  if (mxFooterToggle->get_active())
120  {
121  mxFooterSpacingLB->set_sensitive(true);
122  mxFooterLayoutLB->set_sensitive(true);
123  mxFooterMarginPresetLB->set_sensitive(true);
124  }
125  else
126  {
127  mxFooterSpacingLB->set_sensitive(false);
128  mxFooterLayoutLB->set_sensitive(false);
129  mxFooterMarginPresetLB->set_sensitive(false);
130  }
131 }
132 
134 {
135  sal_uInt16 nLeft = mpFooterLRMarginItem->GetLeft();
136  sal_uInt16 nRight = mpFooterLRMarginItem->GetRight();
137  sal_uInt16 nCount = mxFooterMarginPresetLB->get_count();
138  if(nLeft == nRight)
139  {
140  for (sal_uInt16 i = 0; i < nCount; ++i)
141  {
142  if (mxFooterMarginPresetLB->get_id(i).toUInt32() == nLeft)
143  {
144  mxFooterMarginPresetLB->set_active(i);
145  int nCustomEntry = mxFooterMarginPresetLB->find_text(aCustomEntry);
146  if (nCustomEntry != -1)
147  mxFooterMarginPresetLB->remove(nCustomEntry);
148  return;
149  }
150  }
151  }
152  mxFooterMarginPresetLB->append_text(aCustomEntry);
153  mxFooterMarginPresetLB->set_active_text(aCustomEntry);
154 }
155 
157 {
158  sal_uInt16 nBottom = mpFooterSpacingItem->GetUpper();
159  sal_uInt16 nCount = mxFooterSpacingLB->get_count();
160  for (sal_uInt16 i = 0; i < nCount; ++i)
161  {
162  if (mxFooterSpacingLB->get_id(i).toUInt32() == nBottom)
163  {
164  mxFooterSpacingLB->set_active(i);
165  int nCustomEntry = mxFooterSpacingLB->find_text(aCustomEntry);
166  if (nCustomEntry != -1)
167  mxFooterSpacingLB->remove(nCustomEntry);
168  return;
169  }
170  }
171  mxFooterSpacingLB->append_text(aCustomEntry);
172  mxFooterSpacingLB->set_active_text(aCustomEntry);
173 }
174 
176 {
177  sal_uInt16 nLayout = mpFooterLayoutItem->GetValue();
178  mxFooterLayoutLB->set_active(nLayout);
179 }
180 
182  const sal_uInt16 nSid,
183  const SfxItemState eState,
184  const SfxPoolItem* pState)
185 {
186  if (!mxFooterToggle) //disposed
187  return;
188 
189  switch(nSid)
190  {
192  {
193  if(eState >= SfxItemState::DEFAULT &&
194  dynamic_cast<const SfxBoolItem*>( pState) )
195  {
196  mpFooterItem.reset( static_cast<SfxBoolItem*>(pState->Clone()) );
197  mxFooterToggle->set_active(mpFooterItem->GetValue());
199  }
200  }
201  break;
203  {
204  if(eState >= SfxItemState::DEFAULT &&
205  dynamic_cast<const SvxLongLRSpaceItem*>( pState) )
206  {
207  mpFooterLRMarginItem.reset( static_cast<SvxLongLRSpaceItem*>(pState->Clone()) );
209  }
210  }
211  break;
213  {
214  if(eState >= SfxItemState::DEFAULT &&
215  dynamic_cast<const SvxLongULSpaceItem*>( pState) )
216  {
217  mpFooterSpacingItem.reset(static_cast<SvxLongULSpaceItem*>(pState->Clone()) );
219  }
220  }
221  break;
223  {
224  if(eState >= SfxItemState::DEFAULT &&
225  dynamic_cast<const SfxInt16Item*>( pState) )
226  {
227  mpFooterLayoutItem.reset(static_cast<SfxInt16Item*>(pState->Clone()) );
229  }
230  }
231  break;
232  case SID_ATTR_METRIC:
233  {
234  FieldUnit eFUnit = GetCurrentUnit(eState, pState);
235  if (meFUnit != eFUnit)
236  {
237  meFUnit = eFUnit;
241  }
242  }
243  break;
244  default:
245  break;
246  }
247 }
248 
250 {
251  bool IsChecked = mxFooterToggle->get_active();
252  mpFooterItem->SetValue(IsChecked);
253  GetBindings()->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_FOOTER, SfxCallMode::RECORD, { mpFooterItem.get() } );
254  UpdateFooterCheck();
255 }
256 
257 IMPL_LINK_NOARG( PageFooterPanel, FooterLRMarginHdl, weld::ComboBox&, void )
258 {
259  sal_uInt16 nVal = mxFooterMarginPresetLB->get_active_id().toUInt32();
260  mpFooterLRMarginItem->SetLeft(nVal);
261  mpFooterLRMarginItem->SetRight(nVal);
262  GetBindings()->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_FOOTER_LRMARGIN,
263  SfxCallMode::RECORD, { mpFooterLRMarginItem.get() } );
264 }
265 
266 IMPL_LINK_NOARG( PageFooterPanel, FooterSpacingHdl, weld::ComboBox&, void )
267 {
268  sal_uInt16 nVal = mxFooterSpacingLB->get_active_id().toUInt32();
269  mpFooterSpacingItem->SetUpper(nVal);
270  GetBindings()->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_FOOTER_SPACING,
271  SfxCallMode::RECORD, { mpFooterSpacingItem.get() } );
272 
273 }
274 IMPL_LINK_NOARG( PageFooterPanel, FooterLayoutHdl, weld::ComboBox&, void )
275 {
276  sal_uInt16 nVal = mxFooterLayoutLB->get_active();
277  mpFooterLayoutItem->SetValue(nVal);
278  GetBindings()->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_FOOTER_LAYOUT,
279  SfxCallMode::RECORD, { mpFooterLayoutItem.get() } );
280 }
281 
282 
283 }
284 
285 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::std::unique_ptr< SvxLongLRSpaceItem > mpFooterLRMarginItem
FieldUnit
std::string GetValue
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const =0
void Invalidate(sal_uInt16 nId)
FieldUnit GetModuleFieldUnit(const SfxItemSet &rSet)
#define SID_ATTR_PAGE_FOOTER_SPACING
Definition: cmdid.h:867
#define SID_ATTR_PAGE_FOOTER_LAYOUT
Definition: cmdid.h:868
virtual void NotifyItemUpdate(const sal_uInt16 nSId, const SfxItemState eState, const SfxPoolItem *pState) override
int nCount
std::unique_ptr< weld::Label > mxCustomEntry
std::unique_ptr< weld::ComboBox > mxFooterMarginPresetLB
#define SID_ATTR_PAGE_FOOTER
Definition: cmdid.h:865
::sfx2::sidebar::ControllerItem maMetricController
int i
virtual void dispose()
std::unique_ptr< weld::ComboBox > mxFooterSpacingLB
::std::unique_ptr< SfxBoolItem > mpFooterItem
void Fill(SpacingType eType, weld::ComboBox &rComboBox)
#define SID_ATTR_PAGE_FOOTER_LRMARGIN
Definition: cmdid.h:866
std::unique_ptr< weld::ComboBox > mxFooterLayoutLB
IMPL_LINK_NOARG(PageColumnControl, MoreButtonClickHdl_Impl, weld::Button &, void)
PageFooterPanel(weld::Widget *pParent, SfxBindings *pBindings)
static FieldUnit GetCurrentUnit(SfxItemState eState, const SfxPoolItem *pState)
std::unique_ptr< weld::CheckButton > mxFooterToggle
virtual ~PageFooterPanel() override
SfxItemState
::std::unique_ptr< SfxInt16Item > mpFooterLayoutItem
bool IsInch(MapUnit eU)
static std::unique_ptr< PanelLayout > Create(weld::Widget *pParent, SfxBindings *pBindings)
::std::unique_ptr< SvxLongULSpaceItem > mpFooterSpacingItem
void Fill(weld::ComboBox &rComboBox)