LibreOffice Module vcl (master) 1
PriorityMergedHBox.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
21#include <vcl/layout.hxx>
22#include <bitmaps.hlst>
23#include <NotebookbarPopup.hxx>
24#include <PriorityHBox.hxx>
26#include <comphelper/lok.hxx>
27
28#define DUMMY_WIDTH 50
29#define BUTTON_WIDTH 30
30
31/*
32* PriorityMergedHBox is a VclHBox which hides its own children if there is no sufficient space.
33*/
34
36 : PriorityHBox(pParent)
37{
39 m_pButton->SetClickHdl(LINK(this, PriorityMergedHBox, PBClickHdl));
43 m_pButton->Show();
44}
45
47{
49 return VclHBox::Resize();
50
51 if (!m_bInitialized)
52 Initialize();
53
54 if (!m_bInitialized)
55 {
56 return VclHBox::Resize();
57 }
58
59 tools::Long nWidth = GetSizePixel().Width();
61
62 // Hide lower priority controls
63 for (int i = GetChildCount() - 1; i >= 0; i--)
64 {
65 vcl::Window* pWindow = GetChild(i);
66
67 if (nCurrentWidth <= nWidth)
68 break;
69
70 if (pWindow && pWindow->GetParent() == this && pWindow->IsVisible())
71 {
72 if (pWindow->GetOutputSizePixel().Width())
73 nCurrentWidth -= pWindow->GetOutputSizePixel().Width();
74 else
75 nCurrentWidth -= DUMMY_WIDTH;
76 pWindow->Hide();
77 }
78 }
79
80 // Show higher priority controls if we already have enough space
81 for (int i = 0; i < GetChildCount(); i++)
82 {
83 vcl::Window* pWindow = GetChild(i);
84
85 if (pWindow->GetParent() != this)
86 {
87 continue;
88 }
89
90 if (pWindow && !pWindow->IsVisible())
91 {
92 pWindow->Show();
93 nCurrentWidth += getLayoutRequisition(*pWindow).Width() + get_spacing();
94
95 if (nCurrentWidth > nWidth)
96 {
97 pWindow->Hide();
98 break;
99 }
100 }
101 }
102
104
105 if (GetHiddenCount())
106 m_pButton->Show();
107 else
108 m_pButton->Hide();
109}
110
112{
114 if (m_pPopup)
117}
118
120{
121 int nCount = 0;
122
123 for (int i = GetChildCount() - 1; i >= 0; i--)
124 {
125 vcl::Window* pWindow = GetChild(i);
126 if (pWindow && pWindow->GetParent() == this && !pWindow->IsVisible())
127 nCount++;
128 }
129
130 return nCount;
131}
132
134{
135 if (!m_bInitialized)
136 {
138 }
139
140 sal_uInt16 nVisibleChildren = 0;
141
142 Size aSize;
143 for (vcl::Window* pChild = GetWindow(GetWindowType::FirstChild); pChild;
144 pChild = pChild->GetWindow(GetWindowType::Next))
145 {
146 if (!pChild->IsVisible())
147 continue;
148 ++nVisibleChildren;
149 Size aChildSize = getLayoutRequisition(*pChild);
150
151 tools::Long nPrimaryDimension = getPrimaryDimension(aChildSize);
152 nPrimaryDimension += pChild->get_padding() * 2;
153 setPrimaryDimension(aChildSize, nPrimaryDimension);
154
155 accumulateMaxes(aChildSize, aSize);
156 }
157
158 // find max height
159 for (vcl::Window* pChild = GetWindow(GetWindowType::FirstChild); pChild;
160 pChild = pChild->GetWindow(GetWindowType::Next))
161 {
162 Size aChildSize = getLayoutRequisition(*pChild);
163 setPrimaryDimension(aChildSize, getPrimaryDimension(aSize));
164 accumulateMaxes(aChildSize, aSize);
165 }
166
167 setPrimaryDimension(aSize, 200);
168 return finalizeMaxes(aSize, nVisibleChildren);
169}
170
171IMPL_LINK(PriorityMergedHBox, PBClickHdl, Button*, /*pButton*/, void)
172{
173 if (m_pPopup)
174 m_pPopup.disposeAndClear();
175
176 m_pPopup = VclPtr<NotebookbarPopup>::Create(this);
177
178 for (int i = 0; i < GetChildCount(); i++)
179 {
180 vcl::Window* pWindow = GetChild(i);
181 if (pWindow != m_pButton)
182 {
183 if (!pWindow->IsVisible())
184 {
185 pWindow->Show();
186 pWindow->SetParent(m_pPopup->getBox());
187 // count is decreased because we moved child
188 i--;
189 }
190 }
191 }
192
193 m_pPopup->hideSeparators(true);
194
195 tools::Long x = m_pButton->GetPosPixel().getX();
196 tools::Long y = m_pButton->GetPosPixel().getY() + GetSizePixel().Height();
197 tools::Rectangle aRect(x, y, x, y);
198
199 m_pPopup->StartPopupMode(aRect, FloatWinPopupFlags::Down | FloatWinPopupFlags::GrabFocus
201}
202
203/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define DUMMY_WIDTH
IMPL_LINK(PriorityMergedHBox, PBClickHdl, Button *,, void)
#define BUTTON_WIDTH
void SetClickHdl(const Link< Button *, void > &rLink)
Definition: button.hxx:79
void SetModeImage(const Image &rImage)
Definition: button.cxx:133
Definition: image.hxx:40
void Initialize()
Size calculateRequisition() const override
VclPtr< PushButton > m_pButton
int GetHiddenCount() const override
virtual void Resize() override
VclPtr< NotebookbarPopup > m_pPopup
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects.
PriorityMergedHBox(vcl::Window *pParent)
constexpr tools::Long getWidth() const
constexpr tools::Long Width() const
Size finalizeMaxes(const Size &rSize, sal_uInt16 nVisibleChildren) const
Definition: layout.cxx:416
void accumulateMaxes(const Size &rChildSize, Size &rSize) const
Definition: layout.cxx:237
int get_spacing() const
Definition: layout.hxx:88
virtual Size calculateRequisition() const override
Definition: layout.cxx:251
static Size getLayoutRequisition(const vcl::Window &rWindow)
Definition: layout.cxx:170
virtual tools::Long getPrimaryDimension(const Size &rSize) const override
Definition: layout.hxx:168
virtual void setPrimaryDimension(Size &rSize, tools::Long nWidth) const override
Definition: layout.hxx:172
void disposeAndClear()
Definition: vclptr.hxx:200
static VclPtr< reference_type > Create(Arg &&... arg)
A construction helper for VclPtr.
Definition: vclptr.hxx:127
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects.
Definition: window.cxx:140
vcl::Window * GetParent() const
Definition: window2.cxx:1136
sal_uInt16 GetChildCount() const
Definition: stacking.cxx:1001
virtual void Resize()
Definition: window.cxx:1839
vcl::Window * GetWindow(GetWindowType nType) const
Definition: stacking.cxx:1035
void SetParent(vcl::Window *pNewParent)
Definition: stacking.cxx:831
void Show(bool bVisible=true, ShowFlags nFlags=ShowFlags::NONE)
Definition: window.cxx:2191
void set_pack_type(VclPackType ePackType)
Definition: window2.cxx:1804
void Hide()
Definition: window.hxx:885
void set_width_request(sal_Int32 nWidthRequest)
Definition: window2.cxx:1671
virtual Size GetSizePixel() const
Definition: window.cxx:2406
Size GetOutputSizePixel() const
Definition: window3.cxx:89
bool IsVisible() const
Definition: window2.cxx:1141
vcl::Window * GetChild(sal_uInt16 nChild) const
Definition: stacking.cxx:1017
int nCount
float y
float x
int i
long Long
WinBits const WB_FLATBUTTON
Definition: wintypes.hxx:186