Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / vcl / source / control / group.cxx
blob0e97fecc58e44e6e976cfd2153e361ee1d7b62a4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <tools/rc.h>
23 #include <vcl/event.hxx>
24 #include <vcl/group.hxx>
26 #include <controldata.hxx>
28 // =======================================================================
30 #define GROUP_BORDER 12
31 #define GROUP_TEXT_BORDER 2
33 #define GROUP_VIEW_STYLE (WB_3DLOOK | WB_NOLABEL)
35 // =======================================================================
37 void GroupBox::ImplInit( Window* pParent, WinBits nStyle )
39 nStyle = ImplInitStyle( nStyle );
40 Control::ImplInit( pParent, nStyle, NULL );
41 SetMouseTransparent( sal_True );
42 ImplInitSettings( sal_True, sal_True, sal_True );
45 // -----------------------------------------------------------------------
47 WinBits GroupBox::ImplInitStyle( WinBits nStyle )
49 if ( !(nStyle & WB_NOGROUP) )
50 nStyle |= WB_GROUP;
51 return nStyle;
54 // -----------------------------------------------------------------
56 const Font& GroupBox::GetCanonicalFont( const StyleSettings& _rStyle ) const
58 return _rStyle.GetGroupFont();
61 // -----------------------------------------------------------------
62 const Color& GroupBox::GetCanonicalTextColor( const StyleSettings& _rStyle ) const
64 return _rStyle.GetGroupTextColor();
67 // -----------------------------------------------------------------------
69 void GroupBox::ImplInitSettings( sal_Bool bFont,
70 sal_Bool bForeground, sal_Bool bBackground )
72 Control::ImplInitSettings( bFont, bForeground );
74 if ( bBackground )
76 Window* pParent = GetParent();
77 if ( (pParent->IsChildTransparentModeEnabled() ||
78 !(pParent->GetStyle() & WB_CLIPCHILDREN) ) &&
79 !IsControlBackground() )
81 EnableChildTransparentMode( sal_True );
82 SetParentClipMode( PARENTCLIPMODE_NOCLIP );
83 SetPaintTransparent( sal_True );
84 SetBackground();
86 else
88 EnableChildTransparentMode( sal_False );
89 SetParentClipMode( 0 );
90 SetPaintTransparent( sal_False );
92 if ( IsControlBackground() )
93 SetBackground( GetControlBackground() );
94 else
95 SetBackground( pParent->GetBackground() );
100 // -----------------------------------------------------------------------
102 GroupBox::GroupBox( Window* pParent, WinBits nStyle ) :
103 Control( WINDOW_GROUPBOX )
105 ImplInit( pParent, nStyle );
108 // -----------------------------------------------------------------------
110 GroupBox::GroupBox( Window* pParent, const ResId& rResId ) :
111 Control( WINDOW_GROUPBOX )
113 rResId.SetRT( RSC_GROUPBOX );
114 WinBits nStyle = ImplInitRes( rResId );
115 ImplInit( pParent, nStyle );
116 ImplLoadRes( rResId );
118 if ( !(nStyle & WB_HIDE) )
119 Show();
122 // -----------------------------------------------------------------------
124 void GroupBox::ImplDraw( OutputDevice* pDev, sal_uLong nDrawFlags,
125 const Point& rPos, const Size& rSize, bool bLayout )
127 long nTop;
128 long nTextOff;
129 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
130 OUString aText( GetText() );
131 Rectangle aRect( rPos, rSize );
132 sal_uInt16 nTextStyle = TEXT_DRAW_LEFT | TEXT_DRAW_TOP | TEXT_DRAW_ENDELLIPSIS | TEXT_DRAW_MNEMONIC;
134 if ( GetStyle() & WB_NOLABEL )
135 nTextStyle &= ~TEXT_DRAW_MNEMONIC;
136 if ( nDrawFlags & WINDOW_DRAW_NOMNEMONIC )
138 if ( nTextStyle & TEXT_DRAW_MNEMONIC )
140 aText = GetNonMnemonicString( aText );
141 nTextStyle &= ~TEXT_DRAW_MNEMONIC;
144 if ( !(nDrawFlags & WINDOW_DRAW_NODISABLE) )
146 if ( !IsEnabled() )
147 nTextStyle |= TEXT_DRAW_DISABLE;
149 if ( (nDrawFlags & WINDOW_DRAW_MONO) ||
150 (rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
152 nTextStyle |= TEXT_DRAW_MONO;
153 nDrawFlags |= WINDOW_DRAW_MONO;
156 if (aText.isEmpty())
158 nTop = rPos.Y();
159 nTextOff = 0;
161 else
163 aRect.Left() += GROUP_BORDER;
164 aRect.Right() -= GROUP_BORDER;
165 aRect = pDev->GetTextRect( aRect, aText, nTextStyle );
166 nTop = rPos.Y();
167 nTop += aRect.GetHeight() / 2;
168 nTextOff = GROUP_TEXT_BORDER;
171 if( ! bLayout )
173 if ( nDrawFlags & WINDOW_DRAW_MONO )
174 pDev->SetLineColor( Color( COL_BLACK ) );
175 else
176 pDev->SetLineColor( rStyleSettings.GetShadowColor() );
178 if (aText.isEmpty())
179 pDev->DrawLine( Point( rPos.X(), nTop ), Point( rPos.X()+rSize.Width()-2, nTop ) );
180 else
182 pDev->DrawLine( Point( rPos.X(), nTop ), Point( aRect.Left()-nTextOff, nTop ) );
183 pDev->DrawLine( Point( aRect.Right()+nTextOff, nTop ), Point( rPos.X()+rSize.Width()-2, nTop ) );
185 pDev->DrawLine( Point( rPos.X(), nTop ), Point( rPos.X(), rPos.Y()+rSize.Height()-2 ) );
186 pDev->DrawLine( Point( rPos.X(), rPos.Y()+rSize.Height()-2 ), Point( rPos.X()+rSize.Width()-2, rPos.Y()+rSize.Height()-2 ) );
187 pDev->DrawLine( Point( rPos.X()+rSize.Width()-2, rPos.Y()+rSize.Height()-2 ), Point( rPos.X()+rSize.Width()-2, nTop ) );
189 bool bIsPrinter = OUTDEV_PRINTER == pDev->GetOutDevType();
190 // if we're drawing onto a printer, spare the 3D effect
191 // #i46986# / 2005-04-13 / frank.schoenheit@sun.com
193 if ( !bIsPrinter && !(nDrawFlags & WINDOW_DRAW_MONO) )
195 pDev->SetLineColor( rStyleSettings.GetLightColor() );
196 if (aText.isEmpty())
197 pDev->DrawLine( Point( rPos.X()+1, nTop+1 ), Point( rPos.X()+rSize.Width()-3, nTop+1 ) );
198 else
200 pDev->DrawLine( Point( rPos.X()+1, nTop+1 ), Point( aRect.Left()-nTextOff, nTop+1 ) );
201 pDev->DrawLine( Point( aRect.Right()+nTextOff, nTop+1 ), Point( rPos.X()+rSize.Width()-3, nTop+1 ) );
203 pDev->DrawLine( Point( rPos.X()+1, nTop+1 ), Point( rPos.X()+1, rPos.Y()+rSize.Height()-3 ) );
204 pDev->DrawLine( Point( rPos.X(), rPos.Y()+rSize.Height()-1 ), Point( rPos.X()+rSize.Width()-1, rPos.Y()+rSize.Height()-1 ) );
205 pDev->DrawLine( Point( rPos.X()+rSize.Width()-1, rPos.Y()+rSize.Height()-1 ), Point( rPos.X()+rSize.Width()-1, nTop ) );
209 MetricVector* pVector = bLayout ? &mpControlData->mpLayoutData->m_aUnicodeBoundRects : NULL;
210 OUString* pDisplayText = bLayout ? &mpControlData->mpLayoutData->m_aDisplayText : NULL;
211 DrawControlText( *pDev, aRect, aText, nTextStyle, pVector, pDisplayText );
214 // -----------------------------------------------------------------------
216 void GroupBox::FillLayoutData() const
218 mpControlData->mpLayoutData = new vcl::ControlLayoutData();
219 const_cast<GroupBox*>(this)-> ImplDraw( const_cast<GroupBox*>(this), 0, Point(), GetOutputSizePixel(), true );
222 // -----------------------------------------------------------------------
224 void GroupBox::Paint( const Rectangle& )
226 ImplDraw( this, 0, Point(), GetOutputSizePixel() );
229 // -----------------------------------------------------------------------
231 void GroupBox::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize,
232 sal_uLong nFlags )
234 Point aPos = pDev->LogicToPixel( rPos );
235 Size aSize = pDev->LogicToPixel( rSize );
236 Font aFont = GetDrawPixelFont( pDev );
238 pDev->Push();
239 pDev->SetMapMode();
240 pDev->SetFont( aFont );
241 if ( nFlags & WINDOW_DRAW_MONO )
242 pDev->SetTextColor( Color( COL_BLACK ) );
243 else
244 pDev->SetTextColor( GetTextColor() );
245 pDev->SetTextFillColor();
247 ImplDraw( pDev, nFlags, aPos, aSize );
248 pDev->Pop();
251 // -----------------------------------------------------------------------
253 void GroupBox::Resize()
255 Control::Resize();
256 Invalidate();
259 // -----------------------------------------------------------------------
261 void GroupBox::StateChanged( StateChangedType nType )
263 Control::StateChanged( nType );
265 if ( (nType == STATE_CHANGE_ENABLE) ||
266 (nType == STATE_CHANGE_TEXT) ||
267 (nType == STATE_CHANGE_UPDATEMODE) )
269 if ( IsUpdateMode() )
270 Invalidate();
272 else if ( nType == STATE_CHANGE_STYLE )
274 SetStyle( ImplInitStyle( GetStyle() ) );
275 if ( (GetPrevStyle() & GROUP_VIEW_STYLE) !=
276 (GetStyle() & GROUP_VIEW_STYLE) )
277 Invalidate();
279 else if ( (nType == STATE_CHANGE_ZOOM) ||
280 (nType == STATE_CHANGE_CONTROLFONT) )
282 ImplInitSettings( sal_True, sal_False, sal_False );
283 Invalidate();
285 else if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
287 ImplInitSettings( sal_False, sal_True, sal_False );
288 Invalidate();
290 else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
292 ImplInitSettings( sal_False, sal_False, sal_True );
293 Invalidate();
297 // -----------------------------------------------------------------------
299 void GroupBox::DataChanged( const DataChangedEvent& rDCEvt )
301 Control::DataChanged( rDCEvt );
303 if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
304 (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
305 ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
306 (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
308 ImplInitSettings( sal_True, sal_True, sal_True );
309 Invalidate();
313 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */