LibreOffice Module sfx2 (master) 1
SidebarDockingWindow.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 */
23
25#include <comphelper/lok.hxx>
27#include <sfx2/bindings.hxx>
28#include <sfx2/dispatch.hxx>
29#include <sfx2/viewfrm.hxx>
31#include <tools/gen.hxx>
32#include <vcl/event.hxx>
33#include <osl/diagnose.h>
34
35#include <boost/property_tree/json_parser.hpp>
36
37using namespace css;
38using namespace css::uno;
39
40namespace sfx2::sidebar {
41
43 vcl::Window* pParentWindow, WinBits nBits)
44 : SfxDockingWindow(pSfxBindings, &rChildWindow, pParentWindow, nBits)
45 , mbIsReadyToDrag(false)
46{
47 // Get the XFrame from the bindings.
48 if (pSfxBindings==nullptr || pSfxBindings->GetDispatcher()==nullptr)
49 {
50 OSL_ASSERT(pSfxBindings!=nullptr);
51 OSL_ASSERT(pSfxBindings->GetDispatcher()!=nullptr);
52 }
54 {
56 }
57}
58
60{
62 {
63 const SfxViewFrame* pViewFrame = GetBindings().GetDispatcher()->GetFrame();
65 }
66
68}
69
71{
73}
74
76{
77 Reference<lang::XComponent> xComponent(mpSidebarController);
78 mpSidebarController.clear();
79 if (xComponent.is())
80 xComponent->dispose();
81
83}
84
86{
87 if (mpSidebarController.is())
88 {
89 mpSidebarController->RequestOpenDeck();
90 mpSidebarController->GetFocusManager().GrabFocus();
91 }
92 else
94}
95
97{
98 if (mpSidebarController.is())
99 mpSidebarController->SetFloatingDeckClosed(true);
100
102}
103
105{
106 if (mpSidebarController.is())
107 mpSidebarController->SyncUpdate();
108}
109
111 SfxChildAlignment eCurrentAlignment,
112 SfxChildAlignment eRequestedAlignment)
113{
114 switch (eRequestedAlignment)
115 {
122 return eCurrentAlignment;
123
130 return eRequestedAlignment;
131
132 default:
133 return eRequestedAlignment;
134 }
135}
136
138{
139 NotifyEventType nType = rEvent.GetType();
140 if (NotifyEventType::KEYINPUT == nType)
141 {
142 const vcl::KeyCode& rKeyCode = rEvent.GetKeyEvent()->GetKeyCode();
143 switch (rKeyCode.GetCode())
144 {
145 case KEY_UP:
146 case KEY_DOWN:
147 case KEY_PAGEUP:
148 case KEY_PAGEDOWN:
149 case KEY_HOME:
150 case KEY_END:
151 case KEY_LEFT:
152 case KEY_RIGHT:
153 case KEY_BACKSPACE:
154 case KEY_DELETE:
155 case KEY_INSERT:
156 case KEY_RETURN:
157 case KEY_ESCAPE:
158 {
159 return true;
160 }
161 default:
162 break;
163 }
164 if (!mpAccel)
165 {
168 }
169 const OUString aCommand(mpAccel->findCommand(svt::AcceleratorExecute::st_VCLKey2AWTKey(rKeyCode)));
170 if (".uno:DesignerDialog" == aCommand)
171 {
172 std::shared_ptr<PanelDescriptor> xPanelDescriptor =
173 mpSidebarController->GetResourceManager()->GetPanelDescriptor( u"StyleListPanel" );
174 if ( xPanelDescriptor && mpSidebarController->IsDeckVisible( xPanelDescriptor->msDeckId ) )
175 Close();
176 return true;
177 }
178 if (".uno:Undo" == aCommand || ".uno:Redo" == aCommand)
179 {
181 return true;
182 }
183 }
184 else if (NotifyEventType::MOUSEBUTTONDOWN == nType)
185 {
186 const MouseEvent *mEvt = rEvent.GetMouseEvent();
187 if (mEvt->IsLeft())
188 {
189 tools::Rectangle aGrip = mpSidebarController->GetDeckDragArea();
190 if ( aGrip.Contains( mEvt->GetPosPixel() ) )
191 mbIsReadyToDrag = true;
192 }
193 }
194 else if (NotifyEventType::MOUSEMOVE == nType)
195 {
196 const MouseEvent *mEvt = rEvent.GetMouseEvent();
197 tools::Rectangle aGrip = mpSidebarController->GetDeckDragArea();
198 if (mEvt->IsLeft() && aGrip.Contains( mEvt->GetPosPixel() ) && mbIsReadyToDrag )
199 {
200 Point aPos = mEvt->GetPosPixel();
201 vcl::Window* pWindow = rEvent.GetWindow();
202 if ( pWindow != this )
203 {
204 aPos = pWindow->OutputToScreenPixel( aPos );
205 aPos = ScreenToOutputPixel( aPos );
206 }
207 ImplStartDocking( aPos );
208 }
209 }
210
211 return SfxDockingWindow::EventNotify(rEvent);
212}
213
214} // end of namespace sfx2::sidebar
215
216/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SfxChildAlignment
Definition: chalign.hxx:27
void ImplStartDocking(const Point &rPos)
const vcl::KeyCode & GetKeyCode() const
const Point & GetPosPixel() const
bool IsLeft() const
const KeyEvent * GetKeyEvent() const
vcl::Window * GetWindow() const
const MouseEvent * GetMouseEvent() const
NotifyEventType GetType() const
SfxDispatcher * GetDispatcher() const
Definition: bindings.hxx:172
SfxViewFrame * GetFrame() const
Returns a pointer to the <SfxViewFrame> instance, which belongs to this SfxDispatcher.
Definition: dispatch.cxx:557
SfxBindings & GetBindings() const
Definition: dockwin.hxx:96
virtual bool EventNotify(NotifyEvent &rNEvt) override
Definition: dockwin.cxx:1440
virtual bool Close() override
The window is closed when the ChildWindow is destroyed by running the ChildWindow-slots.
Definition: dockwin.cxx:1408
virtual void dispose() override
Definition: dockwin.cxx:1032
Outer container of the sidebar window.
static rtl::Reference< SidebarController > create(SidebarDockingWindow *pParentWindow, const SfxViewFrame *pViewFrame)
rtl::Reference< sfx2::sidebar::SidebarController > & GetOrCreateSidebarController()
virtual bool Close() override
The window is closed when the ChildWindow is destroyed by running the ChildWindow-slots.
std::unique_ptr< svt::AcceleratorExecute > mpAccel
virtual SfxChildAlignment CheckAlignment(SfxChildAlignment eCurrentAlignment, SfxChildAlignment eRequestedAlignment) override
Virtual method of the SfxDockingWindow class.
::rtl::Reference< sfx2::sidebar::SidebarController > mpSidebarController
void SyncUpdate()
Force generation of all panels by completion.
virtual bool EventNotify(NotifyEvent &rEvent) override
SidebarDockingWindow(SfxBindings *pBindings, SidebarChildWindow &rChildWindow, vcl::Window *pParent, WinBits nBits)
static css::awt::KeyEvent st_VCLKey2AWTKey(const vcl::KeyCode &aKey)
static std::unique_ptr< AcceleratorExecute > createAcceleratorHelper()
bool Contains(const Point &rPOINT) const
sal_uInt16 GetCode() const
Point OutputToScreenPixel(const Point &rPos) const
virtual void GetFocus()
Point ScreenToOutputPixel(const Point &rPos) const
float u
NotifyEventType
constexpr sal_uInt16 KEY_RETURN
constexpr sal_uInt16 KEY_ESCAPE
constexpr sal_uInt16 KEY_HOME
constexpr sal_uInt16 KEY_LEFT
constexpr sal_uInt16 KEY_PAGEDOWN
constexpr sal_uInt16 KEY_UP
constexpr sal_uInt16 KEY_RIGHT
constexpr sal_uInt16 KEY_DELETE
constexpr sal_uInt16 KEY_DOWN
constexpr sal_uInt16 KEY_PAGEUP
constexpr sal_uInt16 KEY_INSERT
constexpr sal_uInt16 KEY_BACKSPACE
constexpr sal_uInt16 KEY_END
bool dispatchCommand(const OUString &rCommand, const uno::Reference< css::frame::XFrame > &rFrame, const css::uno::Sequence< css::beans::PropertyValue > &rArguments, const uno::Reference< css::frame::XDispatchResultListener > &rListener)
Reference< XComponentContext > getProcessComponentContext()
QPRO_FUNC_TYPE nType
OUString aCommand
sal_Int64 WinBits