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 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 88 SidebarPanelBase::~SidebarPanelBase (void) 89 { 90 } 91 92 93 94 95 void SAL_CALL SidebarPanelBase::disposing (void) 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 { 137 IContextChangeReceiver* pContextChangeReceiver 138 = dynamic_cast<IContextChangeReceiver*>(mpControl); 139 if (pContextChangeReceiver != NULL) 140 { 141 const EnumContext aContext( 142 EnumContext::GetApplicationEnum(rEvent.ApplicationName), 143 EnumContext::GetContextEnum(rEvent.ContextName)); 144 pContextChangeReceiver->HandleContextChange(aContext); 145 } 146 } 147 148 149 150 151 void SAL_CALL SidebarPanelBase::disposing ( 152 const css::lang::EventObject& rEvent) 153 { 154 (void)rEvent; 155 156 mxFrame = NULL; 157 mpControl = NULL; 158 } 159 160 161 162 163 cssu::Reference<css::frame::XFrame> SAL_CALL SidebarPanelBase::getFrame (void) 164 { 165 return mxFrame; 166 } 167 168 169 170 171 ::rtl::OUString SAL_CALL SidebarPanelBase::getResourceURL (void) 172 { 173 return msResourceURL; 174 } 175 176 177 178 179 sal_Int16 SAL_CALL SidebarPanelBase::getType (void) 180 { 181 return ui::UIElementType::TOOLPANEL; 182 } 183 184 185 186 187 Reference<XInterface> SAL_CALL SidebarPanelBase::getRealInterface (void) 188 { 189 return Reference<XInterface>(static_cast<XWeak*>(this)); 190 } 191 192 193 194 195 Reference<accessibility::XAccessible> SAL_CALL SidebarPanelBase::createAccessible ( 196 const Reference<accessibility::XAccessible>& rxParentAccessible) 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 { 209 if (mpControl != NULL) 210 return Reference<awt::XWindow>( 211 mpControl->GetComponentInterface(), 212 UNO_QUERY); 213 else 214 return NULL; 215 } 216 217 218 219 220 ui::LayoutSize SAL_CALL SidebarPanelBase::getHeightForWidth (const sal_Int32 nWidth) 221 { 222 if (maLayoutSize.Minimum >= 0) 223 return maLayoutSize; 224 else 225 { 226 ILayoutableWindow* pLayoutableWindow = dynamic_cast<ILayoutableWindow*>(mpControl); 227 if (pLayoutableWindow != NULL) 228 return pLayoutableWindow->GetHeightForWidth(nWidth); 229 else if (mpControl != NULL) 230 { 231 const sal_Int32 nHeight (mpControl->GetSizePixel().Height()); 232 return ui::LayoutSize(nHeight,nHeight,nHeight); 233 } 234 } 235 236 return ui::LayoutSize(0,0,0); 237 } 238 239 240 241 242 } } // end of namespace sfx2::sidebar 243