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/svapp.hxx>
24 #include <vcl/toolbox.hxx>
26 #include <svtools/popupwindowcontroller.hxx>
27 #include <svtools/toolbarmenu.hxx>
29 using namespace ::com::sun::star
;
30 using namespace css::uno
;
31 using namespace css::lang
;
37 class PopupWindowControllerImpl
40 PopupWindowControllerImpl();
41 ~PopupWindowControllerImpl() COVERITY_NOEXCEPT_FALSE
;
43 void SetPopupWindow( vcl::Window
* pPopupWindow
, ToolBox
* pToolBox
);
44 void SetFloatingWindow();
45 DECL_LINK( WindowEventListener
, VclWindowEvent
&, void );
48 VclPtr
<vcl::Window
> mpPopupWindow
, mpFloatingWindow
;
49 VclPtr
<ToolBox
> mpToolBox
;
52 PopupWindowControllerImpl::PopupWindowControllerImpl()
56 PopupWindowControllerImpl::~PopupWindowControllerImpl() COVERITY_NOEXCEPT_FALSE
58 SetPopupWindow(nullptr,nullptr);
62 void PopupWindowControllerImpl::SetPopupWindow( vcl::Window
* pPopupWindow
, ToolBox
* pToolBox
)
66 mpPopupWindow
->RemoveEventListener( LINK( this, PopupWindowControllerImpl
, WindowEventListener
) );
67 mpPopupWindow
.disposeAndClear();
69 mpPopupWindow
= pPopupWindow
;
74 mpPopupWindow
->AddEventListener( LINK( this, PopupWindowControllerImpl
, WindowEventListener
));
78 void PopupWindowControllerImpl::SetFloatingWindow()
80 if( mpFloatingWindow
)
82 mpFloatingWindow
->RemoveEventListener( LINK( this, PopupWindowControllerImpl
, WindowEventListener
) );
83 mpFloatingWindow
.disposeAndClear();
85 mpFloatingWindow
= mpPopupWindow
;
86 mpPopupWindow
.clear();
89 IMPL_LINK( PopupWindowControllerImpl
, WindowEventListener
, VclWindowEvent
&, rWindowEvent
, void )
91 switch( rWindowEvent
.GetId() )
93 case VclEventId::WindowEndPopupMode
:
95 EndPopupModeData
* pData
= static_cast< EndPopupModeData
* >( rWindowEvent
.GetData() );
96 if( pData
&& pData
->mbTearoff
)
98 vcl::Window::GetDockingManager()->SetFloatingMode( mpPopupWindow
.get(), true );
99 vcl::Window::GetDockingManager()->SetPosSizePixel( mpPopupWindow
.get(),
100 pData
->maFloatingPos
.X(),
101 pData
->maFloatingPos
.Y(),
105 mpFloatingWindow
->Show( true, ShowFlags::NoFocusChange
| ShowFlags::NoActivate
);
107 SetPopupWindow(nullptr,nullptr);
110 case VclEventId::WindowPrepareToggleFloating
:
112 if ( mpFloatingWindow
&& rWindowEvent
.GetWindow() == mpFloatingWindow
.get() )
114 bool* pData
= static_cast< bool* >( rWindowEvent
.GetData() );
119 case VclEventId::WindowClose
:
121 SetPopupWindow(nullptr,nullptr);
125 case VclEventId::WindowShow
:
130 mpToolBox
->CallEventListeners( VclEventId::DropdownOpen
, static_cast<void*>(mpPopupWindow
) );
131 mpPopupWindow
->CallEventListeners( VclEventId::WindowGetFocus
);
136 case VclEventId::WindowHide
:
140 mpPopupWindow
->CallEventListeners( VclEventId::WindowLoseFocus
);
142 mpToolBox
->CallEventListeners( VclEventId::DropdownClose
, static_cast<void*>(mpPopupWindow
) );
153 PopupWindowController::PopupWindowController( const Reference
< uno::XComponentContext
>& rxContext
,
154 const Reference
< frame::XFrame
>& xFrame
,
155 const OUString
& aCommandURL
)
156 : PopupWindowController_Base( rxContext
, xFrame
, aCommandURL
)
157 , mxImpl( new PopupWindowControllerImpl() )
161 PopupWindowController::~PopupWindowController()
166 sal_Bool SAL_CALL
PopupWindowController::supportsService( const OUString
& ServiceName
)
168 return cppu::supportsService(this, ServiceName
);
172 void SAL_CALL
PopupWindowController::dispose()
174 mxInterimPopover
.clear();
175 mxPopoverContainer
.reset();
177 svt::ToolboxController::dispose();
181 void SAL_CALL
PopupWindowController::statusChanged( const frame::FeatureStateEvent
& rEvent
)
183 SolarMutexGuard aSolarLock
;
186 rEvent
.State
>>= bValue
;
190 m_pToolbar
->set_item_active(m_aCommandURL
, bValue
);
191 m_pToolbar
->set_item_sensitive(m_aCommandURL
, rEvent
.IsEnabled
);
195 ToolBox
* pToolBox
= nullptr;
196 ToolBoxItemId nItemId
;
197 if ( getToolboxId( nItemId
, &pToolBox
) )
199 pToolBox
->CheckItem( nItemId
, bValue
);
200 pToolBox
->EnableItem( nItemId
, rEvent
.IsEnabled
);
204 VclPtr
<vcl::Window
> PopupWindowController::createVclPopupWindow(vcl::Window
* /*pParent*/)
209 Reference
< awt::XWindow
> SAL_CALL
PopupWindowController::createPopupWindow()
213 mxPopoverContainer
->unsetPopover();
214 mxPopoverContainer
->setPopover(weldPopupWindow());
215 return Reference
<awt::XWindow
>();
218 VclPtr
< ToolBox
> pToolBox
= dynamic_cast< ToolBox
* >( VCLUnoHelper::GetWindow( getParent() ) );
221 vcl::Window
* pItemWindow
= pToolBox
->GetItemWindow( pToolBox
->GetDownItemId() );
222 VclPtr
<vcl::Window
> pWin
= createVclPopupWindow( pItemWindow
? pItemWindow
: pToolBox
);
225 FloatWinPopupFlags eFloatFlags
= FloatWinPopupFlags::GrabFocus
|
226 FloatWinPopupFlags::AllMouseButtonClose
|
227 FloatWinPopupFlags::NoMouseUpClose
;
230 if ( pWin
->GetType() == WindowType::DOCKINGWINDOW
)
231 nWinBits
= static_cast< DockingWindow
* >( pWin
.get() )->GetFloatStyle();
233 nWinBits
= pWin
->GetStyle();
235 if ( nWinBits
& ( WB_SIZEABLE
| WB_CLOSEABLE
) )
236 eFloatFlags
|= FloatWinPopupFlags::AllowTearOff
;
238 pWin
->EnableDocking();
239 mxImpl
->SetPopupWindow(pWin
,pToolBox
);
240 vcl::Window::GetDockingManager()->StartPopupMode( pToolBox
, pWin
, eFloatFlags
);
243 return Reference
< awt::XWindow
>();
246 void SAL_CALL
PopupWindowController::click()
250 if (m_pToolbar
->get_menu_item_active(m_aCommandURL
))
253 mxPopoverContainer
->unsetPopover();
256 svt::ToolboxController::click();
259 void PopupWindowController::EndPopupMode()
262 m_pToolbar
->set_menu_item_active(m_aCommandURL
, false);
263 else if (mxInterimPopover
)
264 mxInterimPopover
->EndPopupMode();
269 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */