merge the formfield patch from ooo-build
[ooovba.git] / dbaccess / source / ui / misc / documentcontroller.cxx
blob34132b99c6aa21b696a7c6d1cd9452a43f0ae61c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: documentcontroller.cxx,v $
10 * $Revision: 1.5.178.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
34 #include "documentcontroller.hxx"
36 /** === begin UNO includes === **/
37 /** === end UNO includes === **/
39 #include <tools/debug.hxx>
40 #include <tools/diagnose_ex.h>
42 //........................................................................
43 namespace dbaui
45 //........................................................................
47 using namespace ::com::sun::star::uno;
48 using namespace ::com::sun::star::frame;
50 //====================================================================
51 //= ModelControllerConnector
52 //====================================================================
53 DBG_NAME( ModelControllerConnector )
54 //--------------------------------------------------------------------
55 ModelControllerConnector::ModelControllerConnector()
57 DBG_CTOR( ModelControllerConnector, NULL );
60 //--------------------------------------------------------------------
61 ModelControllerConnector::ModelControllerConnector( const Reference< XModel >& _rxModel, const Reference< XController >& _rxController )
62 :m_xModel( _rxModel )
63 ,m_xController( _rxController )
65 DBG_CTOR( ModelControllerConnector, NULL );
66 DBG_ASSERT( _rxModel.is() && m_xController.is(), "ModelControllerConnector::ModelControllerConnector: invalid model or controller!" );
67 impl_connect();
70 //--------------------------------------------------------------------
71 ModelControllerConnector::ModelControllerConnector( const ModelControllerConnector& _rSource )
73 DBG_CTOR( ModelControllerConnector, NULL );
74 impl_copyFrom( _rSource );
77 //--------------------------------------------------------------------
78 ModelControllerConnector& ModelControllerConnector::operator=( const ModelControllerConnector& _rSource )
80 if ( this != &_rSource )
81 impl_copyFrom( _rSource );
82 return *this;
85 //--------------------------------------------------------------------
86 void ModelControllerConnector::connect( const Reference< XModel >& _rxModel, const Reference< XController >& _rxController )
88 impl_disconnect();
90 m_xModel = _rxModel;
91 m_xController = _rxController;
93 impl_connect();
96 //--------------------------------------------------------------------
97 void ModelControllerConnector::impl_copyFrom( const ModelControllerConnector& _rSource )
99 Model aNewModel( _rSource.m_xModel );
100 Controller aNewController( _rSource.m_xController );
102 impl_disconnect();
104 m_xModel = aNewModel;
105 m_xController = aNewController;
107 impl_connect();
110 //--------------------------------------------------------------------
111 ModelControllerConnector::~ModelControllerConnector()
113 impl_disconnect();
114 DBG_DTOR( ModelControllerConnector, NULL );
117 //--------------------------------------------------------------------
118 void ModelControllerConnector::impl_connect()
122 Reference< XModel > xModel = m_xModel;
123 if ( xModel.is() && m_xController.is() )
124 xModel->connectController( m_xController );
126 catch( const Exception& )
128 DBG_UNHANDLED_EXCEPTION();
132 //--------------------------------------------------------------------
133 void ModelControllerConnector::impl_disconnect()
137 Reference< XModel > xModel = m_xModel;
138 if ( xModel.is() && m_xController.is() )
139 xModel->disconnectController( m_xController );
141 catch( const Exception& )
143 DBG_UNHANDLED_EXCEPTION();
147 //........................................................................
148 } // namespace dbaui
149 //........................................................................