Commit 761375dd authored by Maciej Suminski's avatar Maciej Suminski

More compatibility fixes.

parent 3eaef97a
......@@ -67,7 +67,6 @@ EDA_DRAW_PANEL_GAL::EDA_DRAW_PANEL_GAL( wxWindow* aParentWindow, wxWindowID aWin
m_viewControls = new KIGFX::WX_VIEW_CONTROLS( m_view, this );
Connect( wxEVT_PAINT, wxPaintEventHandler( EDA_DRAW_PANEL_GAL::onPaint ), NULL, this );
Connect( wxEVT_SIZE, wxSizeEventHandler( EDA_DRAW_PANEL_GAL::onSize ), NULL, this );
/* Generic events for the Tool Dispatcher */
......@@ -184,10 +183,21 @@ void EDA_DRAW_PANEL_GAL::Refresh( bool eraseBackground, const wxRect* rect )
}
void EDA_DRAW_PANEL_GAL::StartDrawing()
{
m_pendingRefresh = false;
Connect( wxEVT_PAINT, wxPaintEventHandler( EDA_DRAW_PANEL_GAL::onPaint ), NULL, this );
wxPaintEvent redrawEvent;
wxPostEvent( this, redrawEvent );
}
void EDA_DRAW_PANEL_GAL::StopDrawing()
{
Disconnect( wxEVT_PAINT, wxPaintEventHandler( EDA_DRAW_PANEL_GAL::onPaint ), NULL, this );
m_pendingRefresh = true;
m_refreshTimer.Stop();
Disconnect( wxEVT_PAINT, wxPaintEventHandler( EDA_DRAW_PANEL_GAL::onPaint ), NULL, this );
}
......@@ -198,8 +208,7 @@ void EDA_DRAW_PANEL_GAL::SwitchBackend( GalType aGalType )
return;
// Prevent refreshing canvas during backend switch
m_pendingRefresh = true;
m_refreshTimer.Stop();
StopDrawing();
delete m_gal;
......@@ -228,7 +237,6 @@ void EDA_DRAW_PANEL_GAL::SwitchBackend( GalType aGalType )
m_view->SetGAL( m_gal );
m_currentGal = aGalType;
m_pendingRefresh = false;
}
......
......@@ -110,7 +110,7 @@ void CONTEXT_MENU::Add( const TOOL_ACTION& aAction )
{
int key = aAction.GetHotKey() & ~MD_MODIFIER_MASK;
int mod = aAction.GetHotKey() & MD_MODIFIER_MASK;
wxAcceleratorEntryFlags flags = wxACCEL_NORMAL;
int flags = wxACCEL_NORMAL;
switch( mod )
{
......
......@@ -26,8 +26,12 @@
#include <wx/stattext.h>
#include <wx/sizer.h>
#include <wx/textctrl.h>
#include <wx/valnum.h>
#include <limits>
#include <base_units.h>
#if wxCHECK_VERSION( 2, 9, 0 )
#include <wx/valnum.h>
#endif
#include <boost/optional.hpp>
WX_UNIT_TEXT::WX_UNIT_TEXT( wxWindow* aParent, const wxString& aLabel, double aValue, double aStep ) :
wxPanel( aParent, wxID_ANY ),
......@@ -47,22 +51,29 @@ WX_UNIT_TEXT::WX_UNIT_TEXT( wxWindow* aParent, const wxString& aLabel, double aV
m_inputLabel->SetMinSize( size );
sizer->Add( m_inputLabel, 1, wxALIGN_CENTER_VERTICAL | wxALL | wxEXPAND, 5 );
wxFloatingPointValidator<double> validator( 4, NULL, wxNUM_VAL_NO_TRAILING_ZEROES );
validator.SetRange( 0.0, std::numeric_limits<double>::max() );
// Main input control
m_inputValue = new wxTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize,
wxTE_PROCESS_ENTER );
m_inputValue->SetValidator( validator );
SetValue( aValue );
sizer->Add( m_inputValue, 0, wxALIGN_CENTER_VERTICAL | wxALL );
#if wxCHECK_VERSION( 2, 9, 0 ) // Sorry guys, I am tired of dealing with 2.8 compatibility
wxFloatingPointValidator<double> validator( 4, NULL, wxNUM_VAL_NO_TRAILING_ZEROES );
validator.SetRange( 0.0, std::numeric_limits<double>::max() );
m_inputValue->SetValidator( validator );
// Spin buttons for modifying values using the mouse
m_spinButton = new wxSpinButton( this, wxID_ANY );
m_spinButton->SetRange( std::numeric_limits<int>::min(), std::numeric_limits<int>::max() );
m_spinButton->SetCanFocus( false );
sizer->Add( m_spinButton, 0, wxALIGN_CENTER_VERTICAL | wxALL );
Connect( wxEVT_SPIN_UP, wxSpinEventHandler( WX_UNIT_TEXT::onSpinUpEvent ), NULL, this );
Connect( wxEVT_SPIN_DOWN, wxSpinEventHandler( WX_UNIT_TEXT::onSpinDownEvent ), NULL, this );
#endif
sizer->AddSpacer( 5 );
// Create units label
......@@ -72,10 +83,6 @@ WX_UNIT_TEXT::WX_UNIT_TEXT( wxWindow* aParent, const wxString& aLabel, double aV
SetSizer( sizer );
Layout();
Connect( wxEVT_SPIN_UP, wxSpinEventHandler( WX_UNIT_TEXT::onSpinUpEvent ), NULL, this );
Connect( wxEVT_SPIN_DOWN, wxSpinEventHandler( WX_UNIT_TEXT::onSpinDownEvent ), NULL, this );
Connect( wxEVT_TEXT_ENTER, wxCommandEventHandler( WX_UNIT_TEXT::onEnter ), NULL, this );
}
......@@ -98,49 +105,87 @@ void WX_UNIT_TEXT::SetValue( double aValue )
if( aValue >= 0.0 )
{
m_inputValue->SetValue( Double2Str( aValue ) );
m_inputValue->SetValue( wxString( Double2Str( aValue ).c_str(), wxConvUTF8 ) );
m_inputValue->MarkDirty();
}
}
double WX_UNIT_TEXT::GetValue( EDA_UNITS_T aUnit ) const
/*boost::optional<double> WX_UNIT_TEXT::GetValue( EDA_UNITS_T aUnit ) const
{
assert( false ); // TODO
if( aUnit == m_units )
return GetValue(); // no conversion needed
switch( m_units )
{
case MILLIMETRES:
switch( aUnit )
{
case INCHES:
iu = Mils2iu( GetValue() * 1000.0 );
break;
case UNSCALED_UNITS:
iu = GetValue();
break;
}
break;
case INCHES:
switch( aUnit )
{
case MILLIMETRES:
return Mils2mm( GetValue() * 1000.0 );
break;
case UNSCALED_UNITS:
return Mils2iu( GetValue() * 1000.0 );
break;
}
break;
case UNSCALED_UNITS:
switch( aUnit )
{
case MILLIMETRES:
return Iu2Mils( GetValue() ) / 1000.0;
break;
// case INCHES:
// return
// break;
}
break;
}
assert( false ); // seems that there are some conversions missing
return 0.0;
}
}*/
double WX_UNIT_TEXT::GetValue() const
boost::optional<double> WX_UNIT_TEXT::GetValue() const
{
wxString text = m_inputValue->GetValue();
double value;
if( !text.ToDouble( &value ) )
value = 0.0;
return boost::optional<double>();
return value;
return boost::optional<double>( value );
}
void WX_UNIT_TEXT::onSpinUpEvent( wxSpinEvent& aEvent )
{
SetValue( GetValue() + m_step );
SetValue( *GetValue() + m_step );
}
void WX_UNIT_TEXT::onSpinDownEvent( wxSpinEvent& aEvent )
{
double newValue = GetValue() - m_step;
double newValue = *GetValue() - m_step;
if( newValue >= 0.0 )
SetValue( newValue );
}
void WX_UNIT_TEXT::onEnter( wxCommandEvent& aEvent )
{
// Move focus to the next widget
Navigate();
}
......@@ -111,9 +111,16 @@ public:
m_eventDispatcher = aEventDispatcher;
}
/**
* Function StartDrawing()
* Begins drawing if it was stopped previously.
*/
void StartDrawing();
/**
* Function StopDrawing()
* Prevents the GAL canvas from further drawing till it is recreated.
* Prevents the GAL canvas from further drawing till it is recreated
* or StartDrawing() is called.
*/
void StopDrawing();
......
......@@ -28,6 +28,11 @@
#include <common.h>
#include <wx/spinbutt.h>
namespace boost
{
template <class T>
class optional;
}
class wxTextCtrl;
class wxSpinButton;
class wxStaticText;
......@@ -42,7 +47,7 @@ public:
* @param aValue is the initial value for the control.
* @param aStep is the step size when using spin buttons.
*/
WX_UNIT_TEXT( wxWindow* aParent, const wxString& aLabel = wxString( "Size:" ),
WX_UNIT_TEXT( wxWindow* aParent, const wxString& aLabel = _( "Size:" ),
double aValue = 0.0, double aStep = 0.1 );
virtual ~WX_UNIT_TEXT();
......@@ -69,13 +74,13 @@ public:
* they are converted first).
* @param aUnits is the wanted unit.
*/
virtual double GetValue( EDA_UNITS_T aUnits ) const;
//virtual double GetValue( EDA_UNITS_T aUnits ) const;
/**
* Function GetValue
* Returns the current value in currently used units.
*/
virtual double GetValue() const;
virtual boost::optional<double> GetValue() const;
/**
* Function GetUnits
......@@ -114,9 +119,6 @@ protected:
///> Spin down button click event handler.
void onSpinDownEvent( wxSpinEvent& aEvent );
///> On Enter press event handler.
void onEnter( wxCommandEvent& aEvent );
///> Label for the input (e.g. "Size:")
wxStaticText* m_inputLabel;
......
......@@ -159,6 +159,9 @@ PCB_BASE_FRAME::PCB_BASE_FRAME( KIWAY* aKiway, wxWindow* aParent, FRAME_T aFrame
this, -1, wxPoint( 0, 0 ), m_FrameSize,
EDA_DRAW_PANEL_GAL::GAL_TYPE_CAIRO ) );
// GAL should not be active yet
GetGalCanvas()->StopDrawing();
// Hide by default, it has to be explicitly shown
GetGalCanvas()->Hide();
......
......@@ -673,10 +673,13 @@ void PCB_EDIT_FRAME::UseGalCanvas( bool aEnable )
if( aEnable )
{
ViewReloadBoard( m_Pcb );
GetGalCanvas()->GetView()->RecacheAllItems();
m_toolManager.SetEnvironment( m_Pcb, GetGalCanvas()->GetView(),
GetGalCanvas()->GetViewControls(), this );
m_toolManager.ResetTools( TOOL_BASE::GAL_SWITCH );
m_toolManager.ResetTools( TOOL_BASE::MODEL_RELOAD );
GetGalCanvas()->StartDrawing();
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment