122de8995SAndre Fischer /**************************************************************
222de8995SAndre Fischer *
322de8995SAndre Fischer * Licensed to the Apache Software Foundation (ASF) under one
422de8995SAndre Fischer * or more contributor license agreements. See the NOTICE file
522de8995SAndre Fischer * distributed with this work for additional information
622de8995SAndre Fischer * regarding copyright ownership. The ASF licenses this file
722de8995SAndre Fischer * to you under the Apache License, Version 2.0 (the
822de8995SAndre Fischer * "License"); you may not use this file except in compliance
922de8995SAndre Fischer * with the License. You may obtain a copy of the License at
1022de8995SAndre Fischer *
1122de8995SAndre Fischer * http://www.apache.org/licenses/LICENSE-2.0
1222de8995SAndre Fischer *
1322de8995SAndre Fischer * Unless required by applicable law or agreed to in writing,
1422de8995SAndre Fischer * software distributed under the License is distributed on an
1522de8995SAndre Fischer * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1622de8995SAndre Fischer * KIND, either express or implied. See the License for the
1722de8995SAndre Fischer * specific language governing permissions and limitations
1822de8995SAndre Fischer * under the License.
1922de8995SAndre Fischer *
2022de8995SAndre Fischer *************************************************************/
2122de8995SAndre Fischer
2222de8995SAndre Fischer #include "precompiled_sfx2.hxx"
2322de8995SAndre Fischer
2422de8995SAndre Fischer #include "Panel.hxx"
25ff12d537SAndre Fischer #include "PanelTitleBar.hxx"
26ff12d537SAndre Fischer #include "PanelDescriptor.hxx"
27b9e67834SAndre Fischer #include "sfx2/sidebar/Theme.hxx"
28ff12d537SAndre Fischer #include "Paint.hxx"
297e429a12SAndre Fischer #include "ResourceManager.hxx"
3022de8995SAndre Fischer
317a32b0c8SAndre Fischer #ifdef DEBUG
32f35c6d02SAndre Fischer #include "sfx2/sidebar/Tools.hxx"
337a32b0c8SAndre Fischer #include "Deck.hxx"
347a32b0c8SAndre Fischer #endif
357a32b0c8SAndre Fischer
3622de8995SAndre Fischer #include <tools/svborder.hxx>
377a32b0c8SAndre Fischer #include <toolkit/helper/vclunohelper.hxx>
3822de8995SAndre Fischer
3995a18594SAndre Fischer #include <com/sun/star/awt/XWindowPeer.hpp>
407a32b0c8SAndre Fischer #include <com/sun/star/awt/PosSize.hpp>
41ff12d537SAndre Fischer #include <com/sun/star/ui/XToolPanel.hpp>
42ff12d537SAndre Fischer
437a32b0c8SAndre Fischer #include <boost/bind.hpp>
447a32b0c8SAndre Fischer
4522de8995SAndre Fischer
4622de8995SAndre Fischer using namespace css;
4722de8995SAndre Fischer using namespace cssu;
4822de8995SAndre Fischer
4922de8995SAndre Fischer
5022de8995SAndre Fischer
51ff12d537SAndre Fischer namespace sfx2 { namespace sidebar {
5222de8995SAndre Fischer
Panel(const PanelDescriptor & rPanelDescriptor,Window * pParentWindow,const bool bIsInitiallyExpanded,const::boost::function<void (void)> & rDeckLayoutTrigger,const::boost::function<Context (void)> & rContextAccess)5322de8995SAndre Fischer Panel::Panel (
54ff12d537SAndre Fischer const PanelDescriptor& rPanelDescriptor,
55ff12d537SAndre Fischer Window* pParentWindow,
567e429a12SAndre Fischer const bool bIsInitiallyExpanded,
577e429a12SAndre Fischer const ::boost::function<void(void)>& rDeckLayoutTrigger,
587e429a12SAndre Fischer const ::boost::function<Context(void)>& rContextAccess)
5922de8995SAndre Fischer : Window(pParentWindow),
6095a18594SAndre Fischer msPanelId(rPanelDescriptor.msId),
617a32b0c8SAndre Fischer mpTitleBar(new PanelTitleBar(
627a32b0c8SAndre Fischer rPanelDescriptor.msTitle,
637a32b0c8SAndre Fischer pParentWindow,
64c545150fSOliver-Rainer Wittmann this)),
6522de8995SAndre Fischer mbIsTitleBarOptional(rPanelDescriptor.mbIsTitleBarOptional),
6622de8995SAndre Fischer mxElement(),
677a32b0c8SAndre Fischer mxPanelComponent(),
687e429a12SAndre Fischer mbIsExpanded(bIsInitiallyExpanded),
697e429a12SAndre Fischer maDeckLayoutTrigger(rDeckLayoutTrigger),
707e429a12SAndre Fischer maContextAccess(rContextAccess)
7122de8995SAndre Fischer {
72b9e67834SAndre Fischer SetBackground(Theme::GetPaint(Theme::Paint_PanelBackground).GetWallpaper());
737a32b0c8SAndre Fischer
747a32b0c8SAndre Fischer #ifdef DEBUG
757a32b0c8SAndre Fischer SetText(A2S("Panel"));
767a32b0c8SAndre Fischer #endif
7722de8995SAndre Fischer }
7822de8995SAndre Fischer
7922de8995SAndre Fischer
8022de8995SAndre Fischer
8122de8995SAndre Fischer
~Panel(void)8222de8995SAndre Fischer Panel::~Panel (void)
8322de8995SAndre Fischer {
847a32b0c8SAndre Fischer Dispose();
8522de8995SAndre Fischer }
8622de8995SAndre Fischer
8722de8995SAndre Fischer
8822de8995SAndre Fischer
8922de8995SAndre Fischer
Dispose(void)90ff12d537SAndre Fischer void Panel::Dispose (void)
91ff12d537SAndre Fischer {
927a32b0c8SAndre Fischer mxPanelComponent = NULL;
9395a18594SAndre Fischer
9495a18594SAndre Fischer {
95ff12d537SAndre Fischer Reference<lang::XComponent> xComponent (mxElement, UNO_QUERY);
96ff12d537SAndre Fischer mxElement = NULL;
97ff12d537SAndre Fischer if (xComponent.is())
98ff12d537SAndre Fischer xComponent->dispose();
99ff12d537SAndre Fischer }
10095a18594SAndre Fischer
101ff12d537SAndre Fischer {
1027a32b0c8SAndre Fischer Reference<lang::XComponent> xComponent (GetElementWindow(), UNO_QUERY);
103ff12d537SAndre Fischer if (xComponent.is())
104ff12d537SAndre Fischer xComponent->dispose();
105ff12d537SAndre Fischer }
106ff12d537SAndre Fischer
1077a32b0c8SAndre Fischer mpTitleBar.reset();
10822de8995SAndre Fischer }
10922de8995SAndre Fischer
11022de8995SAndre Fischer
11122de8995SAndre Fischer
11222de8995SAndre Fischer
GetTitleBar(void) const113*8a1a651aSAndre Fischer PanelTitleBar* Panel::GetTitleBar (void) const
11422de8995SAndre Fischer {
1157a32b0c8SAndre Fischer return mpTitleBar.get();
11622de8995SAndre Fischer }
11722de8995SAndre Fischer
11822de8995SAndre Fischer
11922de8995SAndre Fischer
12022de8995SAndre Fischer
IsTitleBarOptional(void) const12122de8995SAndre Fischer bool Panel::IsTitleBarOptional (void) const
12222de8995SAndre Fischer {
12322de8995SAndre Fischer return mbIsTitleBarOptional;
12422de8995SAndre Fischer }
12522de8995SAndre Fischer
12622de8995SAndre Fischer
12722de8995SAndre Fischer
12822de8995SAndre Fischer
SetUIElement(const Reference<ui::XUIElement> & rxElement)12922de8995SAndre Fischer void Panel::SetUIElement (const Reference<ui::XUIElement>& rxElement)
13022de8995SAndre Fischer {
13122de8995SAndre Fischer mxElement = rxElement;
13222de8995SAndre Fischer if (mxElement.is())
13322de8995SAndre Fischer {
1347a32b0c8SAndre Fischer mxPanelComponent.set(mxElement->getRealInterface(), UNO_QUERY);
13522de8995SAndre Fischer }
13622de8995SAndre Fischer }
13722de8995SAndre Fischer
13822de8995SAndre Fischer
13922de8995SAndre Fischer
14022de8995SAndre Fischer
SetExpanded(const bool bIsExpanded)141ff12d537SAndre Fischer void Panel::SetExpanded (const bool bIsExpanded)
142ff12d537SAndre Fischer {
143ff12d537SAndre Fischer if (mbIsExpanded != bIsExpanded)
144ff12d537SAndre Fischer {
145ff12d537SAndre Fischer mbIsExpanded = bIsExpanded;
146ff12d537SAndre Fischer maDeckLayoutTrigger();
1477e429a12SAndre Fischer
1487e429a12SAndre Fischer if (maContextAccess)
1497e429a12SAndre Fischer ResourceManager::Instance().StorePanelExpansionState(
1507e429a12SAndre Fischer msPanelId,
1517e429a12SAndre Fischer bIsExpanded,
1527e429a12SAndre Fischer maContextAccess());
153ff12d537SAndre Fischer }
154ff12d537SAndre Fischer }
155ff12d537SAndre Fischer
156ff12d537SAndre Fischer
157ff12d537SAndre Fischer
158ff12d537SAndre Fischer
IsExpanded(void) const159ff12d537SAndre Fischer bool Panel::IsExpanded (void) const
160ff12d537SAndre Fischer {
161ff12d537SAndre Fischer return mbIsExpanded;
162ff12d537SAndre Fischer }
163ff12d537SAndre Fischer
164ff12d537SAndre Fischer
165ff12d537SAndre Fischer
166ff12d537SAndre Fischer
HasIdPredicate(const::rtl::OUString & rsId) const16795a18594SAndre Fischer bool Panel::HasIdPredicate (const ::rtl::OUString& rsId) const
16895a18594SAndre Fischer {
16995a18594SAndre Fischer if (this == NULL)
17095a18594SAndre Fischer return false;
17195a18594SAndre Fischer else
17295a18594SAndre Fischer return msPanelId.equals(rsId);
17395a18594SAndre Fischer }
17495a18594SAndre Fischer
17595a18594SAndre Fischer
17695a18594SAndre Fischer
17795a18594SAndre Fischer
GetId(void) const17802c50d82SAndre Fischer const ::rtl::OUString& Panel::GetId (void) const
17902c50d82SAndre Fischer {
18002c50d82SAndre Fischer return msPanelId;
18102c50d82SAndre Fischer }
18202c50d82SAndre Fischer
18302c50d82SAndre Fischer
18402c50d82SAndre Fischer
18502c50d82SAndre Fischer
Paint(const Rectangle & rUpdateArea)18622de8995SAndre Fischer void Panel::Paint (const Rectangle& rUpdateArea)
18722de8995SAndre Fischer {
18822de8995SAndre Fischer Window::Paint(rUpdateArea);
18922de8995SAndre Fischer }
19022de8995SAndre Fischer
19122de8995SAndre Fischer
19222de8995SAndre Fischer
19322de8995SAndre Fischer
Resize(void)1947a32b0c8SAndre Fischer void Panel::Resize (void)
195ff12d537SAndre Fischer {
1967a32b0c8SAndre Fischer Window::Resize();
197ff12d537SAndre Fischer
1987a32b0c8SAndre Fischer // Forward new size to window of XUIElement.
1997a32b0c8SAndre Fischer Reference<awt::XWindow> xElementWindow (GetElementWindow());
2007a32b0c8SAndre Fischer if (xElementWindow.is())
2017a32b0c8SAndre Fischer {
2027a32b0c8SAndre Fischer const Size aSize (GetSizePixel());
2037a32b0c8SAndre Fischer xElementWindow->setPosSize(
2047a32b0c8SAndre Fischer 0,
2057a32b0c8SAndre Fischer 0,
2067a32b0c8SAndre Fischer aSize.Width(),
2077a32b0c8SAndre Fischer aSize.Height(),
2087a32b0c8SAndre Fischer awt::PosSize::POSSIZE);
2097a32b0c8SAndre Fischer }
210ff12d537SAndre Fischer }
211ff12d537SAndre Fischer
212ff12d537SAndre Fischer
213ff12d537SAndre Fischer
214ff12d537SAndre Fischer
Activate(void)215b9e67834SAndre Fischer void Panel::Activate (void)
216b9e67834SAndre Fischer {
217b9e67834SAndre Fischer Window::Activate();
218b9e67834SAndre Fischer }
219b9e67834SAndre Fischer
220b9e67834SAndre Fischer
221b9e67834SAndre Fischer
222b9e67834SAndre Fischer
223b9e67834SAndre Fischer
DataChanged(const DataChangedEvent & rEvent)224b9e67834SAndre Fischer void Panel::DataChanged (const DataChangedEvent& rEvent)
225b9e67834SAndre Fischer {
226b9e67834SAndre Fischer (void)rEvent;
227b9e67834SAndre Fischer SetBackground(Theme::GetPaint(Theme::Paint_PanelBackground).GetWallpaper());
228b9e67834SAndre Fischer }
229b9e67834SAndre Fischer
230b9e67834SAndre Fischer
231b9e67834SAndre Fischer
232b9e67834SAndre Fischer
GetPanelComponent(void) const2337a32b0c8SAndre Fischer Reference<ui::XSidebarPanel> Panel::GetPanelComponent (void) const
23422de8995SAndre Fischer {
2357a32b0c8SAndre Fischer return mxPanelComponent;
23622de8995SAndre Fischer }
23722de8995SAndre Fischer
238b9e67834SAndre Fischer
239b9e67834SAndre Fischer
240b9e67834SAndre Fischer
PrintWindowTree(void)2417a32b0c8SAndre Fischer void Panel::PrintWindowTree (void)
2427a32b0c8SAndre Fischer {
2437a32b0c8SAndre Fischer #ifdef DEBUG
2447a32b0c8SAndre Fischer Window* pElementWindow = VCLUnoHelper::GetWindow(GetElementWindow());
2457a32b0c8SAndre Fischer if (pElementWindow != NULL)
246b9e67834SAndre Fischer {
2477a32b0c8SAndre Fischer OSL_TRACE("panel parent is %x", pElementWindow->GetParent());
2487a32b0c8SAndre Fischer Deck::PrintWindowSubTree(pElementWindow, 2);
2497a32b0c8SAndre Fischer }
2507a32b0c8SAndre Fischer else
2517a32b0c8SAndre Fischer OSL_TRACE(" panel is empty");
2527a32b0c8SAndre Fischer #endif
2537a32b0c8SAndre Fischer }
2547a32b0c8SAndre Fischer
2557a32b0c8SAndre Fischer
2567a32b0c8SAndre Fischer
2577a32b0c8SAndre Fischer
GetElementWindow(void)2587a32b0c8SAndre Fischer Reference<awt::XWindow> Panel::GetElementWindow (void)
2597a32b0c8SAndre Fischer {
2607a32b0c8SAndre Fischer if (mxElement.is())
2617a32b0c8SAndre Fischer {
2627a32b0c8SAndre Fischer Reference<ui::XToolPanel> xToolPanel(mxElement->getRealInterface(), UNO_QUERY);
2637a32b0c8SAndre Fischer if (xToolPanel.is())
2647a32b0c8SAndre Fischer return xToolPanel->getWindow();
265b9e67834SAndre Fischer }
266b9e67834SAndre Fischer
2677a32b0c8SAndre Fischer return NULL;
268b9e67834SAndre Fischer }
269b9e67834SAndre Fischer
270b9e67834SAndre Fischer
271ff12d537SAndre Fischer } } // end of namespace sfx2::sidebar
272