fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / svtools / source / uno / popupwindowcontroller.cxx
blob39ceb320d424c0ff819ff5b1df7c001378f81a38
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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;
35 namespace svt
38 class PopupWindowControllerImpl
40 public:
41 PopupWindowControllerImpl();
42 ~PopupWindowControllerImpl();
44 void SetPopupWindow( vcl::Window* pPopupWindow, ToolBox* pToolBox );
45 DECL_LINK( WindowEventListener, VclSimpleEvent* );
47 private:
48 VclPtr<vcl::Window> mpPopupWindow;
49 VclPtr<ToolBox> mpToolBox;
52 PopupWindowControllerImpl::PopupWindowControllerImpl()
53 : mpPopupWindow( 0 )
54 , mpToolBox( 0 )
58 PopupWindowControllerImpl::~PopupWindowControllerImpl()
60 if( mpPopupWindow )
61 SetPopupWindow(0,0);
64 void PopupWindowControllerImpl::SetPopupWindow( vcl::Window* pPopupWindow, ToolBox* pToolBox )
66 if( mpPopupWindow )
68 mpPopupWindow->RemoveEventListener( LINK( this, PopupWindowControllerImpl, WindowEventListener ) );
69 mpPopupWindow.disposeAndClear();
71 mpPopupWindow = pPopupWindow;
72 mpToolBox = pToolBox;
74 if( mpPopupWindow )
76 mpPopupWindow->AddEventListener( LINK( this, PopupWindowControllerImpl, WindowEventListener ));
80 IMPL_LINK( PopupWindowControllerImpl, WindowEventListener, VclSimpleEvent*, pEvent )
82 VclWindowEvent* pWindowEvent = dynamic_cast< VclWindowEvent* >( pEvent );
83 if( pWindowEvent )
85 switch( pWindowEvent->GetId() )
87 case VCLEVENT_WINDOW_CLOSE:
88 case VCLEVENT_WINDOW_ENDPOPUPMODE:
89 SetPopupWindow(0,0);
90 break;
92 case VCLEVENT_WINDOW_SHOW:
94 if( mpPopupWindow )
96 if( mpToolBox )
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() );
101 if( pToolbarMenu )
102 pToolbarMenu->highlightFirstEntry();
103 break;
105 break;
107 case VCLEVENT_WINDOW_HIDE:
109 if( mpPopupWindow )
111 mpPopupWindow->CallEventListeners( VCLEVENT_WINDOW_LOSEFOCUS, 0 );
112 if( mpToolBox )
113 mpToolBox->CallEventListeners( VCLEVENT_DROPDOWN_CLOSE, (void*)mpPopupWindow );
115 break;
119 return 1;
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()
138 // XInterface
139 Any SAL_CALL PopupWindowController::queryInterface( const Type& aType )
140 throw (RuntimeException, std::exception)
142 Any a( ToolboxController::queryInterface( aType ) );
143 if ( a.hasValue() )
144 return a;
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();
159 // XServiceInfo
160 sal_Bool SAL_CALL PopupWindowController::supportsService( const OUString& ServiceName ) throw(RuntimeException, std::exception)
162 return cppu::supportsService(this, ServiceName);
165 // XInitialization
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 );
173 // XComponent
174 void SAL_CALL PopupWindowController::dispose() throw (RuntimeException, std::exception)
176 if( !m_aCommandURL.isEmpty() )
177 removeStatusListener( m_aCommandURL );
179 svt::ToolboxController::dispose();
183 // XStatusListener
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() );
209 if( pToolBox )
211 vcl::Window* pItemWindow = pToolBox->GetItemWindow( pToolBox->GetDownItemId() );
212 vcl::Window* pWin = createPopupWindow( pItemWindow ? pItemWindow : pToolBox );
213 if( pWin )
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: */