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 
39 WinBits GroupBox::ImplInitStyle( WinBits nStyle )
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) ) &&
65  !IsControlBackground() )
66  {
67  EnableChildTransparentMode();
68  SetParentClipMode( ParentClipMode::NoClip );
69  SetPaintTransparent( true );
70  SetBackground();
71  }
72  else
73  {
74  EnableChildTransparentMode( false );
75  SetParentClipMode();
76  SetPaintTransparent( false );
77 
78  if ( IsControlBackground() )
79  SetBackground( GetControlBackground() );
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 
170 void GroupBox::FillLayoutData() const
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,
182  DrawFlags nFlags )
183 {
184  Point aPos = pDev->LogicToPixel( rPos );
185  Size aSize = GetSizePixel();
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 
201 void GroupBox::Resize()
202 {
203  Control::Resize();
204  Invalidate();
205 }
206 
207 void GroupBox::StateChanged( StateChangedType nType )
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  {
220  SetStyle( ImplInitStyle( GetStyle() ) );
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 
243 void GroupBox::DataChanged( const DataChangedEvent& rDCEvt )
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: */
long Width() const
const Color & GetShadowColor() const
OutDevType GetOutDevType() const
Definition: outdev.hxx:524
const Wallpaper & GetBackground() const
Definition: outdev.hxx:643
long GetHeight() const
std::vector< tools::Rectangle > MetricVector
Definition: outdev.hxx:137
long Height() const
virtual void StateChanged(StateChangedType nStateChange) override
Definition: ctrl.cxx:260
const Color & GetGroupTextColor() const
void SetTextFillColor()
Definition: text.cxx:700
DataChangedEventType GetType() const
Definition: event.hxx:357
void SetMapMode()
Definition: map.cxx:655
StateChangedType
Definition: window.hxx:310
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:1801
sal_Int64 WinBits
#define GROUP_BORDER
Definition: group.cxx:26
AllSettingsFlags GetFlags() const
Definition: event.hxx:358
const Color & GetLightColor() const
void DrawLine(const Point &rStartPt, const Point &rEndPt)
Definition: line.cxx:88
bool IsChildTransparentModeEnabled() const
Definition: window2.cxx:1027
void SetLineColor()
const vcl::Font & GetGroupFont() const
DrawFlags
Definition: window.hxx:353
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:302
#define GROUP_TEXT_BORDER
Definition: group.cxx:27
void SetTextColor(const Color &rColor)
Definition: text.cxx:665
DrawTextFlags
Definition: outdev.hxx:142
StyleSettingsOptions GetOptions() const
Point LogicToPixel(const Point &rLogicPt) const
Definition: map.cxx:942
SAL_DLLPRIVATE void ImplInit(vcl::Window *pParent, WinBits nStyle, SystemParentData *pSystemParentData)
Definition: window.cxx:936
virtual void Resize() override
Definition: ctrl.cxx:74
WindowType
Definition: ctrl.hxx:33
#define GROUP_VIEW_STYLE
Definition: group.cxx:29
void SetFont(const vcl::Font &rNewFont)
void ImplInitSettings()
Definition: ctrl.cxx:428
WinBits GetStyle() const
Definition: window2.cxx:953
WinBits const WB_GROUP
void Push(PushFlags nFlags=PushFlags::ALL)
Definition: outdevstate.cxx:60
WinBits const WB_CLIPCHILDREN
virtual void DataChanged(const DataChangedEvent &rDCEvt)
Definition: event.cxx:35