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