@remarks
- Primary control shall use id wxPG_SUBID1, and secondary (button)
control shall use wxPG_SUBID2.
- - Implementation shoud connect all necessary events to the
- wxPropertyGrid::OnCustomEditorEvent. For Example:
- @code
- // Relays wxEVT_COMMAND_TEXT_UPDATED events of primary editor
- // 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().
+ - 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().
*/
virtual wxPGWindowList CreateControls(wxPropertyGrid* propgrid,
wxPGProperty* property,
#define wxPG_MAN_FL_PAGE_INSERTED 0x02000000
// Active editor control is abnormally large
#define wxPG_FL_ABNORMAL_EDITOR 0x04000000
-// Recursion guard for OnCustomEditorEvent
-#define wxPG_FL_IN_ONCUSTOMEDITOREVENT 0x08000000
+// Recursion guard for HandleCustomEditorEvent
+#define wxPG_FL_IN_HANDLECUSTOMEDITOREVENT 0x08000000
#define wxPG_FL_VALUE_CHANGE_IN_EVENT 0x10000000
// Editor control width should not change on resize
#define wxPG_FL_FIXED_WIDTH_EDITOR 0x20000000
return m_wndEditor2;
}
+ // Events from editor controls are forward to this function
+ void HandleCustomEditorEvent( wxEvent &event );
+
#ifndef SWIG
/**
// Mostly useful for page switching.
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; }
bool HasInternalFlag( long flag ) const
{ return (m_iFlags & flag) ? true : false; }
*/
bool UnfocusEditor();
- virtual bool ProcessEvent(wxEvent& event);
virtual void SetWindowStyleFlag( long style );
protected:
@remarks
- Primary control shall use id wxPG_SUBID1, and secondary (button) control
shall use wxPG_SUBID2.
- - Implementation shoud connect all necessary events to the
- wxPropertyGrid::OnCustomEditorEvent(). For example:
- @code
- control->Connect(control->GetId(), wxEVT_COMMAND_TEXT_UPDATED,
- 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()
+ - 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().
*/
virtual wxPGWindowList CreateControls( wxPropertyGrid* propgrid,
wxPGProperty* property,
*/
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.
*/
wnd2->SetRange( INT_MIN, INT_MAX );
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
wxTextValidator validator(wxFILTER_NUMERIC, &m_tempString);
wxTextCtrl* wnd1 = (wxTextCtrl*) wxPGTextCtrlEditor::CreateControls( propgrid, property, pos, tcSz ).m_primary;
wnd1->SetValidator(validator);
- wnd1->Connect( wnd1->GetId(), wxEVT_KEY_DOWN,
- wxEventHandler(wxPropertyGrid::OnCustomEditorEvent),
- NULL, propgrid );
-
return wxPGWindowList(wnd1, wnd2);
}
useSz,
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__
ctrl->Show();
#endif
wxASSERT( propgrid );
// Must only occur when user triggers event
- if ( !(propgrid->GetInternalFlags() & wxPG_FL_IN_ONCUSTOMEDITOREVENT) )
+ if ( !(propgrid->GetInternalFlags() & wxPG_FL_IN_HANDLECUSTOMEDITOREVENT) )
return res;
wxColourPropertyValue val = GetVal();
else
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__
cb->Show();
#endif
wxPropertyGrid* propGrid = (wxPropertyGrid*) GetParent()->GetParent();
wxASSERT( propGrid->IsKindOf(CLASSINFO(wxPropertyGrid)) );
- propGrid->OnCustomEditorEvent(evt);
+ propGrid->HandleCustomEditorEvent(evt);
}
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 &&
!property->IsValueUnspecified() )
cb->m_state = 1;
if ( maxLen > 0 )
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;
}
if ( selected->HasFlag(wxPG_PROP_READONLY) )
but->Disable();
- // Connect event handling
- id = but->GetId();
- this->Connect(id, wxEVT_COMMAND_BUTTON_CLICKED,
- wxEventHandler(wxPropertyGrid::OnCustomEditorEvent));
-
return but;
}
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 );
-
- // 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
// Don't do this if already processing editor event. It might
// induce recursive dialogs and crap like that.
- if ( m_iFlags & wxPG_FL_IN_ONCUSTOMEDITOREVENT )
+ if ( m_iFlags & wxPG_FL_IN_HANDLECUSTOMEDITOREVENT )
{
if ( m_inDoPropertyChanged )
return true;
// -----------------------------------------------------------------------
-bool wxPropertyGrid::ProcessEvent(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 )
+void wxPropertyGrid::HandleCustomEditorEvent( wxEvent &event )
{
wxPGProperty* selected = m_selected;
if ( !selected )
return;
- if ( m_iFlags & wxPG_FL_IN_ONCUSTOMEDITOREVENT )
+ if ( m_iFlags & wxPG_FL_IN_HANDLECUSTOMEDITOREVENT )
return;
wxVariant pendingValue(selected->GetValueRef());
m_prevTcValue = newTcValue;
}
- SetInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT);
+ SetInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT);
bool validationFailure = false;
bool buttonWasHandled = false;
}
}
- ClearInternalFlag(wxPG_FL_IN_ONCUSTOMEDITOREVENT);
+ ClearInternalFlag(wxPG_FL_IN_HANDLECUSTOMEDITOREVENT);
}
// -----------------------------------------------------------------------
}
// -----------------------------------------------------------------------
-// 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
void wxPropertyGrid::SetupChildEventHandling( wxWindow* argWnd )
{
NULL, this);
}
+ wxPropertyGridEditorEventForwarder* forwarder;
+ forwarder = new wxPropertyGridEditorEventForwarder(this);
+ argWnd->PushEventHandler(forwarder);
+
argWnd->Connect(id, wxEVT_KEY_DOWN,
wxCharEventHandler(wxPropertyGrid::OnChildKeyDown),
NULL, this);
// Do not free editors immediately if processing events
if ( m_wndEditor2 )
{
+ m_wndEditor2->PopEventHandler(true);
m_wndEditor2->Hide();
wxPendingDelete.Append( m_wndEditor2 );
m_wndEditor2 = (wxWindow*) NULL;
if ( m_wndEditor )
{
+ m_wndEditor->PopEventHandler(true);
m_wndEditor->Hide();
wxPendingDelete.Append( m_wndEditor );
m_wndEditor = (wxWindow*) NULL;