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 
43 ScHFPage::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_FOOTERRIGHT>{})
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 
80 void ScHFPage::Reset( const SfxItemSet* rSet )
81 {
82  SvxHFPage::Reset( rSet );
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 ) );
93  rOutSet->Put( aDataSet.Get( ATTR_PAGE_HEADERRIGHT ) );
94  }
95  else
96  {
97  rOutSet->Put( aDataSet.Get( ATTR_PAGE_FOOTERLEFT ) );
98  rOutSet->Put( aDataSet.Get( ATTR_PAGE_FOOTERRIGHT ) );
99  }
100 
101  return bResult;
102 }
103 
105 {
106  sal_uInt16 nPageWhich = GetWhich( SID_ATTR_PAGE );
107  const SvxPageItem& rPageItem = static_cast<const SvxPageItem&>(
108  rSet.Get(nPageWhich));
109 
110  nPageUsage = rPageItem.GetPageUsage();
111 
112  if ( pStyleDlg )
114 
115  aDataSet.Put( rSet.Get(ATTR_PAGE) );
116 
117  SvxHFPage::ActivatePage( rSet );
118 }
119 
121 {
122  if ( DeactivateRC::LeavePage == SvxHFPage::DeactivatePage( pSetP ) )
123  if ( pSetP )
124  FillItemSet( pSetP );
125 
126  return DeactivateRC::LeavePage;
127 }
128 
129 // Handler:
130 
132 {
133  SvxHFPage::TurnOnHdl(*m_xTurnOnBox);
134 
135  if (m_xTurnOnBox->get_active())
136  m_xBtnEdit->set_sensitive(true);
137  else
138  m_xBtnEdit->set_sensitive(false);
139 }
140 
142 {
143  SfxViewShell* pViewSh = SfxViewShell::Current();
144 
145  if ( !pViewSh )
146  {
147  OSL_FAIL( "Current ViewShell not found." );
148  return;
149  }
150 
151  if (m_xCntSharedBox->get_sensitive() && !m_xCntSharedBox->get_active())
152  {
153  sal_uInt16 nResId = ( nId == SID_ATTR_PAGE_HEADERSET )
154  ? RID_SCDLG_HFED_HEADER
155  : RID_SCDLG_HFED_FOOTER;
156 
158 
160  GetFrameWeld(), aDataSet, aStrPageStyle, nResId));
161  pDlg->StartExecuteAsync([this, pDlg](sal_Int32 nResult){
162  if ( nResult == RET_OK )
163  {
164  aDataSet.Put( *pDlg->GetOutputItemSet() );
165  }
166  });
167  }
168  else
169  {
170  OUString aText;
171  SfxSingleTabDialogController aDlg(GetFrameWeld(), &aDataSet);
172  bool bRightPage = m_xCntSharedBox->get_active() || (SvxPageUsage::Left != nPageUsage);
173 
174  if ( nId == SID_ATTR_PAGE_HEADERSET )
175  {
176  aText = ScResId( STR_PAGEHEADER );
177  if ( bRightPage )
178  aDlg.SetTabPage(ScRightHeaderEditPage::Create(aDlg.get_content_area(), &aDlg, &aDataSet));
179  else
180  aDlg.SetTabPage(ScLeftHeaderEditPage::Create(aDlg.get_content_area(), &aDlg, &aDataSet));
181  }
182  else
183  {
184  aText = ScResId( STR_PAGEFOOTER );
185  if ( bRightPage )
186  aDlg.SetTabPage(ScRightFooterEditPage::Create(aDlg.get_content_area(), &aDlg, &aDataSet));
187  else
188  aDlg.SetTabPage(ScLeftFooterEditPage::Create(aDlg.get_content_area(), &aDlg, &aDataSet));
189  }
190 
191  SvxNumType eNumType = aDataSet.Get(ATTR_PAGE).GetNumType();
192  static_cast<ScHFEditPage*>(aDlg.GetTabPage())->SetNumType(eNumType);
193 
194  aText += " (" + ScResId( STR_PAGESTYLE ) +
195  ": " + aStrPageStyle + ")";
196 
197  aDlg.set_title(aText);
198 
199  if (aDlg.run() == RET_OK)
200  {
201  aDataSet.Put(*aDlg.GetOutputItemSet());
202  }
203  }
204 }
205 
206 
208  : ScHFPage(pPage, pController, rSet, SID_ATTR_PAGE_HEADERSET)
209 {
210 }
211 
212 std::unique_ptr<SfxTabPage> ScHeaderPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rCoreSet)
213 {
214  return std::make_unique<ScHeaderPage>(pPage, pController, *rCoreSet);
215 }
216 
217 const sal_uInt16* ScHeaderPage::GetRanges()
218 {
219  return SvxHeaderPage::GetRanges();
220 }
221 
222 
224  : ScHFPage( pPage, pController, rSet, SID_ATTR_PAGE_FOOTERSET )
225 {
226 }
227 
228 std::unique_ptr<SfxTabPage> ScFooterPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rCoreSet)
229 {
230  return std::make_unique<ScFooterPage>(pPage, pController, *rCoreSet);
231 }
232 
233 const sal_uInt16* ScFooterPage::GetRanges()
234 {
235  return SvxHeaderPage::GetRanges();
236 }
237 
238 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: tphf.cxx:228
virtual ~ScHFPage() override
Definition: tphf.cxx:75
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rCoreSet)
sal_Int16 nId
SCTAB GetTabNo() const
Definition: viewdata.hxx:394
static const sal_uInt16 * GetRanges()
Definition: tphf.cxx:233
weld::Container * get_content_area()
SvxPageUsage nPageUsage
Definition: tphf.hxx:46
ScDocument & GetDocument() const
Definition: viewdata.hxx:379
const SfxItemSet * GetOutputItemSet() const
virtual void ActivatePage(const SfxItemSet &rSet) override
Definition: tphf.cxx:104
SvxNumType
OUString aStrPageStyle
Definition: tphf.hxx:45
ScHeaderPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: tphf.cxx:207
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rCoreSet)
const OUString & GetName() const
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rCoreSet)
static SfxViewShell * Current()
#define HID_SC_FOOTER_EDIT
Definition: helpids.h:35
SfxStyleSheetBase & GetStyleSheet()
virtual void Reset(const SfxItemSet *rSet) override
static const sal_uInt16 * GetRanges()
ScViewData & GetViewData()
Definition: tabview.hxx:333
SfxItemSet aDataSet
Definition: tphf.hxx:44
constexpr TypedWhichId< ScPageHFItem > ATTR_PAGE_FOOTERLEFT(178)
std::unique_ptr< weld::CheckButton > m_xTurnOnBox
sal_uInt16 nId
OUString ScResId(const char *pId)
Definition: scdll.cxx:89
SC_DLLPUBLIC OUString GetPageStyle(SCTAB nTab) const
Definition: document.cxx:6173
void SetTabPage(std::unique_ptr< SfxTabPage > xTabPage)
constexpr TypedWhichId< ScPageHFItem > ATTR_PAGE_HEADERRIGHT(179)
constexpr TypedWhichId< ScPageHFItem > ATTR_PAGE_FOOTERRIGHT(180)
SvxPageUsage GetPageUsage() const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
ScHFPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet, sal_uInt16 nSetId)
Definition: tphf.cxx:43
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
#define GetWhich(nSlot)
ScFooterPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: tphf.cxx:223
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: tphf.cxx:120
static SC_DLLPUBLIC ScAbstractDialogFactory * Create()
Definition: scabstdlg.cxx:37
virtual VclPtr< SfxAbstractTabDialog > CreateScHFEditDlg(weld::Window *pParent, const SfxItemSet &rCoreSet, const OUString &rPageStyle, sal_uInt16 nResId)=0
RET_OK
These need to be in global namespace just like their respective types are.
constexpr TypedWhichId< SvxPageItem > ATTR_PAGE(159)
#define HID_SC_HEADER_EDIT
Definition: helpids.h:34
virtual bool FillItemSet(SfxItemSet *rOutSet) override
DeactivateRC
virtual void ActivatePage(const SfxItemSet &rSet) override
ScStyleDlg * pStyleDlg
Definition: tphf.hxx:47
SfxTabPage * GetTabPage() const
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: tphf.cxx:212
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
static const sal_uInt16 * GetRanges()
Definition: tphf.cxx:217
virtual bool FillItemSet(SfxItemSet *rOutSet) override
Definition: tphf.cxx:86
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rCoreSet)
virtual void Reset(const SfxItemSet *rSet) override
Definition: tphf.cxx:80
constexpr TypedWhichId< ScPageHFItem > ATTR_PAGE_HEADERLEFT(177)
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
IMPL_LINK_NOARG(ScHFPage, TurnOnHdl, weld::ToggleButton &, void)
Definition: tphf.cxx:131