NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
searchctrl.hpp
Go to the documentation of this file.
1/*****************************************************************************
2 NumeRe: Framework fuer Numerische Rechnungen
3 Copyright (C) 2019 Erik Haenel et al.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17******************************************************************************/
18
19#ifndef SEARCHCTRL_HPP
20#define SEARCHCTRL_HPP
21
22#include <wx/wx.h>
23#include <wx/combo.h>
24#include <wx/listctrl.h>
25
31class SearchCtrlPopup : public wxListView, public wxComboPopup
32{
33 private:
37 wxArrayInt m_sizes;
38 wxString m_callTip;
40
41 wxArrayString split(wxString sString);
42
43 public:
44 virtual bool Create(wxWindow* parent) override
45 {
46 return wxListView::Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_REPORT | wxLC_NO_HEADER | wxLC_SINGLE_SEL | wxLC_VRULES);
47 }
48
49 virtual void Init() override
50 {
51 m_ListId = -1;
52 m_sizes.Add(200, 1);
53 m_enableDragDrop = false;
54 m_enableColors = false;
55 m_callTip = wxEmptyString;
56 m_callTipHighlight = wxEmptyString;
57 }
58
59 virtual wxWindow* GetControl() override
60 {
61 return this;
62 }
63
64 virtual wxString GetStringValue() const override;
65 void OnKeyEvent(wxKeyEvent& event);
66 void OnMouseUp(wxMouseEvent& WXUNUSED(event));
67 void OnMouseMove(wxMouseEvent& event);
68 void OnDragStart(wxListEvent& event);
69
70 void Set(wxArrayString& stringArray);
71
80 void SetColSizes(const wxArrayInt& sizes)
81 {
82 m_sizes = sizes;
83 }
84
93 void EnableDragDrop(bool enable)
94 {
95 m_enableDragDrop = enable;
96 }
97
106 void EnableColors(bool enable)
107 {
108 m_enableColors = enable;
109 }
110
119 void SetCallTips(const wxString& calltip, const wxString& calltiphighlight = wxEmptyString)
120 {
121 m_callTip = calltip;
122 m_callTipHighlight = calltiphighlight;
123 }
124
125 private:
127};
128
129
134class SearchCtrl : public wxComboCtrl
135{
136 private:
139
140 protected:
141 friend class SearchCtrlPopup;
142
144
145 // Virtual functions to interact with the data
146 // model
147 virtual bool selectItem(const wxString& value);
148 virtual wxString getDragDropText(const wxString& value);
149 virtual wxArrayString getCandidates(const wxString& enteredText);
150
151 public:
152 SearchCtrl(wxWindow* parent, wxWindowID id, const wxString& value = wxEmptyString, int style = wxCB_SORT) : wxComboCtrl(parent, id, value, wxDefaultPosition, wxDefaultSize, style), textChangeMutex(false)
153 {
154 popUp = new SearchCtrlPopup();
155 SetPopupControl(popUp);
156 }
157
158 // Event handler functions
159 void OnItemSelect(wxCommandEvent& event);
160 void OnTextChange(wxCommandEvent& event);
161 void OnMouseEnter(wxMouseEvent& event);
162
164};
165
166
167#endif // SEARCHCTRL_HPP
168
Implementation of a generic search control based on a combo box.
Definition: searchctrl.hpp:135
friend class SearchCtrlPopup
Definition: searchctrl.hpp:141
virtual wxArrayString getCandidates(const wxString &enteredText)
Child classes must override this member function to provide the candidates to be filled into the popu...
Definition: searchctrl.cpp:447
void OnMouseEnter(wxMouseEvent &event)
This event handler will show the drop down list, if the text field contains data and the mouse enters...
Definition: searchctrl.cpp:530
wxString textEntryValue
Definition: searchctrl.hpp:138
bool textChangeMutex
Definition: searchctrl.hpp:137
void OnItemSelect(wxCommandEvent &event)
This event handler function will be fired, if the user selects a proposed string in the opened dropdo...
Definition: searchctrl.cpp:465
SearchCtrl(wxWindow *parent, wxWindowID id, const wxString &value=wxEmptyString, int style=wxCB_SORT)
Definition: searchctrl.hpp:152
DECLARE_EVENT_TABLE()
SearchCtrlPopup * popUp
Definition: searchctrl.hpp:143
virtual wxString getDragDropText(const wxString &value)
Child classes may override this member function to provide a custom string for the built-in drag-drop...
Definition: searchctrl.cpp:431
void OnTextChange(wxCommandEvent &event)
This event handler function will be fired, if the user changes the text in the control....
Definition: searchctrl.cpp:488
virtual bool selectItem(const wxString &value)
Child classes may override this member function to do something, when the user selects an item in the...
Definition: searchctrl.cpp:414
The popup control for the generic search control. Implemented ontop of a list view.
Definition: searchctrl.hpp:32
virtual void Init() override
Definition: searchctrl.hpp:49
virtual bool Create(wxWindow *parent) override
Definition: searchctrl.hpp:44
wxArrayString split(wxString sString)
wxArrayInt m_sizes
Definition: searchctrl.hpp:37
void OnMouseUp(wxMouseEvent &WXUNUSED(event))
This event handler fires, if the user double clicks on an item in the popup list.
Definition: searchctrl.cpp:295
wxString m_callTipHighlight
Definition: searchctrl.hpp:39
virtual wxString GetStringValue() const override
Returns the string representation of the selected item after the popup had been closed.
Definition: searchctrl.cpp:70
void Set(wxArrayString &stringArray)
A set function to update the contents in the displayed list.
Definition: searchctrl.cpp:363
void EnableDragDrop(bool enable)
Enable or disable the drag-drop feature of this control.
Definition: searchctrl.hpp:93
void OnMouseMove(wxMouseEvent &event)
This event handler provides the mouse hover effect in the popup list.
Definition: searchctrl.cpp:310
void OnDragStart(wxListEvent &event)
This event handler is the drag-drop handler for the search results.
Definition: searchctrl.cpp:335
void SetColSizes(const wxArrayInt &sizes)
Change the column sizes. Will create as many columns as fields are in the array.
Definition: searchctrl.hpp:80
wxString m_callTip
Definition: searchctrl.hpp:38
void EnableColors(bool enable)
Enables or disables coloring of functions in blue.
Definition: searchctrl.hpp:106
void SetCallTips(const wxString &calltip, const wxString &calltiphighlight=wxEmptyString)
Sets the calltips for the popup list.
Definition: searchctrl.hpp:119
void OnKeyEvent(wxKeyEvent &event)
This event handler is necessary to pass the keycodes, which are accidentally catched in this control,...
Definition: searchctrl.cpp:89
virtual wxWindow * GetControl() override
Definition: searchctrl.hpp:59