wxPGMultiButton Class Reference
[wxPropertyGrid]

#include <wx/propgrid/editors.h>

Inheritance diagram for wxPGMultiButton:

wxWindow wxEvtHandler wxObject

List of all members.


Detailed Description

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
    {
        DECLARE_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;
    };

    IMPLEMENT_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 first button is pressed
                return true;
            }
            if ( event.GetId() == buttons->GetButtonId(1) )
            {
                // Do something when second button is pressed
                return true;
            }
            if ( event.GetId() == buttons->GetButtonId(2) )
            {
                // Do something when third button is pressed
                return true;
            }
        }
        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 );

Library:  wxPropertyGrid

Category:  wxPropertyGrid

Public Member Functions

 wxPGMultiButton (wxPropertyGrid *pg, const wxSize &sz)
virtual ~wxPGMultiButton ()
void Add (const wxString &label, int id=-2)
void Add (const wxBitmap &bitmap, int id=-2)
void Finalize (wxPropertyGrid *propGrid, const wxPoint &pos)
wxWindowGetButton (unsigned int i)
int GetButtonId (unsigned int i) const
unsigned int GetCount ()
wxSize GetPrimarySize () const

Constructor & Destructor Documentation

wxPGMultiButton::wxPGMultiButton ( wxPropertyGrid pg,
const wxSize sz 
)

Constructor.

virtual wxPGMultiButton::~wxPGMultiButton (  )  [inline, virtual]

Destructor.


Member Function Documentation

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.

Parameters:
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.



wxWidgets logo

[ top ]