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 : }
82 :
83 0 : void ScHFPage::Reset( const SfxItemSet* rSet )
84 : {
85 0 : SvxHFPage::Reset( rSet );
86 0 : TurnOnHdl( 0 );
87 0 : }
88 :
89 0 : bool ScHFPage::FillItemSet( SfxItemSet* rOutSet )
90 : {
91 0 : bool bResult = SvxHFPage::FillItemSet( rOutSet );
92 :
93 0 : if ( nId == SID_ATTR_PAGE_HEADERSET )
94 : {
95 0 : rOutSet->Put( aDataSet.Get( ATTR_PAGE_HEADERLEFT ) );
96 0 : rOutSet->Put( aDataSet.Get( ATTR_PAGE_HEADERRIGHT ) );
97 : }
98 : else
99 : {
100 0 : rOutSet->Put( aDataSet.Get( ATTR_PAGE_FOOTERLEFT ) );
101 0 : rOutSet->Put( aDataSet.Get( ATTR_PAGE_FOOTERRIGHT ) );
102 : }
103 :
104 0 : return bResult;
105 : }
106 :
107 0 : void ScHFPage::ActivatePage( const SfxItemSet& rSet )
108 : {
109 0 : sal_uInt16 nPageWhich = GetWhich( SID_ATTR_PAGE );
110 : const SvxPageItem& rPageItem = static_cast<const SvxPageItem&>(
111 0 : rSet.Get(nPageWhich));
112 :
113 0 : nPageUsage = rPageItem.GetPageUsage();
114 :
115 0 : if ( pStyleDlg )
116 0 : aStrPageStyle = pStyleDlg->GetStyleSheet().GetName();
117 :
118 0 : aDataSet.Put( rSet.Get(ATTR_PAGE) );
119 :
120 0 : SvxHFPage::ActivatePage( rSet );
121 0 : }
122 :
123 0 : int ScHFPage::DeactivatePage( SfxItemSet* pSetP )
124 : {
125 0 : if ( LEAVE_PAGE == SvxHFPage::DeactivatePage( pSetP ) )
126 0 : if ( pSetP )
127 0 : FillItemSet( pSetP );
128 :
129 0 : return LEAVE_PAGE;
130 : }
131 :
132 0 : void ScHFPage::ActivatePage()
133 : {
134 0 : }
135 :
136 0 : void ScHFPage::DeactivatePage()
137 : {
138 0 : }
139 :
140 : // Handler:
141 :
142 0 : IMPL_LINK_NOARG(ScHFPage, TurnOnHdl)
143 : {
144 0 : SvxHFPage::TurnOnHdl( m_pTurnOnBox );
145 :
146 0 : if ( m_pTurnOnBox->IsChecked() )
147 0 : m_pBtnEdit->Enable();
148 : else
149 0 : m_pBtnEdit->Disable();
150 :
151 0 : return 0;
152 : }
153 :
154 0 : IMPL_LINK_NOARG(ScHFPage, BtnHdl)
155 : {
156 : // When the Edit-Dialog is directly called from the Button's Click-Handler,
157 : // the GrabFocus from the Edit-Dialog under OS/2 doesn't work.(Bug #41805#).
158 : // With the new StarView, this workaround should be again considered!
159 :
160 0 : Application::PostUserEvent( LINK( this, ScHFPage, HFEditHdl ) );
161 0 : return 0;
162 : }
163 :
164 0 : IMPL_LINK_NOARG(ScHFPage, HFEditHdl)
165 : {
166 0 : SfxViewShell* pViewSh = SfxViewShell::Current();
167 :
168 0 : if ( !pViewSh )
169 : {
170 : OSL_FAIL( "Current ViewShell not found." );
171 0 : return 0;
172 : }
173 :
174 0 : if ( m_pCntSharedBox->IsEnabled()
175 0 : && !m_pCntSharedBox->IsChecked() )
176 : {
177 0 : sal_uInt16 nResId = ( nId == SID_ATTR_PAGE_HEADERSET )
178 : ? RID_SCDLG_HFED_HEADER
179 0 : : RID_SCDLG_HFED_FOOTER;
180 :
181 0 : ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
182 : OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
183 :
184 : boost::scoped_ptr<SfxAbstractTabDialog> pDlg(pFact->CreateScHFEditDlg(
185 0 : pViewSh->GetViewFrame(), this, aDataSet, aStrPageStyle, nResId));
186 :
187 : OSL_ENSURE(pDlg, "Dialog create fail!");
188 0 : if ( pDlg->Execute() == RET_OK )
189 : {
190 0 : aDataSet.Put( *pDlg->GetOutputItemSet() );
191 0 : }
192 : }
193 : else
194 : {
195 0 : OUString aText;
196 0 : boost::scoped_ptr<SfxSingleTabDialog> pDlg(new SfxSingleTabDialog(this, aDataSet));
197 0 : const int nSettingsId = 42;
198 0 : bool bRightPage = m_pCntSharedBox->IsChecked()
199 0 : || ( SVX_PAGE_LEFT != SvxPageUsage(nPageUsage) );
200 :
201 0 : if ( nId == SID_ATTR_PAGE_HEADERSET )
202 : {
203 0 : aText = ScGlobal::GetRscString( STR_PAGEHEADER );
204 0 : if ( bRightPage )
205 0 : pDlg->SetTabPage( ScRightHeaderEditPage::Create( pDlg->get_content_area(), &aDataSet ), NULL, nSettingsId );
206 : else
207 0 : pDlg->SetTabPage( ScLeftHeaderEditPage::Create( pDlg->get_content_area(), &aDataSet ), NULL, nSettingsId );
208 : }
209 : else
210 : {
211 0 : aText = ScGlobal::GetRscString( STR_PAGEFOOTER );
212 0 : if ( bRightPage )
213 0 : pDlg->SetTabPage( ScRightFooterEditPage::Create( pDlg->get_content_area(), &aDataSet ), NULL, nSettingsId );
214 : else
215 0 : pDlg->SetTabPage( ScLeftFooterEditPage::Create( pDlg->get_content_area(), &aDataSet ), NULL, nSettingsId );
216 : }
217 :
218 0 : SvxNumType eNumType = static_cast<const SvxPageItem&>(aDataSet.Get(ATTR_PAGE)).GetNumType();
219 0 : static_cast<ScHFEditPage*>(pDlg->GetTabPage())->SetNumType(eNumType);
220 :
221 0 : aText += " (" + ScGlobal::GetRscString( STR_PAGESTYLE );
222 0 : aText += ": " + aStrPageStyle + ")";
223 :
224 0 : pDlg->SetText( aText );
225 :
226 0 : if ( pDlg->Execute() == RET_OK )
227 : {
228 0 : aDataSet.Put( *pDlg->GetOutputItemSet() );
229 0 : }
230 : }
231 :
232 0 : return 0;
233 : }
234 :
235 : // class ScHeaderPage
236 :
237 0 : ScHeaderPage::ScHeaderPage( vcl::Window* pParent, const SfxItemSet& rSet )
238 0 : : ScHFPage( pParent, rSet, SID_ATTR_PAGE_HEADERSET )
239 : {
240 0 : }
241 :
242 0 : SfxTabPage* ScHeaderPage::Create( vcl::Window* pParent, const SfxItemSet* rCoreSet )
243 : {
244 0 : return ( new ScHeaderPage( pParent, *rCoreSet ) );
245 : }
246 :
247 0 : const sal_uInt16* ScHeaderPage::GetRanges()
248 : {
249 0 : return SvxHeaderPage::GetRanges();
250 : }
251 :
252 : // class ScFooterPage
253 :
254 0 : ScFooterPage::ScFooterPage( vcl::Window* pParent, const SfxItemSet& rSet )
255 0 : : ScHFPage( pParent, rSet, SID_ATTR_PAGE_FOOTERSET )
256 : {
257 0 : }
258 :
259 0 : SfxTabPage* ScFooterPage::Create( vcl::Window* pParent, const SfxItemSet* rCoreSet )
260 : {
261 0 : return ( new ScFooterPage( pParent, *rCoreSet ) );
262 : }
263 :
264 0 : const sal_uInt16* ScFooterPage::GetRanges()
265 : {
266 0 : return SvxHeaderPage::GetRanges();
267 0 : }
268 :
269 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|