wxPGMultiButton Class Reference

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

#include <editors.h>

List of all members.

Public Member Functions

void Add (const wxString &label, int id=-2)
void FinalizePosition (const wxPoint &pos)
const wxWindow * GetButton (unsigned int i) const
wxWindow * GetButton (unsigned int i)
int GetButtonId (unsigned int i) const
int GetCount () const
wxSize GetPrimarySize () const
 wxPGMultiButton (wxPropertyGrid *pg, const wxSize &sz)
virtual ~wxPGMultiButton ()

Protected Member Functions

int GenId (int id) const

Protected Attributes

wxArrayPtrVoid m_buttons
int m_buttonsWidth
wxSize m_fullEditorSize

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 wxMultiButtonTextCtrlEditor : public wxPGTextCtrlEditor
    {
        WX_PG_DECLARE_EDITOR_CLASS(wxMultiButtonTextCtrlEditor)
    public:
        wxMultiButtonTextCtrlEditor() {}
        virtual ~wxMultiButtonTextCtrlEditor() {}

        wxPG_DECLARE_CREATECONTROLS
        virtual bool OnEvent( wxPropertyGrid* propGrid,
                              wxPGProperty* property,
                              wxWindow* ctrl,
                              wxEvent& event ) const;

    };

    WX_PG_IMPLEMENT_EDITOR_CLASS(MultiButtonTextCtrlEditor, wxMultiButtonTextCtrlEditor,
                                 wxPGTextCtrlEditor)

    wxPGWindowList wxMultiButtonTextCtrlEditor::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( wxT("...") );
        buttons->Add( wxT("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->FinalizePosition(pos);

        wndList.SetSecondary( buttons );
        return wndList;
    }

    bool wxMultiButtonTextCtrlEditor::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 value in editor changed by this
                // action.
                ...
            }
            if ( event.GetId() == buttons->GetButtonId(1) )
            {
                // Do something when second button is pressed
                ...
            }
            if ( event.GetId() == buttons->GetButtonId(2) )
            {
                // Do something when 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
        wxPGRegisterEditorClass( MultiButtonTextCtrlEditor );

        // Insert the property that will have multiple buttons
        propGrid->Append( new wxLongStringProperty(wxT("MultipleButtons"), wxPG_LABEL) );

        // Change property to use editor created in the previous code segment
        propGrid->SetPropertyEditor( wxT("MultipleButtons"), wxPG_EDITOR(MultiButtonTextCtrlEditor) );

Definition at line 552 of file editors.h.


Constructor & Destructor Documentation

wxPGMultiButton::wxPGMultiButton ( wxPropertyGrid pg,
const wxSize &  sz 
)
virtual wxPGMultiButton::~wxPGMultiButton (  )  [inline, virtual]

Definition at line 558 of file editors.h.


Member Function Documentation

void wxPGMultiButton::Add ( const wxString &  label,
int  id = -2 
)
void wxPGMultiButton::FinalizePosition ( const wxPoint &  pos  )  [inline]

Definition at line 581 of file editors.h.

int wxPGMultiButton::GenId ( int  id  )  const [protected]
const wxWindow* wxPGMultiButton::GetButton ( unsigned int  i  )  const [inline]

Definition at line 561 of file editors.h.

wxWindow* wxPGMultiButton::GetButton ( unsigned int  i  )  [inline]

Definition at line 560 of file editors.h.

int wxPGMultiButton::GetButtonId ( unsigned int  i  )  const [inline]

Utility function to be used in event handlers.

Definition at line 565 of file editors.h.

int wxPGMultiButton::GetCount (  )  const [inline]

Returns number of buttons.

Definition at line 569 of file editors.h.

wxSize wxPGMultiButton::GetPrimarySize (  )  const [inline]

Definition at line 576 of file editors.h.


Member Data Documentation

wxArrayPtrVoid wxPGMultiButton::m_buttons [protected]

Definition at line 591 of file editors.h.

Definition at line 593 of file editors.h.

Definition at line 592 of file editors.h.


The documentation for this class was generated from the following file:
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


wxpropgrid
Author(s): Jaakko Salli
autogenerated on Fri Jan 11 09:34:07 2013