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