1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: group.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_vcl.hxx"
33 #include <vcl/event.hxx>
34 #include <vcl/group.hxx>
35 #include <vcl/controllayout.hxx>
43 // =======================================================================
45 #define GROUP_BORDER 12
46 #define GROUP_TEXT_BORDER 2
48 #define GROUP_VIEW_STYLE (WB_3DLOOK | WB_NOLABEL)
50 // =======================================================================
52 void GroupBox::ImplInit( Window
* pParent
, WinBits nStyle
)
54 nStyle
= ImplInitStyle( nStyle
);
55 Control::ImplInit( pParent
, nStyle
, NULL
);
56 SetMouseTransparent( TRUE
);
57 ImplInitSettings( TRUE
, TRUE
, TRUE
);
60 // -----------------------------------------------------------------------
62 WinBits
GroupBox::ImplInitStyle( WinBits nStyle
)
64 if ( !(nStyle
& WB_NOGROUP
) )
69 // -----------------------------------------------------------------------
71 void GroupBox::ImplInitSettings( BOOL bFont
,
72 BOOL bForeground
, BOOL bBackground
)
74 const StyleSettings
& rStyleSettings
= GetSettings().GetStyleSettings();
78 Font aFont
= rStyleSettings
.GetGroupFont();
79 if ( IsControlFont() )
80 aFont
.Merge( GetControlFont() );
81 SetZoomedPointFont( aFont
);
84 if ( bForeground
|| bFont
)
87 if ( IsControlForeground() )
88 aColor
= GetControlForeground();
90 aColor
= rStyleSettings
.GetGroupTextColor();
91 SetTextColor( aColor
);
97 Window
* pParent
= GetParent();
98 if ( (pParent
->IsChildTransparentModeEnabled() ||
99 !(pParent
->GetStyle() & WB_CLIPCHILDREN
) ) &&
100 !IsControlBackground() )
102 EnableChildTransparentMode( TRUE
);
103 SetParentClipMode( PARENTCLIPMODE_NOCLIP
);
104 SetPaintTransparent( TRUE
);
109 EnableChildTransparentMode( FALSE
);
110 SetParentClipMode( 0 );
111 SetPaintTransparent( FALSE
);
113 if ( IsControlBackground() )
114 SetBackground( GetControlBackground() );
116 SetBackground( pParent
->GetBackground() );
121 // -----------------------------------------------------------------------
123 GroupBox::GroupBox( Window
* pParent
, WinBits nStyle
) :
124 Control( WINDOW_GROUPBOX
)
126 ImplInit( pParent
, nStyle
);
129 // -----------------------------------------------------------------------
131 GroupBox::GroupBox( Window
* pParent
, const ResId
& rResId
) :
132 Control( WINDOW_GROUPBOX
)
134 rResId
.SetRT( RSC_GROUPBOX
);
135 WinBits nStyle
= ImplInitRes( rResId
);
136 ImplInit( pParent
, nStyle
);
137 ImplLoadRes( rResId
);
139 if ( !(nStyle
& WB_HIDE
) )
143 // -----------------------------------------------------------------------
145 void GroupBox::ImplDraw( OutputDevice
* pDev
, ULONG nDrawFlags
,
146 const Point
& rPos
, const Size
& rSize
, bool bLayout
)
150 const StyleSettings
& rStyleSettings
= GetSettings().GetStyleSettings();
151 XubString
aText( GetText() );
152 Rectangle
aRect( rPos
, rSize
);
153 USHORT nTextStyle
= TEXT_DRAW_LEFT
| TEXT_DRAW_TOP
| TEXT_DRAW_ENDELLIPSIS
| TEXT_DRAW_MNEMONIC
;
155 if ( GetStyle() & WB_NOLABEL
)
156 nTextStyle
&= ~TEXT_DRAW_MNEMONIC
;
157 if ( nDrawFlags
& WINDOW_DRAW_NOMNEMONIC
)
159 if ( nTextStyle
& TEXT_DRAW_MNEMONIC
)
161 aText
= GetNonMnemonicString( aText
);
162 nTextStyle
&= ~TEXT_DRAW_MNEMONIC
;
165 if ( !(nDrawFlags
& WINDOW_DRAW_NODISABLE
) )
168 nTextStyle
|= TEXT_DRAW_DISABLE
;
170 if ( (nDrawFlags
& WINDOW_DRAW_MONO
) ||
171 (rStyleSettings
.GetOptions() & STYLE_OPTION_MONO
) )
173 nTextStyle
|= TEXT_DRAW_MONO
;
174 nDrawFlags
|= WINDOW_DRAW_MONO
;
184 aRect
.Left() += GROUP_BORDER
;
185 aRect
.Right() -= GROUP_BORDER
;
186 aRect
= pDev
->GetTextRect( aRect
, aText
, nTextStyle
);
188 nTop
+= aRect
.GetHeight() / 2;
189 nTextOff
= GROUP_TEXT_BORDER
;
194 if ( nDrawFlags
& WINDOW_DRAW_MONO
)
195 pDev
->SetLineColor( Color( COL_BLACK
) );
197 pDev
->SetLineColor( rStyleSettings
.GetShadowColor() );
200 pDev
->DrawLine( Point( rPos
.X(), nTop
), Point( rPos
.X()+rSize
.Width()-2, nTop
) );
203 pDev
->DrawLine( Point( rPos
.X(), nTop
), Point( aRect
.Left()-nTextOff
, nTop
) );
204 pDev
->DrawLine( Point( aRect
.Right()+nTextOff
, nTop
), Point( rPos
.X()+rSize
.Width()-2, nTop
) );
206 pDev
->DrawLine( Point( rPos
.X(), nTop
), Point( rPos
.X(), rPos
.Y()+rSize
.Height()-2 ) );
207 pDev
->DrawLine( Point( rPos
.X(), rPos
.Y()+rSize
.Height()-2 ), Point( rPos
.X()+rSize
.Width()-2, rPos
.Y()+rSize
.Height()-2 ) );
208 pDev
->DrawLine( Point( rPos
.X()+rSize
.Width()-2, rPos
.Y()+rSize
.Height()-2 ), Point( rPos
.X()+rSize
.Width()-2, nTop
) );
210 bool bIsPrinter
= OUTDEV_PRINTER
== pDev
->GetOutDevType();
211 // if we're drawing onto a printer, spare the 3D effect
212 // #i46986# / 2005-04-13 / frank.schoenheit@sun.com
214 if ( !bIsPrinter
&& !(nDrawFlags
& WINDOW_DRAW_MONO
) )
216 pDev
->SetLineColor( rStyleSettings
.GetLightColor() );
218 pDev
->DrawLine( Point( rPos
.X()+1, nTop
+1 ), Point( rPos
.X()+rSize
.Width()-3, nTop
+1 ) );
221 pDev
->DrawLine( Point( rPos
.X()+1, nTop
+1 ), Point( aRect
.Left()-nTextOff
, nTop
+1 ) );
222 pDev
->DrawLine( Point( aRect
.Right()+nTextOff
, nTop
+1 ), Point( rPos
.X()+rSize
.Width()-3, nTop
+1 ) );
224 pDev
->DrawLine( Point( rPos
.X()+1, nTop
+1 ), Point( rPos
.X()+1, rPos
.Y()+rSize
.Height()-3 ) );
225 pDev
->DrawLine( Point( rPos
.X(), rPos
.Y()+rSize
.Height()-1 ), Point( rPos
.X()+rSize
.Width()-1, rPos
.Y()+rSize
.Height()-1 ) );
226 pDev
->DrawLine( Point( rPos
.X()+rSize
.Width()-1, rPos
.Y()+rSize
.Height()-1 ), Point( rPos
.X()+rSize
.Width()-1, nTop
) );
230 MetricVector
* pVector
= bLayout
? &mpLayoutData
->m_aUnicodeBoundRects
: NULL
;
231 String
* pDisplayText
= bLayout
? &mpLayoutData
->m_aDisplayText
: NULL
;
232 pDev
->DrawText( aRect
, aText
, nTextStyle
, pVector
, pDisplayText
);
235 // -----------------------------------------------------------------------
237 void GroupBox::FillLayoutData() const
239 mpLayoutData
= new vcl::ControlLayoutData();
240 const_cast<GroupBox
*>(this)-> ImplDraw( const_cast<GroupBox
*>(this), 0, Point(), GetOutputSizePixel(), true );
243 // -----------------------------------------------------------------------
245 void GroupBox::Paint( const Rectangle
& )
247 ImplDraw( this, 0, Point(), GetOutputSizePixel() );
250 // -----------------------------------------------------------------------
252 void GroupBox::Draw( OutputDevice
* pDev
, const Point
& rPos
, const Size
& rSize
,
255 Point aPos
= pDev
->LogicToPixel( rPos
);
256 Size aSize
= pDev
->LogicToPixel( rSize
);
257 Font aFont
= GetDrawPixelFont( pDev
);
261 pDev
->SetFont( aFont
);
262 if ( nFlags
& WINDOW_DRAW_MONO
)
263 pDev
->SetTextColor( Color( COL_BLACK
) );
265 pDev
->SetTextColor( GetTextColor() );
266 pDev
->SetTextFillColor();
268 ImplDraw( pDev
, nFlags
, aPos
, aSize
);
272 // -----------------------------------------------------------------------
274 void GroupBox::Resize()
280 // -----------------------------------------------------------------------
282 void GroupBox::StateChanged( StateChangedType nType
)
284 Control::StateChanged( nType
);
286 if ( (nType
== STATE_CHANGE_ENABLE
) ||
287 (nType
== STATE_CHANGE_TEXT
) ||
288 (nType
== STATE_CHANGE_UPDATEMODE
) )
290 if ( IsUpdateMode() )
293 else if ( nType
== STATE_CHANGE_STYLE
)
295 SetStyle( ImplInitStyle( GetStyle() ) );
296 if ( (GetPrevStyle() & GROUP_VIEW_STYLE
) !=
297 (GetStyle() & GROUP_VIEW_STYLE
) )
300 else if ( (nType
== STATE_CHANGE_ZOOM
) ||
301 (nType
== STATE_CHANGE_CONTROLFONT
) )
303 ImplInitSettings( TRUE
, FALSE
, FALSE
);
306 else if ( nType
== STATE_CHANGE_CONTROLFOREGROUND
)
308 ImplInitSettings( FALSE
, TRUE
, FALSE
);
311 else if ( nType
== STATE_CHANGE_CONTROLBACKGROUND
)
313 ImplInitSettings( FALSE
, FALSE
, TRUE
);
318 // -----------------------------------------------------------------------
320 void GroupBox::DataChanged( const DataChangedEvent
& rDCEvt
)
322 Control::DataChanged( rDCEvt
);
324 if ( (rDCEvt
.GetType() == DATACHANGED_FONTS
) ||
325 (rDCEvt
.GetType() == DATACHANGED_FONTSUBSTITUTION
) ||
326 ((rDCEvt
.GetType() == DATACHANGED_SETTINGS
) &&
327 (rDCEvt
.GetFlags() & SETTINGS_STYLE
)) )
329 ImplInitSettings( TRUE
, TRUE
, TRUE
);