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
36
37class wxGrid;
38class WX_GRID;
39class DIALOG_SHIM;
40class EMBEDDED_FILES;
41
42
43class GRID_CELL_TEXT_BUTTON : public wxGridCellEditor
44{
45public:
47
48 wxString GetValue() const override;
49
50 void SetSize( const wxRect& aRect ) override;
51
52 void StartingKey( wxKeyEvent& event ) override;
53 void BeginEdit( int aRow, int aCol, wxGrid* aGrid ) override;
54 bool EndEdit( int , int , const wxGrid* , const wxString& , wxString *aNewVal ) override;
55 void ApplyEdit( int aRow, int aCol, wxGrid* aGrid ) override;
56 void Reset() override;
57
58#if wxUSE_VALIDATORS
59 void SetValidator( const wxValidator& validator );
60#endif
61
62protected:
63 wxComboCtrl* Combo() const { return static_cast<wxComboCtrl*>( m_control ); }
64
65#if wxUSE_VALIDATORS
66 std::unique_ptr< wxValidator > m_validator;
67#endif
68
69 wxString m_value;
70
72};
73
74
76{
77public:
79 const wxString& aPreselect = wxEmptyString ) :
80 m_dlg( aParent ),
81 m_preselect( aPreselect )
82 { }
83
84 wxGridCellEditor* Clone() const override
85 {
87 }
88
89 void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override;
90
91protected:
93 wxString m_preselect;
94};
95
96
98{
99public:
100 GRID_CELL_FPID_EDITOR( DIALOG_SHIM* aParent, const wxString& aSymbolNetlist,
101 const wxString& aPreselect = wxEmptyString ) :
102 m_dlg( aParent ),
103 m_preselect( aPreselect ),
104 m_symbolNetlist( aSymbolNetlist )
105 { }
106
107 wxGridCellEditor* Clone() const override
108 {
110 }
111
112 void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override;
113
114protected:
116 wxString m_preselect;
118};
119
120
122{
123public:
124 GRID_CELL_URL_EDITOR( DIALOG_SHIM* aParent, SEARCH_STACK* aSearchStack = nullptr,
125 std::vector<EMBEDDED_FILES*> aFilesStack = {} ) :
126 m_dlg( aParent ),
127 m_searchStack( aSearchStack ),
128 m_filesStack( aFilesStack )
129 { }
130
131 wxGridCellEditor* Clone() const override
132 {
133 return new GRID_CELL_URL_EDITOR( m_dlg );
134 }
135
136 void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override;
137
138protected:
140 SEARCH_STACK* m_searchStack; // No ownership.
141 std::vector<EMBEDDED_FILES*> m_filesStack; // No ownership.
142};
143
144
149{
150public:
161 GRID_CELL_PATH_EDITOR( DIALOG_SHIM* aParentDialog, WX_GRID* aGrid, wxString* aCurrentDir,
162 bool aNormalize, const wxString& aNormalizeBasePath,
163 std::function<wxString( WX_GRID* grid, int row )> aFileFilterFn,
164 std::function<wxString( const wxString& )> aEmbedCallback = nullptr ) :
165 m_dlg( aParentDialog ),
166 m_grid( aGrid ),
167 m_currentDir( aCurrentDir ),
168 m_normalize( aNormalize ),
169 m_normalizeBasePath( aNormalizeBasePath ),
170 m_fileFilterFn( std::move( aFileFilterFn ) ),
171 m_embedCallback( std::move( aEmbedCallback ) )
172 { }
173
185 GRID_CELL_PATH_EDITOR( DIALOG_SHIM* aParentDialog, WX_GRID* aGrid, wxString* aCurrentDir,
186 const wxString& aFileFilter, bool aNormalize = false,
187 const wxString& aNormalizeBasePath = wxEmptyString,
188 std::function<wxString( const wxString& )> aEmbedCallback = nullptr ) :
189 m_dlg( aParentDialog ),
190 m_grid( aGrid ),
191 m_currentDir( aCurrentDir ),
192 m_normalize( aNormalize ),
193 m_normalizeBasePath( aNormalizeBasePath ),
194 m_fileFilter( aFileFilter ),
195 m_embedCallback( std::move( aEmbedCallback ) )
196 { }
197
198 wxGridCellEditor* Clone() const override
199 {
200 if( m_fileFilterFn )
201 {
204 }
205 else
206 {
209 }
210 }
211
212 void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override;
213
214protected:
217 wxString* m_currentDir;
220
221 wxString m_fileFilter;
222 std::function<wxString( WX_GRID* aGrid, int aRow )> m_fileFilterFn;
223 std::function<wxString( const wxString& )> m_embedCallback;
224};
225
226
234{
235public:
236 GRID_CELL_RUN_FUNCTION_EDITOR( DIALOG_SHIM* aParent, const std::function<void( int, int )> aFunction,
237 const bool aIsNullable = false ) :
238 GRID_CELL_NULLABLE_INTERFACE( aIsNullable ),
239 m_dlg( aParent ),
240 m_row( -1 ),
241 m_col( -1 ),
242 m_function( aFunction )
243 {
244 }
245
246 wxGridCellEditor* Clone() const override
247 {
249 }
250
251 void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override;
252 void BeginEdit( int aRow, int aCol, wxGrid* aGrid ) override;
253
254
255protected:
257 int m_row;
258 int m_col;
259 std::function<void( int, int )> m_function;
260};
261
262#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.