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
10 #include <sfx2/inputdlg.hxx>
11
InputDialog(weld::Widget * pParent,const OUString & rLabelText)12 InputDialog::InputDialog(weld::Widget* pParent, const OUString& rLabelText)
13 : GenericDialogController(pParent, "sfx/ui/inputdialog.ui", "InputDialog")
14 , m_xEntry(m_xBuilder->weld_entry("entry"))
15 , m_xLabel(m_xBuilder->weld_label("label"))
16 , m_xHelp(m_xBuilder->weld_button("help"))
17 , m_xOk(m_xBuilder->weld_button("ok"))
18 {
19 m_xLabel->set_label(rLabelText);
20 }
21
HideHelpBtn()22 void InputDialog::HideHelpBtn() { m_xHelp->hide(); }
23
GetEntryText() const24 OUString InputDialog::GetEntryText() const { return m_xEntry->get_text(); }
25
SetEntryText(const OUString & rStr)26 void InputDialog::SetEntryText(const OUString& rStr)
27 {
28 m_xEntry->set_text(rStr);
29 m_xEntry->set_position(-1);
30 }
31
SetEntryMessageType(weld::EntryMessageType aType)32 void InputDialog::SetEntryMessageType(weld::EntryMessageType aType)
33 {
34 m_xEntry->set_message_type(aType);
35 if (aType == weld::EntryMessageType::Error)
36 {
37 m_xEntry->select_region(0, -1);
38 m_xEntry->grab_focus();
39 m_xOk->set_sensitive(false);
40 }
41 else
42 {
43 m_xOk->set_sensitive(true);
44 SetTooltip("");
45 }
46 }
47
SetTooltip(const OUString & rStr)48 void InputDialog::SetTooltip(const OUString& rStr)
49 {
50 m_xEntry->set_tooltip_text(rStr);
51 m_xOk->set_tooltip_text(rStr);
52 }
53
setCheckEntry(std::function<bool (OUString)> aFunc)54 void InputDialog::setCheckEntry(std::function<bool(OUString)> aFunc)
55 {
56 mCheckEntry = aFunc;
57 m_xEntry->connect_changed(LINK(this, InputDialog, EntryChangedHdl));
58 }
59
IMPL_LINK_NOARG(InputDialog,EntryChangedHdl,weld::Entry &,void)60 IMPL_LINK_NOARG(InputDialog, EntryChangedHdl, weld::Entry&, void)
61 {
62 if (mCheckEntry(m_xEntry->get_text()))
63 SetEntryMessageType(weld::EntryMessageType::Normal);
64 else
65 SetEntryMessageType(weld::EntryMessageType::Error);
66 }
67 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
68