1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: dockingarea.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_vcl.hxx"
33 #include <tools/debug.hxx>
34 #include <vcl/dockingarea.hxx>
35 #include <vcl/syswin.hxx>
36 #include <vcl/menu.hxx>
37 #include <vcl/svdata.hxx>
41 // =======================================================================
43 class DockingAreaWindow::ImplData
52 DockingAreaWindow::ImplData::ImplData()
54 meAlign
= WINDOWALIGN_TOP
;
57 DockingAreaWindow::ImplData::~ImplData()
61 // =======================================================================
63 static void ImplInitBackground( DockingAreaWindow
* pThis
)
65 if( !pThis
->IsNativeControlSupported( CTRL_TOOLBAR
, PART_ENTIRE_CONTROL
) )
68 aWallpaper
.SetStyle( WALLPAPER_APPLICATIONGRADIENT
);
69 pThis
->SetBackground( aWallpaper
);
72 pThis
->SetBackground( Wallpaper( pThis
->GetSettings().GetStyleSettings().GetFaceColor() ) );
75 DockingAreaWindow::DockingAreaWindow( Window
* pParent
) :
76 Window( WINDOW_DOCKINGAREA
)
78 ImplInit( pParent
, WB_CLIPCHILDREN
|WB_3DLOOK
, NULL
);
80 mpImplData
= new ImplData
;
81 ImplInitBackground( this );
84 DockingAreaWindow::~DockingAreaWindow()
89 // -----------------------------------------------------------------------
91 void DockingAreaWindow::DataChanged( const DataChangedEvent
& rDCEvt
)
93 Window::DataChanged( rDCEvt
);
95 if ( (rDCEvt
.GetType() == DATACHANGED_SETTINGS
) && (rDCEvt
.GetFlags() & SETTINGS_STYLE
) )
97 ImplInitBackground( this );
101 // -----------------------------------------------------------------------
103 static void ImplInvalidateMenubar( DockingAreaWindow
* pThis
)
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
) )
112 SystemWindow
*pSysWin
= pThis
->GetSystemWindow();
113 if( pSysWin
&& pSysWin
->GetMenuBar() )
115 Window
*pMenubarWin
= pSysWin
->GetMenuBar()->GetWindow();
117 pMenubarWin
->Invalidate();
122 void DockingAreaWindow::StateChanged( StateChangedType nType
)
124 Window::StateChanged( nType
);
126 if ( nType
== STATE_CHANGE_VISIBLE
)
127 ImplInvalidateMenubar( this );
130 // -----------------------------------------------------------------------
132 BOOL
DockingAreaWindow::IsHorizontal() const
134 return ( mpImplData
->meAlign
== WINDOWALIGN_TOP
|| mpImplData
->meAlign
== WINDOWALIGN_BOTTOM
);
137 void DockingAreaWindow::SetAlign( WindowAlign eNewAlign
)
139 if( eNewAlign
!= mpImplData
->meAlign
)
141 mpImplData
->meAlign
= eNewAlign
;
146 WindowAlign
DockingAreaWindow::GetAlign() const
148 return mpImplData
->meAlign
;
151 // -----------------------------------------------------------------------
153 void DockingAreaWindow::Paint( const Rectangle
& )
155 EnableNativeWidget( TRUE
); // only required because the toolkit curently switches this flag off
156 if( IsNativeControlSupported( CTRL_TOOLBAR
, PART_ENTIRE_CONTROL
) )
158 ImplControlValue aControlValue
;
159 ToolbarValue aToolbarValue
;
161 if( GetAlign() == WINDOWALIGN_TOP
&& ImplGetSVData()->maNWFData
.mbMenuBarDockingAreaCommonBG
)
163 // give NWF a hint that this dockingarea is adjacent to the menubar
164 // useful for special gradient effects that should cover both windows
165 aToolbarValue
.mbIsTopDockingArea
= TRUE
;
167 aControlValue
.setOptionalVal( (void *)(&aToolbarValue
) );
168 ControlState nState
= CTRL_STATE_ENABLED
;
170 if( !ImplGetSVData()->maNWFData
.mbDockingAreaSeparateTB
)
172 // draw a single toolbar background covering the whole docking area
174 Region
aCtrlRegion( Rectangle( tmp
, GetOutputSizePixel() ) );
176 DrawNativeControl( CTRL_TOOLBAR
, IsHorizontal() ? PART_DRAW_BACKGROUND_HORZ
: PART_DRAW_BACKGROUND_VERT
,
177 aCtrlRegion
, nState
, aControlValue
, rtl::OUString() );
179 // each toolbar gets a thin border to better recognize its borders on the homogeneous docking area
180 USHORT nChildren
= GetChildCount();
181 for( USHORT n
= 0; n
< nChildren
; n
++ )
183 Window
* pChild
= GetChild( n
);
184 if ( pChild
->IsVisible() )
186 Point aPos
= pChild
->GetPosPixel();
187 Size aSize
= pChild
->GetSizePixel();
188 Rectangle
aRect( aPos
, aSize
);
190 SetLineColor( GetSettings().GetStyleSettings().GetLightColor() );
191 DrawLine( aRect
.TopLeft(), aRect
.TopRight() );
192 DrawLine( aRect
.TopLeft(), aRect
.BottomLeft() );
194 SetLineColor( GetSettings().GetStyleSettings().GetSeparatorColor() );
195 DrawLine( aRect
.BottomLeft(), aRect
.BottomRight() );
196 DrawLine( aRect
.TopRight(), aRect
.BottomRight() );
202 // create map to find toolbar lines
203 Size aOutSz
= GetOutputSizePixel();
204 std::map
< int, int > ranges
;
205 USHORT nChildren
= GetChildCount();
206 for( USHORT n
= 0; n
< nChildren
; n
++ )
208 Window
* pChild
= GetChild( n
);
209 Point aPos
= pChild
->GetPosPixel();
210 Size aSize
= pChild
->GetSizePixel();
212 ranges
[ aPos
.Y() ] = aSize
.Height();
214 ranges
[ aPos
.X() ] = aSize
.Width();
218 // draw multiple toolbar backgrounds, i.e., one for each toolbar line
219 for( std::map
<int,int>::const_iterator it
= ranges
.begin(); it
!= ranges
.end(); ++it
)
225 aTBRect
.Right() = aOutSz
.Width() - 1;
226 aTBRect
.Top() = it
->first
;
227 aTBRect
.Bottom() = it
->first
+ it
->second
- 1;
231 aTBRect
.Left() = it
->first
;
232 aTBRect
.Right() = it
->first
+ it
->second
- 1;
234 aTBRect
.Bottom() = aOutSz
.Height() - 1;
236 DrawNativeControl( CTRL_TOOLBAR
, IsHorizontal() ? PART_DRAW_BACKGROUND_HORZ
: PART_DRAW_BACKGROUND_VERT
,
237 Region( aTBRect
), nState
, aControlValue
, rtl::OUString() );
243 void DockingAreaWindow::Resize()
245 ImplInvalidateMenubar( this );
246 if( IsNativeControlSupported( CTRL_TOOLBAR
, PART_ENTIRE_CONTROL
) )
250 // -----------------------------------------------------------------------