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 <swtypes.hxx>
21 #include <svl/intitem.hxx>
22 #include <svl/eitem.hxx>
23 #include <editeng/sizeitem.hxx>
24 #include <editeng/paperinf.hxx>
25 #include <svx/svxids.hrc>
26 #include <svx/dlgutil.hxx>
27 #include <svx/rulritem.hxx>
28 #include <svx/svdtrans.hxx>
29 #include "PageHeaderPanel.hxx"
31 #include <sfx2/dispatch.hxx>
32 #include <sfx2/bindings.hxx>
33 #include <sfx2/viewsh.hxx>
34 #include <sfx2/objsh.hxx>
35 #include <uitool.hxx>
36 #include <cmdid.h>
37 
38 #include <com/sun/star/lang/IllegalArgumentException.hpp>
39 
40 namespace sw { namespace sidebar{
41 
43  vcl::Window* pParent,
44  const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rxFrame,
45  SfxBindings* pBindings)
46 {
47  if( pParent == nullptr )
48  throw ::com::sun::star::lang::IllegalArgumentException("no parent window given to PageHeaderPanel::Create", nullptr, 0);
49  if( !rxFrame.is() )
50  throw ::com::sun::star::lang::IllegalArgumentException("no XFrame given to PageHeaderPanel::Create", nullptr, 0);
51  if( pBindings == nullptr )
52  throw ::com::sun::star::lang::IllegalArgumentException("no SfxBindings given to PageHeaderPanel::Create", nullptr, 0);
53 
54  return VclPtr<PageHeaderPanel>::Create(pParent, rxFrame, pBindings);
55 }
56 
58  vcl::Window* pParent,
59  const ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame >& rxFrame,
60  SfxBindings* pBindings
61  ) :
62  PanelLayout(pParent, "PageHeaderPanel", "modules/swriter/ui/pageheaderpanel.ui", rxFrame),
63  mpBindings( pBindings ),
64  maHFToggleController(SID_ATTR_PAGE_HEADER, *pBindings, *this),
65  maHeaderLRMarginController(SID_ATTR_PAGE_HEADER_LRMARGIN, *pBindings, *this),
66  maHeaderSpacingController(SID_ATTR_PAGE_HEADER_SPACING, *pBindings, *this),
67  maHeaderLayoutController(SID_ATTR_PAGE_HEADER_LAYOUT, *pBindings, *this),
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 {
74  get(mpHeaderToggle, "headertoggle");
75  get(mpHeaderSpacingLB, "spacingpreset");
76  FieldUnit eMetric = ::GetDfltMetric(false);
77  mpHeaderSpacingLB->Init(IsInch(eMetric) ? SpacingType::SPACING_INCH : SpacingType::SPACING_CM);
78  get(mpHeaderLayoutLB, "samecontentLB");
79  get(mpHeaderMarginPresetLB, "headermarginpreset");
80  mpHeaderMarginPresetLB->Init(IsInch(eMetric) ? SpacingType::MARGINS_INCH : SpacingType::MARGINS_CM);
81  get(mpCustomEntry, "customlabel");
82 
83  Initialize();
84 }
85 
87 {
88  disposeOnce();
89 }
90 
92 {
98 
100 }
101 
103 {
105  mpHeaderToggle->SetClickHdl( LINK(this, PageHeaderPanel, HeaderToggleHdl) );
106  mpHeaderMarginPresetLB->SetSelectHdl( LINK(this, PageHeaderPanel, HeaderLRMarginHdl));
107  mpHeaderSpacingLB->SetSelectHdl( LINK(this, PageHeaderPanel, HeaderSpacingHdl));
108  mpHeaderLayoutLB->SetSelectHdl( LINK(this, PageHeaderPanel, HeaderLayoutHdl));
109 
114 }
115 
117 {
119  {
120  mpHeaderSpacingLB->Enable();
121  mpHeaderLayoutLB->Enable();
122  mpHeaderMarginPresetLB->Enable();
123  }
124  else
125  {
126  mpHeaderSpacingLB->Disable();
127  mpHeaderLayoutLB->Disable();
128  mpHeaderMarginPresetLB->Disable();
129  }
130 }
131 
133 {
134  sal_uInt16 nLeft = mpHeaderLRMarginItem->GetLeft();
135  sal_uInt16 nRight = mpHeaderLRMarginItem->GetRight();
136  sal_uInt16 nCount = mpHeaderMarginPresetLB->GetEntryCount();
137  if(nLeft == nRight)
138  {
139  for(sal_uInt16 i = 0; i < nCount; i++)
140  {
141  if(reinterpret_cast<sal_uLong>(mpHeaderMarginPresetLB->GetEntryData(i)) == nLeft )
142  {
143  mpHeaderMarginPresetLB->SelectEntryPos(i);
144  mpHeaderMarginPresetLB->RemoveEntry(aCustomEntry);
145  return;
146  }
147  }
148  }
149  mpHeaderMarginPresetLB->InsertEntry(aCustomEntry);
150  mpHeaderMarginPresetLB->SelectEntry(aCustomEntry);
151 }
152 
154 {
155  sal_uInt16 nBottom = mpHeaderSpacingItem->GetLower();
156  sal_uInt16 nCount = mpHeaderSpacingLB->GetEntryCount();
157  for(sal_uInt16 i = 0; i < nCount; i++)
158  {
159  if(reinterpret_cast<sal_uLong>(mpHeaderSpacingLB->GetEntryData(i)) == nBottom )
160  {
161  mpHeaderSpacingLB->SelectEntryPos(i);
162  mpHeaderSpacingLB->RemoveEntry(aCustomEntry);
163  return;
164  }
165  }
166  mpHeaderSpacingLB->InsertEntry(aCustomEntry);
167  mpHeaderSpacingLB->SelectEntry(aCustomEntry);
168 }
169 
171 {
172  sal_uInt16 nLayout = mpHeaderLayoutItem->GetValue();
173  mpHeaderLayoutLB->SelectEntryPos( nLayout );
174 }
175 
177  const sal_uInt16 nSid,
178  const SfxItemState eState,
179  const SfxPoolItem* pState,
180  const bool)
181 {
182  if (IsDisposed())
183  return;
184 
185  switch(nSid)
186  {
188  {
189  if(eState >= SfxItemState::DEFAULT &&
190  dynamic_cast<const SfxBoolItem*>( pState) )
191  {
192  mpHeaderItem.reset( static_cast<SfxBoolItem*>(pState->Clone()) );
193  mpHeaderToggle->Check(mpHeaderItem->GetValue());
195  }
196  }
197  break;
199  {
200  if(eState >= SfxItemState::DEFAULT &&
201  dynamic_cast<const SvxLongLRSpaceItem*>( pState) )
202  {
203  mpHeaderLRMarginItem.reset( static_cast<SvxLongLRSpaceItem*>(pState->Clone()) );
205  }
206  }
207  break;
209  {
210  if(eState >= SfxItemState::DEFAULT &&
211  dynamic_cast<const SvxLongULSpaceItem*>( pState) )
212  {
213  mpHeaderSpacingItem.reset(static_cast<SvxLongULSpaceItem*>(pState->Clone()) );
215  }
216  }
217  break;
219  {
220  if(eState >= SfxItemState::DEFAULT &&
221  dynamic_cast<const SfxInt16Item*>( pState) )
222  {
223  mpHeaderLayoutItem.reset(static_cast<SfxInt16Item*>(pState->Clone()) );
225  }
226  }
227  break;
228  default:
229  break;
230  }
231 }
232 
233 IMPL_LINK_NOARG( PageHeaderPanel, HeaderToggleHdl, Button*, void )
234 {
235  bool IsChecked = mpHeaderToggle->IsChecked();
236  mpHeaderItem->SetValue(IsChecked);
237  GetBindings()->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_HEADER, SfxCallMode::RECORD, { mpHeaderItem.get() } );
238  UpdateHeaderCheck();
239 }
240 
241 IMPL_LINK_NOARG( PageHeaderPanel, HeaderLRMarginHdl, ListBox&, void )
242 {
243  sal_uInt16 nVal = static_cast<sal_uInt16>(reinterpret_cast<sal_uLong>(mpHeaderMarginPresetLB->GetSelectedEntryData()));
244  mpHeaderLRMarginItem->SetLeft(nVal);
245  mpHeaderLRMarginItem->SetRight(nVal);
246  GetBindings()->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_HEADER_LRMARGIN,
247  SfxCallMode::RECORD, { mpHeaderLRMarginItem.get() } );
248 }
249 
250 IMPL_LINK_NOARG( PageHeaderPanel, HeaderSpacingHdl, ListBox&, void )
251 {
252  sal_uInt16 nVal = static_cast<sal_uInt16>(reinterpret_cast<sal_uLong>(mpHeaderSpacingLB->GetSelectedEntryData()));
253  mpHeaderSpacingItem->SetLower(nVal);
254  GetBindings()->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_HEADER_SPACING,
255  SfxCallMode::RECORD, { mpHeaderSpacingItem.get() } );
256 }
257 IMPL_LINK_NOARG( PageHeaderPanel, HeaderLayoutHdl, ListBox&, void )
258 {
259  sal_uInt16 nVal = mpHeaderLayoutLB->GetSelectedEntryPos();
260  mpHeaderLayoutItem->SetValue(nVal);
261  GetBindings()->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_HEADER_LAYOUT,
262  SfxCallMode::RECORD, { mpHeaderLayoutItem.get() } );
263 }
264 
265 
266 } }
267 
268 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
FieldUnit
#define SID_ATTR_PAGE_HEADER_LRMARGIN
Definition: cmdid.h:839
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:838
#define SID_ATTR_PAGE_HEADER_LAYOUT
Definition: cmdid.h:841
void SetClickHdl(const Link< Button *, void > &rLink)
void Init(SpacingType eType)
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const =0
sal_uIntPtr sal_uLong
Dialog to specify the properties of date form field.
void Invalidate(sal_uInt16 nId)
VclPtr< SpacingListBox > mpHeaderSpacingLB
VclPtr< SpacingListBox > mpHeaderMarginPresetLB
virtual OUString GetText() const
virtual ~PageHeaderPanel() override
virtual void NotifyItemUpdate(const sal_uInt16 nSId, const SfxItemState eState, const SfxPoolItem *pState, const bool bIsEnabled) override
SW_DLLPUBLIC FieldUnit GetDfltMetric(bool bWeb)
Definition: uitool.cxx:710
VclPtr< CheckBox > mpHeaderToggle
IMPL_LINK_NOARG(PageColumnControl, MoreButtonClickHdl_Impl, Button *, void)
int i
::std::unique_ptr< SfxInt16Item > mpHeaderLayoutItem
bool IsChecked() const
::std::unique_ptr< SvxLongLRSpaceItem > mpHeaderLRMarginItem
void Check(bool bCheck=true)
virtual void dispose() override
SfxItemState
::std::unique_ptr< SfxBoolItem > mpHeaderItem
VclPtr< SameContentListBox > mpHeaderLayoutLB
virtual void dispose() override
static VclPtr< reference_type > Create(Arg &&...arg)
VclPtr< FixedText > mpCustomEntry
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:840
::std::unique_ptr< SvxLongULSpaceItem > mpHeaderSpacingItem