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 .
19 #include <sfx2/sidebar/SidebarDockingWindow.hxx>
20 #include <sfx2/sidebar/SidebarChildWindow.hxx>
21 #include <sfx2/sidebar/SidebarController.hxx>
22 #include <sidebar/PanelDescriptor.hxx>
24 #include <comphelper/dispatchcommand.hxx>
25 #include <comphelper/lok.hxx>
26 #include <comphelper/processfactory.hxx>
27 #include <sfx2/bindings.hxx>
28 #include <sfx2/dispatch.hxx>
29 #include <sfx2/viewfrm.hxx>
30 #include <svtools/acceleratorexecute.hxx>
31 #include <tools/gen.hxx>
32 #include <vcl/event.hxx>
33 #include <osl/diagnose.h>
35 #include <boost/property_tree/json_parser.hpp>
38 using namespace css::uno
;
40 namespace sfx2::sidebar
{
42 SidebarDockingWindow::SidebarDockingWindow(SfxBindings
* pSfxBindings
, SidebarChildWindow
& rChildWindow
,
43 vcl::Window
* pParentWindow
, WinBits nBits
)
44 : SfxDockingWindow(pSfxBindings
, &rChildWindow
, pParentWindow
, nBits
)
45 , mbIsReadyToDrag(false)
47 // Get the XFrame from the bindings.
48 if (pSfxBindings
==nullptr || pSfxBindings
->GetDispatcher()==nullptr)
50 assert(pSfxBindings
!= nullptr);
51 OSL_ASSERT(pSfxBindings
->GetDispatcher()!=nullptr);
53 else if (!comphelper::LibreOfficeKit::isActive())
55 GetOrCreateSidebarController();
59 rtl::Reference
<sfx2::sidebar::SidebarController
>& SidebarDockingWindow::GetOrCreateSidebarController()
61 if (!mpSidebarController
)
63 const SfxViewFrame
* pViewFrame
= GetBindings().GetDispatcher()->GetFrame();
64 mpSidebarController
= sfx2::sidebar::SidebarController::create(this, pViewFrame
);
67 return mpSidebarController
;
70 SidebarDockingWindow::~SidebarDockingWindow()
75 void SidebarDockingWindow::dispose()
77 Reference
<lang::XComponent
> xComponent(mpSidebarController
);
78 mpSidebarController
.clear();
80 xComponent
->dispose();
82 SfxDockingWindow::dispose();
85 void SidebarDockingWindow::GetFocus()
87 if (mpSidebarController
.is())
89 mpSidebarController
->RequestOpenDeck();
90 mpSidebarController
->GetFocusManager().GrabFocus();
93 SfxDockingWindow::GetFocus();
96 bool SidebarDockingWindow::Close()
98 if (mpSidebarController
.is())
99 mpSidebarController
->SetFloatingDeckClosed(true);
101 return SfxDockingWindow::Close();
104 void SidebarDockingWindow::SyncUpdate()
106 if (mpSidebarController
.is())
107 mpSidebarController
->SyncUpdate();
110 SfxChildAlignment
SidebarDockingWindow::CheckAlignment (
111 SfxChildAlignment eCurrentAlignment
,
112 SfxChildAlignment eRequestedAlignment
)
114 switch (eRequestedAlignment
)
116 case SfxChildAlignment::TOP
:
117 case SfxChildAlignment::HIGHESTTOP
:
118 case SfxChildAlignment::LOWESTTOP
:
119 case SfxChildAlignment::BOTTOM
:
120 case SfxChildAlignment::LOWESTBOTTOM
:
121 case SfxChildAlignment::HIGHESTBOTTOM
:
122 return eCurrentAlignment
;
124 case SfxChildAlignment::LEFT
:
125 case SfxChildAlignment::RIGHT
:
126 case SfxChildAlignment::FIRSTLEFT
:
127 case SfxChildAlignment::LASTLEFT
:
128 case SfxChildAlignment::FIRSTRIGHT
:
129 case SfxChildAlignment::LASTRIGHT
:
130 return eRequestedAlignment
;
133 return eRequestedAlignment
;
137 bool SidebarDockingWindow::EventNotify(NotifyEvent
& rEvent
)
139 if (mpSidebarController
)
141 NotifyEventType nType
= rEvent
.GetType();
142 if (NotifyEventType::KEYINPUT
== nType
)
144 const vcl::KeyCode
& rKeyCode
= rEvent
.GetKeyEvent()->GetKeyCode();
145 switch (rKeyCode
.GetCode())
168 mpAccel
= svt::AcceleratorExecute::createAcceleratorHelper();
169 mpAccel
->init(comphelper::getProcessComponentContext(), mpSidebarController
->getXFrame());
171 const OUString
aCommand(mpAccel
->findCommand(svt::AcceleratorExecute::st_VCLKey2AWTKey(rKeyCode
)));
172 if (".uno:DesignerDialog" == aCommand
)
174 std::shared_ptr
<PanelDescriptor
> xPanelDescriptor
=
175 mpSidebarController
->GetResourceManager()->GetPanelDescriptor( u
"StyleListPanel" );
176 if ( xPanelDescriptor
&& mpSidebarController
->IsDeckVisible( xPanelDescriptor
->msDeckId
) )
180 if (".uno:Undo" == aCommand
|| ".uno:Redo" == aCommand
)
182 comphelper::dispatchCommand(aCommand
, {});
186 else if (NotifyEventType::MOUSEBUTTONDOWN
== nType
)
188 const MouseEvent
*mEvt
= rEvent
.GetMouseEvent();
191 tools::Rectangle aGrip
= mpSidebarController
->GetDeckDragArea();
192 if ( aGrip
.Contains( mEvt
->GetPosPixel() ) )
193 mbIsReadyToDrag
= true;
196 else if (NotifyEventType::MOUSEMOVE
== nType
)
198 const MouseEvent
*mEvt
= rEvent
.GetMouseEvent();
199 tools::Rectangle aGrip
= mpSidebarController
->GetDeckDragArea();
200 if (mEvt
->IsLeft() && aGrip
.Contains( mEvt
->GetPosPixel() ) && mbIsReadyToDrag
)
202 Point aPos
= mEvt
->GetPosPixel();
203 vcl::Window
* pWindow
= rEvent
.GetWindow();
204 if ( pWindow
!= this )
206 aPos
= pWindow
->OutputToScreenPixel( aPos
);
207 aPos
= ScreenToOutputPixel( aPos
);
209 ImplStartDocking( aPos
);
214 return SfxDockingWindow::EventNotify(rEvent
);
217 } // end of namespace sfx2::sidebar
219 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */