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