Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / ui / fldui / DropDownFieldDialog.cxx
blobd85bc5365bee5c2c548901b9ffb1061fbf6e6708
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <wrtsh.hxx>
21 #include <fldbas.hxx>
22 #include <DropDownFieldDialog.hxx>
23 #include <flddropdown.hxx>
25 #include <memory>
27 using namespace ::com::sun::star;
29 // edit insert-field
30 sw::DropDownFieldDialog::DropDownFieldDialog(weld::Widget *pParent, SwWrtShell &rS,
31 SwField* pField, bool bPrevButton, bool bNextButton)
32 : GenericDialogController(pParent, "modules/swriter/ui/dropdownfielddialog.ui", "DropdownFieldDialog")
33 , m_rSh( rS )
34 , m_pDropField(nullptr)
35 , m_pPressedButton(nullptr)
36 , m_xListItemsLB(m_xBuilder->weld_tree_view("list"))
37 , m_xOKPB(m_xBuilder->weld_button("ok"))
38 , m_xPrevPB(m_xBuilder->weld_button("prev"))
39 , m_xNextPB(m_xBuilder->weld_button("next"))
40 , m_xEditPB(m_xBuilder->weld_button("edit"))
42 m_xListItemsLB->set_size_request(m_xListItemsLB->get_approximate_digit_width() * 24,
43 m_xListItemsLB->get_height_rows(12));
44 Link<weld::TreeView&, bool> aDoubleLk = LINK(this, DropDownFieldDialog, DoubleClickHdl);
45 m_xListItemsLB->connect_row_activated( aDoubleLk );
47 Link<weld::Button&, void> aEditButtonLk = LINK(this, DropDownFieldDialog, EditHdl);
48 Link<weld::Button&,void> aPrevButtonLk = LINK(this, DropDownFieldDialog, PrevHdl);
49 Link<weld::Button&, void> aNextButtonLk = LINK(this, DropDownFieldDialog, NextHdl);
50 m_xEditPB->connect_clicked(aEditButtonLk);
51 if( bPrevButton || bNextButton )
53 m_xPrevPB->show();
54 m_xPrevPB->connect_clicked(aPrevButtonLk);
55 m_xPrevPB->set_sensitive(bPrevButton);
57 m_xNextPB->show();
58 m_xNextPB->connect_clicked(aNextButtonLk);
59 m_xNextPB->set_sensitive(bNextButton);
61 if( SwFieldIds::Dropdown == pField->GetTyp()->Which() )
64 m_pDropField = static_cast<SwDropDownField*>(pField);
65 OUString sTitle = m_xDialog->get_title() +
66 m_pDropField->GetPar2();
67 m_xDialog->set_title(sTitle);
68 const uno::Sequence< OUString > aItems = m_pDropField->GetItemSequence();
69 for (const OUString& rItem : aItems)
70 m_xListItemsLB->append_text(rItem);
71 m_xListItemsLB->select_text(m_pDropField->GetSelectedItem());
74 bool bEnable = !m_rSh.IsCursorReadonly();
75 m_xOKPB->set_sensitive(bEnable);
77 m_xListItemsLB->grab_focus();
80 sw::DropDownFieldDialog::~DropDownFieldDialog()
84 void sw::DropDownFieldDialog::Apply()
86 if (!m_pDropField)
87 return;
89 OUString sSelect = m_xListItemsLB->get_selected_text();
90 if (m_pDropField->GetPar1() == sSelect)
91 return;
93 m_rSh.StartAllAction();
95 std::unique_ptr<SwDropDownField> const pCopy(
96 static_cast<SwDropDownField*>(m_pDropField->CopyField().release()));
98 pCopy->SetPar1(sSelect);
99 m_rSh.SwEditShell::UpdateOneField(*pCopy);
101 m_rSh.SetUndoNoResetModified();
102 m_rSh.EndAllAction();
105 bool sw::DropDownFieldDialog::PrevButtonPressed() const
107 return m_pPressedButton == m_xPrevPB.get();
110 bool sw::DropDownFieldDialog::NextButtonPressed() const
112 return m_pPressedButton == m_xNextPB.get();
115 IMPL_LINK_NOARG(sw::DropDownFieldDialog, EditHdl, weld::Button&, void)
117 m_pPressedButton = m_xEditPB.get();
118 m_xDialog->response(RET_YES);
121 IMPL_LINK_NOARG(sw::DropDownFieldDialog, PrevHdl, weld::Button&, void)
123 m_pPressedButton = m_xPrevPB.get();
124 m_xDialog->response(RET_OK);
127 IMPL_LINK_NOARG(sw::DropDownFieldDialog, NextHdl, weld::Button&, void)
129 m_pPressedButton = m_xNextPB.get();
130 m_xDialog->response(RET_OK);
133 IMPL_LINK_NOARG(sw::DropDownFieldDialog, DoubleClickHdl, weld::TreeView&, bool)
135 // tdf#114144, when next is available make double-click accept and go to next field
136 if (m_xNextPB->get_visible() && m_xNextPB->get_sensitive())
137 m_pPressedButton = m_xNextPB.get();
138 m_xDialog->response(RET_OK);
139 return true;
142 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */