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 
26 #include <svdata.hxx>
27 
28 #include <map>
29 
31 {
32 public:
33  ImplData();
34 
36 };
37 
39 {
40  meAlign = WindowAlign::Top;
41 }
42 
45 {
46  ImplInit( pParent, WB_CLIPCHILDREN|WB_3DLOOK, nullptr );
47 
48  mpImplData.reset(new ImplData);
49 }
50 
52 {
53  disposeOnce();
54 }
55 
57 {
58  mpImplData.reset();
59  Window::dispose();
60 }
61 
63 {
64  Window::DataChanged( rDCEvt );
65 
66  if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) && (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
67  {
68  Invalidate();
69  }
70 }
71 
72 static void ImplInvalidateMenubar( DockingAreaWindow const * pThis )
73 {
74  // due to a possible common gradient covering menubar and top dockingarea
75  // the menubar must be repainted if the top dockingarea changes size or visibility
76  if( ImplGetSVData()->maNWFData.mbMenuBarDockingAreaCommonBG &&
77  (pThis->GetAlign() == WindowAlign::Top)
80  {
81  SystemWindow *pSysWin = pThis->GetSystemWindow();
82  if( pSysWin && pSysWin->GetMenuBar() )
83  {
84  vcl::Window *pMenubarWin = pSysWin->GetMenuBar()->GetWindow();
85  if( pMenubarWin )
86  pMenubarWin->Invalidate();
87  }
88  }
89 }
90 
92 {
93  Window::StateChanged( nType );
94 
95  if ( nType == StateChangedType::Visible )
96  ImplInvalidateMenubar( this );
97 }
98 
100 {
101  return ( mpImplData->meAlign == WindowAlign::Top || mpImplData->meAlign == WindowAlign::Bottom );
102 }
103 
105 {
106  if( eNewAlign != mpImplData->meAlign )
107  {
108  mpImplData->meAlign = eNewAlign;
109  Invalidate();
110  }
111 }
112 
114 {
115  return mpImplData->meAlign;
116 }
117 
119 {
120  const StyleSettings rSetting = rRenderContext.GetSettings().GetStyleSettings();
121  const BitmapEx& rPersonaBitmap = (GetAlign() == WindowAlign::Top) ? rSetting.GetPersonaHeader() : rSetting.GetPersonaFooter();
122 
123  if (!rPersonaBitmap.IsEmpty() && (GetAlign() == WindowAlign::Top || GetAlign()==WindowAlign::Bottom))
124  {
125  Wallpaper aWallpaper(rPersonaBitmap);
126  if (GetAlign() == WindowAlign::Top)
128  else
130  aWallpaper.SetColor(rSetting.GetWorkspaceColor());
131 
132  // we need to shift the bitmap vertically so that it spans over the
133  // menubar conveniently
134  SystemWindow* pSysWin = GetSystemWindow();
135  MenuBar* pMenuBar = pSysWin ? pSysWin->GetMenuBar() : nullptr;
136  int nMenubarHeight = pMenuBar ? pMenuBar->GetMenuBarHeight() : 0;
137  aWallpaper.SetRect(tools::Rectangle(Point(0, -nMenubarHeight),
138  Size(rRenderContext.GetOutputWidthPixel(),
139  rRenderContext.GetOutputHeightPixel() + nMenubarHeight)));
140 
141  rRenderContext.SetBackground(aWallpaper);
142  }
144  {
145  Wallpaper aWallpaper;
147  rRenderContext.SetBackground(aWallpaper);
148  }
149  else
150  rRenderContext.SetBackground(Wallpaper(rSetting.GetFaceColor()));
151 
152 }
153 
155 {
156  const StyleSettings rSetting = rRenderContext.GetSettings().GetStyleSettings();
157 
158  EnableNativeWidget(); // only required because the toolkit currently switches this flag off
160  {
161  ToolbarValue aControlValue;
162 
163  if (GetAlign() == WindowAlign::Top && ImplGetSVData()->maNWFData.mbMenuBarDockingAreaCommonBG)
164  {
165  // give NWF a hint that this dockingarea is adjacent to the menubar
166  // useful for special gradient effects that should cover both windows
167  aControlValue.mbIsTopDockingArea = true;
168  }
169 
171  const bool isFooter = GetAlign() == WindowAlign::Bottom && !rSetting.GetPersonaFooter().IsEmpty();
172 
173  if ((GetAlign() == WindowAlign::Top && !rSetting.GetPersonaHeader().IsEmpty() ) || isFooter)
174  Erase(rRenderContext);
175  else if (!ImplGetSVData()->maNWFData.mbDockingAreaSeparateTB)
176  {
177  // draw a single toolbar background covering the whole docking area
178  tools::Rectangle aCtrlRegion(Point(), GetOutputSizePixel());
179 
181  aCtrlRegion, nState, aControlValue, OUString() );
182 
183  if (!ImplGetSVData()->maNWFData.mbDockingAreaAvoidTBFrames)
184  {
185  // each toolbar gets a thin border to better recognize its borders on the homogeneous docking area
186  sal_uInt16 nChildren = GetChildCount();
187  for (sal_uInt16 n = 0; n < nChildren; n++)
188  {
189  vcl::Window* pChild = GetChild(n);
190  if (pChild->IsVisible())
191  {
192  Point aPos = pChild->GetPosPixel();
193  Size aSize = pChild->GetSizePixel();
194  tools::Rectangle aRect(aPos, aSize);
195 
196  rRenderContext.SetLineColor(rRenderContext.GetSettings().GetStyleSettings().GetLightColor());
197  rRenderContext.DrawLine(aRect.TopLeft(), aRect.TopRight());
198  rRenderContext.DrawLine(aRect.TopLeft(), aRect.BottomLeft());
199 
200  rRenderContext.SetLineColor(rRenderContext.GetSettings().GetStyleSettings().GetSeparatorColor());
201  rRenderContext.DrawLine(aRect.BottomLeft(), aRect.BottomRight());
202  rRenderContext.DrawLine(aRect.TopRight(), aRect.BottomRight());
203  }
204  }
205  }
206  }
207  else
208  {
209  // create map to find toolbar lines
210  Size aOutSz(GetOutputSizePixel());
211  std::map<int, int> ranges;
212  sal_uInt16 nChildren = GetChildCount();
213  for (sal_uInt16 n = 0; n < nChildren; n++)
214  {
215  vcl::Window* pChild = GetChild(n);
216  Point aPos = pChild->GetPosPixel();
217  Size aSize = pChild->GetSizePixel();
218  if (IsHorizontal())
219  ranges[aPos.Y()] = aSize.Height();
220  else
221  ranges[aPos.X()] = aSize.Width();
222  }
223 
224  // draw multiple toolbar backgrounds, i.e., one for each toolbar line
225  for (auto const& range : ranges)
226  {
227  tools::Rectangle aTBRect;
228  if (IsHorizontal())
229  {
230  aTBRect.SetLeft( 0 );
231  aTBRect.SetRight( aOutSz.Width() - 1 );
232  aTBRect.SetTop( range.first );
233  aTBRect.SetBottom( range.first + range.second - 1 );
234  }
235  else
236  {
237  aTBRect.SetLeft( range.first );
238  aTBRect.SetRight( range.first + range.second - 1 );
239  aTBRect.SetTop( 0 );
240  aTBRect.SetBottom( aOutSz.Height() - 1 );
241  }
243  aTBRect, nState, aControlValue, OUString());
244  }
245  }
246  }
247 }
248 
250 {
251  ImplInvalidateMenubar( this );
253  Invalidate();
254 }
255 
256 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual Point GetPosPixel() const
Definition: window.cxx:2806
Point TopLeft() const
long Width() const
WindowAlign
static void ImplInvalidateMenubar(DockingAreaWindow const *pThis)
Definition: dockingarea.cxx:72
SystemWindow * GetSystemWindow() const
Definition: stacking.cxx:806
DockingAreaWindow(const DockingAreaWindow &)=delete
bool DrawNativeControl(ControlType nType, ControlPart nPart, const tools::Rectangle &rControlRegion, ControlState nState, const ImplControlValue &aValue, const OUString &aCaption)
Request rendering of a particular control and/or part.
long Height() const
Point BottomLeft() const
virtual void Resize() override
const StyleSettings & GetStyleSettings() const
const Color & GetFaceColor() const
BitmapEx const & GetPersonaHeader() const
ImplSVNWFData maNWFData
Definition: svdata.hxx:357
bool mbMenuBarDockingAreaCommonBG
Definition: svdata.hxx:272
virtual Size GetSizePixel() const
Definition: window.cxx:2364
void SetColor(const Color &rColor)
Definition: wall.cxx:190
const Color & GetWorkspaceColor() const
Color GetSeparatorColor() const
DataChangedEventType GetType() const
Definition: event.hxx:348
virtual void ApplySettings(vcl::RenderContext &rRenderContext) override
bool IsNativeControlSupported(ControlType nType, ControlPart nPart) const
Query the platform layer for control support.
StateChangedType
Definition: window.hxx:309
void SetBackground()
AllSettingsFlags GetFlags() const
Definition: event.hxx:349
const Color & GetLightColor() const
void DrawLine(const Point &rStartPt, const Point &rEndPt)
Definition: line.cxx:88
BitmapEx const & GetPersonaFooter() const
Point BottomRight() const
void EnableNativeWidget(bool bEnable=true)
Definition: window.cxx:3539
bool IsEmpty() const
Definition: bitmapex.cxx:203
ImplSVData * ImplGetSVData()
Definition: svdata.cxx:66
void SetLineColor()
int GetMenuBarHeight() const
Definition: menu.cxx:2669
void SetTop(long v)
Window(WindowType nType)
Definition: window.cxx:84
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect) override
void SetRect(const tools::Rectangle &rRect)
Definition: wall.cxx:297
void SetStyle(WallpaperStyle eStyle)
Definition: wall.cxx:204
virtual void Invalidate(InvalidateFlags nFlags=InvalidateFlags::NONE)
Definition: paint.cxx:1153
void SetRight(long v)
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:304
const AllSettings & GetSettings() const
Definition: outdev.hxx:420
Size GetOutputSizePixel() const
Definition: outdev.hxx:441
long X() const
virtual void DataChanged(const DataChangedEvent &rDCEvt) override
Definition: dockingarea.cxx:62
long GetOutputWidthPixel() const
Definition: outdev.hxx:443
SAL_DLLPRIVATE void ImplInit(vcl::Window *pParent, WinBits nStyle, SystemParentData *pSystemParentData)
Definition: window.cxx:930
WinBits const WB_3DLOOK
sal_uInt16 GetChildCount() const
Definition: stacking.cxx:1001
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
Definition: dockingarea.cxx:56
void Erase()
Definition: wallpaper.cxx:93
virtual ~DockingAreaWindow() override
Definition: dockingarea.cxx:51
bool IsHorizontal() const
Definition: dockingarea.cxx:99
long GetOutputHeightPixel() const
Definition: outdev.hxx:444
WindowType
virtual void StateChanged(StateChangedType nType) override
Definition: dockingarea.cxx:91
MenuBar * GetMenuBar() const
Definition: syswin.hxx:216
vcl::Window * GetWindow() const
Definition: menu.hxx:377
bool IsVisible() const
Definition: window2.cxx:1096
void SetBottom(long v)
WindowAlign GetAlign() const
void SetLeft(long v)
void SetAlign(WindowAlign eNewAlign)
std::unique_ptr< ImplData > mpImplData
Definition: dockingarea.hxx:30
WinBits const WB_CLIPCHILDREN
Point TopRight() const
long Y() const
vcl::Window * GetChild(sal_uInt16 nChild) const
Definition: stacking.cxx:1017