LCOV - code coverage report
Current view: top level - basctl/source/basicide - layout.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 0 206 0.0 %
Date: 2015-06-13 12:38:46 Functions: 0 25 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include "layout.hxx"
      21             : 
      22             : #include "bastypes.hxx"
      23             : #include <vcl/settings.hxx>
      24             : 
      25             : #include <boost/make_shared.hpp>
      26             : 
      27             : namespace basctl
      28             : {
      29             : 
      30             : namespace
      31             : {
      32             : // the thickness of the splitting lines
      33             : static long const nSplitThickness = 3;
      34             : } // namespace
      35             : 
      36             : // ctor for derived classes
      37             : // pParent: the parent window (Shell)
      38           0 : Layout::Layout (vcl::Window* pParent) :
      39             :     Window(pParent, WB_CLIPCHILDREN),
      40             :     pChild(0),
      41             :     bFirstSize(true),
      42             :     aLeftSide(this, SplittedSide::Left),
      43           0 :     aBottomSide(this, SplittedSide::Bottom)
      44             : {
      45           0 :     SetBackground(GetSettings().GetStyleSettings().GetWindowColor());
      46             : 
      47           0 :     vcl::Font aFont = GetFont();
      48           0 :     Size aSz = aFont.GetSize();
      49           0 :     aSz.Height() *= 1.5;
      50           0 :     aFont.SetSize(aSz);
      51           0 :     aFont.SetWeight(WEIGHT_BOLD);
      52           0 :     aFont.SetColor(GetSettings().GetStyleSettings().GetWindowTextColor());
      53           0 :     SetFont(aFont);
      54           0 : }
      55             : 
      56           0 : Layout::~Layout()
      57             : {
      58           0 :     disposeOnce();
      59           0 : }
      60             : 
      61           0 : void Layout::dispose()
      62             : {
      63           0 :     aLeftSide.dispose();
      64           0 :     aBottomSide.dispose();
      65           0 :     pChild.clear();
      66           0 :     Window::dispose();
      67           0 : }
      68             : 
      69             : // removes a docking window
      70           0 : void Layout::Remove (DockingWindow* pWin)
      71             : {
      72           0 :     aLeftSide.Remove(pWin);
      73           0 :     aBottomSide.Remove(pWin);
      74           0 : }
      75             : 
      76             : // called by Window when resized
      77           0 : void Layout::Resize()
      78             : {
      79           0 :     if (IsVisible())
      80           0 :         ArrangeWindows();
      81           0 : }
      82             : 
      83             : // ArrangeWindows() -- arranges the child windows
      84           0 : void Layout::ArrangeWindows ()
      85             : {
      86             :     // prevent recursion via OnFirstSize() -> Add() -> ArrangeWindows()
      87             :     static bool bInArrangeWindows = false;
      88           0 :     if (bInArrangeWindows)
      89           0 :         return;
      90           0 :     bInArrangeWindows = true;
      91             : 
      92           0 :     Size const aSize = GetOutputSizePixel();
      93           0 :     long const nWidth = aSize.Width(), nHeight = aSize.Height();
      94           0 :     if (nWidth && nHeight) // non-empty size
      95             :     {
      96             :         // On first call the derived classes initializes the sizes of the
      97             :         // docking windows. This cannot be done at construction because
      98             :         // the Layout has empty size at that point.
      99           0 :         if (bFirstSize)
     100             :         {
     101           0 :             bFirstSize = false;
     102           0 :             this->OnFirstSize(nWidth, nHeight); // virtual
     103             :         }
     104             : 
     105             :         // sides
     106           0 :         aBottomSide.ArrangeIn(Rectangle(Point(0, 0), aSize));
     107           0 :         aLeftSide.ArrangeIn(Rectangle(Point(0, 0), Size(nWidth, nHeight - aBottomSide.GetSize())));
     108             :         // child in the middle
     109           0 :         pChild->SetPosSizePixel(
     110             :             Point(aLeftSide.GetSize(), 0),
     111           0 :             Size(nWidth - aLeftSide.GetSize(), nHeight - aBottomSide.GetSize())
     112           0 :         );
     113             :     }
     114             : 
     115           0 :     bInArrangeWindows = false;
     116             : }
     117             : 
     118           0 : void Layout::DockaWindow (DockingWindow*)
     119             : {
     120           0 :     ArrangeWindows();
     121           0 : }
     122             : 
     123           0 : void Layout::Activating (BaseWindow& rWindow)
     124             : {
     125             :     // first activation
     126           0 :     pChild = &rWindow;
     127           0 :     ArrangeWindows();
     128           0 :     Show();
     129           0 :     pChild->Activating();
     130           0 : }
     131             : 
     132           0 : void Layout::Deactivating ()
     133             : {
     134           0 :     if (pChild)
     135           0 :         pChild->Deactivating();
     136           0 :     Hide();
     137           0 :     pChild = 0;
     138           0 : }
     139             : 
     140             : // virtual
     141           0 : void Layout::DataChanged (DataChangedEvent const& rDCEvt)
     142             : {
     143           0 :     Window::DataChanged(rDCEvt);
     144           0 :     if (rDCEvt.GetType() == DataChangedEventType::SETTINGS && (rDCEvt.GetFlags() & AllSettingsFlags::STYLE))
     145             :     {
     146           0 :         bool bInvalidate = false;
     147           0 :         Color aColor = GetSettings().GetStyleSettings().GetWindowColor();
     148           0 :         const AllSettings* pOldSettings = rDCEvt.GetOldSettings();
     149           0 :         if (!pOldSettings || aColor != pOldSettings->GetStyleSettings().GetWindowColor())
     150             :         {
     151           0 :             SetBackground(Wallpaper(aColor));
     152           0 :             bInvalidate = true;
     153             :         }
     154           0 :         aColor = GetSettings().GetStyleSettings().GetWindowTextColor();
     155           0 :         if (!pOldSettings || aColor != pOldSettings->GetStyleSettings().GetWindowTextColor())
     156             :         {
     157           0 :             vcl::Font aFont(GetFont());
     158           0 :             aFont.SetColor(aColor);
     159           0 :             SetFont(aFont);
     160           0 :             bInvalidate = true;
     161             :         }
     162           0 :         if (bInvalidate)
     163           0 :             Invalidate();
     164             :     }
     165           0 : }
     166             : 
     167             : 
     168             : // SplittedSide
     169             : 
     170             : 
     171             : 
     172             : // ctor
     173           0 : Layout::SplittedSide::SplittedSide (Layout* pParent, Side eSide) :
     174             :     rLayout(*pParent),
     175           0 :     bVertical(eSide == Left || eSide == Right),
     176           0 :     bLower(eSide == Left || eSide == Top),
     177             :     nSize(0),
     178           0 :     aSplitter(VclPtr<Splitter>::Create(pParent, bVertical ? WB_HSCROLL : WB_VSCROLL))
     179             : {
     180           0 :     InitSplitter(*aSplitter.get());
     181           0 : }
     182             : 
     183           0 : void Layout::SplittedSide::dispose()
     184             : {
     185           0 :     aSplitter.disposeAndClear();
     186           0 :     for (auto i = vItems.begin(); i != vItems.end(); ++i)
     187             :     {
     188           0 :         i->pSplit.disposeAndClear();
     189           0 :         i->pWin.clear();
     190             :     }
     191           0 : }
     192             : 
     193             : // Add() -- adds a new window to the side (after construction)
     194           0 : void Layout::SplittedSide::Add (DockingWindow* pWin, Size const& rSize)
     195             : {
     196           0 :     long const nSize1 = (bVertical ? rSize.Width() : rSize.Height()) + nSplitThickness;
     197           0 :     long const nSize2 = bVertical ? rSize.Height() : rSize.Width();
     198             :     // nSize
     199           0 :     if (nSize1 > nSize)
     200           0 :         nSize = nSize1;
     201             :     // window
     202           0 :     Item aItem;
     203           0 :     aItem.pWin = pWin;
     204           0 :     aItem.nStartPos = vItems.empty() ? 0 : vItems.back().nEndPos + nSplitThickness;
     205           0 :     aItem.nEndPos = aItem.nStartPos + nSize2;
     206             :     // splitter
     207           0 :     if (!vItems.empty())
     208             :     {
     209           0 :         aItem.pSplit = VclPtr<Splitter>::Create(&rLayout, bVertical ? WB_VSCROLL : WB_HSCROLL);
     210           0 :         aItem.pSplit->SetSplitPosPixel(aItem.nStartPos - nSplitThickness);
     211           0 :         InitSplitter(*aItem.pSplit);
     212             :     }
     213           0 :     vItems.push_back(aItem);
     214             :     // refresh
     215           0 :     rLayout.ArrangeWindows();
     216           0 : }
     217             : 
     218             : // Remove() -- removes a window from the side (if contains)
     219           0 : void Layout::SplittedSide::Remove (DockingWindow* pWin)
     220             : {
     221             :     // contains?
     222             :     unsigned iWin;
     223           0 :     for (iWin = 0; iWin != vItems.size(); ++iWin)
     224           0 :         if (vItems[iWin].pWin == pWin)
     225           0 :             break;
     226           0 :     if (iWin == vItems.size())
     227           0 :         return;
     228             :     // remove
     229           0 :     vItems[iWin].pSplit.disposeAndClear();
     230           0 :     vItems[iWin].pWin.clear();
     231           0 :     vItems.erase(vItems.begin() + iWin);
     232             :     // if that was the first one, remove the first splitter line
     233           0 :     if (iWin == 0 && !vItems.empty())
     234           0 :         vItems.front().pSplit.reset();
     235             : }
     236             : 
     237             : // creating a Point or a Size object
     238             : // The coordinate order depends on bVertical (reversed if true).
     239           0 : inline Size Layout::SplittedSide::MakeSize (long A, long B) const
     240             : {
     241           0 :     return bVertical ? Size(B, A) : Size(A, B);
     242             : }
     243           0 : inline Point Layout::SplittedSide::MakePoint (long A, long B) const
     244             : {
     245           0 :     return bVertical ? Point(B, A) : Point(A, B);
     246             : }
     247             : 
     248             : // IsDocking() -- is this window currently docking in the strip?
     249           0 : bool Layout::SplittedSide::IsDocking (DockingWindow const& rWin)
     250             : {
     251           0 :     return rWin.IsVisible() && !rWin.IsFloatingMode();
     252             : }
     253             : 
     254             : // IsEmpty() -- are there no windows docked in this strip?
     255           0 : bool Layout::SplittedSide::IsEmpty () const
     256             : {
     257           0 :     for (unsigned i = 0; i != vItems.size(); ++i)
     258           0 :         if (IsDocking(*vItems[i].pWin))
     259           0 :             return false;
     260           0 :     return true;
     261             : }
     262             : 
     263             : // GetSize() -- returns the width or height of the strip (depending on the direction)
     264           0 : long Layout::SplittedSide::GetSize () const
     265             : {
     266           0 :     return IsEmpty() ? 0 : nSize;
     267             : }
     268             : 
     269             : // Arrange() -- arranges the docking windows
     270             : // rRect: the available space
     271           0 : void Layout::SplittedSide::ArrangeIn (Rectangle const& rRect)
     272             : {
     273             :     // saving the rectangle
     274           0 :     aRect = rRect;
     275             : 
     276             :     // the length of the side
     277           0 :     long const nLength = bVertical ? aRect.GetSize().Height() : aRect.GetSize().Width();
     278           0 :     long const nOtherSize = bVertical ? aRect.GetSize().Width() : aRect.GetSize().Height();
     279             :     // bVertical ? horizontal pozition : vertical pozition
     280           0 :     long const nPos1 = (bVertical ? aRect.Left() : aRect.Top()) +
     281           0 :         (bLower ? 0 : nOtherSize - (nSize - nSplitThickness));
     282             :     // bVertical ? vertical position : horizontal position
     283           0 :     long const nPos2 = bVertical ? aRect.Top() : aRect.Left();
     284             : 
     285             :     // main line
     286           0 :     bool const bEmpty = IsEmpty();
     287             :     // shown if any of the windows is docked
     288           0 :     if (!bEmpty)
     289             :     {
     290           0 :         aSplitter->Show();
     291             :         // split position
     292           0 :         aSplitter->SetSplitPosPixel((bLower ? nSize : nPos1) - nSplitThickness);
     293             :         // the actual position and size
     294           0 :         aSplitter->SetPosSizePixel(
     295           0 :             MakePoint(nPos2, aSplitter->GetSplitPosPixel()),
     296             :             MakeSize(nLength, nSplitThickness)
     297           0 :         );
     298             :         // dragging rectangle
     299           0 :         aSplitter->SetDragRectPixel(aRect);
     300             :     }
     301             :     else
     302           0 :         aSplitter->Hide();
     303             : 
     304             :     // positioning separator lines and windows
     305           0 :     bool bPrevDocking = false; // is the previous window docked?
     306           0 :     long nStartPos = 0; // window position in the strip
     307           0 :     unsigned iLastWin = vItems.size(); // index of last docking window in the strip
     308             : 
     309           0 :     for (unsigned i = 0; i != vItems.size(); ++i)
     310             :     {
     311             :         // window
     312           0 :         DockingWindow& rWin = *vItems[i].pWin;
     313           0 :         bool const bDocking = IsDocking(rWin);
     314           0 :         if (bDocking)
     315           0 :             iLastWin = i;
     316             :         // sizing window
     317             :         rWin.ResizeIfDocking(
     318           0 :             MakePoint(nPos2 + nStartPos, nPos1),
     319           0 :             MakeSize(vItems[i].nEndPos - nStartPos, nSize - nSplitThickness)
     320           0 :         );
     321             :         // splitting line before the window
     322           0 :         if (i > 0)
     323             :         {
     324           0 :             Splitter& rSplit = *vItems[i].pSplit;
     325             :             // If neither of two adjacent windows are docked,
     326             :             // the splitting line is hidden.
     327             :             // If this window is docking but the previous isn't,
     328             :             // then the splitting line is also hidden, because this window
     329             :             // will occupy the space of the previous.
     330           0 :             if (bPrevDocking)
     331             :             {
     332           0 :                 rSplit.Show();
     333             :                 // the actual position and size of the line
     334             :                 rSplit.SetPosSizePixel(
     335           0 :                     MakePoint(nPos2 + nStartPos - nSplitThickness, nPos1),
     336           0 :                     MakeSize(nSplitThickness, nSize - nSplitThickness)
     337           0 :                 );
     338             :                 // the dragging rectangle
     339             :                 rSplit.SetDragRectPixel(Rectangle(
     340             :                     MakePoint(nPos2, nPos1),
     341           0 :                     MakeSize(nLength, nSize - nSplitThickness)
     342           0 :                 ));
     343             :             }
     344             :             else
     345           0 :                 rSplit.Hide();
     346             :         }
     347             :         // next
     348           0 :         bPrevDocking = bDocking;
     349           0 :         if (bDocking)
     350           0 :             nStartPos = vItems[i].nEndPos + nSplitThickness;
     351             :         // We only set nStartPos if this window is docking, because otherwise
     352             :         // the next window will occupy also the space of this window.
     353             :     }
     354             : 
     355             :     // filling the remaining space with the last docking window
     356           0 :     if (!bEmpty && vItems[iLastWin].nEndPos != nLength)
     357             :     {
     358           0 :         Item& rItem = vItems[iLastWin];
     359           0 :         Size aSize = rItem.pWin->GetDockingSize();
     360           0 :         (bVertical ? aSize.Height() : aSize.Width()) += nLength - rItem.nEndPos;
     361           0 :         rItem.pWin->ResizeIfDocking(aSize);
     362             :         // and hiding the split line after the window
     363           0 :         if (iLastWin < vItems.size() - 1)
     364           0 :             vItems[iLastWin + 1].pSplit->Hide();
     365             :     }
     366           0 : }
     367             : 
     368           0 : IMPL_LINK(Layout::SplittedSide, SplitHdl, Splitter*, pSplitter)
     369             : {
     370             :     // checking margins
     371           0 :     CheckMarginsFor(pSplitter);
     372             :     // changing stored sizes
     373           0 :     if (pSplitter == aSplitter.get())
     374             :     {
     375             :         // nSize
     376           0 :         if (bLower)
     377           0 :             nSize = pSplitter->GetSplitPosPixel();
     378             :         else
     379           0 :             nSize = (bVertical ? aRect.Right() : aRect.Bottom()) + 1 - pSplitter->GetSplitPosPixel();
     380             :     }
     381             :     else
     382             :     {
     383             :         // Item::nStartPos, Item::nLength
     384           0 :         for (size_t i = 1; i < vItems.size(); ++i)
     385             :         {
     386           0 :             if (vItems[i].pSplit.get() == pSplitter)
     387             :             {
     388             :                 // before the line
     389           0 :                 vItems[i - 1].nEndPos = pSplitter->GetSplitPosPixel();
     390             :                 // after the line
     391           0 :                 vItems[i].nStartPos = pSplitter->GetSplitPosPixel() + nSplitThickness;
     392             :             }
     393             :         }
     394             :     }
     395             :     // arranging windows
     396           0 :     rLayout.ArrangeWindows();
     397             : 
     398           0 :     return 0;
     399             : }
     400             : 
     401           0 : void Layout::SplittedSide::CheckMarginsFor (Splitter* pSplitter)
     402             : {
     403             :     // The splitter line cannot be closer to the edges than nMargin pixels.
     404             :     static long const nMargin = 16;
     405             :     // Checking margins:
     406           0 :     if (long const nLength = pSplitter->IsHorizontal() ?
     407           0 :         aRect.GetWidth() : aRect.GetHeight()
     408             :     ) {
     409             :         // bounds
     410           0 :         long const nLower = (pSplitter->IsHorizontal() ? aRect.Left() : aRect.Top()) + nMargin;
     411           0 :         long const nUpper = nLower + nLength - 2*nMargin;
     412             :         // split position
     413           0 :         long const nPos = pSplitter->GetSplitPosPixel();
     414             :         // checking bounds
     415           0 :         if (nPos < nLower)
     416           0 :             pSplitter->SetSplitPosPixel(nLower);
     417           0 :         if (nPos > nUpper)
     418           0 :             pSplitter->SetSplitPosPixel(nUpper);
     419             :     }
     420           0 : }
     421             : 
     422           0 : void Layout::SplittedSide::InitSplitter (Splitter& rSplitter)
     423             : {
     424             :     // link
     425           0 :     rSplitter.SetSplitHdl(LINK(this, SplittedSide, SplitHdl));
     426             :     // color
     427           0 :     Color aColor = rLayout.GetSettings().GetStyleSettings().GetShadowColor();
     428           0 :     rSplitter.SetLineColor(aColor);
     429           0 :     rSplitter.SetFillColor(aColor);
     430           0 : }
     431             : 
     432             : 
     433             : } // namespace basctl
     434             : 
     435             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11