xref: /AOO41X/main/framework/source/uielement/panelwrapper.cxx (revision 6d739b60ff8f4ed2134ae1442e284f9da90334b4)
1*6d739b60SAndrew Rist /**************************************************************
2*6d739b60SAndrew Rist  *
3*6d739b60SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*6d739b60SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*6d739b60SAndrew Rist  * distributed with this work for additional information
6*6d739b60SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*6d739b60SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*6d739b60SAndrew Rist  * "License"); you may not use this file except in compliance
9*6d739b60SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*6d739b60SAndrew Rist  *
11*6d739b60SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*6d739b60SAndrew Rist  *
13*6d739b60SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*6d739b60SAndrew Rist  * software distributed under the License is distributed on an
15*6d739b60SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*6d739b60SAndrew Rist  * KIND, either express or implied.  See the License for the
17*6d739b60SAndrew Rist  * specific language governing permissions and limitations
18*6d739b60SAndrew Rist  * under the License.
19*6d739b60SAndrew Rist  *
20*6d739b60SAndrew Rist  *************************************************************/
21*6d739b60SAndrew Rist 
22cdf0e10cSrcweir 
23cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
24cdf0e10cSrcweir #include "precompiled_framework.hxx"
25cdf0e10cSrcweir //_________________________________________________________________________________________________________________
26cdf0e10cSrcweir //	my own includes
27cdf0e10cSrcweir //_________________________________________________________________________________________________________________
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <services.h>
30cdf0e10cSrcweir #include <uielement/panelwrapper.hxx>
31cdf0e10cSrcweir #include <threadhelp/resetableguard.hxx>
32cdf0e10cSrcweir #include <uielement/constitemcontainer.hxx>
33cdf0e10cSrcweir #include <uielement/rootitemcontainer.hxx>
34cdf0e10cSrcweir #include <uielement/panelwindow.hxx>
35cdf0e10cSrcweir #include <services/modelwinservice.hxx>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir //_________________________________________________________________________________________________________________
38cdf0e10cSrcweir //	interface includes
39cdf0e10cSrcweir //_________________________________________________________________________________________________________________
40cdf0e10cSrcweir 
41cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
42cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
43cdf0e10cSrcweir #include <com/sun/star/awt/XSystemDependentMenuPeer.hpp>
44cdf0e10cSrcweir #include <com/sun/star/awt/XMenuBar.hpp>
45cdf0e10cSrcweir #include <com/sun/star/container/XIndexContainer.hpp>
46cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
47cdf0e10cSrcweir #include <com/sun/star/ui/UIElementType.hpp>
48cdf0e10cSrcweir 
49cdf0e10cSrcweir //_________________________________________________________________________________________________________________
50cdf0e10cSrcweir //	other includes
51cdf0e10cSrcweir //_________________________________________________________________________________________________________________
52cdf0e10cSrcweir 
53cdf0e10cSrcweir #include <toolkit/unohlp.hxx>
54cdf0e10cSrcweir #include <toolkit/awt/vclxwindow.hxx>
55cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
56cdf0e10cSrcweir #include <svtools/miscopt.hxx>
57cdf0e10cSrcweir #include <vcl/svapp.hxx>
58cdf0e10cSrcweir #include <rtl/logfile.hxx>
59cdf0e10cSrcweir 
60cdf0e10cSrcweir using namespace com::sun::star;
61cdf0e10cSrcweir using namespace com::sun::star::uno;
62cdf0e10cSrcweir using namespace com::sun::star::beans;
63cdf0e10cSrcweir using namespace com::sun::star::frame;
64cdf0e10cSrcweir using namespace com::sun::star::lang;
65cdf0e10cSrcweir using namespace com::sun::star::container;
66cdf0e10cSrcweir using namespace com::sun::star::awt;
67cdf0e10cSrcweir using namespace ::com::sun::star::ui;
68cdf0e10cSrcweir 
69cdf0e10cSrcweir namespace framework
70cdf0e10cSrcweir {
71cdf0e10cSrcweir 
PanelWrapper(const Reference<XMultiServiceFactory> & xServiceManager)72cdf0e10cSrcweir PanelWrapper::PanelWrapper( const Reference< XMultiServiceFactory >& xServiceManager ) :
73cdf0e10cSrcweir     UIElementWrapperBase( UIElementType::DOCKINGWINDOW ),
74cdf0e10cSrcweir     m_xServiceManager( xServiceManager ),
75cdf0e10cSrcweir     m_bNoClose(false)
76cdf0e10cSrcweir {
77cdf0e10cSrcweir }
78cdf0e10cSrcweir 
~PanelWrapper()79cdf0e10cSrcweir PanelWrapper::~PanelWrapper()
80cdf0e10cSrcweir {
81cdf0e10cSrcweir }
82cdf0e10cSrcweir 
83cdf0e10cSrcweir // XInterface
acquire()84cdf0e10cSrcweir void SAL_CALL PanelWrapper::acquire() throw()
85cdf0e10cSrcweir {
86cdf0e10cSrcweir     UIElementWrapperBase::acquire();
87cdf0e10cSrcweir }
88cdf0e10cSrcweir 
release()89cdf0e10cSrcweir void SAL_CALL PanelWrapper::release() throw()
90cdf0e10cSrcweir {
91cdf0e10cSrcweir     UIElementWrapperBase::release();
92cdf0e10cSrcweir }
93cdf0e10cSrcweir 
queryInterface(const uno::Type & rType)94cdf0e10cSrcweir uno::Any SAL_CALL PanelWrapper::queryInterface( const uno::Type & rType )
95cdf0e10cSrcweir throw( ::com::sun::star::uno::RuntimeException )
96cdf0e10cSrcweir {
97cdf0e10cSrcweir 	return UIElementWrapperBase::queryInterface( rType );
98cdf0e10cSrcweir }
99cdf0e10cSrcweir 
100cdf0e10cSrcweir // XComponent
dispose()101cdf0e10cSrcweir void SAL_CALL PanelWrapper::dispose() throw ( RuntimeException )
102cdf0e10cSrcweir {
103cdf0e10cSrcweir     Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY );
104cdf0e10cSrcweir     Reference< XMultiServiceFactory > xSMGR( m_xServiceManager );
105cdf0e10cSrcweir     Reference< XWindow > xWindow;
106cdf0e10cSrcweir 
107cdf0e10cSrcweir 	{
108cdf0e10cSrcweir 		ResetableGuard aLock( m_aLock );
109cdf0e10cSrcweir 		if ( m_bDisposed )
110cdf0e10cSrcweir 			return;
111cdf0e10cSrcweir         xSMGR = m_xServiceManager;
112cdf0e10cSrcweir 	}
113cdf0e10cSrcweir 
114cdf0e10cSrcweir 	com::sun::star::lang::EventObject aEvent( xThis );
115cdf0e10cSrcweir     m_aListenerContainer.disposeAndClear( aEvent );
116cdf0e10cSrcweir 
117cdf0e10cSrcweir     rtl::OUString aModelWinService( SERVICENAME_MODELWINSERVICE );
118cdf0e10cSrcweir     Reference< XNameAccess > xNameAccess( xSMGR->createInstance( aModelWinService ), UNO_QUERY );
119cdf0e10cSrcweir     if ( xNameAccess.is() )
120cdf0e10cSrcweir     {
121cdf0e10cSrcweir         ModelWinService* pService = dynamic_cast< ModelWinService* >( xNameAccess.get() );
122cdf0e10cSrcweir         if ( pService != 0 )
123cdf0e10cSrcweir         {
124cdf0e10cSrcweir             vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
125cdf0e10cSrcweir             PanelWindow* pPanelWindow = dynamic_cast< PanelWindow* >( m_xPanelWindow.get() );
126cdf0e10cSrcweir             if ( pPanelWindow != NULL )
127cdf0e10cSrcweir             {
128cdf0e10cSrcweir                 xWindow = VCLUnoHelper::GetInterface( pPanelWindow->getContentWindow() );
129cdf0e10cSrcweir                 pService->deregisterModelForXWindow( xWindow );
130cdf0e10cSrcweir             }
131cdf0e10cSrcweir         }
132cdf0e10cSrcweir     }
133cdf0e10cSrcweir 
134cdf0e10cSrcweir     ResetableGuard aLock( m_aLock );
135cdf0e10cSrcweir     m_xPanelWindow.clear();
136cdf0e10cSrcweir     m_bDisposed = sal_True;
137cdf0e10cSrcweir }
138cdf0e10cSrcweir 
139cdf0e10cSrcweir // XInitialization
initialize(const Sequence<Any> & aArguments)140cdf0e10cSrcweir void SAL_CALL PanelWrapper::initialize( const Sequence< Any >& aArguments ) throw ( Exception, RuntimeException )
141cdf0e10cSrcweir {
142cdf0e10cSrcweir     ResetableGuard aLock( m_aLock );
143cdf0e10cSrcweir 
144cdf0e10cSrcweir     if ( m_bDisposed )
145cdf0e10cSrcweir         throw DisposedException();
146cdf0e10cSrcweir 
147cdf0e10cSrcweir     if ( !m_bInitialized )
148cdf0e10cSrcweir     {
149cdf0e10cSrcweir         UIElementWrapperBase::initialize( aArguments );
150cdf0e10cSrcweir 
151cdf0e10cSrcweir         sal_Bool bPopupMode( sal_False );
152cdf0e10cSrcweir         Reference< XWindow > xContentWindow;
153cdf0e10cSrcweir         for ( sal_Int32 i = 0; i < aArguments.getLength(); i++ )
154cdf0e10cSrcweir         {
155cdf0e10cSrcweir             PropertyValue aPropValue;
156cdf0e10cSrcweir             if ( aArguments[i] >>= aPropValue )
157cdf0e10cSrcweir             {
158cdf0e10cSrcweir                 if ( aPropValue.Name.equalsAsciiL( "PopupMode", 9 ))
159cdf0e10cSrcweir                     aPropValue.Value >>= bPopupMode;
160cdf0e10cSrcweir                 else if ( aPropValue.Name.equalsAsciiL( "ContentWindow", 13 ))
161cdf0e10cSrcweir                     aPropValue.Value >>= xContentWindow;
162cdf0e10cSrcweir             }
163cdf0e10cSrcweir         }
164cdf0e10cSrcweir 
165cdf0e10cSrcweir         Reference< XFrame > xFrame( m_xWeakFrame );
166cdf0e10cSrcweir         if ( xFrame.is() )
167cdf0e10cSrcweir         {
168cdf0e10cSrcweir             PanelWindow* pPanelWindow(0);
169cdf0e10cSrcweir             Window*      pContentWindow(0);
170cdf0e10cSrcweir             {
171cdf0e10cSrcweir                 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
172cdf0e10cSrcweir                 Window* pWindow = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
173cdf0e10cSrcweir                 pContentWindow  = VCLUnoHelper::GetWindow( xContentWindow );
174cdf0e10cSrcweir                 if ( pWindow )
175cdf0e10cSrcweir                 {
176cdf0e10cSrcweir                     sal_uInt32 nStyles = WB_LINESPACING | WB_BORDER | WB_SCROLL | WB_MOVEABLE | WB_3DLOOK | WB_DOCKABLE | WB_SIZEABLE | WB_CLOSEABLE;
177cdf0e10cSrcweir 
178cdf0e10cSrcweir                     pPanelWindow = new PanelWindow( pWindow, nStyles );
179cdf0e10cSrcweir                     m_xPanelWindow = VCLUnoHelper::GetInterface( pPanelWindow );
180cdf0e10cSrcweir 					pPanelWindow->setResourceURL( m_aResourceURL );
181cdf0e10cSrcweir                     pPanelWindow->setContentWindow( pContentWindow );
182cdf0e10cSrcweir                 }
183cdf0e10cSrcweir             }
184cdf0e10cSrcweir 
185cdf0e10cSrcweir             try
186cdf0e10cSrcweir             {
187cdf0e10cSrcweir             }
188cdf0e10cSrcweir             catch ( NoSuchElementException& )
189cdf0e10cSrcweir             {
190cdf0e10cSrcweir             }
191cdf0e10cSrcweir         }
192cdf0e10cSrcweir     }
193cdf0e10cSrcweir }
194cdf0e10cSrcweir 
195cdf0e10cSrcweir // XEventListener
disposing(const::com::sun::star::lang::EventObject &)196cdf0e10cSrcweir void SAL_CALL PanelWrapper::disposing( const ::com::sun::star::lang::EventObject& ) throw (::com::sun::star::uno::RuntimeException)
197cdf0e10cSrcweir {
198cdf0e10cSrcweir     // nothing todo
199cdf0e10cSrcweir }
200cdf0e10cSrcweir 
201cdf0e10cSrcweir // XUpdatable
update()202cdf0e10cSrcweir void SAL_CALL PanelWrapper::update() throw (::com::sun::star::uno::RuntimeException)
203cdf0e10cSrcweir {
204cdf0e10cSrcweir     ResetableGuard aLock( m_aLock );
205cdf0e10cSrcweir 
206cdf0e10cSrcweir     if ( m_bDisposed )
207cdf0e10cSrcweir         throw DisposedException();
208cdf0e10cSrcweir }
209cdf0e10cSrcweir 
210cdf0e10cSrcweir // XUIElement interface
getRealInterface()211cdf0e10cSrcweir Reference< XInterface > SAL_CALL PanelWrapper::getRealInterface(  ) throw (::com::sun::star::uno::RuntimeException)
212cdf0e10cSrcweir {
213cdf0e10cSrcweir     ResetableGuard aLock( m_aLock );
214cdf0e10cSrcweir     return m_xPanelWindow;
215cdf0e10cSrcweir }
216cdf0e10cSrcweir 
setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const com::sun::star::uno::Any & aValue)217cdf0e10cSrcweir void SAL_CALL PanelWrapper::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const com::sun::star::uno::Any&  aValue ) throw( com::sun::star::uno::Exception )
218cdf0e10cSrcweir {
219cdf0e10cSrcweir     ResetableGuard aLock( m_aLock );
220cdf0e10cSrcweir     sal_Bool bNoClose( m_bNoClose );
221cdf0e10cSrcweir     aLock.unlock();
222cdf0e10cSrcweir 
223cdf0e10cSrcweir     UIElementWrapperBase::setFastPropertyValue_NoBroadcast( nHandle, aValue );
224cdf0e10cSrcweir 
225cdf0e10cSrcweir     aLock.lock();
226cdf0e10cSrcweir 
227cdf0e10cSrcweir     sal_Bool bNewNoClose( m_bNoClose );
228cdf0e10cSrcweir     if ( m_xPanelWindow.is() && !m_bDisposed && ( bNewNoClose != bNoClose ))
229cdf0e10cSrcweir     {
230cdf0e10cSrcweir         PanelWindow* pPanelWindow = dynamic_cast< PanelWindow* >( VCLUnoHelper::GetWindow( m_xPanelWindow ) );
231cdf0e10cSrcweir         if ( pPanelWindow )
232cdf0e10cSrcweir         {
233cdf0e10cSrcweir             if ( bNewNoClose )
234cdf0e10cSrcweir             {
235cdf0e10cSrcweir                 pPanelWindow->SetStyle( pPanelWindow->GetStyle() & ~WB_CLOSEABLE );
236cdf0e10cSrcweir                 pPanelWindow->SetFloatStyle( pPanelWindow->GetFloatStyle() & ~WB_CLOSEABLE );
237cdf0e10cSrcweir             }
238cdf0e10cSrcweir             else
239cdf0e10cSrcweir             {
240cdf0e10cSrcweir                 pPanelWindow->SetStyle( pPanelWindow->GetStyle() | WB_CLOSEABLE );
241cdf0e10cSrcweir                 pPanelWindow->SetFloatStyle( pPanelWindow->GetFloatStyle() | WB_CLOSEABLE );
242cdf0e10cSrcweir             }
243cdf0e10cSrcweir         }
244cdf0e10cSrcweir     }
245cdf0e10cSrcweir }
246cdf0e10cSrcweir 
247cdf0e10cSrcweir } // namespace framework
248