LibreOffice Module svx (master) 1
fmmodel.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20
21#include <fmundo.hxx>
23#include <fmcontrollayout.hxx>
24
25#include <com/sun/star/form/XForms.hpp>
26#include <svx/fmmodel.hxx>
27#include <svx/fmpage.hxx>
28
29#include <sfx2/objsh.hxx>
30#include <osl/diagnose.h>
31
32#include <optional>
33
34using ::com::sun::star::uno::Reference;
35using ::com::sun::star::container::XNameContainer;
36using namespace svxform;
37
38
40{
43 std::optional<bool> aControlsUseRefDevice;
44
47 {
48 }
49};
50
52 SfxItemPool* pPool,
53 SfxObjectShell* pPers)
54: SdrModel(
55 pPool,
56 pPers)
57 , m_pObjShell(nullptr)
58 , m_bOpenInDesignMode(false)
59 , m_bAutoControlFocus(false)
60{
61 m_pImpl.reset( new FmFormModelImplData );
62 m_pImpl->mxUndoEnv = new FmXUndoEnvironment(*this);
63}
64
66{
67 if (m_pObjShell && m_pImpl->mxUndoEnv->IsListening(*m_pObjShell))
68 SetObjectShell(nullptr);
69
71 // minimum limit for undos
73}
74
76{
77 return new FmFormPage(*this, bMasterPage);
78}
79
80void FmFormModel::InsertPage(SdrPage* pPage, sal_uInt16 nPos)
81{
82 // hack for as long as the method is internal
83 if (m_pObjShell && !m_pImpl->mxUndoEnv->IsListening( *m_pObjShell ))
85
86 SdrModel::InsertPage( pPage, nPos );
87}
88
90{
91 FmFormPage* pToBeRemovedPage = dynamic_cast< FmFormPage* >( GetPage( nPgNum ) );
92 OSL_ENSURE( pToBeRemovedPage, "FmFormModel::RemovePage: *which page*?" );
93
94 if ( pToBeRemovedPage )
95 {
96 Reference< XNameContainer > xForms( pToBeRemovedPage->GetForms( false ) );
97 if ( xForms.is() )
98 m_pImpl->mxUndoEnv->RemoveForms( xForms );
99 }
100
101 rtl::Reference<FmFormPage> pRemovedPage = static_cast<FmFormPage*>(SdrModel::RemovePage(nPgNum).get());
102 OSL_ENSURE( pRemovedPage == pToBeRemovedPage, "FmFormModel::RemovePage: inconsistency!" );
103 return pRemovedPage;
104}
105
106void FmFormModel::InsertMasterPage(SdrPage* pPage, sal_uInt16 nPos)
107{
108 // hack for as long as the method is internal
109 if (m_pObjShell && !m_pImpl->mxUndoEnv->IsListening( *m_pObjShell ))
111
113}
114
116{
117 rtl::Reference<FmFormPage> pPage = static_cast<FmFormPage*>(SdrModel::RemoveMasterPage(nPgNum).get());
118
119 if ( pPage )
120 {
121 Reference< XNameContainer > xForms( pPage->GetForms( false ) );
122 if ( xForms.is() )
123 m_pImpl->mxUndoEnv->RemoveForms( xForms );
124 }
125
126 return pPage;
127}
128
129
130void FmFormModel::implSetOpenInDesignMode( bool _bOpenDesignMode )
131{
132 if( _bOpenDesignMode != m_bOpenInDesignMode )
133 {
134 m_bOpenInDesignMode = _bOpenDesignMode;
135
136 if ( m_pObjShell )
138 }
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;
141}
142
143
144void FmFormModel::SetOpenInDesignMode( bool bOpenDesignMode )
145{
146 implSetOpenInDesignMode( bOpenDesignMode );
147}
148
149
151{
152 return m_pImpl->bOpenInDesignIsDefaulted;
153}
154
155
157{
158 if ( !m_pImpl->aControlsUseRefDevice )
159 {
161 if ( m_pObjShell )
162 eDocType = DocumentClassification::classifyHostDocument( m_pObjShell->GetModel() );
163 m_pImpl->aControlsUseRefDevice = ControlLayouter::useDocumentReferenceDevice(eDocType);
164 }
165 return *m_pImpl->aControlsUseRefDevice;
166}
167
168
169void FmFormModel::SetAutoControlFocus( bool _bAutoControlFocus )
170{
171 if( _bAutoControlFocus != m_bAutoControlFocus )
172 {
173 m_bAutoControlFocus = _bAutoControlFocus;
175 }
176}
177
178
180{
181 if (pShell == m_pObjShell)
182 return;
183
184 if (m_pObjShell)
185 {
186 m_pImpl->mxUndoEnv->EndListening( *this );
187 m_pImpl->mxUndoEnv->EndListening( *m_pObjShell );
188 }
189
190 m_pObjShell = pShell;
191
192 if (m_pObjShell)
193 {
195
196 if (!m_pImpl->mxUndoEnv->IsReadOnly())
197 m_pImpl->mxUndoEnv->StartListening(*this);
198
199 m_pImpl->mxUndoEnv->StartListening( *m_pObjShell );
200 }
201}
202
203
205{
206 return *m_pImpl->mxUndoEnv;
207}
208
209/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
FmFormModel(const FmFormModel &)=delete
virtual rtl::Reference< SdrPage > RemovePage(sal_uInt16 nPgNum) override
Definition: fmmodel.cxx:89
bool m_bOpenInDesignMode
Definition: fmmodel.hxx:39
virtual void InsertMasterPage(SdrPage *pPage, sal_uInt16 nPos=0xFFFF) override
Definition: fmmodel.cxx:106
void SetOpenInDesignMode(bool _bOpenDesignMode)
Definition: fmmodel.cxx:144
virtual rtl::Reference< SdrPage > RemoveMasterPage(sal_uInt16 nPgNum) override
Definition: fmmodel.cxx:115
void SetAutoControlFocus(bool _bAutoControlFocus)
Definition: fmmodel.cxx:169
bool OpenInDesignModeIsDefaulted()
check whether the OpenInDesignMode has been set explicitly or been loaded (<FALSE>) or if it still ha...
Definition: fmmodel.cxx:150
void SetObjectShell(SfxObjectShell *pShell)
Definition: fmmodel.cxx:179
virtual ~FmFormModel() override
Definition: fmmodel.cxx:65
bool ControlsUseRefDevice() const
determines whether form controls should use the SdrModel's reference device for text rendering
Definition: fmmodel.cxx:156
FmXUndoEnvironment & GetUndoEnv()
Definition: fmmodel.cxx:204
virtual void InsertPage(SdrPage *pPage, sal_uInt16 nPos=0xFFFF) override
Definition: fmmodel.cxx:80
SfxObjectShell * m_pObjShell
Definition: fmmodel.hxx:37
std::unique_ptr< FmFormModelImplData > m_pImpl
Definition: fmmodel.hxx:36
virtual rtl::Reference< SdrPage > AllocPage(bool bMasterPage) override
Definition: fmmodel.cxx:75
bool m_bAutoControlFocus
Definition: fmmodel.hxx:40
void implSetOpenInDesignMode(bool _bOpenDesignMode)
Definition: fmmodel.cxx:130
const css::uno::Reference< css::form::XForms > & GetForms(bool _bForceCreate=true) const
Definition: fmpage.cxx:86
virtual rtl::Reference< SdrPage > RemovePage(sal_uInt16 nPgNum)
Definition: svdmodel.cxx:1197
virtual void InsertPage(SdrPage *pPage, sal_uInt16 nPos=0xFFFF)
Definition: svdmodel.cxx:1172
void SetMaxUndoActionCount(sal_uInt32 nCount)
Definition: svdmodel.cxx:274
virtual rtl::Reference< SdrPage > RemoveMasterPage(sal_uInt16 nPgNum)
Definition: svdmodel.cxx:1248
void ClearUndoBuffer()
Definition: svdmodel.cxx:282
virtual void InsertMasterPage(SdrPage *pPage, sal_uInt16 nPos=0xFFFF)
Definition: svdmodel.cxx:1225
const SdrPage * GetPage(sal_uInt16 nPgNum) const
Definition: svdmodel.cxx:1860
A SdrPage contains exactly one SdrObjList and a description of the physical page dimensions (size / m...
Definition: svdpage.hxx:379
bool IsReadOnly() const
bool IsReadOnlyUI() const
css::uno::Reference< css::frame::XModel3 > GetModel() const
virtual void SetModified(bool bModified=true)
sal_uInt16 nPos
bool useDocumentReferenceDevice(DocumentType _eDocType)
determines whether for the given document type, form controls should use the document's reference dev...
class FmSearchEngine - Impl class for FmSearchDialog
DocumentType
std::optional< bool > aControlsUseRefDevice
Definition: fmmodel.cxx:43
bool bOpenInDesignIsDefaulted
Definition: fmmodel.cxx:42
rtl::Reference< FmXUndoEnvironment > mxUndoEnv
Definition: fmmodel.cxx:41