xref: /aoo42x/main/svx/source/form/fmmodel.cxx (revision f6e50924)
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 
58cdf0e10cSrcweir 	FmFormModelImplData()
59cdf0e10cSrcweir 		:pUndoEnv( NULL )
60cdf0e10cSrcweir 		,bOpenInDesignIsDefaulted( sal_True )
61cdf0e10cSrcweir 		,bMovingPage( sal_False )
62cdf0e10cSrcweir         ,aControlsUseRefDevice()
63cdf0e10cSrcweir 	{
64cdf0e10cSrcweir 	}
65cdf0e10cSrcweir };
66cdf0e10cSrcweir 
67cdf0e10cSrcweir /*************************************************************************
68cdf0e10cSrcweir |*
69cdf0e10cSrcweir |* Ctor
70cdf0e10cSrcweir |*
71cdf0e10cSrcweir \************************************************************************/
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 \************************************************************************/
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 |* Ctor
108cdf0e10cSrcweir |*
109cdf0e10cSrcweir \************************************************************************/
110cdf0e10cSrcweir FmFormModel::FmFormModel(SfxItemPool* pPool, SfxObjectShell* pPers,
111cdf0e10cSrcweir 						 FASTBOOL bUseExtColorTable
112cdf0e10cSrcweir 						 )
113cdf0e10cSrcweir 			:SdrModel(pPool, pPers, bUseExtColorTable, LOADREFCOUNTS)
114cdf0e10cSrcweir 			,m_pImpl(NULL)
115cdf0e10cSrcweir 			,m_pObjShell(0)
116cdf0e10cSrcweir 			,m_bOpenInDesignMode(sal_False)
117cdf0e10cSrcweir 			,m_bAutoControlFocus(sal_False)
118cdf0e10cSrcweir {
119cdf0e10cSrcweir #ifndef SVX_LIGHT
120cdf0e10cSrcweir 	m_pImpl = new FmFormModelImplData;
121cdf0e10cSrcweir 	m_pImpl->pUndoEnv = new FmXUndoEnvironment(*this);
122cdf0e10cSrcweir 	m_pImpl->pUndoEnv->acquire();
123cdf0e10cSrcweir #endif
124cdf0e10cSrcweir }
125cdf0e10cSrcweir 
126cdf0e10cSrcweir /*************************************************************************
127cdf0e10cSrcweir |*
128cdf0e10cSrcweir |* Ctor
129cdf0e10cSrcweir |*
130cdf0e10cSrcweir \************************************************************************/
131cdf0e10cSrcweir FmFormModel::FmFormModel(const XubString& rPath, SfxItemPool* pPool, SfxObjectShell* pPers,
132cdf0e10cSrcweir 						 FASTBOOL bUseExtColorTable)
133cdf0e10cSrcweir 			:SdrModel(rPath, pPool, pPers, bUseExtColorTable, LOADREFCOUNTS)
134cdf0e10cSrcweir             ,m_pImpl( NULL )
135cdf0e10cSrcweir 			,m_pObjShell(0)
136cdf0e10cSrcweir 			,m_bOpenInDesignMode(sal_False)
137cdf0e10cSrcweir 			,m_bAutoControlFocus(sal_False)
138cdf0e10cSrcweir {
139cdf0e10cSrcweir #ifndef SVX_LIGHT
140cdf0e10cSrcweir 	m_pImpl = new FmFormModelImplData;
141cdf0e10cSrcweir 	m_pImpl->pUndoEnv = new FmXUndoEnvironment(*this);
142cdf0e10cSrcweir 	m_pImpl->pUndoEnv->acquire();
143cdf0e10cSrcweir #endif
144cdf0e10cSrcweir }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir /*************************************************************************
147cdf0e10cSrcweir |*
148cdf0e10cSrcweir |* Dtor
149cdf0e10cSrcweir |*
150cdf0e10cSrcweir \************************************************************************/
151cdf0e10cSrcweir FmFormModel::~FmFormModel()
152cdf0e10cSrcweir {
153cdf0e10cSrcweir #ifndef SVX_LIGHT
154cdf0e10cSrcweir 	if (m_pObjShell && m_pImpl->pUndoEnv->IsListening(*m_pObjShell))
155cdf0e10cSrcweir 		SetObjectShell(NULL);
156cdf0e10cSrcweir 
157cdf0e10cSrcweir 	ClearUndoBuffer();
158cdf0e10cSrcweir 	// minimale grenze fuer undos
159cdf0e10cSrcweir 	SetMaxUndoActionCount(1);
160cdf0e10cSrcweir 
161cdf0e10cSrcweir 	m_pImpl->pUndoEnv->release();
162cdf0e10cSrcweir 	delete m_pImpl;
163cdf0e10cSrcweir 
164cdf0e10cSrcweir #endif
165cdf0e10cSrcweir }
166cdf0e10cSrcweir 
167cdf0e10cSrcweir /*************************************************************************
168cdf0e10cSrcweir |*
169cdf0e10cSrcweir |* Erzeugt eine neue Seite
170cdf0e10cSrcweir |*
171cdf0e10cSrcweir \************************************************************************/
172cdf0e10cSrcweir SdrPage* FmFormModel::AllocPage(FASTBOOL bMasterPage)
173cdf0e10cSrcweir {
174cdf0e10cSrcweir 	return new FmFormPage(*this, NULL, bMasterPage);
175cdf0e10cSrcweir }
176cdf0e10cSrcweir 
177cdf0e10cSrcweir /*************************************************************************
178cdf0e10cSrcweir |*
179cdf0e10cSrcweir |* InsertPage
180cdf0e10cSrcweir |*
181cdf0e10cSrcweir \************************************************************************/
182cdf0e10cSrcweir void FmFormModel::InsertPage(SdrPage* pPage, sal_uInt16 nPos)
183cdf0e10cSrcweir {
184cdf0e10cSrcweir #ifndef SVX_LIGHT
185cdf0e10cSrcweir 	// hack solange Methode intern
186cdf0e10cSrcweir 	if (m_pObjShell && !m_pImpl->pUndoEnv->IsListening( *m_pObjShell ))
187cdf0e10cSrcweir 		SetObjectShell(m_pObjShell);
188cdf0e10cSrcweir #endif
189cdf0e10cSrcweir 
190cdf0e10cSrcweir 	SdrModel::InsertPage( pPage, nPos );
191cdf0e10cSrcweir }
192cdf0e10cSrcweir 
193cdf0e10cSrcweir /*************************************************************************
194cdf0e10cSrcweir |*
195cdf0e10cSrcweir |* MovePage
196cdf0e10cSrcweir |*
197cdf0e10cSrcweir \************************************************************************/
198cdf0e10cSrcweir void FmFormModel::MovePage( sal_uInt16 nPgNum, sal_uInt16 nNewPos )
199cdf0e10cSrcweir {
200cdf0e10cSrcweir #ifndef SVX_LIGHT
201cdf0e10cSrcweir 	m_pImpl->bMovingPage = sal_True;
202cdf0e10cSrcweir 		// see InsertPage for this
203cdf0e10cSrcweir #endif
204cdf0e10cSrcweir 
205cdf0e10cSrcweir 	SdrModel::MovePage( nPgNum, nNewPos );
206cdf0e10cSrcweir 
207cdf0e10cSrcweir #ifndef SVX_LIGHT
208cdf0e10cSrcweir 	m_pImpl->bMovingPage = sal_False;
209cdf0e10cSrcweir #endif
210cdf0e10cSrcweir }
211cdf0e10cSrcweir 
212cdf0e10cSrcweir /*************************************************************************
213cdf0e10cSrcweir |*
214cdf0e10cSrcweir |* RemovePage
215cdf0e10cSrcweir |*
216cdf0e10cSrcweir \************************************************************************/
217cdf0e10cSrcweir SdrPage* FmFormModel::RemovePage(sal_uInt16 nPgNum)
218cdf0e10cSrcweir {
219cdf0e10cSrcweir     FmFormPage* pToBeRemovedPage = dynamic_cast< FmFormPage* >( GetPage( nPgNum ) );
220cdf0e10cSrcweir     OSL_ENSURE( pToBeRemovedPage, "FmFormModel::RemovePage: *which page*?" );
221cdf0e10cSrcweir 
222cdf0e10cSrcweir #ifndef SVX_LIGHT
223cdf0e10cSrcweir     if ( pToBeRemovedPage )
224cdf0e10cSrcweir     {
225cdf0e10cSrcweir         Reference< XNameContainer > xForms( pToBeRemovedPage->GetForms( false ) );
226cdf0e10cSrcweir         if ( xForms.is() )
227cdf0e10cSrcweir             m_pImpl->pUndoEnv->RemoveForms( xForms );
228cdf0e10cSrcweir     }
229cdf0e10cSrcweir #endif
230cdf0e10cSrcweir 
231cdf0e10cSrcweir     FmFormPage* pRemovedPage = (FmFormPage*)SdrModel::RemovePage(nPgNum);
232cdf0e10cSrcweir     OSL_ENSURE( pRemovedPage == pToBeRemovedPage, "FmFormModel::RemovePage: inconsistency!" );
233cdf0e10cSrcweir     return pRemovedPage;
234cdf0e10cSrcweir }
235cdf0e10cSrcweir 
236cdf0e10cSrcweir /*************************************************************************
237cdf0e10cSrcweir |*
238cdf0e10cSrcweir |* InsertMasterPage
239cdf0e10cSrcweir |*
240cdf0e10cSrcweir \************************************************************************/
241cdf0e10cSrcweir void FmFormModel::InsertMasterPage(SdrPage* pPage, sal_uInt16 nPos)
242cdf0e10cSrcweir {
243cdf0e10cSrcweir #ifndef SVX_LIGHT
244cdf0e10cSrcweir 	// hack solange Methode intern
245cdf0e10cSrcweir 	if (m_pObjShell && !m_pImpl->pUndoEnv->IsListening( *m_pObjShell ))
246cdf0e10cSrcweir 		SetObjectShell(m_pObjShell);
247cdf0e10cSrcweir #endif
248cdf0e10cSrcweir 
249cdf0e10cSrcweir 	SdrModel::InsertMasterPage(pPage, nPos);
250cdf0e10cSrcweir }
251cdf0e10cSrcweir 
252cdf0e10cSrcweir /*************************************************************************
253cdf0e10cSrcweir |*
254cdf0e10cSrcweir |* RemoveMasterPage
255cdf0e10cSrcweir |*
256cdf0e10cSrcweir \************************************************************************/
257cdf0e10cSrcweir SdrPage* FmFormModel::RemoveMasterPage(sal_uInt16 nPgNum)
258cdf0e10cSrcweir {
259cdf0e10cSrcweir 	FmFormPage* pPage = (FmFormPage*)SdrModel::RemoveMasterPage(nPgNum);
260cdf0e10cSrcweir 
261cdf0e10cSrcweir #ifndef SVX_LIGHT
262cdf0e10cSrcweir 	if ( pPage )
263cdf0e10cSrcweir     {
264cdf0e10cSrcweir         Reference< XNameContainer > xForms( pPage->GetForms( false ) );
265cdf0e10cSrcweir         if ( xForms.is() )
266cdf0e10cSrcweir 		    m_pImpl->pUndoEnv->RemoveForms( xForms );
267cdf0e10cSrcweir     }
268cdf0e10cSrcweir #endif
269cdf0e10cSrcweir 
270cdf0e10cSrcweir 	return pPage;
271cdf0e10cSrcweir }
272cdf0e10cSrcweir 
273cdf0e10cSrcweir //------------------------------------------------------------------------
274cdf0e10cSrcweir SdrLayerID FmFormModel::GetControlExportLayerId( const SdrObject& rObj ) const
275cdf0e10cSrcweir {
276cdf0e10cSrcweir 	return rObj.GetLayer();
277cdf0e10cSrcweir }
278cdf0e10cSrcweir 
279cdf0e10cSrcweir //------------------------------------------------------------------------
280cdf0e10cSrcweir void FmFormModel::implSetOpenInDesignMode( sal_Bool _bOpenDesignMode, sal_Bool _bForce )
281cdf0e10cSrcweir {
282cdf0e10cSrcweir 	if( ( _bOpenDesignMode != m_bOpenInDesignMode ) || _bForce )
283cdf0e10cSrcweir 	{
284cdf0e10cSrcweir 		m_bOpenInDesignMode = _bOpenDesignMode;
285cdf0e10cSrcweir 
286cdf0e10cSrcweir 		if ( m_pObjShell )
287cdf0e10cSrcweir 			m_pObjShell->SetModified( sal_True );
288cdf0e10cSrcweir 	}
289cdf0e10cSrcweir 	// no matter if we really did it or not - from now on, it does not count as defaulted anymore
290cdf0e10cSrcweir 	m_pImpl->bOpenInDesignIsDefaulted = sal_False;
291cdf0e10cSrcweir }
292cdf0e10cSrcweir 
293cdf0e10cSrcweir //------------------------------------------------------------------------
294cdf0e10cSrcweir void FmFormModel::SetOpenInDesignMode( sal_Bool bOpenDesignMode )
295cdf0e10cSrcweir {
296cdf0e10cSrcweir #ifndef SVX_LIGHT
297cdf0e10cSrcweir 	implSetOpenInDesignMode( bOpenDesignMode, sal_False );
298cdf0e10cSrcweir #endif
299cdf0e10cSrcweir }
300cdf0e10cSrcweir 
301cdf0e10cSrcweir #ifndef SVX_LIGHT
302cdf0e10cSrcweir //------------------------------------------------------------------------
303cdf0e10cSrcweir sal_Bool FmFormModel::OpenInDesignModeIsDefaulted( )
304cdf0e10cSrcweir {
305cdf0e10cSrcweir 	return m_pImpl->bOpenInDesignIsDefaulted;
306cdf0e10cSrcweir }
307cdf0e10cSrcweir #endif
308cdf0e10cSrcweir 
309cdf0e10cSrcweir //------------------------------------------------------------------------
310cdf0e10cSrcweir sal_Bool FmFormModel::ControlsUseRefDevice() const
311cdf0e10cSrcweir {
312cdf0e10cSrcweir     if ( !m_pImpl->aControlsUseRefDevice )
313cdf0e10cSrcweir     {
314cdf0e10cSrcweir         DocumentType eDocType = eUnknownDocumentType;
315cdf0e10cSrcweir         if ( m_pObjShell )
316cdf0e10cSrcweir             eDocType = DocumentClassification::classifyHostDocument( m_pObjShell->GetModel() );
317cdf0e10cSrcweir         m_pImpl->aControlsUseRefDevice.reset( ControlLayouter::useDocumentReferenceDevice( eDocType ) );
318cdf0e10cSrcweir     }
319cdf0e10cSrcweir     return *m_pImpl->aControlsUseRefDevice;
320cdf0e10cSrcweir }
321cdf0e10cSrcweir 
322cdf0e10cSrcweir //------------------------------------------------------------------------
323cdf0e10cSrcweir void FmFormModel::SetAutoControlFocus( sal_Bool _bAutoControlFocus )
324cdf0e10cSrcweir {
325cdf0e10cSrcweir #ifndef SVX_LIGHT
326cdf0e10cSrcweir 	if( _bAutoControlFocus != m_bAutoControlFocus )
327cdf0e10cSrcweir 	{
328cdf0e10cSrcweir 		m_bAutoControlFocus = _bAutoControlFocus;
329cdf0e10cSrcweir 		m_pObjShell->SetModified( sal_True );
330cdf0e10cSrcweir 	}
331cdf0e10cSrcweir #endif
332cdf0e10cSrcweir }
333cdf0e10cSrcweir 
334cdf0e10cSrcweir //------------------------------------------------------------------------
335cdf0e10cSrcweir void FmFormModel::SetObjectShell( SfxObjectShell* pShell )
336cdf0e10cSrcweir {
337cdf0e10cSrcweir #ifndef SVX_LIGHT
338cdf0e10cSrcweir 	if (pShell == m_pObjShell)
339cdf0e10cSrcweir 		return;
340cdf0e10cSrcweir 
341cdf0e10cSrcweir 	if (m_pObjShell)
342cdf0e10cSrcweir 	{
343cdf0e10cSrcweir 		m_pImpl->pUndoEnv->EndListening( *this );
344cdf0e10cSrcweir 		m_pImpl->pUndoEnv->EndListening( *m_pObjShell );
345cdf0e10cSrcweir 	}
346cdf0e10cSrcweir 
347cdf0e10cSrcweir 	m_pObjShell = pShell;
348cdf0e10cSrcweir 
349cdf0e10cSrcweir 	if (m_pObjShell)
350cdf0e10cSrcweir 	{
351cdf0e10cSrcweir         m_pImpl->pUndoEnv->SetReadOnly( m_pObjShell->IsReadOnly() || m_pObjShell->IsReadOnlyUI(), FmXUndoEnvironment::Accessor() );
352cdf0e10cSrcweir 
353cdf0e10cSrcweir 		if (!m_pImpl->pUndoEnv->IsReadOnly())
354cdf0e10cSrcweir 			 m_pImpl->pUndoEnv->StartListening(*this);
355cdf0e10cSrcweir 
356cdf0e10cSrcweir 		m_pImpl->pUndoEnv->StartListening( *m_pObjShell );
357cdf0e10cSrcweir 	}
358cdf0e10cSrcweir #endif
359cdf0e10cSrcweir }
360cdf0e10cSrcweir 
361cdf0e10cSrcweir //------------------------------------------------------------------------
362cdf0e10cSrcweir FmXUndoEnvironment&	FmFormModel::GetUndoEnv()
363cdf0e10cSrcweir {
364cdf0e10cSrcweir 	return *m_pImpl->pUndoEnv;
365cdf0e10cSrcweir }
366