LibreOffice Module vcl (master)  1
DropdownBox.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 <vcl/toolkit/button.hxx>
21 #include <vcl/layout.hxx>
22 #include <DropdownBox.hxx>
23 
24 #define NOTEBOOK_HEADER_HEIGHT 30
25 
26 /*
27  * DropdownBox - shows content or moves it to the popup
28  * which can be opened by clicking on a button
29  */
30 
32  : VclHBox(pParent)
33  , m_bInFullView(true)
34 {
36  m_pButton->SetClickHdl(LINK(this, DropdownBox, PBClickHdl));
40  m_pButton->Resize();
41 }
42 
44 
46 {
48  if (m_pPopup)
50 
52 }
53 
55 {
56  if (m_bInFullView)
57  {
58  m_bInFullView = false;
59 
60  for (int i = 0; i < GetChildCount(); i++)
61  GetChild(i)->Hide();
62 
63  m_pButton->Show();
65  }
66 }
67 
69 
71 {
72  if (!m_bInFullView)
73  {
74  m_bInFullView = true;
75 
76  for (int i = 0; i < GetChildCount(); i++)
77  GetChild(i)->Show();
78 
79  m_pButton->Hide();
80  }
81 }
82 
83 IMPL_LINK(DropdownBox, PBClickHdl, Button*, /*pButton*/, void)
84 {
85  if (m_pPopup)
86  m_pPopup.disposeAndClear();
87 
88  m_pPopup = VclPtr<NotebookbarPopup>::Create(this);
89 
90  for (int i = 0; i < GetChildCount(); i++)
91  {
92  if (GetChild(i) != m_pButton)
93  {
94  Window* pChild = GetChild(i);
95  pChild->Show();
96 
97  pChild->SetParent(m_pPopup->getBox());
98  // count is decreased because we moved child
99  i--;
100  }
101  }
102 
103  m_pPopup->hideSeparators(true);
104 
105  m_pPopup->getBox()->set_height_request(GetSizePixel().Height());
106 
107  tools::Long x = GetPosPixel().getX();
108  tools::Long y = GetPosPixel().getY() + NOTEBOOK_HEADER_HEIGHT + GetSizePixel().Height();
109  tools::Rectangle aRect(x, y, x, y);
110 
111  m_pPopup->StartPopupMode(aRect, FloatWinPopupFlags::Down | FloatWinPopupFlags::GrabFocus
113 }
114 
115 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetClickHdl(const Link< Button *, void > &rLink)
Definition: button.hxx:79
long Long
void disposeAndClear()
Definition: vclptr.hxx:200
const OUString & GetQuickHelpText() const
Definition: window2.cxx:1226
virtual Size GetSizePixel() const
Definition: window.cxx:2392
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
Definition: window.cxx:137
float x
void SetQuickHelpText(const OUString &rHelpText)
Definition: window2.cxx:1220
constexpr tools::Long Width() const
void SetSymbol(SymbolType eSymbol)
Definition: button.cxx:1548
void Hide()
Definition: window.hxx:884
virtual void SetOutputSizePixel(const Size &rNewSize)
Definition: window2.cxx:1268
void set_width_request(sal_Int32 nWidthRequest)
Definition: window2.cxx:1619
float y
int i
virtual void Resize() override
Definition: button.cxx:1400
void ShowContent() override
Definition: DropdownBox.cxx:70
VclPtr< PushButton > m_pButton
Definition: DropdownBox.hxx:31
bool IsHidden() override
Definition: DropdownBox.cxx:68
sal_uInt16 GetChildCount() const
Definition: stacking.cxx:1001
constexpr tools::Long Height() const
void HideContent() override
Definition: DropdownBox.cxx:54
static VclPtr< reference_type > Create(Arg &&...arg)
A construction helper for VclPtr.
Definition: vclptr.hxx:127
WinBits const WB_FLATBUTTON
virtual ~DropdownBox() override
Definition: DropdownBox.cxx:43
bool m_bInFullView
Definition: DropdownBox.hxx:30
VclPtr< NotebookbarPopup > m_pPopup
Definition: DropdownBox.hxx:32
DropdownBox(vcl::Window *pParent)
Definition: DropdownBox.cxx:31
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
Definition: DropdownBox.cxx:45
vcl::Window * GetChild(sal_uInt16 nChild) const
Definition: stacking.cxx:1017
void Show(bool bVisible=true, ShowFlags nFlags=ShowFlags::NONE)
Definition: window.cxx:2177