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 <cppuhelper/queryinterface.hxx>
22 #include <toolkit/helper/vclunohelper.hxx>
24 #include <vcl/toolbox.hxx>
25 #include <vcl/svapp.hxx>
27 #include <svtools/popupwindowcontroller.hxx>
28 #include <svtools/toolbarmenu.hxx>
30 using namespace ::com::sun::star
;
31 using namespace ::com::sun::star::uno
;
32 using namespace ::com::sun::star::lang
;
38 class PopupWindowControllerImpl
41 PopupWindowControllerImpl();
42 ~PopupWindowControllerImpl();
44 void SetPopupWindow( vcl::Window
* pPopupWindow
, ToolBox
* pToolBox
);
45 DECL_LINK( WindowEventListener
, VclSimpleEvent
* );
48 VclPtr
<vcl::Window
> mpPopupWindow
;
49 VclPtr
<ToolBox
> mpToolBox
;
52 PopupWindowControllerImpl::PopupWindowControllerImpl()
58 PopupWindowControllerImpl::~PopupWindowControllerImpl()
64 void PopupWindowControllerImpl::SetPopupWindow( vcl::Window
* pPopupWindow
, ToolBox
* pToolBox
)
68 mpPopupWindow
->RemoveEventListener( LINK( this, PopupWindowControllerImpl
, WindowEventListener
) );
69 mpPopupWindow
.disposeAndClear();
71 mpPopupWindow
= pPopupWindow
;
76 mpPopupWindow
->AddEventListener( LINK( this, PopupWindowControllerImpl
, WindowEventListener
));
80 IMPL_LINK( PopupWindowControllerImpl
, WindowEventListener
, VclSimpleEvent
*, pEvent
)
82 VclWindowEvent
* pWindowEvent
= dynamic_cast< VclWindowEvent
* >( pEvent
);
85 switch( pWindowEvent
->GetId() )
87 case VCLEVENT_WINDOW_CLOSE
:
88 case VCLEVENT_WINDOW_ENDPOPUPMODE
:
92 case VCLEVENT_WINDOW_SHOW
:
97 mpToolBox
->CallEventListeners( VCLEVENT_DROPDOWN_OPEN
, (void*)mpPopupWindow
);
98 mpPopupWindow
->CallEventListeners( VCLEVENT_WINDOW_GETFOCUS
, 0 );
100 svtools::ToolbarMenu
* pToolbarMenu
= dynamic_cast< svtools::ToolbarMenu
* >( mpPopupWindow
.get() );
102 pToolbarMenu
->highlightFirstEntry();
107 case VCLEVENT_WINDOW_HIDE
:
111 mpPopupWindow
->CallEventListeners( VCLEVENT_WINDOW_LOSEFOCUS
, 0 );
113 mpToolBox
->CallEventListeners( VCLEVENT_DROPDOWN_CLOSE
, (void*)mpPopupWindow
);
123 // class PopupWindowController
126 PopupWindowController::PopupWindowController( const Reference
< uno::XComponentContext
>& rxContext
,
127 const Reference
< frame::XFrame
>& xFrame
,
128 const OUString
& aCommandURL
)
129 : svt::ToolboxController( rxContext
, xFrame
, aCommandURL
)
130 , mxImpl( new PopupWindowControllerImpl() )
134 PopupWindowController::~PopupWindowController()
139 Any SAL_CALL
PopupWindowController::queryInterface( const Type
& aType
)
140 throw (RuntimeException
, std::exception
)
142 Any
a( ToolboxController::queryInterface( aType
) );
146 return ::cppu::queryInterface( aType
, static_cast< lang::XServiceInfo
* >( this ));
149 void SAL_CALL
PopupWindowController::acquire() throw ()
151 ToolboxController::acquire();
154 void SAL_CALL
PopupWindowController::release() throw ()
156 ToolboxController::release();
160 sal_Bool SAL_CALL
PopupWindowController::supportsService( const OUString
& ServiceName
) throw(RuntimeException
, std::exception
)
162 return cppu::supportsService(this, ServiceName
);
166 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
, std::exception
)
168 svt::ToolboxController::initialize( aArguments
);
169 if( !m_aCommandURL
.isEmpty() )
170 addStatusListener( m_aCommandURL
);
174 void SAL_CALL
PopupWindowController::dispose() throw (RuntimeException
, std::exception
)
176 if( !m_aCommandURL
.isEmpty() )
177 removeStatusListener( m_aCommandURL
);
179 svt::ToolboxController::dispose();
184 void SAL_CALL
PopupWindowController::statusChanged( const frame::FeatureStateEvent
& rEvent
) throw ( RuntimeException
, std::exception
)
186 svt::ToolboxController::statusChanged(rEvent
);
187 enable( rEvent
.IsEnabled
);
190 // XToolbarController
191 void SAL_CALL
PopupWindowController::execute( sal_Int16 KeyModifier
) throw (RuntimeException
, std::exception
)
193 svt::ToolboxController::execute( KeyModifier
);
196 void SAL_CALL
PopupWindowController::click() throw (RuntimeException
, std::exception
)
198 svt::ToolboxController::click();
201 void SAL_CALL
PopupWindowController::doubleClick() throw (RuntimeException
, std::exception
)
203 svt::ToolboxController::doubleClick();
206 Reference
< awt::XWindow
> SAL_CALL
PopupWindowController::createPopupWindow() throw (RuntimeException
, std::exception
)
208 VclPtr
< ToolBox
> pToolBox
= dynamic_cast< ToolBox
* >( VCLUnoHelper::GetWindow( getParent() ).get() );
211 vcl::Window
* pItemWindow
= pToolBox
->GetItemWindow( pToolBox
->GetDownItemId() );
212 vcl::Window
* pWin
= createPopupWindow( pItemWindow
? pItemWindow
: pToolBox
);
215 pWin
->EnableDocking(true);
216 mxImpl
->SetPopupWindow(pWin
,pToolBox
);
217 vcl::Window::GetDockingManager()->StartPopupMode( pToolBox
, pWin
,
218 FloatWinPopupFlags::GrabFocus
|
219 FloatWinPopupFlags::NoFocusClose
|
220 FloatWinPopupFlags::AllMouseButtonClose
|
221 FloatWinPopupFlags::NoMouseUpClose
);
224 return Reference
< awt::XWindow
>();
227 Reference
< awt::XWindow
> SAL_CALL
PopupWindowController::createItemWindow( const Reference
< awt::XWindow
>& /*Parent*/ )
228 throw (RuntimeException
, std::exception
)
230 return Reference
< awt::XWindow
>();
235 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */