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}
46
48{
49 OUString sSelection = rBox.get_selected_text();
50 if (sSelection == SwResId(STR_DROP_DOWN_EMPTY_LIST))
51 {
52 m_xPopup->popdown();
53 return true;
54 }
55
56 sal_Int32 nSelection = rBox.get_selected_index();
57 m_xPopup->popdown();
58 if (nSelection >= 0)
59 {
60 SwView& rView = static_cast<SwEditWin*>(GetParent())->GetView();
61 SwWrtShell& rWrtShell = rView.GetWrtShell();
62 m_pContentControl->SetSelectedListItem(nSelection);
63 rWrtShell.GotoContentControl(*m_pContentControl->GetFormatContentControl());
64 }
65
66 return true;
67}
68
70 SwEditWin* pEditWin, const std::shared_ptr<SwContentControl>& pContentControl)
71 : SwContentControlButton(pEditWin, pContentControl)
72{
73}
74
76
78{
80 "modules/swriter/ui/contentcontroldropdown.ui");
81 m_xPopup = m_xPopupBuilder->weld_popover("ContentControlDropDown");
82 m_xTreeView = m_xPopupBuilder->weld_tree_view("list");
84 m_xTreeView->connect_row_activated(LINK(this, SwDropDownContentControlButton, ListBoxHandler));
86 m_xTreeView->grab_focus();
87}
88
90{
91 m_xTreeView.reset();
93}
94
95/* 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:412
Used by the UI to modify the document model.
Definition: wrtsh.hxx:97
bool GotoContentControl(const SwFormatContentControl &rContentControl)
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:164