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 .
20 #ifndef INCLUDED_SVTOOLS_INETTBC_HXX
21 #define INCLUDED_SVTOOLS_INETTBC_HXX
24 #include <rtl/ref.hxx>
25 #include <svtools/svtdllapi.h>
26 #include <tools/urlobj.hxx>
28 #include <vcl/combobox.hxx>
29 #include <vcl/idle.hxx>
30 #include <vcl/weld.hxx>
32 class MatchContext_Impl
;
33 class SvtMatchContext_Impl
;
35 class SVT_DLLPUBLIC SvtURLBox
: public ComboBox
37 friend class SvtMatchContext_Impl
;
38 friend class SvtURLBox_Impl
;
39 Link
<SvtURLBox
*,void> aOpenHdl
;
41 OUString aPlaceHolder
;
42 rtl::Reference
< SvtMatchContext_Impl
> pCtx
;
43 std::unique_ptr
<SvtURLBox_Impl
> pImpl
;
44 INetProtocol eSmartProtocol
;
45 bool bAutoCompleteMode
: 1;
46 bool bOnlyDirectories
: 1;
47 bool bHistoryDisabled
: 1;
48 bool bNoSelection
: 1;
49 bool bIsAutoCompleteEnabled
: 1;
51 SVT_DLLPRIVATE
bool ProcessKey( const vcl::KeyCode
& rCode
);
52 SVT_DLLPRIVATE
void TryAutoComplete();
53 SVT_DLLPRIVATE
void UpdatePicklistForSmartProtocol_Impl();
54 DECL_DLLPRIVATE_LINK( AutoCompleteHdl_Impl
, Edit
&, void );
55 SVT_DLLPRIVATE
void Init(bool bSetDefaultHelpID
);
58 virtual bool EventNotify( NotifyEvent
& rNEvt
) override
;
59 virtual void Select() override
;
60 virtual bool PreNotify( NotifyEvent
& rNEvt
) override
;
63 SvtURLBox( vcl::Window
* pParent
, INetProtocol eSmart
= INetProtocol::NotValid
, bool bSetDefaultHelpID
= true );
64 SvtURLBox( vcl::Window
* pParent
, WinBits _nStyle
, INetProtocol eSmart
= INetProtocol::NotValid
, bool bSetDefaultHelpID
= true );
65 virtual ~SvtURLBox() override
;
66 virtual void dispose() override
;
68 void SetBaseURL( const OUString
& rURL
);
69 const OUString
& GetBaseURL() const { return aBaseURL
; }
70 void SetOpenHdl( const Link
<SvtURLBox
*,void>& rLink
) { aOpenHdl
= rLink
; }
71 const Link
<SvtURLBox
*,void>& GetOpenHdl() const { return aOpenHdl
; }
72 void SetOnlyDirectories( bool bDir
);
73 void SetNoURLSelection( bool bSet
);
74 INetProtocol
GetSmartProtocol() const { return eSmartProtocol
; }
75 void SetSmartProtocol( INetProtocol eProt
);
77 void DisableHistory();
79 void UpdatePickList( );
81 static OUString
ParseSmart( const OUString
& aText
, const OUString
& aBaseURL
);
83 void SetFilter(const OUString
& _sFilter
);
85 void EnableAutocompletion( bool _bEnable
)
86 { bIsAutoCompleteEnabled
= _bEnable
; }
87 void SetPlaceHolder( const OUString
& sPlaceHolder
)
88 { aPlaceHolder
= sPlaceHolder
; }
89 const OUString
& GetPlaceHolder() { return aPlaceHolder
; }
90 bool MatchesPlaceHolder( const OUString
& sToMatch
) const
91 { return ( !aPlaceHolder
.isEmpty() ) && ( aPlaceHolder
== sToMatch
); }
94 class SVT_DLLPUBLIC URLBox
96 friend class MatchContext_Impl
;
97 friend class SvtURLBox_Impl
;
101 rtl::Reference
< MatchContext_Impl
> pCtx
;
102 std::unique_ptr
<SvtURLBox_Impl
> pImpl
;
103 INetProtocol eSmartProtocol
;
104 bool bHistoryDisabled
: 1;
106 Link
<weld::ComboBox
&, void> aChangeHdl
;
107 Link
<weld::Widget
&, void> aFocusOutHdl
;
109 std::unique_ptr
<weld::ComboBox
> m_xWidget
;
111 DECL_DLLPRIVATE_LINK( TryAutoComplete
, Timer
*, void);
112 SVT_DLLPRIVATE
void UpdatePicklistForSmartProtocol_Impl();
113 DECL_DLLPRIVATE_LINK( ChangedHdl
, weld::ComboBox
&, void);
114 DECL_DLLPRIVATE_LINK( FocusInHdl
, weld::Widget
&, void);
115 DECL_DLLPRIVATE_LINK( FocusOutHdl
, weld::Widget
&, void);
116 SVT_DLLPRIVATE
void Init();
119 URLBox(std::unique_ptr
<weld::ComboBox
> pWidget
);
122 void set_entry_text(const OUString
& rStr
) { m_xWidget
->set_entry_text(rStr
); }
123 void Clear() { m_xWidget
->clear(); }
124 void connect_entry_activate(const Link
<weld::ComboBox
&, bool>& rLink
) { m_xWidget
->connect_entry_activate(rLink
); }
125 void connect_changed(const Link
<weld::ComboBox
&, void>& rLink
) { aChangeHdl
= rLink
; }
126 void connect_focus_out(const Link
<weld::Widget
&, void>& rLink
) { aFocusOutHdl
= rLink
; }
127 void append_text(const OUString
& rStr
) { m_xWidget
->append_text(rStr
); }
128 int find_text(const OUString
& rStr
) const { return m_xWidget
->find_text(rStr
); }
129 OUString
get_active_text() const { return m_xWidget
->get_active_text(); }
130 void grab_focus() { m_xWidget
->grab_focus(); }
131 void set_sensitive(bool bSensitive
) { m_xWidget
->set_sensitive(bSensitive
); }
132 void EnableAutocomplete() { m_xWidget
->set_entry_completion(true); }
134 void SetBaseURL( const OUString
& rURL
);
135 void SetSmartProtocol( INetProtocol eProt
);
136 INetProtocol
GetSmartProtocol() const { return eSmartProtocol
; }
138 void DisableHistory();
140 weld::Widget
* getWidget() { return m_xWidget
.get(); }
142 static OUString
ParseSmart( const OUString
& aText
, const OUString
& aBaseURL
);
144 void SetFilter(const OUString
& _sFilter
);
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */