2008-09-12 20:57:41 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: samples/propgrid/sampleprops.cpp
|
|
|
|
// Purpose: wxPropertyGrid Sample Properties
|
|
|
|
// Author: Jaakko Salli
|
|
|
|
// Modified by:
|
|
|
|
// Created: 2006-03-05
|
|
|
|
// Copyright: (c) Jaakko Salli
|
2010-07-13 13:29:13 +00:00
|
|
|
// Licence: wxWindows licence
|
2008-09-12 20:57:41 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// For compilers that support precompilation, includes "wx/wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// for all others, include the necessary headers (this file is usually all you
|
|
|
|
// need because it includes almost all "standard" wxWidgets headers)
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#endif
|
|
|
|
|
2011-01-07 05:26:57 +00:00
|
|
|
#include "wx/fontdlg.h"
|
2014-05-17 17:22:30 +00:00
|
|
|
#include "wx/numformatter.h"
|
2011-01-07 05:26:57 +00:00
|
|
|
|
2008-09-12 20:57:41 +00:00
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
#include <wx/propgrid/propgrid.h>
|
|
|
|
#include <wx/propgrid/advprops.h>
|
|
|
|
|
|
|
|
#ifndef WX_PROPGRID_SAMPLEPROPS_H
|
|
|
|
#include "sampleprops.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
// wxFontDataProperty
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Dummy comparison required by value type implementation.
|
|
|
|
bool operator == (const wxFontData&, const wxFontData&)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Custom version of wxFontProperty that also holds colour in the value.
|
|
|
|
// Original version by Vladimir Vainer.
|
|
|
|
|
2008-09-16 15:55:53 +00:00
|
|
|
IMPLEMENT_VARIANT_OBJECT_SHALLOWCMP(wxFontData)
|
2008-09-12 20:57:41 +00:00
|
|
|
|
|
|
|
WX_PG_IMPLEMENT_PROPERTY_CLASS(wxFontDataProperty,wxFontProperty,
|
|
|
|
wxFontData,const wxFontData&,TextCtrlAndButton)
|
|
|
|
|
|
|
|
wxFontDataProperty::wxFontDataProperty( const wxString& label, const wxString& name,
|
|
|
|
const wxFontData& value ) : wxFontProperty(label,name,value.GetInitialFont())
|
|
|
|
{
|
2008-09-16 15:55:53 +00:00
|
|
|
wxFontData fontData(value);
|
2008-09-12 20:57:41 +00:00
|
|
|
|
|
|
|
// Fix value.
|
2014-05-22 14:35:55 +00:00
|
|
|
wxFont font;
|
|
|
|
font << m_value; // Get font data from base object.
|
|
|
|
fontData.SetChosenFont(font);
|
2011-05-03 16:29:04 +00:00
|
|
|
if ( !fontData.GetColour().IsOk() )
|
2008-09-12 20:57:41 +00:00
|
|
|
fontData.SetColour(*wxBLACK);
|
|
|
|
|
2008-09-16 15:55:53 +00:00
|
|
|
// Set initial value - should be done in a simpler way like this
|
|
|
|
// (instead of calling SetValue) in derived (wxObject) properties.
|
2014-05-22 14:35:55 +00:00
|
|
|
m_value_wxFontData << fontData;
|
2008-09-16 15:55:53 +00:00
|
|
|
|
2008-09-12 20:57:41 +00:00
|
|
|
// Add extra children.
|
2009-03-12 18:17:55 +00:00
|
|
|
AddPrivateChild( new wxColourProperty(_("Colour"), wxPG_LABEL,
|
|
|
|
fontData.GetColour() ) );
|
2008-09-12 20:57:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wxFontDataProperty::~wxFontDataProperty () { }
|
|
|
|
|
|
|
|
void wxFontDataProperty::OnSetValue()
|
|
|
|
{
|
2008-09-16 15:55:53 +00:00
|
|
|
if ( m_value.GetType() != "wxFontData" )
|
2008-09-12 20:57:41 +00:00
|
|
|
{
|
2008-09-16 15:55:53 +00:00
|
|
|
if ( m_value.GetType() == "wxFont" )
|
2008-09-12 20:57:41 +00:00
|
|
|
{
|
2008-09-16 15:55:53 +00:00
|
|
|
wxFont font;
|
|
|
|
font << m_value;
|
2008-09-12 20:57:41 +00:00
|
|
|
wxFontData fontData;
|
2008-09-16 15:55:53 +00:00
|
|
|
fontData.SetChosenFont(font);
|
|
|
|
if ( !m_value_wxFontData.IsNull() )
|
|
|
|
{
|
|
|
|
wxFontData oldFontData;
|
|
|
|
oldFontData << m_value_wxFontData;
|
|
|
|
fontData.SetColour(oldFontData.GetColour());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fontData.SetColour(*wxBLACK);
|
|
|
|
}
|
|
|
|
wxVariant variant;
|
|
|
|
variant << fontData;
|
|
|
|
m_value_wxFontData = variant;
|
2008-09-12 20:57:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxFAIL_MSG(wxT("Value to wxFontDataProperty must be eithe wxFontData or wxFont"));
|
|
|
|
}
|
|
|
|
}
|
2008-09-16 15:55:53 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// Set m_value to wxFont so that wxFontProperty methods will work
|
|
|
|
// correctly.
|
|
|
|
m_value_wxFontData = m_value;
|
|
|
|
|
|
|
|
wxFontData fontData;
|
|
|
|
fontData << m_value_wxFontData;
|
2008-09-12 20:57:41 +00:00
|
|
|
|
2008-09-16 15:55:53 +00:00
|
|
|
wxFont font = fontData.GetChosenFont();
|
2011-05-03 16:29:04 +00:00
|
|
|
if ( !font.IsOk() )
|
2014-01-11 14:25:30 +00:00
|
|
|
font = wxFontInfo(10).Family(wxFONTFAMILY_SWISS);
|
2008-09-12 20:57:41 +00:00
|
|
|
|
2008-09-16 15:55:53 +00:00
|
|
|
m_value = WXVARIANT(font);
|
|
|
|
}
|
2008-09-12 20:57:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wxVariant wxFontDataProperty::DoGetValue() const
|
|
|
|
{
|
|
|
|
return m_value_wxFontData;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Must re-create font dialog displayer.
|
|
|
|
bool wxFontDataProperty::OnEvent( wxPropertyGrid* propgrid,
|
|
|
|
wxWindow* WXUNUSED(primary), wxEvent& event )
|
|
|
|
{
|
|
|
|
if ( propgrid->IsMainButtonEvent(event) )
|
|
|
|
{
|
2008-10-10 15:22:08 +00:00
|
|
|
wxVariant useValue = propgrid->GetUncommittedPropertyValue();
|
2008-09-12 20:57:41 +00:00
|
|
|
|
2008-09-16 15:55:53 +00:00
|
|
|
wxFontData fontData;
|
2008-10-08 18:15:10 +00:00
|
|
|
fontData << useValue;
|
2008-09-12 20:57:41 +00:00
|
|
|
|
|
|
|
fontData.SetInitialFont(fontData.GetChosenFont());
|
|
|
|
|
|
|
|
wxFontDialog dlg(propgrid, fontData);
|
|
|
|
|
|
|
|
if ( dlg.ShowModal() == wxID_OK )
|
|
|
|
{
|
2008-09-16 15:55:53 +00:00
|
|
|
wxVariant variant;
|
|
|
|
variant << dlg.GetFontData();
|
|
|
|
SetValueInEvent( variant );
|
2008-09-12 20:57:41 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void wxFontDataProperty::RefreshChildren()
|
|
|
|
{
|
|
|
|
wxFontProperty::RefreshChildren();
|
2008-09-16 15:55:53 +00:00
|
|
|
if ( GetChildCount() < 6 ) // Number is count of wxFontProperty's children + 1.
|
2008-09-12 20:57:41 +00:00
|
|
|
return;
|
2008-09-16 15:55:53 +00:00
|
|
|
wxFontData fontData; fontData << m_value_wxFontData;
|
2008-09-12 20:57:41 +00:00
|
|
|
wxVariant variant; variant << fontData.GetColour();
|
|
|
|
Item(6)->SetValue( variant );
|
|
|
|
}
|
|
|
|
|
2009-06-07 07:52:53 +00:00
|
|
|
wxVariant wxFontDataProperty::ChildChanged( wxVariant& thisValue,
|
|
|
|
int childIndex,
|
|
|
|
wxVariant& childValue ) const
|
2008-09-12 20:57:41 +00:00
|
|
|
{
|
2008-09-16 15:55:53 +00:00
|
|
|
wxFontData fontData;
|
|
|
|
fontData << thisValue;
|
2008-09-12 20:57:41 +00:00
|
|
|
wxColour col;
|
|
|
|
wxVariant variant;
|
|
|
|
|
|
|
|
switch ( childIndex )
|
|
|
|
{
|
|
|
|
case 6:
|
|
|
|
col << childValue;
|
|
|
|
fontData.SetColour( col );
|
|
|
|
break;
|
|
|
|
default:
|
2008-09-16 15:55:53 +00:00
|
|
|
// Transfer from subset to superset.
|
|
|
|
wxFont font = fontData.GetChosenFont();
|
|
|
|
variant = WXVARIANT(font);
|
2014-05-22 14:35:55 +00:00
|
|
|
variant = wxFontProperty::ChildChanged( variant, childIndex, childValue );
|
2008-09-16 15:55:53 +00:00
|
|
|
font << variant;
|
|
|
|
fontData.SetChosenFont(font);
|
2008-09-12 20:57:41 +00:00
|
|
|
}
|
2008-09-16 15:55:53 +00:00
|
|
|
|
2009-06-07 07:52:53 +00:00
|
|
|
wxVariant newVariant;
|
|
|
|
newVariant << fontData;
|
|
|
|
return newVariant;
|
2008-09-12 20:57:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
// wxSizeProperty
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
WX_PG_IMPLEMENT_PROPERTY_CLASS(wxSizeProperty,wxPGProperty,
|
|
|
|
wxSize,const wxSize&,TextCtrl)
|
|
|
|
|
|
|
|
wxSizeProperty::wxSizeProperty( const wxString& label, const wxString& name,
|
|
|
|
const wxSize& value) : wxPGProperty(label,name)
|
|
|
|
{
|
|
|
|
SetValueI(value);
|
2009-03-12 18:17:55 +00:00
|
|
|
AddPrivateChild( new wxIntProperty(wxT("Width"),wxPG_LABEL,value.x) );
|
|
|
|
AddPrivateChild( new wxIntProperty(wxT("Height"),wxPG_LABEL,value.y) );
|
2008-09-12 20:57:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wxSizeProperty::~wxSizeProperty() { }
|
|
|
|
|
|
|
|
void wxSizeProperty::RefreshChildren()
|
|
|
|
{
|
|
|
|
if ( !GetChildCount() ) return;
|
2008-09-16 15:55:53 +00:00
|
|
|
const wxSize& size = wxSizeRefFromVariant(m_value);
|
2008-09-12 20:57:41 +00:00
|
|
|
Item(0)->SetValue( (long)size.x );
|
|
|
|
Item(1)->SetValue( (long)size.y );
|
|
|
|
}
|
|
|
|
|
2009-06-07 07:52:53 +00:00
|
|
|
wxVariant wxSizeProperty::ChildChanged( wxVariant& thisValue,
|
|
|
|
int childIndex,
|
|
|
|
wxVariant& childValue ) const
|
2008-09-12 20:57:41 +00:00
|
|
|
{
|
2008-09-16 15:55:53 +00:00
|
|
|
wxSize& size = wxSizeRefFromVariant(thisValue);
|
2009-06-15 22:43:27 +00:00
|
|
|
int val = childValue.GetLong();
|
2008-09-12 20:57:41 +00:00
|
|
|
switch ( childIndex )
|
|
|
|
{
|
|
|
|
case 0: size.x = val; break;
|
|
|
|
case 1: size.y = val; break;
|
|
|
|
}
|
2009-06-07 07:52:53 +00:00
|
|
|
wxVariant newVariant;
|
|
|
|
newVariant << size;
|
|
|
|
return newVariant;
|
2008-09-12 20:57:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
// wxPointProperty
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
WX_PG_IMPLEMENT_PROPERTY_CLASS(wxPointProperty,wxPGProperty,
|
|
|
|
wxPoint,const wxPoint&,TextCtrl)
|
|
|
|
|
|
|
|
wxPointProperty::wxPointProperty( const wxString& label, const wxString& name,
|
|
|
|
const wxPoint& value) : wxPGProperty(label,name)
|
|
|
|
{
|
|
|
|
SetValueI(value);
|
2009-03-12 18:17:55 +00:00
|
|
|
AddPrivateChild( new wxIntProperty(wxT("X"),wxPG_LABEL,value.x) );
|
|
|
|
AddPrivateChild( new wxIntProperty(wxT("Y"),wxPG_LABEL,value.y) );
|
2008-09-12 20:57:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wxPointProperty::~wxPointProperty() { }
|
|
|
|
|
|
|
|
void wxPointProperty::RefreshChildren()
|
|
|
|
{
|
|
|
|
if ( !GetChildCount() ) return;
|
2008-09-16 15:55:53 +00:00
|
|
|
const wxPoint& point = wxPointRefFromVariant(m_value);
|
2008-09-12 20:57:41 +00:00
|
|
|
Item(0)->SetValue( (long)point.x );
|
|
|
|
Item(1)->SetValue( (long)point.y );
|
|
|
|
}
|
|
|
|
|
2009-06-07 07:52:53 +00:00
|
|
|
wxVariant wxPointProperty::ChildChanged( wxVariant& thisValue,
|
|
|
|
int childIndex,
|
|
|
|
wxVariant& childValue ) const
|
2008-09-12 20:57:41 +00:00
|
|
|
{
|
2008-09-16 15:55:53 +00:00
|
|
|
wxPoint& point = wxPointRefFromVariant(thisValue);
|
2009-06-15 22:43:27 +00:00
|
|
|
int val = childValue.GetLong();
|
2008-09-12 20:57:41 +00:00
|
|
|
switch ( childIndex )
|
|
|
|
{
|
|
|
|
case 0: point.x = val; break;
|
|
|
|
case 1: point.y = val; break;
|
|
|
|
}
|
2009-06-07 07:52:53 +00:00
|
|
|
wxVariant newVariant;
|
|
|
|
newVariant << point;
|
|
|
|
return newVariant;
|
2008-09-12 20:57:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
// Dirs Property
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
2010-07-11 17:04:23 +00:00
|
|
|
WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(wxDirsProperty, ',',
|
|
|
|
"Browse")
|
2008-09-12 20:57:41 +00:00
|
|
|
|
|
|
|
#if wxUSE_VALIDATORS
|
|
|
|
|
|
|
|
wxValidator* wxDirsProperty::DoGetValidator() const
|
|
|
|
{
|
|
|
|
return wxFileProperty::GetClassValidator();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
bool wxDirsProperty::OnCustomStringEdit( wxWindow* parent, wxString& value )
|
|
|
|
{
|
|
|
|
wxDirDialog dlg(parent,
|
|
|
|
_("Select a directory to be added to the list:"),
|
|
|
|
value,
|
|
|
|
0);
|
|
|
|
|
|
|
|
if ( dlg.ShowModal() == wxID_OK )
|
|
|
|
{
|
|
|
|
value = dlg.GetPath();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
// wxArrayDoubleEditorDialog
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// You can *almost* convert wxArrayDoubleEditorDialog to wxArrayXXXEditorDialog
|
|
|
|
// by replacing each ArrayDouble with ArrayXXX.
|
|
|
|
//
|
|
|
|
|
2010-07-10 15:30:35 +00:00
|
|
|
class wxArrayDoubleEditorDialog : public wxPGArrayEditorDialog
|
2008-09-12 20:57:41 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
wxArrayDoubleEditorDialog();
|
|
|
|
|
|
|
|
void Init();
|
|
|
|
|
|
|
|
wxArrayDoubleEditorDialog(wxWindow *parent,
|
|
|
|
const wxString& message,
|
|
|
|
const wxString& caption,
|
|
|
|
wxArrayDouble& array,
|
|
|
|
long style = wxAEDIALOG_STYLE,
|
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& sz = wxDefaultSize );
|
|
|
|
|
|
|
|
bool Create(wxWindow *parent,
|
|
|
|
const wxString& message,
|
|
|
|
const wxString& caption,
|
|
|
|
wxArrayDouble& array,
|
|
|
|
long style = wxAEDIALOG_STYLE,
|
|
|
|
const wxPoint& pos = wxDefaultPosition,
|
|
|
|
const wxSize& sz = wxDefaultSize );
|
|
|
|
|
|
|
|
const wxArrayDouble& GetArray() const { return m_array; }
|
|
|
|
|
|
|
|
// Extra method for this type of array
|
|
|
|
void SetPrecision ( int precision )
|
|
|
|
{
|
|
|
|
m_precision = precision;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
// Mandatory array of type
|
|
|
|
wxArrayDouble m_array;
|
|
|
|
|
|
|
|
int m_precision;
|
|
|
|
|
|
|
|
// Mandatory overridden methods
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual wxString ArrayGet( size_t index ) wxOVERRIDE;
|
|
|
|
virtual size_t ArrayGetCount() wxOVERRIDE;
|
|
|
|
virtual bool ArrayInsert( const wxString& str, int index ) wxOVERRIDE;
|
|
|
|
virtual bool ArraySet( size_t index, const wxString& str ) wxOVERRIDE;
|
|
|
|
virtual void ArrayRemoveAt( int index ) wxOVERRIDE;
|
|
|
|
virtual void ArraySwap( size_t first, size_t second ) wxOVERRIDE;
|
2008-09-12 20:57:41 +00:00
|
|
|
|
|
|
|
private:
|
2014-03-30 07:07:55 +00:00
|
|
|
wxDECLARE_DYNAMIC_CLASS_NO_COPY(wxArrayDoubleEditorDialog);
|
2008-09-12 20:57:41 +00:00
|
|
|
};
|
|
|
|
|
2010-07-10 15:30:35 +00:00
|
|
|
IMPLEMENT_DYNAMIC_CLASS(wxArrayDoubleEditorDialog, wxPGArrayEditorDialog)
|
2008-09-12 20:57:41 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Array dialog array access and manipulation
|
|
|
|
//
|
|
|
|
|
|
|
|
wxString wxArrayDoubleEditorDialog::ArrayGet( size_t index )
|
|
|
|
{
|
2014-05-17 17:22:30 +00:00
|
|
|
return wxNumberFormatter::ToString(
|
|
|
|
m_array[index], m_precision, wxNumberFormatter::Style_NoTrailingZeroes);
|
2008-09-12 20:57:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t wxArrayDoubleEditorDialog::ArrayGetCount()
|
|
|
|
{
|
|
|
|
return m_array.GetCount();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool wxArrayDoubleEditorDialog::ArrayInsert( const wxString& str, int index )
|
|
|
|
{
|
|
|
|
double d;
|
|
|
|
if ( !str.ToDouble(&d) )
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (index<0)
|
|
|
|
m_array.Add(d);
|
|
|
|
else
|
|
|
|
m_array.Insert(d,index);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool wxArrayDoubleEditorDialog::ArraySet( size_t index, const wxString& str )
|
|
|
|
{
|
|
|
|
double d;
|
|
|
|
if ( !str.ToDouble(&d) )
|
|
|
|
return FALSE;
|
|
|
|
m_array[index] = d;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void wxArrayDoubleEditorDialog::ArrayRemoveAt( int index )
|
|
|
|
{
|
|
|
|
m_array.RemoveAt(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
void wxArrayDoubleEditorDialog::ArraySwap( size_t first, size_t second )
|
|
|
|
{
|
|
|
|
double a = m_array[first];
|
|
|
|
double b = m_array[second];
|
|
|
|
m_array[first] = b;
|
|
|
|
m_array[second] = a;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Array dialog construction etc.
|
|
|
|
//
|
|
|
|
|
|
|
|
wxArrayDoubleEditorDialog::wxArrayDoubleEditorDialog()
|
2010-07-10 15:30:35 +00:00
|
|
|
: wxPGArrayEditorDialog()
|
2008-09-12 20:57:41 +00:00
|
|
|
{
|
|
|
|
Init();
|
|
|
|
}
|
|
|
|
|
|
|
|
void wxArrayDoubleEditorDialog::Init()
|
|
|
|
{
|
2010-07-10 15:30:35 +00:00
|
|
|
wxPGArrayEditorDialog::Init();
|
2008-09-12 20:57:41 +00:00
|
|
|
SetPrecision(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
wxArrayDoubleEditorDialog::wxArrayDoubleEditorDialog(wxWindow *parent,
|
|
|
|
const wxString& message,
|
|
|
|
const wxString& caption,
|
|
|
|
wxArrayDouble& array,
|
|
|
|
long style,
|
|
|
|
const wxPoint& pos,
|
|
|
|
const wxSize& sz )
|
2010-07-10 15:30:35 +00:00
|
|
|
: wxPGArrayEditorDialog()
|
2008-09-12 20:57:41 +00:00
|
|
|
{
|
|
|
|
Init();
|
|
|
|
Create(parent,message,caption,array,style,pos,sz);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool wxArrayDoubleEditorDialog::Create(wxWindow *parent,
|
|
|
|
const wxString& message,
|
|
|
|
const wxString& caption,
|
|
|
|
wxArrayDouble& array,
|
|
|
|
long style,
|
|
|
|
const wxPoint& pos,
|
|
|
|
const wxSize& sz )
|
|
|
|
{
|
|
|
|
|
|
|
|
m_array = array;
|
|
|
|
|
2010-07-10 15:30:35 +00:00
|
|
|
return wxPGArrayEditorDialog::Create (parent,message,caption,style,pos,sz);
|
2008-09-12 20:57:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
// wxArrayDoubleProperty
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include <math.h> // for fabs
|
|
|
|
|
|
|
|
// Comparison required by value type implementation.
|
|
|
|
bool operator == (const wxArrayDouble& a, const wxArrayDouble& b)
|
|
|
|
{
|
|
|
|
if ( a.GetCount() != b.GetCount() )
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
for ( i=0; i<a.GetCount(); i++ )
|
|
|
|
{
|
|
|
|
// Can't do direct equality comparison with floating point numbers.
|
|
|
|
if ( fabs(a[i] - b[i]) > 0.0000000001 )
|
|
|
|
{
|
|
|
|
//wxLogDebug(wxT("%f != %f"),a[i],b[i]);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2008-09-16 15:55:53 +00:00
|
|
|
WX_PG_IMPLEMENT_VARIANT_DATA_DUMMY_EQ(wxArrayDouble)
|
2008-09-12 20:57:41 +00:00
|
|
|
|
|
|
|
WX_PG_IMPLEMENT_PROPERTY_CLASS(wxArrayDoubleProperty,
|
|
|
|
wxPGProperty,
|
|
|
|
wxArrayDouble,
|
|
|
|
const wxArrayDouble&,
|
|
|
|
TextCtrlAndButton)
|
|
|
|
|
|
|
|
|
|
|
|
wxArrayDoubleProperty::wxArrayDoubleProperty (const wxString& label,
|
|
|
|
const wxString& name,
|
|
|
|
const wxArrayDouble& array )
|
|
|
|
: wxPGProperty(label,name)
|
|
|
|
{
|
|
|
|
m_precision = -1;
|
|
|
|
|
|
|
|
//
|
|
|
|
// Need to figure out delimiter needed for this locale
|
|
|
|
// (ie. can't use comma when comma acts as decimal point in float).
|
|
|
|
wxChar use_delimiter = wxT(',');
|
|
|
|
|
|
|
|
if (wxString::Format(wxT("%.2f"),12.34).Find(use_delimiter) >= 0)
|
|
|
|
use_delimiter = wxT(';');
|
|
|
|
|
|
|
|
m_delimiter = use_delimiter;
|
|
|
|
|
2008-09-16 15:55:53 +00:00
|
|
|
SetValue( WXVARIANT(array) );
|
2008-09-12 20:57:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wxArrayDoubleProperty::~wxArrayDoubleProperty () { }
|
|
|
|
|
|
|
|
void wxArrayDoubleProperty::OnSetValue()
|
|
|
|
{
|
2008-10-16 17:19:50 +00:00
|
|
|
// Generate cached display string, to optimize grid drawing
|
2008-09-12 20:57:41 +00:00
|
|
|
GenerateValueAsString( m_display, m_precision, true );
|
|
|
|
}
|
|
|
|
|
2008-10-16 17:19:50 +00:00
|
|
|
wxString wxArrayDoubleProperty::ValueToString( wxVariant& value,
|
|
|
|
int argFlags ) const
|
2008-09-12 20:57:41 +00:00
|
|
|
{
|
|
|
|
wxString s;
|
2008-10-16 17:19:50 +00:00
|
|
|
|
|
|
|
if ( argFlags & wxPG_FULL_VALUE )
|
|
|
|
{
|
|
|
|
GenerateValueAsString(s,-1,false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
//
|
|
|
|
// Display cached string only if value truly matches m_value
|
|
|
|
if ( value.GetData() == m_value.GetData() )
|
|
|
|
return m_display;
|
|
|
|
else
|
|
|
|
GenerateValueAsString( s, m_precision, true );
|
|
|
|
}
|
|
|
|
|
2008-09-12 20:57:41 +00:00
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
void wxArrayDoubleProperty::GenerateValueAsString( wxString& target, int prec, bool removeZeroes ) const
|
|
|
|
{
|
|
|
|
wxChar between[3] = wxT(", ");
|
|
|
|
size_t i;
|
|
|
|
|
|
|
|
between[0] = m_delimiter;
|
|
|
|
|
|
|
|
target.Empty();
|
|
|
|
|
2008-09-16 15:55:53 +00:00
|
|
|
const wxArrayDouble& value = wxArrayDoubleRefFromVariant(m_value);
|
2014-05-17 17:22:30 +00:00
|
|
|
wxNumberFormatter::Style style = wxNumberFormatter::Style_None;
|
|
|
|
if (removeZeroes)
|
|
|
|
style = wxNumberFormatter::Style_NoTrailingZeroes;
|
2008-09-12 20:57:41 +00:00
|
|
|
|
|
|
|
for ( i=0; i<value.GetCount(); i++ )
|
|
|
|
{
|
2014-05-17 17:22:30 +00:00
|
|
|
target += wxNumberFormatter::ToString(value[i], prec, style);
|
2008-09-12 20:57:41 +00:00
|
|
|
|
|
|
|
if ( i<(value.GetCount()-1) )
|
|
|
|
target += between;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool wxArrayDoubleProperty::OnEvent( wxPropertyGrid* propgrid,
|
|
|
|
wxWindow* WXUNUSED(primary),
|
|
|
|
wxEvent& event)
|
|
|
|
{
|
|
|
|
if ( propgrid->IsMainButtonEvent(event) )
|
|
|
|
{
|
|
|
|
// Update the value in case of last minute changes
|
2008-10-10 15:22:08 +00:00
|
|
|
wxVariant useValue = propgrid->GetUncommittedPropertyValue();
|
2008-10-08 18:15:10 +00:00
|
|
|
|
|
|
|
wxArrayDouble& value = wxArrayDoubleRefFromVariant(useValue);
|
2008-09-12 20:57:41 +00:00
|
|
|
|
|
|
|
// Create editor dialog.
|
|
|
|
wxArrayDoubleEditorDialog dlg;
|
|
|
|
dlg.SetPrecision(m_precision);
|
|
|
|
dlg.Create( propgrid, wxEmptyString, m_label, value );
|
|
|
|
dlg.Move( propgrid->GetGoodEditorDialogPosition(this,dlg.GetSize()) );
|
|
|
|
|
|
|
|
// Execute editor dialog
|
|
|
|
int res = dlg.ShowModal();
|
|
|
|
if ( res == wxID_OK && dlg.IsModified() )
|
|
|
|
{
|
2008-09-16 15:55:53 +00:00
|
|
|
SetValueInEvent( WXVARIANT(dlg.GetArray()) );
|
2008-09-12 20:57:41 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool wxArrayDoubleProperty::StringToValue( wxVariant& variant, const wxString& text, int ) const
|
|
|
|
{
|
|
|
|
double tval;
|
|
|
|
wxString tstr;
|
|
|
|
// Add values to a temporary array so that in case
|
|
|
|
// of error we can opt not to use them.
|
|
|
|
wxArrayDouble new_array;
|
|
|
|
|
|
|
|
bool ok = true;
|
|
|
|
|
|
|
|
wxChar delimiter = m_delimiter;
|
|
|
|
|
|
|
|
WX_PG_TOKENIZER1_BEGIN(text,delimiter)
|
|
|
|
|
2011-01-22 14:38:36 +00:00
|
|
|
if ( !token.empty() )
|
2008-09-12 20:57:41 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
// If token was invalid, exit the loop now
|
|
|
|
if ( !token.ToDouble(&tval) )
|
|
|
|
{
|
|
|
|
tstr.Printf ( _("\"%s\" is not a floating-point number."), token.c_str() );
|
|
|
|
ok = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// TODO: Put validator code here
|
|
|
|
|
|
|
|
new_array.Add(tval);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
WX_PG_TOKENIZER1_END()
|
|
|
|
|
|
|
|
// When invalid token found, show error message and don't change anything
|
|
|
|
if ( !ok )
|
|
|
|
{
|
|
|
|
//ShowError( tstr );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2008-09-16 15:55:53 +00:00
|
|
|
if ( !(wxArrayDoubleRefFromVariant(m_value) == new_array) )
|
2008-09-12 20:57:41 +00:00
|
|
|
{
|
2008-09-16 15:55:53 +00:00
|
|
|
variant = WXVARIANT(new_array);
|
2008-09-12 20:57:41 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool wxArrayDoubleProperty::DoSetAttribute( const wxString& name, wxVariant& value )
|
|
|
|
{
|
|
|
|
if ( name == wxPG_FLOAT_PRECISION )
|
|
|
|
{
|
|
|
|
m_precision = value.GetLong();
|
|
|
|
GenerateValueAsString( m_display, m_precision, true );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|