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