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/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>
26 
27 void TabPage::ImplInit( vcl::Window* pParent, WinBits nStyle )
28 {
29  if ( !(nStyle & WB_NODIALOGCONTROL) )
30  nStyle |= WB_DIALOGCONTROL;
31 
32  Window::ImplInit( pParent, nStyle, nullptr );
33 
35 
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) )
40 }
41 
43 {
44  vcl::Window* pParent = GetParent();
45  if (pParent && pParent->IsChildTransparentModeEnabled() && !IsControlBackground())
46  {
49  SetPaintTransparent( true );
50  SetBackground();
51  }
52  else
53  {
56  SetPaintTransparent( false );
57 
58  if (IsControlBackground() || !pParent)
60  else
61  SetBackground( pParent->GetBackground() );
62  }
63 }
64 
65 TabPage::TabPage( vcl::Window* pParent, WinBits nStyle ) :
67  , IContext()
68 {
69  ImplInit( pParent, nStyle );
70 }
71 
73 {
74  disposeOnce();
75 }
76 
78 {
79  Window::StateChanged( nType );
80 
81  if ( nType == StateChangedType::InitShow )
82  {
83  if (GetSettings().GetStyleSettings().GetAutoMnemonic())
84  Accelerator::GenerateAutoMnemonicsOnHierarchy(this);
85  // FIXME: no layouting, workaround some clipping issues
87  }
88  else if ( nType == StateChangedType::ControlBackground )
89  {
91  Invalidate();
92  }
93 }
94 
96 {
97  Window::DataChanged( rDCEvt );
98 
99  if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
100  (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
101  {
103  Invalidate();
104  }
105 }
106 
107 void TabPage::Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& )
108 {
109  // draw native tabpage only inside tabcontrols, standalone tabpages look ugly (due to bad dialog design)
110  if( !(IsNativeControlSupported(ControlType::TabBody, ControlPart::Entire) && GetParent() && (GetParent()->GetType() == WindowType::TABCONTROL)) )
111  return;
112 
113  const ImplControlValue aControlValue;
114 
116  if ( !IsEnabled() )
117  nState &= ~ControlState::ENABLED;
118  if ( HasFocus() )
119  nState |= ControlState::FOCUSED;
120  // pass the whole window region to NWF as the tab body might be a gradient or bitmap
121  // that has to be scaled properly, clipping makes sure that we do not paint too much
122  tools::Rectangle aCtrlRegion( Point(), GetOutputSizePixel() );
123  rRenderContext.DrawNativeControl( ControlType::TabBody, ControlPart::Entire, aCtrlRegion, nState,
124  aControlValue, OUString() );
125 }
126 
127 void TabPage::Draw( OutputDevice* pDev, const Point& rPos, DrawFlags )
128 {
129  Point aPos = pDev->LogicToPixel( rPos );
130  Size aSize = GetSizePixel();
131 
132  Wallpaper aWallpaper = GetBackground();
133  if ( !aWallpaper.IsBitmap() )
135 
136  pDev->Push();
137  pDev->SetMapMode();
138  pDev->SetLineColor();
139 
140  if ( aWallpaper.IsBitmap() )
141  pDev->DrawBitmapEx( aPos, aSize, aWallpaper.GetBitmap() );
142  else
143  {
144  if( aWallpaper.GetColor() == COL_AUTO )
145  pDev->SetFillColor( GetSettings().GetStyleSettings().GetDialogColor() );
146  else
147  pDev->SetFillColor( aWallpaper.GetColor() );
148  pDev->DrawRect( tools::Rectangle( aPos, aSize ) );
149  }
150 
151  pDev->Pop();
152 }
153 
155 {
156  if (isLayoutEnabled(this))
158  return getLegacyBestSizeForChildren(*this);
159 }
160 
161 void TabPage::SetPosSizePixel(const Point& rAllocPos, const Size& rAllocation)
162 {
163  Window::SetPosSizePixel(rAllocPos, rAllocation);
164  if (isLayoutEnabled(this) && rAllocation.Width() && rAllocation.Height())
166 }
167 
168 void TabPage::SetSizePixel(const Size& rAllocation)
169 {
170  Window::SetSizePixel(rAllocation);
171  if (isLayoutEnabled(this) && rAllocation.Width() && rAllocation.Height())
173 }
174 
175 void TabPage::SetPosPixel(const Point& rAllocPos)
176 {
177  Window::SetPosPixel(rAllocPos);
178  Size aAllocation(GetOutputSizePixel());
179  if (isLayoutEnabled(this) && aAllocation.Width() && aAllocation.Height())
180  {
182  }
183 }
184 
185 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
long Width() const
bool IsControlBackground() const
Definition: window2.cxx:1087
const Wallpaper & GetBackground() const
Definition: outdev.hxx:643
static void setLayoutAllocation(vcl::Window &rWindow, const Point &rPos, const Size &rSize)
Definition: layout.cxx:68
virtual void ImplAdjustNWFSizes()
Definition: window3.cxx:38
long Height() const
WinBits const WB_NODIALOGCONTROL
void DrawBitmapEx(const Point &rDestPt, const BitmapEx &rBitmapEx)
This is an overloaded member function, provided for convenience. It differs from the above function o...
static Size getLayoutRequisition(const vcl::Window &rWindow)
Definition: layout.cxx:143
virtual Size GetSizePixel() const
Definition: window.cxx:2395
void SetParentClipMode(ParentClipMode nMode=ParentClipMode::NONE)
DataChangedEventType GetType() const
Definition: event.hxx:357
const Color & GetControlBackground() const
Definition: window2.cxx:1082
virtual void DataChanged(const DataChangedEvent &rDCEvt) override
Definition: tabpage.cxx:95
bool IsNativeControlSupported(ControlType nType, ControlPart nPart) const
Query the platform layer for control support.
void SetMapMode()
Definition: map.cxx:654
virtual ~TabPage() override
Definition: tabpage.cxx:72
StateChangedType
Definition: window.hxx:317
constexpr::Color COL_AUTO(0xFF, 0xFF, 0xFF, 0xFF)
SAL_DLLPRIVATE void ImplInit(vcl::Window *pParent, WinBits nStyle)
Definition: tabpage.cxx:27
sal_Int64 WinBits
void SetBackground()
virtual void Draw(OutputDevice *pDev, const Point &rPos, DrawFlags nFlags) override
Definition: tabpage.cxx:127
AllSettingsFlags GetFlags() const
Definition: event.hxx:358
bool IsChildTransparentModeEnabled() const
Definition: window2.cxx:1027
void DrawRect(const tools::Rectangle &rRect)
Definition: rect.cxx:51
WinBits const WB_DIALOGCONTROL
Size getLegacyBestSizeForChildren(const vcl::Window &rWindow)
Definition: layout.cxx:2779
void SetLineColor()
DrawFlags
Definition: window.hxx:360
virtual void StateChanged(StateChangedType nStateChange) override
Definition: tabpage.cxx:77
const Color & GetColor() const
Definition: wall.cxx:204
virtual void Invalidate(InvalidateFlags nFlags=InvalidateFlags::NONE)
Definition: paint.cxx:1162
void SetFillColor()
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:302
bool isLayoutEnabled(const vcl::Window *pWindow)
Definition: layout.cxx:2841
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.
const AllSettings & GetSettings() const
Definition: outdev.hxx:418
void SetPaintTransparent(bool bTransparent)
Definition: paint.cxx:1024
Size GetOutputSizePixel() const
Definition: outdev.hxx:441
virtual void SetPosSizePixel(const Point &rNewPos, const Size &rNewSize) override
Definition: tabpage.cxx:161
vcl::Window * GetParent() const
Definition: window2.cxx:1097
virtual void SetSizePixel(const Size &rNewSize) override
Definition: tabpage.cxx:168
vcl::Window * GetWindow(GetWindowType nType) const
Definition: stacking.cxx:1039
Point LogicToPixel(const Point &rLogicPt) const
Definition: map.cxx:941
BitmapEx GetBitmap() const
Definition: wall.cxx:247
WindowType
void EnableChildTransparentMode(bool bEnable=true)
Definition: window2.cxx:1022
SAL_DLLPRIVATE void ImplInitSettings()
Definition: tabpage.cxx:42
virtual void SetPosPixel(const Point &rNewPos) override
Definition: tabpage.cxx:175
bool IsBitmap() const
Definition: wall.cxx:255
WindowType GetType() const
Definition: window2.cxx:974
TabPage(vcl::Window *pParent, WinBits nStyle=0)
Definition: tabpage.cxx:65
bool IsEnabled() const
Definition: window2.cxx:1122
bool HasFocus() const
Definition: window.cxx:2965
void Push(PushFlags nFlags=PushFlags::ALL)
Definition: outdevstate.cxx:60
sal_Int32 nState
virtual Size GetOptimalSize() const override
Definition: tabpage.cxx:154
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect) override
Definition: tabpage.cxx:107