1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_svx.hxx" 26 27 #include "fmundo.hxx" 28 #include "fmdocumentclassification.hxx" 29 #include "fmcontrollayout.hxx" 30 31 #include <svx/fmmodel.hxx> 32 #include <svx/fmpage.hxx> 33 #include <svx/svdobj.hxx> 34 #include <tools/debug.hxx> 35 36 #ifndef SVX_LIGHT 37 #include <sfx2/objsh.hxx> 38 #else 39 class SfxObjectShell; 40 #endif 41 42 #include <boost/optional.hpp> 43 44 using ::com::sun::star::uno::Reference; 45 using ::com::sun::star::container::XNameContainer; 46 using namespace svxform; 47 48 TYPEINIT1(FmFormModel, SdrModel); 49 50 struct FmFormModelImplData 51 { 52 FmXUndoEnvironment* pUndoEnv; 53 sal_Bool bOpenInDesignIsDefaulted; 54 sal_Bool bMovingPage; 55 ::boost::optional< sal_Bool > 56 aControlsUseRefDevice; 57 58 FmFormModelImplData() 59 :pUndoEnv( NULL ) 60 ,bOpenInDesignIsDefaulted( sal_True ) 61 ,bMovingPage( sal_False ) 62 ,aControlsUseRefDevice() 63 { 64 } 65 }; 66 67 /************************************************************************* 68 |* 69 |* Ctor 70 |* 71 \************************************************************************/ 72 FmFormModel::FmFormModel(SfxItemPool* pPool, SfxObjectShell* pPers) 73 :SdrModel(pPool, pPers, LOADREFCOUNTS) 74 ,m_pImpl(NULL) 75 ,m_pObjShell(0) 76 ,m_bOpenInDesignMode(sal_False) 77 ,m_bAutoControlFocus(sal_False) 78 { 79 #ifndef SVX_LIGHT 80 m_pImpl = new FmFormModelImplData; 81 m_pImpl->pUndoEnv = new FmXUndoEnvironment(*this); 82 m_pImpl->pUndoEnv->acquire(); 83 #endif 84 } 85 86 /************************************************************************* 87 |* 88 |* Ctor 89 |* 90 \************************************************************************/ 91 FmFormModel::FmFormModel(const XubString& rPath, SfxItemPool* pPool, SfxObjectShell* pPers) 92 :SdrModel(rPath, pPool, pPers) 93 ,m_pImpl(NULL) 94 ,m_pObjShell(0) 95 ,m_bOpenInDesignMode(sal_False) 96 ,m_bAutoControlFocus(sal_False) 97 { 98 #ifndef SVX_LIGHT 99 m_pImpl = new FmFormModelImplData; 100 m_pImpl->pUndoEnv = new FmXUndoEnvironment(*this); 101 m_pImpl->pUndoEnv->acquire(); 102 #endif 103 } 104 105 /************************************************************************* 106 |* 107 |* Dtor 108 |* 109 \************************************************************************/ 110 FmFormModel::~FmFormModel() 111 { 112 #ifndef SVX_LIGHT 113 if (m_pObjShell && m_pImpl->pUndoEnv->IsListening(*m_pObjShell)) 114 SetObjectShell(NULL); 115 116 ClearUndoBuffer(); 117 // minimale grenze fuer undos 118 SetMaxUndoActionCount(1); 119 120 m_pImpl->pUndoEnv->release(); 121 delete m_pImpl; 122 123 #endif 124 } 125 126 /************************************************************************* 127 |* 128 |* Erzeugt eine neue Seite 129 |* 130 \************************************************************************/ 131 SdrPage* FmFormModel::AllocPage(FASTBOOL bMasterPage) 132 { 133 return new FmFormPage(*this, NULL, bMasterPage); 134 } 135 136 /************************************************************************* 137 |* 138 |* InsertPage 139 |* 140 \************************************************************************/ 141 void FmFormModel::InsertPage(SdrPage* pPage, sal_uInt16 nPos) 142 { 143 #ifndef SVX_LIGHT 144 // hack solange Methode intern 145 if (m_pObjShell && !m_pImpl->pUndoEnv->IsListening( *m_pObjShell )) 146 SetObjectShell(m_pObjShell); 147 #endif 148 149 SdrModel::InsertPage( pPage, nPos ); 150 } 151 152 /************************************************************************* 153 |* 154 |* MovePage 155 |* 156 \************************************************************************/ 157 void FmFormModel::MovePage( sal_uInt16 nPgNum, sal_uInt16 nNewPos ) 158 { 159 #ifndef SVX_LIGHT 160 m_pImpl->bMovingPage = sal_True; 161 // see InsertPage for this 162 #endif 163 164 SdrModel::MovePage( nPgNum, nNewPos ); 165 166 #ifndef SVX_LIGHT 167 m_pImpl->bMovingPage = sal_False; 168 #endif 169 } 170 171 /************************************************************************* 172 |* 173 |* RemovePage 174 |* 175 \************************************************************************/ 176 SdrPage* FmFormModel::RemovePage(sal_uInt16 nPgNum) 177 { 178 FmFormPage* pToBeRemovedPage = dynamic_cast< FmFormPage* >( GetPage( nPgNum ) ); 179 OSL_ENSURE( pToBeRemovedPage, "FmFormModel::RemovePage: *which page*?" ); 180 181 #ifndef SVX_LIGHT 182 if ( pToBeRemovedPage ) 183 { 184 Reference< XNameContainer > xForms( pToBeRemovedPage->GetForms( false ) ); 185 if ( xForms.is() ) 186 m_pImpl->pUndoEnv->RemoveForms( xForms ); 187 } 188 #endif 189 190 FmFormPage* pRemovedPage = (FmFormPage*)SdrModel::RemovePage(nPgNum); 191 OSL_ENSURE( pRemovedPage == pToBeRemovedPage, "FmFormModel::RemovePage: inconsistency!" ); 192 return pRemovedPage; 193 } 194 195 /************************************************************************* 196 |* 197 |* InsertMasterPage 198 |* 199 \************************************************************************/ 200 void FmFormModel::InsertMasterPage(SdrPage* pPage, sal_uInt16 nPos) 201 { 202 #ifndef SVX_LIGHT 203 // hack solange Methode intern 204 if (m_pObjShell && !m_pImpl->pUndoEnv->IsListening( *m_pObjShell )) 205 SetObjectShell(m_pObjShell); 206 #endif 207 208 SdrModel::InsertMasterPage(pPage, nPos); 209 } 210 211 /************************************************************************* 212 |* 213 |* RemoveMasterPage 214 |* 215 \************************************************************************/ 216 SdrPage* FmFormModel::RemoveMasterPage(sal_uInt16 nPgNum) 217 { 218 FmFormPage* pPage = (FmFormPage*)SdrModel::RemoveMasterPage(nPgNum); 219 220 #ifndef SVX_LIGHT 221 if ( pPage ) 222 { 223 Reference< XNameContainer > xForms( pPage->GetForms( false ) ); 224 if ( xForms.is() ) 225 m_pImpl->pUndoEnv->RemoveForms( xForms ); 226 } 227 #endif 228 229 return pPage; 230 } 231 232 //------------------------------------------------------------------------ 233 SdrLayerID FmFormModel::GetControlExportLayerId( const SdrObject& rObj ) const 234 { 235 return rObj.GetLayer(); 236 } 237 238 //------------------------------------------------------------------------ 239 void FmFormModel::implSetOpenInDesignMode( sal_Bool _bOpenDesignMode, sal_Bool _bForce ) 240 { 241 if( ( _bOpenDesignMode != m_bOpenInDesignMode ) || _bForce ) 242 { 243 m_bOpenInDesignMode = _bOpenDesignMode; 244 245 if ( m_pObjShell ) 246 m_pObjShell->SetModified( sal_True ); 247 } 248 // no matter if we really did it or not - from now on, it does not count as defaulted anymore 249 m_pImpl->bOpenInDesignIsDefaulted = sal_False; 250 } 251 252 //------------------------------------------------------------------------ 253 void FmFormModel::SetOpenInDesignMode( sal_Bool bOpenDesignMode ) 254 { 255 #ifndef SVX_LIGHT 256 implSetOpenInDesignMode( bOpenDesignMode, sal_False ); 257 #endif 258 } 259 260 #ifndef SVX_LIGHT 261 //------------------------------------------------------------------------ 262 sal_Bool FmFormModel::OpenInDesignModeIsDefaulted( ) 263 { 264 return m_pImpl->bOpenInDesignIsDefaulted; 265 } 266 #endif 267 268 //------------------------------------------------------------------------ 269 sal_Bool FmFormModel::ControlsUseRefDevice() const 270 { 271 if ( !m_pImpl->aControlsUseRefDevice ) 272 { 273 DocumentType eDocType = eUnknownDocumentType; 274 if ( m_pObjShell ) 275 eDocType = DocumentClassification::classifyHostDocument( m_pObjShell->GetModel() ); 276 m_pImpl->aControlsUseRefDevice.reset( ControlLayouter::useDocumentReferenceDevice( eDocType ) ); 277 } 278 return *m_pImpl->aControlsUseRefDevice; 279 } 280 281 //------------------------------------------------------------------------ 282 void FmFormModel::SetAutoControlFocus( sal_Bool _bAutoControlFocus ) 283 { 284 #ifndef SVX_LIGHT 285 if( _bAutoControlFocus != m_bAutoControlFocus ) 286 { 287 m_bAutoControlFocus = _bAutoControlFocus; 288 m_pObjShell->SetModified( sal_True ); 289 } 290 #endif 291 } 292 293 //------------------------------------------------------------------------ 294 void FmFormModel::SetObjectShell( SfxObjectShell* pShell ) 295 { 296 #ifndef SVX_LIGHT 297 if (pShell == m_pObjShell) 298 return; 299 300 if (m_pObjShell) 301 { 302 m_pImpl->pUndoEnv->EndListening( *this ); 303 m_pImpl->pUndoEnv->EndListening( *m_pObjShell ); 304 } 305 306 m_pObjShell = pShell; 307 308 if (m_pObjShell) 309 { 310 m_pImpl->pUndoEnv->SetReadOnly( m_pObjShell->IsReadOnly() || m_pObjShell->IsReadOnlyUI(), FmXUndoEnvironment::Accessor() ); 311 312 if (!m_pImpl->pUndoEnv->IsReadOnly()) 313 m_pImpl->pUndoEnv->StartListening(*this); 314 315 m_pImpl->pUndoEnv->StartListening( *m_pObjShell ); 316 } 317 #endif 318 } 319 320 //------------------------------------------------------------------------ 321 FmXUndoEnvironment& FmFormModel::GetUndoEnv() 322 { 323 return *m_pImpl->pUndoEnv; 324 } 325