bump product version to 6.4.0.3
[LibreOffice.git] / vcl / source / window / tabpage.cxx
blobd09ef10d542db2834285bfcdfb40ed2134a65dce
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/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>
27 void TabPage::ImplInit( vcl::Window* pParent, WinBits nStyle )
29 if ( !(nStyle & WB_NODIALOGCONTROL) )
30 nStyle |= WB_DIALOGCONTROL;
32 Window::ImplInit( pParent, nStyle, nullptr );
34 ImplInitSettings();
36 // if the tabpage is drawn (ie filled) by a native widget, make sure all controls will have transparent background
37 // otherwise they will paint with a wrong background
38 if( IsNativeControlSupported(ControlType::TabBody, ControlPart::Entire) && GetParent() && (GetParent()->GetType() == WindowType::TABCONTROL) )
39 EnableChildTransparentMode();
42 void TabPage::ImplInitSettings()
44 vcl::Window* pParent = GetParent();
45 if (pParent && pParent->IsChildTransparentModeEnabled() && !IsControlBackground())
47 EnableChildTransparentMode();
48 SetParentClipMode( ParentClipMode::NoClip );
49 SetPaintTransparent( true );
50 SetBackground();
52 else
54 EnableChildTransparentMode( false );
55 SetParentClipMode();
56 SetPaintTransparent( false );
58 if (IsControlBackground() || !pParent)
59 SetBackground( GetControlBackground() );
60 else
61 SetBackground( pParent->GetBackground() );
65 TabPage::TabPage( vcl::Window* pParent, WinBits nStyle ) :
66 Window( WindowType::TABPAGE )
67 , IContext()
69 ImplInit( pParent, nStyle );
72 TabPage::TabPage(vcl::Window *pParent, const OString& rID, const OUString& rUIXMLDescription)
73 : Window(WindowType::TABPAGE)
74 , IContext()
76 ImplInit(pParent, 0);
77 m_pUIBuilder.reset( new VclBuilder(this, getUIRootDir(), rUIXMLDescription, rID) );
78 set_hexpand(true);
79 set_vexpand(true);
80 set_expand(true);
83 TabPage::~TabPage()
85 disposeOnce();
88 void TabPage::dispose()
90 disposeBuilder();
91 vcl::Window::dispose();
94 void TabPage::StateChanged( StateChangedType nType )
96 Window::StateChanged( nType );
98 if ( nType == StateChangedType::InitShow )
100 if (GetSettings().GetStyleSettings().GetAutoMnemonic())
101 Accelerator::GenerateAutoMnemonicsOnHierarchy(this);
102 // FIXME: no layouting, workaround some clipping issues
103 ImplAdjustNWFSizes();
105 else if ( nType == StateChangedType::ControlBackground )
107 ImplInitSettings();
108 Invalidate();
112 void TabPage::DataChanged( const DataChangedEvent& rDCEvt )
114 Window::DataChanged( rDCEvt );
116 if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
117 (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
119 ImplInitSettings();
120 Invalidate();
124 void TabPage::Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& )
126 // draw native tabpage only inside tabcontrols, standalone tabpages look ugly (due to bad dialog design)
127 if( IsNativeControlSupported(ControlType::TabBody, ControlPart::Entire) && GetParent() && (GetParent()->GetType() == WindowType::TABCONTROL) )
129 const ImplControlValue aControlValue;
131 ControlState nState = ControlState::ENABLED;
132 if ( !IsEnabled() )
133 nState &= ~ControlState::ENABLED;
134 if ( HasFocus() )
135 nState |= ControlState::FOCUSED;
136 // pass the whole window region to NWF as the tab body might be a gradient or bitmap
137 // that has to be scaled properly, clipping makes sure that we do not paint too much
138 tools::Rectangle aCtrlRegion( Point(), GetOutputSizePixel() );
139 rRenderContext.DrawNativeControl( ControlType::TabBody, ControlPart::Entire, aCtrlRegion, nState,
140 aControlValue, OUString() );
144 void TabPage::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, DrawFlags )
146 Point aPos = pDev->LogicToPixel( rPos );
147 Size aSize = pDev->LogicToPixel( rSize );
149 Wallpaper aWallpaper = GetBackground();
150 if ( !aWallpaper.IsBitmap() )
151 ImplInitSettings();
153 pDev->Push();
154 pDev->SetMapMode();
155 pDev->SetLineColor();
157 if ( aWallpaper.IsBitmap() )
158 pDev->DrawBitmapEx( aPos, aSize, aWallpaper.GetBitmap() );
159 else
161 if( aWallpaper.GetColor() == COL_AUTO )
162 pDev->SetFillColor( GetSettings().GetStyleSettings().GetDialogColor() );
163 else
164 pDev->SetFillColor( aWallpaper.GetColor() );
165 pDev->DrawRect( tools::Rectangle( aPos, aSize ) );
168 pDev->Pop();
171 void TabPage::ActivatePage()
175 Size TabPage::GetOptimalSize() const
177 if (isLayoutEnabled(this))
178 return VclContainer::getLayoutRequisition(*GetWindow(GetWindowType::FirstChild));
179 return getLegacyBestSizeForChildren(*this);
182 void TabPage::SetPosSizePixel(const Point& rAllocPos, const Size& rAllocation)
184 Window::SetPosSizePixel(rAllocPos, rAllocation);
185 if (isLayoutEnabled(this) && rAllocation.Width() && rAllocation.Height())
186 VclContainer::setLayoutAllocation(*GetWindow(GetWindowType::FirstChild), Point(0, 0), rAllocation);
189 void TabPage::SetSizePixel(const Size& rAllocation)
191 Window::SetSizePixel(rAllocation);
192 if (isLayoutEnabled(this) && rAllocation.Width() && rAllocation.Height())
193 VclContainer::setLayoutAllocation(*GetWindow(GetWindowType::FirstChild), Point(0, 0), rAllocation);
196 void TabPage::SetPosPixel(const Point& rAllocPos)
198 Window::SetPosPixel(rAllocPos);
199 Size aAllocation(GetOutputSizePixel());
200 if (isLayoutEnabled(this) && aAllocation.Width() && aAllocation.Height())
202 VclContainer::setLayoutAllocation(*GetWindow(GetWindowType::FirstChild), Point(0, 0), aAllocation);
206 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */