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/imagemgr.hxx" 27 #include <vcl/ctrl.hxx> 28 #include <comphelper/processfactory.hxx> 29 30 #include <com/sun/star/ui/ContextChangeEventMultiplexer.hpp> 31 #include <com/sun/star/ui/UIElementType.hpp> 32 33 using namespace css; 34 using namespace cssu; 35 36 37 namespace sfx2 { namespace sidebar { 38 39 Reference<ui::XUIElement> SidebarPanelBase::Create ( 40 const ::rtl::OUString& rsResourceURL, 41 const cssu::Reference<css::frame::XFrame>& rxFrame, 42 Window* pWindow, 43 const ::boost::function<void(void)>& rMenuProvider) 44 { 45 Reference<ui::XUIElement> xUIElement ( 46 new SidebarPanelBase( 47 rsResourceURL, 48 rxFrame, 49 pWindow, 50 rMenuProvider)); 51 return xUIElement; 52 } 53 54 55 56 57 SidebarPanelBase::SidebarPanelBase ( 58 const ::rtl::OUString& rsResourceURL, 59 const cssu::Reference<css::frame::XFrame>& rxFrame, 60 Window* pWindow, 61 const ::boost::function<void(void)>& rMenuProvider) 62 : SidebarPanelBaseInterfaceBase(m_aMutex), 63 mxFrame(rxFrame), 64 mpControl(pWindow), 65 msResourceURL(rsResourceURL), 66 maMenuProvider(rMenuProvider) 67 { 68 if (mxFrame.is()) 69 { 70 cssu::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer ( 71 css::ui::ContextChangeEventMultiplexer::get( 72 ::comphelper::getProcessComponentContext())); 73 if (xMultiplexer.is()) 74 xMultiplexer->addContextChangeEventListener(this, mxFrame->getController()); 75 } 76 if (mpControl != NULL) 77 mpControl->Show(); 78 } 79 80 81 82 83 SidebarPanelBase::~SidebarPanelBase (void) 84 { 85 } 86 87 88 89 90 void SAL_CALL SidebarPanelBase::disposing (void) 91 throw (cssu::RuntimeException) 92 { 93 mpControl = NULL; 94 95 if (mxFrame.is()) 96 { 97 cssu::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer ( 98 css::ui::ContextChangeEventMultiplexer::get( 99 ::comphelper::getProcessComponentContext())); 100 if (xMultiplexer.is()) 101 xMultiplexer->removeAllContextChangeEventListeners(this); 102 mxFrame = NULL; 103 } 104 } 105 106 107 108 109 void SidebarPanelBase::SetControl (::Window* pControl) 110 { 111 OSL_TRACE("setting control of SidebarPanelBase at %x to %x", this, pControl); 112 mpControl = pControl; 113 } 114 115 116 117 118 ::Window* SidebarPanelBase::GetControl (void) const 119 { 120 return mpControl; 121 } 122 123 124 125 126 // XContextChangeEventListener 127 void SAL_CALL SidebarPanelBase::notifyContextChangeEvent ( 128 const ui::ContextChangeEventObject& rEvent) 129 throw (cssu::RuntimeException) 130 { 131 ContextChangeReceiverInterface* pContextChangeReceiver 132 = dynamic_cast<ContextChangeReceiverInterface*>(mpControl); 133 if (pContextChangeReceiver != NULL) 134 { 135 const EnumContext aContext( 136 EnumContext::GetApplicationEnum(rEvent.ApplicationName), 137 EnumContext::GetContextEnum(rEvent.ContextName)); 138 pContextChangeReceiver->HandleContextChange(aContext); 139 } 140 } 141 142 143 144 145 void SAL_CALL SidebarPanelBase::disposing ( 146 const css::lang::EventObject& rEvent) 147 throw (cssu::RuntimeException) 148 { 149 (void)rEvent; 150 151 mxFrame = NULL; 152 mpControl = NULL; 153 } 154 155 156 157 158 cssu::Reference<css::frame::XFrame> SAL_CALL SidebarPanelBase::getFrame (void) 159 throw(cssu::RuntimeException) 160 { 161 return mxFrame; 162 } 163 164 165 166 167 ::rtl::OUString SAL_CALL SidebarPanelBase::getResourceURL (void) 168 throw(cssu::RuntimeException) 169 { 170 return msResourceURL; 171 } 172 173 174 175 176 sal_Int16 SAL_CALL SidebarPanelBase::getType (void) 177 throw(cssu::RuntimeException) 178 { 179 return ui::UIElementType::TOOLPANEL; 180 } 181 182 183 184 185 Reference<XInterface> SAL_CALL SidebarPanelBase::getRealInterface (void) 186 throw(cssu::RuntimeException) 187 { 188 return Reference<XInterface>(static_cast<XWeak*>(this)); 189 } 190 191 192 193 194 Reference<accessibility::XAccessible> SAL_CALL SidebarPanelBase::createAccessible ( 195 const Reference<accessibility::XAccessible>& rxParentAccessible) 196 throw(cssu::RuntimeException) 197 { 198 (void)rxParentAccessible; 199 200 // Not yet implemented. 201 return NULL; 202 } 203 204 205 206 207 Reference<awt::XWindow> SAL_CALL SidebarPanelBase::getWindow (void) 208 throw(cssu::RuntimeException) 209 { 210 if (mpControl != NULL) 211 return Reference<awt::XWindow>( 212 mpControl->GetComponentInterface(), 213 UNO_QUERY); 214 else 215 return NULL; 216 } 217 218 219 220 221 ui::LayoutSize SAL_CALL SidebarPanelBase::getHeightForWidth (const sal_Int32 nWidth) 222 throw(cssu::RuntimeException) 223 { 224 if (mpControl != NULL) 225 { 226 const sal_Int32 nHeight (mpControl->GetSizePixel().Height()); 227 return ui::LayoutSize(nHeight,nHeight,nHeight); 228 } 229 else 230 return ui::LayoutSize(0,0,0); 231 } 232 233 234 235 236 void SAL_CALL SidebarPanelBase::showMenu (void) 237 throw(cssu::RuntimeException) 238 { 239 if (maMenuProvider) 240 maMenuProvider(); 241 } 242 243 244 245 246 sal_Bool SAL_CALL SidebarPanelBase::isContextSupported ( 247 const ::rtl::OUString& rsApplicationName, 248 const ::rtl::OUString& rsContextName) 249 throw(cssu::RuntimeException) 250 { 251 (void)rsApplicationName; 252 (void)rsContextName; 253 254 return sal_True; 255 } 256 257 258 } } // end of namespace sfx2::sidebar 259