Update git submodules
[LibreOffice.git] / vcl / source / control / DropdownBox.cxx
blob6aaf2e553ace43cdf7e86682df407aaa62c24a0f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <vcl/toolkit/button.hxx>
21 #include <vcl/layout.hxx>
22 #include <DropdownBox.hxx>
24 #define NOTEBOOK_HEADER_HEIGHT 30
27 * DropdownBox - shows content or moves it to the popup
28 * which can be opened by clicking on a button
31 DropdownBox::DropdownBox(vcl::Window* pParent)
32 : VclHBox(pParent)
33 , m_bInFullView(true)
35 m_pButton = VclPtr<PushButton>::Create(this, WB_FLATBUTTON);
36 m_pButton->SetClickHdl(LINK(this, DropdownBox, PBClickHdl));
37 m_pButton->SetSymbol(SymbolType::MENU);
38 m_pButton->set_width_request(15);
39 m_pButton->SetQuickHelpText(GetQuickHelpText());
40 m_pButton->Resize();
43 DropdownBox::~DropdownBox() { disposeOnce(); }
45 void DropdownBox::dispose()
47 m_pButton.disposeAndClear();
48 if (m_pPopup)
49 m_pPopup.disposeAndClear();
51 VclHBox::dispose();
54 void DropdownBox::HideContent()
56 if (m_bInFullView)
58 m_bInFullView = false;
60 for (int i = 0; i < GetChildCount(); i++)
61 GetChild(i)->Hide();
63 m_pButton->Show();
64 SetOutputSizePixel(Size(m_pButton->GetSizePixel().Width(), GetSizePixel().Height()));
68 bool DropdownBox::IsHidden() { return !m_bInFullView; }
70 void DropdownBox::ShowContent()
72 if (!m_bInFullView)
74 m_bInFullView = true;
76 for (int i = 0; i < GetChildCount(); i++)
77 GetChild(i)->Show();
79 m_pButton->Hide();
83 IMPL_LINK(DropdownBox, PBClickHdl, Button*, /*pButton*/, void)
85 if (m_pPopup)
86 m_pPopup.disposeAndClear();
88 m_pPopup = VclPtr<NotebookbarPopup>::Create(this);
90 for (int i = 0; i < GetChildCount(); i++)
92 if (GetChild(i) != m_pButton)
94 Window* pChild = GetChild(i);
95 pChild->Show();
97 pChild->SetParent(m_pPopup->getBox());
98 // count is decreased because we moved child
99 i--;
103 m_pPopup->hideSeparators(true);
105 m_pPopup->getBox()->set_height_request(GetSizePixel().Height());
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);
111 m_pPopup->StartPopupMode(aRect, FloatWinPopupFlags::Down | FloatWinPopupFlags::GrabFocus
112 | FloatWinPopupFlags::AllMouseButtonClose);
115 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */