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>
13 #include <viewopt.hxx>
14 #include <bookmrk.hxx>
15 #include <vcl/floatwin.hxx>
16 #include <vcl/event.hxx>
17 #include <vcl/lstbox.hxx>
18 #include <xmloff/odffields.hxx>
19 #include <IMark.hxx>
20 #include <view.hxx>
21 #include <docsh.hxx>
22 #include <strings.hrc>
23 
29 {
30 private:
33 
34  DECL_LINK(MyListBoxHandler, ListBox&, void);
35 
36 public:
37  SwFieldDialog(SwEditWin* parent, sw::mark::IFieldmark* fieldBM, long nMinListWidth);
38  virtual ~SwFieldDialog() override;
39  virtual void dispose() override;
40 };
41 
42 SwFieldDialog::SwFieldDialog(SwEditWin* parent, sw::mark::IFieldmark* fieldBM, long nMinListWidth)
44  , aListBox(VclPtr<ListBox>::Create(this))
45  , pFieldmark(fieldBM)
46 {
47  if (fieldBM != nullptr)
48  {
49  const sw::mark::IFieldmark::parameter_map_t* const pParameters = fieldBM->GetParameters();
50 
51  OUString sListKey = ODF_FORMDROPDOWN_LISTENTRY;
52  sw::mark::IFieldmark::parameter_map_t::const_iterator pListEntries
53  = pParameters->find(sListKey);
54  css::uno::Sequence<OUString> vListEntries;
55  if (pListEntries != pParameters->end())
56  {
57  pListEntries->second >>= vListEntries;
58  for (OUString const& i : vListEntries)
60  }
61 
62  if (!vListEntries.hasElements())
63  {
64  aListBox->InsertEntry(SwResId(STR_DROP_DOWN_EMPTY_LIST));
65  }
66 
67  // Select the current one
68  OUString sResultKey = ODF_FORMDROPDOWN_RESULT;
69  sw::mark::IFieldmark::parameter_map_t::const_iterator pResult
70  = pParameters->find(sResultKey);
71  if (pResult != pParameters->end())
72  {
73  sal_Int32 nSelection = -1;
74  pResult->second >>= nSelection;
75  aListBox->SelectEntryPos(nSelection);
76  }
77  }
78 
79  Size lbSize(aListBox->GetOptimalSize());
80  lbSize.AdjustWidth(50);
81  lbSize.AdjustHeight(20);
82  lbSize.setWidth(std::max(lbSize.Width(), nMinListWidth));
83  aListBox->SetSizePixel(lbSize);
84  aListBox->SetSelectHdl(LINK(this, SwFieldDialog, MyListBoxHandler));
85  aListBox->Show();
86 
87  SetSizePixel(lbSize);
88 }
89 
91 
93 {
96 }
97 
98 IMPL_LINK(SwFieldDialog, MyListBoxHandler, ListBox&, rBox, void)
99 {
100  if (!rBox.IsTravelSelect())
101  {
102  OUString sSelection = rBox.GetSelectedEntry();
103  if (sSelection == SwResId(STR_DROP_DOWN_EMPTY_LIST))
104  {
105  EndPopupMode();
106  return;
107  }
108 
109  sal_Int32 nSelection = rBox.GetSelectedEntryPos();
110  if (nSelection >= 0)
111  {
112  OUString sKey = ODF_FORMDROPDOWN_RESULT;
113  (*pFieldmark->GetParameters())[sKey] <<= nSelection;
114  pFieldmark->Invalidate();
115  SwView& rView = static_cast<SwEditWin*>(GetParent())->GetView();
116  rView.GetDocShell()->SetModified();
117  }
118 
119  EndPopupMode();
120  }
121 }
122 
124  sw::mark::DropDownFieldmark& rFieldmark)
125  : FormFieldButton(pEditWin, rFieldmark)
126 {
127 }
128 
130 
132 {
133  m_pFieldPopup = VclPtr<SwFieldDialog>::Create(static_cast<SwEditWin*>(GetParent()),
135 }
136 
137 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
Popup dialog for drop-down form field showing the list items of the field.
DECL_LINK(MyListBoxHandler, ListBox &, void)
virtual Size GetOptimalSize() const override
virtual ~DropDownFormFieldButton() override
virtual void SetModified(bool=true) override
Definition: docsh2.cxx:1404
std::map< OUString, css::uno::Any > parameter_map_t
Definition: IMark.hxx:94
WinBits const WB_SYSTEMWINDOW
long AdjustWidth(long n)
sw::mark::Fieldmark & m_rFieldmark
virtual void InitPopup() override
virtual Size GetSizePixel() const
virtual void SetSizePixel(const Size &rNewSize)
virtual void dispose() override
VclPtr< ListBox > aListBox
const char aListBox[]
Definition: ww8scan.hxx:49
#define ODF_FORMDROPDOWN_RESULT
VclPtr< FloatingWindow > m_pFieldPopup
virtual parameter_map_t * GetParameters()=0
This button is shown when the cursor is on a form field with drop-down capability.
Window class for the Writer edit area, this is the one handling mouse and keyboard events and doing t...
Definition: edtwin.hxx:58
virtual ~SwFieldDialog() override
void SelectEntryPos(sal_Int32 nPos, bool bSelect=true)
int i
sw::mark::IFieldmark * pFieldmark
sal_Int32 InsertEntry(const OUString &rStr, sal_Int32 nPos=LISTBOX_APPEND)
OUString SwResId(const char *pId)
Definition: swmodule.cxx:191
SwFieldDialog(SwEditWin *parent, sw::mark::IFieldmark *fieldBM, long nMinListWidth)
void SetSelectHdl(const Link< ListBox &, void > &rLink)
vcl::Window * GetParent() const
SwDocShell * GetDocShell()
Definition: view.cxx:1115
DropDownFormFieldButton(SwEditWin *pEditWin, sw::mark::DropDownFieldmark &rFieldMark)
WinBits const WB_BORDER
void Create(SwFormatVertOrient &rItem, SvStream &rStrm, sal_uInt16 nVersionAbusedAsSize)
Definition: legacyitem.cxx:34
#define ODF_FORMDROPDOWN_LISTENTRY
static VclPtr< reference_type > Create(Arg &&...arg)
virtual void dispose() override
Fieldmark representing a drop-down form field.
Definition: bookmrk.hxx:289
Definition: view.hxx:146
void Show(bool bVisible=true, ShowFlags nFlags=ShowFlags::NONE)