LibreOffice Module sw (master) 1
dropdowncontentcontrolbutton.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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
11
12#include <vcl/settings.hxx>
13#include <vcl/svapp.hxx>
14
15#include <edtwin.hxx>
16#include <view.hxx>
17#include <strings.hrc>
19#include <wrtsh.hxx>
20
22{
23 std::vector<SwContentControlListItem> aListItems = m_pContentControl->GetListItems();
24
25 for (const auto& rListItem : aListItems)
26 {
27 m_xTreeView->append_text(rListItem.ToString());
28 }
29
30 if (aListItems.empty())
31 {
32 m_xTreeView->append_text(SwResId(STR_DROP_DOWN_EMPTY_LIST));
33 }
34
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());
40 aSize.AdjustWidth(4);
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);
46}
47
49{
50 OUString sSelection = rBox.get_selected_text();
51 if (sSelection == SwResId(STR_DROP_DOWN_EMPTY_LIST))
52 {
53 m_xPopup->popdown();
54 return true;
55 }
56
57 sal_Int32 nSelection = rBox.get_selected_index();
58 m_xPopup->popdown();
59 if (nSelection >= 0)
60 {
61 SwView& rView = static_cast<SwEditWin*>(GetParent())->GetView();
62 SwWrtShell& rWrtShell = rView.GetWrtShell();
63 m_pContentControl->SetSelectedListItem(nSelection);
64 rWrtShell.GotoContentControl(*m_pContentControl->GetFormatContentControl());
65 }
66
67 return true;
68}
69
71 SwEditWin* pEditWin, const std::shared_ptr<SwContentControl>& pContentControl)
72 : SwContentControlButton(pEditWin, pContentControl)
73{
74}
75
77
79{
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));
87 m_xTreeView->grab_focus();
88}
89
91{
92 m_xTreeView.reset();
94}
95
96/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static const AllSettings & GetSettings()
static std::unique_ptr< weld::Builder > CreateBuilder(weld::Widget *pParent, const OUString &rUIFile, bool bMobile=false, sal_uInt64 nLOKWindowId=0)
constexpr tools::Long Height() const
tools::Long AdjustHeight(tools::Long n)
void setWidth(tools::Long nWidth)
tools::Long AdjustWidth(tools::Long n)
constexpr tools::Long Width() const
This button is shown when the cursor is inside a content control with drop-down capability.
std::shared_ptr< SwContentControl > m_pContentControl
std::unique_ptr< weld::Builder > m_xPopupBuilder
std::unique_ptr< weld::Popover > m_xPopup
This button is shown when the cursor is inside a drop-down content control.
std::unique_ptr< weld::TreeView > m_xTreeView
SwDropDownContentControlButton(SwEditWin *pEditWin, const std::shared_ptr< SwContentControl > &pContentControl)
Window class for the Writer edit area, this is the one handling mouse and keyboard events and doing t...
Definition: edtwin.hxx:61
Definition: view.hxx:146
SwWrtShell & GetWrtShell() const
Definition: view.hxx:423
Used by the UI to modify the document model.
Definition: wrtsh.hxx:97
bool GotoContentControl(const SwFormatContentControl &rContentControl, bool bOnlyRefresh=false)
Definition: wrtsh3.cxx:96
virtual Size GetSizePixel() const
weld::Window * GetFrameWeld() const
IMPL_LINK(SwDropDownContentControlButton, ListBoxHandler, weld::TreeView &, rBox, bool)
long Long
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:168