LibreOffice Module svtools (master) 1
popupwindowcontroller.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
22
23#include <vcl/svapp.hxx>
24#include <vcl/toolbox.hxx>
25
28
29using namespace ::com::sun::star;
30using namespace css::uno;
31using namespace css::lang;
32
33
34namespace svt
35{
36
38{
39public:
41 ~PopupWindowControllerImpl() COVERITY_NOEXCEPT_FALSE;
42
43 void SetPopupWindow( vcl::Window* pPopupWindow, ToolBox* pToolBox );
44 void SetFloatingWindow();
45 DECL_LINK( WindowEventListener, VclWindowEvent&, void );
46
47private:
50};
51
53{
54}
55
57{
58 SetPopupWindow(nullptr,nullptr);
60}
61
63{
64 if( mpPopupWindow )
65 {
66 mpPopupWindow->RemoveEventListener( LINK( this, PopupWindowControllerImpl, WindowEventListener ) );
68 }
69 mpPopupWindow = pPopupWindow;
70 mpToolBox = pToolBox;
71
72 if( mpPopupWindow )
73 {
74 mpPopupWindow->AddEventListener( LINK( this, PopupWindowControllerImpl, WindowEventListener ));
75 }
76}
77
79{
81 {
82 mpFloatingWindow->RemoveEventListener( LINK( this, PopupWindowControllerImpl, WindowEventListener ) );
84 }
87}
88
89IMPL_LINK( PopupWindowControllerImpl, WindowEventListener, VclWindowEvent&, rWindowEvent, void )
90{
91 switch( rWindowEvent.GetId() )
92 {
93 case VclEventId::WindowEndPopupMode:
94 {
95 EndPopupModeData* pData = static_cast< EndPopupModeData* >( rWindowEvent.GetData() );
96 if( pData && pData->mbTearoff )
97 {
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 );
106 }
107 SetPopupWindow(nullptr,nullptr);
108 break;
109 }
110 case VclEventId::WindowPrepareToggleFloating:
111 {
112 if ( mpFloatingWindow && rWindowEvent.GetWindow() == mpFloatingWindow.get() )
113 {
114 bool* pData = static_cast< bool* >( rWindowEvent.GetData() );
115 *pData = false;
116 }
117 break;
118 }
119 case VclEventId::WindowClose:
120 {
121 SetPopupWindow(nullptr,nullptr);
122 SetFloatingWindow();
123 break;
124 }
125 case VclEventId::WindowShow:
126 {
127 if( mpPopupWindow )
128 {
129 if( mpToolBox )
130 mpToolBox->CallEventListeners( VclEventId::DropdownOpen, static_cast<void*>(mpPopupWindow) );
131 mpPopupWindow->CallEventListeners( VclEventId::WindowGetFocus );
132 break;
133 }
134 break;
135 }
136 case VclEventId::WindowHide:
137 {
138 if( mpPopupWindow )
139 {
140 mpPopupWindow->CallEventListeners( VclEventId::WindowLoseFocus );
141 if( mpToolBox )
142 mpToolBox->CallEventListeners( VclEventId::DropdownClose, static_cast<void*>(mpPopupWindow) );
143 }
144 break;
145 }
146 default: break;
147 }
148}
149
150
151
152
154 const Reference< frame::XFrame >& xFrame,
155 const OUString& aCommandURL )
156: PopupWindowController_Base( rxContext, xFrame, aCommandURL )
157, mxImpl( new PopupWindowControllerImpl() )
158{
159}
160
162{
163}
164
165// XServiceInfo
166sal_Bool SAL_CALL PopupWindowController::supportsService( const OUString& ServiceName )
167{
169}
170
171// XComponent
173{
175 mxPopoverContainer.reset();
176 mxImpl.reset();
178}
179
180// XStatusListener
181void SAL_CALL PopupWindowController::statusChanged( const frame::FeatureStateEvent& rEvent )
182{
183 SolarMutexGuard aSolarLock;
184
185 bool bValue = false;
186 rEvent.State >>= bValue;
187
188 if (m_pToolbar)
189 {
190 m_pToolbar->set_item_active(m_aCommandURL, bValue);
191 m_pToolbar->set_item_sensitive(m_aCommandURL, rEvent.IsEnabled);
192 return;
193 }
194
195 ToolBox* pToolBox = nullptr;
196 ToolBoxItemId nItemId;
197 if ( getToolboxId( nItemId, &pToolBox ) )
198 {
199 pToolBox->CheckItem( nItemId, bValue );
200 pToolBox->EnableItem( nItemId, rEvent.IsEnabled );
201 }
202}
203
205{
206 return nullptr;
207}
208
210{
211 if (m_pToolbar)
212 {
213 mxPopoverContainer->unsetPopover();
214 mxPopoverContainer->setPopover(weldPopupWindow());
216 }
217
218 VclPtr< ToolBox > pToolBox = dynamic_cast< ToolBox* >( VCLUnoHelper::GetWindow( getParent() ) );
219 if( pToolBox )
220 {
221 vcl::Window* pItemWindow = pToolBox->GetItemWindow( pToolBox->GetDownItemId() );
222 VclPtr<vcl::Window> pWin = createVclPopupWindow( pItemWindow ? pItemWindow : pToolBox );
223 if( pWin )
224 {
225 FloatWinPopupFlags eFloatFlags = FloatWinPopupFlags::GrabFocus |
226 FloatWinPopupFlags::AllMouseButtonClose |
227 FloatWinPopupFlags::NoMouseUpClose;
228
229 WinBits nWinBits;
230 if ( pWin->GetType() == WindowType::DOCKINGWINDOW )
231 nWinBits = static_cast< DockingWindow* >( pWin.get() )->GetFloatStyle();
232 else
233 nWinBits = pWin->GetStyle();
234
235 if ( nWinBits & ( WB_SIZEABLE | WB_CLOSEABLE ) )
236 eFloatFlags |= FloatWinPopupFlags::AllowTearOff;
237
238 pWin->EnableDocking();
239 mxImpl->SetPopupWindow(pWin,pToolBox);
240 vcl::Window::GetDockingManager()->StartPopupMode( pToolBox, pWin, eFloatFlags );
241 }
242 }
244}
245
247{
248 if (m_pToolbar)
249 {
250 if (m_pToolbar->get_menu_item_active(m_aCommandURL))
252 else
253 mxPopoverContainer->unsetPopover();
254 }
255
257}
258
260{
261 if (m_pToolbar)
262 m_pToolbar->set_menu_item_active(m_aCommandURL, false);
263 else if (mxInterimPopover)
264 mxInterimPopover->EndPopupMode();
265}
266
267}
268
269/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetFloatingMode(const vcl::Window *pWin, bool bFloating)
void SetPosSizePixel(vcl::Window const *pWin, tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight, PosSizeFlags nFlags)
void StartPopupMode(const vcl::Window *pWin, const tools::Rectangle &rRect, FloatWinPopupFlags nPopupModeFlags)
void EnableItem(ToolBoxItemId nItemId, bool bEnable=true)
void CheckItem(ToolBoxItemId nItemId, bool bCheck=true)
static vcl::Window * GetWindow(const css::uno::Reference< css::awt::XWindow > &rxWindow)
void disposeAndClear()
void clear()
reference_type * get() const
DECL_LINK(WindowEventListener, VclWindowEvent &, void)
void SetPopupWindow(vcl::Window *pPopupWindow, ToolBox *pToolBox)
~PopupWindowControllerImpl() COVERITY_NOEXCEPT_FALSE
virtual std::unique_ptr< WeldToolbarPopup > weldPopupWindow()=0
std::unique_ptr< PopupWindowControllerImpl, o3tl::default_delete< PopupWindowControllerImpl > > mxImpl
VclPtr< InterimToolbarPopup > mxInterimPopover
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual css::uno::Reference< css::awt::XWindow > SAL_CALL createPopupWindow() override
virtual void SAL_CALL click() override
virtual void SAL_CALL dispose() override
virtual VclPtr< vcl::Window > createVclPopupWindow(vcl::Window *pParent)
PopupWindowController(const css::uno::Reference< css::uno::XComponentContext > &rxContext, const css::uno::Reference< css::frame::XFrame > &xFrame, const OUString &aCommandURL)
virtual void SAL_CALL statusChanged(const css::frame::FeatureStateEvent &Event) override
std::unique_ptr< ToolbarPopupContainer > mxPopoverContainer
virtual ~PopupWindowController() override
virtual void SAL_CALL dispose() override
virtual void SAL_CALL click() override
static DockingManager * GetDockingManager()
std::unique_ptr< sal_Int32[]> pData
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
IMPL_LINK(AsyncPickerAction, OnActionDone, void *, pEmptyArg, void)
Reference< XFrame > xFrame
unsigned char sal_Bool
FloatWinPopupFlags
sal_Int64 WinBits
WinBits const WB_CLOSEABLE
WinBits const WB_SIZEABLE