Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / ui / pagedlg / tphf.cxx
blob7c39776c0c9a7e62ea63bfd153482986caf4076c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #undef SC_DLLIMPLEMENTATION
25 //------------------------------------------------------------------
27 #define _TPHF_CXX
28 #include "scitems.hxx"
29 #include <sfx2/basedlgs.hxx>
30 #include <svl/style.hxx>
31 #include <vcl/svapp.hxx>
32 #include <vcl/msgbox.hxx>
34 #include "tphf.hxx"
35 #include "sc.hrc"
36 #include "scabstdlg.hxx"
37 #include "globstr.hrc"
38 #include "tabvwsh.hxx"
39 #include "viewdata.hxx"
40 #include "document.hxx"
41 #include "hfedtdlg.hxx"
42 #include "styledlg.hxx"
43 #include "scresid.hxx"
44 #include "scuitphfedit.hxx"
45 #undef _TPHF_CXX
49 //==================================================================
50 // class ScHFPage
51 //==================================================================
53 ScHFPage::ScHFPage( Window* pParent, const SfxItemSet& rSet, sal_uInt16 nSetId )
55 : SvxHFPage ( pParent, rSet, nSetId ),
56 aDataSet ( *rSet.GetPool(),
57 ATTR_PAGE_HEADERLEFT, ATTR_PAGE_FOOTERRIGHT,
58 ATTR_PAGE, ATTR_PAGE, 0 ),
59 nPageUsage ( (sal_uInt16)SVX_PAGE_ALL ),
60 pStyleDlg ( NULL )
62 get(m_pBtnEdit, "buttonEdit");
64 SetExchangeSupport();
66 SfxViewShell* pSh = SfxViewShell::Current();
67 ScTabViewShell* pViewSh = PTR_CAST(ScTabViewShell,pSh);
68 m_pBtnEdit->Show();
70 aDataSet.Put( rSet );
72 if ( pViewSh )
74 ScViewData* pViewData = pViewSh->GetViewData();
75 ScDocument* pDoc = pViewData->GetDocument();
77 aStrPageStyle = pDoc->GetPageStyle( pViewData->GetTabNo() );
80 m_pBtnEdit->SetClickHdl ( LINK( this, ScHFPage, BtnHdl ) );
81 m_pTurnOnBox->SetClickHdl ( LINK( this, ScHFPage, TurnOnHdl ) );
83 if ( nId == SID_ATTR_PAGE_HEADERSET )
84 m_pBtnEdit->SetHelpId( HID_SC_HEADER_EDIT );
85 else
86 m_pBtnEdit->SetHelpId( HID_SC_FOOTER_EDIT );
89 //------------------------------------------------------------------
91 ScHFPage::~ScHFPage()
95 //------------------------------------------------------------------
97 void ScHFPage::Reset( const SfxItemSet& rSet )
99 SvxHFPage::Reset( rSet );
100 TurnOnHdl( 0 );
103 //------------------------------------------------------------------
105 sal_Bool ScHFPage::FillItemSet( SfxItemSet& rOutSet )
107 sal_Bool bResult = SvxHFPage::FillItemSet( rOutSet );
109 if ( nId == SID_ATTR_PAGE_HEADERSET )
111 rOutSet.Put( aDataSet.Get( ATTR_PAGE_HEADERLEFT ) );
112 rOutSet.Put( aDataSet.Get( ATTR_PAGE_HEADERRIGHT ) );
114 else
116 rOutSet.Put( aDataSet.Get( ATTR_PAGE_FOOTERLEFT ) );
117 rOutSet.Put( aDataSet.Get( ATTR_PAGE_FOOTERRIGHT ) );
120 return bResult;
123 //------------------------------------------------------------------
125 void ScHFPage::ActivatePage( const SfxItemSet& rSet )
127 sal_uInt16 nPageWhich = GetWhich( SID_ATTR_PAGE );
128 const SvxPageItem& rPageItem = (const SvxPageItem&)
129 rSet.Get(nPageWhich);
131 nPageUsage = rPageItem.GetPageUsage();
133 if ( pStyleDlg )
134 aStrPageStyle = pStyleDlg->GetStyleSheet().GetName();
136 aDataSet.Put( rSet.Get(ATTR_PAGE) );
138 SvxHFPage::ActivatePage( rSet );
141 //------------------------------------------------------------------
143 int ScHFPage::DeactivatePage( SfxItemSet* pSetP )
145 if ( LEAVE_PAGE == SvxHFPage::DeactivatePage( pSetP ) )
146 if ( pSetP )
147 FillItemSet( *pSetP );
149 return LEAVE_PAGE;
152 //------------------------------------------------------------------
154 void ScHFPage::ActivatePage()
158 void ScHFPage::DeactivatePage()
162 //------------------------------------------------------------------
163 // Handler:
164 //------------------------------------------------------------------
166 IMPL_LINK_NOARG(ScHFPage, TurnOnHdl)
168 SvxHFPage::TurnOnHdl( m_pTurnOnBox );
170 if ( m_pTurnOnBox->IsChecked() )
171 m_pBtnEdit->Enable();
172 else
173 m_pBtnEdit->Disable();
175 return 0;
179 //------------------------------------------------------------------
181 IMPL_LINK_NOARG(ScHFPage, BtnHdl)
183 // When the Edit-Dialog is directly called from the Button's Click-Handler,
184 // the GrabFocus from the Edit-Dialog under OS/2 doesn't work.(Bug #41805#).
185 // With the new StarView, this workaround should be again considered!
187 Application::PostUserEvent( LINK( this, ScHFPage, HFEditHdl ) );
188 return 0;
191 IMPL_LINK_NOARG(ScHFPage, HFEditHdl)
193 SfxViewShell* pViewSh = SfxViewShell::Current();
195 if ( !pViewSh )
197 OSL_FAIL( "Current ViewShell not found." );
198 return 0;
201 if ( m_pCntSharedBox->IsEnabled()
202 && !m_pCntSharedBox->IsChecked() )
204 sal_uInt16 nResId = ( nId == SID_ATTR_PAGE_HEADERSET )
205 ? RID_SCDLG_HFED_HEADER
206 : RID_SCDLG_HFED_FOOTER;
209 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
210 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
212 SfxAbstractTabDialog* pDlg = pFact->CreateScHFEditDlg(
213 pViewSh->GetViewFrame(), this, aDataSet, aStrPageStyle, nResId);
215 OSL_ENSURE(pDlg, "Dialog create fail!");
216 if ( pDlg->Execute() == RET_OK )
218 aDataSet.Put( *pDlg->GetOutputItemSet() );
221 delete pDlg;
223 else
225 OUString aText;
226 SfxSingleTabDialog* pDlg = new SfxSingleTabDialog(this, aDataSet);
227 const int nSettingsId = 42;
228 sal_Bool bRightPage = m_pCntSharedBox->IsChecked()
229 || ( SVX_PAGE_LEFT != SvxPageUsage(nPageUsage) );
231 if ( nId == SID_ATTR_PAGE_HEADERSET )
233 aText = ScGlobal::GetRscString( STR_PAGEHEADER );
234 if ( bRightPage )
235 pDlg->setTabPage( ScRightHeaderEditPage::Create( pDlg->get_content_area(), aDataSet ), NULL, nSettingsId );
236 else
237 pDlg->setTabPage( ScLeftHeaderEditPage::Create( pDlg->get_content_area(), aDataSet ), NULL, nSettingsId );
239 else
241 aText = ScGlobal::GetRscString( STR_PAGEFOOTER );
242 if ( bRightPage )
243 pDlg->setTabPage( ScRightFooterEditPage::Create( pDlg->get_content_area(), aDataSet ), NULL, nSettingsId );
244 else
245 pDlg->setTabPage( ScLeftFooterEditPage::Create( pDlg->get_content_area(), aDataSet ), NULL, nSettingsId );
248 SvxNumType eNumType = ((const SvxPageItem&)aDataSet.Get(ATTR_PAGE)).GetNumType();
249 ((ScHFEditPage*)pDlg->GetTabPage())->SetNumType(eNumType);
251 aText += " (" + ScGlobal::GetRscString( STR_PAGESTYLE );
252 aText += ": " + aStrPageStyle + ")";
254 pDlg->SetText( aText );
256 if ( pDlg->Execute() == RET_OK )
258 aDataSet.Put( *pDlg->GetOutputItemSet() );
261 delete pDlg;
264 return 0;
267 //==================================================================
268 // class ScHeaderPage
269 //==================================================================
271 ScHeaderPage::ScHeaderPage( Window* pParent, const SfxItemSet& rSet )
272 : ScHFPage( pParent, rSet, SID_ATTR_PAGE_HEADERSET )
276 //------------------------------------------------------------------
278 SfxTabPage* ScHeaderPage::Create( Window* pParent, const SfxItemSet& rCoreSet )
280 return ( new ScHeaderPage( pParent, rCoreSet ) );
283 //------------------------------------------------------------------
285 sal_uInt16* ScHeaderPage::GetRanges()
287 return SvxHeaderPage::GetRanges();
290 //==================================================================
291 // class ScFooterPage
292 //==================================================================
294 ScFooterPage::ScFooterPage( Window* pParent, const SfxItemSet& rSet )
295 : ScHFPage( pParent, rSet, SID_ATTR_PAGE_FOOTERSET )
299 //------------------------------------------------------------------
301 SfxTabPage* ScFooterPage::Create( Window* pParent, const SfxItemSet& rCoreSet )
303 return ( new ScFooterPage( pParent, rCoreSet ) );
306 //------------------------------------------------------------------
308 sal_uInt16* ScFooterPage::GetRanges()
310 return SvxHeaderPage::GetRanges();
316 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */