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