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 "Deck.hxx" 25 #include "DeckDescriptor.hxx" 26 #include "DeckLayouter.hxx" 27 #include "DrawHelper.hxx" 28 #include "DeckTitleBar.hxx" 29 #include "Paint.hxx" 30 #include "Panel.hxx" 31 #include "ToolBoxBackground.hxx" 32 #include "sfx2/sidebar/Tools.hxx" 33 #include "sfx2/sidebar/Theme.hxx" 34 35 #include <vcl/dockwin.hxx> 36 #include <vcl/scrbar.hxx> 37 #include <tools/svborder.hxx> 38 39 #include <boost/bind.hpp> 40 41 using namespace ::com::sun::star; 42 using namespace ::com::sun::star::uno; 43 44 45 namespace sfx2 { namespace sidebar { 46 47 48 namespace { 49 static const sal_Int32 MinimalPanelHeight (25); 50 } 51 52 53 Deck::Deck ( 54 const DeckDescriptor& rDeckDescriptor, 55 Window* pParentWindow, 56 const ::boost::function<void(void)>& rCloserAction) 57 : Window(pParentWindow, 0), 58 msId(rDeckDescriptor.msId), 59 maIcon(), 60 msIconURL(rDeckDescriptor.msIconURL), 61 msHighContrastIconURL(rDeckDescriptor.msHighContrastIconURL), 62 maPanels(), 63 mpTitleBar(new DeckTitleBar(rDeckDescriptor.msTitle, this, rCloserAction)), 64 mpScrollClipWindow(new Window(this)), 65 mpScrollContainer(new ScrollContainerWindow(mpScrollClipWindow.get())), 66 mpFiller(new Window(this)), 67 mpVerticalScrollBar(new ScrollBar(this)) 68 { 69 SetBackground(Wallpaper()); 70 71 mpScrollClipWindow->SetBackground(Wallpaper()); 72 mpScrollClipWindow->Show(); 73 74 mpScrollContainer->SetStyle(mpScrollContainer->GetStyle() | WB_DIALOGCONTROL); 75 mpScrollContainer->SetBackground(Wallpaper()); 76 mpScrollContainer->Show(); 77 78 mpVerticalScrollBar->SetScrollHdl(LINK(this, Deck, HandleVerticalScrollBarChange)); 79 80 #ifdef DEBUG 81 SetText(A2S("Deck")); 82 mpScrollClipWindow->SetText(A2S("ScrollClipWindow")); 83 mpFiller->SetText(A2S("Filler")); 84 mpVerticalScrollBar->SetText(A2S("VerticalScrollBar")); 85 #endif 86 } 87 88 89 90 91 Deck::~Deck (void) 92 { 93 Dispose(); 94 95 // We have to explicitly trigger the destruction of panels. 96 // Otherwise that is done by one of our base class destructors 97 // without updating maPanels. 98 maPanels.clear(); 99 } 100 101 102 103 104 void Deck::Dispose (void) 105 { 106 SharedPanelContainer aPanels; 107 aPanels.swap(maPanels); 108 for (SharedPanelContainer::iterator 109 iPanel(aPanels.begin()), 110 iEnd(aPanels.end()); 111 iPanel!=iEnd; 112 ++iPanel) 113 { 114 if (*iPanel) 115 { 116 (*iPanel)->Dispose(); 117 OSL_ASSERT(iPanel->unique()); 118 iPanel->reset(); 119 } 120 } 121 122 mpTitleBar.reset(); 123 mpFiller.reset(); 124 mpVerticalScrollBar.reset(); 125 } 126 127 128 129 130 const ::rtl::OUString& Deck::GetId (void) const 131 { 132 return msId; 133 } 134 135 136 137 138 DeckTitleBar* Deck::GetTitleBar (void) const 139 { 140 return mpTitleBar.get(); 141 } 142 143 144 145 146 Rectangle Deck::GetContentArea (void) const 147 { 148 const Size aWindowSize (GetSizePixel()); 149 const int nBorderSize (Theme::GetInteger(Theme::Int_DeckBorderSize)); 150 151 return Rectangle( 152 Theme::GetInteger(Theme::Int_DeckLeftPadding) + nBorderSize, 153 Theme::GetInteger(Theme::Int_DeckTopPadding) + nBorderSize, 154 aWindowSize.Width() - 1 - Theme::GetInteger(Theme::Int_DeckRightPadding) - nBorderSize, 155 aWindowSize.Height() - 1 - Theme::GetInteger(Theme::Int_DeckBottomPadding) - nBorderSize); 156 } 157 158 159 160 161 ::rtl::OUString Deck::GetIconURL (const bool bIsHighContrastModeActive) const 162 { 163 if (bIsHighContrastModeActive) 164 return msHighContrastIconURL; 165 else 166 return msIconURL; 167 } 168 169 170 171 172 void Deck::Paint (const Rectangle& rUpdateArea) 173 { 174 (void) rUpdateArea; 175 176 const Size aWindowSize (GetSizePixel()); 177 const SvBorder aPadding ( 178 Theme::GetInteger(Theme::Int_DeckLeftPadding), 179 Theme::GetInteger(Theme::Int_DeckTopPadding), 180 Theme::GetInteger(Theme::Int_DeckRightPadding), 181 Theme::GetInteger(Theme::Int_DeckBottomPadding)); 182 183 // Paint deck background outside the border. 184 Rectangle aBox( 185 0, 186 0, 187 aWindowSize.Width() - 1, 188 aWindowSize.Height() - 1); 189 DrawHelper::DrawBorder( 190 *this, 191 aBox, 192 aPadding, 193 Theme::GetPaint(Theme::Paint_DeckBackground), 194 Theme::GetPaint(Theme::Paint_DeckBackground)); 195 196 // Paint the border. 197 const int nBorderSize (Theme::GetInteger(Theme::Int_DeckBorderSize)); 198 aBox.Left() += aPadding.Left(); 199 aBox.Top() += aPadding.Top(); 200 aBox.Right() -= aPadding.Right(); 201 aBox.Bottom() -= aPadding.Bottom(); 202 const sfx2::sidebar::Paint& rHorizontalBorderPaint (Theme::GetPaint(Theme::Paint_HorizontalBorder)); 203 DrawHelper::DrawBorder( 204 *this, 205 aBox, 206 SvBorder(nBorderSize, nBorderSize, nBorderSize, nBorderSize), 207 rHorizontalBorderPaint, 208 Theme::GetPaint(Theme::Paint_VerticalBorder)); 209 } 210 211 212 213 214 void Deck::DataChanged (const DataChangedEvent& rEvent) 215 { 216 (void)rEvent; 217 RequestLayout(); 218 } 219 220 221 222 223 long Deck::Notify (NotifyEvent& rEvent) 224 { 225 if (rEvent.GetType() != EVENT_COMMAND) 226 return sal_False; 227 228 CommandEvent* pCommandEvent = reinterpret_cast<CommandEvent*>(rEvent.GetData()); 229 if (pCommandEvent == NULL) 230 return sal_False; 231 232 switch (pCommandEvent->GetCommand()) 233 { 234 case COMMAND_WHEEL: 235 { 236 if ( ! mpVerticalScrollBar 237 || ! mpVerticalScrollBar->IsVisible()) 238 return sal_False; 239 240 // Ignore all wheel commands from outside the vertical 241 // scroll bar. Otherwise after a scroll we might land on 242 // a spin field and subsequent wheel events would change 243 // the value of that control. 244 if (rEvent.GetWindow() != mpVerticalScrollBar.get()) 245 return sal_True; 246 247 // Get the wheel data and check that it describes a valid 248 // vertical scroll. 249 const CommandWheelData* pData = pCommandEvent->GetWheelData(); 250 if (pData==NULL 251 || pData->GetModifier() 252 || pData->GetMode() != COMMAND_WHEEL_SCROLL 253 || pData->IsHorz()) 254 return sal_False; 255 256 // Execute the actual scroll action. 257 long nDelta = pData->GetDelta(); 258 mpVerticalScrollBar->DoScroll( 259 mpVerticalScrollBar->GetThumbPos() - nDelta); 260 return sal_True; 261 } 262 263 default: 264 break; 265 } 266 267 return sal_False; 268 } 269 270 271 272 273 void Deck::SetPanels (const SharedPanelContainer& rPanels) 274 { 275 maPanels = rPanels; 276 277 RequestLayout(); 278 } 279 280 281 282 283 const SharedPanelContainer& Deck::GetPanels (void) const 284 { 285 return maPanels; 286 } 287 288 289 290 291 void Deck::RequestLayout (void) 292 { 293 // PrintWindowTree(); 294 295 DeckLayouter::LayoutDeck( 296 GetContentArea(), 297 maPanels, 298 *GetTitleBar(), 299 *mpScrollClipWindow, 300 *mpScrollContainer, 301 *mpFiller, 302 *mpVerticalScrollBar); 303 304 Invalidate(); 305 } 306 307 308 309 310 ::Window* Deck::GetPanelParentWindow (void) 311 { 312 return mpScrollContainer.get(); 313 } 314 315 316 317 318 void Deck::ShowPanel (const Panel& rPanel) 319 { 320 if (mpVerticalScrollBar && mpVerticalScrollBar->IsVisible()) 321 { 322 // Get vertical extent of the panel. 323 sal_Int32 nPanelTop (rPanel.GetPosPixel().Y()); 324 const sal_Int32 nPanelBottom (nPanelTop + rPanel.GetSizePixel().Height() - 1); 325 // Add the title bar into the extent. 326 if (rPanel.GetTitleBar() != NULL && rPanel.GetTitleBar()->IsVisible()) 327 nPanelTop = rPanel.GetTitleBar()->GetPosPixel().Y(); 328 329 // Determine what the new thumb position should be like. 330 // When the whole panel does not fit then make its top visible 331 // and it off at the bottom. 332 sal_Int32 nNewThumbPos (mpVerticalScrollBar->GetThumbPos()); 333 if (nPanelBottom >= nNewThumbPos+mpVerticalScrollBar->GetVisibleSize()) 334 nNewThumbPos = nPanelBottom - mpVerticalScrollBar->GetVisibleSize(); 335 if (nPanelTop < nNewThumbPos) 336 nNewThumbPos = nPanelTop; 337 338 mpVerticalScrollBar->SetThumbPos(nNewThumbPos); 339 mpScrollContainer->SetPosPixel( 340 Point( 341 mpScrollContainer->GetPosPixel().X(), 342 -nNewThumbPos)); 343 344 } 345 } 346 347 348 349 350 const char* GetWindowClassification (const Window* pWindow) 351 { 352 const String& rsName (pWindow->GetText()); 353 if (rsName.Len() > 0) 354 { 355 return ::rtl::OUStringToOString(rsName, RTL_TEXTENCODING_ASCII_US).getStr(); 356 } 357 else 358 { 359 static char msWindow[] = "window"; 360 return msWindow; 361 } 362 } 363 364 365 void Deck::PrintWindowSubTree (Window* pRoot, int nIndentation) 366 { 367 static const char* sIndentation = " "; 368 const Point aLocation (pRoot->GetPosPixel()); 369 const Size aSize (pRoot->GetSizePixel()); 370 const char* sClassification = GetWindowClassification(pRoot); 371 const char* sVisible = pRoot->IsVisible() ? "visible" : "hidden"; 372 OSL_TRACE("%s%x %s %s +%d+%d x%dx%d", 373 sIndentation+strlen(sIndentation)-nIndentation*4, 374 pRoot, 375 sClassification, 376 sVisible, 377 aLocation.X(),aLocation.Y(), 378 aSize.Width(),aSize.Height()); 379 380 const sal_uInt16 nChildCount (pRoot->GetChildCount()); 381 for (sal_uInt16 nIndex=0; nIndex<nChildCount; ++nIndex) 382 PrintWindowSubTree(pRoot->GetChild(nIndex), nIndentation+1); 383 } 384 385 386 387 388 void Deck::PrintWindowTree (void) 389 { 390 PrintWindowSubTree(this, 0); 391 } 392 393 394 395 396 void Deck::PrintWindowTree (const ::std::vector<Panel*>& rPanels) 397 { 398 (void)rPanels; 399 400 PrintWindowTree(); 401 } 402 403 404 405 406 IMPL_LINK(Deck, HandleVerticalScrollBarChange,void*, EMPTYARG) 407 { 408 const sal_Int32 nYOffset (-mpVerticalScrollBar->GetThumbPos()); 409 mpScrollContainer->SetPosPixel( 410 Point( 411 mpScrollContainer->GetPosPixel().X(), 412 nYOffset)); 413 return sal_True; 414 } 415 416 417 418 419 //----- Deck::ScrollContainerWindow ------------------------------------------- 420 421 Deck::ScrollContainerWindow::ScrollContainerWindow (Window* pParentWindow) 422 : Window(pParentWindow), 423 maSeparators() 424 { 425 #ifdef DEBUG 426 SetText(A2S("ScrollContainerWindow")); 427 #endif 428 } 429 430 431 432 433 Deck::ScrollContainerWindow::~ScrollContainerWindow (void) 434 { 435 } 436 437 438 439 440 void Deck::ScrollContainerWindow::Paint (const Rectangle& rUpdateArea) 441 { 442 (void)rUpdateArea; 443 444 // Paint the separators. 445 const sal_Int32 nSeparatorHeight (Theme::GetInteger(Theme::Int_DeckSeparatorHeight)); 446 const sal_Int32 nLeft (0); 447 const sal_Int32 nRight (GetSizePixel().Width()-1); 448 const sfx2::sidebar::Paint& rHorizontalBorderPaint (Theme::GetPaint(Theme::Paint_HorizontalBorder)); 449 for (::std::vector<sal_Int32>::const_iterator iY(maSeparators.begin()), iEnd(maSeparators.end()); 450 iY!=iEnd; 451 ++iY) 452 { 453 DrawHelper::DrawHorizontalLine( 454 *this, 455 nLeft, 456 nRight, 457 *iY, 458 nSeparatorHeight, 459 rHorizontalBorderPaint); 460 } 461 } 462 463 464 465 466 void Deck::ScrollContainerWindow::SetSeparators (const ::std::vector<sal_Int32>& rSeparators) 467 { 468 maSeparators = rSeparators; 469 } 470 471 472 } } // end of namespace sfx2::sidebar 473