1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
)
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());
45 DropdownBox::~DropdownBox() { disposeOnce(); }
47 void DropdownBox::dispose()
49 m_pButton
.disposeAndClear();
51 m_pPopup
.disposeAndClear();
56 void DropdownBox::HideContent()
60 m_bInFullView
= false;
62 for (int i
= 0; i
< GetChildCount(); i
++)
66 SetOutputSizePixel(Size(m_pButton
->GetSizePixel().Width(), GetSizePixel().Height()));
70 bool DropdownBox::IsHidden() { return !m_bInFullView
; }
72 void DropdownBox::ShowContent()
78 for (int i
= 0; i
< GetChildCount(); i
++)
85 IMPL_LINK(DropdownBox
, PBClickHdl
, Button
*, /*pButton*/, void)
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
);
99 pChild
->SetParent(m_pPopup
->getBox());
100 // count is decreased because we moved child
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: */