X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/48a32cf671d960423138e567ae6835449d7dbd51..474e9711477a5737b232435525da1c87f7eb72d2:/samples/propgrid/propgrid.cpp diff --git a/samples/propgrid/propgrid.cpp b/samples/propgrid/propgrid.cpp index 092b6c6360..74742446d1 100644 --- a/samples/propgrid/propgrid.cpp +++ b/samples/propgrid/propgrid.cpp @@ -493,7 +493,9 @@ void wxVectorProperty::RefreshChildren() Item(2)->SetValue( vector.z ); } -void wxVectorProperty::ChildChanged( wxVariant& thisValue, int childIndex, wxVariant& childValue ) const +wxVariant wxVectorProperty::ChildChanged( wxVariant& thisValue, + int childIndex, + wxVariant& childValue ) const { wxVector3f vector; vector << thisValue; @@ -503,7 +505,9 @@ void wxVectorProperty::ChildChanged( wxVariant& thisValue, int childIndex, wxVar case 1: vector.y = childValue.GetDouble(); break; case 2: vector.z = childValue.GetDouble(); break; } - thisValue << vector; + wxVariant newVariant; + newVariant << vector; + return newVariant; } @@ -541,7 +545,9 @@ void wxTriangleProperty::RefreshChildren() Item(2)->SetValue( WXVARIANT(triangle.c) ); } -void wxTriangleProperty::ChildChanged( wxVariant& thisValue, int childIndex, wxVariant& childValue ) const +wxVariant wxTriangleProperty::ChildChanged( wxVariant& thisValue, + int childIndex, + wxVariant& childValue ) const { wxTriangle triangle; triangle << thisValue; @@ -552,7 +558,9 @@ void wxTriangleProperty::ChildChanged( wxVariant& thisValue, int childIndex, wxV case 1: triangle.b = vector; break; case 2: triangle.c = vector; break; } - thisValue << triangle; + wxVariant newVariant; + newVariant << triangle; + return newVariant; } @@ -679,7 +687,8 @@ enum ID_SELECTSTYLE, ID_SAVESTATE, ID_RESTORESTATE, - ID_RUNMINIMAL + ID_RUNMINIMAL, + ID_ENABLELABELEDITING }; // ----------------------------------------------------------------------- @@ -705,6 +714,12 @@ BEGIN_EVENT_TABLE(FormMain, wxFrame) EVT_PG_DOUBLE_CLICK( PGID, FormMain::OnPropertyGridItemDoubleClick ) // This occurs when propgridmanager's page changes. EVT_PG_PAGE_CHANGED( PGID, FormMain::OnPropertyGridPageChange ) + // This occurs when user starts editing a property label + EVT_PG_LABEL_EDIT_BEGIN( PGID, + FormMain::OnPropertyGridLabelEditBegin ) + // This occurs when user stops editing a property label + EVT_PG_LABEL_EDIT_ENDING( PGID, + FormMain::OnPropertyGridLabelEditEnding ) // This occurs when property's editor button (if any) is clicked. EVT_BUTTON( PGID, FormMain::OnPropertyGridButtonClick ) @@ -737,6 +752,7 @@ BEGIN_EVENT_TABLE(FormMain, wxFrame) EVT_MENU( ID_SETBGCOLOURRECUR, FormMain::OnSetBackgroundColour ) EVT_MENU( ID_CLEARMODIF, FormMain::OnClearModifyStatusClick ) EVT_MENU( ID_FREEZE, FormMain::OnFreezeClick ) + EVT_MENU( ID_ENABLELABELEDITING, FormMain::OnEnableLabelEditing ) EVT_MENU( ID_DUMPLIST, FormMain::OnDumpList ) EVT_MENU( ID_COLOURSCHEME1, FormMain::OnColourScheme ) @@ -912,11 +928,11 @@ void FormMain::OnPropertyGridChange( wxPropertyGridEvent& event ) SetSize ( m_pPropGridManager->GetPropertyValueAsInt(property), -1, -1, -1, wxSIZE_USE_EXISTING ); else if ( name == wxT("Y") ) // wxPGVariantToInt is safe long int value getter - SetSize ( -1, wxPGVariantToInt(value), -1, -1, wxSIZE_USE_EXISTING ); + SetSize ( -1, value.GetLong(), -1, -1, wxSIZE_USE_EXISTING ); else if ( name == wxT("Width") ) SetSize ( -1, -1, m_pPropGridManager->GetPropertyValueAsInt(property), -1, wxSIZE_USE_EXISTING ); else if ( name == wxT("Height") ) - SetSize ( -1, -1, -1, wxPGVariantToInt(value), wxSIZE_USE_EXISTING ); + SetSize ( -1, -1, -1, value.GetLong(), wxSIZE_USE_EXISTING ); else if ( name == wxT("Label") ) { SetTitle ( m_pPropGridManager->GetPropertyValueAsString(property) ); @@ -1010,6 +1026,22 @@ void FormMain::OnPropertyGridPageChange( wxPropertyGridEvent& WXUNUSED(event) ) // ----------------------------------------------------------------------- +void FormMain::OnPropertyGridLabelEditBegin( wxPropertyGridEvent& event ) +{ + wxLogDebug("wxPG_EVT_LABEL_EDIT_BEGIN(%s)", + event.GetProperty()->GetLabel().c_str()); +} + +// ----------------------------------------------------------------------- + +void FormMain::OnPropertyGridLabelEditEnding( wxPropertyGridEvent& event ) +{ + wxLogDebug("wxPG_EVT_LABEL_EDIT_ENDING(%s)", + event.GetProperty()->GetLabel().c_str()); +} + +// ----------------------------------------------------------------------- + void FormMain::OnPropertyGridHighlight( wxPropertyGridEvent& WXUNUSED(event) ) { } @@ -1921,7 +1953,7 @@ void wxMyPropertyGridPage::OnPropertySelect( wxPropertyGridEvent& WXUNUSED(event void wxMyPropertyGridPage::OnPropertyChange( wxPropertyGridEvent& event ) { wxPGProperty* p = event.GetProperty(); - wxLogDebug(wxT("wxMyPropertyGridPage::OnPropertyChange('%s', to value '%s')"), + wxLogVerbose(wxT("wxMyPropertyGridPage::OnPropertyChange('%s', to value '%s')"), p->GetName().c_str(), p->GetDisplayedString().c_str()); } @@ -1929,7 +1961,7 @@ void wxMyPropertyGridPage::OnPropertyChange( wxPropertyGridEvent& event ) void wxMyPropertyGridPage::OnPropertyChanging( wxPropertyGridEvent& event ) { wxPGProperty* p = event.GetProperty(); - wxLogDebug(wxT("wxMyPropertyGridPage::OnPropertyChanging('%s', to value '%s')"), + wxLogVerbose(wxT("wxMyPropertyGridPage::OnPropertyChanging('%s', to value '%s')"), p->GetName().c_str(), event.GetValue().GetString().c_str()); } @@ -2037,7 +2069,8 @@ void FormMain::CreateGrid( int style, int extraStyle ) if ( extraStyle == -1 ) // default extra style - extraStyle = wxPG_EX_MODE_BUTTONS; + extraStyle = wxPG_EX_MODE_BUTTONS | + wxPG_EX_MULTIPLE_SELECTION; //| wxPG_EX_AUTO_UNSPECIFIED_VALUES //| wxPG_EX_GREY_LABEL_WHEN_DISABLED //| wxPG_EX_NATIVE_DOUBLE_BUFFERING @@ -2058,7 +2091,10 @@ void FormMain::CreateGrid( int style, int extraStyle ) // event handling will obviously be broken. PGID, /*wxID_ANY*/ wxDefaultPosition, - wxDefaultSize, + wxSize(100, 100), // FIXME: wxDefaultSize gives assertion in propgrid. + // But calling SetInitialSize in manager changes the code + // order to the grid gets created immediately, before SetExtraStyle + // is called. style ); m_propGrid = pgman->GetGrid(); @@ -2132,7 +2168,8 @@ FormMain::FormMain(const wxString& title, const wxPoint& pos, const wxSize& size wxPG_TOOLBAR | wxPG_DESCRIPTION, // extra style - wxPG_EX_MODE_BUTTONS + wxPG_EX_MODE_BUTTONS | + wxPG_EX_MULTIPLE_SELECTION //| wxPG_EX_AUTO_UNSPECIFIED_VALUES //| wxPG_EX_GREY_LABEL_WHEN_DISABLED //| wxPG_EX_NATIVE_DOUBLE_BUFFERING @@ -2209,6 +2246,8 @@ FormMain::FormMain(const wxString& title, const wxPoint& pos, const wxSize& size menuTry->Append(ID_SELECTSTYLE, wxT("Set Window Style"), wxT("Select window style flags used by the grid.")); + menuTry->Append(ID_ENABLELABELEDITING, "Enable label editing", + "This calls wxPropertyGrid::MakeColumnEditable(0)"); menuTry->AppendSeparator(); menuTry->AppendRadioItem( ID_COLOURSCHEME1, wxT("Standard Colour Scheme") ); menuTry->AppendRadioItem( ID_COLOURSCHEME2, wxT("White Colour Scheme") ); @@ -2430,6 +2469,8 @@ void FormMain::OnContextMenu( wxContextMenuEvent& event ) wxLogDebug(wxT("FormMain::OnContextMenu(%i,%i)"), event.GetPosition().x,event.GetPosition().y); + wxUnusedVar(event); + //event.Skip(); } @@ -2750,6 +2791,13 @@ void FormMain::OnFreezeClick( wxCommandEvent& event ) // ----------------------------------------------------------------------- +void FormMain::OnEnableLabelEditing( wxCommandEvent& WXUNUSED(event) ) +{ + m_propGrid->MakeColumnEditable(0); +} + +// ----------------------------------------------------------------------- + void FormMain::OnAbout(wxCommandEvent& WXUNUSED(event)) { wxString msg; @@ -2774,7 +2822,7 @@ void FormMain::OnAbout(wxCommandEvent& WXUNUSED(event)) wxT("Jaakko Salli"), wxVERSION_STRING ); - wxMessageBox(msg, _T("About"), wxOK | wxICON_INFORMATION, this); + wxMessageBox(msg, wxT("About"), wxOK | wxICON_INFORMATION, this); } // ----------------------------------------------------------------------- @@ -2891,6 +2939,7 @@ void FormMain::OnSelectStyle( wxCommandEvent& WXUNUSED(event) ) ADD_FLAG(wxPG_LIMITED_EDITING) ADD_FLAG(wxPG_TOOLBAR) ADD_FLAG(wxPG_DESCRIPTION) + ADD_FLAG(wxPG_NO_INTERNAL_BORDER) wxMultiChoiceDialog dlg( this, wxT("Select window styles to use"), wxT("wxPropertyGrid Window Style"), chs ); dlg.SetSelections(sel); @@ -2918,6 +2967,11 @@ void FormMain::OnSelectStyle( wxCommandEvent& WXUNUSED(event) ) ADD_FLAG(wxPG_EX_NATIVE_DOUBLE_BUFFERING) ADD_FLAG(wxPG_EX_AUTO_UNSPECIFIED_VALUES) ADD_FLAG(wxPG_EX_WRITEONLY_BUILTIN_ATTRIBUTES) + ADD_FLAG(wxPG_EX_HIDE_PAGE_BUTTONS) + ADD_FLAG(wxPG_EX_MULTIPLE_SELECTION) + ADD_FLAG(wxPG_EX_ENABLE_TLP_TRACKING) + ADD_FLAG(wxPG_EX_NO_TOOLBAR_DIVIDER) + ADD_FLAG(wxPG_EX_TOOLBAR_SEPARATOR) wxMultiChoiceDialog dlg( this, wxT("Select extra window styles to use"), wxT("wxPropertyGrid Extra Style"), chs ); dlg.SetSelections(sel); @@ -3128,8 +3182,8 @@ bool cxApplication::OnInit() //wxLocale Locale; //Locale.Init(wxLANGUAGE_FINNISH); - FormMain* frame = Form1 = new FormMain( wxT("wxPropertyGrid Sample"), wxPoint(0,0), wxSize(300,500) ); - frame->Show(true); + FormMain* frame = Form1 = new FormMain( wxT("wxPropertyGrid Sample"), wxPoint(0,0), wxSize(300,500) ); + frame->Show(true); // // Parse command-line @@ -3148,7 +3202,7 @@ bool cxApplication::OnInit() } } - return true; + return true; } // -----------------------------------------------------------------------