]>
git.saurik.com Git - wxWidgets.git/blob - src/osx/checklst_osx.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/checklst.cpp
3 // Purpose: implementation of wxCheckListBox class
4 // Author: Stefan Csomor
7 // Copyright: (c) Stefan Csomor
8 // Licence: wxWindows licence
9 ///////////////////////////////////////////////////////////////////////////////
11 // new DataBrowser-based version
14 #include "wx/wxprec.h"
16 #if wxUSE_CHECKLISTBOX
18 #include "wx/checklst.h"
21 #include "wx/arrstr.h"
24 #include "wx/osx/private.h"
26 BEGIN_EVENT_TABLE(wxCheckListBox
, wxListBox
)
29 void wxCheckListBox::Init()
33 bool wxCheckListBox::Create(
38 const wxArrayString
& choices
,
40 const wxValidator
& validator
,
41 const wxString
&name
)
43 wxCArrayString
chs( choices
);
45 return Create( parent
, id
, pos
, size
, chs
.GetCount(), chs
.GetStrings(), style
, validator
, name
);
48 bool wxCheckListBox::Create(
54 const wxString choices
[],
56 const wxValidator
& validator
,
57 const wxString
& name
)
60 wxASSERT_MSG( !(style
& wxLB_MULTIPLE
) || !(style
& wxLB_EXTENDED
),
61 wxT("only one of listbox selection modes can be specified") );
63 if ( !wxCheckListBoxBase::Create( parent
, id
, pos
, size
, n
, choices
, style
& ~(wxHSCROLL
| wxVSCROLL
), validator
, name
) )
67 // TODO adapt the width according to the window variant
68 m_checkColumn
= GetListPeer()->InsertCheckColumn(0, wxEmptyString
, true, wxALIGN_CENTER
, colwidth
);
73 // ----------------------------------------------------------------------------
74 // wxCheckListBox functions
75 // ----------------------------------------------------------------------------
77 // ----------------------------------------------------------------------------
78 // wxCheckListBox functions
79 // ----------------------------------------------------------------------------
81 bool wxCheckListBox::IsChecked(unsigned int n
) const
83 wxCHECK_MSG( IsValid(n
), false,
84 wxT("invalid index in wxCheckListBox::IsChecked") );
86 return m_checks
[n
] != 0;
89 void wxCheckListBox::Check(unsigned int n
, bool check
)
91 wxCHECK_RET( IsValid(n
),
92 wxT("invalid index in wxCheckListBox::Check") );
94 // intermediate var is needed to avoid compiler warning with VC++
95 bool isChecked
= m_checks
[n
] != 0;
96 if ( check
!= isChecked
)
100 GetListPeer()->UpdateLine(n
);
104 void wxCheckListBox::GetValueCallback( unsigned int n
, wxListWidgetColumn
* col
, wxListWidgetCellValue
& value
)
106 if ( col
== m_checkColumn
)
107 value
.Check( IsChecked( n
) );
109 wxListBox::GetValueCallback( n
, col
, value
);
112 void wxCheckListBox::SetValueCallback( unsigned int n
, wxListWidgetColumn
* col
, wxListWidgetCellValue
& value
)
114 if ( col
== m_checkColumn
)
116 Check( n
, value
.IsChecked() );
118 wxCommandEvent
event( wxEVT_CHECKLISTBOX
, GetId() );
120 event
.SetString( GetString( n
) );
121 event
.SetEventObject( this );
122 HandleWindowEvent( event
);
128 // ----------------------------------------------------------------------------
129 // methods forwarded to wxListBox
130 // ----------------------------------------------------------------------------
132 void wxCheckListBox::OnItemInserted(unsigned int pos
)
134 wxListBox::OnItemInserted(pos
);
136 m_checks
.Insert(false, pos
);
139 void wxCheckListBox::DoDeleteOneItem(unsigned int n
)
141 wxListBox::DoDeleteOneItem(n
);
143 m_checks
.RemoveAt(n
);
146 void wxCheckListBox::DoClear()
148 wxListBox::DoClear();
153 #endif // wxUSE_CHECKLISTBOX