122de8995SAndre Fischer /************************************************************** 222de8995SAndre Fischer * 322de8995SAndre Fischer * Licensed to the Apache Software Foundation (ASF) under one 422de8995SAndre Fischer * or more contributor license agreements. See the NOTICE file 522de8995SAndre Fischer * distributed with this work for additional information 622de8995SAndre Fischer * regarding copyright ownership. The ASF licenses this file 722de8995SAndre Fischer * to you under the Apache License, Version 2.0 (the 822de8995SAndre Fischer * "License"); you may not use this file except in compliance 922de8995SAndre Fischer * with the License. You may obtain a copy of the License at 1022de8995SAndre Fischer * 1122de8995SAndre Fischer * http://www.apache.org/licenses/LICENSE-2.0 1222de8995SAndre Fischer * 1322de8995SAndre Fischer * Unless required by applicable law or agreed to in writing, 1422de8995SAndre Fischer * software distributed under the License is distributed on an 1522de8995SAndre Fischer * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1622de8995SAndre Fischer * KIND, either express or implied. See the License for the 1722de8995SAndre Fischer * specific language governing permissions and limitations 1822de8995SAndre Fischer * under the License. 1922de8995SAndre Fischer * 2022de8995SAndre Fischer *************************************************************/ 2122de8995SAndre Fischer 2222de8995SAndre Fischer #include "precompiled_sfx2.hxx" 2322de8995SAndre Fischer 2422de8995SAndre Fischer #include "Deck.hxx" 2522de8995SAndre Fischer #include "DeckDescriptor.hxx" 267a32b0c8SAndre Fischer #include "DeckLayouter.hxx" 27ff12d537SAndre Fischer #include "DrawHelper.hxx" 28ff12d537SAndre Fischer #include "DeckTitleBar.hxx" 29b9e67834SAndre Fischer #include "Paint.hxx" 30ff12d537SAndre Fischer #include "Panel.hxx" 317a32b0c8SAndre Fischer #include "ToolBoxBackground.hxx" 327a32b0c8SAndre Fischer #include "Tools.hxx" 33b9e67834SAndre Fischer #include "sfx2/sidebar/Theme.hxx" 34ff12d537SAndre Fischer 357a32b0c8SAndre Fischer #include <vcl/dockwin.hxx> 367a32b0c8SAndre Fischer #include <vcl/scrbar.hxx> 3795a18594SAndre Fischer #include <tools/svborder.hxx> 3822de8995SAndre Fischer 397a32b0c8SAndre Fischer #include <boost/bind.hpp> 407a32b0c8SAndre Fischer 417a32b0c8SAndre Fischer using namespace ::com::sun::star; 427a32b0c8SAndre Fischer using namespace ::com::sun::star::uno; 437a32b0c8SAndre Fischer 4422de8995SAndre Fischer 45ff12d537SAndre Fischer namespace sfx2 { namespace sidebar { 46ff12d537SAndre Fischer 47ff12d537SAndre Fischer 48ff12d537SAndre Fischer namespace { 49ff12d537SAndre Fischer static const sal_Int32 MinimalPanelHeight (25); 50ff12d537SAndre Fischer } 51ff12d537SAndre Fischer 52ff12d537SAndre Fischer 5322de8995SAndre Fischer Deck::Deck ( 5422de8995SAndre Fischer const DeckDescriptor& rDeckDescriptor, 557a32b0c8SAndre Fischer Window* pParentWindow, 567a32b0c8SAndre Fischer const ::boost::function<void(void)>& rCloserAction) 57*65908a7eSAndre Fischer : Window(pParentWindow, 0), 5822de8995SAndre Fischer msId(rDeckDescriptor.msId), 59ff12d537SAndre Fischer maIcon(), 60ff12d537SAndre Fischer msIconURL(rDeckDescriptor.msIconURL), 61ff12d537SAndre Fischer msHighContrastIconURL(rDeckDescriptor.msHighContrastIconURL), 62b9e67834SAndre Fischer maPanels(), 637a32b0c8SAndre Fischer mpTitleBar(new DeckTitleBar(rDeckDescriptor.msTitle, this, rCloserAction)), 647a32b0c8SAndre Fischer mpScrollClipWindow(new Window(this)), 657a32b0c8SAndre Fischer mpScrollContainer(new ScrollContainerWindow(mpScrollClipWindow.get())), 667a32b0c8SAndre Fischer mpFiller(new Window(this)), 677a32b0c8SAndre Fischer mpVerticalScrollBar(new ScrollBar(this)) 6822de8995SAndre Fischer { 6922de8995SAndre Fischer SetBackground(Wallpaper()); 707a32b0c8SAndre Fischer 717a32b0c8SAndre Fischer mpScrollClipWindow->SetBackground(Wallpaper()); 72*65908a7eSAndre Fischer mpScrollClipWindow->Show(); 73*65908a7eSAndre Fischer 74*65908a7eSAndre Fischer mpScrollContainer->SetStyle(mpScrollContainer->GetStyle() | WB_DIALOGCONTROL); 757a32b0c8SAndre Fischer mpScrollContainer->SetBackground(Wallpaper()); 76*65908a7eSAndre Fischer mpScrollContainer->Show(); 777a32b0c8SAndre Fischer 787a32b0c8SAndre Fischer mpVerticalScrollBar->SetScrollHdl(LINK(this, Deck, HandleVerticalScrollBarChange)); 797a32b0c8SAndre Fischer 807a32b0c8SAndre Fischer #ifdef DEBUG 817a32b0c8SAndre Fischer OSL_TRACE("creating Deck at %x", this); 827a32b0c8SAndre Fischer SetText(A2S("Deck")); 837a32b0c8SAndre Fischer mpScrollClipWindow->SetText(A2S("ScrollClipWindow")); 847a32b0c8SAndre Fischer mpFiller->SetText(A2S("Filler")); 857a32b0c8SAndre Fischer mpVerticalScrollBar->SetText(A2S("VerticalScrollBar")); 867a32b0c8SAndre Fischer #endif 8722de8995SAndre Fischer } 8822de8995SAndre Fischer 8922de8995SAndre Fischer 9022de8995SAndre Fischer 9122de8995SAndre Fischer 9222de8995SAndre Fischer Deck::~Deck (void) 9322de8995SAndre Fischer { 947a32b0c8SAndre Fischer OSL_TRACE("destroying Deck at %x", this); 95ff12d537SAndre Fischer Dispose(); 96f120fe41SAndre Fischer 97f120fe41SAndre Fischer // We have to explicitly trigger the destruction of panels. 98f120fe41SAndre Fischer // Otherwise that is done by one of our base class destructors 99f120fe41SAndre Fischer // without updating maPanels. 100f120fe41SAndre Fischer maPanels.clear(); 101ff12d537SAndre Fischer } 102ff12d537SAndre Fischer 103ff12d537SAndre Fischer 104ff12d537SAndre Fischer 105ff12d537SAndre Fischer 106ff12d537SAndre Fischer void Deck::Dispose (void) 107ff12d537SAndre Fischer { 108f120fe41SAndre Fischer SharedPanelContainer aPanels; 109ff12d537SAndre Fischer aPanels.swap(maPanels); 110f120fe41SAndre Fischer for (SharedPanelContainer::iterator 111ff12d537SAndre Fischer iPanel(aPanels.begin()), 112ff12d537SAndre Fischer iEnd(aPanels.end()); 113ff12d537SAndre Fischer iPanel!=iEnd; 114ff12d537SAndre Fischer ++iPanel) 115ff12d537SAndre Fischer { 116f120fe41SAndre Fischer if (*iPanel) 117f120fe41SAndre Fischer { 118ff12d537SAndre Fischer (*iPanel)->Dispose(); 119f120fe41SAndre Fischer OSL_ASSERT(iPanel->unique()); 120f120fe41SAndre Fischer OSL_TRACE("panel has %d references", iPanel->use_count()); 121f120fe41SAndre Fischer iPanel->reset(); 122f120fe41SAndre Fischer } 123ff12d537SAndre Fischer } 1247a32b0c8SAndre Fischer 1257a32b0c8SAndre Fischer mpTitleBar.reset(); 1267a32b0c8SAndre Fischer mpFiller.reset(); 1277a32b0c8SAndre Fischer mpVerticalScrollBar.reset(); 12822de8995SAndre Fischer } 12922de8995SAndre Fischer 13022de8995SAndre Fischer 13122de8995SAndre Fischer 13222de8995SAndre Fischer 13322de8995SAndre Fischer const ::rtl::OUString& Deck::GetId (void) const 13422de8995SAndre Fischer { 13522de8995SAndre Fischer return msId; 13622de8995SAndre Fischer } 13722de8995SAndre Fischer 13822de8995SAndre Fischer 13922de8995SAndre Fischer 14022de8995SAndre Fischer 1417a32b0c8SAndre Fischer DeckTitleBar* Deck::GetTitleBar (void) const 14222de8995SAndre Fischer { 1437a32b0c8SAndre Fischer return mpTitleBar.get(); 14422de8995SAndre Fischer } 14522de8995SAndre Fischer 14622de8995SAndre Fischer 14722de8995SAndre Fischer 14822de8995SAndre Fischer 149ff12d537SAndre Fischer Rectangle Deck::GetContentArea (void) const 15022de8995SAndre Fischer { 151ff12d537SAndre Fischer const Size aWindowSize (GetSizePixel()); 152b9e67834SAndre Fischer const int nBorderSize (Theme::GetInteger(Theme::Int_DeckBorderSize)); 153ff12d537SAndre Fischer 154ff12d537SAndre Fischer return Rectangle( 155b9e67834SAndre Fischer Theme::GetInteger(Theme::Int_DeckLeftPadding) + nBorderSize, 156b9e67834SAndre Fischer Theme::GetInteger(Theme::Int_DeckTopPadding) + nBorderSize, 157b9e67834SAndre Fischer aWindowSize.Width() - 1 - Theme::GetInteger(Theme::Int_DeckRightPadding) - nBorderSize, 158b9e67834SAndre Fischer aWindowSize.Height() - 1 - Theme::GetInteger(Theme::Int_DeckBottomPadding) - nBorderSize); 15922de8995SAndre Fischer } 16022de8995SAndre Fischer 16122de8995SAndre Fischer 162ff12d537SAndre Fischer 163ff12d537SAndre Fischer 164ff12d537SAndre Fischer ::rtl::OUString Deck::GetIconURL (const bool bIsHighContrastModeActive) const 165ff12d537SAndre Fischer { 166ff12d537SAndre Fischer if (bIsHighContrastModeActive) 167ff12d537SAndre Fischer return msHighContrastIconURL; 168ff12d537SAndre Fischer else 169ff12d537SAndre Fischer return msIconURL; 170ff12d537SAndre Fischer } 171ff12d537SAndre Fischer 172ff12d537SAndre Fischer 173ff12d537SAndre Fischer 174ff12d537SAndre Fischer 175ff12d537SAndre Fischer void Deck::Paint (const Rectangle& rUpdateArea) 176ff12d537SAndre Fischer { 17795a18594SAndre Fischer (void) rUpdateArea; 17895a18594SAndre Fischer 179ff12d537SAndre Fischer const Size aWindowSize (GetSizePixel()); 180b9e67834SAndre Fischer const SvBorder aPadding ( 181b9e67834SAndre Fischer Theme::GetInteger(Theme::Int_DeckLeftPadding), 182b9e67834SAndre Fischer Theme::GetInteger(Theme::Int_DeckTopPadding), 183b9e67834SAndre Fischer Theme::GetInteger(Theme::Int_DeckRightPadding), 184b9e67834SAndre Fischer Theme::GetInteger(Theme::Int_DeckBottomPadding)); 185ff12d537SAndre Fischer 186ff12d537SAndre Fischer // Paint deck background outside the border. 187b9e67834SAndre Fischer Rectangle aBox( 188ff12d537SAndre Fischer 0, 189ff12d537SAndre Fischer 0, 190ff12d537SAndre Fischer aWindowSize.Width() - 1, 191b9e67834SAndre Fischer aWindowSize.Height() - 1); 192ff12d537SAndre Fischer DrawHelper::DrawBorder( 193ff12d537SAndre Fischer *this, 194b9e67834SAndre Fischer aBox, 195b9e67834SAndre Fischer aPadding, 196b9e67834SAndre Fischer Theme::GetPaint(Theme::Paint_DeckBackground), 197b9e67834SAndre Fischer Theme::GetPaint(Theme::Paint_DeckBackground)); 198b9e67834SAndre Fischer 199b9e67834SAndre Fischer // Paint the border. 200b9e67834SAndre Fischer const int nBorderSize (Theme::GetInteger(Theme::Int_DeckBorderSize)); 201b9e67834SAndre Fischer aBox.Left() += aPadding.Left(); 202b9e67834SAndre Fischer aBox.Top() += aPadding.Top(); 203b9e67834SAndre Fischer aBox.Right() -= aPadding.Right(); 204b9e67834SAndre Fischer aBox.Bottom() -= aPadding.Bottom(); 205b9e67834SAndre Fischer const sfx2::sidebar::Paint& rHorizontalBorderPaint (Theme::GetPaint(Theme::Paint_HorizontalBorder)); 206b9e67834SAndre Fischer DrawHelper::DrawBorder( 207b9e67834SAndre Fischer *this, 208b9e67834SAndre Fischer aBox, 209ff12d537SAndre Fischer SvBorder(nBorderSize, nBorderSize, nBorderSize, nBorderSize), 210b9e67834SAndre Fischer rHorizontalBorderPaint, 211b9e67834SAndre Fischer Theme::GetPaint(Theme::Paint_VerticalBorder)); 212b9e67834SAndre Fischer } 213b9e67834SAndre Fischer 214b9e67834SAndre Fischer 215b9e67834SAndre Fischer 216b9e67834SAndre Fischer 217b9e67834SAndre Fischer void Deck::DataChanged (const DataChangedEvent& rEvent) 218b9e67834SAndre Fischer { 219b9e67834SAndre Fischer (void)rEvent; 220b9e67834SAndre Fischer RequestLayout(); 221ff12d537SAndre Fischer } 222ff12d537SAndre Fischer 223ff12d537SAndre Fischer 224ff12d537SAndre Fischer 225ff12d537SAndre Fischer 226f120fe41SAndre Fischer void Deck::SetPanels (const SharedPanelContainer& rPanels) 227ff12d537SAndre Fischer { 228f120fe41SAndre Fischer maPanels = rPanels; 229ff12d537SAndre Fischer 230ff12d537SAndre Fischer RequestLayout(); 231ff12d537SAndre Fischer } 232ff12d537SAndre Fischer 233ff12d537SAndre Fischer 234ff12d537SAndre Fischer 235ff12d537SAndre Fischer 236f120fe41SAndre Fischer const SharedPanelContainer& Deck::GetPanels (void) const 237f120fe41SAndre Fischer { 238f120fe41SAndre Fischer return maPanels; 239f120fe41SAndre Fischer } 240f120fe41SAndre Fischer 241f120fe41SAndre Fischer 242f120fe41SAndre Fischer 243f120fe41SAndre Fischer 244ff12d537SAndre Fischer void Deck::RequestLayout (void) 245ff12d537SAndre Fischer { 2467a32b0c8SAndre Fischer PrintWindowTree(); 247ff12d537SAndre Fischer 2487a32b0c8SAndre Fischer DeckLayouter::LayoutDeck( 2497a32b0c8SAndre Fischer GetContentArea(), 2507a32b0c8SAndre Fischer maPanels, 2517a32b0c8SAndre Fischer *GetTitleBar(), 2527a32b0c8SAndre Fischer *mpScrollClipWindow, 2537a32b0c8SAndre Fischer *mpScrollContainer, 2547a32b0c8SAndre Fischer *mpFiller, 2557a32b0c8SAndre Fischer *mpVerticalScrollBar); 256ff12d537SAndre Fischer 257ff12d537SAndre Fischer Invalidate(); 258ff12d537SAndre Fischer } 259ff12d537SAndre Fischer 260ff12d537SAndre Fischer 261ff12d537SAndre Fischer 262ff12d537SAndre Fischer 2637a32b0c8SAndre Fischer ::Window* Deck::GetPanelParentWindow (void) 264ff12d537SAndre Fischer { 2657a32b0c8SAndre Fischer return mpScrollContainer.get(); 2667a32b0c8SAndre Fischer } 267ff12d537SAndre Fischer 268b9e67834SAndre Fischer 2697a32b0c8SAndre Fischer 2707a32b0c8SAndre Fischer 2717a32b0c8SAndre Fischer const char* GetWindowClassification (const Window* pWindow) 272ff12d537SAndre Fischer { 2737a32b0c8SAndre Fischer const String& rsName (pWindow->GetText()); 2747a32b0c8SAndre Fischer if (rsName.Len() > 0) 2757a32b0c8SAndre Fischer { 2767a32b0c8SAndre Fischer return ::rtl::OUStringToOString(rsName, RTL_TEXTENCODING_ASCII_US).getStr(); 277ff12d537SAndre Fischer } 278ff12d537SAndre Fischer else 279ff12d537SAndre Fischer { 2807a32b0c8SAndre Fischer static char msWindow[] = "window"; 2817a32b0c8SAndre Fischer return msWindow; 282ff12d537SAndre Fischer } 283ff12d537SAndre Fischer } 284ff12d537SAndre Fischer 285ff12d537SAndre Fischer 2867a32b0c8SAndre Fischer void Deck::PrintWindowSubTree (Window* pRoot, int nIndentation) 287ff12d537SAndre Fischer { 2887a32b0c8SAndre Fischer static char* sIndentation = " "; 2897a32b0c8SAndre Fischer const Point aLocation (pRoot->GetPosPixel()); 2907a32b0c8SAndre Fischer const Size aSize (pRoot->GetSizePixel()); 2917a32b0c8SAndre Fischer const char* sClassification = GetWindowClassification(pRoot); 2927a32b0c8SAndre Fischer const char* sVisible = pRoot->IsVisible() ? "visible" : "hidden"; 2937a32b0c8SAndre Fischer OSL_TRACE("%s%x %s %s +%d+%d x%dx%d", 2947a32b0c8SAndre Fischer sIndentation+strlen(sIndentation)-nIndentation*4, 2957a32b0c8SAndre Fischer pRoot, 2967a32b0c8SAndre Fischer sClassification, 2977a32b0c8SAndre Fischer sVisible, 2987a32b0c8SAndre Fischer aLocation.X(),aLocation.Y(), 2997a32b0c8SAndre Fischer aSize.Width(),aSize.Height()); 300b9e67834SAndre Fischer 3017a32b0c8SAndre Fischer const sal_uInt16 nChildCount (pRoot->GetChildCount()); 3027a32b0c8SAndre Fischer for (sal_uInt16 nIndex=0; nIndex<nChildCount; ++nIndex) 3037a32b0c8SAndre Fischer PrintWindowSubTree(pRoot->GetChild(nIndex), nIndentation+1); 3047a32b0c8SAndre Fischer } 305ff12d537SAndre Fischer 3067a32b0c8SAndre Fischer 3077a32b0c8SAndre Fischer 3087a32b0c8SAndre Fischer 3097a32b0c8SAndre Fischer void Deck::PrintWindowTree (void) 310ff12d537SAndre Fischer { 3117a32b0c8SAndre Fischer PrintWindowSubTree(this, 0); 3127a32b0c8SAndre Fischer } 31395a18594SAndre Fischer 314ff12d537SAndre Fischer 315ff12d537SAndre Fischer 3167a32b0c8SAndre Fischer 3177a32b0c8SAndre Fischer void Deck::PrintWindowTree (const ::std::vector<Panel*>& rPanels) 318ff12d537SAndre Fischer { 3197a32b0c8SAndre Fischer (void)rPanels; 3207a32b0c8SAndre Fischer 3217a32b0c8SAndre Fischer PrintWindowTree(); 3227a32b0c8SAndre Fischer } 3237a32b0c8SAndre Fischer 3247a32b0c8SAndre Fischer 3257a32b0c8SAndre Fischer 3267a32b0c8SAndre Fischer 3277a32b0c8SAndre Fischer IMPL_LINK(Deck, HandleVerticalScrollBarChange,void*, EMPTYARG) 328ff12d537SAndre Fischer { 3297a32b0c8SAndre Fischer const sal_Int32 nYOffset (-mpVerticalScrollBar->GetThumbPos()); 3307a32b0c8SAndre Fischer mpScrollContainer->SetPosPixel( 3317a32b0c8SAndre Fischer Point( 3327a32b0c8SAndre Fischer mpScrollContainer->GetPosPixel().X(), 3337a32b0c8SAndre Fischer nYOffset)); 3347a32b0c8SAndre Fischer return sal_True; 3357a32b0c8SAndre Fischer } 3367a32b0c8SAndre Fischer 3377a32b0c8SAndre Fischer 3387a32b0c8SAndre Fischer 3397a32b0c8SAndre Fischer 3407a32b0c8SAndre Fischer //----- Deck::ScrollContainerWindow ------------------------------------------- 3417a32b0c8SAndre Fischer 3427a32b0c8SAndre Fischer Deck::ScrollContainerWindow::ScrollContainerWindow (Window* pParentWindow) 3437a32b0c8SAndre Fischer : Window(pParentWindow), 3447a32b0c8SAndre Fischer maSeparators() 34595a18594SAndre Fischer { 3467a32b0c8SAndre Fischer #ifdef DEBUG 3477a32b0c8SAndre Fischer SetText(A2S("ScrollContainerWindow")); 3487a32b0c8SAndre Fischer #endif 349ff12d537SAndre Fischer } 3507a32b0c8SAndre Fischer 3517a32b0c8SAndre Fischer 3527a32b0c8SAndre Fischer 3537a32b0c8SAndre Fischer 3547a32b0c8SAndre Fischer Deck::ScrollContainerWindow::~ScrollContainerWindow (void) 355ff12d537SAndre Fischer { 35695a18594SAndre Fischer } 3577a32b0c8SAndre Fischer 3587a32b0c8SAndre Fischer 3597a32b0c8SAndre Fischer 3607a32b0c8SAndre Fischer 3617a32b0c8SAndre Fischer void Deck::ScrollContainerWindow::Paint (const Rectangle& rUpdateArea) 36295a18594SAndre Fischer { 3637a32b0c8SAndre Fischer (void)rUpdateArea; 364ff12d537SAndre Fischer 3657a32b0c8SAndre Fischer // Paint the separators. 3667a32b0c8SAndre Fischer const sal_Int32 nSeparatorHeight (Theme::GetInteger(Theme::Int_DeckSeparatorHeight)); 3677a32b0c8SAndre Fischer const sal_Int32 nLeft (0); 3687a32b0c8SAndre Fischer const sal_Int32 nRight (GetSizePixel().Width()-1); 3697a32b0c8SAndre Fischer const sfx2::sidebar::Paint& rHorizontalBorderPaint (Theme::GetPaint(Theme::Paint_HorizontalBorder)); 3707a32b0c8SAndre Fischer for (::std::vector<sal_Int32>::const_iterator iY(maSeparators.begin()), iEnd(maSeparators.end()); 3717a32b0c8SAndre Fischer iY!=iEnd; 3727a32b0c8SAndre Fischer ++iY) 373ff12d537SAndre Fischer { 3747a32b0c8SAndre Fischer DrawHelper::DrawHorizontalLine( 3757a32b0c8SAndre Fischer *this, 3767a32b0c8SAndre Fischer nLeft, 3777a32b0c8SAndre Fischer nRight, 3787a32b0c8SAndre Fischer *iY, 3797a32b0c8SAndre Fischer nSeparatorHeight, 3807a32b0c8SAndre Fischer rHorizontalBorderPaint); 3817a32b0c8SAndre Fischer } 382ff12d537SAndre Fischer } 383ff12d537SAndre Fischer 3847a32b0c8SAndre Fischer 3857a32b0c8SAndre Fischer 3867a32b0c8SAndre Fischer 3877a32b0c8SAndre Fischer void Deck::ScrollContainerWindow::SetSeparators (const ::std::vector<sal_Int32>& rSeparators) 388ff12d537SAndre Fischer { 3897a32b0c8SAndre Fischer maSeparators = rSeparators; 390ff12d537SAndre Fischer } 391ff12d537SAndre Fischer 392ff12d537SAndre Fischer } } // end of namespace sfx2::sidebar 393