1 /************************************************************************* 2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * 4 * Copyright 2009 by Sun Microsystems, Inc. 5 * 6 * OpenOffice.org - a multi-platform office productivity suite 7 * 8 * This file is part of OpenOffice.org. 9 * 10 * OpenOffice.org is free software: you can redistribute it and/or modify 11 * it under the terms of the GNU Lesser General Public License version 3 12 * only, as published by the Free Software Foundation. 13 * 14 * OpenOffice.org is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU Lesser General Public License version 3 for more details 18 * (a copy is included in the LICENSE file that accompanied this code). 19 * 20 * You should have received a copy of the GNU Lesser General Public License 21 * version 3 along with OpenOffice.org. If not, see 22 * <http://www.openoffice.org/license.html> 23 * for a copy of the LGPLv3 License. 24 ************************************************************************/ 25 26 #include "precompiled_dbaccess.hxx" 27 28 #include "subcomponentloader.hxx" 29 30 /** === begin UNO includes === **/ 31 #include <com/sun/star/ucb/Command.hpp> 32 #include <com/sun/star/frame/XController2.hpp> 33 /** === end UNO includes === **/ 34 35 #include <tools/diagnose_ex.h> 36 37 //........................................................................ 38 namespace dbaccess 39 { 40 //........................................................................ 41 42 /** === begin UNO using === **/ 43 using ::com::sun::star::uno::Reference; 44 using ::com::sun::star::uno::XInterface; 45 using ::com::sun::star::uno::UNO_QUERY; 46 using ::com::sun::star::uno::UNO_QUERY_THROW; 47 using ::com::sun::star::uno::UNO_SET_THROW; 48 using ::com::sun::star::uno::Exception; 49 using ::com::sun::star::uno::RuntimeException; 50 using ::com::sun::star::uno::Any; 51 using ::com::sun::star::uno::makeAny; 52 using ::com::sun::star::uno::Sequence; 53 using ::com::sun::star::uno::Type; 54 using ::com::sun::star::frame::XController; 55 using ::com::sun::star::frame::XFrame; 56 using ::com::sun::star::awt::XWindow; 57 using ::com::sun::star::awt::WindowEvent; 58 using ::com::sun::star::lang::EventObject; 59 using ::com::sun::star::ucb::Command; 60 using ::com::sun::star::ucb::XCommandProcessor; 61 using ::com::sun::star::frame::XController2; 62 using ::com::sun::star::lang::XComponent; 63 /** === end UNO using === **/ 64 65 //==================================================================== 66 //= SubComponentLoader 67 //==================================================================== 68 struct DBACCESS_DLLPRIVATE SubComponentLoader_Data 69 { 70 const Reference< XCommandProcessor > xDocDefCommands; 71 const Reference< XComponent > xNonDocComponent; 72 Reference< XWindow > xAppComponentWindow; 73 74 SubComponentLoader_Data( const Reference< XCommandProcessor >& i_rDocumentDefinition ) 75 :xDocDefCommands( i_rDocumentDefinition, UNO_SET_THROW ) 76 ,xNonDocComponent() 77 { 78 } 79 80 SubComponentLoader_Data( const Reference< XComponent >& i_rNonDocumentComponent ) 81 :xDocDefCommands() 82 ,xNonDocComponent( i_rNonDocumentComponent, UNO_SET_THROW ) 83 { 84 } 85 }; 86 87 //==================================================================== 88 //= helper 89 //==================================================================== 90 namespace 91 { 92 //................................................................ 93 void lcl_onWindowShown_nothrow( const SubComponentLoader_Data& i_rData ) 94 { 95 try 96 { 97 if ( i_rData.xDocDefCommands.is() ) 98 { 99 Command aCommandOpen; 100 aCommandOpen.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "show" ) ); 101 102 const sal_Int32 nCommandIdentifier = i_rData.xDocDefCommands->createCommandIdentifier(); 103 i_rData.xDocDefCommands->execute( aCommandOpen, nCommandIdentifier, NULL ); 104 } 105 else 106 { 107 const Reference< XController > xController( i_rData.xNonDocComponent, UNO_QUERY_THROW ); 108 const Reference< XFrame > xFrame( xController->getFrame(), UNO_SET_THROW ); 109 const Reference< XWindow > xWindow( xFrame->getContainerWindow(), UNO_SET_THROW ); 110 xWindow->setVisible( sal_True ); 111 } 112 } 113 catch( const Exception& ) 114 { 115 DBG_UNHANDLED_EXCEPTION(); 116 } 117 } 118 } 119 120 //==================================================================== 121 //= SubComponentLoader 122 //==================================================================== 123 //-------------------------------------------------------------------- 124 SubComponentLoader::SubComponentLoader( const Reference< XController >& i_rApplicationController, 125 const Reference< XCommandProcessor >& i_rSubDocumentDefinition ) 126 :m_pData( new SubComponentLoader_Data( i_rSubDocumentDefinition ) ) 127 { 128 // add as window listener to the controller's container window, so we get notified when it is shown 129 Reference< XController2 > xController( i_rApplicationController, UNO_QUERY_THROW ); 130 m_pData->xAppComponentWindow.set( xController->getComponentWindow(), UNO_SET_THROW ); 131 132 osl_incrementInterlockedCount( &m_refCount ); 133 { 134 m_pData->xAppComponentWindow->addWindowListener( this ); 135 } 136 osl_decrementInterlockedCount( &m_refCount ); 137 } 138 139 //-------------------------------------------------------------------- 140 SubComponentLoader::SubComponentLoader( const Reference< XController >& i_rApplicationController, 141 const Reference< XComponent >& i_rNonDocumentComponent ) 142 :m_pData( new SubComponentLoader_Data( i_rNonDocumentComponent ) ) 143 { 144 // add as window listener to the controller's container window, so we get notified when it is shown 145 Reference< XController2 > xController( i_rApplicationController, UNO_QUERY_THROW ); 146 m_pData->xAppComponentWindow.set( xController->getComponentWindow(), UNO_SET_THROW ); 147 148 osl_incrementInterlockedCount( &m_refCount ); 149 { 150 m_pData->xAppComponentWindow->addWindowListener( this ); 151 } 152 osl_decrementInterlockedCount( &m_refCount ); 153 } 154 155 //-------------------------------------------------------------------- 156 SubComponentLoader::~SubComponentLoader() 157 { 158 delete m_pData, m_pData = NULL; 159 } 160 161 //-------------------------------------------------------------------- 162 void SAL_CALL SubComponentLoader::windowResized( const WindowEvent& i_rEvent ) throw (RuntimeException) 163 { 164 // not interested in 165 (void)i_rEvent; 166 } 167 168 //-------------------------------------------------------------------- 169 void SAL_CALL SubComponentLoader::windowMoved( const WindowEvent& i_rEvent ) throw (RuntimeException) 170 { 171 // not interested in 172 (void)i_rEvent; 173 } 174 175 //-------------------------------------------------------------------- 176 void SAL_CALL SubComponentLoader::windowShown( const EventObject& i_rEvent ) throw (RuntimeException) 177 { 178 (void)i_rEvent; 179 180 lcl_onWindowShown_nothrow( *m_pData ); 181 m_pData->xAppComponentWindow->removeWindowListener( this ); 182 } 183 184 //-------------------------------------------------------------------- 185 void SAL_CALL SubComponentLoader::windowHidden( const EventObject& i_rEvent ) throw (RuntimeException) 186 { 187 // not interested in 188 (void)i_rEvent; 189 } 190 191 //-------------------------------------------------------------------- 192 void SAL_CALL SubComponentLoader::disposing( const EventObject& i_rEvent ) throw (RuntimeException) 193 { 194 // not interested in 195 (void)i_rEvent; 196 } 197 198 //........................................................................ 199 } // namespace dbaccess 200 //........................................................................ 201