bump product version to 4.1.6.2
[LibreOffice.git] / vcl / source / window / dockingarea.cxx
blob70a1b5d7b5c8323a6e7df1f8f360fdf0e4a6761a
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 .
21 #include <vcl/dockingarea.hxx>
22 #include <vcl/syswin.hxx>
23 #include <vcl/menu.hxx>
25 #include <svdata.hxx>
27 #include <map>
29 // =======================================================================
31 class DockingAreaWindow::ImplData
33 public:
34 ImplData();
35 ~ImplData();
37 WindowAlign meAlign;
40 DockingAreaWindow::ImplData::ImplData()
42 meAlign = WINDOWALIGN_TOP;
45 DockingAreaWindow::ImplData::~ImplData()
49 // =======================================================================
51 static void ImplInitBackground( DockingAreaWindow* pThis )
53 const BitmapEx& rPersonaBitmap = Application::GetSettings().GetStyleSettings().GetPersonaHeader();
54 if ( !rPersonaBitmap.IsEmpty() && pThis->GetAlign() == WINDOWALIGN_TOP )
56 Wallpaper aWallpaper( rPersonaBitmap );
57 aWallpaper.SetStyle( WALLPAPER_TOPRIGHT );
58 aWallpaper.SetColor( Application::GetSettings().GetStyleSettings().GetWorkspaceColor() );
60 // we need to shift the bitmap vertically so that it spans over the
61 // menubar conveniently
62 long nMenubarHeight = 0;
63 SystemWindow *pSysWin = pThis->GetSystemWindow();
64 if ( pSysWin && pSysWin->GetMenuBar() )
66 Window *pMenubarWin = pSysWin->GetMenuBar()->GetWindow();
67 if ( pMenubarWin )
68 nMenubarHeight = pMenubarWin->GetOutputHeightPixel();
70 aWallpaper.SetRect( Rectangle( Point( 0, -nMenubarHeight ), Size( pThis->GetOutputWidthPixel(), pThis->GetOutputHeightPixel() + nMenubarHeight ) ) );
72 pThis->SetBackground( aWallpaper );
74 else if( !pThis->IsNativeControlSupported( CTRL_TOOLBAR, PART_ENTIRE_CONTROL ) )
76 Wallpaper aWallpaper;
77 aWallpaper.SetStyle( WALLPAPER_APPLICATIONGRADIENT );
78 pThis->SetBackground( aWallpaper );
80 else
81 pThis->SetBackground( Wallpaper( pThis->GetSettings().GetStyleSettings().GetFaceColor() ) );
84 DockingAreaWindow::DockingAreaWindow( Window* pParent ) :
85 Window( WINDOW_DOCKINGAREA )
87 ImplInit( pParent, WB_CLIPCHILDREN|WB_3DLOOK, NULL );
89 mpImplData = new ImplData;
90 ImplInitBackground( this );
93 DockingAreaWindow::~DockingAreaWindow()
95 delete mpImplData;
98 // -----------------------------------------------------------------------
100 void DockingAreaWindow::DataChanged( const DataChangedEvent& rDCEvt )
102 Window::DataChanged( rDCEvt );
104 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
106 ImplInitBackground( this );
107 Invalidate();
111 // -----------------------------------------------------------------------
113 static void ImplInvalidateMenubar( DockingAreaWindow* pThis )
115 // due to a possible comon gradient covering menubar and top dockingarea
116 // the menubar must be repainted if the top dockingarea changes size or visibility
117 if( ImplGetSVData()->maNWFData.mbMenuBarDockingAreaCommonBG &&
118 (pThis->GetAlign() == WINDOWALIGN_TOP)
119 && pThis->IsNativeControlSupported( CTRL_TOOLBAR, PART_ENTIRE_CONTROL )
120 && pThis->IsNativeControlSupported( CTRL_MENUBAR, PART_ENTIRE_CONTROL ) )
122 SystemWindow *pSysWin = pThis->GetSystemWindow();
123 if( pSysWin && pSysWin->GetMenuBar() )
125 Window *pMenubarWin = pSysWin->GetMenuBar()->GetWindow();
126 if( pMenubarWin )
127 pMenubarWin->Invalidate();
132 void DockingAreaWindow::StateChanged( StateChangedType nType )
134 Window::StateChanged( nType );
136 if ( nType == STATE_CHANGE_VISIBLE )
137 ImplInvalidateMenubar( this );
140 // -----------------------------------------------------------------------
142 sal_Bool DockingAreaWindow::IsHorizontal() const
144 return ( mpImplData->meAlign == WINDOWALIGN_TOP || mpImplData->meAlign == WINDOWALIGN_BOTTOM );
147 void DockingAreaWindow::SetAlign( WindowAlign eNewAlign )
149 if( eNewAlign != mpImplData->meAlign )
151 mpImplData->meAlign = eNewAlign;
152 ImplInitBackground( this );
153 Invalidate();
157 WindowAlign DockingAreaWindow::GetAlign() const
159 return mpImplData->meAlign;
162 // -----------------------------------------------------------------------
164 void DockingAreaWindow::Paint( const Rectangle& )
166 EnableNativeWidget( sal_True ); // only required because the toolkit curently switches this flag off
167 if( IsNativeControlSupported( CTRL_TOOLBAR, PART_ENTIRE_CONTROL ) )
169 ToolbarValue aControlValue;
171 if( GetAlign() == WINDOWALIGN_TOP && ImplGetSVData()->maNWFData.mbMenuBarDockingAreaCommonBG )
173 // give NWF a hint that this dockingarea is adjacent to the menubar
174 // useful for special gradient effects that should cover both windows
175 aControlValue.mbIsTopDockingArea = sal_True;
177 ControlState nState = CTRL_STATE_ENABLED;
179 if ( GetAlign() == WINDOWALIGN_TOP && !Application::GetSettings().GetStyleSettings().GetPersonaHeader().IsEmpty() )
180 Erase();
181 else if ( !ImplGetSVData()->maNWFData.mbDockingAreaSeparateTB )
183 // draw a single toolbar background covering the whole docking area
184 Point tmp;
185 Rectangle aCtrlRegion( tmp, GetOutputSizePixel() );
187 DrawNativeControl( CTRL_TOOLBAR, IsHorizontal() ? PART_DRAW_BACKGROUND_HORZ : PART_DRAW_BACKGROUND_VERT,
188 aCtrlRegion, nState, aControlValue, OUString() );
190 if( !ImplGetSVData()->maNWFData.mbDockingAreaAvoidTBFrames )
192 // each toolbar gets a thin border to better recognize its borders on the homogeneous docking area
193 sal_uInt16 nChildren = GetChildCount();
194 for( sal_uInt16 n = 0; n < nChildren; n++ )
196 Window* pChild = GetChild( n );
197 if ( pChild->IsVisible() )
199 Point aPos = pChild->GetPosPixel();
200 Size aSize = pChild->GetSizePixel();
201 Rectangle aRect( aPos, aSize );
203 SetLineColor( GetSettings().GetStyleSettings().GetLightColor() );
204 DrawLine( aRect.TopLeft(), aRect.TopRight() );
205 DrawLine( aRect.TopLeft(), aRect.BottomLeft() );
207 SetLineColor( GetSettings().GetStyleSettings().GetSeparatorColor() );
208 DrawLine( aRect.BottomLeft(), aRect.BottomRight() );
209 DrawLine( aRect.TopRight(), aRect.BottomRight() );
214 else
216 // create map to find toolbar lines
217 Size aOutSz = GetOutputSizePixel();
218 std::map< int, int > ranges;
219 sal_uInt16 nChildren = GetChildCount();
220 for( sal_uInt16 n = 0; n < nChildren; n++ )
222 Window* pChild = GetChild( n );
223 Point aPos = pChild->GetPosPixel();
224 Size aSize = pChild->GetSizePixel();
225 if( IsHorizontal() )
226 ranges[ aPos.Y() ] = aSize.Height();
227 else
228 ranges[ aPos.X() ] = aSize.Width();
232 // draw multiple toolbar backgrounds, i.e., one for each toolbar line
233 for( std::map<int,int>::const_iterator it = ranges.begin(); it != ranges.end(); ++it )
235 Rectangle aTBRect;
236 if( IsHorizontal() )
238 aTBRect.Left() = 0;
239 aTBRect.Right() = aOutSz.Width() - 1;
240 aTBRect.Top() = it->first;
241 aTBRect.Bottom() = it->first + it->second - 1;
243 else
245 aTBRect.Left() = it->first;
246 aTBRect.Right() = it->first + it->second - 1;
247 aTBRect.Top() = 0;
248 aTBRect.Bottom() = aOutSz.Height() - 1;
250 DrawNativeControl( CTRL_TOOLBAR, IsHorizontal() ? PART_DRAW_BACKGROUND_HORZ : PART_DRAW_BACKGROUND_VERT,
251 aTBRect, nState, aControlValue, OUString() );
257 void DockingAreaWindow::Resize()
259 ImplInitBackground( this );
260 ImplInvalidateMenubar( this );
261 if( IsNativeControlSupported( CTRL_TOOLBAR, PART_ENTIRE_CONTROL ) )
262 Invalidate();
265 // -----------------------------------------------------------------------
267 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */