/src/libreoffice/sfx2/source/sidebar/PanelLayout.cxx
Line | Count | Source |
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 <sal/log.hxx> |
11 | | #include <sfx2/sidebar/Panel.hxx> |
12 | | #include <sfx2/sidebar/PanelLayout.hxx> |
13 | | #include <sfx2/sidebar/Theme.hxx> |
14 | | #include <sfx2/viewsh.hxx> |
15 | | #include <vcl/event.hxx> |
16 | | #include <vcl/svapp.hxx> |
17 | | #include <vcl/vclevent.hxx> |
18 | | #include <vcl/weld/Builder.hxx> |
19 | | |
20 | | using namespace sfx2::sidebar; |
21 | | |
22 | | PanelLayout::PanelLayout(weld::Widget* pParent, const OUString& rID, |
23 | | const OUString& rUIXMLDescription) |
24 | 0 | : PanelLayout(pParent, rID, rUIXMLDescription, |
25 | 0 | reinterpret_cast<sal_uInt64>(SfxViewShell::Current())) |
26 | 0 | { |
27 | 0 | } |
28 | | |
29 | | PanelLayout::PanelLayout(weld::Widget* pParent, const OUString& rID, |
30 | | const OUString& rUIXMLDescription, sal_uInt64 nWindowId) |
31 | 0 | : m_xBuilder(Application::CreateBuilder(pParent, rUIXMLDescription, false, nWindowId)) |
32 | 0 | , m_xContainer(m_xBuilder->weld_container(rID)) |
33 | 0 | , m_pPanel(nullptr) |
34 | 0 | { |
35 | 0 | m_xContainer->set_background(Theme::GetColor(Theme::Color_PanelBackground)); |
36 | 0 | m_xContainer->connect_get_property_tree(LINK(this, PanelLayout, DumpAsPropertyTreeHdl)); |
37 | 0 | ::Application::AddEventListener(LINK(this, PanelLayout, DataChangedEventListener)); |
38 | 0 | } |
39 | | |
40 | | IMPL_LINK(PanelLayout, DumpAsPropertyTreeHdl, tools::JsonWriter&, rJsonWriter, void) |
41 | 0 | { |
42 | 0 | DumpAsPropertyTree(rJsonWriter); |
43 | 0 | } |
44 | | |
45 | | void PanelLayout::DumpAsPropertyTree(tools::JsonWriter&) |
46 | 0 | { |
47 | 0 | } |
48 | | |
49 | | IMPL_LINK(PanelLayout, DataChangedEventListener, VclSimpleEvent&, rEvent, void) |
50 | 0 | { |
51 | 0 | if (rEvent.GetId() != VclEventId::ApplicationDataChanged) |
52 | 0 | return; |
53 | | |
54 | 0 | DataChangedEvent* pData = static_cast<DataChangedEvent*>(static_cast<VclWindowEvent&>(rEvent).GetData()); |
55 | 0 | DataChanged(*pData); |
56 | 0 | } |
57 | | |
58 | | void PanelLayout::DataChanged(const DataChangedEvent& rEvent) |
59 | 0 | { |
60 | 0 | if (rEvent.GetType() != DataChangedEventType::SETTINGS) |
61 | 0 | return; |
62 | 0 | if (rEvent.GetFlags() & AllSettingsFlags::STYLE) |
63 | 0 | m_xContainer->set_background(Theme::GetColor(Theme::Color_PanelBackground)); |
64 | 0 | } |
65 | | |
66 | | void PanelLayout::SetPanel(sfx2::sidebar::Panel* pPanel) |
67 | 0 | { |
68 | 0 | m_pPanel = pPanel; |
69 | 0 | } |
70 | | |
71 | | weld::Window* PanelLayout::GetFrameWeld() const |
72 | 0 | { |
73 | 0 | if (!m_pPanel) |
74 | 0 | { |
75 | 0 | SAL_WARN("sfx.sidebar", "Expected a toplevel Panel to exist"); |
76 | 0 | return nullptr; |
77 | 0 | } |
78 | 0 | return m_pPanel->GetFrameWeld(); |
79 | 0 | } |
80 | | |
81 | | PanelLayout::~PanelLayout() |
82 | 0 | { |
83 | 0 | ::Application::RemoveEventListener(LINK(this, PanelLayout, DataChangedEventListener)); |
84 | |
|
85 | 0 | m_xContainer.reset(); |
86 | 0 | m_xBuilder.reset(); |
87 | 0 | } |
88 | | |
89 | | void PanelLayout::queue_resize() |
90 | 0 | { |
91 | 0 | if (!m_xContainer) |
92 | 0 | return; |
93 | 0 | m_xContainer->queue_resize(); |
94 | 0 | } |
95 | | |
96 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |