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/.
10 #include <sfx2/sidebar/SidebarController.hxx>
11 #include <sfx2/sidebar/TabBar.hxx>
12 #include <sfx2/sidebar/PanelLayout.hxx>
13 #include <vcl/layout.hxx>
14 #include <vcl/accel.hxx>
16 using namespace sfx2::sidebar
;
18 PanelLayout::PanelLayout(vcl::Window
* pParent
, const OString
& rID
, const OUString
& rUIXMLDescription
,
19 const css::uno::Reference
<css::frame::XFrame
> &rFrame
)
21 , m_pInitialFocusWidget(nullptr)
25 m_aPanelLayoutIdle
.SetPriority(TaskPriority::RESIZE
);
26 m_aPanelLayoutIdle
.SetInvokeHandler( LINK( this, PanelLayout
, ImplHandlePanelLayoutTimerHdl
) );
27 m_aPanelLayoutIdle
.SetDebugName("sfx2::PanelLayout m_aPanelLayoutIdle");
29 SetStyle(GetStyle() | WB_DIALOGCONTROL
);
31 // Builder will trigger resize and start Idle
32 m_xVclContentArea
= VclPtr
<VclVBox
>::Create(this);
33 m_xVclContentArea
->Show();
34 m_xBuilder
.reset(Application::CreateInterimBuilder(m_xVclContentArea
, rUIXMLDescription
, true));
35 m_xContainer
= m_xBuilder
->weld_container(rID
);
38 void PanelLayout::GetFocus()
41 if (m_pInitialFocusWidget
)
42 m_pInitialFocusWidget
->grab_focus();
45 PanelLayout::~PanelLayout()
50 void PanelLayout::dispose()
53 m_pInitialFocusWidget
= nullptr;
54 m_aPanelLayoutIdle
.Stop();
57 m_xVclContentArea
.disposeAndClear();
61 Size
PanelLayout::GetOptimalSize() const
63 Size aSize
= m_xContainer
->get_preferred_size();
67 SidebarController
* pController
68 = SidebarController::GetSidebarControllerForFrame(mxFrame
);
70 aSize
.setWidth(std::min
<tools::Long
>(
71 aSize
.Width(), (pController
->getMaximumWidth() - TabBar::GetDefaultWidth())
72 * GetDPIScaleFactor()));
78 void PanelLayout::queue_resize(StateChangedType
/*eReason*/)
82 if (m_aPanelLayoutIdle
.IsActive())
84 InvalidateSizeCache();
85 m_aPanelLayoutIdle
.Start();
88 IMPL_LINK_NOARG( PanelLayout
, ImplHandlePanelLayoutTimerHdl
, Timer
*, void )
90 vcl::Window
*pChild
= GetWindow(GetWindowType::FirstChild
);
92 VclContainer::setLayoutAllocation(*pChild
, Point(0, 0), GetSizePixel());
95 void PanelLayout::setPosSizePixel(tools::Long nX
, tools::Long nY
, tools::Long nWidth
, tools::Long nHeight
, PosSizeFlags nFlags
)
97 bool bCanHandleSmallerWidth
= false;
98 bool bCanHandleSmallerHeight
= false;
100 vcl::Window
*pChild
= GetWindow(GetWindowType::FirstChild
);
102 if (pChild
->GetType() == WindowType::SCROLLWINDOW
)
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;
111 Size
aSize(GetOptimalSize());
112 if (!bCanHandleSmallerWidth
)
113 nWidth
= std::max(nWidth
,aSize
.Width());
114 if (!bCanHandleSmallerHeight
)
115 nHeight
= std::max(nHeight
,aSize
.Height());
117 Control::setPosSizePixel(nX
, nY
, nWidth
, nHeight
, nFlags
);
119 if (nFlags
& PosSizeFlags::Size
)
120 VclContainer::setLayoutAllocation(*pChild
, Point(0, 0), Size(nWidth
, nHeight
));
123 bool PanelLayout::EventNotify(NotifyEvent
& rNEvt
)
125 if (rNEvt
.GetType() == MouseNotifyEvent::COMMAND
)
126 Accelerator::ToggleMnemonicsOnHierarchy(*rNEvt
.GetCommandEvent(), this);
127 return Control::EventNotify( rNEvt
);
130 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */