Browse Source

Improve grid cell editors appearance.

(cherry picked from commit 76b7cdd128)
8.0
Alex Shvartzkop 2 years ago
parent
commit
6bb1e59e10
  1. 1
      common/dialogs/dialog_configure_paths.cpp
  2. 1
      common/dialogs/panel_text_variables.cpp
  3. 29
      common/validators.cpp
  4. 23
      common/widgets/grid_text_button_helpers.cpp
  5. 63
      common/widgets/grid_text_helpers.cpp
  6. 17
      common/widgets/wx_grid.cpp
  7. 17
      include/validators.h
  8. 22
      include/widgets/grid_text_helpers.h
  9. 12
      include/widgets/wx_grid.h
  10. 3
      pcbnew/fp_text_grid_table.cpp

1
common/dialogs/dialog_configure_paths.cpp

@ -34,6 +34,7 @@
#include <pgm_base.h>
#include <widgets/wx_grid.h>
#include <widgets/grid_text_button_helpers.h>
#include <widgets/grid_text_helpers.h>
#include <widgets/std_bitmap_button.h>
#include <algorithm>

1
common/dialogs/panel_text_variables.cpp

@ -29,6 +29,7 @@
#include <project.h>
#include <grid_tricks.h>
#include <widgets/std_bitmap_button.h>
#include <widgets/grid_text_helpers.h>
#include <algorithm>

29
common/validators.cpp

@ -39,35 +39,6 @@
#include <wx/log.h>
#include <wx/combo.h>
GRID_CELL_TEXT_EDITOR::GRID_CELL_TEXT_EDITOR() : wxGridCellTextEditor()
{
}
void GRID_CELL_TEXT_EDITOR::SetValidator( const wxValidator& validator )
{
// keep our own copy because wxGridCellTextEditor's is annoyingly private
m_validator.reset( static_cast<wxValidator*>( validator.Clone() ) );
wxGridCellTextEditor::SetValidator( *m_validator );
}
void GRID_CELL_TEXT_EDITOR::StartingKey( wxKeyEvent& event )
{
if( m_validator )
{
m_validator.get()->SetWindow( Text() );
m_validator.get()->ProcessEvent( event );
}
if( event.GetSkipped() )
{
wxGridCellTextEditor::StartingKey( event );
event.Skip( false );
}
}
FOOTPRINT_NAME_VALIDATOR::FOOTPRINT_NAME_VALIDATOR( wxString* aValue ) :
wxTextValidator( wxFILTER_EXCLUDE_CHAR_LIST, aValue )

23
common/widgets/grid_text_button_helpers.cpp

@ -41,16 +41,6 @@
#include <eda_doc.h>
static void setTextMargins( wxTextEntryBase* aEntry )
{
#if defined( __WXMSW__ )
aEntry->SetMargins( 2, 2 );
#elif defined( __WXGTK__ )
aEntry->SetMargins( 0, 0 );
#endif
}
//-------- Renderer ---------------------------------------------------------------------
// None required; just render as normal text.
@ -69,7 +59,10 @@ wxString GRID_CELL_TEXT_BUTTON::GetValue() const
void GRID_CELL_TEXT_BUTTON::SetSize( const wxRect& aRect )
{
Combo()->SetSize( aRect, wxSIZE_ALLOW_MINUS_ONE );
wxRect rect( aRect );
WX_GRID::CellEditorTransformSizeRect( rect );
wxGridCellEditor::SetSize( rect );
}
@ -229,7 +222,7 @@ void GRID_CELL_SYMBOL_ID_EDITOR::Create( wxWindow* aParent, wxWindowID aId,
wxEvtHandler* aEventHandler )
{
m_control = new TEXT_BUTTON_SYMBOL_CHOOSER( aParent, m_dlg, m_preselect );
setTextMargins( Combo() );
WX_GRID::CellEditorSetMargins( Combo() );
wxGridCellEditor::Create( aParent, aId, aEventHandler );
}
@ -313,7 +306,7 @@ void GRID_CELL_FPID_EDITOR::Create( wxWindow* aParent, wxWindowID aId,
wxEvtHandler* aEventHandler )
{
m_control = new TEXT_BUTTON_FP_CHOOSER( aParent, m_dlg, m_symbolNetlist, m_preselect );
setTextMargins( Combo() );
WX_GRID::CellEditorSetMargins( Combo() );
#if wxUSE_VALIDATORS
// validate text in textctrl, if validator is set
@ -365,7 +358,7 @@ void GRID_CELL_URL_EDITOR::Create( wxWindow* aParent, wxWindowID aId,
wxEvtHandler* aEventHandler )
{
m_control = new TEXT_BUTTON_URL( aParent, m_dlg, m_searchStack );
setTextMargins( Combo() );
WX_GRID::CellEditorSetMargins( Combo() );
#if wxUSE_VALIDATORS
// validate text in textctrl, if validator is set
@ -523,7 +516,7 @@ void GRID_CELL_PATH_EDITOR::Create( wxWindow* aParent, wxWindowID aId,
m_control = new TEXT_BUTTON_FILE_BROWSER( aParent, m_dlg, m_grid, m_currentDir, m_fileFilter,
m_normalize, m_normalizeBasePath );
setTextMargins( Combo() );
WX_GRID::CellEditorSetMargins( Combo() );
#if wxUSE_VALIDATORS
// validate text in textctrl, if validator is set

63
common/widgets/grid_text_helpers.cpp

@ -21,9 +21,56 @@
#include <string_utils.h>
#include <wx/stc/stc.h>
#include <widgets/grid_text_helpers.h>
#include <widgets/wx_grid.h>
#include <scintilla_tricks.h>
//-------- GRID_CELL_TEXT_EDITOR ------------------------------------------------------
//
GRID_CELL_TEXT_EDITOR::GRID_CELL_TEXT_EDITOR() : wxGridCellTextEditor()
{
}
void GRID_CELL_TEXT_EDITOR::SetValidator( const wxValidator& validator )
{
// keep our own copy because wxGridCellTextEditor's is annoyingly private
m_validator.reset( static_cast<wxValidator*>( validator.Clone() ) );
wxGridCellTextEditor::SetValidator( *m_validator );
}
void GRID_CELL_TEXT_EDITOR::StartingKey( wxKeyEvent& event )
{
if( m_validator )
{
m_validator.get()->SetWindow( Text() );
m_validator.get()->ProcessEvent( event );
}
if( event.GetSkipped() )
{
wxGridCellTextEditor::StartingKey( event );
event.Skip( false );
}
}
void GRID_CELL_TEXT_EDITOR::SetSize( const wxRect& aRect )
{
wxRect rect( aRect );
WX_GRID::CellEditorTransformSizeRect( rect );
#if defined( __WXMSW__ )
rect.Offset( 0, 1 );
#endif
wxGridCellEditor::SetSize( rect );
}
//-------- GRID_CELL_ESCAPED_TEXT_RENDERER ------------------------------------------------------
//
@ -69,9 +116,23 @@ GRID_CELL_STC_EDITOR::GRID_CELL_STC_EDITOR( bool aIgnoreCase,
{ }
void GRID_CELL_STC_EDITOR::SetSize( const wxRect& aRect )
{
wxRect rect( aRect );
WX_GRID::CellEditorTransformSizeRect( rect );
#if defined( __WXMSW__ )
rect.Offset( -1, 1 );
#endif
wxGridCellEditor::SetSize( rect );
}
void GRID_CELL_STC_EDITOR::Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler )
{
m_control = new wxStyledTextCtrl( aParent );
m_control = new wxStyledTextCtrl( aParent, wxID_ANY, wxDefaultPosition, wxDefaultSize,
wxBORDER_NONE );
stc_ctrl()->SetTabIndents( false );
stc_ctrl()->SetBackSpaceUnIndents( false );

17
common/widgets/wx_grid.cpp

@ -24,6 +24,8 @@
#include <wx/tokenzr.h>
#include <wx/dc.h>
#include <wx/settings.h>
#include <wx/event.h> // Needed for textentry.h on MSW
#include <wx/textentry.h>
#include <widgets/wx_grid.h>
#include <widgets/ui_common.h>
@ -34,6 +36,21 @@
#define MIN_GRIDCELL_MARGIN FromDIP( 3 )
void WX_GRID::CellEditorSetMargins( wxTextEntryBase* aEntry )
{
// This is consistent with wxGridCellTextEditor. But works differently across platforms or course.
aEntry->SetMargins( 0, 0 );
}
void WX_GRID::CellEditorTransformSizeRect( wxRect& aRect )
{
#if defined( __WXMSW__ ) || defined( __WXGTK__ )
aRect.Deflate( 2 );
#endif
}
wxColour getBorderColour()
{
KIGFX::COLOR4D bg = wxSystemSettings::GetColour( wxSYS_COLOUR_FRAMEBK );

17
include/validators.h

@ -50,23 +50,6 @@
#define LABELUSERFIELD_V 200
/**
* This class works around a bug in wxGrid where the first keystroke doesn't get sent through
* the validator if the editor wasn't already open.
*/
class GRID_CELL_TEXT_EDITOR : public wxGridCellTextEditor
{
public:
GRID_CELL_TEXT_EDITOR();
virtual void SetValidator( const wxValidator& validator ) override;
virtual void StartingKey( wxKeyEvent& event ) override;
protected:
std::unique_ptr<wxValidator> m_validator;
};
/**
* This class provides a custom wxValidator object for limiting the allowable characters when
* defining footprint names. Since the introduction of the PRETTY footprint library format,

22
include/widgets/grid_text_helpers.h

@ -22,6 +22,7 @@
#define KICAD_GRID_TEXT_HELPERS_H
#include <functional>
#include <memory>
#include <wx/generic/gridctrl.h>
class wxGrid;
@ -29,6 +30,26 @@ class wxStyledTextCtrl;
class wxStyledTextEvent;
class SCINTILLA_TRICKS;
/**
* This class works around a bug in wxGrid where the first keystroke doesn't get sent through
* the validator if the editor wasn't already open.
*/
class GRID_CELL_TEXT_EDITOR : public wxGridCellTextEditor
{
public:
GRID_CELL_TEXT_EDITOR();
void SetSize( const wxRect& aRect ) override;
virtual void SetValidator( const wxValidator& validator ) override;
virtual void StartingKey( wxKeyEvent& event ) override;
protected:
std::unique_ptr<wxValidator> m_validator;
};
/**
* A text renderer that can unescape text for display
* This is useful where it's desired to keep the underlying storage escaped.
@ -51,6 +72,7 @@ public:
GRID_CELL_STC_EDITOR( bool aIgnoreCase,
std::function<void( wxStyledTextEvent&, SCINTILLA_TRICKS* )> aOnChar );
void SetSize( const wxRect& aRect ) override;
void Create( wxWindow* aParent, wxWindowID aId, wxEvtHandler* aEventHandler ) override;
wxGridCellEditor* Clone() const override

12
include/widgets/wx_grid.h

@ -34,6 +34,8 @@
#include <units_provider.h>
#include <libeval/numeric_evaluator.h>
class wxTextEntryBase;
class WX_GRID : public wxGrid
{
@ -150,6 +152,16 @@ public:
DeleteRows( 0, GetNumberRows() );
}
/**
* 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 );
protected:
/**
* A re-implementation of wxGrid::DrawColLabel which left-aligns the first column and draws

3
pcbnew/fp_text_grid_table.cpp

@ -29,7 +29,8 @@
#include <pcb_base_frame.h>
#include <footprint.h>
#include "grid_layer_box_helpers.h"
#include "widgets/grid_text_button_helpers.h"
#include <widgets/grid_text_button_helpers.h>
#include <widgets/grid_text_helpers.h>
enum
{

Loading…
Cancel
Save