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>
23#include <flddropdown.hxx>
24
25#include <memory>
26
27using namespace ::com::sun::star;
28
29// edit insert-field
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"))
41{
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 );
46
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 )
52 {
53 m_xPrevPB->show();
54 m_xPrevPB->connect_clicked(aPrevButtonLk);
55 m_xPrevPB->set_sensitive(bPrevButton);
56
57 m_xNextPB->show();
58 m_xNextPB->connect_clicked(aNextButtonLk);
59 m_xNextPB->set_sensitive(bNextButton);
60 }
61 if( SwFieldIds::Dropdown == pField->GetTyp()->Which() )
62 {
63
64 m_pDropField = static_cast<SwDropDownField*>(pField);
65 OUString sTitle = m_xDialog->get_title() +
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);
72 }
73
74 bool bEnable = !m_rSh.IsCursorReadonly();
75 m_xOKPB->set_sensitive(bEnable);
76
77 m_xListItemsLB->grab_focus();
78}
79
81{
82}
83
85{
86 if (!m_pDropField)
87 return;
88
89 OUString sSelect = m_xListItemsLB->get_selected_text();
90 if (m_pDropField->GetPar1() == sSelect)
91 return;
92
93 m_rSh.StartAllAction();
94
95 std::unique_ptr<SwDropDownField> const pCopy(
96 static_cast<SwDropDownField*>(m_pDropField->CopyField().release()));
97
98 pCopy->SetPar1(sSelect);
99 m_rSh.SwEditShell::UpdateOneField(*pCopy);
100
101 m_rSh.SetUndoNoResetModified();
102 m_rSh.EndAllAction();
103}
104
106{
107 return m_pPressedButton == m_xPrevPB.get();
108}
109
111{
112 return m_pPressedButton == m_xNextPB.get();
113}
114
116{
117 m_pPressedButton = m_xEditPB.get();
118 m_xDialog->response(RET_YES);
119}
120
122{
123 m_pPressedButton = m_xPrevPB.get();
124 m_xDialog->response(RET_OK);
125}
126
128{
129 m_pPressedButton = m_xNextPB.get();
130 m_xDialog->response(RET_OK);
131}
132
134{
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;
140}
141
142/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Reference< XExecutableDialog > m_xDialog
bool IsCursorReadonly() const
Definition: crsrsh.cxx:3609
Dropdown field.
Definition: flddropdown.hxx:59
virtual OUString GetPar2() const override
Returns the name of the field.
Definition: flddropdown.cxx:88
css::uno::Sequence< OUString > GetItemSequence() const
Returns the items of the dropdown box.
const OUString & GetSelectedItem() const
Returns the selected item.
SwFieldIds Which() const
Definition: fldbas.hxx:276
Base class of all fields.
Definition: fldbas.hxx:296
SwFieldType * GetTyp() const
Definition: fldbas.hxx:402
Used by the UI to modify the document model.
Definition: wrtsh.hxx:97
std::unique_ptr< weld::Button > m_xPrevPB
std::unique_ptr< weld::Button > m_xNextPB
std::unique_ptr< weld::Button > m_xOKPB
virtual ~DropDownFieldDialog() override
DropDownFieldDialog(weld::Widget *pParent, SwWrtShell &rSh, SwField *pField, bool bPrevButton, bool bNextButton)
std::unique_ptr< weld::Button > m_xEditPB
SwDropDownField * m_pDropField
std::unique_ptr< weld::TreeView > m_xListItemsLB
std::shared_ptr< weld::Dialog > m_xDialog
IMPL_LINK_NOARG(DocumentTimerManager, DoIdleJobs, Timer *, void)
RET_OK
RET_YES