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 
72 TabPage::TabPage(vcl::Window *pParent, const OString& rID, const OUString& rUIXMLDescription)
74  , IContext()
75 {
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);
81 }
82 
84 {
85  disposeOnce();
86 }
87 
89 {
92 }
93 
95 {
96  Window::StateChanged( nType );
97 
98  if ( nType == StateChangedType::InitShow )
99  {
100  if (GetSettings().GetStyleSettings().GetAutoMnemonic())
102  // FIXME: no layouting, workaround some clipping issues
104  }
105  else if ( nType == StateChangedType::ControlBackground )
106  {
108  Invalidate();
109  }
110 }
111 
113 {
114  Window::DataChanged( rDCEvt );
115 
116  if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
117  (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
118  {
120  Invalidate();
121  }
122 }
123 
124 void TabPage::Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& )
125 {
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) )
128  {
129  const ImplControlValue aControlValue;
130 
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() );
141  }
142 }
143 
144 void TabPage::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, DrawFlags )
145 {
146  Point aPos = pDev->LogicToPixel( rPos );
147  Size aSize = pDev->LogicToPixel( rSize );
148 
149  Wallpaper aWallpaper = GetBackground();
150  if ( !aWallpaper.IsBitmap() )
152 
153  pDev->Push();
154  pDev->SetMapMode();
155  pDev->SetLineColor();
156 
157  if ( aWallpaper.IsBitmap() )
158  pDev->DrawBitmapEx( aPos, aSize, aWallpaper.GetBitmap() );
159  else
160  {
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 ) );
166  }
167 
168  pDev->Pop();
169 }
170 
172 {
173 }
174 
176 {
177 }
178 
180 {
181  if (isLayoutEnabled(this))
183  return getLegacyBestSizeForChildren(*this);
184 }
185 
186 void TabPage::SetPosSizePixel(const Point& rAllocPos, const Size& rAllocation)
187 {
188  Window::SetPosSizePixel(rAllocPos, rAllocation);
189  if (isLayoutEnabled(this) && rAllocation.Width() && rAllocation.Height())
191 }
192 
193 void TabPage::SetSizePixel(const Size& rAllocation)
194 {
195  Window::SetSizePixel(rAllocation);
196  if (isLayoutEnabled(this) && rAllocation.Width() && rAllocation.Height())
198 }
199 
200 void TabPage::SetPosPixel(const Point& rAllocPos)
201 {
202  Window::SetPosPixel(rAllocPos);
203  Size aAllocation(GetOutputSizePixel());
204  if (isLayoutEnabled(this) && aAllocation.Width() && aAllocation.Height())
205  {
207  }
208 }
209 
210 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
long Width() const
bool IsControlBackground() const
Definition: window2.cxx:1081
const Wallpaper & GetBackground() const
Definition: outdev.hxx:631
static void setLayoutAllocation(vcl::Window &rWindow, const Point &rPos, const Size &rSize)
Definition: layout.cxx:63
bool DrawNativeControl(ControlType nType, ControlPart nPart, const tools::Rectangle &rControlRegion, ControlState nState, const ImplControlValue &aValue, const OUString &aCaption)
Request rendering of a particular control and/or part.
SAL_DLLPRIVATE 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:138
void SetParentClipMode(ParentClipMode nMode=ParentClipMode::NONE)
DataChangedEventType GetType() const
Definition: event.hxx:348
const Color & GetControlBackground() const
Definition: window2.cxx:1076
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
Definition: window.cxx:140
virtual void DataChanged(const DataChangedEvent &rDCEvt) override
Definition: tabpage.cxx:112
bool IsNativeControlSupported(ControlType nType, ControlPart nPart) const
Query the platform layer for control support.
void SetMapMode()
Definition: map.cxx:655
virtual ~TabPage() override
Definition: tabpage.cxx:83
StateChangedType
Definition: window.hxx:309
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()
AllSettingsFlags GetFlags() const
Definition: event.hxx:349
void set_vexpand(bool bExpand)
Definition: window2.cxx:1706
virtual void ActivatePage()
Definition: tabpage.cxx:171
bool IsChildTransparentModeEnabled() const
Definition: window2.cxx:1021
void DrawRect(const tools::Rectangle &rRect)
Definition: rect.cxx:32
WinBits const WB_DIALOGCONTROL
Size getLegacyBestSizeForChildren(const vcl::Window &rWindow)
Definition: layout.cxx:2604
void SetLineColor()
DrawFlags
Definition: window.hxx:352
virtual void StateChanged(StateChangedType nStateChange) override
Definition: tabpage.cxx:94
const Color & GetColor() const
Definition: wall.cxx:203
virtual void Invalidate(InvalidateFlags nFlags=InvalidateFlags::NONE)
Definition: paint.cxx:1153
void SetFillColor()
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:304
std::unique_ptr< VclBuilder > m_pUIBuilder
Definition: builder.hxx:501
bool isLayoutEnabled(const vcl::Window *pWindow)
Definition: layout.cxx:2666
virtual void Draw(OutputDevice *pDev, const Point &rPos, const Size &rSize, DrawFlags nFlags) override
Definition: tabpage.cxx:144
const AllSettings & GetSettings() const
Definition: outdev.hxx:420
void SetPaintTransparent(bool bTransparent)
Definition: paint.cxx:1015
Size GetOutputSizePixel() const
Definition: outdev.hxx:441
static OUString getUIRootDir()
Definition: dialog.cxx:543
virtual void SetPosSizePixel(const Point &rNewPos, const Size &rNewSize) override
Definition: tabpage.cxx:186
vcl::Window * GetParent() const
Definition: window2.cxx:1091
virtual void SetSizePixel(const Size &rNewSize) override
Definition: tabpage.cxx:193
vcl::Window * GetWindow(GetWindowType nType) const
Definition: stacking.cxx:1035
void disposeBuilder()
Definition: dialog.cxx:537
Point LogicToPixel(const Point &rLogicPt) const
Definition: map.cxx:940
BitmapEx GetBitmap() const
Definition: wall.cxx:246
void set_hexpand(bool bExpand)
Definition: window2.cxx:1694
WindowType
void EnableChildTransparentMode(bool bEnable=true)
Definition: window2.cxx:1016
SAL_DLLPRIVATE void ImplInitSettings()
Definition: tabpage.cxx:42
virtual void SetPosPixel(const Point &rNewPos) override
Definition: tabpage.cxx:200
bool IsBitmap() const
Definition: wall.cxx:254
WindowType GetType() const
Definition: window2.cxx:968
TabPage(vcl::Window *pParent, WinBits nStyle=0)
Definition: tabpage.cxx:65
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
Definition: tabpage.cxx:88
bool IsEnabled() const
Definition: window2.cxx:1116
static void GenerateAutoMnemonicsOnHierarchy(const vcl::Window *pWindow)
Definition: dialog.cxx:199
virtual void DeactivatePage()
Definition: tabpage.cxx:175
bool HasFocus() const
Definition: window.cxx:2985
void Push(PushFlags nFlags=PushFlags::ALL)
Definition: outdevstate.cxx:60
virtual Size GetOptimalSize() const override
Definition: tabpage.cxx:179
void set_expand(bool bExpand)
Definition: window2.cxx:1718
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect) override
Definition: tabpage.cxx:124