1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/checklst.cpp
3 // Purpose: implementation of wxCheckListBox class
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
12 // new DataBrowser-based version
15 #include "wx/wxprec.h"
17 #if wxUSE_CHECKLISTBOX
19 #include "wx/checklst.h"
22 #include "wx/arrstr.h"
25 #include "wx/osx/private.h"
27 BEGIN_EVENT_TABLE(wxCheckListBox
, wxListBox
)
30 void wxCheckListBox::Init()
34 bool wxCheckListBox::Create(
39 const wxArrayString
& choices
,
41 const wxValidator
& validator
,
42 const wxString
&name
)
44 wxCArrayString
chs( choices
);
46 return Create( parent
, id
, pos
, size
, chs
.GetCount(), chs
.GetStrings(), style
, validator
, name
);
49 bool wxCheckListBox::Create(
55 const wxString choices
[],
57 const wxValidator
& validator
,
58 const wxString
& name
)
61 wxASSERT_MSG( !(style
& wxLB_MULTIPLE
) || !(style
& wxLB_EXTENDED
),
62 wxT("only one of listbox selection modes can be specified") );
64 if ( !wxCheckListBoxBase::Create( parent
, id
, pos
, size
, n
, choices
, style
& ~(wxHSCROLL
| wxVSCROLL
), validator
, name
) )
68 // TODO adapt the width according to the window variant
69 m_checkColumn
= GetListPeer()->InsertCheckColumn(0, wxEmptyString
, true, wxALIGN_CENTER
, colwidth
);
74 // ----------------------------------------------------------------------------
75 // wxCheckListBox functions
76 // ----------------------------------------------------------------------------
78 // ----------------------------------------------------------------------------
79 // wxCheckListBox functions
80 // ----------------------------------------------------------------------------
82 bool wxCheckListBox::IsChecked(unsigned int n
) const
84 wxCHECK_MSG( IsValid(n
), false,
85 wxT("invalid index in wxCheckListBox::IsChecked") );
87 return m_checks
[n
] != 0;
90 void wxCheckListBox::Check(unsigned int n
, bool check
)
92 wxCHECK_RET( IsValid(n
),
93 wxT("invalid index in wxCheckListBox::Check") );
95 // intermediate var is needed to avoid compiler warning with VC++
96 bool isChecked
= m_checks
[n
] != 0;
97 if ( check
!= isChecked
)
101 GetListPeer()->UpdateLine(n
);
105 void wxCheckListBox::GetValueCallback( unsigned int n
, wxListWidgetColumn
* col
, wxListWidgetCellValue
& value
)
107 if ( col
== m_checkColumn
)
108 value
.Check( IsChecked( n
) );
110 wxListBox::GetValueCallback( n
, col
, value
);
113 void wxCheckListBox::SetValueCallback( unsigned int n
, wxListWidgetColumn
* col
, wxListWidgetCellValue
& value
)
115 if ( col
== m_checkColumn
)
117 Check( n
, value
.IsChecked() );
119 wxCommandEvent
event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED
, GetId() );
121 event
.SetString( GetString( n
) );
122 event
.SetEventObject( this );
123 HandleWindowEvent( event
);
129 // ----------------------------------------------------------------------------
130 // methods forwarded to wxListBox
131 // ----------------------------------------------------------------------------
133 void wxCheckListBox::OnItemInserted(unsigned int pos
)
135 wxListBox::OnItemInserted(pos
);
137 m_checks
.Insert(false, pos
);
140 void wxCheckListBox::DoDeleteOneItem(unsigned int n
)
142 wxListBox::DoDeleteOneItem(n
);
144 m_checks
.RemoveAt(n
);
147 void wxCheckListBox::DoClear()
149 wxListBox::DoClear();
154 #endif // wxUSE_CHECKLISTBOX