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 <svx/dlgutil.hxx>
23 #include <svx/rulritem.hxx>
24 #include <svx/svdtrans.hxx>
25 #include <svx/spacinglistbox.hxx>
26 #include <svx/samecontentlistbox.hxx>
27 #include "PageFooterPanel.hxx"
28 #include <sfx2/dispatch.hxx>
29 #include <sfx2/bindings.hxx>
32 #include <com/sun/star/lang/IllegalArgumentException.hpp>
34 namespace sw::sidebar
{
36 std::unique_ptr
<PanelLayout
> PageFooterPanel::Create(
37 weld::Widget
* pParent
,
38 SfxBindings
* pBindings
)
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
);
45 void PageFooterPanel::SetMarginsAndSpacingFieldUnit()
47 SpacingListBox::Fill(IsInch(meFUnit
) ? SpacingType::SPACING_INCH
: SpacingType::SPACING_CM
, *mxFooterSpacingLB
);
48 SpacingListBox::Fill(IsInch(meFUnit
) ? SpacingType::MARGINS_INCH
: SpacingType::MARGINS_CM
, *mxFooterMarginPresetLB
);
51 PageFooterPanel::PageFooterPanel(
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"))
75 PageFooterPanel::~PageFooterPanel()
77 mxFooterToggle
.reset();
78 maMetricController
.dispose();
79 mxFooterSpacingLB
.reset();
80 mxFooterLayoutLB
.reset();
81 mxFooterMarginPresetLB
.reset();
82 mxCustomEntry
.reset();
85 FieldUnit
PageFooterPanel::GetCurrentUnit(SfxItemState eState
, const SfxPoolItem
* pState
)
89 if (pState
&& eState
>= SfxItemState::DEFAULT
)
90 eUnit
= static_cast<FieldUnit
>(static_cast<const SfxUInt16Item
*>(pState
)->GetValue());
92 eUnit
= GetModuleFieldUnit();
97 void PageFooterPanel::Initialize()
99 SameContentListBox::Fill(*mxFooterLayoutLB
);
101 SetMarginsAndSpacingFieldUnit();
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
));
109 mpBindings
->Invalidate(SID_ATTR_METRIC
);
110 mpBindings
->Invalidate(SID_ATTR_PAGE_FOOTER
);
111 mpBindings
->Invalidate(SID_ATTR_PAGE_FOOTER_LRMARGIN
);
112 mpBindings
->Invalidate(SID_ATTR_PAGE_FOOTER_SPACING
);
113 mpBindings
->Invalidate(SID_ATTR_PAGE_FOOTER_LAYOUT
);
116 void PageFooterPanel::UpdateFooterCheck()
118 if (mxFooterToggle
->get_active())
120 mxFooterSpacingLB
->set_sensitive(true);
121 mxFooterLayoutLB
->set_sensitive(true);
122 mxFooterMarginPresetLB
->set_sensitive(true);
126 mxFooterSpacingLB
->set_sensitive(false);
127 mxFooterLayoutLB
->set_sensitive(false);
128 mxFooterMarginPresetLB
->set_sensitive(false);
132 void PageFooterPanel::UpdateMarginControl()
134 sal_uInt16 nLeft
= mpFooterLRMarginItem
->GetLeft();
135 sal_uInt16 nRight
= mpFooterLRMarginItem
->GetRight();
136 sal_uInt16 nCount
= mxFooterMarginPresetLB
->get_count();
139 for (sal_uInt16 i
= 0; i
< nCount
; ++i
)
141 if (mxFooterMarginPresetLB
->get_id(i
).toUInt32() == nLeft
)
143 mxFooterMarginPresetLB
->set_active(i
);
144 int nCustomEntry
= mxFooterMarginPresetLB
->find_text(m_aCustomEntry
);
145 if (nCustomEntry
!= -1)
146 mxFooterMarginPresetLB
->remove(nCustomEntry
);
151 mxFooterMarginPresetLB
->append_text(m_aCustomEntry
);
152 mxFooterMarginPresetLB
->set_active_text(m_aCustomEntry
);
155 void PageFooterPanel::UpdateSpacingControl()
157 sal_uInt16 nBottom
= mpFooterSpacingItem
->GetUpper();
158 sal_uInt16 nCount
= mxFooterSpacingLB
->get_count();
159 for (sal_uInt16 i
= 0; i
< nCount
; ++i
)
161 if (mxFooterSpacingLB
->get_id(i
).toUInt32() == nBottom
)
163 mxFooterSpacingLB
->set_active(i
);
164 int nCustomEntry
= mxFooterSpacingLB
->find_text(m_aCustomEntry
);
165 if (nCustomEntry
!= -1)
166 mxFooterSpacingLB
->remove(nCustomEntry
);
170 mxFooterSpacingLB
->append_text(m_aCustomEntry
);
171 mxFooterSpacingLB
->set_active_text(m_aCustomEntry
);
174 void PageFooterPanel::UpdateLayoutControl()
176 sal_uInt16 nLayout
= mpFooterLayoutItem
->GetValue();
177 mxFooterLayoutLB
->set_active(nLayout
);
180 void PageFooterPanel::NotifyItemUpdate(
181 const sal_uInt16 nSid
,
182 const SfxItemState eState
,
183 const SfxPoolItem
* pState
)
185 if (!mxFooterToggle
) //disposed
190 case SID_ATTR_PAGE_FOOTER
:
192 if(eState
>= SfxItemState::DEFAULT
&&
193 dynamic_cast<const SfxBoolItem
*>( pState
) )
195 mpFooterItem
.reset( static_cast<SfxBoolItem
*>(pState
->Clone()) );
196 mxFooterToggle
->set_active(mpFooterItem
->GetValue());
201 case SID_ATTR_PAGE_FOOTER_LRMARGIN
:
203 if(eState
>= SfxItemState::DEFAULT
&&
204 dynamic_cast<const SvxLongLRSpaceItem
*>( pState
) )
206 mpFooterLRMarginItem
.reset( static_cast<SvxLongLRSpaceItem
*>(pState
->Clone()) );
207 UpdateMarginControl();
211 case SID_ATTR_PAGE_FOOTER_SPACING
:
213 if(eState
>= SfxItemState::DEFAULT
&&
214 dynamic_cast<const SvxLongULSpaceItem
*>( pState
) )
216 mpFooterSpacingItem
.reset(static_cast<SvxLongULSpaceItem
*>(pState
->Clone()) );
217 UpdateSpacingControl();
221 case SID_ATTR_PAGE_FOOTER_LAYOUT
:
223 if(eState
>= SfxItemState::DEFAULT
&&
224 dynamic_cast<const SfxInt16Item
*>( pState
) )
226 mpFooterLayoutItem
.reset(static_cast<SfxInt16Item
*>(pState
->Clone()) );
227 UpdateLayoutControl();
231 case SID_ATTR_METRIC
:
233 FieldUnit eFUnit
= GetCurrentUnit(eState
, pState
);
234 if (meFUnit
!= eFUnit
)
237 SetMarginsAndSpacingFieldUnit();
238 UpdateSpacingControl();
239 UpdateMarginControl();
248 IMPL_LINK_NOARG( PageFooterPanel
, FooterToggleHdl
, weld::Toggleable
&, void )
250 bool IsChecked
= mxFooterToggle
->get_active();
251 mpFooterItem
->SetValue(IsChecked
);
252 GetBindings()->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_FOOTER
, SfxCallMode::RECORD
, { mpFooterItem
.get() } );
256 IMPL_LINK_NOARG( PageFooterPanel
, FooterLRMarginHdl
, weld::ComboBox
&, void )
258 sal_uInt16 nVal
= mxFooterMarginPresetLB
->get_active_id().toUInt32();
259 mpFooterLRMarginItem
->SetLeft(nVal
);
260 mpFooterLRMarginItem
->SetRight(nVal
);
261 GetBindings()->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_FOOTER_LRMARGIN
,
262 SfxCallMode::RECORD
, { mpFooterLRMarginItem
.get() } );
265 IMPL_LINK_NOARG( PageFooterPanel
, FooterSpacingHdl
, weld::ComboBox
&, void )
267 sal_uInt16 nVal
= mxFooterSpacingLB
->get_active_id().toUInt32();
268 mpFooterSpacingItem
->SetUpper(nVal
);
269 GetBindings()->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_FOOTER_SPACING
,
270 SfxCallMode::RECORD
, { mpFooterSpacingItem
.get() } );
273 IMPL_LINK_NOARG( PageFooterPanel
, FooterLayoutHdl
, weld::ComboBox
&, void )
275 sal_uInt16 nVal
= mxFooterLayoutLB
->get_active();
276 mpFooterLayoutItem
->SetValue(nVal
);
277 GetBindings()->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_FOOTER_LAYOUT
,
278 SfxCallMode::RECORD
, { mpFooterLayoutItem
.get() } );
284 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */