Coverage Report

Created: 2026-11-06 11:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sfx2/source/sidebar/SidebarDockingWindow.cxx
Line
Count
Source
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
#include <sfx2/sidebar/SidebarDockingWindow.hxx>
20
#include <sfx2/sidebar/SidebarChildWindow.hxx>
21
#include <sfx2/sidebar/SidebarController.hxx>
22
#include <sidebar/PanelDescriptor.hxx>
23
24
#include <comphelper/dispatchcommand.hxx>
25
#include <comphelper/lok.hxx>
26
#include <comphelper/processfactory.hxx>
27
#include <sfx2/bindings.hxx>
28
#include <sfx2/chalign.hxx>
29
#include <sfx2/dispatch.hxx>
30
#include <sfx2/viewfrm.hxx>
31
#include <svtools/acceleratorexecute.hxx>
32
#include <tools/gen.hxx>
33
#include <vcl/event.hxx>
34
#include <osl/diagnose.h>
35
36
#include <boost/property_tree/json_parser.hpp>
37
38
using namespace css;
39
using namespace css::uno;
40
41
namespace sfx2::sidebar {
42
43
SidebarDockingWindow::SidebarDockingWindow(SfxBindings& rSfxBindings,
44
                                           SidebarChildWindow& rChildWindow,
45
                                           vcl::Window* pParentWindow, WinBits nBits)
46
0
    : SfxDockingWindow(rSfxBindings, &rChildWindow, pParentWindow, nBits)
47
0
    , mbIsReadyToDrag(false)
48
0
{
49
    // Get the XFrame from the bindings.
50
0
    if (rSfxBindings.GetDispatcher() == nullptr)
51
0
    {
52
0
        OSL_ASSERT(rSfxBindings.GetDispatcher() != nullptr);
53
0
    }
54
0
    else if (!comphelper::LibreOfficeKit::isActive())
55
0
    {
56
0
        GetOrCreateSidebarController();
57
0
    }
58
0
}
Unexecuted instantiation: sfx2::sidebar::SidebarDockingWindow::SidebarDockingWindow(SfxBindings&, sfx2::sidebar::SidebarChildWindow&, vcl::Window*, long)
Unexecuted instantiation: sfx2::sidebar::SidebarDockingWindow::SidebarDockingWindow(SfxBindings&, sfx2::sidebar::SidebarChildWindow&, vcl::Window*, long)
59
60
rtl::Reference<sfx2::sidebar::SidebarController>& SidebarDockingWindow::GetOrCreateSidebarController()
61
0
{
62
0
    if (!mpSidebarController)
63
0
    {
64
0
        const SfxViewFrame* pViewFrame = GetBindings().GetDispatcher()->GetFrame();
65
0
        mpSidebarController = sfx2::sidebar::SidebarController::create(this, pViewFrame);
66
0
    }
67
68
0
    return mpSidebarController;
69
0
}
70
71
SidebarDockingWindow::~SidebarDockingWindow()
72
0
{
73
0
    disposeOnce();
74
0
}
75
76
void SidebarDockingWindow::dispose()
77
0
{
78
0
    rtl::Reference<SidebarController> xComponent = std::move(mpSidebarController);
79
0
    if (xComponent.is())
80
0
        xComponent->dispose();
81
82
0
    SfxDockingWindow::dispose();
83
0
}
84
85
void SidebarDockingWindow::GetFocus()
86
0
{
87
0
    if (mpSidebarController.is())
88
0
    {
89
0
        mpSidebarController->RequestOpenDeck();
90
0
        mpSidebarController->GetFocusManager().GrabFocus();
91
0
    }
92
0
    else
93
0
        SfxDockingWindow::GetFocus();
94
0
}
95
96
bool SidebarDockingWindow::Close()
97
0
{
98
0
    if (mpSidebarController.is())
99
0
        mpSidebarController->SetFloatingDeckClosed(true);
100
101
0
    return SfxDockingWindow::Close();
102
0
}
103
104
void SidebarDockingWindow::SyncUpdate()
105
0
{
106
0
    if (mpSidebarController.is())
107
0
        mpSidebarController->SyncUpdate();
108
0
}
109
110
SfxChildAlignment SidebarDockingWindow::CheckAlignment (
111
    SfxChildAlignment eCurrentAlignment,
112
    SfxChildAlignment eRequestedAlignment)
113
0
{
114
0
    switch (eRequestedAlignment)
115
0
    {
116
0
        case SfxChildAlignment::TOP:
117
0
        case SfxChildAlignment::HIGHESTTOP:
118
0
        case SfxChildAlignment::LOWESTTOP:
119
0
        case SfxChildAlignment::BOTTOM:
120
0
        case SfxChildAlignment::LOWESTBOTTOM:
121
0
        case SfxChildAlignment::HIGHESTBOTTOM:
122
0
            return eCurrentAlignment;
123
124
0
        case SfxChildAlignment::LEFT:
125
0
        case SfxChildAlignment::RIGHT:
126
0
        case SfxChildAlignment::FIRSTLEFT:
127
0
        case SfxChildAlignment::LASTLEFT:
128
0
        case SfxChildAlignment::FIRSTRIGHT:
129
0
        case SfxChildAlignment::LASTRIGHT:
130
0
            return eRequestedAlignment;
131
132
0
        default:
133
0
            return eRequestedAlignment;
134
0
    }
135
0
}
136
137
bool SidebarDockingWindow::EventNotify(NotifyEvent& rEvent)
138
0
{
139
0
    if (mpSidebarController)
140
0
    {
141
0
        NotifyEventType nType = rEvent.GetType();
142
0
        if (NotifyEventType::KEYINPUT == nType)
143
0
        {
144
0
            const vcl::KeyCode& rKeyCode = rEvent.GetKeyEvent()->GetKeyCode();
145
0
            switch (rKeyCode.GetCode())
146
0
            {
147
0
                case KEY_UP:
148
0
                case KEY_DOWN:
149
0
                case KEY_PAGEUP:
150
0
                case KEY_PAGEDOWN:
151
0
                case KEY_HOME:
152
0
                case KEY_END:
153
0
                case KEY_LEFT:
154
0
                case KEY_RIGHT:
155
0
                case KEY_BACKSPACE:
156
0
                case KEY_DELETE:
157
0
                case KEY_INSERT:
158
0
                case KEY_RETURN:
159
0
                case KEY_ESCAPE:
160
0
                {
161
0
                    return true;
162
0
                }
163
0
                default:
164
0
                break;
165
0
            }
166
0
            if (!mpAccel)
167
0
            {
168
0
                mpAccel = svt::AcceleratorExecute::createAcceleratorHelper();
169
0
                mpAccel->init(comphelper::getProcessComponentContext(), mpSidebarController->getXFrame());
170
0
            }
171
0
            const OUString aCommand(mpAccel->findCommand(svt::AcceleratorExecute::st_VCLKey2AWTKey(rKeyCode)));
172
0
            if (".uno:DesignerDialog" == aCommand)
173
0
            {
174
0
                std::shared_ptr<PanelDescriptor> xPanelDescriptor =
175
0
                        mpSidebarController->GetResourceManager()->GetPanelDescriptor( u"StyleListPanel" );
176
0
                if ( xPanelDescriptor && mpSidebarController->IsDeckVisible( xPanelDescriptor->msDeckId ) )
177
0
                    Close();
178
0
                return true;
179
0
            }
180
0
            if (".uno:Undo" == aCommand || ".uno:Redo" == aCommand)
181
0
            {
182
0
                comphelper::dispatchCommand(aCommand, {});
183
0
                return true;
184
0
            }
185
0
        }
186
0
        else if (NotifyEventType::MOUSEBUTTONDOWN == nType)
187
0
        {
188
0
            const MouseEvent *mEvt = rEvent.GetMouseEvent();
189
0
            if (mEvt->IsLeft())
190
0
            {
191
0
                tools::Rectangle aGrip = mpSidebarController->GetDeckDragArea();
192
0
                if ( aGrip.Contains( mEvt->GetPosPixel() ) )
193
0
                    mbIsReadyToDrag = true;
194
0
            }
195
0
        }
196
0
        else if (NotifyEventType::MOUSEMOVE == nType)
197
0
        {
198
0
            const MouseEvent *mEvt = rEvent.GetMouseEvent();
199
0
            tools::Rectangle aGrip = mpSidebarController->GetDeckDragArea();
200
0
            if (mEvt->IsLeft() && aGrip.Contains( mEvt->GetPosPixel() ) && mbIsReadyToDrag )
201
0
            {
202
0
                Point aPos = mEvt->GetPosPixel();
203
0
                vcl::Window* pWindow = rEvent.GetWindow();
204
0
                if ( pWindow != this )
205
0
                {
206
0
                    aPos = pWindow->OutputToScreenPixel( aPos );
207
0
                    aPos = ScreenToOutputPixel( aPos );
208
0
                }
209
0
                ImplStartDocking( aPos );
210
0
            }
211
0
        }
212
0
    }
213
214
0
    return SfxDockingWindow::EventNotify(rEvent);
215
0
}
216
217
} // end of namespace sfx2::sidebar
218
219
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */