]> git.saurik.com Git - wxWidgets.git/blob - src/osx/checklst_osx.cpp
fix for GTK assert after r72696, a draw/expose_event signal may also be attached...
[wxWidgets.git] / src / osx / checklst_osx.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/checklst.cpp
3 // Purpose: implementation of wxCheckListBox class
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 ///////////////////////////////////////////////////////////////////////////////
11 //
12 // new DataBrowser-based version
13
14
15 #include "wx/wxprec.h"
16
17 #if wxUSE_CHECKLISTBOX
18
19 #include "wx/checklst.h"
20
21 #ifndef WX_PRECOMP
22 #include "wx/arrstr.h"
23 #endif
24
25 #include "wx/osx/private.h"
26
27 BEGIN_EVENT_TABLE(wxCheckListBox, wxListBox)
28 END_EVENT_TABLE()
29
30 void wxCheckListBox::Init()
31 {
32 }
33
34 bool wxCheckListBox::Create(
35 wxWindow *parent,
36 wxWindowID id,
37 const wxPoint &pos,
38 const wxSize &size,
39 const wxArrayString& choices,
40 long style,
41 const wxValidator& validator,
42 const wxString &name )
43 {
44 wxCArrayString chs( choices );
45
46 return Create( parent, id, pos, size, chs.GetCount(), chs.GetStrings(), style, validator, name );
47 }
48
49 bool wxCheckListBox::Create(
50 wxWindow *parent,
51 wxWindowID id,
52 const wxPoint& pos,
53 const wxSize& size,
54 int n,
55 const wxString choices[],
56 long style,
57 const wxValidator& validator,
58 const wxString& name )
59 {
60
61 wxASSERT_MSG( !(style & wxLB_MULTIPLE) || !(style & wxLB_EXTENDED),
62 wxT("only one of listbox selection modes can be specified") );
63
64 if ( !wxCheckListBoxBase::Create( parent, id, pos, size, n, choices, style & ~(wxHSCROLL | wxVSCROLL), validator, name ) )
65 return false;
66
67 int colwidth = 30;
68 // TODO adapt the width according to the window variant
69 m_checkColumn = GetListPeer()->InsertCheckColumn(0, wxEmptyString, true, wxALIGN_CENTER, colwidth);
70
71 return true;
72 }
73
74 // ----------------------------------------------------------------------------
75 // wxCheckListBox functions
76 // ----------------------------------------------------------------------------
77
78 // ----------------------------------------------------------------------------
79 // wxCheckListBox functions
80 // ----------------------------------------------------------------------------
81
82 bool wxCheckListBox::IsChecked(unsigned int n) const
83 {
84 wxCHECK_MSG( IsValid(n), false,
85 wxT("invalid index in wxCheckListBox::IsChecked") );
86
87 return m_checks[n] != 0;
88 }
89
90 void wxCheckListBox::Check(unsigned int n, bool check)
91 {
92 wxCHECK_RET( IsValid(n),
93 wxT("invalid index in wxCheckListBox::Check") );
94
95 // intermediate var is needed to avoid compiler warning with VC++
96 bool isChecked = m_checks[n] != 0;
97 if ( check != isChecked )
98 {
99 m_checks[n] = check;
100
101 GetListPeer()->UpdateLine(n);
102 }
103 }
104
105 void wxCheckListBox::GetValueCallback( unsigned int n, wxListWidgetColumn* col , wxListWidgetCellValue& value )
106 {
107 if ( col == m_checkColumn )
108 value.Check( IsChecked( n ) );
109 else
110 wxListBox::GetValueCallback( n, col, value );
111 }
112
113 void wxCheckListBox::SetValueCallback( unsigned int n, wxListWidgetColumn* col , wxListWidgetCellValue& value )
114 {
115 if ( col == m_checkColumn )
116 {
117 Check( n, value.IsChecked() );
118
119 wxCommandEvent event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, GetId() );
120 event.SetInt( n );
121 event.SetString( GetString( n ) );
122 event.SetEventObject( this );
123 HandleWindowEvent( event );
124 }
125 }
126
127
128
129 // ----------------------------------------------------------------------------
130 // methods forwarded to wxListBox
131 // ----------------------------------------------------------------------------
132
133 void wxCheckListBox::OnItemInserted(unsigned int pos)
134 {
135 wxListBox::OnItemInserted(pos);
136
137 m_checks.Insert(false, pos );
138 }
139
140 void wxCheckListBox::DoDeleteOneItem(unsigned int n)
141 {
142 wxListBox::DoDeleteOneItem(n);
143
144 m_checks.RemoveAt(n);
145 }
146
147 void wxCheckListBox::DoClear()
148 {
149 wxListBox::DoClear();
150
151 m_checks.Empty();
152 }
153
154 #endif // wxUSE_CHECKLISTBOX