]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/checklst.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/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"
20 #include "wx/arrstr.h"
22 #include "wx/mac/uma.h"
25 #include <Appearance.h>
28 IMPLEMENT_DYNAMIC_CLASS(wxCheckListBox
, wxListBox
)
30 BEGIN_EVENT_TABLE(wxCheckListBox
, wxListBox
)
33 void wxCheckListBox::Init()
37 bool wxCheckListBox::Create(
42 const wxArrayString
& choices
,
44 const wxValidator
& validator
,
45 const wxString
&name
)
47 wxCArrayString
chs( choices
);
49 return Create( parent
, id
, pos
, size
, chs
.GetCount(), chs
.GetStrings(), style
, validator
, name
);
52 bool wxCheckListBox::Create(
58 const wxString choices
[],
60 const wxValidator
& validator
,
61 const wxString
& name
)
63 m_macIsUserPane
= false;
65 wxASSERT_MSG( !(style
& wxLB_MULTIPLE
) || !(style
& wxLB_EXTENDED
),
66 wxT("only one of listbox selection modes can be specified") );
68 if ( !wxListBoxBase::Create( parent
, id
, pos
, size
, style
& ~(wxHSCROLL
| wxVSCROLL
), validator
, name
) )
71 // this will be increased by our Append command
74 m_peer
= (wxMacControl
*) CreateMacListControl(pos
, size
, style
);
76 MacPostControlCreate(pos
,size
);
78 InsertItems( n
, choices
, 0 );
80 // Needed because it is a wxControlWithItems
86 // ----------------------------------------------------------------------------
87 // wxCheckListBox functions
88 // ----------------------------------------------------------------------------
90 bool wxCheckListBox::IsChecked(unsigned int item
) const
92 wxCHECK_MSG( IsValid(item
), false,
93 wxT("invalid index in wxCheckListBox::IsChecked") );
95 return m_checks
[item
] != 0;
98 void wxCheckListBox::Check(unsigned int item
, bool check
)
100 wxCHECK_RET( IsValid(item
),
101 wxT("invalid index in wxCheckListBox::Check") );
103 bool isChecked
= m_checks
[item
] != 0;
104 if ( check
!= isChecked
)
106 m_checks
[item
] = check
;
107 MacUpdateLine( item
);
111 // ----------------------------------------------------------------------------
112 // methods forwarded to wxCheckListBox
113 // ----------------------------------------------------------------------------
115 void wxCheckListBox::Delete(unsigned int n
)
117 wxCHECK_RET( IsValid(n
), wxT("invalid index in wxCheckListBox::Delete") );
119 wxListBox::Delete( n
);
120 m_checks
.RemoveAt( n
);
123 int wxCheckListBox::DoAppend(const wxString
& item
)
125 int pos
= wxListBox::DoAppend( item
);
127 // the item is initially unchecked
128 m_checks
.Insert( false, pos
);
133 void wxCheckListBox::DoInsertItems(const wxArrayString
& items
, unsigned int pos
)
135 wxListBox::DoInsertItems( items
, pos
);
137 unsigned int count
= items
.GetCount();
138 for ( unsigned int n
= 0; n
< count
; n
++ )
140 m_checks
.Insert( false, pos
+ n
);
144 void wxCheckListBox::DoSetItems(const wxArrayString
& items
, void **clientData
)
146 // call it first as it does DoClear()
147 wxListBox::DoSetItems( items
, clientData
);
149 unsigned int count
= items
.GetCount();
150 for ( unsigned int n
= 0; n
< count
; n
++ )
152 m_checks
.Add( false );
156 void wxCheckListBox::DoClear()
161 #endif // wxUSE_CHECKLISTBOX