diff options
Diffstat (limited to 'sfx2/source/sidebar/PanelLayout.cxx')
-rw-r--r-- | sfx2/source/sidebar/PanelLayout.cxx | 124 |
1 files changed, 39 insertions, 85 deletions
diff --git a/sfx2/source/sidebar/PanelLayout.cxx b/sfx2/source/sidebar/PanelLayout.cxx index 0e37e2278a73..3a47773175ce 100644 --- a/sfx2/source/sidebar/PanelLayout.cxx +++ b/sfx2/source/sidebar/PanelLayout.cxx @@ -7,124 +7,78 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include <sal/log.hxx> #include <sfx2/sidebar/SidebarController.hxx> -#include <sfx2/sidebar/TabBar.hxx> #include <sfx2/sidebar/PanelLayout.hxx> -#include <vcl/layout.hxx> -#include <vcl/accel.hxx> +#include <sfx2/sidebar/TabBar.hxx> +#include <sfx2/sidebar/Theme.hxx> +#include <vcl/event.hxx> using namespace sfx2::sidebar; -PanelLayout::PanelLayout(vcl::Window* pParent, const OString& rID, const OUString& rUIXMLDescription, - const css::uno::Reference<css::frame::XFrame> &rFrame) - : Control(pParent) - , m_pInitialFocusWidget(nullptr) - , m_bInClose(false) - , mxFrame(rFrame) -{ - m_aPanelLayoutIdle.SetPriority(TaskPriority::RESIZE); - m_aPanelLayoutIdle.SetInvokeHandler( LINK( this, PanelLayout, ImplHandlePanelLayoutTimerHdl ) ); - m_aPanelLayoutIdle.SetDebugName("sfx2::PanelLayout m_aPanelLayoutIdle"); - - SetStyle(GetStyle() | WB_DIALOGCONTROL); - - // Builder will trigger resize and start Idle - m_xVclContentArea = VclPtr<VclVBox>::Create(this); - m_xVclContentArea->Show(); - m_xBuilder.reset(Application::CreateInterimBuilder(m_xVclContentArea, rUIXMLDescription, true)); - m_xContainer = m_xBuilder->weld_container(rID); -} - -void PanelLayout::GetFocus() +PanelLayout::PanelLayout(weld::Widget* pParent, const OString& rID, const OUString& rUIXMLDescription) + : m_xBuilder(Application::CreateBuilder(pParent, rUIXMLDescription)) + , m_xContainer(m_xBuilder->weld_container(rID)) { - Control::GetFocus(); - if (m_pInitialFocusWidget) - m_pInitialFocusWidget->grab_focus(); + m_xContainer->set_background(Theme::GetColor(Theme::Color_PanelBackground)); + m_xContainer->connect_get_property_tree(LINK(this, PanelLayout, DumpAsPropertyTreeHdl)); + ::Application::AddEventListener(LINK(this, PanelLayout, DataChangedEventListener)); } -PanelLayout::~PanelLayout() +IMPL_LINK(PanelLayout, DumpAsPropertyTreeHdl, tools::JsonWriter&, rJsonWriter, void) { - disposeOnce(); + DumpAsPropertyTree(rJsonWriter); } -void PanelLayout::dispose() +void PanelLayout::DumpAsPropertyTree(tools::JsonWriter&) { - m_bInClose = true; - m_pInitialFocusWidget = nullptr; - m_aPanelLayoutIdle.Stop(); - m_xContainer.reset(); - m_xBuilder.reset(); - m_xVclContentArea.disposeAndClear(); - Control::dispose(); } -Size PanelLayout::GetOptimalSize() const +IMPL_LINK(PanelLayout, DataChangedEventListener, VclSimpleEvent&, rEvent, void) { - Size aSize = m_xContainer->get_preferred_size(); - - if (mxFrame) - { - SidebarController* pController - = SidebarController::GetSidebarControllerForFrame(mxFrame); - if (pController) - aSize.setWidth(std::min<tools::Long>( - aSize.Width(), (pController->getMaximumWidth() - TabBar::GetDefaultWidth()) - * GetDPIScaleFactor())); - } + if (rEvent.GetId() != VclEventId::ApplicationDataChanged) + return; - return aSize; + DataChangedEvent* pData = static_cast<DataChangedEvent*>(static_cast<VclWindowEvent&>(rEvent).GetData()); + DataChanged(*pData); } -void PanelLayout::queue_resize(StateChangedType /*eReason*/) +void PanelLayout::DataChanged(const DataChangedEvent& rEvent) { - if (m_bInClose) - return; - if (m_aPanelLayoutIdle.IsActive()) + if (rEvent.GetType() != DataChangedEventType::SETTINGS) return; - InvalidateSizeCache(); - m_aPanelLayoutIdle.Start(); + if (rEvent.GetFlags() & AllSettingsFlags::STYLE) + m_xContainer->set_background(Theme::GetColor(Theme::Color_PanelBackground)); } -IMPL_LINK_NOARG( PanelLayout, ImplHandlePanelLayoutTimerHdl, Timer*, void ) +void PanelLayout::SetPanel(sfx2::sidebar::Panel* pPanel) { - vcl::Window *pChild = GetWindow(GetWindowType::FirstChild); - assert(pChild); - VclContainer::setLayoutAllocation(*pChild, Point(0, 0), GetSizePixel()); + m_xPanel = pPanel; } -void PanelLayout::setPosSizePixel(tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight, PosSizeFlags nFlags) +weld::Window* PanelLayout::GetFrameWeld() const { - bool bCanHandleSmallerWidth = false; - bool bCanHandleSmallerHeight = false; - - vcl::Window *pChild = GetWindow(GetWindowType::FirstChild); - - if (pChild->GetType() == WindowType::SCROLLWINDOW) + if (!m_xPanel) { - WinBits nStyle = pChild->GetStyle(); - if (nStyle & (WB_AUTOHSCROLL | WB_HSCROLL)) - bCanHandleSmallerWidth = true; - if (nStyle & (WB_AUTOVSCROLL | WB_VSCROLL)) - bCanHandleSmallerHeight = true; + SAL_WARN("sfx.sidebar", "Expected a toplevel Panel to exist"); + return nullptr; } + return m_xPanel->GetFrameWeld(); +} - Size aSize(GetOptimalSize()); - if (!bCanHandleSmallerWidth) - nWidth = std::max(nWidth,aSize.Width()); - if (!bCanHandleSmallerHeight) - nHeight = std::max(nHeight,aSize.Height()); - - Control::setPosSizePixel(nX, nY, nWidth, nHeight, nFlags); +PanelLayout::~PanelLayout() +{ + ::Application::RemoveEventListener(LINK(this, PanelLayout, DataChangedEventListener)); - if (nFlags & PosSizeFlags::Size) - VclContainer::setLayoutAllocation(*pChild, Point(0, 0), Size(nWidth, nHeight)); + m_xContainer.reset(); + m_xBuilder.reset(); } -bool PanelLayout::EventNotify(NotifyEvent& rNEvt) +void PanelLayout::queue_resize() { - if (rNEvt.GetType() == MouseNotifyEvent::COMMAND) - Accelerator::ToggleMnemonicsOnHierarchy(*rNEvt.GetCommandEvent(), this); - return Control::EventNotify( rNEvt ); + if (!m_xContainer) + return; + m_xContainer->queue_resize(); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |