Browse Source
Move all the grid workarounds into our own WX_GRID class.
Move all the grid workarounds into our own WX_GRID class.
(cherry picked from commit 08b4463)pull/17/head
32 changed files with 298 additions and 229 deletions
-
3common/CMakeLists.txt
-
66common/grid_tricks.cpp
-
118common/widgets/wx_grid.cpp
-
67common/widgets/wx_grid.h
-
16eeschema/dialogs/dialog_edit_component_in_schematic.cpp
-
4eeschema/dialogs/dialog_edit_component_in_schematic_base.cpp
-
2eeschema/dialogs/dialog_edit_component_in_schematic_base.fbp
-
4eeschema/dialogs/dialog_edit_component_in_schematic_base.h
-
13eeschema/dialogs/dialog_edit_libentry_fields_in_lib.cpp
-
4eeschema/dialogs/dialog_edit_libentry_fields_in_lib_base.cpp
-
2eeschema/dialogs/dialog_edit_libentry_fields_in_lib_base.fbp
-
4eeschema/dialogs/dialog_edit_libentry_fields_in_lib_base.h
-
14eeschema/dialogs/dialog_lib_edit_pin_table.cpp
-
4eeschema/dialogs/dialog_lib_edit_pin_table_base.cpp
-
2eeschema/dialogs/dialog_lib_edit_pin_table_base.fbp
-
4eeschema/dialogs/dialog_lib_edit_pin_table_base.h
-
7eeschema/dialogs/panel_eeschema_template_fieldnames.cpp
-
2eeschema/dialogs/panel_eeschema_template_fieldnames.h
-
4eeschema/dialogs/panel_eeschema_template_fieldnames_base.cpp
-
2eeschema/dialogs/panel_eeschema_template_fieldnames_base.fbp
-
4eeschema/dialogs/panel_eeschema_template_fieldnames_base.h
-
12include/grid_tricks.h
-
18pcbnew/dialogs/dialog_edit_footprint_for_BoardEditor.cpp
-
14pcbnew/dialogs/dialog_edit_footprint_for_BoardEditor_base.cpp
-
36pcbnew/dialogs/dialog_edit_footprint_for_BoardEditor_base.fbp
-
14pcbnew/dialogs/dialog_edit_footprint_for_BoardEditor_base.h
-
15pcbnew/dialogs/dialog_edit_footprint_for_fp_editor.cpp
-
10pcbnew/dialogs/dialog_edit_footprint_for_fp_editor_base.cpp
-
8pcbnew/dialogs/dialog_edit_footprint_for_fp_editor_base.fbp
-
10pcbnew/dialogs/dialog_edit_footprint_for_fp_editor_base.h
-
28pcbnew/text_mod_grid_table.cpp
-
16pcbnew/text_mod_grid_table.h
@ -0,0 +1,118 @@ |
|||
/*
|
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors. |
|||
* |
|||
* 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 |
|||
*/ |
|||
|
|||
#include <wx/tokenzr.h>
|
|||
#include <wx/dc.h>
|
|||
#include "wx_grid.h"
|
|||
|
|||
|
|||
void WX_GRID::SetTable( wxGridTableBase* aTable ) |
|||
{ |
|||
// wxGrid::SetTable() messes up the column widths from wxFormBuilder so we have to save
|
|||
// and restore them.
|
|||
int formBuilderColWidths[ GetNumberCols() ]; |
|||
|
|||
for( int i = 0; i < GetNumberCols(); ++i ) |
|||
formBuilderColWidths[ i ] = GetColSize( i ); |
|||
|
|||
wxGrid::SetTable( aTable ); |
|||
|
|||
for( int i = 0; i < GetNumberCols(); ++i ) |
|||
SetColSize( i, formBuilderColWidths[ i ] ); |
|||
} |
|||
|
|||
|
|||
void WX_GRID::DestroyTable( wxGridTableBase* aTable ) |
|||
{ |
|||
// wxGrid's destructor will crash trying to look up the cell attr if the edit control
|
|||
// is left open. Normally it's closed in Validate(), but not if the user hit Cancel.
|
|||
DisableCellEditControl(); |
|||
|
|||
wxGrid::SetTable( nullptr ); |
|||
delete aTable; |
|||
} |
|||
|
|||
|
|||
wxString WX_GRID::GetShownColumns() |
|||
{ |
|||
wxString shownColumns; |
|||
|
|||
for( int i = 0; i < GetNumberCols(); ++i ) |
|||
{ |
|||
if( IsColShown( i ) ) |
|||
{ |
|||
if( shownColumns.Length() ) |
|||
shownColumns << wxT( " " ); |
|||
shownColumns << i; |
|||
} |
|||
} |
|||
|
|||
return shownColumns; |
|||
} |
|||
|
|||
|
|||
void WX_GRID::ShowHideColumns( const wxString& shownColumns ) |
|||
{ |
|||
for( int i = 0; i < GetNumberCols(); ++i ) |
|||
HideCol( i ); |
|||
|
|||
wxStringTokenizer shownTokens( shownColumns ); |
|||
|
|||
while( shownTokens.HasMoreTokens() ) |
|||
{ |
|||
long colNumber; |
|||
shownTokens.GetNextToken().ToLong( &colNumber ); |
|||
|
|||
if( colNumber >= 0 && colNumber < GetNumberCols() ) |
|||
ShowCol( colNumber ); |
|||
} |
|||
} |
|||
|
|||
|
|||
// An re-implementation of wxGrid::DrawColLabel which left-aligns the first column.
|
|||
void WX_GRID::DrawColLabel( wxDC& dc, int col ) |
|||
{ |
|||
if( GetColWidth( col ) <= 0 || m_colLabelHeight <= 0 ) |
|||
return; |
|||
|
|||
int colLeft = GetColLeft( col ); |
|||
|
|||
wxRect rect( colLeft, 0, GetColWidth( col ), m_colLabelHeight ); |
|||
static wxGridColumnHeaderRendererDefault rend; |
|||
|
|||
// It is reported that we need to erase the background to avoid display
|
|||
// artefacts, see #12055.
|
|||
wxDCBrushChanger setBrush( dc, m_colWindow->GetBackgroundColour() ); |
|||
dc.DrawRectangle(rect); |
|||
|
|||
rend.DrawBorder( *this, dc, rect ); |
|||
|
|||
int hAlign, vAlign; |
|||
GetColLabelAlignment( &hAlign, &vAlign ); |
|||
const int orient = GetColLabelTextOrientation(); |
|||
|
|||
if( col == 0 ) |
|||
hAlign = wxALIGN_LEFT; |
|||
|
|||
rend.DrawLabel( *this, dc, GetColLabelValue( col ), rect, hAlign, vAlign, orient ); |
|||
} |
@ -0,0 +1,67 @@ |
|||
/* |
|||
* This program source code file is part of KiCad, a free EDA CAD application. |
|||
* |
|||
* Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors. |
|||
* |
|||
* 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 |
|||
|
|||
#include <wx/grid.h> |
|||
#include <grid_tricks.h> |
|||
|
|||
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, |
|||
long style = wxWANTS_CHARS, const wxString& name = wxGridNameStr ) : |
|||
wxGrid( parent, id, pos, size, style, name ) |
|||
{} |
|||
|
|||
/** |
|||
* Get a tokenized string containing the shown column indexes. |
|||
* Tokens are separated by spaces. |
|||
*/ |
|||
wxString GetShownColumns(); |
|||
|
|||
/** |
|||
* Show/hide the grid columns based on a tokenized string of shown column indexes. |
|||
*/ |
|||
void ShowHideColumns( const wxString& shownColumns ); |
|||
|
|||
/** |
|||
* Hide wxGrid's SetTable() method with one which doesn't mess up the grid column |
|||
* widths when setting the table. |
|||
*/ |
|||
void SetTable( wxGridTableBase* table ); |
|||
|
|||
/** |
|||
* 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 ); |
|||
|
|||
protected: |
|||
void DrawColLabel( wxDC& dc, int col ) override; |
|||
}; |
|||
|
|||
#endif //KICAD_WX_GRID_H |
Write
Preview
Loading…
Cancel
Save
Reference in new issue