NCBI C++ ToolKit
auto_complete_combo.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef GUI_WIDGETS_WX___AUTO_COMPLETE_COMBO__HPP
2 #define GUI_WIDGETS_WX___AUTO_COMPLETE_COMBO__HPP
3 
4 /* $Id: auto_complete_combo.hpp 47479 2023-05-02 13:24:02Z ucko $
5  * ===========================================================================
6  *
7  * PUBLIC DOMAIN NOTICE
8  * National Center for Biotechnology Information
9  *
10  * This software/database is a "United States Government Work" under the
11  * terms of the United States Copyright Act. It was written as part of
12  * the author's official duties as a United States Government employee and
13  * thus cannot be copyrighted. This software/database is freely available
14  * to the public for use. The National Library of Medicine and the U.S.
15  * Government have not placed any restriction on its use or reproduction.
16  *
17  * Although all reasonable efforts have been taken to ensure the accuracy
18  * and reliability of the software and data, the NLM and the U.S.
19  * Government do not and cannot warrant the performance or results that
20  * may be obtained by using this software or data. The NLM and the U.S.
21  * Government disclaim all warranties, express or implied, including
22  * warranties of performance, merchantability or fitness for any particular
23  * purpose.
24  *
25  * Please cite the author in any work or product based on this material.
26  *
27  * ===========================================================================
28  *
29  * Authors: Andrey Yazhuk
30  *
31  * File Description:
32  *
33  */
34 
35 
36 #include <corelib/ncbiobj.hpp>
37 #include <gui/gui.hpp>
38 #include <gui/utils/mru_list.hpp>
40 
41 #include <wx/combobox.h>
42 #ifndef __WXMSW__
43 #include <wx/timer.h>
44 #endif
45 
46 
48 
49 #define DICTIONARY_MAX_SIZE 50
50 
51 ///////////////////////////////////////////////////////////////////////////////
52 /// CAutoCompleteComboBox
54  public wxComboBox
55 {
56  DECLARE_EVENT_TABLE()
57 public:
58  CAutoCompleteCombo(wxWindow* parent, wxWindowID id = wxID_ANY);
60  wxWindow* parent,
61  wxWindowID id,
62  const wxString& value,
63  const wxPoint& pos,
64  const wxSize& size,
65  const wxArrayString& choices,
66  long style = 0,
67  const wxValidator& validator = wxDefaultValidator,
68  const wxString& name = wxT("auto complete combo")
69  );
70 
71  virtual ~CAutoCompleteCombo();
72 
73  void Init();
74  void Create(
75  wxWindow* parent,
76  wxWindowID id,
77  const wxString& value,
78  const wxPoint& pos,
79  const wxSize& size,
80  const wxArrayString& choices,
81  long style = wxCB_DROPDOWN,
82  const wxValidator& validator = wxDefaultValidator,
83  const wxString& name = wxT("auto complete combo")
84  );
85 
87  {
88  m_Provider = provider;
89  }
90  bool HasProvider() const { return !m_Provider.IsNull(); }
91 
92  void SetIgnoreCase( bool fIgnore ){ m_IgnoreCase = fIgnore; }
93 
94  void SetFiltered( bool fFiltered ){ m_Filtered = fFiltered; }
95  void SetMatchedOnly( bool fMatchedOnly ){ m_MatchedOnly = fMatchedOnly; }
96  void SetAutoOff( bool fAutoOff = true ){ m_AutoOff = fAutoOff; }
97 
98  void SetBaseItems( const wxArrayString& choices );
99  void GetBaseItems( wxArrayString& choices );
100  void Push();
101 
102 protected:
103  void OnTextChanged( wxCommandEvent& event );
104  void OnItemSelected( wxCommandEvent& event );
105  void OnKeyDown( wxKeyEvent &event );
106  void OnIdle( wxIdleEvent &event );
107 
108  /// Completes value from available choices
109  void x_AutoComplete();
110 # ifndef __WXMSW__
111  void x_OnTimer( wxTimerEvent& event );
112  wxTimer m_Timer;
113 # endif
114 
115  virtual wxArrayString ProvideItems( const wxString& pattern );
116  wxArrayString GetFilteredItems( const wxString& pattern );
117 
118 private:
119  wxArrayString m_BaseChoices;
124  bool m_AutoOff;
125 
129 
130  wxArrayString m_PrevArray; // previous wxChoice string array
131  wxString m_PrevValue; // last processed input value
133 };
134 
135 template<class T = string> class CMRUItemsProvider
136  : public CObject, public IFilterItems
137 {
138 public:
139  CMRUItemsProvider( CMRUList<T>& aList ) : m_List( aList ) {}
140  virtual void GetItems( const string& pattern, vector<string>& result );
141 
142 protected:
143  const string ToString( const T& item );
144 
145 private:
146 
148 };
149 
150 // template<> void CMRUItemsProvider<string>::GetItems( const string& pattern, vector<string>& result );
151 
152 template<> class CMRUItemsProvider<string>
153 : public CObject, public IFilterItems
154 {
155 public:
156  CMRUItemsProvider( CMRUList<string>& aList ) : m_List( aList ) {}
157  virtual void GetItems( const string& /*pattern*/, vector<string>& result )
158  {
159  m_List.GetItems( result );
160  }
161 
162 private:
164 };
165 
167 
168 /* @} */
169 
170 #endif // GUI_WIDGETS_WX___AUTO_COMPLETE_COMBO__HPP
CAutoCompleteComboBox.
void SetMatchedOnly(bool fMatchedOnly)
void SetFiltered(bool fFiltered)
void SetIgnoreCase(bool fIgnore)
void SetItemsProvider(CIRef< IFilterItems > &provider)
void SetAutoOff(bool fAutoOff=true)
CIRef< IFilterItems > m_Provider
CMRUItemsProvider(CMRUList< string > &aList)
virtual void GetItems(const string &, vector< string > &result)
const string ToString(const T &item)
CMRUItemsProvider(CMRUList< T > &aList)
virtual void GetItems(const string &pattern, vector< string > &result)
CMRUList.
Definition: mru_list.hpp:51
CObject –.
Definition: ncbiobj.hpp:180
#define T(s)
Definition: common.h:230
static void Init(void)
Definition: cursor6.c:76
string
Definition: cgiapp.hpp:687
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define NCBI_GUIWIDGETS_WX_EXPORT
Definition: gui_export.h:543
#define wxT(x)
Definition: muParser.cpp:41
const struct ncbi::grid::netcache::search::fields::SIZE size
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1227
Portable reference counted smart and weak pointers using CWeakRef, CRef, CObject and CObjectEx.
static static static wxID_ANY
else result
Definition: token2.c:20
Modified on Tue Apr 23 07:38:23 2024 by modify_doxy.py rev. 669887