Fixed and clarified editor control event handling

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55903 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Jaakko Salli 2008-09-26 18:20:17 +00:00
parent f9ec0ea7c5
commit d9fb481c56
5 changed files with 63 additions and 42 deletions

View File

@ -113,20 +113,16 @@ public:
@remarks
- Primary control shall use id wxPG_SUBID1, and secondary (button)
control shall use wxPG_SUBID2.
- Implementation shoud use connect all necessary events to the
- 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.
// NOTE: This event in particular is actually automatically
// conveyed, but it is just used as an example.
propgrid->Connect(wxPG_SUBID1, wxEVT_COMMAND_TEXT_UPDATED,
wxCommandEventHandler(
wxPropertyGrid::OnCustomEditorEvent));
propgrid->Connect(control->GetId(), wxEVT_COMMAND_TEXT_UPDATED,
wxCommandEventHandler(wxPropertyGrid::OnCustomEditorEvent));
@endcode
OnCustomEditorEvent will then forward events, first to
wxPGEditor::OnEvent and then to wxPGProperty::OnEvent.
OnCustomEditorEvent will then forward events, first to
wxPGEditor::OnEvent() and then to wxPGProperty::OnEvent().
*/
virtual wxPGWindowList CreateControls(wxPropertyGrid* propgrid,
wxPGProperty* property,

View File

@ -1792,8 +1792,8 @@ protected:
void DoSetPropertyName( wxPGProperty* p, const wxString& newname );
// Setups event handling for child control
void SetupEventHandling( wxWindow* wnd, int id );
// Sets up basic event handling for child control
void SetupChildEventHandling( wxWindow* wnd, int id );
void CustomSetCursor( int type, bool override = false );

View File

@ -65,18 +65,16 @@ public:
@remarks
- Primary control shall use id wxPG_SUBID1, and secondary (button) control
shall use wxPG_SUBID2.
- Implementation shoud use connect all necessary events to the
- 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.
// NOTE: This event in particular is actually automatically conveyed, but
// it is just used as an example.
propgrid->Connect( wxPG_SUBID1, wxEVT_COMMAND_TEXT_UPDATED,
wxCommandEventHandler(wxPropertyGrid::OnCustomEditorEvent) );
propgrid->Connect(control->GetId(), wxEVT_COMMAND_TEXT_UPDATED,
wxCommandEventHandler(wxPropertyGrid::OnCustomEditorEvent));
@endcode
OnCustomEditorEvent will then forward events, first to wxPGEditor::OnEvent and then to wxPGProperty::OnEvent.
OnCustomEditorEvent will then forward events, first to
wxPGEditor::OnEvent() and then to wxPGProperty::OnEvent().
*/
virtual wxPGWindowList CreateControls( wxPropertyGrid* propgrid, wxPGProperty* property,
const wxPoint& pos, const wxSize& size ) const = 0;

View File

@ -1066,6 +1066,15 @@ wxWindow* wxPGChoiceEditor::CreateControlsBase( wxPropertyGrid* propGrid,
else
cb->SetSelection( -1 );
// Connect event handling
wxWindowID id = cb->GetId();
propGrid->Connect(id, wxEVT_COMMAND_COMBOBOX_SELECTED,
wxCommandEventHandler(wxPropertyGrid::OnCustomEditorEvent));
propGrid->Connect(id, wxEVT_COMMAND_TEXT_UPDATED,
wxCommandEventHandler(wxPropertyGrid::OnCustomEditorEvent));
propGrid->Connect(id, wxEVT_COMMAND_TEXT_ENTER,
wxCommandEventHandler(wxPropertyGrid::OnCustomEditorEvent));
#ifdef __WXMSW__
cb->Show();
#endif
@ -1872,6 +1881,7 @@ wxWindow* wxPropertyGrid::GenerateEditorTextCtrl( const wxPoint& pos,
int extraStyle,
int maxLen )
{
wxWindowID id = wxPG_SUBID1;
wxPGProperty* selected = m_selected;
wxASSERT(selected);
@ -1908,7 +1918,7 @@ wxWindow* wxPropertyGrid::GenerateEditorTextCtrl( const wxPoint& pos,
#if defined(__WXMSW__)
wnd->Hide();
#endif
wnd->Create(GetPanel(),wxPG_SUBID1,p,s);
wnd->Create(GetPanel(),id,p,s);
// This generates rect of the control inside the clipper window
if ( !hasSpecialSize )
@ -1933,7 +1943,7 @@ wxWindow* wxPropertyGrid::GenerateEditorTextCtrl( const wxPoint& pos,
tc->Hide();
#endif
SetupTextCtrlValue(value);
tc->Create(ctrlParent,wxPG_SUBID1,value, p, s,tcFlags);
tc->Create(ctrlParent,id,value, p, s,tcFlags);
#if wxPG_NAT_TEXTCTRL_BORDER_ANY
wxWindow* ed = wnd;
@ -1956,6 +1966,13 @@ wxWindow* wxPropertyGrid::GenerateEditorTextCtrl( const wxPoint& pos,
if ( maxLen > 0 )
tc->SetMaxLength( maxLen );
// Connect event handling
id = ed->GetId();
this->Connect(id, wxEVT_COMMAND_TEXT_UPDATED,
wxCommandEventHandler(wxPropertyGrid::OnCustomEditorEvent));
this->Connect(id, wxEVT_COMMAND_TEXT_ENTER,
wxCommandEventHandler(wxPropertyGrid::OnCustomEditorEvent));
return (wxWindow*) ed;
}
@ -1963,6 +1980,7 @@ wxWindow* wxPropertyGrid::GenerateEditorTextCtrl( const wxPoint& pos,
wxWindow* wxPropertyGrid::GenerateEditorButton( const wxPoint& pos, const wxSize& sz )
{
wxWindowID id = wxPG_SUBID2;
wxPGProperty* selected = m_selected;
wxASSERT(selected);
@ -1975,7 +1993,7 @@ wxWindow* wxPropertyGrid::GenerateEditorButton( const wxPoint& pos, const wxSize
wxSize s(25, -1);
wxButton* but = new wxButton();
but->Create(GetPanel(),wxPG_SUBID2,wxS("..."),p,s,wxWANTS_CHARS);
but->Create(GetPanel(),id,wxS("..."),p,s,wxWANTS_CHARS);
// Now that we know the size, move to the correct position
p.x = pos.x + sz.x - but->GetSize().x - 2;
@ -2002,7 +2020,7 @@ wxWindow* wxPropertyGrid::GenerateEditorButton( const wxPoint& pos, const wxSize
#ifdef __WXMSW__
but->Hide();
#endif
but->Create(GetPanel(),wxPG_SUBID2,wxS("..."),p,s,wxWANTS_CHARS);
but->Create(GetPanel(),id,wxS("..."),p,s,wxWANTS_CHARS);
#ifdef __WXGTK__
wxFont font = GetFont();
@ -2016,6 +2034,11 @@ wxWindow* wxPropertyGrid::GenerateEditorButton( const wxPoint& pos, const wxSize
if ( selected->HasFlag(wxPG_PROP_READONLY) )
but->Disable();
// Connect event handling
id = but->GetId();
this->Connect(id, wxEVT_COMMAND_BUTTON_CLICKED,
wxCommandEventHandler(wxPropertyGrid::OnCustomEditorEvent));
return but;
}

View File

@ -499,7 +499,6 @@ BEGIN_EVENT_TABLE(wxPropertyGrid, wxScrolledWindow)
EVT_CHILD_FOCUS(wxPropertyGrid::OnChildFocusEvent)
EVT_SET_FOCUS(wxPropertyGrid::OnFocusEvent)
EVT_KILL_FOCUS(wxPropertyGrid::OnFocusEvent)
EVT_TEXT_ENTER(wxPG_SUBID1,wxPropertyGrid::OnCustomEditorEvent)
EVT_SYS_COLOUR_CHANGED(wxPropertyGrid::OnSysColourChanged)
END_EVENT_TABLE()
@ -3471,33 +3470,38 @@ void wxPropertyGrid::CustomSetCursor( int type, bool override )
// wxPropertyGrid property selection
// -----------------------------------------------------------------------
#define CONNECT_CHILD(EVT,FUNCTYPE,FUNC) \
wnd->Connect(id, EVT, \
(wxObjectEventFunction) (wxEventFunction) \
FUNCTYPE (&wxPropertyGrid::FUNC), \
NULL, this );
// Setups event handling for child control
void wxPropertyGrid::SetupEventHandling( wxWindow* argWnd, int id )
void wxPropertyGrid::SetupChildEventHandling( wxWindow* argWnd, int id )
{
wxWindow* wnd = argWnd;
if ( argWnd == m_wndEditor )
{
CONNECT_CHILD(wxEVT_MOTION,(wxMouseEventFunction),OnMouseMoveChild)
CONNECT_CHILD(wxEVT_LEFT_UP,(wxMouseEventFunction),OnMouseUpChild)
CONNECT_CHILD(wxEVT_LEFT_DOWN,(wxMouseEventFunction),OnMouseClickChild)
CONNECT_CHILD(wxEVT_RIGHT_UP,(wxMouseEventFunction),OnMouseRightClickChild)
CONNECT_CHILD(wxEVT_ENTER_WINDOW,(wxMouseEventFunction),OnMouseEntry)
CONNECT_CHILD(wxEVT_LEAVE_WINDOW,(wxMouseEventFunction),OnMouseEntry)
this->Connect(id, wxEVT_MOTION,
wxMouseEventHandler(wxPropertyGrid::OnMouseMoveChild));
this->Connect(id, wxEVT_LEFT_UP,
wxMouseEventHandler(wxPropertyGrid::OnMouseUpChild));
this->Connect(id, wxEVT_LEFT_DOWN,
wxMouseEventHandler(wxPropertyGrid::OnMouseClickChild));
this->Connect(id, wxEVT_RIGHT_UP,
wxMouseEventHandler(wxPropertyGrid::OnMouseRightClickChild));
this->Connect(id, wxEVT_ENTER_WINDOW,
wxMouseEventHandler(wxPropertyGrid::OnMouseEntry));
this->Connect(id, wxEVT_LEAVE_WINDOW,
wxMouseEventHandler(wxPropertyGrid::OnMouseEntry));
}
else
{
CONNECT_CHILD(wxEVT_NAVIGATION_KEY,(wxNavigationKeyEventFunction),OnNavigationKey)
this->Connect(id, wxEVT_NAVIGATION_KEY,
wxNavigationKeyEventHandler(wxPropertyGrid::OnNavigationKey));
}
CONNECT_CHILD(wxEVT_KEY_DOWN,(wxCharEventFunction),OnChildKeyDown)
CONNECT_CHILD(wxEVT_KEY_UP,(wxCharEventFunction),OnChildKeyUp)
CONNECT_CHILD(wxEVT_KILL_FOCUS,(wxFocusEventFunction),OnFocusEvent)
this->Connect(id, wxEVT_KEY_DOWN,
wxKeyEventHandler(wxPropertyGrid::OnChildKeyDown));
this->Connect(id, wxEVT_KEY_UP,
wxKeyEventHandler(wxPropertyGrid::OnChildKeyUp));
this->Connect(id, wxEVT_KILL_FOCUS,
wxFocusEventHandler(wxPropertyGrid::OnFocusEvent));
}
void wxPropertyGrid::FreeEditors()
@ -3754,7 +3758,7 @@ bool wxPropertyGrid::DoSelectProperty( wxPGProperty* p, unsigned int flags )
#endif
wxWindow* primaryCtrl = GetEditorControl();
SetupEventHandling(primaryCtrl, wxPG_SUBID1);
SetupChildEventHandling(primaryCtrl, wxPG_SUBID1);
// Focus and select all (wxTextCtrl, wxComboBox etc)
if ( flags & wxPG_SEL_FOCUS )
@ -3794,7 +3798,7 @@ bool wxPropertyGrid::DoSelectProperty( wxPGProperty* p, unsigned int flags )
#endif
m_wndEditor2->Show();
SetupEventHandling(m_wndEditor2,wxPG_SUBID2);
SetupChildEventHandling(m_wndEditor2,wxPG_SUBID2);
// If no primary editor, focus to button to allow
// it to interprete ENTER etc.