LCOV - code coverage report
Current view: top level - basctl/source/basicide - layout.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 0 189 0.0 %
Date: 2014-04-11 Functions: 0 23 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 (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 :     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             : // virtual dtor
      57           0 : Layout::~Layout()
      58           0 : { }
      59             : 
      60             : // removes a docking window
      61           0 : void Layout::Remove (DockingWindow* pWin)
      62             : {
      63           0 :     aLeftSide.Remove(pWin);
      64           0 :     aBottomSide.Remove(pWin);
      65           0 : }
      66             : 
      67             : // called by Window when resized
      68           0 : void Layout::Resize()
      69             : {
      70           0 :     if (IsVisible())
      71           0 :         ArrangeWindows();
      72           0 : }
      73             : 
      74             : // ArrangeWindows() -- arranges the child windows
      75           0 : void Layout::ArrangeWindows ()
      76             : {
      77             :     // prevent recursion via OnFirstSize() -> Add() -> ArrangeWindows()
      78             :     static bool bInArrangeWindows = false;
      79           0 :     if (bInArrangeWindows)
      80           0 :         return;
      81           0 :     bInArrangeWindows = true;
      82             : 
      83           0 :     Size const aSize = GetOutputSizePixel();
      84           0 :     long const nWidth = aSize.Width(), nHeight = aSize.Height();
      85           0 :     if (nWidth && nHeight) // non-empty size
      86             :     {
      87             :         // On first call the derived classes initializes the sizes of the
      88             :         // docking windows. This cannot be done at construction because
      89             :         // the Layout has empty size at that point.
      90           0 :         if (bFirstSize)
      91             :         {
      92           0 :             bFirstSize = false;
      93           0 :             this->OnFirstSize(nWidth, nHeight); // virtual
      94             :         }
      95             : 
      96             :         // sides
      97           0 :         aBottomSide.ArrangeIn(Rectangle(Point(0, 0), aSize));
      98           0 :         aLeftSide.ArrangeIn(Rectangle(Point(0, 0), Size(nWidth, nHeight - aBottomSide.GetSize())));
      99             :         // child in the middle
     100             :         pChild->SetPosSizePixel(
     101             :             Point(aLeftSide.GetSize(), 0),
     102           0 :             Size(nWidth - aLeftSide.GetSize(), nHeight - aBottomSide.GetSize())
     103           0 :         );
     104             :     }
     105             : 
     106           0 :     bInArrangeWindows = false;
     107             : }
     108             : 
     109           0 : void Layout::DockaWindow (DockingWindow*)
     110             : {
     111           0 :     ArrangeWindows();
     112           0 : }
     113             : 
     114           0 : void Layout::Activating (BaseWindow& rWindow)
     115             : {
     116             :     // first activation
     117           0 :     pChild = &rWindow;
     118           0 :     ArrangeWindows();
     119           0 :     Show();
     120           0 :     pChild->Activating();
     121           0 : }
     122             : 
     123           0 : void Layout::Deactivating ()
     124             : {
     125           0 :     if (pChild)
     126           0 :         pChild->Deactivating();
     127           0 :     Hide();
     128           0 :     pChild = 0;
     129           0 : }
     130             : 
     131             : // virtual
     132           0 : void Layout::DataChanged (DataChangedEvent const& rDCEvt)
     133             : {
     134           0 :     Window::DataChanged(rDCEvt);
     135           0 :     if (rDCEvt.GetType() == DATACHANGED_SETTINGS && (rDCEvt.GetFlags() & SETTINGS_STYLE))
     136             :     {
     137           0 :         bool bInvalidate = false;
     138           0 :         Color aColor = GetSettings().GetStyleSettings().GetWindowColor();
     139           0 :         const AllSettings* pOldSettings = rDCEvt.GetOldSettings();
     140           0 :         if (!pOldSettings || aColor != pOldSettings->GetStyleSettings().GetWindowColor())
     141             :         {
     142           0 :             SetBackground(Wallpaper(aColor));
     143           0 :             bInvalidate = true;
     144             :         }
     145           0 :         aColor = GetSettings().GetStyleSettings().GetWindowTextColor();
     146           0 :         if (!pOldSettings || aColor != pOldSettings->GetStyleSettings().GetWindowTextColor())
     147             :         {
     148           0 :             Font aFont(GetFont());
     149           0 :             aFont.SetColor(aColor);
     150           0 :             SetFont(aFont);
     151           0 :             bInvalidate = true;
     152             :         }
     153           0 :         if (bInvalidate)
     154           0 :             Invalidate();
     155             :     }
     156           0 : }
     157             : 
     158             : 
     159             : // SplittedSide
     160             : 
     161             : 
     162             : 
     163             : // ctor
     164           0 : Layout::SplittedSide::SplittedSide (Layout* pParent, Side eSide) :
     165             :     rLayout(*pParent),
     166           0 :     bVertical(eSide == Left || eSide == Right),
     167           0 :     bLower(eSide == Left || eSide == Top),
     168             :     nSize(0),
     169           0 :     aSplitter(pParent, bVertical ? WB_HSCROLL : WB_VSCROLL)
     170             : {
     171           0 :     InitSplitter(aSplitter);
     172           0 : }
     173             : 
     174             : 
     175             : // Add() -- adds a new window to the side (after construction)
     176           0 : void Layout::SplittedSide::Add (DockingWindow* pWin, Size const& rSize)
     177             : {
     178           0 :     long const nSize1 = (bVertical ? rSize.Width() : rSize.Height()) + nSplitThickness;
     179           0 :     long const nSize2 = bVertical ? rSize.Height() : rSize.Width();
     180             :     // nSize
     181           0 :     if (nSize1 > nSize)
     182           0 :         nSize = nSize1;
     183             :     // window
     184           0 :     Item aItem;
     185           0 :     aItem.pWin = pWin;
     186           0 :     aItem.nStartPos = vItems.empty() ? 0 : vItems.back().nEndPos + nSplitThickness;
     187           0 :     aItem.nEndPos = aItem.nStartPos + nSize2;
     188             :     // splitter
     189           0 :     if (!vItems.empty())
     190             :     {
     191           0 :         aItem.pSplit = boost::make_shared<Splitter>(&rLayout, bVertical ? WB_VSCROLL : WB_HSCROLL);
     192           0 :         aItem.pSplit->SetSplitPosPixel(aItem.nStartPos - nSplitThickness);
     193           0 :         InitSplitter(*aItem.pSplit);
     194             :     }
     195           0 :     vItems.push_back(aItem);
     196             :     // refresh
     197           0 :     rLayout.ArrangeWindows();
     198           0 : }
     199             : 
     200             : // Remove() -- removes a window from the side (if contains)
     201           0 : void Layout::SplittedSide::Remove (DockingWindow* pWin)
     202             : {
     203             :     // contains?
     204             :     unsigned iWin;
     205           0 :     for (iWin = 0; iWin != vItems.size(); ++iWin)
     206           0 :         if (vItems[iWin].pWin == pWin)
     207           0 :             break;
     208           0 :     if (iWin == vItems.size())
     209           0 :         return;
     210             :     // remove
     211           0 :     vItems.erase(vItems.begin() + iWin);
     212             :     // if that was the first one, remove the first splitter line
     213           0 :     if (iWin == 0 && !vItems.empty())
     214           0 :         vItems.front().pSplit.reset();
     215             : }
     216             : 
     217             : // creating a Point or a Size object
     218             : // The coordinate order depends on bVertical (reversed if true).
     219           0 : inline Size Layout::SplittedSide::MakeSize (long A, long B) const
     220             : {
     221           0 :     return bVertical ? Size(B, A) : Size(A, B);
     222             : }
     223           0 : inline Point Layout::SplittedSide::MakePoint (long A, long B) const
     224             : {
     225           0 :     return bVertical ? Point(B, A) : Point(A, B);
     226             : }
     227             : 
     228             : // IsDocking() -- is this window currently docking in the strip?
     229           0 : bool Layout::SplittedSide::IsDocking (DockingWindow const& rWin)
     230             : {
     231           0 :     return rWin.IsVisible() && !rWin.IsFloatingMode();
     232             : }
     233             : 
     234             : // IsEmpty() -- are there no windows docked in this strip?
     235           0 : bool Layout::SplittedSide::IsEmpty () const
     236             : {
     237           0 :     for (unsigned i = 0; i != vItems.size(); ++i)
     238           0 :         if (IsDocking(*vItems[i].pWin))
     239           0 :             return false;
     240           0 :     return true;
     241             : }
     242             : 
     243             : // GetSize() -- returns the width or height of the strip (depending on the direction)
     244           0 : long Layout::SplittedSide::GetSize () const
     245             : {
     246           0 :     return IsEmpty() ? 0 : nSize;
     247             : }
     248             : 
     249             : // Arrange() -- arranges the docking windows
     250             : // rRect: the available space
     251           0 : void Layout::SplittedSide::ArrangeIn (Rectangle const& rRect)
     252             : {
     253             :     // saving the rectangle
     254           0 :     aRect = rRect;
     255             : 
     256             :     // the length of the side
     257           0 :     long const nLength = bVertical ? aRect.GetSize().Height() : aRect.GetSize().Width();
     258           0 :     long const nOtherSize = bVertical ? aRect.GetSize().Width() : aRect.GetSize().Height();
     259             :     // bVertical ? horizontal pozition : vertical pozition
     260           0 :     long const nPos1 = (bVertical ? aRect.Left() : aRect.Top()) +
     261           0 :         (bLower ? 0 : nOtherSize - (nSize - nSplitThickness));
     262             :     // bVertical ? vertical position : horizontal position
     263           0 :     long const nPos2 = bVertical ? aRect.Top() : aRect.Left();
     264             : 
     265             :     // main line
     266           0 :     bool const bEmpty = IsEmpty();
     267             :     // shown if any of the windows is docked
     268           0 :     if (!bEmpty)
     269             :     {
     270           0 :         aSplitter.Show();
     271             :         // split position
     272           0 :         aSplitter.SetSplitPosPixel((bLower ? nSize : nPos1) - nSplitThickness);
     273             :         // the actual position and size
     274             :         aSplitter.SetPosSizePixel(
     275           0 :             MakePoint(nPos2, aSplitter.GetSplitPosPixel()),
     276             :             MakeSize(nLength, nSplitThickness)
     277           0 :         );
     278             :         // dragging rectangle
     279           0 :         aSplitter.SetDragRectPixel(aRect);
     280             :     }
     281             :     else
     282           0 :         aSplitter.Hide();
     283             : 
     284             :     // positioning separator lines and windows
     285           0 :     bool bPrevDocking = false; // is the previous window docked?
     286           0 :     long nStartPos = 0; // window position in the strip
     287           0 :     unsigned iLastWin = vItems.size(); // index of last docking window in the strip
     288             : 
     289           0 :     for (unsigned i = 0; i != vItems.size(); ++i)
     290             :     {
     291             :         // window
     292           0 :         DockingWindow& rWin = *vItems[i].pWin;
     293           0 :         bool const bDocking = IsDocking(rWin);
     294           0 :         if (bDocking)
     295           0 :             iLastWin = i;
     296             :         // sizing window
     297             :         rWin.ResizeIfDocking(
     298           0 :             MakePoint(nPos2 + nStartPos, nPos1),
     299           0 :             MakeSize(vItems[i].nEndPos - nStartPos, nSize - nSplitThickness)
     300           0 :         );
     301             :         // splitting line before the window
     302           0 :         if (i > 0)
     303             :         {
     304           0 :             Splitter& rSplit = *vItems[i].pSplit;
     305             :             // If neither of two adjacent windows are docked,
     306             :             // the splitting line is hidden.
     307             :             // If this window is docking but the previous isn't,
     308             :             // then the splitting line is also hidden, because this window
     309             :             // will occupy the space of the previous.
     310           0 :             if (bPrevDocking)
     311             :             {
     312           0 :                 rSplit.Show();
     313             :                 // the actual position and size of the line
     314             :                 rSplit.SetPosSizePixel(
     315           0 :                     MakePoint(nPos2 + nStartPos - nSplitThickness, nPos1),
     316           0 :                     MakeSize(nSplitThickness, nSize - nSplitThickness)
     317           0 :                 );
     318             :                 // the dragging rectangle
     319             :                 rSplit.SetDragRectPixel(Rectangle(
     320             :                     MakePoint(nPos2, nPos1),
     321           0 :                     MakeSize(nLength, nSize - nSplitThickness)
     322           0 :                 ));
     323             :             }
     324             :             else
     325           0 :                 rSplit.Hide();
     326             :         }
     327             :         // next
     328           0 :         bPrevDocking = bDocking;
     329           0 :         if (bDocking)
     330           0 :             nStartPos = vItems[i].nEndPos + nSplitThickness;
     331             :         // We only set nStartPos if this window is docking, because otherwise
     332             :         // the next window will occupy also the space of this window.
     333             :     }
     334             : 
     335             :     // filling the remaining space with the last docking window
     336           0 :     if (!bEmpty && vItems[iLastWin].nEndPos != nLength)
     337             :     {
     338           0 :         Item& rItem = vItems[iLastWin];
     339           0 :         Size aSize = rItem.pWin->GetDockingSize();
     340           0 :         (bVertical ? aSize.Height() : aSize.Width()) += nLength - rItem.nEndPos;
     341           0 :         rItem.pWin->ResizeIfDocking(aSize);
     342             :         // and hiding the split line after the window
     343           0 :         if (iLastWin < vItems.size() - 1)
     344           0 :             vItems[iLastWin + 1].pSplit->Hide();
     345             :     }
     346           0 : }
     347             : 
     348           0 : IMPL_LINK(Layout::SplittedSide, SplitHdl, Splitter*, pSplitter)
     349             : {
     350             :     // checking margins
     351           0 :     CheckMarginsFor(pSplitter);
     352             :     // changing stored sizes
     353           0 :     if (pSplitter == &aSplitter)
     354             :     {
     355             :         // nSize
     356           0 :         if (bLower)
     357           0 :             nSize = pSplitter->GetSplitPosPixel();
     358             :         else
     359           0 :             nSize = (bVertical ? aRect.Right() : aRect.Bottom()) + 1 - pSplitter->GetSplitPosPixel();
     360             :     }
     361             :     else
     362             :     {
     363             :         // Item::nStartPos, Item::nLength
     364           0 :         for (unsigned i = 1; i < vItems.size(); ++i)
     365             :         {
     366           0 :             if (vItems[i].pSplit.get() == pSplitter)
     367             :             {
     368             :                 // before the line
     369           0 :                 vItems[i - 1].nEndPos = pSplitter->GetSplitPosPixel();
     370             :                 // after the line
     371           0 :                 vItems[i].nStartPos = pSplitter->GetSplitPosPixel() + nSplitThickness;
     372             :             }
     373             :         }
     374             :     }
     375             :     // arranging windows
     376           0 :     rLayout.ArrangeWindows();
     377             : 
     378           0 :     return 0;
     379             : }
     380             : 
     381           0 : void Layout::SplittedSide::CheckMarginsFor (Splitter* pSplitter)
     382             : {
     383             :     // The splitter line cannot be closer to the edges than nMargin pixels.
     384             :     static long const nMargin = 16;
     385             :     // Checking margins:
     386           0 :     if (long const nLength = pSplitter->IsHorizontal() ?
     387           0 :         aRect.GetWidth() : aRect.GetHeight()
     388             :     ) {
     389             :         // bounds
     390           0 :         long const nLower = (pSplitter->IsHorizontal() ? aRect.Left() : aRect.Top()) + nMargin;
     391           0 :         long const nUpper = nLower + nLength - 2*nMargin;
     392             :         // split position
     393           0 :         long const nPos = pSplitter->GetSplitPosPixel();
     394             :         // checking bounds
     395           0 :         if (nPos < nLower)
     396           0 :             pSplitter->SetSplitPosPixel(nLower);
     397           0 :         if (nPos > nUpper)
     398           0 :             pSplitter->SetSplitPosPixel(nUpper);
     399             :     }
     400           0 : }
     401             : 
     402           0 : void Layout::SplittedSide::InitSplitter (Splitter& rSplitter)
     403             : {
     404             :     // link
     405           0 :     rSplitter.SetSplitHdl(LINK(this, SplittedSide, SplitHdl));
     406             :     // color
     407           0 :     Color aColor = rLayout.GetSettings().GetStyleSettings().GetShadowColor();
     408           0 :     rSplitter.SetLineColor(aColor);
     409           0 :     rSplitter.SetFillColor(aColor);
     410           0 : }
     411             : 
     412             : 
     413             : } // namespace basctl
     414             : 
     415             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10