nss: upgrade to release 3.73
[LibreOffice.git] / sfx2 / source / notebookbar / DropdownBox.cxx
blob315c30a2f95dc1f1cb7bb13be405c0ef24c76acd
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/builderfactory.hxx>
21 #include <vcl/button.hxx>
22 #include <vcl/layout.hxx>
23 #include "DropdownBox.hxx"
25 #define NOTEBOOK_HEADER_HEIGHT 30
28 * DropdownBox - shows content or moves it to the popup
29 * which can be opened by clicking on a button
32 DropdownBox::DropdownBox(vcl::Window* pParent)
33 : VclHBox(pParent)
34 , IPrioritable()
35 , m_bInFullView(true)
37 m_pButton = VclPtr<PushButton>::Create(this, WB_FLATBUTTON);
38 m_pButton->SetClickHdl(LINK(this, DropdownBox, PBClickHdl));
39 m_pButton->SetSymbol(SymbolType::MENU);
40 m_pButton->set_width_request(15);
41 m_pButton->SetQuickHelpText(GetQuickHelpText());
42 m_pButton->Resize();
45 DropdownBox::~DropdownBox() { disposeOnce(); }
47 void DropdownBox::dispose()
49 m_pButton.disposeAndClear();
50 if (m_pPopup)
51 m_pPopup.disposeAndClear();
53 VclHBox::dispose();
56 void DropdownBox::HideContent()
58 if (m_bInFullView)
60 m_bInFullView = false;
62 for (int i = 0; i < GetChildCount(); i++)
63 GetChild(i)->Hide();
65 m_pButton->Show();
66 SetOutputSizePixel(Size(m_pButton->GetSizePixel().Width(), GetSizePixel().Height()));
70 bool DropdownBox::IsHidden() { return !m_bInFullView; }
72 void DropdownBox::ShowContent()
74 if (!m_bInFullView)
76 m_bInFullView = true;
78 for (int i = 0; i < GetChildCount(); i++)
79 GetChild(i)->Show();
81 m_pButton->Hide();
85 IMPL_LINK(DropdownBox, PBClickHdl, Button*, /*pButton*/, void)
87 if (m_pPopup)
88 m_pPopup.disposeAndClear();
90 m_pPopup = VclPtr<NotebookbarPopup>::Create(this);
92 for (int i = 0; i < GetChildCount(); i++)
94 if (GetChild(i) != m_pButton)
96 Window* pChild = GetChild(i);
97 pChild->Show();
99 pChild->SetParent(m_pPopup->getBox());
100 // count is decreased because we moved child
101 i--;
105 m_pPopup->hideSeparators(true);
107 m_pPopup->getBox()->set_height_request(GetSizePixel().Height());
109 tools::Long x = GetPosPixel().getX();
110 tools::Long y = GetPosPixel().getY() + NOTEBOOK_HEADER_HEIGHT + GetSizePixel().Height();
111 tools::Rectangle aRect(x, y, x, y);
113 m_pPopup->StartPopupMode(aRect, FloatWinPopupFlags::Down | FloatWinPopupFlags::GrabFocus
114 | FloatWinPopupFlags::AllMouseButtonClose);
117 VCL_BUILDER_FACTORY(DropdownBox)
119 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */