LibreOffice Module svx (master)  1
PanelLayout.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 
10 #include <com/sun/star/util/URL.hpp>
11 #include <com/sun/star/util/URLTransformer.hpp>
13 #include <sfx2/sidebar/TabBar.hxx>
15 #include <vcl/layout.hxx>
16 #include <vcl/accel.hxx>
17 
18 using namespace sfx2::sidebar;
19 
20 PanelLayout::PanelLayout(vcl::Window* pParent, const OString& rID, const OUString& rUIXMLDescription,
21  const css::uno::Reference<css::frame::XFrame> &rFrame, bool bInterimBuilder)
22  : Control(pParent)
23  , m_bInClose(false)
24  , mxFrame(rFrame)
25 {
27  m_aPanelLayoutIdle.SetPriority(TaskPriority::RESIZE);
28  m_aPanelLayoutIdle.SetInvokeHandler( LINK( this, PanelLayout, ImplHandlePanelLayoutTimerHdl ) );
29  m_aPanelLayoutIdle.SetDebugName("svx::PanelLayout m_aPanelLayoutIdle");
30 
31  // VclBuilder will trigger resize and start Idle
32  if (!bInterimBuilder)
33  m_pUIBuilder.reset(new VclBuilder(this, getUIRootDir(), rUIXMLDescription, rID, rFrame));
34  else
35  m_xBuilder.reset(Application::CreateInterimBuilder(this, rUIXMLDescription));
36  if (GetSettings().GetStyleSettings().GetAutoMnemonic())
38 }
39 
41 {
42  disposeOnce();
43 }
44 
46 {
47  m_bInClose = true;
49  m_xBuilder.reset();
52 }
53 
55 {
56  if (isLayoutEnabled(this))
57  {
58  Size aSize = VclContainer::getLayoutRequisition(*GetWindow(GetWindowType::FirstChild));
59  if (mxFrame)
60  {
61  SidebarController* pController
62  = SidebarController::GetSidebarControllerForFrame(mxFrame);
63  if (pController)
64  aSize.setWidth(std::min<long>(
65  aSize.Width(), (pController->getMaximumWidth() - TabBar::GetDefaultWidth())
66  * GetDPIScaleFactor()));
67  }
68 
69  return aSize;
70  }
71 
72  return Control::GetOptimalSize();
73 }
74 
76 {
77  if (m_bInClose)
78  return;
80  return;
81  if (!isLayoutEnabled(this))
82  return;
85 }
86 
87 IMPL_LINK_NOARG( PanelLayout, ImplHandlePanelLayoutTimerHdl, Timer*, void )
88 {
89  vcl::Window *pChild = GetWindow(GetWindowType::FirstChild);
90  assert(pChild);
91  VclContainer::setLayoutAllocation(*pChild, Point(0, 0), GetSizePixel());
92 }
93 
94 void PanelLayout::setPosSizePixel(long nX, long nY, long nWidth, long nHeight, PosSizeFlags nFlags)
95 {
96  bool bCanHandleSmallerWidth = false;
97  bool bCanHandleSmallerHeight = false;
98 
99  bool bIsLayoutEnabled = isLayoutEnabled(this);
100  vcl::Window *pChild = GetWindow(GetWindowType::FirstChild);
101 
102  if (bIsLayoutEnabled && pChild->GetType() == WindowType::SCROLLWINDOW)
103  {
104  WinBits nStyle = pChild->GetStyle();
105  if (nStyle & (WB_AUTOHSCROLL | WB_HSCROLL))
106  bCanHandleSmallerWidth = true;
107  if (nStyle & (WB_AUTOVSCROLL | WB_VSCROLL))
108  bCanHandleSmallerHeight = true;
109  }
110 
111  Size aSize(GetOptimalSize());
112  if (!bCanHandleSmallerWidth)
113  nWidth = std::max(nWidth,aSize.Width());
114  if (!bCanHandleSmallerHeight)
115  nHeight = std::max(nHeight,aSize.Height());
116 
117  Control::setPosSizePixel(nX, nY, nWidth, nHeight, nFlags);
118 
119  if (bIsLayoutEnabled && (nFlags & PosSizeFlags::Size))
120  VclContainer::setLayoutAllocation(*pChild, Point(0, 0), Size(nWidth, nHeight));
121 }
122 
124 {
125  if (rNEvt.GetType() == MouseNotifyEvent::COMMAND)
127  return Control::EventNotify( rNEvt );
128 }
129 
130 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual ~PanelLayout() override
Definition: PanelLayout.cxx:40
long Width() const
static void setLayoutAllocation(vcl::Window &rWindow, const Point &rPos, const Size &rSize)
This class is the base for the Widget Layout-based sidebar panels.
Definition: PanelLayout.hxx:24
const CommandEvent * GetCommandEvent() const
long Height() const
static Size getLayoutRequisition(const vcl::Window &rWindow)
void InvalidateSizeCache()
WinBits const WB_AUTOVSCROLL
PosSizeFlags
WinBits const WB_VSCROLL
PanelLayout(vcl::Window *pParent, const OString &rID, const OUString &rUIXMLDescription, const css::uno::Reference< css::frame::XFrame > &rFrame, bool bInterimBuilder=false)
Definition: PanelLayout.cxx:20
virtual Size GetOptimalSize() const override
Definition: PanelLayout.cxx:54
bool IsActive() const
StateChangedType
std::unique_ptr< weld::Builder > m_xBuilder
Definition: PanelLayout.hxx:27
virtual void setPosSizePixel(long nX, long nY, long nWidth, long nHeight, PosSizeFlags nFlags=PosSizeFlags::All)
sal_Int64 WinBits
WinBits const WB_HSCROLL
virtual void Start() override
IMPL_LINK_NOARG(PanelLayout, ImplHandlePanelLayoutTimerHdl, Timer *, void)
Definition: PanelLayout.cxx:87
WinBits const WB_DIALOGCONTROL
static bool ToggleMnemonicsOnHierarchy(const CommandEvent &rCEvent, const vcl::Window *pWindow)
css::uno::Reference< css::frame::XFrame > mxFrame
Definition: PanelLayout.hxx:33
static weld::Builder * CreateInterimBuilder(vcl::Window *pParent, const OUString &rUIFile)
std::unique_ptr< VclBuilder > m_pUIBuilder
bool isLayoutEnabled(const vcl::Window *pWindow)
MouseNotifyEvent GetType() const
virtual void dispose() override
virtual bool EventNotify(NotifyEvent &rNEvt) override
const AllSettings & GetSettings() const
static OUString getUIRootDir()
virtual void setPosSizePixel(long nX, long nY, long nWidth, long nHeight, PosSizeFlags nFlags=PosSizeFlags::All) override
Definition: PanelLayout.cxx:94
void SetStyle(WinBits nStyle)
float GetDPIScaleFactor() const
vcl::Window * GetWindow(GetWindowType nType) const
virtual void dispose() override
Definition: PanelLayout.cxx:45
virtual Size GetOptimalSize() const override
void Stop()
void SetInvokeHandler(const Link< Timer *, void > &rLink)
WinBits const WB_AUTOHSCROLL
virtual void queue_resize(StateChangedType eReason=StateChangedType::Layout) override
Definition: PanelLayout.cxx:75
WindowType GetType() const
static void GenerateAutoMnemonicsOnHierarchy(const vcl::Window *pWindow)
WinBits GetStyle() const
void SetPriority(TaskPriority ePriority)
Idle m_aPanelLayoutIdle
Definition: PanelLayout.hxx:31
void setWidth(long nWidth)
sal_Int32 getMaximumWidth() const
void SetDebugName(const sal_Char *pDebugName)
virtual bool EventNotify(NotifyEvent &rNEvt) override