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/processfactory.hxx>
26 #include <sfx2/bindings.hxx>
27 #include <sfx2/dispatch.hxx>
28 #include <sfx2/viewfrm.hxx>
29 #include <sfx2/viewsh.hxx>
30 #include <svtools/acceleratorexecute.hxx>
31 #include <tools/gen.hxx>
32 #include <tools/json_writer.hxx>
33 #include <vcl/event.hxx>
34 #include <comphelper/lok.hxx>
35 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
37 #include <boost/property_tree/json_parser.hpp>
40 using namespace css::uno
;
42 namespace sfx2::sidebar
{
44 SidebarDockingWindow::SidebarDockingWindow(SfxBindings
* pSfxBindings
, SidebarChildWindow
& rChildWindow
,
45 vcl::Window
* pParentWindow
, WinBits nBits
)
46 : SfxDockingWindow(pSfxBindings
, &rChildWindow
, pParentWindow
, nBits
)
47 , mbIsReadyToDrag(false)
49 // Get the XFrame from the bindings.
50 if (pSfxBindings
==nullptr || pSfxBindings
->GetDispatcher()==nullptr)
52 OSL_ASSERT(pSfxBindings
!=nullptr);
53 OSL_ASSERT(pSfxBindings
->GetDispatcher()!=nullptr);
55 else if (!comphelper::LibreOfficeKit::isActive())
57 GetOrCreateSidebarController();
61 rtl::Reference
<sfx2::sidebar::SidebarController
>& SidebarDockingWindow::GetOrCreateSidebarController()
63 if (!mpSidebarController
)
65 const SfxViewFrame
* pViewFrame
= GetBindings().GetDispatcher()->GetFrame();
66 mpSidebarController
= sfx2::sidebar::SidebarController::create(this, pViewFrame
);
69 return mpSidebarController
;
72 SidebarDockingWindow::~SidebarDockingWindow()
77 void SidebarDockingWindow::dispose()
79 Reference
<lang::XComponent
> xComponent(mpSidebarController
);
80 mpSidebarController
.clear();
82 xComponent
->dispose();
84 SfxDockingWindow::dispose();
87 void SidebarDockingWindow::GetFocus()
89 if (mpSidebarController
.is())
91 mpSidebarController
->RequestOpenDeck();
92 mpSidebarController
->GetFocusManager().GrabFocus();
95 SfxDockingWindow::GetFocus();
98 bool SidebarDockingWindow::Close()
100 if (mpSidebarController
.is())
101 mpSidebarController
->SetFloatingDeckClosed(true);
103 return SfxDockingWindow::Close();
106 void SidebarDockingWindow::SyncUpdate()
108 if (mpSidebarController
.is())
109 mpSidebarController
->SyncUpdate();
112 SfxChildAlignment
SidebarDockingWindow::CheckAlignment (
113 SfxChildAlignment eCurrentAlignment
,
114 SfxChildAlignment eRequestedAlignment
)
116 switch (eRequestedAlignment
)
118 case SfxChildAlignment::TOP
:
119 case SfxChildAlignment::HIGHESTTOP
:
120 case SfxChildAlignment::LOWESTTOP
:
121 case SfxChildAlignment::BOTTOM
:
122 case SfxChildAlignment::LOWESTBOTTOM
:
123 case SfxChildAlignment::HIGHESTBOTTOM
:
124 return eCurrentAlignment
;
126 case SfxChildAlignment::LEFT
:
127 case SfxChildAlignment::RIGHT
:
128 case SfxChildAlignment::FIRSTLEFT
:
129 case SfxChildAlignment::LASTLEFT
:
130 case SfxChildAlignment::FIRSTRIGHT
:
131 case SfxChildAlignment::LASTRIGHT
:
132 return eRequestedAlignment
;
135 return eRequestedAlignment
;
139 bool SidebarDockingWindow::EventNotify(NotifyEvent
& rEvent
)
141 MouseNotifyEvent nType
= rEvent
.GetType();
142 if (MouseNotifyEvent::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 (MouseNotifyEvent::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 (MouseNotifyEvent::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
);
213 return SfxDockingWindow::EventNotify(rEvent
);
216 } // end of namespace sfx2::sidebar
218 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */