1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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/.
10 #include <dropdowncontentcontrolbutton.hxx>
12 #include <vcl/settings.hxx>
13 #include <vcl/svapp.hxx>
17 #include <strings.hrc>
18 #include <formatcontentcontrol.hxx>
21 void SwDropDownContentControlButton::InitDropdown()
23 std::vector
<SwContentControlListItem
> aListItems
= m_pContentControl
->GetListItems();
25 for (const auto& rListItem
: aListItems
)
27 m_xTreeView
->append_text(rListItem
.ToString());
30 if (aListItems
.empty())
32 m_xTreeView
->append_text(SwResId(STR_DROP_DOWN_EMPTY_LIST
));
35 int nHeight
= m_xTreeView
->get_height_rows(
36 std::min
<int>(Application::GetSettings().GetStyleSettings().GetListBoxMaximumLineCount(),
37 m_xTreeView
->n_children()));
38 m_xTreeView
->set_size_request(-1, nHeight
);
39 Size
aSize(m_xTreeView
->get_preferred_size());
41 aSize
.AdjustHeight(4);
42 tools::Long nMinListWidth
= GetSizePixel().Width();
43 aSize
.setWidth(std::max(aSize
.Width(), nMinListWidth
));
44 m_xTreeView
->set_size_request(aSize
.Width(), aSize
.Height());
45 m_xTreeView
->set_direction(m_bRTL
);
48 IMPL_LINK(SwDropDownContentControlButton
, ListBoxHandler
, weld::TreeView
&, rBox
, bool)
50 OUString sSelection
= rBox
.get_selected_text();
51 if (sSelection
== SwResId(STR_DROP_DOWN_EMPTY_LIST
))
57 sal_Int32 nSelection
= rBox
.get_selected_index();
61 SwView
& rView
= static_cast<SwEditWin
*>(GetParent())->GetView();
62 SwWrtShell
& rWrtShell
= rView
.GetWrtShell();
63 m_pContentControl
->SetSelectedListItem(nSelection
);
64 rWrtShell
.GotoContentControl(*m_pContentControl
->GetFormatContentControl());
70 SwDropDownContentControlButton::SwDropDownContentControlButton(
71 SwEditWin
* pEditWin
, const std::shared_ptr
<SwContentControl
>& pContentControl
)
72 : SwContentControlButton(pEditWin
, pContentControl
)
76 SwDropDownContentControlButton::~SwDropDownContentControlButton() { disposeOnce(); }
78 void SwDropDownContentControlButton::LaunchPopup()
80 m_xPopupBuilder
= Application::CreateBuilder(GetFrameWeld(),
81 "modules/swriter/ui/contentcontroldropdown.ui");
82 m_xPopup
= m_xPopupBuilder
->weld_popover("ContentControlDropDown");
83 m_xTreeView
= m_xPopupBuilder
->weld_tree_view("list");
85 m_xTreeView
->connect_row_activated(LINK(this, SwDropDownContentControlButton
, ListBoxHandler
));
86 SwContentControlButton::LaunchPopup();
87 m_xTreeView
->grab_focus();
90 void SwDropDownContentControlButton::DestroyPopup()
93 SwContentControlButton::DestroyPopup();
96 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */