merge the formfield patch from ooo-build
[ooovba.git] / svx / source / form / fmmodel.cxx
blob73a1471b26e0b050effe5f00c32259f7751ebdee
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fmmodel.cxx,v $
10 * $Revision: 1.18 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
33 #include <tools/debug.hxx>
35 #ifndef SVX_LIGHT
36 #ifndef _SFX_OBJSH_HXX //autogen
37 #include <sfx2/objsh.hxx>
38 #endif
39 #else
40 class SfxObjectShell;
41 #endif
43 #ifndef _FM_FMMODEL_HXX
44 #include <svx/fmmodel.hxx>
45 #endif
47 #ifndef _FM_PAGE_HXX
48 #include <svx/fmpage.hxx>
49 #endif
50 #include "fmundo.hxx"
51 #ifndef _SVX_SVDOBJ_HXX
52 #include <svx/svdobj.hxx>
53 #endif
55 using ::com::sun::star::uno::Reference;
56 using ::com::sun::star::container::XNameContainer;
58 TYPEINIT1(FmFormModel, SdrModel);
60 struct FmFormModelImplData
62 FmXUndoEnvironment* pUndoEnv;
63 sal_Bool bOpenInDesignIsDefaulted;
64 sal_Bool bMovingPage;
66 FmFormModelImplData()
67 :pUndoEnv( NULL )
68 ,bOpenInDesignIsDefaulted( sal_True )
69 ,bMovingPage( sal_False )
74 /*************************************************************************
76 |* Ctor
78 \************************************************************************/
79 FmFormModel::FmFormModel(SfxItemPool* pPool, SfxObjectShell* pPers)
80 :SdrModel(pPool, pPers, LOADREFCOUNTS)
81 ,m_pImpl(NULL)
82 ,m_pObjShell(0)
83 ,m_bOpenInDesignMode(sal_False)
84 ,m_bAutoControlFocus(sal_False)
86 #ifndef SVX_LIGHT
87 m_pImpl = new FmFormModelImplData;
88 m_pImpl->pUndoEnv = new FmXUndoEnvironment(*this);
89 m_pImpl->pUndoEnv->acquire();
90 #endif
93 /*************************************************************************
95 |* Ctor
97 \************************************************************************/
98 FmFormModel::FmFormModel(const XubString& rPath, SfxItemPool* pPool, SfxObjectShell* pPers)
99 :SdrModel(rPath, pPool, pPers)
100 ,m_pImpl(NULL)
101 ,m_pObjShell(0)
102 ,m_bOpenInDesignMode(sal_False)
103 ,m_bAutoControlFocus(sal_False)
105 #ifndef SVX_LIGHT
106 m_pImpl = new FmFormModelImplData;
107 m_pImpl->pUndoEnv = new FmXUndoEnvironment(*this);
108 m_pImpl->pUndoEnv->acquire();
109 #endif
112 /*************************************************************************
114 |* Ctor
116 \************************************************************************/
117 FmFormModel::FmFormModel(SfxItemPool* pPool, SfxObjectShell* pPers,
118 FASTBOOL bUseExtColorTable
120 :SdrModel(pPool, pPers, bUseExtColorTable, LOADREFCOUNTS)
121 ,m_pImpl(NULL)
122 ,m_pObjShell(0)
123 ,m_bOpenInDesignMode(sal_False)
124 ,m_bAutoControlFocus(sal_False)
126 #ifndef SVX_LIGHT
127 m_pImpl = new FmFormModelImplData;
128 m_pImpl->pUndoEnv = new FmXUndoEnvironment(*this);
129 m_pImpl->pUndoEnv->acquire();
130 #endif
133 /*************************************************************************
135 |* Ctor
137 \************************************************************************/
138 FmFormModel::FmFormModel(const XubString& rPath, SfxItemPool* pPool, SfxObjectShell* pPers,
139 FASTBOOL bUseExtColorTable)
140 :SdrModel(rPath, pPool, pPers, bUseExtColorTable, LOADREFCOUNTS)
141 ,m_pImpl( NULL )
142 ,m_pObjShell(0)
143 ,m_bOpenInDesignMode(sal_False)
144 ,m_bAutoControlFocus(sal_False)
146 #ifndef SVX_LIGHT
147 m_pImpl = new FmFormModelImplData;
148 m_pImpl->pUndoEnv = new FmXUndoEnvironment(*this);
149 m_pImpl->pUndoEnv->acquire();
150 #endif
153 /*************************************************************************
155 |* Dtor
157 \************************************************************************/
158 FmFormModel::~FmFormModel()
160 #ifndef SVX_LIGHT
161 if (m_pObjShell && m_pImpl->pUndoEnv->IsListening(*m_pObjShell))
162 SetObjectShell(NULL);
164 ClearUndoBuffer();
165 // minimale grenze fuer undos
166 SetMaxUndoActionCount(1);
168 m_pImpl->pUndoEnv->release();
169 delete m_pImpl;
171 #endif
174 /*************************************************************************
176 |* Erzeugt eine neue Seite
178 \************************************************************************/
179 SdrPage* FmFormModel::AllocPage(FASTBOOL bMasterPage)
181 return new FmFormPage(*this, NULL, bMasterPage);
184 /*************************************************************************
186 |* InsertPage
188 \************************************************************************/
189 void FmFormModel::InsertPage(SdrPage* pPage, sal_uInt16 nPos)
191 #ifndef SVX_LIGHT
192 // hack solange Methode intern
193 if (m_pObjShell && !m_pImpl->pUndoEnv->IsListening( *m_pObjShell ))
194 SetObjectShell(m_pObjShell);
195 #endif
197 SdrModel::InsertPage( pPage, nPos );
200 /*************************************************************************
202 |* MovePage
204 \************************************************************************/
205 void FmFormModel::MovePage( USHORT nPgNum, USHORT nNewPos )
207 #ifndef SVX_LIGHT
208 m_pImpl->bMovingPage = sal_True;
209 // see InsertPage for this
210 #endif
212 SdrModel::MovePage( nPgNum, nNewPos );
214 #ifndef SVX_LIGHT
215 m_pImpl->bMovingPage = sal_False;
216 #endif
219 /*************************************************************************
221 |* RemovePage
223 \************************************************************************/
224 SdrPage* FmFormModel::RemovePage(sal_uInt16 nPgNum)
226 FmFormPage* pToBeRemovedPage = dynamic_cast< FmFormPage* >( GetPage( nPgNum ) );
227 OSL_ENSURE( pToBeRemovedPage, "FmFormModel::RemovePage: *which page*?" );
229 #ifndef SVX_LIGHT
230 if ( pToBeRemovedPage )
232 Reference< XNameContainer > xForms( pToBeRemovedPage->GetForms( false ) );
233 if ( xForms.is() )
234 m_pImpl->pUndoEnv->RemoveForms( xForms );
236 #endif
238 FmFormPage* pRemovedPage = (FmFormPage*)SdrModel::RemovePage(nPgNum);
239 OSL_ENSURE( pRemovedPage == pToBeRemovedPage, "FmFormModel::RemovePage: inconsistency!" );
240 return pRemovedPage;
243 /*************************************************************************
245 |* InsertMasterPage
247 \************************************************************************/
248 void FmFormModel::InsertMasterPage(SdrPage* pPage, sal_uInt16 nPos)
250 #ifndef SVX_LIGHT
251 // hack solange Methode intern
252 if (m_pObjShell && !m_pImpl->pUndoEnv->IsListening( *m_pObjShell ))
253 SetObjectShell(m_pObjShell);
254 #endif
256 SdrModel::InsertMasterPage(pPage, nPos);
259 /*************************************************************************
261 |* RemoveMasterPage
263 \************************************************************************/
264 SdrPage* FmFormModel::RemoveMasterPage(sal_uInt16 nPgNum)
266 FmFormPage* pPage = (FmFormPage*)SdrModel::RemoveMasterPage(nPgNum);
268 #ifndef SVX_LIGHT
269 if ( pPage )
271 Reference< XNameContainer > xForms( pPage->GetForms( false ) );
272 if ( xForms.is() )
273 m_pImpl->pUndoEnv->RemoveForms( xForms );
275 #endif
277 return pPage;
280 //------------------------------------------------------------------------
281 SdrLayerID FmFormModel::GetControlExportLayerId( const SdrObject& rObj ) const
283 return rObj.GetLayer();
286 //------------------------------------------------------------------------
287 void FmFormModel::implSetOpenInDesignMode( sal_Bool _bOpenDesignMode, sal_Bool _bForce )
289 if( ( _bOpenDesignMode != m_bOpenInDesignMode ) || _bForce )
291 m_bOpenInDesignMode = _bOpenDesignMode;
293 if ( m_pObjShell )
294 m_pObjShell->SetModified( sal_True );
296 // no matter if we really did it or not - from now on, it does not count as defaulted anymore
297 m_pImpl->bOpenInDesignIsDefaulted = sal_False;
300 //------------------------------------------------------------------------
301 void FmFormModel::SetOpenInDesignMode( sal_Bool bOpenDesignMode )
303 #ifndef SVX_LIGHT
304 implSetOpenInDesignMode( bOpenDesignMode, sal_False );
305 #endif
308 #ifndef SVX_LIGHT
309 //------------------------------------------------------------------------
310 sal_Bool FmFormModel::OpenInDesignModeIsDefaulted( )
312 return m_pImpl->bOpenInDesignIsDefaulted;
314 #endif
316 //------------------------------------------------------------------------
317 void FmFormModel::SetAutoControlFocus( sal_Bool _bAutoControlFocus )
319 #ifndef SVX_LIGHT
320 if( _bAutoControlFocus != m_bAutoControlFocus )
322 m_bAutoControlFocus = _bAutoControlFocus;
323 m_pObjShell->SetModified( sal_True );
325 #endif
328 //------------------------------------------------------------------------
329 void FmFormModel::SetObjectShell( SfxObjectShell* pShell )
331 #ifndef SVX_LIGHT
332 if (pShell == m_pObjShell)
333 return;
335 if (m_pObjShell)
337 m_pImpl->pUndoEnv->EndListening( *this );
338 m_pImpl->pUndoEnv->EndListening( *m_pObjShell );
341 m_pObjShell = pShell;
343 if (m_pObjShell)
345 m_pImpl->pUndoEnv->SetReadOnly( m_pObjShell->IsReadOnly() || m_pObjShell->IsReadOnlyUI(), FmXUndoEnvironment::Accessor() );
347 if (!m_pImpl->pUndoEnv->IsReadOnly())
348 m_pImpl->pUndoEnv->StartListening(*this);
350 m_pImpl->pUndoEnv->StartListening( *m_pObjShell );
352 #endif
355 //------------------------------------------------------------------------
356 FmXUndoEnvironment& FmFormModel::GetUndoEnv()
358 return *m_pImpl->pUndoEnv;