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>
25 #include <boost/make_shared.hpp>
32 // the thickness of the splitting lines
33 static long const nSplitThickness
= 3;
36 // ctor for derived classes
37 // pParent: the parent window (Shell)
38 Layout::Layout (vcl::Window
* pParent
) :
39 Window(pParent
, WB_CLIPCHILDREN
),
42 aLeftSide(this, SplittedSide::Left
),
43 aBottomSide(this, SplittedSide::Bottom
)
45 SetBackground(GetSettings().GetStyleSettings().GetWindowColor());
47 vcl::Font aFont
= GetFont();
48 Size aSz
= aFont
.GetSize();
51 aFont
.SetWeight(WEIGHT_BOLD
);
52 aFont
.SetColor(GetSettings().GetStyleSettings().GetWindowTextColor());
61 void Layout::dispose()
64 aBottomSide
.dispose();
69 // removes a docking window
70 void Layout::Remove (DockingWindow
* pWin
)
72 aLeftSide
.Remove(pWin
);
73 aBottomSide
.Remove(pWin
);
76 // called by Window when resized
83 // ArrangeWindows() -- arranges the child windows
84 void Layout::ArrangeWindows ()
86 // prevent recursion via OnFirstSize() -> Add() -> ArrangeWindows()
87 static bool bInArrangeWindows
= false;
88 if (bInArrangeWindows
)
90 bInArrangeWindows
= true;
92 Size
const aSize
= GetOutputSizePixel();
93 long const nWidth
= aSize
.Width(), nHeight
= aSize
.Height();
94 if (nWidth
&& nHeight
) // non-empty size
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.
102 this->OnFirstSize(nWidth
, nHeight
); // virtual
106 aBottomSide
.ArrangeIn(Rectangle(Point(0, 0), aSize
));
107 aLeftSide
.ArrangeIn(Rectangle(Point(0, 0), Size(nWidth
, nHeight
- aBottomSide
.GetSize())));
108 // child in the middle
109 pChild
->SetPosSizePixel(
110 Point(aLeftSide
.GetSize(), 0),
111 Size(nWidth
- aLeftSide
.GetSize(), nHeight
- aBottomSide
.GetSize())
115 bInArrangeWindows
= false;
118 void Layout::DockaWindow (DockingWindow
*)
123 void Layout::Activating (BaseWindow
& rWindow
)
129 pChild
->Activating();
132 void Layout::Deactivating ()
135 pChild
->Deactivating();
141 void Layout::DataChanged (DataChangedEvent
const& rDCEvt
)
143 Window::DataChanged(rDCEvt
);
144 if (rDCEvt
.GetType() == DataChangedEventType::SETTINGS
&& (rDCEvt
.GetFlags() & AllSettingsFlags::STYLE
))
146 bool bInvalidate
= false;
147 Color aColor
= GetSettings().GetStyleSettings().GetWindowColor();
148 const AllSettings
* pOldSettings
= rDCEvt
.GetOldSettings();
149 if (!pOldSettings
|| aColor
!= pOldSettings
->GetStyleSettings().GetWindowColor())
151 SetBackground(Wallpaper(aColor
));
154 aColor
= GetSettings().GetStyleSettings().GetWindowTextColor();
155 if (!pOldSettings
|| aColor
!= pOldSettings
->GetStyleSettings().GetWindowTextColor())
157 vcl::Font
aFont(GetFont());
158 aFont
.SetColor(aColor
);
173 Layout::SplittedSide::SplittedSide (Layout
* pParent
, Side eSide
) :
175 bVertical(eSide
== Left
|| eSide
== Right
),
176 bLower(eSide
== Left
|| eSide
== Top
),
178 aSplitter(VclPtr
<Splitter
>::Create(pParent
, bVertical
? WB_HSCROLL
: WB_VSCROLL
))
180 InitSplitter(*aSplitter
.get());
183 void Layout::SplittedSide::dispose()
185 aSplitter
.disposeAndClear();
186 for (auto i
= vItems
.begin(); i
!= vItems
.end(); ++i
)
188 i
->pSplit
.disposeAndClear();
193 // Add() -- adds a new window to the side (after construction)
194 void Layout::SplittedSide::Add (DockingWindow
* pWin
, Size
const& rSize
)
196 long const nSize1
= (bVertical
? rSize
.Width() : rSize
.Height()) + nSplitThickness
;
197 long const nSize2
= bVertical
? rSize
.Height() : rSize
.Width();
204 aItem
.nStartPos
= vItems
.empty() ? 0 : vItems
.back().nEndPos
+ nSplitThickness
;
205 aItem
.nEndPos
= aItem
.nStartPos
+ nSize2
;
209 aItem
.pSplit
= VclPtr
<Splitter
>::Create(&rLayout
, bVertical
? WB_VSCROLL
: WB_HSCROLL
);
210 aItem
.pSplit
->SetSplitPosPixel(aItem
.nStartPos
- nSplitThickness
);
211 InitSplitter(*aItem
.pSplit
);
213 vItems
.push_back(aItem
);
215 rLayout
.ArrangeWindows();
218 // Remove() -- removes a window from the side (if contains)
219 void Layout::SplittedSide::Remove (DockingWindow
* pWin
)
223 for (iWin
= 0; iWin
!= vItems
.size(); ++iWin
)
224 if (vItems
[iWin
].pWin
== pWin
)
226 if (iWin
== vItems
.size())
229 vItems
[iWin
].pSplit
.disposeAndClear();
230 vItems
[iWin
].pWin
.clear();
231 vItems
.erase(vItems
.begin() + iWin
);
232 // if that was the first one, remove the first splitter line
233 if (iWin
== 0 && !vItems
.empty())
234 vItems
.front().pSplit
.reset();
237 // creating a Point or a Size object
238 // The coordinate order depends on bVertical (reversed if true).
239 inline Size
Layout::SplittedSide::MakeSize (long A
, long B
) const
241 return bVertical
? Size(B
, A
) : Size(A
, B
);
243 inline Point
Layout::SplittedSide::MakePoint (long A
, long B
) const
245 return bVertical
? Point(B
, A
) : Point(A
, B
);
248 // IsDocking() -- is this window currently docking in the strip?
249 bool Layout::SplittedSide::IsDocking (DockingWindow
const& rWin
)
251 return rWin
.IsVisible() && !rWin
.IsFloatingMode();
254 // IsEmpty() -- are there no windows docked in this strip?
255 bool Layout::SplittedSide::IsEmpty () const
257 for (unsigned i
= 0; i
!= vItems
.size(); ++i
)
258 if (IsDocking(*vItems
[i
].pWin
))
263 // GetSize() -- returns the width or height of the strip (depending on the direction)
264 long Layout::SplittedSide::GetSize () const
266 return IsEmpty() ? 0 : nSize
;
269 // Arrange() -- arranges the docking windows
270 // rRect: the available space
271 void Layout::SplittedSide::ArrangeIn (Rectangle
const& rRect
)
273 // saving the rectangle
276 // the length of the side
277 long const nLength
= bVertical
? aRect
.GetSize().Height() : aRect
.GetSize().Width();
278 long const nOtherSize
= bVertical
? aRect
.GetSize().Width() : aRect
.GetSize().Height();
279 // bVertical ? horizontal pozition : vertical pozition
280 long const nPos1
= (bVertical
? aRect
.Left() : aRect
.Top()) +
281 (bLower
? 0 : nOtherSize
- (nSize
- nSplitThickness
));
282 // bVertical ? vertical position : horizontal position
283 long const nPos2
= bVertical
? aRect
.Top() : aRect
.Left();
286 bool const bEmpty
= IsEmpty();
287 // shown if any of the windows is docked
292 aSplitter
->SetSplitPosPixel((bLower
? nSize
: nPos1
) - nSplitThickness
);
293 // the actual position and size
294 aSplitter
->SetPosSizePixel(
295 MakePoint(nPos2
, aSplitter
->GetSplitPosPixel()),
296 MakeSize(nLength
, nSplitThickness
)
298 // dragging rectangle
299 aSplitter
->SetDragRectPixel(aRect
);
304 // positioning separator lines and windows
305 bool bPrevDocking
= false; // is the previous window docked?
306 long nStartPos
= 0; // window position in the strip
307 unsigned iLastWin
= vItems
.size(); // index of last docking window in the strip
309 for (unsigned i
= 0; i
!= vItems
.size(); ++i
)
312 DockingWindow
& rWin
= *vItems
[i
].pWin
;
313 bool const bDocking
= IsDocking(rWin
);
317 rWin
.ResizeIfDocking(
318 MakePoint(nPos2
+ nStartPos
, nPos1
),
319 MakeSize(vItems
[i
].nEndPos
- nStartPos
, nSize
- nSplitThickness
)
321 // splitting line before the window
324 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.
333 // the actual position and size of the line
334 rSplit
.SetPosSizePixel(
335 MakePoint(nPos2
+ nStartPos
- nSplitThickness
, nPos1
),
336 MakeSize(nSplitThickness
, nSize
- nSplitThickness
)
338 // the dragging rectangle
339 rSplit
.SetDragRectPixel(Rectangle(
340 MakePoint(nPos2
, nPos1
),
341 MakeSize(nLength
, nSize
- nSplitThickness
)
348 bPrevDocking
= bDocking
;
350 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.
355 // filling the remaining space with the last docking window
356 if (!bEmpty
&& vItems
[iLastWin
].nEndPos
!= nLength
)
358 Item
& rItem
= vItems
[iLastWin
];
359 Size aSize
= rItem
.pWin
->GetDockingSize();
360 (bVertical
? aSize
.Height() : aSize
.Width()) += nLength
- rItem
.nEndPos
;
361 rItem
.pWin
->ResizeIfDocking(aSize
);
362 // and hiding the split line after the window
363 if (iLastWin
< vItems
.size() - 1)
364 vItems
[iLastWin
+ 1].pSplit
->Hide();
368 IMPL_LINK(Layout::SplittedSide
, SplitHdl
, Splitter
*, pSplitter
)
371 CheckMarginsFor(pSplitter
);
372 // changing stored sizes
373 if (pSplitter
== aSplitter
.get())
377 nSize
= pSplitter
->GetSplitPosPixel();
379 nSize
= (bVertical
? aRect
.Right() : aRect
.Bottom()) + 1 - pSplitter
->GetSplitPosPixel();
383 // Item::nStartPos, Item::nLength
384 for (unsigned i
= 1; i
< vItems
.size(); ++i
)
386 if (vItems
[i
].pSplit
.get() == pSplitter
)
389 vItems
[i
- 1].nEndPos
= pSplitter
->GetSplitPosPixel();
391 vItems
[i
].nStartPos
= pSplitter
->GetSplitPosPixel() + nSplitThickness
;
396 rLayout
.ArrangeWindows();
401 void Layout::SplittedSide::CheckMarginsFor (Splitter
* pSplitter
)
403 // The splitter line cannot be closer to the edges than nMargin pixels.
404 static long const nMargin
= 16;
406 if (long const nLength
= pSplitter
->IsHorizontal() ?
407 aRect
.GetWidth() : aRect
.GetHeight()
410 long const nLower
= (pSplitter
->IsHorizontal() ? aRect
.Left() : aRect
.Top()) + nMargin
;
411 long const nUpper
= nLower
+ nLength
- 2*nMargin
;
413 long const nPos
= pSplitter
->GetSplitPosPixel();
416 pSplitter
->SetSplitPosPixel(nLower
);
418 pSplitter
->SetSplitPosPixel(nUpper
);
422 void Layout::SplittedSide::InitSplitter (Splitter
& rSplitter
)
425 rSplitter
.SetSplitHdl(LINK(this, SplittedSide
, SplitHdl
));
427 Color aColor
= rLayout
.GetSettings().GetStyleSettings().GetShadowColor();
428 rSplitter
.SetLineColor(aColor
);
429 rSplitter
.SetFillColor(aColor
);
433 } // namespace basctl
435 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */