1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 #include "fmdocumentclassification.hxx"
23 #include "fmcontrollayout.hxx"
25 #include <svx/fmmodel.hxx>
26 #include <svx/fmpage.hxx>
27 #include <svx/svdobj.hxx>
29 #include <sfx2/objsh.hxx>
31 #include <boost/optional.hpp>
33 using ::com::sun::star::uno::Reference
;
34 using ::com::sun::star::container::XNameContainer
;
35 using namespace svxform
;
37 TYPEINIT1(FmFormModel
, SdrModel
);
39 struct FmFormModelImplData
41 FmXUndoEnvironment
* pUndoEnv
;
42 sal_Bool bOpenInDesignIsDefaulted
;
44 ::boost::optional
< sal_Bool
>
45 aControlsUseRefDevice
;
49 ,bOpenInDesignIsDefaulted( sal_True
)
50 ,bMovingPage( sal_False
)
51 ,aControlsUseRefDevice()
56 /*************************************************************************
60 \************************************************************************/
61 FmFormModel::FmFormModel(SfxItemPool
* pPool
, SfxObjectShell
* pPers
)
62 :SdrModel(pPool
, pPers
, LOADREFCOUNTS
)
65 ,m_bOpenInDesignMode(sal_False
)
66 ,m_bAutoControlFocus(sal_False
)
68 m_pImpl
= new FmFormModelImplData
;
69 m_pImpl
->pUndoEnv
= new FmXUndoEnvironment(*this);
70 m_pImpl
->pUndoEnv
->acquire();
73 /*************************************************************************
77 \************************************************************************/
78 FmFormModel::FmFormModel(const XubString
& rPath
, SfxItemPool
* pPool
, SfxObjectShell
* pPers
)
79 :SdrModel(rPath
, pPool
, pPers
)
82 ,m_bOpenInDesignMode(sal_False
)
83 ,m_bAutoControlFocus(sal_False
)
85 m_pImpl
= new FmFormModelImplData
;
86 m_pImpl
->pUndoEnv
= new FmXUndoEnvironment(*this);
87 m_pImpl
->pUndoEnv
->acquire();
90 /*************************************************************************
94 \************************************************************************/
95 FmFormModel::FmFormModel(const XubString
& rPath
, SfxItemPool
* pPool
, SfxObjectShell
* pPers
,
96 bool bUseExtColorTable
)
97 :SdrModel(rPath
, pPool
, pPers
, bUseExtColorTable
, LOADREFCOUNTS
)
100 ,m_bOpenInDesignMode(sal_False
)
101 ,m_bAutoControlFocus(sal_False
)
103 m_pImpl
= new FmFormModelImplData
;
104 m_pImpl
->pUndoEnv
= new FmXUndoEnvironment(*this);
105 m_pImpl
->pUndoEnv
->acquire();
108 /*************************************************************************
112 \************************************************************************/
113 FmFormModel::~FmFormModel()
115 if (m_pObjShell
&& m_pImpl
->pUndoEnv
->IsListening(*m_pObjShell
))
116 SetObjectShell(NULL
);
119 // minimale grenze fuer undos
120 SetMaxUndoActionCount(1);
122 m_pImpl
->pUndoEnv
->release();
127 /*************************************************************************
129 |* Erzeugt eine neue Seite
131 \************************************************************************/
132 SdrPage
* FmFormModel::AllocPage(bool bMasterPage
)
134 return new FmFormPage(*this, NULL
, bMasterPage
);
137 /*************************************************************************
141 \************************************************************************/
142 void FmFormModel::InsertPage(SdrPage
* pPage
, sal_uInt16 nPos
)
144 // hack solange Methode intern
145 if (m_pObjShell
&& !m_pImpl
->pUndoEnv
->IsListening( *m_pObjShell
))
146 SetObjectShell(m_pObjShell
);
148 SdrModel::InsertPage( pPage
, nPos
);
151 /*************************************************************************
155 \************************************************************************/
156 void FmFormModel::MovePage( sal_uInt16 nPgNum
, sal_uInt16 nNewPos
)
158 m_pImpl
->bMovingPage
= sal_True
;
159 // see InsertPage for this
161 SdrModel::MovePage( nPgNum
, nNewPos
);
163 m_pImpl
->bMovingPage
= sal_False
;
166 /*************************************************************************
170 \************************************************************************/
171 SdrPage
* FmFormModel::RemovePage(sal_uInt16 nPgNum
)
173 FmFormPage
* pToBeRemovedPage
= dynamic_cast< FmFormPage
* >( GetPage( nPgNum
) );
174 OSL_ENSURE( pToBeRemovedPage
, "FmFormModel::RemovePage: *which page*?" );
176 if ( pToBeRemovedPage
)
178 Reference
< XNameContainer
> xForms( pToBeRemovedPage
->GetForms( false ), css::uno::UNO_QUERY
);
180 m_pImpl
->pUndoEnv
->RemoveForms( xForms
);
183 FmFormPage
* pRemovedPage
= (FmFormPage
*)SdrModel::RemovePage(nPgNum
);
184 OSL_ENSURE( pRemovedPage
== pToBeRemovedPage
, "FmFormModel::RemovePage: inconsistency!" );
188 /*************************************************************************
192 \************************************************************************/
193 void FmFormModel::InsertMasterPage(SdrPage
* pPage
, sal_uInt16 nPos
)
195 // hack solange Methode intern
196 if (m_pObjShell
&& !m_pImpl
->pUndoEnv
->IsListening( *m_pObjShell
))
197 SetObjectShell(m_pObjShell
);
199 SdrModel::InsertMasterPage(pPage
, nPos
);
202 /*************************************************************************
206 \************************************************************************/
207 SdrPage
* FmFormModel::RemoveMasterPage(sal_uInt16 nPgNum
)
209 FmFormPage
* pPage
= (FmFormPage
*)SdrModel::RemoveMasterPage(nPgNum
);
213 Reference
< XNameContainer
> xForms( pPage
->GetForms( false ), css::uno::UNO_QUERY
);
215 m_pImpl
->pUndoEnv
->RemoveForms( xForms
);
221 //------------------------------------------------------------------------
222 SdrLayerID
FmFormModel::GetControlExportLayerId( const SdrObject
& rObj
) const
224 return rObj
.GetLayer();
227 //------------------------------------------------------------------------
228 void FmFormModel::implSetOpenInDesignMode( sal_Bool _bOpenDesignMode
, sal_Bool _bForce
)
230 if( ( _bOpenDesignMode
!= m_bOpenInDesignMode
) || _bForce
)
232 m_bOpenInDesignMode
= _bOpenDesignMode
;
235 m_pObjShell
->SetModified( sal_True
);
237 // no matter if we really did it or not - from now on, it does not count as defaulted anymore
238 m_pImpl
->bOpenInDesignIsDefaulted
= sal_False
;
241 //------------------------------------------------------------------------
242 void FmFormModel::SetOpenInDesignMode( sal_Bool bOpenDesignMode
)
244 implSetOpenInDesignMode( bOpenDesignMode
, sal_False
);
247 //------------------------------------------------------------------------
248 sal_Bool
FmFormModel::OpenInDesignModeIsDefaulted( )
250 return m_pImpl
->bOpenInDesignIsDefaulted
;
253 //------------------------------------------------------------------------
254 sal_Bool
FmFormModel::ControlsUseRefDevice() const
256 if ( !m_pImpl
->aControlsUseRefDevice
)
258 DocumentType eDocType
= eUnknownDocumentType
;
260 eDocType
= DocumentClassification::classifyHostDocument( m_pObjShell
->GetModel() );
261 m_pImpl
->aControlsUseRefDevice
.reset( ControlLayouter::useDocumentReferenceDevice( eDocType
) );
263 return *m_pImpl
->aControlsUseRefDevice
;
266 //------------------------------------------------------------------------
267 void FmFormModel::SetAutoControlFocus( sal_Bool _bAutoControlFocus
)
269 if( _bAutoControlFocus
!= m_bAutoControlFocus
)
271 m_bAutoControlFocus
= _bAutoControlFocus
;
272 m_pObjShell
->SetModified( sal_True
);
276 //------------------------------------------------------------------------
277 void FmFormModel::SetObjectShell( SfxObjectShell
* pShell
)
279 if (pShell
== m_pObjShell
)
284 m_pImpl
->pUndoEnv
->EndListening( *this );
285 m_pImpl
->pUndoEnv
->EndListening( *m_pObjShell
);
288 m_pObjShell
= pShell
;
292 m_pImpl
->pUndoEnv
->SetReadOnly( m_pObjShell
->IsReadOnly() || m_pObjShell
->IsReadOnlyUI(), FmXUndoEnvironment::Accessor() );
294 if (!m_pImpl
->pUndoEnv
->IsReadOnly())
295 m_pImpl
->pUndoEnv
->StartListening(*this);
297 m_pImpl
->pUndoEnv
->StartListening( *m_pObjShell
);
301 //------------------------------------------------------------------------
302 FmXUndoEnvironment
& FmFormModel::GetUndoEnv()
304 return *m_pImpl
->pUndoEnv
;
307 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */