xref: /AOO41X/main/sfx2/source/sidebar/SidebarPanelBase.cxx (revision f120fe4110718eecb5f5933a421104aa4582f505)
1b9e67834SAndre Fischer /**************************************************************
2b9e67834SAndre Fischer  *
3b9e67834SAndre Fischer  * Licensed to the Apache Software Foundation (ASF) under one
4b9e67834SAndre Fischer  * or more contributor license agreements.  See the NOTICE file
5b9e67834SAndre Fischer  * distributed with this work for additional information
6b9e67834SAndre Fischer  * regarding copyright ownership.  The ASF licenses this file
7b9e67834SAndre Fischer  * to you under the Apache License, Version 2.0 (the
8b9e67834SAndre Fischer  * "License"); you may not use this file except in compliance
9b9e67834SAndre Fischer  * with the License.  You may obtain a copy of the License at
10b9e67834SAndre Fischer  *
11b9e67834SAndre Fischer  *   http://www.apache.org/licenses/LICENSE-2.0
12b9e67834SAndre Fischer  *
13b9e67834SAndre Fischer  * Unless required by applicable law or agreed to in writing,
14b9e67834SAndre Fischer  * software distributed under the License is distributed on an
15b9e67834SAndre Fischer  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b9e67834SAndre Fischer  * KIND, either express or implied.  See the License for the
17b9e67834SAndre Fischer  * specific language governing permissions and limitations
18b9e67834SAndre Fischer  * under the License.
19b9e67834SAndre Fischer  *
20b9e67834SAndre Fischer  *************************************************************/
21b9e67834SAndre Fischer 
22b9e67834SAndre Fischer #include "precompiled_sfx2.hxx"
23b9e67834SAndre Fischer 
24b9e67834SAndre Fischer #include "sfx2/sidebar/SidebarPanelBase.hxx"
25b9e67834SAndre Fischer #include "sfx2/sidebar/Theme.hxx"
2602c50d82SAndre Fischer #include "sfx2/sidebar/ILayoutableWindow.hxx"
27*f120fe41SAndre Fischer #include "sfx2/sidebar/IContextChangeReceiver.hxx"
28b9e67834SAndre Fischer #include "sfx2/imagemgr.hxx"
2995a18594SAndre Fischer #include <vcl/ctrl.hxx>
3095a18594SAndre Fischer #include <comphelper/processfactory.hxx>
3195a18594SAndre Fischer 
32b9e67834SAndre Fischer #include <com/sun/star/ui/ContextChangeEventMultiplexer.hpp>
33b9e67834SAndre Fischer #include <com/sun/star/ui/UIElementType.hpp>
34b9e67834SAndre Fischer 
35b9e67834SAndre Fischer using namespace css;
36b9e67834SAndre Fischer using namespace cssu;
37b9e67834SAndre Fischer 
38b9e67834SAndre Fischer 
39b9e67834SAndre Fischer namespace sfx2 { namespace sidebar {
40b9e67834SAndre Fischer 
4195a18594SAndre Fischer Reference<ui::XUIElement> SidebarPanelBase::Create (
4295a18594SAndre Fischer     const ::rtl::OUString& rsResourceURL,
4395a18594SAndre Fischer     const cssu::Reference<css::frame::XFrame>& rxFrame,
447a32b0c8SAndre Fischer     Window* pWindow,
4502c50d82SAndre Fischer     const ::boost::function<void(void)>& rMenuProvider,
4602c50d82SAndre Fischer     const css::ui::LayoutSize& rLayoutSize)
4795a18594SAndre Fischer {
4895a18594SAndre Fischer     Reference<ui::XUIElement> xUIElement (
4995a18594SAndre Fischer         new SidebarPanelBase(
5095a18594SAndre Fischer             rsResourceURL,
5195a18594SAndre Fischer             rxFrame,
527a32b0c8SAndre Fischer             pWindow,
5302c50d82SAndre Fischer             rMenuProvider,
5402c50d82SAndre Fischer             rLayoutSize));
5595a18594SAndre Fischer     return xUIElement;
5695a18594SAndre Fischer }
5795a18594SAndre Fischer 
5895a18594SAndre Fischer 
5995a18594SAndre Fischer 
6095a18594SAndre Fischer 
61b9e67834SAndre Fischer SidebarPanelBase::SidebarPanelBase (
62b9e67834SAndre Fischer     const ::rtl::OUString& rsResourceURL,
63b9e67834SAndre Fischer     const cssu::Reference<css::frame::XFrame>& rxFrame,
647a32b0c8SAndre Fischer     Window* pWindow,
6502c50d82SAndre Fischer     const ::boost::function<void(void)>& rMenuProvider,
6602c50d82SAndre Fischer     const css::ui::LayoutSize& rLayoutSize)
67b9e67834SAndre Fischer     : SidebarPanelBaseInterfaceBase(m_aMutex),
68b9e67834SAndre Fischer       mxFrame(rxFrame),
697a32b0c8SAndre Fischer       mpControl(pWindow),
707a32b0c8SAndre Fischer       msResourceURL(rsResourceURL),
7102c50d82SAndre Fischer       maMenuProvider(rMenuProvider),
7202c50d82SAndre Fischer       maLayoutSize(rLayoutSize)
737a32b0c8SAndre Fischer {
7402c50d82SAndre Fischer     OSL_TRACE("SidebarPanelBase created at %x", this);
7502c50d82SAndre Fischer 
767a32b0c8SAndre Fischer     if (mxFrame.is())
77b9e67834SAndre Fischer     {
78b9e67834SAndre Fischer         cssu::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer (
79b9e67834SAndre Fischer             css::ui::ContextChangeEventMultiplexer::get(
80b9e67834SAndre Fischer                 ::comphelper::getProcessComponentContext()));
81b9e67834SAndre Fischer         if (xMultiplexer.is())
82b9e67834SAndre Fischer             xMultiplexer->addContextChangeEventListener(this, mxFrame->getController());
83b9e67834SAndre Fischer     }
847a32b0c8SAndre Fischer     if (mpControl != NULL)
857a32b0c8SAndre Fischer         mpControl->Show();
867a32b0c8SAndre Fischer }
87b9e67834SAndre Fischer 
88b9e67834SAndre Fischer 
89b9e67834SAndre Fischer 
90b9e67834SAndre Fischer 
91b9e67834SAndre Fischer SidebarPanelBase::~SidebarPanelBase (void)
92b9e67834SAndre Fischer {
9302c50d82SAndre Fischer     OSL_TRACE("SidebarPanelBase destroyed at %x", this);
94b9e67834SAndre Fischer }
95b9e67834SAndre Fischer 
96b9e67834SAndre Fischer 
97b9e67834SAndre Fischer 
98b9e67834SAndre Fischer 
99b9e67834SAndre Fischer void SAL_CALL SidebarPanelBase::disposing (void)
100b9e67834SAndre Fischer     throw (cssu::RuntimeException)
101b9e67834SAndre Fischer {
10202c50d82SAndre Fischer     OSL_TRACE("SidebarPanelBase disposing at %x", this);
10302c50d82SAndre Fischer 
10402c50d82SAndre Fischer     if (mpControl != NULL)
10502c50d82SAndre Fischer     {
10602c50d82SAndre Fischer         delete mpControl;
10795a18594SAndre Fischer         mpControl = NULL;
10802c50d82SAndre Fischer     }
10995a18594SAndre Fischer 
110b9e67834SAndre Fischer     if (mxFrame.is())
111b9e67834SAndre Fischer     {
112b9e67834SAndre Fischer         cssu::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer (
113b9e67834SAndre Fischer             css::ui::ContextChangeEventMultiplexer::get(
114b9e67834SAndre Fischer                 ::comphelper::getProcessComponentContext()));
115b9e67834SAndre Fischer         if (xMultiplexer.is())
116b9e67834SAndre Fischer             xMultiplexer->removeAllContextChangeEventListeners(this);
117b9e67834SAndre Fischer         mxFrame = NULL;
118b9e67834SAndre Fischer     }
119b9e67834SAndre Fischer }
120b9e67834SAndre Fischer 
121b9e67834SAndre Fischer 
122b9e67834SAndre Fischer 
123b9e67834SAndre Fischer 
1247a32b0c8SAndre Fischer void SidebarPanelBase::SetControl (::Window* pControl)
1257a32b0c8SAndre Fischer {
1267a32b0c8SAndre Fischer     OSL_TRACE("setting control of SidebarPanelBase at %x to %x", this, pControl);
1277a32b0c8SAndre Fischer     mpControl = pControl;
1287a32b0c8SAndre Fischer }
1297a32b0c8SAndre Fischer 
1307a32b0c8SAndre Fischer 
1317a32b0c8SAndre Fischer 
1327a32b0c8SAndre Fischer 
1337a32b0c8SAndre Fischer ::Window* SidebarPanelBase::GetControl (void) const
1347a32b0c8SAndre Fischer {
1357a32b0c8SAndre Fischer     return mpControl;
1367a32b0c8SAndre Fischer }
1377a32b0c8SAndre Fischer 
1387a32b0c8SAndre Fischer 
1397a32b0c8SAndre Fischer 
1407a32b0c8SAndre Fischer 
141b9e67834SAndre Fischer // XContextChangeEventListener
142b9e67834SAndre Fischer void SAL_CALL SidebarPanelBase::notifyContextChangeEvent (
143b9e67834SAndre Fischer     const ui::ContextChangeEventObject& rEvent)
14495a18594SAndre Fischer     throw (cssu::RuntimeException)
145b9e67834SAndre Fischer {
14602c50d82SAndre Fischer     OSL_TRACE("SidebarPanelBase notified at %x with control at %x", this, mpControl);
14702c50d82SAndre Fischer 
148*f120fe41SAndre Fischer     IContextChangeReceiver* pContextChangeReceiver
149*f120fe41SAndre Fischer         = dynamic_cast<IContextChangeReceiver*>(mpControl);
1507a32b0c8SAndre Fischer     if (pContextChangeReceiver != NULL)
15195a18594SAndre Fischer     {
15295a18594SAndre Fischer         const EnumContext aContext(
153b9e67834SAndre Fischer             EnumContext::GetApplicationEnum(rEvent.ApplicationName),
15495a18594SAndre Fischer             EnumContext::GetContextEnum(rEvent.ContextName));
15595a18594SAndre Fischer         pContextChangeReceiver->HandleContextChange(aContext);
15695a18594SAndre Fischer     }
157b9e67834SAndre Fischer }
158b9e67834SAndre Fischer 
159b9e67834SAndre Fischer 
160b9e67834SAndre Fischer 
161b9e67834SAndre Fischer 
162b9e67834SAndre Fischer void SAL_CALL SidebarPanelBase::disposing (
163b9e67834SAndre Fischer     const css::lang::EventObject& rEvent)
164b9e67834SAndre Fischer     throw (cssu::RuntimeException)
165b9e67834SAndre Fischer {
16695a18594SAndre Fischer     (void)rEvent;
16795a18594SAndre Fischer 
16802c50d82SAndre Fischer     OSL_TRACE("SidebarPanelBase disposing(e) at %x", this);
16902c50d82SAndre Fischer 
17095a18594SAndre Fischer     mxFrame = NULL;
17195a18594SAndre Fischer     mpControl = NULL;
172b9e67834SAndre Fischer }
173b9e67834SAndre Fischer 
174b9e67834SAndre Fischer 
175b9e67834SAndre Fischer 
176b9e67834SAndre Fischer 
177b9e67834SAndre Fischer cssu::Reference<css::frame::XFrame> SAL_CALL SidebarPanelBase::getFrame (void)
178b9e67834SAndre Fischer     throw(cssu::RuntimeException)
179b9e67834SAndre Fischer {
180b9e67834SAndre Fischer     return mxFrame;
181b9e67834SAndre Fischer }
182b9e67834SAndre Fischer 
183b9e67834SAndre Fischer 
184b9e67834SAndre Fischer 
185b9e67834SAndre Fischer 
186b9e67834SAndre Fischer ::rtl::OUString SAL_CALL SidebarPanelBase::getResourceURL (void)
187b9e67834SAndre Fischer     throw(cssu::RuntimeException)
188b9e67834SAndre Fischer {
189b9e67834SAndre Fischer     return msResourceURL;
190b9e67834SAndre Fischer }
191b9e67834SAndre Fischer 
192b9e67834SAndre Fischer 
193b9e67834SAndre Fischer 
194b9e67834SAndre Fischer 
195b9e67834SAndre Fischer sal_Int16 SAL_CALL SidebarPanelBase::getType (void)
196b9e67834SAndre Fischer     throw(cssu::RuntimeException)
197b9e67834SAndre Fischer {
198b9e67834SAndre Fischer     return ui::UIElementType::TOOLPANEL;
199b9e67834SAndre Fischer }
200b9e67834SAndre Fischer 
201b9e67834SAndre Fischer 
202b9e67834SAndre Fischer 
203b9e67834SAndre Fischer 
204b9e67834SAndre Fischer Reference<XInterface> SAL_CALL SidebarPanelBase::getRealInterface (void)
205b9e67834SAndre Fischer     throw(cssu::RuntimeException)
206b9e67834SAndre Fischer {
207b9e67834SAndre Fischer     return Reference<XInterface>(static_cast<XWeak*>(this));
208b9e67834SAndre Fischer }
209b9e67834SAndre Fischer 
210b9e67834SAndre Fischer 
211b9e67834SAndre Fischer 
212b9e67834SAndre Fischer 
213b9e67834SAndre Fischer Reference<accessibility::XAccessible> SAL_CALL SidebarPanelBase::createAccessible (
214b9e67834SAndre Fischer     const Reference<accessibility::XAccessible>& rxParentAccessible)
215b9e67834SAndre Fischer     throw(cssu::RuntimeException)
216b9e67834SAndre Fischer {
21795a18594SAndre Fischer     (void)rxParentAccessible;
21895a18594SAndre Fischer 
219b9e67834SAndre Fischer     // Not yet implemented.
220b9e67834SAndre Fischer     return NULL;
221b9e67834SAndre Fischer }
222b9e67834SAndre Fischer 
223b9e67834SAndre Fischer 
224b9e67834SAndre Fischer 
225b9e67834SAndre Fischer 
226b9e67834SAndre Fischer Reference<awt::XWindow> SAL_CALL SidebarPanelBase::getWindow (void)
227b9e67834SAndre Fischer     throw(cssu::RuntimeException)
228b9e67834SAndre Fischer {
22995a18594SAndre Fischer     if (mpControl != NULL)
230b9e67834SAndre Fischer         return Reference<awt::XWindow>(
23195a18594SAndre Fischer             mpControl->GetComponentInterface(),
232b9e67834SAndre Fischer             UNO_QUERY);
23395a18594SAndre Fischer     else
23495a18594SAndre Fischer         return NULL;
235b9e67834SAndre Fischer }
236b9e67834SAndre Fischer 
237b9e67834SAndre Fischer 
238b9e67834SAndre Fischer 
239b9e67834SAndre Fischer 
2407a32b0c8SAndre Fischer ui::LayoutSize SAL_CALL SidebarPanelBase::getHeightForWidth (const sal_Int32 nWidth)
24195a18594SAndre Fischer     throw(cssu::RuntimeException)
242b9e67834SAndre Fischer {
24302c50d82SAndre Fischer     if (maLayoutSize.Minimum >= 0)
24402c50d82SAndre Fischer         return maLayoutSize;
24502c50d82SAndre Fischer     else
24602c50d82SAndre Fischer     {
24702c50d82SAndre Fischer         ILayoutableWindow* pLayoutableWindow = dynamic_cast<ILayoutableWindow*>(mpControl);
24802c50d82SAndre Fischer         if (pLayoutableWindow != NULL)
24902c50d82SAndre Fischer             return pLayoutableWindow->GetHeightForWidth(nWidth);
25002c50d82SAndre Fischer         else if (mpControl != NULL)
2517a32b0c8SAndre Fischer         {
2527a32b0c8SAndre Fischer             const sal_Int32 nHeight (mpControl->GetSizePixel().Height());
2537a32b0c8SAndre Fischer             return ui::LayoutSize(nHeight,nHeight,nHeight);
2547a32b0c8SAndre Fischer         }
25502c50d82SAndre Fischer     }
25602c50d82SAndre Fischer 
2577a32b0c8SAndre Fischer     return ui::LayoutSize(0,0,0);
258b9e67834SAndre Fischer }
259b9e67834SAndre Fischer 
260b9e67834SAndre Fischer 
261b9e67834SAndre Fischer 
2627a32b0c8SAndre Fischer 
2637a32b0c8SAndre Fischer void SAL_CALL SidebarPanelBase::showMenu (void)
2647a32b0c8SAndre Fischer     throw(cssu::RuntimeException)
2657a32b0c8SAndre Fischer {
2667a32b0c8SAndre Fischer     if (maMenuProvider)
2677a32b0c8SAndre Fischer         maMenuProvider();
2687a32b0c8SAndre Fischer }
2697a32b0c8SAndre Fischer 
2707a32b0c8SAndre Fischer 
2717a32b0c8SAndre Fischer 
2727a32b0c8SAndre Fischer 
2737a32b0c8SAndre Fischer sal_Bool SAL_CALL SidebarPanelBase::isContextSupported (
2747a32b0c8SAndre Fischer     const ::rtl::OUString& rsApplicationName,
2757a32b0c8SAndre Fischer     const ::rtl::OUString& rsContextName)
2767a32b0c8SAndre Fischer     throw(cssu::RuntimeException)
2777a32b0c8SAndre Fischer {
2787a32b0c8SAndre Fischer     (void)rsApplicationName;
2797a32b0c8SAndre Fischer     (void)rsContextName;
2807a32b0c8SAndre Fischer 
2817a32b0c8SAndre Fischer     return sal_True;
2827a32b0c8SAndre Fischer }
2837a32b0c8SAndre Fischer 
2847a32b0c8SAndre Fischer 
285b9e67834SAndre Fischer } } // end of namespace sfx2::sidebar
286