1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #include "precompiled_sfx2.hxx"
23 
24 #include "sfx2/sidebar/SidebarPanelBase.hxx"
25 #include "sfx2/sidebar/Theme.hxx"
26 #include "sfx2/sidebar/ILayoutableWindow.hxx"
27 #include "sfx2/sidebar/IContextChangeReceiver.hxx"
28 #include "sfx2/imagemgr.hxx"
29 #include <vcl/ctrl.hxx>
30 #include <comphelper/processfactory.hxx>
31 
32 #include <com/sun/star/ui/ContextChangeEventMultiplexer.hpp>
33 #include <com/sun/star/ui/UIElementType.hpp>
34 
35 using namespace css;
36 using namespace cssu;
37 
38 
39 namespace sfx2 { namespace sidebar {
40 
Create(const::rtl::OUString & rsResourceURL,const cssu::Reference<css::frame::XFrame> & rxFrame,Window * pWindow,const css::ui::LayoutSize & rLayoutSize)41 Reference<ui::XUIElement> SidebarPanelBase::Create (
42     const ::rtl::OUString& rsResourceURL,
43     const cssu::Reference<css::frame::XFrame>& rxFrame,
44     Window* pWindow,
45     const css::ui::LayoutSize& rLayoutSize)
46 {
47     Reference<ui::XUIElement> xUIElement (
48         new SidebarPanelBase(
49             rsResourceURL,
50             rxFrame,
51             pWindow,
52             rLayoutSize));
53     return xUIElement;
54 }
55 
56 
57 
58 
SidebarPanelBase(const::rtl::OUString & rsResourceURL,const cssu::Reference<css::frame::XFrame> & rxFrame,Window * pWindow,const css::ui::LayoutSize & rLayoutSize)59 SidebarPanelBase::SidebarPanelBase (
60     const ::rtl::OUString& rsResourceURL,
61     const cssu::Reference<css::frame::XFrame>& rxFrame,
62     Window* pWindow,
63     const css::ui::LayoutSize& rLayoutSize)
64     : SidebarPanelBaseInterfaceBase(m_aMutex),
65       mxFrame(rxFrame),
66       mpControl(pWindow),
67       msResourceURL(rsResourceURL),
68       maLayoutSize(rLayoutSize)
69 {
70     if (mxFrame.is())
71     {
72         cssu::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer (
73             css::ui::ContextChangeEventMultiplexer::get(
74                 ::comphelper::getProcessComponentContext()));
75         if (xMultiplexer.is())
76             xMultiplexer->addContextChangeEventListener(this, mxFrame->getController());
77     }
78     if (mpControl != NULL)
79     {
80         mpControl->SetBackground(Theme::GetWallpaper(Theme::Paint_PanelBackground));
81         mpControl->Show();
82     }
83 }
84 
85 
86 
87 
~SidebarPanelBase(void)88 SidebarPanelBase::~SidebarPanelBase (void)
89 {
90 }
91 
92 
93 
94 
disposing(void)95 void SAL_CALL SidebarPanelBase::disposing (void)
96     throw (cssu::RuntimeException)
97 {
98     if (mpControl != NULL)
99     {
100         delete mpControl;
101         mpControl = NULL;
102     }
103 
104     if (mxFrame.is())
105     {
106         cssu::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer (
107             css::ui::ContextChangeEventMultiplexer::get(
108                 ::comphelper::getProcessComponentContext()));
109         if (xMultiplexer.is())
110             xMultiplexer->removeAllContextChangeEventListeners(this);
111         mxFrame = NULL;
112     }
113 }
114 
115 
116 
117 
SetControl(::Window * pControl)118 void SidebarPanelBase::SetControl (::Window* pControl)
119 {
120     mpControl = pControl;
121 }
122 
123 
124 
125 
GetControl(void) const126 ::Window* SidebarPanelBase::GetControl (void) const
127 {
128     return mpControl;
129 }
130 
131 
132 
133 
134 // XContextChangeEventListener
notifyContextChangeEvent(const ui::ContextChangeEventObject & rEvent)135 void SAL_CALL SidebarPanelBase::notifyContextChangeEvent (
136     const ui::ContextChangeEventObject& rEvent)
137     throw (cssu::RuntimeException)
138 {
139     IContextChangeReceiver* pContextChangeReceiver
140         = dynamic_cast<IContextChangeReceiver*>(mpControl);
141     if (pContextChangeReceiver != NULL)
142     {
143         const EnumContext aContext(
144             EnumContext::GetApplicationEnum(rEvent.ApplicationName),
145             EnumContext::GetContextEnum(rEvent.ContextName));
146         pContextChangeReceiver->HandleContextChange(aContext);
147     }
148 }
149 
150 
151 
152 
disposing(const css::lang::EventObject & rEvent)153 void SAL_CALL SidebarPanelBase::disposing (
154     const css::lang::EventObject& rEvent)
155     throw (cssu::RuntimeException)
156 {
157     (void)rEvent;
158 
159     mxFrame = NULL;
160     mpControl = NULL;
161 }
162 
163 
164 
165 
getFrame(void)166 cssu::Reference<css::frame::XFrame> SAL_CALL SidebarPanelBase::getFrame (void)
167     throw(cssu::RuntimeException)
168 {
169     return mxFrame;
170 }
171 
172 
173 
174 
getResourceURL(void)175 ::rtl::OUString SAL_CALL SidebarPanelBase::getResourceURL (void)
176     throw(cssu::RuntimeException)
177 {
178     return msResourceURL;
179 }
180 
181 
182 
183 
getType(void)184 sal_Int16 SAL_CALL SidebarPanelBase::getType (void)
185     throw(cssu::RuntimeException)
186 {
187     return ui::UIElementType::TOOLPANEL;
188 }
189 
190 
191 
192 
getRealInterface(void)193 Reference<XInterface> SAL_CALL SidebarPanelBase::getRealInterface (void)
194     throw(cssu::RuntimeException)
195 {
196     return Reference<XInterface>(static_cast<XWeak*>(this));
197 }
198 
199 
200 
201 
createAccessible(const Reference<accessibility::XAccessible> & rxParentAccessible)202 Reference<accessibility::XAccessible> SAL_CALL SidebarPanelBase::createAccessible (
203     const Reference<accessibility::XAccessible>& rxParentAccessible)
204     throw(cssu::RuntimeException)
205 {
206     (void)rxParentAccessible;
207 
208     // Not yet implemented.
209     return NULL;
210 }
211 
212 
213 
214 
getWindow(void)215 Reference<awt::XWindow> SAL_CALL SidebarPanelBase::getWindow (void)
216     throw(cssu::RuntimeException)
217 {
218     if (mpControl != NULL)
219         return Reference<awt::XWindow>(
220             mpControl->GetComponentInterface(),
221             UNO_QUERY);
222     else
223         return NULL;
224 }
225 
226 
227 
228 
getHeightForWidth(const sal_Int32 nWidth)229 ui::LayoutSize SAL_CALL SidebarPanelBase::getHeightForWidth (const sal_Int32 nWidth)
230     throw(cssu::RuntimeException)
231 {
232     if (maLayoutSize.Minimum >= 0)
233         return maLayoutSize;
234     else
235     {
236         ILayoutableWindow* pLayoutableWindow = dynamic_cast<ILayoutableWindow*>(mpControl);
237         if (pLayoutableWindow != NULL)
238             return pLayoutableWindow->GetHeightForWidth(nWidth);
239         else if (mpControl != NULL)
240         {
241             const sal_Int32 nHeight (mpControl->GetSizePixel().Height());
242             return ui::LayoutSize(nHeight,nHeight,nHeight);
243         }
244     }
245 
246     return ui::LayoutSize(0,0,0);
247 }
248 
249 
250 
251 
252 } } // end of namespace sfx2::sidebar
253