1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "precompiled_dbaccess.hxx"
25 
26 #include "subcomponentloader.hxx"
27 
28 /** === begin UNO includes === **/
29 #include <com/sun/star/ucb/Command.hpp>
30 #include <com/sun/star/frame/XController2.hpp>
31 /** === end UNO includes === **/
32 
33 #include <tools/diagnose_ex.h>
34 
35 //........................................................................
36 namespace dbaccess
37 {
38 //........................................................................
39 
40 	/** === begin UNO using === **/
41 	using ::com::sun::star::uno::Reference;
42 	using ::com::sun::star::uno::XInterface;
43 	using ::com::sun::star::uno::UNO_QUERY;
44 	using ::com::sun::star::uno::UNO_QUERY_THROW;
45 	using ::com::sun::star::uno::UNO_SET_THROW;
46 	using ::com::sun::star::uno::Exception;
47 	using ::com::sun::star::uno::RuntimeException;
48 	using ::com::sun::star::uno::Any;
49 	using ::com::sun::star::uno::makeAny;
50 	using ::com::sun::star::uno::Sequence;
51 	using ::com::sun::star::uno::Type;
52     using ::com::sun::star::frame::XController;
53     using ::com::sun::star::frame::XFrame;
54     using ::com::sun::star::awt::XWindow;
55     using ::com::sun::star::awt::WindowEvent;
56     using ::com::sun::star::lang::EventObject;
57     using ::com::sun::star::ucb::Command;
58     using ::com::sun::star::ucb::XCommandProcessor;
59     using ::com::sun::star::frame::XController2;
60     using ::com::sun::star::lang::XComponent;
61 	/** === end UNO using === **/
62 
63 	//====================================================================
64 	//= SubComponentLoader
65 	//====================================================================
66     struct DBACCESS_DLLPRIVATE SubComponentLoader_Data
67     {
68         const Reference< XCommandProcessor >    xDocDefCommands;
69         const Reference< XComponent >           xNonDocComponent;
70         Reference< XWindow >                    xAppComponentWindow;
71 
SubComponentLoader_Datadbaccess::SubComponentLoader_Data72         SubComponentLoader_Data( const Reference< XCommandProcessor >& i_rDocumentDefinition )
73             :xDocDefCommands( i_rDocumentDefinition, UNO_SET_THROW )
74             ,xNonDocComponent()
75         {
76         }
77 
SubComponentLoader_Datadbaccess::SubComponentLoader_Data78         SubComponentLoader_Data( const Reference< XComponent >& i_rNonDocumentComponent )
79             :xDocDefCommands()
80             ,xNonDocComponent( i_rNonDocumentComponent, UNO_SET_THROW )
81         {
82         }
83     };
84 
85 	//====================================================================
86 	//= helper
87 	//====================================================================
88     namespace
89     {
90 	    //................................................................
lcl_onWindowShown_nothrow(const SubComponentLoader_Data & i_rData)91         void lcl_onWindowShown_nothrow( const SubComponentLoader_Data& i_rData )
92         {
93             try
94             {
95                 if ( i_rData.xDocDefCommands.is() )
96                 {
97                     Command aCommandOpen;
98                     aCommandOpen.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "show" ) );
99 
100                     const sal_Int32 nCommandIdentifier = i_rData.xDocDefCommands->createCommandIdentifier();
101                     i_rData.xDocDefCommands->execute( aCommandOpen, nCommandIdentifier, NULL );
102                 }
103                 else
104                 {
105                     const Reference< XController > xController( i_rData.xNonDocComponent, UNO_QUERY_THROW );
106                     const Reference< XFrame > xFrame( xController->getFrame(), UNO_SET_THROW );
107                     const Reference< XWindow > xWindow( xFrame->getContainerWindow(), UNO_SET_THROW );
108                     xWindow->setVisible( sal_True );
109                 }
110             }
111             catch( const Exception& )
112             {
113             	DBG_UNHANDLED_EXCEPTION();
114             }
115         }
116     }
117 
118 	//====================================================================
119 	//= SubComponentLoader
120 	//====================================================================
121 	//--------------------------------------------------------------------
SubComponentLoader(const Reference<XController> & i_rApplicationController,const Reference<XCommandProcessor> & i_rSubDocumentDefinition)122     SubComponentLoader::SubComponentLoader( const Reference< XController >& i_rApplicationController,
123             const Reference< XCommandProcessor >& i_rSubDocumentDefinition )
124         :m_pData( new SubComponentLoader_Data( i_rSubDocumentDefinition ) )
125     {
126         // add as window listener to the controller's container window, so we get notified when it is shown
127         Reference< XController2 > xController( i_rApplicationController, UNO_QUERY_THROW );
128         m_pData->xAppComponentWindow.set( xController->getComponentWindow(), UNO_SET_THROW );
129 
130         osl_incrementInterlockedCount( &m_refCount );
131         {
132             m_pData->xAppComponentWindow->addWindowListener( this );
133         }
134         osl_decrementInterlockedCount( &m_refCount );
135     }
136 
137 	//--------------------------------------------------------------------
SubComponentLoader(const Reference<XController> & i_rApplicationController,const Reference<XComponent> & i_rNonDocumentComponent)138     SubComponentLoader::SubComponentLoader( const Reference< XController >& i_rApplicationController,
139             const Reference< XComponent >& i_rNonDocumentComponent )
140         :m_pData( new SubComponentLoader_Data( i_rNonDocumentComponent ) )
141     {
142         // add as window listener to the controller's container window, so we get notified when it is shown
143         Reference< XController2 > xController( i_rApplicationController, UNO_QUERY_THROW );
144         m_pData->xAppComponentWindow.set( xController->getComponentWindow(), UNO_SET_THROW );
145 
146         osl_incrementInterlockedCount( &m_refCount );
147         {
148             m_pData->xAppComponentWindow->addWindowListener( this );
149         }
150         osl_decrementInterlockedCount( &m_refCount );
151     }
152 
153 	//--------------------------------------------------------------------
~SubComponentLoader()154     SubComponentLoader::~SubComponentLoader()
155     {
156         delete m_pData, m_pData = NULL;
157     }
158 
159     //--------------------------------------------------------------------
windowResized(const WindowEvent & i_rEvent)160     void SAL_CALL SubComponentLoader::windowResized( const WindowEvent& i_rEvent ) throw (RuntimeException)
161     {
162         // not interested in
163         (void)i_rEvent;
164     }
165 
166     //--------------------------------------------------------------------
windowMoved(const WindowEvent & i_rEvent)167     void SAL_CALL SubComponentLoader::windowMoved( const WindowEvent& i_rEvent ) throw (RuntimeException)
168     {
169         // not interested in
170         (void)i_rEvent;
171     }
172 
173     //--------------------------------------------------------------------
windowShown(const EventObject & i_rEvent)174     void SAL_CALL SubComponentLoader::windowShown( const EventObject& i_rEvent ) throw (RuntimeException)
175     {
176         (void)i_rEvent;
177 
178         lcl_onWindowShown_nothrow( *m_pData );
179         m_pData->xAppComponentWindow->removeWindowListener( this );
180     }
181 
182     //--------------------------------------------------------------------
windowHidden(const EventObject & i_rEvent)183     void SAL_CALL SubComponentLoader::windowHidden( const EventObject& i_rEvent ) throw (RuntimeException)
184     {
185         // not interested in
186         (void)i_rEvent;
187     }
188 
189     //--------------------------------------------------------------------
disposing(const EventObject & i_rEvent)190     void SAL_CALL SubComponentLoader::disposing( const EventObject& i_rEvent ) throw (RuntimeException)
191     {
192         // not interested in
193         (void)i_rEvent;
194     }
195 
196 //........................................................................
197 } // namespace dbaccess
198 //........................................................................
199