]> git.saurik.com Git - wxWidgets.git/blame - src/osx/checklst_osx.cpp
Add RunScript and implement on all backends. Document and add a very simple unit...
[wxWidgets.git] / src / osx / checklst_osx.cpp
CommitLineData
524c47aa
SC
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
524c47aa
SC
27BEGIN_EVENT_TABLE(wxCheckListBox, wxListBox)
28END_EVENT_TABLE()
03647350 29
524c47aa
SC
30void wxCheckListBox::Init()
31{
32}
33
34bool 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
49bool 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 )
d15694e8
SC
59{
60
524c47aa
SC
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
82bool wxCheckListBox::IsChecked(unsigned int n) const
83{
84 wxCHECK_MSG( IsValid(n), false,
9a83f860 85 wxT("invalid index in wxCheckListBox::IsChecked") );
524c47aa
SC
86
87 return m_checks[n] != 0;
88}
89
90void wxCheckListBox::Check(unsigned int n, bool check)
91{
92 wxCHECK_RET( IsValid(n),
9a83f860 93 wxT("invalid index in wxCheckListBox::Check") );
524c47aa
SC
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
105void wxCheckListBox::GetValueCallback( unsigned int n, wxListWidgetColumn* col , wxListWidgetCellValue& value )
106{
107 if ( col == m_checkColumn )
60ebcb8a 108 value.Check( IsChecked( n ) );
524c47aa
SC
109 else
110 wxListBox::GetValueCallback( n, col, value );
111}
112
113void wxCheckListBox::SetValueCallback( unsigned int n, wxListWidgetColumn* col , wxListWidgetCellValue& value )
114{
115 if ( col == m_checkColumn )
116 {
60ebcb8a 117 Check( n, value.IsChecked() );
03647350 118
524c47aa
SC
119 wxCommandEvent event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, GetId() );
120 event.SetInt( n );
51fbe4cc 121 event.SetString( GetString( n ) );
524c47aa
SC
122 event.SetEventObject( this );
123 HandleWindowEvent( event );
124 }
125}
126
127
128
129// ----------------------------------------------------------------------------
130// methods forwarded to wxListBox
131// ----------------------------------------------------------------------------
132
133void wxCheckListBox::OnItemInserted(unsigned int pos)
134{
7712257e
SC
135 wxListBox::OnItemInserted(pos);
136
524c47aa
SC
137 m_checks.Insert(false, pos );
138}
139
140void wxCheckListBox::DoDeleteOneItem(unsigned int n)
141{
142 wxListBox::DoDeleteOneItem(n);
143
144 m_checks.RemoveAt(n);
145}
146
147void wxCheckListBox::DoClear()
148{
7712257e
SC
149 wxListBox::DoClear();
150
524c47aa
SC
151 m_checks.Empty();
152}
153
154#endif // wxUSE_CHECKLISTBOX