15900e8ecSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
35900e8ecSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
45900e8ecSAndrew Rist * or more contributor license agreements. See the NOTICE file
55900e8ecSAndrew Rist * distributed with this work for additional information
65900e8ecSAndrew Rist * regarding copyright ownership. The ASF licenses this file
75900e8ecSAndrew Rist * to you under the Apache License, Version 2.0 (the
85900e8ecSAndrew Rist * "License"); you may not use this file except in compliance
95900e8ecSAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
115900e8ecSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
135900e8ecSAndrew Rist * Unless required by applicable law or agreed to in writing,
145900e8ecSAndrew Rist * software distributed under the License is distributed on an
155900e8ecSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
165900e8ecSAndrew Rist * KIND, either express or implied. See the License for the
175900e8ecSAndrew Rist * specific language governing permissions and limitations
185900e8ecSAndrew Rist * under the License.
19cdf0e10cSrcweir *
205900e8ecSAndrew Rist *************************************************************/
215900e8ecSAndrew Rist
225900e8ecSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svtools.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <toolkit/helper/vclunohelper.hxx>
28cdf0e10cSrcweir
29cdf0e10cSrcweir #include <vcl/toolbox.hxx>
30cdf0e10cSrcweir #include <vcl/svapp.hxx>
31cdf0e10cSrcweir
32cdf0e10cSrcweir #include "svtools/popupwindowcontroller.hxx"
33cdf0e10cSrcweir #include "svtools/toolbarmenu.hxx"
34cdf0e10cSrcweir
35cdf0e10cSrcweir using rtl::OUString;
36cdf0e10cSrcweir using namespace ::com::sun::star;
37cdf0e10cSrcweir using namespace ::com::sun::star::uno;
38cdf0e10cSrcweir using namespace ::com::sun::star::lang;
39cdf0e10cSrcweir
40cdf0e10cSrcweir
41cdf0e10cSrcweir namespace svt
42cdf0e10cSrcweir {
43cdf0e10cSrcweir
44cdf0e10cSrcweir class PopupWindowControllerImpl
45cdf0e10cSrcweir {
46cdf0e10cSrcweir public:
47cdf0e10cSrcweir PopupWindowControllerImpl();
48cdf0e10cSrcweir ~PopupWindowControllerImpl();
49cdf0e10cSrcweir
50cdf0e10cSrcweir void SetPopupWindow( ::Window* pPopupWindow, ToolBox* pToolBox );
51cdf0e10cSrcweir
52cdf0e10cSrcweir DECL_LINK( WindowEventListener, VclSimpleEvent* );
53cdf0e10cSrcweir DECL_STATIC_LINK( PopupWindowControllerImpl, AsyncDeleteWindowHdl, Window* );
54cdf0e10cSrcweir
55cdf0e10cSrcweir private:
56cdf0e10cSrcweir ::Window* mpPopupWindow;
57cdf0e10cSrcweir ToolBox* mpToolBox;
58cdf0e10cSrcweir };
59cdf0e10cSrcweir
PopupWindowControllerImpl()60cdf0e10cSrcweir PopupWindowControllerImpl::PopupWindowControllerImpl()
61cdf0e10cSrcweir : mpPopupWindow( 0 )
62cdf0e10cSrcweir , mpToolBox( 0 )
63cdf0e10cSrcweir {
64cdf0e10cSrcweir }
65cdf0e10cSrcweir
~PopupWindowControllerImpl()66cdf0e10cSrcweir PopupWindowControllerImpl::~PopupWindowControllerImpl()
67cdf0e10cSrcweir {
68cdf0e10cSrcweir if( mpPopupWindow )
69cdf0e10cSrcweir SetPopupWindow(0,0);
70cdf0e10cSrcweir }
71cdf0e10cSrcweir
SetPopupWindow(::Window * pPopupWindow,ToolBox * pToolBox)72cdf0e10cSrcweir void PopupWindowControllerImpl::SetPopupWindow( ::Window* pPopupWindow, ToolBox* pToolBox )
73cdf0e10cSrcweir {
74cdf0e10cSrcweir if( mpPopupWindow )
75cdf0e10cSrcweir {
76cdf0e10cSrcweir mpPopupWindow->RemoveEventListener( LINK( this, PopupWindowControllerImpl, WindowEventListener ) );
77cdf0e10cSrcweir Application::PostUserEvent( STATIC_LINK( this, PopupWindowControllerImpl, AsyncDeleteWindowHdl ), mpPopupWindow );
78cdf0e10cSrcweir }
79cdf0e10cSrcweir mpPopupWindow = pPopupWindow;
80cdf0e10cSrcweir mpToolBox = pToolBox;
81cdf0e10cSrcweir
82cdf0e10cSrcweir if( mpPopupWindow )
83cdf0e10cSrcweir {
84cdf0e10cSrcweir mpPopupWindow->AddEventListener( LINK( this, PopupWindowControllerImpl, WindowEventListener ));
85cdf0e10cSrcweir }
86cdf0e10cSrcweir }
87cdf0e10cSrcweir
IMPL_LINK(PopupWindowControllerImpl,WindowEventListener,VclSimpleEvent *,pEvent)88cdf0e10cSrcweir IMPL_LINK( PopupWindowControllerImpl, WindowEventListener, VclSimpleEvent*, pEvent )
89cdf0e10cSrcweir {
90cdf0e10cSrcweir VclWindowEvent* pWindowEvent = dynamic_cast< VclWindowEvent* >( pEvent );
91cdf0e10cSrcweir if( pWindowEvent )
92cdf0e10cSrcweir {
93cdf0e10cSrcweir switch( pWindowEvent->GetId() )
94cdf0e10cSrcweir {
95cdf0e10cSrcweir case VCLEVENT_WINDOW_CLOSE:
96cdf0e10cSrcweir case VCLEVENT_WINDOW_ENDPOPUPMODE:
97cdf0e10cSrcweir SetPopupWindow(0,0);
98cdf0e10cSrcweir break;
99cdf0e10cSrcweir
100cdf0e10cSrcweir case VCLEVENT_WINDOW_SHOW:
101cdf0e10cSrcweir {
102cdf0e10cSrcweir if( mpPopupWindow )
103cdf0e10cSrcweir {
104cdf0e10cSrcweir if( mpToolBox )
105cdf0e10cSrcweir mpToolBox->CallEventListeners( VCLEVENT_DROPDOWN_OPEN, (void*)mpPopupWindow );
106cdf0e10cSrcweir mpPopupWindow->CallEventListeners( VCLEVENT_WINDOW_GETFOCUS, 0 );
107cdf0e10cSrcweir
108cdf0e10cSrcweir svtools::ToolbarMenu* pToolbarMenu = dynamic_cast< svtools::ToolbarMenu* >( mpPopupWindow );
109cdf0e10cSrcweir if( pToolbarMenu )
110cdf0e10cSrcweir pToolbarMenu->highlightFirstEntry();
111cdf0e10cSrcweir break;
112cdf0e10cSrcweir }
113cdf0e10cSrcweir break;
114cdf0e10cSrcweir }
115cdf0e10cSrcweir case VCLEVENT_WINDOW_HIDE:
116cdf0e10cSrcweir {
117cdf0e10cSrcweir if( mpPopupWindow )
118cdf0e10cSrcweir {
119cdf0e10cSrcweir mpPopupWindow->CallEventListeners( VCLEVENT_WINDOW_LOSEFOCUS, 0 );
120cdf0e10cSrcweir if( mpToolBox )
121cdf0e10cSrcweir mpToolBox->CallEventListeners( VCLEVENT_DROPDOWN_CLOSE, (void*)mpPopupWindow );
122cdf0e10cSrcweir }
123cdf0e10cSrcweir break;
124cdf0e10cSrcweir }
125cdf0e10cSrcweir }
126cdf0e10cSrcweir }
127cdf0e10cSrcweir return 1;
128cdf0e10cSrcweir }
129cdf0e10cSrcweir
130cdf0e10cSrcweir //--------------------------------------------------------------------
131cdf0e10cSrcweir
IMPL_STATIC_LINK(PopupWindowControllerImpl,AsyncDeleteWindowHdl,Window *,pWindow)132cdf0e10cSrcweir IMPL_STATIC_LINK( PopupWindowControllerImpl, AsyncDeleteWindowHdl, Window*, pWindow )
133cdf0e10cSrcweir {
134cdf0e10cSrcweir (void)*pThis;
135cdf0e10cSrcweir delete pWindow;
136cdf0e10cSrcweir return 0;
137cdf0e10cSrcweir }
138cdf0e10cSrcweir
139cdf0e10cSrcweir //========================================================================
140cdf0e10cSrcweir // class PopupWindowController
141cdf0e10cSrcweir //========================================================================
142cdf0e10cSrcweir
PopupWindowController(const Reference<lang::XMultiServiceFactory> & rServiceManager,const Reference<frame::XFrame> & xFrame,const OUString & aCommandURL)143cdf0e10cSrcweir PopupWindowController::PopupWindowController( const Reference< lang::XMultiServiceFactory >& rServiceManager,
144cdf0e10cSrcweir const Reference< frame::XFrame >& xFrame,
145cdf0e10cSrcweir const OUString& aCommandURL )
146cdf0e10cSrcweir : svt::ToolboxController( rServiceManager, xFrame, aCommandURL )
147cdf0e10cSrcweir , mpImpl( new PopupWindowControllerImpl() )
148cdf0e10cSrcweir {
149cdf0e10cSrcweir }
150cdf0e10cSrcweir
~PopupWindowController()151cdf0e10cSrcweir PopupWindowController::~PopupWindowController()
152cdf0e10cSrcweir {
153cdf0e10cSrcweir }
154cdf0e10cSrcweir
155cdf0e10cSrcweir // XInterface
queryInterface(const Type & aType)156cdf0e10cSrcweir Any SAL_CALL PopupWindowController::queryInterface( const Type& aType )
157cdf0e10cSrcweir throw (RuntimeException)
158cdf0e10cSrcweir {
159cdf0e10cSrcweir Any a( ToolboxController::queryInterface( aType ) );
160cdf0e10cSrcweir if ( a.hasValue() )
161cdf0e10cSrcweir return a;
162cdf0e10cSrcweir
163cdf0e10cSrcweir return ::cppu::queryInterface( aType, static_cast< lang::XServiceInfo* >( this ));
164cdf0e10cSrcweir }
165cdf0e10cSrcweir
acquire()166cdf0e10cSrcweir void SAL_CALL PopupWindowController::acquire() throw ()
167cdf0e10cSrcweir {
168cdf0e10cSrcweir ToolboxController::acquire();
169cdf0e10cSrcweir }
170cdf0e10cSrcweir
release()171cdf0e10cSrcweir void SAL_CALL PopupWindowController::release() throw ()
172cdf0e10cSrcweir {
173cdf0e10cSrcweir ToolboxController::release();
174cdf0e10cSrcweir }
175cdf0e10cSrcweir
176cdf0e10cSrcweir // XServiceInfo
supportsService(const OUString & ServiceName)177cdf0e10cSrcweir sal_Bool SAL_CALL PopupWindowController::supportsService( const OUString& ServiceName ) throw(RuntimeException)
178cdf0e10cSrcweir {
179cdf0e10cSrcweir const Sequence< OUString > aSNL( getSupportedServiceNames() );
180cdf0e10cSrcweir const OUString * pArray = aSNL.getConstArray();
181cdf0e10cSrcweir
182cdf0e10cSrcweir for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
183cdf0e10cSrcweir if( pArray[i] == ServiceName )
184cdf0e10cSrcweir return true;
185cdf0e10cSrcweir
186cdf0e10cSrcweir return false;
187cdf0e10cSrcweir }
188cdf0e10cSrcweir
189cdf0e10cSrcweir // XInitialization
initialize(const::com::sun::star::uno::Sequence<::com::sun::star::uno::Any> & aArguments)190cdf0e10cSrcweir void SAL_CALL PopupWindowController::initialize( const ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Any >& aArguments ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException)
191cdf0e10cSrcweir {
192cdf0e10cSrcweir svt::ToolboxController::initialize( aArguments );
193cdf0e10cSrcweir if( m_aCommandURL.getLength() )
194cdf0e10cSrcweir addStatusListener( m_aCommandURL );
195cdf0e10cSrcweir }
196cdf0e10cSrcweir
197cdf0e10cSrcweir // XComponent
dispose()198cdf0e10cSrcweir void SAL_CALL PopupWindowController::dispose() throw (RuntimeException)
199cdf0e10cSrcweir {
200cdf0e10cSrcweir if( m_aCommandURL.getLength() )
201cdf0e10cSrcweir removeStatusListener( m_aCommandURL );
202cdf0e10cSrcweir
203cdf0e10cSrcweir svt::ToolboxController::dispose();
204cdf0e10cSrcweir }
205cdf0e10cSrcweir
206cdf0e10cSrcweir
207cdf0e10cSrcweir // XStatusListener
statusChanged(const frame::FeatureStateEvent & rEvent)208cdf0e10cSrcweir void SAL_CALL PopupWindowController::statusChanged( const frame::FeatureStateEvent& rEvent ) throw ( RuntimeException )
209cdf0e10cSrcweir {
210cdf0e10cSrcweir svt::ToolboxController::statusChanged(rEvent);
211cdf0e10cSrcweir enable( rEvent.IsEnabled );
212cdf0e10cSrcweir }
213cdf0e10cSrcweir
214cdf0e10cSrcweir // XToolbarController
execute(sal_Int16 KeyModifier)215cdf0e10cSrcweir void SAL_CALL PopupWindowController::execute( sal_Int16 KeyModifier ) throw (RuntimeException)
216cdf0e10cSrcweir {
217cdf0e10cSrcweir svt::ToolboxController::execute( KeyModifier );
218cdf0e10cSrcweir }
219cdf0e10cSrcweir
click()220cdf0e10cSrcweir void SAL_CALL PopupWindowController::click() throw (RuntimeException)
221cdf0e10cSrcweir {
222cdf0e10cSrcweir svt::ToolboxController::click();
223cdf0e10cSrcweir }
224cdf0e10cSrcweir
doubleClick()225cdf0e10cSrcweir void SAL_CALL PopupWindowController::doubleClick() throw (RuntimeException)
226cdf0e10cSrcweir {
227cdf0e10cSrcweir svt::ToolboxController::doubleClick();
228cdf0e10cSrcweir }
229cdf0e10cSrcweir
createPopupWindow()230cdf0e10cSrcweir Reference< awt::XWindow > SAL_CALL PopupWindowController::createPopupWindow() throw (RuntimeException)
231cdf0e10cSrcweir {
232cdf0e10cSrcweir ToolBox* pToolBox = dynamic_cast< ToolBox* >( VCLUnoHelper::GetWindow( getParent() ) );
233cdf0e10cSrcweir if( pToolBox )
234cdf0e10cSrcweir {
235cdf0e10cSrcweir ::Window* pItemWindow = pToolBox->GetItemWindow( pToolBox->GetDownItemId() );
236cdf0e10cSrcweir ::Window* pWin = createPopupWindow( pItemWindow ? pItemWindow : pToolBox );
237cdf0e10cSrcweir if( pWin )
238cdf0e10cSrcweir {
239cdf0e10cSrcweir pWin->EnableDocking(true);
240cdf0e10cSrcweir mpImpl->SetPopupWindow(pWin,pToolBox);
241*5e6a02dfSAriel Constenla-Haile ::Window::GetDockingManager()->StartPopupMode( pToolBox, pWin,
242*5e6a02dfSAriel Constenla-Haile FLOATWIN_POPUPMODE_GRABFOCUS |
243*5e6a02dfSAriel Constenla-Haile FLOATWIN_POPUPMODE_NOFOCUSCLOSE |
244*5e6a02dfSAriel Constenla-Haile FLOATWIN_POPUPMODE_ALLMOUSEBUTTONCLOSE |
245*5e6a02dfSAriel Constenla-Haile FLOATWIN_POPUPMODE_NOMOUSEUPCLOSE );
246cdf0e10cSrcweir }
247cdf0e10cSrcweir }
248cdf0e10cSrcweir return Reference< awt::XWindow >();
249cdf0e10cSrcweir }
250cdf0e10cSrcweir
createItemWindow(const Reference<awt::XWindow> &)251cdf0e10cSrcweir Reference< awt::XWindow > SAL_CALL PopupWindowController::createItemWindow( const Reference< awt::XWindow >& /*Parent*/ )
252cdf0e10cSrcweir throw (RuntimeException)
253cdf0e10cSrcweir {
254cdf0e10cSrcweir return Reference< awt::XWindow >();
255cdf0e10cSrcweir }
256cdf0e10cSrcweir
257cdf0e10cSrcweir }
258