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