LibreOffice Module sc (master) 1
tphf.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
20#undef SC_DLLIMPLEMENTATION
21
22#include <scitems.hxx>
23#include <sfx2/basedlgs.hxx>
24#include <sfx2/sfxdlg.hxx>
25#include <svl/style.hxx>
26#include <svx/pageitem.hxx>
27
28#include <attrib.hxx>
29#include <tphf.hxx>
30#include <scres.hrc>
31#include <scabstdlg.hxx>
32#include <globstr.hrc>
33#include <scresid.hxx>
34#include <tabvwsh.hxx>
35#include <viewdata.hxx>
36#include <document.hxx>
37#include <styledlg.hxx>
38#include <scuitphfedit.hxx>
39#include <memory>
40#include <helpids.h>
41
42
43ScHFPage::ScHFPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet, sal_uInt16 nSetId)
44 : SvxHFPage(pPage, pController, rSet, nSetId)
45 , aDataSet(*rSet.GetPool(), svl::Items<ATTR_PAGE, ATTR_PAGE, ATTR_PAGE_HEADERLEFT, ATTR_PAGE_FOOTERFIRST>)
46 , nPageUsage(SvxPageUsage::All)
47 , pStyleDlg(nullptr)
48 , m_xBtnEdit(m_xBuilder->weld_button("buttonEdit"))
49{
50 SetExchangeSupport();
51
53 ScTabViewShell* pViewSh = dynamic_cast< ScTabViewShell *>( pSh );
54 m_xBtnEdit->show();
55
56 aDataSet.Put( rSet );
57
58 if ( pViewSh )
59 {
60 ScViewData& rViewData = pViewSh->GetViewData();
61 ScDocument& rDoc = rViewData.GetDocument();
62
63 aStrPageStyle = rDoc.GetPageStyle( rViewData.GetTabNo() );
64 }
65
66 m_xBtnEdit->connect_clicked(LINK(this, ScHFPage, BtnHdl));
67 m_xTurnOnBox->connect_toggled(LINK(this, ScHFPage, TurnOnHdl));
68
69 if ( nId == SID_ATTR_PAGE_HEADERSET )
70 m_xBtnEdit->set_help_id(HID_SC_HEADER_EDIT);
71 else
72 m_xBtnEdit->set_help_id(HID_SC_FOOTER_EDIT);
73}
74
76{
77 pStyleDlg = nullptr;
78}
79
80void ScHFPage::Reset( const SfxItemSet* rSet )
81{
83 TurnOnHdl(*m_xTurnOnBox);
84}
85
87{
88 bool bResult = SvxHFPage::FillItemSet( rOutSet );
89
90 if ( nId == SID_ATTR_PAGE_HEADERSET )
91 {
92 rOutSet->Put( aDataSet.Get( ATTR_PAGE_HEADERLEFT ) );
95 }
96 else
97 {
98 rOutSet->Put( aDataSet.Get( ATTR_PAGE_FOOTERLEFT ) );
100 rOutSet->Put( aDataSet.Get( ATTR_PAGE_FOOTERFIRST ) );
101 }
102
103 return bResult;
104}
105
107{
108 sal_uInt16 nPageWhich = GetWhich( SID_ATTR_PAGE );
109 const SvxPageItem& rPageItem = static_cast<const SvxPageItem&>(
110 rSet.Get(nPageWhich));
111
112 nPageUsage = rPageItem.GetPageUsage();
113
114 if ( pStyleDlg )
116
118
120}
121
123{
124 if ( DeactivateRC::LeavePage == SvxHFPage::DeactivatePage( pSetP ) )
125 if ( pSetP )
126 FillItemSet( pSetP );
127
128 return DeactivateRC::LeavePage;
129}
130
131// Handler:
132
134{
135 SvxHFPage::TurnOnHdl(*m_xTurnOnBox);
136
137 if (m_xTurnOnBox->get_active())
138 m_xBtnEdit->set_sensitive(true);
139 else
140 m_xBtnEdit->set_sensitive(false);
141}
142
144{
146
147 if ( !pViewSh )
148 {
149 OSL_FAIL( "Current ViewShell not found." );
150 return;
151 }
152
153 if ( (m_xCntSharedBox->get_sensitive() && !m_xCntSharedBox->get_active()) ||
154 (m_xCntSharedFirstBox->get_sensitive() && !m_xCntSharedFirstBox->get_active()) )
155 {
156 sal_uInt16 nResId;
157
158 if ( m_xCntSharedBox->get_sensitive() && !m_xCntSharedBox->get_active() &&
159 m_xCntSharedFirstBox->get_sensitive() && !m_xCntSharedFirstBox->get_active() )
160 {
161 nResId = ( nId == SID_ATTR_PAGE_HEADERSET )
162 ? RID_SCDLG_HFED_HEADER
163 : RID_SCDLG_HFED_FOOTER;
164 }
165 else if (m_xCntSharedBox->get_sensitive() && !m_xCntSharedBox->get_active())
166 {
167 nResId = ( nId == SID_ATTR_PAGE_HEADERSET )
168 ? RID_SCDLG_HFEDIT_SHAREDFIRSTHEADER
169 : RID_SCDLG_HFEDIT_SHAREDFIRSTFOOTER;
170 }
171 else
172 {
173 OSL_ENSURE( m_xCntSharedFirstBox->get_sensitive() && !m_xCntSharedFirstBox->get_active(), "This should be logically impossible." );
174 nResId = ( nId == SID_ATTR_PAGE_HEADERSET )
175 ? RID_SCDLG_HFEDIT_SHAREDLEFTHEADER
176 : RID_SCDLG_HFEDIT_SHAREDLEFTFOOTER;
177 }
178
180
182 GetFrameWeld(), aDataSet, aStrPageStyle, nResId));
183 pDlg->StartExecuteAsync([this, pDlg](sal_Int32 nResult){
184 if ( nResult == RET_OK )
185 {
186 aDataSet.Put( *pDlg->GetOutputItemSet() );
187 }
188
189 pDlg->disposeOnce();
190 });
191 }
192 else
193 {
194 OUString aText;
196 bool bRightPage = m_xCntSharedBox->get_active() || (SvxPageUsage::Left != nPageUsage);
197
198 if ( nId == SID_ATTR_PAGE_HEADERSET )
199 {
200 aText = ScResId( STR_PAGEHEADER );
201 if ( bRightPage )
202 aDlg.SetTabPage(ScRightHeaderEditPage::Create(aDlg.get_content_area(), &aDlg, &aDataSet));
203 else
204 aDlg.SetTabPage(ScLeftHeaderEditPage::Create(aDlg.get_content_area(), &aDlg, &aDataSet));
205 }
206 else
207 {
208 aText = ScResId( STR_PAGEFOOTER );
209 if ( bRightPage )
210 aDlg.SetTabPage(ScRightFooterEditPage::Create(aDlg.get_content_area(), &aDlg, &aDataSet));
211 else
212 aDlg.SetTabPage(ScLeftFooterEditPage::Create(aDlg.get_content_area(), &aDlg, &aDataSet));
213 }
214
215 SvxNumType eNumType = aDataSet.Get(ATTR_PAGE).GetNumType();
216 static_cast<ScHFEditPage*>(aDlg.GetTabPage())->SetNumType(eNumType);
217
218 aText += " (" + ScResId( STR_PAGESTYLE ) +
219 ": " + aStrPageStyle + ")";
220
221 aDlg.set_title(aText);
222
223 if (aDlg.run() == RET_OK)
224 {
225 aDataSet.Put(*aDlg.GetOutputItemSet());
226 }
227 }
228}
229
230
232 : ScHFPage(pPage, pController, rSet, SID_ATTR_PAGE_HEADERSET)
233{
234}
235
236std::unique_ptr<SfxTabPage> ScHeaderPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rCoreSet)
237{
238 return std::make_unique<ScHeaderPage>(pPage, pController, *rCoreSet);
239}
240
242{
244}
245
246
248 : ScHFPage( pPage, pController, rSet, SID_ATTR_PAGE_FOOTERSET )
249{
250}
251
252std::unique_ptr<SfxTabPage> ScFooterPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rCoreSet)
253{
254 return std::make_unique<ScFooterPage>(pPage, pController, *rCoreSet);
255}
256
258{
260}
261
262/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define GetWhich(nSlot)
virtual VclPtr< SfxAbstractTabDialog > CreateScHFEditDlg(weld::Window *pParent, const SfxItemSet &rCoreSet, const OUString &rPageStyle, sal_uInt16 nResId)=0
static SC_DLLPUBLIC ScAbstractDialogFactory * Create()
Definition: scabstdlg.cxx:37
SC_DLLPUBLIC OUString GetPageStyle(SCTAB nTab) const
Definition: document.cxx:6176
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: tphf.cxx:252
ScFooterPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: tphf.cxx:247
static WhichRangesContainer GetRanges()
Definition: tphf.cxx:257
virtual void Reset(const SfxItemSet *rSet) override
Definition: tphf.cxx:80
virtual ~ScHFPage() override
Definition: tphf.cxx:75
virtual void ActivatePage(const SfxItemSet &rSet) override
Definition: tphf.cxx:106
SvxPageUsage nPageUsage
Definition: tphf.hxx:46
OUString aStrPageStyle
Definition: tphf.hxx:45
SfxItemSet aDataSet
Definition: tphf.hxx:44
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: tphf.cxx:122
std::unique_ptr< weld::Button > m_xBtnEdit
Definition: tphf.hxx:48
ScHFPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet, sal_uInt16 nSetId)
Definition: tphf.cxx:43
ScStyleDlg * pStyleDlg
Definition: tphf.hxx:47
virtual bool FillItemSet(SfxItemSet *rOutSet) override
Definition: tphf.cxx:86
static WhichRangesContainer GetRanges()
Definition: tphf.cxx:241
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: tphf.cxx:236
ScHeaderPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: tphf.cxx:231
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rCoreSet)
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rCoreSet)
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rCoreSet)
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rCoreSet)
ScViewData & GetViewData()
Definition: tabview.hxx:344
SCTAB GetTabNo() const
Definition: viewdata.hxx:395
ScDocument & GetDocument() const
Definition: viewdata.hxx:380
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
const SfxItemSet * GetOutputItemSet() const
void SetTabPage(std::unique_ptr< SfxTabPage > xTabPage)
weld::Container * get_content_area()
SfxTabPage * GetTabPage() const
SfxStyleSheetBase & GetStyleSheet()
const OUString & GetName() const
static SAL_WARN_UNUSED_RESULT SfxViewShell * Current()
virtual void Reset(const SfxItemSet *rSet) override
virtual void ActivatePage(const SfxItemSet &rSet) override
sal_uInt16 nId
std::unique_ptr< weld::CheckButton > m_xTurnOnBox
virtual bool FillItemSet(SfxItemSet *rOutSet) override
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
static WhichRangesContainer GetRanges()
SvxPageUsage GetPageUsage() const
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
constexpr OUStringLiteral HID_SC_FOOTER_EDIT
Definition: helpids.h:37
constexpr OUStringLiteral HID_SC_HEADER_EDIT
Definition: helpids.h:36
These need to be in global namespace just like their respective types are.
sal_Int16 nId
SvxPageUsage
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:90
constexpr TypedWhichId< ScPageHFItem > ATTR_PAGE_FOOTERLEFT(179)
constexpr TypedWhichId< ScPageHFItem > ATTR_PAGE_HEADERLEFT(178)
constexpr TypedWhichId< ScPageHFItem > ATTR_PAGE_FOOTERRIGHT(181)
constexpr TypedWhichId< ScPageHFItem > ATTR_PAGE_HEADERRIGHT(180)
constexpr TypedWhichId< SvxPageItem > ATTR_PAGE(159)
constexpr TypedWhichId< ScPageHFItem > ATTR_PAGE_HEADERFIRST(182)
constexpr TypedWhichId< ScPageHFItem > ATTR_PAGE_FOOTERFIRST(183)
static SfxItemSet & rSet
SvxNumType
DeactivateRC
IMPL_LINK_NOARG(ScHFPage, TurnOnHdl, weld::Toggleable &, void)
Definition: tphf.cxx:133
RET_OK