2018-05-30 10:52:19 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2023-01-17 13:24:49 +00:00
|
|
|
* Copyright (C) 2018-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2018-05-30 10:52:19 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 3
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef KICAD_WX_GRID_H
|
|
|
|
#define KICAD_WX_GRID_H
|
|
|
|
|
2022-10-11 23:47:29 +00:00
|
|
|
#include <memory>
|
2022-10-11 23:37:19 +00:00
|
|
|
#include <vector>
|
2022-10-12 00:15:04 +00:00
|
|
|
#include <memory>
|
2023-04-13 12:57:14 +00:00
|
|
|
#include <bitset>
|
2022-03-21 23:44:28 +00:00
|
|
|
#include <wx/event.h>
|
2018-05-30 10:52:19 +00:00
|
|
|
#include <wx/grid.h>
|
2022-03-21 23:44:28 +00:00
|
|
|
#include <wx/version.h>
|
2022-10-11 17:01:47 +00:00
|
|
|
#include <units_provider.h>
|
|
|
|
#include <libeval/numeric_evaluator.h>
|
2022-03-21 23:44:28 +00:00
|
|
|
|
2024-04-13 20:25:57 +00:00
|
|
|
class wxTextEntryBase;
|
|
|
|
|
2018-05-30 10:52:19 +00:00
|
|
|
|
|
|
|
class WX_GRID : public wxGrid
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// Constructor has to be wxFormBuilder-compatible
|
|
|
|
WX_GRID( wxWindow *parent, wxWindowID id,
|
|
|
|
const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
|
2018-08-19 16:10:14 +00:00
|
|
|
long style = wxWANTS_CHARS, const wxString& name = wxGridNameStr );
|
|
|
|
|
|
|
|
~WX_GRID() override;
|
2018-05-30 10:52:19 +00:00
|
|
|
|
2019-02-07 21:48:41 +00:00
|
|
|
/**
|
|
|
|
* Hide wxGrid's SetColLabelSize() method with one which makes sure the size is tall
|
|
|
|
* enough for the system GUI font.
|
|
|
|
* @param height
|
|
|
|
*/
|
2023-01-18 11:50:47 +00:00
|
|
|
void SetColLabelSize( int aHeight ); // Yes, we're hiding a non-virtual method
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hide wxGrid's SetLabelFont() because for some reason on MSW it's a one-shot and
|
|
|
|
* subsequent calls to it have no effect.
|
|
|
|
*/
|
|
|
|
void SetLabelFont( const wxFont& aFont ); // Yes, we're hiding a non-virtual method
|
2019-02-07 21:48:41 +00:00
|
|
|
|
2024-02-13 18:59:13 +00:00
|
|
|
/**
|
|
|
|
* Enable alternate row highlighting, where every odd row has a different background
|
|
|
|
* color than the even rows.s
|
|
|
|
*
|
|
|
|
* @param aEnable flag to specify to enable alternate row striping in the grid
|
|
|
|
*/
|
|
|
|
void EnableAlternateRowColors( bool aEnable = true );
|
|
|
|
|
2018-05-30 10:52:19 +00:00
|
|
|
/**
|
|
|
|
* Get a tokenized string containing the shown column indexes.
|
|
|
|
* Tokens are separated by spaces.
|
|
|
|
*/
|
2023-04-13 12:45:22 +00:00
|
|
|
wxString GetShownColumnsAsString();
|
|
|
|
std::bitset<64> GetShownColumns();
|
2018-05-30 10:52:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Show/hide the grid columns based on a tokenized string of shown column indexes.
|
|
|
|
*/
|
|
|
|
void ShowHideColumns( const wxString& shownColumns );
|
|
|
|
|
2023-04-13 12:45:22 +00:00
|
|
|
/**
|
|
|
|
* A more performant version of ShowHideColumns (primarily for OnUpdateUI handlers).
|
|
|
|
*/
|
|
|
|
void ShowHideColumns( const std::bitset<64>& aShownColumns );
|
|
|
|
|
2018-05-30 10:52:19 +00:00
|
|
|
/**
|
|
|
|
* Hide wxGrid's SetTable() method with one which doesn't mess up the grid column
|
|
|
|
* widths when setting the table.
|
|
|
|
*/
|
2018-08-19 16:10:14 +00:00
|
|
|
void SetTable( wxGridTableBase* table, bool aTakeOwnership = false );
|
2018-05-30 10:52:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Work-around for a bug in wxGrid which crashes when deleting the table if the
|
|
|
|
* cell edit control was not closed.
|
|
|
|
*/
|
|
|
|
void DestroyTable( wxGridTableBase* aTable );
|
|
|
|
|
2018-08-13 17:00:08 +00:00
|
|
|
/**
|
|
|
|
* Close any open cell edit controls.
|
|
|
|
* @param aQuietMode if true don't send events (ie: for row/col delete operations)
|
|
|
|
* @return false if validation failed
|
|
|
|
*/
|
|
|
|
bool CommitPendingChanges( bool aQuietMode = false );
|
2023-04-10 14:12:35 +00:00
|
|
|
bool CancelPendingChanges();
|
2018-08-13 17:00:08 +00:00
|
|
|
|
2022-10-11 17:01:47 +00:00
|
|
|
/**
|
|
|
|
* Set a UNITS_PROVIDER to enable use of unit- and eval-based Getters.
|
|
|
|
* @param aProvider
|
|
|
|
*/
|
2022-11-04 12:20:53 +00:00
|
|
|
void SetUnitsProvider( UNITS_PROVIDER* aProvider, int aCol = 0 );
|
2022-10-11 17:01:47 +00:00
|
|
|
|
|
|
|
void SetAutoEvalCols( const std::vector<int>& aCols ) { m_autoEvalCols = aCols; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Apply standard KiCad unit and eval services to a numeric cell.
|
|
|
|
* @return the value held by the cell in internal units
|
|
|
|
*/
|
|
|
|
int GetUnitValue( int aRow, int aCol );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a unitized cell's value.
|
|
|
|
*/
|
|
|
|
void SetUnitValue( int aRow, int aCol, int aValue );
|
|
|
|
|
2019-02-09 23:31:31 +00:00
|
|
|
/**
|
|
|
|
* Calculates the specified column based on the actual size of the text
|
|
|
|
* on screen. Will return the maximum value of all calculated widths.
|
|
|
|
* @param aCol - Integer value of the column to resize. Specify -1 for the row labels.
|
|
|
|
* @param aHeader - Include the header in the width calculation
|
2019-02-10 08:49:42 +00:00
|
|
|
* @param aContents - Include the full contents of the column
|
2019-02-09 23:31:31 +00:00
|
|
|
* @param aKeep - Use the current size as a minimum value
|
|
|
|
* @return The new size of the column
|
|
|
|
*/
|
2022-08-18 16:56:36 +00:00
|
|
|
int GetVisibleWidth( int aCol, bool aHeader = true, bool aContents = true, bool aKeep = false );
|
2019-02-09 23:31:31 +00:00
|
|
|
|
2019-02-18 19:34:44 +00:00
|
|
|
/**
|
|
|
|
* Ensure the height of the row displaying the column labels is enough, even
|
|
|
|
* if labels are multiline texts
|
|
|
|
*/
|
|
|
|
void EnsureColLabelsVisible();
|
|
|
|
|
2019-03-04 11:02:12 +00:00
|
|
|
/**
|
|
|
|
* WxWidgets has a bunch of bugs in its handling of wxGrid mouse events which close cell
|
|
|
|
* editors right after opening them. Helpfully, it already has a bunch of work-arounds in
|
|
|
|
* place (such as the SetInSetFocus() hack), including one to make slow clicks work. We
|
|
|
|
* re-purpose this hack to work-around the bugs when we want to open an editor.
|
|
|
|
*/
|
|
|
|
void ShowEditorOnMouseUp() { m_waitForSlowClick = true; }
|
|
|
|
|
2021-08-10 11:59:53 +00:00
|
|
|
/**
|
|
|
|
* wxWidgets recently added an ASSERT which fires if the position is greater than or equal
|
|
|
|
* to the number of rows (even if the delete count is 0). Needless to say, this makes using
|
|
|
|
* DeleteRows for clearing a lot more cumbersome so we add a helper here.
|
|
|
|
*/
|
|
|
|
void ClearRows()
|
|
|
|
{
|
|
|
|
if( GetNumberRows() )
|
|
|
|
DeleteRows( 0, GetNumberRows() );
|
|
|
|
}
|
|
|
|
|
2024-04-13 20:25:57 +00:00
|
|
|
/**
|
|
|
|
* A helper function to set OS-specific margins for text-based cell editors.
|
|
|
|
*/
|
|
|
|
static void CellEditorSetMargins( wxTextEntryBase* aEntry );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A helper function to tweak sizes of text-based cell editors depending on OS.
|
|
|
|
*/
|
|
|
|
static void CellEditorTransformSizeRect( wxRect& aRect );
|
|
|
|
|
2018-05-30 10:52:19 +00:00
|
|
|
protected:
|
2021-07-15 19:26:35 +00:00
|
|
|
/**
|
2023-01-16 02:46:09 +00:00
|
|
|
* A re-implementation of wxGrid::DrawColLabel which left-aligns the first column and draws
|
|
|
|
* flat borders.
|
2021-07-15 19:26:35 +00:00
|
|
|
*/
|
2018-05-30 10:52:19 +00:00
|
|
|
void DrawColLabel( wxDC& dc, int col ) override;
|
2018-08-19 16:10:14 +00:00
|
|
|
|
2023-01-16 02:46:09 +00:00
|
|
|
/**
|
|
|
|
* A re-implementation of wxGrid::DrawRowLabel which draws flat borders.
|
|
|
|
*/
|
|
|
|
void DrawRowLabel( wxDC& dc, int row ) override;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A re-implementation of wxGrid::DrawCornerLabel which draws flat borders.
|
|
|
|
*/
|
|
|
|
void DrawCornerLabel( wxDC& dc ) override;
|
|
|
|
|
2018-10-09 20:27:15 +00:00
|
|
|
void onGridColMove( wxGridEvent& aEvent );
|
2022-02-04 11:36:27 +00:00
|
|
|
void onGridCellSelect( wxGridEvent& aEvent );
|
2022-10-11 17:01:47 +00:00
|
|
|
void onCellEditorShown( wxGridEvent& aEvent );
|
|
|
|
void onCellEditorHidden( wxGridEvent& aEvent );
|
|
|
|
|
2022-03-21 23:44:28 +00:00
|
|
|
void onDPIChanged(wxDPIChangedEvent& event);
|
|
|
|
|
2022-10-11 17:01:47 +00:00
|
|
|
protected:
|
|
|
|
bool m_weOwnTable;
|
|
|
|
|
2022-11-04 12:20:53 +00:00
|
|
|
std::map<int, UNITS_PROVIDER*> m_unitsProviders;
|
2022-10-11 17:01:47 +00:00
|
|
|
std::unique_ptr<NUMERIC_EVALUATOR> m_eval;
|
|
|
|
std::vector<int> m_autoEvalCols;
|
|
|
|
|
|
|
|
std::map< std::pair<int, int>, std::pair<wxString, wxString> > m_evalBeforeAfter;
|
2018-05-30 10:52:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif //KICAD_WX_GRID_H
|