Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
21 : #undef SC_DLLIMPLEMENTATION
22 :
23 :
24 :
25 : #define _TPHF_CXX
26 : #include "scitems.hxx"
27 : #include <sfx2/basedlgs.hxx>
28 : #include <svl/style.hxx>
29 : #include <vcl/svapp.hxx>
30 : #include <vcl/msgbox.hxx>
31 :
32 : #include "tphf.hxx"
33 : #include "sc.hrc"
34 : #include "scabstdlg.hxx"
35 : #include "globstr.hrc"
36 : #include "tabvwsh.hxx"
37 : #include "viewdata.hxx"
38 : #include "document.hxx"
39 : #include "hfedtdlg.hxx"
40 : #include "styledlg.hxx"
41 : #include "scresid.hxx"
42 : #include "scuitphfedit.hxx"
43 : #undef _TPHF_CXX
44 :
45 :
46 : // class ScHFPage
47 :
48 :
49 0 : ScHFPage::ScHFPage( Window* pParent, const SfxItemSet& rSet, sal_uInt16 nSetId )
50 :
51 : : SvxHFPage ( pParent, rSet, nSetId ),
52 0 : aDataSet ( *rSet.GetPool(),
53 : ATTR_PAGE_HEADERLEFT, ATTR_PAGE_FOOTERRIGHT,
54 : ATTR_PAGE, ATTR_PAGE, 0 ),
55 : nPageUsage ( (sal_uInt16)SVX_PAGE_ALL ),
56 0 : pStyleDlg ( NULL )
57 : {
58 0 : get(m_pBtnEdit, "buttonEdit");
59 :
60 0 : SetExchangeSupport();
61 :
62 0 : SfxViewShell* pSh = SfxViewShell::Current();
63 0 : ScTabViewShell* pViewSh = PTR_CAST(ScTabViewShell,pSh);
64 0 : m_pBtnEdit->Show();
65 :
66 0 : aDataSet.Put( rSet );
67 :
68 0 : if ( pViewSh )
69 : {
70 0 : ScViewData* pViewData = pViewSh->GetViewData();
71 0 : ScDocument* pDoc = pViewData->GetDocument();
72 :
73 0 : aStrPageStyle = pDoc->GetPageStyle( pViewData->GetTabNo() );
74 : }
75 :
76 0 : m_pBtnEdit->SetClickHdl ( LINK( this, ScHFPage, BtnHdl ) );
77 0 : m_pTurnOnBox->SetClickHdl ( LINK( this, ScHFPage, TurnOnHdl ) );
78 :
79 0 : if ( nId == SID_ATTR_PAGE_HEADERSET )
80 0 : m_pBtnEdit->SetHelpId( HID_SC_HEADER_EDIT );
81 : else
82 0 : m_pBtnEdit->SetHelpId( HID_SC_FOOTER_EDIT );
83 0 : }
84 :
85 0 : ScHFPage::~ScHFPage()
86 : {
87 0 : }
88 :
89 0 : void ScHFPage::Reset( const SfxItemSet& rSet )
90 : {
91 0 : SvxHFPage::Reset( rSet );
92 0 : TurnOnHdl( 0 );
93 0 : }
94 :
95 0 : bool ScHFPage::FillItemSet( SfxItemSet& rOutSet )
96 : {
97 0 : sal_Bool bResult = SvxHFPage::FillItemSet( rOutSet );
98 :
99 0 : if ( nId == SID_ATTR_PAGE_HEADERSET )
100 : {
101 0 : rOutSet.Put( aDataSet.Get( ATTR_PAGE_HEADERLEFT ) );
102 0 : rOutSet.Put( aDataSet.Get( ATTR_PAGE_HEADERRIGHT ) );
103 : }
104 : else
105 : {
106 0 : rOutSet.Put( aDataSet.Get( ATTR_PAGE_FOOTERLEFT ) );
107 0 : rOutSet.Put( aDataSet.Get( ATTR_PAGE_FOOTERRIGHT ) );
108 : }
109 :
110 0 : return bResult;
111 : }
112 :
113 0 : void ScHFPage::ActivatePage( const SfxItemSet& rSet )
114 : {
115 0 : sal_uInt16 nPageWhich = GetWhich( SID_ATTR_PAGE );
116 : const SvxPageItem& rPageItem = (const SvxPageItem&)
117 0 : rSet.Get(nPageWhich);
118 :
119 0 : nPageUsage = rPageItem.GetPageUsage();
120 :
121 0 : if ( pStyleDlg )
122 0 : aStrPageStyle = pStyleDlg->GetStyleSheet().GetName();
123 :
124 0 : aDataSet.Put( rSet.Get(ATTR_PAGE) );
125 :
126 0 : SvxHFPage::ActivatePage( rSet );
127 0 : }
128 :
129 0 : int ScHFPage::DeactivatePage( SfxItemSet* pSetP )
130 : {
131 0 : if ( LEAVE_PAGE == SvxHFPage::DeactivatePage( pSetP ) )
132 0 : if ( pSetP )
133 0 : FillItemSet( *pSetP );
134 :
135 0 : return LEAVE_PAGE;
136 : }
137 :
138 0 : void ScHFPage::ActivatePage()
139 : {
140 0 : }
141 :
142 0 : void ScHFPage::DeactivatePage()
143 : {
144 0 : }
145 :
146 :
147 : // Handler:
148 :
149 :
150 0 : IMPL_LINK_NOARG(ScHFPage, TurnOnHdl)
151 : {
152 0 : SvxHFPage::TurnOnHdl( m_pTurnOnBox );
153 :
154 0 : if ( m_pTurnOnBox->IsChecked() )
155 0 : m_pBtnEdit->Enable();
156 : else
157 0 : m_pBtnEdit->Disable();
158 :
159 0 : return 0;
160 : }
161 :
162 :
163 0 : IMPL_LINK_NOARG(ScHFPage, BtnHdl)
164 : {
165 : // When the Edit-Dialog is directly called from the Button's Click-Handler,
166 : // the GrabFocus from the Edit-Dialog under OS/2 doesn't work.(Bug #41805#).
167 : // With the new StarView, this workaround should be again considered!
168 :
169 0 : Application::PostUserEvent( LINK( this, ScHFPage, HFEditHdl ) );
170 0 : return 0;
171 : }
172 :
173 0 : IMPL_LINK_NOARG(ScHFPage, HFEditHdl)
174 : {
175 0 : SfxViewShell* pViewSh = SfxViewShell::Current();
176 :
177 0 : if ( !pViewSh )
178 : {
179 : OSL_FAIL( "Current ViewShell not found." );
180 0 : return 0;
181 : }
182 :
183 0 : if ( m_pCntSharedBox->IsEnabled()
184 0 : && !m_pCntSharedBox->IsChecked() )
185 : {
186 0 : sal_uInt16 nResId = ( nId == SID_ATTR_PAGE_HEADERSET )
187 : ? RID_SCDLG_HFED_HEADER
188 0 : : RID_SCDLG_HFED_FOOTER;
189 :
190 :
191 0 : ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
192 : OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
193 :
194 : SfxAbstractTabDialog* pDlg = pFact->CreateScHFEditDlg(
195 0 : pViewSh->GetViewFrame(), this, aDataSet, aStrPageStyle, nResId);
196 :
197 : OSL_ENSURE(pDlg, "Dialog create fail!");
198 0 : if ( pDlg->Execute() == RET_OK )
199 : {
200 0 : aDataSet.Put( *pDlg->GetOutputItemSet() );
201 : }
202 :
203 0 : delete pDlg;
204 : }
205 : else
206 : {
207 0 : OUString aText;
208 0 : SfxSingleTabDialog* pDlg = new SfxSingleTabDialog(this, aDataSet);
209 0 : const int nSettingsId = 42;
210 0 : sal_Bool bRightPage = m_pCntSharedBox->IsChecked()
211 0 : || ( SVX_PAGE_LEFT != SvxPageUsage(nPageUsage) );
212 :
213 0 : if ( nId == SID_ATTR_PAGE_HEADERSET )
214 : {
215 0 : aText = ScGlobal::GetRscString( STR_PAGEHEADER );
216 0 : if ( bRightPage )
217 0 : pDlg->SetTabPage( ScRightHeaderEditPage::Create( pDlg->get_content_area(), aDataSet ), NULL, nSettingsId );
218 : else
219 0 : pDlg->SetTabPage( ScLeftHeaderEditPage::Create( pDlg->get_content_area(), aDataSet ), NULL, nSettingsId );
220 : }
221 : else
222 : {
223 0 : aText = ScGlobal::GetRscString( STR_PAGEFOOTER );
224 0 : if ( bRightPage )
225 0 : pDlg->SetTabPage( ScRightFooterEditPage::Create( pDlg->get_content_area(), aDataSet ), NULL, nSettingsId );
226 : else
227 0 : pDlg->SetTabPage( ScLeftFooterEditPage::Create( pDlg->get_content_area(), aDataSet ), NULL, nSettingsId );
228 : }
229 :
230 0 : SvxNumType eNumType = ((const SvxPageItem&)aDataSet.Get(ATTR_PAGE)).GetNumType();
231 0 : ((ScHFEditPage*)pDlg->GetTabPage())->SetNumType(eNumType);
232 :
233 0 : aText += " (" + ScGlobal::GetRscString( STR_PAGESTYLE );
234 0 : aText += ": " + aStrPageStyle + ")";
235 :
236 0 : pDlg->SetText( aText );
237 :
238 0 : if ( pDlg->Execute() == RET_OK )
239 : {
240 0 : aDataSet.Put( *pDlg->GetOutputItemSet() );
241 : }
242 :
243 0 : delete pDlg;
244 : }
245 :
246 0 : return 0;
247 : }
248 :
249 :
250 : // class ScHeaderPage
251 :
252 :
253 0 : ScHeaderPage::ScHeaderPage( Window* pParent, const SfxItemSet& rSet )
254 0 : : ScHFPage( pParent, rSet, SID_ATTR_PAGE_HEADERSET )
255 : {
256 0 : }
257 :
258 0 : SfxTabPage* ScHeaderPage::Create( Window* pParent, const SfxItemSet& rCoreSet )
259 : {
260 0 : return ( new ScHeaderPage( pParent, rCoreSet ) );
261 : }
262 :
263 0 : sal_uInt16* ScHeaderPage::GetRanges()
264 : {
265 0 : return SvxHeaderPage::GetRanges();
266 : }
267 :
268 :
269 : // class ScFooterPage
270 :
271 :
272 0 : ScFooterPage::ScFooterPage( Window* pParent, const SfxItemSet& rSet )
273 0 : : ScHFPage( pParent, rSet, SID_ATTR_PAGE_FOOTERSET )
274 : {
275 0 : }
276 :
277 0 : SfxTabPage* ScFooterPage::Create( Window* pParent, const SfxItemSet& rCoreSet )
278 : {
279 0 : return ( new ScFooterPage( pParent, rCoreSet ) );
280 : }
281 :
282 0 : sal_uInt16* ScFooterPage::GetRanges()
283 : {
284 0 : return SvxHeaderPage::GetRanges();
285 0 : }
286 :
287 :
288 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|