LibreOffice Module sw (master) 1
DropDownFormFieldButton.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#include <edtwin.hxx>
12#include <bookmark.hxx>
13#include <vcl/settings.hxx>
14#include <vcl/svapp.hxx>
15#include <xmloff/odffields.hxx>
16#include <IMark.hxx>
17#include <view.hxx>
18#include <docsh.hxx>
19#include <strings.hrc>
20
27{
29
30 sw::mark::IFieldmark::parameter_map_t::const_iterator pListEntries
31 = pParameters->find(ODF_FORMDROPDOWN_LISTENTRY);
32 css::uno::Sequence<OUString> vListEntries;
33 if (pListEntries != pParameters->end())
34 {
35 pListEntries->second >>= vListEntries;
36 for (OUString const& i : std::as_const(vListEntries))
37 m_xTreeView->append_text(i);
38 }
39
40 if (!vListEntries.hasElements())
41 {
42 m_xTreeView->append_text(SwResId(STR_DROP_DOWN_EMPTY_LIST));
43 }
44
45 // Select the current one
46 sw::mark::IFieldmark::parameter_map_t::const_iterator pResult
47 = pParameters->find(ODF_FORMDROPDOWN_RESULT);
48 if (pResult != pParameters->end())
49 {
50 sal_Int32 nSelection = -1;
51 pResult->second >>= nSelection;
52 m_xTreeView->set_cursor(nSelection);
53 m_xTreeView->select(nSelection);
54 }
55
56 auto nHeight = m_xTreeView->get_height_rows(
57 std::min<int>(Application::GetSettings().GetStyleSettings().GetListBoxMaximumLineCount(),
58 m_xTreeView->n_children()));
59 m_xTreeView->set_size_request(-1, nHeight);
60 Size lbSize(m_xTreeView->get_preferred_size());
61 lbSize.AdjustWidth(4);
62 lbSize.AdjustHeight(4);
63 auto nMinListWidth = GetSizePixel().Width();
64 lbSize.setWidth(std::max(lbSize.Width(), nMinListWidth));
65 m_xTreeView->set_size_request(lbSize.Width(), lbSize.Height());
66}
67
68IMPL_LINK(DropDownFormFieldButton, MyListBoxHandler, weld::TreeView&, rBox, bool)
69{
70 OUString sSelection = rBox.get_selected_text();
71 if (sSelection == SwResId(STR_DROP_DOWN_EMPTY_LIST))
72 {
73 m_xFieldPopup->popdown();
74 return true;
75 }
76
77 sal_Int32 nSelection = rBox.get_selected_index();
78 if (nSelection >= 0)
79 {
80 (*m_rFieldmark.GetParameters())[ODF_FORMDROPDOWN_RESULT] <<= nSelection;
81 m_rFieldmark.Invalidate();
82 SwView& rView = static_cast<SwEditWin*>(GetParent())->GetView();
83 rView.GetDocShell()->SetModified();
84 }
85
86 m_xFieldPopup->popdown();
87
88 return true;
89}
90
93 : FormFieldButton(pEditWin, rFieldmark)
94{
95}
96
98
100{
102 = Application::CreateBuilder(GetFrameWeld(), "modules/swriter/ui/formdropdown.ui");
103 m_xFieldPopup = m_xFieldPopupBuilder->weld_popover("FormDropDown");
104 m_xTreeView = m_xFieldPopupBuilder->weld_tree_view("list");
105 InitDropdown();
106 m_xTreeView->connect_row_activated(LINK(this, DropDownFormFieldButton, MyListBoxHandler));
108 m_xTreeView->grab_focus();
109}
110
112{
113 m_xTreeView.reset();
115}
116
117/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
IMPL_LINK(DropDownFormFieldButton, MyListBoxHandler, weld::TreeView &, rBox, bool)
static const AllSettings & GetSettings()
static std::unique_ptr< weld::Builder > CreateBuilder(weld::Widget *pParent, const OUString &rUIFile, bool bMobile=false, sal_uInt64 nLOKWindowId=0)
This button is shown when the cursor is on a drop-down form field.
void InitDropdown()
Popup dialog for drop-down form field showing the list items of the field.
DropDownFormFieldButton(SwEditWin *pEditWin, sw::mark::DropDownFieldmark &rFieldMark)
std::unique_ptr< weld::TreeView > m_xTreeView
virtual void LaunchPopup() override
virtual ~DropDownFormFieldButton() override
virtual void DestroyPopup() override
This button is shown when the cursor is on a form field with drop-down capability.
std::unique_ptr< weld::Popover > m_xFieldPopup
virtual void DestroyPopup()
sw::mark::Fieldmark & m_rFieldmark
virtual void LaunchPopup()
std::unique_ptr< weld::Builder > m_xFieldPopupBuilder
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
virtual void SetModified(bool=true) override
Definition: docsh2.cxx:1419
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
SwDocShell * GetDocShell()
Definition: view.cxx:1160
Fieldmark representing a drop-down form field.
virtual IFieldmark::parameter_map_t * GetParameters() override
std::map< OUString, css::uno::Any > parameter_map_t
Definition: IMark.hxx:94
virtual Size GetSizePixel() const
weld::Window * GetFrameWeld() const
int i
constexpr OUStringLiteral ODF_FORMDROPDOWN_RESULT
constexpr OUStringLiteral ODF_FORMDROPDOWN_LISTENTRY
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:164