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>
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
34namespace sw::sidebar{
35
36std::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 mpHeaderItem( new SfxBoolItem(SID_ATTR_PAGE_HEADER) ),
67 mpHeaderLRMarginItem( new SvxLongLRSpaceItem(0, 0, SID_ATTR_PAGE_HEADER_LRMARGIN)),
68 mpHeaderSpacingItem( new SvxLongULSpaceItem(0, 0, SID_ATTR_PAGE_HEADER_SPACING)),
69 mpHeaderLayoutItem( new SfxInt16Item(SID_ATTR_PAGE_HEADER_LAYOUT)),
70 mxHeaderToggle(m_xBuilder->weld_check_button("headertoggle")),
71 mxHeaderSpacingLB(m_xBuilder->weld_combo_box("spacingpreset")),
72 mxHeaderMarginPresetLB(m_xBuilder->weld_combo_box("headermarginpreset")),
73 mxHeaderLayoutLB(m_xBuilder->weld_combo_box("samecontentLB")),
74 mxCustomEntry(m_xBuilder->weld_label("customlabel"))
75{
76 Initialize();
77}
78
80{
81 mxHeaderToggle.reset();
82 mxHeaderSpacingLB.reset();
83 mxHeaderLayoutLB.reset();
85 mxCustomEntry.reset();
86}
87
89{
90 FieldUnit eUnit;
91
92 if (pState && eState >= SfxItemState::DEFAULT)
93 eUnit = static_cast<FieldUnit>(static_cast<const SfxUInt16Item*>(pState)->GetValue());
94 else
95 eUnit = GetModuleFieldUnit();
96
97 return eUnit;
98}
99
101{
103
105
106 m_aCustomEntry = mxCustomEntry->get_label();
107 mxHeaderToggle->connect_toggled( LINK(this, PageHeaderPanel, HeaderToggleHdl) );
108 mxHeaderMarginPresetLB->connect_changed( LINK(this, PageHeaderPanel, HeaderLRMarginHdl));
109 mxHeaderSpacingLB->connect_changed( LINK(this, PageHeaderPanel, HeaderSpacingHdl));
110 mxHeaderLayoutLB->connect_changed( LINK(this, PageHeaderPanel, HeaderLayoutHdl));
111
112 mpBindings->Invalidate(SID_ATTR_METRIC);
117}
118
120{
121 if (mxHeaderToggle->get_active())
122 {
123 mxHeaderSpacingLB->set_sensitive(true);
124 mxHeaderLayoutLB->set_sensitive(true);
125 mxHeaderMarginPresetLB->set_sensitive(true);
126 }
127 else
128 {
129 mxHeaderSpacingLB->set_sensitive(false);
130 mxHeaderLayoutLB->set_sensitive(false);
131 mxHeaderMarginPresetLB->set_sensitive(false);
132 }
133}
134
136{
137 sal_uInt16 nLeft = mpHeaderLRMarginItem->GetLeft();
138 sal_uInt16 nRight = mpHeaderLRMarginItem->GetRight();
139 sal_uInt16 nCount = mxHeaderMarginPresetLB->get_count();
140 if(nLeft == nRight)
141 {
142 for (sal_uInt16 i = 0; i < nCount; ++i)
143 {
144 if (mxHeaderMarginPresetLB->get_id(i).toUInt32() == nLeft)
145 {
146 mxHeaderMarginPresetLB->set_active(i);
147 int nCustomEntry = mxHeaderMarginPresetLB->find_text(m_aCustomEntry);
148 if (nCustomEntry != -1)
149 mxHeaderMarginPresetLB->remove(nCustomEntry);
150 return;
151 }
152 }
153 }
155 mxHeaderMarginPresetLB->set_active_text(m_aCustomEntry);
156}
157
159{
160 sal_uInt16 nBottom = mpHeaderSpacingItem->GetLower();
161 sal_uInt16 nCount = mxHeaderSpacingLB->get_count();
162 for (sal_uInt16 i = 0; i < nCount; ++i)
163 {
164 if (mxHeaderSpacingLB->get_id(i).toUInt32() == nBottom)
165 {
166 mxHeaderSpacingLB->set_active(i);
167 int nCustomEntry = mxHeaderSpacingLB->find_text(m_aCustomEntry);
168 if (nCustomEntry != -1)
169 mxHeaderSpacingLB->remove(nCustomEntry);
170 return;
171 }
172 }
173 mxHeaderSpacingLB->append_text(m_aCustomEntry);
174 mxHeaderSpacingLB->set_active_text(m_aCustomEntry);
175}
176
178{
179 sal_uInt16 nLayout = mpHeaderLayoutItem->GetValue();
180 mxHeaderLayoutLB->set_active(nLayout);
181}
182
184 const sal_uInt16 nSid,
185 const SfxItemState eState,
186 const SfxPoolItem* pState)
187{
188 if (!mxHeaderToggle) //disposed
189 return;
190
191 switch(nSid)
192 {
194 {
195 if(eState >= SfxItemState::DEFAULT &&
196 dynamic_cast<const SfxBoolItem*>( pState) )
197 {
198 mpHeaderItem.reset( static_cast<SfxBoolItem*>(pState->Clone()) );
199 mxHeaderToggle->set_active(mpHeaderItem->GetValue());
201 }
202 }
203 break;
205 {
206 if(eState >= SfxItemState::DEFAULT &&
207 dynamic_cast<const SvxLongLRSpaceItem*>( pState) )
208 {
209 mpHeaderLRMarginItem.reset( static_cast<SvxLongLRSpaceItem*>(pState->Clone()) );
211 }
212 }
213 break;
215 {
216 if(eState >= SfxItemState::DEFAULT &&
217 dynamic_cast<const SvxLongULSpaceItem*>( pState) )
218 {
219 mpHeaderSpacingItem.reset(static_cast<SvxLongULSpaceItem*>(pState->Clone()) );
221 }
222 }
223 break;
225 {
226 if(eState >= SfxItemState::DEFAULT &&
227 dynamic_cast<const SfxInt16Item*>( pState) )
228 {
229 mpHeaderLayoutItem.reset(static_cast<SfxInt16Item*>(pState->Clone()) );
231 }
232 }
233 break;
234 case SID_ATTR_METRIC:
235 {
236 FieldUnit eFUnit = GetCurrentUnit(eState, pState);
237 if (meFUnit != eFUnit)
238 {
239 meFUnit = eFUnit;
243 }
244 }
245 break;
246 default:
247 break;
248 }
249}
250
252{
253 bool IsChecked = mxHeaderToggle->get_active();
254 mpHeaderItem->SetValue(IsChecked);
255 GetBindings()->GetDispatcher()->ExecuteList( SID_ATTR_PAGE_HEADER, SfxCallMode::RECORD, { mpHeaderItem.get() } );
256 UpdateHeaderCheck();
257}
258
259IMPL_LINK_NOARG( PageHeaderPanel, HeaderLRMarginHdl, weld::ComboBox&, void )
260{
261 sal_uInt16 nVal = mxHeaderMarginPresetLB->get_active_id().toUInt32();
262 mpHeaderLRMarginItem->SetLeft(nVal);
263 mpHeaderLRMarginItem->SetRight(nVal);
265 SfxCallMode::RECORD, { mpHeaderLRMarginItem.get() } );
266}
267
269{
270 sal_uInt16 nVal = mxHeaderSpacingLB->get_active_id().toUInt32();
271 mpHeaderSpacingItem->SetLower(nVal);
273 SfxCallMode::RECORD, { mpHeaderSpacingItem.get() } );
274}
276{
277 sal_uInt16 nVal = mxHeaderLayoutLB->get_active();
278 mpHeaderLayoutItem->SetValue(nVal);
280 SfxCallMode::RECORD, { mpHeaderLayoutItem.get() } );
281}
282
283
284}
285
286/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SfxDispatcher * GetDispatcher() const
void Invalidate(sal_uInt16 nId)
const SfxPoolItem * ExecuteList(sal_uInt16 nSlot, SfxCallMode nCall, std::initializer_list< SfxPoolItem const * > args, std::initializer_list< SfxPoolItem const * > internalargs=std::initializer_list< SfxPoolItem const * >())
virtual SfxPoolItem * Clone(SfxItemPool *pPool=nullptr) const=0
std::unique_ptr< weld::CheckButton > mxHeaderToggle
::std::unique_ptr< SfxBoolItem > mpHeaderItem
std::unique_ptr< weld::ComboBox > mxHeaderMarginPresetLB
virtual ~PageHeaderPanel() override
::std::unique_ptr< SvxLongLRSpaceItem > mpHeaderLRMarginItem
::std::unique_ptr< SfxInt16Item > mpHeaderLayoutItem
virtual void NotifyItemUpdate(const sal_uInt16 nSId, const SfxItemState eState, const SfxPoolItem *pState) override
std::unique_ptr< weld::ComboBox > mxHeaderLayoutLB
::std::unique_ptr< SvxLongULSpaceItem > mpHeaderSpacingItem
std::unique_ptr< weld::ComboBox > mxHeaderSpacingLB
PageHeaderPanel(weld::Widget *pParent, SfxBindings *pBindings)
static std::unique_ptr< PanelLayout > Create(weld::Widget *pParent, SfxBindings *pBindings)
static FieldUnit GetCurrentUnit(SfxItemState eState, const SfxPoolItem *pState)
std::unique_ptr< weld::Label > mxCustomEntry
#define SID_ATTR_PAGE_HEADER
Definition: cmdid.h:897
#define SID_ATTR_PAGE_HEADER_LRMARGIN
Definition: cmdid.h:898
#define SID_ATTR_PAGE_HEADER_SPACING
Definition: cmdid.h:899
#define SID_ATTR_PAGE_HEADER_LAYOUT
Definition: cmdid.h:900
int nCount
virtual SfxBindings & GetBindings() override
SVXCORE_DLLPUBLIC FieldUnit GetModuleFieldUnit(const SfxItemSet &)
FieldUnit
void Fill(weld::ComboBox &rComboBox)
void Fill(SpacingType eType, weld::ComboBox &rComboBox)
int i
IMPL_LINK_NOARG(AccessibilityCheckEntry, GotoButtonClicked, weld::LinkButton &, bool)
const char GetValue[]
SfxItemState
bool IsInch(MapUnit eU)