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