LibreOffice Module basctl (master) 1
layout.cxx
Go to the documentation of this file.
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#include <vcl/event.hxx>
25
26namespace basctl
27{
28
29namespace
30{
31// the thickness of the splitting lines
32tools::Long const nSplitThickness = 3;
33} // namespace
34
35// ctor for derived classes
36// pParent: the parent window (Shell)
38 Window(pParent, WB_CLIPCHILDREN),
39 pChild(nullptr),
40 bFirstSize(true),
41 aLeftSide(this, SplittedSide::Side::Left),
42 aBottomSide(this, SplittedSide::Side::Bottom)
43{
44 SetBackground(GetSettings().GetStyleSettings().GetWindowColor());
45
46 vcl::Font aFont = GetFont();
47 Size aSz = aFont.GetFontSize();
48 aSz.setHeight( aSz.Height() * 1.5 );
49 aFont.SetFontSize(aSz);
51 aFont.SetColor(GetSettings().GetStyleSettings().GetWindowTextColor());
52 SetFont(aFont);
53}
54
56{
58}
59
61{
64 pChild.clear();
65 Window::dispose();
66}
67
68// removes a docking window
70{
71 aLeftSide.Remove(pWin);
72 aBottomSide.Remove(pWin);
73}
74
75// called by Window when resized
77{
78 if (IsVisible())
80}
81
82// ArrangeWindows() -- arranges the child windows
84{
85 // prevent recursion via OnFirstSize() -> Add() -> ArrangeWindows()
86 static bool bInArrangeWindows = false;
87 if (bInArrangeWindows)
88 return;
89 bInArrangeWindows = true;
90
91 Size const aSize = GetOutputSizePixel();
92 tools::Long const nWidth = aSize.Width(), nHeight = aSize.Height();
93 if (nWidth && nHeight) // non-empty size
94 {
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.
98 if (bFirstSize)
99 {
100 bFirstSize = false;
101 OnFirstSize(nWidth, nHeight); // virtual
102 }
103
104 // sides
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())
111 );
112 }
113
114 bInArrangeWindows = false;
115}
116
118{
119 // first activation
120 pChild = &rWindow;
122 Show();
123 pChild->Activating();
124}
125
127{
128 if (pChild)
129 pChild->Deactivating();
130 Hide();
131 pChild = nullptr;
132}
133
134// virtual
136{
137 Window::DataChanged(rDCEvt);
138 if (!(rDCEvt.GetType() == DataChangedEventType::SETTINGS && (rDCEvt.GetFlags() & AllSettingsFlags::STYLE)))
139 return;
140
141 bool bInvalidate = false;
143 const AllSettings* pOldSettings = rDCEvt.GetOldSettings();
144 if (!pOldSettings || aColor != pOldSettings->GetStyleSettings().GetWindowColor())
145 {
146 SetBackground(Wallpaper(aColor));
147 bInvalidate = true;
148 }
150 if (!pOldSettings || aColor != pOldSettings->GetStyleSettings().GetWindowTextColor())
151 {
152 vcl::Font aFont(GetFont());
153 aFont.SetColor(aColor);
154 SetFont(aFont);
155 bInvalidate = true;
156 }
157 if (bInvalidate)
158 Invalidate();
159}
160
161
162// SplittedSide
163
164
165// ctor
167 rLayout(*pParent),
168 bVertical(eSide == Side::Left),
169 bLower(eSide == Side::Left),
170 nSize(0),
171 aSplitter(VclPtr<Splitter>::Create(pParent, bVertical ? WB_HSCROLL : WB_VSCROLL))
172{
174}
175
177{
178 aSplitter.disposeAndClear();
179 for (auto & item : vItems)
180 {
181 item.pSplit.disposeAndClear();
182 item.pWin.clear();
183 }
184}
185
186// Add() -- adds a new window to the side (after construction)
188{
189 tools::Long const nSize1 = (bVertical ? rSize.Width() : rSize.Height()) + nSplitThickness;
190 tools::Long const nSize2 = bVertical ? rSize.Height() : rSize.Width();
191 // nSize
192 if (nSize1 > nSize)
193 nSize = nSize1;
194 // window
195 Item aItem;
196 aItem.pWin = pWin;
197 aItem.nStartPos = vItems.empty() ? 0 : vItems.back().nEndPos + nSplitThickness;
198 aItem.nEndPos = aItem.nStartPos + nSize2;
199 // splitter
200 if (!vItems.empty())
201 {
202 aItem.pSplit = VclPtr<Splitter>::Create(&rLayout, bVertical ? WB_VSCROLL : WB_HSCROLL);
203 aItem.pSplit->SetSplitPosPixel(aItem.nStartPos - nSplitThickness);
204 InitSplitter(*aItem.pSplit);
205 }
206 vItems.push_back(aItem);
207 // refresh
208 rLayout.ArrangeWindows();
209}
210
211// Remove() -- removes a window from the side (if contains)
213{
214 // contains?
215 std::vector<Item>::size_type iWin;
216 for (iWin = 0; iWin != vItems.size(); ++iWin)
217 if (vItems[iWin].pWin == pWin)
218 break;
219 if (iWin == vItems.size())
220 return;
221 // remove
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();
228}
229
230// creating a Point or a Size object
231// The coordinate order depends on bVertical (reversed if true).
233{
234 return bVertical ? Size(B, A) : Size(A, B);
235}
237{
238 return bVertical ? Point(B, A) : Point(A, B);
239}
240
241// IsDocking() -- is this window currently docking in the strip?
243{
244 return rWin.IsVisible() && !rWin.IsFloatingMode();
245}
246
247// IsEmpty() -- are there no windows docked in this strip?
249{
250 for (auto const & i: vItems)
251 if (IsDocking(*i.pWin))
252 return false;
253 return true;
254}
255
256// GetSize() -- returns the width or height of the strip (depending on the direction)
258{
259 return IsEmpty() ? 0 : nSize;
260}
261
262// Arrange() -- arranges the docking windows
263// rRect: the available space
265{
266 // saving the rectangle
267 aRect = rRect;
268
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();
277
278 // main line
279 bool const bEmpty = IsEmpty();
280 // shown if any of the windows is docked
281 if (!bEmpty)
282 {
283 aSplitter->Show();
284 // split position
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)
290 );
291 // dragging rectangle
292 aSplitter->SetDragRectPixel(aRect);
293 }
294 else
295 aSplitter->Hide();
296
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
301
302 for (std::vector<Item>::size_type i = 0; i != vItems.size(); ++i)
303 {
304 // window
305 DockingWindow& rWin = *vItems[i].pWin;
306 bool const bDocking = IsDocking(rWin);
307 if (bDocking)
308 iLastWin = i;
309 // sizing window
310 rWin.ResizeIfDocking(
311 MakePoint(nPos2 + nStartPos, nPos1),
312 MakeSize(vItems[i].nEndPos - nStartPos, nSize - nSplitThickness)
313 );
314 // splitting line before the window
315 if (i > 0)
316 {
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.
323 if (bPrevDocking)
324 {
325 rSplit.Show();
326 // the actual position and size of the line
327 rSplit.SetPosSizePixel(
328 MakePoint(nPos2 + nStartPos - nSplitThickness, nPos1),
329 MakeSize(nSplitThickness, nSize - nSplitThickness)
330 );
331 // the dragging rectangle
333 MakePoint(nPos2, nPos1),
334 MakeSize(nLength, nSize - nSplitThickness)
335 ));
336 }
337 else
338 rSplit.Hide();
339 }
340 // next
341 bPrevDocking = bDocking;
342 if (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.
346 }
347
348 // filling the remaining space with the last docking window
349 if (bEmpty || vItems[iLastWin].nEndPos == nLength)
350 return;
351
352 Item& rItem = vItems[iLastWin];
353 Size aSize = rItem.pWin->GetDockingSize();
354 if (bVertical)
355 aSize.AdjustHeight( nLength - rItem.nEndPos );
356 else
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();
362}
363
364IMPL_LINK(Layout::SplittedSide, SplitHdl, Splitter*, pSplitter, void)
365{
366 // checking margins
367 CheckMarginsFor(pSplitter);
368 // changing stored sizes
369 if (pSplitter == aSplitter.get())
370 {
371 // nSize
372 if (bLower)
373 nSize = pSplitter->GetSplitPosPixel();
374 else
375 nSize = (bVertical ? aRect.Right() : aRect.Bottom()) + 1 - pSplitter->GetSplitPosPixel();
376 }
377 else
378 {
379 // Item::nStartPos, Item::nLength
380 for (size_t i = 1; i < vItems.size(); ++i)
381 {
382 if (vItems[i].pSplit.get() == pSplitter)
383 {
384 // before the line
385 vItems[i - 1].nEndPos = pSplitter->GetSplitPosPixel();
386 // after the line
387 vItems[i].nStartPos = pSplitter->GetSplitPosPixel() + nSplitThickness;
388 }
389 }
390 }
391 // arranging windows
392 rLayout.ArrangeWindows();
393}
394
396{
397 // The splitter line cannot be closer to the edges than nMargin pixels.
398 static tools::Long const nMargin = 16;
399 // Checking margins:
400 tools::Long const nLength = pSplitter->IsHorizontal() ?
401 aRect.GetWidth() : aRect.GetHeight();
402 if (!nLength)
403 return;
404
405 // bounds
406 tools::Long const nLower = (pSplitter->IsHorizontal() ? aRect.Left() : aRect.Top()) + nMargin;
407 tools::Long const nUpper = nLower + nLength - 2*nMargin;
408 // split position
409 tools::Long const nPos = pSplitter->GetSplitPosPixel();
410 // checking bounds
411 if (nPos < nLower)
412 pSplitter->SetSplitPosPixel(nLower);
413 if (nPos > nUpper)
414 pSplitter->SetSplitPosPixel(nUpper);
415}
416
418{
419 // link
420 rSplitter.SetSplitHdl(LINK(this, SplittedSide, SplitHdl));
421 // color
422 Color aColor = rLayout.GetSettings().GetStyleSettings().GetShadowColor();
423 rSplitter.GetOutDev()->SetLineColor(aColor);
424 rSplitter.GetOutDev()->SetFillColor(aColor);
425}
426
427
428} // namespace basctl
429
430/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const StyleSettings & GetStyleSettings() const
DataChangedEventType GetType() const
AllSettingsFlags GetFlags() const
const AllSettings * GetOldSettings() const
bool IsFloatingMode() const
void SetLineColor()
void SetFillColor()
constexpr tools::Long Height() const
tools::Long AdjustHeight(tools::Long n)
tools::Long AdjustWidth(tools::Long n)
void setHeight(tools::Long nHeight)
constexpr tools::Long Width() const
bool IsHorizontal() const
void SetSplitHdl(const Link< Splitter *, void > &rLink)
void SetSplitPosPixel(tools::Long nPos)
tools::Long GetSplitPosPixel() const
void SetDragRectPixel(const tools::Rectangle &rDragRect, vcl::Window *pRefWin=nullptr)
const Color & GetWindowColor() const
const Color & GetWindowTextColor() const
static VclPtr< reference_type > Create(Arg &&... arg)
void ResizeIfDocking(Point const &, Size const &)
Definition: bastypes.cxx:346
void Add(DockingWindow *, Size const &)
Definition: layout.cxx:187
Point MakePoint(tools::Long, tools::Long) const
Definition: layout.cxx:236
tools::Long GetSize() const
Definition: layout.cxx:257
VclPtr< Splitter > aSplitter
Definition: layout.hxx:104
void Remove(DockingWindow *)
Definition: layout.cxx:212
static bool IsDocking(DockingWindow const &)
Definition: layout.cxx:242
void ArrangeIn(tools::Rectangle const &)
Definition: layout.cxx:264
void InitSplitter(Splitter &)
Definition: layout.cxx:417
SplittedSide(Layout *, Side)
Definition: layout.cxx:166
Size MakeSize(tools::Long, tools::Long) const
Definition: layout.cxx:232
void CheckMarginsFor(Splitter *)
Definition: layout.cxx:395
virtual void DataChanged(DataChangedEvent const &rDCEvt) override
Definition: layout.cxx:135
virtual void Resize() override
Definition: layout.cxx:76
class basctl::Layout::SplittedSide aLeftSide
virtual ~Layout() override
Definition: layout.cxx:55
void Remove(DockingWindow *)
Definition: layout.cxx:69
class basctl::Layout::SplittedSide aBottomSide
virtual void dispose() override
Definition: layout.cxx:60
Layout(vcl::Window *pParent)
Definition: layout.cxx:37
virtual void OnFirstSize(tools::Long nWidth, tools::Long nHeight)=0
VclPtr< BaseWindow > pChild
Definition: layout.hxx:70
virtual void Deactivating()
Definition: layout.cxx:126
virtual void Activating(BaseWindow &)
Definition: layout.cxx:117
bool bFirstSize
Definition: layout.hxx:73
void ArrangeWindows()
Definition: layout.cxx:83
void SetFontSize(const Size &)
void SetColor(const Color &)
void SetWeight(FontWeight)
const Size & GetFontSize() const
void SetFont(const vcl::Font &rNewFont)
const AllSettings & GetSettings() const
void Show(bool bVisible=true, ShowFlags nFlags=ShowFlags::NONE)
::OutputDevice const * GetOutDev() const
const vcl::Font & GetFont() const
Size GetOutputSizePixel() const
bool IsVisible() const
void Invalidate(InvalidateFlags nFlags=InvalidateFlags::NONE)
virtual void SetPosSizePixel(const Point &rNewPos, const Size &rNewSize)
void SetBackground()
WEIGHT_BOLD
sal_uInt16 nPos
IMPL_LINK(AccessibleDialogWindow, WindowEventListener, VclWindowEvent &, rEvent, void)
int i
void Create(SwFormatVertOrient &rItem, SvStream &rStrm, sal_uInt16 nVersionAbusedAsSize)
long Long
VclPtr< DockingWindow > pWin
Definition: layout.hxx:109
Left
WinBits const WB_VSCROLL
WinBits const WB_CLIPCHILDREN
WinBits const WB_HSCROLL
const sal_uInt8 A
sal_Int32 nLength