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 "PageFooterPanel.hxx"
26 #include <sfx2/dispatch.hxx>
27 #include <sfx2/bindings.hxx>
28 #include <cmdid.h>
29 
30 #include <com/sun/star/lang/IllegalArgumentException.hpp>
31 
32 namespace sw::sidebar{
33 
35  vcl::Window* pParent,
36  const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rxFrame,
37  SfxBindings* pBindings)
38 {
39  if( pParent == nullptr )
40  throw ::com::sun::star::lang::IllegalArgumentException("no parent window given to PageFooterPanel::Create", nullptr, 0);
41  if( !rxFrame.is() )
42  throw ::com::sun::star::lang::IllegalArgumentException("no XFrame given to PageFooterPanel::Create", nullptr, 0);
43 
44  return VclPtr<PageFooterPanel>::Create(pParent, rxFrame, pBindings);
45 }
46 
48 {
49  SpacingListBox::Fill(IsInch(meFUnit) ? SpacingType::SPACING_INCH : SpacingType::SPACING_CM, *mxFooterSpacingLB);
50  SpacingListBox::Fill(IsInch(meFUnit) ? SpacingType::MARGINS_INCH : SpacingType::MARGINS_CM, *mxFooterMarginPresetLB);
51 }
52 
54  vcl::Window* pParent,
55  const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rxFrame,
56  SfxBindings* pBindings) :
57  PanelLayout(pParent, "PageFooterPanel", "modules/swriter/ui/pagefooterpanel.ui", rxFrame),
58  mpBindings( pBindings ),
59  maHFToggleController(SID_ATTR_PAGE_FOOTER, *pBindings, *this),
60  maMetricController(SID_ATTR_METRIC, *pBindings,*this),
61  maFooterLRMarginController(SID_ATTR_PAGE_FOOTER_LRMARGIN, *pBindings, *this),
62  maFooterSpacingController(SID_ATTR_PAGE_FOOTER_SPACING, *pBindings, *this),
63  maFooterLayoutController(SID_ATTR_PAGE_FOOTER_LAYOUT, *pBindings, *this),
64  meFUnit(GetModuleFieldUnit()),
65  aCustomEntry(),
66  mpFooterItem( new SfxBoolItem(SID_ATTR_PAGE_FOOTER) ),
67  mpFooterLRMarginItem( new SvxLongLRSpaceItem(0, 0, SID_ATTR_PAGE_FOOTER_LRMARGIN)),
68  mpFooterSpacingItem( new SvxLongULSpaceItem(0, 0, SID_ATTR_PAGE_FOOTER_SPACING)),
69  mpFooterLayoutItem( new SfxInt16Item(SID_ATTR_PAGE_FOOTER_LAYOUT)),
70  mxFooterToggle(m_xBuilder->weld_check_button("footertoggle")),
71  mxFooterSpacingLB(m_xBuilder->weld_combo_box("spacingpreset")),
72  mxFooterMarginPresetLB(m_xBuilder->weld_combo_box("footermarginpreset")),
73  mxFooterLayoutLB(m_xBuilder->weld_combo_box("samecontentLB")),
74  mxCustomEntry(m_xBuilder->weld_label("customlabel"))
75 {
76  Initialize();
77 }
78 
80 {
81  disposeOnce();
82 }
83 
85 {
86  mxFooterToggle.reset();
88  mxFooterSpacingLB.reset();
89  mxFooterLayoutLB.reset();
90  mxFooterMarginPresetLB.reset();
91  mxCustomEntry.reset();
92 
94 }
95 
97 {
98  FieldUnit eUnit;
99 
100  if (pState && eState >= SfxItemState::DEFAULT)
101  eUnit = static_cast<FieldUnit>(static_cast<const SfxUInt16Item*>(pState)->GetValue());
102  else
103  eUnit = GetModuleFieldUnit();
104 
105  return eUnit;
106 }
107 
109 {
111 
113 
114  aCustomEntry = mxCustomEntry->get_label();
115  mxFooterToggle->connect_toggled( LINK(this, PageFooterPanel, FooterToggleHdl) );
116  mxFooterMarginPresetLB->connect_changed( LINK(this, PageFooterPanel, FooterLRMarginHdl));
117  mxFooterSpacingLB->connect_changed( LINK(this, PageFooterPanel, FooterSpacingHdl));
118  mxFooterLayoutLB->connect_changed( LINK(this, PageFooterPanel, FooterLayoutHdl));
119 
120  mpBindings->Invalidate(SID_ATTR_METRIC);
125 }
126 
128 {
129  if (mxFooterToggle->get_active())
130  {
131  mxFooterSpacingLB->set_sensitive(true);
132  mxFooterLayoutLB->set_sensitive(true);
133  mxFooterMarginPresetLB->set_sensitive(true);
134  }
135  else
136  {
137  mxFooterSpacingLB->set_sensitive(false);
138  mxFooterLayoutLB->set_sensitive(false);
139  mxFooterMarginPresetLB->set_sensitive(false);
140  }
141 }
142 
144 {
145  sal_uInt16 nLeft = mpFooterLRMarginItem->GetLeft();
146  sal_uInt16 nRight = mpFooterLRMarginItem->GetRight();
147  sal_uInt16 nCount = mxFooterMarginPresetLB->get_count();
148  if(nLeft == nRight)
149  {
150  for (sal_uInt16 i = 0; i < nCount; ++i)
151  {
152  if (mxFooterMarginPresetLB->get_id(i).toUInt32() == nLeft)
153  {
154  mxFooterMarginPresetLB->set_active(i);
155  int nCustomEntry = mxFooterMarginPresetLB->find_text(aCustomEntry);
156  if (nCustomEntry != -1)
157  mxFooterMarginPresetLB->remove(nCustomEntry);
158  return;
159  }
160  }
161  }
162  mxFooterMarginPresetLB->append_text(aCustomEntry);
163  mxFooterMarginPresetLB->set_active_text(aCustomEntry);
164 }
165 
167 {
168  sal_uInt16 nBottom = mpFooterSpacingItem->GetUpper();
169  sal_uInt16 nCount = mxFooterSpacingLB->get_count();
170  for (sal_uInt16 i = 0; i < nCount; ++i)
171  {
172  if (mxFooterSpacingLB->get_id(i).toUInt32() == nBottom)
173  {
174  mxFooterSpacingLB->set_active(i);
175  int nCustomEntry = mxFooterSpacingLB->find_text(aCustomEntry);
176  if (nCustomEntry != -1)
177  mxFooterSpacingLB->remove(nCustomEntry);
178  return;
179  }
180  }
181  mxFooterSpacingLB->append_text(aCustomEntry);
182  mxFooterSpacingLB->set_active_text(aCustomEntry);
183 }
184 
186 {
187  sal_uInt16 nLayout = mpFooterLayoutItem->GetValue();
188  mxFooterLayoutLB->set_active(nLayout);
189 }
190 
192  const sal_uInt16 nSid,
193  const SfxItemState eState,
194  const SfxPoolItem* pState)
195 {
196  if (IsDisposed())
197  return;
198 
199  switch(nSid)
200  {
202  {
203  if(eState >= SfxItemState::DEFAULT &&
204  dynamic_cast<const SfxBoolItem*>( pState) )
205  {
206  mpFooterItem.reset( static_cast<SfxBoolItem*>(pState->Clone()) );
207  mxFooterToggle->set_active(mpFooterItem->GetValue());
209  }
210  }
211  break;
213  {
214  if(eState >= SfxItemState::DEFAULT &&
215  dynamic_cast<const SvxLongLRSpaceItem*>( pState) )
216  {
217  mpFooterLRMarginItem.reset( static_cast<SvxLongLRSpaceItem*>(pState->Clone()) );
219  }
220  }
221  break;
223  {
224  if(eState >= SfxItemState::DEFAULT &&
225  dynamic_cast<const SvxLongULSpaceItem*>( pState) )
226  {
227  mpFooterSpacingItem.reset(static_cast<SvxLongULSpaceItem*>(pState->Clone()) );
229  }
230  }
231  break;
233  {
234  if(eState >= SfxItemState::DEFAULT &&
235  dynamic_cast<const SfxInt16Item*>( pState) )
236  {
237  mpFooterLayoutItem.reset(static_cast<SfxInt16Item*>(pState->Clone()) );
239  }
240  }
241  break;
242  case SID_ATTR_METRIC:
243  {
244  FieldUnit eFUnit = GetCurrentUnit(eState, pState);
245  if (meFUnit != eFUnit)
246  {
247  meFUnit = eFUnit;
251  }
252  }
253  break;
254  default:
255  break;
256  }
257 }
258 
260 {
261  bool IsChecked = mxFooterToggle->get_active();
262  mpFooterItem->SetValue(IsChecked);
263  GetBindings()->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_FOOTER, SfxCallMode::RECORD, { mpFooterItem.get() } );
264  UpdateFooterCheck();
265 }
266 
267 IMPL_LINK_NOARG( PageFooterPanel, FooterLRMarginHdl, weld::ComboBox&, void )
268 {
269  sal_uInt16 nVal = mxFooterMarginPresetLB->get_active_id().toUInt32();
270  mpFooterLRMarginItem->SetLeft(nVal);
271  mpFooterLRMarginItem->SetRight(nVal);
272  GetBindings()->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_FOOTER_LRMARGIN,
273  SfxCallMode::RECORD, { mpFooterLRMarginItem.get() } );
274 }
275 
276 IMPL_LINK_NOARG( PageFooterPanel, FooterSpacingHdl, weld::ComboBox&, void )
277 {
278  sal_uInt16 nVal = mxFooterSpacingLB->get_active_id().toUInt32();
279  mpFooterSpacingItem->SetUpper(nVal);
280  GetBindings()->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_FOOTER_SPACING,
281  SfxCallMode::RECORD, { mpFooterSpacingItem.get() } );
282 
283 }
284 IMPL_LINK_NOARG( PageFooterPanel, FooterLayoutHdl, weld::ComboBox&, void )
285 {
286  sal_uInt16 nVal = mxFooterLayoutLB->get_active();
287  mpFooterLayoutItem->SetValue(nVal);
288  GetBindings()->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_FOOTER_LAYOUT,
289  SfxCallMode::RECORD, { mpFooterLayoutItem.get() } );
290 }
291 
292 
293 }
294 
295 /* 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:858
#define SID_ATTR_PAGE_FOOTER_LAYOUT
Definition: cmdid.h:859
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:856
::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:857
std::unique_ptr< weld::ComboBox > mxFooterLayoutLB
IMPL_LINK_NOARG(PageColumnControl, MoreButtonClickHdl_Impl, weld::Button &, void)
static FieldUnit GetCurrentUnit(SfxItemState eState, const SfxPoolItem *pState)
std::unique_ptr< weld::CheckButton > mxFooterToggle
virtual void dispose() override
virtual ~PageFooterPanel() override
SfxItemState
::std::unique_ptr< SfxInt16Item > mpFooterLayoutItem
static VclPtr< reference_type > Create(Arg &&...arg)
virtual void dispose() override
bool IsInch(MapUnit eU)
static VclPtr< vcl::Window > Create(vcl::Window *pParent, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > &rxFrame, SfxBindings *pBindings)
::std::unique_ptr< SvxLongULSpaceItem > mpFooterSpacingItem
PageFooterPanel(vcl::Window *pParent, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > &rxFrame, SfxBindings *pBindings)
void Fill(weld::ComboBox &rComboBox)