LibreOffice Module vcl (master)  1
group.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <vcl/event.hxx>
21 #include <vcl/toolkit/group.hxx>
22 #include <vcl/settings.hxx>
23 
24 #include <controldata.hxx>
25 
26 #define GROUP_BORDER 12
27 #define GROUP_TEXT_BORDER 2
28 
29 #define GROUP_VIEW_STYLE (WB_3DLOOK | WB_NOLABEL)
30 
31 void GroupBox::ImplInit( vcl::Window* pParent, WinBits nStyle )
32 {
33  nStyle = ImplInitStyle( nStyle );
34  Control::ImplInit( pParent, nStyle, nullptr );
35  SetMouseTransparent( true );
36  ImplInitSettings( true );
37 }
38 
40 {
41  if ( !(nStyle & WB_NOGROUP) )
42  nStyle |= WB_GROUP;
43  return nStyle;
44 }
45 
46 const vcl::Font& GroupBox::GetCanonicalFont( const StyleSettings& _rStyle ) const
47 {
48  return _rStyle.GetGroupFont();
49 }
50 
51 const Color& GroupBox::GetCanonicalTextColor( const StyleSettings& _rStyle ) const
52 {
53  return _rStyle.GetGroupTextColor();
54 }
55 
56 void GroupBox::ImplInitSettings( bool bBackground )
57 {
59 
60  if ( bBackground )
61  {
62  vcl::Window* pParent = GetParent();
63  if ( (pParent->IsChildTransparentModeEnabled() ||
64  !(pParent->GetStyle() & WB_CLIPCHILDREN) ) &&
66  {
69  SetPaintTransparent( true );
70  SetBackground();
71  }
72  else
73  {
76  SetPaintTransparent( false );
77 
78  if ( IsControlBackground() )
80  else
81  SetBackground( pParent->GetBackground() );
82  }
83  }
84 }
85 
86 GroupBox::GroupBox( vcl::Window* pParent, WinBits nStyle ) :
88 {
89  ImplInit( pParent, nStyle );
90 }
91 
92 void GroupBox::ImplDraw( OutputDevice* pDev, DrawFlags nDrawFlags,
93  const Point& rPos, const Size& rSize, bool bLayout )
94 {
95  long nTop;
96  long nTextOff;
97  const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
98  OUString aText( GetText() );
99  tools::Rectangle aRect( rPos, rSize );
101 
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) )
108  {
109  nTextStyle |= DrawTextFlags::Mono;
110  nDrawFlags |= DrawFlags::Mono;
111  }
112 
113  if (aText.isEmpty())
114  {
115  nTop = rPos.Y();
116  nTextOff = 0;
117  }
118  else
119  {
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;
126  }
127 
128  if( ! bLayout )
129  {
130  if ( nDrawFlags & DrawFlags::Mono )
131  pDev->SetLineColor( COL_BLACK );
132  else
133  pDev->SetLineColor( rStyleSettings.GetShadowColor() );
134 
135  if (aText.isEmpty())
136  pDev->DrawLine( Point( rPos.X(), nTop ), Point( rPos.X()+rSize.Width()-2, nTop ) );
137  else
138  {
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 ) );
141  }
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 ) );
145 
146  bool bIsPrinter = OUTDEV_PRINTER == pDev->GetOutDevType();
147  // if we're drawing onto a printer, spare the 3D effect #i46986#
148 
149  if ( !bIsPrinter && !(nDrawFlags & DrawFlags::Mono) )
150  {
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
155  {
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 ) );
158  }
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 ) );
162  }
163  }
164 
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 );
168 }
169 
171 {
172  mpControlData->mpLayoutData.reset( new vcl::ControlLayoutData );
173  const_cast<GroupBox*>(this)->ImplDraw( const_cast<GroupBox*>(this), DrawFlags::NONE, Point(), GetOutputSizePixel(), true );
174 }
175 
176 void GroupBox::Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& )
177 {
178  ImplDraw(&rRenderContext, DrawFlags::NONE, Point(), GetOutputSizePixel());
179 }
180 
181 void GroupBox::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize,
182  DrawFlags nFlags )
183 {
184  Point aPos = pDev->LogicToPixel( rPos );
185  Size aSize = pDev->LogicToPixel( rSize );
186  vcl::Font aFont = GetDrawPixelFont( pDev );
187 
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();
196 
197  ImplDraw( pDev, nFlags, aPos, aSize );
198  pDev->Pop();
199 }
200 
202 {
203  Control::Resize();
204  Invalidate();
205 }
206 
208 {
209  Control::StateChanged( nType );
210 
211  if ( (nType == StateChangedType::Enable) ||
212  (nType == StateChangedType::Text) ||
213  (nType == StateChangedType::UpdateMode) )
214  {
215  if ( IsUpdateMode() )
216  Invalidate();
217  }
218  else if ( nType == StateChangedType::Style )
219  {
221  if ( (GetPrevStyle() & GROUP_VIEW_STYLE) !=
222  (GetStyle() & GROUP_VIEW_STYLE) )
223  Invalidate();
224  }
225  else if ( (nType == StateChangedType::Zoom) ||
226  (nType == StateChangedType::ControlFont) )
227  {
228  ImplInitSettings( false );
229  Invalidate();
230  }
231  else if ( nType == StateChangedType::ControlForeground )
232  {
233  ImplInitSettings( false );
234  Invalidate();
235  }
236  else if ( nType == StateChangedType::ControlBackground )
237  {
238  ImplInitSettings( true );
239  Invalidate();
240  }
241 }
242 
244 {
245  Control::DataChanged( rDCEvt );
246 
247  if ( (rDCEvt.GetType() == DataChangedEventType::FONTS) ||
249  ((rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
250  (rDCEvt.GetFlags() & AllSettingsFlags::STYLE)) )
251  {
252  ImplInitSettings( true );
253  Invalidate();
254  }
255 }
256 
257 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void FillLayoutData() const override
Definition: group.cxx:170
long Width() const
const Color & GetTextColor() const
Definition: outdev.hxx:1110
const Color & GetShadowColor() const
OutDevType GetOutDevType() const
Definition: outdev.hxx:522
bool IsControlBackground() const
Definition: window2.cxx:1076
SAL_DLLPRIVATE void ImplDraw(OutputDevice *pDev, DrawFlags nDrawFlags, const Point &rPos, const Size &rSize, bool bLayout=false)
Definition: group.cxx:92
virtual void StateChanged(StateChangedType nType) override
Definition: group.cxx:207
const Wallpaper & GetBackground() const
Definition: outdev.hxx:631
long GetHeight() const
constexpr::Color COL_BLACK(0x00, 0x00, 0x00)
WinBits const WB_NOLABEL
std::vector< tools::Rectangle > MetricVector
Definition: outdev.hxx:139
long Height() const
WinBits const WB_NOGROUP
long AdjustLeft(long nHorzMoveDelta)
const StyleSettings & GetStyleSettings() const
virtual void StateChanged(StateChangedType nStateChange) override
Definition: ctrl.cxx:260
const Color & GetGroupTextColor() const
void SetTextFillColor()
Definition: text.cxx:697
void SetParentClipMode(ParentClipMode nMode=ParentClipMode::NONE)
WinBits GetPrevStyle() const
Definition: window2.cxx:947
DataChangedEventType GetType() const
Definition: event.hxx:348
const Color & GetControlBackground() const
Definition: window2.cxx:1071
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect) override
Definition: group.cxx:176
void SetMapMode()
Definition: map.cxx:655
StateChangedType
Definition: window.hxx:311
tools::Rectangle GetTextRect(const tools::Rectangle &rRect, const OUString &rStr, DrawTextFlags nStyle=DrawTextFlags::WordBreak, TextRectInfo *pInfo=nullptr, const vcl::ITextLayout *_pTextLayout=nullptr) const
Definition: text.cxx:1789
virtual void DataChanged(const DataChangedEvent &rDCEvt) override
Definition: group.cxx:243
sal_Int64 WinBits
void SetBackground()
long Right() const
#define GROUP_BORDER
Definition: group.cxx:26
AllSettingsFlags GetFlags() const
Definition: event.hxx:349
const Color & GetLightColor() const
virtual OUString GetText() const
Definition: window.cxx:3060
void DrawLine(const Point &rStartPt, const Point &rEndPt)
Definition: line.cxx:88
bool IsChildTransparentModeEnabled() const
Definition: window2.cxx:1016
tools::Rectangle DrawControlText(OutputDevice &_rTargetDevice, const tools::Rectangle &_rRect, const OUString &_rStr, DrawTextFlags _nStyle, MetricVector *_pVector, OUString *_pDisplayText, const Size *i_pDeviceSize=nullptr) const
draws the given text onto the given device
Definition: ctrl.cxx:433
void SetLineColor()
const vcl::Font & GetGroupFont() const
DrawFlags
Definition: window.hxx:354
virtual const Color & GetCanonicalTextColor(const StyleSettings &_rStyle) const override
Definition: group.cxx:51
virtual void Invalidate(InvalidateFlags nFlags=InvalidateFlags::NONE)
Definition: paint.cxx:1156
bool IsUpdateMode() const
Definition: window2.cxx:1162
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:304
#define GROUP_TEXT_BORDER
Definition: group.cxx:27
void SetTextColor(const Color &rColor)
Definition: text.cxx:662
GroupBox(vcl::Window *pParent, WinBits nStyle)
Definition: group.cxx:86
virtual void Draw(OutputDevice *pDev, const Point &rPos, const Size &rSize, DrawFlags nFlags) override
Definition: group.cxx:181
const AllSettings & GetSettings() const
Definition: outdev.hxx:420
void SetPaintTransparent(bool bTransparent)
Definition: paint.cxx:1018
Size GetOutputSizePixel() const
Definition: outdev.hxx:441
DrawTextFlags
Definition: outdev.hxx:144
vcl::Window * GetParent() const
Definition: window2.cxx:1086
virtual const vcl::Font & GetCanonicalFont(const StyleSettings &_rStyle) const override
Definition: group.cxx:46
long X() const
void SetStyle(WinBits nStyle)
Definition: window.cxx:1926
StyleSettingsOptions GetOptions() const
Point LogicToPixel(const Point &rLogicPt) const
Definition: map.cxx:940
SAL_DLLPRIVATE void ImplInit(vcl::Window *pParent, WinBits nStyle, SystemParentData *pSystemParentData)
Definition: window.cxx:932
virtual void Resize() override
Definition: ctrl.cxx:74
void SetMouseTransparent(bool bTransparent)
Definition: mouse.cxx:427
long AdjustRight(long nHorzMoveDelta)
WindowType
Definition: ctrl.hxx:33
#define GROUP_VIEW_STYLE
Definition: group.cxx:29
void SetFont(const vcl::Font &rNewFont)
std::unique_ptr< vcl::ImplControlData > mpControlData
Definition: ctrl.hxx:36
vcl::Font GetDrawPixelFont(::OutputDevice const *pDev) const
Definition: window2.cxx:553
void EnableChildTransparentMode(bool bEnable=true)
Definition: window2.cxx:1011
long Left() const
void ImplInitSettings()
Definition: ctrl.cxx:428
SAL_DLLPRIVATE void ImplInit(vcl::Window *pParent, WinBits nStyle)
Definition: group.cxx:31
bool IsEnabled() const
Definition: window2.cxx:1111
WinBits GetStyle() const
Definition: window2.cxx:942
WinBits const WB_GROUP
void Push(PushFlags nFlags=PushFlags::ALL)
Definition: outdevstate.cxx:60
static SAL_DLLPRIVATE WinBits ImplInitStyle(WinBits nStyle)
Definition: group.cxx:39
virtual void Resize() override
Definition: group.cxx:201
WinBits const WB_CLIPCHILDREN
long Y() const
virtual void DataChanged(const DataChangedEvent &rDCEvt)
Definition: event.cxx:35