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>
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
34namespace sw::sidebar{
35
36std::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 mpFooterItem( new SfxBoolItem(SID_ATTR_PAGE_FOOTER) ),
63 mpFooterLRMarginItem( new SvxLongLRSpaceItem(0, 0, SID_ATTR_PAGE_FOOTER_LRMARGIN)),
64 mpFooterSpacingItem( new SvxLongULSpaceItem(0, 0, SID_ATTR_PAGE_FOOTER_SPACING)),
65 mpFooterLayoutItem( new SfxInt16Item(SID_ATTR_PAGE_FOOTER_LAYOUT)),
66 mxFooterToggle(m_xBuilder->weld_check_button("footertoggle")),
67 mxFooterSpacingLB(m_xBuilder->weld_combo_box("spacingpreset")),
68 mxFooterMarginPresetLB(m_xBuilder->weld_combo_box("footermarginpreset")),
69 mxFooterLayoutLB(m_xBuilder->weld_combo_box("samecontentLB")),
70 mxCustomEntry(m_xBuilder->weld_label("customlabel"))
71{
72 Initialize();
73}
74
76{
77 mxFooterToggle.reset();
79 mxFooterSpacingLB.reset();
80 mxFooterLayoutLB.reset();
82 mxCustomEntry.reset();
83}
84
86{
87 FieldUnit eUnit;
88
89 if (pState && eState >= SfxItemState::DEFAULT)
90 eUnit = static_cast<FieldUnit>(static_cast<const SfxUInt16Item*>(pState)->GetValue());
91 else
92 eUnit = GetModuleFieldUnit();
93
94 return eUnit;
95}
96
98{
100
102
103 m_aCustomEntry = mxCustomEntry->get_label();
104 mxFooterToggle->connect_toggled( LINK(this, PageFooterPanel, FooterToggleHdl) );
105 mxFooterMarginPresetLB->connect_changed( LINK(this, PageFooterPanel, FooterLRMarginHdl));
106 mxFooterSpacingLB->connect_changed( LINK(this, PageFooterPanel, FooterSpacingHdl));
107 mxFooterLayoutLB->connect_changed( LINK(this, PageFooterPanel, FooterLayoutHdl));
108
109 mpBindings->Invalidate(SID_ATTR_METRIC);
114}
115
117{
118 if (mxFooterToggle->get_active())
119 {
120 mxFooterSpacingLB->set_sensitive(true);
121 mxFooterLayoutLB->set_sensitive(true);
122 mxFooterMarginPresetLB->set_sensitive(true);
123 }
124 else
125 {
126 mxFooterSpacingLB->set_sensitive(false);
127 mxFooterLayoutLB->set_sensitive(false);
128 mxFooterMarginPresetLB->set_sensitive(false);
129 }
130}
131
133{
134 sal_uInt16 nLeft = mpFooterLRMarginItem->GetLeft();
135 sal_uInt16 nRight = mpFooterLRMarginItem->GetRight();
136 sal_uInt16 nCount = mxFooterMarginPresetLB->get_count();
137 if(nLeft == nRight)
138 {
139 for (sal_uInt16 i = 0; i < nCount; ++i)
140 {
141 if (mxFooterMarginPresetLB->get_id(i).toUInt32() == nLeft)
142 {
143 mxFooterMarginPresetLB->set_active(i);
144 int nCustomEntry = mxFooterMarginPresetLB->find_text(m_aCustomEntry);
145 if (nCustomEntry != -1)
146 mxFooterMarginPresetLB->remove(nCustomEntry);
147 return;
148 }
149 }
150 }
152 mxFooterMarginPresetLB->set_active_text(m_aCustomEntry);
153}
154
156{
157 sal_uInt16 nBottom = mpFooterSpacingItem->GetUpper();
158 sal_uInt16 nCount = mxFooterSpacingLB->get_count();
159 for (sal_uInt16 i = 0; i < nCount; ++i)
160 {
161 if (mxFooterSpacingLB->get_id(i).toUInt32() == nBottom)
162 {
163 mxFooterSpacingLB->set_active(i);
164 int nCustomEntry = mxFooterSpacingLB->find_text(m_aCustomEntry);
165 if (nCustomEntry != -1)
166 mxFooterSpacingLB->remove(nCustomEntry);
167 return;
168 }
169 }
170 mxFooterSpacingLB->append_text(m_aCustomEntry);
171 mxFooterSpacingLB->set_active_text(m_aCustomEntry);
172}
173
175{
176 sal_uInt16 nLayout = mpFooterLayoutItem->GetValue();
177 mxFooterLayoutLB->set_active(nLayout);
178}
179
181 const sal_uInt16 nSid,
182 const SfxItemState eState,
183 const SfxPoolItem* pState)
184{
185 if (!mxFooterToggle) //disposed
186 return;
187
188 switch(nSid)
189 {
191 {
192 if(eState >= SfxItemState::DEFAULT &&
193 dynamic_cast<const SfxBoolItem*>( pState) )
194 {
195 mpFooterItem.reset( static_cast<SfxBoolItem*>(pState->Clone()) );
196 mxFooterToggle->set_active(mpFooterItem->GetValue());
198 }
199 }
200 break;
202 {
203 if(eState >= SfxItemState::DEFAULT &&
204 dynamic_cast<const SvxLongLRSpaceItem*>( pState) )
205 {
206 mpFooterLRMarginItem.reset( static_cast<SvxLongLRSpaceItem*>(pState->Clone()) );
208 }
209 }
210 break;
212 {
213 if(eState >= SfxItemState::DEFAULT &&
214 dynamic_cast<const SvxLongULSpaceItem*>( pState) )
215 {
216 mpFooterSpacingItem.reset(static_cast<SvxLongULSpaceItem*>(pState->Clone()) );
218 }
219 }
220 break;
222 {
223 if(eState >= SfxItemState::DEFAULT &&
224 dynamic_cast<const SfxInt16Item*>( pState) )
225 {
226 mpFooterLayoutItem.reset(static_cast<SfxInt16Item*>(pState->Clone()) );
228 }
229 }
230 break;
231 case SID_ATTR_METRIC:
232 {
233 FieldUnit eFUnit = GetCurrentUnit(eState, pState);
234 if (meFUnit != eFUnit)
235 {
236 meFUnit = eFUnit;
240 }
241 }
242 break;
243 default:
244 break;
245 }
246}
247
249{
250 bool IsChecked = mxFooterToggle->get_active();
251 mpFooterItem->SetValue(IsChecked);
252 GetBindings()->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_FOOTER, SfxCallMode::RECORD, { mpFooterItem.get() } );
253 UpdateFooterCheck();
254}
255
256IMPL_LINK_NOARG( PageFooterPanel, FooterLRMarginHdl, weld::ComboBox&, void )
257{
258 sal_uInt16 nVal = mxFooterMarginPresetLB->get_active_id().toUInt32();
259 mpFooterLRMarginItem->SetLeft(nVal);
260 mpFooterLRMarginItem->SetRight(nVal);
262 SfxCallMode::RECORD, { mpFooterLRMarginItem.get() } );
263}
264
266{
267 sal_uInt16 nVal = mxFooterSpacingLB->get_active_id().toUInt32();
268 mpFooterSpacingItem->SetUpper(nVal);
270 SfxCallMode::RECORD, { mpFooterSpacingItem.get() } );
271
272}
274{
275 sal_uInt16 nVal = mxFooterLayoutLB->get_active();
276 mpFooterLayoutItem->SetValue(nVal);
278 SfxCallMode::RECORD, { mpFooterLayoutItem.get() } );
279}
280
281
282}
283
284/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SfxDispatcher * GetDispatcher() const
void Invalidate(sal_uInt16 nId)
virtual void dispose()
const SfxPoolItem * ExecuteList(sal_uInt16 nSlot, SfxCallMode nCall, std::initializer_list< SfxPoolItem const * > args, std::initializer_list< SfxPoolItem const * > internalargs=std::initializer_list< SfxPoolItem const * >())
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const=0
static FieldUnit GetCurrentUnit(SfxItemState eState, const SfxPoolItem *pState)
::std::unique_ptr< SvxLongLRSpaceItem > mpFooterLRMarginItem
::sfx2::sidebar::ControllerItem maMetricController
std::unique_ptr< weld::ComboBox > mxFooterSpacingLB
virtual void NotifyItemUpdate(const sal_uInt16 nSId, const SfxItemState eState, const SfxPoolItem *pState) override
std::unique_ptr< weld::Label > mxCustomEntry
::std::unique_ptr< SfxBoolItem > mpFooterItem
virtual ~PageFooterPanel() override
static std::unique_ptr< PanelLayout > Create(weld::Widget *pParent, SfxBindings *pBindings)
std::unique_ptr< weld::CheckButton > mxFooterToggle
std::unique_ptr< weld::ComboBox > mxFooterLayoutLB
std::unique_ptr< weld::ComboBox > mxFooterMarginPresetLB
::std::unique_ptr< SfxInt16Item > mpFooterLayoutItem
PageFooterPanel(weld::Widget *pParent, SfxBindings *pBindings)
::std::unique_ptr< SvxLongULSpaceItem > mpFooterSpacingItem
#define SID_ATTR_PAGE_FOOTER_SPACING
Definition: cmdid.h:903
#define SID_ATTR_PAGE_FOOTER_LAYOUT
Definition: cmdid.h:904
#define SID_ATTR_PAGE_FOOTER
Definition: cmdid.h:901
#define SID_ATTR_PAGE_FOOTER_LRMARGIN
Definition: cmdid.h:902
int nCount
virtual SfxBindings & GetBindings() override
SVXCORE_DLLPUBLIC FieldUnit GetModuleFieldUnit(const SfxItemSet &)
FieldUnit
void Fill(weld::ComboBox &rComboBox)
void Fill(SpacingType eType, weld::ComboBox &rComboBox)
int i
IMPL_LINK_NOARG(AccessibilityCheckEntry, GotoButtonClicked, weld::LinkButton &, bool)
const char GetValue[]
SfxItemState
bool IsInch(MapUnit eU)