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 #include <vcl/svapp.hxx>
28 
29 #include <attrib.hxx>
30 #include <tphf.hxx>
31 #include <scres.hrc>
32 #include <scabstdlg.hxx>
33 #include <globstr.hrc>
34 #include <scresid.hxx>
35 #include <tabvwsh.hxx>
36 #include <viewdata.hxx>
37 #include <document.hxx>
38 #include <styledlg.hxx>
39 #include <scuitphfedit.hxx>
40 #include <memory>
41 #include <helpids.h>
42 
43 
44 ScHFPage::ScHFPage(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet& rSet, sal_uInt16 nSetId)
45  : SvxHFPage(pPage, pController, rSet, nSetId)
46  , aDataSet(*rSet.GetPool(), svl::Items<ATTR_PAGE, ATTR_PAGE, ATTR_PAGE_HEADERLEFT, ATTR_PAGE_FOOTERRIGHT>{})
47  , nPageUsage(SvxPageUsage::All)
48  , pStyleDlg(nullptr)
49  , m_xBtnEdit(m_xBuilder->weld_button("buttonEdit"))
50 {
51  SetExchangeSupport();
52 
54  ScTabViewShell* pViewSh = dynamic_cast< ScTabViewShell *>( pSh );
55  m_xBtnEdit->show();
56 
57  aDataSet.Put( rSet );
58 
59  if ( pViewSh )
60  {
61  ScViewData& rViewData = pViewSh->GetViewData();
62  ScDocument* pDoc = rViewData.GetDocument();
63 
64  aStrPageStyle = pDoc->GetPageStyle( rViewData.GetTabNo() );
65  }
66 
67  m_xBtnEdit->connect_clicked(LINK(this, ScHFPage, BtnHdl));
68  m_xTurnOnBox->connect_toggled(LINK(this, ScHFPage, TurnOnHdl));
69 
70  if ( nId == SID_ATTR_PAGE_HEADERSET )
71  m_xBtnEdit->set_help_id(HID_SC_HEADER_EDIT);
72  else
73  m_xBtnEdit->set_help_id(HID_SC_FOOTER_EDIT);
74 }
75 
77 {
78  pStyleDlg = nullptr;
79 }
80 
81 void ScHFPage::Reset( const SfxItemSet* rSet )
82 {
83  SvxHFPage::Reset( rSet );
84  TurnOnHdl(*m_xTurnOnBox);
85 }
86 
88 {
89  bool bResult = SvxHFPage::FillItemSet( rOutSet );
90 
91  if ( nId == SID_ATTR_PAGE_HEADERSET )
92  {
93  rOutSet->Put( aDataSet.Get( ATTR_PAGE_HEADERLEFT ) );
94  rOutSet->Put( aDataSet.Get( ATTR_PAGE_HEADERRIGHT ) );
95  }
96  else
97  {
98  rOutSet->Put( aDataSet.Get( ATTR_PAGE_FOOTERLEFT ) );
99  rOutSet->Put( aDataSet.Get( ATTR_PAGE_FOOTERRIGHT ) );
100  }
101 
102  return bResult;
103 }
104 
106 {
107  sal_uInt16 nPageWhich = GetWhich( SID_ATTR_PAGE );
108  const SvxPageItem& rPageItem = static_cast<const SvxPageItem&>(
109  rSet.Get(nPageWhich));
110 
111  nPageUsage = rPageItem.GetPageUsage();
112 
113  if ( pStyleDlg )
115 
116  aDataSet.Put( rSet.Get(ATTR_PAGE) );
117 
118  SvxHFPage::ActivatePage( rSet );
119 }
120 
122 {
123  if ( DeactivateRC::LeavePage == SvxHFPage::DeactivatePage( pSetP ) )
124  if ( pSetP )
125  FillItemSet( pSetP );
126 
127  return DeactivateRC::LeavePage;
128 }
129 
130 // Handler:
131 
133 {
134  SvxHFPage::TurnOnHdl(*m_xTurnOnBox);
135 
136  if (m_xTurnOnBox->get_active())
137  m_xBtnEdit->set_sensitive(true);
138  else
139  m_xBtnEdit->set_sensitive(false);
140 }
141 
143 {
144  SfxViewShell* pViewSh = SfxViewShell::Current();
145 
146  if ( !pViewSh )
147  {
148  OSL_FAIL( "Current ViewShell not found." );
149  return;
150  }
151 
152  if (m_xCntSharedBox->get_sensitive() && !m_xCntSharedBox->get_active())
153  {
154  sal_uInt16 nResId = ( nId == SID_ATTR_PAGE_HEADERSET )
155  ? RID_SCDLG_HFED_HEADER
156  : RID_SCDLG_HFED_FOOTER;
157 
159 
161  GetFrameWeld(), aDataSet, aStrPageStyle, nResId));
162  pDlg->StartExecuteAsync([this, pDlg](sal_Int32 nResult){
163  if ( nResult == RET_OK )
164  {
165  aDataSet.Put( *pDlg->GetOutputItemSet() );
166  }
167  });
168  }
169  else
170  {
171  OUString aText;
172  SfxSingleTabDialogController aDlg(GetFrameWeld(), &aDataSet);
173  bool bRightPage = m_xCntSharedBox->get_active() || (SvxPageUsage::Left != nPageUsage);
174 
175  if ( nId == SID_ATTR_PAGE_HEADERSET )
176  {
177  aText = ScResId( STR_PAGEHEADER );
178  if ( bRightPage )
179  aDlg.SetTabPage(ScRightHeaderEditPage::Create(aDlg.get_content_area(), &aDlg, &aDataSet));
180  else
181  aDlg.SetTabPage(ScLeftHeaderEditPage::Create(aDlg.get_content_area(), &aDlg, &aDataSet));
182  }
183  else
184  {
185  aText = ScResId( STR_PAGEFOOTER );
186  if ( bRightPage )
187  aDlg.SetTabPage(ScRightFooterEditPage::Create(aDlg.get_content_area(), &aDlg, &aDataSet));
188  else
189  aDlg.SetTabPage(ScLeftFooterEditPage::Create(aDlg.get_content_area(), &aDlg, &aDataSet));
190  }
191 
192  SvxNumType eNumType = aDataSet.Get(ATTR_PAGE).GetNumType();
193  static_cast<ScHFEditPage*>(aDlg.GetTabPage())->SetNumType(eNumType);
194 
195  aText += " (" + ScResId( STR_PAGESTYLE ) +
196  ": " + aStrPageStyle + ")";
197 
198  aDlg.set_title(aText);
199 
200  if (aDlg.run() == RET_OK)
201  {
202  aDataSet.Put(*aDlg.GetOutputItemSet());
203  }
204  }
205 }
206 
207 
209  : ScHFPage(pPage, pController, rSet, SID_ATTR_PAGE_HEADERSET)
210 {
211 }
212 
213 std::unique_ptr<SfxTabPage> ScHeaderPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rCoreSet)
214 {
215  return std::make_unique<ScHeaderPage>(pPage, pController, *rCoreSet);
216 }
217 
218 const sal_uInt16* ScHeaderPage::GetRanges()
219 {
220  return SvxHeaderPage::GetRanges();
221 }
222 
223 
225  : ScHFPage( pPage, pController, rSet, SID_ATTR_PAGE_FOOTERSET )
226 {
227 }
228 
229 std::unique_ptr<SfxTabPage> ScFooterPage::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rCoreSet)
230 {
231  return std::make_unique<ScFooterPage>(pPage, pController, *rCoreSet);
232 }
233 
234 const sal_uInt16* ScFooterPage::GetRanges()
235 {
236  return SvxHeaderPage::GetRanges();
237 }
238 
239 /* 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:229
virtual ~ScHFPage() override
Definition: tphf.cxx:76
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rCoreSet)
sal_Int16 nId
SCTAB GetTabNo() const
Definition: viewdata.hxx:395
static const sal_uInt16 * GetRanges()
Definition: tphf.cxx:234
weld::Container * get_content_area()
SvxPageUsage nPageUsage
Definition: tphf.hxx:47
const SfxItemSet * GetOutputItemSet() const
virtual void ActivatePage(const SfxItemSet &rSet) override
Definition: tphf.cxx:105
SvxNumType
OUString aStrPageStyle
Definition: tphf.hxx:46
ScHeaderPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: tphf.cxx:208
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:36
SfxStyleSheetBase & GetStyleSheet()
ScDocument * GetDocument() const
Definition: viewdata.cxx:859
virtual void Reset(const SfxItemSet *rSet) override
static const sal_uInt16 * GetRanges()
ScViewData & GetViewData()
Definition: tabview.hxx:332
SfxItemSet aDataSet
Definition: tphf.hxx:45
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:95
SC_DLLPUBLIC OUString GetPageStyle(SCTAB nTab) const
Definition: document.cxx:6188
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:44
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:224
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: tphf.cxx:121
static SC_DLLPUBLIC ScAbstractDialogFactory * Create()
Definition: scabstdlg.cxx:38
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:35
virtual bool FillItemSet(SfxItemSet *rOutSet) override
DeactivateRC
virtual void ActivatePage(const SfxItemSet &rSet) override
ScStyleDlg * pStyleDlg
Definition: tphf.hxx:48
SfxTabPage * GetTabPage() const
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: tphf.cxx:213
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
static const sal_uInt16 * GetRanges()
Definition: tphf.cxx:218
virtual bool FillItemSet(SfxItemSet *rOutSet) override
Definition: tphf.cxx:87
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:81
constexpr TypedWhichId< ScPageHFItem > ATTR_PAGE_HEADERLEFT(177)
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
IMPL_LINK_NOARG(ScHFPage, TurnOnHdl, weld::ToggleButton &, void)
Definition: tphf.cxx:132