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 <svx/spacinglistbox.hxx>
27 #include "PageHeaderPanel.hxx"
28 #include <sfx2/dispatch.hxx>
29 #include <sfx2/bindings.hxx>
30 #include <cmdid.h>
31 
32 #include <com/sun/star/lang/IllegalArgumentException.hpp>
33 
34 namespace sw::sidebar{
35 
36 std::unique_ptr<PanelLayout> PageHeaderPanel::Create(
37  weld::Widget* pParent,
38  SfxBindings* pBindings)
39 {
40  if( pParent == nullptr )
41  throw ::com::sun::star::lang::IllegalArgumentException("no parent window given to PageHeaderPanel::Create", nullptr, 0);
42  if( pBindings == nullptr )
43  throw ::com::sun::star::lang::IllegalArgumentException("no SfxBindings given to PageHeaderPanel::Create", nullptr, 0);
44 
45  return std::make_unique<PageHeaderPanel>(pParent, pBindings);
46 }
47 
49 {
50  SpacingListBox::Fill(IsInch(meFUnit) ? SpacingType::SPACING_INCH : SpacingType::SPACING_CM, *mxHeaderSpacingLB);
51  SpacingListBox::Fill(IsInch(meFUnit) ? SpacingType::MARGINS_INCH : SpacingType::MARGINS_CM, *mxHeaderMarginPresetLB);
52 }
53 
55  weld::Widget* pParent,
56  SfxBindings* pBindings
57  ) :
58  PanelLayout(pParent, "PageHeaderPanel", "modules/swriter/ui/pageheaderpanel.ui"),
59  mpBindings( pBindings ),
60  maHFToggleController(SID_ATTR_PAGE_HEADER, *pBindings, *this),
61  maMetricController(SID_ATTR_METRIC, *pBindings,*this),
62  maHeaderLRMarginController(SID_ATTR_PAGE_HEADER_LRMARGIN, *pBindings, *this),
63  maHeaderSpacingController(SID_ATTR_PAGE_HEADER_SPACING, *pBindings, *this),
64  maHeaderLayoutController(SID_ATTR_PAGE_HEADER_LAYOUT, *pBindings, *this),
65  meFUnit(GetModuleFieldUnit()),
66  aCustomEntry(),
67  mpHeaderItem( new SfxBoolItem(SID_ATTR_PAGE_HEADER) ),
68  mpHeaderLRMarginItem( new SvxLongLRSpaceItem(0, 0, SID_ATTR_PAGE_HEADER_LRMARGIN)),
69  mpHeaderSpacingItem( new SvxLongULSpaceItem(0, 0, SID_ATTR_PAGE_HEADER_SPACING)),
70  mpHeaderLayoutItem( new SfxInt16Item(SID_ATTR_PAGE_HEADER_LAYOUT)),
71  mxHeaderToggle(m_xBuilder->weld_check_button("headertoggle")),
72  mxHeaderSpacingLB(m_xBuilder->weld_combo_box("spacingpreset")),
73  mxHeaderMarginPresetLB(m_xBuilder->weld_combo_box("headermarginpreset")),
74  mxHeaderLayoutLB(m_xBuilder->weld_combo_box("samecontentLB")),
75  mxCustomEntry(m_xBuilder->weld_label("customlabel"))
76 {
77  Initialize();
78 }
79 
81 {
82  mxHeaderToggle.reset();
83  mxHeaderSpacingLB.reset();
84  mxHeaderLayoutLB.reset();
85  mxHeaderMarginPresetLB.reset();
86  mxCustomEntry.reset();
87 }
88 
90 {
91  FieldUnit eUnit;
92 
93  if (pState && eState >= SfxItemState::DEFAULT)
94  eUnit = static_cast<FieldUnit>(static_cast<const SfxUInt16Item*>(pState)->GetValue());
95  else
96  eUnit = GetModuleFieldUnit();
97 
98  return eUnit;
99 }
100 
102 {
104 
106 
107  aCustomEntry = mxCustomEntry->get_label();
108  mxHeaderToggle->connect_toggled( LINK(this, PageHeaderPanel, HeaderToggleHdl) );
109  mxHeaderMarginPresetLB->connect_changed( LINK(this, PageHeaderPanel, HeaderLRMarginHdl));
110  mxHeaderSpacingLB->connect_changed( LINK(this, PageHeaderPanel, HeaderSpacingHdl));
111  mxHeaderLayoutLB->connect_changed( LINK(this, PageHeaderPanel, HeaderLayoutHdl));
112 
113  mpBindings->Invalidate(SID_ATTR_METRIC);
118 }
119 
121 {
122  if (mxHeaderToggle->get_active())
123  {
124  mxHeaderSpacingLB->set_sensitive(true);
125  mxHeaderLayoutLB->set_sensitive(true);
126  mxHeaderMarginPresetLB->set_sensitive(true);
127  }
128  else
129  {
130  mxHeaderSpacingLB->set_sensitive(false);
131  mxHeaderLayoutLB->set_sensitive(false);
132  mxHeaderMarginPresetLB->set_sensitive(false);
133  }
134 }
135 
137 {
138  sal_uInt16 nLeft = mpHeaderLRMarginItem->GetLeft();
139  sal_uInt16 nRight = mpHeaderLRMarginItem->GetRight();
140  sal_uInt16 nCount = mxHeaderMarginPresetLB->get_count();
141  if(nLeft == nRight)
142  {
143  for (sal_uInt16 i = 0; i < nCount; ++i)
144  {
145  if (mxHeaderMarginPresetLB->get_id(i).toUInt32() == nLeft)
146  {
147  mxHeaderMarginPresetLB->set_active(i);
148  int nCustomEntry = mxHeaderMarginPresetLB->find_text(aCustomEntry);
149  if (nCustomEntry != -1)
150  mxHeaderMarginPresetLB->remove(nCustomEntry);
151  return;
152  }
153  }
154  }
155  mxHeaderMarginPresetLB->append_text(aCustomEntry);
156  mxHeaderMarginPresetLB->set_active_text(aCustomEntry);
157 }
158 
160 {
161  sal_uInt16 nBottom = mpHeaderSpacingItem->GetLower();
162  sal_uInt16 nCount = mxHeaderSpacingLB->get_count();
163  for (sal_uInt16 i = 0; i < nCount; ++i)
164  {
165  if (mxHeaderSpacingLB->get_id(i).toUInt32() == nBottom)
166  {
167  mxHeaderSpacingLB->set_active(i);
168  int nCustomEntry = mxHeaderSpacingLB->find_text(aCustomEntry);
169  if (nCustomEntry != -1)
170  mxHeaderSpacingLB->remove(nCustomEntry);
171  return;
172  }
173  }
174  mxHeaderSpacingLB->append_text(aCustomEntry);
175  mxHeaderSpacingLB->set_active_text(aCustomEntry);
176 }
177 
179 {
180  sal_uInt16 nLayout = mpHeaderLayoutItem->GetValue();
181  mxHeaderLayoutLB->set_active(nLayout);
182 }
183 
185  const sal_uInt16 nSid,
186  const SfxItemState eState,
187  const SfxPoolItem* pState)
188 {
189  if (!mxHeaderToggle) //disposed
190  return;
191 
192  switch(nSid)
193  {
195  {
196  if(eState >= SfxItemState::DEFAULT &&
197  dynamic_cast<const SfxBoolItem*>( pState) )
198  {
199  mpHeaderItem.reset( static_cast<SfxBoolItem*>(pState->Clone()) );
200  mxHeaderToggle->set_active(mpHeaderItem->GetValue());
202  }
203  }
204  break;
206  {
207  if(eState >= SfxItemState::DEFAULT &&
208  dynamic_cast<const SvxLongLRSpaceItem*>( pState) )
209  {
210  mpHeaderLRMarginItem.reset( static_cast<SvxLongLRSpaceItem*>(pState->Clone()) );
212  }
213  }
214  break;
216  {
217  if(eState >= SfxItemState::DEFAULT &&
218  dynamic_cast<const SvxLongULSpaceItem*>( pState) )
219  {
220  mpHeaderSpacingItem.reset(static_cast<SvxLongULSpaceItem*>(pState->Clone()) );
222  }
223  }
224  break;
226  {
227  if(eState >= SfxItemState::DEFAULT &&
228  dynamic_cast<const SfxInt16Item*>( pState) )
229  {
230  mpHeaderLayoutItem.reset(static_cast<SfxInt16Item*>(pState->Clone()) );
232  }
233  }
234  break;
235  case SID_ATTR_METRIC:
236  {
237  FieldUnit eFUnit = GetCurrentUnit(eState, pState);
238  if (meFUnit != eFUnit)
239  {
240  meFUnit = eFUnit;
244  }
245  }
246  break;
247  default:
248  break;
249  }
250 }
251 
253 {
254  bool IsChecked = mxHeaderToggle->get_active();
255  mpHeaderItem->SetValue(IsChecked);
256  GetBindings()->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_HEADER, SfxCallMode::RECORD, { mpHeaderItem.get() } );
257  UpdateHeaderCheck();
258 }
259 
260 IMPL_LINK_NOARG( PageHeaderPanel, HeaderLRMarginHdl, weld::ComboBox&, void )
261 {
262  sal_uInt16 nVal = mxHeaderMarginPresetLB->get_active_id().toUInt32();
263  mpHeaderLRMarginItem->SetLeft(nVal);
264  mpHeaderLRMarginItem->SetRight(nVal);
265  GetBindings()->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_HEADER_LRMARGIN,
266  SfxCallMode::RECORD, { mpHeaderLRMarginItem.get() } );
267 }
268 
269 IMPL_LINK_NOARG( PageHeaderPanel, HeaderSpacingHdl, weld::ComboBox&, void )
270 {
271  sal_uInt16 nVal = mxHeaderSpacingLB->get_active_id().toUInt32();
272  mpHeaderSpacingItem->SetLower(nVal);
273  GetBindings()->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_HEADER_SPACING,
274  SfxCallMode::RECORD, { mpHeaderSpacingItem.get() } );
275 }
276 IMPL_LINK_NOARG( PageHeaderPanel, HeaderLayoutHdl, weld::ComboBox&, void )
277 {
278  sal_uInt16 nVal = mxHeaderLayoutLB->get_active();
279  mpHeaderLayoutItem->SetValue(nVal);
280  GetBindings()->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_HEADER_LAYOUT,
281  SfxCallMode::RECORD, { mpHeaderLayoutItem.get() } );
282 }
283 
284 
285 }
286 
287 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
FieldUnit
#define SID_ATTR_PAGE_HEADER_LRMARGIN
Definition: cmdid.h:862
std::unique_ptr< weld::ComboBox > mxHeaderSpacingLB
#define SID_ATTR_PAGE_HEADER
Definition: cmdid.h:861
#define SID_ATTR_PAGE_HEADER_LAYOUT
Definition: cmdid.h:864
std::string GetValue
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const =0
void Invalidate(sal_uInt16 nId)
FieldUnit GetModuleFieldUnit(const SfxItemSet &rSet)
PageHeaderPanel(weld::Widget *pParent, SfxBindings *pBindings)
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)
static std::unique_ptr< PanelLayout > Create(weld::Widget *pParent, SfxBindings *pBindings)
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)
SfxItemState
::std::unique_ptr< SfxBoolItem > mpHeaderItem
std::unique_ptr< weld::Label > mxCustomEntry
bool IsInch(MapUnit eU)
#define SID_ATTR_PAGE_HEADER_SPACING
Definition: cmdid.h:863
::std::unique_ptr< SvxLongULSpaceItem > mpHeaderSpacingItem
void Fill(weld::ComboBox &rComboBox)