Simplistic tab support is now default (tab focuses editor if unfocused, otherwise goes out of grid), no longer recognizes wxTAB_TRAVERSAL, unified key handling code
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56422 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -1642,7 +1642,6 @@ protected:
|
|||||||
void OnMouseDoubleClick( wxMouseEvent &event );
|
void OnMouseDoubleClick( wxMouseEvent &event );
|
||||||
void OnMouseUp( wxMouseEvent &event );
|
void OnMouseUp( wxMouseEvent &event );
|
||||||
void OnKey( wxKeyEvent &event );
|
void OnKey( wxKeyEvent &event );
|
||||||
void OnKeyUp( wxKeyEvent &event );
|
|
||||||
void OnResize( wxSizeEvent &event );
|
void OnResize( wxSizeEvent &event );
|
||||||
|
|
||||||
// event handlers
|
// event handlers
|
||||||
@@ -1651,9 +1650,7 @@ protected:
|
|||||||
bool HandleMouseRightClick( int x, unsigned int y, wxMouseEvent &event );
|
bool HandleMouseRightClick( int x, unsigned int y, wxMouseEvent &event );
|
||||||
bool HandleMouseDoubleClick( int x, unsigned int y, wxMouseEvent &event );
|
bool HandleMouseDoubleClick( int x, unsigned int y, wxMouseEvent &event );
|
||||||
bool HandleMouseUp( int x, unsigned int y, wxMouseEvent &event );
|
bool HandleMouseUp( int x, unsigned int y, wxMouseEvent &event );
|
||||||
void HandleKeyEvent( wxKeyEvent &event );
|
void HandleKeyEvent( wxKeyEvent &event, bool fromChild );
|
||||||
// Handle TAB and ESCAPE in control
|
|
||||||
bool HandleChildKey( wxKeyEvent& event );
|
|
||||||
|
|
||||||
void OnMouseEntry( wxMouseEvent &event );
|
void OnMouseEntry( wxMouseEvent &event );
|
||||||
|
|
||||||
@@ -1670,7 +1667,6 @@ protected:
|
|||||||
void OnMouseMoveChild( wxMouseEvent &event );
|
void OnMouseMoveChild( wxMouseEvent &event );
|
||||||
void OnMouseUpChild( wxMouseEvent &event );
|
void OnMouseUpChild( wxMouseEvent &event );
|
||||||
void OnChildKeyDown( wxKeyEvent &event );
|
void OnChildKeyDown( wxKeyEvent &event );
|
||||||
void OnChildKeyUp( wxKeyEvent &event );
|
|
||||||
|
|
||||||
void OnCaptureChange( wxMouseCaptureChangedEvent &event );
|
void OnCaptureChange( wxMouseCaptureChangedEvent &event );
|
||||||
|
|
||||||
@@ -1750,6 +1746,9 @@ protected:
|
|||||||
|
|
||||||
void ImprovedClientToScreen( int* px, int* py );
|
void ImprovedClientToScreen( int* px, int* py );
|
||||||
|
|
||||||
|
// Returns True if editor control has focus
|
||||||
|
bool IsEditorFocused() const;
|
||||||
|
|
||||||
// Called by focus event handlers. newFocused is the window that becomes
|
// Called by focus event handlers. newFocused is the window that becomes
|
||||||
// focused.
|
// focused.
|
||||||
void HandleFocusChange( wxWindow* newFocused );
|
void HandleFocusChange( wxWindow* newFocused );
|
||||||
|
@@ -1929,7 +1929,9 @@ void FormMain::InitPanel()
|
|||||||
if ( m_panel )
|
if ( m_panel )
|
||||||
m_panel->Destroy();
|
m_panel->Destroy();
|
||||||
|
|
||||||
wxWindow* panel = new wxPanel(this,-1,wxPoint(0,0),wxSize(400,400));
|
wxWindow* panel = new wxPanel(this, wxID_ANY,
|
||||||
|
wxPoint(0, 0), wxSize(400, 400),
|
||||||
|
wxTAB_TRAVERSAL);
|
||||||
m_panel = panel;
|
m_panel = panel;
|
||||||
|
|
||||||
// Column
|
// Column
|
||||||
@@ -1940,11 +1942,17 @@ void FormMain::InitPanel()
|
|||||||
|
|
||||||
void FormMain::FinalizePanel( bool wasCreated )
|
void FormMain::FinalizePanel( bool wasCreated )
|
||||||
{
|
{
|
||||||
|
// Button for tab traversal testing
|
||||||
|
m_topSizer->Add( new wxButton(m_panel, wxID_ANY,
|
||||||
|
wxS("Should be able to move here with Tab")),
|
||||||
|
0, wxEXPAND );
|
||||||
|
|
||||||
m_panel->SetSizer( m_topSizer );
|
m_panel->SetSizer( m_topSizer );
|
||||||
m_topSizer->SetSizeHints( m_panel );
|
m_topSizer->SetSizeHints( m_panel );
|
||||||
|
|
||||||
wxBoxSizer* panelSizer = new wxBoxSizer( wxHORIZONTAL );
|
wxBoxSizer* panelSizer = new wxBoxSizer( wxHORIZONTAL );
|
||||||
panelSizer->Add( m_panel, 1, wxEXPAND|wxFIXED_MINSIZE );
|
panelSizer->Add( m_panel, 1, wxEXPAND|wxFIXED_MINSIZE );
|
||||||
|
|
||||||
SetSizer( panelSizer );
|
SetSizer( panelSizer );
|
||||||
panelSizer->SetSizeHints( this );
|
panelSizer->SetSizeHints( this );
|
||||||
|
|
||||||
@@ -1988,7 +1996,6 @@ void FormMain::CreateGrid( int style, int extraStyle )
|
|||||||
//wxPG_TOOLTIPS |
|
//wxPG_TOOLTIPS |
|
||||||
//wxPG_HIDE_CATEGORIES |
|
//wxPG_HIDE_CATEGORIES |
|
||||||
//wxPG_LIMITED_EDITING |
|
//wxPG_LIMITED_EDITING |
|
||||||
wxTAB_TRAVERSAL |
|
|
||||||
wxPG_TOOLBAR |
|
wxPG_TOOLBAR |
|
||||||
wxPG_DESCRIPTION;
|
wxPG_DESCRIPTION;
|
||||||
|
|
||||||
@@ -2084,7 +2091,6 @@ FormMain::FormMain(const wxString& title, const wxPoint& pos, const wxSize& size
|
|||||||
//wxPG_TOOLTIPS |
|
//wxPG_TOOLTIPS |
|
||||||
//wxPG_HIDE_CATEGORIES |
|
//wxPG_HIDE_CATEGORIES |
|
||||||
//wxPG_LIMITED_EDITING |
|
//wxPG_LIMITED_EDITING |
|
||||||
wxTAB_TRAVERSAL |
|
|
||||||
wxPG_TOOLBAR |
|
wxPG_TOOLBAR |
|
||||||
wxPG_DESCRIPTION,
|
wxPG_DESCRIPTION,
|
||||||
// extra style
|
// extra style
|
||||||
|
@@ -408,12 +408,6 @@ protected:
|
|||||||
pg->OnKey( event );
|
pg->OnKey( event );
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnKeyUp( wxKeyEvent& event )
|
|
||||||
{
|
|
||||||
wxPropertyGrid* pg = wxStaticCast(GetParent(), wxPropertyGrid);
|
|
||||||
pg->OnKeyUp( event );
|
|
||||||
}
|
|
||||||
|
|
||||||
void OnPaint( wxPaintEvent& event );
|
void OnPaint( wxPaintEvent& event );
|
||||||
|
|
||||||
// Always be focussable, even with child windows
|
// Always be focussable, even with child windows
|
||||||
@@ -437,8 +431,6 @@ BEGIN_EVENT_TABLE(wxPGCanvas, wxPanel)
|
|||||||
EVT_RIGHT_UP(wxPGCanvas::OnMouseRightClick)
|
EVT_RIGHT_UP(wxPGCanvas::OnMouseRightClick)
|
||||||
EVT_LEFT_DCLICK(wxPGCanvas::OnMouseDoubleClick)
|
EVT_LEFT_DCLICK(wxPGCanvas::OnMouseDoubleClick)
|
||||||
EVT_KEY_DOWN(wxPGCanvas::OnKey)
|
EVT_KEY_DOWN(wxPGCanvas::OnKey)
|
||||||
EVT_KEY_UP(wxPGCanvas::OnKeyUp)
|
|
||||||
EVT_CHAR(wxPGCanvas::OnKey)
|
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
|
|
||||||
@@ -523,18 +515,9 @@ bool wxPropertyGrid::Create( wxWindow *parent,
|
|||||||
|
|
||||||
style |= wxVSCROLL;
|
style |= wxVSCROLL;
|
||||||
|
|
||||||
#ifdef __WXMSW__
|
// Filter out wxTAB_TRAVERSAL - we will handle TABs manually
|
||||||
// This prevents crash under Win2K, but still
|
|
||||||
// enables keyboard navigation
|
|
||||||
if ( style & wxTAB_TRAVERSAL )
|
|
||||||
{
|
|
||||||
style &= ~(wxTAB_TRAVERSAL);
|
style &= ~(wxTAB_TRAVERSAL);
|
||||||
style |= wxWANTS_CHARS;
|
style |= wxWANTS_CHARS;
|
||||||
}
|
|
||||||
#else
|
|
||||||
if ( style & wxTAB_TRAVERSAL )
|
|
||||||
style |= wxWANTS_CHARS;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
wxScrolledWindow::Create(parent,id,pos,size,style,name);
|
wxScrolledWindow::Create(parent,id,pos,size,style,name);
|
||||||
|
|
||||||
@@ -702,7 +685,7 @@ void wxPropertyGrid::Init2()
|
|||||||
|
|
||||||
m_canvas = new wxPGCanvas();
|
m_canvas = new wxPGCanvas();
|
||||||
m_canvas->Create(this, 1, wxPoint(0, 0), GetClientSize(),
|
m_canvas->Create(this, 1, wxPoint(0, 0), GetClientSize(),
|
||||||
(GetWindowStyle() & wxTAB_TRAVERSAL) | wxWANTS_CHARS | wxCLIP_CHILDREN);
|
wxWANTS_CHARS | wxCLIP_CHILDREN);
|
||||||
m_canvas->SetBackgroundStyle( wxBG_STYLE_CUSTOM );
|
m_canvas->SetBackgroundStyle( wxBG_STYLE_CUSTOM );
|
||||||
|
|
||||||
m_iFlags |= wxPG_FL_INITIALIZED;
|
m_iFlags |= wxPG_FL_INITIALIZED;
|
||||||
@@ -4965,7 +4948,7 @@ void wxPropertyGrid::ClearActionTriggers( int action )
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxPropertyGrid::HandleKeyEvent(wxKeyEvent &event)
|
void wxPropertyGrid::HandleKeyEvent( wxKeyEvent &event, bool fromChild )
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
// Handles key event when editor control is not focused.
|
// Handles key event when editor control is not focused.
|
||||||
@@ -4977,11 +4960,25 @@ void wxPropertyGrid::HandleKeyEvent(wxKeyEvent &event)
|
|||||||
|
|
||||||
// Travelsal between items, collapsing/expanding, etc.
|
// Travelsal between items, collapsing/expanding, etc.
|
||||||
int keycode = event.GetKeyCode();
|
int keycode = event.GetKeyCode();
|
||||||
|
bool editorFocused = IsEditorFocused();
|
||||||
|
|
||||||
if ( keycode == WXK_TAB )
|
if ( keycode == WXK_TAB )
|
||||||
{
|
{
|
||||||
if (m_selected)
|
if ( !event.ShiftDown() )
|
||||||
|
{
|
||||||
|
if ( !editorFocused && m_wndEditor )
|
||||||
DoSelectProperty( m_selected, wxPG_SEL_FOCUS );
|
DoSelectProperty( m_selected, wxPG_SEL_FOCUS );
|
||||||
|
else
|
||||||
|
Navigate(wxNavigationKeyEvent::IsForward);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if ( editorFocused )
|
||||||
|
UnfocusEditor();
|
||||||
|
else
|
||||||
|
Navigate(wxNavigationKeyEvent::IsBackward);
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4996,9 +4993,32 @@ void wxPropertyGrid::HandleKeyEvent(wxKeyEvent &event)
|
|||||||
int secondAction;
|
int secondAction;
|
||||||
int action = KeyEventToActions(event, &secondAction);
|
int action = KeyEventToActions(event, &secondAction);
|
||||||
|
|
||||||
|
if ( editorFocused && action == wxPG_ACTION_CANCEL_EDIT )
|
||||||
|
{
|
||||||
|
//
|
||||||
|
// Esc cancels any changes
|
||||||
|
if ( IsEditorsValueModified() )
|
||||||
|
{
|
||||||
|
EditorsValueWasNotModified();
|
||||||
|
|
||||||
|
// Update the control as well
|
||||||
|
m_selected->GetEditorClass()->SetControlStringValue( m_selected,
|
||||||
|
GetEditorControl(),
|
||||||
|
m_selected->GetDisplayedString() );
|
||||||
|
}
|
||||||
|
|
||||||
|
OnValidationFailureReset(m_selected);
|
||||||
|
|
||||||
|
UnfocusEditor();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Except for TAB and ESC, handle child control events in child control
|
||||||
|
if ( fromChild )
|
||||||
|
return;
|
||||||
|
|
||||||
if ( m_selected )
|
if ( m_selected )
|
||||||
{
|
{
|
||||||
|
|
||||||
// Show dialog?
|
// Show dialog?
|
||||||
if ( ButtonTriggerKeyTest(action, event) )
|
if ( ButtonTriggerKeyTest(action, event) )
|
||||||
return;
|
return;
|
||||||
@@ -5034,11 +5054,6 @@ void wxPropertyGrid::HandleKeyEvent(wxKeyEvent &event)
|
|||||||
{
|
{
|
||||||
selectDir = 1;
|
selectDir = 1;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
event.Skip();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( selectDir >= -1 )
|
if ( selectDir >= -1 )
|
||||||
@@ -5062,58 +5077,9 @@ void wxPropertyGrid::HandleKeyEvent(wxKeyEvent &event)
|
|||||||
|
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
|
|
||||||
// Potentially handles a keyboard event for editor controls.
|
|
||||||
// Returns false if event should *not* be skipped (on true it can
|
|
||||||
// be optionally skipped).
|
|
||||||
// Basicly, false means that SelectProperty was called (or was about
|
|
||||||
// to be called, if canDestroy was false).
|
|
||||||
bool wxPropertyGrid::HandleChildKey( wxKeyEvent& event )
|
|
||||||
{
|
|
||||||
bool res = true;
|
|
||||||
|
|
||||||
if ( !m_selected || !m_wndEditor )
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
int action = KeyEventToAction(event);
|
|
||||||
|
|
||||||
// Unfocus?
|
|
||||||
if ( action == wxPG_ACTION_CANCEL_EDIT )
|
|
||||||
{
|
|
||||||
//
|
|
||||||
// Esc cancels any changes
|
|
||||||
if ( IsEditorsValueModified() )
|
|
||||||
{
|
|
||||||
EditorsValueWasNotModified();
|
|
||||||
|
|
||||||
// Update the control as well
|
|
||||||
m_selected->GetEditorClass()->SetControlStringValue( m_selected,
|
|
||||||
GetEditorControl(),
|
|
||||||
m_selected->GetDisplayedString() );
|
|
||||||
}
|
|
||||||
|
|
||||||
OnValidationFailureReset(m_selected);
|
|
||||||
|
|
||||||
res = false;
|
|
||||||
UnfocusEditor();
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------
|
|
||||||
|
|
||||||
void wxPropertyGrid::OnKey( wxKeyEvent &event )
|
void wxPropertyGrid::OnKey( wxKeyEvent &event )
|
||||||
{
|
{
|
||||||
HandleKeyEvent( event );
|
HandleKeyEvent(event, false);
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------
|
|
||||||
|
|
||||||
void wxPropertyGrid::OnKeyUp(wxKeyEvent &event)
|
|
||||||
{
|
|
||||||
event.Skip();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
@@ -5142,30 +5108,7 @@ bool wxPropertyGrid::ButtonTriggerKeyTest( int action, wxKeyEvent& event )
|
|||||||
|
|
||||||
void wxPropertyGrid::OnChildKeyDown( wxKeyEvent &event )
|
void wxPropertyGrid::OnChildKeyDown( wxKeyEvent &event )
|
||||||
{
|
{
|
||||||
int keycode = event.GetKeyCode();
|
HandleKeyEvent(event, true);
|
||||||
|
|
||||||
// Ignore Alt and Control when they are down alone
|
|
||||||
if ( keycode == WXK_ALT ||
|
|
||||||
keycode == WXK_CONTROL )
|
|
||||||
{
|
|
||||||
event.Skip();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ButtonTriggerKeyTest(-1, event) )
|
|
||||||
return;
|
|
||||||
|
|
||||||
if ( HandleChildKey(event) == true )
|
|
||||||
event.Skip();
|
|
||||||
|
|
||||||
GetEventHandler()->AddPendingEvent(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
void wxPropertyGrid::OnChildKeyUp( wxKeyEvent &event )
|
|
||||||
{
|
|
||||||
GetEventHandler()->AddPendingEvent(event);
|
|
||||||
|
|
||||||
event.Skip();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// -----------------------------------------------------------------------
|
// -----------------------------------------------------------------------
|
||||||
@@ -5182,6 +5125,17 @@ void wxPropertyGrid::OnIdle( wxIdleEvent& WXUNUSED(event) )
|
|||||||
HandleFocusChange( newFocused );
|
HandleFocusChange( newFocused );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool wxPropertyGrid::IsEditorFocused() const
|
||||||
|
{
|
||||||
|
wxWindow* focus = wxWindow::FindFocus();
|
||||||
|
|
||||||
|
if ( focus == m_wndEditor || focus == m_wndEditor2 ||
|
||||||
|
focus == GetEditorControl() )
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Called by focus event handlers. newFocused is the window that becomes focused.
|
// Called by focus event handlers. newFocused is the window that becomes focused.
|
||||||
void wxPropertyGrid::HandleFocusChange( wxWindow* newFocused )
|
void wxPropertyGrid::HandleFocusChange( wxWindow* newFocused )
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user