1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #include <sal/config.h>
20 #include <svl/intitem.hxx>
21 #include <svl/eitem.hxx>
22 #include <svl/itemset.hxx>
23 #include <svx/dlgutil.hxx>
24 #include <svx/rulritem.hxx>
25 #include <svx/svdtrans.hxx>
26 #include <svx/spacinglistbox.hxx>
27 #include <svx/samecontentlistbox.hxx>
28 #include "PageFooterPanel.hxx"
29 #include <sfx2/dispatch.hxx>
30 #include <sfx2/bindings.hxx>
33 #include <com/sun/star/lang/IllegalArgumentException.hpp>
35 namespace sw::sidebar
{
37 std::unique_ptr
<PanelLayout
> PageFooterPanel::Create(
38 weld::Widget
* pParent
,
39 SfxBindings
* pBindings
)
41 if( pParent
== nullptr )
42 throw css::lang::IllegalArgumentException(u
"no parent window given to PageFooterPanel::Create"_ustr
, nullptr, 0);
43 return std::make_unique
<PageFooterPanel
>(pParent
, pBindings
);
46 void PageFooterPanel::SetMarginsAndSpacingFieldUnit()
48 SpacingListBox::Fill(IsInch(meFUnit
) ? SpacingType::SPACING_INCH
: SpacingType::SPACING_CM
, *mxFooterSpacingLB
);
49 SpacingListBox::Fill(IsInch(meFUnit
) ? SpacingType::MARGINS_INCH
: SpacingType::MARGINS_CM
, *mxFooterMarginPresetLB
);
52 PageFooterPanel::PageFooterPanel(
53 weld::Widget
* pParent
,
54 SfxBindings
* pBindings
) :
55 PanelLayout(pParent
, u
"PageFooterPanel"_ustr
, u
"modules/swriter/ui/pagefooterpanel.ui"_ustr
),
56 mpBindings( pBindings
),
57 maHFToggleController(SID_ATTR_PAGE_FOOTER
, *pBindings
, *this),
58 maMetricController(SID_ATTR_METRIC
, *pBindings
,*this),
59 maFooterLRMarginController(SID_ATTR_PAGE_FOOTER_LRMARGIN
, *pBindings
, *this),
60 maFooterSpacingController(SID_ATTR_PAGE_FOOTER_SPACING
, *pBindings
, *this),
61 maFooterLayoutController(SID_ATTR_PAGE_FOOTER_LAYOUT
, *pBindings
, *this),
62 meFUnit(GetModuleFieldUnit()),
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(u
"footertoggle"_ustr
)),
68 mxFooterSpacingLB(m_xBuilder
->weld_combo_box(u
"spacingpreset"_ustr
)),
69 mxFooterMarginPresetLB(m_xBuilder
->weld_combo_box(u
"footermarginpreset"_ustr
)),
70 mxFooterLayoutLB(m_xBuilder
->weld_combo_box(u
"samecontentLB"_ustr
)),
71 mxCustomEntry(m_xBuilder
->weld_label(u
"customlabel"_ustr
))
76 PageFooterPanel::~PageFooterPanel()
78 mxFooterToggle
.reset();
79 maMetricController
.dispose();
80 mxFooterSpacingLB
.reset();
81 mxFooterLayoutLB
.reset();
82 mxFooterMarginPresetLB
.reset();
83 mxCustomEntry
.reset();
86 FieldUnit
PageFooterPanel::GetCurrentUnit(SfxItemState eState
, const SfxPoolItem
* pState
)
90 if (pState
&& eState
>= SfxItemState::DEFAULT
)
91 eUnit
= static_cast<FieldUnit
>(static_cast<const SfxUInt16Item
*>(pState
)->GetValue());
93 eUnit
= GetModuleFieldUnit();
98 void PageFooterPanel::Initialize()
100 SameContentListBox::Fill(*mxFooterLayoutLB
);
102 SetMarginsAndSpacingFieldUnit();
104 m_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
));
110 mpBindings
->Invalidate(SID_ATTR_METRIC
);
111 mpBindings
->Invalidate(SID_ATTR_PAGE_FOOTER
);
112 mpBindings
->Invalidate(SID_ATTR_PAGE_FOOTER_LRMARGIN
);
113 mpBindings
->Invalidate(SID_ATTR_PAGE_FOOTER_SPACING
);
114 mpBindings
->Invalidate(SID_ATTR_PAGE_FOOTER_LAYOUT
);
117 void PageFooterPanel::UpdateFooterCheck()
119 if (mxFooterToggle
->get_active())
121 mxFooterSpacingLB
->set_sensitive(true);
122 mxFooterLayoutLB
->set_sensitive(true);
123 mxFooterMarginPresetLB
->set_sensitive(true);
127 mxFooterSpacingLB
->set_sensitive(false);
128 mxFooterLayoutLB
->set_sensitive(false);
129 mxFooterMarginPresetLB
->set_sensitive(false);
133 void PageFooterPanel::UpdateMarginControl()
135 sal_uInt16 nLeft
= mpFooterLRMarginItem
->GetLeft();
136 sal_uInt16 nRight
= mpFooterLRMarginItem
->GetRight();
137 sal_uInt16 nCount
= mxFooterMarginPresetLB
->get_count();
140 for (sal_uInt16 i
= 0; i
< nCount
; ++i
)
142 if (mxFooterMarginPresetLB
->get_id(i
).toUInt32() == nLeft
)
144 mxFooterMarginPresetLB
->set_active(i
);
145 int nCustomEntry
= mxFooterMarginPresetLB
->find_text(m_aCustomEntry
);
146 if (nCustomEntry
!= -1)
147 mxFooterMarginPresetLB
->remove(nCustomEntry
);
152 mxFooterMarginPresetLB
->append_text(m_aCustomEntry
);
153 mxFooterMarginPresetLB
->set_active_text(m_aCustomEntry
);
156 void PageFooterPanel::UpdateSpacingControl()
158 sal_uInt16 nBottom
= mpFooterSpacingItem
->GetUpper();
159 sal_uInt16 nCount
= mxFooterSpacingLB
->get_count();
160 for (sal_uInt16 i
= 0; i
< nCount
; ++i
)
162 if (mxFooterSpacingLB
->get_id(i
).toUInt32() == nBottom
)
164 mxFooterSpacingLB
->set_active(i
);
165 int nCustomEntry
= mxFooterSpacingLB
->find_text(m_aCustomEntry
);
166 if (nCustomEntry
!= -1)
167 mxFooterSpacingLB
->remove(nCustomEntry
);
171 mxFooterSpacingLB
->append_text(m_aCustomEntry
);
172 mxFooterSpacingLB
->set_active_text(m_aCustomEntry
);
175 void PageFooterPanel::UpdateLayoutControl()
177 sal_uInt16 nLayout
= mpFooterLayoutItem
->GetValue();
178 mxFooterLayoutLB
->set_active(nLayout
);
181 void PageFooterPanel::NotifyItemUpdate(
182 const sal_uInt16 nSid
,
183 const SfxItemState eState
,
184 const SfxPoolItem
* pState
)
186 if (!mxFooterToggle
) //disposed
191 case SID_ATTR_PAGE_FOOTER
:
193 if(eState
>= SfxItemState::DEFAULT
&&
194 dynamic_cast<const SfxBoolItem
*>( pState
) )
196 mpFooterItem
.reset( static_cast<SfxBoolItem
*>(pState
->Clone()) );
197 mxFooterToggle
->set_active(mpFooterItem
->GetValue());
202 case SID_ATTR_PAGE_FOOTER_LRMARGIN
:
204 if(eState
>= SfxItemState::DEFAULT
&&
205 dynamic_cast<const SvxLongLRSpaceItem
*>( pState
) )
207 mpFooterLRMarginItem
.reset( static_cast<SvxLongLRSpaceItem
*>(pState
->Clone()) );
208 UpdateMarginControl();
212 case SID_ATTR_PAGE_FOOTER_SPACING
:
214 if(eState
>= SfxItemState::DEFAULT
&&
215 dynamic_cast<const SvxLongULSpaceItem
*>( pState
) )
217 mpFooterSpacingItem
.reset(static_cast<SvxLongULSpaceItem
*>(pState
->Clone()) );
218 UpdateSpacingControl();
222 case SID_ATTR_PAGE_FOOTER_LAYOUT
:
224 if(eState
>= SfxItemState::DEFAULT
&&
225 dynamic_cast<const SfxInt16Item
*>( pState
) )
227 mpFooterLayoutItem
.reset(static_cast<SfxInt16Item
*>(pState
->Clone()) );
228 UpdateLayoutControl();
232 case SID_ATTR_METRIC
:
234 FieldUnit eFUnit
= GetCurrentUnit(eState
, pState
);
235 if (meFUnit
!= eFUnit
)
238 SetMarginsAndSpacingFieldUnit();
239 UpdateSpacingControl();
240 UpdateMarginControl();
249 IMPL_LINK_NOARG( PageFooterPanel
, FooterToggleHdl
, weld::Toggleable
&, void )
251 bool IsChecked
= mxFooterToggle
->get_active();
252 mpFooterItem
->SetValue(IsChecked
);
253 GetBindings()->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_FOOTER
, SfxCallMode::RECORD
, { mpFooterItem
.get() } );
257 IMPL_LINK_NOARG( PageFooterPanel
, FooterLRMarginHdl
, weld::ComboBox
&, void )
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() } );
266 IMPL_LINK_NOARG( PageFooterPanel
, FooterSpacingHdl
, weld::ComboBox
&, void )
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() } );
274 IMPL_LINK_NOARG( PageFooterPanel
, FooterLayoutHdl
, weld::ComboBox
&, void )
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() } );
285 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */