1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
22 #include <bastypes.hxx>
23 #include <vcl/settings.hxx>
24 #include <vcl/event.hxx>
31 // the thickness of the splitting lines
32 tools::Long
const nSplitThickness
= 3;
35 // ctor for derived classes
36 // pParent: the parent window (Shell)
37 Layout::Layout (vcl::Window
* pParent
) :
38 Window(pParent
, WB_CLIPCHILDREN
),
41 aLeftSide(this, SplittedSide::Side::Left
),
42 aBottomSide(this, SplittedSide::Side::Bottom
)
44 SetBackground(GetSettings().GetStyleSettings().GetWindowColor());
46 vcl::Font aFont
= GetFont();
47 Size aSz
= aFont
.GetFontSize();
48 aSz
.setHeight( aSz
.Height() * 1.5 );
49 aFont
.SetFontSize(aSz
);
50 aFont
.SetWeight(WEIGHT_BOLD
);
51 aFont
.SetColor(GetSettings().GetStyleSettings().GetWindowTextColor());
60 void Layout::dispose()
63 aBottomSide
.dispose();
68 // removes a docking window
69 void Layout::Remove (DockingWindow
* pWin
)
71 aLeftSide
.Remove(pWin
);
72 aBottomSide
.Remove(pWin
);
75 // called by Window when resized
82 // ArrangeWindows() -- arranges the child windows
83 void Layout::ArrangeWindows ()
85 // prevent recursion via OnFirstSize() -> Add() -> ArrangeWindows()
86 static bool bInArrangeWindows
= false;
87 if (bInArrangeWindows
)
89 bInArrangeWindows
= true;
91 Size
const aSize
= GetOutputSizePixel();
92 tools::Long
const nWidth
= aSize
.Width(), nHeight
= aSize
.Height();
93 if (nWidth
&& nHeight
) // non-empty size
95 // On first call the derived classes initializes the sizes of the
96 // docking windows. This cannot be done at construction because
97 // the Layout has empty size at that point.
101 OnFirstSize(nWidth
, nHeight
); // virtual
105 aBottomSide
.ArrangeIn(tools::Rectangle(Point(0, 0), aSize
));
106 aLeftSide
.ArrangeIn(tools::Rectangle(Point(0, 0), Size(nWidth
, nHeight
- aBottomSide
.GetSize())));
107 // child in the middle
108 pChild
->SetPosSizePixel(
109 Point(aLeftSide
.GetSize(), 0),
110 Size(nWidth
- aLeftSide
.GetSize(), nHeight
- aBottomSide
.GetSize())
114 bInArrangeWindows
= false;
117 void Layout::Activating (BaseWindow
& rWindow
)
123 pChild
->Activating();
126 void Layout::Deactivating ()
129 pChild
->Deactivating();
135 void Layout::DataChanged (DataChangedEvent
const& rDCEvt
)
137 Window::DataChanged(rDCEvt
);
138 if (!(rDCEvt
.GetType() == DataChangedEventType::SETTINGS
&& (rDCEvt
.GetFlags() & AllSettingsFlags::STYLE
)))
141 bool bInvalidate
= false;
142 Color aColor
= GetSettings().GetStyleSettings().GetWindowColor();
143 const AllSettings
* pOldSettings
= rDCEvt
.GetOldSettings();
144 if (!pOldSettings
|| aColor
!= pOldSettings
->GetStyleSettings().GetWindowColor())
146 SetBackground(Wallpaper(aColor
));
149 aColor
= GetSettings().GetStyleSettings().GetWindowTextColor();
150 if (!pOldSettings
|| aColor
!= pOldSettings
->GetStyleSettings().GetWindowTextColor())
152 vcl::Font
aFont(GetFont());
153 aFont
.SetColor(aColor
);
166 Layout::SplittedSide::SplittedSide (Layout
* pParent
, Side eSide
) :
168 bVertical(eSide
== Side::Left
),
169 bLower(eSide
== Side::Left
),
171 aSplitter(VclPtr
<Splitter
>::Create(pParent
, bVertical
? WB_HSCROLL
: WB_VSCROLL
))
173 InitSplitter(*aSplitter
);
176 void Layout::SplittedSide::dispose()
178 aSplitter
.disposeAndClear();
179 for (auto & item
: vItems
)
181 item
.pSplit
.disposeAndClear();
186 // Add() -- adds a new window to the side (after construction)
187 void Layout::SplittedSide::Add (DockingWindow
* pWin
, Size
const& rSize
)
189 tools::Long
const nSize1
= (bVertical
? rSize
.Width() : rSize
.Height()) + nSplitThickness
;
190 tools::Long
const nSize2
= bVertical
? rSize
.Height() : rSize
.Width();
197 aItem
.nStartPos
= vItems
.empty() ? 0 : vItems
.back().nEndPos
+ nSplitThickness
;
198 aItem
.nEndPos
= aItem
.nStartPos
+ nSize2
;
202 aItem
.pSplit
= VclPtr
<Splitter
>::Create(&rLayout
, bVertical
? WB_VSCROLL
: WB_HSCROLL
);
203 aItem
.pSplit
->SetSplitPosPixel(aItem
.nStartPos
- nSplitThickness
);
204 InitSplitter(*aItem
.pSplit
);
206 vItems
.push_back(aItem
);
208 rLayout
.ArrangeWindows();
211 // Remove() -- removes a window from the side (if contains)
212 void Layout::SplittedSide::Remove (DockingWindow
* pWin
)
215 std::vector
<Item
>::size_type iWin
;
216 for (iWin
= 0; iWin
!= vItems
.size(); ++iWin
)
217 if (vItems
[iWin
].pWin
== pWin
)
219 if (iWin
== vItems
.size())
222 vItems
[iWin
].pSplit
.disposeAndClear();
223 vItems
[iWin
].pWin
.clear();
224 vItems
.erase(vItems
.begin() + iWin
);
225 // if that was the first one, remove the first splitter line
226 if (iWin
== 0 && !vItems
.empty())
227 vItems
.front().pSplit
.reset();
230 // creating a Point or a Size object
231 // The coordinate order depends on bVertical (reversed if true).
232 inline Size
Layout::SplittedSide::MakeSize (tools::Long A
, tools::Long B
) const
234 return bVertical
? Size(B
, A
) : Size(A
, B
);
236 inline Point
Layout::SplittedSide::MakePoint (tools::Long A
, tools::Long B
) const
238 return bVertical
? Point(B
, A
) : Point(A
, B
);
241 // IsDocking() -- is this window currently docking in the strip?
242 bool Layout::SplittedSide::IsDocking (DockingWindow
const& rWin
)
244 return rWin
.IsVisible() && !rWin
.IsFloatingMode();
247 // IsEmpty() -- are there no windows docked in this strip?
248 bool Layout::SplittedSide::IsEmpty () const
250 for (auto const & i
: vItems
)
251 if (IsDocking(*i
.pWin
))
256 // GetSize() -- returns the width or height of the strip (depending on the direction)
257 tools::Long
Layout::SplittedSide::GetSize () const
259 return IsEmpty() ? 0 : nSize
;
262 // Arrange() -- arranges the docking windows
263 // rRect: the available space
264 void Layout::SplittedSide::ArrangeIn (tools::Rectangle
const& rRect
)
266 // saving the rectangle
269 // the length of the side
270 tools::Long
const nLength
= bVertical
? aRect
.GetSize().Height() : aRect
.GetSize().Width();
271 tools::Long
const nOtherSize
= bVertical
? aRect
.GetSize().Width() : aRect
.GetSize().Height();
272 // bVertical ? horizontal position : vertical position
273 tools::Long
const nPos1
= (bVertical
? aRect
.Left() : aRect
.Top()) +
274 (bLower
? 0 : nOtherSize
- (nSize
- nSplitThickness
));
275 // bVertical ? vertical position : horizontal position
276 tools::Long
const nPos2
= bVertical
? aRect
.Top() : aRect
.Left();
279 bool const bEmpty
= IsEmpty();
280 // shown if any of the windows is docked
285 aSplitter
->SetSplitPosPixel((bLower
? nSize
: nPos1
) - nSplitThickness
);
286 // the actual position and size
287 aSplitter
->SetPosSizePixel(
288 MakePoint(nPos2
, aSplitter
->GetSplitPosPixel()),
289 MakeSize(nLength
, nSplitThickness
)
291 // dragging rectangle
292 aSplitter
->SetDragRectPixel(aRect
);
297 // positioning separator lines and windows
298 bool bPrevDocking
= false; // is the previous window docked?
299 tools::Long nStartPos
= 0; // window position in the strip
300 std::vector
<Item
>::size_type iLastWin
= vItems
.size(); // index of last docking window in the strip
302 for (std::vector
<Item
>::size_type i
= 0; i
!= vItems
.size(); ++i
)
305 DockingWindow
& rWin
= *vItems
[i
].pWin
;
306 bool const bDocking
= IsDocking(rWin
);
310 rWin
.ResizeIfDocking(
311 MakePoint(nPos2
+ nStartPos
, nPos1
),
312 MakeSize(vItems
[i
].nEndPos
- nStartPos
, nSize
- nSplitThickness
)
314 // splitting line before the window
317 Splitter
& rSplit
= *vItems
[i
].pSplit
;
318 // If neither of two adjacent windows are docked,
319 // the splitting line is hidden.
320 // If this window is docking but the previous isn't,
321 // then the splitting line is also hidden, because this window
322 // will occupy the space of the previous.
326 // the actual position and size of the line
327 rSplit
.SetPosSizePixel(
328 MakePoint(nPos2
+ nStartPos
- nSplitThickness
, nPos1
),
329 MakeSize(nSplitThickness
, nSize
- nSplitThickness
)
331 // the dragging rectangle
332 rSplit
.SetDragRectPixel(tools::Rectangle(
333 MakePoint(nPos2
, nPos1
),
334 MakeSize(nLength
, nSize
- nSplitThickness
)
341 bPrevDocking
= bDocking
;
343 nStartPos
= vItems
[i
].nEndPos
+ nSplitThickness
;
344 // We only set nStartPos if this window is docking, because otherwise
345 // the next window will occupy also the space of this window.
348 // filling the remaining space with the last docking window
349 if (bEmpty
|| vItems
[iLastWin
].nEndPos
== nLength
)
352 Item
& rItem
= vItems
[iLastWin
];
353 Size aSize
= rItem
.pWin
->GetDockingSize();
355 aSize
.AdjustHeight( nLength
- rItem
.nEndPos
);
357 aSize
.AdjustWidth( nLength
- rItem
.nEndPos
);
358 rItem
.pWin
->ResizeIfDocking(aSize
);
359 // and hiding the split line after the window
360 if (iLastWin
< vItems
.size() - 1)
361 vItems
[iLastWin
+ 1].pSplit
->Hide();
364 IMPL_LINK(Layout::SplittedSide
, SplitHdl
, Splitter
*, pSplitter
, void)
367 CheckMarginsFor(pSplitter
);
368 // changing stored sizes
369 if (pSplitter
== aSplitter
.get())
373 nSize
= pSplitter
->GetSplitPosPixel();
375 nSize
= (bVertical
? aRect
.Right() : aRect
.Bottom()) + 1 - pSplitter
->GetSplitPosPixel();
379 // Item::nStartPos, Item::nLength
380 for (size_t i
= 1; i
< vItems
.size(); ++i
)
382 if (vItems
[i
].pSplit
.get() == pSplitter
)
385 vItems
[i
- 1].nEndPos
= pSplitter
->GetSplitPosPixel();
387 vItems
[i
].nStartPos
= pSplitter
->GetSplitPosPixel() + nSplitThickness
;
392 rLayout
.ArrangeWindows();
395 void Layout::SplittedSide::CheckMarginsFor (Splitter
* pSplitter
)
397 // The splitter line cannot be closer to the edges than nMargin pixels.
398 static tools::Long
const nMargin
= 16;
400 tools::Long
const nLength
= pSplitter
->IsHorizontal() ?
401 aRect
.GetWidth() : aRect
.GetHeight();
406 tools::Long
const nLower
= (pSplitter
->IsHorizontal() ? aRect
.Left() : aRect
.Top()) + nMargin
;
407 tools::Long
const nUpper
= nLower
+ nLength
- 2*nMargin
;
409 tools::Long
const nPos
= pSplitter
->GetSplitPosPixel();
412 pSplitter
->SetSplitPosPixel(nLower
);
414 pSplitter
->SetSplitPosPixel(nUpper
);
417 void Layout::SplittedSide::InitSplitter (Splitter
& rSplitter
)
420 rSplitter
.SetSplitHdl(LINK(this, SplittedSide
, SplitHdl
));
422 Color aColor
= rLayout
.GetSettings().GetStyleSettings().GetShadowColor();
423 rSplitter
.GetOutDev()->SetLineColor(aColor
);
424 rSplitter
.GetOutDev()->SetFillColor(aColor
);
428 } // namespace basctl
430 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */