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#define GROUP_BORDER 12
25#define GROUP_TEXT_BORDER 2
26
27#define GROUP_VIEW_STYLE (WB_3DLOOK | WB_NOLABEL)
28
29void GroupBox::ImplInit( vcl::Window* pParent, WinBits nStyle )
30{
31 nStyle = ImplInitStyle( nStyle );
32 Control::ImplInit( pParent, nStyle, nullptr );
33 SetMouseTransparent( true );
34 ImplInitSettings( true );
35}
36
37WinBits GroupBox::ImplInitStyle( WinBits nStyle )
38{
39 if ( !(nStyle & WB_NOGROUP) )
40 nStyle |= WB_GROUP;
41 return nStyle;
42}
43
44const vcl::Font& GroupBox::GetCanonicalFont( const StyleSettings& _rStyle ) const
45{
46 return _rStyle.GetGroupFont();
47}
48
49const Color& GroupBox::GetCanonicalTextColor( const StyleSettings& _rStyle ) const
50{
51 return _rStyle.GetGroupTextColor();
52}
53
54void GroupBox::ImplInitSettings( bool bBackground )
55{
57
58 if ( !bBackground )
59 return;
60
61 vcl::Window* pParent = GetParent();
62 if ( (pParent->IsChildTransparentModeEnabled() ||
63 !(pParent->GetStyle() & WB_CLIPCHILDREN) ) &&
64 !IsControlBackground() )
65 {
66 EnableChildTransparentMode();
67 SetParentClipMode( ParentClipMode::NoClip );
68 SetPaintTransparent( true );
69 SetBackground();
70 }
71 else
72 {
73 EnableChildTransparentMode( false );
74 SetParentClipMode();
75 SetPaintTransparent( false );
76
77 if ( IsControlBackground() )
78 SetBackground( GetControlBackground() );
79 else
80 SetBackground( pParent->GetBackground() );
81 }
82}
83
84GroupBox::GroupBox( vcl::Window* pParent, WinBits nStyle ) :
86{
87 ImplInit( pParent, nStyle );
88}
89
90void GroupBox::ImplDraw( OutputDevice* pDev, SystemTextColorFlags nSystemTextColorFlags,
91 const Point& rPos, const Size& rSize, bool bLayout )
92{
93 tools::Long nTop;
94 tools::Long nTextOff;
95 const StyleSettings& rStyleSettings = GetSettings().GetStyleSettings();
96 OUString aText( GetText() );
97 tools::Rectangle aRect( rPos, rSize );
99
100 if ( GetStyle() & WB_NOLABEL )
101 nTextStyle &= ~DrawTextFlags::Mnemonic;
102 if ( !IsEnabled() )
103 nTextStyle |= DrawTextFlags::Disable;
104 if ( (nSystemTextColorFlags & SystemTextColorFlags::Mono) ||
105 (rStyleSettings.GetOptions() & StyleSettingsOptions::Mono) )
106 {
107 nTextStyle |= DrawTextFlags::Mono;
108 nSystemTextColorFlags |= SystemTextColorFlags::Mono;
109 }
110
111 if (aText.isEmpty())
112 {
113 nTop = rPos.Y();
114 nTextOff = 0;
115 }
116 else
117 {
118 aRect.AdjustLeft(GROUP_BORDER );
119 aRect.AdjustRight( -(GROUP_BORDER) );
120 aRect = pDev->GetTextRect( aRect, aText, nTextStyle );
121 nTop = rPos.Y();
122 nTop += aRect.GetHeight() / 2;
123 nTextOff = GROUP_TEXT_BORDER;
124 }
125
126 if( ! bLayout )
127 {
128 if ( nSystemTextColorFlags & SystemTextColorFlags::Mono )
129 pDev->SetLineColor( COL_BLACK );
130 else
131 pDev->SetLineColor( rStyleSettings.GetShadowColor() );
132
133 if (aText.isEmpty())
134 pDev->DrawLine( Point( rPos.X(), nTop ), Point( rPos.X()+rSize.Width()-2, nTop ) );
135 else
136 {
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 ) );
139 }
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 ) );
143
144 bool bIsPrinter = OUTDEV_PRINTER == pDev->GetOutDevType();
145 // if we're drawing onto a printer, spare the 3D effect #i46986#
146
147 if ( !bIsPrinter && !(nSystemTextColorFlags & SystemTextColorFlags::Mono) )
148 {
149 pDev->SetLineColor( rStyleSettings.GetLightColor() );
150 if (aText.isEmpty())
151 pDev->DrawLine( Point( rPos.X()+1, nTop+1 ), Point( rPos.X()+rSize.Width()-3, nTop+1 ) );
152 else
153 {
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 ) );
156 }
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 ) );
160 }
161 }
162
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 );
166}
167
168void GroupBox::FillLayoutData() const
169{
170 mxLayoutData.emplace();
171 const_cast<GroupBox*>(this)->ImplDraw( const_cast<GroupBox*>(this)->GetOutDev(), SystemTextColorFlags::NONE, Point(), GetOutputSizePixel(), true );
172}
173
174void GroupBox::Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& )
175{
176 ImplDraw(&rRenderContext, SystemTextColorFlags::NONE, Point(), GetOutputSizePixel());
177}
178
179void GroupBox::Draw( OutputDevice* pDev, const Point& rPos,
180 SystemTextColorFlags nFlags )
181{
182 Point aPos = pDev->LogicToPixel( rPos );
183 Size aSize = GetSizePixel();
184 vcl::Font aFont = GetDrawPixelFont( pDev );
185
186 pDev->Push();
187 pDev->SetMapMode();
188 pDev->SetFont( aFont );
189 if ( nFlags & SystemTextColorFlags::Mono )
190 pDev->SetTextColor( COL_BLACK );
191 else
192 pDev->SetTextColor( GetTextColor() );
193 pDev->SetTextFillColor();
194
195 ImplDraw( pDev, nFlags, aPos, aSize );
196 pDev->Pop();
197}
198
199void GroupBox::Resize()
200{
202 Invalidate();
203}
204
205void GroupBox::StateChanged( StateChangedType nType )
206{
207 Control::StateChanged( nType );
208
209 if ( (nType == StateChangedType::Enable) ||
210 (nType == StateChangedType::Text) ||
212 {
213 if ( IsUpdateMode() )
214 Invalidate();
215 }
216 else if ( nType == StateChangedType::Style )
217 {
218 SetStyle( ImplInitStyle( GetStyle() ) );
219 if ( (GetPrevStyle() & GROUP_VIEW_STYLE) !=
220 (GetStyle() & GROUP_VIEW_STYLE) )
221 Invalidate();
222 }
223 else if ( (nType == StateChangedType::Zoom) ||
225 {
226 ImplInitSettings( false );
227 Invalidate();
228 }
229 else if ( nType == StateChangedType::ControlForeground )
230 {
231 ImplInitSettings( false );
232 Invalidate();
233 }
234 else if ( nType == StateChangedType::ControlBackground )
235 {
236 ImplInitSettings( true );
237 Invalidate();
238 }
239}
240
241void GroupBox::DataChanged( const DataChangedEvent& rDCEvt )
242{
243 Control::DataChanged( rDCEvt );
244
245 if ( (rDCEvt.GetType() == DataChangedEventType::FONTS) ||
248 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE)) )
249 {
250 ImplInitSettings( true );
251 Invalidate();
252 }
253}
254
255/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
DrawTextFlags
SystemTextColorFlags
Definition: ctrl.hxx:82
virtual void StateChanged(StateChangedType nStateChange) override
Definition: ctrl.cxx:256
virtual void Resize() override
Definition: ctrl.cxx:74
void ImplInitSettings()
Definition: ctrl.cxx:423
DataChangedEventType GetType() const
Definition: event.hxx:362
AllSettingsFlags GetFlags() const
Definition: event.hxx:363
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:170
void SetFont(const vcl::Font &rNewFont)
Definition: outdev/font.cxx:53
void DrawLine(const Point &rStartPt, const Point &rEndPt)
Definition: line.cxx:161
void SetLineColor()
Definition: line.cxx:37
void SetMapMode()
Definition: map.cxx:649
void SetTextColor(const Color &rColor)
Definition: text.cxx:715
SAL_WARN_UNUSED_RESULT Point LogicToPixel(const Point &rLogicPt) const
Definition: map.cxx:933
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:1932
void SetTextFillColor()
Definition: text.cxx:733
void Push(vcl::PushFlags nFlags=vcl::PushFlags::ALL)
Definition: stack.cxx:33
void Pop()
Definition: stack.cxx:92
OutDevType GetOutDevType() const
Definition: outdev.hxx:407
constexpr tools::Long Height() const
constexpr tools::Long Width() const
const Color & GetGroupTextColor() const
const Color & GetShadowColor() const
StyleSettingsOptions GetOptions() const
const vcl::Font & GetGroupFont() const
const Color & GetLightColor() const
constexpr tools::Long GetHeight() const
const Wallpaper & GetBackground() const
Definition: window3.cxx:63
bool IsChildTransparentModeEnabled() const
Definition: window2.cxx:1051
WinBits GetStyle() const
Definition: window2.cxx:977
virtual void DataChanged(const DataChangedEvent &rDCEvt)
Definition: event.cxx:36
SAL_DLLPRIVATE void ImplInit(vcl::Window *pParent, WinBits nStyle, SystemParentData *pSystemParentData)
Definition: window.cxx:940
#define GROUP_VIEW_STYLE
Definition: group.cxx:27
#define GROUP_TEXT_BORDER
Definition: group.cxx:25
#define GROUP_BORDER
Definition: group.cxx:24
long Long
Color GetTextColor(Color const &rColor, DrawModeFlags nDrawMode, StyleSettings const &rStyleSettings)
Definition: drawmode.cxx:128
@ OUTDEV_PRINTER
Definition: outdev.hxx:143
StateChangedType
Definition: window.hxx:291
sal_Int64 WinBits
Definition: wintypes.hxx:109
WindowType
Definition: wintypes.hxx:27
WinBits const WB_NOLABEL
Definition: wintypes.hxx:157
WinBits const WB_GROUP
Definition: wintypes.hxx:142
WinBits const WB_NOGROUP
Definition: wintypes.hxx:143
WinBits const WB_CLIPCHILDREN
Definition: wintypes.hxx:112