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 #define GROUP_BORDER 12
25 #define GROUP_TEXT_BORDER 2
27 #define GROUP_VIEW_STYLE (WB_3DLOOK | WB_NOLABEL)
29 void GroupBox::ImplInit( vcl::Window
* pParent
, WinBits nStyle
)
31 nStyle
= ImplInitStyle( nStyle
);
32 Control::ImplInit( pParent
, nStyle
, nullptr );
33 SetMouseTransparent( true );
34 ImplInitSettings( true );
37 WinBits
GroupBox::ImplInitStyle( WinBits nStyle
)
39 if ( !(nStyle
& WB_NOGROUP
) )
44 const vcl::Font
& GroupBox::GetCanonicalFont( const StyleSettings
& _rStyle
) const
46 return _rStyle
.GetGroupFont();
49 const Color
& GroupBox::GetCanonicalTextColor( const StyleSettings
& _rStyle
) const
51 return _rStyle
.GetGroupTextColor();
54 void GroupBox::ImplInitSettings( bool bBackground
)
56 Control::ImplInitSettings();
61 vcl::Window
* pParent
= GetParent();
62 if (pParent
->IsChildTransparentModeEnabled() ||
63 !(pParent
->GetStyle() & WB_CLIPCHILDREN
) ||
64 !IsControlBackground())
66 EnableChildTransparentMode();
67 SetParentClipMode( ParentClipMode::NoClip
);
68 SetPaintTransparent( true );
73 EnableChildTransparentMode( false );
75 SetPaintTransparent( false );
77 if ( IsControlBackground() )
78 SetBackground( GetControlBackground() );
80 SetBackground( pParent
->GetBackground() );
84 GroupBox::GroupBox( vcl::Window
* pParent
, WinBits nStyle
) :
85 Control( WindowType::GROUPBOX
)
87 ImplInit( pParent
, nStyle
);
90 void GroupBox::ImplDraw( OutputDevice
* pDev
, SystemTextColorFlags nSystemTextColorFlags
,
91 const Point
& rPos
, const Size
& rSize
, bool bLayout
)
95 const StyleSettings
& rStyleSettings
= GetSettings().GetStyleSettings();
96 OUString
aText( GetText() );
97 tools::Rectangle
aRect( rPos
, rSize
);
98 DrawTextFlags nTextStyle
= DrawTextFlags::Left
| DrawTextFlags::Top
| DrawTextFlags::EndEllipsis
| DrawTextFlags::Mnemonic
;
100 if ( GetStyle() & WB_NOLABEL
)
101 nTextStyle
&= ~DrawTextFlags::Mnemonic
;
103 nTextStyle
|= DrawTextFlags::Disable
;
104 if ( (nSystemTextColorFlags
& SystemTextColorFlags::Mono
) ||
105 (rStyleSettings
.GetOptions() & StyleSettingsOptions::Mono
) )
107 nTextStyle
|= DrawTextFlags::Mono
;
108 nSystemTextColorFlags
|= SystemTextColorFlags::Mono
;
118 aRect
.AdjustLeft(GROUP_BORDER
);
119 aRect
.AdjustRight( -(GROUP_BORDER
) );
120 aRect
= pDev
->GetTextRect( aRect
, aText
, nTextStyle
);
122 nTop
+= aRect
.GetHeight() / 2;
123 nTextOff
= GROUP_TEXT_BORDER
;
128 if ( nSystemTextColorFlags
& SystemTextColorFlags::Mono
)
129 pDev
->SetLineColor( COL_BLACK
);
131 pDev
->SetLineColor( rStyleSettings
.GetShadowColor() );
134 pDev
->DrawLine( Point( rPos
.X(), nTop
), Point( rPos
.X()+rSize
.Width()-2, nTop
) );
137 pDev
->DrawLine( Point( rPos
.X(), nTop
), Point( aRect
.Left()-nTextOff
, nTop
) );
138 pDev
->DrawLine( Point( aRect
.Right()+nTextOff
, nTop
), Point( rPos
.X()+rSize
.Width()-2, nTop
) );
140 pDev
->DrawLine( Point( rPos
.X(), nTop
), Point( rPos
.X(), rPos
.Y()+rSize
.Height()-2 ) );
141 pDev
->DrawLine( Point( rPos
.X(), rPos
.Y()+rSize
.Height()-2 ), Point( rPos
.X()+rSize
.Width()-2, rPos
.Y()+rSize
.Height()-2 ) );
142 pDev
->DrawLine( Point( rPos
.X()+rSize
.Width()-2, rPos
.Y()+rSize
.Height()-2 ), Point( rPos
.X()+rSize
.Width()-2, nTop
) );
144 bool bIsPrinter
= OUTDEV_PRINTER
== pDev
->GetOutDevType();
145 // if we're drawing onto a printer, spare the 3D effect #i46986#
147 if ( !bIsPrinter
&& !(nSystemTextColorFlags
& SystemTextColorFlags::Mono
) )
149 pDev
->SetLineColor( rStyleSettings
.GetLightColor() );
151 pDev
->DrawLine( Point( rPos
.X()+1, nTop
+1 ), Point( rPos
.X()+rSize
.Width()-3, nTop
+1 ) );
154 pDev
->DrawLine( Point( rPos
.X()+1, nTop
+1 ), Point( aRect
.Left()-nTextOff
, nTop
+1 ) );
155 pDev
->DrawLine( Point( aRect
.Right()+nTextOff
, nTop
+1 ), Point( rPos
.X()+rSize
.Width()-3, nTop
+1 ) );
157 pDev
->DrawLine( Point( rPos
.X()+1, nTop
+1 ), Point( rPos
.X()+1, rPos
.Y()+rSize
.Height()-3 ) );
158 pDev
->DrawLine( Point( rPos
.X(), rPos
.Y()+rSize
.Height()-1 ), Point( rPos
.X()+rSize
.Width()-1, rPos
.Y()+rSize
.Height()-1 ) );
159 pDev
->DrawLine( Point( rPos
.X()+rSize
.Width()-1, rPos
.Y()+rSize
.Height()-1 ), Point( rPos
.X()+rSize
.Width()-1, nTop
) );
163 std::vector
< tools::Rectangle
>* pVector
= bLayout
? &mxLayoutData
->m_aUnicodeBoundRects
: nullptr;
164 OUString
* pDisplayText
= bLayout
? &mxLayoutData
->m_aDisplayText
: nullptr;
165 DrawControlText( *pDev
, aRect
, aText
, nTextStyle
, pVector
, pDisplayText
);
168 void GroupBox::FillLayoutData() const
170 mxLayoutData
.emplace();
171 const_cast<GroupBox
*>(this)->ImplDraw( const_cast<GroupBox
*>(this)->GetOutDev(), SystemTextColorFlags::NONE
, Point(), GetOutputSizePixel(), true );
174 void GroupBox::Paint( vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& )
176 ImplDraw(&rRenderContext
, SystemTextColorFlags::NONE
, Point(), GetOutputSizePixel());
179 void GroupBox::Draw( OutputDevice
* pDev
, const Point
& rPos
,
180 SystemTextColorFlags nFlags
)
182 Point aPos
= pDev
->LogicToPixel( rPos
);
183 Size aSize
= GetSizePixel();
184 vcl::Font aFont
= GetDrawPixelFont( pDev
);
188 pDev
->SetFont( aFont
);
189 if ( nFlags
& SystemTextColorFlags::Mono
)
190 pDev
->SetTextColor( COL_BLACK
);
192 pDev
->SetTextColor( GetTextColor() );
193 pDev
->SetTextFillColor();
195 ImplDraw( pDev
, nFlags
, aPos
, aSize
);
199 void GroupBox::Resize()
205 void GroupBox::StateChanged( StateChangedType nType
)
207 Control::StateChanged( nType
);
209 if ( (nType
== StateChangedType::Enable
) ||
210 (nType
== StateChangedType::Text
) ||
211 (nType
== StateChangedType::UpdateMode
) )
213 if ( IsUpdateMode() )
216 else if ( nType
== StateChangedType::Style
)
218 SetStyle( ImplInitStyle( GetStyle() ) );
219 if ( (GetPrevStyle() & GROUP_VIEW_STYLE
) !=
220 (GetStyle() & GROUP_VIEW_STYLE
) )
223 else if ( (nType
== StateChangedType::Zoom
) ||
224 (nType
== StateChangedType::ControlFont
) )
226 ImplInitSettings( false );
229 else if ( nType
== StateChangedType::ControlForeground
)
231 ImplInitSettings( false );
234 else if ( nType
== StateChangedType::ControlBackground
)
236 ImplInitSettings( true );
241 void GroupBox::DataChanged( const DataChangedEvent
& rDCEvt
)
243 Control::DataChanged( rDCEvt
);
245 if ( (rDCEvt
.GetType() == DataChangedEventType::FONTS
) ||
246 (rDCEvt
.GetType() == DataChangedEventType::FONTSUBSTITUTION
) ||
247 ((rDCEvt
.GetType() == DataChangedEventType::SETTINGS
) &&
248 (rDCEvt
.GetFlags() & AllSettingsFlags::STYLE
)) )
250 ImplInitSettings( true );
255 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */