]> git.saurik.com Git - wxWidgets.git/blob - src/osx/checklst_osx.cpp
Maximize for iPhone
[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 m_macIsUserPane = false;
61
62 wxASSERT_MSG( !(style & wxLB_MULTIPLE) || !(style & wxLB_EXTENDED),
63 wxT("only one of listbox selection modes can be specified") );
64
65 if ( !wxCheckListBoxBase::Create( parent, id, pos, size, n, choices, style & ~(wxHSCROLL | wxVSCROLL), validator, name ) )
66 return false;
67
68 int colwidth = 30;
69 // TODO adapt the width according to the window variant
70 m_checkColumn = GetListPeer()->InsertCheckColumn(0, wxEmptyString, true, wxALIGN_CENTER, colwidth);
71
72 return true;
73 }
74
75 // ----------------------------------------------------------------------------
76 // wxCheckListBox functions
77 // ----------------------------------------------------------------------------
78
79 // ----------------------------------------------------------------------------
80 // wxCheckListBox functions
81 // ----------------------------------------------------------------------------
82
83 bool wxCheckListBox::IsChecked(unsigned int n) const
84 {
85 wxCHECK_MSG( IsValid(n), false,
86 wxT("invalid index in wxCheckListBox::IsChecked") );
87
88 return m_checks[n] != 0;
89 }
90
91 void wxCheckListBox::Check(unsigned int n, bool check)
92 {
93 wxCHECK_RET( IsValid(n),
94 wxT("invalid index in wxCheckListBox::Check") );
95
96 // intermediate var is needed to avoid compiler warning with VC++
97 bool isChecked = m_checks[n] != 0;
98 if ( check != isChecked )
99 {
100 m_checks[n] = check;
101
102 GetListPeer()->UpdateLine(n);
103 }
104 }
105
106 void wxCheckListBox::GetValueCallback( unsigned int n, wxListWidgetColumn* col , wxListWidgetCellValue& value )
107 {
108 if ( col == m_checkColumn )
109 value.Check( IsChecked( n ) );
110 else
111 wxListBox::GetValueCallback( n, col, value );
112 }
113
114 void wxCheckListBox::SetValueCallback( unsigned int n, wxListWidgetColumn* col , wxListWidgetCellValue& value )
115 {
116 if ( col == m_checkColumn )
117 {
118 Check( n, value.IsChecked() );
119
120 wxCommandEvent event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, GetId() );
121 event.SetInt( n );
122 event.SetString( GetString( n ) );
123 event.SetEventObject( this );
124 HandleWindowEvent( event );
125 }
126 }
127
128
129
130 // ----------------------------------------------------------------------------
131 // methods forwarded to wxListBox
132 // ----------------------------------------------------------------------------
133
134 void wxCheckListBox::OnItemInserted(unsigned int pos)
135 {
136 wxListBox::OnItemInserted(pos);
137
138 m_checks.Insert(false, pos );
139 }
140
141 void wxCheckListBox::DoDeleteOneItem(unsigned int n)
142 {
143 wxListBox::DoDeleteOneItem(n);
144
145 m_checks.RemoveAt(n);
146 }
147
148 void wxCheckListBox::DoClear()
149 {
150 wxListBox::DoClear();
151
152 m_checks.Empty();
153 }
154
155 #endif // wxUSE_CHECKLISTBOX