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 "PageFooterPanel.hxx"
26 #include <sfx2/dispatch.hxx>
27 #include <sfx2/bindings.hxx>
30 #include <com/sun/star/lang/IllegalArgumentException.hpp>
32 namespace sw::sidebar
{
34 VclPtr
<vcl::Window
> PageFooterPanel::Create(
36 const ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XFrame
>& rxFrame
,
37 SfxBindings
* pBindings
)
39 if( pParent
== nullptr )
40 throw ::com::sun::star::lang::IllegalArgumentException("no parent window given to PageFooterPanel::Create", nullptr, 0);
42 throw ::com::sun::star::lang::IllegalArgumentException("no XFrame given to PageFooterPanel::Create", nullptr, 0);
44 return VclPtr
<PageFooterPanel
>::Create(pParent
, rxFrame
, pBindings
);
47 void PageFooterPanel::SetMarginsAndSpacingFieldUnit()
49 SpacingListBox::Fill(IsInch(meFUnit
) ? SpacingType::SPACING_INCH
: SpacingType::SPACING_CM
, *mxFooterSpacingLB
);
50 SpacingListBox::Fill(IsInch(meFUnit
) ? SpacingType::MARGINS_INCH
: SpacingType::MARGINS_CM
, *mxFooterMarginPresetLB
);
53 PageFooterPanel::PageFooterPanel(
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()),
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"))
79 PageFooterPanel::~PageFooterPanel()
84 void PageFooterPanel::dispose()
86 mxFooterToggle
.reset();
87 maMetricController
.dispose();
88 mxFooterSpacingLB
.reset();
89 mxFooterLayoutLB
.reset();
90 mxFooterMarginPresetLB
.reset();
91 mxCustomEntry
.reset();
93 PanelLayout::dispose();
96 FieldUnit
PageFooterPanel::GetCurrentUnit(SfxItemState eState
, const SfxPoolItem
* pState
)
100 if (pState
&& eState
>= SfxItemState::DEFAULT
)
101 eUnit
= static_cast<FieldUnit
>(static_cast<const SfxUInt16Item
*>(pState
)->GetValue());
103 eUnit
= GetModuleFieldUnit();
108 void PageFooterPanel::Initialize()
110 SameContentListBox::Fill(*mxFooterLayoutLB
);
112 SetMarginsAndSpacingFieldUnit();
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
));
120 mpBindings
->Invalidate(SID_ATTR_METRIC
);
121 mpBindings
->Invalidate(SID_ATTR_PAGE_FOOTER
);
122 mpBindings
->Invalidate(SID_ATTR_PAGE_FOOTER_LRMARGIN
);
123 mpBindings
->Invalidate(SID_ATTR_PAGE_FOOTER_SPACING
);
124 mpBindings
->Invalidate(SID_ATTR_PAGE_FOOTER_LAYOUT
);
127 void PageFooterPanel::UpdateFooterCheck()
129 if (mxFooterToggle
->get_active())
131 mxFooterSpacingLB
->set_sensitive(true);
132 mxFooterLayoutLB
->set_sensitive(true);
133 mxFooterMarginPresetLB
->set_sensitive(true);
137 mxFooterSpacingLB
->set_sensitive(false);
138 mxFooterLayoutLB
->set_sensitive(false);
139 mxFooterMarginPresetLB
->set_sensitive(false);
143 void PageFooterPanel::UpdateMarginControl()
145 sal_uInt16 nLeft
= mpFooterLRMarginItem
->GetLeft();
146 sal_uInt16 nRight
= mpFooterLRMarginItem
->GetRight();
147 sal_uInt16 nCount
= mxFooterMarginPresetLB
->get_count();
150 for (sal_uInt16 i
= 0; i
< nCount
; ++i
)
152 if (mxFooterMarginPresetLB
->get_id(i
).toUInt32() == nLeft
)
154 mxFooterMarginPresetLB
->set_active(i
);
155 int nCustomEntry
= mxFooterMarginPresetLB
->find_text(aCustomEntry
);
156 if (nCustomEntry
!= -1)
157 mxFooterMarginPresetLB
->remove(nCustomEntry
);
162 mxFooterMarginPresetLB
->append_text(aCustomEntry
);
163 mxFooterMarginPresetLB
->set_active_text(aCustomEntry
);
166 void PageFooterPanel::UpdateSpacingControl()
168 sal_uInt16 nBottom
= mpFooterSpacingItem
->GetUpper();
169 sal_uInt16 nCount
= mxFooterSpacingLB
->get_count();
170 for (sal_uInt16 i
= 0; i
< nCount
; ++i
)
172 if (mxFooterSpacingLB
->get_id(i
).toUInt32() == nBottom
)
174 mxFooterSpacingLB
->set_active(i
);
175 int nCustomEntry
= mxFooterSpacingLB
->find_text(aCustomEntry
);
176 if (nCustomEntry
!= -1)
177 mxFooterSpacingLB
->remove(nCustomEntry
);
181 mxFooterSpacingLB
->append_text(aCustomEntry
);
182 mxFooterSpacingLB
->set_active_text(aCustomEntry
);
185 void PageFooterPanel::UpdateLayoutControl()
187 sal_uInt16 nLayout
= mpFooterLayoutItem
->GetValue();
188 mxFooterLayoutLB
->set_active(nLayout
);
191 void PageFooterPanel::NotifyItemUpdate(
192 const sal_uInt16 nSid
,
193 const SfxItemState eState
,
194 const SfxPoolItem
* pState
)
201 case SID_ATTR_PAGE_FOOTER
:
203 if(eState
>= SfxItemState::DEFAULT
&&
204 dynamic_cast<const SfxBoolItem
*>( pState
) )
206 mpFooterItem
.reset( static_cast<SfxBoolItem
*>(pState
->Clone()) );
207 mxFooterToggle
->set_active(mpFooterItem
->GetValue());
212 case SID_ATTR_PAGE_FOOTER_LRMARGIN
:
214 if(eState
>= SfxItemState::DEFAULT
&&
215 dynamic_cast<const SvxLongLRSpaceItem
*>( pState
) )
217 mpFooterLRMarginItem
.reset( static_cast<SvxLongLRSpaceItem
*>(pState
->Clone()) );
218 UpdateMarginControl();
222 case SID_ATTR_PAGE_FOOTER_SPACING
:
224 if(eState
>= SfxItemState::DEFAULT
&&
225 dynamic_cast<const SvxLongULSpaceItem
*>( pState
) )
227 mpFooterSpacingItem
.reset(static_cast<SvxLongULSpaceItem
*>(pState
->Clone()) );
228 UpdateSpacingControl();
232 case SID_ATTR_PAGE_FOOTER_LAYOUT
:
234 if(eState
>= SfxItemState::DEFAULT
&&
235 dynamic_cast<const SfxInt16Item
*>( pState
) )
237 mpFooterLayoutItem
.reset(static_cast<SfxInt16Item
*>(pState
->Clone()) );
238 UpdateLayoutControl();
242 case SID_ATTR_METRIC
:
244 FieldUnit eFUnit
= GetCurrentUnit(eState
, pState
);
245 if (meFUnit
!= eFUnit
)
248 SetMarginsAndSpacingFieldUnit();
249 UpdateSpacingControl();
250 UpdateMarginControl();
259 IMPL_LINK_NOARG( PageFooterPanel
, FooterToggleHdl
, weld::ToggleButton
&, void )
261 bool IsChecked
= mxFooterToggle
->get_active();
262 mpFooterItem
->SetValue(IsChecked
);
263 GetBindings()->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_FOOTER
, SfxCallMode::RECORD
, { mpFooterItem
.get() } );
267 IMPL_LINK_NOARG( PageFooterPanel
, FooterLRMarginHdl
, weld::ComboBox
&, void )
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() } );
276 IMPL_LINK_NOARG( PageFooterPanel
, FooterSpacingHdl
, weld::ComboBox
&, void )
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() } );
284 IMPL_LINK_NOARG( PageFooterPanel
, FooterLayoutHdl
, weld::ComboBox
&, void )
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() } );
295 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */