bump product version to 7.6.3.2-android
[LibreOffice.git] / vcl / source / window / dockingarea.cxx
blobbe3f6ef99e45e051aa2b02983cc280189aa51ae5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
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>
27 #include <svdata.hxx>
29 #include <map>
31 class DockingAreaWindow::ImplData
33 public:
34 ImplData();
36 WindowAlign meAlign;
39 DockingAreaWindow::ImplData::ImplData()
41 meAlign = WindowAlign::Top;
44 DockingAreaWindow::DockingAreaWindow( vcl::Window* pParent ) :
45 Window( WindowType::DOCKINGAREA )
47 ImplInit( pParent, WB_CLIPCHILDREN|WB_3DLOOK, nullptr );
49 mpImplData.reset(new ImplData);
52 DockingAreaWindow::~DockingAreaWindow()
54 disposeOnce();
57 void DockingAreaWindow::dispose()
59 mpImplData.reset();
60 Window::dispose();
63 void DockingAreaWindow::DataChanged( const DataChangedEvent& rDCEvt )
65 Window::DataChanged( rDCEvt );
67 if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) && (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
69 Invalidate();
73 static void ImplInvalidateMenubar( DockingAreaWindow const * pThis )
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 ) )
82 SystemWindow *pSysWin = pThis->GetSystemWindow();
83 if( pSysWin && pSysWin->GetMenuBar() )
85 vcl::Window *pMenubarWin = pSysWin->GetMenuBar()->GetWindow();
86 if( pMenubarWin )
87 pMenubarWin->Invalidate();
92 void DockingAreaWindow::StateChanged( StateChangedType nType )
94 Window::StateChanged( nType );
96 if ( nType == StateChangedType::Visible )
97 ImplInvalidateMenubar( this );
100 bool DockingAreaWindow::IsHorizontal() const
102 return ( mpImplData->meAlign == WindowAlign::Top || mpImplData->meAlign == WindowAlign::Bottom );
105 void DockingAreaWindow::SetAlign( WindowAlign eNewAlign )
107 if( eNewAlign != mpImplData->meAlign )
109 mpImplData->meAlign = eNewAlign;
110 Invalidate();
114 WindowAlign DockingAreaWindow::GetAlign() const
116 return mpImplData->meAlign;
119 void DockingAreaWindow::ApplySettings(vcl::RenderContext& rRenderContext)
121 const StyleSettings rSetting = rRenderContext.GetSettings().GetStyleSettings();
122 const BitmapEx& rPersonaBitmap = (GetAlign() == WindowAlign::Top) ? rSetting.GetPersonaHeader() : rSetting.GetPersonaFooter();
124 if (!rPersonaBitmap.IsEmpty() && (GetAlign() == WindowAlign::Top || GetAlign()==WindowAlign::Bottom))
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());
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)));
142 rRenderContext.SetBackground(aWallpaper);
144 else if (!rRenderContext.IsNativeControlSupported(ControlType::Toolbar, ControlPart::Entire))
146 Wallpaper aWallpaper;
147 aWallpaper.SetStyle(WallpaperStyle::ApplicationGradient);
148 rRenderContext.SetBackground(aWallpaper);
150 else
151 rRenderContext.SetBackground(Wallpaper(rSetting.GetFaceColor()));
155 void DockingAreaWindow::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&)
157 const StyleSettings rSetting = rRenderContext.GetSettings().GetStyleSettings();
159 EnableNativeWidget(); // only required because the toolkit currently switches this flag off
160 if (!rRenderContext.IsNativeControlSupported(ControlType::Toolbar, ControlPart::Entire))
161 return;
163 ToolbarValue aControlValue;
165 if (GetAlign() == WindowAlign::Top && ImplGetSVData()->maNWFData.mbMenuBarDockingAreaCommonBG)
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;
172 ControlState nState = ControlState::ENABLED;
173 const bool isFooter = GetAlign() == WindowAlign::Bottom && !rSetting.GetPersonaFooter().IsEmpty();
175 if ((GetAlign() == WindowAlign::Top && !rSetting.GetPersonaHeader().IsEmpty() ) || isFooter)
176 Erase(rRenderContext);
177 else if (!ImplGetSVData()->maNWFData.mbDockingAreaSeparateTB)
179 // draw a single toolbar background covering the whole docking area
180 tools::Rectangle aCtrlRegion(Point(), GetOutputSizePixel());
182 rRenderContext.DrawNativeControl(ControlType::Toolbar, IsHorizontal() ? ControlPart::DrawBackgroundHorz : ControlPart::DrawBackgroundVert,
183 aCtrlRegion, nState, aControlValue, OUString() );
185 if (!ImplGetSVData()->maNWFData.mbDockingAreaAvoidTBFrames)
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++)
191 vcl::Window* pChild = GetChild(n);
192 if (pChild->IsVisible())
194 Point aPos = pChild->GetPosPixel();
195 Size aSize = pChild->GetSizePixel();
196 tools::Rectangle aRect(aPos, aSize);
198 rRenderContext.SetLineColor(rRenderContext.GetSettings().GetStyleSettings().GetLightColor());
199 rRenderContext.DrawLine(aRect.TopLeft(), aRect.TopRight());
200 rRenderContext.DrawLine(aRect.TopLeft(), aRect.BottomLeft());
202 rRenderContext.SetLineColor(rRenderContext.GetSettings().GetStyleSettings().GetSeparatorColor());
203 rRenderContext.DrawLine(aRect.BottomLeft(), aRect.BottomRight());
204 rRenderContext.DrawLine(aRect.TopRight(), aRect.BottomRight());
209 else
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++)
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();
226 // draw multiple toolbar backgrounds, i.e., one for each toolbar line
227 for (auto const& range : ranges)
229 tools::Rectangle aTBRect;
230 if (IsHorizontal())
232 aTBRect.SetLeft( 0 );
233 aTBRect.SetRight( aOutSz.Width() - 1 );
234 aTBRect.SetTop( range.first );
235 aTBRect.SetBottom( range.first + range.second - 1 );
237 else
239 aTBRect.SetLeft( range.first );
240 aTBRect.SetRight( range.first + range.second - 1 );
241 aTBRect.SetTop( 0 );
242 aTBRect.SetBottom( aOutSz.Height() - 1 );
244 rRenderContext.DrawNativeControl(ControlType::Toolbar, IsHorizontal() ? ControlPart::DrawBackgroundHorz : ControlPart::DrawBackgroundVert,
245 aTBRect, nState, aControlValue, OUString());
250 void DockingAreaWindow::Resize()
252 ImplInvalidateMenubar( this );
253 if (IsNativeControlSupported(ControlType::Toolbar, ControlPart::Entire))
254 Invalidate();
257 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */