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