LibreOffice Module sw (master)  1
DropDownFieldDialog.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #include <wrtsh.hxx>
21 #include <fldbas.hxx>
22 #include <fldmgr.hxx>
23 #include <DropDownFieldDialog.hxx>
24 #include <flddropdown.hxx>
25 
26 #include <memory>
27 
28 using namespace ::com::sun::star;
29 
30 // edit insert-field
32  SwField* pField, bool bPrevButton, bool bNextButton)
33  : GenericDialogController(pParent, "modules/swriter/ui/dropdownfielddialog.ui", "DropdownFieldDialog")
34  , m_rSh( rS )
35  , m_pDropField(nullptr)
36  , m_pPressedButton(nullptr)
37  , m_xListItemsLB(m_xBuilder->weld_tree_view("list"))
38  , m_xOKPB(m_xBuilder->weld_button("ok"))
39  , m_xPrevPB(m_xBuilder->weld_button("prev"))
40  , m_xNextPB(m_xBuilder->weld_button("next"))
41  , m_xEditPB(m_xBuilder->weld_button("edit"))
42 {
43  m_xListItemsLB->set_size_request(m_xListItemsLB->get_approximate_digit_width() * 24,
44  m_xListItemsLB->get_height_rows(12));
45  Link<weld::TreeView&, bool> aDoubleLk = LINK(this, DropDownFieldDialog, DoubleClickHdl);
46  m_xListItemsLB->connect_row_activated( aDoubleLk );
47 
48  Link<weld::Button&, void> aEditButtonLk = LINK(this, DropDownFieldDialog, EditHdl);
49  Link<weld::Button&,void> aPrevButtonLk = LINK(this, DropDownFieldDialog, PrevHdl);
50  Link<weld::Button&, void> aNextButtonLk = LINK(this, DropDownFieldDialog, NextHdl);
51  m_xEditPB->connect_clicked(aEditButtonLk);
52  if( bPrevButton || bNextButton )
53  {
54  m_xPrevPB->show();
55  m_xPrevPB->connect_clicked(aPrevButtonLk);
56  m_xPrevPB->set_sensitive(bPrevButton);
57 
58  m_xNextPB->show();
59  m_xNextPB->connect_clicked(aNextButtonLk);
60  m_xNextPB->set_sensitive(bNextButton);
61  }
62  if( SwFieldIds::Dropdown == pField->GetTyp()->Which() )
63  {
64 
65  m_pDropField = static_cast<SwDropDownField*>(pField);
66  OUString sTitle = m_xDialog->get_title() +
68  m_xDialog->set_title(sTitle);
69  const uno::Sequence< OUString > aItems = m_pDropField->GetItemSequence();
70  for (const OUString& rItem : aItems)
71  m_xListItemsLB->append_text(rItem);
73  }
74 
75  bool bEnable = !m_rSh.IsCursorReadonly();
76  m_xOKPB->set_sensitive(bEnable);
77 
78  m_xListItemsLB->grab_focus();
79 }
80 
82 {
83 }
84 
86 {
87  if (m_pDropField)
88  {
89  OUString sSelect = m_xListItemsLB->get_selected_text();
90  if (m_pDropField->GetPar1() != sSelect)
91  {
92  m_rSh.StartAllAction();
93 
94  std::unique_ptr<SwDropDownField> const pCopy(
95  static_cast<SwDropDownField*>(m_pDropField->CopyField().release()));
96 
97  pCopy->SetPar1(sSelect);
98  m_rSh.SwEditShell::UpdateOneField(*pCopy);
99 
100  m_rSh.SetUndoNoResetModified();
101  m_rSh.EndAllAction();
102  }
103  }
104 }
105 
107 {
108  return m_pPressedButton == m_xPrevPB.get();
109 }
110 
112 {
113  return m_pPressedButton == m_xNextPB.get();
114 }
115 
117 {
118  m_pPressedButton = m_xEditPB.get();
119  m_xDialog->response(RET_YES);
120 }
121 
123 {
124  m_pPressedButton = m_xPrevPB.get();
125  m_xDialog->response(RET_OK);
126 }
127 
129 {
130  m_pPressedButton = m_xNextPB.get();
131  m_xDialog->response(RET_OK);
132 }
133 
135 {
136  // tdf#114144, when next is available make double-click accept and go to next field
137  if (m_xNextPB->get_visible() && m_xNextPB->get_sensitive())
138  m_pPressedButton = m_xNextPB.get();
139  m_xDialog->response(RET_OK);
140  return true;
141 }
142 
143 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::shared_ptr< weld::Dialog > m_xDialog
std::unique_ptr< weld::TreeView > m_xListItemsLB
Base class of all fields.
Definition: fldbas.hxx:280
Used by the UI to modify the document model.
Definition: wrtsh.hxx:90
RET_YES
const OUString & GetSelectedItem() const
Returns the selected item.
virtual ~DropDownFieldDialog() override
std::unique_ptr< weld::Button > m_xPrevPB
std::unique_ptr< weld::Button > m_xOKPB
IMPL_LINK_NOARG(DocumentTimerManager, DoIdleJobs, Timer *, void)
bool IsCursorReadonly() const
Definition: crsrsh.cxx:3259
DropDownFieldDialog(weld::Widget *pParent, SwWrtShell &rSh, SwField *pField, bool bPrevButton, bool bNextButton)
std::unique_ptr< weld::Button > m_xEditPB
Dropdown field.
Definition: flddropdown.hxx:58
SwFieldType * GetTyp() const
Definition: fldbas.hxx:383
virtual OUString GetPar2() const override
Returns the name of the field.
Definition: flddropdown.cxx:88
SwDropDownField * m_pDropField
RET_OK
std::unique_ptr< weld::Button > m_xNextPB
SwFieldIds Which() const
Definition: fldbas.hxx:266
css::uno::Sequence< OUString > GetItemSequence() const
Returns the items of the dropdown box.