Bump version to 6.4-15
[LibreOffice.git] / svx / source / form / fmmodel.cxx
blob3791cb7a77d7efc5ec4f952b5703b186b04366e7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
21 #include <fmundo.hxx>
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;
38 struct FmFormModelImplData
40 rtl::Reference<FmXUndoEnvironment> mxUndoEnv;
41 bool bOpenInDesignIsDefaulted;
42 boost::optional<bool> aControlsUseRefDevice;
44 FmFormModelImplData()
45 :bOpenInDesignIsDefaulted( true )
50 FmFormModel::FmFormModel(
51 SfxItemPool* pPool,
52 SfxObjectShell* pPers)
53 : SdrModel(
54 pPool,
55 pPers)
56 , m_pObjShell(nullptr)
57 , m_bOpenInDesignMode(false)
58 , m_bAutoControlFocus(false)
60 m_pImpl.reset( new FmFormModelImplData );
61 m_pImpl->mxUndoEnv = new FmXUndoEnvironment(*this);
64 FmFormModel::~FmFormModel()
66 if (m_pObjShell && m_pImpl->mxUndoEnv->IsListening(*m_pObjShell))
67 SetObjectShell(nullptr);
69 ClearUndoBuffer();
70 // minimum limit for undos
71 SetMaxUndoActionCount(1);
74 SdrPage* FmFormModel::AllocPage(bool bMasterPage)
76 return new FmFormPage(*this, bMasterPage);
79 void FmFormModel::InsertPage(SdrPage* pPage, sal_uInt16 nPos)
81 // hack for as long as the method is internal
82 if (m_pObjShell && !m_pImpl->mxUndoEnv->IsListening( *m_pObjShell ))
83 SetObjectShell(m_pObjShell);
85 SdrModel::InsertPage( pPage, nPos );
88 SdrPage* FmFormModel::RemovePage(sal_uInt16 nPgNum)
90 FmFormPage* pToBeRemovedPage = dynamic_cast< FmFormPage* >( GetPage( nPgNum ) );
91 OSL_ENSURE( pToBeRemovedPage, "FmFormModel::RemovePage: *which page*?" );
93 if ( pToBeRemovedPage )
95 Reference< XNameContainer > xForms( pToBeRemovedPage->GetForms( false ), css::uno::UNO_QUERY );
96 if ( xForms.is() )
97 m_pImpl->mxUndoEnv->RemoveForms( xForms );
100 FmFormPage* pRemovedPage = static_cast<FmFormPage*>(SdrModel::RemovePage(nPgNum));
101 OSL_ENSURE( pRemovedPage == pToBeRemovedPage, "FmFormModel::RemovePage: inconsistency!" );
102 return pRemovedPage;
105 void FmFormModel::InsertMasterPage(SdrPage* pPage, sal_uInt16 nPos)
107 // hack for as long as the method is internal
108 if (m_pObjShell && !m_pImpl->mxUndoEnv->IsListening( *m_pObjShell ))
109 SetObjectShell(m_pObjShell);
111 SdrModel::InsertMasterPage(pPage, nPos);
114 SdrPage* FmFormModel::RemoveMasterPage(sal_uInt16 nPgNum)
116 FmFormPage* pPage = static_cast<FmFormPage*>(SdrModel::RemoveMasterPage(nPgNum));
118 if ( pPage )
120 Reference< XNameContainer > xForms( pPage->GetForms( false ), css::uno::UNO_QUERY );
121 if ( xForms.is() )
122 m_pImpl->mxUndoEnv->RemoveForms( xForms );
125 return pPage;
129 void FmFormModel::implSetOpenInDesignMode( bool _bOpenDesignMode )
131 if( _bOpenDesignMode != m_bOpenInDesignMode )
133 m_bOpenInDesignMode = _bOpenDesignMode;
135 if ( m_pObjShell )
136 m_pObjShell->SetModified();
138 // no matter if we really did it or not - from now on, it does not count as defaulted anymore
139 m_pImpl->bOpenInDesignIsDefaulted = false;
143 void FmFormModel::SetOpenInDesignMode( bool bOpenDesignMode )
145 implSetOpenInDesignMode( bOpenDesignMode );
149 bool FmFormModel::OpenInDesignModeIsDefaulted( )
151 return m_pImpl->bOpenInDesignIsDefaulted;
155 bool FmFormModel::ControlsUseRefDevice() const
157 if ( !m_pImpl->aControlsUseRefDevice )
159 DocumentType eDocType = eUnknownDocumentType;
160 if ( m_pObjShell )
161 eDocType = DocumentClassification::classifyHostDocument( m_pObjShell->GetModel() );
162 m_pImpl->aControlsUseRefDevice = ControlLayouter::useDocumentReferenceDevice(eDocType);
164 return *m_pImpl->aControlsUseRefDevice;
168 void FmFormModel::SetAutoControlFocus( bool _bAutoControlFocus )
170 if( _bAutoControlFocus != m_bAutoControlFocus )
172 m_bAutoControlFocus = _bAutoControlFocus;
173 m_pObjShell->SetModified();
178 void FmFormModel::SetObjectShell( SfxObjectShell* pShell )
180 if (pShell == m_pObjShell)
181 return;
183 if (m_pObjShell)
185 m_pImpl->mxUndoEnv->EndListening( *this );
186 m_pImpl->mxUndoEnv->EndListening( *m_pObjShell );
189 m_pObjShell = pShell;
191 if (m_pObjShell)
193 m_pImpl->mxUndoEnv->SetReadOnly( m_pObjShell->IsReadOnly() || m_pObjShell->IsReadOnlyUI(), FmXUndoEnvironment::Accessor() );
195 if (!m_pImpl->mxUndoEnv->IsReadOnly())
196 m_pImpl->mxUndoEnv->StartListening(*this);
198 m_pImpl->mxUndoEnv->StartListening( *m_pObjShell );
203 FmXUndoEnvironment& FmFormModel::GetUndoEnv()
205 return *m_pImpl->mxUndoEnv;
208 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */