bump product version to 4.1.6.2
[LibreOffice.git] / dbaccess / source / core / recovery / subcomponentloader.cxx
blob85ae960dea4af895b4f800774d191e306985455c
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 using ::com::sun::star::uno::Reference;
34 using ::com::sun::star::uno::XInterface;
35 using ::com::sun::star::uno::UNO_QUERY;
36 using ::com::sun::star::uno::UNO_QUERY_THROW;
37 using ::com::sun::star::uno::UNO_SET_THROW;
38 using ::com::sun::star::uno::Exception;
39 using ::com::sun::star::uno::RuntimeException;
40 using ::com::sun::star::uno::Any;
41 using ::com::sun::star::uno::makeAny;
42 using ::com::sun::star::uno::Sequence;
43 using ::com::sun::star::uno::Type;
44 using ::com::sun::star::frame::XController;
45 using ::com::sun::star::frame::XFrame;
46 using ::com::sun::star::awt::XWindow;
47 using ::com::sun::star::awt::WindowEvent;
48 using ::com::sun::star::lang::EventObject;
49 using ::com::sun::star::ucb::Command;
50 using ::com::sun::star::ucb::XCommandProcessor;
51 using ::com::sun::star::frame::XController2;
52 using ::com::sun::star::lang::XComponent;
54 //====================================================================
55 //= SubComponentLoader
56 //====================================================================
57 struct DBACCESS_DLLPRIVATE SubComponentLoader_Data
59 const Reference< XCommandProcessor > xDocDefCommands;
60 const Reference< XComponent > xNonDocComponent;
61 Reference< XWindow > xAppComponentWindow;
63 SubComponentLoader_Data( const Reference< XCommandProcessor >& i_rDocumentDefinition )
64 :xDocDefCommands( i_rDocumentDefinition, UNO_SET_THROW )
65 ,xNonDocComponent()
69 SubComponentLoader_Data( const Reference< XComponent >& i_rNonDocumentComponent )
70 :xDocDefCommands()
71 ,xNonDocComponent( i_rNonDocumentComponent, UNO_SET_THROW )
76 //====================================================================
77 //= helper
78 //====================================================================
79 namespace
81 //................................................................
82 void lcl_onWindowShown_nothrow( const SubComponentLoader_Data& i_rData )
84 try
86 if ( i_rData.xDocDefCommands.is() )
88 Command aCommandOpen;
89 aCommandOpen.Name = "show";
91 const sal_Int32 nCommandIdentifier = i_rData.xDocDefCommands->createCommandIdentifier();
92 i_rData.xDocDefCommands->execute( aCommandOpen, nCommandIdentifier, NULL );
94 else
96 const Reference< XController > xController( i_rData.xNonDocComponent, UNO_QUERY_THROW );
97 const Reference< XFrame > xFrame( xController->getFrame(), UNO_SET_THROW );
98 const Reference< XWindow > xWindow( xFrame->getContainerWindow(), UNO_SET_THROW );
99 xWindow->setVisible( sal_True );
102 catch( const Exception& )
104 DBG_UNHANDLED_EXCEPTION();
109 //====================================================================
110 //= SubComponentLoader
111 //====================================================================
112 //--------------------------------------------------------------------
113 SubComponentLoader::SubComponentLoader( const Reference< XController >& i_rApplicationController,
114 const Reference< XCommandProcessor >& i_rSubDocumentDefinition )
115 :m_pData( new SubComponentLoader_Data( i_rSubDocumentDefinition ) )
117 // add as window listener to the controller's container window, so we get notified when it is shown
118 Reference< XController2 > xController( i_rApplicationController, UNO_QUERY_THROW );
119 m_pData->xAppComponentWindow.set( xController->getComponentWindow(), UNO_SET_THROW );
121 osl_atomic_increment( &m_refCount );
123 m_pData->xAppComponentWindow->addWindowListener( this );
125 osl_atomic_decrement( &m_refCount );
128 //--------------------------------------------------------------------
129 SubComponentLoader::SubComponentLoader( const Reference< XController >& i_rApplicationController,
130 const Reference< XComponent >& i_rNonDocumentComponent )
131 :m_pData( new SubComponentLoader_Data( i_rNonDocumentComponent ) )
133 // add as window listener to the controller's container window, so we get notified when it is shown
134 Reference< XController2 > xController( i_rApplicationController, UNO_QUERY_THROW );
135 m_pData->xAppComponentWindow.set( xController->getComponentWindow(), UNO_SET_THROW );
137 osl_atomic_increment( &m_refCount );
139 m_pData->xAppComponentWindow->addWindowListener( this );
141 osl_atomic_decrement( &m_refCount );
144 //--------------------------------------------------------------------
145 SubComponentLoader::~SubComponentLoader()
147 delete m_pData, m_pData = NULL;
150 //--------------------------------------------------------------------
151 void SAL_CALL SubComponentLoader::windowResized( const WindowEvent& i_rEvent ) throw (RuntimeException)
153 // not interested in
154 (void)i_rEvent;
157 //--------------------------------------------------------------------
158 void SAL_CALL SubComponentLoader::windowMoved( const WindowEvent& i_rEvent ) throw (RuntimeException)
160 // not interested in
161 (void)i_rEvent;
164 //--------------------------------------------------------------------
165 void SAL_CALL SubComponentLoader::windowShown( const EventObject& i_rEvent ) throw (RuntimeException)
167 (void)i_rEvent;
169 lcl_onWindowShown_nothrow( *m_pData );
170 m_pData->xAppComponentWindow->removeWindowListener( this );
173 //--------------------------------------------------------------------
174 void SAL_CALL SubComponentLoader::windowHidden( const EventObject& i_rEvent ) throw (RuntimeException)
176 // not interested in
177 (void)i_rEvent;
180 //--------------------------------------------------------------------
181 void SAL_CALL SubComponentLoader::disposing( const EventObject& i_rEvent ) throw (RuntimeException)
183 // not interested in
184 (void)i_rEvent;
187 //........................................................................
188 } // namespace dbaccess
189 //........................................................................
191 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */