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#define TEMP_WIDTH 200
31
32/*
33* PriorityMergedHBox is a VclHBox which hides its own children if there is no sufficient space.
34*/
35
37 : PriorityHBox(pParent)
38{
40 m_pButton->SetClickHdl(LINK(this, PriorityMergedHBox, PBClickHdl));
44 m_pButton->Show();
45}
46
48{
50 return VclHBox::Resize();
51
52 if (!m_bInitialized)
53 Initialize();
54
55 if (!m_bInitialized)
56 {
57 return VclHBox::Resize();
58 }
59
60 tools::Long nWidth = GetSizePixel().Width();
61 if (nWidth <= 1 || nWidth == TEMP_WIDTH || nWidth == TEMP_WIDTH + 6)
62 return VclHBox::Resize();
63
65
66 // Hide lower priority controls
67 for (int i = GetChildCount() - 1; i >= 0; i--)
68 {
69 vcl::Window* pWindow = GetChild(i);
70
71 if (nCurrentWidth <= nWidth)
72 break;
73
74 if (pWindow && pWindow->GetParent() == this && pWindow->IsVisible())
75 {
76 if (pWindow->GetOutputSizePixel().Width())
77 nCurrentWidth -= pWindow->GetOutputSizePixel().Width();
78 else
79 nCurrentWidth -= DUMMY_WIDTH;
80 pWindow->Hide();
81 }
82 }
83
84 // Show higher priority controls if we already have enough space
85 for (int i = 0; i < GetChildCount(); i++)
86 {
87 vcl::Window* pWindow = GetChild(i);
88
89 if (pWindow->GetParent() != this)
90 {
91 continue;
92 }
93
94 if (pWindow && !pWindow->IsVisible())
95 {
96 pWindow->Show();
97 nCurrentWidth += getLayoutRequisition(*pWindow).Width() + get_spacing();
98
99 if (nCurrentWidth > nWidth)
100 {
101 pWindow->Hide();
102 break;
103 }
104 }
105 }
106
108
109 if (GetHiddenCount())
110 m_pButton->Show();
111 else
112 m_pButton->Hide();
113}
114
116{
118 if (m_pPopup)
121}
122
124{
125 int nCount = 0;
126
127 for (int i = GetChildCount() - 1; i >= 0; i--)
128 {
129 vcl::Window* pWindow = GetChild(i);
130 if (pWindow && pWindow->GetParent() == this && !pWindow->IsVisible())
131 nCount++;
132 }
133
134 return nCount;
135}
136
138{
139 if (!m_bInitialized)
140 {
142 }
143
144 sal_uInt16 nVisibleChildren = 0;
145
146 Size aSize;
147 for (vcl::Window* pChild = GetWindow(GetWindowType::FirstChild); pChild;
148 pChild = pChild->GetWindow(GetWindowType::Next))
149 {
150 if (!pChild->IsVisible())
151 continue;
152 ++nVisibleChildren;
153 Size aChildSize = getLayoutRequisition(*pChild);
154
155 tools::Long nPrimaryDimension = getPrimaryDimension(aChildSize);
156 nPrimaryDimension += pChild->get_padding() * 2;
157 setPrimaryDimension(aChildSize, nPrimaryDimension);
158
159 accumulateMaxes(aChildSize, aSize);
160 }
161
163 return finalizeMaxes(aSize, nVisibleChildren);
164}
165
166IMPL_LINK(PriorityMergedHBox, PBClickHdl, Button*, /*pButton*/, void)
167{
168 if (m_pPopup)
169 m_pPopup.disposeAndClear();
170
171 m_pPopup = VclPtr<NotebookbarPopup>::Create(this);
172
173 for (int i = 0; i < GetChildCount(); i++)
174 {
175 vcl::Window* pWindow = GetChild(i);
176 if (pWindow != m_pButton)
177 {
178 if (!pWindow->IsVisible())
179 {
180 pWindow->Show();
181 pWindow->SetParent(m_pPopup->getBox());
182 // count is decreased because we moved child
183 i--;
184 }
185 }
186 }
187
188 m_pPopup->hideSeparators(true);
189
190 tools::Long x = m_pButton->GetPosPixel().getX();
191 tools::Long y = m_pButton->GetPosPixel().getY() + GetSizePixel().Height();
192 tools::Rectangle aRect(x, y, x, y);
193
194 m_pPopup->StartPopupMode(aRect, FloatWinPopupFlags::Down | FloatWinPopupFlags::GrabFocus
196}
197
198/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
#define DUMMY_WIDTH
IMPL_LINK(PriorityMergedHBox, PBClickHdl, Button *,, void)
#define TEMP_WIDTH
#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:1128
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:1796
void Hide()
Definition: window.hxx:885
void set_width_request(sal_Int32 nWidthRequest)
Definition: window2.cxx:1663
virtual Size GetSizePixel() const
Definition: window.cxx:2406
Size GetOutputSizePixel() const
Definition: window3.cxx:89
bool IsVisible() const
Definition: window2.cxx:1133
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