]> git.saurik.com Git - wxWidgets.git/commitdiff
Simplistic tab support is now default (tab focuses editor if unfocused, otherwise...
authorJaakko Salli <jaakko.salli@dnainternet.net>
Sat, 18 Oct 2008 15:11:44 +0000 (15:11 +0000)
committerJaakko Salli <jaakko.salli@dnainternet.net>
Sat, 18 Oct 2008 15:11:44 +0000 (15:11 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56422 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/propgrid/propgrid.h
samples/propgrid/propgrid.cpp
src/propgrid/propgrid.cpp

index b566b7679a8885af0c2ce47ab2b3652f6077122f..2c583841e6f3bfa8bbc1baf9cc28b2d02a0bbfa4 100644 (file)
@@ -1642,7 +1642,6 @@ protected:
     void OnMouseDoubleClick( wxMouseEvent &event );
     void OnMouseUp( wxMouseEvent &event );
     void OnKey( wxKeyEvent &event );
-    void OnKeyUp( wxKeyEvent &event );
     void OnResize( wxSizeEvent &event );
 
     // event handlers
@@ -1651,9 +1650,7 @@ protected:
     bool HandleMouseRightClick( 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 );
-    void HandleKeyEvent( wxKeyEvent &event );
-    // Handle TAB and ESCAPE in control
-    bool HandleChildKey( wxKeyEvent& event );
+    void HandleKeyEvent( wxKeyEvent &event, bool fromChild );
 
     void OnMouseEntry( wxMouseEvent &event );
 
@@ -1670,7 +1667,6 @@ protected:
     void OnMouseMoveChild( wxMouseEvent &event );
     void OnMouseUpChild( wxMouseEvent &event );
     void OnChildKeyDown( wxKeyEvent &event );
-    void OnChildKeyUp( wxKeyEvent &event );
 
     void OnCaptureChange( wxMouseCaptureChangedEvent &event );
 
@@ -1750,6 +1746,9 @@ protected:
 
     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
     // focused.
     void HandleFocusChange( wxWindow* newFocused );
index 6387831ea1669ff98dc461f8a8f5cef6a1a9b866..1c9ef397a5ca74bc071a235d2b83b8cbc88f037c 100644 (file)
@@ -1929,7 +1929,9 @@ void FormMain::InitPanel()
     if ( m_panel )
         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;
 
     // Column
@@ -1940,11 +1942,17 @@ void FormMain::InitPanel()
 
 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_topSizer->SetSizeHints( m_panel );
 
     wxBoxSizer* panelSizer = new wxBoxSizer( wxHORIZONTAL );
     panelSizer->Add( m_panel, 1, wxEXPAND|wxFIXED_MINSIZE );
+
     SetSizer( panelSizer );
     panelSizer->SetSizeHints( this );
 
@@ -1988,7 +1996,6 @@ void FormMain::CreateGrid( int style, int extraStyle )
                 //wxPG_TOOLTIPS |
                 //wxPG_HIDE_CATEGORIES |
                 //wxPG_LIMITED_EDITING |
-                wxTAB_TRAVERSAL |
                 wxPG_TOOLBAR |
                 wxPG_DESCRIPTION;
 
@@ -2084,7 +2091,6 @@ FormMain::FormMain(const wxString& title, const wxPoint& pos, const wxSize& size
                 //wxPG_TOOLTIPS |
                 //wxPG_HIDE_CATEGORIES |
                 //wxPG_LIMITED_EDITING |
-                wxTAB_TRAVERSAL |
                 wxPG_TOOLBAR |
                 wxPG_DESCRIPTION,
                 // extra style
index f512a6e82b21eb1cebd819271a962ca1e67474ec..f3ee1594ec3938e12086da2a7e0a76d5a1c18baa 100644 (file)
@@ -408,12 +408,6 @@ protected:
         pg->OnKey( event );
     }
 
-    void OnKeyUp( wxKeyEvent& event )
-    {
-        wxPropertyGrid* pg = wxStaticCast(GetParent(), wxPropertyGrid);
-        pg->OnKeyUp( event );
-    }
-
     void OnPaint( wxPaintEvent& event );
     
     // Always be focussable, even with child windows
@@ -437,8 +431,6 @@ BEGIN_EVENT_TABLE(wxPGCanvas, wxPanel)
     EVT_RIGHT_UP(wxPGCanvas::OnMouseRightClick)
     EVT_LEFT_DCLICK(wxPGCanvas::OnMouseDoubleClick)
     EVT_KEY_DOWN(wxPGCanvas::OnKey)
-    EVT_KEY_UP(wxPGCanvas::OnKeyUp)
-    EVT_CHAR(wxPGCanvas::OnKey)
 END_EVENT_TABLE()
 
 
@@ -523,18 +515,9 @@ bool wxPropertyGrid::Create( wxWindow *parent,
 
     style |= wxVSCROLL;
 
-#ifdef __WXMSW__
-    // This prevents crash under Win2K, but still
-    // enables keyboard navigation
-    if ( style & wxTAB_TRAVERSAL )
-    {
-        style &= ~(wxTAB_TRAVERSAL);
-        style |= wxWANTS_CHARS;
-    }
-#else
-    if ( style & wxTAB_TRAVERSAL )
-        style |= wxWANTS_CHARS;
-#endif
+    // Filter out wxTAB_TRAVERSAL - we will handle TABs manually
+    style &= ~(wxTAB_TRAVERSAL);
+    style |= wxWANTS_CHARS;
 
     wxScrolledWindow::Create(parent,id,pos,size,style,name);
 
@@ -702,7 +685,7 @@ void wxPropertyGrid::Init2()
 
     m_canvas = new wxPGCanvas();
     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_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.
@@ -4977,11 +4960,25 @@ void wxPropertyGrid::HandleKeyEvent(wxKeyEvent &event)
 
     // Travelsal between items, collapsing/expanding, etc.
     int keycode = event.GetKeyCode();
+    bool editorFocused = IsEditorFocused();
 
     if ( keycode == WXK_TAB )
     {
-        if (m_selected)
-            DoSelectProperty( m_selected, wxPG_SEL_FOCUS );
+        if ( !event.ShiftDown() )
+        {
+            if ( !editorFocused && m_wndEditor )
+                DoSelectProperty( m_selected, wxPG_SEL_FOCUS );
+            else
+                Navigate(wxNavigationKeyEvent::IsForward);
+        }
+        else
+        {
+            if ( editorFocused )
+                UnfocusEditor();
+            else
+                Navigate(wxNavigationKeyEvent::IsBackward);
+        }
+
         return;
     }
 
@@ -4996,9 +4993,32 @@ void wxPropertyGrid::HandleKeyEvent(wxKeyEvent &event)
     int secondAction;
     int action = KeyEventToActions(event, &secondAction);
 
-    if ( m_selected )
+    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 )
+    {
         // Show dialog?
         if ( ButtonTriggerKeyTest(action, event) )
             return;
@@ -5034,11 +5054,6 @@ void wxPropertyGrid::HandleKeyEvent(wxKeyEvent &event)
             {
                 selectDir = 1;
             }
-            else
-            {
-                event.Skip();
-            }
-
         }
 
         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 )
 {
-    HandleKeyEvent( event );
-}
-
-// -----------------------------------------------------------------------
-
-void wxPropertyGrid::OnKeyUp(wxKeyEvent &event)
-{
-    event.Skip();
+    HandleKeyEvent(event, false);
 }
 
 // -----------------------------------------------------------------------
@@ -5142,30 +5108,7 @@ bool wxPropertyGrid::ButtonTriggerKeyTest( int action, wxKeyEvent& event )
 
 void wxPropertyGrid::OnChildKeyDown( wxKeyEvent &event )
 {
-    int keycode = event.GetKeyCode();
-
-    // 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();
+    HandleKeyEvent(event, true);
 }
 
 // -----------------------------------------------------------------------
@@ -5182,6 +5125,17 @@ void wxPropertyGrid::OnIdle( wxIdleEvent& WXUNUSED(event) )
         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.
 void wxPropertyGrid::HandleFocusChange( wxWindow* newFocused )
 {