fixed multiple bugs in multiple selection wxCheckListBoxes
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@15393 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
98dd66cf4f
commit
d90879fa39
@ -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:
|
||||
|
||||
|
@ -16,19 +16,15 @@
|
||||
#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 WXDLLEXPORT wxOwnerDrawn;
|
||||
class WXDLLEXPORT wxCheckListBoxItem; // fwd decl, defined in checklst.cpp
|
||||
|
||||
class 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
|
||||
|
@ -30,17 +30,22 @@
|
||||
|
||||
#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)
|
||||
|
@ -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);
|
||||
int countSel = ListBox_GetSelCount(GetHwnd());
|
||||
if ( countSel == LB_ERR )
|
||||
{
|
||||
wxLogDebug(_T("ListBox_GetSelCount failed"));
|
||||
}
|
||||
else if ( countSel != 0 )
|
||||
{
|
||||
int *selections = new int[countSel];
|
||||
|
||||
wxCHECK_MSG(rc != LB_ERR, -1, wxT("ListBox_GetSelItems failed"));
|
||||
|
||||
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
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user