]> git.saurik.com Git - wxWidgets.git/blame - src/osx/checklst_osx.cpp
Correct wxDataViewCtrl::IsExpanded
[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
27IMPLEMENT_DYNAMIC_CLASS(wxCheckListBox, wxListBox)
28
29BEGIN_EVENT_TABLE(wxCheckListBox, wxListBox)
30END_EVENT_TABLE()
31
32void wxCheckListBox::Init()
33{
34}
35
36bool wxCheckListBox::Create(
37 wxWindow *parent,
38 wxWindowID id,
39 const wxPoint &pos,
40 const wxSize &size,
41 const wxArrayString& choices,
42 long style,
43 const wxValidator& validator,
44 const wxString &name )
45{
46 wxCArrayString chs( choices );
47
48 return Create( parent, id, pos, size, chs.GetCount(), chs.GetStrings(), style, validator, name );
49}
50
51bool wxCheckListBox::Create(
52 wxWindow *parent,
53 wxWindowID id,
54 const wxPoint& pos,
55 const wxSize& size,
56 int n,
57 const wxString choices[],
58 long style,
59 const wxValidator& validator,
60 const wxString& name )
61{
62 m_macIsUserPane = false;
63
64 wxASSERT_MSG( !(style & wxLB_MULTIPLE) || !(style & wxLB_EXTENDED),
65 wxT("only one of listbox selection modes can be specified") );
66
67 if ( !wxCheckListBoxBase::Create( parent, id, pos, size, n, choices, style & ~(wxHSCROLL | wxVSCROLL), validator, name ) )
68 return false;
69
70 int colwidth = 30;
71 // TODO adapt the width according to the window variant
72 m_checkColumn = GetListPeer()->InsertCheckColumn(0, wxEmptyString, true, wxALIGN_CENTER, colwidth);
73
74 return true;
75}
76
77// ----------------------------------------------------------------------------
78// wxCheckListBox functions
79// ----------------------------------------------------------------------------
80
81// ----------------------------------------------------------------------------
82// wxCheckListBox functions
83// ----------------------------------------------------------------------------
84
85bool wxCheckListBox::IsChecked(unsigned int n) const
86{
87 wxCHECK_MSG( IsValid(n), false,
88 _T("invalid index in wxCheckListBox::IsChecked") );
89
90 return m_checks[n] != 0;
91}
92
93void wxCheckListBox::Check(unsigned int n, bool check)
94{
95 wxCHECK_RET( IsValid(n),
96 _T("invalid index in wxCheckListBox::Check") );
97
98 // intermediate var is needed to avoid compiler warning with VC++
99 bool isChecked = m_checks[n] != 0;
100 if ( check != isChecked )
101 {
102 m_checks[n] = check;
103
104 GetListPeer()->UpdateLine(n);
105 }
106}
107
108void wxCheckListBox::GetValueCallback( unsigned int n, wxListWidgetColumn* col , wxListWidgetCellValue& value )
109{
110 if ( col == m_checkColumn )
111 value.Set( IsChecked( n ) );
112 else
113 wxListBox::GetValueCallback( n, col, value );
114}
115
116void wxCheckListBox::SetValueCallback( unsigned int n, wxListWidgetColumn* col , wxListWidgetCellValue& value )
117{
118 if ( col == m_checkColumn )
119 {
c4021a79 120 Check( n, value.GetIntValue() != 0 );
524c47aa
SC
121
122 wxCommandEvent event( wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, GetId() );
123 event.SetInt( n );
51fbe4cc 124 event.SetString( GetString( n ) );
524c47aa
SC
125 event.SetEventObject( this );
126 HandleWindowEvent( event );
127 }
128}
129
130
131
132// ----------------------------------------------------------------------------
133// methods forwarded to wxListBox
134// ----------------------------------------------------------------------------
135
136void wxCheckListBox::OnItemInserted(unsigned int pos)
137{
7712257e
SC
138 wxListBox::OnItemInserted(pos);
139
524c47aa
SC
140 m_checks.Insert(false, pos );
141}
142
143void wxCheckListBox::DoDeleteOneItem(unsigned int n)
144{
145 wxListBox::DoDeleteOneItem(n);
146
147 m_checks.RemoveAt(n);
148}
149
150void wxCheckListBox::DoClear()
151{
7712257e
SC
152 wxListBox::DoClear();
153
524c47aa
SC
154 m_checks.Empty();
155}
156
157#endif // wxUSE_CHECKLISTBOX