nss: upgrade to release 3.73
[LibreOffice.git] / sw / source / uibase / sidebar / PageHeaderPanel.cxx
bloba81d07a292256bb3e20f77bbbd5d04de323600f7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 "PageHeaderPanel.hxx"
26 #include <sfx2/dispatch.hxx>
27 #include <sfx2/bindings.hxx>
28 #include <cmdid.h>
30 #include <com/sun/star/lang/IllegalArgumentException.hpp>
32 namespace sw::sidebar{
34 VclPtr<vcl::Window> PageHeaderPanel::Create(
35 vcl::Window* pParent,
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 PageHeaderPanel::Create", nullptr, 0);
41 if( !rxFrame.is() )
42 throw ::com::sun::star::lang::IllegalArgumentException("no XFrame given to PageHeaderPanel::Create", nullptr, 0);
43 if( pBindings == nullptr )
44 throw ::com::sun::star::lang::IllegalArgumentException("no SfxBindings given to PageHeaderPanel::Create", nullptr, 0);
46 return VclPtr<PageHeaderPanel>::Create(pParent, rxFrame, pBindings);
49 void PageHeaderPanel::SetMarginsAndSpacingFieldUnit()
51 SpacingListBox::Fill(IsInch(meFUnit) ? SpacingType::SPACING_INCH : SpacingType::SPACING_CM, *mxHeaderSpacingLB);
52 SpacingListBox::Fill(IsInch(meFUnit) ? SpacingType::MARGINS_INCH : SpacingType::MARGINS_CM, *mxHeaderMarginPresetLB);
55 PageHeaderPanel::PageHeaderPanel(
56 vcl::Window* pParent,
57 const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rxFrame,
58 SfxBindings* pBindings
59 ) :
60 PanelLayout(pParent, "PageHeaderPanel", "modules/swriter/ui/pageheaderpanel.ui", rxFrame),
61 mpBindings( pBindings ),
62 maHFToggleController(SID_ATTR_PAGE_HEADER, *pBindings, *this),
63 maMetricController(SID_ATTR_METRIC, *pBindings,*this),
64 maHeaderLRMarginController(SID_ATTR_PAGE_HEADER_LRMARGIN, *pBindings, *this),
65 maHeaderSpacingController(SID_ATTR_PAGE_HEADER_SPACING, *pBindings, *this),
66 maHeaderLayoutController(SID_ATTR_PAGE_HEADER_LAYOUT, *pBindings, *this),
67 meFUnit(GetModuleFieldUnit()),
68 aCustomEntry(),
69 mpHeaderItem( new SfxBoolItem(SID_ATTR_PAGE_HEADER) ),
70 mpHeaderLRMarginItem( new SvxLongLRSpaceItem(0, 0, SID_ATTR_PAGE_HEADER_LRMARGIN)),
71 mpHeaderSpacingItem( new SvxLongULSpaceItem(0, 0, SID_ATTR_PAGE_HEADER_SPACING)),
72 mpHeaderLayoutItem( new SfxInt16Item(SID_ATTR_PAGE_HEADER_LAYOUT)),
73 mxHeaderToggle(m_xBuilder->weld_check_button("headertoggle")),
74 mxHeaderSpacingLB(m_xBuilder->weld_combo_box("spacingpreset")),
75 mxHeaderMarginPresetLB(m_xBuilder->weld_combo_box("headermarginpreset")),
76 mxHeaderLayoutLB(m_xBuilder->weld_combo_box("samecontentLB")),
77 mxCustomEntry(m_xBuilder->weld_label("customlabel"))
79 Initialize();
82 PageHeaderPanel::~PageHeaderPanel()
84 disposeOnce();
87 void PageHeaderPanel::dispose()
89 mxHeaderToggle.reset();
90 mxHeaderSpacingLB.reset();
91 mxHeaderLayoutLB.reset();
92 mxHeaderMarginPresetLB.reset();
93 mxCustomEntry.reset();
95 PanelLayout::dispose();
98 FieldUnit PageHeaderPanel::GetCurrentUnit(SfxItemState eState, const SfxPoolItem* pState)
100 FieldUnit eUnit;
102 if (pState && eState >= SfxItemState::DEFAULT)
103 eUnit = static_cast<FieldUnit>(static_cast<const SfxUInt16Item*>(pState)->GetValue());
104 else
105 eUnit = GetModuleFieldUnit();
107 return eUnit;
110 void PageHeaderPanel::Initialize()
112 SameContentListBox::Fill(*mxHeaderLayoutLB);
114 SetMarginsAndSpacingFieldUnit();
116 aCustomEntry = mxCustomEntry->get_label();
117 mxHeaderToggle->connect_toggled( LINK(this, PageHeaderPanel, HeaderToggleHdl) );
118 mxHeaderMarginPresetLB->connect_changed( LINK(this, PageHeaderPanel, HeaderLRMarginHdl));
119 mxHeaderSpacingLB->connect_changed( LINK(this, PageHeaderPanel, HeaderSpacingHdl));
120 mxHeaderLayoutLB->connect_changed( LINK(this, PageHeaderPanel, HeaderLayoutHdl));
122 mpBindings->Invalidate(SID_ATTR_METRIC);
123 mpBindings->Invalidate(SID_ATTR_PAGE_HEADER);
124 mpBindings->Invalidate(SID_ATTR_PAGE_HEADER_LRMARGIN);
125 mpBindings->Invalidate(SID_ATTR_PAGE_HEADER_SPACING);
126 mpBindings->Invalidate(SID_ATTR_PAGE_HEADER_LAYOUT);
129 void PageHeaderPanel::UpdateHeaderCheck()
131 if (mxHeaderToggle->get_active())
133 mxHeaderSpacingLB->set_sensitive(true);
134 mxHeaderLayoutLB->set_sensitive(true);
135 mxHeaderMarginPresetLB->set_sensitive(true);
137 else
139 mxHeaderSpacingLB->set_sensitive(false);
140 mxHeaderLayoutLB->set_sensitive(false);
141 mxHeaderMarginPresetLB->set_sensitive(false);
145 void PageHeaderPanel::UpdateMarginControl()
147 sal_uInt16 nLeft = mpHeaderLRMarginItem->GetLeft();
148 sal_uInt16 nRight = mpHeaderLRMarginItem->GetRight();
149 sal_uInt16 nCount = mxHeaderMarginPresetLB->get_count();
150 if(nLeft == nRight)
152 for (sal_uInt16 i = 0; i < nCount; ++i)
154 if (mxHeaderMarginPresetLB->get_id(i).toUInt32() == nLeft)
156 mxHeaderMarginPresetLB->set_active(i);
157 int nCustomEntry = mxHeaderMarginPresetLB->find_text(aCustomEntry);
158 if (nCustomEntry != -1)
159 mxHeaderMarginPresetLB->remove(nCustomEntry);
160 return;
164 mxHeaderMarginPresetLB->append_text(aCustomEntry);
165 mxHeaderMarginPresetLB->set_active_text(aCustomEntry);
168 void PageHeaderPanel::UpdateSpacingControl()
170 sal_uInt16 nBottom = mpHeaderSpacingItem->GetLower();
171 sal_uInt16 nCount = mxHeaderSpacingLB->get_count();
172 for (sal_uInt16 i = 0; i < nCount; ++i)
174 if (mxHeaderSpacingLB->get_id(i).toUInt32() == nBottom)
176 mxHeaderSpacingLB->set_active(i);
177 int nCustomEntry = mxHeaderSpacingLB->find_text(aCustomEntry);
178 if (nCustomEntry != -1)
179 mxHeaderSpacingLB->remove(nCustomEntry);
180 return;
183 mxHeaderSpacingLB->append_text(aCustomEntry);
184 mxHeaderSpacingLB->set_active_text(aCustomEntry);
187 void PageHeaderPanel::UpdateLayoutControl()
189 sal_uInt16 nLayout = mpHeaderLayoutItem->GetValue();
190 mxHeaderLayoutLB->set_active(nLayout);
193 void PageHeaderPanel::NotifyItemUpdate(
194 const sal_uInt16 nSid,
195 const SfxItemState eState,
196 const SfxPoolItem* pState)
198 if (IsDisposed())
199 return;
201 switch(nSid)
203 case SID_ATTR_PAGE_HEADER:
205 if(eState >= SfxItemState::DEFAULT &&
206 dynamic_cast<const SfxBoolItem*>( pState) )
208 mpHeaderItem.reset( static_cast<SfxBoolItem*>(pState->Clone()) );
209 mxHeaderToggle->set_active(mpHeaderItem->GetValue());
210 UpdateHeaderCheck();
213 break;
214 case SID_ATTR_PAGE_HEADER_LRMARGIN:
216 if(eState >= SfxItemState::DEFAULT &&
217 dynamic_cast<const SvxLongLRSpaceItem*>( pState) )
219 mpHeaderLRMarginItem.reset( static_cast<SvxLongLRSpaceItem*>(pState->Clone()) );
220 UpdateMarginControl();
223 break;
224 case SID_ATTR_PAGE_HEADER_SPACING:
226 if(eState >= SfxItemState::DEFAULT &&
227 dynamic_cast<const SvxLongULSpaceItem*>( pState) )
229 mpHeaderSpacingItem.reset(static_cast<SvxLongULSpaceItem*>(pState->Clone()) );
230 UpdateSpacingControl();
233 break;
234 case SID_ATTR_PAGE_HEADER_LAYOUT:
236 if(eState >= SfxItemState::DEFAULT &&
237 dynamic_cast<const SfxInt16Item*>( pState) )
239 mpHeaderLayoutItem.reset(static_cast<SfxInt16Item*>(pState->Clone()) );
240 UpdateLayoutControl();
243 break;
244 case SID_ATTR_METRIC:
246 FieldUnit eFUnit = GetCurrentUnit(eState, pState);
247 if (meFUnit != eFUnit)
249 meFUnit = eFUnit;
250 SetMarginsAndSpacingFieldUnit();
251 UpdateSpacingControl();
252 UpdateMarginControl();
255 break;
256 default:
257 break;
261 IMPL_LINK_NOARG( PageHeaderPanel, HeaderToggleHdl, weld::ToggleButton&, void )
263 bool IsChecked = mxHeaderToggle->get_active();
264 mpHeaderItem->SetValue(IsChecked);
265 GetBindings()->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_HEADER, SfxCallMode::RECORD, { mpHeaderItem.get() } );
266 UpdateHeaderCheck();
269 IMPL_LINK_NOARG( PageHeaderPanel, HeaderLRMarginHdl, weld::ComboBox&, void )
271 sal_uInt16 nVal = mxHeaderMarginPresetLB->get_active_id().toUInt32();
272 mpHeaderLRMarginItem->SetLeft(nVal);
273 mpHeaderLRMarginItem->SetRight(nVal);
274 GetBindings()->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_HEADER_LRMARGIN,
275 SfxCallMode::RECORD, { mpHeaderLRMarginItem.get() } );
278 IMPL_LINK_NOARG( PageHeaderPanel, HeaderSpacingHdl, weld::ComboBox&, void )
280 sal_uInt16 nVal = mxHeaderSpacingLB->get_active_id().toUInt32();
281 mpHeaderSpacingItem->SetLower(nVal);
282 GetBindings()->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_HEADER_SPACING,
283 SfxCallMode::RECORD, { mpHeaderSpacingItem.get() } );
285 IMPL_LINK_NOARG( PageHeaderPanel, HeaderLayoutHdl, weld::ComboBox&, void )
287 sal_uInt16 nVal = mxHeaderLayoutLB->get_active();
288 mpHeaderLayoutItem->SetValue(nVal);
289 GetBindings()->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_HEADER_LAYOUT,
290 SfxCallMode::RECORD, { mpHeaderLayoutItem.get() } );
296 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */