Gtk-WARNING gtktreestore.c:1047: Invalid column number 1 added to iter
[LibreOffice.git] / dbaccess / source / ui / inc / SqlNameEdit.hxx
blob14d845b4b17cf05df812b8933ee054e66a8aa1ab
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 .
19 #pragma once
21 #include <svtools/editbrowsebox.hxx>
22 #include <utility>
23 #include <vcl/weld.hxx>
25 namespace dbaui
27 class OSQLNameChecker
29 OUString m_sAllowedChars;
30 bool m_bCheck; // true when we should check for invalid chars
31 public:
32 OSQLNameChecker(OUString _sAllowedChars)
33 :m_sAllowedChars(std::move(_sAllowedChars))
34 ,m_bCheck(true)
38 void setAllowedChars(const OUString& _rAllowedChars)
40 m_sAllowedChars = _rAllowedChars;
42 void setCheck(bool _bCheck)
44 m_bCheck = _bCheck;
46 bool checkString(std::u16string_view _sToCheck,OUString& _rsCorrected);
49 class OSQLNameEditControl : public svt::EditControl
50 , public OSQLNameChecker
52 public:
53 OSQLNameEditControl(BrowserDataWin* pParent, const OUString& rAllowedChars)
54 : svt::EditControl(pParent)
55 , OSQLNameChecker(rAllowedChars)
57 m_xWidget->connect_changed(LINK(this, OSQLNameEditControl, ModifyHdl));
60 virtual void connect_changed(const Link<weld::Entry&, void>& rLink) override
62 m_ChainChangedHdl = rLink;
65 private:
66 DECL_LINK(ModifyHdl, weld::Entry&, void);
68 Link<weld::Entry&,void> m_ChainChangedHdl;
71 class OWidgetBase
73 private:
74 weld::Widget* m_pWidget;
75 public:
76 OWidgetBase(weld::Widget *pWidget)
77 : m_pWidget(pWidget)
81 void hide() { m_pWidget->hide(); }
82 void show() { m_pWidget->show(); }
83 void set_sensitive(bool bSensitive) { m_pWidget->set_sensitive(bSensitive); }
85 weld::Widget* GetWidget() { return m_pWidget; }
87 virtual bool get_value_changed_from_saved() const = 0;
88 virtual void save_value() = 0;
90 virtual ~OWidgetBase() {}
93 class OSQLNameEntry : public OWidgetBase
94 , public OSQLNameChecker
96 private:
97 std::unique_ptr<weld::Entry> m_xEntry;
99 DECL_LINK(ModifyHdl, weld::Entry&, void);
101 public:
102 OSQLNameEntry(std::unique_ptr<weld::Entry> xEntry, const OUString& _rAllowedChars = OUString())
103 : OWidgetBase(xEntry.get())
104 , OSQLNameChecker(_rAllowedChars)
105 , m_xEntry(std::move(xEntry))
107 m_xEntry->connect_changed(LINK(this, OSQLNameEntry, ModifyHdl));
110 OUString get_text() const { return m_xEntry->get_text(); }
111 void set_text(const OUString& rText) { m_xEntry->set_text(rText); }
112 void set_max_length(int nLen) { m_xEntry->set_max_length(nLen); }
113 virtual void save_value() override { m_xEntry->save_value(); }
114 virtual bool get_value_changed_from_saved() const override
116 return m_xEntry->get_value_changed_from_saved();
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */