Coverage Report

Created: 2025-12-31 10:39

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