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 "Panel.hxx" 25 #include "PanelTitleBar.hxx" 26 #include "PanelDescriptor.hxx" 27 #include "sfx2/sidebar/Theme.hxx" 28 #include "Paint.hxx" 29 30 #ifdef DEBUG 31 #include "Tools.hxx" 32 #include "Deck.hxx" 33 #endif 34 35 #include <tools/svborder.hxx> 36 #include <toolkit/helper/vclunohelper.hxx> 37 38 #include <com/sun/star/awt/XWindowPeer.hpp> 39 #include <com/sun/star/awt/PosSize.hpp> 40 #include <com/sun/star/ui/XToolPanel.hpp> 41 42 #include <boost/bind.hpp> 43 44 45 using namespace css; 46 using namespace cssu; 47 48 49 50 namespace sfx2 { namespace sidebar { 51 52 Panel::Panel ( 53 const PanelDescriptor& rPanelDescriptor, 54 Window* pParentWindow, 55 const ::boost::function<void(void)>& rDeckLayoutTrigger, 56 const ::boost::function<void(void)>& rShowMenuFunctor) 57 : Window(pParentWindow), 58 msPanelId(rPanelDescriptor.msId), 59 mpTitleBar(new PanelTitleBar( 60 rPanelDescriptor.msTitle, 61 pParentWindow, 62 this, 63 rShowMenuFunctor)), 64 mbIsTitleBarOptional(rPanelDescriptor.mbIsTitleBarOptional), 65 mxElement(), 66 mxPanelComponent(), 67 mbIsExpanded(true), 68 maDeckLayoutTrigger(rDeckLayoutTrigger) 69 { 70 SetBackground(Theme::GetPaint(Theme::Paint_PanelBackground).GetWallpaper()); 71 72 #ifdef DEBUG 73 OSL_TRACE("creating Panel at %x", this); 74 SetText(A2S("Panel")); 75 #endif 76 } 77 78 79 80 81 Panel::~Panel (void) 82 { 83 OSL_TRACE("destroying Panel at %x", this); 84 Dispose(); 85 } 86 87 88 89 90 void Panel::Dispose (void) 91 { 92 mxPanelComponent = NULL; 93 94 if (mxElement.is()) 95 { 96 Reference<lang::XComponent> xComponent (mxElement->getRealInterface(), UNO_QUERY); 97 if (xComponent.is()) 98 xComponent->dispose(); 99 } 100 101 { 102 Reference<lang::XComponent> xComponent (mxElement, UNO_QUERY); 103 mxElement = NULL; 104 if (xComponent.is()) 105 xComponent->dispose(); 106 } 107 108 { 109 Reference<lang::XComponent> xComponent (GetElementWindow(), UNO_QUERY); 110 if (xComponent.is()) 111 xComponent->dispose(); 112 } 113 114 mpTitleBar.reset(); 115 } 116 117 118 119 120 TitleBar* Panel::GetTitleBar (void) const 121 { 122 return mpTitleBar.get(); 123 } 124 125 126 127 128 bool Panel::IsTitleBarOptional (void) const 129 { 130 return mbIsTitleBarOptional; 131 } 132 133 134 135 136 void Panel::SetUIElement (const Reference<ui::XUIElement>& rxElement) 137 { 138 mxElement = rxElement; 139 if (mxElement.is()) 140 { 141 mxPanelComponent.set(mxElement->getRealInterface(), UNO_QUERY); 142 } 143 } 144 145 146 147 148 void Panel::SetExpanded (const bool bIsExpanded) 149 { 150 if (mbIsExpanded != bIsExpanded) 151 { 152 mbIsExpanded = bIsExpanded; 153 maDeckLayoutTrigger(); 154 } 155 } 156 157 158 159 160 bool Panel::IsExpanded (void) const 161 { 162 return mbIsExpanded; 163 } 164 165 166 167 168 bool Panel::HasIdPredicate (const ::rtl::OUString& rsId) const 169 { 170 if (this == NULL) 171 return false; 172 else 173 return msPanelId.equals(rsId); 174 } 175 176 177 178 179 const ::rtl::OUString& Panel::GetId (void) const 180 { 181 return msPanelId; 182 } 183 184 185 186 187 void Panel::Paint (const Rectangle& rUpdateArea) 188 { 189 Window::Paint(rUpdateArea); 190 } 191 192 193 194 195 void Panel::Resize (void) 196 { 197 Window::Resize(); 198 199 // Forward new size to window of XUIElement. 200 Reference<awt::XWindow> xElementWindow (GetElementWindow()); 201 if (xElementWindow.is()) 202 { 203 const Size aSize (GetSizePixel()); 204 xElementWindow->setPosSize( 205 0, 206 0, 207 aSize.Width(), 208 aSize.Height(), 209 awt::PosSize::POSSIZE); 210 } 211 } 212 213 214 215 216 void Panel::Activate (void) 217 { 218 Window::Activate(); 219 } 220 221 222 223 224 225 void Panel::DataChanged (const DataChangedEvent& rEvent) 226 { 227 (void)rEvent; 228 SetBackground(Theme::GetPaint(Theme::Paint_PanelBackground).GetWallpaper()); 229 } 230 231 232 233 234 Reference<ui::XSidebarPanel> Panel::GetPanelComponent (void) const 235 { 236 return mxPanelComponent; 237 } 238 239 240 241 242 void Panel::PrintWindowTree (void) 243 { 244 #ifdef DEBUG 245 Window* pElementWindow = VCLUnoHelper::GetWindow(GetElementWindow()); 246 if (pElementWindow != NULL) 247 { 248 OSL_TRACE("panel parent is %x", pElementWindow->GetParent()); 249 Deck::PrintWindowSubTree(pElementWindow, 2); 250 } 251 else 252 OSL_TRACE(" panel is empty"); 253 #endif 254 } 255 256 257 258 259 Reference<awt::XWindow> Panel::GetElementWindow (void) 260 { 261 if (mxElement.is()) 262 { 263 Reference<ui::XToolPanel> xToolPanel(mxElement->getRealInterface(), UNO_QUERY); 264 if (xToolPanel.is()) 265 return xToolPanel->getWindow(); 266 } 267 268 return NULL; 269 } 270 271 272 } } // end of namespace sfx2::sidebar 273