1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
20 #include <vcl/event.hxx>
21 #include <vcl/toolkit/group.hxx>
22 #include <vcl/settings.hxx>
24 #include <controldata.hxx>
26 #define GROUP_BORDER 12
27 #define GROUP_TEXT_BORDER 2
29 #define GROUP_VIEW_STYLE (WB_3DLOOK | WB_NOLABEL)
31 void GroupBox::ImplInit( vcl::Window
* pParent
, WinBits nStyle
)
33 nStyle
= ImplInitStyle( nStyle
);
34 Control::ImplInit( pParent
, nStyle
, nullptr );
35 SetMouseTransparent( true );
36 ImplInitSettings( true );
39 WinBits
GroupBox::ImplInitStyle( WinBits nStyle
)
41 if ( !(nStyle
& WB_NOGROUP
) )
46 const vcl::Font
& GroupBox::GetCanonicalFont( const StyleSettings
& _rStyle
) const
48 return _rStyle
.GetGroupFont();
51 const Color
& GroupBox::GetCanonicalTextColor( const StyleSettings
& _rStyle
) const
53 return _rStyle
.GetGroupTextColor();
56 void GroupBox::ImplInitSettings( bool bBackground
)
58 Control::ImplInitSettings();
62 vcl::Window
* pParent
= GetParent();
63 if ( (pParent
->IsChildTransparentModeEnabled() ||
64 !(pParent
->GetStyle() & WB_CLIPCHILDREN
) ) &&
65 !IsControlBackground() )
67 EnableChildTransparentMode();
68 SetParentClipMode( ParentClipMode::NoClip
);
69 SetPaintTransparent( true );
74 EnableChildTransparentMode( false );
76 SetPaintTransparent( false );
78 if ( IsControlBackground() )
79 SetBackground( GetControlBackground() );
81 SetBackground( pParent
->GetBackground() );
86 GroupBox::GroupBox( vcl::Window
* pParent
, WinBits nStyle
) :
87 Control( WindowType::GROUPBOX
)
89 ImplInit( pParent
, nStyle
);
92 void GroupBox::ImplDraw( OutputDevice
* pDev
, DrawFlags nDrawFlags
,
93 const Point
& rPos
, const Size
& rSize
, bool bLayout
)
97 const StyleSettings
& rStyleSettings
= GetSettings().GetStyleSettings();
98 OUString
aText( GetText() );
99 tools::Rectangle
aRect( rPos
, rSize
);
100 DrawTextFlags nTextStyle
= DrawTextFlags::Left
| DrawTextFlags::Top
| DrawTextFlags::EndEllipsis
| DrawTextFlags::Mnemonic
;
102 if ( GetStyle() & WB_NOLABEL
)
103 nTextStyle
&= ~DrawTextFlags::Mnemonic
;
105 nTextStyle
|= DrawTextFlags::Disable
;
106 if ( (nDrawFlags
& DrawFlags::Mono
) ||
107 (rStyleSettings
.GetOptions() & StyleSettingsOptions::Mono
) )
109 nTextStyle
|= DrawTextFlags::Mono
;
110 nDrawFlags
|= DrawFlags::Mono
;
120 aRect
.AdjustLeft(GROUP_BORDER
);
121 aRect
.AdjustRight( -(GROUP_BORDER
) );
122 aRect
= pDev
->GetTextRect( aRect
, aText
, nTextStyle
);
124 nTop
+= aRect
.GetHeight() / 2;
125 nTextOff
= GROUP_TEXT_BORDER
;
130 if ( nDrawFlags
& DrawFlags::Mono
)
131 pDev
->SetLineColor( COL_BLACK
);
133 pDev
->SetLineColor( rStyleSettings
.GetShadowColor() );
136 pDev
->DrawLine( Point( rPos
.X(), nTop
), Point( rPos
.X()+rSize
.Width()-2, nTop
) );
139 pDev
->DrawLine( Point( rPos
.X(), nTop
), Point( aRect
.Left()-nTextOff
, nTop
) );
140 pDev
->DrawLine( Point( aRect
.Right()+nTextOff
, nTop
), Point( rPos
.X()+rSize
.Width()-2, nTop
) );
142 pDev
->DrawLine( Point( rPos
.X(), nTop
), Point( rPos
.X(), rPos
.Y()+rSize
.Height()-2 ) );
143 pDev
->DrawLine( Point( rPos
.X(), rPos
.Y()+rSize
.Height()-2 ), Point( rPos
.X()+rSize
.Width()-2, rPos
.Y()+rSize
.Height()-2 ) );
144 pDev
->DrawLine( Point( rPos
.X()+rSize
.Width()-2, rPos
.Y()+rSize
.Height()-2 ), Point( rPos
.X()+rSize
.Width()-2, nTop
) );
146 bool bIsPrinter
= OUTDEV_PRINTER
== pDev
->GetOutDevType();
147 // if we're drawing onto a printer, spare the 3D effect #i46986#
149 if ( !bIsPrinter
&& !(nDrawFlags
& DrawFlags::Mono
) )
151 pDev
->SetLineColor( rStyleSettings
.GetLightColor() );
153 pDev
->DrawLine( Point( rPos
.X()+1, nTop
+1 ), Point( rPos
.X()+rSize
.Width()-3, nTop
+1 ) );
156 pDev
->DrawLine( Point( rPos
.X()+1, nTop
+1 ), Point( aRect
.Left()-nTextOff
, nTop
+1 ) );
157 pDev
->DrawLine( Point( aRect
.Right()+nTextOff
, nTop
+1 ), Point( rPos
.X()+rSize
.Width()-3, nTop
+1 ) );
159 pDev
->DrawLine( Point( rPos
.X()+1, nTop
+1 ), Point( rPos
.X()+1, rPos
.Y()+rSize
.Height()-3 ) );
160 pDev
->DrawLine( Point( rPos
.X(), rPos
.Y()+rSize
.Height()-1 ), Point( rPos
.X()+rSize
.Width()-1, rPos
.Y()+rSize
.Height()-1 ) );
161 pDev
->DrawLine( Point( rPos
.X()+rSize
.Width()-1, rPos
.Y()+rSize
.Height()-1 ), Point( rPos
.X()+rSize
.Width()-1, nTop
) );
165 MetricVector
* pVector
= bLayout
? &mpControlData
->mpLayoutData
->m_aUnicodeBoundRects
: nullptr;
166 OUString
* pDisplayText
= bLayout
? &mpControlData
->mpLayoutData
->m_aDisplayText
: nullptr;
167 DrawControlText( *pDev
, aRect
, aText
, nTextStyle
, pVector
, pDisplayText
);
170 void GroupBox::FillLayoutData() const
172 mpControlData
->mpLayoutData
.reset( new vcl::ControlLayoutData
);
173 const_cast<GroupBox
*>(this)->ImplDraw( const_cast<GroupBox
*>(this), DrawFlags::NONE
, Point(), GetOutputSizePixel(), true );
176 void GroupBox::Paint( vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& )
178 ImplDraw(&rRenderContext
, DrawFlags::NONE
, Point(), GetOutputSizePixel());
181 void GroupBox::Draw( OutputDevice
* pDev
, const Point
& rPos
, const Size
& rSize
,
184 Point aPos
= pDev
->LogicToPixel( rPos
);
185 Size aSize
= pDev
->LogicToPixel( rSize
);
186 vcl::Font aFont
= GetDrawPixelFont( pDev
);
190 pDev
->SetFont( aFont
);
191 if ( nFlags
& DrawFlags::Mono
)
192 pDev
->SetTextColor( COL_BLACK
);
194 pDev
->SetTextColor( GetTextColor() );
195 pDev
->SetTextFillColor();
197 ImplDraw( pDev
, nFlags
, aPos
, aSize
);
201 void GroupBox::Resize()
207 void GroupBox::StateChanged( StateChangedType nType
)
209 Control::StateChanged( nType
);
211 if ( (nType
== StateChangedType::Enable
) ||
212 (nType
== StateChangedType::Text
) ||
213 (nType
== StateChangedType::UpdateMode
) )
215 if ( IsUpdateMode() )
218 else if ( nType
== StateChangedType::Style
)
220 SetStyle( ImplInitStyle( GetStyle() ) );
221 if ( (GetPrevStyle() & GROUP_VIEW_STYLE
) !=
222 (GetStyle() & GROUP_VIEW_STYLE
) )
225 else if ( (nType
== StateChangedType::Zoom
) ||
226 (nType
== StateChangedType::ControlFont
) )
228 ImplInitSettings( false );
231 else if ( nType
== StateChangedType::ControlForeground
)
233 ImplInitSettings( false );
236 else if ( nType
== StateChangedType::ControlBackground
)
238 ImplInitSettings( true );
243 void GroupBox::DataChanged( const DataChangedEvent
& rDCEvt
)
245 Control::DataChanged( rDCEvt
);
247 if ( (rDCEvt
.GetType() == DataChangedEventType::FONTS
) ||
248 (rDCEvt
.GetType() == DataChangedEventType::FONTSUBSTITUTION
) ||
249 ((rDCEvt
.GetType() == DataChangedEventType::SETTINGS
) &&
250 (rDCEvt
.GetFlags() & AllSettingsFlags::STYLE
)) )
252 ImplInitSettings( true );
257 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */