xref: /trunk/main/vcl/source/window/dockingarea.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_vcl.hxx"
30 
31 #include <tools/debug.hxx>
32 
33 #include <vcl/dockingarea.hxx>
34 #include <vcl/syswin.hxx>
35 #include <vcl/menu.hxx>
36 
37 #include <svdata.hxx>
38 
39 #include <map>
40 
41 // =======================================================================
42 
43 class DockingAreaWindow::ImplData
44 {
45 public:
46     ImplData();
47     ~ImplData();
48 
49     WindowAlign meAlign;
50 };
51 
52 DockingAreaWindow::ImplData::ImplData()
53 {
54     meAlign = WINDOWALIGN_TOP;
55 }
56 
57 DockingAreaWindow::ImplData::~ImplData()
58 {
59 }
60 
61 // =======================================================================
62 
63 static void ImplInitBackground( DockingAreaWindow* pThis )
64 {
65     if( !pThis->IsNativeControlSupported( CTRL_TOOLBAR, PART_ENTIRE_CONTROL ) )
66     {
67         Wallpaper aWallpaper;
68         aWallpaper.SetStyle( WALLPAPER_APPLICATIONGRADIENT );
69         pThis->SetBackground( aWallpaper );
70     }
71     else
72         pThis->SetBackground( Wallpaper( pThis->GetSettings().GetStyleSettings().GetFaceColor() ) );
73 }
74 
75 DockingAreaWindow::DockingAreaWindow( Window* pParent ) :
76     Window( WINDOW_DOCKINGAREA )
77 {
78     ImplInit( pParent, WB_CLIPCHILDREN|WB_3DLOOK, NULL );
79 
80     mpImplData = new ImplData;
81     ImplInitBackground( this );
82 }
83 
84 DockingAreaWindow::~DockingAreaWindow()
85 {
86     delete mpImplData;
87 }
88 
89 // -----------------------------------------------------------------------
90 
91 void DockingAreaWindow::DataChanged( const DataChangedEvent& rDCEvt )
92 {
93     Window::DataChanged( rDCEvt );
94 
95     if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) && (rDCEvt.GetFlags() & SETTINGS_STYLE) )
96     {
97         ImplInitBackground( this );
98     }
99 }
100 
101 // -----------------------------------------------------------------------
102 
103 static void ImplInvalidateMenubar( DockingAreaWindow* pThis )
104 {
105     // due to a possible comon gradient covering menubar and top dockingarea
106     // the menubar must be repainted if the top dockingarea changes size or visibility
107     if( ImplGetSVData()->maNWFData.mbMenuBarDockingAreaCommonBG &&
108         (pThis->GetAlign() == WINDOWALIGN_TOP)
109         && pThis->IsNativeControlSupported( CTRL_TOOLBAR, PART_ENTIRE_CONTROL )
110         && pThis->IsNativeControlSupported( CTRL_MENUBAR, PART_ENTIRE_CONTROL ) )
111     {
112         SystemWindow *pSysWin = pThis->GetSystemWindow();
113         if( pSysWin && pSysWin->GetMenuBar() )
114         {
115             Window *pMenubarWin = pSysWin->GetMenuBar()->GetWindow();
116             if( pMenubarWin )
117                 pMenubarWin->Invalidate();
118         }
119     }
120 }
121 
122 void DockingAreaWindow::StateChanged( StateChangedType nType )
123 {
124     Window::StateChanged( nType );
125 
126     if ( nType == STATE_CHANGE_VISIBLE )
127         ImplInvalidateMenubar( this );
128 }
129 
130 // -----------------------------------------------------------------------
131 
132 sal_Bool DockingAreaWindow::IsHorizontal() const
133 {
134     return ( mpImplData->meAlign == WINDOWALIGN_TOP || mpImplData->meAlign == WINDOWALIGN_BOTTOM );
135 }
136 
137 void DockingAreaWindow::SetAlign( WindowAlign eNewAlign )
138 {
139     if( eNewAlign != mpImplData->meAlign )
140     {
141         mpImplData->meAlign = eNewAlign;
142         Invalidate();
143     }
144 }
145 
146 WindowAlign DockingAreaWindow::GetAlign() const
147 {
148     return mpImplData->meAlign;
149 }
150 
151 // -----------------------------------------------------------------------
152 
153 void DockingAreaWindow::Paint( const Rectangle& )
154 {
155     EnableNativeWidget( sal_True ); // only required because the toolkit curently switches this flag off
156     if( IsNativeControlSupported( CTRL_TOOLBAR, PART_ENTIRE_CONTROL ) )
157     {
158         ToolbarValue        aControlValue;
159 
160         if( GetAlign() == WINDOWALIGN_TOP && ImplGetSVData()->maNWFData.mbMenuBarDockingAreaCommonBG )
161         {
162             // give NWF a hint that this dockingarea is adjacent to the menubar
163             // useful for special gradient effects that should cover both windows
164             aControlValue.mbIsTopDockingArea = sal_True;
165         }
166         ControlState        nState = CTRL_STATE_ENABLED;
167 
168         if( !ImplGetSVData()->maNWFData.mbDockingAreaSeparateTB )
169         {
170             // draw a single toolbar background covering the whole docking area
171             Point tmp;
172             Rectangle aCtrlRegion( tmp, GetOutputSizePixel() );
173 
174             DrawNativeControl( CTRL_TOOLBAR, IsHorizontal() ? PART_DRAW_BACKGROUND_HORZ : PART_DRAW_BACKGROUND_VERT,
175                                aCtrlRegion, nState, aControlValue, rtl::OUString() );
176 
177             // each toolbar gets a thin border to better recognize its borders on the homogeneous docking area
178             sal_uInt16 nChildren = GetChildCount();
179             for( sal_uInt16 n = 0; n < nChildren; n++ )
180             {
181                 Window* pChild = GetChild( n );
182                 if ( pChild->IsVisible() )
183                 {
184                     Point aPos = pChild->GetPosPixel();
185                     Size aSize = pChild->GetSizePixel();
186                     Rectangle aRect( aPos, aSize );
187 
188                     SetLineColor( GetSettings().GetStyleSettings().GetLightColor() );
189                     DrawLine( aRect.TopLeft(), aRect.TopRight() );
190                     DrawLine( aRect.TopLeft(), aRect.BottomLeft() );
191 
192                     SetLineColor( GetSettings().GetStyleSettings().GetSeparatorColor() );
193                     DrawLine( aRect.BottomLeft(), aRect.BottomRight() );
194                     DrawLine( aRect.TopRight(), aRect.BottomRight() );
195                 }
196             }
197         }
198         else
199         {
200             // create map to find toolbar lines
201             Size aOutSz = GetOutputSizePixel();
202             std::map< int, int > ranges;
203             sal_uInt16 nChildren = GetChildCount();
204             for( sal_uInt16 n = 0; n < nChildren; n++ )
205             {
206                 Window* pChild = GetChild( n );
207                 Point aPos = pChild->GetPosPixel();
208                 Size aSize = pChild->GetSizePixel();
209                 if( IsHorizontal() )
210                     ranges[ aPos.Y() ] = aSize.Height();
211                 else
212                     ranges[ aPos.X() ] = aSize.Width();
213             }
214 
215 
216             // draw multiple toolbar backgrounds, i.e., one for each toolbar line
217             for( std::map<int,int>::const_iterator it = ranges.begin(); it != ranges.end(); ++it )
218             {
219                 Rectangle aTBRect;
220                 if( IsHorizontal() )
221                 {
222                     aTBRect.Left()      = 0;
223                     aTBRect.Right()     = aOutSz.Width() - 1;
224                     aTBRect.Top()       = it->first;
225                     aTBRect.Bottom()    = it->first + it->second - 1;
226                 }
227                 else
228                 {
229                     aTBRect.Left()      = it->first;
230                     aTBRect.Right()     = it->first + it->second - 1;
231                     aTBRect.Top()       = 0;
232                     aTBRect.Bottom()    = aOutSz.Height() - 1;
233                 }
234                 DrawNativeControl( CTRL_TOOLBAR, IsHorizontal() ? PART_DRAW_BACKGROUND_HORZ : PART_DRAW_BACKGROUND_VERT,
235                                    aTBRect, nState, aControlValue, rtl::OUString() );
236             }
237         }
238     }
239 }
240 
241 void DockingAreaWindow::Resize()
242 {
243     ImplInvalidateMenubar( this );
244     if( IsNativeControlSupported( CTRL_TOOLBAR, PART_ENTIRE_CONTROL ) )
245         Invalidate();
246 }
247 
248 // -----------------------------------------------------------------------
249 
250