1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: fmmodel.cxx,v $
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>
36 #ifndef _SFX_OBJSH_HXX //autogen
37 #include <sfx2/objsh.hxx>
43 #ifndef _FM_FMMODEL_HXX
44 #include <svx/fmmodel.hxx>
48 #include <svx/fmpage.hxx>
51 #ifndef _SVX_SVDOBJ_HXX
52 #include <svx/svdobj.hxx>
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
;
68 ,bOpenInDesignIsDefaulted( sal_True
)
69 ,bMovingPage( sal_False
)
74 /*************************************************************************
78 \************************************************************************/
79 FmFormModel::FmFormModel(SfxItemPool
* pPool
, SfxObjectShell
* pPers
)
80 :SdrModel(pPool
, pPers
, LOADREFCOUNTS
)
83 ,m_bOpenInDesignMode(sal_False
)
84 ,m_bAutoControlFocus(sal_False
)
87 m_pImpl
= new FmFormModelImplData
;
88 m_pImpl
->pUndoEnv
= new FmXUndoEnvironment(*this);
89 m_pImpl
->pUndoEnv
->acquire();
93 /*************************************************************************
97 \************************************************************************/
98 FmFormModel::FmFormModel(const XubString
& rPath
, SfxItemPool
* pPool
, SfxObjectShell
* pPers
)
99 :SdrModel(rPath
, pPool
, pPers
)
102 ,m_bOpenInDesignMode(sal_False
)
103 ,m_bAutoControlFocus(sal_False
)
106 m_pImpl
= new FmFormModelImplData
;
107 m_pImpl
->pUndoEnv
= new FmXUndoEnvironment(*this);
108 m_pImpl
->pUndoEnv
->acquire();
112 /*************************************************************************
116 \************************************************************************/
117 FmFormModel::FmFormModel(SfxItemPool
* pPool
, SfxObjectShell
* pPers
,
118 FASTBOOL bUseExtColorTable
120 :SdrModel(pPool
, pPers
, bUseExtColorTable
, LOADREFCOUNTS
)
123 ,m_bOpenInDesignMode(sal_False
)
124 ,m_bAutoControlFocus(sal_False
)
127 m_pImpl
= new FmFormModelImplData
;
128 m_pImpl
->pUndoEnv
= new FmXUndoEnvironment(*this);
129 m_pImpl
->pUndoEnv
->acquire();
133 /*************************************************************************
137 \************************************************************************/
138 FmFormModel::FmFormModel(const XubString
& rPath
, SfxItemPool
* pPool
, SfxObjectShell
* pPers
,
139 FASTBOOL bUseExtColorTable
)
140 :SdrModel(rPath
, pPool
, pPers
, bUseExtColorTable
, LOADREFCOUNTS
)
143 ,m_bOpenInDesignMode(sal_False
)
144 ,m_bAutoControlFocus(sal_False
)
147 m_pImpl
= new FmFormModelImplData
;
148 m_pImpl
->pUndoEnv
= new FmXUndoEnvironment(*this);
149 m_pImpl
->pUndoEnv
->acquire();
153 /*************************************************************************
157 \************************************************************************/
158 FmFormModel::~FmFormModel()
161 if (m_pObjShell
&& m_pImpl
->pUndoEnv
->IsListening(*m_pObjShell
))
162 SetObjectShell(NULL
);
165 // minimale grenze fuer undos
166 SetMaxUndoActionCount(1);
168 m_pImpl
->pUndoEnv
->release();
174 /*************************************************************************
176 |* Erzeugt eine neue Seite
178 \************************************************************************/
179 SdrPage
* FmFormModel::AllocPage(FASTBOOL bMasterPage
)
181 return new FmFormPage(*this, NULL
, bMasterPage
);
184 /*************************************************************************
188 \************************************************************************/
189 void FmFormModel::InsertPage(SdrPage
* pPage
, sal_uInt16 nPos
)
192 // hack solange Methode intern
193 if (m_pObjShell
&& !m_pImpl
->pUndoEnv
->IsListening( *m_pObjShell
))
194 SetObjectShell(m_pObjShell
);
197 SdrModel::InsertPage( pPage
, nPos
);
200 /*************************************************************************
204 \************************************************************************/
205 void FmFormModel::MovePage( USHORT nPgNum
, USHORT nNewPos
)
208 m_pImpl
->bMovingPage
= sal_True
;
209 // see InsertPage for this
212 SdrModel::MovePage( nPgNum
, nNewPos
);
215 m_pImpl
->bMovingPage
= sal_False
;
219 /*************************************************************************
223 \************************************************************************/
224 SdrPage
* FmFormModel::RemovePage(sal_uInt16 nPgNum
)
226 FmFormPage
* pToBeRemovedPage
= dynamic_cast< FmFormPage
* >( GetPage( nPgNum
) );
227 OSL_ENSURE( pToBeRemovedPage
, "FmFormModel::RemovePage: *which page*?" );
230 if ( pToBeRemovedPage
)
232 Reference
< XNameContainer
> xForms( pToBeRemovedPage
->GetForms( false ) );
234 m_pImpl
->pUndoEnv
->RemoveForms( xForms
);
238 FmFormPage
* pRemovedPage
= (FmFormPage
*)SdrModel::RemovePage(nPgNum
);
239 OSL_ENSURE( pRemovedPage
== pToBeRemovedPage
, "FmFormModel::RemovePage: inconsistency!" );
243 /*************************************************************************
247 \************************************************************************/
248 void FmFormModel::InsertMasterPage(SdrPage
* pPage
, sal_uInt16 nPos
)
251 // hack solange Methode intern
252 if (m_pObjShell
&& !m_pImpl
->pUndoEnv
->IsListening( *m_pObjShell
))
253 SetObjectShell(m_pObjShell
);
256 SdrModel::InsertMasterPage(pPage
, nPos
);
259 /*************************************************************************
263 \************************************************************************/
264 SdrPage
* FmFormModel::RemoveMasterPage(sal_uInt16 nPgNum
)
266 FmFormPage
* pPage
= (FmFormPage
*)SdrModel::RemoveMasterPage(nPgNum
);
271 Reference
< XNameContainer
> xForms( pPage
->GetForms( false ) );
273 m_pImpl
->pUndoEnv
->RemoveForms( xForms
);
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
;
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
)
304 implSetOpenInDesignMode( bOpenDesignMode
, sal_False
);
309 //------------------------------------------------------------------------
310 sal_Bool
FmFormModel::OpenInDesignModeIsDefaulted( )
312 return m_pImpl
->bOpenInDesignIsDefaulted
;
316 //------------------------------------------------------------------------
317 void FmFormModel::SetAutoControlFocus( sal_Bool _bAutoControlFocus
)
320 if( _bAutoControlFocus
!= m_bAutoControlFocus
)
322 m_bAutoControlFocus
= _bAutoControlFocus
;
323 m_pObjShell
->SetModified( sal_True
);
328 //------------------------------------------------------------------------
329 void FmFormModel::SetObjectShell( SfxObjectShell
* pShell
)
332 if (pShell
== m_pObjShell
)
337 m_pImpl
->pUndoEnv
->EndListening( *this );
338 m_pImpl
->pUndoEnv
->EndListening( *m_pObjShell
);
341 m_pObjShell
= pShell
;
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
);
355 //------------------------------------------------------------------------
356 FmXUndoEnvironment
& FmFormModel::GetUndoEnv()
358 return *m_pImpl
->pUndoEnv
;