]> git.saurik.com Git - wxWidgets.git/commitdiff
Added wxPropertyGrid::DedicateKey(), which prevents specific key presses from being...
authorJaakko Salli <jaakko.salli@dnainternet.net>
Sat, 12 Jun 2010 09:30:57 +0000 (09:30 +0000)
committerJaakko Salli <jaakko.salli@dnainternet.net>
Sat, 12 Jun 2010 09:30:57 +0000 (09:30 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64562 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
include/wx/propgrid/propgrid.h
include/wx/propgrid/propgriddefs.h
interface/wx/propgrid/propgrid.h
samples/propgrid/propgrid.cpp
samples/propgrid/propgrid.h
src/propgrid/property.cpp
src/propgrid/propgrid.cpp
src/propgrid/propgridpagestate.cpp

index ae2a06e6ee70db973e46145a6487319b8a135d3b..fee187ad4dc6175c48a84ef779b7dc4715e11305 100644 (file)
@@ -494,6 +494,7 @@ All (GUI):
   dismissed immediately as text control grabbed the focus).
 - wxPropertyGrid: added wxPG_EX_MULTIPLE_SELECTION.
 - wxPropertyGrid: added functions for editing property labels.
+- wxPropertyGrid: Added wxPropertyGrid::DedicateKey().
 - wxPropertyGridManager: added wxPG_NO_INTERNAL_BORDER,
   wxPG_EX_NO_TOOLBAR_DIVIDER and wxPG_EX_TOOLBAR_SEPARATOR styles for finer
   control over borders. Borders around property grid are now native for
index 9d783e2be08a4d71b2b3e949f969d310d382340c..973b9e21131b5163c5cca30f12fbd747cc0813a7 100644 (file)
@@ -709,12 +709,34 @@ public:
 
     /** Adds given key combination to trigger given action.
 
+        Here is a sample code to make Enter key press move focus to
+        the next property.
+
+        @code
+            propGrid->AddActionTrigger(wxPG_ACTION_NEXT_PROPERTY,
+                                       WXK_RETURN);
+            propGrid->DedicateKey(WXK_RETURN);
+        @endcode
+
         @param action
             Which action to trigger. See @link pgactions List of list of
             wxPropertyGrid actions@endlink.
     */
     void AddActionTrigger( int action, int keycode, int modifiers = 0 );
 
+    /**
+        Dedicates a specific keycode to wxPropertyGrid. This means that such
+        key presses will not be redirected to editor controls.
+
+        Using this function allows, for example, navigation between
+        properties using arrow keys even when the focus is in the editor
+        control.
+    */
+    void DedicateKey( int keycode )
+    {
+        m_dedicatedKeys.push_back(keycode);
+    }
+
     /**
         This static function enables or disables automatic use of
         wxGetTranslation for following strings: wxEnumProperty list labels,
@@ -1814,6 +1836,10 @@ protected:
     wxArrayPGProperty   m_deletedProperties;
     wxArrayPGProperty   m_removedProperties;
 
+    /** List of key codes that will not be handed over to editor controls. */
+    // FIXME: Make this a hash set once there is template-based wxHashSet.
+    wxVector<int>       m_dedicatedKeys;
+
     //
     // Temporary values
     //
index a9f7778fb2ebc76a29f84dc292b6e2d4b37174fb..57a042eb35f967538a903179f8b64afd40cbe346 100644 (file)
@@ -340,6 +340,19 @@ WX_DECLARE_HASH_MAP_WITH_DECL(wxInt32,
                               wxPGHashMapI2I,
                               class WXDLLIMPEXP_PROPGRID);
 
+// Utility to find if specific item is in a vector. Returns index to
+// the item, or wxNOT_FOUND if not present.
+template<typename CONTAINER, typename T>
+int wxPGFindInVector( CONTAINER vector, const T& item )
+{
+    for ( unsigned int i=0; i<vector.size(); i++ )
+    {
+        if ( vector[i] == item )
+            return (int) i;
+    }
+    return wxNOT_FOUND;
+}
+
 // -----------------------------------------------------------------------
 
 enum wxPG_GETPROPERTYVALUES_FLAGS
index 4f540172f55cc015a6be0e8a839ade545378422c..01d0bdd0753e919c0aba16b63f2743d7199c82cf 100644 (file)
@@ -445,6 +445,15 @@ public:
     /**
         Adds given key combination to trigger given action.
 
+        Here is a sample code to make Enter key press move focus to
+        the next property.
+
+        @code
+            propGrid->AddActionTrigger(wxPG_ACTION_NEXT_PROPERTY,
+                                       WXK_RETURN);
+            propGrid->DedicateKey(WXK_RETURN);
+        @endcode
+
         @param action
             Which action to trigger. See @ref propgrid_keyboard_actions.
         @param keycode
@@ -546,6 +555,16 @@ public:
                 long style = wxPG_DEFAULT_STYLE,
                 const wxChar* name = wxPropertyGridNameStr );
 
+    /**
+        Dedicates a specific keycode to wxPropertyGrid. This means that such
+        key presses will not be redirected to editor controls.
+
+        Using this function allows, for example, navigation between
+        properties using arrow keys even when the focus is in the editor
+        control.
+    */
+    void DedicateKey( int keycode );
+
     /**
         Enables or disables (shows/hides) categories according to parameter
         enable.
index 9bca75f01b9fe3fe4da56f7c1d29cd67d69306cd..83002fb868cd18def5e41a1980fc3eeeabce3d93 100644 (file)
@@ -691,7 +691,8 @@ enum
     ID_RUNMINIMAL,
     ID_ENABLELABELEDITING,
     ID_VETOCOLDRAG,
-    ID_SHOWHEADER
+    ID_SHOWHEADER,
+    ID_ONEXTENDEDKEYNAV
 };
 
 // -----------------------------------------------------------------------
@@ -756,6 +757,7 @@ BEGIN_EVENT_TABLE(FormMain, wxFrame)
     EVT_MENU( ID_ITERATE2, FormMain::OnIterate2Click )
     EVT_MENU( ID_ITERATE3, FormMain::OnIterate3Click )
     EVT_MENU( ID_ITERATE4, FormMain::OnIterate4Click )
+    EVT_MENU( ID_ONEXTENDEDKEYNAV, FormMain::OnExtendedKeyNav )
     EVT_MENU( ID_SETBGCOLOUR, FormMain::OnSetBackgroundColour )
     EVT_MENU( ID_SETBGCOLOURRECUR, FormMain::OnSetBackgroundColour )
     EVT_MENU( ID_CLEARMODIF, FormMain::OnClearModifyStatusClick )
@@ -2308,6 +2310,11 @@ FormMain::FormMain(const wxString& title, const wxPoint& pos, const wxSize& size
     menuTools2->Append(ID_ITERATE3, wxT("Reverse Iterate Over Properties") );
     menuTools2->Append(ID_ITERATE4, wxT("Iterate Over Categories") );
     menuTools2->AppendSeparator();
+    menuTools2->Append(ID_ONEXTENDEDKEYNAV, "Extend Keyboard Navigation",
+                       "This will set Enter to navigate to next property, "
+                       "and allows arrow keys to navigate even when in "
+                       "editor control.");
+    menuTools2->AppendSeparator();
     menuTools2->Append(ID_SETPROPERTYVALUE, wxT("Set Property Value") );
     menuTools2->Append(ID_CLEARMODIF, wxT("Clear Modified Status"), wxT("Clears wxPG_MODIFIED flag from all properties.") );
     menuTools2->AppendSeparator();
@@ -2684,6 +2691,25 @@ void FormMain::OnIterate4Click( wxCommandEvent& WXUNUSED(event) )
 
 // -----------------------------------------------------------------------
 
+void FormMain::OnExtendedKeyNav( wxCommandEvent& WXUNUSED(event) )
+{
+    // Use AddActionTrigger() and DedicateKey() to set up Enter,
+    // Up, and Down keys for navigating between properties.
+    wxPropertyGrid* propGrid = m_pPropGridManager->GetGrid();
+
+    propGrid->AddActionTrigger(wxPG_ACTION_NEXT_PROPERTY,
+                               WXK_RETURN);
+    propGrid->DedicateKey(WXK_RETURN);
+
+    // Up and Down keys are alredy associated with navigation,
+    // but we must also prevent them from being eaten by
+    // editor controls.
+    propGrid->DedicateKey(WXK_UP);
+    propGrid->DedicateKey(WXK_DOWN);
+}
+
+// -----------------------------------------------------------------------
+
 void FormMain::OnFitColumnsClick( wxCommandEvent& WXUNUSED(event) )
 {
     wxPropertyGridPage* page = m_pPropGridManager->GetCurrentPage();
index fb051d3978d05ff9adcf19ae43ce5e78790f4d83..5a73ace546d9f62af2d66023a1fd3df618e7242c 100644 (file)
@@ -226,6 +226,8 @@ public:
     void OnIterate3Click( wxCommandEvent& event );
     void OnIterate4Click( wxCommandEvent& event );
 
+    void OnExtendedKeyNav( wxCommandEvent& event );
+
     void OnPropertyGridChange( wxPropertyGridEvent& event );
     void OnPropertyGridChanging( wxPropertyGridEvent& event );
     void OnPropertyGridSelect( wxPropertyGridEvent& event );
index 93067a10f669c79bf46c36058e9589f249d091b2..04d2504498439752858f9bea401a91211ad16989 100644 (file)
@@ -692,12 +692,7 @@ wxPropertyGrid* wxPGProperty::GetGrid() const
 
 int wxPGProperty::Index( const wxPGProperty* p ) const
 {
-    for ( unsigned int i = 0; i<m_children.size(); i++ )
-    {
-        if ( p == m_children[i] )
-            return i;
-    }
-    return wxNOT_FOUND;
+    return wxPGFindInVector(m_children, p);
 }
 
 bool wxPGProperty::ValidateValue( wxVariant& WXUNUSED(value), wxPGValidationInfo& WXUNUSED(validationInfo) ) const
index 413443ad04aca9a1554e46910c3c104b2bc03d80..1500ccc3767e527b6a873380460b33d086f3fe39 100644 (file)
@@ -1022,6 +1022,7 @@ void wxPropertyGrid::OnLabelEditorKeyPress( wxKeyEvent& event )
 {
     int keycode = event.GetKeyCode();
 
+    // If key code was registered as action trigger, then trigger that action
     if ( keycode == WXK_ESCAPE )
     {
         DoEndLabelEdit(false);
@@ -5553,8 +5554,10 @@ void wxPropertyGrid::HandleKeyEvent( wxKeyEvent &event, bool fromChild )
         return;
     }
 
-    // Except for TAB and ESC, handle child control events in child control
-    if ( fromChild )
+    // Except for TAB, ESC, and any keys specifically dedicated to
+    // wxPropertyGrid itself, handle child control events in child control.
+    if ( fromChild &&
+         wxPGFindInVector(m_dedicatedKeys, keycode) == wxNOT_FOUND )
     {
         // Only propagate event if it had modifiers
         if ( !event.HasModifiers() )
@@ -5608,7 +5611,13 @@ void wxPropertyGrid::HandleKeyEvent( wxKeyEvent &event, bool fromChild )
         {
             p = wxPropertyGridIterator::OneStep( m_pState, wxPG_ITERATE_VISIBLE, p, selectDir );
             if ( p )
-                DoSelectProperty(p);
+            {
+                // If editor was focused, then make the next editor focused as well
+                int selFlags = 0;
+                if ( editorFocused )
+                    selFlags |= wxPG_SEL_FOCUS;
+                DoSelectProperty(p, selFlags);
+            }
             wasHandled = true;
         }
     }
index 1279370d12641d57afdefe58823f3e23d0bed06d..00357190c07a789115d250957ad7f89957e34f10 100644 (file)
@@ -1299,13 +1299,8 @@ bool wxPropertyGridPageState::DoSetPropertyValueWxObjectPtr( wxPGProperty* p, wx
 
 bool wxPropertyGridPageState::DoIsPropertySelected( wxPGProperty* prop ) const
 {
-    const wxArrayPGProperty& selection = m_selection;
-
-    for ( unsigned int i=0; i<selection.size(); i++ )
-    {
-        if ( selection[i] == prop )
-            return true;
-    }
+    if ( wxPGFindInVector(m_selection, prop) != wxNOT_FOUND )
+        return true;
 
     return false;
 }