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 .
22 #include <vcl/event.hxx>
23 #include <vcl/layout.hxx>
24 #include <vcl/svapp.hxx>
25 #include <vcl/tabpage.hxx>
26 #include <vcl/tabctrl.hxx>
27 #include <vcl/bitmapex.hxx>
28 #include <vcl/settings.hxx>
32 #include <com/sun/star/accessibility/XAccessible.hpp>
34 void TabPage::ImplInit( vcl::Window
* pParent
, WinBits nStyle
)
36 if ( !(nStyle
& WB_NODIALOGCONTROL
) )
37 nStyle
|= WB_DIALOGCONTROL
;
39 Window::ImplInit( pParent
, nStyle
, nullptr );
43 // if the tabpage is drawn (ie filled) by a native widget, make sure all controls will have transparent background
44 // otherwise they will paint with a wrong background
45 if( IsNativeControlSupported(ControlType::TabBody
, ControlPart::Entire
) && GetParent() && (GetParent()->GetType() == WINDOW_TABCONTROL
) )
46 EnableChildTransparentMode();
49 void TabPage::ImplInitSettings()
51 vcl::Window
* pParent
= GetParent();
52 if ( pParent
->IsChildTransparentModeEnabled() && !IsControlBackground() )
54 EnableChildTransparentMode();
55 SetParentClipMode( ParentClipMode::NoClip
);
56 SetPaintTransparent( true );
61 EnableChildTransparentMode( false );
63 SetPaintTransparent( false );
65 if ( IsControlBackground() )
66 SetBackground( GetControlBackground() );
68 SetBackground( pParent
->GetBackground() );
72 TabPage::TabPage( vcl::Window
* pParent
, WinBits nStyle
) :
73 Window( WINDOW_TABPAGE
)
76 ImplInit( pParent
, nStyle
);
79 TabPage::TabPage(vcl::Window
*pParent
, const OString
& rID
, const OUString
& rUIXMLDescription
)
80 : Window(WINDOW_TABPAGE
)
84 m_pUIBuilder
.reset( new VclBuilder(this, getUIRootDir(), rUIXMLDescription
, rID
) );
95 void TabPage::dispose()
98 vcl::Window::dispose();
101 void TabPage::StateChanged( StateChangedType nType
)
103 Window::StateChanged( nType
);
105 if ( nType
== StateChangedType::InitShow
)
107 if (GetSettings().GetStyleSettings().GetAutoMnemonic())
108 Accelerator::GenerateAutoMnemonicsOnHierarchy(this);
109 // FIXME: no layouting, workaround some clipping issues
110 ImplAdjustNWFSizes();
112 else if ( nType
== StateChangedType::ControlBackground
)
119 void TabPage::DataChanged( const DataChangedEvent
& rDCEvt
)
121 Window::DataChanged( rDCEvt
);
123 if ( (rDCEvt
.GetType() == DataChangedEventType::SETTINGS
) &&
124 (rDCEvt
.GetFlags() & AllSettingsFlags::STYLE
) )
131 void TabPage::Paint( vcl::RenderContext
& rRenderContext
, const Rectangle
& )
133 // draw native tabpage only inside tabcontrols, standalone tabpages look ugly (due to bad dialog design)
134 if( IsNativeControlSupported(ControlType::TabBody
, ControlPart::Entire
) && GetParent() && (GetParent()->GetType() == WINDOW_TABCONTROL
) )
136 const ImplControlValue aControlValue
;
138 ControlState nState
= ControlState::ENABLED
;
139 ControlPart part
= ControlPart::Entire
;
141 nState
&= ~ControlState::ENABLED
;
143 nState
|= ControlState::FOCUSED
;
144 // pass the whole window region to NWF as the tab body might be a gradient or bitmap
145 // that has to be scaled properly, clipping makes sure that we do not paint too much
146 Rectangle
aCtrlRegion( Point(), GetOutputSizePixel() );
147 rRenderContext
.DrawNativeControl( ControlType::TabBody
, part
, aCtrlRegion
, nState
,
148 aControlValue
, OUString() );
152 void TabPage::Draw( OutputDevice
* pDev
, const Point
& rPos
, const Size
& rSize
, DrawFlags
)
154 Point aPos
= pDev
->LogicToPixel( rPos
);
155 Size aSize
= pDev
->LogicToPixel( rSize
);
157 Wallpaper aWallpaper
= GetBackground();
158 if ( !aWallpaper
.IsBitmap() )
163 pDev
->SetLineColor();
165 if ( aWallpaper
.IsBitmap() )
166 pDev
->DrawBitmapEx( aPos
, aSize
, aWallpaper
.GetBitmap() );
169 if( aWallpaper
.GetColor() == COL_AUTO
)
170 pDev
->SetFillColor( GetSettings().GetStyleSettings().GetDialogColor() );
172 pDev
->SetFillColor( aWallpaper
.GetColor() );
173 pDev
->DrawRect( Rectangle( aPos
, aSize
) );
179 void TabPage::ActivatePage()
183 void TabPage::DeactivatePage()
187 OString
TabPage::GetConfigId() const
189 OString
sId(GetHelpId());
190 if (sId
.isEmpty() && isLayoutEnabled(this))
191 sId
= GetWindow(GetWindowType::FirstChild
)->GetHelpId();
195 Size
TabPage::GetOptimalSize() const
197 if (isLayoutEnabled(this))
198 return VclContainer::getLayoutRequisition(*GetWindow(GetWindowType::FirstChild
));
199 return getLegacyBestSizeForChildren(*this);
202 void TabPage::SetPosSizePixel(const Point
& rAllocPos
, const Size
& rAllocation
)
204 Window::SetPosSizePixel(rAllocPos
, rAllocation
);
205 if (isLayoutEnabled(this) && rAllocation
.Width() && rAllocation
.Height())
206 VclContainer::setLayoutAllocation(*GetWindow(GetWindowType::FirstChild
), Point(0, 0), rAllocation
);
209 void TabPage::SetSizePixel(const Size
& rAllocation
)
211 Window::SetSizePixel(rAllocation
);
212 if (isLayoutEnabled(this) && rAllocation
.Width() && rAllocation
.Height())
213 VclContainer::setLayoutAllocation(*GetWindow(GetWindowType::FirstChild
), Point(0, 0), rAllocation
);
216 void TabPage::SetPosPixel(const Point
& rAllocPos
)
218 Window::SetPosPixel(rAllocPos
);
219 Size
aAllocation(GetOutputSizePixel());
220 if (isLayoutEnabled(this) && aAllocation
.Width() && aAllocation
.Height())
222 VclContainer::setLayoutAllocation(*GetWindow(GetWindowType::FirstChild
), Point(0, 0), aAllocation
);
226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */