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