1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
25 #include <vcl/toolkit/scrbar.hxx>
28 void TabPage::ImplInit( vcl::Window
* pParent
, WinBits nStyle
)
30 if ( !(nStyle
& WB_NODIALOGCONTROL
) )
31 nStyle
|= WB_DIALOGCONTROL
;
33 Window::ImplInit( pParent
, nStyle
, nullptr );
38 Link
<ScrollBar
*,void> aLink( LINK( this, TabPage
, ScrollBarHdl
) );
40 if ( nStyle
& ( WB_AUTOHSCROLL
| WB_AUTOVSCROLL
) )
42 if ( nStyle
& WB_AUTOHSCROLL
)
45 m_pHScroll
.set(VclPtr
<ScrollBar
>::Create(this, (WB_HSCROLL
| WB_DRAG
)));
47 m_pHScroll
->SetScrollHdl(aLink
);
49 if ( nStyle
& WB_AUTOVSCROLL
)
52 m_pVScroll
.set(VclPtr
<ScrollBar
>::Create(this, (WB_VSCROLL
| WB_DRAG
)));
54 m_pVScroll
->SetScrollHdl(aLink
);
58 if ( mbHasHoriBar
|| mbHasVertBar
)
60 SetStyle( GetStyle() | WB_CLIPCHILDREN
);
63 mnScrWidth
= Application::GetSettings().GetStyleSettings().GetScrollBarSize();
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
) )
70 EnableChildTransparentMode();
73 void TabPage::ImplInitSettings()
75 vcl::Window
* pParent
= GetParent();
76 if (pParent
&& pParent
->IsChildTransparentModeEnabled() && !IsControlBackground())
78 EnableChildTransparentMode();
79 SetParentClipMode( ParentClipMode::NoClip
);
80 SetPaintTransparent( true );
85 EnableChildTransparentMode( false );
87 SetPaintTransparent( false );
89 if (IsControlBackground() || !pParent
)
90 SetBackground( GetControlBackground() );
92 SetBackground( pParent
->GetBackground() );
96 TabPage::TabPage( vcl::Window
* pParent
, WinBits nStyle
) :
97 Window( WindowType::TABPAGE
)
99 ImplInit( pParent
, nStyle
);
107 void TabPage::dispose()
109 m_pVScroll
.disposeAndClear();
110 m_pHScroll
.disposeAndClear();
111 vcl::Window::dispose();
114 void TabPage::StateChanged( StateChangedType nType
)
116 Window::StateChanged( nType
);
118 if ( nType
== StateChangedType::InitShow
)
120 if (GetSettings().GetStyleSettings().GetAutoMnemonic())
121 GenerateAutoMnemonicsOnHierarchy(this);
122 // FIXME: no layouting, workaround some clipping issues
123 ImplAdjustNWFSizes();
125 else if ( nType
== StateChangedType::ControlBackground
)
132 void TabPage::DataChanged( const DataChangedEvent
& rDCEvt
)
134 Window::DataChanged( rDCEvt
);
136 if ( (rDCEvt
.GetType() == DataChangedEventType::SETTINGS
) &&
137 (rDCEvt
.GetFlags() & AllSettingsFlags::STYLE
) )
144 void TabPage::Paint( vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& )
146 // draw native tabpage only inside tabcontrols, standalone tabpages look ugly (due to bad dialog design)
147 if( !(IsNativeControlSupported(ControlType::TabBody
, ControlPart::Entire
) && GetParent() && (GetParent()->GetType() == WindowType::TABCONTROL
)) )
150 const ImplControlValue aControlValue
;
152 ControlState nState
= ControlState::ENABLED
;
154 nState
&= ~ControlState::ENABLED
;
156 nState
|= ControlState::FOCUSED
;
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() );
160 rRenderContext
.DrawNativeControl( ControlType::TabBody
, ControlPart::Entire
, aCtrlRegion
, nState
,
161 aControlValue
, OUString() );
164 void TabPage::Draw( OutputDevice
* pDev
, const Point
& rPos
, SystemTextColorFlags
)
166 Point aPos
= pDev
->LogicToPixel( rPos
);
167 Size aSize
= GetSizePixel();
169 Wallpaper aWallpaper
= GetBackground();
170 if ( !aWallpaper
.IsBitmap() )
175 pDev
->SetLineColor();
177 if ( aWallpaper
.IsBitmap() )
178 pDev
->DrawBitmapEx( aPos
, aSize
, aWallpaper
.GetBitmap() );
181 if( aWallpaper
.GetColor() == COL_AUTO
)
182 pDev
->SetFillColor( GetSettings().GetStyleSettings().GetDialogColor() );
184 pDev
->SetFillColor( aWallpaper
.GetColor() );
185 pDev
->DrawRect( tools::Rectangle( aPos
, aSize
) );
191 Size
TabPage::GetOptimalSize() const
193 if (isLayoutEnabled(this))
194 return VclContainer::getLayoutRequisition(*GetWindow(GetWindowType::FirstChild
));
195 return getLegacyBestSizeForChildren(*this);
198 void TabPage::SetPosSizePixel(const Point
& rAllocPos
, const Size
& rAllocation
)
200 Window::SetPosSizePixel(rAllocPos
, rAllocation
);
201 if (isLayoutEnabled(this) && rAllocation
.Width() && rAllocation
.Height())
202 VclContainer::setLayoutAllocation(*GetWindow(GetWindowType::FirstChild
), Point(0, 0), rAllocation
);
205 void TabPage::SetSizePixel(const Size
& rAllocation
)
207 Window::SetSizePixel(rAllocation
);
208 if (isLayoutEnabled(this) && rAllocation
.Width() && rAllocation
.Height())
209 VclContainer::setLayoutAllocation(*GetWindow(GetWindowType::FirstChild
), Point(0, 0), rAllocation
);
212 void TabPage::SetPosPixel(const Point
& rAllocPos
)
214 Window::SetPosPixel(rAllocPos
);
215 Size
aAllocation(GetOutputSizePixel());
216 if (isLayoutEnabled(this) && aAllocation
.Width() && aAllocation
.Height())
218 VclContainer::setLayoutAllocation(*GetWindow(GetWindowType::FirstChild
), Point(0, 0), aAllocation
);
222 void TabPage::lcl_Scroll( tools::Long nX
, tools::Long nY
)
224 tools::Long nXScroll
= mnScrollPos
.X() - nX
;
225 tools::Long nYScroll
= mnScrollPos
.Y() - nY
;
226 mnScrollPos
= Point( nX
, nY
);
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
)
233 vcl::Window
* pChild
= GetChild( index
);
234 if ( pChild
&& pChild
!= m_pVScroll
.get() && pChild
!= m_pHScroll
.get() )
236 Point aPos
= pChild
->GetPosPixel();
237 aPos
+= Point( nXScroll
, nYScroll
);
238 pChild
->SetPosPixel( aPos
);
243 IMPL_LINK( TabPage
, ScrollBarHdl
, ScrollBar
*, pSB
, void )
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() );
252 void TabPage::SetScrollTop( tools::Long nTop
)
254 Point aOld
= mnScrollPos
;
255 lcl_Scroll( mnScrollPos
.X() , mnScrollPos
.Y() - nTop
);
257 m_pHScroll
->SetThumbPos( 0 );
261 void TabPage::SetScrollLeft( tools::Long nLeft
)
263 Point aOld
= mnScrollPos
;
264 lcl_Scroll( mnScrollPos
.X() - nLeft
, mnScrollPos
.Y() );
266 m_pVScroll
->SetThumbPos( 0 );
271 void TabPage::SetScrollWidth( tools::Long nWidth
)
273 maScrollArea
.setWidth( nWidth
);
277 void TabPage::SetScrollHeight( tools::Long nHeight
)
279 maScrollArea
.setHeight( nHeight
);
283 void TabPage::Resize()
288 void TabPage::ResetScrollBars()
290 Size aOutSz
= GetOutputSizePixel();
292 Point
aVPos( aOutSz
.Width() - mnScrWidth
, 0 );
293 Point
aHPos( 0, aOutSz
.Height() - mnScrWidth
);
297 m_pVScroll
->SetPosSizePixel( aVPos
, Size( mnScrWidth
, GetSizePixel().Height() - mnScrWidth
) );
298 m_pVScroll
->SetRangeMax( maScrollArea
.Height() + mnScrWidth
);
299 m_pVScroll
->SetVisibleSize( GetSizePixel().Height() );
304 m_pHScroll
->SetPosSizePixel( aHPos
, Size( GetSizePixel().Width() - mnScrWidth
, mnScrWidth
) );
305 m_pHScroll
->SetRangeMax( maScrollArea
.Width() + mnScrWidth
);
306 m_pHScroll
->SetVisibleSize( GetSizePixel().Width() );
310 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */