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