KiCad PCB EDA Suite
Loading...
Searching...
No Matches
grid_text_button_helpers.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2021 CERN
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#ifndef GRID_TEXT_BUTTON_HELPERS_H
26#define GRID_TEXT_BUTTON_HELPERS_H
27
29
30#include <memory>
31
32#include <wx/combo.h>
33#include <wx/generic/gridctrl.h>
34#include <wx/generic/grideditors.h>
35#include <search_stack.h>
36
37
38class wxGrid;
39class WX_GRID;
40class DIALOG_SHIM;
41class EMBEDDED_FILES;
42
43
44class GRID_CELL_TEXT_BUTTON : public wxGridCellEditor
45{
46public:
48
49 wxString GetValue() const override;
50
51 void SetSize( const wxRect& aRect ) override;
52
53 void StartingKey( wxKeyEvent& event ) override;
54 void BeginEdit( int aRow, int aCol, wxGrid* aGrid ) override;
55 bool EndEdit( int , int , const wxGrid* , const wxString& , wxString *aNewVal ) override;
56 void ApplyEdit( int aRow, int aCol, wxGrid* aGrid ) override;
57 void Reset() override;
58
59#if wxUSE_VALIDATORS
60 void SetValidator( const wxValidator& validator );
61#endif
62
63protected:
64 wxComboCtrl* Combo() const { return static_cast<wxComboCtrl*>( m_control ); }
65
66#if wxUSE_VALIDATORS
67 std::unique_ptr< wxValidator > m_validator;
68#endif
69
70 wxString m_value;
71
73};
74
75
77{
78public:
80 const wxString& aPreselect = wxEmptyString ) :
81 m_dlg( aParent ),
82 m_preselect( aPreselect )
83 { }
84
85 wxGridCellEditor* Clone() const override
86 {
88 }
89
90 void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override;
91
92protected:
94 wxString m_preselect;
95};
96
97
99{
100public:
101 GRID_CELL_FPID_EDITOR( DIALOG_SHIM* aParent, const wxString& aSymbolNetlist,
102 const wxString& aPreselect = wxEmptyString ) :
103 m_dlg( aParent ),
104 m_preselect( aPreselect ),
105 m_symbolNetlist( aSymbolNetlist )
106 { }
107
108 wxGridCellEditor* Clone() const override
109 {
111 }
112
113 void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override;
114
115protected:
117 wxString m_preselect;
119};
120
121
123{
124public:
125 GRID_CELL_URL_EDITOR( DIALOG_SHIM* aParent, SEARCH_STACK* aSearchStack = nullptr,
126 std::vector<EMBEDDED_FILES*> aFilesStack = {} ) :
127 m_dlg( aParent ),
128 m_searchStack( aSearchStack ),
129 m_filesStack( aFilesStack )
130 { }
131
132 wxGridCellEditor* Clone() const override
133 {
134 return new GRID_CELL_URL_EDITOR( m_dlg );
135 }
136
137 void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override;
138
139protected:
141 SEARCH_STACK* m_searchStack; // No ownership.
142 std::vector<EMBEDDED_FILES*> m_filesStack; // No ownership.
143};
144
145
150{
151public:
162 GRID_CELL_PATH_EDITOR( DIALOG_SHIM* aParentDialog, WX_GRID* aGrid, wxString* aCurrentDir,
163 bool aNormalize, const wxString& aNormalizeBasePath,
164 std::function<wxString( WX_GRID* grid, int row )> aFileFilterFn,
165 std::function<wxString( const wxString& )> aEmbedCallback = nullptr ) :
166 m_dlg( aParentDialog ),
167 m_grid( aGrid ),
168 m_currentDir( aCurrentDir ),
169 m_normalize( aNormalize ),
170 m_normalizeBasePath( aNormalizeBasePath ),
171 m_fileFilterFn( std::move( aFileFilterFn ) ),
172 m_embedCallback( std::move( aEmbedCallback ) )
173 { }
174
186 GRID_CELL_PATH_EDITOR( DIALOG_SHIM* aParentDialog, WX_GRID* aGrid, wxString* aCurrentDir,
187 const wxString& aFileFilter, bool aNormalize = false,
188 const wxString& aNormalizeBasePath = wxEmptyString,
189 std::function<wxString( const wxString& )> aEmbedCallback = nullptr ) :
190 m_dlg( aParentDialog ),
191 m_grid( aGrid ),
192 m_currentDir( aCurrentDir ),
193 m_normalize( aNormalize ),
194 m_normalizeBasePath( aNormalizeBasePath ),
195 m_fileFilter( aFileFilter ),
196 m_embedCallback( std::move( aEmbedCallback ) )
197 { }
198
199 wxGridCellEditor* Clone() const override
200 {
201 if( m_fileFilterFn )
202 {
205 }
206 else
207 {
210 }
211 }
212
213 void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override;
214
215protected:
218 wxString* m_currentDir;
221
222 wxString m_fileFilter;
223 std::function<wxString( WX_GRID* aGrid, int aRow )> m_fileFilterFn;
224 std::function<wxString( const wxString& )> m_embedCallback;
225};
226
227
235{
236public:
237 GRID_CELL_RUN_FUNCTION_EDITOR( DIALOG_SHIM* aParent, const std::function<void( int, int )> aFunction,
238 const bool aIsNullable = false ) :
239 GRID_CELL_NULLABLE_INTERFACE( aIsNullable ),
240 m_dlg( aParent ),
241 m_row( -1 ),
242 m_col( -1 ),
243 m_function( aFunction )
244 {
245 }
246
247 wxGridCellEditor* Clone() const override
248 {
250 }
251
252 void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override;
253 void BeginEdit( int aRow, int aCol, wxGrid* aGrid ) override;
254
255
256protected:
258 int m_row;
259 int m_col;
260 std::function<void( int, int )> m_function;
261};
262
263#endif // GRID_TEXT_BUTTON_HELPERS_H
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
Definition dialog_shim.h:68
GRID_CELL_FPID_EDITOR(DIALOG_SHIM *aParent, const wxString &aSymbolNetlist, const wxString &aPreselect=wxEmptyString)
void Create(wxWindow *aParent, wxWindowID aId, wxEvtHandler *aEventHandler) override
wxGridCellEditor * Clone() const override
wxGridCellEditor * Clone() const override
GRID_CELL_PATH_EDITOR(DIALOG_SHIM *aParentDialog, WX_GRID *aGrid, wxString *aCurrentDir, const wxString &aFileFilter, bool aNormalize=false, const wxString &aNormalizeBasePath=wxEmptyString, std::function< wxString(const wxString &)> aEmbedCallback=nullptr)
Constructor.
void Create(wxWindow *aParent, wxWindowID aId, wxEvtHandler *aEventHandler) override
std::function< wxString(WX_GRID *aGrid, int aRow)> m_fileFilterFn
std::function< wxString(const wxString &)> m_embedCallback
GRID_CELL_PATH_EDITOR(DIALOG_SHIM *aParentDialog, WX_GRID *aGrid, wxString *aCurrentDir, bool aNormalize, const wxString &aNormalizeBasePath, std::function< wxString(WX_GRID *grid, int row)> aFileFilterFn, std::function< wxString(const wxString &)> aEmbedCallback=nullptr)
Constructor.
void BeginEdit(int aRow, int aCol, wxGrid *aGrid) override
wxGridCellEditor * Clone() const override
GRID_CELL_RUN_FUNCTION_EDITOR(DIALOG_SHIM *aParent, const std::function< void(int, int)> aFunction, const bool aIsNullable=false)
void Create(wxWindow *aParent, wxWindowID aId, wxEvtHandler *aEventHandler) override
std::function< void(int, int)> m_function
wxGridCellEditor * Clone() const override
GRID_CELL_SYMBOL_ID_EDITOR(DIALOG_SHIM *aParent, const wxString &aPreselect=wxEmptyString)
void Create(wxWindow *aParent, wxWindowID aId, wxEvtHandler *aEventHandler) override
wxDECLARE_NO_COPY_CLASS(GRID_CELL_TEXT_BUTTON)
wxString GetValue() const override
wxComboCtrl * Combo() const
void StartingKey(wxKeyEvent &event) override
void BeginEdit(int aRow, int aCol, wxGrid *aGrid) override
bool EndEdit(int, int, const wxGrid *, const wxString &, wxString *aNewVal) override
void ApplyEdit(int aRow, int aCol, wxGrid *aGrid) override
void SetSize(const wxRect &aRect) override
wxGridCellEditor * Clone() const override
void Create(wxWindow *aParent, wxWindowID aId, wxEvtHandler *aEventHandler) override
std::vector< EMBEDDED_FILES * > m_filesStack
GRID_CELL_URL_EDITOR(DIALOG_SHIM *aParent, SEARCH_STACK *aSearchStack=nullptr, std::vector< EMBEDDED_FILES * > aFilesStack={})
Look for files in a number of paths.
STL namespace.