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  , IPrioritable()
34  , m_bInFullView(true)
35 {
37  m_pButton->SetClickHdl(LINK(this, DropdownBox, PBClickHdl));
41  m_pButton->Resize();
42 }
43 
45 
47 {
49  if (m_pPopup)
51 
53 }
54 
56 {
57  if (m_bInFullView)
58  {
59  m_bInFullView = false;
60 
61  for (int i = 0; i < GetChildCount(); i++)
62  GetChild(i)->Hide();
63 
64  m_pButton->Show();
66  }
67 }
68 
70 
72 {
73  if (!m_bInFullView)
74  {
75  m_bInFullView = true;
76 
77  for (int i = 0; i < GetChildCount(); i++)
78  GetChild(i)->Show();
79 
80  m_pButton->Hide();
81  }
82 }
83 
84 IMPL_LINK(DropdownBox, PBClickHdl, Button*, /*pButton*/, void)
85 {
86  if (m_pPopup)
87  m_pPopup.disposeAndClear();
88 
89  m_pPopup = VclPtr<NotebookbarPopup>::Create(this);
90 
91  for (int i = 0; i < GetChildCount(); i++)
92  {
93  if (GetChild(i) != m_pButton)
94  {
95  Window* pChild = GetChild(i);
96  pChild->Show();
97 
98  pChild->SetParent(m_pPopup->getBox());
99  // count is decreased because we moved child
100  i--;
101  }
102  }
103 
104  m_pPopup->hideSeparators(true);
105 
106  m_pPopup->getBox()->set_height_request(GetSizePixel().Height());
107 
108  tools::Long x = GetPosPixel().getX();
109  tools::Long y = GetPosPixel().getY() + NOTEBOOK_HEADER_HEIGHT + GetSizePixel().Height();
110  tools::Rectangle aRect(x, y, x, y);
111 
112  m_pPopup->StartPopupMode(aRect, FloatWinPopupFlags::Down | FloatWinPopupFlags::GrabFocus
114 }
115 
116 /* 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:1230
virtual Size GetSizePixel() const
Definition: window.cxx:2393
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
Definition: window.cxx:147
float x
void SetQuickHelpText(const OUString &rHelpText)
Definition: window2.cxx:1224
void SetSymbol(SymbolType eSymbol)
Definition: button.cxx:1514
void Hide()
Definition: window.hxx:948
virtual void SetOutputSizePixel(const Size &rNewSize)
Definition: window2.cxx:1272
void set_width_request(sal_Int32 nWidthRequest)
Definition: window2.cxx:1623
float y
int i
virtual void Resize() override
Definition: button.cxx:1366
tools::Long Width() const
void ShowContent() override
Definition: DropdownBox.cxx:71
VclPtr< PushButton > m_pButton
Definition: DropdownBox.hxx:31
bool IsHidden() override
Definition: DropdownBox.cxx:69
sal_uInt16 GetChildCount() const
Definition: stacking.cxx:1001
void HideContent() override
Definition: DropdownBox.cxx:55
static VclPtr< reference_type > Create(Arg &&...arg)
A construction helper for VclPtr.
Definition: vclptr.hxx:127
tools::Long Height() const
WinBits const WB_FLATBUTTON
virtual ~DropdownBox() override
Definition: DropdownBox.cxx:44
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:46
vcl::Window * GetChild(sal_uInt16 nChild) const
Definition: stacking.cxx:1017
void Show(bool bVisible=true, ShowFlags nFlags=ShowFlags::NONE)
Definition: window.cxx:2179