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/rc.h> 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include <vcl/event.hxx> 34*cdf0e10cSrcweir #include <vcl/group.hxx> 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir #include <controldata.hxx> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir // ======================================================================= 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir #define GROUP_BORDER 12 41*cdf0e10cSrcweir #define GROUP_TEXT_BORDER 2 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir #define GROUP_VIEW_STYLE (WB_3DLOOK | WB_NOLABEL) 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir // ======================================================================= 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir void GroupBox::ImplInit( Window* pParent, WinBits nStyle ) 48*cdf0e10cSrcweir { 49*cdf0e10cSrcweir nStyle = ImplInitStyle( nStyle ); 50*cdf0e10cSrcweir Control::ImplInit( pParent, nStyle, NULL ); 51*cdf0e10cSrcweir SetMouseTransparent( sal_True ); 52*cdf0e10cSrcweir ImplInitSettings( sal_True, sal_True, sal_True ); 53*cdf0e10cSrcweir } 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir // ----------------------------------------------------------------------- 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir WinBits GroupBox::ImplInitStyle( WinBits nStyle ) 58*cdf0e10cSrcweir { 59*cdf0e10cSrcweir if ( !(nStyle & WB_NOGROUP) ) 60*cdf0e10cSrcweir nStyle |= WB_GROUP; 61*cdf0e10cSrcweir return nStyle; 62*cdf0e10cSrcweir } 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir // ----------------------------------------------------------------- 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir const Font& GroupBox::GetCanonicalFont( const StyleSettings& _rStyle ) const 67*cdf0e10cSrcweir { 68*cdf0e10cSrcweir return _rStyle.GetGroupFont(); 69*cdf0e10cSrcweir } 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir // ----------------------------------------------------------------- 72*cdf0e10cSrcweir const Color& GroupBox::GetCanonicalTextColor( const StyleSettings& _rStyle ) const 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir return _rStyle.GetGroupTextColor(); 75*cdf0e10cSrcweir } 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir // ----------------------------------------------------------------------- 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir void GroupBox::ImplInitSettings( sal_Bool bFont, 80*cdf0e10cSrcweir sal_Bool bForeground, sal_Bool bBackground ) 81*cdf0e10cSrcweir { 82*cdf0e10cSrcweir Control::ImplInitSettings( bFont, bForeground ); 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir if ( bBackground ) 85*cdf0e10cSrcweir { 86*cdf0e10cSrcweir Window* pParent = GetParent(); 87*cdf0e10cSrcweir if ( (pParent->IsChildTransparentModeEnabled() || 88*cdf0e10cSrcweir !(pParent->GetStyle() & WB_CLIPCHILDREN) ) && 89*cdf0e10cSrcweir !IsControlBackground() ) 90*cdf0e10cSrcweir { 91*cdf0e10cSrcweir EnableChildTransparentMode( sal_True ); 92*cdf0e10cSrcweir SetParentClipMode( PARENTCLIPMODE_NOCLIP ); 93*cdf0e10cSrcweir SetPaintTransparent( sal_True ); 94*cdf0e10cSrcweir SetBackground(); 95*cdf0e10cSrcweir } 96*cdf0e10cSrcweir else 97*cdf0e10cSrcweir { 98*cdf0e10cSrcweir EnableChildTransparentMode( sal_False ); 99*cdf0e10cSrcweir SetParentClipMode( 0 ); 100*cdf0e10cSrcweir SetPaintTransparent( sal_False ); 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir if ( IsControlBackground() ) 103*cdf0e10cSrcweir SetBackground( GetControlBackground() ); 104*cdf0e10cSrcweir else 105*cdf0e10cSrcweir SetBackground( pParent->GetBackground() ); 106*cdf0e10cSrcweir } 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir // ----------------------------------------------------------------------- 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir GroupBox::GroupBox( Window* pParent, WinBits nStyle ) : 113*cdf0e10cSrcweir Control( WINDOW_GROUPBOX ) 114*cdf0e10cSrcweir { 115*cdf0e10cSrcweir ImplInit( pParent, nStyle ); 116*cdf0e10cSrcweir } 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir // ----------------------------------------------------------------------- 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir GroupBox::GroupBox( Window* pParent, const ResId& rResId ) : 121*cdf0e10cSrcweir Control( WINDOW_GROUPBOX ) 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir rResId.SetRT( RSC_GROUPBOX ); 124*cdf0e10cSrcweir WinBits nStyle = ImplInitRes( rResId ); 125*cdf0e10cSrcweir ImplInit( pParent, nStyle ); 126*cdf0e10cSrcweir ImplLoadRes( rResId ); 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir if ( !(nStyle & WB_HIDE) ) 129*cdf0e10cSrcweir Show(); 130*cdf0e10cSrcweir } 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir // ----------------------------------------------------------------------- 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir void GroupBox::ImplDraw( OutputDevice* pDev, sal_uLong nDrawFlags, 135*cdf0e10cSrcweir const Point& rPos, const Size& rSize, bool bLayout ) 136*cdf0e10cSrcweir { 137*cdf0e10cSrcweir long nTop; 138*cdf0e10cSrcweir long nTextOff; 139*cdf0e10cSrcweir const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings(); 140*cdf0e10cSrcweir XubString aText( GetText() ); 141*cdf0e10cSrcweir Rectangle aRect( rPos, rSize ); 142*cdf0e10cSrcweir sal_uInt16 nTextStyle = TEXT_DRAW_LEFT | TEXT_DRAW_TOP | TEXT_DRAW_ENDELLIPSIS | TEXT_DRAW_MNEMONIC; 143*cdf0e10cSrcweir 144*cdf0e10cSrcweir if ( GetStyle() & WB_NOLABEL ) 145*cdf0e10cSrcweir nTextStyle &= ~TEXT_DRAW_MNEMONIC; 146*cdf0e10cSrcweir if ( nDrawFlags & WINDOW_DRAW_NOMNEMONIC ) 147*cdf0e10cSrcweir { 148*cdf0e10cSrcweir if ( nTextStyle & TEXT_DRAW_MNEMONIC ) 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir aText = GetNonMnemonicString( aText ); 151*cdf0e10cSrcweir nTextStyle &= ~TEXT_DRAW_MNEMONIC; 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir if ( !(nDrawFlags & WINDOW_DRAW_NODISABLE) ) 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir if ( !IsEnabled() ) 157*cdf0e10cSrcweir nTextStyle |= TEXT_DRAW_DISABLE; 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir if ( (nDrawFlags & WINDOW_DRAW_MONO) || 160*cdf0e10cSrcweir (rStyleSettings.GetOptions() & STYLE_OPTION_MONO) ) 161*cdf0e10cSrcweir { 162*cdf0e10cSrcweir nTextStyle |= TEXT_DRAW_MONO; 163*cdf0e10cSrcweir nDrawFlags |= WINDOW_DRAW_MONO; 164*cdf0e10cSrcweir } 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir if ( !aText.Len() ) 167*cdf0e10cSrcweir { 168*cdf0e10cSrcweir nTop = rPos.Y(); 169*cdf0e10cSrcweir nTextOff = 0; 170*cdf0e10cSrcweir } 171*cdf0e10cSrcweir else 172*cdf0e10cSrcweir { 173*cdf0e10cSrcweir aRect.Left() += GROUP_BORDER; 174*cdf0e10cSrcweir aRect.Right() -= GROUP_BORDER; 175*cdf0e10cSrcweir aRect = pDev->GetTextRect( aRect, aText, nTextStyle ); 176*cdf0e10cSrcweir nTop = rPos.Y(); 177*cdf0e10cSrcweir nTop += aRect.GetHeight() / 2; 178*cdf0e10cSrcweir nTextOff = GROUP_TEXT_BORDER; 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir if( ! bLayout ) 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir if ( nDrawFlags & WINDOW_DRAW_MONO ) 184*cdf0e10cSrcweir pDev->SetLineColor( Color( COL_BLACK ) ); 185*cdf0e10cSrcweir else 186*cdf0e10cSrcweir pDev->SetLineColor( rStyleSettings.GetShadowColor() ); 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir if ( !aText.Len() ) 189*cdf0e10cSrcweir pDev->DrawLine( Point( rPos.X(), nTop ), Point( rPos.X()+rSize.Width()-2, nTop ) ); 190*cdf0e10cSrcweir else 191*cdf0e10cSrcweir { 192*cdf0e10cSrcweir pDev->DrawLine( Point( rPos.X(), nTop ), Point( aRect.Left()-nTextOff, nTop ) ); 193*cdf0e10cSrcweir pDev->DrawLine( Point( aRect.Right()+nTextOff, nTop ), Point( rPos.X()+rSize.Width()-2, nTop ) ); 194*cdf0e10cSrcweir } 195*cdf0e10cSrcweir pDev->DrawLine( Point( rPos.X(), nTop ), Point( rPos.X(), rPos.Y()+rSize.Height()-2 ) ); 196*cdf0e10cSrcweir pDev->DrawLine( Point( rPos.X(), rPos.Y()+rSize.Height()-2 ), Point( rPos.X()+rSize.Width()-2, rPos.Y()+rSize.Height()-2 ) ); 197*cdf0e10cSrcweir pDev->DrawLine( Point( rPos.X()+rSize.Width()-2, rPos.Y()+rSize.Height()-2 ), Point( rPos.X()+rSize.Width()-2, nTop ) ); 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir bool bIsPrinter = OUTDEV_PRINTER == pDev->GetOutDevType(); 200*cdf0e10cSrcweir // if we're drawing onto a printer, spare the 3D effect 201*cdf0e10cSrcweir // #i46986# / 2005-04-13 / frank.schoenheit@sun.com 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir if ( !bIsPrinter && !(nDrawFlags & WINDOW_DRAW_MONO) ) 204*cdf0e10cSrcweir { 205*cdf0e10cSrcweir pDev->SetLineColor( rStyleSettings.GetLightColor() ); 206*cdf0e10cSrcweir if ( !aText.Len() ) 207*cdf0e10cSrcweir pDev->DrawLine( Point( rPos.X()+1, nTop+1 ), Point( rPos.X()+rSize.Width()-3, nTop+1 ) ); 208*cdf0e10cSrcweir else 209*cdf0e10cSrcweir { 210*cdf0e10cSrcweir pDev->DrawLine( Point( rPos.X()+1, nTop+1 ), Point( aRect.Left()-nTextOff, nTop+1 ) ); 211*cdf0e10cSrcweir pDev->DrawLine( Point( aRect.Right()+nTextOff, nTop+1 ), Point( rPos.X()+rSize.Width()-3, nTop+1 ) ); 212*cdf0e10cSrcweir } 213*cdf0e10cSrcweir pDev->DrawLine( Point( rPos.X()+1, nTop+1 ), Point( rPos.X()+1, rPos.Y()+rSize.Height()-3 ) ); 214*cdf0e10cSrcweir pDev->DrawLine( Point( rPos.X(), rPos.Y()+rSize.Height()-1 ), Point( rPos.X()+rSize.Width()-1, rPos.Y()+rSize.Height()-1 ) ); 215*cdf0e10cSrcweir pDev->DrawLine( Point( rPos.X()+rSize.Width()-1, rPos.Y()+rSize.Height()-1 ), Point( rPos.X()+rSize.Width()-1, nTop ) ); 216*cdf0e10cSrcweir } 217*cdf0e10cSrcweir } 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir MetricVector* pVector = bLayout ? &mpControlData->mpLayoutData->m_aUnicodeBoundRects : NULL; 220*cdf0e10cSrcweir String* pDisplayText = bLayout ? &mpControlData->mpLayoutData->m_aDisplayText : NULL; 221*cdf0e10cSrcweir DrawControlText( *pDev, aRect, aText, nTextStyle, pVector, pDisplayText ); 222*cdf0e10cSrcweir } 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir // ----------------------------------------------------------------------- 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir void GroupBox::FillLayoutData() const 227*cdf0e10cSrcweir { 228*cdf0e10cSrcweir mpControlData->mpLayoutData = new vcl::ControlLayoutData(); 229*cdf0e10cSrcweir const_cast<GroupBox*>(this)-> ImplDraw( const_cast<GroupBox*>(this), 0, Point(), GetOutputSizePixel(), true ); 230*cdf0e10cSrcweir } 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir // ----------------------------------------------------------------------- 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir void GroupBox::Paint( const Rectangle& ) 235*cdf0e10cSrcweir { 236*cdf0e10cSrcweir ImplDraw( this, 0, Point(), GetOutputSizePixel() ); 237*cdf0e10cSrcweir } 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir // ----------------------------------------------------------------------- 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir void GroupBox::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, 242*cdf0e10cSrcweir sal_uLong nFlags ) 243*cdf0e10cSrcweir { 244*cdf0e10cSrcweir Point aPos = pDev->LogicToPixel( rPos ); 245*cdf0e10cSrcweir Size aSize = pDev->LogicToPixel( rSize ); 246*cdf0e10cSrcweir Font aFont = GetDrawPixelFont( pDev ); 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir pDev->Push(); 249*cdf0e10cSrcweir pDev->SetMapMode(); 250*cdf0e10cSrcweir pDev->SetFont( aFont ); 251*cdf0e10cSrcweir if ( nFlags & WINDOW_DRAW_MONO ) 252*cdf0e10cSrcweir pDev->SetTextColor( Color( COL_BLACK ) ); 253*cdf0e10cSrcweir else 254*cdf0e10cSrcweir pDev->SetTextColor( GetTextColor() ); 255*cdf0e10cSrcweir pDev->SetTextFillColor(); 256*cdf0e10cSrcweir 257*cdf0e10cSrcweir ImplDraw( pDev, nFlags, aPos, aSize ); 258*cdf0e10cSrcweir pDev->Pop(); 259*cdf0e10cSrcweir } 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir // ----------------------------------------------------------------------- 262*cdf0e10cSrcweir 263*cdf0e10cSrcweir void GroupBox::Resize() 264*cdf0e10cSrcweir { 265*cdf0e10cSrcweir Control::Resize(); 266*cdf0e10cSrcweir Invalidate(); 267*cdf0e10cSrcweir } 268*cdf0e10cSrcweir 269*cdf0e10cSrcweir // ----------------------------------------------------------------------- 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir void GroupBox::StateChanged( StateChangedType nType ) 272*cdf0e10cSrcweir { 273*cdf0e10cSrcweir Control::StateChanged( nType ); 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir if ( (nType == STATE_CHANGE_ENABLE) || 276*cdf0e10cSrcweir (nType == STATE_CHANGE_TEXT) || 277*cdf0e10cSrcweir (nType == STATE_CHANGE_UPDATEMODE) ) 278*cdf0e10cSrcweir { 279*cdf0e10cSrcweir if ( IsUpdateMode() ) 280*cdf0e10cSrcweir Invalidate(); 281*cdf0e10cSrcweir } 282*cdf0e10cSrcweir else if ( nType == STATE_CHANGE_STYLE ) 283*cdf0e10cSrcweir { 284*cdf0e10cSrcweir SetStyle( ImplInitStyle( GetStyle() ) ); 285*cdf0e10cSrcweir if ( (GetPrevStyle() & GROUP_VIEW_STYLE) != 286*cdf0e10cSrcweir (GetStyle() & GROUP_VIEW_STYLE) ) 287*cdf0e10cSrcweir Invalidate(); 288*cdf0e10cSrcweir } 289*cdf0e10cSrcweir else if ( (nType == STATE_CHANGE_ZOOM) || 290*cdf0e10cSrcweir (nType == STATE_CHANGE_CONTROLFONT) ) 291*cdf0e10cSrcweir { 292*cdf0e10cSrcweir ImplInitSettings( sal_True, sal_False, sal_False ); 293*cdf0e10cSrcweir Invalidate(); 294*cdf0e10cSrcweir } 295*cdf0e10cSrcweir else if ( nType == STATE_CHANGE_CONTROLFOREGROUND ) 296*cdf0e10cSrcweir { 297*cdf0e10cSrcweir ImplInitSettings( sal_False, sal_True, sal_False ); 298*cdf0e10cSrcweir Invalidate(); 299*cdf0e10cSrcweir } 300*cdf0e10cSrcweir else if ( nType == STATE_CHANGE_CONTROLBACKGROUND ) 301*cdf0e10cSrcweir { 302*cdf0e10cSrcweir ImplInitSettings( sal_False, sal_False, sal_True ); 303*cdf0e10cSrcweir Invalidate(); 304*cdf0e10cSrcweir } 305*cdf0e10cSrcweir } 306*cdf0e10cSrcweir 307*cdf0e10cSrcweir // ----------------------------------------------------------------------- 308*cdf0e10cSrcweir 309*cdf0e10cSrcweir void GroupBox::DataChanged( const DataChangedEvent& rDCEvt ) 310*cdf0e10cSrcweir { 311*cdf0e10cSrcweir Control::DataChanged( rDCEvt ); 312*cdf0e10cSrcweir 313*cdf0e10cSrcweir if ( (rDCEvt.GetType() == DATACHANGED_FONTS) || 314*cdf0e10cSrcweir (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) || 315*cdf0e10cSrcweir ((rDCEvt.GetType() == DATACHANGED_SETTINGS) && 316*cdf0e10cSrcweir (rDCEvt.GetFlags() & SETTINGS_STYLE)) ) 317*cdf0e10cSrcweir { 318*cdf0e10cSrcweir ImplInitSettings( sal_True, sal_True, sal_True ); 319*cdf0e10cSrcweir Invalidate(); 320*cdf0e10cSrcweir } 321*cdf0e10cSrcweir } 322*cdf0e10cSrcweir 323