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 // MARKER(update_precomp.py): autogen include statement, do not remove
24 #include "precompiled_framework.hxx"
25 //_________________________________________________________________________________________________________________
26 //	my own includes
27 //_________________________________________________________________________________________________________________
28 
29 #include <services.h>
30 #include <uielement/panelwrapper.hxx>
31 #include <threadhelp/resetableguard.hxx>
32 #include <uielement/constitemcontainer.hxx>
33 #include <uielement/rootitemcontainer.hxx>
34 #include <uielement/panelwindow.hxx>
35 #include <services/modelwinservice.hxx>
36 
37 //_________________________________________________________________________________________________________________
38 //	interface includes
39 //_________________________________________________________________________________________________________________
40 
41 #include <com/sun/star/lang/XServiceInfo.hpp>
42 #include <com/sun/star/beans/XPropertySet.hpp>
43 #include <com/sun/star/awt/XSystemDependentMenuPeer.hpp>
44 #include <com/sun/star/awt/XMenuBar.hpp>
45 #include <com/sun/star/container/XIndexContainer.hpp>
46 #include <com/sun/star/container/XNameAccess.hpp>
47 #include <com/sun/star/ui/UIElementType.hpp>
48 
49 //_________________________________________________________________________________________________________________
50 //	other includes
51 //_________________________________________________________________________________________________________________
52 
53 #include <toolkit/helper/vclunohelper.hxx>
54 #include <toolkit/awt/vclxwindow.hxx>
55 #include <comphelper/processfactory.hxx>
56 #include <svtools/miscopt.hxx>
57 #include <vcl/svapp.hxx>
58 #include <rtl/logfile.hxx>
59 
60 using namespace com::sun::star;
61 using namespace com::sun::star::uno;
62 using namespace com::sun::star::beans;
63 using namespace com::sun::star::frame;
64 using namespace com::sun::star::lang;
65 using namespace com::sun::star::container;
66 using namespace com::sun::star::awt;
67 using namespace ::com::sun::star::ui;
68 
69 namespace framework
70 {
71 
PanelWrapper(const Reference<XMultiServiceFactory> & xServiceManager)72 PanelWrapper::PanelWrapper( const Reference< XMultiServiceFactory >& xServiceManager ) :
73     UIElementWrapperBase( UIElementType::DOCKINGWINDOW ),
74     m_xServiceManager( xServiceManager ),
75     m_bNoClose(false)
76 {
77 }
78 
~PanelWrapper()79 PanelWrapper::~PanelWrapper()
80 {
81 }
82 
83 // XInterface
acquire()84 void SAL_CALL PanelWrapper::acquire() throw()
85 {
86     UIElementWrapperBase::acquire();
87 }
88 
release()89 void SAL_CALL PanelWrapper::release() throw()
90 {
91     UIElementWrapperBase::release();
92 }
93 
queryInterface(const uno::Type & rType)94 uno::Any SAL_CALL PanelWrapper::queryInterface( const uno::Type & rType )
95 throw( ::com::sun::star::uno::RuntimeException )
96 {
97 	return UIElementWrapperBase::queryInterface( rType );
98 }
99 
100 // XComponent
dispose()101 void SAL_CALL PanelWrapper::dispose() throw ( RuntimeException )
102 {
103     Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY );
104     Reference< XMultiServiceFactory > xSMGR( m_xServiceManager );
105     Reference< XWindow > xWindow;
106 
107 	{
108 		ResetableGuard aLock( m_aLock );
109 		if ( m_bDisposed )
110 			return;
111         xSMGR = m_xServiceManager;
112 	}
113 
114 	com::sun::star::lang::EventObject aEvent( xThis );
115     m_aListenerContainer.disposeAndClear( aEvent );
116 
117     rtl::OUString aModelWinService( SERVICENAME_MODELWINSERVICE );
118     Reference< XNameAccess > xNameAccess( xSMGR->createInstance( aModelWinService ), UNO_QUERY );
119     if ( xNameAccess.is() )
120     {
121         ModelWinService* pService = dynamic_cast< ModelWinService* >( xNameAccess.get() );
122         if ( pService != 0 )
123         {
124             vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
125             PanelWindow* pPanelWindow = dynamic_cast< PanelWindow* >( m_xPanelWindow.get() );
126             if ( pPanelWindow != NULL )
127             {
128                 xWindow = VCLUnoHelper::GetInterface( pPanelWindow->getContentWindow() );
129                 pService->deregisterModelForXWindow( xWindow );
130             }
131         }
132     }
133 
134     ResetableGuard aLock( m_aLock );
135     m_xPanelWindow.clear();
136     m_bDisposed = sal_True;
137 }
138 
139 // XInitialization
initialize(const Sequence<Any> & aArguments)140 void SAL_CALL PanelWrapper::initialize( const Sequence< Any >& aArguments ) throw ( Exception, RuntimeException )
141 {
142     ResetableGuard aLock( m_aLock );
143 
144     if ( m_bDisposed )
145         throw DisposedException();
146 
147     if ( !m_bInitialized )
148     {
149         UIElementWrapperBase::initialize( aArguments );
150 
151         sal_Bool bPopupMode( sal_False );
152         Reference< XWindow > xContentWindow;
153         for ( sal_Int32 i = 0; i < aArguments.getLength(); i++ )
154         {
155             PropertyValue aPropValue;
156             if ( aArguments[i] >>= aPropValue )
157             {
158                 if ( aPropValue.Name.equalsAsciiL( "PopupMode", 9 ))
159                     aPropValue.Value >>= bPopupMode;
160                 else if ( aPropValue.Name.equalsAsciiL( "ContentWindow", 13 ))
161                     aPropValue.Value >>= xContentWindow;
162             }
163         }
164 
165         Reference< XFrame > xFrame( m_xWeakFrame );
166         if ( xFrame.is() )
167         {
168             PanelWindow* pPanelWindow(0);
169             Window*      pContentWindow(0);
170             {
171                 vos::OGuard aSolarMutexGuard( Application::GetSolarMutex() );
172                 Window* pWindow = VCLUnoHelper::GetWindow( xFrame->getContainerWindow() );
173                 pContentWindow  = VCLUnoHelper::GetWindow( xContentWindow );
174                 if ( pWindow )
175                 {
176                     sal_uInt32 nStyles = WB_LINESPACING | WB_BORDER | WB_SCROLL | WB_MOVEABLE | WB_3DLOOK | WB_DOCKABLE | WB_SIZEABLE | WB_CLOSEABLE;
177 
178                     pPanelWindow = new PanelWindow( pWindow, nStyles );
179                     m_xPanelWindow = VCLUnoHelper::GetInterface( pPanelWindow );
180 					pPanelWindow->setResourceURL( m_aResourceURL );
181                     pPanelWindow->setContentWindow( pContentWindow );
182                 }
183             }
184 
185             try
186             {
187             }
188             catch ( NoSuchElementException& )
189             {
190             }
191         }
192     }
193 }
194 
195 // XEventListener
disposing(const::com::sun::star::lang::EventObject &)196 void SAL_CALL PanelWrapper::disposing( const ::com::sun::star::lang::EventObject& ) throw (::com::sun::star::uno::RuntimeException)
197 {
198     // nothing todo
199 }
200 
201 // XUpdatable
update()202 void SAL_CALL PanelWrapper::update() throw (::com::sun::star::uno::RuntimeException)
203 {
204     ResetableGuard aLock( m_aLock );
205 
206     if ( m_bDisposed )
207         throw DisposedException();
208 }
209 
210 // XUIElement interface
getRealInterface()211 Reference< XInterface > SAL_CALL PanelWrapper::getRealInterface(  ) throw (::com::sun::star::uno::RuntimeException)
212 {
213     ResetableGuard aLock( m_aLock );
214     return m_xPanelWindow;
215 }
216 
setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const com::sun::star::uno::Any & aValue)217 void SAL_CALL PanelWrapper::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle, const com::sun::star::uno::Any&  aValue ) throw( com::sun::star::uno::Exception )
218 {
219     ResetableGuard aLock( m_aLock );
220     sal_Bool bNoClose( m_bNoClose );
221     aLock.unlock();
222 
223     UIElementWrapperBase::setFastPropertyValue_NoBroadcast( nHandle, aValue );
224 
225     aLock.lock();
226 
227     sal_Bool bNewNoClose( m_bNoClose );
228     if ( m_xPanelWindow.is() && !m_bDisposed && ( bNewNoClose != bNoClose ))
229     {
230         PanelWindow* pPanelWindow = dynamic_cast< PanelWindow* >( VCLUnoHelper::GetWindow( m_xPanelWindow ) );
231         if ( pPanelWindow )
232         {
233             if ( bNewNoClose )
234             {
235                 pPanelWindow->SetStyle( pPanelWindow->GetStyle() & ~WB_CLOSEABLE );
236                 pPanelWindow->SetFloatStyle( pPanelWindow->GetFloatStyle() & ~WB_CLOSEABLE );
237             }
238             else
239             {
240                 pPanelWindow->SetStyle( pPanelWindow->GetStyle() | WB_CLOSEABLE );
241                 pPanelWindow->SetFloatStyle( pPanelWindow->GetFloatStyle() | WB_CLOSEABLE );
242             }
243         }
244     }
245 }
246 
247 } // namespace framework
248