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 bool bOpenInDesignIsDefaulted
;
44 ::boost::optional
< sal_Bool
>
45 aControlsUseRefDevice
;
49 ,bOpenInDesignIsDefaulted( true )
51 ,aControlsUseRefDevice()
56 FmFormModel::FmFormModel(SfxItemPool
* pPool
, SfxObjectShell
* pPers
)
57 : SdrModel(pPool
, pPers
, false, LOADREFCOUNTS
)
60 , m_bOpenInDesignMode(false)
61 , m_bAutoControlFocus(false)
63 m_pImpl
= new FmFormModelImplData
;
64 m_pImpl
->pUndoEnv
= new FmXUndoEnvironment(*this);
65 m_pImpl
->pUndoEnv
->acquire();
68 FmFormModel::FmFormModel(const OUString
& rPath
, SfxItemPool
* pPool
, SfxObjectShell
* pPers
)
69 : SdrModel(rPath
, pPool
, pPers
, false, LOADREFCOUNTS
)
72 , m_bOpenInDesignMode(false)
73 , m_bAutoControlFocus(false)
75 m_pImpl
= new FmFormModelImplData
;
76 m_pImpl
->pUndoEnv
= new FmXUndoEnvironment(*this);
77 m_pImpl
->pUndoEnv
->acquire();
80 FmFormModel::FmFormModel(const OUString
& rPath
, SfxItemPool
* pPool
, SfxObjectShell
* pPers
,
81 bool bUseExtColorTable
)
82 : SdrModel(rPath
, pPool
, pPers
, bUseExtColorTable
, LOADREFCOUNTS
)
85 , m_bOpenInDesignMode(false)
86 , m_bAutoControlFocus(false)
88 m_pImpl
= new FmFormModelImplData
;
89 m_pImpl
->pUndoEnv
= new FmXUndoEnvironment(*this);
90 m_pImpl
->pUndoEnv
->acquire();
93 FmFormModel::~FmFormModel()
95 if (m_pObjShell
&& m_pImpl
->pUndoEnv
->IsListening(*m_pObjShell
))
99 // minimale grenze fuer undos
100 SetMaxUndoActionCount(1);
102 m_pImpl
->pUndoEnv
->release();
107 SdrPage
* FmFormModel::AllocPage(bool bMasterPage
)
109 return new FmFormPage(*this, bMasterPage
);
112 void FmFormModel::InsertPage(SdrPage
* pPage
, sal_uInt16 nPos
)
114 // hack solange Methode intern
115 if (m_pObjShell
&& !m_pImpl
->pUndoEnv
->IsListening( *m_pObjShell
))
116 SetObjectShell(m_pObjShell
);
118 SdrModel::InsertPage( pPage
, nPos
);
121 void FmFormModel::MovePage( sal_uInt16 nPgNum
, sal_uInt16 nNewPos
)
123 m_pImpl
->bMovingPage
= true;
124 // see InsertPage for this
126 SdrModel::MovePage( nPgNum
, nNewPos
);
128 m_pImpl
->bMovingPage
= false;
131 SdrPage
* FmFormModel::RemovePage(sal_uInt16 nPgNum
)
133 FmFormPage
* pToBeRemovedPage
= dynamic_cast< FmFormPage
* >( GetPage( nPgNum
) );
134 OSL_ENSURE( pToBeRemovedPage
, "FmFormModel::RemovePage: *which page*?" );
136 if ( pToBeRemovedPage
)
138 Reference
< XNameContainer
> xForms( pToBeRemovedPage
->GetForms( false ), css::uno::UNO_QUERY
);
140 m_pImpl
->pUndoEnv
->RemoveForms( xForms
);
143 FmFormPage
* pRemovedPage
= static_cast<FmFormPage
*>(SdrModel::RemovePage(nPgNum
));
144 OSL_ENSURE( pRemovedPage
== pToBeRemovedPage
, "FmFormModel::RemovePage: inconsistency!" );
148 void FmFormModel::InsertMasterPage(SdrPage
* pPage
, sal_uInt16 nPos
)
150 // hack solange Methode intern
151 if (m_pObjShell
&& !m_pImpl
->pUndoEnv
->IsListening( *m_pObjShell
))
152 SetObjectShell(m_pObjShell
);
154 SdrModel::InsertMasterPage(pPage
, nPos
);
157 SdrPage
* FmFormModel::RemoveMasterPage(sal_uInt16 nPgNum
)
159 FmFormPage
* pPage
= static_cast<FmFormPage
*>(SdrModel::RemoveMasterPage(nPgNum
));
163 Reference
< XNameContainer
> xForms( pPage
->GetForms( false ), css::uno::UNO_QUERY
);
165 m_pImpl
->pUndoEnv
->RemoveForms( xForms
);
172 SdrLayerID
FmFormModel::GetControlExportLayerId( const SdrObject
& rObj
) const
174 return rObj
.GetLayer();
178 void FmFormModel::implSetOpenInDesignMode( bool _bOpenDesignMode
, bool _bForce
)
180 if( ( _bOpenDesignMode
!= m_bOpenInDesignMode
) || _bForce
)
182 m_bOpenInDesignMode
= _bOpenDesignMode
;
185 m_pObjShell
->SetModified( true );
187 // no matter if we really did it or not - from now on, it does not count as defaulted anymore
188 m_pImpl
->bOpenInDesignIsDefaulted
= false;
192 void FmFormModel::SetOpenInDesignMode( bool bOpenDesignMode
)
194 implSetOpenInDesignMode( bOpenDesignMode
, false );
198 bool FmFormModel::OpenInDesignModeIsDefaulted( )
200 return m_pImpl
->bOpenInDesignIsDefaulted
;
204 bool FmFormModel::ControlsUseRefDevice() const
206 if ( !m_pImpl
->aControlsUseRefDevice
)
208 DocumentType eDocType
= eUnknownDocumentType
;
210 eDocType
= DocumentClassification::classifyHostDocument( m_pObjShell
->GetModel() );
211 m_pImpl
->aControlsUseRefDevice
.reset( ControlLayouter::useDocumentReferenceDevice( eDocType
) );
213 return *m_pImpl
->aControlsUseRefDevice
;
217 void FmFormModel::SetAutoControlFocus( bool _bAutoControlFocus
)
219 if( _bAutoControlFocus
!= m_bAutoControlFocus
)
221 m_bAutoControlFocus
= _bAutoControlFocus
;
222 m_pObjShell
->SetModified( true );
227 void FmFormModel::SetObjectShell( SfxObjectShell
* pShell
)
229 if (pShell
== m_pObjShell
)
234 m_pImpl
->pUndoEnv
->EndListening( *this );
235 m_pImpl
->pUndoEnv
->EndListening( *m_pObjShell
);
238 m_pObjShell
= pShell
;
242 m_pImpl
->pUndoEnv
->SetReadOnly( m_pObjShell
->IsReadOnly() || m_pObjShell
->IsReadOnlyUI(), FmXUndoEnvironment::Accessor() );
244 if (!m_pImpl
->pUndoEnv
->IsReadOnly())
245 m_pImpl
->pUndoEnv
->StartListening(*this);
247 m_pImpl
->pUndoEnv
->StartListening( *m_pObjShell
);
252 FmXUndoEnvironment
& FmFormModel::GetUndoEnv()
254 return *m_pImpl
->pUndoEnv
;
257 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */