17a32b0c8SAndre Fischer /************************************************************** 27a32b0c8SAndre Fischer * 37a32b0c8SAndre Fischer * Licensed to the Apache Software Foundation (ASF) under one 47a32b0c8SAndre Fischer * or more contributor license agreements. See the NOTICE file 57a32b0c8SAndre Fischer * distributed with this work for additional information 67a32b0c8SAndre Fischer * regarding copyright ownership. The ASF licenses this file 77a32b0c8SAndre Fischer * to you under the Apache License, Version 2.0 (the 87a32b0c8SAndre Fischer * "License"); you may not use this file except in compliance 97a32b0c8SAndre Fischer * with the License. You may obtain a copy of the License at 107a32b0c8SAndre Fischer * 117a32b0c8SAndre Fischer * http://www.apache.org/licenses/LICENSE-2.0 127a32b0c8SAndre Fischer * 137a32b0c8SAndre Fischer * Unless required by applicable law or agreed to in writing, 147a32b0c8SAndre Fischer * software distributed under the License is distributed on an 157a32b0c8SAndre Fischer * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 167a32b0c8SAndre Fischer * KIND, either express or implied. See the License for the 177a32b0c8SAndre Fischer * specific language governing permissions and limitations 187a32b0c8SAndre Fischer * under the License. 197a32b0c8SAndre Fischer * 207a32b0c8SAndre Fischer *************************************************************/ 217a32b0c8SAndre Fischer 227a32b0c8SAndre Fischer #include "precompiled_sfx2.hxx" 237a32b0c8SAndre Fischer 247a32b0c8SAndre Fischer #include "DeckLayouter.hxx" 257a32b0c8SAndre Fischer #include "sfx2/sidebar/Theme.hxx" 267a32b0c8SAndre Fischer #include "Panel.hxx" 277a32b0c8SAndre Fischer #include "TitleBar.hxx" 287a32b0c8SAndre Fischer #include "Deck.hxx" 297a32b0c8SAndre Fischer 307a32b0c8SAndre Fischer #include <vcl/window.hxx> 317a32b0c8SAndre Fischer #include <vcl/scrbar.hxx> 327a32b0c8SAndre Fischer 337a32b0c8SAndre Fischer using namespace ::com::sun::star; 347a32b0c8SAndre Fischer using namespace ::com::sun::star::uno; 357a32b0c8SAndre Fischer 367a32b0c8SAndre Fischer 377a32b0c8SAndre Fischer namespace sfx2 { namespace sidebar { 387a32b0c8SAndre Fischer 397a32b0c8SAndre Fischer 407a32b0c8SAndre Fischer namespace { 417a32b0c8SAndre Fischer static const sal_Int32 MinimalPanelHeight (25); 427a32b0c8SAndre Fischer } 437a32b0c8SAndre Fischer 447a32b0c8SAndre Fischer #define IterateLayoutItems(iterator_name,container) \ 457a32b0c8SAndre Fischer for(::std::vector<LayoutItem>::iterator \ 467a32b0c8SAndre Fischer iterator_name(container.begin()), \ 477a32b0c8SAndre Fischer iEnd(container.end()); \ 487a32b0c8SAndre Fischer iterator_name!=iEnd; \ 497a32b0c8SAndre Fischer ++iterator_name) 507a32b0c8SAndre Fischer 517a32b0c8SAndre Fischer 527a32b0c8SAndre Fischer 537a32b0c8SAndre Fischer void DeckLayouter::LayoutDeck ( 547a32b0c8SAndre Fischer const Rectangle aContentArea, 55*f120fe41SAndre Fischer SharedPanelContainer& rPanels, 567a32b0c8SAndre Fischer Window& rDeckTitleBar, 577a32b0c8SAndre Fischer Window& rScrollClipWindow, 587a32b0c8SAndre Fischer Window& rScrollContainer, 597a32b0c8SAndre Fischer Window& rFiller, 607a32b0c8SAndre Fischer ScrollBar& rVerticalScrollBar) 617a32b0c8SAndre Fischer { 627a32b0c8SAndre Fischer if (aContentArea.GetWidth()<=0 || aContentArea.GetHeight()<=0) 637a32b0c8SAndre Fischer return; 647a32b0c8SAndre Fischer Rectangle aBox (PlaceDeckTitle(rDeckTitleBar, aContentArea)); 657a32b0c8SAndre Fischer 667a32b0c8SAndre Fischer if ( ! rPanels.empty()) 677a32b0c8SAndre Fischer { 687a32b0c8SAndre Fischer // Prepare the layout item container. 697a32b0c8SAndre Fischer ::std::vector<LayoutItem> aLayoutItems; 707a32b0c8SAndre Fischer aLayoutItems.resize(rPanels.size()); 717a32b0c8SAndre Fischer for (sal_Int32 nIndex(0),nCount(rPanels.size()); nIndex<nCount; ++nIndex) 727a32b0c8SAndre Fischer { 737a32b0c8SAndre Fischer aLayoutItems[nIndex].mpPanel = rPanels[nIndex]; 747a32b0c8SAndre Fischer aLayoutItems[nIndex].mnPanelIndex = nIndex; 757a32b0c8SAndre Fischer } 767a32b0c8SAndre Fischer aBox = LayoutPanels( 777a32b0c8SAndre Fischer aBox, 787a32b0c8SAndre Fischer aLayoutItems, 797a32b0c8SAndre Fischer rScrollClipWindow, 807a32b0c8SAndre Fischer rScrollContainer, 817a32b0c8SAndre Fischer rVerticalScrollBar, 827a32b0c8SAndre Fischer false); 837a32b0c8SAndre Fischer } 847a32b0c8SAndre Fischer UpdateFiller(rFiller, aBox); 857a32b0c8SAndre Fischer } 867a32b0c8SAndre Fischer 877a32b0c8SAndre Fischer 887a32b0c8SAndre Fischer 897a32b0c8SAndre Fischer 907a32b0c8SAndre Fischer Rectangle DeckLayouter::LayoutPanels ( 917a32b0c8SAndre Fischer const Rectangle aContentArea, 927a32b0c8SAndre Fischer ::std::vector<LayoutItem>& rLayoutItems, 937a32b0c8SAndre Fischer Window& rScrollClipWindow, 947a32b0c8SAndre Fischer Window& rScrollContainer, 957a32b0c8SAndre Fischer ScrollBar& rVerticalScrollBar, 967a32b0c8SAndre Fischer const bool bShowVerticalScrollBar) 977a32b0c8SAndre Fischer { 987a32b0c8SAndre Fischer Rectangle aBox (PlaceVerticalScrollBar(rVerticalScrollBar, aContentArea, bShowVerticalScrollBar)); 997a32b0c8SAndre Fischer 1007a32b0c8SAndre Fischer const sal_Int32 nWidth (aBox.GetWidth()); 1017a32b0c8SAndre Fischer const sal_Int32 nPanelTitleBarHeight (Theme::GetInteger(Theme::Int_PanelTitleBarHeight)); 1027a32b0c8SAndre Fischer 1037a32b0c8SAndre Fischer // Prepare the separators, horizontal lines above and below the 1047a32b0c8SAndre Fischer // panel titels. 1057a32b0c8SAndre Fischer const sal_Int32 nDeckSeparatorHeight (Theme::GetInteger(Theme::Int_DeckSeparatorHeight)); 1067a32b0c8SAndre Fischer 1077a32b0c8SAndre Fischer // Get the requested heights of the panels and the available 1087a32b0c8SAndre Fischer // height that is left when all panel titles and separators are 1097a32b0c8SAndre Fischer // taken into account. 1107a32b0c8SAndre Fischer sal_Int32 nAvailableHeight (aBox.GetHeight()); 1117a32b0c8SAndre Fischer GetRequestedSizes(rLayoutItems, nAvailableHeight, aBox); 1127a32b0c8SAndre Fischer const sal_Int32 nTotalDecorationHeight (aBox.GetHeight() - nAvailableHeight); 1137a32b0c8SAndre Fischer 1147a32b0c8SAndre Fischer // Analyze the requested heights. 1157a32b0c8SAndre Fischer // Determine the height that is available for panel content 1167a32b0c8SAndre Fischer // and count the different layouts. 1177a32b0c8SAndre Fischer sal_Int32 nTotalPreferredHeight (0); 1187a32b0c8SAndre Fischer sal_Int32 nTotalMinimumHeight (0); 1197a32b0c8SAndre Fischer IterateLayoutItems(iItem,rLayoutItems) 1207a32b0c8SAndre Fischer { 1217a32b0c8SAndre Fischer nTotalMinimumHeight += iItem->maLayoutSize.Minimum; 1227a32b0c8SAndre Fischer nTotalPreferredHeight += iItem->maLayoutSize.Preferred; 1237a32b0c8SAndre Fischer } 1247a32b0c8SAndre Fischer 1257a32b0c8SAndre Fischer if (nTotalMinimumHeight > nAvailableHeight 1267a32b0c8SAndre Fischer && ! bShowVerticalScrollBar) 1277a32b0c8SAndre Fischer { 1287a32b0c8SAndre Fischer // Not enough space, even when all panels are shrunk to their 1297a32b0c8SAndre Fischer // minimum height. 1307a32b0c8SAndre Fischer // Show a vertical scrollbar. 1317a32b0c8SAndre Fischer return LayoutPanels( 1327a32b0c8SAndre Fischer aContentArea, 1337a32b0c8SAndre Fischer rLayoutItems, 1347a32b0c8SAndre Fischer rScrollClipWindow, 1357a32b0c8SAndre Fischer rScrollContainer, 1367a32b0c8SAndre Fischer rVerticalScrollBar, 1377a32b0c8SAndre Fischer true); 1387a32b0c8SAndre Fischer } 1397a32b0c8SAndre Fischer 1407a32b0c8SAndre Fischer // We are now in one of three modes. 1417a32b0c8SAndre Fischer // - The preferred height fits into the available size: 1427a32b0c8SAndre Fischer // Use the preferred size, distribute the remaining height bei 1437a32b0c8SAndre Fischer // enlarging panels. 1447a32b0c8SAndre Fischer // - The total minimum height fits into the available size: 1457a32b0c8SAndre Fischer // Use the minimum size, distribute the remaining height bei 1467a32b0c8SAndre Fischer // enlarging panels. 1477a32b0c8SAndre Fischer // - The total minimum height does not fit into the available 1487a32b0c8SAndre Fischer // size: 1497a32b0c8SAndre Fischer // Use the unmodified preferred height for all panels. 1507a32b0c8SAndre Fischer 1517a32b0c8SAndre Fischer LayoutMode eMode (MinimumOrLarger); 1527a32b0c8SAndre Fischer if (bShowVerticalScrollBar) 1537a32b0c8SAndre Fischer eMode = Preferred; 1547a32b0c8SAndre Fischer else if (nTotalPreferredHeight <= nAvailableHeight) 1557a32b0c8SAndre Fischer eMode = PreferredOrLarger; 1567a32b0c8SAndre Fischer else 1577a32b0c8SAndre Fischer eMode = MinimumOrLarger; 1587a32b0c8SAndre Fischer 1597a32b0c8SAndre Fischer if (eMode != Preferred) 1607a32b0c8SAndre Fischer { 1617a32b0c8SAndre Fischer const sal_Int32 nTotalHeight (eMode==MinimumOrLarger ? nTotalMinimumHeight : nTotalPreferredHeight); 1627a32b0c8SAndre Fischer 1637a32b0c8SAndre Fischer DistributeHeights( 1647a32b0c8SAndre Fischer rLayoutItems, 1657a32b0c8SAndre Fischer nAvailableHeight-nTotalHeight, 1667a32b0c8SAndre Fischer aBox.GetHeight(), 1677a32b0c8SAndre Fischer eMode==MinimumOrLarger); 1687a32b0c8SAndre Fischer } 1697a32b0c8SAndre Fischer 1707a32b0c8SAndre Fischer // Set position and size of the mpScrollClipWindow to the available 1717a32b0c8SAndre Fischer // size. Its child, the mpScrollContainer, may have a bigger 1727a32b0c8SAndre Fischer // height. 1737a32b0c8SAndre Fischer rScrollClipWindow.SetPosSizePixel(aBox.Left(), aBox.Top(), aBox.GetWidth(), aBox.GetHeight()); 1747a32b0c8SAndre Fischer 1757a32b0c8SAndre Fischer const sal_Int32 nContentHeight ( 1767a32b0c8SAndre Fischer eMode==Preferred 1777a32b0c8SAndre Fischer ? nTotalPreferredHeight + nTotalDecorationHeight 1787a32b0c8SAndre Fischer : aBox.GetHeight()); 1797a32b0c8SAndre Fischer rScrollContainer.SetPosSizePixel( 1807a32b0c8SAndre Fischer 0, 1817a32b0c8SAndre Fischer 0, 1827a32b0c8SAndre Fischer nWidth, 1837a32b0c8SAndre Fischer nContentHeight); 1847a32b0c8SAndre Fischer 1857a32b0c8SAndre Fischer if (bShowVerticalScrollBar) 1867a32b0c8SAndre Fischer SetupVerticalScrollBar(rVerticalScrollBar, nContentHeight, aBox.GetHeight()); 1877a32b0c8SAndre Fischer 1887a32b0c8SAndre Fischer aBox.Top() += PlacePanels(rLayoutItems, nWidth, eMode, rScrollContainer); 1897a32b0c8SAndre Fischer return aBox; 1907a32b0c8SAndre Fischer } 1917a32b0c8SAndre Fischer 1927a32b0c8SAndre Fischer 1937a32b0c8SAndre Fischer 1947a32b0c8SAndre Fischer 1957a32b0c8SAndre Fischer sal_Int32 DeckLayouter::PlacePanels ( 1967a32b0c8SAndre Fischer ::std::vector<LayoutItem>& rLayoutItems, 1977a32b0c8SAndre Fischer const sal_Int32 nWidth, 1987a32b0c8SAndre Fischer const LayoutMode eMode, 1997a32b0c8SAndre Fischer Window& rScrollContainer) 2007a32b0c8SAndre Fischer { 2017a32b0c8SAndre Fischer ::std::vector<sal_Int32> aSeparators; 2027a32b0c8SAndre Fischer const sal_Int32 nDeckSeparatorHeight (Theme::GetInteger(Theme::Int_DeckSeparatorHeight)); 2037a32b0c8SAndre Fischer const sal_Int32 nPanelTitleBarHeight (Theme::GetInteger(Theme::Int_PanelTitleBarHeight)); 2047a32b0c8SAndre Fischer sal_Int32 nY (0); 2057a32b0c8SAndre Fischer 2067a32b0c8SAndre Fischer // Assign heights and places. 2077a32b0c8SAndre Fischer IterateLayoutItems(iItem,rLayoutItems) 2087a32b0c8SAndre Fischer { 2097a32b0c8SAndre Fischer if (iItem->mpPanel == NULL) 2107a32b0c8SAndre Fischer continue; 2117a32b0c8SAndre Fischer 2127a32b0c8SAndre Fischer Panel& rPanel (*iItem->mpPanel); 2137a32b0c8SAndre Fischer 2147a32b0c8SAndre Fischer // Separator above the panel title bar. 2157a32b0c8SAndre Fischer aSeparators.push_back(nY); 2167a32b0c8SAndre Fischer nY += nDeckSeparatorHeight; 2177a32b0c8SAndre Fischer 2187a32b0c8SAndre Fischer // Place the title bar. 2197a32b0c8SAndre Fischer TitleBar* pTitleBar = rPanel.GetTitleBar(); 2207a32b0c8SAndre Fischer pTitleBar->SetPosSizePixel(0, nY, nWidth, nPanelTitleBarHeight); 2217a32b0c8SAndre Fischer pTitleBar->Show(); 2227a32b0c8SAndre Fischer nY += nPanelTitleBarHeight; 2237a32b0c8SAndre Fischer 2247a32b0c8SAndre Fischer // Separator below the panel title bar. 2257a32b0c8SAndre Fischer aSeparators.push_back(nY); 2267a32b0c8SAndre Fischer nY += nDeckSeparatorHeight; 2277a32b0c8SAndre Fischer 2287a32b0c8SAndre Fischer if (rPanel.IsExpanded()) 2297a32b0c8SAndre Fischer { 2307a32b0c8SAndre Fischer rPanel.Show(); 2317a32b0c8SAndre Fischer 2327a32b0c8SAndre Fischer // Determine the height of the panel depending on layout 2337a32b0c8SAndre Fischer // mode and distributed heights. 2347a32b0c8SAndre Fischer sal_Int32 nPanelHeight (0); 2357a32b0c8SAndre Fischer switch(eMode) 2367a32b0c8SAndre Fischer { 2377a32b0c8SAndre Fischer case MinimumOrLarger: 2387a32b0c8SAndre Fischer nPanelHeight = iItem->maLayoutSize.Minimum + iItem->mnDistributedHeight; 2397a32b0c8SAndre Fischer break; 2407a32b0c8SAndre Fischer case PreferredOrLarger: 2417a32b0c8SAndre Fischer nPanelHeight = iItem->maLayoutSize.Preferred + iItem->mnDistributedHeight; 2427a32b0c8SAndre Fischer break; 2437a32b0c8SAndre Fischer case Preferred: 2447a32b0c8SAndre Fischer nPanelHeight = iItem->maLayoutSize.Preferred; 2457a32b0c8SAndre Fischer break; 2467a32b0c8SAndre Fischer default: 2477a32b0c8SAndre Fischer OSL_ASSERT(false); 2487a32b0c8SAndre Fischer break; 2497a32b0c8SAndre Fischer } 2507a32b0c8SAndre Fischer 2517a32b0c8SAndre Fischer // Place the panel. 2527a32b0c8SAndre Fischer OSL_TRACE("panel %d: placing @%d +%d", iItem->mnPanelIndex, nY, nPanelHeight); 2537a32b0c8SAndre Fischer rPanel.SetPosSizePixel(0, nY, nWidth, nPanelHeight); 2547a32b0c8SAndre Fischer 2557a32b0c8SAndre Fischer nY += nPanelHeight; 2567a32b0c8SAndre Fischer } 2577a32b0c8SAndre Fischer else 2587a32b0c8SAndre Fischer { 2597a32b0c8SAndre Fischer rPanel.Hide(); 2607a32b0c8SAndre Fischer } 2617a32b0c8SAndre Fischer } 2627a32b0c8SAndre Fischer 2637a32b0c8SAndre Fischer Deck::ScrollContainerWindow* pScrollContainerWindow 2647a32b0c8SAndre Fischer = dynamic_cast<Deck::ScrollContainerWindow*>(&rScrollContainer); 2657a32b0c8SAndre Fischer if (pScrollContainerWindow != NULL) 2667a32b0c8SAndre Fischer pScrollContainerWindow->SetSeparators(aSeparators); 2677a32b0c8SAndre Fischer 2687a32b0c8SAndre Fischer return nY; 2697a32b0c8SAndre Fischer } 2707a32b0c8SAndre Fischer 2717a32b0c8SAndre Fischer 2727a32b0c8SAndre Fischer 2737a32b0c8SAndre Fischer 2747a32b0c8SAndre Fischer void DeckLayouter::GetRequestedSizes ( 2757a32b0c8SAndre Fischer ::std::vector<LayoutItem>& rLayoutItems, 2767a32b0c8SAndre Fischer sal_Int32& rAvailableHeight, 2777a32b0c8SAndre Fischer const Rectangle& rContentBox) 2787a32b0c8SAndre Fischer { 2797a32b0c8SAndre Fischer rAvailableHeight = rContentBox.GetHeight(); 2807a32b0c8SAndre Fischer 2817a32b0c8SAndre Fischer const sal_Int32 nPanelTitleBarHeight (Theme::GetInteger(Theme::Int_PanelTitleBarHeight)); 2827a32b0c8SAndre Fischer const sal_Int32 nDeckSeparatorHeight (Theme::GetInteger(Theme::Int_DeckSeparatorHeight)); 2837a32b0c8SAndre Fischer 2847a32b0c8SAndre Fischer IterateLayoutItems(iItem,rLayoutItems) 2857a32b0c8SAndre Fischer { 2867a32b0c8SAndre Fischer ui::LayoutSize aLayoutSize (ui::LayoutSize(0,0,0)); 2877a32b0c8SAndre Fischer if (iItem->mpPanel != NULL) 2887a32b0c8SAndre Fischer { 2897a32b0c8SAndre Fischer rAvailableHeight -= nPanelTitleBarHeight; 2907a32b0c8SAndre Fischer rAvailableHeight -= 2*nDeckSeparatorHeight; 2917a32b0c8SAndre Fischer 2927a32b0c8SAndre Fischer if (iItem->mpPanel->IsExpanded()) 2937a32b0c8SAndre Fischer { 2947a32b0c8SAndre Fischer Reference<ui::XSidebarPanel> xPanel (iItem->mpPanel->GetPanelComponent()); 2957a32b0c8SAndre Fischer if (xPanel.is()) 2967a32b0c8SAndre Fischer aLayoutSize = xPanel->getHeightForWidth(rContentBox.GetWidth()); 2977a32b0c8SAndre Fischer else 2987a32b0c8SAndre Fischer aLayoutSize = ui::LayoutSize(MinimalPanelHeight, 0, -1); 2997a32b0c8SAndre Fischer } 3007a32b0c8SAndre Fischer } 3017a32b0c8SAndre Fischer iItem->maLayoutSize = aLayoutSize; 3027a32b0c8SAndre Fischer } 3037a32b0c8SAndre Fischer } 3047a32b0c8SAndre Fischer 3057a32b0c8SAndre Fischer 3067a32b0c8SAndre Fischer 3077a32b0c8SAndre Fischer 3087a32b0c8SAndre Fischer void DeckLayouter::DistributeHeights ( 3097a32b0c8SAndre Fischer ::std::vector<LayoutItem>& rLayoutItems, 3107a32b0c8SAndre Fischer const sal_Int32 nHeightToDistribute, 3117a32b0c8SAndre Fischer const sal_Int32 nContainerHeight, 3127a32b0c8SAndre Fischer const bool bMinimumHeightIsBase) 3137a32b0c8SAndre Fischer { 3147a32b0c8SAndre Fischer if (nHeightToDistribute <= 0) 3157a32b0c8SAndre Fischer return; 3167a32b0c8SAndre Fischer 3177a32b0c8SAndre Fischer sal_Int32 nRemainingHeightToDistribute (nHeightToDistribute); 3187a32b0c8SAndre Fischer 3197a32b0c8SAndre Fischer // Compute the weights as difference between panel base height 3207a32b0c8SAndre Fischer // (either its minimum or preferred height) and the container height. 3217a32b0c8SAndre Fischer sal_Int32 nTotalWeight (0); 3227a32b0c8SAndre Fischer sal_Int32 nNoMaximumCount (0); 3237a32b0c8SAndre Fischer sal_Int32 nIndex (0); 3247a32b0c8SAndre Fischer IterateLayoutItems(iItem,rLayoutItems) 3257a32b0c8SAndre Fischer { 3267a32b0c8SAndre Fischer if (iItem->maLayoutSize.Maximum == 0) 3277a32b0c8SAndre Fischer continue; 3287a32b0c8SAndre Fischer if (iItem->maLayoutSize.Maximum < 0) 3297a32b0c8SAndre Fischer ++nNoMaximumCount; 3307a32b0c8SAndre Fischer 3317a32b0c8SAndre Fischer const sal_Int32 nBaseHeight ( 3327a32b0c8SAndre Fischer bMinimumHeightIsBase 3337a32b0c8SAndre Fischer ? iItem->maLayoutSize.Minimum 3347a32b0c8SAndre Fischer : iItem->maLayoutSize.Preferred); 3357a32b0c8SAndre Fischer if (nBaseHeight < nContainerHeight) 3367a32b0c8SAndre Fischer { 3377a32b0c8SAndre Fischer iItem->mnWeight = nContainerHeight - nBaseHeight; 3387a32b0c8SAndre Fischer nTotalWeight += iItem->mnWeight; 3397a32b0c8SAndre Fischer } 3407a32b0c8SAndre Fischer OSL_TRACE("panel %d: base height is %d, weight is %d, min/max/pref are %d/%d/%d", 3417a32b0c8SAndre Fischer nIndex, nBaseHeight, iItem->mnWeight, 3427a32b0c8SAndre Fischer iItem->maLayoutSize.Minimum, iItem->maLayoutSize.Maximum, iItem->maLayoutSize.Preferred); 3437a32b0c8SAndre Fischer } 3447a32b0c8SAndre Fischer 3457a32b0c8SAndre Fischer if (nTotalWeight == 0) 3467a32b0c8SAndre Fischer return; 3477a32b0c8SAndre Fischer 3487a32b0c8SAndre Fischer // First pass of height distribution. 3497a32b0c8SAndre Fischer nIndex = 0; 3507a32b0c8SAndre Fischer IterateLayoutItems(iItem,rLayoutItems) 3517a32b0c8SAndre Fischer { 3527a32b0c8SAndre Fischer const sal_Int32 nBaseHeight ( 3537a32b0c8SAndre Fischer bMinimumHeightIsBase 3547a32b0c8SAndre Fischer ? iItem->maLayoutSize.Minimum 3557a32b0c8SAndre Fischer : iItem->maLayoutSize.Preferred); 3567a32b0c8SAndre Fischer sal_Int32 nDistributedHeight (iItem->mnWeight * nHeightToDistribute / nTotalWeight); 3577a32b0c8SAndre Fischer if (nBaseHeight+nDistributedHeight > iItem->maLayoutSize.Maximum 3587a32b0c8SAndre Fischer && iItem->maLayoutSize.Maximum >= 0) 3597a32b0c8SAndre Fischer { 3607a32b0c8SAndre Fischer nDistributedHeight = ::std::max<sal_Int32>(0,iItem->maLayoutSize.Maximum - nBaseHeight); 3617a32b0c8SAndre Fischer } 3627a32b0c8SAndre Fischer iItem->mnDistributedHeight = nDistributedHeight; 3637a32b0c8SAndre Fischer OSL_TRACE("panel %d: distributed height is %d", nIndex, nDistributedHeight); 3647a32b0c8SAndre Fischer nRemainingHeightToDistribute -= nDistributedHeight; 3657a32b0c8SAndre Fischer } 3667a32b0c8SAndre Fischer 3677a32b0c8SAndre Fischer if (nRemainingHeightToDistribute == 0) 3687a32b0c8SAndre Fischer return; 3697a32b0c8SAndre Fischer OSL_ASSERT(nRemainingHeightToDistribute > 0); 3707a32b0c8SAndre Fischer 3717a32b0c8SAndre Fischer // It is possible that not all of the height could be distributed 3727a32b0c8SAndre Fischer // because of Maximum heights being smaller than expected. 3737a32b0c8SAndre Fischer // Distribute the remaining height between the panels that have no 3747a32b0c8SAndre Fischer // Maximum (ie Maximum==-1). 3757a32b0c8SAndre Fischer if (nNoMaximumCount == 0) 3767a32b0c8SAndre Fischer { 3777a32b0c8SAndre Fischer // There are no panels with unrestricted height. 3787a32b0c8SAndre Fischer return; 3797a32b0c8SAndre Fischer } 3807a32b0c8SAndre Fischer const sal_Int32 nAdditionalHeightPerPanel (nRemainingHeightToDistribute / nNoMaximumCount); 3817a32b0c8SAndre Fischer // Handle rounding error. 3827a32b0c8SAndre Fischer sal_Int32 nAdditionalHeightForFirstPanel (nRemainingHeightToDistribute 3837a32b0c8SAndre Fischer - nNoMaximumCount*nAdditionalHeightPerPanel); 3847a32b0c8SAndre Fischer nIndex = 0; 3857a32b0c8SAndre Fischer IterateLayoutItems(iItem,rLayoutItems) 3867a32b0c8SAndre Fischer { 3877a32b0c8SAndre Fischer if (iItem->maLayoutSize.Maximum < 0) 3887a32b0c8SAndre Fischer { 3897a32b0c8SAndre Fischer iItem->mnDistributedHeight += nAdditionalHeightPerPanel + nAdditionalHeightForFirstPanel; 3907a32b0c8SAndre Fischer OSL_TRACE("panel %d: additionl height is %d", 3917a32b0c8SAndre Fischer iItem->mnPanelIndex, 3927a32b0c8SAndre Fischer nAdditionalHeightPerPanel + nAdditionalHeightForFirstPanel); 3937a32b0c8SAndre Fischer nRemainingHeightToDistribute -= nAdditionalHeightPerPanel + nAdditionalHeightForFirstPanel; 3947a32b0c8SAndre Fischer } 3957a32b0c8SAndre Fischer } 3967a32b0c8SAndre Fischer 3977a32b0c8SAndre Fischer OSL_ASSERT(nRemainingHeightToDistribute==0); 3987a32b0c8SAndre Fischer } 3997a32b0c8SAndre Fischer 4007a32b0c8SAndre Fischer 4017a32b0c8SAndre Fischer 4027a32b0c8SAndre Fischer 4037a32b0c8SAndre Fischer Rectangle DeckLayouter::PlaceDeckTitle ( 4047a32b0c8SAndre Fischer Window& rDeckTitleBar, 4057a32b0c8SAndre Fischer const Rectangle& rAvailableSpace) 4067a32b0c8SAndre Fischer { 4077a32b0c8SAndre Fischer if (static_cast<DockingWindow*>(rDeckTitleBar.GetParent()->GetParent())->IsFloatingMode()) 4087a32b0c8SAndre Fischer { 4097a32b0c8SAndre Fischer // When the side bar is undocked then the outer system window displays the deck title. 4107a32b0c8SAndre Fischer rDeckTitleBar.Hide(); 4117a32b0c8SAndre Fischer return rAvailableSpace; 4127a32b0c8SAndre Fischer } 4137a32b0c8SAndre Fischer else 4147a32b0c8SAndre Fischer { 4157a32b0c8SAndre Fischer const sal_Int32 nDeckTitleBarHeight (Theme::GetInteger(Theme::Int_DeckTitleBarHeight)); 4167a32b0c8SAndre Fischer rDeckTitleBar.SetPosSizePixel( 4177a32b0c8SAndre Fischer rAvailableSpace.Left(), 4187a32b0c8SAndre Fischer rAvailableSpace.Top(), 4197a32b0c8SAndre Fischer rAvailableSpace.GetWidth(), 4207a32b0c8SAndre Fischer nDeckTitleBarHeight); 4217a32b0c8SAndre Fischer rDeckTitleBar.Show(); 4227a32b0c8SAndre Fischer return Rectangle( 4237a32b0c8SAndre Fischer rAvailableSpace.Left(), 4247a32b0c8SAndre Fischer rAvailableSpace.Top() + nDeckTitleBarHeight, 4257a32b0c8SAndre Fischer rAvailableSpace.Right(), 4267a32b0c8SAndre Fischer rAvailableSpace.Bottom()); 4277a32b0c8SAndre Fischer } 4287a32b0c8SAndre Fischer } 4297a32b0c8SAndre Fischer 4307a32b0c8SAndre Fischer 4317a32b0c8SAndre Fischer 4327a32b0c8SAndre Fischer 4337a32b0c8SAndre Fischer Rectangle DeckLayouter::PlaceVerticalScrollBar ( 4347a32b0c8SAndre Fischer ScrollBar& rVerticalScrollBar, 4357a32b0c8SAndre Fischer const Rectangle& rAvailableSpace, 4367a32b0c8SAndre Fischer const bool bShowVerticalScrollBar) 4377a32b0c8SAndre Fischer { 4387a32b0c8SAndre Fischer if (bShowVerticalScrollBar) 4397a32b0c8SAndre Fischer { 4407a32b0c8SAndre Fischer const sal_Int32 nScrollBarWidth (rVerticalScrollBar.GetSizePixel().Width()); 4417a32b0c8SAndre Fischer rVerticalScrollBar.SetPosSizePixel( 4427a32b0c8SAndre Fischer rAvailableSpace.Right() - nScrollBarWidth + 1, 4437a32b0c8SAndre Fischer rAvailableSpace.Top(), 4447a32b0c8SAndre Fischer nScrollBarWidth, 4457a32b0c8SAndre Fischer rAvailableSpace.GetHeight()); 4467a32b0c8SAndre Fischer rVerticalScrollBar.Show(); 4477a32b0c8SAndre Fischer return Rectangle( 4487a32b0c8SAndre Fischer rAvailableSpace.Left(), 4497a32b0c8SAndre Fischer rAvailableSpace.Top(), 4507a32b0c8SAndre Fischer rAvailableSpace.Right() - nScrollBarWidth, 4517a32b0c8SAndre Fischer rAvailableSpace.Bottom()); 4527a32b0c8SAndre Fischer } 4537a32b0c8SAndre Fischer else 4547a32b0c8SAndre Fischer { 4557a32b0c8SAndre Fischer rVerticalScrollBar.Hide(); 4567a32b0c8SAndre Fischer return rAvailableSpace; 4577a32b0c8SAndre Fischer } 4587a32b0c8SAndre Fischer } 4597a32b0c8SAndre Fischer 4607a32b0c8SAndre Fischer 4617a32b0c8SAndre Fischer 4627a32b0c8SAndre Fischer 4637a32b0c8SAndre Fischer void DeckLayouter::SetupVerticalScrollBar( 4647a32b0c8SAndre Fischer ScrollBar& rVerticalScrollBar, 4657a32b0c8SAndre Fischer const sal_Int32 nContentHeight, 4667a32b0c8SAndre Fischer const sal_Int32 nVisibleHeight) 4677a32b0c8SAndre Fischer { 4687a32b0c8SAndre Fischer OSL_ASSERT(nContentHeight > nVisibleHeight); 4697a32b0c8SAndre Fischer 4707a32b0c8SAndre Fischer rVerticalScrollBar.SetRangeMin(0); 4717a32b0c8SAndre Fischer rVerticalScrollBar.SetRangeMax(nContentHeight-1); 4727a32b0c8SAndre Fischer rVerticalScrollBar.SetVisibleSize(nVisibleHeight); 4737a32b0c8SAndre Fischer } 4747a32b0c8SAndre Fischer 4757a32b0c8SAndre Fischer 4767a32b0c8SAndre Fischer 4777a32b0c8SAndre Fischer 4787a32b0c8SAndre Fischer void DeckLayouter::UpdateFiller ( 4797a32b0c8SAndre Fischer Window& rFiller, 4807a32b0c8SAndre Fischer const Rectangle& rBox) 4817a32b0c8SAndre Fischer { 4827a32b0c8SAndre Fischer if (rBox.GetHeight() > 0) 4837a32b0c8SAndre Fischer { 4847a32b0c8SAndre Fischer // Show the filler. 4857a32b0c8SAndre Fischer rFiller.SetBackground(Theme::GetPaint(Theme::Paint_PanelBackground).GetWallpaper()); 4867a32b0c8SAndre Fischer rFiller.SetPosSizePixel(rBox.TopLeft(), rBox.GetSize()); 4877a32b0c8SAndre Fischer rFiller.Show(); 4887a32b0c8SAndre Fischer } 4897a32b0c8SAndre Fischer else 4907a32b0c8SAndre Fischer { 4917a32b0c8SAndre Fischer // Hide the filler. 4927a32b0c8SAndre Fischer rFiller.Hide(); 4937a32b0c8SAndre Fischer } 4947a32b0c8SAndre Fischer } 4957a32b0c8SAndre Fischer 4967a32b0c8SAndre Fischer 4977a32b0c8SAndre Fischer 4987a32b0c8SAndre Fischer } } // end of namespace sfx2::sidebar 499