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/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
)
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());
43 DropdownBox::~DropdownBox() { disposeOnce(); }
45 void DropdownBox::dispose()
47 m_pButton
.disposeAndClear();
49 m_pPopup
.disposeAndClear();
54 void DropdownBox::HideContent()
58 m_bInFullView
= false;
60 for (int i
= 0; i
< GetChildCount(); i
++)
64 SetOutputSizePixel(Size(m_pButton
->GetSizePixel().Width(), GetSizePixel().Height()));
68 bool DropdownBox::IsHidden() { return !m_bInFullView
; }
70 void DropdownBox::ShowContent()
76 for (int i
= 0; i
< GetChildCount(); i
++)
83 IMPL_LINK(DropdownBox
, PBClickHdl
, Button
*, /*pButton*/, void)
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
);
97 pChild
->SetParent(m_pPopup
->getBox());
98 // count is decreased because we moved child
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: */