LibreOffice Module vcl (master) 1
dockingarea.cxx
Go to the documentation of this file.
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
32{
33public:
34 ImplData();
35
37};
38
40{
42}
43
44DockingAreaWindow::DockingAreaWindow( vcl::Window* pParent ) :
46{
47 ImplInit( pParent, WB_CLIPCHILDREN|WB_3DLOOK, nullptr );
48
49 mpImplData.reset(new ImplData);
50}
51
52DockingAreaWindow::~DockingAreaWindow()
53{
54 disposeOnce();
55}
56
57void DockingAreaWindow::dispose()
58{
59 mpImplData.reset();
60 Window::dispose();
61}
62
63void DockingAreaWindow::DataChanged( const DataChangedEvent& rDCEvt )
64{
65 Window::DataChanged( rDCEvt );
66
68 {
69 Invalidate();
70 }
71}
72
73static void ImplInvalidateMenubar( DockingAreaWindow const * pThis )
74{
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 if( ImplGetSVData()->maNWFData.mbMenuBarDockingAreaCommonBG &&
78 (pThis->GetAlign() == WindowAlign::Top)
79 && pThis->IsNativeControlSupported( ControlType::Toolbar, ControlPart::Entire )
80 && pThis->IsNativeControlSupported( ControlType::Menubar, ControlPart::Entire ) )
81 {
82 SystemWindow *pSysWin = pThis->GetSystemWindow();
83 if( pSysWin && pSysWin->GetMenuBar() )
84 {
85 vcl::Window *pMenubarWin = pSysWin->GetMenuBar()->GetWindow();
86 if( pMenubarWin )
87 pMenubarWin->Invalidate();
88 }
89 }
90}
91
92void DockingAreaWindow::StateChanged( StateChangedType nType )
93{
94 Window::StateChanged( nType );
95
96 if ( nType == StateChangedType::Visible )
98}
99
100bool DockingAreaWindow::IsHorizontal() const
101{
102 return ( mpImplData->meAlign == WindowAlign::Top || mpImplData->meAlign == WindowAlign::Bottom );
103}
104
105void DockingAreaWindow::SetAlign( WindowAlign eNewAlign )
106{
107 if( eNewAlign != mpImplData->meAlign )
108 {
109 mpImplData->meAlign = eNewAlign;
110 Invalidate();
111 }
112}
113
114WindowAlign DockingAreaWindow::GetAlign() const
115{
116 return mpImplData->meAlign;
117}
118
119void DockingAreaWindow::ApplySettings(vcl::RenderContext& rRenderContext)
120{
121 const StyleSettings rSetting = rRenderContext.GetSettings().GetStyleSettings();
122 const BitmapEx& rPersonaBitmap = (GetAlign() == WindowAlign::Top) ? rSetting.GetPersonaHeader() : rSetting.GetPersonaFooter();
123
124 if (!rPersonaBitmap.IsEmpty() && (GetAlign() == WindowAlign::Top || GetAlign()==WindowAlign::Bottom))
125 {
126 Wallpaper aWallpaper(rPersonaBitmap);
127 if (GetAlign() == WindowAlign::Top)
128 aWallpaper.SetStyle(WallpaperStyle::TopRight);
129 else
130 aWallpaper.SetStyle(WallpaperStyle::BottomRight);
131 aWallpaper.SetColor(rSetting.GetWorkspaceColor());
132
133 // we need to shift the bitmap vertically so that it spans over the
134 // menubar conveniently
135 SystemWindow* pSysWin = GetSystemWindow();
136 MenuBar* pMenuBar = pSysWin ? pSysWin->GetMenuBar() : nullptr;
137 int nMenubarHeight = pMenuBar ? pMenuBar->GetMenuBarHeight() : 0;
138 aWallpaper.SetRect(tools::Rectangle(Point(0, -nMenubarHeight),
139 Size(rRenderContext.GetOutputWidthPixel(),
140 rRenderContext.GetOutputHeightPixel() + nMenubarHeight)));
141
142 rRenderContext.SetBackground(aWallpaper);
143 }
145 {
146 Wallpaper aWallpaper;
148 rRenderContext.SetBackground(aWallpaper);
149 }
150 else
151 rRenderContext.SetBackground(Wallpaper(rSetting.GetFaceColor()));
152
153}
154
155void DockingAreaWindow::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&)
156{
157 const StyleSettings rSetting = rRenderContext.GetSettings().GetStyleSettings();
158
159 EnableNativeWidget(); // only required because the toolkit currently switches this flag off
161 return;
162
163 ToolbarValue aControlValue;
164
165 if (GetAlign() == WindowAlign::Top && ImplGetSVData()->maNWFData.mbMenuBarDockingAreaCommonBG)
166 {
167 // give NWF a hint that this dockingarea is adjacent to the menubar
168 // useful for special gradient effects that should cover both windows
169 aControlValue.mbIsTopDockingArea = true;
170 }
171
173 const bool isFooter = GetAlign() == WindowAlign::Bottom && !rSetting.GetPersonaFooter().IsEmpty();
174
175 if ((GetAlign() == WindowAlign::Top && !rSetting.GetPersonaHeader().IsEmpty() ) || isFooter)
176 Erase(rRenderContext);
177 else if (!ImplGetSVData()->maNWFData.mbDockingAreaSeparateTB)
178 {
179 // draw a single toolbar background covering the whole docking area
180 tools::Rectangle aCtrlRegion(Point(), GetOutputSizePixel());
181
183 aCtrlRegion, nState, aControlValue, OUString() );
184
185 if (!ImplGetSVData()->maNWFData.mbDockingAreaAvoidTBFrames)
186 {
187 // each toolbar gets a thin border to better recognize its borders on the homogeneous docking area
188 sal_uInt16 nChildren = GetChildCount();
189 for (sal_uInt16 n = 0; n < nChildren; n++)
190 {
191 vcl::Window* pChild = GetChild(n);
192 if (pChild->IsVisible())
193 {
194 Point aPos = pChild->GetPosPixel();
195 Size aSize = pChild->GetSizePixel();
196 tools::Rectangle aRect(aPos, aSize);
197
198 rRenderContext.SetLineColor(rRenderContext.GetSettings().GetStyleSettings().GetLightColor());
199 rRenderContext.DrawLine(aRect.TopLeft(), aRect.TopRight());
200 rRenderContext.DrawLine(aRect.TopLeft(), aRect.BottomLeft());
201
202 rRenderContext.SetLineColor(rRenderContext.GetSettings().GetStyleSettings().GetSeparatorColor());
203 rRenderContext.DrawLine(aRect.BottomLeft(), aRect.BottomRight());
204 rRenderContext.DrawLine(aRect.TopRight(), aRect.BottomRight());
205 }
206 }
207 }
208 }
209 else
210 {
211 // create map to find toolbar lines
212 Size aOutSz(GetOutputSizePixel());
213 std::map<int, int> ranges;
214 sal_uInt16 nChildren = GetChildCount();
215 for (sal_uInt16 n = 0; n < nChildren; n++)
216 {
217 vcl::Window* pChild = GetChild(n);
218 Point aPos = pChild->GetPosPixel();
219 Size aSize = pChild->GetSizePixel();
220 if (IsHorizontal())
221 ranges[aPos.Y()] = aSize.Height();
222 else
223 ranges[aPos.X()] = aSize.Width();
224 }
225
226 // draw multiple toolbar backgrounds, i.e., one for each toolbar line
227 for (auto const& range : ranges)
228 {
229 tools::Rectangle aTBRect;
230 if (IsHorizontal())
231 {
232 aTBRect.SetLeft( 0 );
233 aTBRect.SetRight( aOutSz.Width() - 1 );
234 aTBRect.SetTop( range.first );
235 aTBRect.SetBottom( range.first + range.second - 1 );
236 }
237 else
238 {
239 aTBRect.SetLeft( range.first );
240 aTBRect.SetRight( range.first + range.second - 1 );
241 aTBRect.SetTop( 0 );
242 aTBRect.SetBottom( aOutSz.Height() - 1 );
243 }
245 aTBRect, nState, aControlValue, OUString());
246 }
247 }
248}
249
250void DockingAreaWindow::Resize()
251{
252 ImplInvalidateMenubar( this );
253 if (IsNativeControlSupported(ControlType::Toolbar, ControlPart::Entire))
254 Invalidate();
255}
256
257/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const StyleSettings & GetStyleSettings() const
bool IsEmpty() const
Definition: BitmapEx.cxx:186
DataChangedEventType GetType() const
Definition: event.hxx:362
AllSettingsFlags GetFlags() const
Definition: event.hxx:363
int GetMenuBarHeight() const
Definition: menu.cxx:2669
vcl::Window * GetWindow() const
Definition: menu.hxx:377
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:170
tools::Long GetOutputWidthPixel() const
Definition: outdev.hxx:316
void DrawLine(const Point &rStartPt, const Point &rEndPt)
Definition: line.cxx:161
tools::Long GetOutputHeightPixel() const
Definition: outdev.hxx:317
void SetLineColor()
Definition: line.cxx:37
void SetBackground()
Definition: background.cxx:27
bool DrawNativeControl(ControlType nType, ControlPart nPart, const tools::Rectangle &rControlRegion, ControlState nState, const ImplControlValue &aValue, const OUString &aCaption, const Color &rBackgroundColor=COL_AUTO)
Request rendering of a particular control and/or part.
const AllSettings & GetSettings() const
Definition: outdev.hxx:288
bool IsNativeControlSupported(ControlType nType, ControlPart nPart) const
Query the platform layer for control support.
constexpr tools::Long Y() const
constexpr tools::Long X() const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
BitmapEx const & GetPersonaHeader() const
BitmapEx const & GetPersonaFooter() const
const Color & GetWorkspaceColor() const
Color GetSeparatorColor() const
const Color & GetLightColor() const
const Color & GetFaceColor() const
MenuBar * GetMenuBar() const
Definition: syswin.hxx:183
bool mbIsTopDockingArea
void SetStyle(WallpaperStyle eStyle)
Definition: wall.cxx:165
constexpr void SetLeft(tools::Long v)
constexpr void SetTop(tools::Long v)
constexpr void SetRight(tools::Long v)
constexpr void SetBottom(tools::Long v)
virtual Point GetPosPixel() const
Definition: window.cxx:2794
SystemWindow * GetSystemWindow() const
Definition: stacking.cxx:807
virtual Size GetSizePixel() const
Definition: window.cxx:2402
bool IsVisible() const
Definition: window2.cxx:1128
void Invalidate(InvalidateFlags nFlags=InvalidateFlags::NONE)
Definition: paint.cxx:1143
static void ImplInvalidateMenubar(DockingAreaWindow const *pThis)
Definition: dockingarea.cxx:73
sal_Int32 nState
sal_Int64 n
ImplSVData * ImplGetSVData()
Definition: svdata.cxx:77
StateChangedType
Definition: window.hxx:291
WindowType
Definition: wintypes.hxx:27
WinBits const WB_3DLOOK
Definition: wintypes.hxx:118
WindowAlign
Definition: wintypes.hxx:232
WinBits const WB_CLIPCHILDREN
Definition: wintypes.hxx:112