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 Control* pControl) 43 { 44 Reference<ui::XUIElement> xUIElement ( 45 new SidebarPanelBase( 46 rsResourceURL, 47 rxFrame, 48 pControl)); 49 return xUIElement; 50 } 51 52 53 54 55 SidebarPanelBase::SidebarPanelBase ( 56 const ::rtl::OUString& rsResourceURL, 57 const cssu::Reference<css::frame::XFrame>& rxFrame, 58 Control* pControl) 59 : SidebarPanelBaseInterfaceBase(m_aMutex), 60 msResourceURL(rsResourceURL), 61 mxFrame(rxFrame), 62 mpControl(pControl) 63 { 64 cssu::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer ( 65 css::ui::ContextChangeEventMultiplexer::get( 66 ::comphelper::getProcessComponentContext())); 67 if (xMultiplexer.is()) 68 xMultiplexer->addContextChangeEventListener(this, mxFrame->getController()); 69 } 70 71 72 73 74 SidebarPanelBase::~SidebarPanelBase (void) 75 { 76 } 77 78 79 80 81 void SAL_CALL SidebarPanelBase::disposing (void) 82 throw (cssu::RuntimeException) 83 { 84 mpControl = NULL; 85 86 if (mxFrame.is()) 87 { 88 cssu::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer ( 89 css::ui::ContextChangeEventMultiplexer::get( 90 ::comphelper::getProcessComponentContext())); 91 if (xMultiplexer.is()) 92 xMultiplexer->removeAllContextChangeEventListeners(this); 93 mxFrame = NULL; 94 } 95 } 96 97 98 99 100 // XContextChangeEventListener 101 void SAL_CALL SidebarPanelBase::notifyContextChangeEvent ( 102 const ui::ContextChangeEventObject& rEvent) 103 throw (cssu::RuntimeException) 104 { 105 if (mpControl != NULL) 106 { 107 const EnumContext aContext( 108 EnumContext::GetApplicationEnum(rEvent.ApplicationName), 109 EnumContext::GetContextEnum(rEvent.ContextName)); 110 111 ContextChangeReceiverInterface* pContextChangeReceiver 112 = dynamic_cast<ContextChangeReceiverInterface*>(mpControl); 113 if (pContextChangeReceiver != NULL) 114 pContextChangeReceiver->HandleContextChange(aContext); 115 } 116 } 117 118 119 120 121 void SAL_CALL SidebarPanelBase::disposing ( 122 const css::lang::EventObject& rEvent) 123 throw (cssu::RuntimeException) 124 { 125 (void)rEvent; 126 127 mxFrame = NULL; 128 mpControl = NULL; 129 } 130 131 132 133 134 cssu::Reference<css::frame::XFrame> SAL_CALL SidebarPanelBase::getFrame (void) 135 throw(cssu::RuntimeException) 136 { 137 return mxFrame; 138 } 139 140 141 142 143 ::rtl::OUString SAL_CALL SidebarPanelBase::getResourceURL (void) 144 throw(cssu::RuntimeException) 145 { 146 return msResourceURL; 147 } 148 149 150 151 152 sal_Int16 SAL_CALL SidebarPanelBase::getType (void) 153 throw(cssu::RuntimeException) 154 { 155 return ui::UIElementType::TOOLPANEL; 156 } 157 158 159 160 161 Reference<XInterface> SAL_CALL SidebarPanelBase::getRealInterface (void) 162 throw(cssu::RuntimeException) 163 { 164 return Reference<XInterface>(static_cast<XWeak*>(this)); 165 } 166 167 168 169 170 Reference<accessibility::XAccessible> SAL_CALL SidebarPanelBase::createAccessible ( 171 const Reference<accessibility::XAccessible>& rxParentAccessible) 172 throw(cssu::RuntimeException) 173 { 174 (void)rxParentAccessible; 175 176 // Not yet implemented. 177 return NULL; 178 } 179 180 181 182 183 Reference<awt::XWindow> SAL_CALL SidebarPanelBase::getWindow (void) 184 throw(cssu::RuntimeException) 185 { 186 if (mpControl != NULL) 187 return Reference<awt::XWindow>( 188 mpControl->GetComponentInterface(), 189 UNO_QUERY); 190 else 191 return NULL; 192 } 193 194 195 196 197 sal_Int32 SAL_CALL SidebarPanelBase::getHeightForWidth (const sal_Int32 nWidth) 198 throw(cssu::RuntimeException) 199 { 200 if (mpControl != NULL) 201 return mpControl->GetSizePixel().Height(); 202 else 203 return -1; 204 } 205 206 207 208 } } // end of namespace sfx2::sidebar 209