1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 #include <svtools/editbrowsebox.hxx>
23 #include <vcl/weld.hxx>
29 OUString m_sAllowedChars
;
30 bool m_bCheck
; // true when we should check for invalid chars
32 OSQLNameChecker(OUString _sAllowedChars
)
33 :m_sAllowedChars(std::move(_sAllowedChars
))
38 void setAllowedChars(const OUString
& _rAllowedChars
)
40 m_sAllowedChars
= _rAllowedChars
;
42 void setCheck(bool _bCheck
)
46 bool checkString(std::u16string_view _sToCheck
,OUString
& _rsCorrected
);
49 class OSQLNameEditControl
: public svt::EditControl
50 , public OSQLNameChecker
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
;
66 DECL_LINK(ModifyHdl
, weld::Entry
&, void);
68 Link
<weld::Entry
&,void> m_ChainChangedHdl
;
74 weld::Widget
* m_pWidget
;
76 OWidgetBase(weld::Widget
*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
97 std::unique_ptr
<weld::Entry
> m_xEntry
;
99 DECL_LINK(ModifyHdl
, weld::Entry
&, void);
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: */