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"
26*02c50d82SAndre Fischer #include "sfx2/sidebar/ILayoutableWindow.hxx"
27b9e67834SAndre Fischer #include "sfx2/imagemgr.hxx"
2895a18594SAndre Fischer #include <vcl/ctrl.hxx>
2995a18594SAndre Fischer #include <comphelper/processfactory.hxx>
3095a18594SAndre Fischer 
31b9e67834SAndre Fischer #include <com/sun/star/ui/ContextChangeEventMultiplexer.hpp>
32b9e67834SAndre Fischer #include <com/sun/star/ui/UIElementType.hpp>
33b9e67834SAndre Fischer 
34b9e67834SAndre Fischer using namespace css;
35b9e67834SAndre Fischer using namespace cssu;
36b9e67834SAndre Fischer 
37b9e67834SAndre Fischer 
38b9e67834SAndre Fischer namespace sfx2 { namespace sidebar {
39b9e67834SAndre Fischer 
4095a18594SAndre Fischer Reference<ui::XUIElement> SidebarPanelBase::Create (
4195a18594SAndre Fischer     const ::rtl::OUString& rsResourceURL,
4295a18594SAndre Fischer     const cssu::Reference<css::frame::XFrame>& rxFrame,
437a32b0c8SAndre Fischer     Window* pWindow,
44*02c50d82SAndre Fischer     const ::boost::function<void(void)>& rMenuProvider,
45*02c50d82SAndre Fischer     const css::ui::LayoutSize& rLayoutSize)
4695a18594SAndre Fischer {
4795a18594SAndre Fischer     Reference<ui::XUIElement> xUIElement (
4895a18594SAndre Fischer         new SidebarPanelBase(
4995a18594SAndre Fischer             rsResourceURL,
5095a18594SAndre Fischer             rxFrame,
517a32b0c8SAndre Fischer             pWindow,
52*02c50d82SAndre Fischer             rMenuProvider,
53*02c50d82SAndre Fischer             rLayoutSize));
5495a18594SAndre Fischer     return xUIElement;
5595a18594SAndre Fischer }
5695a18594SAndre Fischer 
5795a18594SAndre Fischer 
5895a18594SAndre Fischer 
5995a18594SAndre Fischer 
60b9e67834SAndre Fischer SidebarPanelBase::SidebarPanelBase (
61b9e67834SAndre Fischer     const ::rtl::OUString& rsResourceURL,
62b9e67834SAndre Fischer     const cssu::Reference<css::frame::XFrame>& rxFrame,
637a32b0c8SAndre Fischer     Window* pWindow,
64*02c50d82SAndre Fischer     const ::boost::function<void(void)>& rMenuProvider,
65*02c50d82SAndre Fischer     const css::ui::LayoutSize& rLayoutSize)
66b9e67834SAndre Fischer     : SidebarPanelBaseInterfaceBase(m_aMutex),
67b9e67834SAndre Fischer       mxFrame(rxFrame),
687a32b0c8SAndre Fischer       mpControl(pWindow),
697a32b0c8SAndre Fischer       msResourceURL(rsResourceURL),
70*02c50d82SAndre Fischer       maMenuProvider(rMenuProvider),
71*02c50d82SAndre Fischer       maLayoutSize(rLayoutSize)
72b9e67834SAndre Fischer {
73*02c50d82SAndre Fischer     OSL_TRACE("SidebarPanelBase created at %x", this);
74*02c50d82SAndre Fischer 
757a32b0c8SAndre Fischer     if (mxFrame.is())
767a32b0c8SAndre Fischer     {
777a32b0c8SAndre Fischer         cssu::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer (
787a32b0c8SAndre Fischer             css::ui::ContextChangeEventMultiplexer::get(
797a32b0c8SAndre Fischer                 ::comphelper::getProcessComponentContext()));
807a32b0c8SAndre Fischer         if (xMultiplexer.is())
817a32b0c8SAndre Fischer             xMultiplexer->addContextChangeEventListener(this, mxFrame->getController());
827a32b0c8SAndre Fischer     }
837a32b0c8SAndre Fischer     if (mpControl != NULL)
847a32b0c8SAndre Fischer         mpControl->Show();
85b9e67834SAndre Fischer }
86b9e67834SAndre Fischer 
87b9e67834SAndre Fischer 
88b9e67834SAndre Fischer 
89b9e67834SAndre Fischer 
90b9e67834SAndre Fischer SidebarPanelBase::~SidebarPanelBase (void)
91b9e67834SAndre Fischer {
92*02c50d82SAndre Fischer     OSL_TRACE("SidebarPanelBase destroyed at %x", this);
93b9e67834SAndre Fischer }
94b9e67834SAndre Fischer 
95b9e67834SAndre Fischer 
96b9e67834SAndre Fischer 
97b9e67834SAndre Fischer 
98b9e67834SAndre Fischer void SAL_CALL SidebarPanelBase::disposing (void)
99b9e67834SAndre Fischer     throw (cssu::RuntimeException)
100b9e67834SAndre Fischer {
101*02c50d82SAndre Fischer     OSL_TRACE("SidebarPanelBase disposing at %x", this);
102*02c50d82SAndre Fischer 
103*02c50d82SAndre Fischer     if (mpControl != NULL)
104*02c50d82SAndre Fischer     {
105*02c50d82SAndre Fischer         delete mpControl;
106*02c50d82SAndre Fischer         mpControl = NULL;
107*02c50d82SAndre Fischer     }
10895a18594SAndre Fischer 
109b9e67834SAndre Fischer     if (mxFrame.is())
110b9e67834SAndre Fischer     {
111b9e67834SAndre Fischer         cssu::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer (
112b9e67834SAndre Fischer             css::ui::ContextChangeEventMultiplexer::get(
113b9e67834SAndre Fischer                 ::comphelper::getProcessComponentContext()));
114b9e67834SAndre Fischer         if (xMultiplexer.is())
115b9e67834SAndre Fischer             xMultiplexer->removeAllContextChangeEventListeners(this);
116b9e67834SAndre Fischer         mxFrame = NULL;
117b9e67834SAndre Fischer     }
118b9e67834SAndre Fischer }
119b9e67834SAndre Fischer 
120b9e67834SAndre Fischer 
121b9e67834SAndre Fischer 
122b9e67834SAndre Fischer 
1237a32b0c8SAndre Fischer void SidebarPanelBase::SetControl (::Window* pControl)
1247a32b0c8SAndre Fischer {
1257a32b0c8SAndre Fischer     OSL_TRACE("setting control of SidebarPanelBase at %x to %x", this, pControl);
1267a32b0c8SAndre Fischer     mpControl = pControl;
1277a32b0c8SAndre Fischer }
1287a32b0c8SAndre Fischer 
1297a32b0c8SAndre Fischer 
1307a32b0c8SAndre Fischer 
1317a32b0c8SAndre Fischer 
1327a32b0c8SAndre Fischer ::Window* SidebarPanelBase::GetControl (void) const
1337a32b0c8SAndre Fischer {
1347a32b0c8SAndre Fischer     return mpControl;
1357a32b0c8SAndre Fischer }
1367a32b0c8SAndre Fischer 
1377a32b0c8SAndre Fischer 
1387a32b0c8SAndre Fischer 
1397a32b0c8SAndre Fischer 
140b9e67834SAndre Fischer // XContextChangeEventListener
141b9e67834SAndre Fischer void SAL_CALL SidebarPanelBase::notifyContextChangeEvent (
142b9e67834SAndre Fischer     const ui::ContextChangeEventObject& rEvent)
14395a18594SAndre Fischer     throw (cssu::RuntimeException)
144b9e67834SAndre Fischer {
145*02c50d82SAndre Fischer     OSL_TRACE("SidebarPanelBase notified at %x with control at %x", this, mpControl);
146*02c50d82SAndre Fischer 
1477a32b0c8SAndre Fischer     ContextChangeReceiverInterface* pContextChangeReceiver
1487a32b0c8SAndre Fischer         = dynamic_cast<ContextChangeReceiverInterface*>(mpControl);
1497a32b0c8SAndre Fischer     if (pContextChangeReceiver != NULL)
15095a18594SAndre Fischer     {
15195a18594SAndre Fischer         const EnumContext aContext(
152b9e67834SAndre Fischer             EnumContext::GetApplicationEnum(rEvent.ApplicationName),
15395a18594SAndre Fischer             EnumContext::GetContextEnum(rEvent.ContextName));
1547a32b0c8SAndre Fischer         pContextChangeReceiver->HandleContextChange(aContext);
15595a18594SAndre Fischer     }
156b9e67834SAndre Fischer }
157b9e67834SAndre Fischer 
158b9e67834SAndre Fischer 
159b9e67834SAndre Fischer 
160b9e67834SAndre Fischer 
161b9e67834SAndre Fischer void SAL_CALL SidebarPanelBase::disposing (
162b9e67834SAndre Fischer     const css::lang::EventObject& rEvent)
163b9e67834SAndre Fischer     throw (cssu::RuntimeException)
164b9e67834SAndre Fischer {
16595a18594SAndre Fischer     (void)rEvent;
166*02c50d82SAndre Fischer 
167*02c50d82SAndre Fischer     OSL_TRACE("SidebarPanelBase disposing(e) at %x", this);
16895a18594SAndre Fischer 
16995a18594SAndre Fischer     mxFrame = NULL;
17095a18594SAndre Fischer     mpControl = NULL;
171b9e67834SAndre Fischer }
172b9e67834SAndre Fischer 
173b9e67834SAndre Fischer 
174b9e67834SAndre Fischer 
175b9e67834SAndre Fischer 
176b9e67834SAndre Fischer cssu::Reference<css::frame::XFrame> SAL_CALL SidebarPanelBase::getFrame (void)
177b9e67834SAndre Fischer     throw(cssu::RuntimeException)
178b9e67834SAndre Fischer {
179b9e67834SAndre Fischer     return mxFrame;
180b9e67834SAndre Fischer }
181b9e67834SAndre Fischer 
182b9e67834SAndre Fischer 
183b9e67834SAndre Fischer 
184b9e67834SAndre Fischer 
185b9e67834SAndre Fischer ::rtl::OUString SAL_CALL SidebarPanelBase::getResourceURL (void)
186b9e67834SAndre Fischer     throw(cssu::RuntimeException)
187b9e67834SAndre Fischer {
188b9e67834SAndre Fischer     return msResourceURL;
189b9e67834SAndre Fischer }
190b9e67834SAndre Fischer 
191b9e67834SAndre Fischer 
192b9e67834SAndre Fischer 
193b9e67834SAndre Fischer 
194b9e67834SAndre Fischer sal_Int16 SAL_CALL SidebarPanelBase::getType (void)
195b9e67834SAndre Fischer     throw(cssu::RuntimeException)
196b9e67834SAndre Fischer {
197b9e67834SAndre Fischer     return ui::UIElementType::TOOLPANEL;
198b9e67834SAndre Fischer }
199b9e67834SAndre Fischer 
200b9e67834SAndre Fischer 
201b9e67834SAndre Fischer 
202b9e67834SAndre Fischer 
203b9e67834SAndre Fischer Reference<XInterface> SAL_CALL SidebarPanelBase::getRealInterface (void)
204b9e67834SAndre Fischer     throw(cssu::RuntimeException)
205b9e67834SAndre Fischer {
206b9e67834SAndre Fischer     return Reference<XInterface>(static_cast<XWeak*>(this));
207b9e67834SAndre Fischer }
208b9e67834SAndre Fischer 
209b9e67834SAndre Fischer 
210b9e67834SAndre Fischer 
211b9e67834SAndre Fischer 
212b9e67834SAndre Fischer Reference<accessibility::XAccessible> SAL_CALL SidebarPanelBase::createAccessible (
213b9e67834SAndre Fischer     const Reference<accessibility::XAccessible>& rxParentAccessible)
214b9e67834SAndre Fischer     throw(cssu::RuntimeException)
215b9e67834SAndre Fischer {
21695a18594SAndre Fischer     (void)rxParentAccessible;
21795a18594SAndre Fischer 
218b9e67834SAndre Fischer     // Not yet implemented.
219b9e67834SAndre Fischer     return NULL;
220b9e67834SAndre Fischer }
221b9e67834SAndre Fischer 
222b9e67834SAndre Fischer 
223b9e67834SAndre Fischer 
224b9e67834SAndre Fischer 
225b9e67834SAndre Fischer Reference<awt::XWindow> SAL_CALL SidebarPanelBase::getWindow (void)
226b9e67834SAndre Fischer     throw(cssu::RuntimeException)
227b9e67834SAndre Fischer {
22895a18594SAndre Fischer     if (mpControl != NULL)
22995a18594SAndre Fischer         return Reference<awt::XWindow>(
23095a18594SAndre Fischer             mpControl->GetComponentInterface(),
23195a18594SAndre Fischer             UNO_QUERY);
23295a18594SAndre Fischer     else
23395a18594SAndre Fischer         return NULL;
234b9e67834SAndre Fischer }
235b9e67834SAndre Fischer 
236b9e67834SAndre Fischer 
237b9e67834SAndre Fischer 
238b9e67834SAndre Fischer 
2397a32b0c8SAndre Fischer ui::LayoutSize SAL_CALL SidebarPanelBase::getHeightForWidth (const sal_Int32 nWidth)
24095a18594SAndre Fischer     throw(cssu::RuntimeException)
241b9e67834SAndre Fischer {
242*02c50d82SAndre Fischer     if (maLayoutSize.Minimum >= 0)
243*02c50d82SAndre Fischer         return maLayoutSize;
244*02c50d82SAndre Fischer     else
2457a32b0c8SAndre Fischer     {
246*02c50d82SAndre Fischer         ILayoutableWindow* pLayoutableWindow = dynamic_cast<ILayoutableWindow*>(mpControl);
247*02c50d82SAndre Fischer         if (pLayoutableWindow != NULL)
248*02c50d82SAndre Fischer             return pLayoutableWindow->GetHeightForWidth(nWidth);
249*02c50d82SAndre Fischer         else if (mpControl != NULL)
250*02c50d82SAndre Fischer         {
251*02c50d82SAndre Fischer             const sal_Int32 nHeight (mpControl->GetSizePixel().Height());
252*02c50d82SAndre Fischer             return ui::LayoutSize(nHeight,nHeight,nHeight);
253*02c50d82SAndre Fischer         }
2547a32b0c8SAndre Fischer     }
255*02c50d82SAndre Fischer 
256*02c50d82SAndre Fischer     return ui::LayoutSize(0,0,0);
2577a32b0c8SAndre Fischer }
2587a32b0c8SAndre Fischer 
2597a32b0c8SAndre Fischer 
2607a32b0c8SAndre Fischer 
2617a32b0c8SAndre Fischer 
2627a32b0c8SAndre Fischer void SAL_CALL SidebarPanelBase::showMenu (void)
2637a32b0c8SAndre Fischer     throw(cssu::RuntimeException)
2647a32b0c8SAndre Fischer {
2657a32b0c8SAndre Fischer     if (maMenuProvider)
2667a32b0c8SAndre Fischer         maMenuProvider();
267b9e67834SAndre Fischer }
268b9e67834SAndre Fischer 
269b9e67834SAndre Fischer 
270b9e67834SAndre Fischer 
2717a32b0c8SAndre Fischer 
2727a32b0c8SAndre Fischer sal_Bool SAL_CALL SidebarPanelBase::isContextSupported (
2737a32b0c8SAndre Fischer     const ::rtl::OUString& rsApplicationName,
2747a32b0c8SAndre Fischer     const ::rtl::OUString& rsContextName)
2757a32b0c8SAndre Fischer     throw(cssu::RuntimeException)
2767a32b0c8SAndre Fischer {
2777a32b0c8SAndre Fischer     (void)rsApplicationName;
2787a32b0c8SAndre Fischer     (void)rsContextName;
2797a32b0c8SAndre Fischer 
2807a32b0c8SAndre Fischer     return sal_True;
2817a32b0c8SAndre Fischer }
2827a32b0c8SAndre Fischer 
2837a32b0c8SAndre Fischer 
284b9e67834SAndre Fischer } } // end of namespace sfx2::sidebar
285