bump product version to 6.4.0.3
[LibreOffice.git] / vcl / source / toolkit / group.cxx
blob0743518f8ba1cdaf75e2e73a73316c358ada2578
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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) )
42 nStyle |= WB_GROUP;
43 return nStyle;
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();
60 if ( bBackground )
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 );
70 SetBackground();
72 else
74 EnableChildTransparentMode( false );
75 SetParentClipMode();
76 SetPaintTransparent( false );
78 if ( IsControlBackground() )
79 SetBackground( GetControlBackground() );
80 else
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 )
95 long nTop;
96 long nTextOff;
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;
104 if ( !IsEnabled() )
105 nTextStyle |= DrawTextFlags::Disable;
106 if ( (nDrawFlags & DrawFlags::Mono) ||
107 (rStyleSettings.GetOptions() & StyleSettingsOptions::Mono) )
109 nTextStyle |= DrawTextFlags::Mono;
110 nDrawFlags |= DrawFlags::Mono;
113 if (aText.isEmpty())
115 nTop = rPos.Y();
116 nTextOff = 0;
118 else
120 aRect.AdjustLeft(GROUP_BORDER );
121 aRect.AdjustRight( -(GROUP_BORDER) );
122 aRect = pDev->GetTextRect( aRect, aText, nTextStyle );
123 nTop = rPos.Y();
124 nTop += aRect.GetHeight() / 2;
125 nTextOff = GROUP_TEXT_BORDER;
128 if( ! bLayout )
130 if ( nDrawFlags & DrawFlags::Mono )
131 pDev->SetLineColor( COL_BLACK );
132 else
133 pDev->SetLineColor( rStyleSettings.GetShadowColor() );
135 if (aText.isEmpty())
136 pDev->DrawLine( Point( rPos.X(), nTop ), Point( rPos.X()+rSize.Width()-2, nTop ) );
137 else
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() );
152 if (aText.isEmpty())
153 pDev->DrawLine( Point( rPos.X()+1, nTop+1 ), Point( rPos.X()+rSize.Width()-3, nTop+1 ) );
154 else
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,
182 DrawFlags nFlags )
184 Point aPos = pDev->LogicToPixel( rPos );
185 Size aSize = pDev->LogicToPixel( rSize );
186 vcl::Font aFont = GetDrawPixelFont( pDev );
188 pDev->Push();
189 pDev->SetMapMode();
190 pDev->SetFont( aFont );
191 if ( nFlags & DrawFlags::Mono )
192 pDev->SetTextColor( COL_BLACK );
193 else
194 pDev->SetTextColor( GetTextColor() );
195 pDev->SetTextFillColor();
197 ImplDraw( pDev, nFlags, aPos, aSize );
198 pDev->Pop();
201 void GroupBox::Resize()
203 Control::Resize();
204 Invalidate();
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() )
216 Invalidate();
218 else if ( nType == StateChangedType::Style )
220 SetStyle( ImplInitStyle( GetStyle() ) );
221 if ( (GetPrevStyle() & GROUP_VIEW_STYLE) !=
222 (GetStyle() & GROUP_VIEW_STYLE) )
223 Invalidate();
225 else if ( (nType == StateChangedType::Zoom) ||
226 (nType == StateChangedType::ControlFont) )
228 ImplInitSettings( false );
229 Invalidate();
231 else if ( nType == StateChangedType::ControlForeground )
233 ImplInitSettings( false );
234 Invalidate();
236 else if ( nType == StateChangedType::ControlBackground )
238 ImplInitSettings( true );
239 Invalidate();
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 );
253 Invalidate();
257 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */