xref: /aoo41x/main/svx/source/form/fmmodel.cxx (revision c7be74b1)
1*f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f6e50924SAndrew Rist  * distributed with this work for additional information
6*f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9*f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*f6e50924SAndrew Rist  *
11*f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*f6e50924SAndrew Rist  *
13*f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15*f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17*f6e50924SAndrew Rist  * specific language governing permissions and limitations
18*f6e50924SAndrew Rist  * under the License.
19*f6e50924SAndrew Rist  *
20*f6e50924SAndrew Rist  *************************************************************/
21*f6e50924SAndrew Rist 
22*f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "fmundo.hxx"
28cdf0e10cSrcweir #include "fmdocumentclassification.hxx"
29cdf0e10cSrcweir #include "fmcontrollayout.hxx"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <svx/fmmodel.hxx>
32cdf0e10cSrcweir #include <svx/fmpage.hxx>
33cdf0e10cSrcweir #include <svx/svdobj.hxx>
34cdf0e10cSrcweir #include <tools/debug.hxx>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #ifndef SVX_LIGHT
37cdf0e10cSrcweir #include <sfx2/objsh.hxx>
38cdf0e10cSrcweir #else
39cdf0e10cSrcweir class SfxObjectShell;
40cdf0e10cSrcweir #endif
41cdf0e10cSrcweir 
42cdf0e10cSrcweir #include <boost/optional.hpp>
43cdf0e10cSrcweir 
44cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
45cdf0e10cSrcweir using ::com::sun::star::container::XNameContainer;
46cdf0e10cSrcweir using namespace svxform;
47cdf0e10cSrcweir 
48cdf0e10cSrcweir TYPEINIT1(FmFormModel, SdrModel);
49cdf0e10cSrcweir 
50cdf0e10cSrcweir struct FmFormModelImplData
51cdf0e10cSrcweir {
52cdf0e10cSrcweir 	FmXUndoEnvironment*		pUndoEnv;
53cdf0e10cSrcweir 	sal_Bool				bOpenInDesignIsDefaulted;
54cdf0e10cSrcweir 	sal_Bool				bMovingPage;
55cdf0e10cSrcweir     ::boost::optional< sal_Bool >
56cdf0e10cSrcweir                             aControlsUseRefDevice;
57cdf0e10cSrcweir 
FmFormModelImplDataFmFormModelImplData58cdf0e10cSrcweir 	FmFormModelImplData()
59cdf0e10cSrcweir 		:pUndoEnv( NULL )
60cdf0e10cSrcweir 		,bOpenInDesignIsDefaulted( sal_True )
61cdf0e10cSrcweir 		,bMovingPage( sal_False )
62cdf0e10cSrcweir         ,aControlsUseRefDevice()
63cdf0e10cSrcweir 	{
64cdf0e10cSrcweir 	}
65cdf0e10cSrcweir };
66cdf0e10cSrcweir 
67cdf0e10cSrcweir /*************************************************************************
68cdf0e10cSrcweir |*
69cdf0e10cSrcweir |* Ctor
70cdf0e10cSrcweir |*
71cdf0e10cSrcweir \************************************************************************/
FmFormModel(SfxItemPool * pPool,SfxObjectShell * pPers)72cdf0e10cSrcweir FmFormModel::FmFormModel(SfxItemPool* pPool, SfxObjectShell* pPers)
73cdf0e10cSrcweir 			:SdrModel(pPool, pPers, LOADREFCOUNTS)
74cdf0e10cSrcweir 			,m_pImpl(NULL)
75cdf0e10cSrcweir 			,m_pObjShell(0)
76cdf0e10cSrcweir 			,m_bOpenInDesignMode(sal_False)
77cdf0e10cSrcweir 			,m_bAutoControlFocus(sal_False)
78cdf0e10cSrcweir {
79cdf0e10cSrcweir #ifndef SVX_LIGHT
80cdf0e10cSrcweir 	m_pImpl = new FmFormModelImplData;
81cdf0e10cSrcweir 	m_pImpl->pUndoEnv = new FmXUndoEnvironment(*this);
82cdf0e10cSrcweir 	m_pImpl->pUndoEnv->acquire();
83cdf0e10cSrcweir #endif
84cdf0e10cSrcweir }
85cdf0e10cSrcweir 
86cdf0e10cSrcweir /*************************************************************************
87cdf0e10cSrcweir |*
88cdf0e10cSrcweir |* Ctor
89cdf0e10cSrcweir |*
90cdf0e10cSrcweir \************************************************************************/
FmFormModel(const XubString & rPath,SfxItemPool * pPool,SfxObjectShell * pPers)91cdf0e10cSrcweir FmFormModel::FmFormModel(const XubString& rPath, SfxItemPool* pPool, SfxObjectShell* pPers)
92cdf0e10cSrcweir 			:SdrModel(rPath, pPool, pPers)
93cdf0e10cSrcweir 			,m_pImpl(NULL)
94cdf0e10cSrcweir 			,m_pObjShell(0)
95cdf0e10cSrcweir 			,m_bOpenInDesignMode(sal_False)
96cdf0e10cSrcweir 			,m_bAutoControlFocus(sal_False)
97cdf0e10cSrcweir {
98cdf0e10cSrcweir #ifndef SVX_LIGHT
99cdf0e10cSrcweir 	m_pImpl = new FmFormModelImplData;
100cdf0e10cSrcweir 	m_pImpl->pUndoEnv = new FmXUndoEnvironment(*this);
101cdf0e10cSrcweir 	m_pImpl->pUndoEnv->acquire();
102cdf0e10cSrcweir #endif
103cdf0e10cSrcweir }
104cdf0e10cSrcweir 
105cdf0e10cSrcweir /*************************************************************************
106cdf0e10cSrcweir |*
107cdf0e10cSrcweir |* Dtor
108cdf0e10cSrcweir |*
109cdf0e10cSrcweir \************************************************************************/
~FmFormModel()110cdf0e10cSrcweir FmFormModel::~FmFormModel()
111cdf0e10cSrcweir {
112cdf0e10cSrcweir #ifndef SVX_LIGHT
113cdf0e10cSrcweir 	if (m_pObjShell && m_pImpl->pUndoEnv->IsListening(*m_pObjShell))
114cdf0e10cSrcweir 		SetObjectShell(NULL);
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 	ClearUndoBuffer();
117cdf0e10cSrcweir 	// minimale grenze fuer undos
118cdf0e10cSrcweir 	SetMaxUndoActionCount(1);
119cdf0e10cSrcweir 
120cdf0e10cSrcweir 	m_pImpl->pUndoEnv->release();
121cdf0e10cSrcweir 	delete m_pImpl;
122cdf0e10cSrcweir 
123cdf0e10cSrcweir #endif
124cdf0e10cSrcweir }
125cdf0e10cSrcweir 
126cdf0e10cSrcweir /*************************************************************************
127cdf0e10cSrcweir |*
128cdf0e10cSrcweir |* Erzeugt eine neue Seite
129cdf0e10cSrcweir |*
130cdf0e10cSrcweir \************************************************************************/
AllocPage(FASTBOOL bMasterPage)131cdf0e10cSrcweir SdrPage* FmFormModel::AllocPage(FASTBOOL bMasterPage)
132cdf0e10cSrcweir {
133cdf0e10cSrcweir 	return new FmFormPage(*this, NULL, bMasterPage);
134cdf0e10cSrcweir }
135cdf0e10cSrcweir 
136cdf0e10cSrcweir /*************************************************************************
137cdf0e10cSrcweir |*
138cdf0e10cSrcweir |* InsertPage
139cdf0e10cSrcweir |*
140cdf0e10cSrcweir \************************************************************************/
InsertPage(SdrPage * pPage,sal_uInt16 nPos)141cdf0e10cSrcweir void FmFormModel::InsertPage(SdrPage* pPage, sal_uInt16 nPos)
142cdf0e10cSrcweir {
143cdf0e10cSrcweir #ifndef SVX_LIGHT
144cdf0e10cSrcweir 	// hack solange Methode intern
145cdf0e10cSrcweir 	if (m_pObjShell && !m_pImpl->pUndoEnv->IsListening( *m_pObjShell ))
146cdf0e10cSrcweir 		SetObjectShell(m_pObjShell);
147cdf0e10cSrcweir #endif
148cdf0e10cSrcweir 
149cdf0e10cSrcweir 	SdrModel::InsertPage( pPage, nPos );
150cdf0e10cSrcweir }
151cdf0e10cSrcweir 
152cdf0e10cSrcweir /*************************************************************************
153cdf0e10cSrcweir |*
154cdf0e10cSrcweir |* MovePage
155cdf0e10cSrcweir |*
156cdf0e10cSrcweir \************************************************************************/
MovePage(sal_uInt16 nPgNum,sal_uInt16 nNewPos)157cdf0e10cSrcweir void FmFormModel::MovePage( sal_uInt16 nPgNum, sal_uInt16 nNewPos )
158cdf0e10cSrcweir {
159cdf0e10cSrcweir #ifndef SVX_LIGHT
160cdf0e10cSrcweir 	m_pImpl->bMovingPage = sal_True;
161cdf0e10cSrcweir 		// see InsertPage for this
162cdf0e10cSrcweir #endif
163cdf0e10cSrcweir 
164cdf0e10cSrcweir 	SdrModel::MovePage( nPgNum, nNewPos );
165cdf0e10cSrcweir 
166cdf0e10cSrcweir #ifndef SVX_LIGHT
167cdf0e10cSrcweir 	m_pImpl->bMovingPage = sal_False;
168cdf0e10cSrcweir #endif
169cdf0e10cSrcweir }
170cdf0e10cSrcweir 
171cdf0e10cSrcweir /*************************************************************************
172cdf0e10cSrcweir |*
173cdf0e10cSrcweir |* RemovePage
174cdf0e10cSrcweir |*
175cdf0e10cSrcweir \************************************************************************/
RemovePage(sal_uInt16 nPgNum)176cdf0e10cSrcweir SdrPage* FmFormModel::RemovePage(sal_uInt16 nPgNum)
177cdf0e10cSrcweir {
178cdf0e10cSrcweir     FmFormPage* pToBeRemovedPage = dynamic_cast< FmFormPage* >( GetPage( nPgNum ) );
179cdf0e10cSrcweir     OSL_ENSURE( pToBeRemovedPage, "FmFormModel::RemovePage: *which page*?" );
180cdf0e10cSrcweir 
181cdf0e10cSrcweir #ifndef SVX_LIGHT
182cdf0e10cSrcweir     if ( pToBeRemovedPage )
183cdf0e10cSrcweir     {
184cdf0e10cSrcweir         Reference< XNameContainer > xForms( pToBeRemovedPage->GetForms( false ) );
185cdf0e10cSrcweir         if ( xForms.is() )
186cdf0e10cSrcweir             m_pImpl->pUndoEnv->RemoveForms( xForms );
187cdf0e10cSrcweir     }
188cdf0e10cSrcweir #endif
189cdf0e10cSrcweir 
190cdf0e10cSrcweir     FmFormPage* pRemovedPage = (FmFormPage*)SdrModel::RemovePage(nPgNum);
191cdf0e10cSrcweir     OSL_ENSURE( pRemovedPage == pToBeRemovedPage, "FmFormModel::RemovePage: inconsistency!" );
192cdf0e10cSrcweir     return pRemovedPage;
193cdf0e10cSrcweir }
194cdf0e10cSrcweir 
195cdf0e10cSrcweir /*************************************************************************
196cdf0e10cSrcweir |*
197cdf0e10cSrcweir |* InsertMasterPage
198cdf0e10cSrcweir |*
199cdf0e10cSrcweir \************************************************************************/
InsertMasterPage(SdrPage * pPage,sal_uInt16 nPos)200cdf0e10cSrcweir void FmFormModel::InsertMasterPage(SdrPage* pPage, sal_uInt16 nPos)
201cdf0e10cSrcweir {
202cdf0e10cSrcweir #ifndef SVX_LIGHT
203cdf0e10cSrcweir 	// hack solange Methode intern
204cdf0e10cSrcweir 	if (m_pObjShell && !m_pImpl->pUndoEnv->IsListening( *m_pObjShell ))
205cdf0e10cSrcweir 		SetObjectShell(m_pObjShell);
206cdf0e10cSrcweir #endif
207cdf0e10cSrcweir 
208cdf0e10cSrcweir 	SdrModel::InsertMasterPage(pPage, nPos);
209cdf0e10cSrcweir }
210cdf0e10cSrcweir 
211cdf0e10cSrcweir /*************************************************************************
212cdf0e10cSrcweir |*
213cdf0e10cSrcweir |* RemoveMasterPage
214cdf0e10cSrcweir |*
215cdf0e10cSrcweir \************************************************************************/
RemoveMasterPage(sal_uInt16 nPgNum)216cdf0e10cSrcweir SdrPage* FmFormModel::RemoveMasterPage(sal_uInt16 nPgNum)
217cdf0e10cSrcweir {
218cdf0e10cSrcweir 	FmFormPage* pPage = (FmFormPage*)SdrModel::RemoveMasterPage(nPgNum);
219cdf0e10cSrcweir 
220cdf0e10cSrcweir #ifndef SVX_LIGHT
221cdf0e10cSrcweir 	if ( pPage )
222cdf0e10cSrcweir     {
223cdf0e10cSrcweir         Reference< XNameContainer > xForms( pPage->GetForms( false ) );
224cdf0e10cSrcweir         if ( xForms.is() )
225cdf0e10cSrcweir 		    m_pImpl->pUndoEnv->RemoveForms( xForms );
226cdf0e10cSrcweir     }
227cdf0e10cSrcweir #endif
228cdf0e10cSrcweir 
229cdf0e10cSrcweir 	return pPage;
230cdf0e10cSrcweir }
231cdf0e10cSrcweir 
232cdf0e10cSrcweir //------------------------------------------------------------------------
GetControlExportLayerId(const SdrObject & rObj) const233cdf0e10cSrcweir SdrLayerID FmFormModel::GetControlExportLayerId( const SdrObject& rObj ) const
234cdf0e10cSrcweir {
235cdf0e10cSrcweir 	return rObj.GetLayer();
236cdf0e10cSrcweir }
237cdf0e10cSrcweir 
238cdf0e10cSrcweir //------------------------------------------------------------------------
implSetOpenInDesignMode(sal_Bool _bOpenDesignMode,sal_Bool _bForce)239cdf0e10cSrcweir void FmFormModel::implSetOpenInDesignMode( sal_Bool _bOpenDesignMode, sal_Bool _bForce )
240cdf0e10cSrcweir {
241cdf0e10cSrcweir 	if( ( _bOpenDesignMode != m_bOpenInDesignMode ) || _bForce )
242cdf0e10cSrcweir 	{
243cdf0e10cSrcweir 		m_bOpenInDesignMode = _bOpenDesignMode;
244cdf0e10cSrcweir 
245cdf0e10cSrcweir 		if ( m_pObjShell )
246cdf0e10cSrcweir 			m_pObjShell->SetModified( sal_True );
247cdf0e10cSrcweir 	}
248cdf0e10cSrcweir 	// no matter if we really did it or not - from now on, it does not count as defaulted anymore
249cdf0e10cSrcweir 	m_pImpl->bOpenInDesignIsDefaulted = sal_False;
250cdf0e10cSrcweir }
251cdf0e10cSrcweir 
252cdf0e10cSrcweir //------------------------------------------------------------------------
SetOpenInDesignMode(sal_Bool bOpenDesignMode)253cdf0e10cSrcweir void FmFormModel::SetOpenInDesignMode( sal_Bool bOpenDesignMode )
254cdf0e10cSrcweir {
255cdf0e10cSrcweir #ifndef SVX_LIGHT
256cdf0e10cSrcweir 	implSetOpenInDesignMode( bOpenDesignMode, sal_False );
257cdf0e10cSrcweir #endif
258cdf0e10cSrcweir }
259cdf0e10cSrcweir 
260cdf0e10cSrcweir #ifndef SVX_LIGHT
261cdf0e10cSrcweir //------------------------------------------------------------------------
OpenInDesignModeIsDefaulted()262cdf0e10cSrcweir sal_Bool FmFormModel::OpenInDesignModeIsDefaulted( )
263cdf0e10cSrcweir {
264cdf0e10cSrcweir 	return m_pImpl->bOpenInDesignIsDefaulted;
265cdf0e10cSrcweir }
266cdf0e10cSrcweir #endif
267cdf0e10cSrcweir 
268cdf0e10cSrcweir //------------------------------------------------------------------------
ControlsUseRefDevice() const269cdf0e10cSrcweir sal_Bool FmFormModel::ControlsUseRefDevice() const
270cdf0e10cSrcweir {
271cdf0e10cSrcweir     if ( !m_pImpl->aControlsUseRefDevice )
272cdf0e10cSrcweir     {
273cdf0e10cSrcweir         DocumentType eDocType = eUnknownDocumentType;
274cdf0e10cSrcweir         if ( m_pObjShell )
275cdf0e10cSrcweir             eDocType = DocumentClassification::classifyHostDocument( m_pObjShell->GetModel() );
276cdf0e10cSrcweir         m_pImpl->aControlsUseRefDevice.reset( ControlLayouter::useDocumentReferenceDevice( eDocType ) );
277cdf0e10cSrcweir     }
278cdf0e10cSrcweir     return *m_pImpl->aControlsUseRefDevice;
279cdf0e10cSrcweir }
280cdf0e10cSrcweir 
281cdf0e10cSrcweir //------------------------------------------------------------------------
SetAutoControlFocus(sal_Bool _bAutoControlFocus)282cdf0e10cSrcweir void FmFormModel::SetAutoControlFocus( sal_Bool _bAutoControlFocus )
283cdf0e10cSrcweir {
284cdf0e10cSrcweir #ifndef SVX_LIGHT
285cdf0e10cSrcweir 	if( _bAutoControlFocus != m_bAutoControlFocus )
286cdf0e10cSrcweir 	{
287cdf0e10cSrcweir 		m_bAutoControlFocus = _bAutoControlFocus;
288cdf0e10cSrcweir 		m_pObjShell->SetModified( sal_True );
289cdf0e10cSrcweir 	}
290cdf0e10cSrcweir #endif
291cdf0e10cSrcweir }
292cdf0e10cSrcweir 
293cdf0e10cSrcweir //------------------------------------------------------------------------
SetObjectShell(SfxObjectShell * pShell)294cdf0e10cSrcweir void FmFormModel::SetObjectShell( SfxObjectShell* pShell )
295cdf0e10cSrcweir {
296cdf0e10cSrcweir #ifndef SVX_LIGHT
297cdf0e10cSrcweir 	if (pShell == m_pObjShell)
298cdf0e10cSrcweir 		return;
299cdf0e10cSrcweir 
300cdf0e10cSrcweir 	if (m_pObjShell)
301cdf0e10cSrcweir 	{
302cdf0e10cSrcweir 		m_pImpl->pUndoEnv->EndListening( *this );
303cdf0e10cSrcweir 		m_pImpl->pUndoEnv->EndListening( *m_pObjShell );
304cdf0e10cSrcweir 	}
305cdf0e10cSrcweir 
306cdf0e10cSrcweir 	m_pObjShell = pShell;
307cdf0e10cSrcweir 
308cdf0e10cSrcweir 	if (m_pObjShell)
309cdf0e10cSrcweir 	{
310cdf0e10cSrcweir         m_pImpl->pUndoEnv->SetReadOnly( m_pObjShell->IsReadOnly() || m_pObjShell->IsReadOnlyUI(), FmXUndoEnvironment::Accessor() );
311cdf0e10cSrcweir 
312cdf0e10cSrcweir 		if (!m_pImpl->pUndoEnv->IsReadOnly())
313cdf0e10cSrcweir 			 m_pImpl->pUndoEnv->StartListening(*this);
314cdf0e10cSrcweir 
315cdf0e10cSrcweir 		m_pImpl->pUndoEnv->StartListening( *m_pObjShell );
316cdf0e10cSrcweir 	}
317cdf0e10cSrcweir #endif
318cdf0e10cSrcweir }
319cdf0e10cSrcweir 
320cdf0e10cSrcweir //------------------------------------------------------------------------
GetUndoEnv()321cdf0e10cSrcweir FmXUndoEnvironment&	FmFormModel::GetUndoEnv()
322cdf0e10cSrcweir {
323cdf0e10cSrcweir 	return *m_pImpl->pUndoEnv;
324cdf0e10cSrcweir }
325