xref: /aoo41x/main/sfx2/source/sidebar/Panel.cxx (revision 7a32b0c8)
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"
2922de8995SAndre Fischer 
30*7a32b0c8SAndre Fischer #ifdef DEBUG
31*7a32b0c8SAndre Fischer #include "Tools.hxx"
32*7a32b0c8SAndre Fischer #include "Deck.hxx"
33*7a32b0c8SAndre Fischer #endif
34*7a32b0c8SAndre Fischer 
3522de8995SAndre Fischer #include <tools/svborder.hxx>
36*7a32b0c8SAndre Fischer #include <toolkit/helper/vclunohelper.hxx>
3722de8995SAndre Fischer 
3895a18594SAndre Fischer #include <com/sun/star/awt/XWindowPeer.hpp>
39*7a32b0c8SAndre Fischer #include <com/sun/star/awt/PosSize.hpp>
40ff12d537SAndre Fischer #include <com/sun/star/ui/XToolPanel.hpp>
41ff12d537SAndre Fischer 
42*7a32b0c8SAndre Fischer #include <boost/bind.hpp>
43*7a32b0c8SAndre Fischer 
4422de8995SAndre Fischer 
4522de8995SAndre Fischer using namespace css;
4622de8995SAndre Fischer using namespace cssu;
4722de8995SAndre Fischer 
4822de8995SAndre Fischer namespace {
4922de8995SAndre Fischer     static const char* VerticalStackLayouterName("vertical-stack");
5022de8995SAndre Fischer }
5122de8995SAndre Fischer 
5222de8995SAndre Fischer 
53ff12d537SAndre Fischer namespace sfx2 { namespace sidebar {
5422de8995SAndre Fischer 
5522de8995SAndre Fischer Panel::Panel (
56ff12d537SAndre Fischer     const PanelDescriptor& rPanelDescriptor,
57ff12d537SAndre Fischer     Window* pParentWindow,
58ff12d537SAndre Fischer     const ::boost::function<void(void)>& rDeckLayoutTrigger)
5922de8995SAndre Fischer     : Window(pParentWindow),
6095a18594SAndre Fischer       msPanelId(rPanelDescriptor.msId),
61*7a32b0c8SAndre Fischer       mpTitleBar(new PanelTitleBar(
62*7a32b0c8SAndre Fischer               rPanelDescriptor.msTitle,
63*7a32b0c8SAndre Fischer               pParentWindow,
64*7a32b0c8SAndre Fischer               this,
65*7a32b0c8SAndre Fischer               rPanelDescriptor.mbHasMenu
66*7a32b0c8SAndre Fischer                   ? ::boost::bind(&Panel::ShowMenu, this)
67*7a32b0c8SAndre Fischer                   : ::boost::function<void(void)>())),
6822de8995SAndre Fischer       mbIsTitleBarOptional(rPanelDescriptor.mbIsTitleBarOptional),
6922de8995SAndre Fischer       mxElement(),
70*7a32b0c8SAndre Fischer       mxPanelComponent(),
71ff12d537SAndre Fischer       mbIsExpanded(true),
72ff12d537SAndre Fischer       maDeckLayoutTrigger(rDeckLayoutTrigger)
7322de8995SAndre Fischer {
74b9e67834SAndre Fischer     SetBackground(Theme::GetPaint(Theme::Paint_PanelBackground).GetWallpaper());
75*7a32b0c8SAndre Fischer 
76*7a32b0c8SAndre Fischer #ifdef DEBUG
77*7a32b0c8SAndre Fischer     OSL_TRACE("creating Panel at %x", this);
78*7a32b0c8SAndre Fischer     SetText(A2S("Panel"));
79*7a32b0c8SAndre Fischer #endif
8022de8995SAndre Fischer }
8122de8995SAndre Fischer 
8222de8995SAndre Fischer 
8322de8995SAndre Fischer 
8422de8995SAndre Fischer 
8522de8995SAndre Fischer Panel::~Panel (void)
8622de8995SAndre Fischer {
87*7a32b0c8SAndre Fischer     OSL_TRACE("destroying Panel at %x", this);
88*7a32b0c8SAndre Fischer     Dispose();
8922de8995SAndre Fischer }
9022de8995SAndre Fischer 
9122de8995SAndre Fischer 
9222de8995SAndre Fischer 
9322de8995SAndre Fischer 
94ff12d537SAndre Fischer void Panel::Dispose (void)
95ff12d537SAndre Fischer {
96*7a32b0c8SAndre Fischer     mxPanelComponent = NULL;
9795a18594SAndre Fischer 
9895a18594SAndre Fischer     if (mxElement.is())
99ff12d537SAndre Fischer     {
10095a18594SAndre Fischer         Reference<lang::XComponent> xComponent (mxElement->getRealInterface(), UNO_QUERY);
10195a18594SAndre Fischer         if (xComponent.is())
10295a18594SAndre Fischer             xComponent->dispose();
10395a18594SAndre Fischer     }
10495a18594SAndre Fischer 
10595a18594SAndre Fischer     {
106ff12d537SAndre Fischer         Reference<lang::XComponent> xComponent (mxElement, UNO_QUERY);
107ff12d537SAndre Fischer         mxElement = NULL;
108ff12d537SAndre Fischer         if (xComponent.is())
109ff12d537SAndre Fischer             xComponent->dispose();
110ff12d537SAndre Fischer     }
11195a18594SAndre Fischer 
112ff12d537SAndre Fischer     {
113*7a32b0c8SAndre Fischer         Reference<lang::XComponent> xComponent (GetElementWindow(), UNO_QUERY);
114ff12d537SAndre Fischer         if (xComponent.is())
115ff12d537SAndre Fischer             xComponent->dispose();
116ff12d537SAndre Fischer     }
117ff12d537SAndre Fischer 
118*7a32b0c8SAndre Fischer     mpTitleBar.reset();
11922de8995SAndre Fischer }
12022de8995SAndre Fischer 
12122de8995SAndre Fischer 
12222de8995SAndre Fischer 
12322de8995SAndre Fischer 
12422de8995SAndre Fischer TitleBar* Panel::GetTitleBar (void) const
12522de8995SAndre Fischer {
126*7a32b0c8SAndre Fischer     return mpTitleBar.get();
12722de8995SAndre Fischer }
12822de8995SAndre Fischer 
12922de8995SAndre Fischer 
13022de8995SAndre Fischer 
13122de8995SAndre Fischer 
13222de8995SAndre Fischer bool Panel::IsTitleBarOptional (void) const
13322de8995SAndre Fischer {
13422de8995SAndre Fischer     return mbIsTitleBarOptional;
13522de8995SAndre Fischer }
13622de8995SAndre Fischer 
13722de8995SAndre Fischer 
13822de8995SAndre Fischer 
13922de8995SAndre Fischer 
14022de8995SAndre Fischer void Panel::SetUIElement (const Reference<ui::XUIElement>& rxElement)
14122de8995SAndre Fischer {
14222de8995SAndre Fischer     mxElement = rxElement;
14322de8995SAndre Fischer     if (mxElement.is())
14422de8995SAndre Fischer     {
145*7a32b0c8SAndre Fischer         mxPanelComponent.set(mxElement->getRealInterface(), UNO_QUERY);
14622de8995SAndre Fischer     }
14722de8995SAndre Fischer }
14822de8995SAndre Fischer 
14922de8995SAndre Fischer 
15022de8995SAndre Fischer 
15122de8995SAndre Fischer 
152ff12d537SAndre Fischer void Panel::SetExpanded (const bool bIsExpanded)
153ff12d537SAndre Fischer {
154ff12d537SAndre Fischer     if (mbIsExpanded != bIsExpanded)
155ff12d537SAndre Fischer     {
156ff12d537SAndre Fischer         mbIsExpanded = bIsExpanded;
157ff12d537SAndre Fischer         maDeckLayoutTrigger();
158ff12d537SAndre Fischer     }
159ff12d537SAndre Fischer }
160ff12d537SAndre Fischer 
161ff12d537SAndre Fischer 
162ff12d537SAndre Fischer 
163ff12d537SAndre Fischer 
164ff12d537SAndre Fischer bool Panel::IsExpanded (void) const
165ff12d537SAndre Fischer {
166ff12d537SAndre Fischer     return mbIsExpanded;
167ff12d537SAndre Fischer }
168ff12d537SAndre Fischer 
169ff12d537SAndre Fischer 
170ff12d537SAndre Fischer 
171ff12d537SAndre Fischer 
17295a18594SAndre Fischer bool Panel::HasIdPredicate (const ::rtl::OUString& rsId) const
17395a18594SAndre Fischer {
17495a18594SAndre Fischer     if (this == NULL)
17595a18594SAndre Fischer         return false;
17695a18594SAndre Fischer     else
17795a18594SAndre Fischer         return msPanelId.equals(rsId);
17895a18594SAndre Fischer }
17995a18594SAndre Fischer 
18095a18594SAndre Fischer 
18195a18594SAndre Fischer 
18295a18594SAndre Fischer 
18322de8995SAndre Fischer void Panel::Paint (const Rectangle& rUpdateArea)
18422de8995SAndre Fischer {
18522de8995SAndre Fischer     Window::Paint(rUpdateArea);
18622de8995SAndre Fischer }
18722de8995SAndre Fischer 
18822de8995SAndre Fischer 
18922de8995SAndre Fischer 
19022de8995SAndre Fischer 
191*7a32b0c8SAndre Fischer void Panel::Resize (void)
192ff12d537SAndre Fischer {
193*7a32b0c8SAndre Fischer     Window::Resize();
194ff12d537SAndre Fischer 
195*7a32b0c8SAndre Fischer     // Forward new size to window of XUIElement.
196*7a32b0c8SAndre Fischer     Reference<awt::XWindow> xElementWindow (GetElementWindow());
197*7a32b0c8SAndre Fischer     if (xElementWindow.is())
198*7a32b0c8SAndre Fischer     {
199*7a32b0c8SAndre Fischer         const Size aSize (GetSizePixel());
200*7a32b0c8SAndre Fischer         xElementWindow->setPosSize(
201*7a32b0c8SAndre Fischer             0,
202*7a32b0c8SAndre Fischer             0,
203*7a32b0c8SAndre Fischer             aSize.Width(),
204*7a32b0c8SAndre Fischer             aSize.Height(),
205*7a32b0c8SAndre Fischer             awt::PosSize::POSSIZE);
206*7a32b0c8SAndre Fischer     }
207ff12d537SAndre Fischer }
208ff12d537SAndre Fischer 
209ff12d537SAndre Fischer 
210ff12d537SAndre Fischer 
211ff12d537SAndre Fischer 
212b9e67834SAndre Fischer void Panel::Activate (void)
213b9e67834SAndre Fischer {
214b9e67834SAndre Fischer     Window::Activate();
215b9e67834SAndre Fischer }
216b9e67834SAndre Fischer 
217b9e67834SAndre Fischer 
218b9e67834SAndre Fischer 
219b9e67834SAndre Fischer 
220b9e67834SAndre Fischer 
221b9e67834SAndre Fischer void Panel::DataChanged (const DataChangedEvent& rEvent)
222b9e67834SAndre Fischer {
223b9e67834SAndre Fischer     (void)rEvent;
224b9e67834SAndre Fischer     SetBackground(Theme::GetPaint(Theme::Paint_PanelBackground).GetWallpaper());
225b9e67834SAndre Fischer }
226b9e67834SAndre Fischer 
227b9e67834SAndre Fischer 
228b9e67834SAndre Fischer 
229b9e67834SAndre Fischer 
230*7a32b0c8SAndre Fischer Reference<ui::XSidebarPanel> Panel::GetPanelComponent (void) const
23122de8995SAndre Fischer {
232*7a32b0c8SAndre Fischer     return mxPanelComponent;
23322de8995SAndre Fischer }
23422de8995SAndre Fischer 
235b9e67834SAndre Fischer 
236b9e67834SAndre Fischer 
237b9e67834SAndre Fischer 
238*7a32b0c8SAndre Fischer void Panel::ShowMenu (void)
239b9e67834SAndre Fischer {
240*7a32b0c8SAndre Fischer     if (mxPanelComponent.is())
241*7a32b0c8SAndre Fischer         mxPanelComponent->showMenu();
242*7a32b0c8SAndre Fischer }
243*7a32b0c8SAndre Fischer 
244*7a32b0c8SAndre Fischer 
245*7a32b0c8SAndre Fischer 
246*7a32b0c8SAndre Fischer void Panel::PrintWindowTree (void)
247*7a32b0c8SAndre Fischer {
248*7a32b0c8SAndre Fischer #ifdef DEBUG
249*7a32b0c8SAndre Fischer     Window* pElementWindow = VCLUnoHelper::GetWindow(GetElementWindow());
250*7a32b0c8SAndre Fischer     if (pElementWindow != NULL)
251b9e67834SAndre Fischer     {
252*7a32b0c8SAndre Fischer         OSL_TRACE("panel parent is %x", pElementWindow->GetParent());
253*7a32b0c8SAndre Fischer         Deck::PrintWindowSubTree(pElementWindow, 2);
254*7a32b0c8SAndre Fischer     }
255*7a32b0c8SAndre Fischer     else
256*7a32b0c8SAndre Fischer         OSL_TRACE("    panel is empty");
257*7a32b0c8SAndre Fischer #endif
258*7a32b0c8SAndre Fischer }
259*7a32b0c8SAndre Fischer 
260*7a32b0c8SAndre Fischer 
261*7a32b0c8SAndre Fischer 
262*7a32b0c8SAndre Fischer 
263*7a32b0c8SAndre Fischer Reference<awt::XWindow> Panel::GetElementWindow (void)
264*7a32b0c8SAndre Fischer {
265*7a32b0c8SAndre Fischer     if (mxElement.is())
266*7a32b0c8SAndre Fischer     {
267*7a32b0c8SAndre Fischer         Reference<ui::XToolPanel> xToolPanel(mxElement->getRealInterface(), UNO_QUERY);
268*7a32b0c8SAndre Fischer         if (xToolPanel.is())
269*7a32b0c8SAndre Fischer             return xToolPanel->getWindow();
270b9e67834SAndre Fischer     }
271b9e67834SAndre Fischer 
272*7a32b0c8SAndre Fischer     return NULL;
273b9e67834SAndre Fischer }
274b9e67834SAndre Fischer 
275b9e67834SAndre Fischer 
276ff12d537SAndre Fischer } } // end of namespace sfx2::sidebar
277