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 <com/sun/star/form/XForms.hpp>
26 #include <svx/fmmodel.hxx>
27 #include <svx/fmpage.hxx>
29 #include <sfx2/objsh.hxx>
30 #include <osl/diagnose.h>
34 using ::com::sun::star::uno::Reference
;
35 using ::com::sun::star::container::XNameContainer
;
36 using namespace svxform
;
39 struct FmFormModelImplData
41 rtl::Reference
<FmXUndoEnvironment
> mxUndoEnv
;
42 bool bOpenInDesignIsDefaulted
;
43 std::optional
<bool> aControlsUseRefDevice
;
46 :bOpenInDesignIsDefaulted( true )
51 FmFormModel::FmFormModel(
53 SfxObjectShell
* pPers
)
57 , m_pObjShell(nullptr)
58 , m_bOpenInDesignMode(false)
59 , m_bAutoControlFocus(false)
61 m_pImpl
.reset( new FmFormModelImplData
);
62 m_pImpl
->mxUndoEnv
= new FmXUndoEnvironment(*this);
65 FmFormModel::~FmFormModel()
67 if (m_pObjShell
&& m_pImpl
->mxUndoEnv
->IsListening(*m_pObjShell
))
68 SetObjectShell(nullptr);
71 // minimum limit for undos
72 SetMaxUndoActionCount(1);
75 rtl::Reference
<SdrPage
> FmFormModel::AllocPage(bool bMasterPage
)
77 return new FmFormPage(*this, bMasterPage
);
80 void FmFormModel::InsertPage(SdrPage
* pPage
, sal_uInt16 nPos
)
82 // hack for as long as the method is internal
83 if (m_pObjShell
&& !m_pImpl
->mxUndoEnv
->IsListening( *m_pObjShell
))
84 SetObjectShell(m_pObjShell
);
86 SdrModel::InsertPage( pPage
, nPos
);
89 rtl::Reference
<SdrPage
> FmFormModel::RemovePage(sal_uInt16 nPgNum
)
91 FmFormPage
* pToBeRemovedPage
= dynamic_cast< FmFormPage
* >( GetPage( nPgNum
) );
92 OSL_ENSURE( pToBeRemovedPage
, "FmFormModel::RemovePage: *which page*?" );
94 if ( pToBeRemovedPage
)
96 Reference
< XNameContainer
> xForms( pToBeRemovedPage
->GetForms( false ) );
98 m_pImpl
->mxUndoEnv
->RemoveForms( xForms
);
101 rtl::Reference
<FmFormPage
> pRemovedPage
= static_cast<FmFormPage
*>(SdrModel::RemovePage(nPgNum
).get());
102 OSL_ENSURE( pRemovedPage
== pToBeRemovedPage
, "FmFormModel::RemovePage: inconsistency!" );
106 void FmFormModel::InsertMasterPage(SdrPage
* pPage
, sal_uInt16 nPos
)
108 // hack for as long as the method is internal
109 if (m_pObjShell
&& !m_pImpl
->mxUndoEnv
->IsListening( *m_pObjShell
))
110 SetObjectShell(m_pObjShell
);
112 SdrModel::InsertMasterPage(pPage
, nPos
);
115 rtl::Reference
<SdrPage
> FmFormModel::RemoveMasterPage(sal_uInt16 nPgNum
)
117 rtl::Reference
<FmFormPage
> pPage
= static_cast<FmFormPage
*>(SdrModel::RemoveMasterPage(nPgNum
).get());
121 Reference
< XNameContainer
> xForms( pPage
->GetForms( false ) );
123 m_pImpl
->mxUndoEnv
->RemoveForms( xForms
);
130 void FmFormModel::implSetOpenInDesignMode( bool _bOpenDesignMode
)
132 if( _bOpenDesignMode
!= m_bOpenInDesignMode
)
134 m_bOpenInDesignMode
= _bOpenDesignMode
;
137 m_pObjShell
->SetModified();
139 // no matter if we really did it or not - from now on, it does not count as defaulted anymore
140 m_pImpl
->bOpenInDesignIsDefaulted
= false;
144 void FmFormModel::SetOpenInDesignMode( bool bOpenDesignMode
)
146 implSetOpenInDesignMode( bOpenDesignMode
);
150 bool FmFormModel::OpenInDesignModeIsDefaulted( )
152 return m_pImpl
->bOpenInDesignIsDefaulted
;
156 bool FmFormModel::ControlsUseRefDevice() const
158 if ( !m_pImpl
->aControlsUseRefDevice
)
160 DocumentType eDocType
= eUnknownDocumentType
;
162 eDocType
= DocumentClassification::classifyHostDocument( m_pObjShell
->GetModel() );
163 m_pImpl
->aControlsUseRefDevice
= ControlLayouter::useDocumentReferenceDevice(eDocType
);
165 return *m_pImpl
->aControlsUseRefDevice
;
169 void FmFormModel::SetAutoControlFocus( bool _bAutoControlFocus
)
171 if( _bAutoControlFocus
!= m_bAutoControlFocus
)
173 m_bAutoControlFocus
= _bAutoControlFocus
;
174 m_pObjShell
->SetModified();
179 void FmFormModel::SetObjectShell( SfxObjectShell
* pShell
)
181 if (pShell
== m_pObjShell
)
186 m_pImpl
->mxUndoEnv
->EndListening( *this );
187 m_pImpl
->mxUndoEnv
->EndListening( *m_pObjShell
);
190 m_pObjShell
= pShell
;
194 m_pImpl
->mxUndoEnv
->SetReadOnly( m_pObjShell
->IsReadOnly() || m_pObjShell
->IsReadOnlyUI(), FmXUndoEnvironment::Accessor() );
196 if (!m_pImpl
->mxUndoEnv
->IsReadOnly())
197 m_pImpl
->mxUndoEnv
->StartListening(*this);
199 m_pImpl
->mxUndoEnv
->StartListening( *m_pObjShell
);
204 FmXUndoEnvironment
& FmFormModel::GetUndoEnv()
206 return *m_pImpl
->mxUndoEnv
;
209 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */