1
/////////////////////////////////////////////////////////////////////////////
3
// Purpose: wxPropertyGrid Advanced Properties (font, colour, etc.)
4
// Author: Jaakko Salli
6
// Created: Sep-25-2004
8
// Copyright: (c) Jaakko Salli
9
// Licence: wxWindows license
10
/////////////////////////////////////////////////////////////////////////////
12
// For compilers that support precompilation, includes "wx/wx.h".
13
#include "wx/wxprec.h"
21
#include "wx/object.h"
23
#include "wx/string.h"
26
#include "wx/window.h"
29
#include "wx/dcclient.h"
30
#include "wx/button.h"
33
#include "wx/cursor.h"
34
#include "wx/dialog.h"
35
#include "wx/settings.h"
36
#include "wx/msgdlg.h"
37
#include "wx/choice.h"
38
#include "wx/stattext.h"
39
#include "wx/textctrl.h"
40
#include "wx/scrolwin.h"
41
#include "wx/dirdlg.h"
42
#include "wx/combobox.h"
43
#include "wx/layout.h"
45
#include "wx/textdlg.h"
46
#include "wx/filedlg.h"
50
#define __wxPG_SOURCE_FILE__
52
#include <wx/propgrid/propgrid.h>
54
#if wxPG_INCLUDE_ADVPROPS
56
#include <wx/propgrid/propdev.h>
58
#include <wx/propgrid/advprops.h>
61
#include <wx/msw/private.h>
62
#if wxCHECK_VERSION(2,9,0)
63
#include <wx/msw/dc.h>
67
// -----------------------------------------------------------------------
69
#if defined(__WXMSW__)
70
#define wxPG_CAN_DRAW_CURSOR 1
71
#elif defined(__WXGTK__)
72
#define wxPG_CAN_DRAW_CURSOR 0
73
#elif defined(__WXMAC__)
74
#define wxPG_CAN_DRAW_CURSOR 0
76
#define wxPG_CAN_DRAW_CURSOR 0
80
// -----------------------------------------------------------------------
82
// -----------------------------------------------------------------------
85
// Implement dynamic class for type value.
86
IMPLEMENT_DYNAMIC_CLASS(wxColourPropertyValue, wxObject)
88
bool operator == (const wxColourPropertyValue& a, const wxColourPropertyValue& b)
90
return ( ( a.m_colour == b.m_colour ) && (a.m_type == b.m_type) );
93
bool operator == (const wxArrayInt& array1, const wxArrayInt& array2)
95
if ( array1.GetCount() != array2.GetCount() )
98
for ( i=0; i<array1.GetCount(); i++ )
100
if ( array1[i] != array2[i] )
106
// -----------------------------------------------------------------------
107
// wxSpinCtrl-based property editor
108
// -----------------------------------------------------------------------
113
#define IS_MOTION_SPIN_SUPPORTED 1
115
#define IS_MOTION_SPIN_SUPPORTED 0
118
#if IS_MOTION_SPIN_SUPPORTED
120
// This class implements ability to rapidly change "spin" value
121
// by moving mouse when one of the spin buttons is depressed.
122
class wxPGSpinButton : public wxSpinButton
125
wxPGSpinButton() : wxSpinButton()
128
m_hasCapture = false;
131
Connect( wxEVT_LEFT_DOWN,
132
(wxObjectEventFunction) (wxEventFunction)
133
(wxMouseEventFunction)&wxPGSpinButton::OnMouseEvent );
134
Connect( wxEVT_LEFT_UP,
135
(wxObjectEventFunction) (wxEventFunction)
136
(wxMouseEventFunction)&wxPGSpinButton::OnMouseEvent );
137
Connect( wxEVT_MOTION,
138
(wxObjectEventFunction) (wxEventFunction)
139
(wxMouseEventFunction)&wxPGSpinButton::OnMouseEvent );
140
#if wxCHECK_VERSION(2,8,0)
141
Connect( wxEVT_MOUSE_CAPTURE_LOST,
142
(wxObjectEventFunction) (wxEventFunction)
143
(wxMouseCaptureLostEventFunction)&wxPGSpinButton::OnMouseCaptureLost );
154
wxPoint m_ptPosition;
156
// Having a separate spins variable allows us to handle validation etc. for
157
// multiple spin events at once (with quick mouse movements there could be
158
// hundreds of 'spins' being done at once). Technically things like this
159
// should be stored in event (wxSpinEvent in this case), but there probably
160
// isn't anything there that can be reliably reused.
165
// SpinButton seems to be a special for mouse capture, so we may need track
166
// privately whether mouse is actually captured.
177
SetCursor(wxCURSOR_SIZENS);
186
m_hasCapture = false;
189
wxWindow *parent = GetParent();
191
SetCursor(parent->GetCursor());
193
SetCursor(wxNullCursor);
196
void OnMouseEvent(wxMouseEvent& event)
198
if ( event.GetEventType() == wxEVT_LEFT_DOWN )
201
m_ptPosition = event.GetPosition();
203
else if ( event.GetEventType() == wxEVT_LEFT_UP )
208
else if ( event.GetEventType() == wxEVT_MOTION )
212
int dy = m_ptPosition.y - event.GetPosition().y;
216
m_ptPosition = event.GetPosition();
218
wxSpinEvent evtscroll( (dy >= 0) ? wxEVT_SCROLL_LINEUP :
219
wxEVT_SCROLL_LINEDOWN,
221
evtscroll.SetEventObject(this);
223
wxASSERT( m_spins == 1 );
226
GetEventHandler()->ProcessEvent(evtscroll);
234
#if wxCHECK_VERSION(2,8,0)
235
void OnMouseCaptureLost(wxMouseCaptureLostEvent& WXUNUSED(event))
242
#endif // IS_MOTION_SPIN_SUPPORTED
245
// This macro also defines global wxPGEditor_SpinCtrl for storing
246
// the singleton class instance.
247
WX_PG_IMPLEMENT_EDITOR_CLASS(SpinCtrl,wxPGSpinCtrlEditor,wxPGEditor)
250
// Trivial destructor.
251
wxPGSpinCtrlEditor::~wxPGSpinCtrlEditor()
256
// Create controls and initialize event handling.
257
wxPGWindowList wxPGSpinCtrlEditor::CreateControls( wxPropertyGrid* propgrid, wxPGProperty* property,
258
const wxPoint& pos, const wxSize& sz ) const
260
const int margin = 1;
261
wxSize butSz(18, sz.y);
262
wxSize tcSz(sz.x - butSz.x - margin, sz.y);
263
wxPoint butPos(pos.x + tcSz.x + margin, pos.y);
267
#if IS_MOTION_SPIN_SUPPORTED
268
if ( property->GetAttributeAsLong(wxT("MotionSpin"), 0) )
270
wnd2 = new wxPGSpinButton();
275
wnd2 = new wxSpinButton();
281
wnd2->Create( propgrid->GetPanel(), wxPG_SUBID2, butPos, butSz, wxSP_VERTICAL );
283
wnd2->SetRange( INT_MIN, INT_MAX );
286
propgrid->Connect( wxPG_SUBID2, wxEVT_SCROLL_LINEUP,
287
(wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction)
288
&wxPropertyGrid::OnCustomEditorEvent, NULL, propgrid );
289
propgrid->Connect( wxPG_SUBID2, wxEVT_SCROLL_LINEDOWN,
290
(wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction)
291
&wxPropertyGrid::OnCustomEditorEvent, NULL, propgrid );
292
propgrid->Connect( wxPG_SUBID1, wxEVT_KEY_DOWN,
293
(wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction)
294
&wxPropertyGrid::OnCustomEditorEvent, NULL, propgrid );
296
// Let's add validator to make sure only numbers can be entered
297
wxTextValidator validator(wxFILTER_NUMERIC, &m_tempString);
299
wxTextCtrl* wnd1 = (wxTextCtrl*) wxPGTextCtrlEditor::CreateControls( propgrid, property, pos, tcSz ).m_primary;
300
wnd1->SetValidator(validator);
302
return wxPGWindowList(wnd1, wnd2);
305
// Control's events are redirected here
306
bool wxPGSpinCtrlEditor::OnEvent( wxPropertyGrid* propgrid, wxPGProperty* property,
307
wxWindow* wnd, wxEvent& event ) const
309
int evtType = event.GetEventType();
312
bool bigStep = false;
314
if ( evtType == wxEVT_KEY_DOWN )
316
wxKeyEvent& keyEvent = (wxKeyEvent&)event;
317
keycode = keyEvent.GetKeyCode();
319
if ( keycode == WXK_UP )
320
evtType = wxEVT_SCROLL_LINEUP;
321
else if ( keycode == WXK_DOWN )
322
evtType = wxEVT_SCROLL_LINEDOWN;
323
else if ( keycode == WXK_PAGEUP )
325
evtType = wxEVT_SCROLL_LINEUP;
328
else if ( keycode == WXK_PAGEDOWN )
330
evtType = wxEVT_SCROLL_LINEDOWN;
335
if ( evtType == wxEVT_SCROLL_LINEUP || evtType == wxEVT_SCROLL_LINEDOWN )
337
#if IS_MOTION_SPIN_SUPPORTED
338
if ( property->GetAttributeAsLong(wxT("MotionSpin"), 0) )
340
wxPGSpinButton* spinButton =
341
(wxPGSpinButton*) propgrid->GetEditorControlSecondary();
344
spins = spinButton->GetSpins();
349
// Can't use wnd since it might be clipper window
350
wxTextCtrl* tc = wxDynamicCast(propgrid->GetEditorControl(), wxTextCtrl);
355
s = property->GetValueAsString(wxPG_FULL_VALUE);
357
int mode = wxPG_PROPERTY_VALIDATION_SATURATE;
359
if ( property->GetAttributeAsLong(wxT("Wrap"), 0) )
360
mode = wxPG_PROPERTY_VALIDATION_WRAP;
362
if ( property->GetValueType() == wxT("double") )
365
double step = property->GetAttributeAsDouble(wxT("Step"), 1.0);
368
if ( s.ToDouble(&v_d) )
373
step *= (double) spins;
375
if ( evtType == wxEVT_SCROLL_LINEUP ) v_d += step;
379
wxFloatProperty::DoValidation(property, v_d, NULL, mode);
381
wxPropertyGrid::DoubleToString(s, v_d, 6, true, NULL);
391
wxLongLong_t step = property->GetAttributeAsLong(wxT("Step"), 1);
394
if ( wxPGStringToLongLong(s, &v_ll, 10) )
401
if ( evtType == wxEVT_SCROLL_LINEUP ) v_ll += step;
405
wxIntProperty::DoValidation(property, v_ll, NULL, mode);
407
s = wxLongLong(v_ll).ToString();
417
int ip = tc->GetInsertionPoint();
418
int lp = tc->GetLastPosition();
420
tc->SetInsertionPoint(ip+(tc->GetLastPosition()-lp));
426
return wxPGTextCtrlEditor::OnEvent(propgrid,property,wnd,event);
429
#endif // wxUSE_SPINBTN
432
// -----------------------------------------------------------------------
433
// wxDatePickerCtrl-based property editor
434
// -----------------------------------------------------------------------
436
#if wxUSE_DATEPICKCTRL
439
#include <wx/datectrl.h>
440
#include <wx/dateevt.h>
442
class wxPGDatePickerCtrlEditor : public wxPGEditor
444
WX_PG_DECLARE_EDITOR_CLASS(wxPGDatePickerCtrlEditor)
446
virtual ~wxPGDatePickerCtrlEditor();
448
wxPG_DECLARE_CREATECONTROLS
450
virtual void UpdateControl( wxPGProperty* property, wxWindow* wnd ) const;
451
virtual bool OnEvent( wxPropertyGrid* propgrid, wxPGProperty* property,
452
wxWindow* wnd, wxEvent& event ) const;
453
virtual bool GetValueFromControl( wxVariant& variant, wxPGProperty* property, wxWindow* wnd ) const;
454
virtual void SetValueToUnspecified( wxPGProperty* WXUNUSED(property), wxWindow* wnd ) const;
458
WX_PG_IMPLEMENT_EDITOR_CLASS(DatePickerCtrl,wxPGDatePickerCtrlEditor,wxPGEditor)
461
wxPGDatePickerCtrlEditor::~wxPGDatePickerCtrlEditor()
465
wxPGWindowList wxPGDatePickerCtrlEditor::CreateControls( wxPropertyGrid* propgrid,
466
wxPGProperty* property,
468
const wxSize& sz ) const
470
wxCHECK_MSG( property->IsKindOf(WX_PG_CLASSINFO(wxDateProperty)),
472
wxT("DatePickerCtrl editor can only be used with wxDateProperty or derivative.") );
474
wxDateProperty* prop = (wxDateProperty*) property;
476
// Use two stage creation to allow cleaner display on wxMSW
477
wxDatePickerCtrl* ctrl = new wxDatePickerCtrl();
480
wxSize useSz = wxDefaultSize;
486
wxDateTime dateValue(wxInvalidDateTime);
487
if ( prop->GetType() == wxT("datetime") )
488
dateValue = prop->GetDateValue();
490
ctrl->Create(propgrid->GetPanel(),
495
prop->GetDatePickerStyle() | wxNO_BORDER);
497
// Connect all required events to grid's OnCustomEditorEvent
498
// (all relevenat wxTextCtrl, wxComboBox and wxButton events are
499
// already connected)
500
propgrid->Connect( wxPG_SUBID1, wxEVT_DATE_CHANGED,
501
(wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction)
502
&wxPropertyGrid::OnCustomEditorEvent );
511
// Copies value from property to control
512
void wxPGDatePickerCtrlEditor::UpdateControl( wxPGProperty* property, wxWindow* wnd ) const
514
wxDatePickerCtrl* ctrl = (wxDatePickerCtrl*) wnd;
515
wxASSERT( ctrl && ctrl->IsKindOf(CLASSINFO(wxDatePickerCtrl)) );
517
// We assume that property's data type is 'int' (or something similar),
518
// thus allowing us to get raw, unchecked value via DoGetValue.
519
ctrl->SetValue( property->GetValue().GetDateTime() );
522
// Control's events are redirected here
523
bool wxPGDatePickerCtrlEditor::OnEvent( wxPropertyGrid* WXUNUSED(propgrid),
524
wxPGProperty* WXUNUSED(property),
525
wxWindow* WXUNUSED(wnd),
526
wxEvent& event ) const
528
if ( event.GetEventType() == wxEVT_DATE_CHANGED )
534
bool wxPGDatePickerCtrlEditor::GetValueFromControl( wxVariant& variant, wxPGProperty* WXUNUSED(property), wxWindow* wnd ) const
536
wxDatePickerCtrl* ctrl = (wxDatePickerCtrl*) wnd;
537
wxASSERT( ctrl && ctrl->IsKindOf(CLASSINFO(wxDatePickerCtrl)) );
539
variant = ctrl->GetValue();
544
void wxPGDatePickerCtrlEditor::SetValueToUnspecified( wxPGProperty* WXUNUSED(property), wxWindow* WXUNUSED(wnd) ) const
547
//wxDateProperty* prop = (wxDateProperty*) property;
551
#endif // wxUSE_DATEPICKCTRL
554
// -----------------------------------------------------------------------
556
// -----------------------------------------------------------------------
558
#include <wx/fontdlg.h>
559
#include <wx/fontenum.h>
561
static const wxChar* gs_fp_es_family_labels[] = {
562
wxT("Default"), wxT("Decorative"),
563
wxT("Roman"), wxT("Script"),
564
wxT("Swiss"), wxT("Modern"),
568
static long gs_fp_es_family_values[] = {
569
wxDEFAULT, wxDECORATIVE,
574
static const wxChar* gs_fp_es_style_labels[] = {
581
static long gs_fp_es_style_values[] = {
587
static const wxChar* gs_fp_es_weight_labels[] = {
594
static long gs_fp_es_weight_values[] = {
600
// Class body is in advprops.h
603
WX_PG_IMPLEMENT_PROPERTY_CLASS(wxFontProperty,wxPGProperty,
604
wxFont,const wxFont&,TextCtrlAndButton)
607
wxFontProperty::wxFontProperty( const wxString& label, const wxString& name,
608
const wxFont& value )
609
: wxPGProperty(label,name)
611
SetValue( wxFontToVariant(value) );
613
// Initialize font family choices list
614
if ( !wxPGGlobalVars->m_fontFamilyChoices )
616
wxFontEnumerator enumerator;
617
enumerator.EnumerateFacenames();
619
#if wxMINOR_VERSION > 6
620
wxArrayString faceNames = enumerator.GetFacenames();
622
wxArrayString& faceNames = *enumerator.GetFacenames();
627
wxPGGlobalVars->m_fontFamilyChoices = new wxPGChoices(faceNames);
630
wxString emptyString(wxEmptyString);
632
wxFont& font = wxFontFromVariant(m_value);
634
AddChild( new wxIntProperty( _("Point Size"), wxT("Point Size"), (long)font.GetPointSize() ) );
636
AddChild( new wxEnumProperty(_("Family"), wxT("Family"),
637
gs_fp_es_family_labels,gs_fp_es_family_values,
640
wxString faceName = font.GetFaceName();
641
// If font was not in there, add it now
642
if ( faceName.length() &&
643
wxPGGlobalVars->m_fontFamilyChoices->Index(faceName) == wxNOT_FOUND )
644
wxPGGlobalVars->m_fontFamilyChoices->AddAsSorted(faceName);
646
wxPGProperty* p = new wxEnumProperty(_("Face Name"), wxT("Face Name"),
647
*wxPGGlobalVars->m_fontFamilyChoices);
649
p->SetValueFromString(faceName, wxPG_FULL_VALUE);
653
AddChild( new wxEnumProperty(_("Style"), wxT("Style"),
654
gs_fp_es_style_labels,gs_fp_es_style_values,font.GetStyle()) );
656
AddChild( new wxEnumProperty(_("Weight"), wxT("Weight"),
657
gs_fp_es_weight_labels,gs_fp_es_weight_values,font.GetWeight()) );
659
AddChild( new wxBoolProperty(_("Underlined"), wxT("Underlined"),
660
font.GetUnderlined()) );
663
wxFontProperty::~wxFontProperty() { }
665
void wxFontProperty::OnSetValue()
667
wxFont& font = wxFontFromVariant(m_value);
672
font2 = wxFont(10,wxSWISS,wxNORMAL,wxNORMAL);
676
m_value = wxFontToVariant(font2);
679
wxString wxFontProperty::GetValueAsString( int argFlags ) const
681
return wxPGProperty::GetValueAsString(argFlags);
684
bool wxFontProperty::OnEvent( wxPropertyGrid* propgrid, wxWindow* WXUNUSED(primary),
687
if ( propgrid->IsMainButtonEvent(event) )
689
// Update value from last minute changes
690
PrepareValueForDialogEditing(propgrid);
693
data.SetInitialFont( wxFontFromVariant(m_value) );
694
data.SetColour(*wxBLACK);
696
wxFontDialog dlg(propgrid, data);
697
if ( dlg.ShowModal() == wxID_OK )
699
propgrid->EditorsValueWasModified();
701
wxVariant variant = wxFontToVariant(dlg.GetFontData().GetChosenFont());
702
SetValueInEvent( variant );
709
void wxFontProperty::RefreshChildren()
711
if ( !GetCount() ) return;
712
const wxFont& font = wxFontFromVariant(m_value);
713
Item(0)->SetValue( (long)font.GetPointSize() );
714
Item(1)->SetValue( (long)font.GetFamily() );
715
Item(2)->SetValueFromString( font.GetFaceName(), wxPG_FULL_VALUE );
716
Item(3)->SetValue( (long)font.GetStyle() );
717
Item(4)->SetValue( (long)font.GetWeight() );
718
Item(5)->SetValue( font.GetUnderlined() );
721
void wxFontProperty::ChildChanged( wxVariant& thisValue, int ind, wxVariant& childValue ) const
723
wxFont& font = wxFontFromVariant(thisValue);
727
font.SetPointSize( wxPGVariantToInt(childValue) );
731
int fam = childValue.GetLong();
732
if ( fam < wxDEFAULT ||
735
font.SetFamily( fam );
740
int faceIndex = childValue.GetLong();
742
if ( faceIndex >= 0 )
743
faceName = wxPGGlobalVars->m_fontFamilyChoices->GetLabel(faceIndex);
745
font.SetFaceName( faceName );
749
int st = childValue.GetLong();
750
if ( st != wxFONTSTYLE_NORMAL &&
751
st != wxFONTSTYLE_SLANT &&
752
st != wxFONTSTYLE_ITALIC )
753
st = wxFONTWEIGHT_NORMAL;
758
int wt = childValue.GetLong();
759
if ( wt != wxFONTWEIGHT_NORMAL &&
760
wt != wxFONTWEIGHT_LIGHT &&
761
wt != wxFONTWEIGHT_BOLD )
762
wt = wxFONTWEIGHT_NORMAL;
763
font.SetWeight( wt );
767
font.SetUnderlined( childValue.GetBool() );
772
wxSize wxFontProperty::OnMeasureImage() const
774
return wxSize(-1,-1);
777
void wxFontProperty::OnCustomPaint(wxDC& dc,
779
wxPGPaintData& paintData)
782
if ( paintData.m_choiceItem >= 0 )
783
drawFace = wxPGGlobalVars->m_fontFamilyChoices->GetLabel(paintData.m_choiceItem);
785
drawFace = m_value_wxFont.GetFaceName();
787
if ( drawFace.length() )
789
// Draw the background
790
dc.SetBrush( wxColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)) );
791
//dc.SetBrush( *wxWHITE_BRUSH );
792
//dc.SetPen( *wxMEDIUM_GREY_PEN );
793
dc.DrawRectangle( rect );
795
wxFont oldFont = dc.GetFont();
796
wxFont drawFont(oldFont.GetPointSize(),
797
wxDEFAULT,wxNORMAL,wxBOLD,false,drawFace);
798
dc.SetFont(drawFont);
800
dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT) );
801
dc.DrawText( wxT("Aa"), rect.x+2, rect.y+1 );
807
// No file - just draw a white box
808
dc.SetBrush ( *wxWHITE_BRUSH );
809
dc.DrawRectangle ( rect );
815
// -----------------------------------------------------------------------
816
// wxSystemColourProperty
817
// -----------------------------------------------------------------------
819
// wxEnumProperty based classes cannot use wxPG_PROP_CLASS_SPECIFIC_1
820
#define wxPG_PROP_HIDE_CUSTOM_COLOUR wxPG_PROP_CLASS_SPECIFIC_2
822
#include <wx/colordlg.h>
824
//#define wx_cp_es_syscolours_len 25
825
static const wxChar* gs_cp_es_syscolour_labels[] = {
828
wxT("ActiveCaption"),
830
wxT("ButtonHighlight"),
839
wxT("HighlightText"),
840
wxT("InactiveBorder"),
841
wxT("InactiveCaption"),
842
wxT("InactiveCaptionText"),
854
static long gs_cp_es_syscolour_values[] = {
855
wxSYS_COLOUR_APPWORKSPACE,
856
wxSYS_COLOUR_ACTIVEBORDER,
857
wxSYS_COLOUR_ACTIVECAPTION,
858
wxSYS_COLOUR_BTNFACE,
859
wxSYS_COLOUR_BTNHIGHLIGHT,
860
wxSYS_COLOUR_BTNSHADOW,
861
wxSYS_COLOUR_BTNTEXT ,
862
wxSYS_COLOUR_CAPTIONTEXT,
863
wxSYS_COLOUR_3DDKSHADOW,
864
wxSYS_COLOUR_3DLIGHT,
865
wxSYS_COLOUR_BACKGROUND,
866
wxSYS_COLOUR_GRAYTEXT,
867
wxSYS_COLOUR_HIGHLIGHT,
868
wxSYS_COLOUR_HIGHLIGHTTEXT,
869
wxSYS_COLOUR_INACTIVEBORDER,
870
wxSYS_COLOUR_INACTIVECAPTION,
871
wxSYS_COLOUR_INACTIVECAPTIONTEXT,
873
wxSYS_COLOUR_SCROLLBAR,
875
wxSYS_COLOUR_INFOTEXT,
877
wxSYS_COLOUR_WINDOWFRAME,
878
wxSYS_COLOUR_WINDOWTEXT,
883
WX_PG_IMPLEMENT_WXOBJECT_VARIANT_DATA_WITH_PROPER_EQ(wxPGVariantDataColourPropertyValue,
884
wxColourPropertyValue)
887
// Class body is in advprops.h
889
WX_PG_IMPLEMENT_PROPERTY_CLASS(wxSystemColourProperty,wxEnumProperty,
890
wxColourPropertyValue,const wxColourPropertyValue&,Choice)
893
void wxSystemColourProperty::Init( int type, const wxColour& colour )
895
wxColourPropertyValue cpv;
898
cpv.Init( type, colour );
900
cpv.Init( type, *wxWHITE );
902
m_flags |= wxPG_PROP_STATIC_CHOICES; // Colour selection cannot be changed.
904
m_value = wxColourPropertyValueToVariant(cpv);
910
static wxPGChoices gs_wxSystemColourProperty_choicesCache;
913
wxSystemColourProperty::wxSystemColourProperty( const wxString& label, const wxString& name,
914
const wxColourPropertyValue& value )
915
: wxEnumProperty( label,
917
gs_cp_es_syscolour_labels,
918
gs_cp_es_syscolour_values,
919
&gs_wxSystemColourProperty_choicesCache )
922
Init( value.m_type, value.m_colour );
924
Init( wxPG_COLOUR_CUSTOM, *wxWHITE );
928
wxSystemColourProperty::wxSystemColourProperty( const wxString& label, const wxString& name,
929
const wxChar** labels, const long* values, wxPGChoices* choicesCache,
930
const wxColourPropertyValue& value )
931
: wxEnumProperty( label, name, labels, values, choicesCache )
934
Init( value.m_type, value.m_colour );
936
Init( wxPG_COLOUR_CUSTOM, *wxWHITE );
940
wxSystemColourProperty::wxSystemColourProperty( const wxString& label, const wxString& name,
941
const wxChar** labels, const long* values, wxPGChoices* choicesCache,
942
const wxColour& value )
943
: wxEnumProperty( label, name, labels, values, choicesCache )
946
Init( wxPG_COLOUR_CUSTOM, value );
948
Init( wxPG_COLOUR_CUSTOM, *wxWHITE );
952
wxSystemColourProperty::~wxSystemColourProperty() { }
955
wxColourPropertyValue wxSystemColourProperty::GetVal( const wxVariant* pVariant ) const
960
if ( pVariant->IsNull() )
961
return wxColourPropertyValue(wxPG_COLOUR_UNSPECIFIED, wxColour());
963
wxColourPropertyValue* v1 = &wxColourPropertyValueFromVariant(*pVariant);
967
wxColour* pCol = wxGetVariantCast(*pVariant, wxColour);
975
wxColourPropertyValue v2( wxPG_COLOUR_CUSTOM, col );
977
int colInd = ColToInd(col);
978
if ( colInd != wxNOT_FOUND )
984
wxVariant wxSystemColourProperty::DoTranslateVal( wxColourPropertyValue& v ) const
986
return wxColourPropertyValueToVariant(v);
989
int wxSystemColourProperty::ColToInd( const wxColour& colour ) const
992
size_t i_max = m_choices.GetCount() - 1;
994
for ( i=0; i<i_max; i++ )
996
int ind = m_choices[i].GetValue();
998
if ( colour == GetColour(ind) )
1000
/*wxLogDebug(wxT("%s(%s): Index %i for ( getcolour(%i,%i,%i), colour(%i,%i,%i))"),
1001
GetClassName(),GetLabel().c_str(),
1002
(int)i,(int)GetColour(ind).Red(),(int)GetColour(ind).Green(),(int)GetColour(ind).Blue(),
1003
(int)colour.Red(),(int)colour.Green(),(int)colour.Blue());*/
1011
static inline wxColour wxColourFromPGLong( long col )
1013
return wxColour((col&0xFF),((col>>8)&0xFF),((col>>16)&0xFF));
1017
void wxSystemColourProperty::OnSetValue()
1019
// Convert from generic wxobject ptr to wxPGVariantDataColour
1020
if ( wxPGIsVariantType(m_value, wxobject) )
1022
wxASSERT( m_value.IsValueKindOf(CLASSINFO(wxColour)) );
1023
wxColour* pCol = (wxColour*) m_value.GetWxObjectPtr();
1024
#if wxCHECK_VERSION(2,8,0)
1027
wxPGVariantAssign(m_value, WXVARIANT(*pCol));
1031
wxColourPropertyValue val = GetVal(&m_value);
1033
if ( val.m_type == wxPG_COLOUR_UNSPECIFIED )
1041
if ( val.m_type < wxPG_COLOUR_WEB_BASE )
1042
val.m_colour = GetColour( val.m_type );
1044
m_value = TranslateVal(val);
1047
wxColourPropertyValue* pCpv = &wxColourPropertyValueFromVariant(m_value);
1050
col = pCpv->m_colour;
1056
SetValueToUnspecified();
1057
SetIndex(wxNOT_FOUND);
1065
if ( pCpv->m_type < wxPG_COLOUR_WEB_BASE )
1067
ind = GetIndexForValue(pCpv->m_type);
1071
pCpv->m_type = wxPG_COLOUR_CUSTOM;
1072
ind = GetCustomColourIndex();
1077
ind = ColToInd(col);
1079
if ( ind == wxNOT_FOUND )
1080
ind = GetCustomColourIndex();
1087
wxColour wxSystemColourProperty::GetColour( int index ) const
1089
return wxSystemSettings::GetColour( (wxSystemColour)index );
1092
wxString wxSystemColourProperty::ColourToString( const wxColour& col, int index ) const
1094
if ( index == wxNOT_FOUND )
1095
return wxString::Format(wxT("(%i,%i,%i)"),
1100
return m_choices.GetLabel(index);
1103
wxString wxSystemColourProperty::GetValueAsString( int argFlags ) const
1105
wxColourPropertyValue val = GetVal();
1107
int ind = GetIndex();
1109
// Always show custom colour for textctrl-editor
1110
if ( val.m_type == wxPG_COLOUR_CUSTOM ||
1111
ind == GetCustomColourIndex() ||
1112
(argFlags & wxPG_PROPERTY_SPECIFIC) )
1114
return ColourToString(val.m_colour, wxNOT_FOUND);
1118
return wxEmptyString;
1120
return ColourToString(val.m_colour, ind);
1124
wxSize wxSystemColourProperty::OnMeasureImage( int ) const
1126
return wxPG_DEFAULT_IMAGE_SIZE;
1130
int wxSystemColourProperty::GetCustomColourIndex() const
1132
return m_choices.GetCount() - 1;
1136
bool wxSystemColourProperty::QueryColourFromUser( wxVariant& variant ) const
1138
wxASSERT( m_value.GetType() != wxT("string") );
1141
wxPropertyGrid* propgrid = GetGrid();
1142
wxASSERT( propgrid );
1144
// Must only occur when user triggers event
1145
if ( !(propgrid->GetInternalFlags() & wxPG_FL_IN_ONCUSTOMEDITOREVENT) )
1148
wxColourPropertyValue val = GetVal();
1150
val.m_type = wxPG_COLOUR_CUSTOM;
1153
data.SetChooseFull(true);
1154
data.SetColour(val.m_colour);
1156
for ( i = 0; i < 16; i++)
1158
wxColour colour(i*16, i*16, i*16);
1159
data.SetCustomColour(i, colour);
1162
wxColourDialog dialog(propgrid, &data);
1163
if ( dialog.ShowModal() == wxID_OK )
1165
wxColourData retData = dialog.GetColourData();
1166
val.m_colour = retData.GetColour();
1168
variant = DoTranslateVal(val);
1170
SetValueInEvent(variant);
1179
bool wxSystemColourProperty::IntToValue( wxVariant& variant, int number, int WXUNUSED(argFlags) ) const
1182
int type = GetValueForIndex(index);
1184
if ( type == wxPG_COLOUR_CUSTOM )
1186
QueryColourFromUser(variant);
1190
variant = TranslateVal( type, GetColour(type) );
1196
// Need to do some extra event handling.
1197
bool wxSystemColourProperty::OnEvent( wxPropertyGrid* propgrid, wxWindow* WXUNUSED(primary), wxEvent& event )
1199
if ( propgrid->IsMainButtonEvent(event) )
1201
// We need to handle button click in case editor has been
1202
// switched to one that has wxButton as well.
1204
if ( QueryColourFromUser(variant) )
1210
/*class wxPGColourPropertyRenderer : public wxPGDefaultRenderer
1213
virtual void Render( wxDC& dc, const wxRect& rect,
1214
const wxPropertyGrid* propertyGrid, wxPGProperty* property,
1215
int WXUNUSED(column), int item, int WXUNUSED(flags) ) const
1217
wxASSERT( property->IsKindOf(CLASSINFO(wxSystemColourProperty)) );
1218
wxSystemColourProperty* prop = wxStaticCast(property, wxSystemColourProperty);
1220
dc.SetPen(*wxBLACK_PEN);
1222
( item < (int)(GetCustomColourIndex) || (prop->HasFlag(wxPG_PROP_HIDE_CUSTOM_COLOUR)))
1226
const wxArrayInt& values = prop->GetValues();
1227
if ( values.GetCount() )
1228
colInd = values[item];
1231
dc.SetBrush( wxColour( prop->GetColour( colInd ) ) );
1233
else if ( !prop->IsValueUnspecified() )
1234
dc.SetBrush( prop->GetVal().m_colour );
1236
dc.SetBrush( *wxWHITE );
1238
wxRect imageRect = propertyGrid->GetImageRect(property, item);
1239
wxLogDebug(wxT("%i, %i"),imageRect.x,imageRect.y);
1240
dc.DrawRectangle( rect.x+imageRect.x, rect.y+imageRect.y,
1241
imageRect.width, imageRect.height );
1245
text = property->GetValueAsString();
1247
text = property->GetChoiceString(item);
1248
DrawText( dc, rect, imageRect.width, text );
1253
wxPGColourPropertyRenderer g_wxPGColourPropertyRenderer;
1255
wxPGCellRenderer* wxSystemColourProperty::GetCellRenderer( int column ) const
1258
return &g_wxPGColourPropertyRenderer;
1259
return wxEnumProperty::GetCellRenderer(column);
1262
void wxSystemColourProperty::OnCustomPaint( wxDC& dc, const wxRect& rect,
1263
wxPGPaintData& paintdata )
1267
if ( paintdata.m_choiceItem >= 0 && paintdata.m_choiceItem < (int)m_choices.GetCount() &&
1268
paintdata.m_choiceItem != GetCustomColourIndex() )
1270
int colInd = m_choices[paintdata.m_choiceItem].GetValue();
1271
col = GetColour( colInd );
1273
else if ( !IsValueUnspecified() )
1275
col = GetVal().m_colour;
1281
dc.DrawRectangle(rect);
1286
bool wxSystemColourProperty::StringToValue( wxVariant& value, const wxString& text, int argFlags ) const
1289
// Accept colour format "[Name] [(R,G,B)]"
1290
// Name takes precedence.
1292
wxString colourName;
1295
int ppos = text.Find(wxT("("));
1297
if ( ppos == wxNOT_FOUND )
1303
colourName = text.substr(0, ppos);
1304
colourRGB = text.substr(ppos, text.length()-ppos);
1307
// Strip spaces from extremities
1308
colourName.Trim(true);
1309
colourName.Trim(false);
1310
colourRGB.Trim(true);
1312
// Validate colourRGB string - (1,1,1) is shortest allowed
1313
if ( colourRGB.length() < 7 )
1316
if ( colourRGB.length() == 0 && m_choices.GetCount() &&
1317
colourName == m_choices.GetLabel(GetCustomColourIndex()) )
1319
if ( !(argFlags & wxPG_EDITABLE_VALUE ))
1321
// This really should not occurr...
1327
QueryColourFromUser(value);
1331
wxColourPropertyValue val;
1335
if ( colourName.length() )
1337
// Try predefined colour first
1338
bool res = wxEnumProperty::StringToValue(value, colourName, argFlags);
1339
if ( res && GetIndex() >= 0 )
1341
val.m_type = GetIndex();
1342
if ( val.m_type >= 0 && val.m_type < m_choices.GetCount() )
1343
val.m_type = m_choices[val.m_type].GetValue();
1345
// Get proper colour for type.
1346
val.m_colour = GetColour(val.m_type);
1351
if ( colourRGB.length() && !done )
1353
// Then check custom colour.
1354
val.m_type = wxPG_COLOUR_CUSTOM;
1356
int r = -1, g = -1, b = -1;
1357
wxSscanf(colourRGB.c_str(),wxT("(%i,%i,%i)"),&r,&g,&b);
1359
if ( r >= 0 && r <= 255 &&
1360
g >= 0 && g <= 255 &&
1361
b >= 0 && b <= 255 )
1363
val.m_colour.Set(r,g,b);
1375
value = DoTranslateVal(val);
1382
bool wxSystemColourProperty::DoSetAttribute( const wxString& name, wxVariant& value )
1384
if ( name == wxPG_COLOUR_ALLOW_CUSTOM )
1386
int ival = wxPGVariantToInt(value);
1388
SetChoicesExclusive(); // Make sure we don't corrupt colour lists of other properties
1390
if ( ival && (m_flags & wxPG_PROP_HIDE_CUSTOM_COLOUR) )
1392
// Show custom choice
1393
m_choices.Insert(wxT("Custom"), GetCustomColourIndex(), wxPG_COLOUR_CUSTOM);
1394
m_flags &= ~(wxPG_PROP_HIDE_CUSTOM_COLOUR);
1396
else if ( !ival && !(m_flags & wxPG_PROP_HIDE_CUSTOM_COLOUR) )
1398
// Hide custom choice
1399
m_choices.RemoveAt(GetCustomColourIndex());
1400
m_flags |= wxPG_PROP_HIDE_CUSTOM_COLOUR;
1408
// -----------------------------------------------------------------------
1410
// -----------------------------------------------------------------------
1412
static const wxChar* gs_cp_es_normcolour_labels[] = {
1432
(const wxChar*) NULL
1435
static unsigned long gs_cp_es_normcolour_colours[] = {
1437
wxPG_COLOUR(128,0,0),
1438
wxPG_COLOUR(0,0,128),
1439
wxPG_COLOUR(128,0,128),
1440
wxPG_COLOUR(0,128,128),
1441
wxPG_COLOUR(128,128,128),
1442
wxPG_COLOUR(0,128,0),
1443
wxPG_COLOUR(128,128,0),
1444
wxPG_COLOUR(166,124,81),
1445
wxPG_COLOUR(0,0,255),
1446
wxPG_COLOUR(255,0,255),
1447
wxPG_COLOUR(255,0,0),
1448
wxPG_COLOUR(247,148,28),
1449
wxPG_COLOUR(192,192,192),
1450
wxPG_COLOUR(0,255,0),
1451
wxPG_COLOUR(0,255,255),
1452
wxPG_COLOUR(255,255,0),
1453
wxPG_COLOUR(255,255,255),
1457
WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR2(wxColourProperty,
1458
gs_cp_es_normcolour_labels,
1460
gs_cp_es_normcolour_colours,
1463
// -----------------------------------------------------------------------
1465
// -----------------------------------------------------------------------
1467
#define wxPG_CURSOR_IMAGE_WIDTH 32
1469
#define NUM_CURSORS 28
1471
//#define wx_cp_es_syscursors_len 28
1472
static const wxChar* gs_cp_es_syscursors_labels[NUM_CURSORS+1] = {
1484
wxT("Middle Button"),
1490
wxT("Question Arrow"),
1491
wxT("Right Button"),
1492
wxT("Sizing NE-SW"),
1494
wxT("Sizing NW-SE"),
1501
(const wxChar*) NULL
1504
static long gs_cp_es_syscursors_values[NUM_CURSORS] = {
1507
wxCURSOR_RIGHT_ARROW,
1514
wxCURSOR_LEFT_BUTTON,
1516
wxCURSOR_MIDDLE_BUTTON,
1518
wxCURSOR_PAINT_BRUSH,
1520
wxCURSOR_POINT_LEFT,
1521
wxCURSOR_POINT_RIGHT,
1522
wxCURSOR_QUESTION_ARROW,
1523
wxCURSOR_RIGHT_BUTTON,
1535
IMPLEMENT_DYNAMIC_CLASS(wxCursorProperty, wxEnumProperty)
1537
wxCursorProperty::wxCursorProperty( const wxString& label, const wxString& name,
1539
: wxEnumProperty( label,
1541
gs_cp_es_syscursors_labels,
1542
gs_cp_es_syscursors_values,
1545
m_flags |= wxPG_PROP_STATIC_CHOICES; // Cursor selection cannot be changed.
1548
wxCursorProperty::~wxCursorProperty()
1552
wxSize wxCursorProperty::OnMeasureImage( int item ) const
1554
#if wxPG_CAN_DRAW_CURSOR
1555
if ( item != -1 && item < NUM_CURSORS )
1556
return wxSize(wxPG_CURSOR_IMAGE_WIDTH,wxPG_CURSOR_IMAGE_WIDTH);
1561
#if wxPG_CAN_DRAW_CURSOR
1563
void wxCursorProperty::OnCustomPaint( wxDC& dc,
1565
wxPGPaintData& paintdata )
1568
dc.SetBrush( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE ) );
1570
if ( paintdata.m_choiceItem >= 0 )
1572
dc.DrawRectangle( rect );
1574
if ( paintdata.m_choiceItem < NUM_CURSORS )
1576
int cursorindex = gs_cp_es_syscursors_values[paintdata.m_choiceItem];
1579
if ( cursorindex == wxCURSOR_NONE )
1580
cursorindex = wxCURSOR_ARROW;
1582
wxCursor cursor( cursorindex );
1585
::DrawIconEx( wxPG_GetHDCOf(dc),
1588
(HICON)cursor.GetHandle(),
1593
#if !defined(__WXWINCE__)
1594
DI_COMPAT | DI_DEFAULTSIZE |
1605
void wxCursorProperty::OnCustomPaint( wxDC&, const wxRect&, wxPGPaintData& ) { }
1606
/*wxPGCellRenderer* wxCursorProperty::GetCellRenderer( int column ) const
1608
return wxEnumProperty::GetCellRenderer(column);
1612
// -----------------------------------------------------------------------
1613
// wxImageFileProperty
1614
// -----------------------------------------------------------------------
1618
const wxString& wxPGGetDefaultImageWildcard()
1620
// Form the wildcard, if not done yet
1621
if ( !wxPGGlobalVars->m_pDefaultImageWildcard.length() )
1626
// TODO: This section may require locking (using global).
1628
wxList& handlers = wxImage::GetHandlers();
1630
wxList::iterator node;
1632
// Let's iterate over the image handler list.
1633
//for ( wxList::Node *node = handlers.GetFirst(); node; node = node->GetNext() )
1634
for ( node = handlers.begin(); node != handlers.end(); node++ )
1636
wxImageHandler *handler = (wxImageHandler*)*node;
1638
wxString ext_lo = handler->GetExtension();
1639
wxString ext_up = ext_lo.Upper();
1641
str.append( ext_up );
1642
str.append( wxT(" files (*.") );
1643
str.append( ext_up );
1644
str.append( wxT(")|*.") );
1645
str.append( ext_lo );
1646
str.append( wxT("|") );
1649
str.append ( wxT("All files (*.*)|*.*") );
1651
wxPGGlobalVars->m_pDefaultImageWildcard = str;
1654
return wxPGGlobalVars->m_pDefaultImageWildcard;
1657
WX_PG_IMPLEMENT_DERIVED_PROPERTY_CLASS(wxImageFileProperty,
1661
wxImageFileProperty::wxImageFileProperty( const wxString& label, const wxString& name,
1662
const wxString& value )
1663
: wxFileProperty(label,name,value)
1665
SetAttribute( wxPG_FILE_WILDCARD, wxPGGetDefaultImageWildcard() );
1667
m_pImage = (wxImage*) NULL;
1668
m_pBitmap = (wxBitmap*) NULL;
1671
wxImageFileProperty::~wxImageFileProperty()
1679
void wxImageFileProperty::OnSetValue()
1681
wxFileProperty::OnSetValue();
1695
// Create the image thumbnail
1696
if ( m_filename.FileExists() )
1698
m_pImage = new wxImage( m_filename.GetFullPath() );
1702
wxSize wxImageFileProperty::OnMeasureImage( int ) const
1704
return wxPG_DEFAULT_IMAGE_SIZE;
1707
void wxImageFileProperty::OnCustomPaint( wxDC& dc,
1711
if ( m_pBitmap || (m_pImage && m_pImage->Ok() ) )
1713
// Draw the thumbnail
1715
// Create the bitmap here because required size is not known in OnSetValue().
1718
m_pImage->Rescale( rect.width, rect.height );
1719
m_pBitmap = new wxBitmap( *m_pImage );
1724
dc.DrawBitmap( *m_pBitmap, rect.x, rect.y, false );
1728
// No file - just draw a white box
1729
dc.SetBrush( *wxWHITE_BRUSH );
1730
dc.DrawRectangle ( rect );
1734
#endif // wxUSE_IMAGE
1736
// -----------------------------------------------------------------------
1737
// wxMultiChoiceProperty
1738
// -----------------------------------------------------------------------
1742
#include <wx/choicdlg.h>
1744
WX_PG_IMPLEMENT_PROPERTY_CLASS(wxMultiChoiceProperty,wxPGProperty,
1745
wxArrayInt,const wxArrayInt&,TextCtrlAndButton)
1747
wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString& label,
1748
const wxString& name,
1749
const wxPGChoices& choices,
1750
const wxArrayString& value)
1751
: wxPGProperty(label,name)
1753
m_choices.Assign(choices);
1757
wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString& label,
1758
const wxString& name,
1759
const wxArrayString& strings,
1760
const wxArrayString& value)
1761
: wxPGProperty(label,name)
1763
m_choices.Set(strings);
1767
wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString& label,
1768
const wxString& name,
1769
const wxArrayString& value)
1770
: wxPGProperty(label,name)
1772
wxArrayString strings;
1773
m_choices.Set(strings);
1777
wxMultiChoiceProperty::~wxMultiChoiceProperty()
1781
void wxMultiChoiceProperty::OnSetValue()
1783
GenerateValueAsString();
1786
wxString wxMultiChoiceProperty::GetValueAsString( int ) const
1791
void wxMultiChoiceProperty::GenerateValueAsString()
1793
wxArrayString strings;
1795
if ( wxPGIsVariantType(m_value, arrstring) )
1796
strings = m_value.GetArrayString();
1798
wxString& tempStr = m_display;
1800
unsigned int itemCount = strings.GetCount();
1805
tempStr.append( wxT("\"") );
1807
for ( i = 0; i < itemCount; i++ )
1809
tempStr.append( strings[i] );
1810
tempStr.append( wxT("\"") );
1811
if ( i < (itemCount-1) )
1812
tempStr.append ( wxT(" \"") );
1816
wxArrayInt wxMultiChoiceProperty::GetValueAsIndices() const
1818
const wxArrayInt& valueArr = wxArrayIntFromVariant(GetValue());
1821
// Translate values to string indices.
1822
wxArrayInt selections;
1824
if ( !m_choices.IsOk() || !m_choices.GetCount() || !(&valueArr) )
1826
for ( i=0; i<valueArr.GetCount(); i++ )
1831
for ( i=0; i<valueArr.GetCount(); i++ )
1833
int sIndex = m_choices.Index(valueArr[i]);
1835
selections.Add(sIndex);
1842
bool wxMultiChoiceProperty::OnEvent( wxPropertyGrid* propgrid,
1843
wxWindow* WXUNUSED(primary),
1846
if ( propgrid->IsMainButtonEvent(event) )
1849
PrepareValueForDialogEditing(propgrid);
1851
wxArrayString labels = m_choices.GetLabels();
1852
unsigned int choiceCount;
1854
if ( m_choices.IsOk() )
1855
choiceCount = m_choices.GetCount();
1859
// launch editor dialog
1860
wxMultiChoiceDialog dlg( propgrid,
1861
_("Make a selection:"),
1864
choiceCount?&labels[0]:NULL,
1865
wxCHOICEDLG_STYLE );
1867
dlg.Move( propgrid->GetGoodEditorDialogPosition(this,dlg.GetSize()) );
1869
wxArrayString strings = m_value.GetArrayString();
1870
wxArrayString extraStrings;
1872
dlg.SetSelections(m_choices.GetIndicesForStrings(strings, &extraStrings));
1874
if ( dlg.ShowModal() == wxID_OK && choiceCount )
1876
int userStringMode = GetAttributeAsLong(wxT("UserStringMode"), 0);
1878
wxArrayInt arrInt = dlg.GetSelections();
1882
// Strings that were not in list of choices
1883
wxArrayString value;
1885
// Translate string indices to strings
1888
if ( userStringMode == 1 )
1890
for (n=0;n<extraStrings.size();n++)
1891
value.push_back(extraStrings[n]);
1895
for ( i=0; i<arrInt.GetCount(); i++ )
1896
value.Add(m_choices.GetLabel(arrInt.Item(i)));
1898
if ( userStringMode == 2 )
1900
for (n=0;n<extraStrings.size();n++)
1901
value.push_back(extraStrings[n]);
1904
variant = WXVARIANT(value);
1906
SetValueInEvent(variant);
1914
int wxMultiChoiceProperty::GetChoiceInfo( wxPGChoiceInfo* choiceinfo )
1917
choiceinfo->m_choices = &m_choices;
1921
bool wxMultiChoiceProperty::StringToValue( wxVariant& variant, const wxString& text, int ) const
1925
int userStringMode = GetAttributeAsLong(wxT("UserStringMode"), 0);
1927
WX_PG_TOKENIZER2_BEGIN(text,wxT('"'))
1928
if ( userStringMode > 0 || (m_choices.IsOk() && m_choices.Index( token ) != wxNOT_FOUND) )
1930
WX_PG_TOKENIZER2_END()
1932
wxVariant v( WXVARIANT(arr) );
1938
#endif // wxUSE_CHOICEDLG
1941
// -----------------------------------------------------------------------
1943
// -----------------------------------------------------------------------
1948
#if wxUSE_DATEPICKCTRL
1949
#define dtCtrl DatePickerCtrl
1951
#define dtCtrl TextCtrl
1954
WX_PG_IMPLEMENT_PROPERTY_CLASS(wxDateProperty,
1961
wxString wxDateProperty::ms_defaultDateFormat;
1964
wxDateProperty::wxDateProperty( const wxString& label,
1965
const wxString& name,
1966
const wxDateTime& value )
1967
: wxPGProperty(label,name)
1969
//wxPGRegisterDefaultValueType(wxDateTime)
1971
#if wxUSE_DATEPICKCTRL
1972
wxPGRegisterEditorClass(DatePickerCtrl);
1974
m_dpStyle = wxDP_DEFAULT | wxDP_SHOWCENTURY;
1982
wxDateProperty::~wxDateProperty()
1986
bool wxDateProperty::StringToValue( wxVariant& variant, const wxString& text,
1987
int WXUNUSED(argFlags) ) const
1991
#if wxCHECK_VERSION(2,9,0)
1992
const char* c = dt.ParseFormat(text, wxString(wxDefaultDateTimeFormat), wxDefaultDateTime, NULL);
1994
const wxChar* c = dt.ParseFormat(text, wxDefaultDateTimeFormat);
2006
wxString wxDateProperty::GetValueAsString( int argFlags ) const
2008
const wxChar* format = (const wxChar*) NULL;
2010
wxDateTime dateTime = m_value.GetDateTime();
2012
if ( !dateTime.IsValid() )
2013
return wxT("Invalid");
2015
if ( !ms_defaultDateFormat.length() )
2017
#if wxUSE_DATEPICKCTRL
2018
bool showCentury = m_dpStyle & wxDP_SHOWCENTURY ? true : false;
2020
bool showCentury = true;
2022
ms_defaultDateFormat = DetermineDefaultDateFormat( showCentury );
2025
if ( m_format.length() &&
2026
!(argFlags & wxPG_FULL_VALUE) )
2027
format = m_format.c_str();
2029
// Determine default from locale
2030
// NB: This is really simple stuff, but can't figure anything
2031
// better without proper support in wxLocale
2033
format = ms_defaultDateFormat.c_str();
2035
return dateTime.Format(format);
2038
wxString wxDateProperty::DetermineDefaultDateFormat( bool showCentury )
2040
// This code is basicly copied from datectlg.cpp's SetFormat
2045
dt.ParseFormat(wxT("2003-10-13"), wxT("%Y-%m-%d"));
2046
wxString str(dt.Format(wxT("%x")));
2048
const wxChar *p = str.c_str();
2052
if (n == dt.GetDay())
2054
format.Append(wxT("%d"));
2057
else if (n == (int)dt.GetMonth()+1)
2059
format.Append(wxT("%m"));
2062
else if (n == dt.GetYear())
2064
format.Append(wxT("%Y"));
2067
else if (n == (dt.GetYear() % 100))
2070
format.Append(wxT("%Y"));
2072
format.Append(wxT("%y"));
2076
format.Append(*p++);
2082
bool wxDateProperty::DoSetAttribute( const wxString& name, wxVariant& value )
2084
if ( name == wxPG_DATE_FORMAT )
2086
m_format = value.GetString();
2089
else if ( name == wxPG_DATE_PICKER_STYLE )
2091
m_dpStyle = value.GetLong();
2092
ms_defaultDateFormat.clear(); // This may need recalculation
2098
#endif // wxUSE_DATETIME
2101
// -----------------------------------------------------------------------
2102
// wxPropertyGridInterface
2103
// -----------------------------------------------------------------------
2105
void wxPropertyGridInterface::InitAllTypeHandlers()
2107
//wxPG_INIT_REQUIRED_TYPE(wxColour)
2108
//wxPG_INIT_REQUIRED_TYPE(wxFont)
2109
//wxPG_INIT_REQUIRED_TYPE(wxArrayInt)
2110
//wxPG_INIT_REQUIRED_TYPE(wxColourPropertyValue)
2111
/*#if wxUSE_DATETIME
2112
wxPGRegisterDefaultValueType(wxDateTime)
2116
// -----------------------------------------------------------------------
2118
void wxPropertyGridInterface::RegisterAdditionalEditors()
2121
wxPGRegisterEditorClass(SpinCtrl);
2123
#if wxUSE_DATEPICKCTRL
2124
wxPGRegisterEditorClass(DatePickerCtrl);
2128
// -----------------------------------------------------------------------
2130
#endif // wxPG_INCLUDE_ADVPROPS