Coverage Report

Created: 2026-06-30 11:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/vcl/source/window/dockingarea.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
20
#include <vcl/dockingarea.hxx>
21
#include <vcl/syswin.hxx>
22
#include <vcl/menu.hxx>
23
#include <vcl/settings.hxx>
24
#include <vcl/event.hxx>
25
#include <toolbarvalue.hxx>
26
27
#include <svdata.hxx>
28
29
#include <map>
30
31
class DockingAreaWindow::ImplData
32
{
33
public:
34
    ImplData();
35
36
    WindowAlign meAlign;
37
};
38
39
DockingAreaWindow::ImplData::ImplData()
40
49.7k
{
41
49.7k
    meAlign = WindowAlign::Top;
42
49.7k
}
43
44
DockingAreaWindow::DockingAreaWindow( vcl::Window* pParent ) :
45
49.7k
    Window( WindowType::DOCKINGAREA )
46
49.7k
{
47
49.7k
    ImplInit( pParent, WB_CLIPCHILDREN|WB_3DLOOK, nullptr );
48
49
49.7k
    mpImplData.reset(new ImplData);
50
49.7k
}
Unexecuted instantiation: DockingAreaWindow::DockingAreaWindow(vcl::Window*)
DockingAreaWindow::DockingAreaWindow(vcl::Window*)
Line
Count
Source
45
49.7k
    Window( WindowType::DOCKINGAREA )
46
49.7k
{
47
49.7k
    ImplInit( pParent, WB_CLIPCHILDREN|WB_3DLOOK, nullptr );
48
49
49.7k
    mpImplData.reset(new ImplData);
50
49.7k
}
51
52
DockingAreaWindow::~DockingAreaWindow()
53
32.0k
{
54
32.0k
    disposeOnce();
55
32.0k
}
56
57
void DockingAreaWindow::dispose()
58
32.0k
{
59
32.0k
    mpImplData.reset();
60
32.0k
    Window::dispose();
61
32.0k
}
62
63
void DockingAreaWindow::DataChanged( const DataChangedEvent& rDCEvt )
64
0
{
65
0
    Window::DataChanged( rDCEvt );
66
67
0
    if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) && (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
68
0
    {
69
0
        Invalidate();
70
0
    }
71
0
}
72
73
static void ImplInvalidateMenubar( DockingAreaWindow const * pThis )
74
0
{
75
    // due to a possible common gradient covering menubar and top dockingarea
76
    // the menubar must be repainted if the top dockingarea changes size or visibility
77
0
    if( ImplGetSVData()->maNWFData.mbMenuBarDockingAreaCommonBG &&
78
0
        (pThis->GetAlign() == WindowAlign::Top)
79
0
        && pThis->IsNativeControlSupported( ControlType::Toolbar, ControlPart::Entire )
80
0
        && pThis->IsNativeControlSupported( ControlType::Menubar, ControlPart::Entire ) )
81
0
    {
82
0
        SystemWindow *pSysWin = pThis->GetSystemWindow();
83
0
        if( pSysWin && pSysWin->GetMenuBar() )
84
0
        {
85
0
            vcl::Window *pMenubarWin = pSysWin->GetMenuBar()->GetWindow();
86
0
            if( pMenubarWin )
87
0
                pMenubarWin->Invalidate();
88
0
        }
89
0
    }
90
0
}
91
92
void DockingAreaWindow::StateChanged( StateChangedType nType )
93
0
{
94
0
    Window::StateChanged( nType );
95
96
0
    if ( nType == StateChangedType::Visible )
97
0
        ImplInvalidateMenubar( this );
98
0
}
99
100
bool DockingAreaWindow::IsHorizontal() const
101
0
{
102
0
    return ( mpImplData->meAlign == WindowAlign::Top || mpImplData->meAlign == WindowAlign::Bottom );
103
0
}
104
105
void DockingAreaWindow::SetAlign( WindowAlign eNewAlign )
106
49.7k
{
107
49.7k
    if( eNewAlign != mpImplData->meAlign )
108
37.3k
    {
109
37.3k
        mpImplData->meAlign = eNewAlign;
110
37.3k
        Invalidate();
111
37.3k
    }
112
49.7k
}
113
114
WindowAlign DockingAreaWindow::GetAlign() const
115
0
{
116
0
    return mpImplData->meAlign;
117
0
}
118
119
void DockingAreaWindow::ApplySettings(vcl::RenderContext& rRenderContext)
120
0
{
121
0
    const StyleSettings rSetting = rRenderContext.GetSettings().GetStyleSettings();
122
123
0
    if (!rRenderContext.IsNativeControlSupported(ControlType::Toolbar, ControlPart::Entire))
124
0
    {
125
0
        Wallpaper aWallpaper;
126
0
        aWallpaper.SetStyle(WallpaperStyle::ApplicationGradient);
127
0
        rRenderContext.SetBackground(aWallpaper);
128
0
    }
129
0
    else
130
0
        rRenderContext.SetBackground(Wallpaper(rSetting.GetFaceColor()));
131
132
0
}
133
134
void DockingAreaWindow::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&)
135
0
{
136
0
    EnableNativeWidget(); // only required because the toolkit currently switches this flag off
137
0
    if (!rRenderContext.IsNativeControlSupported(ControlType::Toolbar, ControlPart::Entire))
138
0
        return;
139
140
0
    ToolbarValue aControlValue;
141
142
0
    if (GetAlign() == WindowAlign::Top && ImplGetSVData()->maNWFData.mbMenuBarDockingAreaCommonBG)
143
0
    {
144
        // give NWF a hint that this dockingarea is adjacent to the menubar
145
        // useful for special gradient effects that should cover both windows
146
0
        aControlValue.mbIsTopDockingArea = true;
147
0
    }
148
149
0
    ControlState nState = ControlState::ENABLED;
150
0
    if (!ImplGetSVData()->maNWFData.mbDockingAreaSeparateTB)
151
0
    {
152
        // draw a single toolbar background covering the whole docking area
153
0
        tools::Rectangle aCtrlRegion(Point(), GetOutputSizePixel());
154
155
0
        rRenderContext.DrawNativeControl(ControlType::Toolbar, IsHorizontal() ? ControlPart::DrawBackgroundHorz : ControlPart::DrawBackgroundVert,
156
0
                                         aCtrlRegion, nState, aControlValue, OUString() );
157
158
0
        if (!ImplGetSVData()->maNWFData.mbDockingAreaAvoidTBFrames)
159
0
        {
160
            // each toolbar gets a thin border to better recognize its borders on the homogeneous docking area
161
0
            sal_uInt16 nChildren = GetChildCount();
162
0
            for (sal_uInt16 n = 0; n < nChildren; n++)
163
0
            {
164
0
                vcl::Window* pChild = GetChild(n);
165
0
                if (pChild->IsVisible())
166
0
                {
167
0
                    Point aPos = pChild->GetPosPixel();
168
0
                    Size aSize = pChild->GetSizePixel();
169
0
                    tools::Rectangle aRect(aPos, aSize);
170
171
0
                    rRenderContext.SetLineColor(rRenderContext.GetSettings().GetStyleSettings().GetLightColor());
172
0
                    rRenderContext.DrawLine(aRect.TopLeft(), aRect.TopRight());
173
0
                    rRenderContext.DrawLine(aRect.TopLeft(), aRect.BottomLeft());
174
175
0
                    rRenderContext.SetLineColor(rRenderContext.GetSettings().GetStyleSettings().GetSeparatorColor());
176
0
                    rRenderContext.DrawLine(aRect.BottomLeft(), aRect.BottomRight());
177
0
                    rRenderContext.DrawLine(aRect.TopRight(), aRect.BottomRight());
178
0
                }
179
0
            }
180
0
        }
181
0
    }
182
0
    else
183
0
    {
184
        // create map to find toolbar lines
185
0
        Size aOutSz(GetOutputSizePixel());
186
0
        std::map<int, int> ranges;
187
0
        sal_uInt16 nChildren = GetChildCount();
188
0
        for (sal_uInt16 n = 0; n < nChildren; n++)
189
0
        {
190
0
            vcl::Window* pChild = GetChild(n);
191
0
            Point aPos = pChild->GetPosPixel();
192
0
            Size aSize = pChild->GetSizePixel();
193
0
            if (IsHorizontal())
194
0
                ranges[aPos.Y()] = aSize.Height();
195
0
            else
196
0
                ranges[aPos.X()] = aSize.Width();
197
0
        }
198
199
        // draw multiple toolbar backgrounds, i.e., one for each toolbar line
200
0
        for (auto const& range : ranges)
201
0
        {
202
0
            tools::Rectangle aTBRect;
203
0
            if (IsHorizontal())
204
0
            {
205
0
                aTBRect.SetLeft( 0 );
206
0
                aTBRect.SetRight( aOutSz.Width() - 1 );
207
0
                aTBRect.SetTop( range.first );
208
0
                aTBRect.SetBottom( range.first + range.second - 1 );
209
0
            }
210
0
            else
211
0
            {
212
0
                aTBRect.SetLeft( range.first );
213
0
                aTBRect.SetRight( range.first + range.second - 1 );
214
0
                aTBRect.SetTop( 0 );
215
0
                aTBRect.SetBottom( aOutSz.Height() - 1 );
216
0
            }
217
0
            rRenderContext.DrawNativeControl(ControlType::Toolbar, IsHorizontal() ? ControlPart::DrawBackgroundHorz : ControlPart::DrawBackgroundVert,
218
0
                                             aTBRect, nState, aControlValue, OUString());
219
0
        }
220
0
    }
221
0
}
222
223
void DockingAreaWindow::Resize()
224
0
{
225
0
    ImplInvalidateMenubar( this );
226
0
    if (IsNativeControlSupported(ControlType::Toolbar, ControlPart::Entire))
227
0
        Invalidate();
228
0
}
229
230
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */