Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svx / source / form / fmmodel.cxx
blobe518319aab1e560dd1113c3e662314b2eb109b0d
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 <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>
32 #include <optional>
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;
45 FmFormModelImplData()
46 :bOpenInDesignIsDefaulted( true )
51 FmFormModel::FmFormModel(
52 SfxItemPool* pPool,
53 SfxObjectShell* pPers)
54 : SdrModel(
55 pPool,
56 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);
70 ClearUndoBuffer();
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 ) );
97 if ( xForms.is() )
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!" );
103 return pRemovedPage;
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());
119 if ( pPage )
121 Reference< XNameContainer > xForms( pPage->GetForms( false ) );
122 if ( xForms.is() )
123 m_pImpl->mxUndoEnv->RemoveForms( xForms );
126 return pPage;
130 void FmFormModel::implSetOpenInDesignMode( bool _bOpenDesignMode )
132 if( _bOpenDesignMode != m_bOpenInDesignMode )
134 m_bOpenInDesignMode = _bOpenDesignMode;
136 if ( m_pObjShell )
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;
161 if ( m_pObjShell )
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)
182 return;
184 if (m_pObjShell)
186 m_pImpl->mxUndoEnv->EndListening( *this );
187 m_pImpl->mxUndoEnv->EndListening( *m_pObjShell );
190 m_pObjShell = pShell;
192 if (m_pObjShell)
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: */