]> git.saurik.com Git - wxWidgets.git/commitdiff
fixed multiple bugs in multiple selection wxCheckListBoxes
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 5 May 2002 23:09:37 +0000 (23:09 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 5 May 2002 23:09:37 +0000 (23:09 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15393 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
include/wx/msw/checklst.h
src/msw/checklst.cpp
src/msw/listbox.cpp

index 5808c49333613a7f748170f2302ac25085292321..bdeb238c76bf85c97a437b4bf5514c7908d0a271 100644 (file)
@@ -190,6 +190,7 @@ wxMSW:
 - Multiline labels in buttons are now supoprted (simply use "\n" in the label)
 - Implemented wxMouseCaptureChangedEvent and made wxGenericDragImage check it
   has the capture before release it.
+- fixed bugs in multiple selection wxCheckListBox
 
 wxGTK:
 
index 255a564fd39c3c321791db8c5ed6b96fb47011e3..473cc09b76901cdf1d314f3224865f886a254e57 100644 (file)
 #pragma interface "checklst.h"
 #endif
 
-#include "wx/setup.h"
-
 #if !wxUSE_OWNER_DRAWN
   #error  "wxCheckListBox class requires owner-drawn functionality."
 #endif
 
-#include "wx/listbox.h"
-
-class wxCheckListBoxItem; // fwd decl, defined in checklst.cpp
+class WXDLLEXPORT wxOwnerDrawn;
+class WXDLLEXPORT wxCheckListBoxItem; // fwd decl, defined in checklst.cpp
 
-class WXDLLEXPORT wxCheckListBox : public wxListBox
+class WXDLLEXPORT wxCheckListBox : public wxCheckListBoxBase
 {
-  DECLARE_DYNAMIC_CLASS(wxCheckListBox)
 public:
   // ctors
   wxCheckListBox();
@@ -47,8 +43,8 @@ public:
   virtual bool SetFont( const wxFont &font );
 
   // items may be checked
-  bool IsChecked(size_t uiIndex) const;
-  void Check(size_t uiIndex, bool bCheck = TRUE);
+  virtual bool IsChecked(size_t uiIndex) const;
+  virtual void Check(size_t uiIndex, bool bCheck = TRUE);
 
   // accessors
   size_t GetItemHeight() const { return m_nItemHeight; }
@@ -60,13 +56,14 @@ protected:
   virtual bool          MSWOnMeasure(WXMEASUREITEMSTRUCT *item);
 
   // pressing space or clicking the check box toggles the item
-  void OnChar(wxKeyEvent& event);
+  void OnKeyDown(wxKeyEvent& event);
   void OnLeftClick(wxMouseEvent& event);
 
 private:
   size_t    m_nItemHeight;  // height of checklistbox items (the same for all)
 
   DECLARE_EVENT_TABLE()
+  DECLARE_DYNAMIC_CLASS(wxCheckListBox)
 };
 
 #endif    //_CHECKLST_H
index 67c6494df89bf47d3926afbff1bcd0eb83974ae9..5aa72dd1e4196b5d723af61420746e4ef1f5ec7f 100644 (file)
 
 #if wxUSE_OWNER_DRAWN
 
-#include "wx/object.h"
-#include "wx/colour.h"
-#include "wx/font.h"
-#include "wx/bitmap.h"
-#include "wx/window.h"
-#include "wx/listbox.h"
+#ifndef WX_PRECOMP
+    #include "wx/object.h"
+    #include "wx/colour.h"
+    #include "wx/font.h"
+    #include "wx/bitmap.h"
+    #include "wx/window.h"
+    #include "wx/listbox.h"
+    #include "wx/dcmemory.h"
+
+    #include "wx/settings.h"
+
+    #include "wx/log.h"
+#endif
+
 #include "wx/ownerdrw.h"
-#include "wx/settings.h"
-#include "wx/dcmemory.h"
-#include "wx/msw/checklst.h"
-#include "wx/log.h"
+#include "wx/checklst.h"
 
 #include <windows.h>
 #include <windowsx.h>
@@ -262,7 +267,7 @@ void wxCheckListBoxItem::Check(bool check)
 // define event table
 // ------------------
 BEGIN_EVENT_TABLE(wxCheckListBox, wxListBox)
-  EVT_CHAR(wxCheckListBox::OnChar)
+  EVT_KEY_DOWN(wxCheckListBox::OnKeyDown)
   EVT_LEFT_DOWN(wxCheckListBox::OnLeftClick)
 END_EVENT_TABLE()
 
@@ -270,7 +275,7 @@ END_EVENT_TABLE()
 // ----------------
 
 // def ctor: use Create() to really create the control
-wxCheckListBox::wxCheckListBox() : wxListBox()
+wxCheckListBox::wxCheckListBox()
 {
 }
 
@@ -280,7 +285,6 @@ wxCheckListBox::wxCheckListBox(wxWindow *parent, wxWindowID id,
                                int nStrings, const wxString choices[],
                                long style, const wxValidator& val,
                                const wxString& name)
-              : wxListBox()
 {
     Create(parent, id, pos, size, nStrings, choices,
            style | wxLB_OWNERDRAW, val, name);
@@ -344,23 +348,95 @@ bool wxCheckListBox::MSWOnMeasure(WXMEASUREITEMSTRUCT *item)
 
 bool wxCheckListBox::IsChecked(size_t uiIndex) const
 {
-  return GetItem(uiIndex)->IsChecked();
+    wxCHECK_MSG( uiIndex < (size_t)GetCount(), FALSE, _T("bad wxCheckListBox index") );
+
+    return GetItem(uiIndex)->IsChecked();
 }
 
 void wxCheckListBox::Check(size_t uiIndex, bool bCheck)
 {
-  GetItem(uiIndex)->Check(bCheck);
+    wxCHECK_RET( uiIndex < (size_t)GetCount(), _T("bad wxCheckListBox index") );
+
+    GetItem(uiIndex)->Check(bCheck);
 }
 
 // process events
 // --------------
 
-void wxCheckListBox::OnChar(wxKeyEvent& event)
+void wxCheckListBox::OnKeyDown(wxKeyEvent& event)
 {
-  if ( event.KeyCode() == WXK_SPACE )
-    GetItem(GetSelection())->Toggle();
-  else
-    event.Skip();
+    // what do we do?
+    enum
+    {
+        None,
+        Toggle,
+        Set,
+        Clear
+    } oper;
+
+    switch ( event.KeyCode() )
+    {
+        case WXK_SPACE:
+            oper = Toggle;
+            break;
+
+        case WXK_NUMPAD_ADD:
+        case '+':
+            oper = Set;
+            break;
+
+        case WXK_NUMPAD_SUBTRACT:
+        case '-':
+            oper = Clear;
+            break;
+
+        default:
+            oper = None;
+    }
+
+    if ( oper != None )
+    {
+        wxArrayInt selections;
+        int count;
+        if ( HasMultipleSelection() )
+        {
+            count = GetSelections(selections);
+        }
+        else
+        {
+            count = 1;
+            selections.Add(GetSelection());
+        }
+
+        for ( int i = 0; i < count; i++ )
+        {
+            wxCheckListBoxItem *item = GetItem(selections[i]);
+            if ( !item )
+            {
+                wxFAIL_MSG( _T("no wxCheckListBoxItem?") );
+                continue;
+            }
+
+            switch ( oper )
+            {
+                case Toggle:
+                    item->Toggle();
+                    break;
+
+                case Set:
+                case Clear:
+                    item->Check( oper == Set );
+                    break;
+
+                default:
+                    wxFAIL_MSG( _T("what should this key do?") );
+            }
+        }
+    }
+    else // nothing to do
+    {
+        event.Skip();
+    }
 }
 
 void wxCheckListBox::OnLeftClick(wxMouseEvent& event)
index e6103c20255bc575c69fbaa94eae54d29b7fafa7..2eeafd8a784e6d50de4b559abb7e124342f6072a 100644 (file)
@@ -453,21 +453,32 @@ int wxListBox::GetSelections(wxArrayInt& aSelections) const
 
     if ( HasMultipleSelection() )
     {
-        int no_sel = ListBox_GetSelCount(GetHwnd());
-        if (no_sel != 0) {
-            int *selections = new int[no_sel];
-            int rc = ListBox_GetSelItems(GetHwnd(), no_sel, selections);
-
-            wxCHECK_MSG(rc != LB_ERR, -1, wxT("ListBox_GetSelItems failed"));
+        int countSel = ListBox_GetSelCount(GetHwnd());
+        if ( countSel == LB_ERR )
+        {
+            wxLogDebug(_T("ListBox_GetSelCount failed"));
+        }
+        else if ( countSel != 0 )
+        {
+            int *selections = new int[countSel];
 
-            aSelections.Alloc(no_sel);
-            for ( int n = 0; n < no_sel; n++ )
-                aSelections.Add(selections[n]);
+            if ( ListBox_GetSelItems(GetHwnd(),
+                                     countSel, selections) == LB_ERR )
+            {
+                wxLogDebug(wxT("ListBox_GetSelItems failed"));
+                countSel = -1;
+            }
+            else
+            {
+                aSelections.Alloc(countSel);
+                for ( int n = 0; n < countSel; n++ )
+                    aSelections.Add(selections[n]);
+            }
 
             delete [] selections;
         }
 
-        return no_sel;
+        return countSel;
     }
     else  // single-selection listbox
     {