xref: /aoo41x/main/sc/source/ui/pagedlg/tphf.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sc.hxx"
30 
31 #undef SC_DLLIMPLEMENTATION
32 
33 
34 
35 //------------------------------------------------------------------
36 
37 #define _TPHF_CXX
38 #include "scitems.hxx"
39 #include <sfx2/basedlgs.hxx>
40 #include <svl/style.hxx>
41 #include <vcl/svapp.hxx>
42 #include <vcl/msgbox.hxx>
43 
44 #include "tphf.hxx"
45 #include "sc.hrc"
46 #include "globstr.hrc"
47 #include "tabvwsh.hxx"
48 #include "viewdata.hxx"
49 #include "document.hxx"
50 //CHINA001 #include "tphfedit.hxx"
51 #include "hfedtdlg.hxx"
52 #include "styledlg.hxx"
53 #include "scresid.hxx"
54 #include "scuitphfedit.hxx" //CHINA001
55 #undef _TPHF_CXX
56 
57 
58 
59 //==================================================================
60 // class ScHFPage
61 //==================================================================
62 
63 ScHFPage::ScHFPage( Window* pParent, sal_uInt16 nResId,
64 					const SfxItemSet& rSet, sal_uInt16 nSetId )
65 
66 	:	SvxHFPage	( pParent, nResId, rSet, nSetId ),
67 		aBtnEdit	( this, ScResId( RID_SCBTN_HFEDIT ) ),
68 		aDataSet 	( *rSet.GetPool(),
69 					   ATTR_PAGE_HEADERLEFT, ATTR_PAGE_FOOTERRIGHT,
70 					   ATTR_PAGE, ATTR_PAGE, 0 ),
71 		nPageUsage	( (sal_uInt16)SVX_PAGE_ALL ),
72 		pStyleDlg	( NULL )
73 {
74 	SetExchangeSupport();
75 
76 	SfxViewShell*	pSh = SfxViewShell::Current();
77 	ScTabViewShell* pViewSh = PTR_CAST(ScTabViewShell,pSh);
78 	Point			aPos( aBackgroundBtn.GetPosPixel() );
79 
80 	// aBackgroundBtn position not changed anymore
81 
82 	aPos.X() += aBackgroundBtn.GetSizePixel().Width();
83 	aPos.X() += LogicToPixel( Size(3,0), MAP_APPFONT ).Width();
84 	aBtnEdit.SetPosPixel( aPos );
85 	aBtnEdit.Show();
86 
87 	aDataSet.Put( rSet );
88 
89 	if ( pViewSh )
90 	{
91 		ScViewData* pViewData = pViewSh->GetViewData();
92 		ScDocument* pDoc	  = pViewData->GetDocument();
93 
94 		aStrPageStyle = pDoc->GetPageStyle( pViewData->GetTabNo() );
95 	}
96 
97 	aBtnEdit.SetClickHdl 	( LINK( this, ScHFPage, BtnHdl ) );
98 	aTurnOnBox.SetClickHdl	( LINK( this, ScHFPage, TurnOnHdl ) );
99 
100 	if ( nId == SID_ATTR_PAGE_HEADERSET )
101 		aBtnEdit.SetHelpId( HID_SC_HEADER_EDIT );
102 	else
103 		aBtnEdit.SetHelpId( HID_SC_FOOTER_EDIT );
104 
105 	aBtnEdit.SetAccessibleRelationMemberOf(&aFrm);
106 }
107 
108 //------------------------------------------------------------------
109 
110 __EXPORT ScHFPage::~ScHFPage()
111 {
112 }
113 
114 //------------------------------------------------------------------
115 
116 void __EXPORT ScHFPage::Reset( const SfxItemSet& rSet )
117 {
118 	SvxHFPage::Reset( rSet );
119 	TurnOnHdl( 0 );
120 }
121 
122 //------------------------------------------------------------------
123 
124 sal_Bool __EXPORT ScHFPage::FillItemSet( SfxItemSet& rOutSet )
125 {
126 	sal_Bool bResult = SvxHFPage::FillItemSet( rOutSet );
127 
128 	if ( nId == SID_ATTR_PAGE_HEADERSET )
129 	{
130 		rOutSet.Put( aDataSet.Get( ATTR_PAGE_HEADERLEFT ) );
131 		rOutSet.Put( aDataSet.Get( ATTR_PAGE_HEADERRIGHT ) );
132 	}
133 	else
134 	{
135 		rOutSet.Put( aDataSet.Get( ATTR_PAGE_FOOTERLEFT ) );
136 		rOutSet.Put( aDataSet.Get( ATTR_PAGE_FOOTERRIGHT ) );
137 	}
138 
139 	return bResult;
140 }
141 
142 //------------------------------------------------------------------
143 
144 void __EXPORT ScHFPage::ActivatePage( const SfxItemSet& rSet )
145 {
146 	sal_uInt16				nPageWhich = GetWhich( SID_ATTR_PAGE );
147 	const SvxPageItem&	rPageItem  = (const SvxPageItem&)
148 									 rSet.Get(nPageWhich);
149 
150 	nPageUsage = rPageItem.GetPageUsage();
151 
152 	if ( pStyleDlg )
153 		aStrPageStyle = pStyleDlg->GetStyleSheet().GetName();
154 
155 	aDataSet.Put( rSet.Get(ATTR_PAGE) );
156 
157 	SvxHFPage::ActivatePage( rSet );
158 }
159 
160 //------------------------------------------------------------------
161 
162 int __EXPORT ScHFPage::DeactivatePage( SfxItemSet* pSetP )
163 {
164     if ( LEAVE_PAGE == SvxHFPage::DeactivatePage( pSetP ) )
165         if ( pSetP )
166             FillItemSet( *pSetP );
167 
168 	return LEAVE_PAGE;
169 }
170 
171 //------------------------------------------------------------------
172 
173 void ScHFPage::ActivatePage()
174 {
175 }
176 
177 void ScHFPage::DeactivatePage()
178 {
179 }
180 
181 //------------------------------------------------------------------
182 // Handler:
183 //------------------------------------------------------------------
184 
185 IMPL_LINK( ScHFPage, TurnOnHdl, CheckBox*, EMPTYARG )
186 {
187 	SvxHFPage::TurnOnHdl( &aTurnOnBox );
188 
189 	if ( aTurnOnBox.IsChecked() )
190 		aBtnEdit.Enable();
191 	else
192 		aBtnEdit.Disable();
193 
194 	return 0;
195 }
196 
197 
198 //------------------------------------------------------------------
199 
200 IMPL_LINK( ScHFPage, BtnHdl, PushButton*, EMPTYARG )
201 {
202 	//	Wenn der Bearbeiten-Dialog direkt aus dem Click-Handler des Buttons
203 	//	aufgerufen wird, funktioniert im Bearbeiten-Dialog unter OS/2 das
204 	//	GrabFocus nicht (Bug #41805#).
205 	//	Mit dem neuen StarView sollte dieser Workaround wieder raus koennen!
206 
207 	Application::PostUserEvent( LINK( this, ScHFPage, HFEditHdl ) );
208 	return 0;
209 }
210 
211 IMPL_LINK( ScHFPage, HFEditHdl, void*, EMPTYARG )
212 {
213 	SfxViewShell*	pViewSh = SfxViewShell::Current();
214 
215 	if ( !pViewSh )
216 	{
217 		DBG_ERROR( "Current ViewShell not found." );
218 		return 0;
219 	}
220 
221 	if (   aCntSharedBox.IsEnabled()
222 		&& !aCntSharedBox.IsChecked() )
223 	{
224 		sal_uInt16 nResId = ( nId == SID_ATTR_PAGE_HEADERSET )
225 							? RID_SCDLG_HFED_HEADER
226 							: RID_SCDLG_HFED_FOOTER;
227 
228 		ScHFEditDlg* pDlg
229 			 = new ScHFEditDlg( pViewSh->GetViewFrame(), this,
230 								aDataSet, aStrPageStyle, nResId );
231 
232 		if ( pDlg->Execute() == RET_OK )
233 		{
234 			aDataSet.Put( *pDlg->GetOutputItemSet() );
235 		}
236 
237 		delete pDlg;
238 	}
239 	else
240 	{
241 		String				aText;
242 		SfxSingleTabDialog* pDlg = new SfxSingleTabDialog( this, aDataSet, 42 );
243 		sal_Bool bRightPage =   aCntSharedBox.IsChecked()
244 						 || ( SVX_PAGE_LEFT != SvxPageUsage(nPageUsage) );
245 
246 		if ( nId == SID_ATTR_PAGE_HEADERSET )
247 		{
248 			aText = ScGlobal::GetRscString( STR_PAGEHEADER );
249 			if ( bRightPage )
250 				pDlg->SetTabPage( ScRightHeaderEditPage::Create( pDlg, aDataSet ) );
251 			else
252 				pDlg->SetTabPage( ScLeftHeaderEditPage::Create( pDlg, aDataSet ) );
253 		}
254 		else
255 		{
256 			aText = ScGlobal::GetRscString( STR_PAGEFOOTER );
257 			if ( bRightPage )
258 				pDlg->SetTabPage( ScRightFooterEditPage::Create( pDlg, aDataSet ) );
259 			else
260 				pDlg->SetTabPage( ScLeftFooterEditPage::Create( pDlg, aDataSet ) );
261 		}
262 
263 		SvxNumType eNumType = ((const SvxPageItem&)aDataSet.Get(ATTR_PAGE)).GetNumType();
264 		((ScHFEditPage*)pDlg->GetTabPage())->SetNumType(eNumType);
265 
266 		aText.AppendAscii(RTL_CONSTASCII_STRINGPARAM( " (" ));
267 		aText += ScGlobal::GetRscString( STR_PAGESTYLE );
268 		aText.AppendAscii(RTL_CONSTASCII_STRINGPARAM( ": " ));
269 		aText += aStrPageStyle;
270 		aText += ')';
271 
272 		pDlg->SetText( aText );
273 
274 		if ( pDlg->Execute() == RET_OK )
275 		{
276 			aDataSet.Put( *pDlg->GetOutputItemSet() );
277 		}
278 
279 		delete pDlg;
280 	}
281 
282 	return 0;
283 }
284 
285 //==================================================================
286 // class ScHeaderPage
287 //==================================================================
288 
289 ScHeaderPage::ScHeaderPage( Window* pParent, const SfxItemSet& rSet )
290 	: ScHFPage( pParent, RID_SVXPAGE_HEADER, rSet, SID_ATTR_PAGE_HEADERSET )
291 {
292 }
293 
294 //------------------------------------------------------------------
295 
296 SfxTabPage* __EXPORT ScHeaderPage::Create( Window* pParent, const SfxItemSet& rCoreSet )
297 {
298 	return ( new ScHeaderPage( pParent, rCoreSet ) );
299 }
300 
301 //------------------------------------------------------------------
302 
303 sal_uInt16* __EXPORT ScHeaderPage::GetRanges()
304 {
305 	return SvxHeaderPage::GetRanges();
306 }
307 
308 //==================================================================
309 // class ScFooterPage
310 //==================================================================
311 
312 ScFooterPage::ScFooterPage( Window* pParent, const SfxItemSet& rSet )
313 	: ScHFPage( pParent, RID_SVXPAGE_FOOTER, rSet, SID_ATTR_PAGE_FOOTERSET )
314 {
315 }
316 
317 //------------------------------------------------------------------
318 
319 SfxTabPage* __EXPORT ScFooterPage::Create( Window* pParent, const SfxItemSet& rCoreSet )
320 {
321 	return ( new ScFooterPage( pParent, rCoreSet ) );
322 }
323 
324 //------------------------------------------------------------------
325 
326 sal_uInt16* __EXPORT ScFooterPage::GetRanges()
327 {
328 	return SvxHeaderPage::GetRanges();
329 }
330 
331 
332 
333 
334