From 46fa86f72086f4955919cbcc78a72a532aceca99 Mon Sep 17 00:00:00 2001 From: Jaakko Salli Date: Mon, 14 Dec 2009 16:13:21 +0000 Subject: [PATCH] Make wxPG_EX_MULTIPLE_SELECTION behave more like a Windows list box (regarding Ctrl and Shift keys) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62885 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/propgrid/propgrid.cpp | 81 +++++++++++++++++++++++++++++++++------ 1 file changed, 70 insertions(+), 11 deletions(-) diff --git a/src/propgrid/propgrid.cpp b/src/propgrid/propgrid.cpp index 1120d4ce51..c11f78d36f 100644 --- a/src/propgrid/propgrid.cpp +++ b/src/propgrid/propgrid.cpp @@ -779,9 +779,12 @@ bool wxPropertyGrid::AddToSelectionFromInputEvent( wxPGProperty* prop, wxMouseEvent* mouseEvent, int selFlags ) { + const wxArrayPGProperty& selection = GetSelectedProperties(); bool alreadySelected = m_pState->DoIsPropertySelected(prop); bool res = true; - bool addToExistingSelection; + + // Set to 2 if also add all items in between + int addToExistingSelection = 0; if ( GetExtraStyle() & wxPG_EX_MULTIPLE_SELECTION ) { @@ -799,21 +802,24 @@ bool wxPropertyGrid::AddToSelectionFromInputEvent( wxPGProperty* prop, } else { - addToExistingSelection = mouseEvent->ShiftDown(); + if ( mouseEvent->ControlDown() ) + { + addToExistingSelection = 1; + } + else if ( mouseEvent->ShiftDown() ) + { + if ( selection.size() > 0 && !prop->IsCategory() ) + addToExistingSelection = 2; + else + addToExistingSelection = 1; + } } } - else - { - addToExistingSelection = false; - } - } - else - { - addToExistingSelection = false; } - if ( addToExistingSelection ) + if ( addToExistingSelection == 1 ) { + // Add/remove one if ( !alreadySelected ) { res = DoAddToSelection(prop, selFlags); @@ -823,6 +829,59 @@ bool wxPropertyGrid::AddToSelectionFromInputEvent( wxPGProperty* prop, res = DoRemoveFromSelection(prop, selFlags); } } + else if ( addToExistingSelection == 2 ) + { + // Add this, and all in between + + // Find top selected property + wxPGProperty* topSelProp = selection[0]; + int topSelPropY = topSelProp->GetY(); + for ( unsigned int i=1; iGetY(); + if ( y < topSelPropY ) + { + topSelProp = p; + topSelPropY = y; + } + } + + wxPGProperty* startFrom; + wxPGProperty* stopAt; + + if ( prop->GetY() <= topSelPropY ) + { + // Property is above selection (or same) + startFrom = prop; + stopAt = topSelProp; + } + else + { + // Property is below selection + startFrom = topSelProp; + stopAt = prop; + } + + // Iterate through properties in-between, and select them + wxPropertyGridIterator it; + + for ( it = GetIterator(wxPG_ITERATE_VISIBLE, startFrom); + !it.AtEnd(); + it++ ) + { + wxPGProperty* p = *it; + + if ( !p->IsCategory() && + !m_pState->DoIsPropertySelected(p) ) + { + DoAddToSelection(p, selFlags); + } + + if ( p == stopAt ) + break; + } + } else { res = DoSelectAndEdit(prop, colIndex, selFlags); -- 2.45.2