Update ooo320-m1
[ooovba.git] / sc / source / ui / pagedlg / tphf.cxx
blobfac6a06674aa702b459844cb2b778b354f440abe
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tphf.cxx,v $
10 * $Revision: 1.12 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 #undef SC_DLLIMPLEMENTATION
38 //------------------------------------------------------------------
40 #define _TPHF_CXX
41 #include "scitems.hxx"
42 #include <sfx2/basedlgs.hxx>
43 #include <svtools/style.hxx>
44 #include <vcl/svapp.hxx>
45 #include <vcl/msgbox.hxx>
47 #include "tphf.hxx"
48 #include "sc.hrc"
49 #include "globstr.hrc"
50 #include "tabvwsh.hxx"
51 #include "viewdata.hxx"
52 #include "document.hxx"
53 //CHINA001 #include "tphfedit.hxx"
54 #include "hfedtdlg.hxx"
55 #include "styledlg.hxx"
56 #include "scresid.hxx"
57 #include "scuitphfedit.hxx" //CHINA001
58 #undef _TPHF_CXX
62 //==================================================================
63 // class ScHFPage
64 //==================================================================
66 ScHFPage::ScHFPage( Window* pParent, USHORT nResId,
67 const SfxItemSet& rSet, USHORT nSetId )
69 : SvxHFPage ( pParent, nResId, rSet, nSetId ),
70 aBtnEdit ( this, ScResId( RID_SCBTN_HFEDIT ) ),
71 aDataSet ( *rSet.GetPool(),
72 ATTR_PAGE_HEADERLEFT, ATTR_PAGE_FOOTERRIGHT,
73 ATTR_PAGE, ATTR_PAGE, 0 ),
74 nPageUsage ( (USHORT)SVX_PAGE_ALL ),
75 pStyleDlg ( NULL )
77 SetExchangeSupport();
79 SfxViewShell* pSh = SfxViewShell::Current();
80 ScTabViewShell* pViewSh = PTR_CAST(ScTabViewShell,pSh);
81 Point aPos( aBackgroundBtn.GetPosPixel() );
83 // aBackgroundBtn position not changed anymore
85 aPos.X() += aBackgroundBtn.GetSizePixel().Width();
86 aPos.X() += LogicToPixel( Size(3,0), MAP_APPFONT ).Width();
87 aBtnEdit.SetPosPixel( aPos );
88 aBtnEdit.Show();
90 aDataSet.Put( rSet );
92 if ( pViewSh )
94 ScViewData* pViewData = pViewSh->GetViewData();
95 ScDocument* pDoc = pViewData->GetDocument();
97 aStrPageStyle = pDoc->GetPageStyle( pViewData->GetTabNo() );
100 aBtnEdit.SetClickHdl ( LINK( this, ScHFPage, BtnHdl ) );
101 aTurnOnBox.SetClickHdl ( LINK( this, ScHFPage, TurnOnHdl ) );
103 if ( nId == SID_ATTR_PAGE_HEADERSET )
104 aBtnEdit.SetHelpId( HID_SC_HEADER_EDIT );
105 else
106 aBtnEdit.SetHelpId( HID_SC_FOOTER_EDIT );
109 //------------------------------------------------------------------
111 __EXPORT ScHFPage::~ScHFPage()
115 //------------------------------------------------------------------
117 void __EXPORT ScHFPage::Reset( const SfxItemSet& rSet )
119 SvxHFPage::Reset( rSet );
120 TurnOnHdl( 0 );
123 //------------------------------------------------------------------
125 BOOL __EXPORT ScHFPage::FillItemSet( SfxItemSet& rOutSet )
127 BOOL bResult = SvxHFPage::FillItemSet( rOutSet );
129 if ( nId == SID_ATTR_PAGE_HEADERSET )
131 rOutSet.Put( aDataSet.Get( ATTR_PAGE_HEADERLEFT ) );
132 rOutSet.Put( aDataSet.Get( ATTR_PAGE_HEADERRIGHT ) );
134 else
136 rOutSet.Put( aDataSet.Get( ATTR_PAGE_FOOTERLEFT ) );
137 rOutSet.Put( aDataSet.Get( ATTR_PAGE_FOOTERRIGHT ) );
140 return bResult;
143 //------------------------------------------------------------------
145 void __EXPORT ScHFPage::ActivatePage( const SfxItemSet& rSet )
147 USHORT nPageWhich = GetWhich( SID_ATTR_PAGE );
148 const SvxPageItem& rPageItem = (const SvxPageItem&)
149 rSet.Get(nPageWhich);
151 nPageUsage = rPageItem.GetPageUsage();
153 if ( pStyleDlg )
154 aStrPageStyle = pStyleDlg->GetStyleSheet().GetName();
156 aDataSet.Put( rSet.Get(ATTR_PAGE) );
158 SvxHFPage::ActivatePage( rSet );
161 //------------------------------------------------------------------
163 int __EXPORT ScHFPage::DeactivatePage( SfxItemSet* pSetP )
165 if ( LEAVE_PAGE == SvxHFPage::DeactivatePage( pSetP ) )
166 if ( pSetP )
167 FillItemSet( *pSetP );
169 return LEAVE_PAGE;
172 //------------------------------------------------------------------
174 void ScHFPage::ActivatePage()
178 void ScHFPage::DeactivatePage()
182 //------------------------------------------------------------------
183 // Handler:
184 //------------------------------------------------------------------
186 IMPL_LINK( ScHFPage, TurnOnHdl, CheckBox*, EMPTYARG )
188 SvxHFPage::TurnOnHdl( &aTurnOnBox );
190 if ( aTurnOnBox.IsChecked() )
191 aBtnEdit.Enable();
192 else
193 aBtnEdit.Disable();
195 return 0;
199 //------------------------------------------------------------------
201 IMPL_LINK( ScHFPage, BtnHdl, PushButton*, EMPTYARG )
203 // Wenn der Bearbeiten-Dialog direkt aus dem Click-Handler des Buttons
204 // aufgerufen wird, funktioniert im Bearbeiten-Dialog unter OS/2 das
205 // GrabFocus nicht (Bug #41805#).
206 // Mit dem neuen StarView sollte dieser Workaround wieder raus koennen!
208 Application::PostUserEvent( LINK( this, ScHFPage, HFEditHdl ) );
209 return 0;
212 IMPL_LINK( ScHFPage, HFEditHdl, void*, EMPTYARG )
214 SfxViewShell* pViewSh = SfxViewShell::Current();
216 if ( !pViewSh )
218 DBG_ERROR( "Current ViewShell not found." );
219 return 0;
222 if ( aCntSharedBox.IsEnabled()
223 && !aCntSharedBox.IsChecked() )
225 USHORT nResId = ( nId == SID_ATTR_PAGE_HEADERSET )
226 ? RID_SCDLG_HFED_HEADER
227 : RID_SCDLG_HFED_FOOTER;
229 ScHFEditDlg* pDlg
230 = new ScHFEditDlg( pViewSh->GetViewFrame(), this,
231 aDataSet, aStrPageStyle, nResId );
233 if ( pDlg->Execute() == RET_OK )
235 aDataSet.Put( *pDlg->GetOutputItemSet() );
238 delete pDlg;
240 else
242 String aText;
243 SfxSingleTabDialog* pDlg = new SfxSingleTabDialog( this, aDataSet, 42 );
244 BOOL bRightPage = aCntSharedBox.IsChecked()
245 || ( SVX_PAGE_LEFT != SvxPageUsage(nPageUsage) );
247 if ( nId == SID_ATTR_PAGE_HEADERSET )
249 aText = ScGlobal::GetRscString( STR_PAGEHEADER );
250 if ( bRightPage )
251 pDlg->SetTabPage( ScRightHeaderEditPage::Create( pDlg, aDataSet ) );
252 else
253 pDlg->SetTabPage( ScLeftHeaderEditPage::Create( pDlg, aDataSet ) );
255 else
257 aText = ScGlobal::GetRscString( STR_PAGEFOOTER );
258 if ( bRightPage )
259 pDlg->SetTabPage( ScRightFooterEditPage::Create( pDlg, aDataSet ) );
260 else
261 pDlg->SetTabPage( ScLeftFooterEditPage::Create( pDlg, aDataSet ) );
264 SvxNumType eNumType = ((const SvxPageItem&)aDataSet.Get(ATTR_PAGE)).GetNumType();
265 ((ScHFEditPage*)pDlg->GetTabPage())->SetNumType(eNumType);
267 aText.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " (" ));
268 aText += ScGlobal::GetRscString( STR_PAGESTYLE );
269 aText.AppendAscii(RTL_CONSTASCII_STRINGPARAM( ": " ));
270 aText += aStrPageStyle;
271 aText += ')';
273 pDlg->SetText( aText );
275 if ( pDlg->Execute() == RET_OK )
277 aDataSet.Put( *pDlg->GetOutputItemSet() );
280 delete pDlg;
283 return 0;
286 //==================================================================
287 // class ScHeaderPage
288 //==================================================================
290 ScHeaderPage::ScHeaderPage( Window* pParent, const SfxItemSet& rSet )
291 : ScHFPage( pParent, RID_SVXPAGE_HEADER, rSet, SID_ATTR_PAGE_HEADERSET )
295 //------------------------------------------------------------------
297 SfxTabPage* __EXPORT ScHeaderPage::Create( Window* pParent, const SfxItemSet& rCoreSet )
299 return ( new ScHeaderPage( pParent, rCoreSet ) );
302 //------------------------------------------------------------------
304 USHORT* __EXPORT ScHeaderPage::GetRanges()
306 return SvxHeaderPage::GetRanges();
309 //==================================================================
310 // class ScFooterPage
311 //==================================================================
313 ScFooterPage::ScFooterPage( Window* pParent, const SfxItemSet& rSet )
314 : ScHFPage( pParent, RID_SVXPAGE_FOOTER, rSet, SID_ATTR_PAGE_FOOTERSET )
318 //------------------------------------------------------------------
320 SfxTabPage* __EXPORT ScFooterPage::Create( Window* pParent, const SfxItemSet& rCoreSet )
322 return ( new ScFooterPage( pParent, rCoreSet ) );
325 //------------------------------------------------------------------
327 USHORT* __EXPORT ScFooterPage::GetRanges()
329 return SvxHeaderPage::GetRanges();