Eliminate need to call Connect() in wxPGEditor::CreateControls()

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56929 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Jaakko Salli
2008-11-23 11:00:40 +00:00
parent eb6a8d695e
commit b0996c3da0
7 changed files with 57 additions and 142 deletions

View File

@@ -114,17 +114,10 @@ public:
@remarks @remarks
- Primary control shall use id wxPG_SUBID1, and secondary (button) - Primary control shall use id wxPG_SUBID1, and secondary (button)
control shall use wxPG_SUBID2. control shall use wxPG_SUBID2.
- Implementation shoud connect all necessary events to the - Unlike in previous version of wxPropertyGrid, it is no longer
wxPropertyGrid::OnCustomEditorEvent. For Example: necessary to call wxEvtHandler::Connect() for interesting editor
@code events. Instead, all events from control are now automatically
// Relays wxEVT_COMMAND_TEXT_UPDATED events of primary editor forwarded to wxPGEditor::OnEvent() and wxPGProperty::OnEvent().
// control to the OnEvent.
control->Connect(control->GetId(), wxEVT_COMMAND_TEXT_UPDATED,
wxCommandEventHandler(wxPropertyGrid::OnCustomEditorEvent),
NULL, propgrid);
@endcode
OnCustomEditorEvent will then forward events, first to
wxPGEditor::OnEvent() and then to wxPGProperty::OnEvent().
*/ */
virtual wxPGWindowList CreateControls(wxPropertyGrid* propgrid, virtual wxPGWindowList CreateControls(wxPropertyGrid* propgrid,
wxPGProperty* property, wxPGProperty* property,

View File

@@ -495,8 +495,8 @@ enum wxPG_KEYBOARD_ACTIONS
#define wxPG_MAN_FL_PAGE_INSERTED 0x02000000 #define wxPG_MAN_FL_PAGE_INSERTED 0x02000000
// Active editor control is abnormally large // Active editor control is abnormally large
#define wxPG_FL_ABNORMAL_EDITOR 0x04000000 #define wxPG_FL_ABNORMAL_EDITOR 0x04000000
// Recursion guard for OnCustomEditorEvent // Recursion guard for HandleCustomEditorEvent
#define wxPG_FL_IN_ONCUSTOMEDITOREVENT 0x08000000 #define wxPG_FL_IN_HANDLECUSTOMEDITOREVENT 0x08000000
#define wxPG_FL_VALUE_CHANGE_IN_EVENT 0x10000000 #define wxPG_FL_VALUE_CHANGE_IN_EVENT 0x10000000
// Editor control width should not change on resize // Editor control width should not change on resize
#define wxPG_FL_FIXED_WIDTH_EDITOR 0x20000000 #define wxPG_FL_FIXED_WIDTH_EDITOR 0x20000000
@@ -1179,6 +1179,9 @@ public:
return m_wndEditor2; return m_wndEditor2;
} }
// Events from editor controls are forward to this function
void HandleCustomEditorEvent( wxEvent &event );
#ifndef SWIG #ifndef SWIG
/** /**
@@ -1196,22 +1199,6 @@ public:
// Mostly useful for page switching. // Mostly useful for page switching.
void SwitchState( wxPropertyGridPageState* pNewState ); void SwitchState( wxPropertyGridPageState* pNewState );
/**
When creating custom property editors, connect required editor events to
this function. For instance:
@code
control->Connect(control->GetId(), wxEVT_COMMAND_TEXT_UPDATED,
wxEventHandler(wxPropertyGrid::OnCustomEditorEvent),
NULL, propgrid);
@endcode
@remarks You should never need to call this function directly!
@see wxPGEditor::CreateControls(), wxEvtHandler::Connect()
*/
void OnCustomEditorEvent( wxEvent &event );
long GetInternalFlags() const { return m_iFlags; } long GetInternalFlags() const { return m_iFlags; }
bool HasInternalFlag( long flag ) const bool HasInternalFlag( long flag ) const
{ return (m_iFlags & flag) ? true : false; } { return (m_iFlags & flag) ? true : false; }
@@ -1327,7 +1314,6 @@ public:
*/ */
bool UnfocusEditor(); bool UnfocusEditor();
virtual bool ProcessEvent(wxEvent& event);
virtual void SetWindowStyleFlag( long style ); virtual void SetWindowStyleFlag( long style );
protected: protected:

View File

@@ -70,17 +70,10 @@ public:
@remarks @remarks
- Primary control shall use id wxPG_SUBID1, and secondary (button) control - Primary control shall use id wxPG_SUBID1, and secondary (button) control
shall use wxPG_SUBID2. shall use wxPG_SUBID2.
- Implementation shoud connect all necessary events to the - Unlike in previous version of wxPropertyGrid, it is no longer
wxPropertyGrid::OnCustomEditorEvent(). For example: necessary to call wxEvtHandler::Connect() for interesting editor
@code events. Instead, all events from control are now automatically
control->Connect(control->GetId(), wxEVT_COMMAND_TEXT_UPDATED, forwarded to wxPGEditor::OnEvent() and wxPGProperty::OnEvent().
wxEventHandler(wxPropertyGrid::OnCustomEditorEvent),
NULL, propgrid);
@endcode
OnCustomEditorEvent will then forward events, first to
wxPGEditor::OnEvent() and then to wxPGProperty::OnEvent().
@see wxPropertyGrid::OnCustomEditorEvent(), wxEvtHandler::Connect()
*/ */
virtual wxPGWindowList CreateControls( wxPropertyGrid* propgrid, virtual wxPGWindowList CreateControls( wxPropertyGrid* propgrid,
wxPGProperty* property, wxPGProperty* property,

View File

@@ -658,22 +658,6 @@ public:
*/ */
bool IsFrozen() const; bool IsFrozen() const;
/**
When creating custom property editors, connect required editor events to
this function. For instance:
@code
control->Connect(control->GetId(), wxEVT_COMMAND_TEXT_UPDATED,
wxEventHandler(wxPropertyGrid::OnCustomEditorEvent),
NULL, propgrid);
@endcode
@remarks You should never need to call this function directly!
@see wxPGEditor::CreateControls(), wxEvtHandler::Connect()
*/
void OnCustomEditorEvent( wxEvent &event );
/** /**
Redraws given property. Redraws given property.
*/ */

View File

@@ -137,24 +137,12 @@ wxPGWindowList wxPGSpinCtrlEditor::CreateControls( wxPropertyGrid* propgrid, wxP
wnd2->SetRange( INT_MIN, INT_MAX ); wnd2->SetRange( INT_MIN, INT_MAX );
wnd2->SetValue( 0 ); wnd2->SetValue( 0 );
wxWindowID id = wnd2->GetId();
wnd2->Connect( id, wxEVT_SCROLL_LINEUP,
wxEventHandler(wxPropertyGrid::OnCustomEditorEvent),
NULL, propgrid );
wnd2->Connect( id, wxEVT_SCROLL_LINEDOWN,
wxEventHandler(wxPropertyGrid::OnCustomEditorEvent),
NULL, propgrid );
// Let's add validator to make sure only numbers can be entered // Let's add validator to make sure only numbers can be entered
wxTextValidator validator(wxFILTER_NUMERIC, &m_tempString); wxTextValidator validator(wxFILTER_NUMERIC, &m_tempString);
wxTextCtrl* wnd1 = (wxTextCtrl*) wxPGTextCtrlEditor::CreateControls( propgrid, property, pos, tcSz ).m_primary; wxTextCtrl* wnd1 = (wxTextCtrl*) wxPGTextCtrlEditor::CreateControls( propgrid, property, pos, tcSz ).m_primary;
wnd1->SetValidator(validator); wnd1->SetValidator(validator);
wnd1->Connect( wnd1->GetId(), wxEVT_KEY_DOWN,
wxEventHandler(wxPropertyGrid::OnCustomEditorEvent),
NULL, propgrid );
return wxPGWindowList(wnd1, wnd2); return wxPGWindowList(wnd1, wnd2);
} }
@@ -334,13 +322,6 @@ wxPGWindowList wxPGDatePickerCtrlEditor::CreateControls( wxPropertyGrid* propgri
useSz, useSz,
prop->GetDatePickerStyle() | wxNO_BORDER); prop->GetDatePickerStyle() | wxNO_BORDER);
// Connect all required events to grid's OnCustomEditorEvent
// (all relevenat wxTextCtrl, wxComboBox and wxButton events are
// already connected)
ctrl->Connect( wxPG_SUBID1, wxEVT_DATE_CHANGED,
wxEventHandler(wxPropertyGrid::OnCustomEditorEvent),
NULL, propgrid );
#ifdef __WXMSW__ #ifdef __WXMSW__
ctrl->Show(); ctrl->Show();
#endif #endif
@@ -1026,7 +1007,7 @@ bool wxSystemColourProperty::QueryColourFromUser( wxVariant& variant ) const
wxASSERT( propgrid ); wxASSERT( propgrid );
// Must only occur when user triggers event // Must only occur when user triggers event
if ( !(propgrid->GetInternalFlags() & wxPG_FL_IN_ONCUSTOMEDITOREVENT) ) if ( !(propgrid->GetInternalFlags() & wxPG_FL_IN_HANDLECUSTOMEDITOREVENT) )
return res; return res;
wxColourPropertyValue val = GetVal(); wxColourPropertyValue val = GetVal();

View File

@@ -877,15 +877,6 @@ wxWindow* wxPGChoiceEditor::CreateControlsBase( wxPropertyGrid* propGrid,
else else
cb->SetSelection( -1 ); cb->SetSelection( -1 );
// Connect event handling
wxWindowID id = cb->GetId();
propGrid->Connect(id, wxEVT_COMMAND_COMBOBOX_SELECTED,
wxEventHandler(wxPropertyGrid::OnCustomEditorEvent));
propGrid->Connect(id, wxEVT_COMMAND_TEXT_UPDATED,
wxEventHandler(wxPropertyGrid::OnCustomEditorEvent));
propGrid->Connect(id, wxEVT_COMMAND_TEXT_ENTER,
wxEventHandler(wxPropertyGrid::OnCustomEditorEvent));
#ifdef __WXMSW__ #ifdef __WXMSW__
cb->Show(); cb->Show();
#endif #endif
@@ -1298,7 +1289,7 @@ void wxSimpleCheckBox::SetValue( int value )
wxPropertyGrid* propGrid = (wxPropertyGrid*) GetParent()->GetParent(); wxPropertyGrid* propGrid = (wxPropertyGrid*) GetParent()->GetParent();
wxASSERT( propGrid->IsKindOf(CLASSINFO(wxPropertyGrid)) ); wxASSERT( propGrid->IsKindOf(CLASSINFO(wxPropertyGrid)) );
propGrid->OnCustomEditorEvent(evt); propGrid->HandleCustomEditorEvent(evt);
} }
@@ -1401,14 +1392,6 @@ wxPGWindowList wxPGCheckBoxEditor::CreateControls( wxPropertyGrid* propGrid,
cb->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); cb->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
cb->Connect( wxPG_SUBID1, wxEVT_LEFT_DOWN,
(wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction)
&wxPropertyGrid::OnCustomEditorEvent, NULL, propGrid );
cb->Connect( wxPG_SUBID1, wxEVT_LEFT_DCLICK,
(wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction)
&wxPropertyGrid::OnCustomEditorEvent, NULL, propGrid );
if ( property->GetChoiceSelection() > 0 && if ( property->GetChoiceSelection() > 0 &&
!property->IsValueUnspecified() ) !property->IsValueUnspecified() )
cb->m_state = 1; cb->m_state = 1;
@@ -1711,13 +1694,6 @@ wxWindow* wxPropertyGrid::GenerateEditorTextCtrl( const wxPoint& pos,
if ( maxLen > 0 ) if ( maxLen > 0 )
tc->SetMaxLength( maxLen ); tc->SetMaxLength( maxLen );
// Connect event handling
id = ed->GetId();
this->Connect(id, wxEVT_COMMAND_TEXT_UPDATED,
wxEventHandler(wxPropertyGrid::OnCustomEditorEvent));
this->Connect(id, wxEVT_COMMAND_TEXT_ENTER,
wxEventHandler(wxPropertyGrid::OnCustomEditorEvent));
return (wxWindow*) ed; return (wxWindow*) ed;
} }
@@ -1779,11 +1755,6 @@ wxWindow* wxPropertyGrid::GenerateEditorButton( const wxPoint& pos, const wxSize
if ( selected->HasFlag(wxPG_PROP_READONLY) ) if ( selected->HasFlag(wxPG_PROP_READONLY) )
but->Disable(); but->Disable();
// Connect event handling
id = but->GetId();
this->Connect(id, wxEVT_COMMAND_BUTTON_CLICKED,
wxEventHandler(wxPropertyGrid::OnCustomEditorEvent));
return but; return but;
} }
@@ -1881,17 +1852,10 @@ wxPGMultiButton::wxPGMultiButton( wxPropertyGrid* pg, const wxSize& sz )
SetBackgroundColour(pg->GetCellBackgroundColour()); SetBackgroundColour(pg->GetCellBackgroundColour());
} }
void wxPGMultiButton::Finalize( wxPropertyGrid* propGrid, const wxPoint& pos ) void wxPGMultiButton::Finalize( wxPropertyGrid* WXUNUSED(propGrid),
const wxPoint& pos )
{ {
Move( pos.x + m_fullEditorSize.x - m_buttonsWidth, pos.y ); Move( pos.x + m_fullEditorSize.x - m_buttonsWidth, pos.y );
// Connect event handling
for ( unsigned int i=0; i<GetCount(); i++ )
{
wxWindowID id = GetButtonId(i);
propGrid->Connect(id, wxEVT_COMMAND_BUTTON_CLICKED,
wxEventHandler(wxPropertyGrid::OnCustomEditorEvent));
}
} }
int wxPGMultiButton::GenId( int id ) const int wxPGMultiButton::GenId( int id ) const

View File

@@ -2388,7 +2388,7 @@ bool wxPropertyGrid::CommitChangesFromEditor( wxUint32 flags )
// Don't do this if already processing editor event. It might // Don't do this if already processing editor event. It might
// induce recursive dialogs and crap like that. // induce recursive dialogs and crap like that.
if ( m_iFlags & wxPG_FL_IN_ONCUSTOMEDITOREVENT ) if ( m_iFlags & wxPG_FL_IN_HANDLECUSTOMEDITOREVENT )
{ {
if ( m_inDoPropertyChanged ) if ( m_inDoPropertyChanged )
return true; return true;
@@ -2879,27 +2879,7 @@ bool wxPropertyGrid::DoEditorValidate()
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
bool wxPropertyGrid::ProcessEvent(wxEvent& event) void wxPropertyGrid::HandleCustomEditorEvent( wxEvent &event )
{
wxWindow* wnd = (wxWindow*) event.GetEventObject();
if ( wnd && wnd->IsKindOf(CLASSINFO(wxWindow)) )
{
wxWindow* parent = wnd->GetParent();
if ( parent &&
(parent == m_canvas ||
parent->GetParent() == m_canvas) )
{
OnCustomEditorEvent(event);
return true;
}
}
return wxPanel::ProcessEvent(event);
}
// -----------------------------------------------------------------------
void wxPropertyGrid::OnCustomEditorEvent( wxEvent &event )
{ {
wxPGProperty* selected = m_selected; wxPGProperty* selected = m_selected;
@@ -2908,7 +2888,7 @@ void wxPropertyGrid::OnCustomEditorEvent( wxEvent &event )
if ( !selected ) if ( !selected )
return; return;
if ( m_iFlags & wxPG_FL_IN_ONCUSTOMEDITOREVENT ) if ( m_iFlags & wxPG_FL_IN_HANDLECUSTOMEDITOREVENT )
return; return;
wxVariant pendingValue(selected->GetValueRef()); wxVariant pendingValue(selected->GetValueRef());
@@ -2938,7 +2918,7 @@ void wxPropertyGrid::OnCustomEditorEvent( wxEvent &event )
m_prevTcValue = newTcValue; m_prevTcValue = newTcValue;
} }
SetInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT); SetInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT);
bool validationFailure = false; bool validationFailure = false;
bool buttonWasHandled = false; bool buttonWasHandled = false;
@@ -3038,7 +3018,7 @@ void wxPropertyGrid::OnCustomEditorEvent( wxEvent &event )
} }
} }
ClearInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT); ClearInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT);
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
@@ -3163,9 +3143,37 @@ void wxPropertyGrid::CustomSetCursor( int type, bool override )
} }
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
// wxPropertyGrid property selection // wxPropertyGrid property selection, editor creation
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
//
// This class forwards events from property editor controls to wxPropertyGrid.
class wxPropertyGridEditorEventForwarder : public wxEvtHandler
{
public:
wxPropertyGridEditorEventForwarder( wxPropertyGrid* propGrid )
: wxEvtHandler(), m_propGrid(propGrid)
{
}
virtual ~wxPropertyGridEditorEventForwarder()
{
}
private:
bool ProcessEvent( wxEvent& event )
{
// Always skip
event.Skip();
m_propGrid->HandleCustomEditorEvent(event);
return wxEvtHandler::ProcessEvent(event);
}
wxPropertyGrid* m_propGrid;
};
// Setups event handling for child control // Setups event handling for child control
void wxPropertyGrid::SetupChildEventHandling( wxWindow* argWnd ) void wxPropertyGrid::SetupChildEventHandling( wxWindow* argWnd )
{ {
@@ -3193,6 +3201,10 @@ void wxPropertyGrid::SetupChildEventHandling( wxWindow* argWnd )
NULL, this); NULL, this);
} }
wxPropertyGridEditorEventForwarder* forwarder;
forwarder = new wxPropertyGridEditorEventForwarder(this);
argWnd->PushEventHandler(forwarder);
argWnd->Connect(id, wxEVT_KEY_DOWN, argWnd->Connect(id, wxEVT_KEY_DOWN,
wxCharEventHandler(wxPropertyGrid::OnChildKeyDown), wxCharEventHandler(wxPropertyGrid::OnChildKeyDown),
NULL, this); NULL, this);
@@ -3222,6 +3234,7 @@ void wxPropertyGrid::FreeEditors()
// Do not free editors immediately if processing events // Do not free editors immediately if processing events
if ( m_wndEditor2 ) if ( m_wndEditor2 )
{ {
m_wndEditor2->PopEventHandler(true);
m_wndEditor2->Hide(); m_wndEditor2->Hide();
wxPendingDelete.Append( m_wndEditor2 ); wxPendingDelete.Append( m_wndEditor2 );
m_wndEditor2 = (wxWindow*) NULL; m_wndEditor2 = (wxWindow*) NULL;
@@ -3229,6 +3242,7 @@ void wxPropertyGrid::FreeEditors()
if ( m_wndEditor ) if ( m_wndEditor )
{ {
m_wndEditor->PopEventHandler(true);
m_wndEditor->Hide(); m_wndEditor->Hide();
wxPendingDelete.Append( m_wndEditor ); wxPendingDelete.Append( m_wndEditor );
m_wndEditor = (wxWindow*) NULL; m_wndEditor = (wxWindow*) NULL;