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/event.hxx>
21#include <vcl/layout.hxx>
22#include <vcl/tabpage.hxx>
23#include <vcl/bitmapex.hxx>
24#include <vcl/settings.hxx>
26#include <svdata.hxx>
27
28void 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;
48 }
49 if ( nStyle & WB_AUTOVSCROLL )
50 {
51 mbHasVertBar = true;
55 }
56 }
57
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
71}
72
74{
75 vcl::Window* pParent = GetParent();
76 if (pParent && pParent->IsChildTransparentModeEnabled() && !IsControlBackground())
77 {
80 SetPaintTransparent( true );
82 }
83 else
84 {
87 SetPaintTransparent( false );
88
89 if (IsControlBackground() || !pParent)
91 else
92 SetBackground( pParent->GetBackground() );
93 }
94}
95
98{
99 ImplInit( pParent, nStyle );
100}
101
103{
104 disposeOnce();
105}
106
108{
112}
113
115{
116 Window::StateChanged( nType );
117
119 {
120 if (GetSettings().GetStyleSettings().GetAutoMnemonic())
122 // FIXME: no layouting, workaround some clipping issues
124 }
126 {
128 Invalidate();
129 }
130}
131
133{
134 Window::DataChanged( rDCEvt );
135
136 if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
137 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
138 {
140 Invalidate();
141 }
142}
143
145{
146 // draw native tabpage only inside tabcontrols, standalone tabpages look ugly (due to bad dialog design)
148 return;
149
150 const ImplControlValue aControlValue;
151
153 if ( !IsEnabled() )
154 nState &= ~ControlState::ENABLED;
155 if ( HasFocus() )
157 // pass the whole window region to NWF as the tab body might be a gradient or bitmap
158 // that has to be scaled properly, clipping makes sure that we do not paint too much
159 tools::Rectangle aCtrlRegion( Point(), GetOutputSizePixel() );
161 aControlValue, OUString() );
162}
163
164void TabPage::Draw( OutputDevice* pDev, const Point& rPos, SystemTextColorFlags )
165{
166 Point aPos = pDev->LogicToPixel( rPos );
167 Size aSize = GetSizePixel();
168
169 Wallpaper aWallpaper = GetBackground();
170 if ( !aWallpaper.IsBitmap() )
172
173 pDev->Push();
174 pDev->SetMapMode();
175 pDev->SetLineColor();
176
177 if ( aWallpaper.IsBitmap() )
178 pDev->DrawBitmapEx( aPos, aSize, aWallpaper.GetBitmap() );
179 else
180 {
181 if( aWallpaper.GetColor() == COL_AUTO )
182 pDev->SetFillColor( GetSettings().GetStyleSettings().GetDialogColor() );
183 else
184 pDev->SetFillColor( aWallpaper.GetColor() );
185 pDev->DrawRect( tools::Rectangle( aPos, aSize ) );
186 }
187
188 pDev->Pop();
189}
190
192{
193 if (isLayoutEnabled(this))
195 return getLegacyBestSizeForChildren(*this);
196}
197
198void TabPage::SetPosSizePixel(const Point& rAllocPos, const Size& rAllocation)
199{
200 Window::SetPosSizePixel(rAllocPos, rAllocation);
201 if (isLayoutEnabled(this) && rAllocation.Width() && rAllocation.Height())
203}
204
205void TabPage::SetSizePixel(const Size& rAllocation)
206{
207 Window::SetSizePixel(rAllocation);
208 if (isLayoutEnabled(this) && rAllocation.Width() && rAllocation.Height())
210}
211
212void TabPage::SetPosPixel(const Point& rAllocPos)
213{
214 Window::SetPosPixel(rAllocPos);
215 Size aAllocation(GetOutputSizePixel());
216 if (isLayoutEnabled(this) && aAllocation.Width() && aAllocation.Height())
217 {
219 }
220}
221
223{
224 tools::Long nXScroll = mnScrollPos.X() - nX;
225 tools::Long nYScroll = mnScrollPos.Y() - nY;
226 mnScrollPos = Point( nX, nY );
227
228 tools::Rectangle aScrollableArea( 0, 0, maScrollArea.Width(), maScrollArea.Height() );
229 Scroll(nXScroll, nYScroll, aScrollableArea );
230 // Manually scroll all children ( except the scrollbars )
231 for ( int index = 0; index < GetChildCount(); ++index )
232 {
233 vcl::Window* pChild = GetChild( index );
234 if ( pChild && pChild != m_pVScroll.get() && pChild != m_pHScroll.get() )
235 {
236 Point aPos = pChild->GetPosPixel();
237 aPos += Point( nXScroll, nYScroll );
238 pChild->SetPosPixel( aPos );
239 }
240 }
241}
242
243IMPL_LINK( TabPage, ScrollBarHdl, ScrollBar*, pSB, void )
244{
245 sal_uInt16 nPos = static_cast<sal_uInt16>(pSB->GetThumbPos());
246 if( pSB == m_pVScroll.get() )
247 lcl_Scroll(mnScrollPos.X(), nPos );
248 else if( pSB == m_pHScroll.get() )
249 lcl_Scroll(nPos, mnScrollPos.Y() );
250}
251
253{
254 Point aOld = mnScrollPos;
255 lcl_Scroll( mnScrollPos.X() , mnScrollPos.Y() - nTop );
256 if( m_pHScroll )
258 // new pos is 0,0
259 mnScrollPos = aOld;
260}
262{
263 Point aOld = mnScrollPos;
264 lcl_Scroll( mnScrollPos.X() - nLeft , mnScrollPos.Y() );
265 if( m_pVScroll )
267 // new pos is 0,0
268 mnScrollPos = aOld;
269}
270
272{
273 maScrollArea.setWidth( nWidth );
275}
276
278{
279 maScrollArea.setHeight( nHeight );
281}
282
284{
286}
287
289{
290 Size aOutSz = GetOutputSizePixel();
291
292 Point aVPos( aOutSz.Width() - mnScrWidth, 0 );
293 Point aHPos( 0, aOutSz.Height() - mnScrWidth );
294
295 if( m_pVScroll )
296 {
300 }
301
302 if( m_pHScroll )
303 {
307 }
308}
309
310/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SystemTextColorFlags
const StyleSettings & GetStyleSettings() const
static const AllSettings & GetSettings()
Gets the application's settings.
Definition: svapp.cxx:761
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:171
void DrawBitmapEx(const Point &rDestPt, const BitmapEx &rBitmapEx)
Definition: bitmapex.cxx:33
void DrawRect(const tools::Rectangle &rRect)
Definition: rect.cxx:50
void SetLineColor()
Definition: line.cxx:37
void SetMapMode()
Definition: map.cxx:610
void SetFillColor()
Definition: fill.cxx:29
SAL_WARN_UNUSED_RESULT Point LogicToPixel(const Point &rLogicPt) const
Definition: map.cxx:892
void Push(vcl::PushFlags nFlags=vcl::PushFlags::ALL)
Definition: stack.cxx:32
void Pop()
Definition: stack.cxx:91
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.
void SetThumbPos(tools::Long nThumbPos) override
Definition: scrbar.cxx:1362
void SetScrollHdl(const Link< ScrollBar *, void > &rLink)
Definition: scrbar.hxx:130
void SetVisibleSize(tools::Long nNewSize) override
Definition: scrbar.cxx:1376
void SetRangeMax(tools::Long nNewRange) override
Definition: scrbar.cxx:1333
constexpr tools::Long Height() const
void setWidth(tools::Long nWidth)
void setHeight(tools::Long nHeight)
constexpr tools::Long Width() const
sal_Int32 GetScrollBarSize() const
virtual void StateChanged(StateChangedType nStateChange) override
Definition: tabpage.cxx:114
SAL_DLLPRIVATE void ImplInit(vcl::Window *pParent, WinBits nStyle)
Definition: tabpage.cxx:28
virtual void SetPosSizePixel(const Point &rNewPos, const Size &rNewSize) override
Definition: tabpage.cxx:198
virtual Size GetOptimalSize() const override
Definition: tabpage.cxx:191
virtual void SetSizePixel(const Size &rNewSize) override
Definition: tabpage.cxx:205
bool mbHasHoriBar
Definition: tabpage.hxx:43
void ResetScrollBars()
Definition: tabpage.cxx:288
virtual void DataChanged(const DataChangedEvent &rDCEvt) override
Definition: tabpage.cxx:132
bool mbHasVertBar
Definition: tabpage.hxx:44
VclPtr< ScrollBar > m_pVScroll
Definition: tabpage.hxx:40
VclPtr< ScrollBar > m_pHScroll
Definition: tabpage.hxx:41
virtual void Resize() override
Definition: tabpage.cxx:283
void SetScrollLeft(tools::Long nLeft)
Definition: tabpage.cxx:261
Size maScrollArea
Definition: tabpage.hxx:42
tools::Long mnScrWidth
Definition: tabpage.hxx:46
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects.
Definition: tabpage.cxx:107
void SetScrollTop(tools::Long Top)
Definition: tabpage.cxx:252
void SetScrollWidth(tools::Long nWidth)
Definition: tabpage.cxx:271
Point mnScrollPos
Definition: tabpage.hxx:45
SAL_DLLPRIVATE void ImplInitSettings()
Definition: tabpage.cxx:73
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect) override
Definition: tabpage.cxx:144
virtual void Draw(OutputDevice *pDev, const Point &rPos, SystemTextColorFlags nFlags) override
Definition: tabpage.cxx:164
TabPage(vcl::Window *pParent, WinBits nStyle=0)
Definition: tabpage.cxx:96
virtual void SetPosPixel(const Point &rNewPos) override
Definition: tabpage.cxx:212
virtual ~TabPage() override
Definition: tabpage.cxx:102
void SetScrollHeight(tools::Long nHeight)
Definition: tabpage.cxx:277
void lcl_Scroll(tools::Long nX, tools::Long nY)
Definition: tabpage.cxx:222
static void setLayoutAllocation(vcl::Window &rWindow, const Point &rPos, const Size &rSize)
Definition: layout.cxx:95
static Size getLayoutRequisition(const vcl::Window &rWindow)
Definition: layout.cxx:170
A thin wrapper around rtl::Reference to implement the acquire and dispose semantics we want for refer...
Definition: vclptr.hxx:58
void disposeAndClear()
Definition: vclptr.hxx:200
void set(reference_type *pBody)
Definition: vclptr.hxx:148
reference_type * get() const
Get the body.
Definition: vclptr.hxx:143
const BitmapEx & GetBitmap() const
Definition: wall.cxx:184
const Color & GetColor() const
Definition: wall.hxx:71
bool IsBitmap() const
Definition: wall.cxx:189
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects.
Definition: window.cxx:140
const Wallpaper & GetBackground() const
Definition: window3.cxx:63
void SetStyle(WinBits nStyle)
Definition: window.cxx:1966
vcl::Window * GetParent() const
Definition: window2.cxx:1128
sal_uInt16 GetChildCount() const
Definition: stacking.cxx:1001
WindowType GetType() const
Definition: window2.cxx:1005
vcl::Window * GetWindow(GetWindowType nType) const
Definition: stacking.cxx:1035
void SetParentClipMode(ParentClipMode nMode=ParentClipMode::NONE)
bool IsChildTransparentModeEnabled() const
Definition: window2.cxx:1058
bool HasFocus() const
Definition: window.cxx:2988
virtual Point GetPosPixel() const
Definition: window.cxx:2798
WinBits GetStyle() const
Definition: window2.cxx:984
const AllSettings & GetSettings() const
Definition: window3.cxx:129
void Show(bool bVisible=true, ShowFlags nFlags=ShowFlags::NONE)
Definition: window.cxx:2191
bool IsNativeControlSupported(ControlType nType, ControlPart nPart) const
Query the platform layer for control support.
Definition: window3.cxx:74
virtual void Scroll(tools::Long nHorzScroll, tools::Long nVertScroll, ScrollFlags nFlags=ScrollFlags::NONE)
Definition: window.cxx:2951
virtual Size GetSizePixel() const
Definition: window.cxx:2406
Size GetOutputSizePixel() const
Definition: window3.cxx:89
bool IsControlBackground() const
Definition: window2.cxx:1118
const Color & GetControlBackground() const
Definition: window2.cxx:1113
void SetPaintTransparent(bool bTransparent)
Definition: paint.cxx:1025
virtual void ImplAdjustNWFSizes()
Definition: window3.cxx:28
virtual void Invalidate(InvalidateFlags nFlags=InvalidateFlags::NONE)
Definition: paint.cxx:1143
virtual void SetPosPixel(const Point &rNewPos)
Definition: window2.cxx:1288
virtual void SetPosSizePixel(const Point &rNewPos, const Size &rNewSize)
Definition: window2.cxx:1299
vcl::Window * GetChild(sal_uInt16 nChild) const
Definition: stacking.cxx:1017
bool IsEnabled() const
Definition: window2.cxx:1153
void EnableChildTransparentMode(bool bEnable=true)
Definition: window2.cxx:1053
void SetBackground()
Definition: window3.cxx:100
constexpr ::Color COL_AUTO(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
void GenerateAutoMnemonicsOnHierarchy(const vcl::Window *pWindow)
Definition: dialog.cxx:205
sal_Int32 nState
bool isLayoutEnabled(const vcl::Window *pWindow)
Definition: layout.cxx:2923
Size getLegacyBestSizeForChildren(const vcl::Window &rWindow)
Definition: layout.cxx:2861
sal_uInt16 nPos
index
long Long
QPRO_FUNC_TYPE nType
IMPL_LINK(TabPage, ScrollBarHdl, ScrollBar *, pSB, void)
Definition: tabpage.cxx:243
StateChangedType
Definition: window.hxx:291
sal_Int64 WinBits
Definition: wintypes.hxx:109
WinBits const WB_DIALOGCONTROL
Definition: wintypes.hxx:113
WinBits const WB_DRAG
Definition: wintypes.hxx:152
WindowType
Definition: wintypes.hxx:27
WinBits const WB_AUTOVSCROLL
Definition: wintypes.hxx:163
WinBits const WB_AUTOHSCROLL
Definition: wintypes.hxx:161
WinBits const WB_VSCROLL
Definition: wintypes.hxx:178
WinBits const WB_NODIALOGCONTROL
Definition: wintypes.hxx:114
WinBits const WB_CLIPCHILDREN
Definition: wintypes.hxx:112
WinBits const WB_HSCROLL
Definition: wintypes.hxx:177