From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- sfx2/source/dialog/inputdlg.cxx | 67 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 sfx2/source/dialog/inputdlg.cxx (limited to 'sfx2/source/dialog/inputdlg.cxx') diff --git a/sfx2/source/dialog/inputdlg.cxx b/sfx2/source/dialog/inputdlg.cxx new file mode 100644 index 000000000..243f2fa09 --- /dev/null +++ b/sfx2/source/dialog/inputdlg.cxx @@ -0,0 +1,67 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include + +InputDialog::InputDialog(weld::Widget* pParent, const OUString& rLabelText) + : GenericDialogController(pParent, "sfx/ui/inputdialog.ui", "InputDialog") + , m_xEntry(m_xBuilder->weld_entry("entry")) + , m_xLabel(m_xBuilder->weld_label("label")) + , m_xHelp(m_xBuilder->weld_button("help")) + , m_xOk(m_xBuilder->weld_button("ok")) +{ + m_xLabel->set_label(rLabelText); +} + +void InputDialog::HideHelpBtn() { m_xHelp->hide(); } + +OUString InputDialog::GetEntryText() const { return m_xEntry->get_text(); } + +void InputDialog::SetEntryText(const OUString& rStr) +{ + m_xEntry->set_text(rStr); + m_xEntry->set_position(-1); +} + +void InputDialog::SetEntryMessageType(weld::EntryMessageType aType) +{ + m_xEntry->set_message_type(aType); + if (aType == weld::EntryMessageType::Error) + { + m_xEntry->select_region(0, -1); + m_xEntry->grab_focus(); + m_xOk->set_sensitive(false); + } + else + { + m_xOk->set_sensitive(true); + SetTooltip(""); + } +} + +void InputDialog::SetTooltip(const OUString& rStr) +{ + m_xEntry->set_tooltip_text(rStr); + m_xOk->set_tooltip_text(rStr); +} + +void InputDialog::setCheckEntry(std::function aFunc) +{ + mCheckEntry = aFunc; + m_xEntry->connect_changed(LINK(this, InputDialog, EntryChangedHdl)); +} + +IMPL_LINK_NOARG(InputDialog, EntryChangedHdl, weld::Entry&, void) +{ + if (mCheckEntry(m_xEntry->get_text())) + SetEntryMessageType(weld::EntryMessageType::Normal); + else + SetEntryMessageType(weld::EntryMessageType::Error); +} +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3