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

Generated by: LCOV version 1.10