Branch libreoffice-5-0-4
[LibreOffice.git] / sfx2 / source / sidebar / Panel.cxx
blob7ea2689bb20574cd0bda36b18a57b33df222209f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "Panel.hxx"
21 #include "PanelTitleBar.hxx"
22 #include "PanelDescriptor.hxx"
23 #include <sfx2/sidebar/Theme.hxx>
24 #include "Paint.hxx"
25 #include "ResourceManager.hxx"
27 #ifdef DEBUG
28 #include <sfx2/sidebar/Tools.hxx>
29 #include "Deck.hxx"
30 #endif
32 #include <tools/svborder.hxx>
33 #include <toolkit/helper/vclunohelper.hxx>
35 #include <com/sun/star/awt/XWindowPeer.hpp>
36 #include <com/sun/star/awt/PosSize.hpp>
37 #include <com/sun/star/ui/XToolPanel.hpp>
39 #include <boost/bind.hpp>
41 using namespace css;
42 using namespace css::uno;
44 namespace sfx2 { namespace sidebar {
46 Panel::Panel(const PanelDescriptor& rPanelDescriptor,
47 vcl::Window* pParentWindow,
48 const bool bIsInitiallyExpanded,
49 const std::function<void()>& rDeckLayoutTrigger,
50 const std::function<Context()>& rContextAccess)
51 : Window(pParentWindow)
52 , msPanelId(rPanelDescriptor.msId)
53 , mpTitleBar(VclPtr<PanelTitleBar>::Create(rPanelDescriptor.msTitle, pParentWindow, this))
54 , mbIsTitleBarOptional(rPanelDescriptor.mbIsTitleBarOptional)
55 , mxElement()
56 , mxPanelComponent()
57 , mbIsExpanded(bIsInitiallyExpanded)
58 , maDeckLayoutTrigger(rDeckLayoutTrigger)
59 , maContextAccess(rContextAccess)
61 #ifdef DEBUG
62 SetText(OUString("Panel"));
63 #endif
66 Panel::~Panel()
68 disposeOnce();
71 void Panel::ApplySettings(vcl::RenderContext& rRenderContext)
73 rRenderContext.SetBackground(Theme::GetPaint(Theme::Paint_PanelBackground).GetWallpaper());
76 void Panel::dispose()
78 mxPanelComponent = NULL;
81 Reference<lang::XComponent> xComponent (mxElement, UNO_QUERY);
82 mxElement = NULL;
83 if (xComponent.is())
84 xComponent->dispose();
88 Reference<lang::XComponent> xComponent (GetElementWindow(), UNO_QUERY);
89 if (xComponent.is())
90 xComponent->dispose();
93 mpTitleBar.disposeAndClear();
95 vcl::Window::dispose();
98 PanelTitleBar* Panel::GetTitleBar() const
100 return mpTitleBar.get();
103 void Panel::SetUIElement (const Reference<ui::XUIElement>& rxElement)
105 mxElement = rxElement;
106 if (mxElement.is())
108 mxPanelComponent.set(mxElement->getRealInterface(), UNO_QUERY);
112 void Panel::SetExpanded (const bool bIsExpanded)
114 if (mbIsExpanded != bIsExpanded)
116 mbIsExpanded = bIsExpanded;
117 maDeckLayoutTrigger();
119 if (maContextAccess)
121 ResourceManager::Instance().StorePanelExpansionState(
122 msPanelId,
123 bIsExpanded,
124 maContextAccess());
129 bool Panel::HasIdPredicate (const OUString& rsId) const
131 return msPanelId.equals(rsId);
134 void Panel::Paint (vcl::RenderContext& rRenderContext, const Rectangle& rUpdateArea)
136 Window::Paint(rRenderContext, rUpdateArea);
139 void Panel::Resize()
141 Window::Resize();
143 // Forward new size to window of XUIElement.
144 Reference<awt::XWindow> xElementWindow (GetElementWindow());
145 if(xElementWindow.is())
147 const Size aSize(GetSizePixel());
148 xElementWindow->setPosSize(0, 0, aSize.Width(), aSize.Height(),
149 awt::PosSize::POSSIZE);
153 void Panel::Activate()
155 Window::Activate();
158 void Panel::DataChanged (const DataChangedEvent& rEvent)
160 (void)rEvent;
161 Invalidate();
164 Reference<awt::XWindow> Panel::GetElementWindow()
166 if (mxElement.is())
168 Reference<ui::XToolPanel> xToolPanel(mxElement->getRealInterface(), UNO_QUERY);
169 if (xToolPanel.is())
170 return xToolPanel->getWindow();
173 return NULL;
176 } } // end of namespace sfx2::sidebar
178 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */