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 <svx/fmmodel.hxx>
26 #include <svx/fmpage.hxx>
27 
28 #include <sfx2/objsh.hxx>
29 
30 #include <optional>
31 
32 using ::com::sun::star::uno::Reference;
33 using ::com::sun::star::container::XNameContainer;
34 using namespace svxform;
35 
36 
38 {
41  std::optional<bool> aControlsUseRefDevice;
42 
44  :bOpenInDesignIsDefaulted( true )
45  {
46  }
47 };
48 
50  SfxItemPool* pPool,
51  SfxObjectShell* pPers)
52 : SdrModel(
53  pPool,
54  pPers)
55  , m_pObjShell(nullptr)
56  , m_bOpenInDesignMode(false)
57  , m_bAutoControlFocus(false)
58 {
59  m_pImpl.reset( new FmFormModelImplData );
60  m_pImpl->mxUndoEnv = new FmXUndoEnvironment(*this);
61 }
62 
64 {
65  if (m_pObjShell && m_pImpl->mxUndoEnv->IsListening(*m_pObjShell))
66  SetObjectShell(nullptr);
67 
69  // minimum limit for undos
71 }
72 
73 SdrPage* FmFormModel::AllocPage(bool bMasterPage)
74 {
75  return new FmFormPage(*this, bMasterPage);
76 }
77 
78 void FmFormModel::InsertPage(SdrPage* pPage, sal_uInt16 nPos)
79 {
80  // hack for as long as the method is internal
81  if (m_pObjShell && !m_pImpl->mxUndoEnv->IsListening( *m_pObjShell ))
83 
84  SdrModel::InsertPage( pPage, nPos );
85 }
86 
87 SdrPage* FmFormModel::RemovePage(sal_uInt16 nPgNum)
88 {
89  FmFormPage* pToBeRemovedPage = dynamic_cast< FmFormPage* >( GetPage( nPgNum ) );
90  OSL_ENSURE( pToBeRemovedPage, "FmFormModel::RemovePage: *which page*?" );
91 
92  if ( pToBeRemovedPage )
93  {
94  Reference< XNameContainer > xForms( pToBeRemovedPage->GetForms( false ), css::uno::UNO_QUERY );
95  if ( xForms.is() )
96  m_pImpl->mxUndoEnv->RemoveForms( xForms );
97  }
98 
99  FmFormPage* pRemovedPage = static_cast<FmFormPage*>(SdrModel::RemovePage(nPgNum));
100  OSL_ENSURE( pRemovedPage == pToBeRemovedPage, "FmFormModel::RemovePage: inconsistency!" );
101  return pRemovedPage;
102 }
103 
104 void FmFormModel::InsertMasterPage(SdrPage* pPage, sal_uInt16 nPos)
105 {
106  // hack for as long as the method is internal
107  if (m_pObjShell && !m_pImpl->mxUndoEnv->IsListening( *m_pObjShell ))
109 
110  SdrModel::InsertMasterPage(pPage, nPos);
111 }
112 
114 {
115  FmFormPage* pPage = static_cast<FmFormPage*>(SdrModel::RemoveMasterPage(nPgNum));
116 
117  if ( pPage )
118  {
119  Reference< XNameContainer > xForms( pPage->GetForms( false ), css::uno::UNO_QUERY );
120  if ( xForms.is() )
121  m_pImpl->mxUndoEnv->RemoveForms( xForms );
122  }
123 
124  return pPage;
125 }
126 
127 
128 void FmFormModel::implSetOpenInDesignMode( bool _bOpenDesignMode )
129 {
130  if( _bOpenDesignMode != m_bOpenInDesignMode )
131  {
132  m_bOpenInDesignMode = _bOpenDesignMode;
133 
134  if ( m_pObjShell )
136  }
137  // no matter if we really did it or not - from now on, it does not count as defaulted anymore
138  m_pImpl->bOpenInDesignIsDefaulted = false;
139 }
140 
141 
142 void FmFormModel::SetOpenInDesignMode( bool bOpenDesignMode )
143 {
144  implSetOpenInDesignMode( bOpenDesignMode );
145 }
146 
147 
149 {
150  return m_pImpl->bOpenInDesignIsDefaulted;
151 }
152 
153 
155 {
156  if ( !m_pImpl->aControlsUseRefDevice )
157  {
159  if ( m_pObjShell )
160  eDocType = DocumentClassification::classifyHostDocument( m_pObjShell->GetModel() );
161  m_pImpl->aControlsUseRefDevice = ControlLayouter::useDocumentReferenceDevice(eDocType);
162  }
163  return *m_pImpl->aControlsUseRefDevice;
164 }
165 
166 
167 void FmFormModel::SetAutoControlFocus( bool _bAutoControlFocus )
168 {
169  if( _bAutoControlFocus != m_bAutoControlFocus )
170  {
171  m_bAutoControlFocus = _bAutoControlFocus;
173  }
174 }
175 
176 
178 {
179  if (pShell == m_pObjShell)
180  return;
181 
182  if (m_pObjShell)
183  {
184  m_pImpl->mxUndoEnv->EndListening( *this );
185  m_pImpl->mxUndoEnv->EndListening( *m_pObjShell );
186  }
187 
188  m_pObjShell = pShell;
189 
190  if (m_pObjShell)
191  {
193 
194  if (!m_pImpl->mxUndoEnv->IsReadOnly())
195  m_pImpl->mxUndoEnv->StartListening(*this);
196 
197  m_pImpl->mxUndoEnv->StartListening( *m_pObjShell );
198  }
199 }
200 
201 
203 {
204  return *m_pImpl->mxUndoEnv;
205 }
206 
207 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual ~FmFormModel() override
Definition: fmmodel.cxx:63
virtual SdrPage * RemoveMasterPage(sal_uInt16 nPgNum) override
Definition: fmmodel.cxx:113
void SetAutoControlFocus(bool _bAutoControlFocus)
Definition: fmmodel.cxx:167
virtual void InsertMasterPage(SdrPage *pPage, sal_uInt16 nPos=0xFFFF)
Definition: svdmodel.cxx:1341
virtual void SetModified(bool bModified=true)
virtual void InsertPage(SdrPage *pPage, sal_uInt16 nPos=0xFFFF)
Definition: svdmodel.cxx:1289
bool bOpenInDesignIsDefaulted
Definition: fmmodel.cxx:40
css::uno::Reference< css::frame::XModel > GetModel() const
void SetOpenInDesignMode(bool _bOpenDesignMode)
Definition: fmmodel.cxx:142
bool IsReadOnlyUI() const
void implSetOpenInDesignMode(bool _bOpenDesignMode)
Definition: fmmodel.cxx:128
bool m_bAutoControlFocus
Definition: fmmodel.hxx:40
FmXUndoEnvironment & GetUndoEnv()
Definition: fmmodel.cxx:202
bool m_bOpenInDesignMode
Definition: fmmodel.hxx:39
virtual SdrPage * RemoveMasterPage(sal_uInt16 nPgNum)
Definition: svdmodel.cxx:1365
std::optional< bool > aControlsUseRefDevice
Definition: fmmodel.cxx:41
DocumentType
virtual void InsertPage(SdrPage *pPage, sal_uInt16 nPos=0xFFFF) override
Definition: fmmodel.cxx:78
bool ControlsUseRefDevice() const
determines whether form controls should use the SdrModel's reference device for text rendering ...
Definition: fmmodel.cxx:154
const SdrPage * GetPage(sal_uInt16 nPgNum) const
Definition: svdmodel.cxx:1903
bool OpenInDesignModeIsDefaulted()
check whether the OpenInDesignMode has been set explicitly or been loaded () or if it still ha...
Definition: fmmodel.cxx:148
FmFormModel(const FmFormModel &)=delete
bool IsReadOnly() const
void SetObjectShell(SfxObjectShell *pShell)
Definition: fmmodel.cxx:177
virtual SdrPage * RemovePage(sal_uInt16 nPgNum) override
Definition: fmmodel.cxx:87
std::unique_ptr< FmFormModelImplData > m_pImpl
Definition: fmmodel.hxx:36
void SetMaxUndoActionCount(sal_uInt32 nCount)
Definition: svdmodel.cxx:293
virtual void InsertMasterPage(SdrPage *pPage, sal_uInt16 nPos=0xFFFF) override
Definition: fmmodel.cxx:104
rtl::Reference< FmXUndoEnvironment > mxUndoEnv
Definition: fmmodel.cxx:39
class FmSearchEngine - Impl class for FmSearchDialog
virtual SdrPage * RemovePage(sal_uInt16 nPgNum)
Definition: svdmodel.cxx:1313
A SdrPage contains exactly one SdrObjList and a description of the physical page dimensions (size / m...
Definition: svdpage.hxx:366
bool useDocumentReferenceDevice(DocumentType _eDocType)
determines whether for the given document type, form controls should use the document's reference dev...
const css::uno::Reference< css::form::XForms > & GetForms(bool _bForceCreate=true) const
Definition: fmpage.cxx:84
void ClearUndoBuffer()
Definition: svdmodel.cxx:304
SfxObjectShell * m_pObjShell
Definition: fmmodel.hxx:37
virtual SdrPage * AllocPage(bool bMasterPage) override
Definition: fmmodel.cxx:73