2008-09-12 16:57:41 -04:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: editors.h
|
|
|
|
// Purpose: interface of wxPropertyGrid editors
|
|
|
|
// Author: wxWidgets team
|
2008-10-06 11:14:06 -04:00
|
|
|
// RCS-ID: $Id$
|
2008-09-12 16:57:41 -04:00
|
|
|
// Licence: wxWindows license
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
2008-09-27 10:03:10 -04:00
|
|
|
/**
|
|
|
|
@class wxPGEditor
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
Base class for custom wxPropertyGrid editors.
|
|
|
|
|
|
|
|
@remarks
|
2008-09-27 10:03:10 -04:00
|
|
|
- Names of built-in property editors are: TextCtrl, Choice,
|
|
|
|
ComboBox, CheckBox, TextCtrlAndButton, and ChoiceAndButton. Additional
|
|
|
|
editors include SpinCtrl and DatePickerCtrl, but using them requires
|
|
|
|
calling wxPropertyGrid::RegisterAdditionalEditors() prior use.
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-27 10:03:10 -04:00
|
|
|
- Pointer to built-in editor is available as wxPGEditor_EditorName
|
2008-09-12 16:57:41 -04:00
|
|
|
(eg. wxPGEditor_TextCtrl).
|
|
|
|
|
2008-09-27 10:03:10 -04:00
|
|
|
- Before you start using new editor you just created, you need to register
|
|
|
|
it using static function
|
2008-09-12 16:57:41 -04:00
|
|
|
wxPropertyGrid::RegisterEditorClass(), with code like this:
|
|
|
|
@code
|
|
|
|
wxPGEditor* editorPointer = wxPropertyGrid::RegisterEditorClass(new MyEditorClass(), "MyEditor");
|
|
|
|
@endcode
|
|
|
|
After that, wxPropertyGrid will take ownership of the given object, but
|
|
|
|
you should still store editorPointer somewhere, so you can pass it to
|
|
|
|
wxPGProperty::SetEditor(), or return it from wxPGEditor::DoGetEditorClass().
|
|
|
|
|
|
|
|
@library{wxpropgrid}
|
|
|
|
@category{propgrid}
|
|
|
|
*/
|
|
|
|
class wxPGEditor : public wxObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
/** Constructor. */
|
2008-10-22 16:48:31 -04:00
|
|
|
wxPGEditor();
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
/** Destructor. */
|
|
|
|
virtual ~wxPGEditor();
|
|
|
|
|
2008-09-27 10:03:10 -04:00
|
|
|
/**
|
|
|
|
Returns pointer to the name of the editor. For example,
|
2008-10-06 11:48:27 -04:00
|
|
|
wxPGEditor_TextCtrl has name "TextCtrl". If you dont' need to access
|
|
|
|
your custom editor by string name, then you do not need to implement
|
|
|
|
this function.
|
2008-09-12 16:57:41 -04:00
|
|
|
*/
|
2008-10-06 11:48:27 -04:00
|
|
|
virtual wxString GetName() const;
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-27 10:03:10 -04:00
|
|
|
/**
|
|
|
|
Instantiates editor controls.
|
|
|
|
|
2008-09-12 16:57:41 -04:00
|
|
|
@param propgrid
|
2008-09-27 10:03:10 -04:00
|
|
|
wxPropertyGrid to which the property belongs (use as parent for control).
|
|
|
|
|
2008-09-12 16:57:41 -04:00
|
|
|
@param property
|
2008-09-27 10:03:10 -04:00
|
|
|
Property for which this method is called.
|
|
|
|
|
2008-09-12 16:57:41 -04:00
|
|
|
@param pos
|
2008-09-27 10:03:10 -04:00
|
|
|
Position, inside wxPropertyGrid, to create control(s) to.
|
|
|
|
|
2008-09-12 16:57:41 -04:00
|
|
|
@param size
|
2008-09-27 10:03:10 -04:00
|
|
|
Initial size for control(s).
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
@remarks
|
|
|
|
- Primary control shall use id wxPG_SUBID1, and secondary (button) control
|
|
|
|
shall use wxPG_SUBID2.
|
2008-11-23 06:00:40 -05:00
|
|
|
- Unlike in previous version of wxPropertyGrid, it is no longer
|
|
|
|
necessary to call wxEvtHandler::Connect() for interesting editor
|
|
|
|
events. Instead, all events from control are now automatically
|
|
|
|
forwarded to wxPGEditor::OnEvent() and wxPGProperty::OnEvent().
|
2008-09-12 16:57:41 -04:00
|
|
|
*/
|
2008-09-27 10:03:10 -04:00
|
|
|
virtual wxPGWindowList CreateControls( wxPropertyGrid* propgrid,
|
|
|
|
wxPGProperty* property,
|
|
|
|
const wxPoint& pos,
|
|
|
|
const wxSize& size ) const = 0;
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
/** Loads value from property to the control. */
|
|
|
|
virtual void UpdateControl( wxPGProperty* property, wxWindow* ctrl ) const = 0;
|
|
|
|
|
2008-09-27 10:03:10 -04:00
|
|
|
/**
|
|
|
|
Draws value for given property.
|
2008-09-12 16:57:41 -04:00
|
|
|
*/
|
2008-09-27 10:03:10 -04:00
|
|
|
virtual void DrawValue( wxDC& dc, const wxRect& rect,
|
|
|
|
wxPGProperty* property, const wxString& text ) const;
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-27 10:03:10 -04:00
|
|
|
/**
|
|
|
|
Handles events. Returns @true if value in control was modified
|
|
|
|
(see wxPGProperty::OnEvent() for more information).
|
2008-10-01 12:24:21 -04:00
|
|
|
|
|
|
|
@remarks wxPropertyGrid will automatically unfocus the editor when
|
2008-10-22 16:48:31 -04:00
|
|
|
wxEVT_COMMAND_TEXT_ENTER is received and when it results in
|
|
|
|
property value being modified. This happens regardless of
|
|
|
|
editor type (ie. behavior is same for any wxTextCtrl and
|
|
|
|
wxComboBox based editor).
|
2008-09-12 16:57:41 -04:00
|
|
|
*/
|
|
|
|
virtual bool OnEvent( wxPropertyGrid* propgrid, wxPGProperty* property,
|
|
|
|
wxWindow* wnd_primary, wxEvent& event ) const = 0;
|
|
|
|
|
2008-09-27 10:03:10 -04:00
|
|
|
/**
|
|
|
|
Returns value from control, via parameter 'variant'.
|
|
|
|
Usually ends up calling property's StringToValue() or IntToValue().
|
|
|
|
Returns @true if value was different.
|
2008-09-12 16:57:41 -04:00
|
|
|
*/
|
2008-09-27 10:03:10 -04:00
|
|
|
virtual bool GetValueFromControl( wxVariant& variant, wxPGProperty* property,
|
2008-10-22 16:48:31 -04:00
|
|
|
wxWindow* ctrl ) const;
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
/** Sets value in control to unspecified. */
|
2008-09-27 10:03:10 -04:00
|
|
|
virtual void SetValueToUnspecified( wxPGProperty* property,
|
2008-10-22 16:48:31 -04:00
|
|
|
wxWindow* ctrl ) const = 0;
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2009-12-25 03:33:56 -05:00
|
|
|
/**
|
|
|
|
Called by property grid to set new appearance for the control.
|
|
|
|
Default implementation sets foreground colour, background colour,
|
|
|
|
font, plus text for wxTextCtrl and wxComboCtrl.
|
|
|
|
|
|
|
|
@param appearance
|
|
|
|
New appearance to be applied.
|
|
|
|
|
|
|
|
@param oldAppearance
|
|
|
|
Previously applied appearance. Used to detect which
|
|
|
|
control attributes need to be changed (e.g. so we only
|
|
|
|
change background colour if really needed).
|
|
|
|
|
|
|
|
@param unspecified
|
|
|
|
@true if the new appearance represents an unspecified
|
|
|
|
property value.
|
|
|
|
*/
|
|
|
|
virtual void SetControlAppearance( wxPropertyGrid* pg,
|
|
|
|
wxPGProperty* property,
|
|
|
|
wxWindow* ctrl,
|
|
|
|
const wxPGCell& appearance,
|
|
|
|
const wxPGCell& oldAppearance,
|
|
|
|
bool unspecified ) const;
|
|
|
|
|
2008-09-12 16:57:41 -04:00
|
|
|
/** Sets control's value specifically from string. */
|
2008-09-27 10:03:10 -04:00
|
|
|
virtual void SetControlStringValue( wxPGProperty* property,
|
2008-10-22 16:48:31 -04:00
|
|
|
wxWindow* ctrl, const wxString& txt ) const;
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
/** Sets control's value specifically from int (applies to choice etc.). */
|
2008-09-27 10:03:10 -04:00
|
|
|
virtual void SetControlIntValue( wxPGProperty* property,
|
2008-10-22 16:48:31 -04:00
|
|
|
wxWindow* ctrl, int value ) const;
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-27 10:03:10 -04:00
|
|
|
/**
|
|
|
|
Inserts item to existing control. Index -1 means end of list.
|
2008-09-12 16:57:41 -04:00
|
|
|
Default implementation does nothing. Returns index of item added.
|
|
|
|
*/
|
2008-10-22 16:48:31 -04:00
|
|
|
virtual int InsertItem( wxWindow* ctrl, const wxString& label, int index ) const;
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-27 10:03:10 -04:00
|
|
|
/**
|
|
|
|
Deletes item from existing control.
|
2008-09-12 16:57:41 -04:00
|
|
|
Default implementation does nothing.
|
|
|
|
*/
|
|
|
|
virtual void DeleteItem( wxWindow* ctrl, int index ) const;
|
|
|
|
|
2008-09-27 10:03:10 -04:00
|
|
|
/**
|
2008-10-22 16:48:31 -04:00
|
|
|
Extra processing when control gains focus.
|
|
|
|
For example, wxTextCtrl based controls should select all text.
|
2008-09-12 16:57:41 -04:00
|
|
|
*/
|
|
|
|
virtual void OnFocus( wxPGProperty* property, wxWindow* wnd ) const;
|
|
|
|
|
2008-09-27 10:03:10 -04:00
|
|
|
/**
|
2008-10-22 16:48:31 -04:00
|
|
|
Returns @true if control itself can contain the custom image.
|
|
|
|
Default implementation returns @false.
|
2008-09-12 16:57:41 -04:00
|
|
|
*/
|
|
|
|
virtual bool CanContainCustomImage() const;
|
|
|
|
};
|
|
|
|
|
2008-10-22 16:48:31 -04:00
|
|
|
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-27 10:03:10 -04:00
|
|
|
/**
|
|
|
|
@class wxPGMultiButton
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
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().
|
2008-09-27 10:03:10 -04:00
|
|
|
|
|
|
|
For instance, here we add three buttons to a TextCtrl editor:
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
@code
|
|
|
|
#include <wx/propgrid/editors.h>
|
|
|
|
|
2008-09-27 10:03:10 -04:00
|
|
|
class wxSampleMultiButtonEditor : public wxPGTextCtrlEditor
|
2008-09-12 16:57:41 -04:00
|
|
|
{
|
2008-09-27 10:03:10 -04:00
|
|
|
DECLARE_DYNAMIC_CLASS(wxSampleMultiButtonEditor)
|
2008-09-12 16:57:41 -04:00
|
|
|
public:
|
2008-09-27 10:03:10 -04:00
|
|
|
wxSampleMultiButtonEditor() {}
|
|
|
|
virtual ~wxSampleMultiButtonEditor() {}
|
|
|
|
|
|
|
|
virtual wxString GetName() const { return "SampleMultiButtonEditor"; }
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-27 10:03:10 -04:00
|
|
|
virtual wxPGWindowList CreateControls( wxPropertyGrid* propGrid,
|
|
|
|
wxPGProperty* property,
|
|
|
|
const wxPoint& pos,
|
|
|
|
const wxSize& sz ) const;
|
2008-09-12 16:57:41 -04:00
|
|
|
virtual bool OnEvent( wxPropertyGrid* propGrid,
|
|
|
|
wxPGProperty* property,
|
|
|
|
wxWindow* ctrl,
|
|
|
|
wxEvent& event ) const;
|
|
|
|
};
|
|
|
|
|
2008-09-27 10:03:10 -04:00
|
|
|
IMPLEMENT_DYNAMIC_CLASS(wxSampleMultiButtonEditor, wxPGTextCtrlEditor)
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-27 10:03:10 -04:00
|
|
|
wxPGWindowList wxSampleMultiButtonEditor::CreateControls( wxPropertyGrid* propGrid,
|
|
|
|
wxPGProperty* property,
|
|
|
|
const wxPoint& pos,
|
|
|
|
const wxSize& sz ) const
|
2008-09-12 16:57:41 -04:00
|
|
|
{
|
|
|
|
// 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
|
2008-09-27 10:03:10 -04:00
|
|
|
( propGrid, property, pos,
|
|
|
|
buttons->GetPrimarySize() );
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
// Finally, move buttons-subwindow to correct position and make sure
|
|
|
|
// returned wxPGWindowList contains our custom button list.
|
2008-09-27 10:03:10 -04:00
|
|
|
buttons->Finalize(propGrid, pos);
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
wndList.SetSecondary( buttons );
|
|
|
|
return wndList;
|
|
|
|
}
|
|
|
|
|
2008-09-27 10:03:10 -04:00
|
|
|
bool wxSampleMultiButtonEditor::OnEvent( wxPropertyGrid* propGrid,
|
|
|
|
wxPGProperty* property,
|
|
|
|
wxWindow* ctrl,
|
|
|
|
wxEvent& event ) const
|
2008-09-12 16:57:41 -04:00
|
|
|
{
|
|
|
|
if ( event.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED )
|
|
|
|
{
|
|
|
|
wxPGMultiButton* buttons = (wxPGMultiButton*) propGrid->GetEditorControlSecondary();
|
|
|
|
|
|
|
|
if ( event.GetId() == buttons->GetButtonId(0) )
|
|
|
|
{
|
2009-03-09 14:32:43 -04:00
|
|
|
// Do something when the first button is pressed
|
|
|
|
// Return true if the action modified the value in editor.
|
|
|
|
...
|
2008-09-12 16:57:41 -04:00
|
|
|
}
|
|
|
|
if ( event.GetId() == buttons->GetButtonId(1) )
|
|
|
|
{
|
2009-03-09 14:32:43 -04:00
|
|
|
// Do something when the second button is pressed
|
|
|
|
...
|
2008-09-12 16:57:41 -04:00
|
|
|
}
|
|
|
|
if ( event.GetId() == buttons->GetButtonId(2) )
|
|
|
|
{
|
2009-03-09 14:32:43 -04:00
|
|
|
// Do something when the third button is pressed
|
|
|
|
...
|
2008-09-12 16:57:41 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return wxPGTextCtrlEditor::OnEvent(propGrid, property, ctrl, event);
|
|
|
|
}
|
|
|
|
@endcode
|
|
|
|
|
|
|
|
Further to use this editor, code like this can be used:
|
|
|
|
|
|
|
|
@code
|
|
|
|
// Register editor class - needs only to be called once
|
2008-09-27 10:03:10 -04:00
|
|
|
wxPGEditor* multiButtonEditor = new wxSampleMultiButtonEditor();
|
|
|
|
wxPropertyGrid::RegisterEditorClass( multiButtonEditor );
|
2008-09-12 16:57:41 -04:00
|
|
|
|
|
|
|
// 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
|
2008-09-27 10:03:10 -04:00
|
|
|
propGrid->SetPropertyEditor( "MultipleButtons", multiButtonEditor );
|
2008-09-12 16:57:41 -04:00
|
|
|
@endcode
|
|
|
|
|
|
|
|
@library{wxpropgrid}
|
|
|
|
@category{propgrid}
|
|
|
|
*/
|
|
|
|
class WXDLLIMPEXP_PROPGRID wxPGMultiButton : public wxWindow
|
|
|
|
{
|
|
|
|
public:
|
2008-09-27 10:03:10 -04:00
|
|
|
/**
|
|
|
|
Constructor.
|
|
|
|
*/
|
2008-09-12 16:57:41 -04:00
|
|
|
wxPGMultiButton( wxPropertyGrid* pg, const wxSize& sz );
|
|
|
|
|
2008-09-27 10:03:10 -04:00
|
|
|
/**
|
|
|
|
Destructor.
|
|
|
|
*/
|
2008-09-12 16:57:41 -04:00
|
|
|
virtual ~wxPGMultiButton() { }
|
|
|
|
|
2008-09-27 10:03:10 -04:00
|
|
|
/**
|
|
|
|
Adds new button, with given label.
|
|
|
|
*/
|
|
|
|
void Add( const wxString& label, int id = -2 );
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-27 10:03:10 -04:00
|
|
|
/**
|
|
|
|
Adds new bitmap button.
|
2008-09-12 16:57:41 -04:00
|
|
|
*/
|
2008-09-27 10:03:10 -04:00
|
|
|
void Add( const wxBitmap& bitmap, int id = -2 );
|
|
|
|
|
|
|
|
/**
|
|
|
|
Call this in CreateControls() of your custom editor class
|
|
|
|
after all buttons have been added.
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-27 10:03:10 -04:00
|
|
|
@param propGrid
|
|
|
|
wxPropertyGrid given in CreateControls().
|
|
|
|
|
|
|
|
@param pos
|
|
|
|
wxPoint given in CreateControls().
|
2008-09-12 16:57:41 -04:00
|
|
|
*/
|
2008-09-27 10:03:10 -04:00
|
|
|
void Finalize( wxPropertyGrid* propGrid, const wxPoint& pos );
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-27 10:03:10 -04:00
|
|
|
/**
|
|
|
|
Returns pointer to one of the buttons.
|
|
|
|
*/
|
|
|
|
wxWindow* GetButton( unsigned int i );
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-27 10:03:10 -04:00
|
|
|
/**
|
2008-10-22 16:48:31 -04:00
|
|
|
Returns Id of one of the buttons.
|
|
|
|
This is utility function to be used in event handlers.
|
2008-09-27 10:03:10 -04:00
|
|
|
*/
|
|
|
|
int GetButtonId( unsigned int i ) const;
|
2008-09-12 16:57:41 -04:00
|
|
|
|
2008-09-27 10:03:10 -04:00
|
|
|
/**
|
|
|
|
Returns number of buttons.
|
|
|
|
*/
|
2008-10-12 08:23:48 -04:00
|
|
|
unsigned int GetCount();
|
2008-09-27 10:03:10 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns size of primary editor control, as appropriately
|
|
|
|
reduced by number of buttons present.
|
|
|
|
*/
|
|
|
|
wxSize GetPrimarySize() const;
|
2008-09-12 16:57:41 -04:00
|
|
|
};
|
|
|
|
|