bump product version to 7.6.3.2-android
[LibreOffice.git] / vcl / source / window / tabpage.cxx
blob5a83165eb1af3282dce9d413af41555c5a76023f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
26 #include <svdata.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 );
35 mbHasHoriBar = false;
36 mbHasVertBar = false;
38 Link<ScrollBar*,void> aLink( LINK( this, TabPage, ScrollBarHdl ) );
40 if ( nStyle & ( WB_AUTOHSCROLL | WB_AUTOVSCROLL ) )
42 if ( nStyle & WB_AUTOHSCROLL )
44 mbHasHoriBar = true;
45 m_pHScroll.set(VclPtr<ScrollBar>::Create(this, (WB_HSCROLL | WB_DRAG)));
46 m_pHScroll->Show();
47 m_pHScroll->SetScrollHdl(aLink);
49 if ( nStyle & WB_AUTOVSCROLL )
51 mbHasVertBar = true;
52 m_pVScroll.set(VclPtr<ScrollBar>::Create(this, (WB_VSCROLL | WB_DRAG)));
53 m_pVScroll->Show();
54 m_pVScroll->SetScrollHdl(aLink);
58 if ( mbHasHoriBar || mbHasVertBar )
60 SetStyle( GetStyle() | WB_CLIPCHILDREN );
63 mnScrWidth = Application::GetSettings().GetStyleSettings().GetScrollBarSize();
65 ImplInitSettings();
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 );
81 SetBackground();
83 else
85 EnableChildTransparentMode( false );
86 SetParentClipMode();
87 SetPaintTransparent( false );
89 if (IsControlBackground() || !pParent)
90 SetBackground( GetControlBackground() );
91 else
92 SetBackground( pParent->GetBackground() );
96 TabPage::TabPage( vcl::Window* pParent, WinBits nStyle ) :
97 Window( WindowType::TABPAGE )
99 ImplInit( pParent, nStyle );
102 TabPage::~TabPage()
104 disposeOnce();
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 )
127 ImplInitSettings();
128 Invalidate();
132 void TabPage::DataChanged( const DataChangedEvent& rDCEvt )
134 Window::DataChanged( rDCEvt );
136 if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
137 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
139 ImplInitSettings();
140 Invalidate();
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)) )
148 return;
150 const ImplControlValue aControlValue;
152 ControlState nState = ControlState::ENABLED;
153 if ( !IsEnabled() )
154 nState &= ~ControlState::ENABLED;
155 if ( HasFocus() )
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() )
171 ImplInitSettings();
173 pDev->Push();
174 pDev->SetMapMode();
175 pDev->SetLineColor();
177 if ( aWallpaper.IsBitmap() )
178 pDev->DrawBitmapEx( aPos, aSize, aWallpaper.GetBitmap() );
179 else
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 ) );
188 pDev->Pop();
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 );
256 if( m_pHScroll )
257 m_pHScroll->SetThumbPos( 0 );
258 // new pos is 0,0
259 mnScrollPos = aOld;
261 void TabPage::SetScrollLeft( tools::Long nLeft )
263 Point aOld = mnScrollPos;
264 lcl_Scroll( mnScrollPos.X() - nLeft , mnScrollPos.Y() );
265 if( m_pVScroll )
266 m_pVScroll->SetThumbPos( 0 );
267 // new pos is 0,0
268 mnScrollPos = aOld;
271 void TabPage::SetScrollWidth( tools::Long nWidth )
273 maScrollArea.setWidth( nWidth );
274 ResetScrollBars();
277 void TabPage::SetScrollHeight( tools::Long nHeight )
279 maScrollArea.setHeight( nHeight );
280 ResetScrollBars();
283 void TabPage::Resize()
285 ResetScrollBars();
288 void TabPage::ResetScrollBars()
290 Size aOutSz = GetOutputSizePixel();
292 Point aVPos( aOutSz.Width() - mnScrWidth, 0 );
293 Point aHPos( 0, aOutSz.Height() - mnScrWidth );
295 if( m_pVScroll )
297 m_pVScroll->SetPosSizePixel( aVPos, Size( mnScrWidth, GetSizePixel().Height() - mnScrWidth ) );
298 m_pVScroll->SetRangeMax( maScrollArea.Height() + mnScrWidth );
299 m_pVScroll->SetVisibleSize( GetSizePixel().Height() );
302 if( m_pHScroll )
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: */