1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_svx.hxx" 30 31 #include "fmundo.hxx" 32 #include "fmdocumentclassification.hxx" 33 #include "fmcontrollayout.hxx" 34 35 #include <svx/fmmodel.hxx> 36 #include <svx/fmpage.hxx> 37 #include <svx/svdobj.hxx> 38 #include <tools/debug.hxx> 39 40 #ifndef SVX_LIGHT 41 #include <sfx2/objsh.hxx> 42 #else 43 class SfxObjectShell; 44 #endif 45 46 #include <boost/optional.hpp> 47 48 using ::com::sun::star::uno::Reference; 49 using ::com::sun::star::container::XNameContainer; 50 using namespace svxform; 51 52 TYPEINIT1(FmFormModel, SdrModel); 53 54 struct FmFormModelImplData 55 { 56 FmXUndoEnvironment* pUndoEnv; 57 sal_Bool bOpenInDesignIsDefaulted; 58 sal_Bool bMovingPage; 59 ::boost::optional< sal_Bool > 60 aControlsUseRefDevice; 61 62 FmFormModelImplData() 63 :pUndoEnv( NULL ) 64 ,bOpenInDesignIsDefaulted( sal_True ) 65 ,bMovingPage( sal_False ) 66 ,aControlsUseRefDevice() 67 { 68 } 69 }; 70 71 /************************************************************************* 72 |* 73 |* Ctor 74 |* 75 \************************************************************************/ 76 FmFormModel::FmFormModel(SfxItemPool* pPool, SfxObjectShell* pPers) 77 :SdrModel(pPool, pPers, LOADREFCOUNTS) 78 ,m_pImpl(NULL) 79 ,m_pObjShell(0) 80 ,m_bOpenInDesignMode(sal_False) 81 ,m_bAutoControlFocus(sal_False) 82 { 83 #ifndef SVX_LIGHT 84 m_pImpl = new FmFormModelImplData; 85 m_pImpl->pUndoEnv = new FmXUndoEnvironment(*this); 86 m_pImpl->pUndoEnv->acquire(); 87 #endif 88 } 89 90 /************************************************************************* 91 |* 92 |* Ctor 93 |* 94 \************************************************************************/ 95 FmFormModel::FmFormModel(const XubString& rPath, SfxItemPool* pPool, SfxObjectShell* pPers) 96 :SdrModel(rPath, pPool, pPers) 97 ,m_pImpl(NULL) 98 ,m_pObjShell(0) 99 ,m_bOpenInDesignMode(sal_False) 100 ,m_bAutoControlFocus(sal_False) 101 { 102 #ifndef SVX_LIGHT 103 m_pImpl = new FmFormModelImplData; 104 m_pImpl->pUndoEnv = new FmXUndoEnvironment(*this); 105 m_pImpl->pUndoEnv->acquire(); 106 #endif 107 } 108 109 /************************************************************************* 110 |* 111 |* Ctor 112 |* 113 \************************************************************************/ 114 FmFormModel::FmFormModel(SfxItemPool* pPool, SfxObjectShell* pPers, 115 FASTBOOL bUseExtColorTable 116 ) 117 :SdrModel(pPool, pPers, bUseExtColorTable, LOADREFCOUNTS) 118 ,m_pImpl(NULL) 119 ,m_pObjShell(0) 120 ,m_bOpenInDesignMode(sal_False) 121 ,m_bAutoControlFocus(sal_False) 122 { 123 #ifndef SVX_LIGHT 124 m_pImpl = new FmFormModelImplData; 125 m_pImpl->pUndoEnv = new FmXUndoEnvironment(*this); 126 m_pImpl->pUndoEnv->acquire(); 127 #endif 128 } 129 130 /************************************************************************* 131 |* 132 |* Ctor 133 |* 134 \************************************************************************/ 135 FmFormModel::FmFormModel(const XubString& rPath, SfxItemPool* pPool, SfxObjectShell* pPers, 136 FASTBOOL bUseExtColorTable) 137 :SdrModel(rPath, pPool, pPers, bUseExtColorTable, LOADREFCOUNTS) 138 ,m_pImpl( NULL ) 139 ,m_pObjShell(0) 140 ,m_bOpenInDesignMode(sal_False) 141 ,m_bAutoControlFocus(sal_False) 142 { 143 #ifndef SVX_LIGHT 144 m_pImpl = new FmFormModelImplData; 145 m_pImpl->pUndoEnv = new FmXUndoEnvironment(*this); 146 m_pImpl->pUndoEnv->acquire(); 147 #endif 148 } 149 150 /************************************************************************* 151 |* 152 |* Dtor 153 |* 154 \************************************************************************/ 155 FmFormModel::~FmFormModel() 156 { 157 #ifndef SVX_LIGHT 158 if (m_pObjShell && m_pImpl->pUndoEnv->IsListening(*m_pObjShell)) 159 SetObjectShell(NULL); 160 161 ClearUndoBuffer(); 162 // minimale grenze fuer undos 163 SetMaxUndoActionCount(1); 164 165 m_pImpl->pUndoEnv->release(); 166 delete m_pImpl; 167 168 #endif 169 } 170 171 /************************************************************************* 172 |* 173 |* Erzeugt eine neue Seite 174 |* 175 \************************************************************************/ 176 SdrPage* FmFormModel::AllocPage(FASTBOOL bMasterPage) 177 { 178 return new FmFormPage(*this, NULL, bMasterPage); 179 } 180 181 /************************************************************************* 182 |* 183 |* InsertPage 184 |* 185 \************************************************************************/ 186 void FmFormModel::InsertPage(SdrPage* pPage, sal_uInt16 nPos) 187 { 188 #ifndef SVX_LIGHT 189 // hack solange Methode intern 190 if (m_pObjShell && !m_pImpl->pUndoEnv->IsListening( *m_pObjShell )) 191 SetObjectShell(m_pObjShell); 192 #endif 193 194 SdrModel::InsertPage( pPage, nPos ); 195 } 196 197 /************************************************************************* 198 |* 199 |* MovePage 200 |* 201 \************************************************************************/ 202 void FmFormModel::MovePage( sal_uInt16 nPgNum, sal_uInt16 nNewPos ) 203 { 204 #ifndef SVX_LIGHT 205 m_pImpl->bMovingPage = sal_True; 206 // see InsertPage for this 207 #endif 208 209 SdrModel::MovePage( nPgNum, nNewPos ); 210 211 #ifndef SVX_LIGHT 212 m_pImpl->bMovingPage = sal_False; 213 #endif 214 } 215 216 /************************************************************************* 217 |* 218 |* RemovePage 219 |* 220 \************************************************************************/ 221 SdrPage* FmFormModel::RemovePage(sal_uInt16 nPgNum) 222 { 223 FmFormPage* pToBeRemovedPage = dynamic_cast< FmFormPage* >( GetPage( nPgNum ) ); 224 OSL_ENSURE( pToBeRemovedPage, "FmFormModel::RemovePage: *which page*?" ); 225 226 #ifndef SVX_LIGHT 227 if ( pToBeRemovedPage ) 228 { 229 Reference< XNameContainer > xForms( pToBeRemovedPage->GetForms( false ) ); 230 if ( xForms.is() ) 231 m_pImpl->pUndoEnv->RemoveForms( xForms ); 232 } 233 #endif 234 235 FmFormPage* pRemovedPage = (FmFormPage*)SdrModel::RemovePage(nPgNum); 236 OSL_ENSURE( pRemovedPage == pToBeRemovedPage, "FmFormModel::RemovePage: inconsistency!" ); 237 return pRemovedPage; 238 } 239 240 /************************************************************************* 241 |* 242 |* InsertMasterPage 243 |* 244 \************************************************************************/ 245 void FmFormModel::InsertMasterPage(SdrPage* pPage, sal_uInt16 nPos) 246 { 247 #ifndef SVX_LIGHT 248 // hack solange Methode intern 249 if (m_pObjShell && !m_pImpl->pUndoEnv->IsListening( *m_pObjShell )) 250 SetObjectShell(m_pObjShell); 251 #endif 252 253 SdrModel::InsertMasterPage(pPage, nPos); 254 } 255 256 /************************************************************************* 257 |* 258 |* RemoveMasterPage 259 |* 260 \************************************************************************/ 261 SdrPage* FmFormModel::RemoveMasterPage(sal_uInt16 nPgNum) 262 { 263 FmFormPage* pPage = (FmFormPage*)SdrModel::RemoveMasterPage(nPgNum); 264 265 #ifndef SVX_LIGHT 266 if ( pPage ) 267 { 268 Reference< XNameContainer > xForms( pPage->GetForms( false ) ); 269 if ( xForms.is() ) 270 m_pImpl->pUndoEnv->RemoveForms( xForms ); 271 } 272 #endif 273 274 return pPage; 275 } 276 277 //------------------------------------------------------------------------ 278 SdrLayerID FmFormModel::GetControlExportLayerId( const SdrObject& rObj ) const 279 { 280 return rObj.GetLayer(); 281 } 282 283 //------------------------------------------------------------------------ 284 void FmFormModel::implSetOpenInDesignMode( sal_Bool _bOpenDesignMode, sal_Bool _bForce ) 285 { 286 if( ( _bOpenDesignMode != m_bOpenInDesignMode ) || _bForce ) 287 { 288 m_bOpenInDesignMode = _bOpenDesignMode; 289 290 if ( m_pObjShell ) 291 m_pObjShell->SetModified( sal_True ); 292 } 293 // no matter if we really did it or not - from now on, it does not count as defaulted anymore 294 m_pImpl->bOpenInDesignIsDefaulted = sal_False; 295 } 296 297 //------------------------------------------------------------------------ 298 void FmFormModel::SetOpenInDesignMode( sal_Bool bOpenDesignMode ) 299 { 300 #ifndef SVX_LIGHT 301 implSetOpenInDesignMode( bOpenDesignMode, sal_False ); 302 #endif 303 } 304 305 #ifndef SVX_LIGHT 306 //------------------------------------------------------------------------ 307 sal_Bool FmFormModel::OpenInDesignModeIsDefaulted( ) 308 { 309 return m_pImpl->bOpenInDesignIsDefaulted; 310 } 311 #endif 312 313 //------------------------------------------------------------------------ 314 sal_Bool FmFormModel::ControlsUseRefDevice() const 315 { 316 if ( !m_pImpl->aControlsUseRefDevice ) 317 { 318 DocumentType eDocType = eUnknownDocumentType; 319 if ( m_pObjShell ) 320 eDocType = DocumentClassification::classifyHostDocument( m_pObjShell->GetModel() ); 321 m_pImpl->aControlsUseRefDevice.reset( ControlLayouter::useDocumentReferenceDevice( eDocType ) ); 322 } 323 return *m_pImpl->aControlsUseRefDevice; 324 } 325 326 //------------------------------------------------------------------------ 327 void FmFormModel::SetAutoControlFocus( sal_Bool _bAutoControlFocus ) 328 { 329 #ifndef SVX_LIGHT 330 if( _bAutoControlFocus != m_bAutoControlFocus ) 331 { 332 m_bAutoControlFocus = _bAutoControlFocus; 333 m_pObjShell->SetModified( sal_True ); 334 } 335 #endif 336 } 337 338 //------------------------------------------------------------------------ 339 void FmFormModel::SetObjectShell( SfxObjectShell* pShell ) 340 { 341 #ifndef SVX_LIGHT 342 if (pShell == m_pObjShell) 343 return; 344 345 if (m_pObjShell) 346 { 347 m_pImpl->pUndoEnv->EndListening( *this ); 348 m_pImpl->pUndoEnv->EndListening( *m_pObjShell ); 349 } 350 351 m_pObjShell = pShell; 352 353 if (m_pObjShell) 354 { 355 m_pImpl->pUndoEnv->SetReadOnly( m_pObjShell->IsReadOnly() || m_pObjShell->IsReadOnlyUI(), FmXUndoEnvironment::Accessor() ); 356 357 if (!m_pImpl->pUndoEnv->IsReadOnly()) 358 m_pImpl->pUndoEnv->StartListening(*this); 359 360 m_pImpl->pUndoEnv->StartListening( *m_pObjShell ); 361 } 362 #endif 363 } 364 365 //------------------------------------------------------------------------ 366 FmXUndoEnvironment& FmFormModel::GetUndoEnv() 367 { 368 return *m_pImpl->pUndoEnv; 369 } 370