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 IMPLEMENT_DYNAMIC_CLASS(wxCheckListBox
, wxListBox
)
29 BEGIN_EVENT_TABLE(wxCheckListBox
, wxListBox
)
32 void wxCheckListBox::Init()
36 bool wxCheckListBox::Create(
41 const wxArrayString
& choices
,
43 const wxValidator
& validator
,
44 const wxString
&name
)
46 wxCArrayString
chs( choices
);
48 return Create( parent
, id
, pos
, size
, chs
.GetCount(), chs
.GetStrings(), style
, validator
, name
);
51 bool wxCheckListBox::Create(
57 const wxString choices
[],
59 const wxValidator
& validator
,
60 const wxString
& name
)
62 m_macIsUserPane
= false;
64 wxASSERT_MSG( !(style
& wxLB_MULTIPLE
) || !(style
& wxLB_EXTENDED
),
65 wxT("only one of listbox selection modes can be specified") );
67 if ( !wxCheckListBoxBase::Create( parent
, id
, pos
, size
, n
, choices
, style
& ~(wxHSCROLL
| wxVSCROLL
), validator
, name
) )
71 // TODO adapt the width according to the window variant
72 m_checkColumn
= GetListPeer()->InsertCheckColumn(0, wxEmptyString
, true, wxALIGN_CENTER
, colwidth
);
77 // ----------------------------------------------------------------------------
78 // wxCheckListBox functions
79 // ----------------------------------------------------------------------------
81 // ----------------------------------------------------------------------------
82 // wxCheckListBox functions
83 // ----------------------------------------------------------------------------
85 bool wxCheckListBox::IsChecked(unsigned int n
) const
87 wxCHECK_MSG( IsValid(n
), false,
88 wxT("invalid index in wxCheckListBox::IsChecked") );
90 return m_checks
[n
] != 0;
93 void wxCheckListBox::Check(unsigned int n
, bool check
)
95 wxCHECK_RET( IsValid(n
),
96 wxT("invalid index in wxCheckListBox::Check") );
98 // intermediate var is needed to avoid compiler warning with VC++
99 bool isChecked
= m_checks
[n
] != 0;
100 if ( check
!= isChecked
)
104 GetListPeer()->UpdateLine(n
);
108 void wxCheckListBox::GetValueCallback( unsigned int n
, wxListWidgetColumn
* col
, wxListWidgetCellValue
& value
)
110 if ( col
== m_checkColumn
)
111 value
.Check( IsChecked( n
) );
113 wxListBox::GetValueCallback( n
, col
, value
);
116 void wxCheckListBox::SetValueCallback( unsigned int n
, wxListWidgetColumn
* col
, wxListWidgetCellValue
& value
)
118 if ( col
== m_checkColumn
)
120 Check( n
, value
.IsChecked() );
122 wxCommandEvent
event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED
, GetId() );
124 event
.SetString( GetString( n
) );
125 event
.SetEventObject( this );
126 HandleWindowEvent( event
);
132 // ----------------------------------------------------------------------------
133 // methods forwarded to wxListBox
134 // ----------------------------------------------------------------------------
136 void wxCheckListBox::OnItemInserted(unsigned int pos
)
138 wxListBox::OnItemInserted(pos
);
140 m_checks
.Insert(false, pos
);
143 void wxCheckListBox::DoDeleteOneItem(unsigned int n
)
145 wxListBox::DoDeleteOneItem(n
);
147 m_checks
.RemoveAt(n
);
150 void wxCheckListBox::DoClear()
152 wxListBox::DoClear();
157 #endif // wxUSE_CHECKLISTBOX