1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <comphelper/diagnose_ex.hxx>
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::frame::XController
;
35 using ::com::sun::star::frame::XFrame
;
36 using ::com::sun::star::awt::XWindow
;
37 using ::com::sun::star::awt::WindowEvent
;
38 using ::com::sun::star::lang::EventObject
;
39 using ::com::sun::star::ucb::Command
;
40 using ::com::sun::star::ucb::XCommandProcessor
;
41 using ::com::sun::star::frame::XController2
;
42 using ::com::sun::star::lang::XComponent
;
45 SubComponentLoader::SubComponentLoader( const Reference
< XController
>& i_rApplicationController
,
46 const Reference
< XCommandProcessor
>& i_rSubDocumentDefinition
)
47 :mxDocDefCommands( i_rSubDocumentDefinition
)
49 // add as window listener to the controller's container window, so we get notified when it is shown
50 Reference
< XController2
> xController( i_rApplicationController
, UNO_QUERY_THROW
);
51 mxAppComponentWindow
.set( xController
->getComponentWindow(), UNO_SET_THROW
);
53 osl_atomic_increment( &m_refCount
);
55 mxAppComponentWindow
->addWindowListener( this );
57 osl_atomic_decrement( &m_refCount
);
60 SubComponentLoader::SubComponentLoader( const Reference
< XController
>& i_rApplicationController
,
61 const Reference
< XComponent
>& i_rNonDocumentComponent
)
62 :mxNonDocComponent( i_rNonDocumentComponent
)
64 // add as window listener to the controller's container window, so we get notified when it is shown
65 Reference
< XController2
> xController( i_rApplicationController
, UNO_QUERY_THROW
);
66 mxAppComponentWindow
.set( xController
->getComponentWindow(), UNO_SET_THROW
);
68 osl_atomic_increment( &m_refCount
);
70 mxAppComponentWindow
->addWindowListener( this );
72 osl_atomic_decrement( &m_refCount
);
75 SubComponentLoader::~SubComponentLoader()
79 void SAL_CALL
SubComponentLoader::windowResized( const WindowEvent
& )
83 void SAL_CALL
SubComponentLoader::windowMoved( const WindowEvent
& )
87 void SAL_CALL
SubComponentLoader::windowShown( const EventObject
& )
91 if ( mxDocDefCommands
.is() )
94 aCommandOpen
.Name
= "show";
96 const sal_Int32 nCommandIdentifier
= mxDocDefCommands
->createCommandIdentifier();
97 mxDocDefCommands
->execute( aCommandOpen
, nCommandIdentifier
, nullptr );
101 const Reference
< XController
> xController( mxNonDocComponent
, UNO_QUERY_THROW
);
102 const Reference
< XFrame
> xFrame( xController
->getFrame(), UNO_SET_THROW
);
103 const Reference
< XWindow
> xWindow( xFrame
->getContainerWindow(), UNO_SET_THROW
);
104 xWindow
->setVisible( true );
107 catch( const Exception
& )
109 DBG_UNHANDLED_EXCEPTION("dbaccess");
111 mxAppComponentWindow
->removeWindowListener( this );
114 void SAL_CALL
SubComponentLoader::windowHidden( const EventObject
& )
118 void SAL_CALL
SubComponentLoader::disposing( const EventObject
& )
122 } // namespace dbaccess
124 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */