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 <swtypes.hxx>
21 #include <svl/intitem.hxx>
22 #include <svl/eitem.hxx>
23 #include <editeng/sizeitem.hxx>
24 #include <editeng/paperinf.hxx>
25 #include <svx/svxids.hrc>
26 #include <svx/dlgutil.hxx>
27 #include <svx/rulritem.hxx>
28 #include <svx/svdtrans.hxx>
29 #include "PageFooterPanel.hxx"
31 #include <sfx2/dispatch.hxx>
32 #include <sfx2/bindings.hxx>
33 #include <sfx2/viewsh.hxx>
34 #include <sfx2/objsh.hxx>
35 #include <uitool.hxx>
36 #include <cmdid.h>
37 
38 #include <com/sun/star/lang/IllegalArgumentException.hpp>
39 
40 namespace sw { namespace sidebar{
41 
43  vcl::Window* pParent,
44  const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rxFrame,
45  SfxBindings* pBindings)
46 {
47  if( pParent == nullptr )
48  throw ::com::sun::star::lang::IllegalArgumentException("no parent window given to PageFooterPanel::Create", nullptr, 0);
49  if( !rxFrame.is() )
50  throw ::com::sun::star::lang::IllegalArgumentException("no XFrame given to PageFooterPanel::Create", nullptr, 0);
51 
52  return VclPtr<PageFooterPanel>::Create(pParent, rxFrame, pBindings);
53 }
54 
56  vcl::Window* pParent,
57  const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rxFrame,
58  SfxBindings* pBindings) :
59  PanelLayout(pParent, "PageFooterPanel", "modules/swriter/ui/pagefooterpanel.ui", rxFrame),
60  mpBindings( pBindings ),
61  maHFToggleController(SID_ATTR_PAGE_FOOTER, *pBindings, *this),
62  maFooterLRMarginController(SID_ATTR_PAGE_FOOTER_LRMARGIN, *pBindings, *this),
63  maFooterSpacingController(SID_ATTR_PAGE_FOOTER_SPACING, *pBindings, *this),
64  maFooterLayoutController(SID_ATTR_PAGE_FOOTER_LAYOUT, *pBindings, *this),
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 {
71  get(mpFooterToggle, "footertoggle");
72  get(mpFooterSpacingLB, "spacingpreset");
73  FieldUnit eMetric = ::GetDfltMetric(false);
74  mpFooterSpacingLB->Init(IsInch(eMetric) ? SpacingType::SPACING_INCH : SpacingType::SPACING_CM);
75  get(mpFooterLayoutLB, "samecontentLB");
76  get(mpFooterMarginPresetLB, "footermarginpreset");
77  mpFooterMarginPresetLB->Init(IsInch(GetModuleFieldUnit()) ? SpacingType::MARGINS_INCH : SpacingType::MARGINS_CM);
78  get(mpCustomEntry, "customlabel");
79 
80  Initialize();
81 }
82 
84 {
85  disposeOnce();
86 }
87 
89 {
95 
97 }
98 
100 {
102  mpFooterToggle->SetClickHdl( LINK(this, PageFooterPanel, FooterToggleHdl) );
103  mpFooterMarginPresetLB->SetSelectHdl( LINK(this, PageFooterPanel, FooterLRMarginHdl));
104  mpFooterSpacingLB->SetSelectHdl( LINK(this, PageFooterPanel, FooterSpacingHdl));
105  mpFooterLayoutLB->SetSelectHdl( LINK(this, PageFooterPanel, FooterLayoutHdl));
106 
111 }
112 
114 {
116  {
117  mpFooterSpacingLB->Enable();
118  mpFooterLayoutLB->Enable();
119  mpFooterMarginPresetLB->Enable();
120  }
121  else
122  {
123  mpFooterSpacingLB->Disable();
124  mpFooterLayoutLB->Disable();
125  mpFooterMarginPresetLB->Disable();
126  }
127 }
128 
130 {
131  sal_uInt16 nLeft = mpFooterLRMarginItem->GetLeft();
132  sal_uInt16 nRight = mpFooterLRMarginItem->GetRight();
133  sal_uInt16 nCount = mpFooterMarginPresetLB->GetEntryCount();
134  if(nLeft == nRight)
135  {
136  for(sal_uInt16 i = 0; i < nCount; i++)
137  {
138  if(reinterpret_cast<sal_uLong>(mpFooterMarginPresetLB->GetEntryData(i)) == nLeft )
139  {
140  mpFooterMarginPresetLB->SelectEntryPos(i);
141  mpFooterMarginPresetLB->RemoveEntry(aCustomEntry);
142  return;
143  }
144  }
145  }
146  mpFooterMarginPresetLB->InsertEntry(aCustomEntry);
147  mpFooterMarginPresetLB->SelectEntry(aCustomEntry);
148 }
149 
151 {
152  sal_uInt16 nBottom = mpFooterSpacingItem->GetUpper();
153  sal_uInt16 nCount = mpFooterSpacingLB->GetEntryCount();
154  for(sal_uInt16 i = 0; i < nCount; i++)
155  {
156  if(reinterpret_cast<sal_uLong>(mpFooterSpacingLB->GetEntryData(i)) == nBottom )
157  {
158  mpFooterSpacingLB->SelectEntryPos(i);
159  mpFooterSpacingLB->RemoveEntry(aCustomEntry);
160  return;
161  }
162  }
163  mpFooterSpacingLB->InsertEntry(aCustomEntry);
164  mpFooterSpacingLB->SelectEntry(aCustomEntry);
165 }
166 
168 {
169  sal_uInt16 nLayout = mpFooterLayoutItem->GetValue();
170  mpFooterLayoutLB->SelectEntryPos( nLayout );
171 }
172 
174  const sal_uInt16 nSid,
175  const SfxItemState eState,
176  const SfxPoolItem* pState,
177  const bool)
178 {
179  if (IsDisposed())
180  return;
181 
182  switch(nSid)
183  {
185  {
186  if(eState >= SfxItemState::DEFAULT &&
187  dynamic_cast<const SfxBoolItem*>( pState) )
188  {
189  mpFooterItem.reset( static_cast<SfxBoolItem*>(pState->Clone()) );
190  mpFooterToggle->Check(mpFooterItem->GetValue());
192  }
193  }
194  break;
196  {
197  if(eState >= SfxItemState::DEFAULT &&
198  dynamic_cast<const SvxLongLRSpaceItem*>( pState) )
199  {
200  mpFooterLRMarginItem.reset( static_cast<SvxLongLRSpaceItem*>(pState->Clone()) );
202  }
203  }
204  break;
206  {
207  if(eState >= SfxItemState::DEFAULT &&
208  dynamic_cast<const SvxLongULSpaceItem*>( pState) )
209  {
210  mpFooterSpacingItem.reset(static_cast<SvxLongULSpaceItem*>(pState->Clone()) );
212  }
213  }
214  break;
216  {
217  if(eState >= SfxItemState::DEFAULT &&
218  dynamic_cast<const SfxInt16Item*>( pState) )
219  {
220  mpFooterLayoutItem.reset(static_cast<SfxInt16Item*>(pState->Clone()) );
222  }
223  }
224  break;
225  default:
226  break;
227  }
228 }
229 
230 IMPL_LINK_NOARG( PageFooterPanel, FooterToggleHdl, Button*, void )
231 {
232  bool IsChecked = mpFooterToggle->IsChecked();
233  mpFooterItem->SetValue(IsChecked);
234  GetBindings()->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_FOOTER, SfxCallMode::RECORD, { mpFooterItem.get() } );
235  UpdateFooterCheck();
236 }
237 
238 IMPL_LINK_NOARG( PageFooterPanel, FooterLRMarginHdl, ListBox&, void )
239 {
240  sal_uInt16 nVal = static_cast<sal_uInt16>(reinterpret_cast<sal_uLong>(mpFooterMarginPresetLB->GetSelectedEntryData()));
241  mpFooterLRMarginItem->SetLeft(nVal);
242  mpFooterLRMarginItem->SetRight(nVal);
243  GetBindings()->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_FOOTER_LRMARGIN,
244  SfxCallMode::RECORD, { mpFooterLRMarginItem.get() } );
245 }
246 
247 IMPL_LINK_NOARG( PageFooterPanel, FooterSpacingHdl, ListBox&, void )
248 {
249  sal_uInt16 nVal = static_cast<sal_uInt16>(reinterpret_cast<sal_uLong>(mpFooterSpacingLB->GetSelectedEntryData()));
250  mpFooterSpacingItem->SetUpper(nVal);
251  GetBindings()->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_FOOTER_SPACING,
252  SfxCallMode::RECORD, { mpFooterSpacingItem.get() } );
253 
254 }
255 IMPL_LINK_NOARG( PageFooterPanel, FooterLayoutHdl, ListBox&, void )
256 {
257  sal_uInt16 nVal = mpFooterLayoutLB->GetSelectedEntryPos();
258  mpFooterLayoutItem->SetValue(nVal);
259  GetBindings()->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_FOOTER_LAYOUT,
260  SfxCallMode::RECORD, { mpFooterLayoutItem.get() } );
261 }
262 
263 
264 } }
265 
266 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::std::unique_ptr< SvxLongLRSpaceItem > mpFooterLRMarginItem
FieldUnit
void SetClickHdl(const Link< Button *, void > &rLink)
void Init(SpacingType eType)
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const =0
sal_uIntPtr sal_uLong
Dialog to specify the properties of date form field.
Definition: accfrmobj.cxx:40
void Invalidate(sal_uInt16 nId)
FieldUnit GetModuleFieldUnit(const SfxItemSet &rSet)
#define SID_ATTR_PAGE_FOOTER_SPACING
Definition: cmdid.h:841
#define SID_ATTR_PAGE_FOOTER_LAYOUT
Definition: cmdid.h:842
VclPtr< FixedText > mpCustomEntry
virtual OUString GetText() const
#define SID_ATTR_PAGE_FOOTER
Definition: cmdid.h:839
SW_DLLPUBLIC FieldUnit GetDfltMetric(bool bWeb)
Definition: uitool.cxx:710
IMPL_LINK_NOARG(PageColumnControl, MoreButtonClickHdl_Impl, Button *, void)
::std::unique_ptr< SfxBoolItem > mpFooterItem
int i
virtual void NotifyItemUpdate(const sal_uInt16 nSId, const SfxItemState eState, const SfxPoolItem *pState, const bool bIsEnabled) override
#define SID_ATTR_PAGE_FOOTER_LRMARGIN
Definition: cmdid.h:840
bool IsChecked() const
VclPtr< SameContentListBox > mpFooterLayoutLB
void Check(bool bCheck=true)
virtual void dispose() override
VclPtr< SpacingListBox > mpFooterSpacingLB
virtual ~PageFooterPanel() override
SfxItemState
::std::unique_ptr< SfxInt16Item > mpFooterLayoutItem
VclPtr< CheckBox > mpFooterToggle
static VclPtr< reference_type > Create(Arg &&...arg)
virtual void dispose() override
bool IsInch(MapUnit eU)
VclPtr< SpacingListBox > mpFooterMarginPresetLB
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)