bump product version to 4.1.6.2
[LibreOffice.git] / sfx2 / source / sidebar / Panel.cxx
blob309dc04cb379bf011e0c34ae29138ccc42779dff
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #include "Panel.hxx"
20 #include "PanelTitleBar.hxx"
21 #include "PanelDescriptor.hxx"
22 #include "sfx2/sidebar/Theme.hxx"
23 #include "Paint.hxx"
24 #include "ResourceManager.hxx"
26 #ifdef DEBUG
27 #include "sfx2/sidebar/Tools.hxx"
28 #include "Deck.hxx"
29 #endif
31 #include <tools/svborder.hxx>
32 #include <toolkit/helper/vclunohelper.hxx>
34 #include <com/sun/star/awt/XWindowPeer.hpp>
35 #include <com/sun/star/awt/PosSize.hpp>
36 #include <com/sun/star/ui/XToolPanel.hpp>
38 #include <boost/bind.hpp>
41 using namespace css;
42 using namespace cssu;
46 namespace sfx2 { namespace sidebar {
48 Panel::Panel (
49 const PanelDescriptor& rPanelDescriptor,
50 Window* pParentWindow,
51 const bool bIsInitiallyExpanded,
52 const ::boost::function<void(void)>& rDeckLayoutTrigger,
53 const ::boost::function<Context(void)>& rContextAccess)
54 : Window(pParentWindow),
55 msPanelId(rPanelDescriptor.msId),
56 mpTitleBar(new PanelTitleBar(
57 rPanelDescriptor.msTitle,
58 pParentWindow,
59 this)),
60 mbIsTitleBarOptional(rPanelDescriptor.mbIsTitleBarOptional),
61 mxElement(),
62 mxPanelComponent(),
63 mbIsExpanded(bIsInitiallyExpanded),
64 maDeckLayoutTrigger(rDeckLayoutTrigger),
65 maContextAccess(rContextAccess)
67 SetBackground(Theme::GetPaint(Theme::Paint_PanelBackground).GetWallpaper());
69 #ifdef DEBUG
70 SetText(A2S("Panel"));
71 #endif
77 Panel::~Panel (void)
79 Dispose();
85 void Panel::Dispose (void)
87 mxPanelComponent = NULL;
90 Reference<lang::XComponent> xComponent (mxElement, UNO_QUERY);
91 mxElement = NULL;
92 if (xComponent.is())
93 xComponent->dispose();
97 Reference<lang::XComponent> xComponent (GetElementWindow(), UNO_QUERY);
98 if (xComponent.is())
99 xComponent->dispose();
102 mpTitleBar.reset();
108 PanelTitleBar* Panel::GetTitleBar (void) const
110 return mpTitleBar.get();
116 bool Panel::IsTitleBarOptional (void) const
118 return mbIsTitleBarOptional;
124 void Panel::SetUIElement (const Reference<ui::XUIElement>& rxElement)
126 mxElement = rxElement;
127 if (mxElement.is())
129 mxPanelComponent.set(mxElement->getRealInterface(), UNO_QUERY);
136 void Panel::SetExpanded (const bool bIsExpanded)
138 if (mbIsExpanded != bIsExpanded)
140 mbIsExpanded = bIsExpanded;
141 maDeckLayoutTrigger();
143 if (maContextAccess)
144 ResourceManager::Instance().StorePanelExpansionState(
145 msPanelId,
146 bIsExpanded,
147 maContextAccess());
154 bool Panel::IsExpanded (void) const
156 return mbIsExpanded;
162 bool Panel::HasIdPredicate (const ::rtl::OUString& rsId) const
164 if (this == NULL)
165 return false;
166 else
167 return msPanelId.equals(rsId);
173 const ::rtl::OUString& Panel::GetId (void) const
175 return msPanelId;
181 void Panel::Paint (const Rectangle& rUpdateArea)
183 Window::Paint(rUpdateArea);
189 void Panel::Resize (void)
191 Window::Resize();
193 // Forward new size to window of XUIElement.
194 Reference<awt::XWindow> xElementWindow (GetElementWindow());
195 if (xElementWindow.is())
197 const Size aSize (GetSizePixel());
198 xElementWindow->setPosSize(
201 aSize.Width(),
202 aSize.Height(),
203 awt::PosSize::POSSIZE);
210 void Panel::Activate (void)
212 Window::Activate();
219 void Panel::DataChanged (const DataChangedEvent& rEvent)
221 (void)rEvent;
222 SetBackground(Theme::GetPaint(Theme::Paint_PanelBackground).GetWallpaper());
228 Reference<ui::XSidebarPanel> Panel::GetPanelComponent (void) const
230 return mxPanelComponent;
236 void Panel::PrintWindowTree (void)
238 #ifdef DEBUG
239 Window* pElementWindow = VCLUnoHelper::GetWindow(GetElementWindow());
240 if (pElementWindow != NULL)
242 OSL_TRACE("panel parent is %x", pElementWindow->GetParent());
243 Deck::PrintWindowSubTree(pElementWindow, 2);
245 else
246 OSL_TRACE(" panel is empty");
247 #endif
253 Reference<awt::XWindow> Panel::GetElementWindow (void)
255 if (mxElement.is())
257 Reference<ui::XToolPanel> xToolPanel(mxElement->getRealInterface(), UNO_QUERY);
258 if (xToolPanel.is())
259 return xToolPanel->getWindow();
262 return NULL;
266 } } // end of namespace sfx2::sidebar