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_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 
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  rOutSet->Put( aDataSet.Get( ATTR_PAGE_HEADERFIRST ) );
95  }
96  else
97  {
98  rOutSet->Put( aDataSet.Get( ATTR_PAGE_FOOTERLEFT ) );
99  rOutSet->Put( aDataSet.Get( ATTR_PAGE_FOOTERRIGHT ) );
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 
117  aDataSet.Put( rSet.Get(ATTR_PAGE) );
118 
119  SvxHFPage::ActivatePage( rSet );
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 {
145  SfxViewShell* pViewSh = SfxViewShell::Current();
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;
195  SfxSingleTabDialogController aDlg(GetFrameWeld(), &aDataSet);
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 
236 std::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 {
243  return SvxHeaderPage::GetRanges();
244 }
245 
246 
248  : ScHFPage( pPage, pController, rSet, SID_ATTR_PAGE_FOOTERSET )
249 {
250 }
251 
252 std::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 {
259  return SvxHeaderPage::GetRanges();
260 }
261 
262 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr TypedWhichId< ScPageHFItem > ATTR_PAGE_FOOTERFIRST(183)
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: tphf.cxx:252
virtual ~ScHFPage() override
Definition: tphf.cxx:75
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rCoreSet)
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:89
constexpr TypedWhichId< ScPageHFItem > ATTR_PAGE_HEADERLEFT(178)
static WhichRangesContainer GetRanges()
Definition: tphf.cxx:241
sal_Int16 nId
SCTAB GetTabNo() const
Definition: viewdata.hxx:394
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:106
SvxNumType
OUString aStrPageStyle
Definition: tphf.hxx:45
ScHeaderPage(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rSet)
Definition: tphf.cxx:231
constexpr TypedWhichId< ScPageHFItem > ATTR_PAGE_HEADERRIGHT(180)
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)
std::unique_ptr< weld::Button > m_xBtnEdit
Definition: tphf.hxx:48
static SfxViewShell * Current()
#define HID_SC_FOOTER_EDIT
Definition: helpids.h:35
SfxStyleSheetBase & GetStyleSheet()
virtual void Reset(const SfxItemSet *rSet) override
ScViewData & GetViewData()
Definition: tabview.hxx:333
constexpr TypedWhichId< ScPageHFItem > ATTR_PAGE_HEADERFIRST(182)
SfxItemSet aDataSet
Definition: tphf.hxx:44
std::unique_ptr< weld::CheckButton > m_xTurnOnBox
sal_uInt16 nId
SC_DLLPUBLIC OUString GetPageStyle(SCTAB nTab) const
Definition: document.cxx:6213
void SetTabPage(std::unique_ptr< SfxTabPage > xTabPage)
SvxPageUsage
SvxPageUsage GetPageUsage() const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
constexpr TypedWhichId< ScPageHFItem > ATTR_PAGE_FOOTERLEFT(179)
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:247
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: tphf.cxx:122
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
IMPL_LINK_NOARG(ScHFPage, TurnOnHdl, weld::Toggleable &, void)
Definition: tphf.cxx:133
DeactivateRC
virtual void ActivatePage(const SfxItemSet &rSet) override
ScStyleDlg * pStyleDlg
Definition: tphf.hxx:47
SfxTabPage * GetTabPage() const
static WhichRangesContainer GetRanges()
Definition: tphf.cxx:257
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rSet)
Definition: tphf.cxx:236
constexpr TypedWhichId< ScPageHFItem > ATTR_PAGE_FOOTERRIGHT(181)
static WhichRangesContainer GetRanges()
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
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
weld::Window * GetFrameWeld(const SfxFrame *pFrame)