1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <cppuhelper/supportsservice.hxx>
21 #include <toolkit/helper/vclunohelper.hxx>
23 #include <vcl/toolbox.hxx>
24 #include <vcl/svapp.hxx>
26 #include "svtools/popupwindowcontroller.hxx"
27 #include "svtools/toolbarmenu.hxx"
29 using namespace ::com::sun::star
;
30 using namespace ::com::sun::star::uno
;
31 using namespace ::com::sun::star::lang
;
37 class PopupWindowControllerImpl
40 PopupWindowControllerImpl();
41 ~PopupWindowControllerImpl();
43 void SetPopupWindow( ::Window
* pPopupWindow
, ToolBox
* pToolBox
);
45 DECL_LINK( WindowEventListener
, VclSimpleEvent
* );
46 DECL_STATIC_LINK( PopupWindowControllerImpl
, AsyncDeleteWindowHdl
, Window
* );
49 ::Window
* mpPopupWindow
;
53 PopupWindowControllerImpl::PopupWindowControllerImpl()
59 PopupWindowControllerImpl::~PopupWindowControllerImpl()
65 void PopupWindowControllerImpl::SetPopupWindow( ::Window
* pPopupWindow
, ToolBox
* pToolBox
)
69 mpPopupWindow
->RemoveEventListener( LINK( this, PopupWindowControllerImpl
, WindowEventListener
) );
70 Application::PostUserEvent( STATIC_LINK( this, PopupWindowControllerImpl
, AsyncDeleteWindowHdl
), mpPopupWindow
);
72 mpPopupWindow
= pPopupWindow
;
77 mpPopupWindow
->AddEventListener( LINK( this, PopupWindowControllerImpl
, WindowEventListener
));
81 IMPL_LINK( PopupWindowControllerImpl
, WindowEventListener
, VclSimpleEvent
*, pEvent
)
83 VclWindowEvent
* pWindowEvent
= dynamic_cast< VclWindowEvent
* >( pEvent
);
86 switch( pWindowEvent
->GetId() )
88 case VCLEVENT_WINDOW_CLOSE
:
89 case VCLEVENT_WINDOW_ENDPOPUPMODE
:
93 case VCLEVENT_WINDOW_SHOW
:
98 mpToolBox
->CallEventListeners( VCLEVENT_DROPDOWN_OPEN
, (void*)mpPopupWindow
);
99 mpPopupWindow
->CallEventListeners( VCLEVENT_WINDOW_GETFOCUS
, 0 );
101 svtools::ToolbarMenu
* pToolbarMenu
= dynamic_cast< svtools::ToolbarMenu
* >( mpPopupWindow
);
103 pToolbarMenu
->highlightFirstEntry();
108 case VCLEVENT_WINDOW_HIDE
:
112 mpPopupWindow
->CallEventListeners( VCLEVENT_WINDOW_LOSEFOCUS
, 0 );
114 mpToolBox
->CallEventListeners( VCLEVENT_DROPDOWN_CLOSE
, (void*)mpPopupWindow
);
123 //--------------------------------------------------------------------
125 IMPL_STATIC_LINK( PopupWindowControllerImpl
, AsyncDeleteWindowHdl
, Window
*, pWindow
)
132 //========================================================================
133 // class PopupWindowController
134 //========================================================================
136 PopupWindowController::PopupWindowController( const Reference
< uno::XComponentContext
>& rxContext
,
137 const Reference
< frame::XFrame
>& xFrame
,
138 const OUString
& aCommandURL
)
139 : svt::ToolboxController( rxContext
, xFrame
, aCommandURL
)
140 , mpImpl( new PopupWindowControllerImpl() )
144 PopupWindowController::~PopupWindowController()
149 Any SAL_CALL
PopupWindowController::queryInterface( const Type
& aType
)
150 throw (RuntimeException
)
152 Any
a( ToolboxController::queryInterface( aType
) );
156 return ::cppu::queryInterface( aType
, static_cast< lang::XServiceInfo
* >( this ));
159 void SAL_CALL
PopupWindowController::acquire() throw ()
161 ToolboxController::acquire();
164 void SAL_CALL
PopupWindowController::release() throw ()
166 ToolboxController::release();
170 sal_Bool SAL_CALL
PopupWindowController::supportsService( const OUString
& ServiceName
) throw(RuntimeException
)
172 return cppu::supportsService(this, ServiceName
);
176 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
)
178 svt::ToolboxController::initialize( aArguments
);
179 if( !m_aCommandURL
.isEmpty() )
180 addStatusListener( m_aCommandURL
);
184 void SAL_CALL
PopupWindowController::dispose() throw (RuntimeException
)
186 if( !m_aCommandURL
.isEmpty() )
187 removeStatusListener( m_aCommandURL
);
189 svt::ToolboxController::dispose();
194 void SAL_CALL
PopupWindowController::statusChanged( const frame::FeatureStateEvent
& rEvent
) throw ( RuntimeException
)
196 svt::ToolboxController::statusChanged(rEvent
);
197 enable( rEvent
.IsEnabled
);
200 // XToolbarController
201 void SAL_CALL
PopupWindowController::execute( sal_Int16 KeyModifier
) throw (RuntimeException
)
203 svt::ToolboxController::execute( KeyModifier
);
206 void SAL_CALL
PopupWindowController::click() throw (RuntimeException
)
208 svt::ToolboxController::click();
211 void SAL_CALL
PopupWindowController::doubleClick() throw (RuntimeException
)
213 svt::ToolboxController::doubleClick();
216 Reference
< awt::XWindow
> SAL_CALL
PopupWindowController::createPopupWindow() throw (RuntimeException
)
218 ToolBox
* pToolBox
= dynamic_cast< ToolBox
* >( VCLUnoHelper::GetWindow( getParent() ) );
221 ::Window
* pItemWindow
= pToolBox
->GetItemWindow( pToolBox
->GetDownItemId() );
222 ::Window
* pWin
= createPopupWindow( pItemWindow
? pItemWindow
: pToolBox
);
225 pWin
->EnableDocking(true);
226 mpImpl
->SetPopupWindow(pWin
,pToolBox
);
227 ::Window::GetDockingManager()->StartPopupMode( pToolBox
, pWin
,
228 FLOATWIN_POPUPMODE_GRABFOCUS
|
229 FLOATWIN_POPUPMODE_NOFOCUSCLOSE
|
230 FLOATWIN_POPUPMODE_ALLMOUSEBUTTONCLOSE
|
231 FLOATWIN_POPUPMODE_NOMOUSEUPCLOSE
);
234 return Reference
< awt::XWindow
>();
237 Reference
< awt::XWindow
> SAL_CALL
PopupWindowController::createItemWindow( const Reference
< awt::XWindow
>& /*Parent*/ )
238 throw (RuntimeException
)
240 return Reference
< awt::XWindow
>();
245 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */