/src/libreoffice/vcl/source/control/DropdownBox.cxx
Line | Count | Source |
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 | 0 | #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 | | |
31 | | DropdownBox::DropdownBox(vcl::Window* pParent) |
32 | 0 | : VclHBox(pParent) |
33 | 0 | , m_bInFullView(true) |
34 | 0 | { |
35 | 0 | m_pButton = VclPtr<PushButton>::Create(this, WB_FLATBUTTON); |
36 | 0 | m_pButton->SetClickHdl(LINK(this, DropdownBox, PBClickHdl)); |
37 | 0 | m_pButton->SetSymbol(SymbolType::MENU); |
38 | 0 | m_pButton->set_width_request(15); |
39 | 0 | m_pButton->SetQuickHelpText(GetQuickHelpText()); |
40 | 0 | m_pButton->Resize(); |
41 | 0 | } Unexecuted instantiation: DropdownBox::DropdownBox(vcl::Window*) Unexecuted instantiation: DropdownBox::DropdownBox(vcl::Window*) |
42 | | |
43 | 0 | DropdownBox::~DropdownBox() { disposeOnce(); } |
44 | | |
45 | | void DropdownBox::dispose() |
46 | 0 | { |
47 | 0 | m_pButton.disposeAndClear(); |
48 | 0 | if (m_pPopup) |
49 | 0 | m_pPopup.disposeAndClear(); |
50 | |
|
51 | 0 | VclHBox::dispose(); |
52 | 0 | } |
53 | | |
54 | | void DropdownBox::HideContent() |
55 | 0 | { |
56 | 0 | if (m_bInFullView) |
57 | 0 | { |
58 | 0 | m_bInFullView = false; |
59 | |
|
60 | 0 | for (int i = 0; i < GetChildCount(); i++) |
61 | 0 | GetChild(i)->Hide(); |
62 | |
|
63 | 0 | m_pButton->Show(); |
64 | 0 | SetOutputSizePixel(Size(m_pButton->GetSizePixel().Width(), GetSizePixel().Height())); |
65 | 0 | } |
66 | 0 | } |
67 | | |
68 | | void DropdownBox::ShowContent() |
69 | 0 | { |
70 | 0 | if (!m_bInFullView) |
71 | 0 | { |
72 | 0 | m_bInFullView = true; |
73 | |
|
74 | 0 | for (int i = 0; i < GetChildCount(); i++) |
75 | 0 | GetChild(i)->Show(); |
76 | |
|
77 | 0 | m_pButton->Hide(); |
78 | 0 | } |
79 | 0 | } |
80 | | |
81 | | IMPL_LINK(DropdownBox, PBClickHdl, Button*, /*pButton*/, void) |
82 | 0 | { |
83 | 0 | if (m_pPopup) |
84 | 0 | m_pPopup.disposeAndClear(); |
85 | |
|
86 | 0 | m_pPopup = VclPtr<NotebookbarPopup>::Create(this); |
87 | |
|
88 | 0 | for (int i = 0; i < GetChildCount(); i++) |
89 | 0 | { |
90 | 0 | if (GetChild(i) != m_pButton) |
91 | 0 | { |
92 | 0 | Window* pChild = GetChild(i); |
93 | 0 | pChild->Show(); |
94 | |
|
95 | 0 | pChild->SetParent(m_pPopup->getBox()); |
96 | | // count is decreased because we moved child |
97 | 0 | i--; |
98 | 0 | } |
99 | 0 | } |
100 | |
|
101 | 0 | m_pPopup->hideSeparators(true); |
102 | |
|
103 | 0 | m_pPopup->getBox()->set_height_request(GetSizePixel().Height()); |
104 | |
|
105 | 0 | tools::Long x = GetPosPixel().getX(); |
106 | 0 | tools::Long y = GetPosPixel().getY() + NOTEBOOK_HEADER_HEIGHT + GetSizePixel().Height(); |
107 | 0 | tools::Rectangle aRect(x, y, x, y); |
108 | |
|
109 | 0 | m_pPopup->StartPopupMode(aRect, FloatWinPopupFlags::Down | FloatWinPopupFlags::GrabFocus |
110 | 0 | | FloatWinPopupFlags::AllMouseButtonClose); |
111 | 0 | } |
112 | | |
113 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |