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