Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / svtools / source / uno / popupwindowcontroller.cxx
blob41c8510c5f04b57c0494d75bbd0bae4bd13ec4b2
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 <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;
34 namespace svt
37 class PopupWindowControllerImpl
39 public:
40 PopupWindowControllerImpl();
41 ~PopupWindowControllerImpl() COVERITY_NOEXCEPT_FALSE;
43 void SetPopupWindow( vcl::Window* pPopupWindow, ToolBox* pToolBox );
44 void SetFloatingWindow();
45 DECL_LINK( WindowEventListener, VclWindowEvent&, void );
47 private:
48 VclPtr<vcl::Window> mpPopupWindow, mpFloatingWindow;
49 VclPtr<ToolBox> mpToolBox;
52 PopupWindowControllerImpl::PopupWindowControllerImpl()
56 PopupWindowControllerImpl::~PopupWindowControllerImpl() COVERITY_NOEXCEPT_FALSE
58 SetPopupWindow(nullptr,nullptr);
59 SetFloatingWindow();
62 void PopupWindowControllerImpl::SetPopupWindow( vcl::Window* pPopupWindow, ToolBox* pToolBox )
64 if( mpPopupWindow )
66 mpPopupWindow->RemoveEventListener( LINK( this, PopupWindowControllerImpl, WindowEventListener ) );
67 mpPopupWindow.disposeAndClear();
69 mpPopupWindow = pPopupWindow;
70 mpToolBox = pToolBox;
72 if( mpPopupWindow )
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(),
102 0, 0,
103 PosSizeFlags::Pos );
104 SetFloatingWindow();
105 mpFloatingWindow->Show( true, ShowFlags::NoFocusChange | ShowFlags::NoActivate );
107 SetPopupWindow(nullptr,nullptr);
108 break;
110 case VclEventId::WindowPrepareToggleFloating:
112 if ( mpFloatingWindow && rWindowEvent.GetWindow() == mpFloatingWindow.get() )
114 bool* pData = static_cast< bool* >( rWindowEvent.GetData() );
115 *pData = false;
117 break;
119 case VclEventId::WindowClose:
121 SetPopupWindow(nullptr,nullptr);
122 SetFloatingWindow();
123 break;
125 case VclEventId::WindowShow:
127 if( mpPopupWindow )
129 if( mpToolBox )
130 mpToolBox->CallEventListeners( VclEventId::DropdownOpen, static_cast<void*>(mpPopupWindow) );
131 mpPopupWindow->CallEventListeners( VclEventId::WindowGetFocus );
132 break;
134 break;
136 case VclEventId::WindowHide:
138 if( mpPopupWindow )
140 mpPopupWindow->CallEventListeners( VclEventId::WindowLoseFocus );
141 if( mpToolBox )
142 mpToolBox->CallEventListeners( VclEventId::DropdownClose, static_cast<void*>(mpPopupWindow) );
144 break;
146 default: break;
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()
165 // XServiceInfo
166 sal_Bool SAL_CALL PopupWindowController::supportsService( const OUString& ServiceName )
168 return cppu::supportsService(this, ServiceName);
171 // XComponent
172 void SAL_CALL PopupWindowController::dispose()
174 mxInterimPopover.clear();
175 mxPopoverContainer.reset();
176 mxImpl.reset();
177 svt::ToolboxController::dispose();
180 // XStatusListener
181 void SAL_CALL PopupWindowController::statusChanged( const frame::FeatureStateEvent& rEvent )
183 SolarMutexGuard aSolarLock;
185 bool bValue = false;
186 rEvent.State >>= bValue;
188 if (m_pToolbar)
190 m_pToolbar->set_item_active(m_aCommandURL, bValue);
191 m_pToolbar->set_item_sensitive(m_aCommandURL, rEvent.IsEnabled);
192 return;
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*/)
206 return nullptr;
209 Reference< awt::XWindow > SAL_CALL PopupWindowController::createPopupWindow()
211 if (m_pToolbar)
213 mxPopoverContainer->unsetPopover();
214 mxPopoverContainer->setPopover(weldPopupWindow());
215 return Reference<awt::XWindow>();
218 VclPtr< ToolBox > pToolBox = dynamic_cast< ToolBox* >( VCLUnoHelper::GetWindow( getParent() ) );
219 if( pToolBox )
221 vcl::Window* pItemWindow = pToolBox->GetItemWindow( pToolBox->GetDownItemId() );
222 VclPtr<vcl::Window> pWin = createVclPopupWindow( pItemWindow ? pItemWindow : pToolBox );
223 if( pWin )
225 FloatWinPopupFlags eFloatFlags = FloatWinPopupFlags::GrabFocus |
226 FloatWinPopupFlags::AllMouseButtonClose |
227 FloatWinPopupFlags::NoMouseUpClose;
229 WinBits nWinBits;
230 if ( pWin->GetType() == WindowType::DOCKINGWINDOW )
231 nWinBits = static_cast< DockingWindow* >( pWin.get() )->GetFloatStyle();
232 else
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()
248 if (m_pToolbar)
250 if (m_pToolbar->get_menu_item_active(m_aCommandURL))
251 createPopupWindow();
252 else
253 mxPopoverContainer->unsetPopover();
256 svt::ToolboxController::click();
259 void PopupWindowController::EndPopupMode()
261 if (m_pToolbar)
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: */