LibreOffice Module vcl (master)  1
tabpage.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/accel.hxx>
21 #include <vcl/event.hxx>
22 #include <vcl/layout.hxx>
23 #include <vcl/tabpage.hxx>
24 #include <vcl/bitmapex.hxx>
25 #include <vcl/settings.hxx>
26 #include <vcl/scrbar.hxx>
27 
28 void TabPage::ImplInit( vcl::Window* pParent, WinBits nStyle )
29 {
30  if ( !(nStyle & WB_NODIALOGCONTROL) )
31  nStyle |= WB_DIALOGCONTROL;
32 
33  Window::ImplInit( pParent, nStyle, nullptr );
34 
35  mbHasHoriBar = false;
36  mbHasVertBar = false;
37 
38  Link<ScrollBar*,void> aLink( LINK( this, TabPage, ScrollBarHdl ) );
39 
40  if ( nStyle & ( WB_AUTOHSCROLL | WB_AUTOVSCROLL ) )
41  {
42  if ( nStyle & WB_AUTOHSCROLL )
43  {
44  mbHasHoriBar = true;
46  m_pHScroll->Show();
47  m_pHScroll->SetScrollHdl(aLink);
48  }
49  if ( nStyle & WB_AUTOVSCROLL )
50  {
51  mbHasVertBar = true;
53  m_pVScroll->Show();
54  m_pVScroll->SetScrollHdl(aLink);
55  }
56  }
57 
58  if ( mbHasHoriBar || mbHasVertBar )
59  {
61  }
62 
64 
66 
67  // if the tabpage is drawn (ie filled) by a native widget, make sure all controls will have transparent background
68  // otherwise they will paint with a wrong background
69  if( IsNativeControlSupported(ControlType::TabBody, ControlPart::Entire) && GetParent() && (GetParent()->GetType() == WindowType::TABCONTROL) )
71 }
72 
74 {
75  vcl::Window* pParent = GetParent();
76  if (pParent && pParent->IsChildTransparentModeEnabled() && !IsControlBackground())
77  {
80  SetPaintTransparent( true );
81  SetBackground();
82  }
83  else
84  {
87  SetPaintTransparent( false );
88 
89  if (IsControlBackground() || !pParent)
91  else
92  SetBackground( pParent->GetBackground() );
93  }
94 }
95 
96 TabPage::TabPage( vcl::Window* pParent, WinBits nStyle ) :
98  , IContext()
99 {
100  ImplInit( pParent, nStyle );
101 }
102 
104 {
105  disposeOnce();
106 }
107 
109 {
113 }
114 
116 {
117  Window::StateChanged( nType );
118 
119  if ( nType == StateChangedType::InitShow )
120  {
121  if (GetSettings().GetStyleSettings().GetAutoMnemonic())
122  Accelerator::GenerateAutoMnemonicsOnHierarchy(this);
123  // FIXME: no layouting, workaround some clipping issues
125  }
126  else if ( nType == StateChangedType::ControlBackground )
127  {
129  Invalidate();
130  }
131 }
132 
134 {
135  Window::DataChanged( rDCEvt );
136 
137  if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
138  (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
139  {
141  Invalidate();
142  }
143 }
144 
145 void TabPage::Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& )
146 {
147  // draw native tabpage only inside tabcontrols, standalone tabpages look ugly (due to bad dialog design)
148  if( !(IsNativeControlSupported(ControlType::TabBody, ControlPart::Entire) && GetParent() && (GetParent()->GetType() == WindowType::TABCONTROL)) )
149  return;
150 
151  const ImplControlValue aControlValue;
152 
154  if ( !IsEnabled() )
155  nState &= ~ControlState::ENABLED;
156  if ( HasFocus() )
157  nState |= ControlState::FOCUSED;
158  // pass the whole window region to NWF as the tab body might be a gradient or bitmap
159  // that has to be scaled properly, clipping makes sure that we do not paint too much
160  tools::Rectangle aCtrlRegion( Point(), GetOutputSizePixel() );
161  rRenderContext.DrawNativeControl( ControlType::TabBody, ControlPart::Entire, aCtrlRegion, nState,
162  aControlValue, OUString() );
163 }
164 
165 void TabPage::Draw( OutputDevice* pDev, const Point& rPos, DrawFlags )
166 {
167  Point aPos = pDev->LogicToPixel( rPos );
168  Size aSize = GetSizePixel();
169 
170  Wallpaper aWallpaper = GetBackground();
171  if ( !aWallpaper.IsBitmap() )
173 
174  pDev->Push();
175  pDev->SetMapMode();
176  pDev->SetLineColor();
177 
178  if ( aWallpaper.IsBitmap() )
179  pDev->DrawBitmapEx( aPos, aSize, aWallpaper.GetBitmap() );
180  else
181  {
182  if( aWallpaper.GetColor() == COL_AUTO )
183  pDev->SetFillColor( GetSettings().GetStyleSettings().GetDialogColor() );
184  else
185  pDev->SetFillColor( aWallpaper.GetColor() );
186  pDev->DrawRect( tools::Rectangle( aPos, aSize ) );
187  }
188 
189  pDev->Pop();
190 }
191 
193 {
194  if (isLayoutEnabled(this))
196  return getLegacyBestSizeForChildren(*this);
197 }
198 
199 void TabPage::SetPosSizePixel(const Point& rAllocPos, const Size& rAllocation)
200 {
201  Window::SetPosSizePixel(rAllocPos, rAllocation);
202  if (isLayoutEnabled(this) && rAllocation.Width() && rAllocation.Height())
204 }
205 
206 void TabPage::SetSizePixel(const Size& rAllocation)
207 {
208  Window::SetSizePixel(rAllocation);
209  if (isLayoutEnabled(this) && rAllocation.Width() && rAllocation.Height())
211 }
212 
213 void TabPage::SetPosPixel(const Point& rAllocPos)
214 {
215  Window::SetPosPixel(rAllocPos);
216  Size aAllocation(GetOutputSizePixel());
217  if (isLayoutEnabled(this) && aAllocation.Width() && aAllocation.Height())
218  {
220  }
221 }
222 
224 {
225  tools::Long nXScroll = mnScrollPos.X() - nX;
226  tools::Long nYScroll = mnScrollPos.Y() - nY;
227  mnScrollPos = Point( nX, nY );
228 
229  tools::Rectangle aScrollableArea( 0, 0, maScrollArea.Width(), maScrollArea.Height() );
230  Scroll(nXScroll, nYScroll, aScrollableArea );
231  // Manually scroll all children ( except the scrollbars )
232  for ( int index = 0; index < GetChildCount(); ++index )
233  {
234  vcl::Window* pChild = GetChild( index );
235  if ( pChild && pChild != m_pVScroll.get() && pChild != m_pHScroll.get() )
236  {
237  Point aPos = pChild->GetPosPixel();
238  aPos += Point( nXScroll, nYScroll );
239  pChild->SetPosPixel( aPos );
240  }
241  }
242 }
243 
244 IMPL_LINK( TabPage, ScrollBarHdl, ScrollBar*, pSB, void )
245 {
246  sal_uInt16 nPos = static_cast<sal_uInt16>(pSB->GetThumbPos());
247  if( pSB == m_pVScroll.get() )
248  lcl_Scroll(mnScrollPos.X(), nPos );
249  else if( pSB == m_pHScroll.get() )
250  lcl_Scroll(nPos, mnScrollPos.Y() );
251 }
252 
254 {
255  Point aOld = mnScrollPos;
256  lcl_Scroll( mnScrollPos.X() , mnScrollPos.Y() - nTop );
257  if( m_pHScroll )
258  m_pHScroll->SetThumbPos( 0 );
259  // new pos is 0,0
260  mnScrollPos = aOld;
261 }
263 {
264  Point aOld = mnScrollPos;
265  lcl_Scroll( mnScrollPos.X() - nLeft , mnScrollPos.Y() );
266  if( m_pVScroll )
267  m_pVScroll->SetThumbPos( 0 );
268  // new pos is 0,0
269  mnScrollPos = aOld;
270 }
271 
273 {
274  maScrollArea.setWidth( nWidth );
275  ResetScrollBars();
276 }
277 
279 {
280  maScrollArea.setHeight( nHeight );
281  ResetScrollBars();
282 }
283 
285 {
286  ResetScrollBars();
287 }
288 
290 {
291  Size aOutSz = GetOutputSizePixel();
292 
293  Point aVPos( aOutSz.Width() - mnScrWidth, 0 );
294  Point aHPos( 0, aOutSz.Height() - mnScrWidth );
295 
296  if( m_pVScroll )
297  {
301  }
302 
303  if( m_pHScroll )
304  {
308  }
309 }
310 
311 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual Point GetPosPixel() const
Definition: window.cxx:2783
bool IsControlBackground() const
Definition: window2.cxx:1086
const Wallpaper & GetBackground() const
Definition: outdev.hxx:647
static void setLayoutAllocation(vcl::Window &rWindow, const Point &rPos, const Size &rSize)
Definition: layout.cxx:68
void SetScrollTop(tools::Long Top)
Definition: tabpage.cxx:253
Point mnScrollPos
Definition: tabpage.hxx:45
VclPtr< ScrollBar > m_pVScroll
Definition: tabpage.hxx:40
void setWidth(tools::Long nWidth)
virtual void ImplAdjustNWFSizes()
Definition: window3.cxx:28
A thin wrapper around rtl::Reference to implement the acquire and dispose semantics we want for refer...
Definition: button.hxx:35
WinBits const WB_NODIALOGCONTROL
void DrawBitmapEx(const Point &rDestPt, const BitmapEx &rBitmapEx)
This is an overloaded member function, provided for convenience. It differs from the above function o...
static Size getLayoutRequisition(const vcl::Window &rWindow)
Definition: layout.cxx:143
long Long
void disposeAndClear()
Definition: vclptr.hxx:200
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
Gets the application's settings.
Definition: svapp.cxx:733
constexpr::Color COL_AUTO(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
virtual Size GetSizePixel() const
Definition: window.cxx:2394
WinBits const WB_AUTOVSCROLL
void SetParentClipMode(ParentClipMode nMode=ParentClipMode::NONE)
DataChangedEventType GetType() const
Definition: event.hxx:354
WinBits const WB_VSCROLL
const Color & GetControlBackground() const
Definition: window2.cxx:1081
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
Definition: window.cxx:148
void SetRangeMax(tools::Long nNewRange)
Definition: scrbar.cxx:1333
virtual void DataChanged(const DataChangedEvent &rDCEvt) override
Definition: tabpage.cxx:133
bool IsNativeControlSupported(ControlType nType, ControlPart nPart) const
Query the platform layer for control support.
void SetMapMode()
Definition: map.cxx:516
bool mbHasVertBar
Definition: tabpage.hxx:44
void lcl_Scroll(tools::Long nX, tools::Long nY)
Definition: tabpage.cxx:223
virtual ~TabPage() override
Definition: tabpage.cxx:103
StateChangedType
Definition: window.hxx:289
constexpr tools::Long Width() const
SAL_DLLPRIVATE void ImplInit(vcl::Window *pParent, WinBits nStyle)
Definition: tabpage.cxx:28
sal_Int64 WinBits
void SetBackground()
virtual void Draw(OutputDevice *pDev, const Point &rPos, DrawFlags nFlags) override
Definition: tabpage.cxx:165
WinBits const WB_HSCROLL
AllSettingsFlags GetFlags() const
Definition: event.hxx:355
VclPtr< ScrollBar > m_pHScroll
Definition: tabpage.hxx:41
bool mbHasHoriBar
Definition: tabpage.hxx:43
void SetScrollWidth(tools::Long nWidth)
Definition: tabpage.cxx:272
void SetThumbPos(tools::Long nThumbPos)
Definition: scrbar.cxx:1362
bool IsChildTransparentModeEnabled() const
Definition: window2.cxx:1026
void DrawRect(const tools::Rectangle &rRect)
Definition: rect.cxx:51
void SetScrollHeight(tools::Long nHeight)
Definition: tabpage.cxx:278
WinBits const WB_DIALOGCONTROL
Size getLegacyBestSizeForChildren(const vcl::Window &rWindow)
Definition: layout.cxx:2812
void SetLineColor()
DrawFlags
Definition: window.hxx:332
Size maScrollArea
Definition: tabpage.hxx:42
virtual void StateChanged(StateChangedType nStateChange) override
Definition: tabpage.cxx:115
void SetVisibleSize(tools::Long nNewSize)
Definition: scrbar.cxx:1376
const Color & GetColor() const
Definition: wall.cxx:199
virtual void Invalidate(InvalidateFlags nFlags=InvalidateFlags::NONE)
Definition: paint.cxx:1140
void SetFillColor()
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:303
bool isLayoutEnabled(const vcl::Window *pWindow)
Definition: layout.cxx:2874
bool DrawNativeControl(ControlType nType, ControlPart nPart, const tools::Rectangle &rControlRegion, ControlState nState, const ImplControlValue &aValue, const OUString &aCaption, const Color &rBackgroundColor=COL_AUTO)
Request rendering of a particular control and/or part.
const AllSettings & GetSettings() const
Definition: outdev.hxx:418
void SetPaintTransparent(bool bTransparent)
Definition: paint.cxx:1022
Size GetOutputSizePixel() const
Definition: outdev.hxx:441
tools::Long GetScrollBarSize() const
tuple index
virtual void Resize() override
Definition: tabpage.cxx:284
virtual void SetPosSizePixel(const Point &rNewPos, const Size &rNewSize) override
Definition: tabpage.cxx:199
vcl::Window * GetParent() const
Definition: window2.cxx:1096
void SetStyle(WinBits nStyle)
Definition: window.cxx:1955
virtual void SetSizePixel(const Size &rNewSize) override
Definition: tabpage.cxx:206
virtual void SetPosSizePixel(const Point &rNewPos, const Size &rNewSize)
Definition: window2.cxx:1267
vcl::Window * GetWindow(GetWindowType nType) const
Definition: stacking.cxx:1035
Point LogicToPixel(const Point &rLogicPt) const
Definition: map.cxx:800
tools::Long mnScrWidth
Definition: tabpage.hxx:46
sal_uInt16 GetChildCount() const
Definition: stacking.cxx:1001
BitmapEx GetBitmap() const
Definition: wall.cxx:242
virtual void Scroll(tools::Long nHorzScroll, tools::Long nVertScroll, ScrollFlags nFlags=ScrollFlags::NONE)
Definition: window.cxx:2936
WindowType
constexpr tools::Long Height() const
void EnableChildTransparentMode(bool bEnable=true)
Definition: window2.cxx:1021
void SetScrollHdl(const Link< ScrollBar *, void > &rLink)
Definition: scrbar.hxx:133
void SetScrollLeft(tools::Long nLeft)
Definition: tabpage.cxx:262
WinBits const WB_AUTOHSCROLL
void set(reference_type *pBody)
Definition: vclptr.hxx:148
SAL_DLLPRIVATE void ImplInitSettings()
Definition: tabpage.cxx:73
virtual void SetPosPixel(const Point &rNewPos) override
Definition: tabpage.cxx:213
bool IsBitmap() const
Definition: wall.cxx:250
void setHeight(tools::Long nHeight)
void ResetScrollBars()
Definition: tabpage.cxx:289
WindowType GetType() const
Definition: window2.cxx:973
TabPage(vcl::Window *pParent, WinBits nStyle=0)
Definition: tabpage.cxx:96
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
Definition: tabpage.cxx:108
reference_type * get() const
Get the body.
Definition: vclptr.hxx:143
bool IsEnabled() const
Definition: window2.cxx:1121
WinBits GetStyle() const
Definition: window2.cxx:952
bool HasFocus() const
Definition: window.cxx:2973
void Push(PushFlags nFlags=PushFlags::ALL)
Definition: outdevstate.cxx:59
IMPL_LINK(TabPage, ScrollBarHdl, ScrollBar *, pSB, void)
Definition: tabpage.cxx:244
WinBits const WB_CLIPCHILDREN
sal_Int32 nState
virtual void SetPosPixel(const Point &rNewPos)
Definition: window2.cxx:1256
virtual Size GetOptimalSize() const override
Definition: tabpage.cxx:192
sal_uInt16 nPos
vcl::Window * GetChild(sal_uInt16 nChild) const
Definition: stacking.cxx:1017
WinBits const WB_DRAG
void Show(bool bVisible=true, ShowFlags nFlags=ShowFlags::NONE)
Definition: window.cxx:2180
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect) override
Definition: tabpage.cxx:145