LibreOffice Module sw (master)  1
PageHeaderPanel.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>
25 #include "PageHeaderPanel.hxx"
26 #include <sfx2/dispatch.hxx>
27 #include <sfx2/bindings.hxx>
28 #include <cmdid.h>
29 
30 #include <com/sun/star/lang/IllegalArgumentException.hpp>
31 
32 namespace sw::sidebar{
33 
35  vcl::Window* pParent,
36  const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rxFrame,
37  SfxBindings* pBindings)
38 {
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);
45 
46  return VclPtr<PageHeaderPanel>::Create(pParent, rxFrame, pBindings);
47 }
48 
50 {
51  SpacingListBox::Fill(IsInch(meFUnit) ? SpacingType::SPACING_INCH : SpacingType::SPACING_CM, *mxHeaderSpacingLB);
52  SpacingListBox::Fill(IsInch(meFUnit) ? SpacingType::MARGINS_INCH : SpacingType::MARGINS_CM, *mxHeaderMarginPresetLB);
53 }
54 
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"))
78 {
79  Initialize();
80 }
81 
83 {
84  disposeOnce();
85 }
86 
88 {
89  mxHeaderToggle.reset();
90  mxHeaderSpacingLB.reset();
91  mxHeaderLayoutLB.reset();
92  mxHeaderMarginPresetLB.reset();
93  mxCustomEntry.reset();
94 
96 }
97 
99 {
100  FieldUnit eUnit;
101 
102  if (pState && eState >= SfxItemState::DEFAULT)
103  eUnit = static_cast<FieldUnit>(static_cast<const SfxUInt16Item*>(pState)->GetValue());
104  else
105  eUnit = GetModuleFieldUnit();
106 
107  return eUnit;
108 }
109 
111 {
113 
115 
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));
121 
122  mpBindings->Invalidate(SID_ATTR_METRIC);
127 }
128 
130 {
131  if (mxHeaderToggle->get_active())
132  {
133  mxHeaderSpacingLB->set_sensitive(true);
134  mxHeaderLayoutLB->set_sensitive(true);
135  mxHeaderMarginPresetLB->set_sensitive(true);
136  }
137  else
138  {
139  mxHeaderSpacingLB->set_sensitive(false);
140  mxHeaderLayoutLB->set_sensitive(false);
141  mxHeaderMarginPresetLB->set_sensitive(false);
142  }
143 }
144 
146 {
147  sal_uInt16 nLeft = mpHeaderLRMarginItem->GetLeft();
148  sal_uInt16 nRight = mpHeaderLRMarginItem->GetRight();
149  sal_uInt16 nCount = mxHeaderMarginPresetLB->get_count();
150  if(nLeft == nRight)
151  {
152  for (sal_uInt16 i = 0; i < nCount; ++i)
153  {
154  if (mxHeaderMarginPresetLB->get_id(i).toUInt32() == nLeft)
155  {
156  mxHeaderMarginPresetLB->set_active(i);
157  int nCustomEntry = mxHeaderMarginPresetLB->find_text(aCustomEntry);
158  if (nCustomEntry != -1)
159  mxHeaderMarginPresetLB->remove(nCustomEntry);
160  return;
161  }
162  }
163  }
164  mxHeaderMarginPresetLB->append_text(aCustomEntry);
165  mxHeaderMarginPresetLB->set_active_text(aCustomEntry);
166 }
167 
169 {
170  sal_uInt16 nBottom = mpHeaderSpacingItem->GetLower();
171  sal_uInt16 nCount = mxHeaderSpacingLB->get_count();
172  for (sal_uInt16 i = 0; i < nCount; ++i)
173  {
174  if (mxHeaderSpacingLB->get_id(i).toUInt32() == nBottom)
175  {
176  mxHeaderSpacingLB->set_active(i);
177  int nCustomEntry = mxHeaderSpacingLB->find_text(aCustomEntry);
178  if (nCustomEntry != -1)
179  mxHeaderSpacingLB->remove(nCustomEntry);
180  return;
181  }
182  }
183  mxHeaderSpacingLB->append_text(aCustomEntry);
184  mxHeaderSpacingLB->set_active_text(aCustomEntry);
185 }
186 
188 {
189  sal_uInt16 nLayout = mpHeaderLayoutItem->GetValue();
190  mxHeaderLayoutLB->set_active(nLayout);
191 }
192 
194  const sal_uInt16 nSid,
195  const SfxItemState eState,
196  const SfxPoolItem* pState)
197 {
198  if (IsDisposed())
199  return;
200 
201  switch(nSid)
202  {
204  {
205  if(eState >= SfxItemState::DEFAULT &&
206  dynamic_cast<const SfxBoolItem*>( pState) )
207  {
208  mpHeaderItem.reset( static_cast<SfxBoolItem*>(pState->Clone()) );
209  mxHeaderToggle->set_active(mpHeaderItem->GetValue());
211  }
212  }
213  break;
215  {
216  if(eState >= SfxItemState::DEFAULT &&
217  dynamic_cast<const SvxLongLRSpaceItem*>( pState) )
218  {
219  mpHeaderLRMarginItem.reset( static_cast<SvxLongLRSpaceItem*>(pState->Clone()) );
221  }
222  }
223  break;
225  {
226  if(eState >= SfxItemState::DEFAULT &&
227  dynamic_cast<const SvxLongULSpaceItem*>( pState) )
228  {
229  mpHeaderSpacingItem.reset(static_cast<SvxLongULSpaceItem*>(pState->Clone()) );
231  }
232  }
233  break;
235  {
236  if(eState >= SfxItemState::DEFAULT &&
237  dynamic_cast<const SfxInt16Item*>( pState) )
238  {
239  mpHeaderLayoutItem.reset(static_cast<SfxInt16Item*>(pState->Clone()) );
241  }
242  }
243  break;
244  case SID_ATTR_METRIC:
245  {
246  FieldUnit eFUnit = GetCurrentUnit(eState, pState);
247  if (meFUnit != eFUnit)
248  {
249  meFUnit = eFUnit;
253  }
254  }
255  break;
256  default:
257  break;
258  }
259 }
260 
262 {
263  bool IsChecked = mxHeaderToggle->get_active();
264  mpHeaderItem->SetValue(IsChecked);
265  GetBindings()->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_HEADER, SfxCallMode::RECORD, { mpHeaderItem.get() } );
266  UpdateHeaderCheck();
267 }
268 
269 IMPL_LINK_NOARG( PageHeaderPanel, HeaderLRMarginHdl, weld::ComboBox&, void )
270 {
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() } );
276 }
277 
278 IMPL_LINK_NOARG( PageHeaderPanel, HeaderSpacingHdl, weld::ComboBox&, void )
279 {
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() } );
284 }
285 IMPL_LINK_NOARG( PageHeaderPanel, HeaderLayoutHdl, weld::ComboBox&, void )
286 {
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() } );
291 }
292 
293 
294 }
295 
296 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
FieldUnit
#define SID_ATTR_PAGE_HEADER_LRMARGIN
Definition: cmdid.h:853
std::unique_ptr< weld::ComboBox > mxHeaderSpacingLB
static VclPtr< vcl::Window > Create(vcl::Window *pParent, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > &rxFrame, SfxBindings *pBindings)
#define SID_ATTR_PAGE_HEADER
Definition: cmdid.h:852
#define SID_ATTR_PAGE_HEADER_LAYOUT
Definition: cmdid.h:855
std::string GetValue
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const =0
void Invalidate(sal_uInt16 nId)
FieldUnit GetModuleFieldUnit(const SfxItemSet &rSet)
virtual void NotifyItemUpdate(const sal_uInt16 nSId, const SfxItemState eState, const SfxPoolItem *pState) override
int nCount
std::unique_ptr< weld::ComboBox > mxHeaderMarginPresetLB
virtual ~PageHeaderPanel() override
std::unique_ptr< weld::CheckButton > mxHeaderToggle
static FieldUnit GetCurrentUnit(SfxItemState eState, const SfxPoolItem *pState)
int i
void Fill(SpacingType eType, weld::ComboBox &rComboBox)
::std::unique_ptr< SfxInt16Item > mpHeaderLayoutItem
std::unique_ptr< weld::ComboBox > mxHeaderLayoutLB
::std::unique_ptr< SvxLongLRSpaceItem > mpHeaderLRMarginItem
IMPL_LINK_NOARG(PageColumnControl, MoreButtonClickHdl_Impl, weld::Button &, void)
virtual void dispose() override
SfxItemState
::std::unique_ptr< SfxBoolItem > mpHeaderItem
virtual void dispose() override
static VclPtr< reference_type > Create(Arg &&...arg)
std::unique_ptr< weld::Label > mxCustomEntry
bool IsInch(MapUnit eU)
PageHeaderPanel(vcl::Window *pParent, const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > &rxFrame, SfxBindings *pBindings)
#define SID_ATTR_PAGE_HEADER_SPACING
Definition: cmdid.h:854
::std::unique_ptr< SvxLongULSpaceItem > mpHeaderSpacingItem
void Fill(weld::ComboBox &rComboBox)