Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / dbaccess / source / core / recovery / subcomponentloader.cxx
blob7238b39930e835b01522e46401be2a93b5648dcd
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "subcomponentloader.hxx"
23 #include <com/sun/star/ucb/Command.hpp>
24 #include <com/sun/star/frame/XController2.hpp>
26 #include <tools/diagnose_ex.h>
28 //........................................................................
29 namespace dbaccess
31 //........................................................................
33 /** === begin UNO using === **/
34 using ::com::sun::star::uno::Reference;
35 using ::com::sun::star::uno::XInterface;
36 using ::com::sun::star::uno::UNO_QUERY;
37 using ::com::sun::star::uno::UNO_QUERY_THROW;
38 using ::com::sun::star::uno::UNO_SET_THROW;
39 using ::com::sun::star::uno::Exception;
40 using ::com::sun::star::uno::RuntimeException;
41 using ::com::sun::star::uno::Any;
42 using ::com::sun::star::uno::makeAny;
43 using ::com::sun::star::uno::Sequence;
44 using ::com::sun::star::uno::Type;
45 using ::com::sun::star::frame::XController;
46 using ::com::sun::star::frame::XFrame;
47 using ::com::sun::star::awt::XWindow;
48 using ::com::sun::star::awt::WindowEvent;
49 using ::com::sun::star::lang::EventObject;
50 using ::com::sun::star::ucb::Command;
51 using ::com::sun::star::ucb::XCommandProcessor;
52 using ::com::sun::star::frame::XController2;
53 using ::com::sun::star::lang::XComponent;
54 /** === end UNO using === **/
56 //====================================================================
57 //= SubComponentLoader
58 //====================================================================
59 struct DBACCESS_DLLPRIVATE SubComponentLoader_Data
61 const Reference< XCommandProcessor > xDocDefCommands;
62 const Reference< XComponent > xNonDocComponent;
63 Reference< XWindow > xAppComponentWindow;
65 SubComponentLoader_Data( const Reference< XCommandProcessor >& i_rDocumentDefinition )
66 :xDocDefCommands( i_rDocumentDefinition, UNO_SET_THROW )
67 ,xNonDocComponent()
71 SubComponentLoader_Data( const Reference< XComponent >& i_rNonDocumentComponent )
72 :xDocDefCommands()
73 ,xNonDocComponent( i_rNonDocumentComponent, UNO_SET_THROW )
78 //====================================================================
79 //= helper
80 //====================================================================
81 namespace
83 //................................................................
84 void lcl_onWindowShown_nothrow( const SubComponentLoader_Data& i_rData )
86 try
88 if ( i_rData.xDocDefCommands.is() )
90 Command aCommandOpen;
91 aCommandOpen.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "show" ) );
93 const sal_Int32 nCommandIdentifier = i_rData.xDocDefCommands->createCommandIdentifier();
94 i_rData.xDocDefCommands->execute( aCommandOpen, nCommandIdentifier, NULL );
96 else
98 const Reference< XController > xController( i_rData.xNonDocComponent, UNO_QUERY_THROW );
99 const Reference< XFrame > xFrame( xController->getFrame(), UNO_SET_THROW );
100 const Reference< XWindow > xWindow( xFrame->getContainerWindow(), UNO_SET_THROW );
101 xWindow->setVisible( sal_True );
104 catch( const Exception& )
106 DBG_UNHANDLED_EXCEPTION();
111 //====================================================================
112 //= SubComponentLoader
113 //====================================================================
114 //--------------------------------------------------------------------
115 SubComponentLoader::SubComponentLoader( const Reference< XController >& i_rApplicationController,
116 const Reference< XCommandProcessor >& i_rSubDocumentDefinition )
117 :m_pData( new SubComponentLoader_Data( i_rSubDocumentDefinition ) )
119 // add as window listener to the controller's container window, so we get notified when it is shown
120 Reference< XController2 > xController( i_rApplicationController, UNO_QUERY_THROW );
121 m_pData->xAppComponentWindow.set( xController->getComponentWindow(), UNO_SET_THROW );
123 osl_atomic_increment( &m_refCount );
125 m_pData->xAppComponentWindow->addWindowListener( this );
127 osl_atomic_decrement( &m_refCount );
130 //--------------------------------------------------------------------
131 SubComponentLoader::SubComponentLoader( const Reference< XController >& i_rApplicationController,
132 const Reference< XComponent >& i_rNonDocumentComponent )
133 :m_pData( new SubComponentLoader_Data( i_rNonDocumentComponent ) )
135 // add as window listener to the controller's container window, so we get notified when it is shown
136 Reference< XController2 > xController( i_rApplicationController, UNO_QUERY_THROW );
137 m_pData->xAppComponentWindow.set( xController->getComponentWindow(), UNO_SET_THROW );
139 osl_atomic_increment( &m_refCount );
141 m_pData->xAppComponentWindow->addWindowListener( this );
143 osl_atomic_decrement( &m_refCount );
146 //--------------------------------------------------------------------
147 SubComponentLoader::~SubComponentLoader()
149 delete m_pData, m_pData = NULL;
152 //--------------------------------------------------------------------
153 void SAL_CALL SubComponentLoader::windowResized( const WindowEvent& i_rEvent ) throw (RuntimeException)
155 // not interested in
156 (void)i_rEvent;
159 //--------------------------------------------------------------------
160 void SAL_CALL SubComponentLoader::windowMoved( const WindowEvent& i_rEvent ) throw (RuntimeException)
162 // not interested in
163 (void)i_rEvent;
166 //--------------------------------------------------------------------
167 void SAL_CALL SubComponentLoader::windowShown( const EventObject& i_rEvent ) throw (RuntimeException)
169 (void)i_rEvent;
171 lcl_onWindowShown_nothrow( *m_pData );
172 m_pData->xAppComponentWindow->removeWindowListener( this );
175 //--------------------------------------------------------------------
176 void SAL_CALL SubComponentLoader::windowHidden( const EventObject& i_rEvent ) throw (RuntimeException)
178 // not interested in
179 (void)i_rEvent;
182 //--------------------------------------------------------------------
183 void SAL_CALL SubComponentLoader::disposing( const EventObject& i_rEvent ) throw (RuntimeException)
185 // not interested in
186 (void)i_rEvent;
189 //........................................................................
190 } // namespace dbaccess
191 //........................................................................
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */