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
)
60 m_macIsUserPane
= false;
62 wxASSERT_MSG( !(style
& wxLB_MULTIPLE
) || !(style
& wxLB_EXTENDED
),
63 wxT("only one of listbox selection modes can be specified") );
65 if ( !wxCheckListBoxBase::Create( parent
, id
, pos
, size
, n
, choices
, style
& ~(wxHSCROLL
| wxVSCROLL
), validator
, name
) )
69 // TODO adapt the width according to the window variant
70 m_checkColumn
= GetListPeer()->InsertCheckColumn(0, wxEmptyString
, true, wxALIGN_CENTER
, colwidth
);
75 // ----------------------------------------------------------------------------
76 // wxCheckListBox functions
77 // ----------------------------------------------------------------------------
79 // ----------------------------------------------------------------------------
80 // wxCheckListBox functions
81 // ----------------------------------------------------------------------------
83 bool wxCheckListBox::IsChecked(unsigned int n
) const
85 wxCHECK_MSG( IsValid(n
), false,
86 wxT("invalid index in wxCheckListBox::IsChecked") );
88 return m_checks
[n
] != 0;
91 void wxCheckListBox::Check(unsigned int n
, bool check
)
93 wxCHECK_RET( IsValid(n
),
94 wxT("invalid index in wxCheckListBox::Check") );
96 // intermediate var is needed to avoid compiler warning with VC++
97 bool isChecked
= m_checks
[n
] != 0;
98 if ( check
!= isChecked
)
102 GetListPeer()->UpdateLine(n
);
106 void wxCheckListBox::GetValueCallback( unsigned int n
, wxListWidgetColumn
* col
, wxListWidgetCellValue
& value
)
108 if ( col
== m_checkColumn
)
109 value
.Check( IsChecked( n
) );
111 wxListBox::GetValueCallback( n
, col
, value
);
114 void wxCheckListBox::SetValueCallback( unsigned int n
, wxListWidgetColumn
* col
, wxListWidgetCellValue
& value
)
116 if ( col
== m_checkColumn
)
118 Check( n
, value
.IsChecked() );
120 wxCommandEvent
event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED
, GetId() );
122 event
.SetString( GetString( n
) );
123 event
.SetEventObject( this );
124 HandleWindowEvent( event
);
130 // ----------------------------------------------------------------------------
131 // methods forwarded to wxListBox
132 // ----------------------------------------------------------------------------
134 void wxCheckListBox::OnItemInserted(unsigned int pos
)
136 wxListBox::OnItemInserted(pos
);
138 m_checks
.Insert(false, pos
);
141 void wxCheckListBox::DoDeleteOneItem(unsigned int n
)
143 wxListBox::DoDeleteOneItem(n
);
145 m_checks
.RemoveAt(n
);
148 void wxCheckListBox::DoClear()
150 wxListBox::DoClear();
155 #endif // wxUSE_CHECKLISTBOX