xref: /AOO41X/main/sfx2/source/sidebar/SidebarPanelBase.cxx (revision fe617e93560c0575040cf13b538ba840fa9e2479)
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 
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 
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     //    OSL_TRACE("SidebarPanelBase created at %x", this);
71 
72     if (mxFrame.is())
73     {
74         cssu::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer (
75             css::ui::ContextChangeEventMultiplexer::get(
76                 ::comphelper::getProcessComponentContext()));
77         if (xMultiplexer.is())
78             xMultiplexer->addContextChangeEventListener(this, mxFrame->getController());
79     }
80     if (mpControl != NULL)
81         mpControl->Show();
82 }
83 
84 
85 
86 
87 SidebarPanelBase::~SidebarPanelBase (void)
88 {
89 }
90 
91 
92 
93 
94 void SAL_CALL SidebarPanelBase::disposing (void)
95     throw (cssu::RuntimeException)
96 {
97     if (mpControl != NULL)
98     {
99         delete mpControl;
100         mpControl = NULL;
101     }
102 
103     if (mxFrame.is())
104     {
105         cssu::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer (
106             css::ui::ContextChangeEventMultiplexer::get(
107                 ::comphelper::getProcessComponentContext()));
108         if (xMultiplexer.is())
109             xMultiplexer->removeAllContextChangeEventListeners(this);
110         mxFrame = NULL;
111     }
112 }
113 
114 
115 
116 
117 void SidebarPanelBase::SetControl (::Window* pControl)
118 {
119     mpControl = pControl;
120 }
121 
122 
123 
124 
125 ::Window* SidebarPanelBase::GetControl (void) const
126 {
127     return mpControl;
128 }
129 
130 
131 
132 
133 // XContextChangeEventListener
134 void SAL_CALL SidebarPanelBase::notifyContextChangeEvent (
135     const ui::ContextChangeEventObject& rEvent)
136     throw (cssu::RuntimeException)
137 {
138     IContextChangeReceiver* pContextChangeReceiver
139         = dynamic_cast<IContextChangeReceiver*>(mpControl);
140     if (pContextChangeReceiver != NULL)
141     {
142         const EnumContext aContext(
143             EnumContext::GetApplicationEnum(rEvent.ApplicationName),
144             EnumContext::GetContextEnum(rEvent.ContextName));
145         pContextChangeReceiver->HandleContextChange(aContext);
146     }
147 }
148 
149 
150 
151 
152 void SAL_CALL SidebarPanelBase::disposing (
153     const css::lang::EventObject& rEvent)
154     throw (cssu::RuntimeException)
155 {
156     (void)rEvent;
157 
158     mxFrame = NULL;
159     mpControl = NULL;
160 }
161 
162 
163 
164 
165 cssu::Reference<css::frame::XFrame> SAL_CALL SidebarPanelBase::getFrame (void)
166     throw(cssu::RuntimeException)
167 {
168     return mxFrame;
169 }
170 
171 
172 
173 
174 ::rtl::OUString SAL_CALL SidebarPanelBase::getResourceURL (void)
175     throw(cssu::RuntimeException)
176 {
177     return msResourceURL;
178 }
179 
180 
181 
182 
183 sal_Int16 SAL_CALL SidebarPanelBase::getType (void)
184     throw(cssu::RuntimeException)
185 {
186     return ui::UIElementType::TOOLPANEL;
187 }
188 
189 
190 
191 
192 Reference<XInterface> SAL_CALL SidebarPanelBase::getRealInterface (void)
193     throw(cssu::RuntimeException)
194 {
195     return Reference<XInterface>(static_cast<XWeak*>(this));
196 }
197 
198 
199 
200 
201 Reference<accessibility::XAccessible> SAL_CALL SidebarPanelBase::createAccessible (
202     const Reference<accessibility::XAccessible>& rxParentAccessible)
203     throw(cssu::RuntimeException)
204 {
205     (void)rxParentAccessible;
206 
207     // Not yet implemented.
208     return NULL;
209 }
210 
211 
212 
213 
214 Reference<awt::XWindow> SAL_CALL SidebarPanelBase::getWindow (void)
215     throw(cssu::RuntimeException)
216 {
217     if (mpControl != NULL)
218         return Reference<awt::XWindow>(
219             mpControl->GetComponentInterface(),
220             UNO_QUERY);
221     else
222         return NULL;
223 }
224 
225 
226 
227 
228 ui::LayoutSize SAL_CALL SidebarPanelBase::getHeightForWidth (const sal_Int32 nWidth)
229     throw(cssu::RuntimeException)
230 {
231     if (maLayoutSize.Minimum >= 0)
232         return maLayoutSize;
233     else
234     {
235         ILayoutableWindow* pLayoutableWindow = dynamic_cast<ILayoutableWindow*>(mpControl);
236         if (pLayoutableWindow != NULL)
237             return pLayoutableWindow->GetHeightForWidth(nWidth);
238         else if (mpControl != NULL)
239         {
240             const sal_Int32 nHeight (mpControl->GetSizePixel().Height());
241             return ui::LayoutSize(nHeight,nHeight,nHeight);
242         }
243     }
244 
245     return ui::LayoutSize(0,0,0);
246 }
247 
248 
249 
250 
251 } } // end of namespace sfx2::sidebar
252