build fix: no comphelper/profilezone.hxx in this branch
[LibreOffice.git] / dbaccess / source / core / recovery / subcomponentloader.cxx
blobfbb9d0b5f0f27fd32d2f08130ced320c033f8edb
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 .
20 #include "subcomponentloader.hxx"
22 #include <com/sun/star/ucb/Command.hpp>
23 #include <com/sun/star/frame/XController2.hpp>
25 #include <tools/diagnose_ex.h>
27 namespace dbaccess
30 using ::com::sun::star::uno::Reference;
31 using ::com::sun::star::uno::UNO_QUERY_THROW;
32 using ::com::sun::star::uno::UNO_SET_THROW;
33 using ::com::sun::star::uno::Exception;
34 using ::com::sun::star::uno::RuntimeException;
35 using ::com::sun::star::frame::XController;
36 using ::com::sun::star::frame::XFrame;
37 using ::com::sun::star::awt::XWindow;
38 using ::com::sun::star::awt::WindowEvent;
39 using ::com::sun::star::lang::EventObject;
40 using ::com::sun::star::ucb::Command;
41 using ::com::sun::star::ucb::XCommandProcessor;
42 using ::com::sun::star::frame::XController2;
43 using ::com::sun::star::lang::XComponent;
45 // SubComponentLoader
46 struct SubComponentLoader_Data
48 const Reference< XCommandProcessor > xDocDefCommands;
49 const Reference< XComponent > xNonDocComponent;
50 Reference< XWindow > xAppComponentWindow;
52 explicit SubComponentLoader_Data( const Reference< XCommandProcessor >& i_rDocumentDefinition )
53 :xDocDefCommands( i_rDocumentDefinition )
54 ,xNonDocComponent()
58 explicit SubComponentLoader_Data( const Reference< XComponent >& i_rNonDocumentComponent )
59 :xDocDefCommands()
60 ,xNonDocComponent( i_rNonDocumentComponent )
65 // helper
66 namespace
68 void lcl_onWindowShown_nothrow( const SubComponentLoader_Data& i_rData )
70 try
72 if ( i_rData.xDocDefCommands.is() )
74 Command aCommandOpen;
75 aCommandOpen.Name = "show";
77 const sal_Int32 nCommandIdentifier = i_rData.xDocDefCommands->createCommandIdentifier();
78 i_rData.xDocDefCommands->execute( aCommandOpen, nCommandIdentifier, nullptr );
80 else
82 const Reference< XController > xController( i_rData.xNonDocComponent, UNO_QUERY_THROW );
83 const Reference< XFrame > xFrame( xController->getFrame(), UNO_SET_THROW );
84 const Reference< XWindow > xWindow( xFrame->getContainerWindow(), UNO_SET_THROW );
85 xWindow->setVisible( true );
88 catch( const Exception& )
90 DBG_UNHANDLED_EXCEPTION();
95 // SubComponentLoader
96 SubComponentLoader::SubComponentLoader( const Reference< XController >& i_rApplicationController,
97 const Reference< XCommandProcessor >& i_rSubDocumentDefinition )
98 :m_pData( new SubComponentLoader_Data( i_rSubDocumentDefinition ) )
100 // add as window listener to the controller's container window, so we get notified when it is shown
101 Reference< XController2 > xController( i_rApplicationController, UNO_QUERY_THROW );
102 m_pData->xAppComponentWindow.set( xController->getComponentWindow(), UNO_SET_THROW );
104 osl_atomic_increment( &m_refCount );
106 m_pData->xAppComponentWindow->addWindowListener( this );
108 osl_atomic_decrement( &m_refCount );
111 SubComponentLoader::SubComponentLoader( const Reference< XController >& i_rApplicationController,
112 const Reference< XComponent >& i_rNonDocumentComponent )
113 :m_pData( new SubComponentLoader_Data( i_rNonDocumentComponent ) )
115 // add as window listener to the controller's container window, so we get notified when it is shown
116 Reference< XController2 > xController( i_rApplicationController, UNO_QUERY_THROW );
117 m_pData->xAppComponentWindow.set( xController->getComponentWindow(), UNO_SET_THROW );
119 osl_atomic_increment( &m_refCount );
121 m_pData->xAppComponentWindow->addWindowListener( this );
123 osl_atomic_decrement( &m_refCount );
126 SubComponentLoader::~SubComponentLoader()
128 delete m_pData;
129 m_pData = nullptr;
132 void SAL_CALL SubComponentLoader::windowResized( const WindowEvent& i_rEvent ) throw (RuntimeException, std::exception)
134 // not interested in
135 (void)i_rEvent;
138 void SAL_CALL SubComponentLoader::windowMoved( const WindowEvent& i_rEvent ) throw (RuntimeException, std::exception)
140 // not interested in
141 (void)i_rEvent;
144 void SAL_CALL SubComponentLoader::windowShown( const EventObject& i_rEvent ) throw (RuntimeException, std::exception)
146 (void)i_rEvent;
148 lcl_onWindowShown_nothrow( *m_pData );
149 m_pData->xAppComponentWindow->removeWindowListener( this );
152 void SAL_CALL SubComponentLoader::windowHidden( const EventObject& i_rEvent ) throw (RuntimeException, std::exception)
154 // not interested in
155 (void)i_rEvent;
158 void SAL_CALL SubComponentLoader::disposing( const EventObject& i_rEvent ) throw (RuntimeException, std::exception)
160 // not interested in
161 (void)i_rEvent;
164 } // namespace dbaccess
166 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */