Line data Source code
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 :
25 : #include <svdata.hxx>
26 :
27 : #include <map>
28 :
29 : class DockingAreaWindow::ImplData
30 : {
31 : public:
32 : ImplData();
33 : ~ImplData();
34 :
35 : WindowAlign meAlign;
36 : };
37 :
38 44648 : DockingAreaWindow::ImplData::ImplData()
39 : {
40 44648 : meAlign = WINDOWALIGN_TOP;
41 44648 : }
42 :
43 44600 : DockingAreaWindow::ImplData::~ImplData()
44 : {
45 44600 : }
46 :
47 145736 : static void ImplInitBackground( DockingAreaWindow* pThis )
48 : {
49 145736 : const StyleSettings rSetting = Application::GetSettings().GetStyleSettings();
50 291472 : const BitmapEx& rPersonaBitmap = pThis->GetAlign() == WINDOWALIGN_TOP ? rSetting.GetPersonaHeader() :rSetting.GetPersonaFooter();
51 145736 : if ( !rPersonaBitmap.IsEmpty() &&( pThis->GetAlign() == WINDOWALIGN_TOP|| pThis->GetAlign()==WINDOWALIGN_BOTTOM ) )
52 : {
53 0 : Wallpaper aWallpaper( rPersonaBitmap );
54 0 : if(pThis->GetAlign()==WINDOWALIGN_TOP )
55 0 : aWallpaper.SetStyle( WALLPAPER_TOPRIGHT );
56 : else
57 0 : aWallpaper.SetStyle( WALLPAPER_BOTTOMRIGHT );
58 0 : aWallpaper.SetColor( rSetting.GetWorkspaceColor() );
59 :
60 : // we need to shift the bitmap vertically so that it spans over the
61 : // menubar conveniently
62 0 : long nMenubarHeight = 0;
63 0 : SystemWindow *pSysWin = pThis->GetSystemWindow();
64 0 : if ( pSysWin && pSysWin->GetMenuBar() )
65 : {
66 0 : vcl::Window *pMenubarWin = pSysWin->GetMenuBar()->GetWindow();
67 0 : if ( pMenubarWin )
68 0 : nMenubarHeight = pMenubarWin->GetOutputHeightPixel();
69 : }
70 0 : aWallpaper.SetRect( Rectangle( Point( 0, -nMenubarHeight ), Size( pThis->GetOutputWidthPixel(), pThis->GetOutputHeightPixel() + nMenubarHeight ) ) );
71 :
72 0 : pThis->SetBackground( aWallpaper );
73 : }
74 145736 : else if( !pThis->IsNativeControlSupported( CTRL_TOOLBAR, PART_ENTIRE_CONTROL ) )
75 : {
76 145736 : Wallpaper aWallpaper;
77 145736 : aWallpaper.SetStyle( WALLPAPER_APPLICATIONGRADIENT );
78 145736 : pThis->SetBackground( aWallpaper );
79 : }
80 : else
81 145736 : pThis->SetBackground( Wallpaper( pThis->GetSettings().GetStyleSettings().GetFaceColor() ) );
82 145736 : }
83 :
84 44648 : DockingAreaWindow::DockingAreaWindow( vcl::Window* pParent ) :
85 44648 : Window( WINDOW_DOCKINGAREA )
86 : {
87 44648 : ImplInit( pParent, WB_CLIPCHILDREN|WB_3DLOOK, NULL );
88 :
89 44648 : mpImplData = new ImplData;
90 44648 : ImplInitBackground( this );
91 44648 : }
92 :
93 133800 : DockingAreaWindow::~DockingAreaWindow()
94 : {
95 44600 : delete mpImplData;
96 89200 : }
97 :
98 808 : void DockingAreaWindow::DataChanged( const DataChangedEvent& rDCEvt )
99 : {
100 808 : Window::DataChanged( rDCEvt );
101 :
102 808 : if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
103 : {
104 776 : ImplInitBackground( this );
105 776 : Invalidate();
106 : }
107 808 : }
108 :
109 88818 : static void ImplInvalidateMenubar( DockingAreaWindow* pThis )
110 : {
111 : // due to a possible comon gradient covering menubar and top dockingarea
112 : // the menubar must be repainted if the top dockingarea changes size or visibility
113 177636 : if( ImplGetSVData()->maNWFData.mbMenuBarDockingAreaCommonBG &&
114 0 : (pThis->GetAlign() == WINDOWALIGN_TOP)
115 0 : && pThis->IsNativeControlSupported( CTRL_TOOLBAR, PART_ENTIRE_CONTROL )
116 88818 : && pThis->IsNativeControlSupported( CTRL_MENUBAR, PART_ENTIRE_CONTROL ) )
117 : {
118 0 : SystemWindow *pSysWin = pThis->GetSystemWindow();
119 0 : if( pSysWin && pSysWin->GetMenuBar() )
120 : {
121 0 : vcl::Window *pMenubarWin = pSysWin->GetMenuBar()->GetWindow();
122 0 : if( pMenubarWin )
123 0 : pMenubarWin->Invalidate();
124 : }
125 : }
126 88818 : }
127 :
128 61568 : void DockingAreaWindow::StateChanged( StateChangedType nType )
129 : {
130 61568 : Window::StateChanged( nType );
131 :
132 61568 : if ( nType == StateChangedType::VISIBLE )
133 21992 : ImplInvalidateMenubar( this );
134 61568 : }
135 :
136 0 : bool DockingAreaWindow::IsHorizontal() const
137 : {
138 0 : return ( mpImplData->meAlign == WINDOWALIGN_TOP || mpImplData->meAlign == WINDOWALIGN_BOTTOM );
139 : }
140 :
141 44648 : void DockingAreaWindow::SetAlign( WindowAlign eNewAlign )
142 : {
143 44648 : if( eNewAlign != mpImplData->meAlign )
144 : {
145 33486 : mpImplData->meAlign = eNewAlign;
146 33486 : ImplInitBackground( this );
147 33486 : Invalidate();
148 : }
149 44648 : }
150 :
151 145736 : WindowAlign DockingAreaWindow::GetAlign() const
152 : {
153 145736 : return mpImplData->meAlign;
154 : }
155 :
156 11932 : void DockingAreaWindow::Paint( const Rectangle& )
157 : {
158 11932 : EnableNativeWidget( true ); // only required because the toolkit curently switches this flag off
159 11932 : if( IsNativeControlSupported( CTRL_TOOLBAR, PART_ENTIRE_CONTROL ) )
160 : {
161 0 : ToolbarValue aControlValue;
162 0 : const StyleSettings rSetting = Application::GetSettings().GetStyleSettings();
163 :
164 0 : if( GetAlign() == WINDOWALIGN_TOP && ImplGetSVData()->maNWFData.mbMenuBarDockingAreaCommonBG )
165 : {
166 : // give NWF a hint that this dockingarea is adjacent to the menubar
167 : // useful for special gradient effects that should cover both windows
168 0 : aControlValue.mbIsTopDockingArea = true;
169 : }
170 :
171 0 : ControlState nState = CTRL_STATE_ENABLED;
172 0 : const bool isFooter = GetAlign() == WINDOWALIGN_BOTTOM && !rSetting.GetPersonaFooter().IsEmpty();
173 :
174 0 : if (( GetAlign() == WINDOWALIGN_TOP && !rSetting.GetPersonaHeader().IsEmpty() ) || isFooter )
175 0 : Erase();
176 0 : else if ( !ImplGetSVData()->maNWFData.mbDockingAreaSeparateTB )
177 : {
178 : // draw a single toolbar background covering the whole docking area
179 0 : Point tmp;
180 0 : Rectangle aCtrlRegion( tmp, GetOutputSizePixel() );
181 :
182 0 : DrawNativeControl( CTRL_TOOLBAR, IsHorizontal() ? PART_DRAW_BACKGROUND_HORZ : PART_DRAW_BACKGROUND_VERT,
183 0 : aCtrlRegion, nState, aControlValue, OUString() );
184 :
185 0 : if( !ImplGetSVData()->maNWFData.mbDockingAreaAvoidTBFrames )
186 : {
187 : // each toolbar gets a thin border to better recognize its borders on the homogeneous docking area
188 0 : sal_uInt16 nChildren = GetChildCount();
189 0 : for( sal_uInt16 n = 0; n < nChildren; n++ )
190 : {
191 0 : vcl::Window* pChild = GetChild( n );
192 0 : if ( pChild->IsVisible() )
193 : {
194 0 : Point aPos = pChild->GetPosPixel();
195 0 : Size aSize = pChild->GetSizePixel();
196 0 : Rectangle aRect( aPos, aSize );
197 :
198 0 : SetLineColor( GetSettings().GetStyleSettings().GetLightColor() );
199 0 : DrawLine( aRect.TopLeft(), aRect.TopRight() );
200 0 : DrawLine( aRect.TopLeft(), aRect.BottomLeft() );
201 :
202 0 : SetLineColor( GetSettings().GetStyleSettings().GetSeparatorColor() );
203 0 : DrawLine( aRect.BottomLeft(), aRect.BottomRight() );
204 0 : DrawLine( aRect.TopRight(), aRect.BottomRight() );
205 : }
206 : }
207 : }
208 : }
209 : else
210 : {
211 : // create map to find toolbar lines
212 0 : Size aOutSz = GetOutputSizePixel();
213 0 : std::map< int, int > ranges;
214 0 : sal_uInt16 nChildren = GetChildCount();
215 0 : for( sal_uInt16 n = 0; n < nChildren; n++ )
216 : {
217 0 : vcl::Window* pChild = GetChild( n );
218 0 : Point aPos = pChild->GetPosPixel();
219 0 : Size aSize = pChild->GetSizePixel();
220 0 : if( IsHorizontal() )
221 0 : ranges[ aPos.Y() ] = aSize.Height();
222 : else
223 0 : ranges[ aPos.X() ] = aSize.Width();
224 : }
225 :
226 : // draw multiple toolbar backgrounds, i.e., one for each toolbar line
227 0 : for( std::map<int,int>::const_iterator it = ranges.begin(); it != ranges.end(); ++it )
228 : {
229 0 : Rectangle aTBRect;
230 0 : if( IsHorizontal() )
231 : {
232 0 : aTBRect.Left() = 0;
233 0 : aTBRect.Right() = aOutSz.Width() - 1;
234 0 : aTBRect.Top() = it->first;
235 0 : aTBRect.Bottom() = it->first + it->second - 1;
236 : }
237 : else
238 : {
239 0 : aTBRect.Left() = it->first;
240 0 : aTBRect.Right() = it->first + it->second - 1;
241 0 : aTBRect.Top() = 0;
242 0 : aTBRect.Bottom() = aOutSz.Height() - 1;
243 : }
244 0 : DrawNativeControl( CTRL_TOOLBAR, IsHorizontal() ? PART_DRAW_BACKGROUND_HORZ : PART_DRAW_BACKGROUND_VERT,
245 0 : aTBRect, nState, aControlValue, OUString() );
246 0 : }
247 0 : }
248 : }
249 11932 : }
250 :
251 66826 : void DockingAreaWindow::Resize()
252 : {
253 66826 : ImplInitBackground( this );
254 66826 : ImplInvalidateMenubar( this );
255 66826 : if( IsNativeControlSupported( CTRL_TOOLBAR, PART_ENTIRE_CONTROL ) )
256 0 : Invalidate();
257 68059 : }
258 :
259 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|