xref: /aoo41x/main/vcl/source/control/group.cxx (revision 9f62ea84)
1*9f62ea84SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9f62ea84SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9f62ea84SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9f62ea84SAndrew Rist  * distributed with this work for additional information
6*9f62ea84SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9f62ea84SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9f62ea84SAndrew Rist  * "License"); you may not use this file except in compliance
9*9f62ea84SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*9f62ea84SAndrew Rist  *
11*9f62ea84SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*9f62ea84SAndrew Rist  *
13*9f62ea84SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9f62ea84SAndrew Rist  * software distributed under the License is distributed on an
15*9f62ea84SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9f62ea84SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9f62ea84SAndrew Rist  * specific language governing permissions and limitations
18*9f62ea84SAndrew Rist  * under the License.
19*9f62ea84SAndrew Rist  *
20*9f62ea84SAndrew Rist  *************************************************************/
21*9f62ea84SAndrew Rist 
22*9f62ea84SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_vcl.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <tools/rc.h>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <vcl/event.hxx>
30cdf0e10cSrcweir #include <vcl/group.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <controldata.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir // =======================================================================
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #define GROUP_BORDER			12
37cdf0e10cSrcweir #define GROUP_TEXT_BORDER		2
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #define GROUP_VIEW_STYLE		(WB_3DLOOK | WB_NOLABEL)
40cdf0e10cSrcweir 
41cdf0e10cSrcweir // =======================================================================
42cdf0e10cSrcweir 
ImplInit(Window * pParent,WinBits nStyle)43cdf0e10cSrcweir void GroupBox::ImplInit( Window* pParent, WinBits nStyle )
44cdf0e10cSrcweir {
45cdf0e10cSrcweir 	nStyle = ImplInitStyle( nStyle );
46cdf0e10cSrcweir 	Control::ImplInit( pParent, nStyle, NULL );
47cdf0e10cSrcweir 	SetMouseTransparent( sal_True );
48cdf0e10cSrcweir 	ImplInitSettings( sal_True, sal_True, sal_True );
49cdf0e10cSrcweir }
50cdf0e10cSrcweir 
51cdf0e10cSrcweir // -----------------------------------------------------------------------
52cdf0e10cSrcweir 
ImplInitStyle(WinBits nStyle)53cdf0e10cSrcweir WinBits GroupBox::ImplInitStyle( WinBits nStyle )
54cdf0e10cSrcweir {
55cdf0e10cSrcweir 	if ( !(nStyle & WB_NOGROUP) )
56cdf0e10cSrcweir 		nStyle |= WB_GROUP;
57cdf0e10cSrcweir 	return nStyle;
58cdf0e10cSrcweir }
59cdf0e10cSrcweir 
60cdf0e10cSrcweir // -----------------------------------------------------------------
61cdf0e10cSrcweir 
GetCanonicalFont(const StyleSettings & _rStyle) const62cdf0e10cSrcweir const Font& GroupBox::GetCanonicalFont( const StyleSettings& _rStyle ) const
63cdf0e10cSrcweir {
64cdf0e10cSrcweir     return _rStyle.GetGroupFont();
65cdf0e10cSrcweir }
66cdf0e10cSrcweir 
67cdf0e10cSrcweir // -----------------------------------------------------------------
GetCanonicalTextColor(const StyleSettings & _rStyle) const68cdf0e10cSrcweir const Color& GroupBox::GetCanonicalTextColor( const StyleSettings& _rStyle ) const
69cdf0e10cSrcweir {
70cdf0e10cSrcweir     return _rStyle.GetGroupTextColor();
71cdf0e10cSrcweir }
72cdf0e10cSrcweir 
73cdf0e10cSrcweir // -----------------------------------------------------------------------
74cdf0e10cSrcweir 
ImplInitSettings(sal_Bool bFont,sal_Bool bForeground,sal_Bool bBackground)75cdf0e10cSrcweir void GroupBox::ImplInitSettings( sal_Bool bFont,
76cdf0e10cSrcweir 								 sal_Bool bForeground, sal_Bool bBackground )
77cdf0e10cSrcweir {
78cdf0e10cSrcweir     Control::ImplInitSettings( bFont, bForeground );
79cdf0e10cSrcweir 
80cdf0e10cSrcweir 	if ( bBackground )
81cdf0e10cSrcweir 	{
82cdf0e10cSrcweir 		Window* pParent = GetParent();
83cdf0e10cSrcweir 		if ( (pParent->IsChildTransparentModeEnabled() ||
84cdf0e10cSrcweir 			  !(pParent->GetStyle() & WB_CLIPCHILDREN) ) &&
85cdf0e10cSrcweir 			 !IsControlBackground() )
86cdf0e10cSrcweir 		{
87cdf0e10cSrcweir 			EnableChildTransparentMode( sal_True );
88cdf0e10cSrcweir 			SetParentClipMode( PARENTCLIPMODE_NOCLIP );
89cdf0e10cSrcweir 			SetPaintTransparent( sal_True );
90cdf0e10cSrcweir 			SetBackground();
91cdf0e10cSrcweir 		}
92cdf0e10cSrcweir 		else
93cdf0e10cSrcweir 		{
94cdf0e10cSrcweir 			EnableChildTransparentMode( sal_False );
95cdf0e10cSrcweir 			SetParentClipMode( 0 );
96cdf0e10cSrcweir 			SetPaintTransparent( sal_False );
97cdf0e10cSrcweir 
98cdf0e10cSrcweir 			if ( IsControlBackground() )
99cdf0e10cSrcweir 				SetBackground( GetControlBackground() );
100cdf0e10cSrcweir 			else
101cdf0e10cSrcweir 				SetBackground( pParent->GetBackground() );
102cdf0e10cSrcweir 		}
103cdf0e10cSrcweir 	}
104cdf0e10cSrcweir }
105cdf0e10cSrcweir 
106cdf0e10cSrcweir // -----------------------------------------------------------------------
107cdf0e10cSrcweir 
GroupBox(Window * pParent,WinBits nStyle)108cdf0e10cSrcweir GroupBox::GroupBox( Window* pParent, WinBits nStyle ) :
109cdf0e10cSrcweir 	Control( WINDOW_GROUPBOX )
110cdf0e10cSrcweir {
111cdf0e10cSrcweir 	ImplInit( pParent, nStyle );
112cdf0e10cSrcweir }
113cdf0e10cSrcweir 
114cdf0e10cSrcweir // -----------------------------------------------------------------------
115cdf0e10cSrcweir 
GroupBox(Window * pParent,const ResId & rResId)116cdf0e10cSrcweir GroupBox::GroupBox( Window* pParent, const ResId& rResId ) :
117cdf0e10cSrcweir 	Control( WINDOW_GROUPBOX )
118cdf0e10cSrcweir {
119cdf0e10cSrcweir 	rResId.SetRT( RSC_GROUPBOX );
120cdf0e10cSrcweir 	WinBits nStyle = ImplInitRes( rResId );
121cdf0e10cSrcweir 	ImplInit( pParent, nStyle );
122cdf0e10cSrcweir 	ImplLoadRes( rResId );
123cdf0e10cSrcweir 
124cdf0e10cSrcweir 	if ( !(nStyle & WB_HIDE) )
125cdf0e10cSrcweir 		Show();
126cdf0e10cSrcweir }
127cdf0e10cSrcweir 
128cdf0e10cSrcweir // -----------------------------------------------------------------------
129cdf0e10cSrcweir 
ImplDraw(OutputDevice * pDev,sal_uLong nDrawFlags,const Point & rPos,const Size & rSize,bool bLayout)130cdf0e10cSrcweir void GroupBox::ImplDraw( OutputDevice* pDev, sal_uLong nDrawFlags,
131cdf0e10cSrcweir 						 const Point& rPos, const Size& rSize, bool bLayout )
132cdf0e10cSrcweir {
133cdf0e10cSrcweir 	long					nTop;
134cdf0e10cSrcweir 	long					nTextOff;
135cdf0e10cSrcweir 	const StyleSettings&	rStyleSettings = GetSettings().GetStyleSettings();
136cdf0e10cSrcweir 	XubString				aText( GetText() );
137cdf0e10cSrcweir 	Rectangle				aRect( rPos, rSize );
138cdf0e10cSrcweir 	sal_uInt16					nTextStyle = TEXT_DRAW_LEFT | TEXT_DRAW_TOP | TEXT_DRAW_ENDELLIPSIS | TEXT_DRAW_MNEMONIC;
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 	if ( GetStyle() & WB_NOLABEL )
141cdf0e10cSrcweir 		nTextStyle &= ~TEXT_DRAW_MNEMONIC;
142cdf0e10cSrcweir 	if ( nDrawFlags & WINDOW_DRAW_NOMNEMONIC )
143cdf0e10cSrcweir 	{
144cdf0e10cSrcweir 		if ( nTextStyle & TEXT_DRAW_MNEMONIC )
145cdf0e10cSrcweir 		{
146cdf0e10cSrcweir 			aText = GetNonMnemonicString( aText );
147cdf0e10cSrcweir 			nTextStyle &= ~TEXT_DRAW_MNEMONIC;
148cdf0e10cSrcweir 		}
149cdf0e10cSrcweir 	}
150cdf0e10cSrcweir 	if ( !(nDrawFlags & WINDOW_DRAW_NODISABLE) )
151cdf0e10cSrcweir 	{
152cdf0e10cSrcweir 		if ( !IsEnabled() )
153cdf0e10cSrcweir 			nTextStyle |= TEXT_DRAW_DISABLE;
154cdf0e10cSrcweir 	}
155cdf0e10cSrcweir 	if ( (nDrawFlags & WINDOW_DRAW_MONO) ||
156cdf0e10cSrcweir 		 (rStyleSettings.GetOptions() & STYLE_OPTION_MONO) )
157cdf0e10cSrcweir 	{
158cdf0e10cSrcweir 		nTextStyle |= TEXT_DRAW_MONO;
159cdf0e10cSrcweir 		nDrawFlags |= WINDOW_DRAW_MONO;
160cdf0e10cSrcweir 	}
161cdf0e10cSrcweir 
162cdf0e10cSrcweir 	if ( !aText.Len() )
163cdf0e10cSrcweir 	{
164cdf0e10cSrcweir 		nTop = rPos.Y();
165cdf0e10cSrcweir 		nTextOff = 0;
166cdf0e10cSrcweir 	}
167cdf0e10cSrcweir 	else
168cdf0e10cSrcweir 	{
169cdf0e10cSrcweir 		aRect.Left() += GROUP_BORDER;
170cdf0e10cSrcweir 		aRect.Right() -= GROUP_BORDER;
171cdf0e10cSrcweir 		aRect = pDev->GetTextRect( aRect, aText, nTextStyle );
172cdf0e10cSrcweir 		nTop = rPos.Y();
173cdf0e10cSrcweir 		nTop += aRect.GetHeight() / 2;
174cdf0e10cSrcweir 		nTextOff = GROUP_TEXT_BORDER;
175cdf0e10cSrcweir 	}
176cdf0e10cSrcweir 
177cdf0e10cSrcweir     if( ! bLayout )
178cdf0e10cSrcweir     {
179cdf0e10cSrcweir         if ( nDrawFlags & WINDOW_DRAW_MONO )
180cdf0e10cSrcweir             pDev->SetLineColor( Color( COL_BLACK ) );
181cdf0e10cSrcweir         else
182cdf0e10cSrcweir             pDev->SetLineColor( rStyleSettings.GetShadowColor() );
183cdf0e10cSrcweir 
184cdf0e10cSrcweir         if ( !aText.Len() )
185cdf0e10cSrcweir             pDev->DrawLine( Point( rPos.X(), nTop ), Point( rPos.X()+rSize.Width()-2, nTop ) );
186cdf0e10cSrcweir         else
187cdf0e10cSrcweir         {
188cdf0e10cSrcweir             pDev->DrawLine( Point( rPos.X(), nTop ), Point( aRect.Left()-nTextOff, nTop ) );
189cdf0e10cSrcweir             pDev->DrawLine( Point( aRect.Right()+nTextOff, nTop ), Point( rPos.X()+rSize.Width()-2, nTop ) );
190cdf0e10cSrcweir         }
191cdf0e10cSrcweir         pDev->DrawLine( Point( rPos.X(), nTop ), Point( rPos.X(), rPos.Y()+rSize.Height()-2 ) );
192cdf0e10cSrcweir         pDev->DrawLine( Point( rPos.X(), rPos.Y()+rSize.Height()-2 ), Point( rPos.X()+rSize.Width()-2, rPos.Y()+rSize.Height()-2 ) );
193cdf0e10cSrcweir         pDev->DrawLine( Point( rPos.X()+rSize.Width()-2, rPos.Y()+rSize.Height()-2 ), Point( rPos.X()+rSize.Width()-2, nTop ) );
194cdf0e10cSrcweir 
195cdf0e10cSrcweir         bool bIsPrinter = OUTDEV_PRINTER == pDev->GetOutDevType();
196cdf0e10cSrcweir         // if we're drawing onto a printer, spare the 3D effect
197cdf0e10cSrcweir         // #i46986# / 2005-04-13 / frank.schoenheit@sun.com
198cdf0e10cSrcweir 
199cdf0e10cSrcweir         if ( !bIsPrinter && !(nDrawFlags & WINDOW_DRAW_MONO) )
200cdf0e10cSrcweir         {
201cdf0e10cSrcweir             pDev->SetLineColor( rStyleSettings.GetLightColor() );
202cdf0e10cSrcweir             if ( !aText.Len() )
203cdf0e10cSrcweir                 pDev->DrawLine( Point( rPos.X()+1, nTop+1 ), Point( rPos.X()+rSize.Width()-3, nTop+1 ) );
204cdf0e10cSrcweir             else
205cdf0e10cSrcweir             {
206cdf0e10cSrcweir                 pDev->DrawLine( Point( rPos.X()+1, nTop+1 ), Point( aRect.Left()-nTextOff, nTop+1 ) );
207cdf0e10cSrcweir                 pDev->DrawLine( Point( aRect.Right()+nTextOff, nTop+1 ), Point( rPos.X()+rSize.Width()-3, nTop+1 ) );
208cdf0e10cSrcweir             }
209cdf0e10cSrcweir             pDev->DrawLine( Point( rPos.X()+1, nTop+1 ), Point( rPos.X()+1, rPos.Y()+rSize.Height()-3 ) );
210cdf0e10cSrcweir             pDev->DrawLine( Point( rPos.X(), rPos.Y()+rSize.Height()-1 ), Point( rPos.X()+rSize.Width()-1, rPos.Y()+rSize.Height()-1 ) );
211cdf0e10cSrcweir             pDev->DrawLine( Point( rPos.X()+rSize.Width()-1, rPos.Y()+rSize.Height()-1 ), Point( rPos.X()+rSize.Width()-1, nTop ) );
212cdf0e10cSrcweir         }
213cdf0e10cSrcweir     }
214cdf0e10cSrcweir 
215cdf0e10cSrcweir     MetricVector* pVector = bLayout ? &mpControlData->mpLayoutData->m_aUnicodeBoundRects : NULL;
216cdf0e10cSrcweir     String* pDisplayText = bLayout ? &mpControlData->mpLayoutData->m_aDisplayText : NULL;
217cdf0e10cSrcweir     DrawControlText( *pDev, aRect, aText, nTextStyle, pVector, pDisplayText );
218cdf0e10cSrcweir }
219cdf0e10cSrcweir 
220cdf0e10cSrcweir // -----------------------------------------------------------------------
221cdf0e10cSrcweir 
FillLayoutData() const222cdf0e10cSrcweir void GroupBox::FillLayoutData() const
223cdf0e10cSrcweir {
224cdf0e10cSrcweir     mpControlData->mpLayoutData = new vcl::ControlLayoutData();
225cdf0e10cSrcweir     const_cast<GroupBox*>(this)->	ImplDraw( const_cast<GroupBox*>(this), 0, Point(), GetOutputSizePixel(), true );
226cdf0e10cSrcweir }
227cdf0e10cSrcweir 
228cdf0e10cSrcweir // -----------------------------------------------------------------------
229cdf0e10cSrcweir 
Paint(const Rectangle &)230cdf0e10cSrcweir void GroupBox::Paint( const Rectangle& )
231cdf0e10cSrcweir {
232cdf0e10cSrcweir 	ImplDraw( this, 0, Point(), GetOutputSizePixel() );
233cdf0e10cSrcweir }
234cdf0e10cSrcweir 
235cdf0e10cSrcweir // -----------------------------------------------------------------------
236cdf0e10cSrcweir 
Draw(OutputDevice * pDev,const Point & rPos,const Size & rSize,sal_uLong nFlags)237cdf0e10cSrcweir void GroupBox::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize,
238cdf0e10cSrcweir 					 sal_uLong nFlags )
239cdf0e10cSrcweir {
240cdf0e10cSrcweir 	Point		aPos  = pDev->LogicToPixel( rPos );
241cdf0e10cSrcweir 	Size		aSize = pDev->LogicToPixel( rSize );
242cdf0e10cSrcweir 	Font		aFont = GetDrawPixelFont( pDev );
243cdf0e10cSrcweir 
244cdf0e10cSrcweir 	pDev->Push();
245cdf0e10cSrcweir 	pDev->SetMapMode();
246cdf0e10cSrcweir 	pDev->SetFont( aFont );
247cdf0e10cSrcweir 	if ( nFlags & WINDOW_DRAW_MONO )
248cdf0e10cSrcweir 		pDev->SetTextColor( Color( COL_BLACK ) );
249cdf0e10cSrcweir 	else
250cdf0e10cSrcweir 		pDev->SetTextColor( GetTextColor() );
251cdf0e10cSrcweir 	pDev->SetTextFillColor();
252cdf0e10cSrcweir 
253cdf0e10cSrcweir 	ImplDraw( pDev, nFlags, aPos, aSize );
254cdf0e10cSrcweir 	pDev->Pop();
255cdf0e10cSrcweir }
256cdf0e10cSrcweir 
257cdf0e10cSrcweir // -----------------------------------------------------------------------
258cdf0e10cSrcweir 
Resize()259cdf0e10cSrcweir void GroupBox::Resize()
260cdf0e10cSrcweir {
261cdf0e10cSrcweir     Control::Resize();
262cdf0e10cSrcweir 	Invalidate();
263cdf0e10cSrcweir }
264cdf0e10cSrcweir 
265cdf0e10cSrcweir // -----------------------------------------------------------------------
266cdf0e10cSrcweir 
StateChanged(StateChangedType nType)267cdf0e10cSrcweir void GroupBox::StateChanged( StateChangedType nType )
268cdf0e10cSrcweir {
269cdf0e10cSrcweir 	Control::StateChanged( nType );
270cdf0e10cSrcweir 
271cdf0e10cSrcweir 	if ( (nType == STATE_CHANGE_ENABLE) ||
272cdf0e10cSrcweir 		 (nType == STATE_CHANGE_TEXT) ||
273cdf0e10cSrcweir 		 (nType == STATE_CHANGE_UPDATEMODE) )
274cdf0e10cSrcweir 	{
275cdf0e10cSrcweir 		if ( IsUpdateMode() )
276cdf0e10cSrcweir 			Invalidate();
277cdf0e10cSrcweir 	}
278cdf0e10cSrcweir 	else if ( nType == STATE_CHANGE_STYLE )
279cdf0e10cSrcweir 	{
280cdf0e10cSrcweir 		SetStyle( ImplInitStyle( GetStyle() ) );
281cdf0e10cSrcweir 		if ( (GetPrevStyle() & GROUP_VIEW_STYLE) !=
282cdf0e10cSrcweir 			 (GetStyle() & GROUP_VIEW_STYLE) )
283cdf0e10cSrcweir 			Invalidate();
284cdf0e10cSrcweir 	}
285cdf0e10cSrcweir 	else if ( (nType == STATE_CHANGE_ZOOM)	||
286cdf0e10cSrcweir 			  (nType == STATE_CHANGE_CONTROLFONT) )
287cdf0e10cSrcweir 	{
288cdf0e10cSrcweir 		ImplInitSettings( sal_True, sal_False, sal_False );
289cdf0e10cSrcweir 		Invalidate();
290cdf0e10cSrcweir 	}
291cdf0e10cSrcweir 	else if ( nType == STATE_CHANGE_CONTROLFOREGROUND )
292cdf0e10cSrcweir 	{
293cdf0e10cSrcweir 		ImplInitSettings( sal_False, sal_True, sal_False );
294cdf0e10cSrcweir 		Invalidate();
295cdf0e10cSrcweir 	}
296cdf0e10cSrcweir 	else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
297cdf0e10cSrcweir 	{
298cdf0e10cSrcweir 		ImplInitSettings( sal_False, sal_False, sal_True );
299cdf0e10cSrcweir 		Invalidate();
300cdf0e10cSrcweir 	}
301cdf0e10cSrcweir }
302cdf0e10cSrcweir 
303cdf0e10cSrcweir // -----------------------------------------------------------------------
304cdf0e10cSrcweir 
DataChanged(const DataChangedEvent & rDCEvt)305cdf0e10cSrcweir void GroupBox::DataChanged( const DataChangedEvent& rDCEvt )
306cdf0e10cSrcweir {
307cdf0e10cSrcweir 	Control::DataChanged( rDCEvt );
308cdf0e10cSrcweir 
309cdf0e10cSrcweir 	if ( (rDCEvt.GetType() == DATACHANGED_FONTS) ||
310cdf0e10cSrcweir 		 (rDCEvt.GetType() == DATACHANGED_FONTSUBSTITUTION) ||
311cdf0e10cSrcweir 		 ((rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
312cdf0e10cSrcweir 		  (rDCEvt.GetFlags() & SETTINGS_STYLE)) )
313cdf0e10cSrcweir 	{
314cdf0e10cSrcweir 		ImplInitSettings( sal_True, sal_True, sal_True );
315cdf0e10cSrcweir 		Invalidate();
316cdf0e10cSrcweir 	}
317cdf0e10cSrcweir }
318cdf0e10cSrcweir 
319