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