#include </home/zeitlin/src/wx/github/interface/wx/propgrid/editors.h>
This class can be used to have multiple buttons in a property editor.
You will need to create a new property editor class, override CreateControls, and have it return wxPGMultiButton instance in wxPGWindowList::SetSecondary().
For instance, here we add three buttons to a TextCtrl editor:
#include <wx/propgrid/editors.h> class wxSampleMultiButtonEditor : public wxPGTextCtrlEditor { wxDECLARE_DYNAMIC_CLASS(wxSampleMultiButtonEditor); public: wxSampleMultiButtonEditor() {} virtual ~wxSampleMultiButtonEditor() {} virtual wxString GetName() const { return "SampleMultiButtonEditor"; } virtual wxPGWindowList CreateControls( wxPropertyGrid* propGrid, wxPGProperty* property, const wxPoint& pos, const wxSize& sz ) const; virtual bool OnEvent( wxPropertyGrid* propGrid, wxPGProperty* property, wxWindow* ctrl, wxEvent& event ) const; }; wxIMPLEMENT_DYNAMIC_CLASS(wxSampleMultiButtonEditor, wxPGTextCtrlEditor); wxPGWindowList wxSampleMultiButtonEditor::CreateControls( wxPropertyGrid* propGrid, wxPGProperty* property, const wxPoint& pos, const wxSize& sz ) const { // Create and populate buttons-subwindow wxPGMultiButton* buttons = new wxPGMultiButton( propGrid, sz ); // Add two regular buttons buttons->Add( "..." ); buttons->Add( "A" ); // Add a bitmap button buttons->Add( wxArtProvider::GetBitmap(wxART_FOLDER) ); // Create the 'primary' editor control (textctrl in this case) wxPGWindowList wndList = wxPGTextCtrlEditor::CreateControls ( propGrid, property, pos, buttons->GetPrimarySize() ); // Finally, move buttons-subwindow to correct position and make sure // returned wxPGWindowList contains our custom button list. buttons->Finalize(propGrid, pos); wndList.SetSecondary( buttons ); return wndList; } bool wxSampleMultiButtonEditor::OnEvent( wxPropertyGrid* propGrid, wxPGProperty* property, wxWindow* ctrl, wxEvent& event ) const { if ( event.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED ) { wxPGMultiButton* buttons = (wxPGMultiButton*) propGrid->GetEditorControlSecondary(); if ( event.GetId() == buttons->GetButtonId(0) ) { // Do something when the first button is pressed // Return true if the action modified the value in editor. ... } if ( event.GetId() == buttons->GetButtonId(1) ) { // Do something when the second button is pressed ... } if ( event.GetId() == buttons->GetButtonId(2) ) { // Do something when the third button is pressed ... } } return wxPGTextCtrlEditor::OnEvent(propGrid, property, ctrl, event); }
Further to use this editor, code like this can be used:
// Register editor class - needs only to be called once wxPGEditor* multiButtonEditor = new wxSampleMultiButtonEditor(); wxPropertyGrid::RegisterEditorClass( multiButtonEditor ); // Insert the property that will have multiple buttons propGrid->Append( new wxLongStringProperty("MultipleButtons", wxPG_LABEL) ); // Change property to use editor created in the previous code segment propGrid->SetPropertyEditor( "MultipleButtons", multiButtonEditor );
Public Member Functions | |
wxPGMultiButton (wxPropertyGrid *pg, const wxSize &sz) | |
Constructor. | |
virtual | ~wxPGMultiButton () |
Destructor. | |
void | Add (const wxString &label, int id=-2) |
Adds new button, with given label. | |
void | Add (const wxBitmap &bitmap, int id=-2) |
Adds new bitmap button. | |
void | Finalize (wxPropertyGrid *propGrid, const wxPoint &pos) |
Call this in CreateControls() of your custom editor class after all buttons have been added. | |
wxWindow * | GetButton (unsigned int i) |
Returns pointer to one of the buttons. | |
int | GetButtonId (unsigned int i) const |
Returns Id of one of the buttons. | |
unsigned int | GetCount () |
Returns number of buttons. | |
wxSize | GetPrimarySize () const |
Returns size of primary editor control, as appropriately reduced by number of buttons present. |
wxPGMultiButton::wxPGMultiButton | ( | wxPropertyGrid * | pg, |
const wxSize & | sz | ||
) |
Constructor.
virtual wxPGMultiButton::~wxPGMultiButton | ( | ) | [inline, virtual] |
Destructor.
void wxPGMultiButton::Add | ( | const wxString & | label, |
int | id = -2 |
||
) |
Adds new button, with given label.
void wxPGMultiButton::Add | ( | const wxBitmap & | bitmap, |
int | id = -2 |
||
) |
Adds new bitmap button.
void wxPGMultiButton::Finalize | ( | wxPropertyGrid * | propGrid, |
const wxPoint & | pos | ||
) |
Call this in CreateControls() of your custom editor class after all buttons have been added.
propGrid | wxPropertyGrid given in CreateControls(). |
pos | wxPoint given in CreateControls(). |
wxWindow* wxPGMultiButton::GetButton | ( | unsigned int | i | ) |
Returns pointer to one of the buttons.
int wxPGMultiButton::GetButtonId | ( | unsigned int | i | ) | const |
Returns Id of one of the buttons.
This is utility function to be used in event handlers.
unsigned int wxPGMultiButton::GetCount | ( | ) |
Returns number of buttons.
wxSize wxPGMultiButton::GetPrimarySize | ( | ) | const |
Returns size of primary editor control, as appropriately reduced by number of buttons present.